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