UniquePointerTests.cpp 1000 B

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