| 76 | namespace crown |
| 77 | { |
| 78 | static void test_memory() |
| 79 | { |
| 80 | memory_globals::init(); |
| 81 | Allocator &a = default_allocator(); |
| 82 | { |
| 83 | void *p = a.allocate(32); |
| 84 | ENSURE(a.allocated_size(p) >= 32); |
| 85 | a.deallocate(p); |
| 86 | } |
| 87 | { |
| 88 | char A[100]; |
| 89 | char B[countof(A)]; |
| 90 | memset(A, 'A', countof(A)); |
| 91 | memset(B, 'B', countof(B)); |
| 92 | |
| 93 | for (int align = 1; align <= 16; align *= 2) { |
| 94 | for (size_t bs = sizeof(void *); bs < countof(A); ++bs) { |
| 95 | PoolAllocator pool(a, 2, (u32)bs, (u32)align); |
| 96 | char *a = (char *)pool.allocate((u32)bs, (u32)align); |
| 97 | char *b = (char *)pool.allocate((u32)bs, (u32)align); |
| 98 | memset(a, 'A', bs); |
| 99 | memset(b, 'B', bs); |
| 100 | |
| 101 | ENSURE(memcmp(a, A, bs) == 0); |
| 102 | ENSURE(memcmp(b, B, bs) == 0); |
| 103 | memset(a, 0, bs); |
| 104 | memset(b, 0, bs); |
| 105 | |
| 106 | pool.deallocate(a); |
| 107 | pool.deallocate(b); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | { |
| 112 | void *p = a.reallocate(NULL, 64, 0); |
| 113 | ENSURE(p != NULL); |
| 114 | ENSURE(a.reallocate(NULL, 0) == NULL); |
| 115 | ENSURE(a.reallocate(p, 0) == NULL); |
| 116 | } |
| 117 | { |
| 118 | TempAllocator64 ta(a); |
| 119 | void *p = ta.allocate(16); |
| 120 | ENSURE(p != NULL); |
| 121 | } |
| 122 | memory_globals::shutdown(); |
| 123 | } |
| 124 | |
| 125 | static void test_array() |
| 126 | { |
nothing calls this directly
no test coverage detected