1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/tests/test_worker.cpp
2016-09-09 21:13:22 +01:00

50 lines
956 B
C++

#include <boost/test/unit_test.hpp>
#include <job/WorkContext.hpp>
class TestJob : public WorkJob {
public:
bool *_worked, *_completed;
TestJob(WorkContext *context, bool *w, bool *c)
: WorkJob(context), _worked(w), _completed(c) {
}
void work() {
*_worked = true;
}
void complete() {
*_completed = true;
}
};
BOOST_AUTO_TEST_SUITE(WorkTests)
BOOST_AUTO_TEST_CASE(test_interface) {
{
WorkContext context;
bool worked = false, completed = false;
TestJob *job = new TestJob(&context, &worked, &completed);
BOOST_CHECK(!worked);
BOOST_CHECK(!completed);
context.queueJob(job);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
BOOST_CHECK(worked);
BOOST_CHECK(!completed);
context.update();
;
BOOST_CHECK(worked);
BOOST_CHECK(completed);
}
}
BOOST_AUTO_TEST_SUITE_END()