| 35 | }; |
| 36 | |
| 37 | TEST_F(dlib, HashToString32) |
| 38 | { |
| 39 | std::map<std::string, std::pair<uint32_t, uint32_t> > string_to_hash; |
| 40 | |
| 41 | for (uint32_t i = 0; i < 1000; ++i) |
| 42 | { |
| 43 | std::string s; |
| 44 | uint32_t n = rand() % 32 + 1; |
| 45 | for (uint32_t j = 0; j < n; ++j) |
| 46 | { |
| 47 | char tmp[] = { (char)((rand() % ('z' - '0')) + '0'), 0 }; |
| 48 | s += tmp; |
| 49 | } |
| 50 | |
| 51 | uint32_t h = dmHashBuffer32(s.c_str(), s.size()); |
| 52 | string_to_hash[s] = std::pair<uint32_t, uint32_t>(h, s.size()); |
| 53 | } |
| 54 | |
| 55 | std::map<std::string, std::pair<uint32_t, uint32_t> >::const_iterator iter = string_to_hash.begin(); |
| 56 | while (iter != string_to_hash.end()) |
| 57 | { |
| 58 | uint32_t len; |
| 59 | const char* reverse = (const char*) dmHashReverse32(iter->second.first, &len); |
| 60 | ASSERT_NE((void*) 0, reverse); |
| 61 | ASSERT_EQ(iter->second.second, len); |
| 62 | ASSERT_TRUE(memcmp(iter->first.c_str(), reverse, len) == 0); |
| 63 | // Check that the buffer is null-terminated |
| 64 | ASSERT_STREQ(iter->first.c_str(), reverse); |
| 65 | ++iter; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | TEST_F(dlib, HashToString64) |
| 70 | { |
nothing calls this directly
no test coverage detected