Changeset 11071 for code/trunk/test/core/object
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/test/core/object/ClassFactoryTest.cc
r10624 r11071 14 14 { 15 15 public: 16 virtual void SetUp() 16 virtual void SetUp() override 17 17 { 18 18 new IdentifierManager(); 19 19 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 20 Context::setRootContext(new Context( NULL));20 Context::setRootContext(new Context(nullptr)); 21 21 } 22 22 23 virtual void TearDown() 23 virtual void TearDown() override 24 24 { 25 25 Context::destroyRootContext(); … … 33 33 { 34 34 Factory* factory = new ClassFactoryWithContext<BaseObject>(); 35 Identifiable* object = factory->fabricate( NULL);36 ASSERT_TRUE(object != NULL);35 Identifiable* object = factory->fabricate(nullptr); 36 ASSERT_TRUE(object != nullptr); 37 37 BaseObject* baseObject = dynamic_cast<BaseObject*>(object); 38 EXPECT_TRUE(baseObject != NULL);38 EXPECT_TRUE(baseObject != nullptr); 39 39 delete object; 40 40 // don't delete factory - it remains in the identifier -
code/trunk/test/core/object/ContextTest.cc
r10624 r11071 12 12 { 13 13 public: 14 SubclassContext() : Context( NULL) { RegisterObject(SubclassContext); }14 SubclassContext() : Context(nullptr) { RegisterObject(SubclassContext); } 15 15 }; 16 16 … … 21 21 { 22 22 public: 23 virtual void SetUp() 23 virtual void SetUp() override 24 24 { 25 25 new IdentifierManager(); 26 26 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 27 Context::setRootContext(new Context( NULL));27 Context::setRootContext(new Context(nullptr)); 28 28 } 29 29 30 virtual void TearDown() 30 virtual void TearDown() override 31 31 { 32 32 Context::destroyRootContext(); … … 39 39 TEST_F(ContextTest, CanCreateContext) 40 40 { 41 Context context( NULL);41 Context context(nullptr); 42 42 } 43 43 … … 49 49 TEST_F(ContextTest, ContextIsItsOwnContext) 50 50 { 51 Context context( NULL);51 Context context(nullptr); 52 52 EXPECT_EQ(&context, context.getContext()); 53 53 } … … 68 68 TEST_F(ContextTest, ContextIsAddedToItsOwnObjectList) 69 69 { 70 Context context( NULL);70 Context context(nullptr); 71 71 ASSERT_EQ(1u, context.getObjectList<Context>()->size()); 72 72 EXPECT_TRUE(context.getObjectList<Context>()->begin()->objectBase_ == static_cast<Listable*>(&context)); … … 75 75 TEST_F(ContextTest, ContextIsAddedToObjectListOfBaseContext) 76 76 { 77 Context baseContext( NULL);77 Context baseContext(nullptr); 78 78 Context subContext(&baseContext); 79 79 -
code/trunk/test/core/object/DestroyableTest.cc
r9603 r11071 32 32 DestroyableTest* test = new DestroyableTest(destroyed); 33 33 EXPECT_FALSE(destroyed); 34 EXPECT_TRUE(test != NULL);34 EXPECT_TRUE(test != nullptr); 35 35 test->destroy(); 36 36 EXPECT_TRUE(destroyed); -
code/trunk/test/core/object/IteratorTest.cc
r10624 r11071 15 15 { 16 16 public: 17 TestInterface() { RegisterObject(TestInterface); }17 TestInterface() { RegisterObject(TestInterface); } 18 18 }; 19 19 … … 32 32 { 33 33 public: 34 virtual void SetUp() 34 virtual void SetUp() override 35 35 { 36 36 new IdentifierManager(); 37 37 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 38 Context::setRootContext(new Context( NULL));38 Context::setRootContext(new Context(nullptr)); 39 39 } 40 40 41 virtual void TearDown() 41 virtual void TearDown() override 42 42 { 43 43 Context::destroyRootContext(); … … 55 55 TEST_F(IteratorTest, CanAssignIterator) 56 56 { 57 Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); 57 ObjectList<TestInterface> list; 58 Iterator<TestInterface> it = list.begin(); 58 59 } 59 60 … … 61 62 { 62 63 size_t i = 0; 63 for (Iterator<TestInterface> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) 64 ObjectList<TestInterface> list; 65 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it) 64 66 ++i; 65 67 EXPECT_EQ(0u, i); … … 77 79 78 80 // iterate over interfaces but use a TestClass iterator - now we can call TestClass::test() 79 for (Iterator<TestClass> it = ObjectList<TestInterface>::begin(); it != ObjectList<TestInterface>::end(); ++it) 81 ObjectList<TestInterface> list; 82 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it) 80 83 it->test(); 81 84 } 85 86 TEST_F(IteratorTest, CanIterateOverInterfaceListWithInterfaceIterator) 87 { 88 TestClass testClass; 89 TestInterface testInterface; 90 91 size_t i = 0; 92 ObjectList<TestInterface> list; 93 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it) 94 { 95 ++i; 96 if (i == 1u) EXPECT_EQ(&testClass, *it); 97 if (i == 2u) EXPECT_EQ(&testInterface, *it); 98 } 99 EXPECT_EQ(2u, i); 100 } 101 102 TEST_F(IteratorTest, CanIterateOverClassListWithClassIterator) 103 { 104 TestClass testClass; 105 TestInterface testInterface; 106 107 size_t i = 0; 108 ObjectList<TestClass> list; 109 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it) 110 { 111 ++i; 112 if (i == 1u) EXPECT_EQ(&testClass, *it); 113 } 114 EXPECT_EQ(1u, i); 115 } 116 117 TEST_F(IteratorTest, CanIterateOverInterfaceListWithClassIterator) 118 { 119 TestClass testClass; 120 TestInterface testInterface; 121 122 size_t i = 0; 123 ObjectList<TestInterface> list; 124 for (Iterator<TestClass> it = list.begin(); it != list.end(); ++it) 125 { 126 ++i; 127 if (i == 1u) EXPECT_EQ(&testClass, *it); 128 if (i == 2u) EXPECT_EQ(nullptr, *it); 129 } 130 EXPECT_EQ(2u, i); 131 } 132 133 TEST_F(IteratorTest, CanIterateOverClassListWithInterfaceIterator) 134 { 135 TestClass testClass; 136 TestInterface testInterface; 137 138 size_t i = 0; 139 ObjectList<TestClass> list; 140 for (Iterator<TestInterface> it = list.begin(); it != list.end(); ++it) 141 { 142 ++i; 143 if (i == 1u) EXPECT_EQ(&testClass, *it); 144 } 145 EXPECT_EQ(1u, i); 146 } 82 147 } -
code/trunk/test/core/object/ListableTest.cc
r10624 r11071 37 37 { 38 38 public: 39 virtual void SetUp() 39 virtual void SetUp() override 40 40 { 41 41 new IdentifierManager(); 42 42 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 43 Context::setRootContext(new Context( NULL));43 Context::setRootContext(new Context(nullptr)); 44 44 } 45 45 46 virtual void TearDown() 46 virtual void TearDown() override 47 47 { 48 48 Context::destroyRootContext(); … … 56 56 { 57 57 ListableClassTest* test = new ListableClassTest(); 58 ASSERT_TRUE(test != NULL);58 ASSERT_TRUE(test != nullptr); 59 59 delete test; 60 60 } … … 63 63 { 64 64 ListableClassTest test; 65 EXPECT_EQ(1u, ObjectList<ListableClassTest> ::size());65 EXPECT_EQ(1u, ObjectList<ListableClassTest>().size()); 66 66 EXPECT_TRUE(objectListContains<ListableClassTest>(&test)); 67 67 } … … 70 70 { 71 71 ListableSubclassTest test; 72 EXPECT_EQ(1u, ObjectList<ListableClassTest> ::size());72 EXPECT_EQ(1u, ObjectList<ListableClassTest>().size()); 73 73 EXPECT_TRUE(objectListContains<ListableClassTest>(&test)); 74 EXPECT_EQ(1u, ObjectList<ListableSubclassTest> ::size());74 EXPECT_EQ(1u, ObjectList<ListableSubclassTest>().size()); 75 75 EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test)); 76 76 } … … 78 78 TEST_F(ListableTest, RemovesFromObjectList) 79 79 { 80 EXPECT_EQ(0u, ObjectList<ListableClassTest> ::size());80 EXPECT_EQ(0u, ObjectList<ListableClassTest>().size()); 81 81 { 82 82 ListableClassTest test; 83 EXPECT_EQ(1u, ObjectList<ListableClassTest> ::size());83 EXPECT_EQ(1u, ObjectList<ListableClassTest>().size()); 84 84 EXPECT_TRUE(objectListContains<ListableClassTest>(&test)); 85 85 } 86 EXPECT_EQ(0u, ObjectList<ListableClassTest> ::size());86 EXPECT_EQ(0u, ObjectList<ListableClassTest>().size()); 87 87 } 88 88 89 89 TEST_F(ListableTest, RemovesFromAllObjectLists) 90 90 { 91 EXPECT_EQ(0u, ObjectList<ListableClassTest> ::size());92 EXPECT_EQ(0u, ObjectList<ListableSubclassTest> ::size());91 EXPECT_EQ(0u, ObjectList<ListableClassTest>().size()); 92 EXPECT_EQ(0u, ObjectList<ListableSubclassTest>().size()); 93 93 { 94 94 ListableSubclassTest test; 95 EXPECT_EQ(1u, ObjectList<ListableClassTest> ::size());95 EXPECT_EQ(1u, ObjectList<ListableClassTest>().size()); 96 96 EXPECT_TRUE(objectListContains<ListableClassTest>(&test)); 97 EXPECT_EQ(1u, ObjectList<ListableSubclassTest> ::size());97 EXPECT_EQ(1u, ObjectList<ListableSubclassTest>().size()); 98 98 EXPECT_TRUE(objectListContains<ListableSubclassTest>(&test)); 99 99 } 100 EXPECT_EQ(0u, ObjectList<ListableClassTest> ::size());101 EXPECT_EQ(0u, ObjectList<ListableSubclassTest> ::size());100 EXPECT_EQ(0u, ObjectList<ListableClassTest>().size()); 101 EXPECT_EQ(0u, ObjectList<ListableSubclassTest>().size()); 102 102 } 103 103 104 104 TEST_F(ListableTest, CanAddObjectToContext) 105 105 { 106 Context context( NULL);106 Context context(nullptr); 107 107 ListableSubclassTest test; 108 108 … … 118 118 TEST_F(ListableTest, CanAddObjectToSubContext) 119 119 { 120 Context baseContext( NULL);120 Context baseContext(nullptr); 121 121 Context subContext(&baseContext); 122 122 ListableSubclassTest test; … … 139 139 { 140 140 Context* rootContext = Context::getRootContext(); 141 Context newContext( NULL);141 Context newContext(nullptr); 142 142 ListableSubclassTest test; 143 143 -
code/trunk/test/core/object/ObjectListBaseTest.cc
r9661 r11071 24 24 { 25 25 ObjectListBase list; 26 ObjectListBaseElement* element = new ObjectListElement<Listable>( NULL);26 ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); 27 27 list.addElement(element); 28 28 EXPECT_EQ(1u, list.size()); … … 32 32 { 33 33 ObjectListBase list; 34 ObjectListBaseElement* element = new ObjectListElement<Listable>( NULL);34 ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); 35 35 list.addElement(element); 36 36 EXPECT_EQ(1u, list.size()); … … 43 43 { 44 44 ObjectListBase list; 45 list.addElement(new ObjectListElement<Listable>( NULL));45 list.addElement(new ObjectListElement<Listable>(nullptr)); 46 46 EXPECT_EQ(1u, list.size()); 47 47 } … … 52 52 EXPECT_EQ(0u, list.size()); 53 53 { 54 ObjectListElement<Listable> element1( NULL);54 ObjectListElement<Listable> element1(nullptr); 55 55 list.addElement(&element1); 56 56 EXPECT_EQ(1u, list.size()); 57 57 { 58 ObjectListElement<Listable> element1( NULL);58 ObjectListElement<Listable> element1(nullptr); 59 59 list.addElement(&element1); 60 60 EXPECT_EQ(2u, list.size()); 61 61 { 62 ObjectListElement<Listable> element1( NULL);62 ObjectListElement<Listable> element1(nullptr); 63 63 list.addElement(&element1); 64 64 EXPECT_EQ(3u, list.size()); … … 76 76 ObjectListElementRemovalListenerMock listener; 77 77 list.registerRemovalListener(&listener); 78 ObjectListBaseElement* element = new ObjectListElement<Listable>( NULL);78 ObjectListBaseElement* element = new ObjectListElement<Listable>(nullptr); 79 79 list.addElement(element); 80 80 EXPECT_CALL(listener, removedElement(element)); -
code/trunk/test/core/object/ObjectListIteratorTest.cc
r10624 r11071 3 3 4 4 #include "core/object/ObjectListIterator.h" 5 #include "core/object/Listable.h" 5 #include "core/class/OrxonoxClass.h" 6 #include "core/class/OrxonoxInterface.h" 6 7 #include "core/CoreIncludes.h" 7 8 #include "core/module/ModuleInstance.h" … … 11 12 namespace 12 13 { 13 class ListableTest : public Listable14 class TestInterface : virtual public OrxonoxInterface 14 15 { 15 16 public: 16 ListableTest() { RegisterObject(ListableTest); } 17 TestInterface() { RegisterObject(TestInterface); } 18 }; 19 20 class TestClass : public OrxonoxClass, public TestInterface 21 { 22 public: 23 TestClass() { RegisterObject(TestClass); } 17 24 MOCK_METHOD0(test, void()); 18 25 }; 19 26 20 RegisterClassNoArgs(ListableTest); 27 RegisterClassNoArgs(TestInterface); 28 RegisterClassNoArgs(TestClass); 21 29 22 30 // Fixture … … 24 32 { 25 33 public: 26 virtual void SetUp() 34 virtual void SetUp() override 27 35 { 28 36 new IdentifierManager(); 29 37 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER); 30 Context::setRootContext(new Context( NULL));38 Context::setRootContext(new Context(nullptr)); 31 39 } 32 40 33 virtual void TearDown() 41 virtual void TearDown() override 34 42 { 35 43 Context::destroyRootContext(); … … 42 50 TEST_F(ObjectListIteratorTest, CanCreateIterator) 43 51 { 44 ObjectListIterator< ListableTest> it;52 ObjectListIterator<TestClass> it; 45 53 } 46 54 47 55 TEST_F(ObjectListIteratorTest, CanAssignIterator) 48 56 { 49 ObjectListIterator<ListableTest> it = ObjectList<ListableTest>::begin(); 57 ObjectList<TestClass> list; 58 ObjectListIterator<TestClass> it = list.begin(); 50 59 } 51 60 … … 53 62 { 54 63 size_t i = 0; 55 for (ObjectListIterator<ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it) 64 ObjectList<TestClass> list; 65 for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it) 56 66 ++i; 57 67 EXPECT_EQ(0u, i); … … 60 70 TEST_F(ObjectListIteratorTest, CanIterateOverFullList) 61 71 { 62 ListableTest test1; 63 ListableTest test2; 64 ListableTest test3; 72 TestClass test1; 73 TestClass test2; 74 TestClass test3; 75 TestInterface interface; 65 76 66 77 size_t i = 0; 67 for (ObjectListIterator<ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it) 78 ObjectList<TestClass> list; 79 for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it) 68 80 { 69 81 ++i; … … 77 89 TEST_F(ObjectListIteratorTest, CanIterateReverseOverFullList) 78 90 { 79 ListableTest test1; 80 ListableTest test2; 81 ListableTest test3; 91 TestClass test1; 92 TestClass test2; 93 TestClass test3; 94 TestInterface interface; 82 95 83 96 size_t i = 0; 84 for (ObjectListIterator<ListableTest> it = ObjectList<ListableTest>::rbegin(); it != ObjectList<ListableTest>::rend(); --it) 97 ObjectList<TestClass> list; 98 for (ObjectListIterator<TestClass> it = list.rbegin(); it != list.rend(); --it) 85 99 { 86 100 ++i; … … 94 108 TEST_F(ObjectListIteratorTest, CanCallObjects) 95 109 { 96 ListableTest test1; 97 ListableTest test2; 98 ListableTest test3; 110 TestClass test1; 111 TestClass test2; 112 TestClass test3; 113 TestInterface interface; 99 114 100 115 EXPECT_CALL(test1, test()); … … 102 117 EXPECT_CALL(test3, test()); 103 118 104 for (ObjectListIterator<ListableTest> it = ObjectList<ListableTest>::begin(); it != ObjectList<ListableTest>::end(); ++it) 119 ObjectList<TestClass> list; 120 for (ObjectListIterator<TestClass> it = list.begin(); it != list.end(); ++it) 105 121 it->test(); 106 122 } -
code/trunk/test/core/object/StrongPtrTest.cc
r10624 r11071 1 #include <utility> 1 2 #include <gtest/gtest.h> 2 3 #include "core/object/StrongPtr.h" … … 23 24 StrongPtr<DestroyableTest> strongPtr = test; 24 25 EXPECT_EQ(test, strongPtr.get()); 26 EXPECT_EQ(test, &(*strongPtr)); 27 EXPECT_EQ(static_cast<Destroyable*>(test), strongPtr.getBase()); 28 test->destroy(); 29 } 30 31 TEST(StrongPtrTest, CanHaveMultiplePointers) 32 { 33 bool bla; 34 DestroyableTest* test = new DestroyableTest(bla); 35 StrongPtr<DestroyableTest> strongPtr1 = test; 36 StrongPtr<DestroyableTest> strongPtr2 = test; 37 StrongPtr<DestroyableTest> strongPtr3 = test; 38 EXPECT_EQ(test, strongPtr1.get()); 39 EXPECT_EQ(test, strongPtr2.get()); 40 EXPECT_EQ(test, strongPtr3.get()); 41 EXPECT_EQ(3u, test->getReferenceCount()); 25 42 test->destroy(); 26 43 } … … 94 111 void isNull(const StrongPtr<DestroyableTest> strongPtr) 95 112 { 96 EXPECT_TRUE(strongPtr == NULL);97 EXPECT_TRUE(strongPtr == 0);113 EXPECT_TRUE(strongPtr == nullptr); 114 EXPECT_TRUE(strongPtr == nullptr); 98 115 EXPECT_TRUE(!strongPtr); 99 EXPECT_FALSE(strongPtr != NULL);100 EXPECT_FALSE(strongPtr != 0);116 EXPECT_FALSE(strongPtr != nullptr); 117 EXPECT_FALSE(strongPtr != nullptr); 101 118 EXPECT_FALSE(strongPtr); 102 119 } … … 109 126 } 110 127 { 111 StrongPtr<DestroyableTest> strongPtr = NULL;128 StrongPtr<DestroyableTest> strongPtr = nullptr; 112 129 isNull(strongPtr); 113 130 } 114 131 { 115 132 StrongPtr<DestroyableTest> strongPtr; 116 strongPtr = NULL;117 isNull(strongPtr); 118 } 119 { 120 StrongPtr<DestroyableTest> strongPtr = 0;133 strongPtr = nullptr; 134 isNull(strongPtr); 135 } 136 { 137 StrongPtr<DestroyableTest> strongPtr = nullptr; 121 138 isNull(strongPtr); 122 139 } 123 140 { 124 141 StrongPtr<DestroyableTest> strongPtr; 125 strongPtr = 0;142 strongPtr = nullptr; 126 143 isNull(strongPtr); 127 144 } … … 133 150 DestroyableTest* test = new DestroyableTest(destroyed); 134 151 StrongPtr<DestroyableTest> strongPtr = test; 135 EXPECT_FALSE(strongPtr == NULL);136 EXPECT_FALSE(strongPtr == 0);152 EXPECT_FALSE(strongPtr == nullptr); 153 EXPECT_FALSE(strongPtr == nullptr); 137 154 EXPECT_FALSE(!strongPtr); 138 EXPECT_TRUE(strongPtr != NULL);139 EXPECT_TRUE(strongPtr != 0);155 EXPECT_TRUE(strongPtr != nullptr); 156 EXPECT_TRUE(strongPtr != nullptr); 140 157 EXPECT_TRUE(strongPtr); 141 158 test->destroy(); 142 159 } 160 161 TEST(StrongPtrTest, TestConstructors) 162 { 163 bool bla; 164 DestroyableTest* test = new DestroyableTest(bla); 165 166 // default 167 StrongPtr<DestroyableTest> strongPtr1; 168 EXPECT_EQ(nullptr, strongPtr1.get()); 169 170 // pointer 171 StrongPtr<DestroyableTest> strongPtr2a = test; 172 StrongPtr<DestroyableTest> strongPtr2b(test); 173 EXPECT_EQ(test, strongPtr2a.get()); 174 EXPECT_EQ(test, strongPtr2b.get()); 175 176 // copy 177 StrongPtr<DestroyableTest> strongPtr3a = strongPtr2a; 178 StrongPtr<DestroyableTest> strongPtr3b(strongPtr2b); 179 EXPECT_EQ(test, strongPtr3a.get()); 180 EXPECT_EQ(test, strongPtr3b.get()); 181 182 // move 183 StrongPtr<DestroyableTest> strongPtr4a = std::move(strongPtr3a); 184 StrongPtr<DestroyableTest> strongPtr4b(std::move(strongPtr3b)); 185 EXPECT_EQ(test, strongPtr4a.get()); 186 EXPECT_EQ(test, strongPtr4b.get()); 187 188 // other 189 StrongPtr<Destroyable> strongPtr5a = strongPtr4a; 190 StrongPtr<Destroyable> strongPtr5b(strongPtr4b); 191 EXPECT_EQ(test, strongPtr5a.get()); 192 EXPECT_EQ(test, strongPtr5b.get()); 193 194 // weakPtr 195 WeakPtr<DestroyableTest> weakPtr = test; 196 StrongPtr<DestroyableTest> strongPtr6a = weakPtr; 197 StrongPtr<DestroyableTest> strongPtr6b(weakPtr); 198 EXPECT_EQ(test, strongPtr6a.get()); 199 EXPECT_EQ(test, strongPtr6b.get()); 200 201 // weakPtr other 202 StrongPtr<Destroyable> strongPtr7a = weakPtr; 203 StrongPtr<Destroyable> strongPtr7b(weakPtr); 204 EXPECT_EQ(test, strongPtr7a.get()); 205 EXPECT_EQ(test, strongPtr7b.get()); 206 207 test->destroy(); 208 } 209 210 TEST(StrongPtrTest, TestAssignments) 211 { 212 bool bla; 213 DestroyableTest* test = new DestroyableTest(bla); 214 215 // pointer 216 StrongPtr<DestroyableTest> strongPtr1; 217 strongPtr1 = test; 218 EXPECT_EQ(test, strongPtr1.get()); 219 220 // copy 221 StrongPtr<DestroyableTest> strongPtr2; 222 strongPtr2 = strongPtr1; 223 EXPECT_EQ(test, strongPtr2.get()); 224 225 // move 226 StrongPtr<DestroyableTest> strongPtr3; 227 strongPtr3 = std::move(strongPtr2); 228 EXPECT_EQ(test, strongPtr3.get()); 229 230 // other 231 StrongPtr<Destroyable> strongPtr4; 232 strongPtr4 = strongPtr3; 233 EXPECT_EQ(test, strongPtr4.get()); 234 235 // weakPtr 236 WeakPtr<DestroyableTest> weakPtr = test; 237 StrongPtr<DestroyableTest> strongPtr5; 238 strongPtr5 = weakPtr; 239 EXPECT_EQ(test, strongPtr5.get()); 240 241 // weakPtr other 242 StrongPtr<Destroyable> strongPtr6; 243 strongPtr6 = weakPtr; 244 EXPECT_EQ(test, strongPtr6.get()); 245 246 test->destroy(); 247 } 248 249 TEST(StrongPtrTest, TestStrongPtrInVector) 250 { 251 bool bla; 252 DestroyableTest* test = new DestroyableTest(bla); 253 254 std::vector<StrongPtr<DestroyableTest>> vector; 255 vector.push_back(test); 256 vector.push_back(test); 257 vector.push_back(test); 258 259 ASSERT_EQ(3, vector.size()); 260 EXPECT_EQ(test, vector[0].get()); 261 EXPECT_EQ(test, vector[1].get()); 262 EXPECT_EQ(test, vector[2].get()); 263 EXPECT_EQ(3u, test->getReferenceCount()); 264 265 vector.clear(); 266 EXPECT_EQ(0u, test->getReferenceCount()); 267 268 test->destroy(); 269 } 270 271 TEST(StrongPtrTest, TestReset) 272 { 273 bool bla; 274 DestroyableTest* test = new DestroyableTest(bla); 275 StrongPtr<DestroyableTest> strongPtr(test); 276 EXPECT_EQ(test, strongPtr.get()); 277 EXPECT_EQ(1u, test->getReferenceCount()); 278 strongPtr.reset(); 279 EXPECT_EQ(nullptr, strongPtr.get()); 280 EXPECT_EQ(0u, test->getReferenceCount()); 281 282 test->destroy(); 283 } 284 285 TEST(StrongPtrTest, TestSwap) 286 { 287 bool bla; 288 DestroyableTest* test1 = new DestroyableTest(bla); 289 DestroyableTest* test2 = new DestroyableTest(bla); 290 291 StrongPtr<DestroyableTest> strongPtr1(test1); 292 StrongPtr<DestroyableTest> strongPtr2(test2); 293 EXPECT_EQ(test1, strongPtr1.get()); 294 EXPECT_EQ(test2, strongPtr2.get()); 295 EXPECT_EQ(1u, test1->getReferenceCount()); 296 EXPECT_EQ(1u, test2->getReferenceCount()); 297 298 strongPtr1.swap(strongPtr2); 299 300 EXPECT_EQ(test2, strongPtr1.get()); 301 EXPECT_EQ(test1, strongPtr2.get()); 302 EXPECT_EQ(1u, test1->getReferenceCount()); 303 EXPECT_EQ(1u, test2->getReferenceCount()); 304 305 test1->destroy(); 306 test2->destroy(); 307 } 143 308 } -
code/trunk/test/core/object/WeakPtrTest.cc
r10624 r11071 1 #include <utility> 1 2 #include <gtest/gtest.h> 2 3 #include <gmock/gmock.h> … … 24 25 WeakPtr<DestroyableTest> weakPtr = test; 25 26 EXPECT_EQ(test, weakPtr.get()); 27 EXPECT_EQ(test, &(*weakPtr)); 28 EXPECT_EQ(static_cast<Destroyable*>(test), weakPtr.getBase()); 26 29 test->destroy(); 27 30 } … … 33 36 EXPECT_EQ(test, weakPtr.get()); 34 37 test->destroy(); 35 EXPECT_EQ(NULL, weakPtr.get()); 38 EXPECT_EQ(nullptr, weakPtr.get()); 39 } 40 41 TEST(WeakPtrTest, CanHaveMultiplePointers) 42 { 43 DestroyableTest* test = new DestroyableTest(); 44 WeakPtr<DestroyableTest> weakPtr1 = test; 45 WeakPtr<DestroyableTest> weakPtr2 = test; 46 WeakPtr<DestroyableTest> weakPtr3 = test; 47 EXPECT_EQ(test, weakPtr1.get()); 48 EXPECT_EQ(test, weakPtr2.get()); 49 EXPECT_EQ(test, weakPtr3.get()); 50 test->destroy(); 51 EXPECT_EQ(nullptr, weakPtr1.get()); 52 EXPECT_EQ(nullptr, weakPtr2.get()); 53 EXPECT_EQ(nullptr, weakPtr3.get()); 36 54 } 37 55 … … 48 66 void isNull(const WeakPtr<DestroyableTest> weakPtr) 49 67 { 50 EXPECT_TRUE(weakPtr == NULL);51 EXPECT_TRUE(weakPtr == 0);68 EXPECT_TRUE(weakPtr == nullptr); 69 EXPECT_TRUE(weakPtr == nullptr); 52 70 EXPECT_TRUE(!weakPtr); 53 EXPECT_FALSE(weakPtr != NULL);54 EXPECT_FALSE(weakPtr != 0);71 EXPECT_FALSE(weakPtr != nullptr); 72 EXPECT_FALSE(weakPtr != nullptr); 55 73 EXPECT_FALSE(weakPtr); 56 74 } … … 63 81 } 64 82 { 65 WeakPtr<DestroyableTest> weakPtr = NULL;83 WeakPtr<DestroyableTest> weakPtr = nullptr; 66 84 isNull(weakPtr); 67 85 } 68 86 { 69 87 WeakPtr<DestroyableTest> weakPtr; 70 weakPtr = NULL;71 isNull(weakPtr); 72 } 73 { 74 WeakPtr<DestroyableTest> weakPtr = 0;88 weakPtr = nullptr; 89 isNull(weakPtr); 90 } 91 { 92 WeakPtr<DestroyableTest> weakPtr = nullptr; 75 93 isNull(weakPtr); 76 94 } 77 95 { 78 96 WeakPtr<DestroyableTest> weakPtr; 79 weakPtr = 0;97 weakPtr = nullptr; 80 98 isNull(weakPtr); 81 99 } … … 86 104 DestroyableTest* test = new DestroyableTest(); 87 105 WeakPtr<DestroyableTest> weakPtr = test; 88 EXPECT_FALSE(weakPtr == NULL);89 EXPECT_FALSE(weakPtr == 0);106 EXPECT_FALSE(weakPtr == nullptr); 107 EXPECT_FALSE(weakPtr == nullptr); 90 108 EXPECT_FALSE(!weakPtr); 91 EXPECT_TRUE(weakPtr != NULL);92 EXPECT_TRUE(weakPtr != 0);109 EXPECT_TRUE(weakPtr != nullptr); 110 EXPECT_TRUE(weakPtr != nullptr); 93 111 EXPECT_TRUE(weakPtr); 94 112 test->destroy(); 95 113 } 114 115 TEST(WeakPtrTest, TestConstructors) 116 { 117 DestroyableTest* test = new DestroyableTest(); 118 119 // default 120 WeakPtr<DestroyableTest> weakPtr1; 121 EXPECT_EQ(nullptr, weakPtr1.get()); 122 123 // pointer 124 WeakPtr<DestroyableTest> weakPtr2a = test; 125 WeakPtr<DestroyableTest> weakPtr2b(test); 126 EXPECT_EQ(test, weakPtr2a.get()); 127 EXPECT_EQ(test, weakPtr2b.get()); 128 129 // copy 130 WeakPtr<DestroyableTest> weakPtr3a = weakPtr2a; 131 WeakPtr<DestroyableTest> weakPtr3b(weakPtr2b); 132 EXPECT_EQ(test, weakPtr3a.get()); 133 EXPECT_EQ(test, weakPtr3b.get()); 134 135 // move 136 WeakPtr<DestroyableTest> weakPtr4a = std::move(weakPtr3a); 137 WeakPtr<DestroyableTest> weakPtr4b(std::move(weakPtr3b)); 138 EXPECT_EQ(test, weakPtr4a.get()); 139 EXPECT_EQ(test, weakPtr4b.get()); 140 141 // other 142 WeakPtr<Destroyable> weakPtr5a = weakPtr4a; 143 WeakPtr<Destroyable> weakPtr5b(weakPtr4b); 144 EXPECT_EQ(test, weakPtr5a.get()); 145 EXPECT_EQ(test, weakPtr5b.get()); 146 147 test->destroy(); 148 } 149 150 TEST(WeakPtrTest, TestAssignments) 151 { 152 DestroyableTest* test = new DestroyableTest(); 153 154 // pointer 155 WeakPtr<DestroyableTest> weakPtr1; 156 weakPtr1 = test; 157 EXPECT_EQ(test, weakPtr1.get()); 158 159 // copy 160 WeakPtr<DestroyableTest> weakPtr2; 161 weakPtr2 = weakPtr1; 162 EXPECT_EQ(test, weakPtr2.get()); 163 164 // move 165 WeakPtr<DestroyableTest> weakPtr3; 166 weakPtr3 = std::move(weakPtr2); 167 EXPECT_EQ(test, weakPtr3.get()); 168 169 // other 170 WeakPtr<Destroyable> weakPtr4; 171 weakPtr4 = weakPtr3; 172 EXPECT_EQ(test, weakPtr4.get()); 173 174 test->destroy(); 175 } 176 177 TEST(WeakPtrTest, TestWeakPtrInVector) 178 { 179 DestroyableTest* test = new DestroyableTest(); 180 181 std::vector<WeakPtr<DestroyableTest>> vector; 182 vector.push_back(test); 183 vector.push_back(test); 184 vector.push_back(test); 185 186 ASSERT_EQ(3, vector.size()); 187 EXPECT_EQ(test, vector[0].get()); 188 EXPECT_EQ(test, vector[1].get()); 189 EXPECT_EQ(test, vector[2].get()); 190 191 test->destroy(); 192 193 EXPECT_EQ(nullptr, vector[0].get()); 194 EXPECT_EQ(nullptr, vector[1].get()); 195 EXPECT_EQ(nullptr, vector[2].get()); 196 } 197 198 TEST(WeakPtrTest, TestReset) 199 { 200 DestroyableTest* test = new DestroyableTest(); 201 WeakPtr<DestroyableTest> weakPtr(test); 202 EXPECT_EQ(test, weakPtr.get()); 203 weakPtr.reset(); 204 EXPECT_EQ(nullptr, weakPtr.get()); 205 206 test->destroy(); 207 } 208 209 TEST(WeakPtrTest, TestSwap) 210 { 211 DestroyableTest* test1 = new DestroyableTest(); 212 DestroyableTest* test2 = new DestroyableTest(); 213 214 WeakPtr<DestroyableTest> weakPtr1(test1); 215 WeakPtr<DestroyableTest> weakPtr2(test2); 216 EXPECT_EQ(test1, weakPtr1.get()); 217 EXPECT_EQ(test2, weakPtr2.get()); 218 219 weakPtr1.swap(weakPtr2); 220 221 EXPECT_EQ(test2, weakPtr1.get()); 222 EXPECT_EQ(test1, weakPtr2.get()); 223 224 test1->destroy(); 225 test2->destroy(); 226 } 96 227 }
Note: See TracChangeset
for help on using the changeset viewer.