Remove the memory database for the cache
[platform/core/appfw/pkgmgr-info.git] / test / unit_tests / parcel_utils.cc
1 /*
2  * Copyright (c) 2021 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 #include "parcel_utils.hh"
17
18 #include <cstdio>
19 #include <iostream>
20
21 #include "pkgmgrinfo_basic.h"
22
23 bool IS_STR_EQ(const char* a, const char* b) {
24   if (a == nullptr && b == nullptr)
25     return true;
26   if (a == nullptr || b == nullptr)
27     return false;
28   return strcmp(a, b) == 0;
29 }
30
31 #define STR_EQ(str_a, str_b) do {                                            \
32     if (!IS_STR_EQ(str_a, str_b)) {                                          \
33       std::cout << #str_a << "(" << str_a << ") is not equal to "            \
34           << #str_b << "(" << str_b << ")" <<  std::endl;                    \
35       return false;                                                          \
36     }                                                                        \
37 } while (0);
38
39 #define INT_EQ(a, b) do {                                                    \
40     if (a != b) {                                                            \
41       std::cout << #a << "(" << a << ") is not equal to "                    \
42           << #b << "(" << b << ")" <<  std::endl;                            \
43       return false;                                                          \
44     }                                                                        \
45 } while (0);
46
47 application_x* GetTestApplication(std::string appid) {
48   application_x* application;
49   application =
50       reinterpret_cast<application_x*>(calloc(1, sizeof(application_x)));
51
52   application->appid = strdup(appid.c_str());
53   application->exec = strdup("test_exec");
54   application->nodisplay = strdup("test_nodisplay");
55   application->multiple = strdup("test_multiple");
56   application->taskmanage = strdup("test_taskmanage");
57   application->type = strdup("test_type");
58   application->hwacceleration = strdup("test_hwacceleration");
59   application->screenreader = strdup("test_screenreader");
60   application->mainapp = strdup("test_mainapp");
61   application->package = strdup("test_package");
62   application->recentimage = strdup("test_recentimage");
63   application->launchcondition = strdup("test_launchcondition");
64   application->indicatordisplay = strdup("test_indicatordisplay");
65   application->portraitimg = strdup("test_portraitimg");
66   application->landscapeimg = strdup("test_landscapeimg");
67   application->guestmode_visibility = strdup("test_guestmode_visibility");
68   application->component = strdup("test_component");
69   application->permission_type = strdup("test_permission_type");
70   application->component_type = strdup("test_component");
71   application->preload = strdup("test_preload");
72   application->submode = strdup("test_submode");
73   application->submode_mainid = strdup("test_submode_mainid");
74   application->process_pool = strdup("test_process_pool");
75   application->installed_storage = strdup("test_installed_storage");
76   application->autorestart = strdup("test_autorestart");
77   application->onboot = strdup("test_onboot");
78   application->support_disable = strdup("test_support_disable");
79   application->ui_gadget = strdup("test_ui_gadget");
80   application->launch_mode = strdup("test_launch_mode");
81   application->support_ambient = strdup("test_support_ambient");
82   application->setup_appid = strdup("test_setup_appid");
83   application->package_type = strdup("test_type");
84   application->tep_name = strdup("test_tep_name");
85   application->zip_mount_file = strdup("test_zip_mount_file");
86   application->root_path = strdup("test_root_path");
87   application->api_version = strdup("test_api_version");
88   application->for_all_users = strdup("false");
89   application->is_disabled = strdup("false");
90   application->splash_screen_display = strdup("test_splash_screen_display");
91   application->external_path = strdup("test_external_path");
92   application->package_system = strdup("test_system");
93   application->removable = strdup("test_removable");
94   application->package_installed_time = strdup("test_installed_time");
95   application->support_mode = strdup("test_support_mode");
96
97   label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
98   label->lang = strdup("test_lang");
99   label->name = strdup("test_name");
100   label->text = strdup("test_text");
101   application->label = g_list_append(application->label, label);
102
103   icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
104   icon->text = strdup("test_text");
105   icon->lang = strdup("test_lang");
106   icon->section = strdup("test_section");
107   icon->size = strdup("test_size");
108   icon->resolution = strdup("test_resolution");
109   icon->dpi = strdup("ldpi");
110   application->icon = g_list_append(application->icon, icon);
111
112   application->category =
113       g_list_append(application->category, strdup("test_category"));
114
115   metadata_x* metadata =
116       reinterpret_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
117   metadata->key = strdup("test_key");
118   metadata->value = strdup("test_value");
119   application->metadata = g_list_append(application->metadata, metadata);
120
121   datacontrol_x* datacontrol =
122       reinterpret_cast<datacontrol_x*>(calloc(1, sizeof(datacontrol_x)));
123   datacontrol->providerid = strdup(appid.c_str());
124   datacontrol->access = strdup("test_access");
125   datacontrol->type = strdup("test_type");
126   datacontrol->trusted = strdup("test_trusted");
127   datacontrol->privileges = g_list_append(datacontrol->privileges,
128       strdup("test_datacontrol_privilege"));
129   application->datacontrol =
130       g_list_append(application->datacontrol, datacontrol);
131
132   application->background_category = g_list_prepend(
133       application->background_category, strdup("enable"));
134   application->background_category = g_list_prepend(
135       application->background_category, strdup("media"));
136   application->background_category = g_list_prepend(
137       application->background_category, strdup("download"));
138   application->background_category = g_list_prepend(
139       application->background_category, strdup("background-network"));
140   application->background_category = g_list_prepend(
141       application->background_category, strdup("location"));
142   application->background_category = g_list_prepend(
143       application->background_category, strdup("sensor"));
144   application->background_category = g_list_prepend(
145       application->background_category, strdup("iot-communication"));
146   application->background_category = g_list_prepend(
147       application->background_category, strdup("system"));
148
149   appcontrol_x* appcontrol =
150       reinterpret_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
151   appcontrol->operation = strdup("test_operation");
152   appcontrol->uri = strdup("test_uri");
153   appcontrol->mime = strdup("test_mime");
154   appcontrol->visibility = strdup("test_visibility");
155   appcontrol->id = strdup("test_id");
156   appcontrol->privileges = g_list_append(
157       appcontrol->privileges, strdup("test_appcontrol_privilege"));
158   application->appcontrol = g_list_append(application->appcontrol, appcontrol);
159
160   splashscreen_x* splashscreen =
161       reinterpret_cast<splashscreen_x*>(calloc(1, sizeof(splashscreen_x)));
162   splashscreen->src = strdup("test_src");
163   splashscreen->type = strdup("ttest_type");
164   splashscreen->dpi = strdup("ldpi");
165   splashscreen->orientation = strdup("portrait");
166   splashscreen->indicatordisplay =
167       strdup("indicatordisptest_indicatordisplay");
168   splashscreen->operation = strdup("operattest_operation");
169   splashscreen->color_depth = strdup("color_detest_color_depth");
170   application->splashscreens =
171       g_list_append(application->splashscreens, splashscreen);
172
173   res_control_x* res_control =
174       reinterpret_cast<res_control_x*>(calloc(1, sizeof(res_control_x)));
175   res_control->res_type = strdup("test_res_type");
176   res_control->min_res_version = strdup("1.0.0");
177   res_control->max_res_version = strdup("2.0.0");
178   res_control->auto_close = strdup("true");
179   application->res_control =
180       g_list_append(application->res_control, res_control);
181
182   return application;
183 }
184
185 bool IsEqualApplicationExtraInfo(application_x* applicationA,
186     application_x* applicationB) {
187   for (GList* a = applicationA->label, *b = applicationB->label;
188       a && b; a = a->next, b = b->next) {
189     label_x* label_a = reinterpret_cast<label_x* >(a->data);
190     label_x* label_b = reinterpret_cast<label_x* >(b->data);
191     STR_EQ(label_a->name, label_b->name);
192   }
193
194   INT_EQ(g_list_length(applicationA->icon),
195       g_list_length(applicationB->icon));
196   for (GList* a = applicationA->icon, *b = applicationB->icon;
197       a && b; a = a->next, b = b->next) {
198     icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
199     icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
200     STR_EQ(icon_a->dpi, icon_b->dpi);
201     STR_EQ(icon_a->resolution, icon_b->resolution);
202     STR_EQ(icon_a->section, icon_b->section);
203     STR_EQ(icon_a->size, icon_b->size);
204   }
205
206   INT_EQ(g_list_length(applicationA->datacontrol),
207       g_list_length(applicationB->datacontrol));
208   for (GList* a = applicationA->datacontrol, *b = applicationB->datacontrol;
209       a && b; a = a->next, b = b->next) {
210     datacontrol_x* datacontrol_a = reinterpret_cast<datacontrol_x*>(a->data);
211     datacontrol_x* datacontrol_b = reinterpret_cast<datacontrol_x*>(b->data);
212     STR_EQ(datacontrol_a->access, datacontrol_b->access);
213     STR_EQ(datacontrol_a->providerid, datacontrol_b->providerid);
214     STR_EQ(datacontrol_a->trusted, datacontrol_b->trusted);
215     STR_EQ(datacontrol_a->type, datacontrol_b->type);
216     INT_EQ(g_list_length(datacontrol_a->privileges)
217         , g_list_length(datacontrol_b->privileges));
218     for (GList* a = datacontrol_a->privileges, *b = datacontrol_b->privileges;
219         a && b; a = a->next, b = b->next) {
220       char* privilege_a = reinterpret_cast<char*>(a->data);
221       char* privilege_b = reinterpret_cast<char*>(b->data);
222       STR_EQ(privilege_a, privilege_b);
223     }
224   }
225
226   for (GList* a = applicationA->appcontrol, *b = applicationB->appcontrol;
227       a && b; a = a->next, b = b->next) {
228     appcontrol_x* appcontrol_a = reinterpret_cast<appcontrol_x*>(a->data);
229     appcontrol_x* appcontrol_b = reinterpret_cast<appcontrol_x*>(b->data);
230     for (GList* a = appcontrol_a->privileges, *b = appcontrol_b->privileges;
231         a && b; a = a->next, b = b->next) {
232       char* privilege_a = reinterpret_cast<char*>(a->data);
233       char* privilege_b = reinterpret_cast<char*>(b->data);
234       STR_EQ(privilege_a, privilege_b);
235     }
236   }
237
238
239   return true;
240 }
241
242 bool IsEqualApplication(application_x* applicationA,
243     application_x* applicationB) {
244   STR_EQ(applicationA->appid, applicationB->appid);
245   STR_EQ(applicationA->exec, applicationB->exec);
246   STR_EQ(applicationA->nodisplay, applicationB->nodisplay);
247   STR_EQ(applicationA->multiple, applicationB->multiple);
248   STR_EQ(applicationA->taskmanage, applicationB->taskmanage);
249   STR_EQ(applicationA->type, applicationB->type);
250   STR_EQ(applicationA->categories, applicationB->categories);
251   STR_EQ(applicationA->extraid, applicationB->extraid);
252   STR_EQ(applicationA->hwacceleration, applicationB->hwacceleration);
253   STR_EQ(applicationA->screenreader, applicationB->screenreader);
254   STR_EQ(applicationA->mainapp, applicationB->mainapp);
255   STR_EQ(applicationA->package, applicationB->package);
256   STR_EQ(applicationA->recentimage, applicationB->recentimage);
257   STR_EQ(applicationA->launchcondition, applicationB->launchcondition);
258   STR_EQ(applicationA->indicatordisplay, applicationB->indicatordisplay);
259   STR_EQ(applicationA->portraitimg, applicationB->portraitimg);
260   STR_EQ(applicationA->landscapeimg, applicationB->landscapeimg);
261   STR_EQ(applicationA->effectimage_type, applicationB->effectimage_type);
262   STR_EQ(applicationA->guestmode_visibility,
263       applicationB->guestmode_visibility);
264   STR_EQ(applicationA->component, applicationB->component);
265   STR_EQ(applicationA->permission_type, applicationB->permission_type);
266   STR_EQ(applicationA->component_type, applicationB->component_type);
267   STR_EQ(applicationA->preload, applicationB->preload);
268   STR_EQ(applicationA->submode, applicationB->submode);
269   STR_EQ(applicationA->submode_mainid, applicationB->submode_mainid);
270   STR_EQ(applicationA->process_pool, applicationB->process_pool);
271   STR_EQ(applicationA->installed_storage, applicationB->installed_storage);
272   STR_EQ(applicationA->autorestart, applicationB->autorestart);
273   STR_EQ(applicationA->onboot, applicationB->onboot);
274   STR_EQ(applicationA->support_disable, applicationB->support_disable);
275   STR_EQ(applicationA->ui_gadget, applicationB->ui_gadget);
276   STR_EQ(applicationA->launch_mode, applicationB->launch_mode);
277   STR_EQ(applicationA->support_ambient, applicationB->support_ambient);
278   STR_EQ(applicationA->setup_appid, applicationB->setup_appid);
279   STR_EQ(applicationA->alias_appid, applicationB->alias_appid);
280   STR_EQ(applicationA->effective_appid, applicationB->effective_appid);
281   STR_EQ(applicationA->package_type, applicationB->package_type);
282   STR_EQ(applicationA->tep_name, applicationB->tep_name);
283   STR_EQ(applicationA->zip_mount_file, applicationB->zip_mount_file);
284   STR_EQ(applicationA->root_path, applicationB->root_path);
285   STR_EQ(applicationA->api_version, applicationB->api_version);
286   STR_EQ(applicationA->for_all_users, applicationB->for_all_users);
287   STR_EQ(applicationA->is_disabled, applicationB->is_disabled);
288   STR_EQ(applicationA->splash_screen_display,
289       applicationB->splash_screen_display);
290   STR_EQ(applicationA->external_path, applicationB->external_path);
291   STR_EQ(applicationA->package_system, applicationB->package_system);
292   STR_EQ(applicationA->removable, applicationB->removable);
293   STR_EQ(applicationA->package_installed_time,
294       applicationB->package_installed_time);
295   STR_EQ(applicationA->support_mode, applicationB->support_mode);
296
297   INT_EQ(g_list_length(applicationA->label),
298       g_list_length(applicationB->label));
299   for (GList* a = applicationA->label, *b = applicationB->label;
300       a && b; a = a->next, b = b->next) {
301     label_x* label_a = reinterpret_cast<label_x*>(a->data);
302     label_x* label_b = reinterpret_cast<label_x*>(b->data);
303     STR_EQ(label_a->lang, label_b->lang);
304     STR_EQ(label_a->text, label_b->text);
305   }
306
307   INT_EQ(g_list_length(applicationA->icon),
308       g_list_length(applicationB->icon));
309   for (GList* a = applicationA->icon, *b = applicationB->icon;
310       a && b; a = a->next, b = b->next) {
311     icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
312     icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
313     STR_EQ(icon_a->lang, icon_b->lang);
314     STR_EQ(icon_a->text, icon_b->text);
315   }
316
317   INT_EQ(g_list_length(applicationA->image),
318       g_list_length(applicationB->image));
319   for (GList* a = applicationA->image, *b = applicationB->image;
320       a && b; a = a->next, b = b->next) {
321     image_x* image_a = reinterpret_cast<image_x*>(a->data);
322     image_x* image_b = reinterpret_cast<image_x*>(b->data);
323     STR_EQ(image_a->lang, image_b->lang);
324     STR_EQ(image_a->section, image_b->section);
325     STR_EQ(image_a->text, image_b->text);
326   }
327
328   INT_EQ(g_list_length(applicationA->category),
329       g_list_length(applicationB->category));
330   for (GList* a = applicationA->category, *b = applicationB->category;
331       a && b; a = a->next, b = b->next) {
332     char* category_a = reinterpret_cast<char*>(a->data);
333     char* category_b = reinterpret_cast<char*>(b->data);
334     STR_EQ(category_a, category_b);
335   }
336
337   INT_EQ(g_list_length(applicationA->metadata),
338       g_list_length(applicationB->metadata));
339   for (GList* a = applicationA->metadata, *b = applicationB->metadata;
340       a && b; a = a->next, b = b->next) {
341     metadata_x* metadata_a = reinterpret_cast<metadata_x*>(a->data);
342     metadata_x* metadata_b = reinterpret_cast<metadata_x*>(b->data);
343     STR_EQ(metadata_a->key, metadata_b->key);
344     STR_EQ(metadata_a->value, metadata_b->value);
345   }
346
347   INT_EQ(g_list_length(applicationA->background_category),
348       g_list_length(applicationB->background_category));
349   for (GList* a = applicationA->background_category,
350       *b = applicationB->background_category;
351       a && b; a = a->next, b = b->next) {
352     char* background_category_a = reinterpret_cast<char*>(a->data);
353     char* background_category_b = reinterpret_cast<char*>(b->data);
354     STR_EQ(background_category_a, background_category_b);
355   }
356
357   INT_EQ(g_list_length(applicationA->appcontrol),
358       g_list_length(applicationB->appcontrol));
359   for (GList* a = applicationA->appcontrol, *b = applicationB->appcontrol;
360       a && b; a = a->next, b = b->next) {
361     appcontrol_x* appcontrol_a = reinterpret_cast<appcontrol_x*>(a->data);
362     appcontrol_x* appcontrol_b = reinterpret_cast<appcontrol_x*>(b->data);
363     STR_EQ(appcontrol_a->id, appcontrol_b->id);
364     STR_EQ(appcontrol_a->mime, appcontrol_b->mime);
365     STR_EQ(appcontrol_a->operation, appcontrol_b->operation);
366     STR_EQ(appcontrol_a->uri, appcontrol_b->uri);
367     STR_EQ(appcontrol_a->visibility, appcontrol_b->visibility);
368   }
369
370   INT_EQ(g_list_length(applicationA->splashscreens),
371       g_list_length(applicationB->splashscreens));
372   for (GList* a = applicationA->splashscreens,
373       *b = applicationB->splashscreens;
374       a && b; a = a->next, b = b->next) {
375     splashscreen_x* splashscreen_a =
376         reinterpret_cast<splashscreen_x*>(a->data);
377     splashscreen_x* splashscreen_b =
378         reinterpret_cast<splashscreen_x*>(b->data);
379     STR_EQ(splashscreen_a->color_depth, splashscreen_b->color_depth);
380     STR_EQ(splashscreen_a->indicatordisplay, splashscreen_b->indicatordisplay);
381     STR_EQ(splashscreen_a->operation, splashscreen_b->operation);
382     STR_EQ(splashscreen_a->orientation, splashscreen_b->orientation);
383     STR_EQ(splashscreen_a->src, splashscreen_b->src);
384     STR_EQ(splashscreen_a->type, splashscreen_b->type);
385   }
386
387   return true;
388 }
389
390 bool IsEqualApplicationsStructure(
391     const std::vector<std::shared_ptr<application_x>>& applicationsA,
392     const std::vector<std::shared_ptr<application_x>>& applicationsB) {
393
394   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
395     if (!IsEqualApplication(applicationsA[i].get(), applicationsB[i].get()))
396       return false;
397     if (!IsEqualApplicationExtraInfo(applicationsA[i].get(),
398         applicationsB[i].get()))
399       return false;
400   }
401
402   return true;
403 }
404
405 bool IsEqualApplicationsInfo(
406     const std::vector<std::shared_ptr<application_x>>& applicationsA,
407     const std::vector<std::shared_ptr<application_x>>& applicationsB) {
408   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
409     if (!IsEqualApplication(applicationsA[i].get(), applicationsB[i].get()))
410       return false;
411   }
412
413   return true;
414 }
415
416 package_x* GetTestPackage(std::string pkgid) {
417   package_x* package;
418   package = reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
419
420   package->for_all_users = strdup("false");
421   package->package = strdup(pkgid.c_str());
422   package->version = strdup("test_version");
423   package->installlocation = strdup("test_installlocation");
424   package->ns = strdup("test_ns");
425   package->removable = strdup("test_removable");
426   package->preload = strdup("test_preload");
427   package->readonly = strdup("test_readonly");
428   package->update = strdup("test_update");
429   package->appsetting = strdup("test_appsetting");
430   package->system = strdup("test_system");
431   package->type = strdup("test_type");
432   package->package_size = strdup("test_package_size");
433   package->installed_time = strdup("test_installed_time");
434   package->installed_storage = strdup("test_installed_storage");
435   package->storeclient_id = strdup("test_storeclient_id");
436   package->mainapp_id = strdup("test_mainapp_id");
437   package->package_url = strdup("test_package_url");
438   package->root_path = strdup("test_root_path");
439   package->csc_path = strdup("test_csc_path");
440   package->nodisplay_setting = strdup("test_nodisplay_setting");
441   package->support_mode = strdup("test_support_mode");
442   package->support_disable = strdup("test_support_disable");
443   package->api_version = strdup("test_api_version");
444   package->tep_name = strdup("test_tep_name");
445   package->zip_mount_file = strdup("test_zip_mount_file");
446   package->backend_installer = strdup("test_backend_installer");
447   package->external_path = strdup("test_external_path");
448   package->use_system_certs = strdup("test_use_system_certs");
449   package->res_type = strdup("test_res_type");
450   package->res_version = strdup("test_res_version");
451   package->light_user_switch_mode = strdup("default");
452
453   icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
454   icon->text = strdup("test_text");
455   icon->lang = strdup("test_lang");
456   icon->section = strdup("test_section");
457   icon->size = strdup("test_size");
458   icon->resolution = strdup("test_resolution");
459   icon->dpi = strdup("ldpi");
460   package->icon = g_list_append(package->icon, icon);
461
462
463   label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
464   label->lang = strdup("test_lang");
465   label->name = strdup("test_name");
466   label->text = strdup("test_text");
467   package->label = g_list_append(package->label, label);
468
469
470   author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
471   author->email = strdup("test_email");
472   author->href = strdup("test_href");
473   author->text = strdup("test_text");
474   author->lang = strdup("test_lang");
475
476   package->author = g_list_append(package->author, author);
477
478   description_x* description =
479       reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
480   description->name = strdup("test_name");
481   description->text = strdup("test_text");
482   description->lang = strdup("test_lang");
483
484   package->description = g_list_append(package->description, description);
485
486   privilege_x* privilege =
487       reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
488   privilege->type = strdup("test_type");
489   privilege->value = strdup("test_value");
490
491   package->privileges = g_list_append(package->privileges, privilege);
492
493   appdefined_privilege_x* appdefined_privilege =
494       reinterpret_cast<appdefined_privilege_x*>(
495           calloc(1, sizeof(appdefined_privilege_x)));
496   appdefined_privilege->type = strdup("test_type");
497   appdefined_privilege->value = strdup("test_value");
498   appdefined_privilege->license = strdup("test_license");
499
500   package->appdefined_privileges =
501       g_list_append(package->appdefined_privileges, appdefined_privilege);
502
503   appdefined_privilege_x* provides_appdefined_privileges =
504       reinterpret_cast<appdefined_privilege_x*>(
505           calloc(1, sizeof(appdefined_privilege_x)));
506   provides_appdefined_privileges->type = strdup("test_type");
507   provides_appdefined_privileges->value = strdup("test_value");
508   provides_appdefined_privileges->license = strdup("test_license");
509
510   package->provides_appdefined_privileges =
511       g_list_append(package->provides_appdefined_privileges,
512           provides_appdefined_privileges);
513
514   package->dependencies = g_list_append(package->dependencies,
515       GetTestDepInfo(pkgid));
516
517   plugin_x* plugin = reinterpret_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
518   plugin->pkgid = strdup(pkgid.c_str());
519   plugin->appid = strdup("test_appid");
520   plugin->plugin_type = strdup("test_plugin_type");
521   plugin->plugin_name = strdup("test_plugin_name");
522
523   package->plugin = g_list_append(package->plugin, plugin);
524
525   res_allowed_package_x* allowed_package =
526       reinterpret_cast<res_allowed_package_x*>(calloc(1,
527           sizeof(res_allowed_package_x)));
528   allowed_package->allowed_package = strdup("test_allowed_package");
529   allowed_package->required_privileges = g_list_append(
530       allowed_package->required_privileges,
531           strdup("test_required_privilege1"));
532
533   package->res_allowed_packages =
534       g_list_append(package->res_allowed_packages, allowed_package);
535
536   package->application = g_list_append(package->application,
537       GetTestApplication("test_app1"));
538   package->application = g_list_append(package->application,
539       GetTestApplication("test_app2"));
540
541   return package;
542 }
543
544 package_x* GetUpdatedTestPackage(std::string pkgid) {
545   auto package = GetTestPackage(pkgid);
546
547   free(package->version);
548   package->version = strdup("2.0.0");
549
550   return package;
551 }
552
553 bool IsEqualPackageExtraInfo(package_x* packageA, package_x* packageB) {
554   STR_EQ(packageA->ns, packageB->ns);
555   STR_EQ(packageA->backend_installer, packageB->backend_installer);
556   STR_EQ(packageA->use_system_certs, packageB->use_system_certs);
557
558   for (GList* a = packageA->icon, *b = packageB->icon;
559       a && b; a = a->next, b = b->next) {
560     icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
561     icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
562     STR_EQ(icon_a->dpi, icon_b->dpi);
563     STR_EQ(icon_a->resolution, icon_b->resolution);
564     STR_EQ(icon_a->section, icon_b->section);
565     STR_EQ(icon_a->size, icon_b->size);
566   }
567
568   INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
569   for (GList* a = packageA->label, *b = packageB->label;
570       a && b; a = a->next, b = b->next) {
571     label_x* label_a = reinterpret_cast<label_x*>(a->data);
572     label_x* label_b = reinterpret_cast<label_x*>(b->data);
573     STR_EQ(label_a->name, label_b->name);
574   }
575
576   INT_EQ(g_list_length(packageA->author), g_list_length(packageB->author));
577   for (GList* a = packageA->author, *b = packageB->author;
578       a && b; a = a->next, b = b->next) {
579     author_x* author_a = reinterpret_cast<author_x* >(a->data);
580     author_x* author_b = reinterpret_cast<author_x* >(b->data);
581     STR_EQ(author_a->email, author_b->email);
582     STR_EQ(author_a->href, author_b->href);
583     STR_EQ(author_a->lang, author_b->lang);
584     STR_EQ(author_a->text, author_b->text);
585   }
586
587   INT_EQ(g_list_length(packageA->description),
588       g_list_length(packageB->description));
589   for (GList* a = packageA->description, *b = packageB->description;
590       a && b; a = a->next, b = b->next) {
591     description_x* description_a = reinterpret_cast<description_x* >(a->data);
592     description_x* description_b = reinterpret_cast<description_x* >(b->data);
593     STR_EQ(description_a->name, description_b->name);
594   }
595
596   INT_EQ(g_list_length(packageA->provides_appdefined_privileges),
597       g_list_length(packageB->provides_appdefined_privileges));
598   for (GList* a = packageA->provides_appdefined_privileges,
599       *b = packageB->provides_appdefined_privileges;
600       a && b; a = a->next, b = b->next) {
601     appdefined_privilege_x* privilege_a =
602         reinterpret_cast<appdefined_privilege_x* >(a->data);
603     appdefined_privilege_x* privilege_b =
604         reinterpret_cast<appdefined_privilege_x* >(b->data);
605     STR_EQ(privilege_a->license, privilege_b->license);
606     STR_EQ(privilege_a->type, privilege_b->type);
607     STR_EQ(privilege_a->value, privilege_b->value);
608   }
609
610   INT_EQ(g_list_length(packageA->plugin), g_list_length(packageB->plugin));
611   for (GList* a = packageA->plugin, *b = packageB->plugin;
612       a && b; a = a->next, b = b->next) {
613     plugin_x* plugin_a = reinterpret_cast<plugin_x*>(a->data);
614     plugin_x* plugin_b = reinterpret_cast<plugin_x*>(b->data);
615     STR_EQ(plugin_a->appid, plugin_b->appid);
616     STR_EQ(plugin_a->pkgid, plugin_b->pkgid);
617     STR_EQ(plugin_a->plugin_name, plugin_b->plugin_name);
618     STR_EQ(plugin_a->plugin_type, plugin_b->plugin_type);
619   }
620
621   INT_EQ(g_list_length(packageA->application),
622       g_list_length(packageB->application));
623   for (GList* a = packageA->application, *b = packageB->application;
624       a && b; a = a->next, b = b->next) {
625     application_x* application_a = reinterpret_cast<application_x*>(a->data);
626     application_x* application_b = reinterpret_cast<application_x*>(b->data);
627
628     if (!IsEqualApplication(application_a, application_b))
629       return false;
630     if (!IsEqualApplicationExtraInfo(application_a, application_b))
631       return false;
632   }
633
634   return true;
635 }
636
637 bool IsEqualPackage(package_x* packageA, package_x* packageB) {
638   STR_EQ(packageA->for_all_users, packageB->for_all_users);
639   STR_EQ(packageA->package, packageB->package);
640   STR_EQ(packageA->version, packageB->version);
641   STR_EQ(packageA->installlocation, packageB->installlocation);
642   STR_EQ(packageA->removable, packageB->removable);
643   STR_EQ(packageA->preload, packageB->preload);
644   STR_EQ(packageA->readonly, packageB->readonly);
645   STR_EQ(packageA->update, packageB->update);
646   STR_EQ(packageA->appsetting, packageB->appsetting);
647   STR_EQ(packageA->system, packageB->system);
648   STR_EQ(packageA->type, packageB->type);
649   STR_EQ(packageA->package_size, packageB->package_size);
650   STR_EQ(packageA->installed_time, packageB->installed_time);
651   STR_EQ(packageA->installed_storage, packageB->installed_storage);
652   STR_EQ(packageA->storeclient_id, packageB->storeclient_id);
653   STR_EQ(packageA->mainapp_id, packageB->mainapp_id);
654   STR_EQ(packageA->package_url, packageB->package_url);
655   STR_EQ(packageA->root_path, packageB->root_path);
656   STR_EQ(packageA->csc_path, packageB->csc_path);
657   STR_EQ(packageA->nodisplay_setting, packageB->nodisplay_setting);
658   STR_EQ(packageA->support_mode, packageB->support_mode);
659   STR_EQ(packageA->support_disable, packageB->support_disable);
660   STR_EQ(packageA->api_version, packageB->api_version);
661   STR_EQ(packageA->tep_name, packageB->tep_name);
662   STR_EQ(packageA->zip_mount_file, packageB->zip_mount_file);
663   STR_EQ(packageA->external_path, packageB->external_path);
664   STR_EQ(packageA->light_user_switch_mode, packageB->light_user_switch_mode);
665
666   INT_EQ(g_list_length(packageA->icon), g_list_length(packageB->icon));
667   for (GList* a = packageA->icon, *b = packageB->icon;
668       a && b; a = a->next, b = b->next) {
669     icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
670     icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
671     STR_EQ(icon_a->lang, icon_b->lang);
672     STR_EQ(icon_a->text, icon_b->text);
673   }
674
675   INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
676   for (GList* a = packageA->label, *b = packageB->label;
677       a && b; a = a->next, b = b->next) {
678     label_x* label_a = reinterpret_cast<label_x*>(a->data);
679     label_x* label_b = reinterpret_cast<label_x*>(b->data);
680     STR_EQ(label_a->lang, label_b->lang);
681     STR_EQ(label_a->text, label_b->text);
682   }
683
684   INT_EQ(g_list_length(packageA->description),
685       g_list_length(packageB->description));
686   for (GList* a = packageA->description, *b = packageB->description;
687       a && b; a = a->next, b = b->next) {
688     description_x* description_a = reinterpret_cast<description_x*>(a->data);
689     description_x* description_b = reinterpret_cast<description_x*>(b->data);
690     STR_EQ(description_a->lang, description_b->lang);
691     STR_EQ(description_a->text, description_b->text);
692   }
693
694   INT_EQ(g_list_length(packageA->privileges),
695       g_list_length(packageB->privileges));
696   for (GList* a = packageA->privileges, *b = packageB->privileges;
697       a && b; a = a->next, b = b->next) {
698     privilege_x* privilege_a = reinterpret_cast<privilege_x*>(a->data);
699     privilege_x* privilege_b = reinterpret_cast<privilege_x*>(b->data);
700     STR_EQ(privilege_a->type, privilege_b->type);
701     STR_EQ(privilege_a->value, privilege_b->value);
702   }
703
704   INT_EQ(g_list_length(packageA->appdefined_privileges),
705       g_list_length(packageB->appdefined_privileges));
706   for (GList* a = packageA->appdefined_privileges,
707       *b = packageB->appdefined_privileges;
708       a && b; a = a->next, b = b->next) {
709     appdefined_privilege_x* privilege_a =
710         reinterpret_cast<appdefined_privilege_x*>(a->data);
711     appdefined_privilege_x* privilege_b =
712         reinterpret_cast<appdefined_privilege_x*>(b->data);
713     STR_EQ(privilege_a->license, privilege_b->license);
714     STR_EQ(privilege_a->type, privilege_b->type);
715     STR_EQ(privilege_a->value, privilege_b->value);
716   }
717
718   INT_EQ(g_list_length(packageA->dependencies),
719       g_list_length(packageB->dependencies));
720   for (GList* a = packageA->dependencies, *b = packageB->dependencies;
721       a && b; a = a->next, b = b->next) {
722     dependency_x* dependency_a = reinterpret_cast<dependency_x*>(a->data);
723     dependency_x* dependency_b = reinterpret_cast<dependency_x*>(b->data);
724     STR_EQ(dependency_a->depends_on, dependency_b->depends_on);
725     STR_EQ(dependency_a->required_version, dependency_b->required_version);
726     STR_EQ(dependency_a->type, dependency_b->type);
727   }
728
729   INT_EQ(g_list_length(packageA->res_allowed_packages),
730       g_list_length(packageB->res_allowed_packages));
731   for (GList* a = packageA->res_allowed_packages,
732       *b = packageB->res_allowed_packages; a && b; a = a->next, b = b->next) {
733     res_allowed_package_x* allowed_package_a =
734         reinterpret_cast<res_allowed_package_x*>(a->data);
735     res_allowed_package_x* allowed_package_b =
736         reinterpret_cast<res_allowed_package_x*>(b->data);
737     STR_EQ(allowed_package_a->allowed_package,
738         allowed_package_b->allowed_package);
739
740     INT_EQ(g_list_length(allowed_package_a->required_privileges),
741         g_list_length(allowed_package_b->required_privileges));
742
743     for (GList* a = allowed_package_a->required_privileges,
744         *b = allowed_package_b->required_privileges; a && b;
745         a = a->next, b = b->next) {
746       STR_EQ(reinterpret_cast<char*>(a->data),
747           reinterpret_cast<char*>(b->data));
748     }
749   }
750
751   return true;
752 }
753
754 bool IsEqualPackagesStructure(
755     const std::vector<std::shared_ptr<package_x>>& packagesA,
756     const std::vector<std::shared_ptr<package_x>>& packagesB) {
757   if (packagesA.size() != packagesB.size())
758     return false;
759
760   for (unsigned int i = 0; i < packagesA.size(); ++i) {
761     if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
762       return false;
763     if (!IsEqualPackageExtraInfo(packagesA[i].get(), packagesB[i].get()))
764       return false;
765   }
766
767   return true;
768 }
769
770 bool IsEqualPackagesInfo(
771     const std::vector<std::shared_ptr<package_x>>& packagesA,
772     const std::vector<std::shared_ptr<package_x>>& packagesB) {
773   if (packagesA.size() != packagesB.size())
774     return false;
775
776   for (unsigned int i = 0; i < packagesA.size(); ++i) {
777     if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
778       return false;
779   }
780
781   return true;
782 }
783
784 pkgmgrinfo_filter_x* GetTestFilter() {
785   pkgmgrinfo_filter_x* filter;
786   pkgmgrinfo_node_x* node;
787   pkgmgrinfo_metadata_node_x* metadata_node;
788   filter = reinterpret_cast<pkgmgrinfo_filter_x*>(
789       calloc(1, sizeof(pkgmgrinfo_filter_x)));
790
791   filter->uid = 1234;
792   node = reinterpret_cast<pkgmgrinfo_node_x*>(
793       calloc(1, sizeof(pkgmgrinfo_node_x)));
794   node->prop = 4321;
795   node->key = strdup("test_key1");
796   node->value = strdup("test_value1");
797   filter->list = g_slist_append(filter->list, node);
798
799   node = reinterpret_cast<pkgmgrinfo_node_x*>(
800       calloc(1, sizeof(pkgmgrinfo_node_x)));
801   node->prop = 4321;
802   node->key = strdup("test_key2");
803   node->value = strdup("test_value2");
804   filter->list = g_slist_append(filter->list, node);
805
806   metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x*>(
807       calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
808   metadata_node->key = strdup("test_metadata_key1");
809   metadata_node->value = strdup("test_metadata_value1");
810   filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
811
812   metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x*>(
813       calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
814   metadata_node->key = strdup("test_metadata_key2");
815   metadata_node->value = strdup("test_metadata_value2");
816   filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
817
818   return filter;
819 }
820
821 bool IsEqualFilter(const pkgmgrinfo_filter_x* filterA,
822     const pkgmgrinfo_filter_x* filterB) {
823   INT_EQ(filterA->uid, filterB->uid);
824
825   INT_EQ(g_slist_length(filterA->list), g_slist_length(filterB->list));
826   for (GSList* a = filterA->list, *b = filterB->list;
827       a && b; a = a->next, b = b->next) {
828     pkgmgrinfo_node_x* node_a = reinterpret_cast<pkgmgrinfo_node_x*>(a->data);
829     pkgmgrinfo_node_x* node_b = reinterpret_cast<pkgmgrinfo_node_x*>(b->data);
830     INT_EQ(node_a->prop, node_b->prop);
831     STR_EQ(node_a->key, node_b->key);
832     STR_EQ(node_a->value, node_b->value);
833   }
834
835   INT_EQ(g_slist_length(filterA->list_metadata),
836       g_slist_length(filterB->list_metadata));
837   for (GSList* a = filterA->list_metadata, *b = filterB->list_metadata;
838       a && b; a = a->next, b = b->next) {
839     pkgmgrinfo_metadata_node_x* node_a =
840         reinterpret_cast<pkgmgrinfo_metadata_node_x*>(a->data);
841     pkgmgrinfo_metadata_node_x* node_b =
842         reinterpret_cast<pkgmgrinfo_metadata_node_x*>(b->data);
843     STR_EQ(node_a->key, node_b->key);
844     STR_EQ(node_a->value, node_b->value);
845   }
846
847   return true;
848 }
849
850 pkgmgr_certinfo_x* GetTestCertInfo() {
851   pkgmgr_certinfo_x* cert_info;
852   cert_info = reinterpret_cast<pkgmgr_certinfo_x*>(
853       calloc(1, sizeof(pkgmgr_certinfo_x)));
854
855   cert_info->for_all_users = 1;
856   cert_info->pkgid = strdup("test_pkgid");
857   cert_info->cert_value = strdup("test_cert_value");
858   for (int i = 0; i < MAX_CERT_TYPE; ++i) {
859     char buf[1024] = { 0, };
860     snprintf(buf, sizeof(buf), "test_cert_info_%d", i);
861     cert_info->cert_info[i] = strdup(buf);
862   }
863   for (int i = 0; i < MAX_CERT_TYPE; ++i) {
864     cert_info->cert_id[i] = i + 1000;
865   }
866
867   return cert_info;
868 }
869
870 bool IsEqualCertInfoStructure(const pkgmgr_certinfo_x* certA,
871     const pkgmgr_certinfo_x* certB) {
872   if (!IsEqualCertInfo(certA, certB))
873     return false;
874
875   STR_EQ(certA->pkgid, certB->pkgid);
876   STR_EQ(certA->cert_value, certB->cert_value);
877   INT_EQ(certA->for_all_users, certB->for_all_users);
878   return true;
879 }
880
881 bool IsEqualCertInfo(const pkgmgr_certinfo_x* certA,
882     const pkgmgr_certinfo_x* certB) {
883   for (int i = 0; i < MAX_CERT_TYPE; ++i)
884     STR_EQ(certA->cert_info[i], certB->cert_info[i]);
885   for (int i = 0; i < MAX_CERT_TYPE; ++i)
886     INT_EQ(certA->cert_id[i], certB->cert_id[i]);
887
888   return true;
889 }
890
891 dependency_x* GetTestDepInfo(std::string pkgid) {
892   dependency_x* dependency;
893   dependency = reinterpret_cast<dependency_x*>(
894       calloc(1, sizeof(dependency_x)));
895
896   dependency->pkgid = strdup(pkgid.c_str());
897   dependency->depends_on = strdup("depends_on_pkgid");
898   dependency->required_version = strdup("test_required_version");
899   dependency->type = strdup("test_type");
900
901   return dependency;
902 }
903
904 bool IsEqualDepInfo(const std::vector<dependency_x*>& depA,
905     const std::vector<dependency_x*>& depB) {
906   INT_EQ(depA.size(), depB.size());
907
908   for (unsigned int i = 0; i < depA.size(); ++i) {
909     dependency_x *A = depA[0];
910     dependency_x *B = depB[0];
911     STR_EQ(A->depends_on, B->depends_on);
912     STR_EQ(A->pkgid, B->pkgid);
913     STR_EQ(A->required_version, B->required_version);
914     STR_EQ(A->type, B->type);
915   }
916
917   return true;
918 }
919
920 pkgmgr_certinfo_x* GetTestCertificate() {
921   pkgmgr_certinfo_x* cert_info = reinterpret_cast<pkgmgr_certinfo_x*>(
922       calloc(1, sizeof(pkgmgr_certinfo_x)));
923
924   cert_info->for_all_users = 1;
925   cert_info->pkgid = strdup("test_pkgid");
926   cert_info->cert_value = strdup("test_certvalue");
927   for (int i = 0; i < MAX_CERT_TYPE; i++) {
928     std::string cert_value(std::to_string(i));
929     cert_value += "test_cert_value";
930     cert_info->cert_info[i] = strdup(cert_value.c_str());
931     cert_info->cert_id[i] = i + 1;
932   }
933
934   return cert_info;
935 }