Changeset 9534 for code/branches/testing/test/util/output
- Timestamp:
- Mar 3, 2013, 8:25:53 PM (12 years ago)
- Location:
- code/branches/testing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing
- Property svn:ignore
-
old new 3 3 vs 4 4 dependencies 5 .metadata 6 eclipse
-
- Property svn:ignore
-
code/branches/testing/test/util/output/OutputListenerTest.cc
r9533 r9534 235 235 236 236 // test acceptsOutput 237 namespace 238 { 239 void testContext(const OutputListener& listener, const OutputContextContainer& context, bool accepted) 240 { 241 EXPECT_TRUE(listener.acceptsOutput(level::message, context)); 242 EXPECT_TRUE(listener.acceptsOutput(level::user_error, context)); 243 EXPECT_TRUE(listener.acceptsOutput(level::user_warning, context)); 244 245 if (accepted) 246 { 247 EXPECT_TRUE(listener.acceptsOutput(level::user_status, context)); 248 EXPECT_TRUE(listener.acceptsOutput(level::internal_error, context)); 249 EXPECT_TRUE(listener.acceptsOutput(level::internal_info, context)); 250 } 251 else 252 { 253 EXPECT_FALSE(listener.acceptsOutput(level::user_status, context)); 254 EXPECT_FALSE(listener.acceptsOutput(level::internal_error, context)); 255 EXPECT_FALSE(listener.acceptsOutput(level::internal_info, context)); 256 } 257 258 EXPECT_FALSE(listener.acceptsOutput(level::verbose, context)); 259 EXPECT_FALSE(listener.acceptsOutput(level::verbose_ultra, context)); 260 } 261 } 262 263 TEST(OutputListenerTest, AcceptsOutputNoAdditionalContext) 264 { 265 MockOutputListener listener; 266 267 listener.setLevelMax(level::user_warning); 268 269 testContext(listener, context::undefined(), false); 270 testContext(listener, context::unittest1(), false); 271 testContext(listener, context::unittest2(), false); 272 } 273 274 TEST(OutputListenerTest, AcceptsOutputWithAdditionalContext) 275 { 276 MockOutputListener listener; 277 278 listener.setLevelMax(level::user_warning); 279 listener.setAdditionalContextsMask(context::unittest1().mask); 280 listener.setAdditionalContextsLevelMax(level::internal_info); 281 282 testContext(listener, context::undefined(), false); 283 testContext(listener, context::unittest1(), true); 284 testContext(listener, context::unittest2(), false); 285 } 286 287 TEST(OutputListenerTest, AcceptsOutputWithTwoAdditionalContexts) 288 { 289 MockOutputListener listener; 290 291 listener.setLevelMax(level::user_warning); 292 293 listener.setLevelMax(level::user_warning); 294 listener.setAdditionalContextsMask(context::unittest1().mask | context::unittest2().mask); 295 listener.setAdditionalContextsLevelMax(level::internal_info); 296 297 testContext(listener, context::undefined(), false); 298 testContext(listener, context::unittest1(), true); 299 testContext(listener, context::unittest2(), true); 300 } 301 237 302 // test unfilteredOutput 303 TEST(OutputListenerTest, UnfilteredOutputCallsOutputIfOutputAccepted) 304 { 305 MockOutputListener listener; 306 307 listener.setLevelMax(level::user_warning); 308 309 const OutputLevel& level = level::message; 310 const OutputContextContainer& context = context::undefined(); 311 312 EXPECT_TRUE(listener.acceptsOutput(level, context)); 313 314 std::vector<std::string> lines; 315 EXPECT_CALL(listener, output(level, ::testing::_, lines)).Times(1); 316 317 listener.unfilteredOutput(level, context, lines); 318 } 319 320 TEST(OutputListenerTest, UnfilteredOutputDoesNotCallOutputIfOutputNotAccepted) 321 { 322 MockOutputListener listener; 323 324 listener.setLevelMax(level::user_warning); 325 326 const OutputLevel& level = level::verbose; 327 const OutputContextContainer& context = context::undefined(); 328 329 EXPECT_FALSE(listener.acceptsOutput(level, context)); 330 331 std::vector<std::string> lines; 332 EXPECT_CALL(listener, output(level, ::testing::_, lines)).Times(0); 333 334 listener.unfilteredOutput(level, context, lines); 335 } 238 336 239 337 // Fixture -
code/branches/testing/test/util/output/SubcontextOutputListenerTest.cc
r9529 r9534 1 1 #include <gtest/gtest.h> 2 #include <gmock/gmock.h> 2 3 #include "util/Output.h" 4 #include "util/output/SubcontextOutputListener.h" 3 5 4 6 namespace orxonox 5 7 { 8 namespace context 9 { 10 namespace 11 { 12 REGISTER_OUTPUT_CONTEXT(unittest1); 13 REGISTER_OUTPUT_CONTEXT(unittest2); 14 REGISTER_OUTPUT_CONTEXT(unittest3); 15 16 REGISTER_OUTPUT_SUBCONTEXT(unittest3, sub1); 17 REGISTER_OUTPUT_SUBCONTEXT(unittest3, sub2); 18 REGISTER_OUTPUT_SUBCONTEXT(unittest3, sub3); 19 } 20 } 21 22 namespace 23 { 24 class MockSubcontextOutputListener : public SubcontextOutputListener 25 { 26 public: 27 MockSubcontextOutputListener(bool bRegister = true) : SubcontextOutputListener(bRegister) {} 28 MOCK_METHOD3(output, void(OutputLevel, const OutputContextContainer&, const std::vector<std::string>&)); 29 }; 30 } 31 32 TEST(SubcontextOutputListenerTest, ContextsDefinedCorrectly) 33 { 34 EXPECT_TRUE(context::unittest1().sub_id == context::no_subcontext); 35 EXPECT_TRUE(context::unittest2().sub_id == context::no_subcontext); 36 EXPECT_TRUE(context::unittest3().sub_id == context::no_subcontext); 37 EXPECT_FALSE(context::sub1().sub_id == context::no_subcontext); 38 EXPECT_FALSE(context::sub2().sub_id == context::no_subcontext); 39 EXPECT_FALSE(context::sub3().sub_id == context::no_subcontext); 40 } 41 42 // test setAdditionalContextsMask 43 TEST(SubcontextOutputListenerTest, SetAdditionalContextsMask) 44 { 45 MockSubcontextOutputListener listener; 46 47 listener.setAdditionalContextsMask(context::unittest1().mask | context::unittest2().mask); 48 49 OutputContextMask mask = listener.getAdditionalContextsMask(); 50 51 EXPECT_TRUE(mask & context::unittest1().mask); 52 EXPECT_TRUE(mask & context::unittest2().mask); 53 EXPECT_FALSE(mask & context::unittest3().mask); 54 } 55 56 // test setAdditionalSubcontexts 57 TEST(SubcontextOutputListenerTest, SetAdditionalSubcontexts) 58 { 59 MockSubcontextOutputListener listener; 60 61 std::set<const OutputContextContainer*> subcontexts; 62 subcontexts.insert(&context::sub1()); 63 subcontexts.insert(&context::sub3()); 64 65 listener.setAdditionalSubcontexts(subcontexts); 66 OutputContextMask mask = listener.getAdditionalContextsMask(); 67 68 EXPECT_FALSE(mask & context::unittest1().mask); 69 EXPECT_FALSE(mask & context::unittest2().mask); 70 EXPECT_TRUE(mask & context::unittest3().mask); 71 } 72 73 // test setAdditionalContextsMask and setAdditionalSubcontexts 74 TEST(SubcontextOutputListenerTest, SetAdditionalContextsAndSubcontexts) 75 { 76 MockSubcontextOutputListener listener; 77 78 std::set<const OutputContextContainer*> subcontexts; 79 subcontexts.insert(&context::sub1()); 80 subcontexts.insert(&context::sub3()); 81 82 listener.setAdditionalSubcontexts(subcontexts); 83 listener.setAdditionalContextsMask(context::unittest1().mask | context::unittest2().mask); 84 85 OutputContextMask mask = listener.getAdditionalContextsMask(); 86 87 EXPECT_TRUE(mask & context::unittest1().mask); 88 EXPECT_TRUE(mask & context::unittest2().mask); 89 EXPECT_TRUE(mask & context::unittest3().mask); 90 } 91 92 // test acceptsOutput 93 namespace 94 { 95 void testContext(const OutputListener& listener, const OutputContextContainer& context, bool accepted) 96 { 97 EXPECT_TRUE(accepted == listener.acceptsOutput(level::message, context)); 98 EXPECT_TRUE(accepted == listener.acceptsOutput(level::user_error, context)); 99 EXPECT_TRUE(accepted == listener.acceptsOutput(level::internal_info, context)); 100 } 101 } 102 103 TEST(SubcontextOutputListenerTest, NoContext) 104 { 105 MockSubcontextOutputListener listener; 106 listener.setAdditionalContextsLevelMax(level::verbose); 107 108 testContext(listener, context::unittest1(), false); 109 testContext(listener, context::unittest2(), false); 110 testContext(listener, context::unittest3(), false); 111 testContext(listener, context::sub1(), false); 112 testContext(listener, context::sub2(), false); 113 testContext(listener, context::sub3(), false); 114 } 115 116 TEST(SubcontextOutputListenerTest, OneContext) 117 { 118 MockSubcontextOutputListener listener; 119 listener.setAdditionalContextsLevelMax(level::verbose); 120 121 listener.setAdditionalContextsMask(context::unittest1().mask); 122 123 testContext(listener, context::unittest1(), true); 124 testContext(listener, context::unittest2(), false); 125 testContext(listener, context::unittest3(), false); 126 testContext(listener, context::sub1(), false); 127 testContext(listener, context::sub2(), false); 128 testContext(listener, context::sub3(), false); 129 } 130 131 TEST(SubcontextOutputListenerTest, TwoContexts) 132 { 133 MockSubcontextOutputListener listener; 134 listener.setAdditionalContextsLevelMax(level::verbose); 135 136 listener.setAdditionalContextsMask(context::unittest1().mask | context::unittest2().mask); 137 138 testContext(listener, context::unittest1(), true); 139 testContext(listener, context::unittest2(), true); 140 testContext(listener, context::unittest3(), false); 141 testContext(listener, context::sub1(), false); 142 testContext(listener, context::sub2(), false); 143 testContext(listener, context::sub3(), false); 144 } 145 146 TEST(SubcontextOutputListenerTest, OneSubcontext) 147 { 148 MockSubcontextOutputListener listener; 149 listener.setAdditionalContextsLevelMax(level::verbose); 150 151 std::set<const OutputContextContainer*> subcontexts; 152 subcontexts.insert(&context::sub1()); 153 154 listener.setAdditionalSubcontexts(subcontexts); 155 156 testContext(listener, context::unittest1(), false); 157 testContext(listener, context::unittest2(), false); 158 testContext(listener, context::unittest3(), false); 159 testContext(listener, context::sub1(), true); 160 testContext(listener, context::sub2(), false); 161 testContext(listener, context::sub3(), false); 162 } 163 164 TEST(SubcontextOutputListenerTest, TwoSubcontexts) 165 { 166 MockSubcontextOutputListener listener; 167 listener.setAdditionalContextsLevelMax(level::verbose); 168 169 std::set<const OutputContextContainer*> subcontexts; 170 subcontexts.insert(&context::sub1()); 171 subcontexts.insert(&context::sub3()); 172 173 listener.setAdditionalSubcontexts(subcontexts); 174 175 testContext(listener, context::unittest1(), false); 176 testContext(listener, context::unittest2(), false); 177 testContext(listener, context::unittest3(), false); 178 testContext(listener, context::sub1(), true); 179 testContext(listener, context::sub2(), false); 180 testContext(listener, context::sub3(), true); 181 } 182 183 TEST(SubcontextOutputListenerTest, ContextsAndSubcontexts) 184 { 185 MockSubcontextOutputListener listener; 186 listener.setAdditionalContextsLevelMax(level::verbose); 187 188 std::set<const OutputContextContainer*> subcontexts; 189 subcontexts.insert(&context::sub1()); 190 subcontexts.insert(&context::sub3()); 191 192 listener.setAdditionalContextsMask(context::unittest1().mask | context::unittest2().mask); 193 listener.setAdditionalSubcontexts(subcontexts); 194 195 testContext(listener, context::unittest1(), true); 196 testContext(listener, context::unittest2(), true); 197 testContext(listener, context::unittest3(), false); 198 testContext(listener, context::sub1(), true); 199 testContext(listener, context::sub2(), false); 200 testContext(listener, context::sub3(), true); 201 } 202 203 TEST(SubcontextOutputListenerTest, BaseContextEnablesAllSubcontexts) 204 { 205 MockSubcontextOutputListener listener; 206 listener.setAdditionalContextsLevelMax(level::verbose); 207 208 listener.setAdditionalContextsMask(context::unittest3().mask); 209 210 testContext(listener, context::unittest1(), false); 211 testContext(listener, context::unittest2(), false); 212 testContext(listener, context::unittest3(), true); 213 testContext(listener, context::sub1(), true); 214 testContext(listener, context::sub2(), true); 215 testContext(listener, context::sub3(), true); 216 } 6 217 }
Note: See TracChangeset
for help on using the changeset viewer.