Changeset 10744 for code/branches/cpp11_v2/test/util/SharedPtrTest.cc
- Timestamp:
- Nov 1, 2015, 9:03:05 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/test/util/SharedPtrTest.cc
r9114 r10744 1 #include <utility> 1 2 #include <gtest/gtest.h> 2 3 #include <gmock/gmock.h> … … 27 28 }; 28 29 29 class TestC lassMock : public TestClass30 class TestChildClassMock : public TestChildClass 30 31 { 31 32 public: 32 TestC lassMock() {}33 ~TestC lassMock() { objectDestroyed(); }33 TestChildClassMock() {} 34 ~TestChildClassMock() { objectDestroyed(); } 34 35 35 36 MOCK_METHOD0(objectDestroyed, void()); … … 49 50 SharedPtr<TestClass> test = pointer; 50 51 EXPECT_EQ(pointer, test.get()); 52 EXPECT_EQ(pointer, &(*test)); 51 53 } 52 54 … … 165 167 TEST(SharedPtr, ObjectDestroyedOnePointer) 166 168 { 167 TestC lassMock* pointer = new TestClassMock();169 TestChildClassMock* pointer = new TestChildClassMock(); 168 170 SharedPtr<TestClass> test = pointer; 169 171 … … 173 175 TEST(SharedPtr, ObjectDestroyedManyPointers) 174 176 { 175 TestC lassMock* pointer = new TestClassMock();177 TestChildClassMock* pointer = new TestChildClassMock(); 176 178 177 179 SharedPtr<TestClass> test = pointer; … … 182 184 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); 183 185 } 186 187 TEST(SharedPtr, TestConstructors) 188 { 189 { 190 TestChildClassMock* pointer = new TestChildClassMock(); 191 192 // default 193 SharedPtr<TestChildClass> sharedPtr1; 194 EXPECT_EQ(NULL, sharedPtr1.get()); 195 196 // pointer 197 SharedPtr<TestChildClass> sharedPtr2(pointer); 198 EXPECT_EQ(pointer, sharedPtr2.get()); 199 200 // copy 201 SharedPtr<TestChildClass> sharedPtr3(sharedPtr2); 202 EXPECT_EQ(pointer, sharedPtr3.get()); 203 204 // move 205 SharedPtr<TestChildClass> sharedPtr4(std::move(sharedPtr3)); 206 EXPECT_EQ(pointer, sharedPtr4.get()); 207 208 // other 209 SharedPtr<TestClass> sharedPtr5(sharedPtr4); 210 EXPECT_EQ(pointer, sharedPtr5.get()); 211 212 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); 213 } 214 } 215 216 TEST(SharedPtr, TestConstructors2) 217 { 218 { 219 TestChildClassMock* pointer = new TestChildClassMock(); 220 221 // default 222 SharedPtr<TestChildClass> sharedPtr1; 223 EXPECT_EQ(NULL, sharedPtr1.get()); 224 225 // pointer 226 SharedPtr<TestChildClass> sharedPtr2 = pointer; 227 EXPECT_EQ(pointer, sharedPtr2.get()); 228 229 // copy 230 SharedPtr<TestChildClass> sharedPtr3 = sharedPtr2; 231 EXPECT_EQ(pointer, sharedPtr3.get()); 232 233 // move 234 SharedPtr<TestChildClass> sharedPtr4 = std::move(sharedPtr3); 235 EXPECT_EQ(pointer, sharedPtr4.get()); 236 237 // other 238 SharedPtr<TestClass> sharedPtr5 = sharedPtr4; 239 EXPECT_EQ(pointer, sharedPtr5.get()); 240 241 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); 242 } 243 } 244 245 TEST(SharedPtr, TestAssignments) 246 { 247 TestChildClassMock* pointer = new TestChildClassMock(); 248 249 SharedPtr<TestChildClass> sharedPtr1(pointer); 250 EXPECT_EQ(pointer, sharedPtr1.get()); 251 252 // copy 253 SharedPtr<TestChildClass> sharedPtr2; 254 sharedPtr2 = sharedPtr1; 255 EXPECT_EQ(pointer, sharedPtr2.get()); 256 257 // move 258 SharedPtr<TestChildClass> sharedPtr3; 259 sharedPtr3 = std::move(sharedPtr2); 260 EXPECT_EQ(pointer, sharedPtr3.get()); 261 262 // other 263 SharedPtr<TestClass> sharedPtr4; 264 sharedPtr4 = sharedPtr3; 265 EXPECT_EQ(pointer, sharedPtr4.get()); 266 267 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); 268 } 184 269 }
Note: See TracChangeset
for help on using the changeset viewer.