1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement AreaStore serialization

This commit is contained in:
ShadowNinja 2015-10-30 19:27:48 -04:00
parent c4b7afed7e
commit 821551a266
6 changed files with 104 additions and 95 deletions

View file

@ -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
}