Changeset 9533 for code/branches/testing/test/util/output
- Timestamp:
- Mar 2, 2013, 7:15:37 PM (12 years ago)
- Location:
- code/branches/testing/test/util/output
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/test/util/output/OutputDefinitionsTest.cc
r9529 r9533 4 4 namespace orxonox 5 5 { 6 TEST(OutputDefinitions , Levels)6 TEST(OutputDefinitionsTest, Levels) 7 7 { 8 8 EXPECT_EQ(0x0000, level::none); -
code/branches/testing/test/util/output/OutputListenerTest.cc
r9529 r9533 2 2 #include <gmock/gmock.h> 3 3 #include "util/output/OutputListener.h" 4 #include "util/output/OutputManager.h" 5 #include "util/SharedPtr.h" 4 6 5 7 namespace orxonox … … 20 22 { 21 23 public: 24 MockOutputListener(bool bRegister = true) : OutputListener(bRegister) {} 25 22 26 MOCK_METHOD3(output, void(OutputLevel, const OutputContextContainer&, const std::vector<std::string>&)); 27 28 inline const std::vector<AdditionalContextListener*>& getListeners() const 29 { return OutputListener::getListeners(); } 23 30 }; 31 32 class MockAdditionalContextListener : public AdditionalContextListener 33 { 34 public: 35 MOCK_METHOD1(updatedLevelMask, void(const OutputListener*)); 36 MOCK_METHOD1(updatedAdditionalContextsLevelMask, void(const OutputListener*)); 37 MOCK_METHOD1(updatedAdditionalContextsMask, void(const OutputListener*)); 38 }; 39 40 class MockOutputManager : public OutputManager 41 { 42 public: 43 MOCK_METHOD1(registerListener, void(OutputListener*)); 44 MOCK_METHOD1(unregisterListener, void(OutputListener*)); 45 }; 24 46 } 25 47 26 48 // test default settings 27 TEST(OutputListener , DefaultConstructorAcceptsNothing)49 TEST(OutputListenerTest, DefaultConstructorAcceptsNothing) 28 50 { 29 51 MockOutputListener listener; … … 35 57 36 58 // test setLevelMax 37 TEST(OutputListener , TestSetLevelMax)59 TEST(OutputListenerTest, SetLevelMax) 38 60 { 39 61 MockOutputListener listener; … … 52 74 53 75 // test setLevelRange 54 TEST(OutputListener , TestSetLevelRange)76 TEST(OutputListenerTest, SetLevelRange) 55 77 { 56 78 MockOutputListener listener; … … 69 91 70 92 // test setLevelMask 71 TEST(OutputListener , TestSetLevelMask)93 TEST(OutputListenerTest, SetLevelMask) 72 94 { 73 95 MockOutputListener listener; … … 86 108 87 109 // test setAdditionalContextsLevelMax 88 TEST(OutputListener , TestSetAdditionalContextsLevelMax)110 TEST(OutputListenerTest, SetAdditionalContextsLevelMax) 89 111 { 90 112 MockOutputListener listener; … … 103 125 104 126 // test setAdditionalContextsLevelRange 105 TEST(OutputListener , TestSetAdditionalContextsLevelRange)127 TEST(OutputListenerTest, SetAdditionalContextsLevelRange) 106 128 { 107 129 MockOutputListener listener; … … 120 142 121 143 // test setAdditionalContextsLevelMask 122 TEST(OutputListener , TestSetAdditionalContextsLevelMask)144 TEST(OutputListenerTest, SetAdditionalContextsLevelMask) 123 145 { 124 146 MockOutputListener listener; … … 137 159 138 160 // test setAdditionalContextsMask 139 TEST(OutputListener , TestSetAdditionalContextsMask)161 TEST(OutputListenerTest, SetAdditionalContextsMask) 140 162 { 141 163 MockOutputListener listener; … … 150 172 } 151 173 152 // test setAdditionalContextsLevelMask calls OutputManager::updateCombinedAdditionalContextsLevelMask 153 // test setAdditionalContextsMask calls OutputManager::updateCombinedAdditionalContextsMask 174 // test registerListener 175 TEST(OutputListenerTest, RegisterListener) 176 { 177 MockOutputListener outputListener(false); 178 MockAdditionalContextListener additionalContextListener; 179 180 EXPECT_EQ(0u, outputListener.getListeners().size()); 181 outputListener.registerListener(&additionalContextListener); 182 EXPECT_EQ(1u, outputListener.getListeners().size()); 183 EXPECT_EQ(&additionalContextListener, outputListener.getListeners()[0]); 184 } 185 186 // test unregisterListener 187 TEST(OutputListenerTest, UnregisterListener) 188 { 189 MockOutputListener outputListener(false); 190 MockAdditionalContextListener additionalContextListener; 191 192 outputListener.registerListener(&additionalContextListener); 193 EXPECT_EQ(1u, outputListener.getListeners().size()); 194 EXPECT_EQ(&additionalContextListener, outputListener.getListeners()[0]); 195 196 outputListener.unregisterListener(&additionalContextListener); 197 EXPECT_EQ(0u, outputListener.getListeners().size()); 198 } 199 200 // test setLevelMask calls OutputManager::updatedLevelMask 201 TEST(OutputListenerTest, SetLevelMaskCallsListeners) 202 { 203 MockOutputListener listener; 204 MockAdditionalContextListener additionalContextListener; 205 listener.registerListener(&additionalContextListener); 206 207 EXPECT_CALL(additionalContextListener, updatedLevelMask(&listener)).Times(1); 208 209 listener.setLevelMask(level::debug_output); 210 } 211 212 // test setAdditionalContextsLevelMask calls OutputManager::updatedAdditionalContextsLevelMask 213 TEST(OutputListenerTest, SetAdditionalContextsLevelMaskCallsListeners) 214 { 215 MockOutputListener listener; 216 MockAdditionalContextListener additionalContextListener; 217 listener.registerListener(&additionalContextListener); 218 219 EXPECT_CALL(additionalContextListener, updatedAdditionalContextsLevelMask(&listener)).Times(1); 220 221 listener.setAdditionalContextsLevelMask(level::debug_output); 222 } 223 224 // test setAdditionalContextsMask calls OutputManager::updatedAdditionalContextsMask 225 TEST(OutputListenerTest, SetAdditionalContextsMaskCallsListeners) 226 { 227 MockOutputListener listener; 228 MockAdditionalContextListener additionalContextListener; 229 listener.registerListener(&additionalContextListener); 230 231 EXPECT_CALL(additionalContextListener, updatedAdditionalContextsMask(&listener)).Times(1); 232 233 listener.setAdditionalContextsMask(context::unittest1().mask); 234 } 154 235 155 236 // test acceptsOutput 156 237 // test unfilteredOutput 238 239 // Fixture 240 class OutputListenerTestWithMockedOutputManager : public ::testing::Test 241 { 242 public: 243 virtual void SetUp() 244 { 245 this->manager_ = new MockOutputManager(); 246 OutputManager::Testing::getInstancePointer() = this->manager_; 247 } 248 249 virtual void TearDown() 250 { 251 OutputManager::Testing::getInstancePointer() = new OutputManager(); 252 } 253 254 protected: 255 MockOutputManager* manager_; 256 }; 257 258 // test default-constructor calls OutputManager::registerListener 259 TEST_F(OutputListenerTestWithMockedOutputManager, ConstructorRegistersInOutputManager) 260 { 261 EXPECT_CALL(*this->manager_, registerListener(::testing::_)).Times(1); 262 MockOutputListener listener; 263 } 264 265 // test prevent constructor from calling OutputManager::registerListener 266 TEST_F(OutputListenerTestWithMockedOutputManager, PreventRegisteringInOutputManager) 267 { 268 EXPECT_CALL(*this->manager_, registerListener(::testing::_)).Times(0); 269 MockOutputListener listener(false); 270 } 271 272 // test destructor calls OutputManager::unregisterListener 273 TEST_F(OutputListenerTestWithMockedOutputManager, DestructorUnregistersFromOutputManager) 274 { 275 MockOutputListener listener; 276 EXPECT_CALL(*this->manager_, unregisterListener(::testing::_)).Times(1); 277 } 157 278 }
Note: See TracChangeset
for help on using the changeset viewer.