Memory.cpp 833 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "tests/framework/Framework.h"
  2. #include "tests/util/Foo.h"
  3. #include "anki/util/Memory.h"
  4. #include <type_traits>
  5. ANKI_TEST(Memory, Test)
  6. {
  7. constexpr U n = 4;
  8. StackAllocator<U8, true> alloc(sizeof(Foo) * n + sizeof(PtrSize));
  9. Foo* f = ANKI_NEW(Foo, alloc, 123);
  10. ANKI_TEST_EXPECT_EQ(f->x, 123);
  11. ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(),
  12. sizeof(Foo) + sizeof(U32));
  13. ANKI_DELETE(f, alloc);
  14. ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(), 0);
  15. // Array
  16. f = ANKI_NEW_ARRAY(Foo, alloc, 2, 123);
  17. ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(),
  18. 2 * sizeof(Foo) + sizeof(U32) + sizeof(PtrSize));
  19. ANKI_TEST_EXPECT_NEQ(alloc.getMemoryPool().getAllocatedSize(), 0);
  20. ANKI_DELETE_ARRAY(f, alloc);
  21. ANKI_TEST_EXPECT_EQ(alloc.getMemoryPool().getAllocatedSize(), 0);
  22. }