1#include <gtest/gtest.h>
2
3#include "AllocationTestHarness.h"
4
5#include <sys/select.h>
6
7#include "osi/include/osi.h"
8#include "osi/include/reactor.h"
9#include "osi/include/thread.h"
10
11class ThreadTest : public AllocationTestHarness {};
12
13TEST_F(ThreadTest, test_new_simple) {
14  thread_t* thread = thread_new("test_thread");
15  ASSERT_TRUE(thread != NULL);
16  thread_free(thread);
17}
18
19TEST_F(ThreadTest, test_free_simple) {
20  thread_t* thread = thread_new("test_thread");
21  thread_free(thread);
22}
23
24TEST_F(ThreadTest, test_name) {
25  thread_t* thread = thread_new("test_name");
26  ASSERT_STREQ(thread_name(thread), "test_name");
27  thread_free(thread);
28}
29
30TEST_F(ThreadTest, test_long_name) {
31  thread_t* thread = thread_new("0123456789abcdef");
32  ASSERT_STREQ("0123456789abcdef", thread_name(thread));
33  thread_free(thread);
34}
35
36TEST_F(ThreadTest, test_very_long_name) {
37  thread_t* thread = thread_new("0123456789abcdefg");
38  ASSERT_STREQ("0123456789abcdef", thread_name(thread));
39  thread_free(thread);
40}
41
42static void thread_is_self_fn(void* context) {
43  thread_t* thread = (thread_t*)context;
44  EXPECT_TRUE(thread_is_self(thread));
45}
46
47TEST_F(ThreadTest, test_thread_is_self) {
48  thread_t* thread = thread_new("test_thread");
49  thread_post(thread, thread_is_self_fn, thread);
50  thread_free(thread);
51}
52
53TEST_F(ThreadTest, test_thread_is_not_self) {
54  thread_t* thread = thread_new("test_thread");
55  EXPECT_FALSE(thread_is_self(thread));
56  thread_free(thread);
57}
58