57a7abaf668d6b1092e72c0019ddd014792b61f7
[platform/core/uifw/libtdm.git] / ut / src / ut_tdm.cpp
1 /**************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
4  *
5  * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27 **************************************************************************/
28
29 #include "gtest/gtest.h"
30
31 #include "tbm_stubs.h"
32 #include "stub_pthread.h"
33 #include "stub_stdlib.h"
34
35 #include "tdm.c"
36
37 #include "tdm_private.h"
38
39 static tdm_private_display ut_private_display;
40
41 static void _init_test()
42 {
43         stub_pthread_init();
44         stub_tbm_init();
45         stub_stdlib_init();
46
47         g_private_display = NULL;
48 }
49
50 /* tdm_display_update */
51
52 TEST(tdm_display_update, work_flow_success_1)
53 {
54         tdm_error error = TDM_ERROR_NONE;
55         tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
56
57         _init_test();
58
59         error = tdm_display_update(NULL);
60
61         ASSERT_EQ(error, expected_error);
62 }
63
64 /* tdm_display_deinit */
65
66 TEST(tdm_display_deinit, work_flow_success_1)
67 {
68         tdm_private_display *dpy;
69         unsigned int expected = 2;
70         unsigned int actual;
71
72         _init_test();
73
74         dpy = (tdm_private_display *)calloc(1, sizeof(tdm_private_display));
75         g_private_display = dpy;
76         dpy->init_count = 3;
77
78         tdm_display_deinit(dpy);
79
80         actual = dpy->init_count;
81
82         free(dpy);
83
84         ASSERT_NE(g_private_display, NULL);
85         ASSERT_EQ(actual, expected);
86 }
87
88 /* tdm_display_init() */
89 TEST(tdm_display_init, work_flow_success_7)
90 {
91         int actual;
92         int expected = 1;
93
94         _init_test();
95
96         PTHREAD_MUTEX_INIT_ERROR = 1;
97         FREE_CALLED = 0;
98
99         tdm_display_init(NULL);
100
101         actual = FREE_CALLED;
102
103         ASSERT_EQ(actual, expected);
104 }
105
106 TEST(tdm_display_init, work_flow_success_6)
107 {
108         tdm_private_display *actual;
109         tdm_private_display *expected;
110
111         _init_test();
112
113         PTHREAD_MUTEX_INIT_ERROR = 1;
114
115         actual = (tdm_private_display *)tdm_display_init(NULL);
116
117         expected = NULL;
118
119         ASSERT_EQ(actual, expected);
120 }
121
122 TEST(tdm_display_init, work_flow_success_5)
123 {
124         tdm_error error;
125         tdm_error expected_error;
126
127         _init_test();
128
129         error = TDM_ERROR_BAD_REQUEST;
130         PTHREAD_MUTEX_INIT_ERROR = 1;
131
132         tdm_display_init(&error);
133
134         expected_error = TDM_ERROR_OPERATION_FAILED;
135
136         ASSERT_EQ(error, expected_error);
137 }
138
139 TEST(tdm_display_init, work_flow_success_4)
140 {
141         tdm_private_display *actual;
142         tdm_private_display *expected = NULL;
143
144         _init_test();
145
146         CALLOC_ERROR = 1;
147
148         actual = (tdm_private_display *)tdm_display_init(NULL);
149
150         ASSERT_EQ(actual, expected);
151 }
152
153 TEST(tdm_display_init, work_flow_success_3)
154 {
155         tdm_error error = TDM_ERROR_BAD_REQUEST;
156         tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY;
157
158         _init_test();
159
160         CALLOC_ERROR = 1;
161
162         tdm_display_init(&error);
163
164         ASSERT_EQ(error, expected_error);
165 }
166
167 TEST(tdm_display_init, work_flow_success_2)
168 {
169         tdm_error error = TDM_ERROR_BAD_REQUEST;
170         tdm_error expected_error = TDM_ERROR_NONE;
171
172         _init_test();
173
174         g_private_display = &ut_private_display;
175
176         tdm_display_init(&error);
177
178         ASSERT_EQ(error, expected_error);
179 }
180
181 TEST(tdm_display_init, work_flow_success_1)
182 {
183         tdm_private_display *actual;
184         tdm_private_display *expected = &ut_private_display;
185
186         _init_test();
187
188         g_private_display = &ut_private_display;
189
190         actual = (tdm_private_display *)tdm_display_init(NULL);
191
192         ASSERT_TRUE(actual == expected);
193 }