| 171 | } |
| 172 | |
| 173 | inline void TestAlign() { |
| 174 | TMemoryPool pool(1); |
| 175 | |
| 176 | void* aligned16 = pool.Allocate(3, 16); |
| 177 | void* aligned2 = pool.Allocate(3, 2); |
| 178 | void* aligned128 = pool.Allocate(3, 128); |
| 179 | void* aligned4 = pool.Allocate(3, 4); |
| 180 | void* aligned256 = pool.Allocate(3, 256); |
| 181 | void* aligned8 = pool.Allocate(3, 8); |
| 182 | void* aligned1024 = pool.Allocate(3, 1024); |
| 183 | |
| 184 | UNIT_ASSERT_VALUES_UNEQUAL(aligned16, nullptr); |
| 185 | UNIT_ASSERT_VALUES_UNEQUAL(aligned2, nullptr); |
| 186 | UNIT_ASSERT_VALUES_UNEQUAL(aligned128, nullptr); |
| 187 | UNIT_ASSERT_VALUES_UNEQUAL(aligned4, nullptr); |
| 188 | UNIT_ASSERT_VALUES_UNEQUAL(aligned256, nullptr); |
| 189 | UNIT_ASSERT_VALUES_UNEQUAL(aligned8, nullptr); |
| 190 | UNIT_ASSERT_VALUES_UNEQUAL(aligned1024, nullptr); |
| 191 | |
| 192 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned2) & 1, 0); |
| 193 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned4) & 3, 0); |
| 194 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned8) & 7, 0); |
| 195 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned16) & 15, 0); |
| 196 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned128) & 127, 0); |
| 197 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned256) & 255, 0); |
| 198 | UNIT_ASSERT_VALUES_EQUAL(reinterpret_cast<uintptr_t>(aligned1024) & 1023, 0); |
| 199 | } |
| 200 | |
| 201 | void TestZeroArray() { |
| 202 | TMemoryPool pool(1); |