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