MCPcopy Create free account
hub / github.com/comaps/comaps / UNIT_TEST

Function UNIT_TEST

libs/base/base_tests/threaded_list_test.cpp:40–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38};
39
40UNIT_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}

Callers

nothing calls this directly

Calls 6

SleepFunction · 0.85
frontMethod · 0.80
CreateMethod · 0.45
PushBackMethod · 0.45
CancelMethod · 0.45
JoinMethod · 0.45

Tested by

no test coverage detected