4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #include <sys/types.h>
30 #include <app2ext_interface.h>
36 app2ext_handle *handle = NULL;
38 #define TEST_PKGNAME "org.example.basicuiapplication"
40 char pkg_ro_content_rpm[3][5] = { "bin", "res", "lib" };
42 char error_list[45][100] = {
44 "APP2EXT_ERROR_UNKNOW",
45 "APP2EXT_ERROR_INVALID_ARGUMENTS",
47 "APP2EXT_ERROR_PRE_UNINSTALL",
48 "APP2EXT_ERROR_MMC_STATUS",
49 "APP2EXT_ERROR_DB_INITIALIZE",
50 "APP2EXT_ERROR_SQLITE_REGISTRY",
51 "APP2EXT_ERROR_PASSWD_GENERATION",
52 "APP2EXT_ERROR_MMC_INFORMATION",
53 "APP2EXT_ERROR_MMC_INSUFFICIENT_MEMORY",
54 "APP2EXT_ERROR_DELETE_DIRECTORY",
55 "APP2EXT_ERROR_CREATE_SYMLINK",
56 "APP2EXT_ERROR_CREATE_DIRECTORY",
57 "APP2EXT_ERROR_DELETE_LINK_FILE",
58 "APP2EXT_ERROR_PKG_EXISTS",
59 "APP2EXT_ERROR_ACCESS_FILE",
60 "APP2EXT_ERROR_OPEN_DIR",
61 "APP2EXT_ERROR_ALREADY_FILE_PRESENT",
62 "APP2EXT_ERROR_FILE_ABSENT",
63 "APP2EXT_ERROR_STRCMP_FAILED",
64 "APP2EXT_ERROR_INVALID_PACKAGE",
65 "APP2EXT_ERROR_CREATE_DIR_ENTRY",
66 "APP2EXT_ERROR_PASSWORD_GENERATION",
67 "APP2EXT_ERROR_COPY_DIRECTORY",
68 "APP2EXT_ERROR_INVALID_CASE",
69 "APP2EXT_ERROR_SYMLINK_ALREADY_EXISTS",
70 "APP2EXT_ERROR_APPEND_HASH_TO_FILE",
71 "APP2EXT_ERROR_CREATE_DEVICE",
72 "APP2EXT_ERROR_DO_LOSETUP",
73 "APP2EXT_ERROR_CREATE_FS",
74 "APP2EXT_ERROR_MOUNT_PATH",
75 "APP2EXT_ERROR_CLEANUP",
76 "APP2EXT_ERROR_MOUNT",
77 "APP2EXT_ERROR_REMOUNT",
78 "APP2EXT_ERROR_PIPE_CREATION",
79 "APP2EXT_ERROR_LOOPBACK_DEVICE_UNAVAILABLE",
80 "APP2EXT_ERROR_VCONF_REGISTRY",
81 "APP2EXT_ERROR_FIND_ASSOCIATED_DEVICE_NODE",
82 "APP2EXT_ERROR_UNMOUNT",
83 "APP2EXT_ERROR_DELETE_LOOPBACK_DEVICE",
84 "APP2EXT_ERROR_DETACH_LOOPBACK_DEVICE",
85 "APP2EXT_ERROR_ALREADY_MOUNTED",
86 "APP2EXT_ERROR_PLUGIN_INIT_FAILED",
87 "APP2EXT_ERROR_PLUGIN_DEINIT_FAILED"
90 static int __get_integer_input_data(void);
92 static int __get_integer_input_data(void)
94 char input_str[32] = { 0, };
97 if (fgets(input_str, 32, stdin) == NULL) {
98 printf("Input buffer overflow....\n");
102 if (sscanf(input_str, "%4d", &data) != 1) {
103 printf("Input only integer option....\n");
110 static void usage(void)
112 printf("\n*********************************************\n");
113 printf("app2sd test\n");
114 printf("test_case\n");
115 printf("<1> app_install (pre-install, install, post-install, enable, launch, disable)\n");
116 printf("<2> app_uninstall (pre-uninstall, uninstall, post-uninstall)\n");
117 printf("<3> app_upgrade (pre-upgrade, upgrade, post-Upgrade)\n");
118 printf("<4> app_move\n");
119 printf("<5> app_get_location\n");
120 printf("<6> enable_external_dir\n");
121 printf("<7> disable_external_dir\n");
122 printf("<8> exit\n");
125 GList * populate_dir_details()
127 GList *dir_list = NULL;
129 app2ext_dir_details* dir_detail = NULL;
133 for (i=0; i<3; i++) {
134 dir_detail = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
135 if (dir_detail == NULL) {
136 printf("\nMemory allocation failed\n");
139 dir_detail->name = (char*) calloc(1, sizeof(char)*(strlen(pkg_ro_content_rpm[i])+2));
140 if (dir_detail->name == NULL) {
141 printf("\nMemory allocation failed\n");
145 snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i])+1), "%s", pkg_ro_content_rpm[i]);
146 dir_detail->type = APP2EXT_DIR_RO;
147 dir_list = g_list_append(dir_list, dir_detail);
150 list = g_list_first(dir_list);
152 dir_detail = (app2ext_dir_details *)list->data;
153 list = g_list_next(list);
159 list = g_list_first(dir_list);
161 dir_detail = (app2ext_dir_details *)list->data;
162 if (dir_detail && dir_detail->name) {
163 free(dir_detail->name);
165 list = g_list_next(list);
167 g_list_free(dir_list);
172 void clear_dir_list(GList* dir_list)
175 app2ext_dir_details* dir_detail = NULL;
177 list = g_list_first(dir_list);
179 dir_detail = (app2ext_dir_details *)list->data;
180 if (dir_detail && dir_detail->name) {
181 free(dir_detail->name);
183 list = g_list_next(list);
185 g_list_free(dir_list);
191 printf("app_install %s\n", TEST_PKGNAME);
192 GList *dir_list = NULL;
195 //char cmd_install[CMD_LEN+1];
196 //snprintf(cmd_install, CMD_LEN,"tpk-backend -y %s", TEST_PKGNAME);
198 dir_list = populate_dir_details();
199 if (dir_list == NULL) {
200 printf("Error in populating the directory list\n");
203 ret = handle->interface.pre_install(TEST_PKGNAME, dir_list, 20);
205 printf("pre_install failed(%s)\n", error_list[ret]);
206 clear_dir_list(dir_list);
211 printf("\n cmd_install is %s ", cmd_install);
212 ret = system(cmd_install);
215 printf("tpk-backend install command fail %d ", ret);
216 ret = handle->interface.post_install(TEST_PKGNAME, 1);
218 printf("post_install failed(%s)\n", error_list[ret]);
220 clear_dir_list(dir_list);
225 ret = handle->interface.post_install(TEST_PKGNAME, 2);
227 printf("post_install failed(%s)\n", error_list[ret]);
228 clear_dir_list(dir_list);
232 ret = handle->interface.enable(TEST_PKGNAME);
234 printf("enable failed(%s)\n", error_list[ret]);
235 clear_dir_list(dir_list);
240 printf("\nLaunching application after install");
241 ret = aul_open_app(TEST_PKGNAME);
244 printf("\n launch fail");
246 printf("\n application launched");
250 ret = system("killall -9 basicuiapplication");
252 printf("\n app exit fail");
254 printf("\n application exited");
259 ret = handle->interface.disable(TEST_PKGNAME);
260 if (ret < 0 || ret > 44) {
261 printf("disable failed : unknown error\n");
263 printf("disable return(%s)\n", error_list[ret]);
266 clear_dir_list(dir_list);
273 printf("app_uninstall %s\n", TEST_PKGNAME);
275 //char cmd_uninstall[CMD_LEN+1];
276 //snprintf(cmd_uninstall, CMD_LEN, "tpk-backend -y %s", TEST_PKGNAME);
278 ret = handle->interface.pre_uninstall(TEST_PKGNAME);
280 printf("pre_uninstall failed(%s)", error_list[ret]);
285 printf("\n cmd_uninstall is %s ", cmd_uninstall);
286 ret = system(cmd_uninstall);
288 printf("\nrpm uninstall command fail Reason %s", error_list[ret]);
293 ret = handle->interface.post_uninstall(TEST_PKGNAME);
295 printf("post app uninstall API fail Reason %s\n", error_list[ret]);
304 printf("app_upgrade %s\n", TEST_PKGNAME);
306 //char cmd_uninstall[CMD_LEN+1];
307 //snprintf(cmd_uninstall, CMD_LEN, "rpm -U %s", TEST_PKGNAME);
309 GList *dir_list = populate_dir_details();
310 if (dir_list == NULL) {
311 printf("Error in populating the directory list\n");
315 ret = handle->interface.pre_upgrade(TEST_PKGNAME, dir_list, 40);
317 printf("pre app upgrade API fail. Reason %s\n", error_list[ret]);
318 clear_dir_list(dir_list);
323 printf("\n cmd_uninstall is %s ", cmd_uninstall);
324 ret = system(cmd_uninstall);
326 printf("\nrpm upgrade command fail Reason %s", error_list[ret]);
327 ret = handle->interface.post_upgrade(TEST_PKGNAME_RPM, 1);
329 printf("post app upgrade API fail Reason %s\n", error_list[ret]);
331 clear_dir_list(dir_list);
336 ret = handle->interface.post_upgrade(TEST_PKGNAME, 2);
338 printf("\n TC : post app upgrade API fail Reason %s", error_list[ret]);
339 clear_dir_list(dir_list);
342 clear_dir_list(dir_list);
348 printf("app_move %s\n", TEST_PKGNAME);
351 GList *dir_list = populate_dir_details();
352 if (dir_list == NULL) {
353 printf("\nError in populating the directory list\n");
357 ret = app2ext_get_app_location(TEST_PKGNAME);
358 printf("return value = (%d)", ret);
359 if (ret == APP2EXT_SD_CARD) {
360 printf("\n app %s is in sd card ", TEST_PKGNAME);
361 printf("\n app %s will be moved to internal memory ",
363 ret = handle->interface.move(TEST_PKGNAME, dir_list, APP2EXT_MOVE_TO_PHONE);
365 printf("\n TC: move API failed Reason %s", error_list[ret]);
366 clear_dir_list(dir_list);
369 ret = app2ext_get_app_location(TEST_PKGNAME);
370 if (ret_check == APP2EXT_INTERNAL_MEM)
371 printf("\n app %s is moved to internal memory ",
373 } else if (ret == APP2EXT_INTERNAL_MEM) {
374 printf("\n app %s is in internal memory ", TEST_PKGNAME);
375 printf("\n app %s will be moved to sd card", TEST_PKGNAME);
377 ret = handle->interface.move(TEST_PKGNAME, dir_list, APP2EXT_MOVE_TO_EXT);
379 printf("\n TC: move API failed Reason %s", error_list[ret]);
380 clear_dir_list(dir_list);
383 ret = app2ext_get_app_location(TEST_PKGNAME);
384 if (ret_check == APP2EXT_SD_CARD)
385 printf("\n app %s is moved to sd card ",
388 ret = APP2EXT_ERROR_INVALID_PACKAGE;
389 printf("\n errorReason %s", error_list[ret]);
390 clear_dir_list(dir_list);
393 clear_dir_list(dir_list);
397 void app_get_location()
399 printf("app_get_location %s \n", TEST_PKGNAME);
402 ret = app2ext_get_app_location(TEST_PKGNAME);
403 if (ret == APP2EXT_SD_CARD) {
404 printf("\n app %s is in sd card ", TEST_PKGNAME);
405 } else if (ret == APP2EXT_INTERNAL_MEM) {
406 printf("\n app %s is in internal memory ", TEST_PKGNAME);
408 printf("\napp %s is not installed", TEST_PKGNAME);
412 void enable_external_dir()
414 printf("enable_external_dir\n");
417 ret = app2ext_enable_external_dir();
419 printf("\n app2ext_enable_external_dir() success");
421 printf("\n app2ext_enable_external_dir() failed");
425 void disable_external_dir()
427 printf("disable_external_dir\n");
430 ret = app2ext_disable_external_dir();
432 printf("\n app2ext_disable_external_dir() success");
434 printf("\n app2ext_disable_external_dir() failed");
438 int main(int argc, char **argv)
442 /* check authorized user */
444 handle = app2ext_init(APP2EXT_SD_CARD);
445 if (handle == NULL) {
446 ret = APP2EXT_ERROR_PLUGIN_INIT_FAILED;
447 printf("app2ext_init failed (%s)\n", error_list[ret]);
453 printf("enter testcase\n");
454 int option = __get_integer_input_data();
472 enable_external_dir();
475 disable_external_dir();
478 app2ext_deinit(handle);
482 printf("\nInvalid test id\n");
487 app2ext_deinit(handle);