summaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-10-30 19:27:48 -0400
committerShadowNinja <shadowninja@minetest.net>2016-03-07 16:33:20 -0500
commit821551a2669123ac9a476894d65b5efe10026040 (patch)
tree33fcfe3b0c6182a2084fa9957d4eb602483f4f44 /src/unittest
parentc4b7afed7ed12f8d5894c1a5dd15ea376af06da6 (diff)
downloadminetest-821551a2669123ac9a476894d65b5efe10026040.tar.gz
minetest-821551a2669123ac9a476894d65b5efe10026040.tar.bz2
minetest-821551a2669123ac9a476894d65b5efe10026040.zip
Implement AreaStore serialization
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test_areastore.cpp39
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
+}
+