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