Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/components/tests/test_CommandQueue.h
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 34 Lines | void test_basic() | ||||
TS_ASSERT(test.GetScriptInterface().Eval("var cmds = []; function ProcessCommand(player, cmd) { cmds.push([player, cmd]); }")); | TS_ASSERT(test.GetScriptInterface().Eval("var cmds = []; function ProcessCommand(player, cmd) { cmds.push([player, cmd]); }")); | ||||
JS::RootedValue cmd(cx); | JS::RootedValue cmd(cx); | ||||
TS_ASSERT(test.GetScriptInterface().Eval("([1,2,3])", &cmd)); | TS_ASSERT(test.GetScriptInterface().Eval("([1,2,3])", &cmd)); | ||||
cmp->PushLocalCommand(1, cmd); | cmp->PushLocalCommand(1, cmd); | ||||
TS_ASSERT(test.GetScriptInterface().Eval("({x:4})", &cmd)); | TS_ASSERT(test.GetScriptInterface().Eval("({\"x\":4})", &cmd)); | ||||
cmp->PushLocalCommand(-1, cmd); | cmp->PushLocalCommand(-1, cmd); | ||||
test.Roundtrip(); | test.Roundtrip(); | ||||
// Process the first two commands | // Process the first two commands | ||||
cmp->FlushTurn(empty); | cmp->FlushTurn(empty); | ||||
TS_ASSERT(test.GetScriptInterface().Eval("({y:5})", &cmd)); | TS_ASSERT(test.GetScriptInterface().Eval("({\"y\":5})", &cmd)); | ||||
cmp->PushLocalCommand(10, cmd); | cmp->PushLocalCommand(10, cmd); | ||||
// Process the next command | // Process the next command | ||||
cmp->FlushTurn(empty); | cmp->FlushTurn(empty); | ||||
// Process no commands | // Process no commands | ||||
cmp->FlushTurn(empty); | cmp->FlushTurn(empty); | ||||
test.Roundtrip(); | test.Roundtrip(); | ||||
std::string output; | std::string output; | ||||
TS_ASSERT(test.GetScriptInterface().Eval("uneval(cmds)", output)); | TS_ASSERT(test.GetScriptInterface().Eval("JSON.stringify(cmds)", output)); | ||||
TS_ASSERT_STR_EQUALS(output, "[[1, [1, 2, 3]], [-1, {x:4}], [10, {y:5}]]"); | TS_ASSERT_STR_EQUALS(output, "[[1,[1,2,3]],[-1,{\"x\":4}],[10,{\"y\":5}]]"); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator