2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include "parcel_utils.hh"
21 #include "pkgmgrinfo_basic.h"
23 bool IS_STR_EQ(const char* a, const char* b) {
24 if (a == nullptr && b == nullptr)
26 if (a == nullptr || b == nullptr)
28 return strcmp(a, b) == 0;
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; \
39 #define INT_EQ(a, b) do { \
41 std::cout << #a << "(" << a << ") is not equal to " \
42 << #b << "(" << b << ")" << std::endl; \
47 application_x* GetTestApplication(std::string appid) {
48 application_x* application;
50 reinterpret_cast<application_x*>(calloc(1, sizeof(application_x)));
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");
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);
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);
112 application->category =
113 g_list_append(application->category, strdup("test_category"));
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);
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);
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"));
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
390 bool IsEqualApplicationsStructure(
391 const std::vector<std::shared_ptr<application_x>>& applicationsA,
392 const std::vector<std::shared_ptr<application_x>>& applicationsB) {
394 for (unsigned int i = 0; i < applicationsA.size(); ++i) {
395 if (!IsEqualApplication(applicationsA[i].get(), applicationsB[i].get()))
397 if (!IsEqualApplicationExtraInfo(applicationsA[i].get(),
398 applicationsB[i].get()))
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()))
416 package_x* GetTestPackage(std::string pkgid) {
418 package = reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
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->lib = strdup("false");
452 package->light_user_switch_mode = strdup("default");
454 icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
455 icon->text = strdup("test_text");
456 icon->lang = strdup("test_lang");
457 icon->section = strdup("test_section");
458 icon->size = strdup("test_size");
459 icon->resolution = strdup("test_resolution");
460 icon->dpi = strdup("ldpi");
461 package->icon = g_list_append(package->icon, icon);
464 label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
465 label->lang = strdup("test_lang");
466 label->name = strdup("test_name");
467 label->text = strdup("test_text");
468 package->label = g_list_append(package->label, label);
471 author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
472 author->email = strdup("test_email");
473 author->href = strdup("test_href");
474 author->text = strdup("test_text");
475 author->lang = strdup("test_lang");
477 package->author = g_list_append(package->author, author);
479 description_x* description =
480 reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
481 description->name = strdup("test_name");
482 description->text = strdup("test_text");
483 description->lang = strdup("test_lang");
485 package->description = g_list_append(package->description, description);
487 privilege_x* privilege =
488 reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
489 privilege->type = strdup("test_type");
490 privilege->value = strdup("test_value");
492 package->privileges = g_list_append(package->privileges, privilege);
494 appdefined_privilege_x* appdefined_privilege =
495 reinterpret_cast<appdefined_privilege_x*>(
496 calloc(1, sizeof(appdefined_privilege_x)));
497 appdefined_privilege->type = strdup("test_type");
498 appdefined_privilege->value = strdup("test_value");
499 appdefined_privilege->license = strdup("test_license");
501 package->appdefined_privileges =
502 g_list_append(package->appdefined_privileges, appdefined_privilege);
504 appdefined_privilege_x* provides_appdefined_privileges =
505 reinterpret_cast<appdefined_privilege_x*>(
506 calloc(1, sizeof(appdefined_privilege_x)));
507 provides_appdefined_privileges->type = strdup("test_type");
508 provides_appdefined_privileges->value = strdup("test_value");
509 provides_appdefined_privileges->license = strdup("test_license");
511 package->provides_appdefined_privileges =
512 g_list_append(package->provides_appdefined_privileges,
513 provides_appdefined_privileges);
515 package->dependencies = g_list_append(package->dependencies,
516 GetTestDepInfo(pkgid));
518 plugin_x* plugin = reinterpret_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
519 plugin->pkgid = strdup(pkgid.c_str());
520 plugin->appid = strdup("test_appid");
521 plugin->plugin_type = strdup("test_plugin_type");
522 plugin->plugin_name = strdup("test_plugin_name");
524 package->plugin = g_list_append(package->plugin, plugin);
526 res_allowed_package_x* allowed_package =
527 reinterpret_cast<res_allowed_package_x*>(calloc(1,
528 sizeof(res_allowed_package_x)));
529 allowed_package->allowed_package = strdup("test_allowed_package");
530 allowed_package->required_privileges = g_list_append(
531 allowed_package->required_privileges,
532 strdup("test_required_privilege1"));
534 package->res_allowed_packages =
535 g_list_append(package->res_allowed_packages, allowed_package);
537 package->application = g_list_append(package->application,
538 GetTestApplication("test_app1"));
539 package->application = g_list_append(package->application,
540 GetTestApplication("test_app2"));
545 package_x* GetUpdatedTestPackage(std::string pkgid) {
546 auto package = GetTestPackage(pkgid);
548 free(package->version);
549 package->version = strdup("2.0.0");
554 bool IsEqualPackageExtraInfo(package_x* packageA, package_x* packageB) {
555 STR_EQ(packageA->ns, packageB->ns);
556 STR_EQ(packageA->backend_installer, packageB->backend_installer);
557 STR_EQ(packageA->use_system_certs, packageB->use_system_certs);
559 for (GList* a = packageA->icon, *b = packageB->icon;
560 a && b; a = a->next, b = b->next) {
561 icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
562 icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
563 STR_EQ(icon_a->dpi, icon_b->dpi);
564 STR_EQ(icon_a->resolution, icon_b->resolution);
565 STR_EQ(icon_a->section, icon_b->section);
566 STR_EQ(icon_a->size, icon_b->size);
569 INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
570 for (GList* a = packageA->label, *b = packageB->label;
571 a && b; a = a->next, b = b->next) {
572 label_x* label_a = reinterpret_cast<label_x*>(a->data);
573 label_x* label_b = reinterpret_cast<label_x*>(b->data);
574 STR_EQ(label_a->name, label_b->name);
577 INT_EQ(g_list_length(packageA->author), g_list_length(packageB->author));
578 for (GList* a = packageA->author, *b = packageB->author;
579 a && b; a = a->next, b = b->next) {
580 author_x* author_a = reinterpret_cast<author_x* >(a->data);
581 author_x* author_b = reinterpret_cast<author_x* >(b->data);
582 STR_EQ(author_a->email, author_b->email);
583 STR_EQ(author_a->href, author_b->href);
584 STR_EQ(author_a->lang, author_b->lang);
585 STR_EQ(author_a->text, author_b->text);
588 INT_EQ(g_list_length(packageA->description),
589 g_list_length(packageB->description));
590 for (GList* a = packageA->description, *b = packageB->description;
591 a && b; a = a->next, b = b->next) {
592 description_x* description_a = reinterpret_cast<description_x* >(a->data);
593 description_x* description_b = reinterpret_cast<description_x* >(b->data);
594 STR_EQ(description_a->name, description_b->name);
597 INT_EQ(g_list_length(packageA->provides_appdefined_privileges),
598 g_list_length(packageB->provides_appdefined_privileges));
599 for (GList* a = packageA->provides_appdefined_privileges,
600 *b = packageB->provides_appdefined_privileges;
601 a && b; a = a->next, b = b->next) {
602 appdefined_privilege_x* privilege_a =
603 reinterpret_cast<appdefined_privilege_x* >(a->data);
604 appdefined_privilege_x* privilege_b =
605 reinterpret_cast<appdefined_privilege_x* >(b->data);
606 STR_EQ(privilege_a->license, privilege_b->license);
607 STR_EQ(privilege_a->type, privilege_b->type);
608 STR_EQ(privilege_a->value, privilege_b->value);
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);
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);
629 if (!IsEqualApplication(application_a, application_b))
631 if (!IsEqualApplicationExtraInfo(application_a, application_b))
638 bool IsEqualPackage(package_x* packageA, package_x* packageB) {
639 STR_EQ(packageA->for_all_users, packageB->for_all_users);
640 STR_EQ(packageA->package, packageB->package);
641 STR_EQ(packageA->version, packageB->version);
642 STR_EQ(packageA->installlocation, packageB->installlocation);
643 STR_EQ(packageA->removable, packageB->removable);
644 STR_EQ(packageA->preload, packageB->preload);
645 STR_EQ(packageA->readonly, packageB->readonly);
646 STR_EQ(packageA->update, packageB->update);
647 STR_EQ(packageA->appsetting, packageB->appsetting);
648 STR_EQ(packageA->system, packageB->system);
649 STR_EQ(packageA->type, packageB->type);
650 STR_EQ(packageA->package_size, packageB->package_size);
651 STR_EQ(packageA->installed_time, packageB->installed_time);
652 STR_EQ(packageA->installed_storage, packageB->installed_storage);
653 STR_EQ(packageA->storeclient_id, packageB->storeclient_id);
654 STR_EQ(packageA->mainapp_id, packageB->mainapp_id);
655 STR_EQ(packageA->package_url, packageB->package_url);
656 STR_EQ(packageA->root_path, packageB->root_path);
657 STR_EQ(packageA->csc_path, packageB->csc_path);
658 STR_EQ(packageA->nodisplay_setting, packageB->nodisplay_setting);
659 STR_EQ(packageA->support_mode, packageB->support_mode);
660 STR_EQ(packageA->support_disable, packageB->support_disable);
661 STR_EQ(packageA->api_version, packageB->api_version);
662 STR_EQ(packageA->tep_name, packageB->tep_name);
663 STR_EQ(packageA->zip_mount_file, packageB->zip_mount_file);
664 STR_EQ(packageA->external_path, packageB->external_path);
665 STR_EQ(packageA->light_user_switch_mode, packageB->light_user_switch_mode);
667 INT_EQ(g_list_length(packageA->icon), g_list_length(packageB->icon));
668 for (GList* a = packageA->icon, *b = packageB->icon;
669 a && b; a = a->next, b = b->next) {
670 icon_x* icon_a = reinterpret_cast<icon_x*>(a->data);
671 icon_x* icon_b = reinterpret_cast<icon_x*>(b->data);
672 STR_EQ(icon_a->lang, icon_b->lang);
673 STR_EQ(icon_a->text, icon_b->text);
676 INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
677 for (GList* a = packageA->label, *b = packageB->label;
678 a && b; a = a->next, b = b->next) {
679 label_x* label_a = reinterpret_cast<label_x*>(a->data);
680 label_x* label_b = reinterpret_cast<label_x*>(b->data);
681 STR_EQ(label_a->lang, label_b->lang);
682 STR_EQ(label_a->text, label_b->text);
685 INT_EQ(g_list_length(packageA->description),
686 g_list_length(packageB->description));
687 for (GList* a = packageA->description, *b = packageB->description;
688 a && b; a = a->next, b = b->next) {
689 description_x* description_a = reinterpret_cast<description_x*>(a->data);
690 description_x* description_b = reinterpret_cast<description_x*>(b->data);
691 STR_EQ(description_a->lang, description_b->lang);
692 STR_EQ(description_a->text, description_b->text);
695 INT_EQ(g_list_length(packageA->privileges),
696 g_list_length(packageB->privileges));
697 for (GList* a = packageA->privileges, *b = packageB->privileges;
698 a && b; a = a->next, b = b->next) {
699 privilege_x* privilege_a = reinterpret_cast<privilege_x*>(a->data);
700 privilege_x* privilege_b = reinterpret_cast<privilege_x*>(b->data);
701 STR_EQ(privilege_a->type, privilege_b->type);
702 STR_EQ(privilege_a->value, privilege_b->value);
705 INT_EQ(g_list_length(packageA->appdefined_privileges),
706 g_list_length(packageB->appdefined_privileges));
707 for (GList* a = packageA->appdefined_privileges,
708 *b = packageB->appdefined_privileges;
709 a && b; a = a->next, b = b->next) {
710 appdefined_privilege_x* privilege_a =
711 reinterpret_cast<appdefined_privilege_x*>(a->data);
712 appdefined_privilege_x* privilege_b =
713 reinterpret_cast<appdefined_privilege_x*>(b->data);
714 STR_EQ(privilege_a->license, privilege_b->license);
715 STR_EQ(privilege_a->type, privilege_b->type);
716 STR_EQ(privilege_a->value, privilege_b->value);
719 INT_EQ(g_list_length(packageA->dependencies),
720 g_list_length(packageB->dependencies));
721 for (GList* a = packageA->dependencies, *b = packageB->dependencies;
722 a && b; a = a->next, b = b->next) {
723 dependency_x* dependency_a = reinterpret_cast<dependency_x*>(a->data);
724 dependency_x* dependency_b = reinterpret_cast<dependency_x*>(b->data);
725 STR_EQ(dependency_a->depends_on, dependency_b->depends_on);
726 STR_EQ(dependency_a->required_version, dependency_b->required_version);
727 STR_EQ(dependency_a->type, dependency_b->type);
730 INT_EQ(g_list_length(packageA->res_allowed_packages),
731 g_list_length(packageB->res_allowed_packages));
732 for (GList* a = packageA->res_allowed_packages,
733 *b = packageB->res_allowed_packages; a && b; a = a->next, b = b->next) {
734 res_allowed_package_x* allowed_package_a =
735 reinterpret_cast<res_allowed_package_x*>(a->data);
736 res_allowed_package_x* allowed_package_b =
737 reinterpret_cast<res_allowed_package_x*>(b->data);
738 STR_EQ(allowed_package_a->allowed_package,
739 allowed_package_b->allowed_package);
741 INT_EQ(g_list_length(allowed_package_a->required_privileges),
742 g_list_length(allowed_package_b->required_privileges));
744 for (GList* a = allowed_package_a->required_privileges,
745 *b = allowed_package_b->required_privileges; a && b;
746 a = a->next, b = b->next) {
747 STR_EQ(reinterpret_cast<char*>(a->data),
748 reinterpret_cast<char*>(b->data));
755 bool IsEqualPackagesStructure(
756 const std::vector<std::shared_ptr<package_x>>& packagesA,
757 const std::vector<std::shared_ptr<package_x>>& packagesB) {
758 if (packagesA.size() != packagesB.size())
761 for (unsigned int i = 0; i < packagesA.size(); ++i) {
762 if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
764 if (!IsEqualPackageExtraInfo(packagesA[i].get(), packagesB[i].get()))
771 bool IsEqualPackagesInfo(
772 const std::vector<std::shared_ptr<package_x>>& packagesA,
773 const std::vector<std::shared_ptr<package_x>>& packagesB) {
774 if (packagesA.size() != packagesB.size())
777 for (unsigned int i = 0; i < packagesA.size(); ++i) {
778 if (!IsEqualPackage(packagesA[i].get(), packagesB[i].get()))
785 pkgmgrinfo_filter_x* GetTestFilter() {
786 pkgmgrinfo_filter_x* filter;
787 pkgmgrinfo_node_x* node;
788 pkgmgrinfo_metadata_node_x* metadata_node;
789 filter = reinterpret_cast<pkgmgrinfo_filter_x*>(
790 calloc(1, sizeof(pkgmgrinfo_filter_x)));
793 node = reinterpret_cast<pkgmgrinfo_node_x*>(
794 calloc(1, sizeof(pkgmgrinfo_node_x)));
796 node->key = strdup("test_key1");
797 node->value = strdup("test_value1");
798 filter->list = g_slist_append(filter->list, node);
800 node = reinterpret_cast<pkgmgrinfo_node_x*>(
801 calloc(1, sizeof(pkgmgrinfo_node_x)));
803 node->key = strdup("test_key2");
804 node->value = strdup("test_value2");
805 filter->list = g_slist_append(filter->list, node);
807 metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x*>(
808 calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
809 metadata_node->key = strdup("test_metadata_key1");
810 metadata_node->value = strdup("test_metadata_value1");
811 filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
813 metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x*>(
814 calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
815 metadata_node->key = strdup("test_metadata_key2");
816 metadata_node->value = strdup("test_metadata_value2");
817 filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
822 bool IsEqualFilter(const pkgmgrinfo_filter_x* filterA,
823 const pkgmgrinfo_filter_x* filterB) {
824 INT_EQ(filterA->uid, filterB->uid);
826 INT_EQ(g_slist_length(filterA->list), g_slist_length(filterB->list));
827 for (GSList* a = filterA->list, *b = filterB->list;
828 a && b; a = a->next, b = b->next) {
829 pkgmgrinfo_node_x* node_a = reinterpret_cast<pkgmgrinfo_node_x*>(a->data);
830 pkgmgrinfo_node_x* node_b = reinterpret_cast<pkgmgrinfo_node_x*>(b->data);
831 INT_EQ(node_a->prop, node_b->prop);
832 STR_EQ(node_a->key, node_b->key);
833 STR_EQ(node_a->value, node_b->value);
836 INT_EQ(g_slist_length(filterA->list_metadata),
837 g_slist_length(filterB->list_metadata));
838 for (GSList* a = filterA->list_metadata, *b = filterB->list_metadata;
839 a && b; a = a->next, b = b->next) {
840 pkgmgrinfo_metadata_node_x* node_a =
841 reinterpret_cast<pkgmgrinfo_metadata_node_x*>(a->data);
842 pkgmgrinfo_metadata_node_x* node_b =
843 reinterpret_cast<pkgmgrinfo_metadata_node_x*>(b->data);
844 STR_EQ(node_a->key, node_b->key);
845 STR_EQ(node_a->value, node_b->value);
851 pkgmgr_certinfo_x* GetTestCertInfo() {
852 pkgmgr_certinfo_x* cert_info;
853 cert_info = reinterpret_cast<pkgmgr_certinfo_x*>(
854 calloc(1, sizeof(pkgmgr_certinfo_x)));
856 cert_info->for_all_users = 1;
857 cert_info->pkgid = strdup("test_pkgid");
858 cert_info->cert_value = strdup("test_cert_value");
859 for (int i = 0; i < MAX_CERT_TYPE; ++i) {
860 char buf[1024] = { 0, };
861 snprintf(buf, sizeof(buf), "test_cert_info_%d", i);
862 cert_info->cert_info[i] = strdup(buf);
864 for (int i = 0; i < MAX_CERT_TYPE; ++i) {
865 cert_info->cert_id[i] = i + 1000;
871 bool IsEqualCertInfoStructure(const pkgmgr_certinfo_x* certA,
872 const pkgmgr_certinfo_x* certB) {
873 if (!IsEqualCertInfo(certA, certB))
876 STR_EQ(certA->pkgid, certB->pkgid);
877 STR_EQ(certA->cert_value, certB->cert_value);
878 INT_EQ(certA->for_all_users, certB->for_all_users);
882 bool IsEqualCertInfo(const pkgmgr_certinfo_x* certA,
883 const pkgmgr_certinfo_x* certB) {
884 for (int i = 0; i < MAX_CERT_TYPE; ++i)
885 STR_EQ(certA->cert_info[i], certB->cert_info[i]);
886 for (int i = 0; i < MAX_CERT_TYPE; ++i)
887 INT_EQ(certA->cert_id[i], certB->cert_id[i]);
892 dependency_x* GetTestDepInfo(std::string pkgid) {
893 dependency_x* dependency;
894 dependency = reinterpret_cast<dependency_x*>(
895 calloc(1, sizeof(dependency_x)));
897 dependency->pkgid = strdup(pkgid.c_str());
898 dependency->depends_on = strdup("depends_on_pkgid");
899 dependency->required_version = strdup("test_required_version");
900 dependency->type = strdup("test_type");
905 bool IsEqualDepInfo(const std::vector<dependency_x*>& depA,
906 const std::vector<dependency_x*>& depB) {
907 INT_EQ(depA.size(), depB.size());
909 for (unsigned int i = 0; i < depA.size(); ++i) {
910 dependency_x *A = depA[0];
911 dependency_x *B = depB[0];
912 STR_EQ(A->depends_on, B->depends_on);
913 STR_EQ(A->pkgid, B->pkgid);
914 STR_EQ(A->required_version, B->required_version);
915 STR_EQ(A->type, B->type);
921 pkgmgr_certinfo_x* GetTestCertificate() {
922 pkgmgr_certinfo_x* cert_info = reinterpret_cast<pkgmgr_certinfo_x*>(
923 calloc(1, sizeof(pkgmgr_certinfo_x)));
925 cert_info->for_all_users = 1;
926 cert_info->pkgid = strdup("test_pkgid");
927 cert_info->cert_value = strdup("test_certvalue");
928 for (int i = 0; i < MAX_CERT_TYPE; i++) {
929 std::string cert_value(std::to_string(i));
930 cert_value += "test_cert_value";
931 cert_info->cert_info[i] = strdup(cert_value.c_str());
932 cert_info->cert_id[i] = i + 1;