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