UniquePointerTests.cpp 807 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "tests/UniquePointerTests.h"
  2. #include "test/Test.h"
  3. #include "utils/UniquePointer.h"
  4. #include "utils/Utility.h"
  5. struct B final {
  6. static int instances;
  7. B() {
  8. instances++;
  9. }
  10. ~B() {
  11. instances--;
  12. }
  13. };
  14. int B::instances = 0;
  15. static void testDestroy() {
  16. {
  17. Core::UniquePointer<B> p(new B());
  18. CORE_TEST_EQUAL(1, B::instances);
  19. }
  20. CORE_TEST_EQUAL(0, B::instances);
  21. }
  22. static void testMoveDestroys() {
  23. {
  24. Core::UniquePointer<B> p1(new B());
  25. Core::UniquePointer<B> p2(new B());
  26. CORE_TEST_EQUAL(2, B::instances);
  27. p1 = Core::move(p2);
  28. CORE_TEST_EQUAL(1, B::instances);
  29. }
  30. CORE_TEST_EQUAL(0, B::instances);
  31. }
  32. void Core::UniquePointerTests::test() {
  33. testDestroy();
  34. testMoveDestroys();
  35. }