add license
[apps/native/boot-animation.git] / test / unit / unit_test / unit_test_function_test / unit_test_unit_function.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "../../../../inc/test.h"
19 #if (TEST_MODE == TEST_UNIT)
20
21 #include "unit_test_function.h"
22 #include "../unit_test_append_log/unit_test_append_log.h"
23
24 extern unit_result_t * __t__get_unit_result(void);
25
26 static Eina_Bool __unit_test_uint_result(void);
27 static Eina_Bool __unit_test_unit_init(void);
28 static Eina_Bool __unit_test_unit_fini(void);
29
30 void unit_test_unit_function(void)
31 {
32         __unit_test_run_function(__unit_test_uint_result() == EINA_TRUE);
33         __unit_test_run_function(__unit_test_unit_init() == EINA_TRUE);
34         __unit_test_run_function(__unit_test_unit_fini() == EINA_TRUE);
35 }
36
37 static Eina_Bool __unit_test_uint_result(void)
38 {
39         unit_result_t * result = unit_result_new();
40
41         TEST_ASSERT_EQUAL_INT(0, result->ran_case);
42         TEST_ASSERT_EQUAL_INT(0, result->passed);
43         TEST_ASSERT_EQUAL_INT(0, result->failed);
44
45         int i = 0;
46         for (i = 0; i < 3; i++) unit_result_pass(result);
47         for (i = 0; i < 2; i++) unit_result_fail(result);
48         for (i = 0; i < 3; i++) unit_result_pass(result);
49         for (i = 0; i < 2; i++) unit_result_fail(result);
50         for (i = 0; i < 3; i++) unit_result_pass(result);
51         for (i = 0; i < 2; i++) unit_result_fail(result);
52
53         TEST_ASSERT_EQUAL_INT(15, result->ran_case);
54         TEST_ASSERT_EQUAL_INT(9, result->passed);
55         TEST_ASSERT_EQUAL_INT(6, result->failed);
56
57         unit_result_t * result2 = unit_result_new();
58         for (i = 0; i < 9; i++) unit_result_pass(result2);
59         for (i = 0; i < 8; i++) unit_result_fail(result2);
60
61         TEST_ASSERT_EQUAL_INT(17, result2->ran_case);
62         TEST_ASSERT_EQUAL_INT(9, result2->passed);
63         TEST_ASSERT_EQUAL_INT(8, result2->failed);
64
65         unit_result_add(result, result2);
66
67         TEST_ASSERT_EQUAL_INT(32, result->ran_case);
68         TEST_ASSERT_EQUAL_INT(18, result->passed);
69         TEST_ASSERT_EQUAL_INT(14, result->failed);
70
71         unit_result_init(result);
72
73         TEST_ASSERT_EQUAL_INT(0, result->ran_case);
74         TEST_ASSERT_EQUAL_INT(0, result->passed);
75         TEST_ASSERT_EQUAL_INT(0, result->failed);
76
77         unit_result_del(result2);
78         unit_result_del(result);
79
80         return EINA_TRUE;
81 }
82
83 static Eina_Bool __unit_test_unit_init(void)
84 {
85         unit_clear_log();
86
87         int i = 0;
88         unit_result_t * result = __t__get_unit_result();
89         unit_result_init(result);
90
91         for (i = 0; i < 9; i++) unit_result_pass(result);
92         for (i = 0; i < 8; i++) unit_result_fail(result);
93         TEST_ASSERT_EQUAL_INT(8, result->failed);
94         TEST_ASSERT_EQUAL_INT(9, result->passed);
95         TEST_ASSERT_EQUAL_INT(17, result->ran_case);
96
97         unit_init();
98
99         TEST_ASSERT_EQUAL_INT(0, result->failed);
100         TEST_ASSERT_EQUAL_INT(0, result->passed);
101         TEST_ASSERT_EQUAL_INT(0, result->ran_case);
102
103         char buf[1024] = { 0, };
104         unit_test_log_append_unit_init(buf);
105         TEST_ASSERT_EQUAL_LOG(buf);
106
107         return EINA_TRUE;
108 }
109
110 static Eina_Bool __unit_test_unit_fini(void)
111 {
112         unit_init();
113         unit_clear_log();
114
115         int i = 0;
116         unit_result_t * result = __t__get_unit_result();
117         for (i = 0; i < 9; i++) unit_result_pass(result);
118         for (i = 0; i < 8; i++) unit_result_fail(result);
119         TEST_ASSERT_EQUAL_INT(8, result->failed);
120         TEST_ASSERT_EQUAL_INT(9, result->passed);
121         TEST_ASSERT_EQUAL_INT(17, result->ran_case);
122
123         char buf[1024] = { 0, };
124         unit_test_log_append_unit_fini(buf, result);
125
126         unit_fini();
127         TEST_ASSERT_EQUAL_LOG(buf);
128
129         unit_clear_log();
130
131         result = __t__get_unit_result();
132         for (i = 0; i < 99; i++) unit_result_pass(result);
133         for (i = 0; i < 88; i++) unit_result_fail(result);
134
135         buf[0] = 0;
136         unit_test_log_append_unit_fini(buf, result);
137
138         unit_fini();
139
140         TEST_ASSERT_EQUAL_LOG(buf);
141
142         return EINA_TRUE;
143 }
144
145 #endif