84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
|
#include <lw/lib/Utilities.hh>
|
||
|
#include <cppunit/extensions/HelperMacros.h>
|
||
|
using namespace lw;
|
||
|
|
||
|
|
||
|
/* - ComputeHashTest ---------------------------------------------------{{{-*/
|
||
|
class ComputeHashTest : public CppUnit::TestFixture
|
||
|
{
|
||
|
CPPUNIT_TEST_SUITE( ComputeHashTest );
|
||
|
CPPUNIT_TEST( testInt8 );
|
||
|
CPPUNIT_TEST( testInt16 );
|
||
|
CPPUNIT_TEST( testInt32 );
|
||
|
CPPUNIT_TEST( testInt64 );
|
||
|
CPPUNIT_TEST( testStructDefault );
|
||
|
CPPUNIT_TEST_SUITE_END( );
|
||
|
|
||
|
public:
|
||
|
void testInt8( );
|
||
|
void testInt16( );
|
||
|
void testInt32( );
|
||
|
void testInt64( );
|
||
|
void testStructDefault( );
|
||
|
};
|
||
|
|
||
|
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION( ComputeHashTest );
|
||
|
|
||
|
void ComputeHashTest::testInt8( ) // {{{
|
||
|
{
|
||
|
const uint8_t t8u = 1;
|
||
|
const int8_t t8su = 1 , t8ss = -1;
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t8u ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t8su ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0xff ) , ComputeHash( t8ss ) );
|
||
|
}
|
||
|
|
||
|
// }}}
|
||
|
void ComputeHashTest::testInt16( ) // {{{
|
||
|
{
|
||
|
const uint16_t t16u = 1;
|
||
|
const int16_t t16su = 1, t16ss = -1;
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t16u ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t16su ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0xffff ) , ComputeHash( t16ss ) );
|
||
|
}
|
||
|
|
||
|
// }}}
|
||
|
void ComputeHashTest::testInt32( ) // {{{
|
||
|
{
|
||
|
uint32_t t32u = 1;
|
||
|
int32_t t32su = 1, t32ss = -1;
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t32u ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 1 ) , ComputeHash( t32su ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0xffffffff ) , ComputeHash( t32ss ) );
|
||
|
}
|
||
|
|
||
|
// }}}
|
||
|
void ComputeHashTest::testInt64( ) // {{{
|
||
|
{
|
||
|
uint64_t t64u = 0x100000010L;
|
||
|
int64_t t64s = -1;
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0x11 ) , ComputeHash( t64u ) );
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( 0 ) , ComputeHash( t64s ) );
|
||
|
}
|
||
|
|
||
|
// }}}
|
||
|
void ComputeHashTest::testStructDefault( ) // {{{
|
||
|
{
|
||
|
struct T_Test_ {
|
||
|
uint8_t meh[ 16 ];
|
||
|
};
|
||
|
T_Test_ test;
|
||
|
for ( auto i = 0 ; i < 16 ; i ++ ) {
|
||
|
test.meh[ i ] = i;
|
||
|
}
|
||
|
|
||
|
CPPUNIT_ASSERT_EQUAL( uint32_t( HashData( test.meh , 16 ) ) ,
|
||
|
ComputeHash( test ) );
|
||
|
}
|
||
|
|
||
|
// }}}
|
||
|
|
||
|
/*------------------------------------------------------------------------}}}-*/
|