68 void Check (
const std::string hashName,
const uint32_t
hash);
74 void Check (
const std::string hashName,
const uint64_t
hash);
87 void Check (
const std::string hashName,
const int bits,
const uint64_t
hash);
88 virtual void DoRun (
void);
94 key (
"The quick brown fox jumped over the lazy dogs.")
132 std::cout <<
GetName () <<
"checking "
134 << bits <<
"-bit result...";
136 hashName <<
" " << type
137 <<
" produced " << std::hex << std::setw (w) <<
hash
138 <<
", expected " << std::hex << std::setw (w) << hashRef
141 std::cout << std::hex << std::setw (w) <<
hash <<
", ok"
142 << std::dec << std::endl;
163 virtual void DoRun (
void);
176 std::cout <<
GetName () <<
"checking with key: \""
177 <<
key <<
"\"" << std::endl;
199 virtual void DoRun (
void);
212 Hasher hasher =
Hasher ( Create<Hash::Function::Fnv1a> () );
234 virtual void DoRun (
void);
247 Hasher hasher =
Hasher ( Create<Hash::Function::Murmur3> () );
270 gnu_sum (
const char * buffer,
const std::size_t size)
272 const char * p = buffer;
273 const char *
const pend = p + size;
275 uint16_t checksum = 0;
279 checksum = (checksum >> 1) + ((checksum & 1) << 15);
293 uint32_t h =
gnu_sum (buffer, size);
294 return (uint32_t)( (h << 16) + h);
306 return (uint64_t)( (h << 32) + h);
322 virtual void DoRun (
void);
353 virtual void DoRun (
void);
384 virtual void DoRun (
void);
418 key1 =
"The quick brown ";
419 key2 =
"Incremental.";
422 std::cout <<
GetName () <<
"checking with key: "
423 <<
"\"" <<
key1 <<
"\"[" <<
key1.size () <<
"] + "
424 <<
"\"" <<
key2 <<
"\"[" <<
key2.size () <<
"]" << std::endl;
425 std::cout <<
GetName () <<
"equivalent to: "
426 <<
"\"" <<
key12 <<
"\"[" <<
key12.size () <<
"]" << std::endl;
429 DoHash (
"murmur3",
Hasher ( Create<Hash::Function::Murmur3> () ) );
430 DoHash (
"FNV1a",
Hasher ( Create<Hash::Function::Fnv1a> () ) );
Generic Hash function interface.
uint32_t GetHash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer.
uint64_t GetHash64(const char *buffer, const std::size_t size)
Compute 64-bit hash of a byte buffer.
Hasher & clear(void)
Restore initial state.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::string GetName(void) const
Test default hash on fixed string.
DefaultHashTestCase()
Constructor.
virtual ~DefaultHashTestCase()
Destructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
FNV hash on fixed string.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~Fnv1aTestCase()
Destructor.
Fnv1aTestCase()
Constructor.
Test 32-bit function pointer.
virtual ~Hash32FunctionPtrTestCase()
Destructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Hash32FunctionPtrTestCase()
Constructor.
Test 64-bit function pointer.
virtual ~Hash64FunctionPtrTestCase()
Destructor.
Hash64FunctionPtrTestCase()
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Base class for hash tests.
uint64_t hash64Reference
The 64-bit hash of the reference.
virtual ~HashTestCase()
Destructor.
uint32_t hash32Reference
The 32-bit hash of the reference.
HashTestCase(const std::string name)
Constructor.
std::string key
The reference value to hash.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Check(const std::string hashName, const uint32_t hash)
Check function.
Hash functions test suite.
HashTestSuite()
Constructor.
Test incremental hashing.
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::string key1
test string
virtual ~IncrementalTestCase()
Destructor.
void DoHash(const std::string name, Hasher hasher)
Complute the hash test function.
std::string key2
test string
IncrementalTestCase()
Constructor.
std::string key12
test string
Test Murmur3 hash on fixed string.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Murmur3TestCase()
Constructor.
virtual ~Murmur3TestCase()
Destructor.
uint32_t gnu_sum32(const char *buffer, const std::size_t size)
A 32-bit hash function, based on gnu_sum().
uint64_t gnu_sum64(const char *buffer, const std::size_t size)
A 64-bit hash function, base on gnu_sum().
static HashTestSuite g_hashTestSuite
HashTestSuite instance variable.
uint16_t gnu_sum(const char *buffer, const std::size_t size)
Simple hash function based on the GNU sum program.
uint64_t Hash64(const char *buffer, const std::size_t size)
Compute 64-bit hash of a byte buffer, using the default hash function.
uint32_t Hash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Every class exported by the ns3 library is enclosed in the ns3 namespace.