summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-08-12 18:55:52 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-08-12 18:55:52 (GMT)
commit7917a635fb1cd67100391a0787942288481fc47b (patch)
tree97f598b6b1bd65b2ea76c91cd050858701b8b6db /Swiften/StringCodecs/UnitTest/SHA256Test.cpp
parentc6ffcd27e94d2f90fd4a3bcb5d2d3c6550ead59c (diff)
downloadswift-contrib-7917a635fb1cd67100391a0787942288481fc47b.zip
swift-contrib-7917a635fb1cd67100391a0787942288481fc47b.tar.bz2
Added SHA256.
Diffstat (limited to 'Swiften/StringCodecs/UnitTest/SHA256Test.cpp')
-rw-r--r--Swiften/StringCodecs/UnitTest/SHA256Test.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/Swiften/StringCodecs/UnitTest/SHA256Test.cpp b/Swiften/StringCodecs/UnitTest/SHA256Test.cpp
new file mode 100644
index 0000000..5bcdd11
--- /dev/null
+++ b/Swiften/StringCodecs/UnitTest/SHA256Test.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Base/ByteArray.h>
+#include <QA/Checker/IO.h>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/StringCodecs/SHA256.h>
+
+using namespace Swift;
+
+class SHA256Test : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SHA256Test);
+ CPPUNIT_TEST(testGetHashStatic_Empty);
+ CPPUNIT_TEST(testGetHashStatic_Small);
+ CPPUNIT_TEST(testGetHashStatic_Large);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetHashStatic_Empty() {
+ ByteArray result(SHA256::getHash(createByteArray("")));
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\xe3\xb0\xc4" "B" "\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99" "o" "\xb9" "$'" "\xae" "A" "\xe4" "d" "\x9b\x93" "L" "\xa4\x95\x99\x1b" "xR" "\xb8" "U", 32), result);
+ }
+
+ void testGetHashStatic_Small() {
+ ByteArray result(SHA256::getHash(createByteArray("abc")));
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad", 32), result);
+ }
+
+ void testGetHashStatic_Large() {
+ ByteArray result(SHA256::getHash(createByteArray("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")));
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1", 32), result);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SHA256Test);