123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "tests/ThreadTests.h"
- #include "test/Test.h"
- #include "thread/Thread.h"
- static int runDone = 0;
- struct IntHolder {
- int value;
- };
- static int run(void*) {
- runDone = 1;
- return 7;
- }
- static void testStart() {
- runDone = 0;
- Core::Thread::Id id = Core::Thread::INVALID_ID;
- CORE_TEST_ERROR(Core::Thread::start(id, run, nullptr));
- int returnValue = 0;
- CORE_TEST_ERROR(Core::Thread::join(id, &returnValue));
- CORE_TEST_EQUAL(1, runDone);
- CORE_TEST_EQUAL(7, returnValue);
- }
- static void testLambda() {
- IntHolder i(0);
- Core::Thread::Id id = Core::Thread::INVALID_ID;
- CORE_TEST_ERROR(Core::Thread::start(
- id,
- [](void* p) {
- IntHolder* ip = static_cast<IntHolder*>(p);
- ip->value = 2;
- return 0;
- },
- &i));
- CORE_TEST_ERROR(Core::Thread::join(id, nullptr));
- CORE_TEST_EQUAL(2, i.value);
- }
- void Core::ThreadTests::test() {
- testStart();
- testLambda();
- }
|