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

Function TEST

engine/dlib/src/test/test_stringpool.cpp:29–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#include "dlib/hash.h"
28
29TEST(dmStringPool, Test01)
30{
31 dmStringPool::HPool pool = dmStringPool::New();
32
33 std::map<const char*, std::string > strings;
34
35 uint32_t n_allocated = 0;
36 for (uint32_t i = 0; i < 20000; ++i)
37 {
38 std::string tmp;
39 uint32_t n = rand() % 16;
40 for (uint32_t j = 0; j < n; ++j)
41 {
42 char c = 'a' + (rand() % 26);
43 tmp += c;
44 }
45 n_allocated += n;
46
47 const char* s = dmStringPool::Add(pool, tmp.c_str(), tmp.length(), dmHashBufferNoReverse32(tmp.c_str(), tmp.length()));
48 strings[s] = std::string(s);
49 }
50
51 std::map<const char*, std::string>::iterator iter;
52 for (iter = strings.begin(); iter != strings.end(); ++iter)
53 {
54 const char*key = iter->first;
55 const std::string& value = iter->second;
56
57 ASSERT_STREQ(value.c_str(), key);
58
59 // Assert that we get the same pointer back
60 ASSERT_EQ((uintptr_t) key, (uintptr_t) dmStringPool::Add(pool, key, strlen(key), dmHashBufferNoReverse32(key, strlen(key))));
61 ASSERT_EQ((uintptr_t) key, (uintptr_t) dmStringPool::Add(pool, value.c_str(), value.length(), dmHashBufferNoReverse32(value.c_str(), value.length())));
62 }
63
64 // Assert that at least 5 pages are allocated in string-pool
65 ASSERT_GE(n_allocated, 5U * 4096U);
66
67 dmStringPool::Delete(pool);
68}
69
70
71int main(int argc, char **argv)

Callers

nothing calls this directly

Calls 8

randClass · 0.85
dmHashBufferNoReverse32Function · 0.85
NewFunction · 0.50
AddFunction · 0.50
DeleteFunction · 0.50
lengthMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected