Implement PkgGetDBHandler unit test
[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->categories = strdup("test_categories");
59   application->extraid = strdup("test_extraid");
60   application->hwacceleration = strdup("test_hwacceleration");
61   application->screenreader = strdup("test_screenreader");
62   application->mainapp = strdup("test_mainapp");
63   application->package = strdup("test_package");
64   application->recentimage = strdup("test_recentimage");
65   application->launchcondition = strdup("test_launchcondition");
66   application->indicatordisplay = strdup("test_indicatordisplay");
67   application->portraitimg = strdup("test_portraitimg");
68   application->landscapeimg = strdup("test_landscapeimg");
69   application->effectimage_type = strdup("test_effectimage_type");
70   application->guestmode_visibility = strdup("test_guestmode_visibility");
71   application->component = strdup("test_component");
72   application->permission_type = strdup("test_permission_type");
73   application->component_type = strdup("test_component_type");
74   application->preload = strdup("test_preload");
75   application->submode = strdup("test_submode");
76   application->submode_mainid = strdup("test_submode_mainid");
77   application->process_pool = strdup("test_process_pool");
78   application->installed_storage = strdup("test_installed_storage");
79   application->autorestart = strdup("test_autorestart");
80   application->onboot = strdup("test_onboot");
81   application->support_disable = strdup("test_support_disable");
82   application->ui_gadget = strdup("test_ui_gadget");
83   application->launch_mode = strdup("test_launch_mode");
84   application->support_ambient = strdup("test_support_ambient");
85   application->setup_appid = strdup("test_setup_appid");
86   application->alias_appid = strdup("test_alias_appid");
87   application->effective_appid = strdup("test_effective_appid");
88   application->package_type = strdup("test_package_type");
89   application->tep_name = strdup("test_tep_name");
90   application->zip_mount_file = strdup("test_zip_mount_file");
91   application->root_path = strdup("test_root_path");
92   application->api_version = strdup("test_api_version");
93   application->for_all_users = strdup("test_for_all_users");
94   application->is_disabled = strdup("false");
95   application->splash_screen_display = strdup("test_splash_screen_display");
96   application->external_path = strdup("test_external_path");
97   application->package_system = strdup("test_package_system");
98   application->removable = strdup("test_removable");
99   application->package_installed_time = strdup("test_package_installed_time");
100   application->support_mode = strdup("test_support_mode");
101
102
103   label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
104   label->lang = strdup("test_lang");
105   label->name = strdup("test_name");
106   label->text = strdup("test_text");
107   application->label = g_list_append(application->label, label);
108
109   icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
110   icon->text = strdup("test_text");
111   icon->lang = strdup("test_lang");
112   icon->section = strdup("test_section");
113   icon->size = strdup("test_size");
114   icon->resolution = strdup("test_resolution");
115   icon->dpi = strdup("test_dpi");
116   application->icon = g_list_append(application->icon, icon);
117
118   image_x* image = reinterpret_cast<image_x*>(calloc(1, sizeof(image_x)));
119   image->text = strdup("test_text");
120   image->lang = strdup("test_lang");
121   image->section = strdup("test_section");
122   application->image = g_list_append(application->image, image);
123
124   application->category =
125       g_list_append(application->category, strdup("test_category"));
126
127   metadata_x* metadata =
128       reinterpret_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
129   metadata->key = strdup("test_key");
130   metadata->value = strdup("test_value");
131   application->metadata = g_list_append(application->metadata, metadata);
132
133   datacontrol_x* datacontrol =
134       reinterpret_cast<datacontrol_x*>(calloc(1, sizeof(datacontrol_x)));
135   datacontrol->providerid = strdup(appid.c_str());
136   datacontrol->access = strdup("test_access");
137   datacontrol->type = strdup("test_type");
138   datacontrol->trusted = strdup("test_trusted");
139   datacontrol->privileges = g_list_append(datacontrol->privileges,
140       strdup("test_datacontrol_privilege"));
141   application->datacontrol =
142       g_list_append(application->datacontrol, datacontrol);
143
144   application->background_category = g_list_append(
145       application->background_category, strdup("test_background_category"));
146
147   appcontrol_x* appcontrol =
148       reinterpret_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
149   appcontrol->operation = strdup("test_operation");
150   appcontrol->uri = strdup("test_uri");
151   appcontrol->mime = strdup("test_mime");
152   appcontrol->visibility = strdup("test_visibility");
153   appcontrol->id = strdup("test_id");
154   appcontrol->privileges = g_list_append(
155       appcontrol->privileges, strdup("test_appcontrol_privilege"));
156   application->appcontrol = g_list_append(application->appcontrol, appcontrol);
157
158   splashscreen_x* splashscreen =
159       reinterpret_cast<splashscreen_x*>(calloc(1, sizeof(splashscreen_x)));
160   splashscreen->src = strdup("test_src");
161   splashscreen->type = strdup("ttest_type");
162   splashscreen->dpi = strdup("test_dpi");
163   splashscreen->orientation = strdup("orientattest_orientation");
164   splashscreen->indicatordisplay =
165       strdup("indicatordisptest_indicatordisplay");
166   splashscreen->operation = strdup("operattest_operation");
167   splashscreen->color_depth = strdup("color_detest_color_depth");
168   application->splashscreens =
169       g_list_append(application->splashscreens, splashscreen);
170
171   return application;
172 }
173
174 bool IsEqualApplication(application_x *applicationA,
175     application_x *applicationB) {
176   STR_EQ(applicationA->appid, applicationB->appid);
177   STR_EQ(applicationA->exec, applicationB->exec);
178   STR_EQ(applicationA->nodisplay, applicationB->nodisplay);
179   STR_EQ(applicationA->multiple, applicationB->multiple);
180   STR_EQ(applicationA->taskmanage, applicationB->taskmanage);
181   STR_EQ(applicationA->type, applicationB->type);
182   STR_EQ(applicationA->categories, applicationB->categories);
183   STR_EQ(applicationA->extraid, applicationB->extraid);
184   STR_EQ(applicationA->hwacceleration, applicationB->hwacceleration);
185   STR_EQ(applicationA->screenreader, applicationB->screenreader);
186   STR_EQ(applicationA->mainapp, applicationB->mainapp);
187   STR_EQ(applicationA->package, applicationB->package);
188   STR_EQ(applicationA->recentimage, applicationB->recentimage);
189   STR_EQ(applicationA->launchcondition, applicationB->launchcondition);
190   STR_EQ(applicationA->indicatordisplay, applicationB->indicatordisplay);
191   STR_EQ(applicationA->portraitimg, applicationB->portraitimg);
192   STR_EQ(applicationA->landscapeimg, applicationB->landscapeimg);
193   STR_EQ(applicationA->effectimage_type, applicationB->effectimage_type);
194   STR_EQ(applicationA->guestmode_visibility,
195       applicationB->guestmode_visibility);
196   STR_EQ(applicationA->component, applicationB->component);
197   STR_EQ(applicationA->permission_type, applicationB->permission_type);
198   STR_EQ(applicationA->component_type, applicationB->component_type);
199   STR_EQ(applicationA->preload, applicationB->preload);
200   STR_EQ(applicationA->submode, applicationB->submode);
201   STR_EQ(applicationA->submode_mainid, applicationB->submode_mainid);
202   STR_EQ(applicationA->process_pool, applicationB->process_pool);
203   STR_EQ(applicationA->installed_storage, applicationB->installed_storage);
204   STR_EQ(applicationA->autorestart, applicationB->autorestart);
205   STR_EQ(applicationA->onboot, applicationB->onboot);
206   STR_EQ(applicationA->support_disable, applicationB->support_disable);
207   STR_EQ(applicationA->ui_gadget, applicationB->ui_gadget);
208   STR_EQ(applicationA->launch_mode, applicationB->launch_mode);
209   STR_EQ(applicationA->support_ambient, applicationB->support_ambient);
210   STR_EQ(applicationA->setup_appid, applicationB->setup_appid);
211   STR_EQ(applicationA->alias_appid, applicationB->alias_appid);
212   STR_EQ(applicationA->effective_appid, applicationB->effective_appid);
213   STR_EQ(applicationA->package_type, applicationB->package_type);
214   STR_EQ(applicationA->tep_name, applicationB->tep_name);
215   STR_EQ(applicationA->zip_mount_file, applicationB->zip_mount_file);
216   STR_EQ(applicationA->root_path, applicationB->root_path);
217   STR_EQ(applicationA->api_version, applicationB->api_version);
218   STR_EQ(applicationA->for_all_users, applicationB->for_all_users);
219   STR_EQ(applicationA->is_disabled, applicationB->is_disabled);
220   STR_EQ(applicationA->splash_screen_display,
221       applicationB->splash_screen_display);
222   STR_EQ(applicationA->external_path, applicationB->external_path);
223   STR_EQ(applicationA->package_system, applicationB->package_system);
224   STR_EQ(applicationA->removable, applicationB->removable);
225   STR_EQ(applicationA->package_installed_time,
226       applicationB->package_installed_time);
227   STR_EQ(applicationA->support_mode, applicationB->support_mode);
228
229   INT_EQ(g_list_length(applicationA->label),
230       g_list_length(applicationB->label));
231   for (GList *a = applicationA->label, *b = applicationB->label;
232       a && b; a = a->next, b = b->next) {
233     label_x *label_a = reinterpret_cast<label_x *>(a->data);
234     label_x *label_b = reinterpret_cast<label_x *>(b->data);
235     STR_EQ(label_a->lang, label_b->lang);
236     STR_EQ(label_a->name, label_b->name);
237     STR_EQ(label_a->text, label_b->text);
238   }
239
240   INT_EQ(g_list_length(applicationA->icon),
241       g_list_length(applicationB->icon));
242   for (GList *a = applicationA->icon, *b = applicationB->icon;
243       a && b; a = a->next, b = b->next) {
244     icon_x *icon_a = reinterpret_cast<icon_x *>(a->data);
245     icon_x *icon_b = reinterpret_cast<icon_x *>(b->data);
246     STR_EQ(icon_a->dpi, icon_b->dpi);
247     STR_EQ(icon_a->lang, icon_b->lang);
248     STR_EQ(icon_a->resolution, icon_b->resolution);
249     STR_EQ(icon_a->section, icon_b->section);
250     STR_EQ(icon_a->size, icon_b->size);
251     STR_EQ(icon_a->text, icon_b->text);
252   }
253
254   INT_EQ(g_list_length(applicationA->image),
255       g_list_length(applicationB->image));
256   for (GList *a = applicationA->image, *b = applicationB->image;
257       a && b; a = a->next, b = b->next) {
258     image_x *image_a = reinterpret_cast<image_x *>(a->data);
259     image_x *image_b = reinterpret_cast<image_x *>(b->data);
260     STR_EQ(image_a->lang, image_b->lang);
261     STR_EQ(image_a->section, image_b->section);
262     STR_EQ(image_a->text, image_b->text);
263   }
264
265   INT_EQ(g_list_length(applicationA->category),
266       g_list_length(applicationB->category));
267   for (GList *a = applicationA->category, *b = applicationB->category;
268       a && b; a = a->next, b = b->next) {
269     char *category_a = reinterpret_cast<char *>(a->data);
270     char *category_b = reinterpret_cast<char *>(b->data);
271     STR_EQ(category_a, category_b);
272   }
273
274   INT_EQ(g_list_length(applicationA->metadata),
275       g_list_length(applicationB->metadata));
276   for (GList *a = applicationA->metadata, *b = applicationB->metadata;
277       a && b; a = a->next, b = b->next) {
278     metadata_x *metadata_a = reinterpret_cast<metadata_x *>(a->data);
279     metadata_x *metadata_b = reinterpret_cast<metadata_x *>(b->data);
280     STR_EQ(metadata_a->key, metadata_b->key);
281     STR_EQ(metadata_a->value, metadata_b->value);
282   }
283
284   INT_EQ(g_list_length(applicationA->datacontrol),
285       g_list_length(applicationB->datacontrol));
286   for (GList *a = applicationA->datacontrol, *b = applicationB->datacontrol;
287       a && b; a = a->next, b = b->next) {
288     datacontrol_x *datacontrol_a = reinterpret_cast<datacontrol_x *>(a->data);
289     datacontrol_x *datacontrol_b = reinterpret_cast<datacontrol_x *>(b->data);
290     STR_EQ(datacontrol_a->access, datacontrol_b->access);
291     STR_EQ(datacontrol_a->providerid, datacontrol_b->providerid);
292     STR_EQ(datacontrol_a->trusted, datacontrol_b->trusted);
293     STR_EQ(datacontrol_a->type, datacontrol_b->type);
294     INT_EQ(g_list_length(datacontrol_a->privileges)
295         , g_list_length(datacontrol_b->privileges));
296     for (GList *a = datacontrol_a->privileges, *b = datacontrol_b->privileges;
297         a && b; a = a->next, b = b->next) {
298       char *privilege_a = reinterpret_cast<char *>(a->data);
299       char *privilege_b = reinterpret_cast<char *>(b->data);
300       STR_EQ(privilege_a, privilege_b);
301     }
302   }
303
304   INT_EQ(g_list_length(applicationA->background_category),
305       g_list_length(applicationB->background_category));
306   for (GList *a = applicationA->background_category,
307       *b = applicationB->background_category;
308       a && b; a = a->next, b = b->next) {
309     char *background_category_a = reinterpret_cast<char *>(a->data);
310     char *background_category_b = reinterpret_cast<char *>(b->data);
311     STR_EQ(background_category_a, background_category_b);
312   }
313
314   INT_EQ(g_list_length(applicationA->appcontrol),
315       g_list_length(applicationB->appcontrol));
316   for (GList *a = applicationA->appcontrol, *b = applicationB->appcontrol;
317       a && b; a = a->next, b = b->next) {
318     appcontrol_x *appcontrol_a = reinterpret_cast<appcontrol_x *>(a->data);
319     appcontrol_x *appcontrol_b = reinterpret_cast<appcontrol_x *>(b->data);
320     STR_EQ(appcontrol_a->id, appcontrol_b->id);
321     STR_EQ(appcontrol_a->mime, appcontrol_b->mime);
322     STR_EQ(appcontrol_a->operation, appcontrol_b->operation);
323     STR_EQ(appcontrol_a->uri, appcontrol_b->uri);
324     STR_EQ(appcontrol_a->visibility, appcontrol_b->visibility);
325     INT_EQ(g_list_length(appcontrol_a->privileges)
326         , g_list_length(appcontrol_b->privileges));
327     for (GList *a = appcontrol_a->privileges, *b = appcontrol_b->privileges;
328         a && b; a = a->next, b = b->next) {
329       char *privilege_a = reinterpret_cast<char *>(a->data);
330       char *privilege_b = reinterpret_cast<char *>(b->data);
331       STR_EQ(privilege_a, privilege_b);
332     }
333   }
334
335   INT_EQ(g_list_length(applicationA->splashscreens),
336       g_list_length(applicationB->splashscreens));
337   for (GList *a = applicationA->splashscreens,
338       *b = applicationB->splashscreens;
339       a && b; a = a->next, b = b->next) {
340     splashscreen_x *splashscreen_a =
341         reinterpret_cast<splashscreen_x *>(a->data);
342     splashscreen_x *splashscreen_b =
343         reinterpret_cast<splashscreen_x *>(b->data);
344     STR_EQ(splashscreen_a->color_depth, splashscreen_b->color_depth);
345     STR_EQ(splashscreen_a->dpi, splashscreen_b->dpi);
346     STR_EQ(splashscreen_a->indicatordisplay, splashscreen_b->indicatordisplay);
347     STR_EQ(splashscreen_a->operation, splashscreen_b->operation);
348     STR_EQ(splashscreen_a->orientation, splashscreen_b->orientation);
349     STR_EQ(splashscreen_a->src, splashscreen_b->src);
350     STR_EQ(splashscreen_a->type, splashscreen_b->type);
351   }
352
353   return true;
354 }
355
356 bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
357     const std::vector<application_x *>& applicationsB) {
358
359   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
360     if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
361       return false;
362   }
363
364   return true;
365 }
366
367 package_x *GetTestPackage(std::string pkgid) {
368   package_x *package;
369   package = reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
370
371   package->for_all_users = strdup("test_for_all_users");
372   package->package = strdup(pkgid.c_str());
373   package->version = strdup("test_version");
374   package->installlocation = strdup("test_installlocation");
375   package->ns = strdup("test_ns");
376   package->removable = strdup("test_removable");
377   package->preload = strdup("test_preload");
378   package->readonly = strdup("test_readonly");
379   package->update = strdup("test_update");
380   package->appsetting = strdup("test_appsetting");
381   package->system = strdup("test_system");
382   package->type = strdup("test_type");
383   package->package_size = strdup("test_package_size");
384   package->installed_time = strdup("test_installed_time");
385   package->installed_storage = strdup("test_installed_storage");
386   package->storeclient_id = strdup("test_storeclient_id");
387   package->mainapp_id = strdup("test_mainapp_id");
388   package->package_url = strdup("test_package_url");
389   package->root_path = strdup("test_root_path");
390   package->csc_path = strdup("test_csc_path");
391   package->nodisplay_setting = strdup("test_nodisplay_setting");
392   package->support_mode = strdup("test_support_mode");
393   package->support_disable = strdup("test_support_disable");
394   package->api_version = strdup("test_api_version");
395   package->tep_name = strdup("test_tep_name");
396   package->zip_mount_file = strdup("test_zip_mount_file");
397   package->backend_installer = strdup("test_backend_installer");
398   package->external_path = strdup("test_external_path");
399   package->use_system_certs = strdup("test_use_system_certs");
400
401   icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
402   icon->text = strdup("test_text");
403   icon->lang = strdup("test_lang");
404   icon->section = strdup("test_section");
405   icon->size = strdup("test_size");
406   icon->resolution = strdup("test_resolution");
407   icon->dpi = strdup("test_dpi");
408   package->icon = g_list_append(package->icon, icon);
409
410
411   label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
412   label->lang = strdup("test_lang");
413   label->name = strdup("test_name");
414   label->text = strdup("test_text");
415
416   package->label = g_list_append(package->label, label);
417
418   author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
419   author->email = strdup("test_email");
420   author->href = strdup("test_href");
421   author->text = strdup("test_text");
422   author->lang = strdup("test_lang");
423
424   package->author = g_list_append(package->author, author);
425
426   description_x* description =
427       reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
428   description->name = strdup("test_name");
429   description->text = strdup("test_text");
430   description->lang = strdup("test_lang");
431
432   package->description = g_list_append(package->description, description);
433
434   privilege_x* privilege =
435       reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
436   privilege->type = strdup("test_type");
437   privilege->value = strdup("test_value");
438
439   package->privileges = g_list_append(package->privileges, privilege);
440
441   appdefined_privilege_x* appdefined_privilege =
442       reinterpret_cast<appdefined_privilege_x*>(
443           calloc(1, sizeof(appdefined_privilege_x)));
444   appdefined_privilege->type = strdup("test_type");
445   appdefined_privilege->value = strdup("test_value");
446   appdefined_privilege->license = strdup("test_license");
447
448   package->appdefined_privileges =
449       g_list_append(package->appdefined_privileges, appdefined_privilege);
450
451   appdefined_privilege_x* provides_appdefined_privileges =
452       reinterpret_cast<appdefined_privilege_x*>(
453           calloc(1, sizeof(appdefined_privilege_x)));
454   provides_appdefined_privileges->type = strdup("test_type");
455   provides_appdefined_privileges->value = strdup("test_value");
456   provides_appdefined_privileges->license = strdup("test_license");
457
458   package->provides_appdefined_privileges =
459       g_list_append(package->provides_appdefined_privileges,
460           provides_appdefined_privileges);
461
462   dependency_x* dependency =
463       reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
464   dependency->depends_on = strdup("test_depends_on");
465   dependency->type = strdup("test_type");
466   dependency->required_version = strdup("test_required_version");
467
468   package->dependencies = g_list_append(package->dependencies, dependency);
469
470   plugin_x* plugin = reinterpret_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
471   plugin->pkgid = strdup(pkgid.c_str());
472   plugin->appid = strdup("test_appid");
473   plugin->plugin_type = strdup("test_plugin_type");
474   plugin->plugin_name = strdup("test_plugin_name");
475
476   package->plugin = g_list_append(package->plugin, plugin);
477
478   package->application = g_list_append(package->application,
479       GetTestApplication("test_app1"));
480   package->application = g_list_append(package->application,
481       GetTestApplication("test_app2"));
482
483   return package;
484 }
485
486 bool IsEqualPackage(package_x *packageA, package_x *packageB) {
487   STR_EQ(packageA->for_all_users, packageB->for_all_users);
488   STR_EQ(packageA->package, packageB->package);
489   STR_EQ(packageA->version, packageB->version);
490   STR_EQ(packageA->installlocation, packageB->installlocation);
491   STR_EQ(packageA->ns, packageB->ns);
492   STR_EQ(packageA->removable, packageB->removable);
493   STR_EQ(packageA->preload, packageB->preload);
494   STR_EQ(packageA->readonly, packageB->readonly);
495   STR_EQ(packageA->update, packageB->update);
496   STR_EQ(packageA->appsetting, packageB->appsetting);
497   STR_EQ(packageA->system, packageB->system);
498   STR_EQ(packageA->type, packageB->type);
499   STR_EQ(packageA->package_size, packageB->package_size);
500   STR_EQ(packageA->installed_time, packageB->installed_time);
501   STR_EQ(packageA->installed_storage, packageB->installed_storage);
502   STR_EQ(packageA->storeclient_id, packageB->storeclient_id);
503   STR_EQ(packageA->mainapp_id, packageB->mainapp_id);
504   STR_EQ(packageA->package_url, packageB->package_url);
505   STR_EQ(packageA->root_path, packageB->root_path);
506   STR_EQ(packageA->csc_path, packageB->csc_path);
507   STR_EQ(packageA->nodisplay_setting, packageB->nodisplay_setting);
508   STR_EQ(packageA->support_mode, packageB->support_mode);
509   STR_EQ(packageA->support_disable, packageB->support_disable);
510   STR_EQ(packageA->api_version, packageB->api_version);
511   STR_EQ(packageA->tep_name, packageB->tep_name);
512   STR_EQ(packageA->zip_mount_file, packageB->zip_mount_file);
513   STR_EQ(packageA->backend_installer, packageB->backend_installer);
514   STR_EQ(packageA->external_path, packageB->external_path);
515   STR_EQ(packageA->use_system_certs, packageB->use_system_certs);
516
517   INT_EQ(g_list_length(packageA->icon), g_list_length(packageB->icon));
518   for (GList *a = packageA->icon, *b = packageB->icon;
519       a && b; a = a->next, b = b->next) {
520     icon_x *icon_a = reinterpret_cast<icon_x *>(a->data);
521     icon_x *icon_b = reinterpret_cast<icon_x *>(b->data);
522     STR_EQ(icon_a->dpi, icon_b->dpi);
523     STR_EQ(icon_a->lang, icon_b->lang);
524     STR_EQ(icon_a->resolution, icon_b->resolution);
525     STR_EQ(icon_a->section, icon_b->section);
526     STR_EQ(icon_a->size, icon_b->size);
527     STR_EQ(icon_a->text, icon_b->text);
528   }
529
530   INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
531   for (GList *a = packageA->label, *b = packageB->label;
532       a && b; a = a->next, b = b->next) {
533     label_x *label_a = reinterpret_cast<label_x *>(a->data);
534     label_x *label_b = reinterpret_cast<label_x *>(b->data);
535     STR_EQ(label_a->lang, label_b->lang);
536     STR_EQ(label_a->name, label_b->name);
537     STR_EQ(label_a->text, label_b->text);
538   }
539
540   INT_EQ(g_list_length(packageA->author), g_list_length(packageB->author));
541   for (GList *a = packageA->author, *b = packageB->author;
542       a && b; a = a->next, b = b->next) {
543     author_x *author_a = reinterpret_cast<author_x *>(a->data);
544     author_x *author_b = reinterpret_cast<author_x *>(b->data);
545     STR_EQ(author_a->email, author_b->email);
546     STR_EQ(author_a->href, author_b->href);
547     STR_EQ(author_a->lang, author_b->lang);
548     STR_EQ(author_a->text, author_b->text);
549   }
550
551   INT_EQ(g_list_length(packageA->description),
552       g_list_length(packageB->description));
553   for (GList *a = packageA->description, *b = packageB->description;
554       a && b; a = a->next, b = b->next) {
555     description_x *description_a = reinterpret_cast<description_x *>(a->data);
556     description_x *description_b = reinterpret_cast<description_x *>(b->data);
557     STR_EQ(description_a->lang, description_b->lang);
558     STR_EQ(description_a->name, description_b->name);
559     STR_EQ(description_a->text, description_b->text);
560   }
561
562   INT_EQ(g_list_length(packageA->privileges),
563       g_list_length(packageB->privileges));
564   for (GList *a = packageA->privileges, *b = packageB->privileges;
565       a && b; a = a->next, b = b->next) {
566     privilege_x *privilege_a = reinterpret_cast<privilege_x *>(a->data);
567     privilege_x *privilege_b = reinterpret_cast<privilege_x *>(b->data);
568     STR_EQ(privilege_a->type, privilege_b->type);
569     STR_EQ(privilege_a->value, privilege_b->value);
570   }
571
572   INT_EQ(g_list_length(packageA->appdefined_privileges),
573       g_list_length(packageB->appdefined_privileges));
574   for (GList *a = packageA->appdefined_privileges,
575       *b = packageB->appdefined_privileges;
576       a && b; a = a->next, b = b->next) {
577     appdefined_privilege_x *privilege_a =
578         reinterpret_cast<appdefined_privilege_x *>(a->data);
579     appdefined_privilege_x *privilege_b =
580         reinterpret_cast<appdefined_privilege_x *>(b->data);
581     STR_EQ(privilege_a->license, privilege_b->license);
582     STR_EQ(privilege_a->type, privilege_b->type);
583     STR_EQ(privilege_a->value, privilege_b->value);
584   }
585
586   INT_EQ(g_list_length(packageA->provides_appdefined_privileges),
587       g_list_length(packageB->provides_appdefined_privileges));
588   for (GList *a = packageA->provides_appdefined_privileges,
589       *b = packageB->provides_appdefined_privileges;
590       a && b; a = a->next, b = b->next) {
591     appdefined_privilege_x *privilege_a =
592         reinterpret_cast<appdefined_privilege_x *>(a->data);
593     appdefined_privilege_x *privilege_b =
594         reinterpret_cast<appdefined_privilege_x *>(b->data);
595     STR_EQ(privilege_a->license, privilege_b->license);
596     STR_EQ(privilege_a->type, privilege_b->type);
597     STR_EQ(privilege_a->value, privilege_b->value);
598   }
599
600   INT_EQ(g_list_length(packageA->dependencies),
601       g_list_length(packageB->dependencies));
602   for (GList *a = packageA->dependencies, *b = packageB->dependencies;
603       a && b; a = a->next, b = b->next) {
604     dependency_x *dependency_a = reinterpret_cast<dependency_x *>(a->data);
605     dependency_x *dependency_b = reinterpret_cast<dependency_x *>(b->data);
606     STR_EQ(dependency_a->depends_on, dependency_b->depends_on);
607     STR_EQ(dependency_a->required_version, dependency_b->required_version);
608     STR_EQ(dependency_a->type, dependency_b->type);
609   }
610
611   INT_EQ(g_list_length(packageA->plugin), g_list_length(packageB->plugin));
612   for (GList *a = packageA->plugin, *b = packageB->plugin;
613       a && b; a = a->next, b = b->next) {
614     plugin_x *plugin_a = reinterpret_cast<plugin_x *>(a->data);
615     plugin_x *plugin_b = reinterpret_cast<plugin_x *>(b->data);
616     STR_EQ(plugin_a->appid, plugin_b->appid);
617     STR_EQ(plugin_a->pkgid, plugin_b->pkgid);
618     STR_EQ(plugin_a->plugin_name, plugin_b->plugin_name);
619     STR_EQ(plugin_a->plugin_type, plugin_b->plugin_type);
620   }
621
622   INT_EQ(g_list_length(packageA->application),
623       g_list_length(packageB->application));
624   for (GList *a = packageA->application, *b = packageB->application;
625       a && b; a = a->next, b = b->next) {
626     application_x *application_a = reinterpret_cast<application_x *>(a->data);
627     application_x *application_b = reinterpret_cast<application_x *>(b->data);
628
629     if (!IsEqualApplication(application_a, application_b))
630       return false;
631   }
632
633   return true;
634 }
635
636 bool IsEqualPackages(const std::vector<package_x *>&packagesA,
637     const std::vector<package_x *>&packagesB) {
638   if (packagesA.size() != packagesB.size())
639     return false;
640
641   for (unsigned int i = 0; i < packagesA.size(); ++i) {
642     if (!IsEqualPackage(packagesA[i], packagesB[i]))
643       return false;
644   }
645
646   return true;
647 }
648
649 pkgmgrinfo_filter_x *GetTestFilter() {
650   pkgmgrinfo_filter_x *filter;
651   pkgmgrinfo_node_x *node;
652   pkgmgrinfo_metadata_node_x *metadata_node;
653   filter = reinterpret_cast<pkgmgrinfo_filter_x*>(
654       calloc(1, sizeof(pkgmgrinfo_filter_x)));
655
656   filter->uid = 1234;
657   node = reinterpret_cast<pkgmgrinfo_node_x *>(
658       calloc(1, sizeof(pkgmgrinfo_node_x)));
659   node->prop = 4321;
660   node->key = strdup("test_key1");
661   node->value = strdup("test_value1");
662   filter->list = g_slist_append(filter->list, node);
663
664   node = reinterpret_cast<pkgmgrinfo_node_x *>(
665       calloc(1, sizeof(pkgmgrinfo_node_x)));
666   node->prop = 4321;
667   node->key = strdup("test_key2");
668   node->value = strdup("test_value2");
669   filter->list = g_slist_append(filter->list, node);
670
671   metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(
672       calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
673   metadata_node->key = strdup("test_metadata_key1");
674   metadata_node->value = strdup("test_metadata_value1");
675   filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
676
677   metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(
678       calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
679   metadata_node->key = strdup("test_metadata_key2");
680   metadata_node->value = strdup("test_metadata_value2");
681   filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
682
683   return filter;
684 }
685
686 bool IsEqualFilter(const pkgmgrinfo_filter_x *filterA,
687     const pkgmgrinfo_filter_x *filterB) {
688   INT_EQ(filterA->uid, filterB->uid);
689
690   INT_EQ(g_slist_length(filterA->list), g_slist_length(filterB->list));
691   for (GSList *a = filterA->list, *b = filterB->list;
692       a && b; a = a->next, b = b->next) {
693     pkgmgrinfo_node_x *node_a = reinterpret_cast<pkgmgrinfo_node_x *>(a->data);
694     pkgmgrinfo_node_x *node_b = reinterpret_cast<pkgmgrinfo_node_x *>(b->data);
695     INT_EQ(node_a->prop, node_b->prop);
696     STR_EQ(node_a->key, node_b->key);
697     STR_EQ(node_a->value, node_b->value);
698   }
699
700   INT_EQ(g_slist_length(filterA->list_metadata),
701       g_slist_length(filterB->list_metadata));
702   for (GSList *a = filterA->list_metadata, *b = filterB->list_metadata;
703       a && b; a = a->next, b = b->next) {
704     pkgmgrinfo_metadata_node_x *node_a =
705         reinterpret_cast<pkgmgrinfo_metadata_node_x *>(a->data);
706     pkgmgrinfo_metadata_node_x *node_b =
707         reinterpret_cast<pkgmgrinfo_metadata_node_x *>(b->data);
708     STR_EQ(node_a->key, node_b->key);
709     STR_EQ(node_a->value, node_b->value);
710   }
711
712   return true;
713 }
714
715 pkgmgr_certinfo_x *GetTestCertInfo() {
716   pkgmgr_certinfo_x *cert_info;
717   cert_info = reinterpret_cast<pkgmgr_certinfo_x*>(
718       calloc(1, sizeof(pkgmgr_certinfo_x)));
719
720   cert_info->for_all_users = 1;
721   cert_info->pkgid = strdup("test_pkgid");
722   cert_info->cert_value = strdup("test_cert_value");
723   for (int i = 0; i < MAX_CERT_TYPE; ++i) {
724     char buf[1024] = { 0, };
725     snprintf(buf, sizeof(buf), "test_cert_info_%d", i);
726     cert_info->cert_info[i] = strdup(buf);
727   }
728   for (int i = 0; i < MAX_CERT_TYPE; ++i) {
729     cert_info->cert_id[i] = i + 1000;
730   }
731
732   return cert_info;
733 }
734
735 bool IsEqualCertInfo(const pkgmgr_certinfo_x *certA,
736     const pkgmgr_certinfo_x *certB) {
737   INT_EQ(certA->for_all_users, certB->for_all_users);
738   STR_EQ(certA->pkgid, certB->pkgid);
739   STR_EQ(certA->cert_value, certB->cert_value);
740   for (int i = 0; i < MAX_CERT_TYPE; ++i)
741     STR_EQ(certA->cert_info[i], certB->cert_info[i]);
742   for (int i = 0; i < MAX_CERT_TYPE; ++i)
743     INT_EQ(certA->cert_id[i], certB->cert_id[i]);
744
745   return true;
746 }
747
748 dependency_x *GetTestDepInfo(std::string pkgid) {
749   dependency_x *dependency;
750   dependency = reinterpret_cast<dependency_x *>(
751       calloc(1, sizeof(dependency_x)));
752
753   dependency->pkgid = strdup(pkgid.c_str());
754   dependency->depends_on = strdup("test_depends_on");
755   dependency->required_version = strdup("test_required_version");
756   dependency->type = strdup("test_type");
757
758   return dependency;
759 }
760
761 bool IsEqualDepInfo(const std::vector<dependency_x *>& depA,
762     const std::vector<dependency_x *>& depB) {
763   INT_EQ(depA.size(), depB.size());
764
765   for (int i = 0; i < static_cast<int>(depA.size()); ++i) {
766     dependency_x *A = depA[0];
767     dependency_x *B = depB[0];
768     STR_EQ(A->depends_on, B->depends_on);
769     STR_EQ(A->pkgid, B->pkgid);
770     STR_EQ(A->required_version, B->required_version);
771     STR_EQ(A->type, B->type);
772   }
773
774   return true;
775 }