12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include "tests/UniquePointerTests.h"
- #include "memory/UniquePointer.h"
- #include "tests/Test.h"
- struct B {
- static int instances;
- B() {
- instances++;
- }
- ~B() {
- instances--;
- }
- };
- int B::instances = 0;
- static void testDestroy(Test& test) {
- {
- UniquePointer<B> p(new B());
- test.checkEqual(1, B::instances, "one instance");
- }
- test.checkEqual(0, B::instances, "instance is destroyed");
- }
- static void testMoveDestroys(Test& test) {
- {
- UniquePointer<B> p1(new B());
- UniquePointer<B> p2(new B());
- test.checkEqual(2, B::instances, "two instances");
- p1 = std::move(p2);
- test.checkEqual(1, B::instances, "one after move");
- }
- test.checkEqual(0, B::instances, "everything destroyed correctly after move");
- }
- void UniquePointerTests::test() {
- Test test("UniquePointer");
- testDestroy(test);
- testMoveDestroys(test);
- test.finalize();
- }
|