Initialize Tizen 2.3
[framework/system/deviced.git] / src / auto-test / tvout.c
1 /*
2  * test
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #include "test.h"
19
20 static const struct device_change_type {
21         char *name;
22         char *status;
23 } device_change_types [] = {
24         {"tvout",       "1"},
25         {"tvout",       "0"},
26 };
27
28 static int test(int index)
29 {
30         DBusError err;
31         DBusMessage *msg;
32         int ret, ret_val;
33         char *param[4];
34
35         param[0] = METHOD_SET_DEVICE;
36         param[1] = "2";
37         param[2] = device_change_types[index].name;
38         param[3] = device_change_types[index].status;
39
40         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
41                         DEVICED_PATH_SYSNOTI,
42                         DEVICED_INTERFACE_SYSNOTI,
43                         METHOD_SET_DEVICE, "siss", param);
44         if (!msg) {
45                 _E("fail : %s %s %s %s",
46                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
47                         METHOD_SET_DEVICE);
48                 return -EBADMSG;
49         }
50
51         dbus_error_init(&err);
52
53         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID);
54         if (ret == 0) {
55                 _E("no message : [%s:%s]", err.name, err.message);
56                 dbus_error_free(&err);
57                 ret_val = -EBADMSG;
58         }
59         _I("%s %s", device_change_types[index].name, device_change_types[index].status);
60         dbus_message_unref(msg);
61         dbus_error_free(&err);
62         sleep(TEST_WAIT_TIME_INTERVAL);
63         return ret_val;
64 }
65
66 static void unit(char *unit, char *status)
67 {
68         int index;
69
70         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
71                 if (strcmp(unit, device_change_types[index].name) != 0 ||
72                     strcmp(status, device_change_types[index].status) != 0)
73                         continue;
74                 test(index);
75         }
76 }
77
78 static void tvout_init(void *data)
79 {
80         int index;
81
82         _I("start test");
83         for (index = 0; index < ARRAY_SIZE(device_change_types); index++)
84                 test(index);
85 }
86
87 static void tvout_exit(void *data)
88 {
89         _I("end test");
90 }
91
92 static int tvout_unit(int argc, char **argv)
93 {
94         int status;
95
96         if (argv[1] == NULL)
97                 return -EINVAL;
98         if (argc != 3)
99                 return -EAGAIN;
100
101         unit(argv[1], argv[2]);
102 out:
103         return 0;
104 }
105
106 static const struct test_ops tvout_test_ops = {
107         .priority = TEST_PRIORITY_NORMAL,
108         .name     = "tvout",
109         .init     = tvout_init,
110         .exit    = tvout_exit,
111         .unit    = tvout_unit,
112 };
113
114 TEST_OPS_REGISTER(&tvout_test_ops)