12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include "../Tests.hpp"
- #include "core/Test.hpp"
- #include "core/UniquePointer.hpp"
- struct B final {
- static int instances;
- bool b = false;
- B() {
- instances++;
- }
- ~B() {
- instances--;
- }
- void test() {
- b = true;
- }
- };
- int B::instances = 0;
- template class Core::UniquePointer<B>;
- using UniqueB = Core::UniquePointer<B>;
- static void testDestroy() {
- {
- UniqueB p(new B());
- TEST(1, B::instances);
- }
- TEST(0, B::instances);
- }
- static void testMoveConstructDestroys() {
- UniqueB p1(new B());
- TEST(1, B::instances);
- UniqueB p2(Core::move(p1));
- TEST(1, B::instances);
- p2 = nullptr;
- TEST(0, B::instances);
- }
- static void testMoveDestroys() {
- {
- UniqueB p1(new B());
- UniqueB p2(new B());
- TEST(2, B::instances);
- p1 = Core::move(p2);
- TEST(1, B::instances);
- }
- TEST(0, B::instances);
- }
- static void testEmpty() {
- UniqueB p;
- TEST_TRUE(p == nullptr);
- TEST_TRUE(static_cast<const UniqueB&>(p) == nullptr);
- }
- static void testCall() {
- UniqueB p(new B());
- TEST_FALSE(p->b);
- p->test();
- TEST_TRUE(p->b);
- TEST_TRUE(static_cast<const UniqueB&>(p)->b);
- }
- void testUniquePointer() {
- testDestroy();
- testMoveConstructDestroys();
- testMoveDestroys();
- testEmpty();
- testCall();
- }
|