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.
36 typedef struct _test_func_t {
43 void __set_bundle_from_args(bundle *kb)
50 char *category = NULL;
54 while ((opt = getopt(gargc, gargv, "d:o:m:u:p:c:")) != -1) {
67 mime = strdup(optarg);
81 package = strdup(optarg);
88 category = strdup(optarg);
94 key = strtok(optarg, ",");
96 val_array[i] = strtok(NULL, ",");
97 if (val_array[i] == NULL)
102 appsvc_add_data(kb, key, val_array[0]);
104 appsvc_add_data_array(kb, key, (const char **)val_array, i);
111 appsvc_set_operation(kb, op);
115 appsvc_set_mime(kb, mime);
119 appsvc_set_uri(kb, uri);
123 appsvc_set_appid(kb, package);
127 appsvc_set_category(kb, category);
136 kb = bundle_create();
138 printf("bundle creation fail\n");
141 printf("[run_svc test]\n");
143 __set_bundle_from_args(kb);
145 ret = appsvc_usr_run_service(kb, 0, NULL, NULL, getuid());
148 printf("open service success\n");
155 printf("open service fail\n");
164 static void prt_recvd_bundle(const char *key, const int type, const bundle_keyval_t *kv, void *user_data)
168 size_t *array_item_size;
174 if (bundle_keyval_type_is_array((bundle_keyval_t *)kv) > 0) {
175 bundle_keyval_get_array_val((bundle_keyval_t *)kv, (void ***)&array_val, (unsigned int *)&array_len, &array_item_size);
177 for (i = 0; i < array_len; i++)
178 printf("recvd - key: %s[%d], value: %s\n", key, i, array_val[i]);
180 bundle_keyval_get_basic_val((bundle_keyval_t *)kv, (void **)&val, &size);
181 printf("recvd - key: %s, value: %s\n", key, val);
185 static void cb_func(bundle *kb, int request_code, appsvc_result_val result, void *data)
190 if (result == APPSVC_RES_CANCEL) {
191 printf("==== %d : canceled(preemptted) my request ===\n", num);
193 printf("==== %d : result packet === result %d\n", num, (int)result);
194 //bundle_iterate(kb, prt_recvd_bundle, NULL);
196 bundle_foreach(kb, prt_recvd_bundle, NULL);
199 if (strcmp(cmd, "run_svc_res") == 0) {
200 printf("==== end of appsvc_run() ====\n");
201 ecore_main_loop_quit();
211 kb = bundle_create();
213 printf("bundle creation fail\n");
217 printf("[run_svc_res test]\n");
219 __set_bundle_from_args(kb);
221 ret = appsvc_usr_run_service(kb, 0, cb_func, (void *)num, getuid());
224 printf("open service success\n");
231 printf("open service fail\n");
240 static test_func_t test_func[] = {
242 {"run_svc", run_svc, "run_svc test",
243 "[usage] run_svc -o <OPERATION> [-m <MIME TYPE>] [-u <URI>] [-d \"<key>,<val>\"]..."},
244 {"run_svc_res", run_svc_res, "run_svc_res test",
245 "[usage] run_svc_res -o <OPERATION> [-m <MIME TYPE>] [-u <URI>] [-d \"<key>,<val>\"]..."},
249 int callfunc(char *testname)
255 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
257 if (strcmp(testname, tmp->name) == 0) {
259 if (strcmp(testname, "all")) {
261 printf("... test failed\n");
263 printf("... test successs ret = %d\n", res);
270 void print_usage(char *progname)
275 printf("[usage] %s <cmd> ...\n", progname);
276 printf(" - available cmd list\n");
278 for (i = 0; i < sizeof(test_func) / sizeof(test_func_t); i++) {
280 printf("\t%s : %s\n", tmp->name, tmp->desc);
281 printf("\t\t%s\n", tmp->usage);
286 static Eina_Bool run_func(void *data)
290 if (strcmp(cmd, "run_svc_res") == 0)
293 ecore_main_loop_quit();
298 int main(int argc, char **argv)
301 print_usage(argv[0]);
310 apn_pid = atoi(argv[2]);
312 aul_launch_init(NULL, NULL);
314 //aul_listen_app_dead_signal(dead_tracker,NULL);
315 //aul_listen_app_dead_signal(NULL,NULL);
317 ecore_idler_add(run_func, NULL);
319 ecore_main_loop_begin();