thread_test.cpp revision 118bdd58389c77dd69b37e377b4e98ea89d2b14e
1#include <gtest/gtest.h> 2 3extern "C" { 4#include "thread.h" 5#include "osi.h" 6} 7 8void *start_routine(void *arg) 9{ 10 return arg; 11} 12 13TEST(ThreadTest, test_new_simple) { 14 thread_t *thread = thread_create("test_thread", &start_routine, NULL); 15 ASSERT_TRUE(thread != NULL); 16 thread_join(thread, NULL); 17} 18 19TEST(ThreadTest, test_join_simple) { 20 thread_t *thread = thread_create("test_thread", &start_routine, NULL); 21 thread_join(thread, NULL); 22} 23 24TEST(ThreadTest, test_name) { 25 thread_t *thread = thread_create("test_name", &start_routine, NULL); 26 ASSERT_STREQ(thread_name(thread), "test_name"); 27 thread_join(thread, NULL); 28} 29 30TEST(ThreadTest, test_long_name) { 31 thread_t *thread = thread_create("0123456789abcdef", &start_routine, NULL); 32 ASSERT_STREQ("0123456789abcdef", thread_name(thread)); 33 thread_join(thread, NULL); 34} 35 36TEST(ThreadTest, test_very_long_name) { 37 thread_t *thread = thread_create("0123456789abcdefg", &start_routine, NULL); 38 ASSERT_STREQ("0123456789abcdef", thread_name(thread)); 39 thread_join(thread, NULL); 40} 41 42TEST(ThreadTest, test_return) { 43 int arg = 10; 44 void *ret; 45 thread_t *thread = thread_create("test", &start_routine, &arg); 46 thread_join(thread, &ret); 47 ASSERT_EQ(ret, &arg); 48} 49