| 6 | namespace ValdiTest { |
| 7 | |
| 8 | TEST(AutoMalloc, doesntAllocateWhenCapacityIsLargeEnough) { |
| 9 | AutoMalloc<uint32_t, 16> storage(8); |
| 10 | |
| 11 | ASSERT_FALSE(storage.allocated()); |
| 12 | |
| 13 | ASSERT_TRUE(storage.data() != nullptr); |
| 14 | |
| 15 | for (size_t i = 0; i < 8; i++) { |
| 16 | storage.data()[i] = 42; |
| 17 | } |
| 18 | |
| 19 | for (size_t i = 0; i < 8; i++) { |
| 20 | ASSERT_EQ(static_cast<uint32_t>(42), storage.data()[i]); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | TEST(AutoMalloc, allocatesWhenCapacityIsNotLargeEnough) { |
| 25 | AutoMalloc<uint32_t, 16> storage(32); |