diff options
Diffstat (limited to 'Swiften/Base/UnitTest/ByteArrayTest.cpp')
-rw-r--r-- | Swiften/Base/UnitTest/ByteArrayTest.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Swiften/Base/UnitTest/ByteArrayTest.cpp b/Swiften/Base/UnitTest/ByteArrayTest.cpp index cb10dd4..069e68e 100644 --- a/Swiften/Base/UnitTest/ByteArrayTest.cpp +++ b/Swiften/Base/UnitTest/ByteArrayTest.cpp @@ -8,12 +8,17 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include "Swiften/Base/ByteArray.h" +#include <boost/lexical_cast.hpp> using namespace Swift; class ByteArrayTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ByteArrayTest); CPPUNIT_TEST(testGetData_NoData); + CPPUNIT_TEST(testToString); + CPPUNIT_TEST(testToString_NullTerminated); + CPPUNIT_TEST(testToString_TwoNullTerminated); + CPPUNIT_TEST(testToString_AllNull); CPPUNIT_TEST_SUITE_END(); public: @@ -22,6 +27,30 @@ class ByteArrayTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(reinterpret_cast<const char*>(NULL), reinterpret_cast<const char*>(testling.getData())); } + + void testToString() { + ByteArray testling(ByteArray::create("abcde")); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_NullTerminated() { + ByteArray testling(ByteArray::create("abcde\0", 6)); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_TwoNullTerminated() { + ByteArray testling(ByteArray::create("abcde\0\0", 7)); + + CPPUNIT_ASSERT_EQUAL(std::string("abcde"), testling.toString()); + } + + void testToString_AllNull() { + ByteArray testling(ByteArray::create("\0\0", 2)); + + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.toString()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ByteArrayTest); |