MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TestScriptEventAdminPort

Function TestScriptEventAdminPort

src/tests/test_script_admin.cpp:102–119  ·  view source on GitHub ↗

* Validate ScriptEventAdminPort can convert JSON to Squirrel. * * This function is not actually part of ScriptAdmin, but we will use MakeJSON, * and as such need to be inside this class. * * The easiest way to do validate, is to first use ScriptEventAdminPort (the function * we are testing) to convert the JSON to a Squirrel table. Then to use MakeJSON * to convert it back to JSON. * * Sad

Source from the content-addressed store, hash-verified

100 * @return The Squirrel table converted to a JSON-string.
101 */
102static std::optional<std::string> TestScriptEventAdminPort(const std::string &json)
103{
104 auto vm = sq_open(1024);
105
106 /* Run the conversion JSON -> Squirrel (this will now be on top of the stack). */
107 ScriptEventAdminPort(json).GetObject(vm);
108 if (sq_gettype(vm, -1) == OT_NULL) {
109 sq_close(vm);
110 return std::nullopt;
111 }
112 REQUIRE(sq_gettype(vm, -1) == OT_TABLE);
113
114 nlohmann::json squirrel_json;
115 REQUIRE(ScriptAdminMakeJSON(squirrel_json, vm, -1) == true);
116
117 sq_close(vm);
118 return squirrel_json.dump();
119}
120
121TEST_CASE("Squirrel -> JSON conversion")
122{

Callers 1

Calls 7

sq_openFunction · 0.85
sq_gettypeFunction · 0.85
sq_closeFunction · 0.85
ScriptAdminMakeJSONFunction · 0.85
GetObjectMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected