12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #include "tests/UniquePointerTests.h"
- #include "test/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(Core::Test& test) {
- {
- Core::UniquePointer<B> p(new B());
- test.checkEqual(1, B::instances, "one instance");
- }
- test.checkEqual(0, B::instances, "instance is destroyed");
- }
- static void testMoveDestroys(Core::Test& test) {
- {
- Core::UniquePointer<B> p1(new B());
- Core::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 Core::UniquePointerTests::test() {
- Test test("UniquePointer");
- testDestroy(test);
- testMoveDestroys(test);
- test.finalize();
- }
|