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]);
141 printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
142 return aul_resume_app(gargv[2]);
145 int resume_pid_test()
148 printf("[aul_resume_pid %d test] %d \n", num++, apn_pid);
149 return aul_resume_pid(apn_pid);
155 printf("[aul_term_pid %d test] %d \n", num++, apn_pid);
156 return aul_terminate_pid(apn_pid);
159 static test_func_t scn_func[] = {
160 {"n", launch_test, "launch_test", ""},
161 {"n", launch_test, "launch_test", ""},
162 {"n", resume_test, "open_test", ""},
163 {"n", resume_test, "open_test", ""},
164 {"p", resume_pid_test, "resume_pid_test", ""},
165 {"p", resume_pid_test, "resume_pid_test", ""},
166 {"p", term_pid_test, "term_pid_test", ""},
167 {"n", resume_test, "open_test", ""},
168 {"n", launch_test, "launch_test", ""}
171 static Eina_Bool run_all_test(void *data)
176 if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) {
177 printf("all internal test done\n");
178 ecore_main_loop_quit();
182 if (strncmp(scn_func[pos].name, "n", 1) == 0) {
183 printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc,
185 apn_pid = scn_func[pos].func();
186 printf("... return pid = %d\n", apn_pid);
188 printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc,
190 ret = scn_func[pos].func();
191 printf("... return res = %d\n", ret);
200 ecore_timer_add(2, run_all_test, NULL);
206 if (aul_app_is_running(gargv[2]))
207 printf("... %s is running\n", gargv[2]);
209 printf("... %s is not running\n", gargv[2]);
214 int iterfunc(const aul_app_info *info, void *data)
216 printf("\t==========================\n");
217 printf("\t pkg_name: %s\n", info->appid);
218 printf("\t app_path: %s\n", info->app_path);
219 printf("\t running pid: %d\n", info->pid);
220 printf("\t==========================\n");
225 int get_allpkg_test()
228 printf("[aul_app_get_ruuning_app_info %d test] \n", num++);
229 return aul_app_get_running_app_info(iterfunc, NULL);
232 int get_pkgpid_test()
236 char buf[MAX_LOCAL_BUFSZ];
238 printf("[aul_app_get_appid_bypid %d test] \n", num++);
239 pid = atoi(gargv[2]);
241 if (aul_app_get_appid_bypid(pid, buf, sizeof(buf)) < 0)
242 printf("no such pkg by %d\n", pid);
244 printf("pkgname = %s, pid = %d\n", buf, pid);
252 printf("[aul_open_file %d test] %s \n", num++, gargv[2]);
253 return aul_open_file(gargv[2]);
256 int open_content_test()
259 printf("[aul_open_content %d test] %s \n", num++, gargv[2]);
260 return aul_open_content(gargv[2]);
263 int get_defapp_test()
267 char buf[MAX_LOCAL_BUFSZ];
268 printf("[aul_get_defapp_from_mime %d test] %s \n", num++, gargv[2]);
269 ret = aul_get_defapp_from_mime(gargv[2], buf, sizeof(buf));
271 printf("==> defapp name = %s\n", buf);
275 int set_defapp_test()
279 printf("[aul_set_defapp_with_mime %d test] %s %s\n", num++, gargv[2],
281 ret = aul_set_defapp_with_mime(gargv[2], gargv[3]);
285 int get_mime_file_test()
289 char buf[MAX_LOCAL_BUFSZ];
290 printf("[aul_get_mime_from_file %d test] %s \n", num++, gargv[2]);
291 ret = aul_get_mime_from_file(gargv[2], buf, sizeof(buf));
293 printf("==> mime type = %s\n", buf);
297 int get_mime_content_test()
301 char buf[MAX_LOCAL_BUFSZ];
302 printf("[aul_get_mime_from_content %d test] %s \n", num++, gargv[2]);
303 ret = aul_get_mime_from_content(gargv[2], buf, sizeof(buf));
305 printf("==> mime type = %s\n", buf);
309 int aul_get_mime_icon_test()
312 char buf[MAX_LOCAL_BUFSZ];
313 ret = aul_get_mime_icon(gargv[2], buf, sizeof(buf));
315 printf("==> mimetype %s : iconname = %s\n", gargv[2], buf);
319 int aul_get_mime_description_test()
322 char buf[MAX_LOCAL_BUFSZ];
323 ret = aul_get_mime_description(gargv[2], buf, sizeof(buf));
325 printf("==> mimetype %s : description = %s\n", gargv[2], buf);
329 int aul_get_mime_extension_test()
332 char buf[MAX_LOCAL_BUFSZ];
333 ret = aul_get_mime_extension(gargv[2], buf, sizeof(buf));
335 printf("==> mimetype %s : extension = %s\n", gargv[2], buf);
339 static void print_menu_db_info(const app_info_from_db *info)
342 printf("pkg %s no found\n", gargv[2]);
346 printf("\t==========================\n");
347 printf("\t pkg_name: %s\n", info->pkg_name);
348 printf("\t app_path: %s\n", info->app_path);
349 printf("\t is_minst: %d\n", 0);
350 printf("\t==========================\n");
353 static int get_pkg_func()
355 app_info_from_db *info;
357 info = _get_app_info_from_db_by_pkgname(gargv[2]);
358 print_menu_db_info(info);
360 _free_app_info_from_db(info);
366 static int set_pkg_func()
371 char query[QUERY_LEN];
376 appname = strrchr(apppath,'/')+1;
377 snprintf(ai.app_icon_path, PATH_LEN, "aul_test_icon_path/%d",getpid());
378 snprintf(ai.desktop_path, PATH_LEN,
379 "aul_test_desktop_path/%d",getpid());
381 snprintf (query, sizeof(query), "insert into "TABLE_MENU"(\
387 values ('%s', '%s', '%s', '%s', '%s')",
391 record->app_icon_path,
392 record->desktop_path,
395 // TODO: record_add is not supported anymore; use AIL
396 if (record_add(ADD_ICON, &ai)){
397 printf("set pkg success\n");
401 printf("set pkg fail\n");
406 static int del_pkg_func()
410 memset(&ai, 0, sizeof(app_info));
411 snprintf(ai.pkg_name, NAME_LEN, "%s", gargv[2]);
413 // TODO: record_add is not supported anymore; use AIL
414 if(record_delete(DELETE_MENU, &ai)){
415 printf("del pkg success\n");
419 printf("del pkg fail\n");
425 static int test_regex()
428 char mime[MAX_LOCAL_BUFSZ];
433 printf("=======================\n");
435 token = strtok_r(gargv[2], " \t\n,.()", &saveptr);
436 if (aul_get_mime_from_content(token, mime, sizeof(mime)) == AUL_R_OK)
437 printf("found %s %s\n", mime, token);
440 token = strtok_r(NULL, " \t\n,()", &saveptr);
441 if (aul_get_mime_from_content(token, mime, sizeof(mime)) ==
443 printf("found %s %s\n", mime, token);
446 PERF("======= parse end =====\n");
456 kb = create_internal_bundle(3);
458 printf("bundle creation fail\n");
461 printf("[aul_open_service %d test] %s \n", num++, gargv[2]);
462 ret = aul_open_service(gargv[2], kb, NULL, NULL);
464 printf("open service success\n");
471 printf("open service fail\n");
480 int open_svc_res_test()
486 kb = create_internal_bundle(3);
487 if (kb == NULL) { /* Prevent Fix: ID: 21027,21581 */
488 printf("bundle creation fail\n");
492 printf("[aul_open_service(wait result) %d test] %s \n", num++,
494 ret = aul_open_service(gargv[2], kb, cb_func, (void *)num);
496 printf("open service(wait result) success\n");
503 printf("open service(wait result) fail\n");
512 int get_defapp_svc_test()
516 char buf[MAX_LOCAL_BUFSZ];
517 printf("[aul_get_defapp_from_svc %d test] %s \n", num++, gargv[2]);
518 ret = aul_get_defapp_for_service(gargv[2], buf, sizeof(buf));
520 printf("==> defapp name = %s\n", buf);
524 int set_defapp_svc_test()
528 printf("[aul_set_defapp_with_svc %d test] %s %s\n", num++, gargv[2],
530 ret = aul_set_defapp_for_service(gargv[2], gargv[3]);
534 static test_func_t test_func[] = {
535 {"launch",launch_test,"aul_launch_app test",
536 "[usage] launch <pkgname> <key1> <val1> <key2> <val2> ..."},
537 {"open",open_test,"aul_open_app test",
538 "[usage] open <pkgname>" },
539 {"resume",resume_test,"aul_resume_app test",
540 "[usage] resume <pkgname>" },
541 {"resume_pid",resume_pid_test,"aul_resume_pid test",
542 "[usage] resume_pid <pid>" },
543 {"term_pid", term_pid_test,"aul_terminate_pid test",
544 "[usage] term_pid <pid>" },
545 {"dbuslaunch", dbus_launch_test,"launch by dbus auto activation",
546 "[usage] term_pid <pid>" },
547 {"all",all_test,"test based on predefine scenario",
548 "[usage] all <pkgname>"},
550 {"is_run", is_run_test,"aul_is_running test",
551 "[usage] is_run <pkgname>"},
552 {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
553 "[usage] getallpkg all"},
554 {"getpkgpid", get_pkgpid_test, "aul_app_get_appid_bypid test",
555 "[usage] getpkgpid <pid>"},
557 {"open_file", open_file_test, "aul_open_file test",
558 "[usage] open_file <filename>"},
559 {"open_content", open_content_test, "aul_open_content test",
560 "[usage] open_content <content>"},
561 {"get_defapp_mime", get_defapp_test, "aul_get_defapp_from_mime test",
562 "[usage] get_defapp_mime <mime_type>"},
563 {"set_defapp_mime", set_defapp_test, "aul_set_defapp_with_mime test",
564 "[usage] set_defapp_mime <mime_type> <defapp to be set>"},
565 {"get_mime_file", get_mime_file_test, "aul_get_mime_from_file test",
566 "[usage] get_mime_file <filename>"},
567 {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content",
568 "[usage] get_mime_content <content>"},
570 {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test",
571 "[usage] get_mime_icon <mimetype>"},
572 {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test",
573 "[usage] get_mime_desc <mimetype>"},
574 {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test",
575 "[usage] get_mime_ext <mimetype>"},
577 {"test_regex", test_regex, "regular expression parser test",
578 "[usage] test_regex <full text>"},
580 {"open_svc", open_svc_test, "aul_open_service test"
581 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
582 {"open_svc_res", open_svc_res_test, "aul_open_service (wait result) test"
583 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
584 {"set_defapp_svc", set_defapp_svc_test, "aul_set_defapp_with_svc test"
585 "[usage] set_defapp_svc <svcname> <defapp to be set>"},
586 {"get_defapp_svc", get_defapp_svc_test, "aul_get_defapp_from_svc test"
587 "[usage] get_defapp_svc <svcname>"},
589 {"getpkg", get_pkg_func, "get package",
590 "[usage] getpkg <pkgname>"},
592 {"setpkg", set_pkg_func, "set package",
593 "[usage] setpkg <pkgname> <apppath>"},
594 {"delpkg", del_pkg_func, "del package",
595 "[usage] getpkg <pkgname>"},
599 int callfunc(char *testname)
605 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
607 if (strcmp(testname, tmp->name) == 0) {
609 if (strcmp(testname, "all")) {
611 printf("... test failed\n");
613 printf("... test successs ret = %d\n",
621 int dead_tracker(int pid, void *data)
623 printf("[DEAD] pid = %d dead\n", pid);
627 void print_usage(char *progname)
632 printf("[usage] %s <cmd> ...\n", progname);
633 printf(" - available cmd list\n");
635 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
637 printf("\t%s : %s\n", tmp->name, tmp->desc);
638 printf("\t\t%s\n", tmp->usage);
641 printf("[note] getpkg/setpkg/delpkg/init_defapp_mime "
642 "cmd is internal purpose\n");
645 static Eina_Bool run_func(void *data)
649 if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0
650 || strcmp(cmd, "dbuslaunch") == 0
651 || strcmp(cmd, "open_svc_res") == 0)
654 ecore_main_loop_quit();
659 int main(int argc, char **argv)
662 print_usage(argv[0]);
671 apn_pid = atoi(argv[2]);
673 aul_launch_init(NULL, NULL);
675 /*aul_listen_app_dead_signal(dead_tracker,NULL); */
676 /*aul_listen_app_dead_signal(NULL,NULL); */
678 ecore_idler_add(run_func, NULL);
680 ecore_main_loop_begin();
685 /* vi: set ts=8 sts=8 sw=8: */