MCPcopy Create free account
hub / github.com/CobaltFusion/DebugViewPP / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

CobaltFusionTest/TestExecutor.cpp:17–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15BOOST_AUTO_TEST_SUITE(TestExecutor)
16
17BOOST_AUTO_TEST_CASE(TestExecutor)
18{
19 using namespace std::chrono_literals;
20
21 ActiveExecutor exec;
22
23 BOOST_CHECK_EQUAL(exec.Call([]() { return 1 + 1; }), 2);
24 auto f = exec.CallAsync([]() { return 2 + 2; });
25 BOOST_CHECK_EQUAL(f.get(), 4);
26
27 auto now = ActiveExecutor::Clock::now();
28
29 std::vector<int> vec;
30 auto timer = exec.CallAt(now + 600ms, [&vec]() { vec.push_back(10); });
31 exec.CallAt(now + 504ms, [&vec]() { vec.push_back(4); });
32 exec.CallAt(now + 501ms, [&vec]() { vec.push_back(1); });
33 exec.CallAt(now + 503ms, [&vec]() { vec.push_back(3); });
34 exec.CallAt(now + 502ms, [&vec]() { vec.push_back(2); });
35 exec.Call([&vec]() { vec.push_back(0); });
36
37 // Cancel needs to excute within 600 ms. The 600ms needs to elapse within the 1 s sleep.
38 // If not, the additional 10 will be appended to vec.
39 // Longer delays help for test robustness but slows down testing.
40 timer.Cancel();
41 std::this_thread::sleep_for(1s);
42
43 int results[] = { 0, 1, 2, 3, 4 };
44 BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(vec), std::end(vec), std::begin(results), std::end(results));
45}
46
47BOOST_AUTO_TEST_SUITE_END()
48

Callers

nothing calls this directly

Calls 4

CallMethod · 0.45
CallAsyncMethod · 0.45
CallAtMethod · 0.45
CancelMethod · 0.45

Tested by

no test coverage detected