Changeset 10830 for code/branches/cpp11_v2
- Timestamp:
- Nov 22, 2015, 5:31:51 PM (9 years ago)
- Location:
- code/branches/cpp11_v2
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/util/CMakeLists.txt
r10624 r10830 26 26 CRC32.cc 27 27 ExprParser.cc 28 SharedPtr.cc29 28 Sleep.cc 30 29 SmallObjectAllocator.cc -
code/branches/cpp11_v2/src/libraries/util/UtilPrereqs.h
r10624 r10830 80 80 class OutputStream; 81 81 class ScopeListener; 82 template <class T>83 class SharedPtr;84 82 class SignalHandler; 85 83 template <class T> -
code/branches/cpp11_v2/test/util/SharedPtrTest.cc
r10770 r10830 1 #include <memory> 1 2 #include <utility> 2 3 #include <gtest/gtest.h> 3 4 #include <gmock/gmock.h> 4 #include "util/SharedPtr.h"5 5 6 6 namespace orxonox … … 40 40 TEST(SharedPtr, ConstructorDefault) 41 41 { 42 SharedPtr<TestClass> test;42 std::shared_ptr<TestClass> test; 43 43 EXPECT_EQ(nullptr, test.get()); 44 44 } … … 48 48 TestClass* pointer = new TestClass(); 49 49 50 SharedPtr<TestClass> test = pointer;50 std::shared_ptr<TestClass> test(pointer); 51 51 EXPECT_EQ(pointer, test.get()); 52 52 EXPECT_EQ(pointer, &(*test)); … … 57 57 TestChildClass* pointer = new TestChildClass(); 58 58 59 SharedPtr<TestClass> test = pointer;59 std::shared_ptr<TestClass> test(pointer); 60 60 EXPECT_EQ(pointer, test.get()); 61 61 } … … 65 65 TestClass* pointer = new TestClass(); 66 66 67 SharedPtr<TestClass> other = pointer;68 EXPECT_EQ(pointer, other.get()); 69 70 SharedPtr<TestClass> test = other;67 std::shared_ptr<TestClass> other(pointer); 68 EXPECT_EQ(pointer, other.get()); 69 70 std::shared_ptr<TestClass> test = other; 71 71 EXPECT_EQ(pointer, test.get()); 72 72 } … … 76 76 TestChildClass* pointer = new TestChildClass(); 77 77 78 SharedPtr<TestChildClass> other = pointer;79 EXPECT_EQ(pointer, other.get()); 80 81 SharedPtr<TestClass> test = other;78 std::shared_ptr<TestChildClass> other(pointer); 79 EXPECT_EQ(pointer, other.get()); 80 81 std::shared_ptr<TestClass> test = other; 82 82 EXPECT_EQ(pointer, test.get()); 83 83 } … … 87 87 TestClass* pointer = new TestClass(); 88 88 89 SharedPtr<TestClass> other = pointer;90 EXPECT_EQ(pointer, other.get()); 91 92 SharedPtr<TestClass> test;89 std::shared_ptr<TestClass> other(pointer); 90 EXPECT_EQ(pointer, other.get()); 91 92 std::shared_ptr<TestClass> test; 93 93 EXPECT_EQ(nullptr, test.get()); 94 94 … … 101 101 TestChildClass* pointer = new TestChildClass(); 102 102 103 SharedPtr<TestChildClass> other = pointer;104 EXPECT_EQ(pointer, other.get()); 105 106 SharedPtr<TestClass> test;103 std::shared_ptr<TestChildClass> other(pointer); 104 EXPECT_EQ(pointer, other.get()); 105 106 std::shared_ptr<TestClass> test; 107 107 EXPECT_EQ(nullptr, test.get()); 108 108 … … 115 115 TestChildClass* pointer = new TestChildClass(); 116 116 117 SharedPtr<TestChildClass> other = pointer;118 EXPECT_EQ(pointer, other.get()); 119 120 SharedPtr<TestClass> test = other.cast<TestClass>();117 std::shared_ptr<TestChildClass> other(pointer); 118 EXPECT_EQ(pointer, other.get()); 119 120 std::shared_ptr<TestClass> test = std::static_pointer_cast<TestClass>(other); 121 121 EXPECT_EQ(pointer, test.get()); 122 122 } … … 126 126 TestClass* pointer = new TestClass(); 127 127 128 SharedPtr<TestClass> test = pointer;128 std::shared_ptr<TestClass> test(pointer); 129 129 EXPECT_EQ(pointer, test.get()); 130 130 … … 137 137 TEST(SharedPtr, Boolean) 138 138 { 139 SharedPtr<TestClass> test;139 std::shared_ptr<TestClass> test; 140 140 EXPECT_EQ(nullptr, test.get()); 141 141 EXPECT_FALSE(test); … … 143 143 TestClass* pointer = new TestClass(); 144 144 145 test = pointer;145 test.reset(pointer); 146 146 EXPECT_EQ(pointer, test.get()); 147 147 EXPECT_TRUE(static_cast<bool>(test)); … … 153 153 TestClass* pointer2 = new TestClass(); 154 154 155 SharedPtr<TestClass> test1 = pointer1;156 SharedPtr<TestClass> test2 = pointer2;155 std::shared_ptr<TestClass> test1(pointer1); 156 std::shared_ptr<TestClass> test2(pointer2); 157 157 158 158 EXPECT_EQ(pointer1, test1.get()); … … 168 168 { 169 169 TestChildClassMock* pointer = new TestChildClassMock(); 170 SharedPtr<TestClass> test = pointer;170 std::shared_ptr<TestClass> test(pointer); 171 171 172 172 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); … … 177 177 TestChildClassMock* pointer = new TestChildClassMock(); 178 178 179 SharedPtr<TestClass> test = pointer;180 std::vector< SharedPtr<TestClass>> tests;179 std::shared_ptr<TestClass> test(pointer); 180 std::vector<std::shared_ptr<TestClass>> tests; 181 181 for (size_t i = 0; i < 100; ++i) 182 tests.push_back( SharedPtr<TestClass>(test));182 tests.push_back(std::shared_ptr<TestClass>(test)); 183 183 184 184 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); … … 191 191 192 192 // default 193 SharedPtr<TestChildClass> sharedPtr1;193 std::shared_ptr<TestChildClass> sharedPtr1; 194 194 EXPECT_EQ(nullptr, sharedPtr1.get()); 195 195 196 196 // pointer 197 SharedPtr<TestChildClass> sharedPtr2(pointer);197 std::shared_ptr<TestChildClass> sharedPtr2(pointer); 198 198 EXPECT_EQ(pointer, sharedPtr2.get()); 199 199 200 200 // copy 201 SharedPtr<TestChildClass> sharedPtr3(sharedPtr2);201 std::shared_ptr<TestChildClass> sharedPtr3(sharedPtr2); 202 202 EXPECT_EQ(pointer, sharedPtr3.get()); 203 203 204 204 // move 205 SharedPtr<TestChildClass> sharedPtr4(std::move(sharedPtr3));205 std::shared_ptr<TestChildClass> sharedPtr4(std::move(sharedPtr3)); 206 206 EXPECT_EQ(pointer, sharedPtr4.get()); 207 207 208 208 // other 209 SharedPtr<TestClass> sharedPtr5(sharedPtr4);209 std::shared_ptr<TestClass> sharedPtr5(sharedPtr4); 210 210 EXPECT_EQ(pointer, sharedPtr5.get()); 211 211 … … 220 220 221 221 // default 222 SharedPtr<TestChildClass> sharedPtr1;222 std::shared_ptr<TestChildClass> sharedPtr1; 223 223 EXPECT_EQ(nullptr, sharedPtr1.get()); 224 224 225 225 // pointer 226 SharedPtr<TestChildClass> sharedPtr2 = pointer;226 std::shared_ptr<TestChildClass> sharedPtr2(pointer); 227 227 EXPECT_EQ(pointer, sharedPtr2.get()); 228 228 229 229 // copy 230 SharedPtr<TestChildClass> sharedPtr3 = sharedPtr2;230 std::shared_ptr<TestChildClass> sharedPtr3 = sharedPtr2; 231 231 EXPECT_EQ(pointer, sharedPtr3.get()); 232 232 233 233 // move 234 SharedPtr<TestChildClass> sharedPtr4 = std::move(sharedPtr3);234 std::shared_ptr<TestChildClass> sharedPtr4 = std::move(sharedPtr3); 235 235 EXPECT_EQ(pointer, sharedPtr4.get()); 236 236 237 237 // other 238 SharedPtr<TestClass> sharedPtr5 = sharedPtr4;238 std::shared_ptr<TestClass> sharedPtr5 = sharedPtr4; 239 239 EXPECT_EQ(pointer, sharedPtr5.get()); 240 240 … … 247 247 TestChildClassMock* pointer = new TestChildClassMock(); 248 248 249 SharedPtr<TestChildClass> sharedPtr1(pointer);249 std::shared_ptr<TestChildClass> sharedPtr1(pointer); 250 250 EXPECT_EQ(pointer, sharedPtr1.get()); 251 251 252 252 // copy 253 SharedPtr<TestChildClass> sharedPtr2;253 std::shared_ptr<TestChildClass> sharedPtr2; 254 254 sharedPtr2 = sharedPtr1; 255 255 EXPECT_EQ(pointer, sharedPtr2.get()); 256 256 257 257 // move 258 SharedPtr<TestChildClass> sharedPtr3;258 std::shared_ptr<TestChildClass> sharedPtr3; 259 259 sharedPtr3 = std::move(sharedPtr2); 260 260 EXPECT_EQ(pointer, sharedPtr3.get()); 261 261 262 262 // other 263 SharedPtr<TestClass> sharedPtr4;263 std::shared_ptr<TestClass> sharedPtr4; 264 264 sharedPtr4 = sharedPtr3; 265 265 EXPECT_EQ(pointer, sharedPtr4.get());
Note: See TracChangeset
for help on using the changeset viewer.