From f3d486839814ebe93bf6baaf9b77f54cfeff405d Mon Sep 17 00:00:00 2001
From: Brad Hards <bradh@frogmouth.net>
Date: Sun, 8 Jul 2007 04:50:36 +0000
Subject: [PATCH] Rework the MD5 and SHA1 file tests to remove reliance on
 additional files (not provided with QCA).

This also makes the tests run much, much faster.

svn path=/trunk/kdesupport/qca/; revision=685152
---
 unittest/hashunittest/CMakeLists.txt       |   2 +
 unittest/hashunittest/data/twobytes        |   1 +
 unittest/hashunittest/data/twohundredbytes | Bin 0 -> 200 bytes
 unittest/hashunittest/hashunittest.cpp     |  43 ++++++---------------
 4 files changed, 15 insertions(+), 31 deletions(-)
 create mode 100644 unittest/hashunittest/data/twobytes
 create mode 100644 unittest/hashunittest/data/twohundredbytes

diff --git a/unittest/hashunittest/CMakeLists.txt b/unittest/hashunittest/CMakeLists.txt
index 757b8664..b2c6c1da 100644
--- a/unittest/hashunittest/CMakeLists.txt
+++ b/unittest/hashunittest/CMakeLists.txt
@@ -9,5 +9,7 @@ add_executable( hashunittest ${hashunittest_bin_SRCS} )
 target_link_libraries( hashunittest qca ${QT_QTTEST_LIBRARY})
 
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/empty ${CMAKE_CURRENT_BINARY_DIR}/data/empty COPYONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/twobytes ${CMAKE_CURRENT_BINARY_DIR}/data/twobytes COPYONLY)
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/data/twohundredbytes ${CMAKE_CURRENT_BINARY_DIR}/data/twohundredbytes COPYONLY)
 
 ADD_TEST(Hashing ${EXECUTABLE_OUTPUT_PATH}/hashunittest)
diff --git a/unittest/hashunittest/data/twobytes b/unittest/hashunittest/data/twobytes
new file mode 100644
index 00000000..bb2a610e
--- /dev/null
+++ b/unittest/hashunittest/data/twobytes
@@ -0,0 +1 @@
+3w
\ No newline at end of file
diff --git a/unittest/hashunittest/data/twohundredbytes b/unittest/hashunittest/data/twohundredbytes
new file mode 100644
index 0000000000000000000000000000000000000000..7319f277675201d16db6974bf601ca720944e7df
GIT binary patch
literal 200
zcmXwyy$*sf6or|ceSrG{wxtY;U5v<Jf}?Q;dI{D3kb(w$dJF1ylJlMKh`h+wQ53C&
z5Rf_3DUA}U2_EjQs;ANt{b5A=iwS8^I$x5m9f?QTmIJAs0cYVBc9(Jjo<Pj@Y`14I
zaK^Tax$yyNf*a^!lFEMrJzmeniJ~d%e#1FoBuyFBs_*Ea48EO3f_iZ%3;B$}3w^J`
I;~$^f51|e{@Bjb+

literal 0
HcmV?d00001

diff --git a/unittest/hashunittest/hashunittest.cpp b/unittest/hashunittest/hashunittest.cpp
index b4aa4050..d11ce0c8 100644
--- a/unittest/hashunittest/hashunittest.cpp
+++ b/unittest/hashunittest/hashunittest.cpp
@@ -229,36 +229,27 @@ void HashUnitTest::md5filetest()
 		QWARN( "./data/empty could not be opened - do you need to create it?");
 	    }
 
-	    QFile f2( "./data/Botan-1.4.1.tar.bz2" );
+	    QFile f2( "./data/twobytes" );
 	    if ( f2.open( QIODevice::ReadOnly ) ) {
 		QCA::Hash hashObj("md5", provider);
 		hashObj.update( &f2 );
 		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "7c4b3d8a360c6c3cb647160fa9adfe71" ) );
+			 QString( "5fc9808ed18e442ab4164c59f151e757" ) );
 	    } else {
-		QWARN( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
+		QWARN( "./data/twobytes could not be opened - do you need to download it?");
 	    }
 
 
-	    QFile f3( "./data/linux-2.6.7.tar.bz2" );
+	    QFile f3( "./data/twohundredbytes" );
 	    if ( f3.open( QIODevice::ReadOnly ) ) {
 		QCA::Hash hashObj("md5", provider);
 		hashObj.update( &f3 );
 		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "a74671ea68b0e3c609e8785ed8497c14" ) );
+			 QString( "b91c1f114d942520ecdf7e84e580cda3" ) );
 	    } else {
-		QWARN( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
+		QWARN( "./data/twohundredbytes could not be opened - do you need to download it?");
 	    }
 
-	    QFile f4( "./data/scribus-1.2.tar.bz2" );
-	    if ( f4.open( QIODevice::ReadOnly ) ) {
-		QCA::Hash hashObj("md5", provider);
-		hashObj.update( &f4 );
-		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "7d2c2b228f9a6ff82c9401fd54bdbe16" ) );
-	    } else {
-		QWARN( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
-	    }
 	}
     }
 }
@@ -407,36 +398,26 @@ void HashUnitTest::sha1longtest()
 		QWARN( "./data/empty could not be opened - do you need to create it?");
 	    }
 
-	    QFile f2( "./data/Botan-1.4.1.tar.bz2" );
+	    QFile f2( "./data/twobytes" );
 	    if ( f2.open( QIODevice::ReadOnly ) ) {
 		QCA::Hash hashObj("sha1", provider);
 		hashObj.update( &f2 );
 		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "cda343591428a68e22bd2e349b890cbafb642cf7" ) );
+			 QString( "efbd6de3c51ca16094391e837bf52f7452593e5c" ) );
 	    } else {
-		QWARN( "./data/Botan-1.4.1.tar.bz2 could not be opened - do you need to download it?");
+		QWARN( "./data/twobytes could not be opened - do you need to download it?");
 	    }
 
-	    QFile f3( "./data/linux-2.6.7.tar.bz2" );
+	    QFile f3( "./data/twohundredbytes" );
 	    if ( f3.open( QIODevice::ReadOnly ) ) {
 		QCA::Hash hashObj("sha1", provider);
 		hashObj.update( &f3 );
 		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "a030a9c6dcd10c5d90a86f915ad4710084cbca71" ) );
+			 QString( "d636519dfb18d913acbe69fc3ee5a4c7ac870297" ) );
 	    } else {
-		QWARN( "./data/linux-2.6.7.tar.bz2 could not be opened - do you need to download it?");
+		QWARN( "./data/twohundredbytes could not be opened - do you need to download it?");
 	    }
 
-	    QFile f4( "./data/scribus-1.2.tar.bz2" );
-	    if ( f4.open( QIODevice::ReadOnly ) ) {
-		QCA::Hash hashObj("sha1", provider);
-		hashObj.update( &f4 );
-		QCOMPARE( QString( QCA::arrayToHex( hashObj.final().toByteArray() ) ),
-			 QString( "a1fb6ed6acfd92381055b310d926d6e83e76ff1e" ) );
-	    } else {
-		QWARN( "./data/scribus-1.2.tar.bz2 could not be opened - do you need to download it?");
-	    }
-	    // qDebug() << "SHA1: " << provider << " elapsed " << t.elapsed();
 	}
     }
 }