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 void DoRun()
override;
94 key(
"The quick brown fox jumped over the lazy dogs.")
134 std::cout <<
GetName() <<
"checking " << hashName <<
" " << bits <<
"-bit result...";
137 hashName <<
" " <<
type <<
" produced " << std::hex << std::setw(w)
138 <<
hash <<
", expected " << std::hex << std::setw(w) << hashRef
140 std::cout << std::hex << std::setw(w) <<
hash <<
", ok" << std::dec << std::endl;
161 void DoRun()
override;
176 std::cout <<
GetName() <<
"checking with key: \"" <<
key <<
"\"" << std::endl;
198 void DoRun()
override;
213 Hasher hasher =
Hasher(Create<Hash::Function::Fnv1a>());
234 void DoRun()
override;
249 Hasher hasher =
Hasher(Create<Hash::Function::Murmur3>());
271 gnu_sum(
const char* buffer,
const std::size_t size)
273 const char* p = buffer;
274 const char*
const pend = p + size;
276 uint16_t checksum = 0;
280 checksum = (checksum >> 1) + ((checksum & 1) << 15);
294 uint32_t h =
gnu_sum(buffer, size);
295 return (uint32_t)((h << 16) + h);
307 return (uint64_t)((h << 32) + h);
323 void DoRun()
override;
356 void DoRun()
override;
389 void DoRun()
override;
425 key1 =
"The quick brown ";
426 key2 =
"Incremental.";
429 std::cout <<
GetName() <<
"checking with key: "
430 <<
"\"" <<
key1 <<
"\"[" <<
key1.size() <<
"] + "
431 <<
"\"" <<
key2 <<
"\"[" <<
key2.size() <<
"]" << std::endl;
432 std::cout <<
GetName() <<
"equivalent to: "
433 <<
"\"" <<
key12 <<
"\"[" <<
key12.size() <<
"]" << std::endl;
436 DoHash(
"murmur3",
Hasher(Create<Hash::Function::Murmur3>()));
437 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()
Restore initial state.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::string GetName() const
Test default hash on fixed string.
DefaultHashTestCase()
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
~DefaultHashTestCase() override
Destructor.
FNV hash on fixed string.
void DoRun() override
Implementation to actually run this TestCase.
Fnv1aTestCase()
Constructor.
~Fnv1aTestCase() override
Destructor.
Test 32-bit function pointer.
Hash32FunctionPtrTestCase()
Constructor.
void DoRun() override
Implementation to actually run this TestCase.
~Hash32FunctionPtrTestCase() override
Destructor.
Test 64-bit function pointer.
Hash64FunctionPtrTestCase()
Constructor.
~Hash64FunctionPtrTestCase() override
Destructor.
void DoRun() override
Implementation to actually run this TestCase.
Base class for hash tests.
void DoRun() override
Implementation to actually run this TestCase.
uint64_t hash64Reference
The 64-bit hash of the reference.
uint32_t hash32Reference
The 32-bit hash of the reference.
~HashTestCase() override
Destructor.
HashTestCase(const std::string name)
Constructor.
std::string key
The reference value to hash.
void Check(const std::string hashName, const uint32_t hash)
Check function.
Hash functions test suite.
HashTestSuite()
Constructor.
Test incremental hashing.
std::string key1
test string
void DoRun() override
Implementation to actually run this TestCase.
~IncrementalTestCase() override
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.
void DoRun() override
Implementation to actually run this TestCase.
Murmur3TestCase()
Constructor.
~Murmur3TestCase() override
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.