diff --git a/src/tests/util.cpp b/src/tests/util.cpp index c091f2ece0832c8ce7c4f59230a9aa1523f36731..c590e81a0740f5c2f1cdcf6c070b38a5bfc05421 100644 --- a/src/tests/util.cpp +++ b/src/tests/util.cpp @@ -26,6 +26,7 @@ using namespace Transport; class UtilTest : public CPPUNIT_NS :: TestFixture{ CPPUNIT_TEST_SUITE(UtilTest); CPPUNIT_TEST(encryptDecryptPassword); + CPPUNIT_TEST(serializeGroups); CPPUNIT_TEST_SUITE_END(); public: @@ -41,6 +42,27 @@ class UtilTest : public CPPUNIT_NS :: TestFixture{ CPPUNIT_ASSERT_EQUAL(std::string("password"), StorageBackend::decryptPassword(encrypted, "key")); } + void serializeGroups() { + std::vector groups; + std::string g = ""; + + CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups)); + CPPUNIT_ASSERT_EQUAL(0, (int) StorageBackend::deserializeGroups(g).size()); + + groups.push_back("Buddies"); + g = "Buddies"; + CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups)); + CPPUNIT_ASSERT_EQUAL(1, (int) StorageBackend::deserializeGroups(g).size()); + CPPUNIT_ASSERT_EQUAL(g, StorageBackend::deserializeGroups(g)[0]); + + groups.push_back("Buddies2"); + g = "Buddies\nBuddies2"; + CPPUNIT_ASSERT_EQUAL(g, StorageBackend::serializeGroups(groups)); + CPPUNIT_ASSERT_EQUAL(2, (int) StorageBackend::deserializeGroups(g).size()); + CPPUNIT_ASSERT_EQUAL(std::string("Buddies"), StorageBackend::deserializeGroups(g)[0]); + CPPUNIT_ASSERT_EQUAL(std::string("Buddies2"), StorageBackend::deserializeGroups(g)[1]); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION (UtilTest);