summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-04-26 18:04:37 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-26 18:04:37 (GMT)
commitaa131405927fc7f597ed06aff71abb0a30b59926 (patch)
tree4289d7dc61a0f19efad3434b155e29d3843b4461 /Swiften/StringCodecs/UnitTest
parent7ef27db79a528263b17610444f4f85bafd0fa6fa (diff)
downloadswift-aa131405927fc7f597ed06aff71abb0a30b59926.zip
swift-aa131405927fc7f597ed06aff71abb0a30b59926.tar.bz2
Replace third-party Base64 by our own algorithm.
Change-Id: I48037fbc475c84f55dd74054bceb187a4798244a
Diffstat (limited to 'Swiften/StringCodecs/UnitTest')
-rw-r--r--Swiften/StringCodecs/UnitTest/Base64Test.cpp42
1 files changed, 28 insertions, 14 deletions
diff --git a/Swiften/StringCodecs/UnitTest/Base64Test.cpp b/Swiften/StringCodecs/UnitTest/Base64Test.cpp
index f6a424b..4005047 100644
--- a/Swiften/StringCodecs/UnitTest/Base64Test.cpp
+++ b/Swiften/StringCodecs/UnitTest/Base64Test.cpp
@@ -16,22 +16,41 @@ using namespace Swift;
class Base64Test : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(Base64Test);
- CPPUNIT_TEST(testEncode);
- CPPUNIT_TEST(testEncode_NonAscii);
+ CPPUNIT_TEST(testEncodeDecodeAllChars);
+ CPPUNIT_TEST(testEncodeDecodeOneBytePadding);
+ CPPUNIT_TEST(testEncodeDecodeTwoBytesPadding);
CPPUNIT_TEST(testEncode_NoData);
- CPPUNIT_TEST(testDecode);
CPPUNIT_TEST(testDecode_NoData);
CPPUNIT_TEST_SUITE_END();
public:
- void testEncode() {
- std::string result(Base64::encode(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")));
- CPPUNIT_ASSERT_EQUAL(std::string("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejEyMzQ1Njc4OTA="), result);
+ void testEncodeDecodeAllChars() {
+ ByteArray input;
+ for (unsigned char i = 0; i < 255; ++i) {
+ input.push_back(i);
+ }
+ std::string result(Base64::encode(input));
+
+ CPPUNIT_ASSERT_EQUAL(std::string("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+"), result);
+ CPPUNIT_ASSERT_EQUAL(input, Base64::decode(result));
}
- void testEncode_NonAscii() {
- std::string result(Base64::encode(createByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed")));
- CPPUNIT_ASSERT_EQUAL(std::string("QgayPKawpkPSDYmwT/WM94uAlu0="), result);
+ void testEncodeDecodeOneBytePadding() {
+ ByteArray input = createByteArray("ABCDE", 5);
+
+ std::string result = Base64::encode(input);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("QUJDREU="), result);
+ CPPUNIT_ASSERT_EQUAL(input, Base64::decode(result));
+ }
+
+ void testEncodeDecodeTwoBytesPadding() {
+ ByteArray input = createByteArray("ABCD", 4);
+
+ std::string result = Base64::encode(input);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("QUJDRA=="), result);
+ CPPUNIT_ASSERT_EQUAL(input, Base64::decode(result));
}
void testEncode_NoData() {
@@ -39,11 +58,6 @@ class Base64Test : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string(""), result);
}
- void testDecode() {
- ByteArray result(Base64::decode("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejEyMzQ1Njc4OTA="));
- CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), result);
- }
-
void testDecode_NoData() {
ByteArray result(Base64::decode(""));
CPPUNIT_ASSERT_EQUAL(ByteArray(), result);