* 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
| 100 | * @return The Squirrel table converted to a JSON-string. |
| 101 | */ |
| 102 | static 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 | |
| 121 | TEST_CASE("Squirrel -> JSON conversion") |
| 122 | { |
no test coverage detected