A base type for 128 bit unsigned integer values.
#include <test.h>
#include <lunchbox/clock.h>
#include <lunchbox/init.h>
#include <lunchbox/rng.h>
#include <lunchbox/thread.h>
#include <lunchbox/uint128_t.h>
#define N_UUIDS 10000
#define N_THREADS 10
typedef stde::hash_map< lunchbox::uint128_t, bool > TestHash;
void testConvertUint128ToUUID();
void testIncrement();
{
public:
virtual void run()
{
size_t i = N_UUIDS;
while( i-- )
{
TESTINFO( hash.find( uuid ) == hash.end(),
"Iteration " << N_UUIDS - i );
hash[ uuid ] = true;
}
}
TestHash hash;
};
int main( int argc, char **argv )
{
TEST( id1 != id2 );
TEST( id1 != id2 );
TEST( id2.isUUID( ));
id1 = id2;
TEST( id1 == id2 );
TEST( id1 == *id3 );
TEST( *id4 != *id3 );
*id4 = *id3;
TEST( *id4 == *id3 );
delete id3;
delete id4;
TEST( id5 == id6 );
"The quick brown fox jumps over the lazy dog." );
TEST( empty != fox );
0xE9800998ECF8427Eull ),
empty );
0xA068FFADDF22CBD0ull ),
fox );
const uint16_t
high = rng.
get< uint16_t >();
const int32_t
low = rng.
get< int32_t >();
TEST( id6.high() ==
high );
TEST( id6.low() == uint64_t( low ));
TEST( id6.high() == 0 );
TEST( id6.low() == uint64_t( low ));
id6 = std::string( "0xD41D8CD98F00B204" );
TEST( id6.high() == 0 );
TEST( id6.low() == 0xD41D8CD98F00B204ull );
id6 = std::string( "0xD41D8CD98F00B204:0xE9800998ECF8427E" );
TESTINFO( id6.high() == 0xD41D8CD98F00B204ull, id6 );
TEST( id6.low() == 0xE9800998ECF8427Eull );
Thread threads[ N_THREADS ];
for( size_t i = 0; i < N_THREADS; ++i )
threads[ i ].start();
for( size_t i = 0; i < N_THREADS; ++i )
threads[ i ].join();
<< " UUID generations and hash ops / ms" << std::endl;
TestHash& first = threads[0].hash;
for( size_t i = 1; i < N_THREADS; ++i )
{
TestHash& current = threads[i].hash;
for( TestHash::const_iterator j = current.begin();
j != current.end(); ++j )
{
TESTINFO( uuid == j->first, j->first << " = " << uuid );
std::ostringstream stream;
stream << uuid;
uuid = stream.str();
TESTINFO( uuid == j->first,
j->first << " -> " << stream.str() << " -> " << uuid );
TEST( first.find( uuid ) == first.end( ));
first[ uuid ] = true;
}
}
testConvertUint128ToUUID();
testIncrement();
return EXIT_SUCCESS;
}
void testConvertUint128ToUUID()
{
const uint64_t low = 1212;
const uint64_t high = 2314;
TEST( test128.low() == low && test128.high() ==
high );
testUUID = test128;
TEST( compare128 == test128 );
}
void testIncrement()
{
{
++test128;
TEST( test128.high() == 0 && test128.low() == 1 );
--test128;
TEST( test128.high() == 0 && test128.low() == 0 );
test128 = test128 + 1;
TEST( test128.high() == 0 && test128.low() == 1 );
test128 = test128 - 1;
TEST( test128.high() == 0 && test128.low() == 0 );
}
{
++test128;
TEST( test128.high() == 1 && test128.low() == 0 );
--test128;
TEST( test128.high() == 0 &&
test128.low() == std::numeric_limits< uint64_t >::max() );
test128 = test128 + 1;
TEST( test128.high() == 1 && test128.low() == 0 );
test128 = test128 - 1;
TEST( test128.high() == 0 &&
test128.low() == std::numeric_limits< uint64_t >::max() );
}
{
++test128;
TEST( test128.high() == 0 && test128.low() == 1 );
--test128;
TEST( test128.high() == 0 && test128.low() == 0 );
test128 = test128 + 1;
TEST( test128.high() == 0 && test128.low() == 1 );
test128 = test128 - 1;
TEST( test128.high() == 0 && test128.low() == 0 );
}
{
++test128;
TEST( test128.high() == 1 && test128.low() == 0 );
--test128;
TEST( test128.high() == 0 &&
test128.low() == std::numeric_limits< uint64_t >::max() );
test128 = test128 + 1;
TEST( test128.high() == 1 && test128.low() == 0 );
test128 = test128 - 1;
TEST( test128.high() == 0 &&
test128.low() == std::numeric_limits< uint64_t >::max() );
}
}