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

Function TEST

engine/dlib/src/test/test_poolallocator.cpp:23–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include "../dlib/poolallocator.h"
22
23TEST(dmPoolAllocator, Test)
24{
25 for (uint32_t page_size = 16; page_size < 1024; page_size += 17)
26 {
27 dmPoolAllocator::HPool pool = dmPoolAllocator::New(page_size);
28 std::map<void*, char> pointer_to_char;
29 std::map<void*, uint32_t> pointer_to_size;
30
31 for (uint32_t i = 0; i < 100; ++i)
32 {
33 uint32_t size = rand() % (page_size + 1);
34 char* buffer = (char*) dmPoolAllocator::Alloc(pool, size);
35 ASSERT_NE((char*) 0, buffer);
36 char c = rand() % 255;
37 pointer_to_char[(void*) buffer] = c;
38 pointer_to_size[(void*) buffer] = size;
39 for (int j = 0; j < (int) size; ++j)
40 {
41 int val = (c + j) % 255;
42 val = c;
43 buffer[j] = (char) val;
44 }
45 }
46
47 std::map<void*, char>::iterator iter = pointer_to_char.begin();
48 while (iter != pointer_to_char.end())
49 {
50 uint32_t size = pointer_to_size[iter->first];
51
52 char c = iter->second;
53 char* buffer = (char*) iter->first;
54 for (int j = 0; j < (int) size; ++j)
55 {
56 int val = (c + j) % 255;
57 val = c;
58 ASSERT_EQ((int) val, (int) buffer[j]);
59 }
60
61 ++iter;
62 }
63
64 dmPoolAllocator::Delete(pool);
65 }
66}
67
68int main(int argc, char **argv)
69{

Callers

nothing calls this directly

Calls 6

randClass · 0.85
NewFunction · 0.50
AllocFunction · 0.50
DeleteFunction · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected