Skip to content

Commit

Permalink
StringPool|Test: Verify serialization and deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 5, 2012
1 parent d775b9d commit f56d8d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/unittest.h
Expand Up @@ -23,7 +23,7 @@
#define LIBDENG_UNIT_TEST_H

#ifdef _DEBUG
# define LIBDENG_RUN_UNITTEST(Name) static int testResult_##Name = UNITTEST_##Name();
# define LIBDENG_RUN_UNITTEST(Name) int testResult_##Name = UNITTEST_##Name();
#else
# define LIBDENG_RUN_UNITTEST(Name)
#endif
Expand Down
25 changes: 24 additions & 1 deletion doomsday/engine/portable/src/stringpool.cpp
Expand Up @@ -965,7 +965,7 @@ LIBDENG_DEFINE_UNITTEST(StringPool)
assert(StringPool_Intern(p, is) == 2);

assert(StringPool_Size(p) == 2);
StringPool_Print(p);
//StringPool_Print(p);

assert(!StringPool_Empty(p));

Expand All @@ -984,6 +984,29 @@ LIBDENG_DEFINE_UNITTEST(StringPool)
assert(StringPool_Intern(p, s) == 1);
assert(StringPool_Size(p) == 2);

Str_Set(s, "FOUR");
StringPool_Intern(p, s);
StringPool_RemoveById(p, 1); // "Third!"

// Serialize.
Writer* w = Writer_NewWithDynamicBuffer(0);
StringPool_Write(p, w);

// Deserialize.
Reader* r = Reader_NewWithBuffer(Writer_Data(w), Writer_Size(w));
StringPool* p2 = StringPool_New();
StringPool_Read(p2, r);
//StringPool_Print(p2);
assert(StringPool_Size(p2) == 2);
assert(!Str_Compare(StringPool_String(p2, 2), "abc"));
assert(!Str_Compare(StringPool_String(p2, 3), "FOUR"));
Str_Set(s, "hello again");
assert(StringPool_Intern(p2, s) == 1);

StringPool_Delete(p2);
Reader_Delete(r);
Writer_Delete(w);

StringPool_Clear(p);
assert(StringPool_Empty(p));

Expand Down

0 comments on commit f56d8d3

Please sign in to comment.