MCPcopy Create free account
hub / github.com/defold/defold / TEST_F

Function TEST_F

engine/dlib/src/test/test_dlib.cpp:37–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35};
36
37TEST_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
69TEST_F(dlib, HashToString64)
70{

Callers

nothing calls this directly

Calls 15

randClass · 0.85
dmHashReverse32Function · 0.85
dmHashReverse64Function · 0.85
dmHashReverseSafe64Function · 0.85
dmHashEnableReverseHashFunction · 0.85
dmHashReverseSafe32Function · 0.85
dmEndianCTestFunction · 0.85
EndianToHost16Function · 0.85
EndianToNetwork16Function · 0.85
EndianToHost32Function · 0.85
EndianToNetwork32Function · 0.85
EndianToHost64Function · 0.85

Tested by

no test coverage detected