4 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #define METHOD_EXTCON_GETSTATUS "GetStatus"
21 #define METHOD_EXTCON_ENABLE "enable"
22 #define METHOD_EXTCON_DISABLE "disable"
24 #define METHOD_SYSNOTI_GETCRADLE "GetCradle"
25 #define METHOD_SYSNOTI_GETHDMI "GetHDMI"
27 static bool request_extcon_method(const char *method, GVariant *param)
33 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
35 DEVICED_INTERFACE_EXTCON,
40 _E("fail (%s): no reply", method);
44 if (!g_variant_get_safe(msg, "(i)", &val))
45 _E("fail (%s): no message", method);
47 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
48 _I("Not supported feature! (%s): %d", method, val);
51 _E("fail (%s): returned fail (%d)", method, val);
53 _I("success (%s): %d", method, val);
62 static bool get_sysnoti_method(const char *method)
68 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
70 DEVICED_INTERFACE_SYSNOTI,
73 _E("fail (%s): no reply", method);
77 if (!g_variant_get_safe(msg, "(i)", &val))
78 _E("fail (%s): no message", method);
80 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
81 _I("Not supported feature! (%s): %d", method, val);
83 } else if ((val == -EINVAL) || (val == -ENOENT)) {
84 _E("fail : returned fail (%d)", val);
86 _I("success (%s): %d", method, val);
95 static bool get_extcon_status(char *device_name)
101 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
103 DEVICED_INTERFACE_EXTCON,
104 METHOD_EXTCON_GETSTATUS,
105 g_variant_new("(s)", device_name),
108 _E("fail : no reply");
112 if (!g_variant_get_safe(msg, "(i)", &val))
113 _E("fail : no message");
115 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
116 _I("Not supported feature! : %d", val);
118 } else if ((val == -EINVAL) || (val == -ENOENT)) {
119 _E("fail : returned fail (%d)", val);
121 _I("success : %d", val);
126 g_variant_unref(msg);
130 static bool set_extcon_enable(char *device_name)
132 return request_extcon_method(METHOD_EXTCON_ENABLE, g_variant_new("(s)", device_name));
135 static bool set_extcon_disable(char *device_name)
137 return request_extcon_method(METHOD_EXTCON_DISABLE, g_variant_new("(s)", device_name));
140 static bool get_sysnoti_cradle()
142 return get_sysnoti_method(METHOD_SYSNOTI_GETCRADLE);
145 static bool get_sysnoti_hdmi()
147 return get_sysnoti_method(METHOD_SYSNOTI_GETHDMI);
150 void extcon_test_all(int *success, int *fail)
155 (set_extcon_enable("Headphone")) ? s++ : f++;
156 (get_extcon_status("Headphone")) ? s++ : f++;
157 (set_extcon_disable("Headphone")) ? s++ : f++;
159 (get_sysnoti_cradle()) ? s++ : f++;
160 (get_sysnoti_hdmi()) ? s++ : f++;
162 if (NULL != success) *success = s;
163 if (NULL != fail) *fail = f;
166 static void extcon_init(void *data)
173 extcon_test_all(&success, &fail);
175 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
178 static void extcon_exit(void *data)
183 static int extcon_unit(int argc, char **argv)
190 extcon_test_all(&success, &fail);
191 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
192 } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_GETSTATUS)) {
193 get_extcon_status(argv[4]);
194 } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_ENABLE)) {
195 set_extcon_enable(argv[4]);
196 } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_DISABLE)) {
197 set_extcon_disable(argv[4]);
198 } else if (0 == strcasecmp(argv[3], METHOD_SYSNOTI_GETCRADLE)) {
199 get_sysnoti_cradle();
200 } else if (0 == strcasecmp(argv[3], METHOD_SYSNOTI_GETHDMI)) {
203 _E("Unknown test case!!!");
209 static const struct test_ops extcon_test_ops = {
210 .priority = TEST_PRIORITY_NORMAL,
217 TEST_OPS_REGISTER(&extcon_test_ops)