summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/StringCodecs/UnitTest')
-rw-r--r--Swiften/StringCodecs/UnitTest/Base64Test.cpp44
-rw-r--r--Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp21
-rw-r--r--Swiften/StringCodecs/UnitTest/HexifyTest.cpp21
-rw-r--r--Swiften/StringCodecs/UnitTest/MD5Test.cpp29
-rw-r--r--Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp36
-rw-r--r--Swiften/StringCodecs/UnitTest/SHA1Test.cpp37
6 files changed, 188 insertions, 0 deletions
diff --git a/Swiften/StringCodecs/UnitTest/Base64Test.cpp b/Swiften/StringCodecs/UnitTest/Base64Test.cpp
new file mode 100644
index 0000000..a28a9ab
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/Base64Test.cpp
@@ -0,0 +1,44 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/StringCodecs/Base64.h"
+
+using namespace Swift;
+
+class Base64Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(Base64Test);
+ CPPUNIT_TEST(testEncode);
+ CPPUNIT_TEST(testEncode_NonAscii);
+ CPPUNIT_TEST(testEncode_NoData);
+ CPPUNIT_TEST(testDecode);
+ CPPUNIT_TEST(testDecode_NoData);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testEncode() {
+ String result(Base64::encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"));
+ CPPUNIT_ASSERT_EQUAL(String("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejEyMzQ1Njc4OTA="), result);
+ }
+
+ void testEncode_NonAscii() {
+ String result(Base64::encode(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed")));
+ CPPUNIT_ASSERT_EQUAL(String("QgayPKawpkPSDYmwT/WM94uAlu0="), result);
+ }
+
+ void testEncode_NoData() {
+ String result(Base64::encode(ByteArray()));
+ CPPUNIT_ASSERT_EQUAL(String(""), result);
+ }
+
+ void testDecode() {
+ ByteArray result(Base64::decode("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejEyMzQ1Njc4OTA="));
+ CPPUNIT_ASSERT_EQUAL(ByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), result);
+ }
+
+ void testDecode_NoData() {
+ ByteArray result(Base64::decode(""));
+ CPPUNIT_ASSERT_EQUAL(ByteArray(), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Base64Test);
diff --git a/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp b/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp
new file mode 100644
index 0000000..edfae10
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/HMACSHA1Test.cpp
@@ -0,0 +1,21 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/StringCodecs/HMACSHA1.h"
+
+using namespace Swift;
+
+class HMACSHA1Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(HMACSHA1Test);
+ CPPUNIT_TEST(testGetResult);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetResult() {
+ ByteArray result(HMACSHA1::getResult("foo", "foobar"));
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\xa4\xee\xba\x8e\x63\x3d\x77\x88\x69\xf5\x68\xd0\x5a\x1b\x3d\xc7\x2b\xfd\x4\xdd"), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HMACSHA1Test);
diff --git a/Swiften/StringCodecs/UnitTest/HexifyTest.cpp b/Swiften/StringCodecs/UnitTest/HexifyTest.cpp
new file mode 100644
index 0000000..bf032a3
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/HexifyTest.cpp
@@ -0,0 +1,21 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/StringCodecs/Hexify.h"
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/ByteArray.h"
+
+using namespace Swift;
+
+class HexifyTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(HexifyTest);
+ CPPUNIT_TEST(testHexify);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testHexify() {
+ CPPUNIT_ASSERT_EQUAL(String("4206b23ca6b0a643d20d89b04ff58cf78b8096ed"), Hexify::hexify(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed")));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HexifyTest);
diff --git a/Swiften/StringCodecs/UnitTest/MD5Test.cpp b/Swiften/StringCodecs/UnitTest/MD5Test.cpp
new file mode 100644
index 0000000..cad8754
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/MD5Test.cpp
@@ -0,0 +1,29 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/StringCodecs/MD5.h"
+#include "Swiften/Base/ByteArray.h"
+
+using namespace Swift;
+
+class MD5Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(MD5Test);
+ CPPUNIT_TEST(testGetHash_Empty);
+ CPPUNIT_TEST(testGetHash_Alphabet);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetHash_Empty() {
+ ByteArray result(MD5::getHash(""));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42\x7e", 16), result);
+ }
+
+ void testGetHash_Alphabet() {
+ ByteArray result(MD5::getHash("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f", 16), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MD5Test);
diff --git a/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp b/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp
new file mode 100644
index 0000000..92f4fe9
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/PBKDF2Test.cpp
@@ -0,0 +1,36 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/StringCodecs/PBKDF2.h"
+
+using namespace Swift;
+
+class PBKDF2Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PBKDF2Test);
+ CPPUNIT_TEST(testGetResult_I1);
+ CPPUNIT_TEST(testGetResult_I2);
+ CPPUNIT_TEST(testGetResult_I4096);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetResult_I1() {
+ ByteArray result(PBKDF2::encode("password", "salt", 1));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6"), result);
+ }
+
+ void testGetResult_I2() {
+ ByteArray result(PBKDF2::encode("password", "salt", 2));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\xea\x6c\x1\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce\x1d\x41\xf0\xd8\xde\x89\x57"), result);
+ }
+
+ void testGetResult_I4096() {
+ ByteArray result(PBKDF2::encode("password", "salt", 4096));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\x4b\x00\x79\x1\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26\xf7\x21\xd0\x65\xa4\x29\xc1", 20), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PBKDF2Test);
diff --git a/Swiften/StringCodecs/UnitTest/SHA1Test.cpp b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp
new file mode 100644
index 0000000..3dbf341
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp
@@ -0,0 +1,37 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/StringCodecs/SHA1.h"
+
+using namespace Swift;
+
+class SHA1Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SHA1Test);
+ CPPUNIT_TEST(testGetHash);
+ CPPUNIT_TEST(testGetHash_Twice);
+ CPPUNIT_TEST(testGetHash_NoData);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetHash() {
+ ByteArray result(SHA1::getHash("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<"));
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), result);
+ }
+
+
+ void testGetHash_Twice() {
+ ByteArray input("client/pc//Exodus 0.9.1<http://jabber.org/protocol/caps<http://jabber.org/protocol/disco#info<http://jabber.org/protocol/disco#items<http://jabber.org/protocol/muc<");
+ SHA1::getHash(input);
+ ByteArray result(SHA1::getHash(input));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\x42\x06\xb2\x3c\xa6\xb0\xa6\x43\xd2\x0d\x89\xb0\x4f\xf5\x8c\xf7\x8b\x80\x96\xed"), result);
+ }
+
+ void testGetHash_NoData() {
+ ByteArray result(SHA1::getHash(ByteArray()));
+
+ CPPUNIT_ASSERT_EQUAL(ByteArray("\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18\x90\xaf\xd8\x07\x09"), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SHA1Test);