General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. #include "gp/utils/pointers.hpp"
  2. #include "gp/utils/allocators/arena.hpp"
  3. #include "test_scaffold.h"
  4. #include "allocator.hpp"
  5. #include <memory>
  6. struct arena_test : public test_scaffold {
  7. uint32_t seed;
  8. arena_test() {
  9. name = __FILE__ ":1";
  10. }
  11. virtual int run() {
  12. int return_val = 0;
  13. std::unique_ptr<gp::array<char, 4096*4>> store = std::make_unique<gp::array<char, 4096*4>>();
  14. gp::arena alloc{&*store->begin(), store->size()};
  15. auto v = gp::unique_ptr<uint64_t>::make(alloc, 1024);
  16. gp::arena alloc2{alloc, 1024};
  17. gp::arena alloc3{};
  18. {
  19. auto v2 = gp::unique_ptr<uint64_t>::make(alloc2, 1024);
  20. void* some_memory = alloc2.allocate(128);
  21. if(!some_memory) return_val++;
  22. if(alloc2.deallocate(nullptr)) return_val++;
  23. }
  24. {
  25. if(alloc3.allocate(4)) return_val++;
  26. if(alloc3.deallocate(nullptr)) return_val++;
  27. }
  28. alloc2.reset();
  29. return return_val;
  30. }
  31. };
  32. append_test dummy_8djbvs543(new arena_test{});