| 38 | }; |
| 39 | |
| 40 | UNIT_TEST(ThreadedList) |
| 41 | { |
| 42 | std::mutex resMutex; |
| 43 | std::list<int> res; |
| 44 | |
| 45 | ThreadedList<int> p; |
| 46 | |
| 47 | threads::Thread t0; |
| 48 | t0.Create(std::make_unique<ThreadedListProcessor>(p, resMutex, res, 0)); |
| 49 | |
| 50 | threads::Thread t1; |
| 51 | t1.Create(std::make_unique<ThreadedListProcessor>(p, resMutex, res, 1)); |
| 52 | |
| 53 | threads::Thread t2; |
| 54 | t2.Create(std::make_unique<ThreadedListProcessor>(p, resMutex, res, 2)); |
| 55 | |
| 56 | p.PushBack(0); |
| 57 | threads::Sleep(200); |
| 58 | |
| 59 | p.PushBack(1); |
| 60 | threads::Sleep(200); |
| 61 | |
| 62 | p.PushBack(2); |
| 63 | threads::Sleep(200); |
| 64 | |
| 65 | p.Cancel(); |
| 66 | |
| 67 | t0.Join(); |
| 68 | t1.Join(); |
| 69 | t2.Join(); |
| 70 | |
| 71 | TEST_EQUAL(res.front(), 0, ()); |
| 72 | res.pop_front(); |
| 73 | TEST_EQUAL(res.front(), 1, ()); |
| 74 | res.pop_front(); |
| 75 | TEST_EQUAL(res.front(), 2, ()); |
| 76 | res.pop_front(); |
| 77 | } |