| 1 | #include <mil/PrecompiledHeaders.h> |
|---|
| 2 | #include <mil/Atomic.h> |
|---|
| 3 | #include <mil/UIModule.h> |
|---|
| 4 | #include <mil/Mil.h> |
|---|
| 5 | #include <mil/Module.h> |
|---|
| 6 | #include <mil/Thread.h> |
|---|
| 7 | #include "Test.h" |
|---|
| 8 | |
|---|
| 9 | namespace module_test { |
|---|
| 10 | |
|---|
| 11 | int global = 0; |
|---|
| 12 | |
|---|
| 13 | struct DummyModule : mil::Module<DummyModule> { |
|---|
| 14 | }; |
|---|
| 15 | |
|---|
| 16 | struct FooEvent { |
|---|
| 17 | int value; |
|---|
| 18 | }; |
|---|
| 19 | |
|---|
| 20 | struct FooEvent2 { |
|---|
| 21 | int value; |
|---|
| 22 | char pad[mil::pool::private_::BLOCK_SIZE]; |
|---|
| 23 | }; |
|---|
| 24 | |
|---|
| 25 | struct FooEvent3 { |
|---|
| 26 | int value; |
|---|
| 27 | char pad[mil::pool::private_::BLOCK_SIZE * 2]; |
|---|
| 28 | }; |
|---|
| 29 | |
|---|
| 30 | struct FooEvent4 { |
|---|
| 31 | int value; |
|---|
| 32 | char pad[mil::pool::private_::BLOCK_SIZE * 3]; |
|---|
| 33 | }; |
|---|
| 34 | |
|---|
| 35 | struct FooEvent5 { |
|---|
| 36 | int value; |
|---|
| 37 | char pad[mil::pool::private_::BLOCK_SIZE * 4]; |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | struct BarEvent { |
|---|
| 41 | int value; |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | struct BarEvent2 { |
|---|
| 45 | int value; |
|---|
| 46 | char pad[mil::pool::private_::BLOCK_SIZE]; |
|---|
| 47 | }; |
|---|
| 48 | |
|---|
| 49 | struct BarEvent3 { |
|---|
| 50 | int value; |
|---|
| 51 | char pad[mil::pool::private_::BLOCK_SIZE * 2]; |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | struct BarEvent4 { |
|---|
| 55 | int value; |
|---|
| 56 | char pad[mil::pool::private_::BLOCK_SIZE * 3]; |
|---|
| 57 | }; |
|---|
| 58 | |
|---|
| 59 | struct BarEvent5 { |
|---|
| 60 | int value; |
|---|
| 61 | char pad[mil::pool::private_::BLOCK_SIZE * 4]; |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | struct InfinityIncEvent { |
|---|
| 65 | }; |
|---|
| 66 | |
|---|
| 67 | struct Plus5 { |
|---|
| 68 | int pad[5]; |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | struct Minus3 { |
|---|
| 72 | int pad; |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | struct Plus5_3Times { |
|---|
| 76 | int count; |
|---|
| 77 | Plus5_3Times() : count(0) { |
|---|
| 78 | } |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | struct Destroy { |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | struct AppendString { |
|---|
| 85 | std::string* str; |
|---|
| 86 | void* pad[5]; |
|---|
| 87 | }; |
|---|
| 88 | |
|---|
| 89 | struct FooModule : mil::Module<FooModule> { |
|---|
| 90 | std::string str; |
|---|
| 91 | void execute(AppendString& e) { |
|---|
| 92 | str += *(e.str); |
|---|
| 93 | delete e.str; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | void execute(FooEvent& e) { |
|---|
| 97 | global = e.value; |
|---|
| 98 | repostEvent(); |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | void execute(FooEvent2& e) { |
|---|
| 102 | global = e.value; |
|---|
| 103 | repostEvent(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | void execute(FooEvent3& e) { |
|---|
| 107 | global = e.value; |
|---|
| 108 | repostEvent(); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | void execute(FooEvent4& e) { |
|---|
| 112 | global = e.value; |
|---|
| 113 | repostEvent(); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | void execute(FooEvent5& e) { |
|---|
| 117 | global = e.value; |
|---|
| 118 | repostEvent(); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | void execute(BarEvent& e) { |
|---|
| 122 | global = e.value; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void execute(BarEvent2& e) { |
|---|
| 126 | global = e.value; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | void execute(BarEvent3& e) { |
|---|
| 130 | global = e.value; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | void execute(BarEvent4& e) { |
|---|
| 134 | global = e.value; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | void execute(BarEvent5& e) { |
|---|
| 138 | global = e.value; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | void execute(InfinityIncEvent& i) { |
|---|
| 142 | global++; |
|---|
| 143 | repostEvent(); |
|---|
| 144 | } |
|---|
| 145 | void execute(Plus5& e) { |
|---|
| 146 | global += 5; |
|---|
| 147 | } |
|---|
| 148 | void execute(Minus3& e) { |
|---|
| 149 | global -= 3; |
|---|
| 150 | } |
|---|
| 151 | void execute(Plus5_3Times& e) { |
|---|
| 152 | e.count++; |
|---|
| 153 | if (e.count <= 3) { |
|---|
| 154 | global += 5; |
|---|
| 155 | repostEvent(); |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | void execute(Destroy& e) { |
|---|
| 159 | destroy(); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | static void test_event_sfinae() { |
|---|
| 163 | QT_CHECK_EQUAL(is_exit_event<Event<ExitEvent> >(), true); |
|---|
| 164 | QT_CHECK_EQUAL(is_exit_event<Event<Plus5> >(), false); |
|---|
| 165 | QT_CHECK_EQUAL(is_return_memory_event<Event<ReturnMemoryEvent> >(), true); |
|---|
| 166 | QT_CHECK_EQUAL(is_return_memory_event<Event<ReturnMemoryEvent> >(), true); |
|---|
| 167 | QT_CHECK_EQUAL(is_return_memory_event<Event<Minus3> >(), false); |
|---|
| 168 | } |
|---|
| 169 | }; |
|---|
| 170 | struct FooUIModule : UIModule<FooUIModule> { |
|---|
| 171 | std::string str; |
|---|
| 172 | void execute(AppendString& e) { |
|---|
| 173 | str += *(e.str); |
|---|
| 174 | delete e.str; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | void createGui() { |
|---|
| 178 | this->setWindow(create_window()); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | void execute(FooEvent& e) { |
|---|
| 182 | global = e.value; |
|---|
| 183 | repostEvent(); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | void execute(FooEvent2& e) { |
|---|
| 187 | global = e.value; |
|---|
| 188 | repostEvent(); |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | void execute(FooEvent3& e) { |
|---|
| 192 | global = e.value; |
|---|
| 193 | repostEvent(); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | void execute(FooEvent4& e) { |
|---|
| 197 | global = e.value; |
|---|
| 198 | repostEvent(); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | void execute(FooEvent5& e) { |
|---|
| 202 | global = e.value; |
|---|
| 203 | repostEvent(); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | void execute(BarEvent& e) { |
|---|
| 207 | global = e.value; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | void execute(BarEvent2& e) { |
|---|
| 211 | global = e.value; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | void execute(BarEvent3& e) { |
|---|
| 215 | global = e.value; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | void execute(BarEvent4& e) { |
|---|
| 219 | global = e.value; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | void execute(BarEvent5& e) { |
|---|
| 223 | global = e.value; |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | void execute(InfinityIncEvent& i) { |
|---|
| 228 | global++; |
|---|
| 229 | repostEvent(); |
|---|
| 230 | } |
|---|
| 231 | void execute(Plus5& e) { |
|---|
| 232 | global += 5; |
|---|
| 233 | } |
|---|
| 234 | void execute(Minus3& e) { |
|---|
| 235 | global -= 3; |
|---|
| 236 | } |
|---|
| 237 | void execute(Plus5_3Times& e) { |
|---|
| 238 | e.count++; |
|---|
| 239 | if (e.count <= 3) { |
|---|
| 240 | global += 5; |
|---|
| 241 | repostEvent(); |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | void execute(Destroy& e) { |
|---|
| 245 | destroy(); |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | static void test_event_sfinae() { |
|---|
| 249 | QT_CHECK_EQUAL(is_exit_event<Event<ExitEvent> >(), true); |
|---|
| 250 | QT_CHECK_EQUAL(is_exit_event<Event<Plus5> >(), false); |
|---|
| 251 | QT_CHECK_EQUAL(is_return_memory_event<Event<ReturnMemoryEvent> >(), true); |
|---|
| 252 | QT_CHECK_EQUAL(is_return_memory_event<Event<ReturnMemoryEvent> >(), true); |
|---|
| 253 | QT_CHECK_EQUAL(is_return_memory_event<Event<Minus3> >(), false); |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | }; |
|---|
| 257 | |
|---|
| 258 | struct FooSingleThreadedUIModule : public FooUIModule { |
|---|
| 259 | FooSingleThreadedUIModule() { |
|---|
| 260 | createGui(); |
|---|
| 261 | } |
|---|
| 262 | }; |
|---|
| 263 | |
|---|
| 264 | template <typename TestModuleType> |
|---|
| 265 | void test() { |
|---|
| 266 | DummyModule dummy; |
|---|
| 267 | { |
|---|
| 268 | global = 0; |
|---|
| 269 | TestModuleType m; |
|---|
| 270 | FooEvent e = {100}; |
|---|
| 271 | m.post(e, dummy); |
|---|
| 272 | m.execute_front(); |
|---|
| 273 | QT_CHECK_EQUAL(global, 100); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | { |
|---|
| 277 | global = 0; |
|---|
| 278 | TestModuleType m; |
|---|
| 279 | FooEvent e = {50}; |
|---|
| 280 | m.post(e, dummy); |
|---|
| 281 | m.execute_front(); |
|---|
| 282 | QT_CHECK_EQUAL(global, 50); |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | { |
|---|
| 286 | global = 0; |
|---|
| 287 | TestModuleType m; |
|---|
| 288 | FooEvent e = {-1}; |
|---|
| 289 | m.post(e, dummy); |
|---|
| 290 | m.execute_front(); |
|---|
| 291 | QT_CHECK_EQUAL(global, -1); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | { |
|---|
| 295 | global = 0; |
|---|
| 296 | TestModuleType m; |
|---|
| 297 | InfinityIncEvent i; |
|---|
| 298 | m.post(i, dummy); |
|---|
| 299 | m.execute_front(); |
|---|
| 300 | QT_CHECK_EQUAL(global, 1); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | { |
|---|
| 304 | TestModuleType m; |
|---|
| 305 | FooEvent e = {100}; |
|---|
| 306 | m.post(e, dummy); |
|---|
| 307 | global = 0; |
|---|
| 308 | m.execute_front(); |
|---|
| 309 | QT_CHECK_EQUAL(global, 100); |
|---|
| 310 | global = 0; |
|---|
| 311 | m.execute_front(); |
|---|
| 312 | QT_CHECK_EQUAL(global, 100); |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | { |
|---|
| 316 | TestModuleType m; |
|---|
| 317 | FooEvent2 e = {100}; |
|---|
| 318 | m.post(e, dummy); |
|---|
| 319 | for (int i = 0; i < 100; i++) { |
|---|
| 320 | global = 0; |
|---|
| 321 | QT_CHECK_EQUAL(global, 0); |
|---|
| 322 | m.execute_front(); |
|---|
| 323 | QT_CHECK_EQUAL(global, 100); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | { |
|---|
| 328 | TestModuleType m; |
|---|
| 329 | FooEvent3 e = {100}; |
|---|
| 330 | m.post(e, dummy); |
|---|
| 331 | global = 0; |
|---|
| 332 | m.execute_front(); |
|---|
| 333 | QT_CHECK_EQUAL(global, 100); |
|---|
| 334 | global = 0; |
|---|
| 335 | m.execute_front(); |
|---|
| 336 | QT_CHECK_EQUAL(global, 100); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | { |
|---|
| 340 | TestModuleType m; |
|---|
| 341 | FooEvent4 e = {100}; |
|---|
| 342 | m.post(e, dummy); |
|---|
| 343 | global = 0; |
|---|
| 344 | m.execute_front(); |
|---|
| 345 | QT_CHECK_EQUAL(global, 100); |
|---|
| 346 | global = 0; |
|---|
| 347 | m.execute_front(); |
|---|
| 348 | QT_CHECK_EQUAL(global, 100); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | { |
|---|
| 352 | TestModuleType m; |
|---|
| 353 | FooEvent5 e = {100}; |
|---|
| 354 | m.post(e, dummy); |
|---|
| 355 | global = 0; |
|---|
| 356 | m.execute_front(); |
|---|
| 357 | QT_CHECK_EQUAL(global, 100); |
|---|
| 358 | global = 0; |
|---|
| 359 | m.execute_front(); |
|---|
| 360 | QT_CHECK_EQUAL(global, 100); |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | { |
|---|
| 364 | global = 0; |
|---|
| 365 | TestModuleType m; |
|---|
| 366 | InfinityIncEvent i; |
|---|
| 367 | m.post(i, dummy); |
|---|
| 368 | m.execute_front(); |
|---|
| 369 | m.execute_front(); |
|---|
| 370 | m.execute_front(); |
|---|
| 371 | QT_CHECK_EQUAL(global, 3); |
|---|
| 372 | } |
|---|
| 373 | { |
|---|
| 374 | global = 0; |
|---|
| 375 | TestModuleType foo; |
|---|
| 376 | Plus5 p; |
|---|
| 377 | InfinityIncEvent i; |
|---|
| 378 | Minus3 m; |
|---|
| 379 | foo.post(p, dummy); |
|---|
| 380 | foo.post(p, dummy); |
|---|
| 381 | foo.post(m, dummy); |
|---|
| 382 | foo.post(i, dummy); |
|---|
| 383 | foo.post(p, dummy); |
|---|
| 384 | foo.post(i, dummy); |
|---|
| 385 | |
|---|
| 386 | foo.execute_front(); |
|---|
| 387 | QT_CHECK_EQUAL(global, 5); |
|---|
| 388 | foo.execute_front(); |
|---|
| 389 | QT_CHECK_EQUAL(global, 10); |
|---|
| 390 | foo.execute_front(); |
|---|
| 391 | QT_CHECK_EQUAL(global, 7); |
|---|
| 392 | foo.execute_front(); |
|---|
| 393 | QT_CHECK_EQUAL(global, 8); |
|---|
| 394 | foo.execute_front(); |
|---|
| 395 | QT_CHECK_EQUAL(global, 13); |
|---|
| 396 | foo.execute_front(); |
|---|
| 397 | QT_CHECK_EQUAL(global, 14); |
|---|
| 398 | foo.execute_front(); |
|---|
| 399 | QT_CHECK_EQUAL(global, 15); |
|---|
| 400 | foo.execute_front(); |
|---|
| 401 | QT_CHECK_EQUAL(global, 16); |
|---|
| 402 | foo.execute_front(); |
|---|
| 403 | QT_CHECK_EQUAL(global, 17); |
|---|
| 404 | } |
|---|
| 405 | { |
|---|
| 406 | global = 3; |
|---|
| 407 | TestModuleType foo; |
|---|
| 408 | |
|---|
| 409 | AppendString s1; |
|---|
| 410 | s1.str = new std::string("foo"); |
|---|
| 411 | foo.post(s1, dummy); |
|---|
| 412 | foo.execute_front(); |
|---|
| 413 | QT_CHECK_EQUAL(foo.str, "foo"); |
|---|
| 414 | Plus5_3Times p5_3; |
|---|
| 415 | foo.post(p5_3, dummy); |
|---|
| 416 | QT_CHECK_EQUAL(global, 3); |
|---|
| 417 | foo.execute_front(); |
|---|
| 418 | QT_CHECK_EQUAL(global, 8); |
|---|
| 419 | foo.execute_front(); |
|---|
| 420 | QT_CHECK_EQUAL(global, 13); |
|---|
| 421 | foo.execute_front(); |
|---|
| 422 | QT_CHECK_EQUAL(global, 18); |
|---|
| 423 | foo.execute_front(); |
|---|
| 424 | QT_CHECK_EQUAL(global, 18); |
|---|
| 425 | foo.execute_front(); |
|---|
| 426 | QT_CHECK_EQUAL(global, 18); |
|---|
| 427 | AppendString s2; |
|---|
| 428 | s2.str = new std::string("bar"); |
|---|
| 429 | foo.post(s2, dummy); |
|---|
| 430 | foo.execute_front(); |
|---|
| 431 | QT_CHECK_EQUAL(foo.str, "foobar"); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | } |
|---|
| 435 | |
|---|
| 436 | template <typename TestModuleType> |
|---|
| 437 | void test2() { |
|---|
| 438 | |
|---|
| 439 | DummyModule dummy; |
|---|
| 440 | |
|---|
| 441 | { |
|---|
| 442 | TestModuleType m; |
|---|
| 443 | FooEvent e = {100}; |
|---|
| 444 | m.post(e, dummy); |
|---|
| 445 | global = 0; |
|---|
| 446 | m.execute_front(); |
|---|
| 447 | QT_CHECK_EQUAL(global, 100); |
|---|
| 448 | global = 0; |
|---|
| 449 | m.execute_front(); |
|---|
| 450 | QT_CHECK_EQUAL(global, 100); |
|---|
| 451 | } |
|---|
| 452 | { |
|---|
| 453 | global = 0; |
|---|
| 454 | TestModuleType m; |
|---|
| 455 | InfinityIncEvent i; |
|---|
| 456 | m.post(i, dummy); |
|---|
| 457 | m.execute_front(); |
|---|
| 458 | m.execute_front(); |
|---|
| 459 | m.execute_front(); |
|---|
| 460 | QT_CHECK_EQUAL(global, 3); |
|---|
| 461 | |
|---|
| 462 | } |
|---|
| 463 | { |
|---|
| 464 | global = 0; |
|---|
| 465 | TestModuleType foo; |
|---|
| 466 | Plus5 p; |
|---|
| 467 | InfinityIncEvent i; |
|---|
| 468 | Minus3 m; |
|---|
| 469 | foo.post(p, dummy); |
|---|
| 470 | foo.post(p, dummy); |
|---|
| 471 | foo.post(m, dummy); |
|---|
| 472 | foo.post(i, dummy); |
|---|
| 473 | foo.post(p, dummy); |
|---|
| 474 | foo.post(i, dummy); |
|---|
| 475 | |
|---|
| 476 | foo.execute_front(); |
|---|
| 477 | QT_CHECK_EQUAL(global, 5); |
|---|
| 478 | foo.execute_front(); |
|---|
| 479 | QT_CHECK_EQUAL(global, 10); |
|---|
| 480 | foo.execute_front(); |
|---|
| 481 | QT_CHECK_EQUAL(global, 7); |
|---|
| 482 | foo.execute_front(); |
|---|
| 483 | QT_CHECK_EQUAL(global, 8); |
|---|
| 484 | foo.execute_front(); |
|---|
| 485 | QT_CHECK_EQUAL(global, 13); |
|---|
| 486 | foo.execute_front(); |
|---|
| 487 | QT_CHECK_EQUAL(global, 14); |
|---|
| 488 | foo.execute_front(); |
|---|
| 489 | QT_CHECK_EQUAL(global, 15); |
|---|
| 490 | foo.execute_front(); |
|---|
| 491 | QT_CHECK_EQUAL(global, 16); |
|---|
| 492 | foo.execute_front(); |
|---|
| 493 | QT_CHECK_EQUAL(global, 17); |
|---|
| 494 | } |
|---|
| 495 | { |
|---|
| 496 | mil::Tls tls(0); |
|---|
| 497 | global = 3; |
|---|
| 498 | TestModuleType foo; |
|---|
| 499 | Plus5_3Times p5_3; |
|---|
| 500 | foo.post(p5_3, dummy); |
|---|
| 501 | QT_CHECK_EQUAL(global, 3); |
|---|
| 502 | foo.execute_front(); |
|---|
| 503 | QT_CHECK_EQUAL(global, 8); |
|---|
| 504 | foo.execute_front(); |
|---|
| 505 | QT_CHECK_EQUAL(global, 13); |
|---|
| 506 | foo.execute_front(); |
|---|
| 507 | QT_CHECK_EQUAL(global, 18); |
|---|
| 508 | foo.execute_front(); |
|---|
| 509 | QT_CHECK_EQUAL(global, 18); |
|---|
| 510 | foo.execute_front(); |
|---|
| 511 | QT_CHECK_EQUAL(global, 18); |
|---|
| 512 | } |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | |
|---|
| 516 | |
|---|
| 517 | template <typename TestModuleType> |
|---|
| 518 | void ttest2() { |
|---|
| 519 | TestModuleType poster; |
|---|
| 520 | |
|---|
| 521 | { |
|---|
| 522 | TestModuleType t; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | { |
|---|
| 526 | TestModuleType t; |
|---|
| 527 | t.start(); |
|---|
| 528 | } |
|---|
| 529 | |
|---|
| 530 | { |
|---|
| 531 | global = 0; |
|---|
| 532 | TestModuleType t; |
|---|
| 533 | Plus5 e; |
|---|
| 534 | t.start(); |
|---|
| 535 | sleep(1); |
|---|
| 536 | t.post(e, poster); |
|---|
| 537 | sleep(1); |
|---|
| 538 | QT_CHECK_EQUAL(global, 5); |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | { |
|---|
| 542 | global = 0; |
|---|
| 543 | TestModuleType t; |
|---|
| 544 | BarEvent e; |
|---|
| 545 | e.value = 1; |
|---|
| 546 | t.start(); |
|---|
| 547 | sleep(1); |
|---|
| 548 | t.post(e, poster); |
|---|
| 549 | sleep(1); |
|---|
| 550 | QT_CHECK_EQUAL(global, 1); |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | { |
|---|
| 554 | global = 0; |
|---|
| 555 | TestModuleType t; |
|---|
| 556 | BarEvent2 e2; |
|---|
| 557 | BarEvent3 e3; |
|---|
| 558 | BarEvent4 e4; |
|---|
| 559 | BarEvent5 e5; |
|---|
| 560 | e2.value = 2; |
|---|
| 561 | e3.value = 3; |
|---|
| 562 | e4.value = 4; |
|---|
| 563 | e5.value = 5; |
|---|
| 564 | t.start(); |
|---|
| 565 | sleep(1); |
|---|
| 566 | |
|---|
| 567 | t.post(e2, poster); |
|---|
| 568 | sleep(1); |
|---|
| 569 | QT_CHECK_EQUAL(global, 2); |
|---|
| 570 | t.post(e3, poster); |
|---|
| 571 | sleep(1); |
|---|
| 572 | QT_CHECK_EQUAL(global, 3); |
|---|
| 573 | t.post(e4, poster); |
|---|
| 574 | sleep(1); |
|---|
| 575 | QT_CHECK_EQUAL(global, 4); |
|---|
| 576 | t.post(e5, poster); |
|---|
| 577 | sleep(1); |
|---|
| 578 | QT_CHECK_EQUAL(global, 5); |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | { |
|---|
| 582 | global = 0; |
|---|
| 583 | TestModuleType t; |
|---|
| 584 | Plus5 e; |
|---|
| 585 | t.start(); |
|---|
| 586 | sleep(1); |
|---|
| 587 | for (int i = 0; i < 50; i++) { |
|---|
| 588 | t.post(e, poster); |
|---|
| 589 | } |
|---|
| 590 | sleep(1); |
|---|
| 591 | QT_CHECK_EQUAL(global, 50 * 5); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | { |
|---|
| 595 | global = 0; |
|---|
| 596 | TestModuleType t1; |
|---|
| 597 | TestModuleType t2; |
|---|
| 598 | Plus5 e; |
|---|
| 599 | t1.start(); |
|---|
| 600 | sleep(1); |
|---|
| 601 | for (int i = 0; i < 50; i++) { |
|---|
| 602 | t1.post(e, poster); |
|---|
| 603 | } |
|---|
| 604 | sleep(1); |
|---|
| 605 | QT_CHECK_EQUAL(global, 50 * 5); |
|---|
| 606 | global = 0; |
|---|
| 607 | t2.start(); |
|---|
| 608 | sleep(1); |
|---|
| 609 | for (int i = 0; i < 60; i++) { |
|---|
| 610 | t2.post(e, poster); |
|---|
| 611 | } |
|---|
| 612 | sleep(1); |
|---|
| 613 | QT_CHECK_EQUAL(global, 60 * 5); |
|---|
| 614 | } |
|---|
| 615 | |
|---|
| 616 | { |
|---|
| 617 | Plus5 e; |
|---|
| 618 | TestModuleType foo[3]; |
|---|
| 619 | for (unsigned i = 0; i < _countof(foo); i++) { |
|---|
| 620 | foo[i].start(); |
|---|
| 621 | } |
|---|
| 622 | { |
|---|
| 623 | global = 0; |
|---|
| 624 | TestModuleType bar[_countof(foo)]; |
|---|
| 625 | for (unsigned i = 0; i < _countof(foo); i++) { |
|---|
| 626 | bar[i].start(); |
|---|
| 627 | } |
|---|
| 628 | sleep(1); |
|---|
| 629 | for (int i = 0; i < 50; i++) { |
|---|
| 630 | foo[i % _countof(foo)].post(e, poster); |
|---|
| 631 | bar[i % _countof(foo)].post(e, poster); |
|---|
| 632 | } |
|---|
| 633 | sleep(1); |
|---|
| 634 | QT_CHECK_EQUAL(global, 50 * 2 * 5); |
|---|
| 635 | } |
|---|
| 636 | |
|---|
| 637 | { |
|---|
| 638 | global = 0; |
|---|
| 639 | TestModuleType bar[_countof(foo)]; |
|---|
| 640 | TestModuleType baz[_countof(foo)]; |
|---|
| 641 | for (unsigned i = 0; i < _countof(foo); i++) { |
|---|
| 642 | bar[i].start(); |
|---|
| 643 | baz[i].start(); |
|---|
| 644 | } |
|---|
| 645 | sleep(1); |
|---|
| 646 | for (unsigned i = 0; i < 3000; i++) { |
|---|
| 647 | foo[(i + 1) % _countof(foo)].post(e, poster); |
|---|
| 648 | bar[(i + 1) % _countof(foo)].post(e, poster); |
|---|
| 649 | baz[(i + 3) % _countof(foo)].post(e, poster); |
|---|
| 650 | } |
|---|
| 651 | sleep(1); |
|---|
| 652 | QT_CHECK_EQUAL(global, 3000 * 2 * 5); |
|---|
| 653 | } |
|---|
| 654 | } |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | template <typename TestModuleType> |
|---|
| 658 | void ttest4() { |
|---|
| 659 | TestModuleType poster; |
|---|
| 660 | { |
|---|
| 661 | auto_ptr<TestModuleType> t(new TestModuleType); |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | { |
|---|
| 665 | auto_ptr<TestModuleType> t(new TestModuleType); |
|---|
| 666 | t->start(); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | { |
|---|
| 670 | global = 0; |
|---|
| 671 | auto_ptr<TestModuleType> t(new TestModuleType); |
|---|
| 672 | Plus5 e; |
|---|
| 673 | t->start(); |
|---|
| 674 | sleep(1); |
|---|
| 675 | t->post(e, poster); |
|---|
| 676 | sleep(1); |
|---|
| 677 | QT_CHECK_EQUAL(global, 5); |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | { |
|---|
| 681 | global = 0; |
|---|
| 682 | auto_ptr<TestModuleType> t(new TestModuleType); |
|---|
| 683 | Plus5 e; |
|---|
| 684 | t->start(); |
|---|
| 685 | sleep(1); |
|---|
| 686 | for (int i = 0; i < 50; i++) { |
|---|
| 687 | t->post(e, poster); |
|---|
| 688 | } |
|---|
| 689 | sleep(1); |
|---|
| 690 | QT_CHECK_EQUAL(global, 50 * 5); |
|---|
| 691 | } |
|---|
| 692 | |
|---|
| 693 | { |
|---|
| 694 | global = 0; |
|---|
| 695 | auto_ptr<TestModuleType> t1(new TestModuleType); |
|---|
| 696 | auto_ptr<TestModuleType> t2(new TestModuleType); |
|---|
| 697 | Plus5 e; |
|---|
| 698 | t1->start(); |
|---|
| 699 | sleep(1); |
|---|
| 700 | for (int i = 0; i < 50; i++) { |
|---|
| 701 | t1->post(e, poster); |
|---|
| 702 | } |
|---|
| 703 | sleep(1); |
|---|
| 704 | QT_CHECK_EQUAL(global, 50 * 5); |
|---|
| 705 | global = 0; |
|---|
| 706 | t2->start(); |
|---|
| 707 | sleep(1); |
|---|
| 708 | for (int i = 0; i < 60; i++) { |
|---|
| 709 | t2->post(e, poster); |
|---|
| 710 | } |
|---|
| 711 | sleep(1); |
|---|
| 712 | QT_CHECK_EQUAL(global, 60 * 5); |
|---|
| 713 | } |
|---|
| 714 | |
|---|
| 715 | { |
|---|
| 716 | Plus5 e; |
|---|
| 717 | int foo[3] = {}; |
|---|
| 718 | |
|---|
| 719 | { |
|---|
| 720 | global = 0; |
|---|
| 721 | auto_ptr<TestModuleType> bar[_countof(foo)]; |
|---|
| 722 | auto_ptr<TestModuleType> baz[_countof(foo)]; |
|---|
| 723 | for (thread::id_t i = 0; i < _countof(foo); i++) { |
|---|
| 724 | bar[i] = auto_ptr<TestModuleType>(new TestModuleType); |
|---|
| 725 | baz[i] = auto_ptr<TestModuleType>(new TestModuleType); |
|---|
| 726 | bar[i]->start(); |
|---|
| 727 | baz[i]->start(); |
|---|
| 728 | } |
|---|
| 729 | sleep(2); |
|---|
| 730 | for (thread::id_t i = 0; i < 3000; i++) { |
|---|
| 731 | bar[(i + 1) % _countof(foo)]->post(e, poster); |
|---|
| 732 | baz[(i + 3) % _countof(foo)]->post(e, poster); |
|---|
| 733 | } |
|---|
| 734 | sleep(2); |
|---|
| 735 | QT_CHECK_EQUAL(global, 3000 * 2 * 5); |
|---|
| 736 | } |
|---|
| 737 | } |
|---|
| 738 | } |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | template <typename TestModuleType> |
|---|
| 743 | void ttest3() { |
|---|
| 744 | DummyModule dummy; |
|---|
| 745 | global = 0; |
|---|
| 746 | TestModuleType t; |
|---|
| 747 | TestModuleType t2; |
|---|
| 748 | Plus5 e; |
|---|
| 749 | t.start(); |
|---|
| 750 | sleep(1); |
|---|
| 751 | for (int i = 0; i < 50; i++) { |
|---|
| 752 | t.post(e, dummy); |
|---|
| 753 | } |
|---|
| 754 | sleep(1); |
|---|
| 755 | QT_CHECK_EQUAL(global, 50 * 5); |
|---|
| 756 | } |
|---|
| 757 | |
|---|
| 758 | QT_TEST(test_Module) { |
|---|
| 759 | using namespace module_test; |
|---|
| 760 | test2<FooModule>(); |
|---|
| 761 | test2<FooSingleThreadedUIModule>(); |
|---|
| 762 | test<FooModule>(); |
|---|
| 763 | test<FooSingleThreadedUIModule>(); |
|---|
| 764 | ttest2<FooUIModule>(); |
|---|
| 765 | ttest2<FooModule>(); |
|---|
| 766 | ttest3<FooUIModule>(); |
|---|
| 767 | ttest3<FooModule>(); |
|---|
| 768 | ttest4<FooUIModule>(); |
|---|
| 769 | ttest4<FooModule>(); |
|---|
| 770 | |
|---|
| 771 | FooModule::test_event_sfinae(); |
|---|
| 772 | FooUIModule::test_event_sfinae(); |
|---|
| 773 | FooSingleThreadedUIModule::test_event_sfinae(); |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | } |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | namespace module_test2 { |
|---|
| 780 | |
|---|
| 781 | static int global = 0; |
|---|
| 782 | struct Plus6 { |
|---|
| 783 | int pad[5]; |
|---|
| 784 | }; |
|---|
| 785 | |
|---|
| 786 | |
|---|
| 787 | struct FooModule : mil::Module<FooModule> { |
|---|
| 788 | void execute(Plus6& e) { |
|---|
| 789 | global += 6; |
|---|
| 790 | } |
|---|
| 791 | }; |
|---|
| 792 | |
|---|
| 793 | struct BarModule : mil::Module<FooModule> { |
|---|
| 794 | }; |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | QT_TEST(test_Thread0809) { |
|---|
| 798 | BarModule bar; |
|---|
| 799 | FooModule foo; |
|---|
| 800 | Plus6 e; |
|---|
| 801 | foo.post(e, bar); |
|---|
| 802 | } |
|---|
| 803 | |
|---|
| 804 | QT_TEST(test_Thread08099) { |
|---|
| 805 | BarModule bar; |
|---|
| 806 | FooModule foo; |
|---|
| 807 | Plus6 e; |
|---|
| 808 | foo.start(); |
|---|
| 809 | sleep(1); |
|---|
| 810 | for (int i = 0; i < 200; i++) { |
|---|
| 811 | foo.post(e, bar); |
|---|
| 812 | } |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | QT_TEST(test_forscopeaadfadf) { |
|---|
| 816 | struct ForScopeChecker { |
|---|
| 817 | ForScopeChecker() { |
|---|
| 818 | global = 0; |
|---|
| 819 | } |
|---|
| 820 | ~ForScopeChecker() { |
|---|
| 821 | global = 1; |
|---|
| 822 | } |
|---|
| 823 | }; |
|---|
| 824 | |
|---|
| 825 | { |
|---|
| 826 | int c = 8; |
|---|
| 827 | for (ForScopeChecker c; false;) { |
|---|
| 828 | } |
|---|
| 829 | c = c / 5 % 8 * 124; |
|---|
| 830 | } |
|---|
| 831 | |
|---|
| 832 | { |
|---|
| 833 | global = 5; |
|---|
| 834 | for (ForScopeChecker c;;) { |
|---|
| 835 | QT_CHECK_EQUAL(global, 0); |
|---|
| 836 | break; |
|---|
| 837 | } |
|---|
| 838 | QT_CHECK_EQUAL(global, 1); |
|---|
| 839 | } |
|---|
| 840 | } |
|---|
| 841 | |
|---|
| 842 | QT_TEST(test_Thread080889) { |
|---|
| 843 | BarModule bar; |
|---|
| 844 | FooModule foo; |
|---|
| 845 | Plus6 e; |
|---|
| 846 | foo.start(); |
|---|
| 847 | sleep(1); |
|---|
| 848 | for (int i = 0; i < 200; i++) { |
|---|
| 849 | foo.post(e, bar); |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | QT_TEST(test_Thread080iio889) { |
|---|
| 855 | mil::Mutex m; |
|---|
| 856 | synchronized (m) { |
|---|
| 857 | } |
|---|
| 858 | } |
|---|
| 859 | |
|---|
| 860 | struct Sf { |
|---|
| 861 | typedef SFINAE_CONDITION isSf; |
|---|
| 862 | }; |
|---|
| 863 | |
|---|
| 864 | struct SfSelector { |
|---|
| 865 | template <class T> |
|---|
| 866 | static void func(typename T::isSf) { |
|---|
| 867 | global = 5; |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | template <class T> |
|---|
| 871 | static void func(...) { |
|---|
| 872 | global = 10; |
|---|
| 873 | } |
|---|
| 874 | }; |
|---|
| 875 | |
|---|
| 876 | QT_TEST(test_sfinae1) { |
|---|
| 877 | global = 0; |
|---|
| 878 | SfSelector::func<Sf>(SFINAE_DUMMY_VALUE); |
|---|
| 879 | QT_CHECK_EQUAL(global, 5); |
|---|
| 880 | SfSelector::func<int>(SFINAE_DUMMY_VALUE); |
|---|
| 881 | QT_CHECK_EQUAL(global, 10); |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | QT_TEST(test_cond1) { |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | } |
|---|
| 890 | |
|---|
| 891 | namespace module_test3 { |
|---|
| 892 | |
|---|
| 893 | int global = 0; |
|---|
| 894 | |
|---|
| 895 | struct Plus5 { |
|---|
| 896 | int pad[5]; |
|---|
| 897 | }; |
|---|
| 898 | |
|---|
| 899 | struct FooModule : mil::Module<FooModule> { |
|---|
| 900 | void execute(Plus5& e) { |
|---|
| 901 | global += 5; |
|---|
| 902 | } |
|---|
| 903 | }; |
|---|
| 904 | |
|---|
| 905 | QT_TEST(test_Threa77d0909) { |
|---|
| 906 | FooModule t; |
|---|
| 907 | FooModule t2; |
|---|
| 908 | Plus5 e; |
|---|
| 909 | t.start(); |
|---|
| 910 | sleep(1); |
|---|
| 911 | for (int i = 0; i < 5000; i++) { |
|---|
| 912 | t.post(e, t2); |
|---|
| 913 | } |
|---|
| 914 | } |
|---|
| 915 | |
|---|
| 916 | } |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | namespace module_test4 { |
|---|
| 920 | |
|---|
| 921 | int global = 0; |
|---|
| 922 | atomic<bool> spin; |
|---|
| 923 | |
|---|
| 924 | struct TinyEvent { |
|---|
| 925 | }; |
|---|
| 926 | |
|---|
| 927 | struct SmallEvent { |
|---|
| 928 | short data; |
|---|
| 929 | char pad[mil::pool::private_::BLOCK_SIZE * 1]; |
|---|
| 930 | }; |
|---|
| 931 | |
|---|
| 932 | struct MiddleEvent { |
|---|
| 933 | int data; |
|---|
| 934 | char pad[mil::pool::private_::BLOCK_SIZE * 2]; |
|---|
| 935 | }; |
|---|
| 936 | |
|---|
| 937 | struct BigEvent { |
|---|
| 938 | char pad[500]; |
|---|
| 939 | int data; |
|---|
| 940 | }; |
|---|
| 941 | |
|---|
| 942 | struct Foo : UIModule<Foo> { |
|---|
| 943 | void createGui() { |
|---|
| 944 | this->setWindow(create_window()); |
|---|
| 945 | } |
|---|
| 946 | |
|---|
| 947 | void execute(SmallEvent& e) { |
|---|
| 948 | global += e.data; |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | void execute(BigEvent& e) { |
|---|
| 952 | global++; |
|---|
| 953 | } |
|---|
| 954 | }; |
|---|
| 955 | |
|---|
| 956 | struct Bar : UIModule<Bar> { |
|---|
| 957 | Foo& foo; |
|---|
| 958 | Bar(Foo& foo): foo(foo) { |
|---|
| 959 | } |
|---|
| 960 | void run() { |
|---|
| 961 | this->setWindow(create_window()); |
|---|
| 962 | |
|---|
| 963 | for (int i = 0; i < 5000; i++) { |
|---|
| 964 | SmallEvent e; |
|---|
| 965 | e.data = 5; |
|---|
| 966 | foo.post(e, *this); |
|---|
| 967 | } |
|---|
| 968 | |
|---|
| 969 | spin.store(false); |
|---|
| 970 | |
|---|
| 971 | this->loop(); |
|---|
| 972 | } |
|---|
| 973 | }; |
|---|
| 974 | |
|---|
| 975 | struct Bar2 : UIModule<Bar2> { |
|---|
| 976 | Foo& foo; |
|---|
| 977 | Bar2(Foo& foo): foo(foo) { |
|---|
| 978 | } |
|---|
| 979 | void run() { |
|---|
| 980 | this->setWindow(create_window()); |
|---|
| 981 | while (spin.load()) { |
|---|
| 982 | } |
|---|
| 983 | |
|---|
| 984 | for (int i = 0; i < 500; i++) { |
|---|
| 985 | BigEvent e2; |
|---|
| 986 | foo.post(e2, *this); |
|---|
| 987 | } |
|---|
| 988 | this->loop(); |
|---|
| 989 | } |
|---|
| 990 | }; |
|---|
| 991 | |
|---|
| 992 | struct Bar3 : UIModule<Bar3> { |
|---|
| 993 | Foo& foo; |
|---|
| 994 | Bar3(Foo& foo): foo(foo) { |
|---|
| 995 | } |
|---|
| 996 | void run() { |
|---|
| 997 | this->setWindow(create_window()); |
|---|
| 998 | while (spin.load()) { |
|---|
| 999 | } |
|---|
| 1000 | |
|---|
| 1001 | for (int i = 0; i < 500; i++) { |
|---|
| 1002 | SmallEvent e; |
|---|
| 1003 | e.data = 5; |
|---|
| 1004 | foo.post(e, *this); |
|---|
| 1005 | |
|---|
| 1006 | BigEvent e2; |
|---|
| 1007 | foo.post(e2, *this); |
|---|
| 1008 | } |
|---|
| 1009 | this->loop(); |
|---|
| 1010 | } |
|---|
| 1011 | }; |
|---|
| 1012 | |
|---|
| 1013 | struct Hoge : UIModule<Hoge> { |
|---|
| 1014 | void createGui() { |
|---|
| 1015 | this->setWindow(create_window()); |
|---|
| 1016 | while (spin.load()) {} |
|---|
| 1017 | } |
|---|
| 1018 | void execute(TinyEvent& e) { |
|---|
| 1019 | global++; |
|---|
| 1020 | } |
|---|
| 1021 | void execute(SmallEvent& e) { |
|---|
| 1022 | global += e.data; |
|---|
| 1023 | } |
|---|
| 1024 | void execute(MiddleEvent& e) { |
|---|
| 1025 | global += e.data; |
|---|
| 1026 | } |
|---|
| 1027 | void execute(BigEvent& e) { |
|---|
| 1028 | global += e.data; |
|---|
| 1029 | } |
|---|
| 1030 | }; |
|---|
| 1031 | |
|---|
| 1032 | struct Hige : mil::Module<Hige> { |
|---|
| 1033 | void run() { |
|---|
| 1034 | while (spin.load()) {} |
|---|
| 1035 | this->loop(); |
|---|
| 1036 | } |
|---|
| 1037 | void execute(TinyEvent& e) { |
|---|
| 1038 | global += 2; |
|---|
| 1039 | } |
|---|
| 1040 | void execute(SmallEvent& e) { |
|---|
| 1041 | global += e.data * 2; |
|---|
| 1042 | } |
|---|
| 1043 | void execute(MiddleEvent& e) { |
|---|
| 1044 | global += e.data * 2; |
|---|
| 1045 | } |
|---|
| 1046 | void execute(BigEvent& e) { |
|---|
| 1047 | global += e.data * 2; |
|---|
| 1048 | } |
|---|
| 1049 | }; |
|---|
| 1050 | |
|---|
| 1051 | template <class Receiver> |
|---|
| 1052 | struct Hage : UIModule<Hage<Receiver> > { |
|---|
| 1053 | Receiver& r; |
|---|
| 1054 | Hage(Receiver& r) : r(r) {} |
|---|
| 1055 | void run() { |
|---|
| 1056 | this->setWindow(create_window()); |
|---|
| 1057 | while (spin.load()) {} |
|---|
| 1058 | |
|---|
| 1059 | //for (int i = 0; i < 50; i++) { |
|---|
| 1060 | // TinyEvent t; |
|---|
| 1061 | // r.post(t, *this); |
|---|
| 1062 | //} |
|---|
| 1063 | |
|---|
| 1064 | //sleep(1); |
|---|
| 1065 | |
|---|
| 1066 | for (int i = 0; i < 50; i++) { |
|---|
| 1067 | |
|---|
| 1068 | MiddleEvent m; |
|---|
| 1069 | m.data = 2; |
|---|
| 1070 | BigEvent b; |
|---|
| 1071 | b.data = 4; |
|---|
| 1072 | r.post(m, *this); |
|---|
| 1073 | r.post(b, *this); |
|---|
| 1074 | r.post(m, *this); |
|---|
| 1075 | r.post(b, *this); |
|---|
| 1076 | } |
|---|
| 1077 | sleep(1); |
|---|
| 1078 | this->loop(); |
|---|
| 1079 | } |
|---|
| 1080 | }; |
|---|
| 1081 | |
|---|
| 1082 | template <class Receiver> |
|---|
| 1083 | struct Fuga : mil::Module<Fuga<Receiver> > { |
|---|
| 1084 | Receiver& r; |
|---|
| 1085 | Fuga(Receiver& r) : r(r) {} |
|---|
| 1086 | void run() { |
|---|
| 1087 | while (spin.load()) {} |
|---|
| 1088 | |
|---|
| 1089 | for (int i = 0; i < 50; i++) { |
|---|
| 1090 | TinyEvent t; |
|---|
| 1091 | r.post(t, *this); |
|---|
| 1092 | SmallEvent s; |
|---|
| 1093 | s.data = 8; |
|---|
| 1094 | r.post(s, *this); |
|---|
| 1095 | MiddleEvent m; |
|---|
| 1096 | m.data = 16; |
|---|
| 1097 | r.post(m, *this); |
|---|
| 1098 | BigEvent b; |
|---|
| 1099 | b.data = 32; |
|---|
| 1100 | r.post(b, *this); |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | this->loop(); |
|---|
| 1104 | } |
|---|
| 1105 | }; |
|---|
| 1106 | |
|---|
| 1107 | |
|---|
| 1108 | QT_TEST(test_asdfadfaadfasdfadf) { |
|---|
| 1109 | global = 0; |
|---|
| 1110 | |
|---|
| 1111 | { |
|---|
| 1112 | spin.store(true); |
|---|
| 1113 | Hoge hoge; |
|---|
| 1114 | Hage<Hoge> hage(hoge); |
|---|
| 1115 | hoge.start(); |
|---|
| 1116 | hage.start(); |
|---|
| 1117 | sleep(1); |
|---|
| 1118 | spin.store(false); |
|---|
| 1119 | sleep(1); |
|---|
| 1120 | QT_CHECK_EQUAL(global, 600); |
|---|
| 1121 | } |
|---|
| 1122 | |
|---|
| 1123 | { |
|---|
| 1124 | spin.store(true); |
|---|
| 1125 | Hoge hoge; |
|---|
| 1126 | Fuga<Hoge> fuga(hoge); |
|---|
| 1127 | hoge.start(); |
|---|
| 1128 | fuga.start(); |
|---|
| 1129 | sleep(1); |
|---|
| 1130 | spin.store(false); |
|---|
| 1131 | sleep(1); |
|---|
| 1132 | QT_CHECK_EQUAL(global, 3450); |
|---|
| 1133 | } |
|---|
| 1134 | |
|---|
| 1135 | { |
|---|
| 1136 | spin.store(true); |
|---|
| 1137 | Hige hige; |
|---|
| 1138 | Hage<Hige> hage(hige); |
|---|
| 1139 | hige.start(); |
|---|
| 1140 | hage.start(); |
|---|
| 1141 | sleep(1); |
|---|
| 1142 | spin.store(false); |
|---|
| 1143 | sleep(1); |
|---|
| 1144 | QT_CHECK_EQUAL(global, 4650); |
|---|
| 1145 | } |
|---|
| 1146 | |
|---|
| 1147 | { |
|---|
| 1148 | spin.store(true); |
|---|
| 1149 | Hige hige; |
|---|
| 1150 | Fuga<Hige> fuga(hige); |
|---|
| 1151 | hige.start(); |
|---|
| 1152 | fuga.start(); |
|---|
| 1153 | sleep(1); |
|---|
| 1154 | spin.store(false); |
|---|
| 1155 | sleep(1); |
|---|
| 1156 | QT_CHECK_EQUAL(global, 10350); |
|---|
| 1157 | } |
|---|
| 1158 | } |
|---|
| 1159 | QT_TEST(test_adifjadfioajdfaoidffgzg8) { |
|---|
| 1160 | using namespace module_test4; |
|---|
| 1161 | for (int i = 0; i < 5; i++) { |
|---|
| 1162 | global = 0; |
|---|
| 1163 | { |
|---|
| 1164 | spin.store(true); |
|---|
| 1165 | |
|---|
| 1166 | Foo foo; |
|---|
| 1167 | Bar bar(foo); |
|---|
| 1168 | |
|---|
| 1169 | foo.start(); |
|---|
| 1170 | bar.start(); |
|---|
| 1171 | |
|---|
| 1172 | sleep(1); |
|---|
| 1173 | while (spin.load()) {} |
|---|
| 1174 | } |
|---|
| 1175 | QT_CHECK_EQUAL(global, 25000); |
|---|
| 1176 | } |
|---|
| 1177 | } |
|---|
| 1178 | |
|---|
| 1179 | |
|---|
| 1180 | QT_TEST(test_dasfhsdfsadfoiaaaaaoioio) { |
|---|
| 1181 | using namespace module_test4; |
|---|
| 1182 | global = 0; |
|---|
| 1183 | spin.store(true); |
|---|
| 1184 | |
|---|
| 1185 | Foo foo; |
|---|
| 1186 | Bar2 bar(foo); |
|---|
| 1187 | |
|---|
| 1188 | foo.start(); |
|---|
| 1189 | bar.start(); |
|---|
| 1190 | |
|---|
| 1191 | sleep(1); |
|---|
| 1192 | spin.store(false); |
|---|
| 1193 | sleep(1); |
|---|
| 1194 | QT_CHECK_EQUAL(global, 500); |
|---|
| 1195 | } |
|---|
| 1196 | |
|---|
| 1197 | QT_TEST(test_dasfhsdfsadfoiaaaaaoioioa89) { |
|---|
| 1198 | using namespace module_test4; |
|---|
| 1199 | { |
|---|
| 1200 | global = 0; |
|---|
| 1201 | QT_CHECK_EQUAL(global, 0); |
|---|
| 1202 | spin.store(true); |
|---|
| 1203 | |
|---|
| 1204 | Foo foo; |
|---|
| 1205 | Bar bar(foo); |
|---|
| 1206 | |
|---|
| 1207 | foo.start(); |
|---|
| 1208 | bar.start(); |
|---|
| 1209 | |
|---|
| 1210 | sleep(1); |
|---|
| 1211 | while (spin.load()) {} |
|---|
| 1212 | QT_CHECK_EQUAL(global, 25000); |
|---|
| 1213 | } |
|---|
| 1214 | |
|---|
| 1215 | { |
|---|
| 1216 | global = 0; |
|---|
| 1217 | spin.store(true); |
|---|
| 1218 | |
|---|
| 1219 | Foo foo; |
|---|
| 1220 | Bar2 bar(foo); |
|---|
| 1221 | |
|---|
| 1222 | foo.start(); |
|---|
| 1223 | bar.start(); |
|---|
| 1224 | |
|---|
| 1225 | sleep(1); |
|---|
| 1226 | spin.store(false); |
|---|
| 1227 | sleep(1); |
|---|
| 1228 | QT_CHECK_EQUAL(global, 500); |
|---|
| 1229 | } |
|---|
| 1230 | |
|---|
| 1231 | { |
|---|
| 1232 | global = 0; |
|---|
| 1233 | spin.store(true); |
|---|
| 1234 | |
|---|
| 1235 | Foo foo; |
|---|
| 1236 | Bar3 bar(foo); |
|---|
| 1237 | |
|---|
| 1238 | foo.start(); |
|---|
| 1239 | bar.start(); |
|---|
| 1240 | |
|---|
| 1241 | sleep(1); |
|---|
| 1242 | spin.store(false); |
|---|
| 1243 | sleep(1); |
|---|
| 1244 | QT_CHECK_EQUAL(global, 3000); |
|---|
| 1245 | } |
|---|
| 1246 | } |
|---|
| 1247 | |
|---|
| 1248 | QT_TEST(test_das1223sadfoio) { |
|---|
| 1249 | using namespace module_test4; |
|---|
| 1250 | global = 0; |
|---|
| 1251 | spin.store(true); |
|---|
| 1252 | |
|---|
| 1253 | Foo foo; |
|---|
| 1254 | Bar bar(foo); |
|---|
| 1255 | |
|---|
| 1256 | foo.start(); |
|---|
| 1257 | bar.start(); |
|---|
| 1258 | |
|---|
| 1259 | sleep(1); |
|---|
| 1260 | while (spin.load()) {} |
|---|
| 1261 | QT_CHECK_EQUAL(global, 25000); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | } |
|---|
| 1265 | |
|---|
| 1266 | |
|---|
| 1267 | |
|---|