63 void Check(
const std::string hashName,
const uint64_t hash);
76 void Check(
const std::string hashName,
const int bits,
const uint64_t hash);
77 void DoRun()
override;
84 key(
"The quick brown fox jumped over the lazy dogs.")
95 Check(hashName, 32, hash);
101 Check(hashName, 64, hash);
124 std::cout <<
GetName() <<
"checking " << hashName <<
" " << bits <<
"-bit result...";
127 hashName <<
" " << type <<
" produced " << std::hex << std::setw(w)
128 << hash <<
", expected " << std::hex << std::setw(w) << hashRef
130 std::cout << std::hex << std::setw(w) << hash <<
", ok" << std::dec << std::endl;
151 void DoRun()
override;
166 std::cout <<
GetName() <<
"checking with key: \"" <<
key <<
"\"" << std::endl;
188 void DoRun()
override;
224 void DoRun()
override;
261gnu_sum(
const char* buffer,
const std::size_t size)
263 const char* p = buffer;
264 const char*
const pend = p + size;
266 uint16_t checksum = 0;
270 checksum = (checksum >> 1) + ((checksum & 1) << 15);
297 return (uint64_t)((h << 32) + h);
313 void DoRun()
override;
346 void DoRun()
override;
379 void DoRun()
override;
415 key1 =
"The quick brown ";
416 key2 =
"Incremental.";
419 std::cout <<
GetName() <<
"checking with key: ";
420 std::cout <<
"\"" <<
key1 <<
"\"[" <<
key1.size() <<
"] + ";
421 std::cout <<
"\"" <<
key2 <<
"\"[" <<
key2.size() <<
"]" << std::endl;
423 std::cout <<
GetName() <<
"equivalent to: ";
424 std::cout <<
"\"" <<
key12 <<
"\"[" <<
key12.size() <<
"]" << std::endl;
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, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
std::string GetName() const
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
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.
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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Namespace for test files, TestCases and TestSuites.
Every class exported by the ns3 library is enclosed in the ns3 namespace.