Remove build dependency to EFL
[platform/core/api/system-settings.git] / unit_test / src / unit_test_fw.c
1 #include <unit_test_fw.h>
2
3 typedef struct __thread_test_table {
4         char * test_name;
5         GTestFunc t_func;
6 } thread_test_node;
7
8 static GThread *my_thread = NULL;
9 static GMainLoop *main_loop = NULL;
10 static thread_test_node thread_test_table[1000] = {0};
11 static int thread_test_idx = 0;
12 static int loop = 100;
13 static int thread_sw = 1;
14
15 void *thread_function(void *data)
16 {
17         int cnt = 0;
18         int test_idx = (int)data;
19
20         while (thread_sw) {
21                 if (cnt > loop)
22                         break;
23                 cnt++;
24                 thread_test_table[test_idx].t_func();
25                 sleep(0);
26         }
27
28         return 0;
29
30 }
31
32 static GThread **unit_test_thread_start(int test_num)
33 {
34         int i;
35         GThread **thread_list = (GThread **)calloc(sizeof(GThread*), N_THREADS);
36         for (i = 0; i < N_THREADS; i++) {
37                 thread_list[i] = g_thread_new(NULL, thread_function, (void*)test_num);
38         }
39         return thread_list;
40 }
41
42 static void unit_test_thread_stop(GThread **thread_list)
43 {
44         int i;
45         for (i = 0; i < N_THREADS; i++) {
46                 g_thread_join(thread_list[i]);
47         }
48
49         g_free(thread_list);
50 }
51
52 static void unit_thread_test()
53 {
54         int i;
55         GThread **thread_test[MAX_TEST_CASE];
56
57         printf("START!!!! thread test for system-settings %d tests\n", thread_test_idx);
58
59         thread_sw = 1;
60         for (i = 0; i < thread_test_idx; i++) {
61                 thread_test[i] = unit_test_thread_start(i);
62                 printf("%3d %s:start!\n", i, thread_test_table[i].test_name);
63
64                 unit_test_thread_stop(thread_test[i]);
65                 printf("%3d %s:OK\n", i, thread_test_table[i].test_name);
66         }
67
68         printf("END!!!! thread test for system-settings\n");
69 }
70
71 static gpointer loop_func(gpointer data)
72 {
73         g_main_loop_run(main_loop);
74         return NULL;
75 }
76
77 static void start_main_loop_thread()
78 {
79         my_thread = g_thread_new(NULL, loop_func, NULL);
80 }
81
82 static void stop_main_loop_thread()
83 {
84         g_main_loop_quit(main_loop);
85         g_thread_join(my_thread);
86         g_main_loop_unref(main_loop);
87 }
88
89
90 int main(int argc, char* argv[])
91 {
92         main_loop = g_main_loop_new(NULL, FALSE);
93
94         g_test_init(&argc, &argv, NULL);
95         g_test_set_nonfatal_assertions();
96
97         start_main_loop_thread();
98
99         unittest_api();
100
101         g_test_run();
102         unit_thread_test();
103
104         stop_main_loop_thread();
105         return 0;
106 }
107
108 void add_test_func(char * test_name,  GTestFunc func_pointer)
109 {
110         g_test_add_func(test_name, func_pointer);
111
112         thread_test_table[thread_test_idx].test_name = test_name;
113         thread_test_table[thread_test_idx].t_func = func_pointer;
114
115         thread_test_idx++;
116 }
117