2 Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 PROPRIETARY/CONFIDENTIAL
4 This software is the confidential and proprietary information of
5 SAMSUNG ELECTRONICS ("Confidential Information"). You agree and acknowledge that
6 this software is owned by Samsung and you
7 shall not disclose such Confidential Information and shall
8 use it only in accordance with the terms of the license agreement
9 you entered into with SAMSUNG ELECTRONICS. SAMSUNG make no
10 representations or warranties about the suitability
11 of the software, either express or implied, including but not
12 limited to the implied warranties of merchantability, fitness for
13 a particular purpose, or non-infringement.
14 SAMSUNG shall not be liable for any damages suffered by licensee arising out of or
15 related to this software.
24 #include "menu_db_util.h"
29 #define MAX_LOCAL_BUFSZ 128
30 #define QUERY_LEN 10240
37 typedef struct _test_func_t {
44 static bundle *create_internal_bundle(int start)
50 for (i = start; i < gargc - 1; i++) {
51 if ((i + 1) > gargc - 1)
52 bundle_add(kb, gargv[i], " ");
54 bundle_add(kb, gargv[i], gargv[i + 1]);
66 kb = create_internal_bundle(3);
70 printf("[aul_launch_app %d test] %s \n", num++, gargv[2]);
72 ret = aul_launch_app(gargv[2], kb);
81 int dbus_launch_test()
86 kb = create_internal_bundle(3);
92 ret = aul_launch_app(gargv[2], kb);
102 static void prt_recvd_bundle(const char *key, const char *value, void *d)
104 printf("recvd - key: %s, value: %s\n", key, value);
107 static void cb_func(bundle *kb, int is_cancel, void *data)
113 printf("==== %d : canceled(preemptted) my request ===\n", num);
115 printf("==== %d : result packet ===\n", num);
116 bundle_iterate(kb, prt_recvd_bundle, NULL);
119 if ((strcmp(cmd, "launch_res") == 0)
120 || (strcmp(cmd, "open_svc_res") == 0))
121 ecore_main_loop_quit();
128 printf("[aul_open_app %d test] %s \n", num++, gargv[2]);
129 return aul_open_app(gargv[2]);
132 int resume_pid_test()
135 printf("[aul_resume_pid %d test] %d \n", num++, apn_pid);
136 return aul_resume_pid(apn_pid);
142 printf("[aul_term_pid %d test] %d \n", num++, apn_pid);
143 return aul_terminate_pid(apn_pid);
146 static test_func_t scn_func[] = {
147 {"n", launch_test, "launch_test", ""},
148 {"n", launch_test, "launch_test", ""},
149 {"n", resume_test, "open_test", ""},
150 {"n", resume_test, "open_test", ""},
151 {"p", resume_pid_test, "resume_pid_test", ""},
152 {"p", resume_pid_test, "resume_pid_test", ""},
153 {"p", term_pid_test, "term_pid_test", ""},
154 {"n", resume_test, "open_test", ""},
155 {"n", launch_test, "launch_test", ""}
158 static Eina_Bool run_all_test(void *data)
163 if (pos > sizeof(scn_func) / sizeof(test_func_t) - 1) {
164 printf("all internal test done\n");
165 ecore_main_loop_quit();
169 if (strncmp(scn_func[pos].name, "n", 1) == 0) {
170 printf("[test %d] %s , pkgname = %s\n", pos, scn_func[pos].desc,
172 apn_pid = scn_func[pos].func();
173 printf("... return pid = %d\n", apn_pid);
175 printf("[test %d] %s , pid = %d\n", pos, scn_func[pos].desc,
177 ret = scn_func[pos].func();
178 printf("... return res = %d\n", ret);
187 ecore_timer_add(2, run_all_test, NULL);
193 if (aul_app_is_running(gargv[2]))
194 printf("... %s is running\n", gargv[2]);
196 printf("... %s is not running\n", gargv[2]);
201 int iterfunc(const aul_app_info *info, void *data)
203 printf("\t==========================\n");
204 printf("\t pkg_name: %s\n", info->pkg_name);
205 printf("\t app_path: %s\n", info->app_path);
206 printf("\t running pid: %d\n", info->pid);
207 printf("\t==========================\n");
212 int get_allpkg_test()
215 printf("[aul_app_get_ruuning_app_info %d test] \n", num++);
216 return aul_app_get_running_app_info(iterfunc, NULL);
219 int get_pkgpid_test()
223 char buf[MAX_LOCAL_BUFSZ];
225 printf("[aul_app_get_pkgname_bypid %d test] \n", num++);
226 pid = atoi(gargv[2]);
228 if (aul_app_get_pkgname_bypid(pid, buf, sizeof(buf)) < 0)
229 printf("no such pkg by %d\n", pid);
231 printf("pkgname = %s, pid = %d\n", buf, pid);
239 printf("[aul_open_file %d test] %s \n", num++, gargv[2]);
240 return aul_open_file(gargv[2]);
243 int open_content_test()
246 printf("[aul_open_content %d test] %s \n", num++, gargv[2]);
247 return aul_open_content(gargv[2]);
250 int get_defapp_test()
254 char buf[MAX_LOCAL_BUFSZ];
255 printf("[aul_get_defapp_from_mime %d test] %s \n", num++, gargv[2]);
256 ret = aul_get_defapp_from_mime(gargv[2], buf, sizeof(buf));
258 printf("==> defapp name = %s\n", buf);
262 int set_defapp_test()
266 printf("[aul_set_defapp_with_mime %d test] %s %s\n", num++, gargv[2],
268 ret = aul_set_defapp_with_mime(gargv[2], gargv[3]);
272 int get_mime_file_test()
276 char buf[MAX_LOCAL_BUFSZ];
277 printf("[aul_get_mime_from_file %d test] %s \n", num++, gargv[2]);
278 ret = aul_get_mime_from_file(gargv[2], buf, sizeof(buf));
280 printf("==> mime type = %s\n", buf);
284 int get_mime_content_test()
288 char buf[MAX_LOCAL_BUFSZ];
289 printf("[aul_get_mime_from_content %d test] %s \n", num++, gargv[2]);
290 ret = aul_get_mime_from_content(gargv[2], buf, sizeof(buf));
292 printf("==> mime type = %s\n", buf);
296 int aul_get_mime_icon_test()
299 char buf[MAX_LOCAL_BUFSZ];
300 ret = aul_get_mime_icon(gargv[2], buf, sizeof(buf));
302 printf("==> mimetype %s : iconname = %s\n", gargv[2], buf);
306 int aul_get_mime_description_test()
309 char buf[MAX_LOCAL_BUFSZ];
310 ret = aul_get_mime_description(gargv[2], buf, sizeof(buf));
312 printf("==> mimetype %s : description = %s\n", gargv[2], buf);
316 int aul_get_mime_extension_test()
319 char buf[MAX_LOCAL_BUFSZ];
320 ret = aul_get_mime_extension(gargv[2], buf, sizeof(buf));
322 printf("==> mimetype %s : extension = %s\n", gargv[2], buf);
326 static void print_menu_db_info(const app_info_from_db *info)
329 printf("pkg %s no found\n", gargv[2]);
333 printf("\t==========================\n");
334 printf("\t pkg_name: %s\n", info->pkg_name);
335 printf("\t app_path: %s\n", info->app_path);
336 printf("\t w: %d\n", info->width);
337 printf("\t h: %d\n", info->height);
338 printf("\t is_minst: %d\n", 0);
339 printf("\t==========================\n");
342 static int get_pkg_func()
344 app_info_from_db *info;
346 info = _get_app_info_from_db_by_pkgname(gargv[2]);
347 print_menu_db_info(info);
349 _free_app_info_from_db(info);
355 static int set_pkg_func()
360 char query[QUERY_LEN];
365 appname = strrchr(apppath,'/')+1;
366 snprintf(ai.app_icon_path, PATH_LEN, "aul_test_icon_path/%d",getpid());
367 snprintf(ai.desktop_path, PATH_LEN,
368 "aul_test_desktop_path/%d",getpid());
370 snprintf (query, sizeof(query), "insert into "TABLE_MENU"(\
376 values ('%s', '%s', '%s', '%s', '%s')",
380 record->app_icon_path,
381 record->desktop_path,
384 // TODO: record_add is not supported anymore; use AIL
385 if (record_add(ADD_ICON, &ai)){
386 printf("set pkg success\n");
390 printf("set pkg fail\n");
395 static int del_pkg_func()
399 memset(&ai, 0, sizeof(app_info));
400 snprintf(ai.pkg_name, NAME_LEN, "%s", gargv[2]);
402 // TODO: record_add is not supported anymore; use AIL
403 if(record_delete(DELETE_MENU, &ai)){
404 printf("del pkg success\n");
408 printf("del pkg fail\n");
414 static int test_regex()
417 char mime[MAX_LOCAL_BUFSZ];
422 printf("=======================\n");
424 token = strtok_r(gargv[2], " \t\n,.()", &saveptr);
425 if (aul_get_mime_from_content(token, mime, sizeof(mime)) == AUL_R_OK)
426 printf("found %s %s\n", mime, token);
429 token = strtok_r(NULL, " \t\n,()", &saveptr);
430 if (aul_get_mime_from_content(token, mime, sizeof(mime)) ==
432 printf("found %s %s\n", mime, token);
435 PERF("======= parse end =====\n");
445 kb = create_internal_bundle(3);
447 printf("bundle creation fail\n");
450 printf("[aul_open_service %d test] %s \n", num++, gargv[2]);
451 ret = aul_open_service(gargv[2], kb, NULL, NULL);
453 printf("open service success\n");
460 printf("open service fail\n");
469 int open_svc_res_test()
475 kb = create_internal_bundle(3);
476 if (kb == NULL) { /* Prevent Fix: ID: 21027,21581 */
477 printf("bundle creation fail\n");
481 printf("[aul_open_service(wait result) %d test] %s \n", num++,
483 ret = aul_open_service(gargv[2], kb, cb_func, (void *)num);
485 printf("open service(wait result) success\n");
492 printf("open service(wait result) fail\n");
501 int get_defapp_svc_test()
505 char buf[MAX_LOCAL_BUFSZ];
506 printf("[aul_get_defapp_from_svc %d test] %s \n", num++, gargv[2]);
507 ret = aul_get_defapp_for_service(gargv[2], buf, sizeof(buf));
509 printf("==> defapp name = %s\n", buf);
513 int set_defapp_svc_test()
517 printf("[aul_set_defapp_with_svc %d test] %s %s\n", num++, gargv[2],
519 ret = aul_set_defapp_for_service(gargv[2], gargv[3]);
523 static test_func_t test_func[] = {
524 {"launch",launch_test,"aul_launch_app test",
525 "[usage] launch <pkgname> <key1> <val1> <key2> <val2> ..."},
526 {"open",resume_test,"aul_open_app test",
527 "[usage] open <pkgname>" },
528 {"resume_pid",resume_pid_test,"aul_resume_pid test",
529 "[usage] resume_pid <pid>" },
530 {"term_pid", term_pid_test,"aul_terminate_pid test",
531 "[usage] term_pid <pid>" },
532 {"dbuslaunch", dbus_launch_test,"launch by dbus auto activation",
533 "[usage] term_pid <pid>" },
534 {"all",all_test,"test based on predefine scenario",
535 "[usage] all <pkgname>"},
537 {"is_run", is_run_test,"aul_is_running test",
538 "[usage] is_run_test <pkgname>"},
539 {"getallpkg", get_allpkg_test, "aul_app_get_running_app_info test",
540 "[usage] getallpkg all"},
541 {"getpkgpid", get_pkgpid_test, "aul_app_get_pkgname_bypid test",
542 "[usage] getpkgpid <pid>"},
544 {"open_file", open_file_test, "aul_open_file test",
545 "[usage] open_file <filename>"},
546 {"open_content", open_content_test, "aul_open_content test",
547 "[usage] open_content <content>"},
548 {"get_defapp_mime", get_defapp_test, "aul_get_defapp_from_mime test",
549 "[usage] get_defapp_mime <mime_type>"},
550 {"set_defapp_mime", set_defapp_test, "aul_set_defapp_with_mime test",
551 "[usage] set_defapp_mime <mime_type> <defapp to be set>"},
552 {"get_mime_file", get_mime_file_test, "aul_get_mime_from_file test",
553 "[usage] get_mime_file <filename>"},
554 {"get_mime_content", get_mime_content_test, "aul_get_mime_from_content",
555 "[usage] get_mime_content <content>"},
557 {"get_mime_icon", aul_get_mime_icon_test, "aul_get_mime_icon test",
558 "[usage] get_mime_icon <mimetype>"},
559 {"get_mime_desc", aul_get_mime_description_test, "aul_get_mime_description test",
560 "[usage] get_mime_desc <mimetype>"},
561 {"get_mime_ext", aul_get_mime_extension_test, "aul_get_mime_extension test",
562 "[usage] get_mime_ext <mimetype>"},
564 {"test_regex", test_regex, "regular expression parser test",
565 "[usage] test_regex <full text>"},
567 {"open_svc", open_svc_test, "aul_open_service test"
568 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
569 {"open_svc_res", open_svc_res_test, "aul_open_service (wait result) test"
570 "[usage] open_svc <svcname> <key1> <val1> <key2> <val2> ..."},
571 {"set_defapp_svc", set_defapp_svc_test, "aul_set_defapp_with_svc test"
572 "[usage] set_defapp_svc <svcname> <defapp to be set>"},
573 {"get_defapp_svc", get_defapp_svc_test, "aul_get_defapp_from_svc test"
574 "[usage] get_defapp_svc <svcname>"},
576 {"getpkg", get_pkg_func, "get package",
577 "[usage] getpkg <pkgname>"},
579 {"setpkg", set_pkg_func, "set package",
580 "[usage] setpkg <pkgname> <apppath>"},
581 {"delpkg", del_pkg_func, "del package",
582 "[usage] getpkg <pkgname>"},
586 int callfunc(char *testname)
592 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
594 if (strcmp(testname, tmp->name) == 0) {
596 if (strcmp(testname, "all")) {
598 printf("... test failed\n");
600 printf("... test successs ret = %d\n",
608 int dead_tracker(int pid, void *data)
610 printf("[DEAD] pid = %d dead\n", pid);
614 void print_usage(char *progname)
619 printf("[usage] %s <cmd> ...\n", progname);
620 printf(" - available cmd list\n");
622 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
624 printf("\t%s : %s\n", tmp->name, tmp->desc);
625 printf("\t\t%s\n", tmp->usage);
628 printf("[note] getpkg/setpkg/delpkg/init_defapp_mime "
629 "cmd is internal purpose\n");
632 static Eina_Bool run_func(void *data)
636 if (strcmp(cmd, "launch_res") == 0 || strcmp(cmd, "all") == 0
637 || strcmp(cmd, "dbuslaunch") == 0
638 || strcmp(cmd, "open_svc_res") == 0)
641 ecore_main_loop_quit();
646 int main(int argc, char **argv)
649 print_usage(argv[0]);
658 apn_pid = atoi(argv[2]);
660 aul_launch_init(NULL, NULL);
662 /*aul_listen_app_dead_signal(dead_tracker,NULL); */
663 /*aul_listen_app_dead_signal(NULL,NULL); */
665 ecore_idler_add(run_func, NULL);
667 ecore_main_loop_begin();
672 /* vi: set ts=8 sts=8 sw=8: */