| 25 | #include "platform/threads/thread.h" |
| 26 | |
| 27 | TEST(Thread, CallbackAPI) |
| 28 | { |
| 29 | #define VALUE_TO_SET 10 |
| 30 | |
| 31 | // This struct exists just so we can define run as a local function. |
| 32 | struct thread |
| 33 | { |
| 34 | // Do some work we can observe. |
| 35 | static void body(void* arg) |
| 36 | { |
| 37 | U32* value = reinterpret_cast<U32*>(arg); |
| 38 | *value = VALUE_TO_SET; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | // Test most basic Thread API functions. |
| 43 | U32 value = ~VALUE_TO_SET; |
| 44 | Thread thread(&thread::body, reinterpret_cast<void*>(&value)); |
| 45 | thread.start(); |
| 46 | EXPECT_TRUE(thread.isAlive()); |
| 47 | thread.join(); |
| 48 | EXPECT_FALSE(thread.isAlive()); |
| 49 | |
| 50 | EXPECT_EQ(value, VALUE_TO_SET) |
| 51 | << "Thread did not set expected value!"; |
| 52 | |
| 53 | #undef VALUE_TO_SET |
| 54 | } |
| 55 | |
| 56 | TEST(Thread, InheritanceAPI) |
| 57 | { |