MCPcopy Create free account
hub / github.com/Tencent/rapidjson / TestAllocator

Function TestAllocator

test/unittest/allocatorstest.cpp:22–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21template <typename Allocator>
22void TestAllocator(Allocator& a) {
23 EXPECT_TRUE(a.Malloc(0) == 0);
24
25 uint8_t* p = static_cast<uint8_t*>(a.Malloc(100));
26 EXPECT_TRUE(p != 0);
27 for (size_t i = 0; i < 100; i++)
28 p[i] = static_cast<uint8_t>(i);
29
30 // Expand
31 uint8_t* q = static_cast<uint8_t*>(a.Realloc(p, 100, 200));
32 EXPECT_TRUE(q != 0);
33 for (size_t i = 0; i < 100; i++)
34 EXPECT_EQ(i, q[i]);
35 for (size_t i = 100; i < 200; i++)
36 q[i] = static_cast<uint8_t>(i);
37
38 // Shrink
39 uint8_t *r = static_cast<uint8_t*>(a.Realloc(q, 200, 150));
40 EXPECT_TRUE(r != 0);
41 for (size_t i = 0; i < 150; i++)
42 EXPECT_EQ(i, r[i]);
43
44 Allocator::Free(r);
45
46 // Realloc to zero size
47 EXPECT_TRUE(a.Realloc(a.Malloc(1), 1, 0) == 0);
48}
49
50TEST(Allocator, CrtAllocator) {
51 CrtAllocator a;

Callers 1

TESTFunction · 0.85

Calls 3

FreeFunction · 0.85
MallocMethod · 0.45
ReallocMethod · 0.45

Tested by

no test coverage detected