summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-04-13 19:46:24 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-04-18 19:11:43 (GMT)
commit07152630c3a9d04dd86f7b370ee30b553665f5c7 (patch)
tree5b3f57a46d6a4ae1f6a6c60cb095866a0e752ef9 /Swiften/Base/UnitTest
parent68b51298da4fcfcdc3bb81a9abba6c56809ae1b7 (diff)
downloadswift-contrib-07152630c3a9d04dd86f7b370ee30b553665f5c7.zip
swift-contrib-07152630c3a9d04dd86f7b370ee30b553665f5c7.tar.bz2
Chop off trailing \0 in ByteArray::toString().
Diffstat (limited to 'Swiften/Base/UnitTest')
-rw-r--r--Swiften/Base/UnitTest/ByteArrayTest.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Swiften/Base/UnitTest/ByteArrayTest.cpp b/Swiften/Base/UnitTest/ByteArrayTest.cpp
index b9797d2..069e68e 100644
--- a/Swiften/Base/UnitTest/ByteArrayTest.cpp
+++ b/Swiften/Base/UnitTest/ByteArrayTest.cpp
@@ -8,6 +8,7 @@
#include <cppunit/extensions/TestFactoryRegistry.h>
#include "Swiften/Base/ByteArray.h"
+#include <boost/lexical_cast.hpp>
using namespace Swift;
@@ -17,6 +18,7 @@ class ByteArrayTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testToString_NullTerminated);
CPPUNIT_TEST(testToString_TwoNullTerminated);
+ CPPUNIT_TEST(testToString_AllNull);
CPPUNIT_TEST_SUITE_END();
public:
@@ -33,16 +35,22 @@ class ByteArrayTest : public CppUnit::TestFixture {
}
void testToString_NullTerminated() {
- ByteArray testling(ByteArray::create("abcde\0"));
+ 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"));
+ 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);