Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/tests/test_Mod.h
Show All 18 Lines | |||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
*/ | */ | ||||
#include "lib/self_test.h" | #include "lib/self_test.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Mod.h" | #include "ps/Mod.h" | ||||
#include "scriptinterface/JSON.h" | |||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
class TestMod : public CxxTest::TestSuite | class TestMod : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void test_version_check() | void test_version_check() | ||||
{ | { | ||||
CStr eq = "="; | CStr eq = "="; | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | CStr jsonString = "{\ | ||||
\"version\" : \"0.0.25\",\ | \"version\" : \"0.0.25\",\ | ||||
\"label\" : \"0 A.D. Empires Ascendant\",\ | \"label\" : \"0 A.D. Empires Ascendant\",\ | ||||
\"url\" : \"https://play0ad.com\",\ | \"url\" : \"https://play0ad.com\",\ | ||||
\"description\" : \"A free, open-source, historical RTS game.\",\ | \"description\" : \"A free, open-source, historical RTS game.\",\ | ||||
\"dependencies\" : []\ | \"dependencies\" : []\ | ||||
}\ | }\ | ||||
"; | "; | ||||
JS::RootedValue json(rq.cx); | JS::RootedValue json(rq.cx); | ||||
TS_ASSERT(script.ParseJSON(jsonString, &json)); | TS_ASSERT(Script::ParseJSON(rq, jsonString, &json)); | ||||
JS_SetProperty(rq.cx, obj, "public", json); | JS_SetProperty(rq.cx, obj, "public", json); | ||||
JS::RootedValue jsonW(rq.cx); | JS::RootedValue jsonW(rq.cx); | ||||
CStr jsonStringW = "{\ | CStr jsonStringW = "{\ | ||||
\"name\": \"wrong\",\ | \"name\": \"wrong\",\ | ||||
\"version\" : \"0.0.25\",\ | \"version\" : \"0.0.25\",\ | ||||
\"label\" : \"wrong mod\",\ | \"label\" : \"wrong mod\",\ | ||||
\"url\" : \"\",\ | \"url\" : \"\",\ | ||||
\"description\" : \"fail\",\ | \"description\" : \"fail\",\ | ||||
\"dependencies\" : [\"0ad=0.0.24\"]\ | \"dependencies\" : [\"0ad=0.0.24\"]\ | ||||
}\ | }\ | ||||
"; | "; | ||||
TS_ASSERT(script.ParseJSON(jsonStringW, &jsonW)); | TS_ASSERT(Script::ParseJSON(rq, jsonStringW, &jsonW)); | ||||
JS_SetProperty(rq.cx, obj, "wrong", jsonW); | JS_SetProperty(rq.cx, obj, "wrong", jsonW); | ||||
JS::RootedValue jsonG(rq.cx); | JS::RootedValue jsonG(rq.cx); | ||||
CStr jsonStringG = "{\ | CStr jsonStringG = "{\ | ||||
\"name\": \"good\",\ | \"name\": \"good\",\ | ||||
\"version\" : \"0.0.25\",\ | \"version\" : \"0.0.25\",\ | ||||
\"label\" : \"good mod\",\ | \"label\" : \"good mod\",\ | ||||
\"url\" : \"\",\ | \"url\" : \"\",\ | ||||
\"description\" : \"ok\",\ | \"description\" : \"ok\",\ | ||||
\"dependencies\" : [\"0ad=0.0.25\"]\ | \"dependencies\" : [\"0ad=0.0.25\"]\ | ||||
}\ | }\ | ||||
"; | "; | ||||
TS_ASSERT(script.ParseJSON(jsonStringG, &jsonG)); | TS_ASSERT(Script::ParseJSON(rq, jsonStringG, &jsonG)); | ||||
JS_SetProperty(rq.cx, obj, "good", jsonG); | JS_SetProperty(rq.cx, obj, "good", jsonG); | ||||
JS::RootedValue jsonG2(rq.cx); | JS::RootedValue jsonG2(rq.cx); | ||||
CStr jsonStringG2 = "{\ | CStr jsonStringG2 = "{\ | ||||
\"name\": \"good\",\ | \"name\": \"good\",\ | ||||
\"version\" : \"0.0.25\",\ | \"version\" : \"0.0.25\",\ | ||||
\"label\" : \"good mod\",\ | \"label\" : \"good mod\",\ | ||||
\"url\" : \"\",\ | \"url\" : \"\",\ | ||||
\"description\" : \"ok\",\ | \"description\" : \"ok\",\ | ||||
\"dependencies\" : [\"0ad>=0.0.24\"]\ | \"dependencies\" : [\"0ad>=0.0.24\"]\ | ||||
}\ | }\ | ||||
"; | "; | ||||
TS_ASSERT(script.ParseJSON(jsonStringG2, &jsonG2)); | TS_ASSERT(Script::ParseJSON(rq, jsonStringG2, &jsonG2)); | ||||
JS_SetProperty(rq.cx, obj, "good2", jsonG2); | JS_SetProperty(rq.cx, obj, "good2", jsonG2); | ||||
JS::RootedValue availableMods(rq.cx, JS::ObjectValue(*obj)); | JS::RootedValue availableMods(rq.cx, JS::ObjectValue(*obj)); | ||||
std::vector<CStr> mods; | std::vector<CStr> mods; | ||||
mods.clear(); | mods.clear(); | ||||
mods.push_back("public"); | mods.push_back("public"); | ||||
Show All 35 Lines |
Wildfire Games · Phabricator