This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/source/simulation2/components/tests/test_CommandQueue.h

Last change on this file was 27965, checked in by Vladislav Belov, 13 months ago

Revert non-ASCII characters from source and configuration files introduced in rP27786.

Fixes #6846

Differential Revision: https://code.wildfiregames.com/D5185

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1/* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "simulation2/system/ComponentTest.h"
19
20#include "simulation2/components/ICmpCommandQueue.h"
21
22class TestCmpCommandQueue : public CxxTest::TestSuite
23{
24public:
25 void setUp()
26 {
27 CXeromyces::Startup();
28 }
29
30 void tearDown()
31 {
32 CXeromyces::Terminate();
33 }
34
35 void test_basic()
36 {
37 ComponentTestHelper test(*g_ScriptContext);
38 ScriptRequest rq(test.GetScriptInterface());
39
40 std::vector<SimulationCommand> empty;
41
42 ICmpCommandQueue* cmp = test.Add<ICmpCommandQueue>(CID_CommandQueue, "", SYSTEM_ENTITY);
43
44 TS_ASSERT(test.GetScriptInterface().Eval("var cmds = []; function ProcessCommand(player, cmd) { cmds.push([player, cmd]); }"));
45
46 JS::RootedValue cmd(rq.cx);
47
48 TS_ASSERT(test.GetScriptInterface().Eval("([1,2,3])", &cmd));
49 cmp->PushLocalCommand(1, cmd);
50
51 TS_ASSERT(test.GetScriptInterface().Eval("({\"x\":4})", &cmd));
52 cmp->PushLocalCommand(-1, cmd);
53
54 test.Roundtrip();
55
56 // Process the first two commands
57 cmp->FlushTurn(empty);
58
59 TS_ASSERT(test.GetScriptInterface().Eval("({\"y\":5})", &cmd));
60 cmp->PushLocalCommand(10, cmd);
61
62 // Process the next command
63 cmp->FlushTurn(empty);
64
65 // Process no commands
66 cmp->FlushTurn(empty);
67
68 test.Roundtrip();
69
70 std::string output;
71 TS_ASSERT(test.GetScriptInterface().Eval("JSON.stringify(cmds)", output));
72 TS_ASSERT_STR_EQUALS(output, "[[1,[1,2,3]],[-1,{\"x\":4}],[10,{\"y\":5}]]");
73 }
74};
Note: See TracBrowser for help on using the repository browser.