tizen 2.3 release
[framework/system/deviced.git] / src / auto-test / time.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
19 #include "test.h"
20
21 #define TIME_CHANGE_SIGNAL "STimeChanged"
22
23 static E_DBus_Signal_Handler *edbus_handler;
24 static E_DBus_Connection     *edbus_conn;
25
26 static void unregister_edbus_signal_handler(void)
27 {
28         e_dbus_signal_handler_del(edbus_conn, edbus_handler);
29         e_dbus_connection_close(edbus_conn);
30         e_dbus_shutdown();
31 }
32
33 static void time_changed(void *data, DBusMessage *msg)
34 {
35         DBusError err;
36         int val;
37         int ret;
38
39         _I("edbus signal Received");
40
41         ret = dbus_message_is_signal(msg, DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL);
42         if (!ret) {
43                 _E("dbus_message_is_signal error");
44                 return;
45         }
46
47         _I("%s - %s", DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL);
48         if (ret < 0)
49                 _R("[NG] ---- %s", __func__);
50         else
51                 _R("[OK] ---- %s", __func__);
52         unregister_edbus_signal_handler();
53         ecore_shutdown();
54 }
55
56 static int register_edbus_signal_handler(void)
57 {
58         int ret;
59
60         e_dbus_init();
61
62         edbus_conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
63         if (!(edbus_conn)) {
64                 ret = -ECONNREFUSED;
65                 goto edbus_handler_out;
66         }
67
68         edbus_handler = e_dbus_signal_handler_add(edbus_conn, NULL, DEVICED_PATH_TIME,
69                         DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL, time_changed, NULL);
70         if (!(edbus_handler)) {
71                 ret = -ECONNREFUSED;
72                 goto edbus_handler_connection_out;
73         }
74         return 0;
75
76 edbus_handler_connection_out:
77         e_dbus_connection_close(edbus_conn);
78 edbus_handler_out:
79         e_dbus_shutdown();
80         return ret;
81 }
82
83 static void test_signal(void)
84 {
85         _I("test");
86         register_edbus_signal_handler();
87         ecore_main_loop_begin();
88 }
89
90 static void time_init(void *data)
91 {
92 }
93
94 static void time_exit(void *data)
95 {
96 }
97
98 static int time_unit(int argc, char **argv)
99 {
100         if (argv[1] == NULL)
101                 return -EINVAL;
102         else if (argc != 4)
103                 return -EAGAIN;
104         if (strcmp("wait", argv[2]) == 0)
105                 test_signal();
106         return 0;
107 }
108
109 static const struct test_ops power_test_ops = {
110         .priority = TEST_PRIORITY_NORMAL,
111         .name     = "time",
112         .init     = time_init,
113         .exit    = time_exit,
114         .unit    = time_unit,
115 };
116
117 TEST_OPS_REGISTER(&power_test_ops)