Merge branch 'tizen_5.5' into tizen
[platform/core/uifw/capi-ui-sticker.git] / tests / src / sticker_data_unittests.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
20 #include <sticker_data.h>
21
22 #include "app_common_mock.h"
23
24 using namespace std;
25
26 namespace {
27
28 static bool callback_result = false;
29 static sticker_data_h g_dh = NULL;
30
31 static void foreach_keyword_cb(const char *keyword, void *user_data)
32 {
33     callback_result = true;
34 }
35
36 class StickerDataTest : public testing::Test {
37     public:
38         virtual void SetUp() {
39             sticker_data_create(&g_dh);
40             sticker_data_set_uri(g_dh, STICKER_DATA_URI_WEB_RESOURCE, "www.samsung.com");
41             sticker_data_add_keyword(g_dh, "smile");
42             sticker_data_add_keyword(g_dh, "face");
43             sticker_data_add_keyword(g_dh, "cute");
44             sticker_data_set_group_name(g_dh, "tizen");
45             sticker_data_set_thumbnail(g_dh, "/res/test.png");
46             sticker_data_set_description(g_dh, "TCT Test");
47         }
48         virtual void TearDown() {
49             if (g_dh) {
50                 sticker_data_destroy(g_dh);
51                 g_dh = NULL;
52             }
53         }
54 };
55
56 int __fake_app_get_id(char** app_id) {
57     if (app_id)
58         *app_id = strdup("org.tizen.hello");
59
60     return 0;
61 }
62
63 /**
64  * @function        utc_sticker_data_create_p
65  * @description     Positive UTC of the function that creates sticker data handle
66  * @parameter       NA
67  */
68 TEST_F(StickerDataTest, utc_sticker_data_create_p)
69 {
70     app_get_id_fake.custom_fake = __fake_app_get_id;
71
72     sticker_data_h sd_h = NULL;
73     int ret = sticker_data_create(&sd_h);
74     EXPECT_EQ(ret, STICKER_ERROR_NONE);
75 }
76
77 /**
78  * @function        utc_sticker_data_create_n
79  * @description     Negative UTC of the function that creates sticker data handle
80  * @parameter       NA
81  */
82 TEST_F(StickerDataTest, utc_sticker_data_create_n)
83 {
84     int ret = sticker_data_create(NULL);
85     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
86 }
87
88 /**
89  * @function        utc_sticker_data_destroy_p
90  * @description     Positive UTC of the function that destroys sticker data handle
91  * @parameter       NA
92  */
93 TEST_F(StickerDataTest, utc_sticker_data_destroy_p)
94 {
95     app_get_id_fake.custom_fake = __fake_app_get_id;
96
97     sticker_data_h sd_h = NULL;
98     int ret = sticker_data_create(&sd_h);
99     EXPECT_EQ(ret, STICKER_ERROR_NONE);
100
101     ret = sticker_data_destroy(sd_h);
102     EXPECT_EQ(ret, STICKER_ERROR_NONE);
103 }
104
105 /**
106  * @function        utc_sticker_data_destroy_n
107  * @description     Negative UTC of the function that destroys sticker data handle
108  * @parameter       NA
109  */
110 TEST_F(StickerDataTest, utc_sticker_data_destroy_n)
111 {
112     int ret = sticker_data_destroy(NULL);
113     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
114 }
115
116 /**
117  * @testcase        utc_sticker_data_clone_p
118  * @since_tizen     5.5
119  * @description     Positive UTC of the function that clones sticker data.
120  */
121 TEST_F(StickerDataTest, utc_sticker_data_clone_p)
122 {
123     sticker_data_h clone = NULL;
124     int ret = sticker_data_clone(g_dh, &clone);
125     EXPECT_EQ(ret, STICKER_ERROR_NONE);
126
127     sticker_data_destroy(clone);
128     clone = NULL;
129 }
130
131 /**
132  * @testcase        utc_sticker_data_clone_n
133  * @since_tizen     5.5
134  * @description     Negative UTC of the function that clones sticker data.
135  */
136 TEST_F(StickerDataTest, utc_sticker_data_clone_n)
137 {
138     int ret = sticker_data_clone(NULL, NULL);
139     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
140 }
141
142 /**
143  * @testcase        utc_sticker_data_get_app_id_p
144  * @since_tizen     5.5
145  * @description     Positive UTC of the function that gets application id of sticker data.
146  */
147 TEST_F(StickerDataTest, utc_sticker_data_get_app_id_p)
148 {
149     char *app_id = NULL;
150     int ret = sticker_data_get_app_id(g_dh, &app_id);
151     EXPECT_EQ(ret, STICKER_ERROR_NONE);
152
153     if (app_id)
154         free(app_id);
155 }
156
157 /**
158  * @testcase        utc_sticker_data_get_app_id_n
159  * @since_tizen     5.5
160  * @description     Negative UTC of the function that gets application id of sticker data.
161  */
162 TEST_F(StickerDataTest, utc_sticker_data_get_app_id_n)
163 {
164     char *app_id = NULL;
165     int ret = sticker_data_get_app_id(NULL, &app_id);
166     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
167 }
168
169 /**
170  * @testcase        utc_sticker_data_set_uri_p
171  * @since_tizen     5.5
172  * @description     Positive UTC of the function that sets uri of sticker data.
173  */
174 TEST_F(StickerDataTest, utc_sticker_data_set_uri_p)
175 {
176     int ret = sticker_data_set_uri(g_dh, STICKER_DATA_URI_WEB_RESOURCE, "www.tizen.org");
177     EXPECT_EQ(ret, STICKER_ERROR_NONE);
178 }
179
180 /**
181  * @testcase        utc_sticker_data_set_uri_n
182  * @since_tizen     5.5
183  * @description     Negative UTC of the function that sets uri of sticker data.
184  */
185 TEST_F(StickerDataTest, utc_sticker_data_set_uri_n)
186 {
187     int ret = sticker_data_set_uri(NULL, STICKER_DATA_URI_WEB_RESOURCE, "www.tizen.org");
188     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
189 }
190
191 /**
192  * @testcase        utc_sticker_data_set_uri_n2
193  * @since_tizen     5.5
194  * @description     Negative UTC of the function that sets uri of sticker data.
195  */
196 TEST_F(StickerDataTest, utc_sticker_data_set_uri_n2)
197 {
198     int ret = sticker_data_set_uri(g_dh, STICKER_DATA_URI_LOCAL_PATH, "/aaa/bbb/ccc.png");
199     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
200 }
201
202 /**
203  * @testcase        utc_sticker_data_get_uri_p
204  * @since_tizen     5.5
205  * @description     Positive UTC of the function that gets uri of sticker data.
206  */
207 TEST_F(StickerDataTest, utc_sticker_data_get_uri_p)
208 {
209     sticker_data_uri_type_e type;
210     char *uri = NULL;
211
212     int ret = sticker_data_get_uri(g_dh, &type, &uri);
213     EXPECT_EQ(ret, STICKER_ERROR_NONE);
214
215     if (uri)
216         free(uri);
217 }
218
219 /**
220  * @testcase        utc_sticker_data_get_uri_n
221  * @since_tizen     5.5
222  * @description     Negative UTC of the function that gets uri of sticker data.
223  */
224 TEST_F(StickerDataTest, utc_sticker_data_get_uri_n)
225 {
226     int ret = sticker_data_get_uri(g_dh, NULL, NULL);
227     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
228 }
229
230 /**
231  * @testcase        utc_sticker_data_foreach_keyword_p
232  * @since_tizen     5.5
233  * @description     Positive UTC of the function that retrieves all keywords of sticker data.
234  */
235 TEST_F(StickerDataTest, utc_sticker_data_foreach_keyword_p)
236 {
237     callback_result = false;
238     int ret = sticker_data_foreach_keyword(g_dh, foreach_keyword_cb, NULL);
239     EXPECT_EQ(callback_result, true);
240     EXPECT_EQ(ret, STICKER_ERROR_NONE);
241 }
242
243 /**
244  * @testcase        utc_sticker_data_foreach_keyword_n
245  * @since_tizen     5.5
246  * @description     Negative UTC of the function that retrieves all keywords of sticker data.
247  */
248 TEST_F(StickerDataTest, utc_sticker_data_foreach_keyword_n)
249 {
250     int ret = sticker_data_foreach_keyword(g_dh, NULL, NULL);
251     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
252 }
253
254 /**
255  * @testcase        utc_sticker_data_add_keyword_p
256  * @since_tizen     5.5
257  * @description     Positive UTC of the function that adds keyword of sticker data.
258  */
259 TEST_F(StickerDataTest, utc_sticker_data_add_keyword_p)
260 {
261     int ret = sticker_data_add_keyword(g_dh, "test");
262     EXPECT_EQ(ret, STICKER_ERROR_NONE);
263 }
264
265 /**
266  * @testcase        utc_sticker_data_add_keyword_n
267  * @since_tizen     5.5
268  * @description     Negative UTC of the function that adds keyword of sticker data.
269  */
270 TEST_F(StickerDataTest, utc_sticker_data_add_keyword_n)
271 {
272     int ret = sticker_data_add_keyword(g_dh, NULL);
273     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
274 }
275
276 /**
277  * @testcase        utc_sticker_data_add_keyword_n2
278  * @since_tizen     5.5
279  * @description     Negative UTC of the function that adds keyword of sticker data.
280  */
281 TEST_F(StickerDataTest, utc_sticker_data_add_keyword_n2)
282 {
283     int ret = sticker_data_add_keyword(g_dh, "smile");
284     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
285 }
286
287 /**
288  * @testcase        utc_sticker_data_remove_keyword_p
289  * @since_tizen     5.5
290  * @description     Positive UTC of the function that removes keyword of sticker data.
291  */
292 TEST_F(StickerDataTest, utc_sticker_data_remove_keyword_p)
293 {
294     int ret = sticker_data_remove_keyword(g_dh, "face");
295     EXPECT_EQ(ret, STICKER_ERROR_NONE);
296 }
297
298 /**
299  * @testcase        utc_sticker_data_remove_keyword_n
300  * @since_tizen     5.5
301  * @description     Negative UTC of the function that removes keyword of sticker data.
302  */
303 TEST_F(StickerDataTest, utc_sticker_data_remove_keyword_n)
304 {
305     int ret = sticker_data_remove_keyword(g_dh, NULL);
306     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
307 }
308
309 /**
310  * @testcase        utc_sticker_data_remove_keyword_n2
311  * @since_tizen     5.5
312  * @description     Negative UTC of the function that removes keyword of sticker data.
313  */
314 TEST_F(StickerDataTest, utc_sticker_data_remove_keyword_n2)
315 {
316     int ret = sticker_data_remove_keyword(g_dh, "test");
317     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
318 }
319
320 /**
321  * @testcase        utc_sticker_data_set_group_name_p
322  * @since_tizen     5.5
323  * @description     Positive UTC of the function that sets group name of sticker data.
324  */
325 TEST_F(StickerDataTest, utc_sticker_data_set_group_name_p)
326 {
327     int ret = sticker_data_set_group_name(g_dh, "samsung");
328     EXPECT_EQ(ret, STICKER_ERROR_NONE);
329 }
330
331 /**
332  * @testcase        utc_sticker_data_set_group_name_n
333  * @since_tizen     5.5
334  * @description     Negative UTC of the function that sets group name of sticker data.
335  */
336 TEST_F(StickerDataTest, utc_sticker_data_set_group_name_n)
337 {
338     int ret = sticker_data_set_group_name(g_dh, NULL);
339     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
340 }
341
342 /**
343  * @testcase        utc_sticker_data_get_group_name_p
344  * @since_tizen     5.5
345  * @description     Positive UTC of the function that gets group name of sticker data.
346  */
347 TEST_F(StickerDataTest, utc_sticker_data_get_group_name_p)
348 {
349     char *group = NULL;
350     int ret = sticker_data_get_group_name(g_dh, &group);
351
352     if (group) {
353         free(group);
354         group = NULL;
355     }
356
357     EXPECT_EQ(ret, STICKER_ERROR_NONE);
358 }
359
360 /**
361  * @testcase        utc_sticker_data_get_group_name_n
362  * @since_tizen     5.5
363  * @description     Negative UTC of the function that gets group name of sticker data.
364  */
365 TEST_F(StickerDataTest, utc_sticker_data_get_group_name_n)
366 {
367     int ret = sticker_data_get_group_name(g_dh, NULL);
368     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
369 }
370
371 /**
372  * @testcase        utc_sticker_data_set_thumbnail_n
373  * @since_tizen     5.5
374  * @description     Negative UTC of the function that sets thumbnail of sticker data.
375  */
376 TEST_F(StickerDataTest, utc_sticker_data_set_thumbnail_n)
377 {
378     int ret = sticker_data_set_thumbnail(g_dh, NULL);
379     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
380 }
381
382 /**
383  * @testcase        utc_sticker_data_set_thumbnail_n2
384  * @since_tizen     5.5
385  * @description     Negative UTC of the function that sets thumbnail of sticker data.
386  */
387 TEST_F(StickerDataTest, utc_sticker_data_set_thumbnail_n2)
388 {
389     int ret = sticker_data_set_thumbnail(g_dh, "/aaa/bbb/ccc.png");
390     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
391 }
392
393 /**
394  * @testcase        utc_sticker_data_get_thumbnail_p
395  * @since_tizen     5.5
396  * @description     Positive UTC of the function that gets thumbnail of sticker data.
397  */
398 TEST_F(StickerDataTest, utc_sticker_data_get_thumbnail_p)
399 {
400     char *thumbnail = NULL;
401     int ret = sticker_data_get_thumbnail(g_dh, &thumbnail);
402
403     if (thumbnail) {
404         free(thumbnail);
405         thumbnail = NULL;
406     }
407
408     EXPECT_EQ(ret, STICKER_ERROR_NONE);
409 }
410
411 /**
412  * @testcase        utc_sticker_data_get_thumbnail_n
413  * @since_tizen     5.5
414  * @description     Negative UTC of the function that gets thumbnail of sticker data.
415  */
416 TEST_F(StickerDataTest, utc_sticker_data_get_thumbnail_n)
417 {
418     int ret = sticker_data_get_thumbnail(g_dh, NULL);
419     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
420 }
421
422 /**
423  * @testcase        utc_sticker_data_set_description_p
424  * @since_tizen     5.5
425  * @description     Positive UTC of the function that sets description of sticker data.
426  */
427 TEST_F(StickerDataTest, utc_sticker_data_set_description_p)
428 {
429     int ret = sticker_data_set_description(g_dh, "capi-ui-sticker TCT Test");
430     EXPECT_EQ(ret, STICKER_ERROR_NONE);
431 }
432
433 /**
434  * @testcase        utc_sticker_data_set_description_n
435  * @since_tizen     5.5
436  * @description     Negative UTC of the function that sets description of sticker data.
437  */
438 TEST_F(StickerDataTest, utc_sticker_data_set_description_n)
439 {
440     int ret = sticker_data_set_description(g_dh, NULL);
441     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
442 }
443
444 /**
445  * @testcase        utc_sticker_data_get_description_p
446  * @since_tizen     5.5
447  * @description     Positive UTC of the function that gets description of sticker data.
448  */
449 TEST_F(StickerDataTest, utc_sticker_data_get_description_p)
450 {
451     char *description = NULL;
452     int ret = sticker_data_get_description(g_dh, &description);
453
454     if (description) {
455         free(description);
456         description = NULL;
457     }
458
459     EXPECT_EQ(ret, STICKER_ERROR_NONE);
460 }
461
462 /**
463  * @testcase        utc_sticker_data_get_description_n
464  * @since_tizen     5.5
465  * @description     Negative UTC of the function that gets description of sticker data.
466  */
467 TEST_F(StickerDataTest, utc_sticker_data_get_description_n)
468 {
469     int ret = sticker_data_get_description(g_dh, NULL);
470     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
471 }
472
473 /**
474  * @testcase        utc_sticker_data_get_date_p
475  * @since_tizen     5.5
476  * @description     Positive UTC of the function that gets last updated date.
477  */
478 TEST_F(StickerDataTest, utc_sticker_data_get_date_p)
479 {
480     char *date = NULL;
481     int ret = sticker_data_get_date(g_dh, &date);
482
483     if (date) {
484         free(date);
485         date = NULL;
486     }
487
488     EXPECT_NE(ret, STICKER_ERROR_INVALID_PARAMETER);
489 }
490
491 /**
492  * @testcase        utc_sticker_data_get_date_n
493  * @since_tizen     5.5
494  * @description     Negative UTC of the function that gets last updated date.
495  */
496 TEST_F(StickerDataTest, utc_sticker_data_get_date_n)
497 {
498     int ret = sticker_data_get_date(g_dh, NULL);
499     EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
500 }
501
502 } // namespace