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