tizen 2.3 release
[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 tvout(int index)
29 {
30         DBusError err;
31         DBusMessage *msg;
32         int 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, &val, DBUS_TYPE_INVALID);
54         if (ret == 0) {
55                 _E("no message : [%s:%s]", err.name, err.message);
56                 dbus_error_free(&err);
57                 val = -EBADMSG;
58         }
59         _I("%s %s", device_change_types[index].name, device_change_types[index].status);
60         if (val < 0)
61                 _R("[NG] ---- %s", __func__);
62         else
63                 _R("[OK] ---- %s            : V(%s %s)",
64                 __func__, device_change_types[index].name, device_change_types[index].status);
65         dbus_message_unref(msg);
66         dbus_error_free(&err);
67         sleep(TEST_WAIT_TIME_INTERVAL);
68         return val;
69 }
70
71 static void unit(char *unit, char *status)
72 {
73         int index;
74
75         for (index = 0; index < ARRAY_SIZE(device_change_types); index++) {
76                 if (strcmp(unit, device_change_types[index].name) != 0 ||
77                     strcmp(status, device_change_types[index].status) != 0)
78                         continue;
79                 tvout(index);
80         }
81 }
82
83 static void tvout_init(void *data)
84 {
85         int index;
86
87         _I("start test");
88         for (index = 0; index < ARRAY_SIZE(device_change_types); index++)
89                 tvout(index);
90 }
91
92 static void tvout_exit(void *data)
93 {
94         _I("end test");
95 }
96
97 static int tvout_unit(int argc, char **argv)
98 {
99         int status;
100
101         if (argv[1] == NULL)
102                 return -EINVAL;
103         if (argc != 3)
104                 return -EAGAIN;
105
106         unit(argv[1], argv[2]);
107 out:
108         return 0;
109 }
110
111 static const struct test_ops tvout_test_ops = {
112         .priority = TEST_PRIORITY_NORMAL,
113         .name     = "tvout",
114         .init     = tvout_init,
115         .exit    = tvout_exit,
116         .unit    = tvout_unit,
117 };
118
119 TEST_OPS_REGISTER(&tvout_test_ops)