summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2010-11-17 04:07:51 +0000
committertanjent@gmail.com <tanjent@gmail.com@77a7d1d3-4c08-bdc2-d393-d5859734b01a>2010-11-17 04:07:51 +0000
commit9d17d0b842230279e2a89b2e65a7dde05494d529 (patch)
treefb99e8908bae903917842deb0f84d33cf53d0bd3
parent31a9e8ef5b491fda1cc2f09ebef2353a30b0eb40 (diff)
downloadsrc-9d17d0b842230279e2a89b2e65a7dde05494d529.tar.gz
remove swap() and use std::swap instead, make alignment test a bit more robust
git-svn-id: http://smhasher.googlecode.com/svn/trunk@69 77a7d1d3-4c08-bdc2-d393-d5859734b01a
-rw-r--r--KeysetTest.cpp31
-rw-r--r--KeysetTest.h6
-rw-r--r--Types.h8
3 files changed, 26 insertions, 19 deletions
diff --git a/KeysetTest.cpp b/KeysetTest.cpp
index 3424ce6..70b63de 100644
--- a/KeysetTest.cpp
+++ b/KeysetTest.cpp
@@ -36,27 +36,32 @@ void AlignmentTest ( pfHash hash, const int hashbits )
{
const int hashbytes = hashbits / 8;
- printf("Testing alignment handling on small keys..........");
+ printf("Testing alignment handling..........");
- char bufs[16][64];
+ char testblob[512];
+ rand_p(testblob,512);
+ char * bufs[16];
char * strings[16];
for(int i = 0; i < 16; i++)
{
- uint32_t b = uint32_t(&bufs[i][0]);
+ bufs[i] = new char[1024];
+ uint32_t b = uint32_t(bufs[i]);
b = (b+15)&(~15);
strings[i] = (char*)(b + i);
-
- strcpy_s(strings[i],32,"DeadBeefDeadBeef");
+
+ memcpy(strings[i],testblob,512);
}
+ bool result = true;
+
uint32_t hash1[64];
uint32_t hash2[64];
- for(int k = 1; k <= 16; k++)
+ for(int k = 1; k <= 512; k++)
for(int j = 0; j < 15; j++)
for(int i = j+1; i < 16; i++)
{
@@ -68,12 +73,20 @@ void AlignmentTest ( pfHash hash, const int hashbits )
if(memcmp(hash1,hash2,hashbytes) != 0)
{
- printf("*********FAIL*********\n");
- return;
+ result = false;
}
}
- printf("PASS\n");
+ if(!result)
+ {
+ printf("*********FAIL*********\n");
+ }
+ else
+ {
+ printf("PASS\n");
+ }
+
+ for(int i = 0; i < 16; i++) delete [] bufs[i];
}
//----------------------------------------------------------------------------
diff --git a/KeysetTest.h b/KeysetTest.h
index ae2bfcf..53b61ec 100644
--- a/KeysetTest.h
+++ b/KeysetTest.h
@@ -10,6 +10,8 @@
#include "Types.h"
#include "Stats.h"
+#include <algorithm> // for std::swap
+
//-----------------------------------------------------------------------------
// Sanity tests
@@ -38,11 +40,11 @@ void PermutationKeygenRecurse ( pfHash hash, uint32_t * blocks, int blockcount,
for(int i = k; i < blockcount; i++)
{
- swap(blocks[k],blocks[i]);
+ std::swap(blocks[k],blocks[i]);
PermutationKeygenRecurse(hash,blocks,blockcount,k+1,hashes);
- swap(blocks[k],blocks[i]);
+ std::swap(blocks[k],blocks[i]);
}
}
diff --git a/Types.h b/Types.h
index d31a647..eb2a309 100644
--- a/Types.h
+++ b/Types.h
@@ -17,14 +17,6 @@ uint32_t whitehole ( void );
typedef void (*pfHash) ( const void * blob, const int len, const uint32_t seed, void * out );
-template < typename T >
-void swap ( T & a, T & b )
-{
- T t = a;
- a = b;
- b = t;
-}
-
//-----------------------------------------------------------------------------
template < class T >