UniquePointerTests.cpp 971 B

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