- Timestamp:
- Mar 2, 2013, 7:15:37 PM (12 years ago)
- Location:
- code/branches/testing
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/UtilPrereqs.h
r9530 r9533 97 97 class ScopedSingleton; 98 98 class ScopeListener; 99 template <class T> 100 class SharedPtr; 99 101 class SignalHandler; 100 102 template <class T> -
code/branches/testing/src/libraries/util/output/OutputManager.cc
r9530 r9533 39 39 #include "util/Output.h" 40 40 #include "util/StringUtils.h" 41 #include "util/SharedPtr.h" 41 42 42 43 namespace orxonox … … 61 62 } 62 63 64 /*static*/ SharedPtr<OutputManager>& OutputManager::Testing::getInstancePointer() 65 { 66 static SharedPtr<OutputManager> instance(new OutputManager()); 67 return instance; 68 } 69 63 70 /** 64 71 @brief Returns the only existing instance of the OutputManager singleton. … … 66 73 /*static*/ OutputManager& OutputManager::getInstance() 67 74 { 68 static OutputManager instance; 69 return instance; 75 return *OutputManager::Testing::getInstancePointer(); 70 76 } 71 77 -
code/branches/testing/src/libraries/util/output/OutputManager.h
r9530 r9533 65 65 { 66 66 public: 67 OutputManager(); 68 OutputManager(const OutputManager&); 69 virtual ~OutputManager(); 70 67 71 static OutputManager& getInstance(); 68 72 static OutputManager& getInstanceAndCreateListeners(); … … 70 74 void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message); 71 75 72 v oid registerListener(OutputListener* listener);73 v oid unregisterListener(OutputListener* listener);76 virtual void registerListener(OutputListener* listener); 77 virtual void unregisterListener(OutputListener* listener); 74 78 75 79 virtual void updatedLevelMask(const OutputListener* listener) … … 103 107 104 108 private: 105 OutputManager();106 OutputManager(const OutputManager&);107 ~OutputManager();108 109 109 void updateMasks(); 110 110 void updateCombinedLevelMask(); … … 121 121 std::map<std::string, OutputContextContainer> contextContainers_; ///< Contains all contexts including sub-contexts and their containers 122 122 OutputContextSubID subcontextCounter_; ///< Counts the number of sub-contexts (and generates their IDs) 123 124 public: 125 struct _UtilExport Testing 126 { 127 static SharedPtr<OutputManager>& getInstancePointer(); 128 }; 123 129 }; 124 130 } -
code/branches/testing/test/util/OutputTest.cc
r9529 r9533 12 12 } 13 13 14 TEST(Output , CanUseOrxout)14 TEST(OutputTest, CanUseOrxout) 15 15 { 16 16 orxout() << "test" << endl; 17 17 } 18 18 19 TEST(Output , OrxoutUsesCorrectOutputLevel)19 TEST(OutputTest, OrxoutUsesCorrectOutputLevel) 20 20 { 21 21 { … … 30 30 } 31 31 32 TEST(Output , OrxoutUsesCorrectOutputContext)32 TEST(OutputTest, OrxoutUsesCorrectOutputContext) 33 33 { 34 34 const OutputStream& stream = orxout(verbose, context::unittest()); … … 39 39 } 40 40 41 TEST(Output , OrxoutAcceptsFunctionPointer)41 TEST(OutputTest, OrxoutAcceptsFunctionPointer) 42 42 { 43 43 const OutputStream& stream = orxout(verbose, context::unittest); -
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.