12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "tests/UniquePointerTests.h"
- #include "tests/Test.h"
- #include "utils/UniquePointer.h"
- #include "utils/Utility.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 = Core::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();
- }
|