Changeset 11054 for code/branches/cpp11_v3/test/util
- Timestamp:
- Jan 10, 2016, 1:54:11 PM (9 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/test/util/MathTest.cc
r11052 r11054 245 245 246 246 // all numbers must satisfy 0 <= <number> < 1 247 for ( std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)247 for (float number : numbers) 248 248 { 249 EXPECT_LE(min, *it);250 EXPECT_GT(max, *it);249 EXPECT_LE(min, number); 250 EXPECT_GT(max, number); 251 251 } 252 252 } … … 268 268 269 269 // all numbers must satisfy 0 <= <number> < <max> 270 for ( std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)270 for (float number : numbers) 271 271 { 272 EXPECT_LE(min, *it);273 EXPECT_GT(max, *it);272 EXPECT_LE(min, number); 273 EXPECT_GT(max, number); 274 274 } 275 275 } … … 291 291 292 292 // all numbers must satisfy <min> <= <number> < <max> 293 for ( std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)293 for (float number : numbers) 294 294 { 295 EXPECT_LE(min, *it);296 EXPECT_GT(max, *it);295 EXPECT_LE(min, number); 296 EXPECT_GT(max, number); 297 297 } 298 298 } … … 315 315 316 316 // all numbers must be either 1 oder -1 317 for ( std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)318 EXPECT_TRUE( *it == 1 || *it== -1);317 for (float number : numbers) 318 EXPECT_TRUE(number == 1 || number == -1); 319 319 } 320 320 -
code/branches/cpp11_v3/test/util/SharedPtrTest.cc
r9114 r11054 1 #include <memory> 2 #include <utility> 1 3 #include <gtest/gtest.h> 2 4 #include <gmock/gmock.h> 3 #include "util/SharedPtr.h"4 5 5 6 namespace orxonox … … 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()); … … 39 40 TEST(SharedPtr, ConstructorDefault) 40 41 { 41 SharedPtr<TestClass> test;42 EXPECT_EQ( 0, test.get());42 std::shared_ptr<TestClass> test; 43 EXPECT_EQ(nullptr, test.get()); 43 44 } 44 45 … … 47 48 TestClass* pointer = new TestClass(); 48 49 49 SharedPtr<TestClass> test = pointer; 50 EXPECT_EQ(pointer, test.get()); 50 std::shared_ptr<TestClass> test(pointer); 51 EXPECT_EQ(pointer, test.get()); 52 EXPECT_EQ(pointer, &(*test)); 51 53 } 52 54 … … 55 57 TestChildClass* pointer = new TestChildClass(); 56 58 57 SharedPtr<TestClass> test = pointer;59 std::shared_ptr<TestClass> test(pointer); 58 60 EXPECT_EQ(pointer, test.get()); 59 61 } … … 63 65 TestClass* pointer = new TestClass(); 64 66 65 SharedPtr<TestClass> other = pointer;66 EXPECT_EQ(pointer, other.get()); 67 68 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; 69 71 EXPECT_EQ(pointer, test.get()); 70 72 } … … 74 76 TestChildClass* pointer = new TestChildClass(); 75 77 76 SharedPtr<TestChildClass> other = pointer;77 EXPECT_EQ(pointer, other.get()); 78 79 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; 80 82 EXPECT_EQ(pointer, test.get()); 81 83 } … … 85 87 TestClass* pointer = new TestClass(); 86 88 87 SharedPtr<TestClass> other = pointer;88 EXPECT_EQ(pointer, other.get()); 89 90 SharedPtr<TestClass> test;91 EXPECT_EQ( 0, test.get());89 std::shared_ptr<TestClass> other(pointer); 90 EXPECT_EQ(pointer, other.get()); 91 92 std::shared_ptr<TestClass> test; 93 EXPECT_EQ(nullptr, test.get()); 92 94 93 95 test = other; … … 99 101 TestChildClass* pointer = new TestChildClass(); 100 102 101 SharedPtr<TestChildClass> other = pointer;102 EXPECT_EQ(pointer, other.get()); 103 104 SharedPtr<TestClass> test;105 EXPECT_EQ( 0, test.get());103 std::shared_ptr<TestChildClass> other(pointer); 104 EXPECT_EQ(pointer, other.get()); 105 106 std::shared_ptr<TestClass> test; 107 EXPECT_EQ(nullptr, test.get()); 106 108 107 109 test = other; … … 113 115 TestChildClass* pointer = new TestChildClass(); 114 116 115 SharedPtr<TestChildClass> other = pointer;116 EXPECT_EQ(pointer, other.get()); 117 118 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); 119 121 EXPECT_EQ(pointer, test.get()); 120 122 } … … 124 126 TestClass* pointer = new TestClass(); 125 127 126 SharedPtr<TestClass> test = pointer;128 std::shared_ptr<TestClass> test(pointer); 127 129 EXPECT_EQ(pointer, test.get()); 128 130 … … 135 137 TEST(SharedPtr, Boolean) 136 138 { 137 SharedPtr<TestClass> test;138 EXPECT_EQ( 0, test.get());139 std::shared_ptr<TestClass> test; 140 EXPECT_EQ(nullptr, test.get()); 139 141 EXPECT_FALSE(test); 140 142 141 143 TestClass* pointer = new TestClass(); 142 144 143 test = pointer;144 EXPECT_EQ(pointer, test.get()); 145 EXPECT_TRUE( test);145 test.reset(pointer); 146 EXPECT_EQ(pointer, test.get()); 147 EXPECT_TRUE(static_cast<bool>(test)); 146 148 } 147 149 … … 151 153 TestClass* pointer2 = new TestClass(); 152 154 153 SharedPtr<TestClass> test1 = pointer1;154 SharedPtr<TestClass> test2 = pointer2;155 std::shared_ptr<TestClass> test1(pointer1); 156 std::shared_ptr<TestClass> test2(pointer2); 155 157 156 158 EXPECT_EQ(pointer1, test1.get()); … … 165 167 TEST(SharedPtr, ObjectDestroyedOnePointer) 166 168 { 167 TestC lassMock* pointer = new TestClassMock();168 SharedPtr<TestClass> test = pointer;169 TestChildClassMock* pointer = new TestChildClassMock(); 170 std::shared_ptr<TestClass> test(pointer); 169 171 170 172 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); … … 173 175 TEST(SharedPtr, ObjectDestroyedManyPointers) 174 176 { 175 TestC lassMock* pointer = new TestClassMock();176 177 SharedPtr<TestClass> test = pointer;178 std::vector< SharedPtr<TestClass>> tests;177 TestChildClassMock* pointer = new TestChildClassMock(); 178 179 std::shared_ptr<TestClass> test(pointer); 180 std::vector<std::shared_ptr<TestClass>> tests; 179 181 for (size_t i = 0; i < 100; ++i) 180 tests.push_back(SharedPtr<TestClass>(test)); 182 tests.push_back(std::shared_ptr<TestClass>(test)); 183 184 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); 185 } 186 187 TEST(SharedPtr, TestConstructors) 188 { 189 { 190 TestChildClassMock* pointer = new TestChildClassMock(); 191 192 // default 193 std::shared_ptr<TestChildClass> sharedPtr1; 194 EXPECT_EQ(nullptr, sharedPtr1.get()); 195 196 // pointer 197 std::shared_ptr<TestChildClass> sharedPtr2(pointer); 198 EXPECT_EQ(pointer, sharedPtr2.get()); 199 200 // copy 201 std::shared_ptr<TestChildClass> sharedPtr3(sharedPtr2); 202 EXPECT_EQ(pointer, sharedPtr3.get()); 203 204 // move 205 std::shared_ptr<TestChildClass> sharedPtr4(std::move(sharedPtr3)); 206 EXPECT_EQ(pointer, sharedPtr4.get()); 207 208 // other 209 std::shared_ptr<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 std::shared_ptr<TestChildClass> sharedPtr1; 223 EXPECT_EQ(nullptr, sharedPtr1.get()); 224 225 // pointer 226 std::shared_ptr<TestChildClass> sharedPtr2(pointer); 227 EXPECT_EQ(pointer, sharedPtr2.get()); 228 229 // copy 230 std::shared_ptr<TestChildClass> sharedPtr3 = sharedPtr2; 231 EXPECT_EQ(pointer, sharedPtr3.get()); 232 233 // move 234 std::shared_ptr<TestChildClass> sharedPtr4 = std::move(sharedPtr3); 235 EXPECT_EQ(pointer, sharedPtr4.get()); 236 237 // other 238 std::shared_ptr<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 std::shared_ptr<TestChildClass> sharedPtr1(pointer); 250 EXPECT_EQ(pointer, sharedPtr1.get()); 251 252 // copy 253 std::shared_ptr<TestChildClass> sharedPtr2; 254 sharedPtr2 = sharedPtr1; 255 EXPECT_EQ(pointer, sharedPtr2.get()); 256 257 // move 258 std::shared_ptr<TestChildClass> sharedPtr3; 259 sharedPtr3 = std::move(sharedPtr2); 260 EXPECT_EQ(pointer, sharedPtr3.get()); 261 262 // other 263 std::shared_ptr<TestClass> sharedPtr4; 264 sharedPtr4 = sharedPtr3; 265 EXPECT_EQ(pointer, sharedPtr4.get()); 181 266 182 267 EXPECT_CALL(*pointer, objectDestroyed()).Times(1); -
code/branches/cpp11_v3/test/util/SingletonTest.cc
r9114 r11054 23 23 }; 24 24 25 TestSingleton* TestSingleton::singletonPtr_s = NULL;25 TestSingleton* TestSingleton::singletonPtr_s = nullptr; 26 26 const size_t TestSingleton::MAGIC_VALUE = 0xCAFEBABE; 27 27 } -
code/branches/cpp11_v3/test/util/SmallObjectAllocatorTest.cc
r9114 r11054 47 47 // create an integer 48 48 size_t* pointer = this->create(5); 49 ASSERT_NE((void*) 0, pointer);49 ASSERT_NE((void*)nullptr, pointer); 50 50 EXPECT_EQ(5u, *pointer); 51 51 } … … 55 55 // create an integer 56 56 size_t* pointer = this->create(5); 57 ASSERT_NE((void*) 0, pointer);57 ASSERT_NE((void*)nullptr, pointer); 58 58 EXPECT_EQ(5u, *pointer); 59 59 … … 228 228 // create an object 229 229 SmallObject* pointer = this->create(5); 230 ASSERT_NE((void*) 0, pointer);230 ASSERT_NE((void*)nullptr, pointer); 231 231 EXPECT_EQ(5u, pointer->getValue()); 232 232 EXPECT_EQ(5u, SmallObject::total_s); … … 239 239 // create an object 240 240 SmallObject* pointer = this->create(5); 241 ASSERT_NE((void*) 0, pointer);241 ASSERT_NE((void*)nullptr, pointer); 242 242 EXPECT_EQ(5u, pointer->getValue()); 243 243 EXPECT_EQ(5u, SmallObject::total_s); -
code/branches/cpp11_v3/test/util/output/BaseWriterTest.cc
r9545 r11054 30 30 MOCK_METHOD2(printLine, void(const std::string&, OutputLevel)); 31 31 32 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) 32 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) override 33 33 { this->BaseWriter::output(level, context, lines); } 34 34 }; -
code/branches/cpp11_v3/test/util/output/ConsoleWriterTest.cc
r10712 r11054 3 3 #include "util/output/ConsoleWriter.h" 4 4 #include "util/output/OutputManager.h" 5 #include "util/SharedPtr.h"6 5 7 6 namespace orxonox … … 13 12 { 14 13 public: 15 virtual void SetUp() 14 virtual void SetUp() override 16 15 { 17 16 // reset output manager 18 OutputManager::Testing::getInstancePointer() = new OutputManager();17 OutputManager::Testing::getInstancePointer().reset(new OutputManager()); 19 18 } 20 19 21 virtual void TearDown() 20 virtual void TearDown() override 22 21 { 23 22 } … … 27 26 TEST_F(ConsoleWriterTest, Disable) 28 27 { 29 std::ostream stream( NULL);28 std::ostream stream(nullptr); 30 29 EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size()); 31 30 ConsoleWriter writer(stream); … … 37 36 TEST_F(ConsoleWriterTest, Enable) 38 37 { 39 std::ostream stream( NULL);38 std::ostream stream(nullptr); 40 39 ConsoleWriter writer(stream); 41 40 writer.disable(); -
code/branches/cpp11_v3/test/util/output/LogWriterTest.cc
r10624 r11054 4 4 #include "util/Convert.h" 5 5 #include "util/output/OutputManager.h" 6 #include "util/SharedPtr.h"7 6 8 7 namespace orxonox … … 13 12 { 14 13 public: 15 virtual void printLine(const std::string& line, OutputLevel level) 14 virtual void printLine(const std::string& line, OutputLevel level) override 16 15 { this->LogWriter::printLine(line, level); } 17 16 }; … … 21 20 { 22 21 public: 23 virtual void SetUp() 22 virtual void SetUp() override 24 23 { 25 24 // reset output manager 26 OutputManager::Testing::getInstancePointer() = new OutputManager();25 OutputManager::Testing::getInstancePointer().reset(new OutputManager()); 27 26 } 28 27 29 virtual void TearDown() 28 virtual void TearDown() override 30 29 { 31 30 } … … 138 137 std::string line = getLineWhichContains(path, "myothertestoutput"); 139 138 EXPECT_FALSE(line.empty()); 139 ASSERT_TRUE(line.length() > 12); 140 140 141 EXPECT_TRUE(isdigit(line[0])); 141 142 EXPECT_TRUE(isdigit(line[1])); … … 146 147 EXPECT_TRUE(isdigit(line[6])); 147 148 EXPECT_TRUE(isdigit(line[7])); 148 EXPECT_EQ(' ', line[8]); 149 EXPECT_EQ(':', line[8]); 150 EXPECT_TRUE(isdigit(line[9])); 151 EXPECT_TRUE(isdigit(line[10])); 152 EXPECT_TRUE(isdigit(line[11])); 153 EXPECT_EQ(' ', line[12]); 149 154 } 150 155 -
code/branches/cpp11_v3/test/util/output/MemoryWriterTest.cc
r10624 r11054 4 4 #include "util/output/MemoryWriter.h" 5 5 #include "util/output/OutputManager.h" 6 #include "util/SharedPtr.h"7 6 8 7 namespace orxonox … … 20 19 { 21 20 public: 22 virtual void SetUp() 21 virtual void SetUp() override 23 22 { 24 23 // reset output manager 25 OutputManager::Testing::getInstancePointer() = new OutputManager();24 OutputManager::Testing::getInstancePointer().reset(new OutputManager()); 26 25 } 27 26 28 virtual void TearDown() 27 virtual void TearDown() override 29 28 { 30 29 } -
code/branches/cpp11_v3/test/util/output/OutputListenerTest.cc
r9545 r11054 3 3 #include "util/output/OutputListener.h" 4 4 #include "util/output/OutputManager.h" 5 #include "util/SharedPtr.h"6 5 7 6 namespace orxonox … … 342 341 { 343 342 this->manager_ = new MockOutputManager(); 344 OutputManager::Testing::getInstancePointer() = this->manager_;343 OutputManager::Testing::getInstancePointer().reset(this->manager_); 345 344 } 346 345 347 346 virtual void TearDown() 348 347 { 349 OutputManager::Testing::getInstancePointer() = new OutputManager();348 OutputManager::Testing::getInstancePointer().reset(new OutputManager()); 350 349 } 351 350 -
code/branches/cpp11_v3/test/util/output/OutputManagerTest.cc
r10624 r11054 54 54 TEST(OutputManagerTest, GetInstanceDoesNotCreateDefaultListeners) 55 55 { 56 EXPECT_TRUE( NULL== OutputManager::getInstance().getMemoryWriter());57 EXPECT_TRUE( NULL== OutputManager::getInstance().getConsoleWriter());58 EXPECT_TRUE( NULL== OutputManager::getInstance().getLogWriter());56 EXPECT_TRUE(nullptr == OutputManager::getInstance().getMemoryWriter()); 57 EXPECT_TRUE(nullptr == OutputManager::getInstance().getConsoleWriter()); 58 EXPECT_TRUE(nullptr == OutputManager::getInstance().getLogWriter()); 59 59 } 60 60 … … 62 62 TEST(OutputManagerTest, GetInstanceAndCreateListenersCreatesDefaultListeners) 63 63 { 64 EXPECT_TRUE( NULL!= OutputManager::getInstanceAndCreateListeners().getMemoryWriter());65 EXPECT_TRUE( NULL!= OutputManager::getInstanceAndCreateListeners().getConsoleWriter());66 EXPECT_TRUE( NULL!= OutputManager::getInstanceAndCreateListeners().getLogWriter());64 EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getMemoryWriter()); 65 EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getConsoleWriter()); 66 EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getLogWriter()); 67 67 } 68 68 -
code/branches/cpp11_v3/test/util/output/OutputStreamTest.cc
r9547 r11054 8 8 #include "util/output/OutputManager.h" 9 9 #include "util/output/MemoryWriter.h" 10 #include "util/SharedPtr.h"11 10 12 11 namespace orxonox … … 88 87 { 89 88 this->manager_ = new MockOutputManager(); 90 OutputManager::Testing::getInstancePointer() = this->manager_;89 OutputManager::Testing::getInstancePointer().reset(this->manager_); 91 90 } 92 91 93 92 virtual void TearDown() 94 93 { 95 OutputManager::Testing::getInstancePointer() = new OutputManager();94 OutputManager::Testing::getInstancePointer().reset(new OutputManager()); 96 95 } 97 96
Note: See TracChangeset
for help on using the changeset viewer.