diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 12:29:24 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 12:29:24 +0100 |
commit | e671adba5a57e1d4e848eb4d6de0f480e7b3709a (patch) | |
tree | cb4e9009379ba3b48a8606fada5006a959063dee /test | |
parent | New WorkItem/job/promise/future based interface (diff) | |
download | ilt-e671adba5a57e1d4e848eb4d6de0f480e7b3709a.tar.bz2 ilt-e671adba5a57e1d4e848eb4d6de0f480e7b3709a.tar.xz ilt-e671adba5a57e1d4e848eb4d6de0f480e7b3709a.zip |
Simplify doWork, add tests for various interface uses
Diffstat (limited to 'test')
-rw-r--r-- | test/test-worker.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/test/test-worker.cpp b/test/test-worker.cpp index c542020..319261b 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -14,6 +14,19 @@ workCounter() return n++; } +void +workVoid() +{ + usleep(1000); +} + +void +workFail() +{ + usleep(1000); + throw std::runtime_error {"test"}; +} + BOOST_AUTO_TEST_CASE(basic_slow_counter) { std::vector<Worker::WorkPtrT<uint32_t>> ps; @@ -31,14 +44,40 @@ BOOST_AUTO_TEST_CASE(basic_slow_counter) BOOST_AUTO_TEST_CASE(basic_error_handler) { - auto workitem = Worker::addWork([]() { - throw std::runtime_error {"test"}; - }); + auto workitem = Worker::addWork(workFail); BOOST_CHECK_THROW(workitem->get(), std::runtime_error); } BOOST_AUTO_TEST_CASE(basic_void_work) { - auto workitem = Worker::addWork([]() {}); + auto workitem = Worker::addWork(workVoid); BOOST_CHECK_NO_THROW(workitem->get()); } + +BOOST_AUTO_TEST_CASE(lambda_void) +{ + BOOST_CHECK_NO_THROW(Worker::addWork([]() {})->get()); + BOOST_CHECK_NO_THROW(Worker::addWork([](int) {}, 0)->get()); + BOOST_CHECK_NO_THROW(Worker::addWork([](int, int) {}, 0, 0)->get()); +} + +BOOST_AUTO_TEST_CASE(lambda_value) +{ + BOOST_CHECK_EQUAL(1, Worker::addWork([]() { + return 1; + })->get()); + BOOST_CHECK_EQUAL(2, + Worker::addWork( + [](int i) { + return i; + }, + 2) + ->get()); + BOOST_CHECK_EQUAL(3, + Worker::addWork( + [](int i, int j) { + return i + j; + }, + 1, 2) + ->get()); +} |