4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "menu_db_util.h"
34 #define MAX_LOCAL_BUFSZ 128
35 #define QUERY_LEN 10240
42 typedef struct _test_func_t {
49 static bundle *create_internal_bundle(int start)
55 for (i = start; i < gargc - 1; i++) {
56 if ((i + 1) > gargc - 1)
57 bundle_add(kb, gargv[i], " ");
59 bundle_add(kb, gargv[i], gargv[i + 1]);
71 kb = create_internal_bundle(3);
75 printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
77 ret = aul_launch_app(gargv[2], kb);
86 int dbus_launch_test()
91 kb = create_internal_bundle(3);
97 ret = aul_launch_app(gargv[2], kb);
107 static void prt_recvd_bundle(const char *key, const char *value, void *d)
109 printf("recvd - key: %s, value: %s\n", key, value);
112 static void cb_func(bundle *kb, int is_cancel, void *data)
118 printf("==== %d : canceled(preemptted) my request ===\n", num);
120 printf("==== %d : result packet ===\n", num);
121 bundle_iterate(kb, prt_recvd_bundle, NULL);
124 if ((strcmp(cmd, "launch_res") == 0)
125 || (strcmp(cmd, "open_svc_res") == 0))
126 ecore_main_loop_quit();
133 printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
134 return aul_open_app(gargv[2]);
137 int resume_pid_test()
140 printf("[aul_resume_pid %d test] %d \n", num++, apn_pid);
141 return aul_resume_pid(apn_pid);
147 printf("[aul_term_pid %d test] %d \n", num++, apn_pid);
148 return aul_terminate_pid(apn_pid);
151 static test_func_t scn_func[] = {
152 {"n", launch_test, "launch_test", ""},
153 {"n", launch_test, "launch_test", ""},
154 {"n", resume_test, "open_test", ""},
155 {"n", resume_test, "open_test", ""},
156 {"p", resume_pid_test, "resume_pid_test", ""},
157 {"p", resume_pid_test, "resume_pid_test", ""},
158 {"p", term_pid_test, "term_pid_test", ""},
159 {"n", resume_test, "open_test", ""},
160 {"n", launch_test, "launch_test", ""}
163 static Eina_Bool run_all_test(void *data)
168 if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) {
169 printf("all internal test done\n");
170 ecore_main_loop_quit();
174 if (strncmp(scn_func[pos].name, "n", 1) == 0) {
175 printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc,
177 apn_pid = scn_func[pos].func();
178 printf("... return pid = %d\n", apn_pid);
180 printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc,
182 ret = scn_func[pos].func();
183 printf("... return res = %d\n", ret);
192 ecore_timer_add(2, run_all_test, NULL);
198 if (aul_app_is_running(gargv[2]))
199 printf("... %s is running\n", gargv[2]);
201 printf("... %s is not running\n", gargv[2]);
206 int iterfunc(const aul_app_info *info, void *data)
208 printf("\t==========================\n");
209 printf("\t pkg_name: %s\n", info->pkg_name);
210 printf("\t app_path: %s\n", info->app_path);
211 printf("\t running pid: %d\n", info->pid);
212 printf("\t==========================\n");
217 int get_allpkg_test()
220 printf("[aul_app_get_ruuning_app_info %d test] \n", num++);
221 return aul_app_get_running_app_info(iterfunc, NULL);
224 int get_pkgpid_test()
228 char buf[MAX_LOCAL_BUFSZ];
230 printf("[aul_app_get_pkgname_bypid %d test] \n", num++);
231 pid = atoi(gargv[2]);
233 if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0)
234 printf("no such pkg by %d\n", pid);
236 printf("pkgname = %s, pid = %d\n", buf, pid);
244 printf("[aul_open_file %d test] %s \n", num++, gargv[2]);
245 return aul_open_file(gargv[2]);
248 int open_content_test()
251 printf("[aul_open_content %d test] %s \n", num++, gargv[2]);
252 return aul_open_content(gargv[2]);
255 int get_defapp_test()
259 char buf[MAX_LOCAL_BUFSZ];
260 printf("[aul_get_defapp_from_mime %d test] %s \n", num++, gargv[2]);
261 ret = aul_get_defapp_from_mime(gargv[2], buf, sizeof(buf));
263 printf("==> defapp name = %s\n", buf);
267 int set_defapp_test()
271 printf("[aul_set_defapp_with_mime %d test] %s %s\n", num++, gargv[2],
273 ret = aul_set_defapp_with_mime(gargv[2], gargv[3]);
277 int get_mime_file_test()
281 char buf[MAX_LOCAL_BUFSZ];
282 printf("[aul_get_mime_from_file %d test] %s \n", num++, gargv[2]);
283 ret = aul_get_mime_from_file(gargv[2], buf, sizeof(buf));
285 printf("==> mime type = %s\n", buf);
289 int get_mime_content_test()
293 char buf[MAX_LOCAL_BUFSZ];
294 printf("[aul_get_mime_from_content %d test] %s \n", num++, gargv[2]);
295 ret = aul_get_mime_from_content(gargv[2], buf, sizeof(buf));
297 printf("==> mime type = %s\n", buf);
301 int aul_get_mime_icon_test()
304 char buf[MAX_LOCAL_BUFSZ];
305 ret = aul_get_mime_icon(gargv[2], buf, sizeof(buf));
307 printf("==> mimetype %s : iconname = %s\n", gargv[2], buf);
311 int aul_get_mime_description_test()
314 char buf[MAX_LOCAL_BUFSZ];
315 ret = aul_get_mime_description(gargv[2], buf, sizeof(buf));
317 printf("==> mimetype %s : description = %s\n", gargv[2], buf);
321 int aul_get_mime_extension_test()
324 char buf[MAX_LOCAL_BUFSZ];
325 ret = aul_get_mime_extension(gargv[2], buf, sizeof(buf));
327 printf("==> mimetype %s : extension = %s\n", gargv[2], buf);
331 static void print_menu_db_info(const app_info_from_db *info)
334 printf("pkg %s no found\n", gargv[2]);
338 printf("\t==========================\n");
339 printf("\t pkg_name: %s\n", info->pkg_name);
340 printf("\t app_path: %s\n", info->app_path);
341 printf("\t is_minst: %d\n", 0);
342 printf("\t==========================\n");
345 static int get_pkg_func()
347 app_info_from_db *info;
349 info = _get_app_info_from_db_by_pkgname(gargv[2]);
350 print_menu_db_info(info);
352 _free_app_info_from_db(info);
358 static int set_pkg_func()
363 char query[QUERY_LEN];
368 appname = strrchr(apppath,'/')+1;
369 snprintf(ai.app_icon_path, PATH_LEN, "aul_test_icon_path/%d",getpid());
370 snprintf(ai.desktop_path, PATH_LEN,
371 "aul_test_desktop_path/%d",getpid());
373 snprintf (query, sizeof(query), "insert into "TABLE_MENU"(\
379 values ('%s', '%s', '%s', '%s', '%s')",
383 record->app_icon_path,
384 record->desktop_path,
387 // TODO: record_add is not supported anymore; use AIL
388 if (record_add(ADD_ICON, &ai)){
389 printf("set pkg success\n");
393 printf("set pkg fail\n");
398 static int del_pkg_func()
402 memset(&ai, 0, sizeof(app_info));
403 snprintf(ai.pkg_name, NAME_LEN, "%s", gargv[2]);
405 // TODO: record_add is not supported anymore; use AIL
406 if(record_delete(DELETE_MENU, &ai)){
407 printf("del pkg success\n");
411 printf("del pkg fail\n");
417 static int test_regex()
420 char mime[MAX_LOCAL_BUFSZ];
425 printf("=======================\n");
427 token = strtok_r(gargv[2], " \t\n,.()", &saveptr);
428 if (aul_get_mime_from_content(token, mime, sizeof(mime)) == AUL_R_OK)
429 printf("found %s %s\n", mime, token);
432 token = strtok_r(NULL, " \t\n,()", &saveptr);
433 if (aul_get_mime_from_content(token, mime, sizeof(mime)) ==
435 printf("found %s %s\n", mime, token);
438 PERF("======= parse end =====\n");
448 kb = create_internal_bundle(3);
450 printf("bundle creation fail\n");
453 printf("[aul_open_service %d test] %s \n", num++, gargv[2]);
454 ret = aul_open_service(gargv[2], kb, NULL, NULL);
456 printf("open service success\n");
463 printf("open service fail\n");
472 int open_svc_res_test()
478 kb = create_internal_bundle(3);
479 if (kb == NULL) { /* Prevent Fix: ID: 21027,21581 */
480 printf("bundle creation fail\n");
484 printf("[aul_open_service(wait result) %d test] %s \n", num++,
486 ret = aul_open_service(gargv[2], kb, cb_func, (void *)num);
488 printf("open service(wait result) success\n");
495 printf("open service(wait result) fail\n");
504 int get_defapp_svc_test()
508 char buf[MAX_LOCAL_BUFSZ];
509 printf("[aul_get_defapp_from_svc %d test] %s \n", num++, gargv[2]);
510 ret = aul_get_defapp_for_service(gargv[2], buf, sizeof(buf));
512 printf("==> defapp name = %s\n", buf);
516 int set_defapp_svc_test()
520 printf("[aul_set_defapp_with_svc %d test] %s %s\n", num++, gargv[2],
522 ret = aul_set_defapp_for_service(gargv[2], gargv[3]);
526 static test_func_t test_func[] = {
527 {"launch",launch_test,"aul_launch_app test",
528 "[usage] launch <pkgname> <key1> <val1> <key2> <val2> ..."},
529 {"open",resume_test,"aul_open_app test",
530 "[usage] open <pkgname>" },
531 {"resume_pid",resume_pid_test,"aul_resume_pid test",
532 "[usage] resume_pid <pid>" },
533 {"term_pid", term_pid_test,"aul_terminate_pid test",
534 "[usage] term_pid <pid>" },
535 {"dbuslaunch", dbus_launch_test,"launch by dbus auto activation",
536 "[usage] term_pid <pid>" },
537 {"all",all_test,"test based on predefine scenario",
538 "[usage] all <pkgname>"},
540 {"is_run", is_run_test,"aul_is_running test",
541 "[usage] is_run <pkgname>"},
542 {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
543 "[usage] getallpkg all"},
544 {"getpkgpid", get_pkgpid_test, "aul_app_get_pkgname_bypid test",
545 "[usage] getpkgpid <pid>"},
547 {"open_file", open_file_test, "aul_open_file test",
548 "[usage] open_file <filename>"},
549 {"open_content", open_content_test, "aul_open_content test",
550 "[usage] open_content <content>"},
551 {"get_defapp_mime", get_defapp_test, "aul_get_defapp_from_mime test",
552 "[usage] get_defapp_mime <mime_type>"},
553 {"set_defapp_mime", set_defapp_test, "aul_set_defapp_with_mime test",
554 "[usage] set_defapp_mime <mime_type> <defapp to be set>"},
555 {"get_mime_file", get_mime_file_test, "aul_get_mime_from_file test",
556 "[usage] get_mime_file <filename>"},
557 {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content",
558 "[usage] get_mime_content <content>"},
560 {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test",
561 "[usage] get_mime_icon <mimetype>"},
562 {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test",
563 "[usage] get_mime_desc <mimetype>"},
564 {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test",
565 "[usage] get_mime_ext <mimetype>"},
567 {"test_regex", test_regex, "regular expression parser test",
568 "[usage] test_regex <full text>"},
570 {"open_svc", open_svc_test, "aul_open_service test"
571 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
572 {"open_svc_res", open_svc_res_test, "aul_open_service (wait result) test"
573 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
574 {"set_defapp_svc", set_defapp_svc_test, "aul_set_defapp_with_svc test"
575 "[usage] set_defapp_svc <svcname> <defapp to be set>"},
576 {"get_defapp_svc", get_defapp_svc_test, "aul_get_defapp_from_svc test"
577 "[usage] get_defapp_svc <svcname>"},
579 {"getpkg", get_pkg_func, "get package",
580 "[usage] getpkg <pkgname>"},
582 {"setpkg", set_pkg_func, "set package",
583 "[usage] setpkg <pkgname> <apppath>"},
584 {"delpkg", del_pkg_func, "del package",
585 "[usage] getpkg <pkgname>"},
589 int callfunc(char *testname)
595 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
597 if (strcmp(testname, tmp->name) == 0) {
599 if (strcmp(testname, "all")) {
601 printf("... test failed\n");
603 printf("... test successs ret = %d\n",
611 int dead_tracker(int pid, void *data)
613 printf("[DEAD] pid = %d dead\n", pid);
617 void print_usage(char *progname)
622 printf("[usage] %s <cmd> ...\n", progname);
623 printf(" - available cmd list\n");
625 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
627 printf("\t%s : %s\n", tmp->name, tmp->desc);
628 printf("\t\t%s\n", tmp->usage);
631 printf("[note] getpkg/setpkg/delpkg/init_defapp_mime "
632 "cmd is internal purpose\n");
635 static Eina_Bool run_func(void *data)
639 if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0
640 || strcmp(cmd, "dbuslaunch") == 0
641 || strcmp(cmd, "open_svc_res") == 0)
644 ecore_main_loop_quit();
649 int main(int argc, char **argv)
652 print_usage(argv[0]);
661 apn_pid = atoi(argv[2]);
663 aul_launch_init(NULL, NULL);
665 /*aul_listen_app_dead_signal(dead_tracker,NULL); */
666 /*aul_listen_app_dead_signal(NULL,NULL); */
668 ecore_idler_add(run_func, NULL);
670 ecore_main_loop_begin();
675 /* vi: set ts=8 sts=8 sw=8: */