Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
allocatorstest.cpp File Reference
#include "unittest.h"
#include "rapidjson/allocators.h"
Include dependency graph for allocatorstest.cpp:

Go to the source code of this file.

Functions

template<typename Allocator >
void TestAllocator (Allocator &a)
 
 TEST (Allocator, CrtAllocator)
 
 TEST (Allocator, MemoryPoolAllocator)
 
 TEST (Allocator, Alignment)
 
 TEST (Allocator, Issue399)
 

Function Documentation

◆ TEST() [1/4]

TEST ( Allocator ,
Alignment  )

Definition at line 65 of file allocatorstest.cpp.

65 {
66 if (sizeof(size_t) >= 8) {
67 EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000000), RAPIDJSON_ALIGN(0));
68 for (uint64_t i = 1; i < 8; i++) {
69 EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008), RAPIDJSON_ALIGN(i));
70 EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000010), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008) + i));
71 EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000001, 0x00000000), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0xFFFFFFF8) + i));
72 EXPECT_EQ(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF8), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF0) + i));
73 }
74 }
75
77 for (uint32_t i = 1; i < 8; i++) {
79 EXPECT_EQ(0xFFFFFFF8u, RAPIDJSON_ALIGN(0xFFFFFFF0u + i));
80 }
81}
#define RAPIDJSON_ALIGN(x)
Data alignment of the machine.
Definition rapidjson.h:276
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:289
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136

◆ TEST() [2/4]

TEST ( Allocator ,
CrtAllocator  )

Definition at line 50 of file allocatorstest.cpp.

50 {
53}
void TestAllocator(Allocator &a)
C-runtime library allocator.
Definition allocators.h:75
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
Here is the call graph for this function:

◆ TEST() [3/4]

TEST ( Allocator ,
Issue399  )

Definition at line 83 of file allocatorstest.cpp.

83 {
85 void* p = a.Malloc(100);
86 void* q = a.Realloc(p, 100, 200);
87 EXPECT_EQ(p, q);
88
89 // exhuasive testing
90 for (size_t j = 1; j < 32; j++) {
91 a.Clear();
92 a.Malloc(j); // some unaligned size
93 p = a.Malloc(1);
94 for (size_t i = 1; i < 1024; i++) {
95 q = a.Realloc(p, i, i + 1);
96 EXPECT_EQ(p, q);
97 p = q;
98 }
99 }
100}
const mie::Vuint & p
Definition bn.cpp:27
Default memory allocator used by the parser and DOM.
Definition allocators.h:115
uint16_t j

◆ TEST() [4/4]

Definition at line 55 of file allocatorstest.cpp.

55 {
58
59 for (size_t i = 1; i < 1000; i++) {
60 EXPECT_TRUE(a.Malloc(i) != 0);
61 EXPECT_LE(a.Size(), a.Capacity());
62 }
63}
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
#define EXPECT_LE(val1, val2)
Definition gtest.h:1960
Here is the call graph for this function:

◆ TestAllocator()

template<typename Allocator >
void TestAllocator ( Allocator & a)

Definition at line 22 of file allocatorstest.cpp.

22 {
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}
const mie::Vuint & r
Definition bn.cpp:28
unsigned char uint8_t
Definition stdint.h:124
Here is the caller graph for this function: