1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include "tests/UniquePointerTests.h"
- #include "tests/Test.h"
- #include "utils/UniquePointer.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();
- }
|