Add new unittest TCs
[platform/core/appfw/widget-service.git] / unittest / src / test_widget_service_instance.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include <stdio.h>
20
21 #include "include/widget_errno.h"
22 #include "include/widget_instance.h"
23 #include "include/widget_service_internal.h"
24 #include "unittest/mock/tzplatform_config_mock.h"
25 #include "unittest/mock/db_mock.h"
26 #include "unittest/mock/aul_mock.h"
27
28 namespace {
29
30 const char *__fake_tzplatform_mkpath(enum tzplatform_variable id, const char *path) {
31   return get_db_path();
32 }
33
34 int __fake_aul_launch_app_async(const char *appid, bundle *kb) {
35   return 0;
36 }
37
38 int __fake_aul_app_com_create(const char *endpoint, aul_app_com_permission_h permission,
39     app_com_cb callback, void *user_data, aul_app_com_connection_h *connection) {
40   aul_app_com_connection_h *conn;
41
42   conn = (aul_app_com_connection_h *)malloc(sizeof(connection));
43   *connection = conn;
44   free(conn);
45   return 0;
46 }
47
48 int __fake_aul_app_com_leave(aul_app_com_connection_h connection) {
49   return 0;
50 }
51
52 int __fake_aul_widget_instance_update(const char *widget_id, const char *instance_id, bundle *b) {
53   return 0;
54 }
55
56 int __fake_aul_debug_info_init() {
57   return 0;
58 }
59
60 int __fake_aul_debug_info_set(bundle *src, bundle *dst) {
61   return 0;
62 }
63
64 class WidgetInstanceTest : public ::testing::Test {
65   public:
66     virtual void SetUp() {
67       tzplatform_mkpath_fake.custom_fake = __fake_tzplatform_mkpath;
68       aul_launch_app_async_fake.custom_fake= __fake_aul_launch_app_async;
69       aul_app_com_create_fake.custom_fake = __fake_aul_app_com_create;
70       aul_app_com_leave_fake.custom_fake = __fake_aul_app_com_leave;
71       aul_widget_instance_update_fake.custom_fake = __fake_aul_widget_instance_update;
72       aul_debug_info_init_fake.custom_fake = __fake_aul_debug_info_init;
73       aul_debug_info_set_fake.custom_fake = __fake_aul_debug_info_set;
74     }
75     virtual void TearDown() {
76     }
77 };
78
79 TEST_F(WidgetInstanceTest, InstanceInit) {
80   int ret;
81
82   ret = widget_instance_init("org.tizen.test_viewer");
83   ASSERT_EQ(ret, 0);
84 }
85
86 char *instance_id = NULL;
87
88 TEST_F(WidgetInstanceTest, InstanceCreate) {
89   int ret = 0;
90
91   ret = widget_instance_create("org.tizen.test_widget", &instance_id);
92   ASSERT_EQ(ret, 0);
93 }
94
95 TEST_F(WidgetInstanceTest, InstanceLaunch) {
96   int ret = 0;
97
98   ret = widget_instance_launch(instance_id, (char *)"TestContent", 4, 2);
99   ASSERT_EQ(ret, 0);
100 }
101
102 TEST_F(WidgetInstanceTest, InstanceResume) {
103   int ret = 0;
104
105   ret = widget_instance_resume(instance_id);
106   ASSERT_EQ(ret, 0);
107 }
108
109 TEST_F(WidgetInstanceTest, InstancePause) {
110   int ret = 0;
111
112   ret = widget_instance_pause(instance_id);
113   ASSERT_EQ(ret, 0);
114 }
115
116 TEST_F(WidgetInstanceTest, InstanceResize) {
117   int ret = 0;
118
119   ret = widget_instance_resize(instance_id, 4, 2);
120   ASSERT_EQ(ret, 0);
121 }
122
123 widget_instance_h ins;
124
125 int _widget_instance_foreach_cb(widget_instance_h instance, void *data) {
126   return 0;
127 }
128
129 TEST_F(WidgetInstanceTest, InstanceForeach) {
130   int ret = 0;
131
132   ret = widget_instance_foreach("org.tizen.test_widget", _widget_instance_foreach_cb, NULL);
133   ASSERT_EQ(ret, 0);
134 }
135
136 TEST_F(WidgetInstanceTest, InstanceGetInstance) {
137   widget_instance_h instance = nullptr;
138
139   instance =  widget_instance_get_instance("org.tizen.test_widget", instance_id);
140   ASSERT_NE(instance, nullptr);
141
142   ins = instance;
143 }
144
145 TEST_F(WidgetInstanceTest, InstanceGetId) {
146   int ret = 0;
147   char *id = NULL;
148
149   ret = widget_instance_get_id(ins, &id);
150   ASSERT_EQ(ret, 0);
151 }
152
153 TEST_F(WidgetInstanceTest, InstanceGetContent) {
154   int ret = 0;
155   char *content = NULL;
156
157   ret = widget_instance_get_content(ins, &content);
158   ASSERT_EQ(ret, 0);
159 }
160
161 TEST_F(WidgetInstanceTest, InstanceGetWidth) {
162   int ret = 0;
163   int w;
164
165   ret = widget_instance_get_width(ins, &w);
166   ASSERT_EQ(ret, 0);
167 }
168
169 TEST_F(WidgetInstanceTest, InstanceGetHeight) {
170   int ret = 0;
171   int h;
172
173   ret = widget_instance_get_height(ins, &h);
174   ASSERT_EQ(ret, 0);
175 }
176
177 TEST_F(WidgetInstanceTest, InstanceSetPeriod) {
178   int ret = 0;
179
180   ret = widget_instance_set_period(ins, 3.0);
181   ASSERT_EQ(ret, 0);
182 }
183
184 TEST_F(WidgetInstanceTest, InstanceGetPeriod) {
185   int ret = 0;
186   double period;
187
188   ret = widget_instance_get_period(ins, &period);
189   ASSERT_EQ(ret, 0);
190 }
191
192 TEST_F(WidgetInstanceTest, InstanceGetErr) {
193   int ret = 0;
194   int err;
195
196   ret = widget_instance_get_error_code(ins, &err);
197   ASSERT_EQ(ret, 0);
198 }
199
200 int _widget_instance_list_cb(const char *widget_id, const char *instance_id, void *user_data) {
201   return 0;
202 }
203
204 TEST_F(WidgetInstanceTest, InstanceGetList) {
205   int ret = 0;
206
207   ret = widget_instance_get_instance_list("org.tizen.test_widget", _widget_instance_list_cb, NULL);
208   ASSERT_EQ(ret, 0);
209 }
210
211 TEST_F(WidgetInstanceTest, InstanceChangePeriod) {
212   int ret = 0;
213
214   ret = widget_instance_change_period("org.tizen.test_widget", instance_id, 5.0);
215   ASSERT_EQ(ret, 0);
216 }
217
218 TEST_F(WidgetInstanceTest, InstanceTriggerUpdate) {
219   int ret = 0;
220
221   ret = widget_instance_trigger_update(ins, "ContentInfo", 1);
222   ASSERT_EQ(ret, 0);
223 }
224
225 int _widget_instance_event_cb(const char *widget_id, const char *instance_id, int event, void *data) {
226   return 0;
227 }
228
229 TEST_F(WidgetInstanceTest, InstanceListenEvent) {
230   int ret = 0;
231
232   ret = widget_instance_listen_event(_widget_instance_event_cb, NULL);
233   ASSERT_EQ(ret, 0);
234 }
235
236 TEST_F(WidgetInstanceTest, InstanceUnlistenEvent) {
237   int ret = 0;
238
239   ret = widget_instance_unlisten_event(_widget_instance_event_cb);
240   ASSERT_EQ(ret, 0);
241 }
242
243 TEST_F(WidgetInstanceTest, InstanceListenStatus) {
244   int ret = 0;
245
246   ret = widget_instance_listen_status("org.tizen.test_widget", _widget_instance_event_cb, NULL);
247   ASSERT_EQ(ret, 0);
248 }
249
250 TEST_F(WidgetInstanceTest, InstanceUnlistenStatus) {
251   int ret = 0;
252
253   ret = widget_instance_unlisten_status("org.tizen.test_widget");
254   ASSERT_EQ(ret, 0);
255 }
256
257 TEST_F(WidgetInstanceTest, InstanceTriggerUpdateV2) {
258   int ret = 0;
259
260   ret = widget_instance_trigger_update_v2("org.tizen.test_widget", instance_id, "ContetnInfo", 1);
261   ASSERT_EQ(ret, 0);
262 }
263
264
265 TEST_F(WidgetInstanceTest, InstanceSetSdkUtil) {
266   int ret = 0;
267   bundle *b;
268
269   b = bundle_create();
270   bundle_add_str(b, "__AUL_SDK__", "SdkUtil");
271
272   ret = widget_service_set_sdk_util(b);
273   ASSERT_EQ(ret, 0);
274
275   bundle_free(b);
276 }
277
278 TEST_F(WidgetInstanceTest, InstanceRefUnref) {
279   widget_instance_h instance = nullptr;
280
281   instance = widget_instance_ref(ins);
282   ASSERT_NE(instance, nullptr);
283
284   widget_instance_unref(instance);
285 }
286
287 TEST_F(WidgetInstanceTest, InstanceTerminate) {
288   int ret = 0;
289
290   ret = widget_instance_terminate(instance_id);
291   ASSERT_EQ(ret, 0);
292 }
293
294 TEST_F(WidgetInstanceTest, InstanceDestroy) {
295   int ret = 0;
296
297   ret = widget_instance_destroy(instance_id);
298   ASSERT_EQ(ret, 0);
299 }
300
301 TEST_F(WidgetInstanceTest, InstanceFini) {
302   int ret = 0;
303
304   ret = widget_instance_fini();
305   ASSERT_EQ(ret, 0);
306 }
307
308 }