diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-11-27 19:06:47 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-11-27 19:06:47 (GMT) |
commit | aa09a889108c4d0e3c5888ad98958d8f3e12bd3b (patch) | |
tree | 3c621ae0a6e2150281be182b37e2837b804adcba /Swiften/StringCodecs/UnitTest | |
parent | c89ef0ffae597ac8c1063732e1d9a2d84703a80c (diff) | |
download | swift-aa09a889108c4d0e3c5888ad98958d8f3e12bd3b.zip swift-aa09a889108c4d0e3c5888ad98958d8f3e12bd3b.tar.bz2 |
Added MD5 hashing algorithm.
Moved 'hexifying' of hashes into its own class, such that it can be
shared between all hashes.
Diffstat (limited to 'Swiften/StringCodecs/UnitTest')
-rw-r--r-- | Swiften/StringCodecs/UnitTest/Base64Test.cpp | 5 | ||||
-rw-r--r-- | Swiften/StringCodecs/UnitTest/HexifyTest.cpp | 21 | ||||
-rw-r--r-- | Swiften/StringCodecs/UnitTest/MD5Test.cpp | 29 | ||||
-rw-r--r-- | Swiften/StringCodecs/UnitTest/SHA1Test.cpp | 33 |
4 files changed, 63 insertions, 25 deletions
diff --git a/Swiften/StringCodecs/UnitTest/Base64Test.cpp b/Swiften/StringCodecs/UnitTest/Base64Test.cpp index 0217758..a28a9ab 100644 --- a/Swiften/StringCodecs/UnitTest/Base64Test.cpp +++ b/Swiften/StringCodecs/UnitTest/Base64Test.cpp @@ -5,8 +5,7 @@ using namespace Swift; -class Base64Test : public CppUnit::TestFixture -{ +class Base64Test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(Base64Test); CPPUNIT_TEST(testEncode); CPPUNIT_TEST(testEncode_NonAscii); @@ -16,8 +15,6 @@ class Base64Test : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: - Base64Test() {} - void testEncode() { String result(Base64::encode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")); CPPUNIT_ASSERT_EQUAL(String("QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejEyMzQ1Njc4OTA="), result); 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/SHA1Test.cpp b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp index 849dd6d..3dbf341 100644 --- a/Swiften/StringCodecs/UnitTest/SHA1Test.cpp +++ b/Swiften/StringCodecs/UnitTest/SHA1Test.cpp @@ -5,41 +5,32 @@ using namespace Swift; -class SHA1Test : public CppUnit::TestFixture -{ +class SHA1Test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(SHA1Test); - CPPUNIT_TEST(testGetBinaryHash); - CPPUNIT_TEST(testGetBinaryHash_Twice); - CPPUNIT_TEST(testGetHexHash); - CPPUNIT_TEST(testGetHexHash_NoData); + CPPUNIT_TEST(testGetHash); + CPPUNIT_TEST(testGetHash_Twice); + CPPUNIT_TEST(testGetHash_NoData); CPPUNIT_TEST_SUITE_END(); public: - SHA1Test() {} - - void testGetBinaryHash() { - ByteArray result(SHA1::getBinaryHash("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<")); + 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 testGetBinaryHash_Twice() { + 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::getBinaryHash(input); - ByteArray result(SHA1::getBinaryHash(input)); + 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 testGetHexHash() { - String result(SHA1::getHexHash("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(String("4206b23ca6b0a643d20d89b04ff58cf78b8096ed"), result); - } - - void testGetHexHash_NoData() { - String result(SHA1::getHexHash(ByteArray())); + void testGetHash_NoData() { + ByteArray result(SHA1::getHash(ByteArray())); - CPPUNIT_ASSERT_EQUAL(String("da39a3ee5e6b4b0d3255bfef95601890afd80709"), result); + 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); } }; |