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