diff options
Diffstat (limited to 'src/unittest/test_areastore.cpp')
-rw-r--r-- | src/unittest/test_areastore.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/unittest/test_areastore.cpp b/src/unittest/test_areastore.cpp index cac9e0b58..62d446f5c 100644 --- a/src/unittest/test_areastore.cpp +++ b/src/unittest/test_areastore.cpp @@ -31,6 +31,7 @@ public: void genericStoreTest(AreaStore *store); void testVectorStore(); void testSpatialStore(); + void testSerialization(); }; static TestAreaStore g_test_instance; @@ -41,6 +42,7 @@ void TestAreaStore::runTests(IGameDef *gamedef) #if USE_SPATIAL TEST(testSpatialStore); #endif + TEST(testSerialization); } //////////////////////////////////////////////////////////////////////////////// @@ -121,3 +123,40 @@ void TestAreaStore::genericStoreTest(AreaStore *store) store->removeArea(d.id); } +void TestAreaStore::testSerialization() +{ + VectorAreaStore store; + + Area a(v3s16(-1, 0, 1), v3s16(0, 1, 2)); + a.data = "Area A"; + store.insertArea(&a); + + Area b(v3s16(123, 456, 789), v3s16(32000, 100, 10)); + b.data = "Area B"; + store.insertArea(&b); + + std::ostringstream os; + store.serialize(os); + std::string str = os.str(); + + std::string str_wanted("\x00" // Version + "\x00\x02" // Count + "\xFF\xFF\x00\x00\x00\x01" // Area A min edge + "\x00\x00\x00\x01\x00\x02" // Area A max edge + "\x00\x06" // Area A data length + "Area A" // Area A data + "\x00\x7B\x00\x64\x00\x0A" // Area B min edge (last two swapped with max edge for sorting) + "\x7D\x00\x01\xC8\x03\x15" // Area B max edge (^) + "\x00\x06" // Area B data length + "Area B", // Area B data + 1 + 2 + + 6 + 6 + 2 + 6 + + 6 + 6 + 2 + 6); + UASSERTEQ(std::string, str, str_wanted); + + std::istringstream is(str); + store.deserialize(is); + + UASSERTEQ(size_t, store.size(), 4); // deserialize() doesn't clear the store +} + |