tizen 2.3 release
[framework/system/deviced.git] / src / auto-test / cool-down.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 METHOD_COOL_DOWN_STATUS         "GetCoolDownStatus"
22 #define METHOD_COOL_DOWN_CHANGED        "CoolDownChanged"
23 static int get_status(void)
24 {
25         DBusError err;
26         DBusMessage *msg;
27         int ret;
28         char *str;
29
30         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
31                         DEVICED_PATH_SYSNOTI,
32                         DEVICED_INTERFACE_SYSNOTI,
33                         METHOD_COOL_DOWN_STATUS, NULL, NULL);
34         if (!msg) {
35                 _E("fail : %s %s %s %s",
36                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
37                         METHOD_COOL_DOWN_STATUS);
38                 return -EBADMSG;
39         }
40
41         dbus_error_init(&err);
42
43         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str,
44                         DBUS_TYPE_INVALID);
45         if (!ret)
46                 _E("no message : [%s:%s]", err.name, err.message);
47
48         _I("%s", str);
49         if (ret < 0)
50                 _R("[NG] ---- %s", __func__);
51         else
52                 _R("[OK] ---- %s      : V(%s)", __func__, str);
53         dbus_message_unref(msg);
54         dbus_error_free(&err);
55         return ret;
56 }
57
58 static int cool_down(char *name, char *status)
59 {
60         DBusError err;
61         DBusMessage *msg;
62         int ret, val;
63         char *param[4];
64
65         param[0] = METHOD_SET_DEVICE;
66         param[1] = "2";
67         param[2] = name;
68         param[3] = status;
69
70         msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
71                         DEVICED_PATH_SYSNOTI,
72                         DEVICED_INTERFACE_SYSNOTI,
73                         METHOD_COOL_DOWN_CHANGED, "siss", param);
74         if (!msg) {
75                 _E("fail : %s %s %s %s",
76                         DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI,
77                         METHOD_SET_DEVICE);
78                 return -EBADMSG;
79         }
80
81         dbus_error_init(&err);
82
83         ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID);
84         if (ret == 0) {
85                 _E("no message : [%s:%s]", err.name, err.message);
86                 dbus_error_free(&err);
87                 val = -EBADMSG;
88         }
89         _I("%s %s", name, status);
90         if (val < 0)
91                 _R("[NG] ---- %s", __func__);
92         else
93                 _R("[OK] ---- %s           : V(%s %s)",
94                 __func__, name, status);
95         dbus_message_unref(msg);
96         dbus_error_free(&err);
97         return val;
98 }
99
100 static void unit(char *unit, char *status)
101 {
102         int index;
103
104         cool_down(unit, status);
105         get_status();
106 }
107
108 static void cool_down_init(void *data)
109 {
110 }
111
112 static void cool_down_exit(void *data)
113 {
114 }
115
116 static int cool_down_unit(int argc, char **argv)
117 {
118         int status;
119
120         if (argv[1] == NULL)
121                 return -EINVAL;
122         if (argc != 4)
123                 return -EAGAIN;
124
125         unit(argv[2], argv[3]);
126 out:
127         return 0;
128 }
129
130 static const struct test_ops cool_down_test_ops = {
131         .priority = TEST_PRIORITY_NORMAL,
132         .name     = "cool-down",
133         .init     = cool_down_init,
134         .exit     = cool_down_exit,
135         .unit     = cool_down_unit,
136 };
137
138 TEST_OPS_REGISTER(&cool_down_test_ops)