Clean up file mode
[platform/core/base/syspopup.git] / tool / test.c
1 /*
2  * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <bundle.h>
21 #include <bundle_internal.h>
22 #include "syspopup_caller.h"
23
24 static int __foreach_cb(const char *popup_name, const char *appid,
25                 void *user_data)
26 {
27         printf("system popup    name [%s]  appid [%s]\n", popup_name, appid);
28         return 0;
29 }
30
31 static void usage(void)
32 {
33         printf("[usage] sp_test launch/destroy/foreach popup_name..."
34                                 "(key1,val1,key2,val2,...)\n");
35 }
36
37 int main(int argc, char **argv)
38 {
39         bundle *b;
40         int i;
41         int ret = 0;
42
43         if (argc < 2) {
44                 usage();
45                 return -1;
46         }
47
48         if (strcmp(argv[1], "launch") == 0) {
49                 if ((argc < 3) || (argc % 2 == 0)) {
50                         usage();
51                         return -1;
52                 }
53
54                 b = bundle_create();
55                 for (i = 3; i < argc; i = i + 2)
56                         bundle_add(b, argv[i], argv[i + 1]);
57                 ret = syspopup_launch(argv[2], b);
58                 bundle_free(b);
59                 if (ret < 0)
60                         return -1;
61
62         } else if (strcmp(argv[1], "destroy") == 0) {
63                 ret = syspopup_destroy_all();
64                 if (ret < 0)
65                         return -1;
66         } else if (strcmp(argv[1], "foreach") == 0) {
67                 ret = syspopup_foreach_info(__foreach_cb, NULL);
68                 if (ret < 0)
69                         return -1;
70         } else {
71                 usage();
72         }
73
74         return 0;
75 }
76