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

Function TestGuiExecutorImpl

CobaltFusionTest/TestGuiExecutor.cpp:17–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 4

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

Tested by

no test coverage detected