]> git.lizzy.rs Git - minetest.git/blobdiff - src/unittest/test_areastore.cpp
Fix arm inertia limit case
[minetest.git] / src / unittest / test_areastore.cpp
index cac9e0b5815caed73bcaf5308d0330ca0e6b0f4b..62d446f5c076a189bbc2f8a295a4ae068354c0dc 100644 (file)
@@ -31,6 +31,7 @@ class TestAreaStore : public TestBase {
        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
+}
+