Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/tests/test_SerializeTemplates.h
Show All 25 Lines | |||||
#include <sstream> | #include <sstream> | ||||
#include <vector> | #include <vector> | ||||
class TestSerializeTemplates : public CxxTest::TestSuite | class TestSerializeTemplates : public CxxTest::TestSuite | ||||
{ | { | ||||
public: | public: | ||||
void test_Debug_array() | void test_Debug_array() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
std::stringstream stream; | std::stringstream stream; | ||||
CDebugSerializer serialize(script, stream); | CDebugSerializer serialize(script, stream); | ||||
std::array<u32, 6> value = { | std::array<u32, 6> value = { | ||||
3, 0, 1, 4, 1, 5 | 3, 0, 1, 4, 1, 5 | ||||
}; | }; | ||||
SerializeArray<SerializeU32_Unbounded>()(serialize, "E", value); | SerializeArray<SerializeU32_Unbounded>()(serialize, "E", value); | ||||
TS_ASSERT_STR_EQUALS(stream.str(), "E: 3\nE: 0\nE: 1\nE: 4\nE: 1\nE: 5\n"); | TS_ASSERT_STR_EQUALS(stream.str(), "E: 3\nE: 0\nE: 1\nE: 4\nE: 1\nE: 5\n"); | ||||
} | } | ||||
void test_Debug_vector() | void test_Debug_vector() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
std::stringstream stream; | std::stringstream stream; | ||||
CDebugSerializer serialize(script, stream); | CDebugSerializer serialize(script, stream); | ||||
std::vector<u32> value = { | std::vector<u32> value = { | ||||
3, 0, 1, 4, 1, 5 | 3, 0, 1, 4, 1, 5 | ||||
}; | }; | ||||
SerializeVector<SerializeU32_Unbounded>()(serialize, "E", value); | SerializeVector<SerializeU32_Unbounded>()(serialize, "E", value); | ||||
TS_ASSERT_STR_EQUALS(stream.str(), "length: 6\nE: 3\nE: 0\nE: 1\nE: 4\nE: 1\nE: 5\n"); | TS_ASSERT_STR_EQUALS(stream.str(), "length: 6\nE: 3\nE: 0\nE: 1\nE: 4\nE: 1\nE: 5\n"); | ||||
} | } | ||||
void test_Debug_set() | void test_Debug_set() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
std::stringstream stream; | std::stringstream stream; | ||||
CDebugSerializer serialize(script, stream); | CDebugSerializer serialize(script, stream); | ||||
std::set<u32> value = { | std::set<u32> value = { | ||||
3, 0, 1, 4, 1, 5 | 3, 0, 1, 4, 1, 5 | ||||
}; | }; | ||||
SerializeSet<SerializeU32_Unbounded>()(serialize, "E", value); | SerializeSet<SerializeU32_Unbounded>()(serialize, "E", value); | ||||
TS_ASSERT_STR_EQUALS(stream.str(), "size: 5\nE: 0\nE: 1\nE: 3\nE: 4\nE: 5\n"); | TS_ASSERT_STR_EQUALS(stream.str(), "size: 5\nE: 0\nE: 1\nE: 3\nE: 4\nE: 5\n"); | ||||
} | } | ||||
void test_Debug_grid() | void test_Debug_grid() | ||||
{ | { | ||||
ScriptInterface script("Test", "Test", g_ScriptRuntime); | ScriptInterface script("Test", "Test", g_ScriptContext); | ||||
std::stringstream stream; | std::stringstream stream; | ||||
CDebugSerializer serialize(script, stream); | CDebugSerializer serialize(script, stream); | ||||
Grid<u16> value; | Grid<u16> value; | ||||
value.resize(3,2); | value.resize(3,2); | ||||
// Checkerboard pattern. | // Checkerboard pattern. | ||||
for (u8 j = 0; j < value.height(); ++j) | for (u8 j = 0; j < value.height(); ++j) | ||||
for (u8 i = 0; i < value.width(); ++i) | for (u8 i = 0; i < value.width(); ++i) | ||||
value.set(i, j, ((i % 2) + (j % 2)) % 2); | value.set(i, j, ((i % 2) + (j % 2)) % 2); | ||||
SerializedGridCompressed<SerializeU16_Unbounded>()(serialize, "E", value); | SerializedGridCompressed<SerializeU16_Unbounded>()(serialize, "E", value); | ||||
TS_ASSERT_STR_EQUALS(stream.str(), "width: 3\nheight: 2\n" | TS_ASSERT_STR_EQUALS(stream.str(), "width: 3\nheight: 2\n" | ||||
"#: 1\nE: 0\n#: 1\nE: 1\n#: 1\nE: 0\n" | "#: 1\nE: 0\n#: 1\nE: 1\n#: 1\nE: 0\n" | ||||
"#: 1\nE: 1\n#: 1\nE: 0\n#: 1\nE: 1\n"); | "#: 1\nE: 1\n#: 1\nE: 0\n#: 1\nE: 1\n"); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator