MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / TriClickText

Function TriClickText

engine/Poseidon/Game/Commands/GameStateExtTest.cpp:679–714  ·  view source on GitHub ↗

triClickText "text" — find control by text content and click it. Returns true on success. triClickText "needle" -> "OK" or "FAIL:not_found" / "FAIL:no_display". Returns a string (rather than a bool) so the tri runner can apply Capybara-style automatic synchronisation: if the text isn't on screen yet, the runner re-tries every poll_interval until the assertion timeout. Tests that previously had t

Source from the content-addressed store, hash-verified

677 C3DStatic* s = dynamic_cast<C3DStatic*>(display->GetCtrl(idc));
678 if (s == nullptr)
679 return GameValue(Format("FAIL:no C3DStatic with idc %d", idc));
680 for (int i = 0; i < s->GetLineCount(); i++)
681 {
682 std::string line = (const char*)s->GetLine(i);
683 std::size_t start = line.find_first_not_of(" \t\r\n");
684 if (start != std::string::npos && line.compare(start, prefix.size(), prefix) == 0)
685 return GameValue(RString("OK"));
686 }
687 return GameValue(Format("FAIL:no line starts with '%s' (%d lines)", prefix.c_str(), s->GetLineCount()));
688}
689
690/// triAssertControlLinesExclude [idc, "needle"] - assert no rendered line of the
691/// active display's C3DStatic (idc) contains needle. Useful for catching explicit
692/// line-break delimiters that split lines but still leak into the drawn substring.
693GameValue TriAssertControlLinesExclude(const GameState* /*state*/, GameValuePar arg)
694{
695 const GameArrayType& a = arg;
696 if (a.Size() < 2)
697 return GameValue(RString("FAIL:triAssertControlLinesExclude needs [idc, needle]"));
698 const int idc = static_cast<int>(static_cast<GameScalarType>(a[0]));
699 std::string needle = (const char*)static_cast<RString>(a[1]);
700 if (needle == "\\n")
701 needle = "\n";
702 else if (needle == "\\r")
703 needle = "\r";
704 ControlsContainer* display = GetActiveDisplayForSQF();
705 if (display == nullptr)
706 return GameValue(RString("FAIL:no active display"));
707 C3DStatic* s = dynamic_cast<C3DStatic*>(display->GetCtrl(idc));
708 if (s == nullptr)
709 return GameValue(Format("FAIL:no C3DStatic with idc %d", idc));
710 for (int i = 0; i < s->GetLineCount(); i++)
711 {
712 std::string line = (const char*)s->GetLine(i);
713 if (line.find(needle) != std::string::npos)
714 return GameValue(Format("FAIL:line %d contains excluded text", i));
715 }
716 return GameValue(RString("OK"));
717}

Callers

nothing calls this directly

Calls 11

GetActiveDisplayForSQFFunction · 0.85
GameValueClass · 0.50
GetCtrlMethod · 0.45
IsVisibleMethod · 0.45
emptyMethod · 0.45
XMethod · 0.45
WMethod · 0.45
YMethod · 0.45
HMethod · 0.45
OnLButtonDownMethod · 0.45
OnLButtonUpMethod · 0.45

Tested by

no test coverage detected