--- /dev/null
+/*
+ * test
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "test.h"
+
+#define METHOD_EXTCON_GETSTATUS "GetStatus"
+#define METHOD_EXTCON_ENABLE "enable"
+#define METHOD_EXTCON_DISABLE "disable"
+
+static bool request_extcon_method(const char *method, char *sig, char *param[])
+{
+ DBusMessage *msg;
+ int val;
+ bool ret = FALSE;
+
+ msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_EXTCON,
+ DEVICED_INTERFACE_EXTCON,
+ method, sig, param);
+ if (!msg) {
+ _E("fail (%s): no reply", method);
+ return ret;
+ }
+
+ if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0)
+ _E("fail (%s): no message", method);
+ else {
+ if ((val == -ENOTSUP) || (val == -ENOSYS)) {
+ _I("Not supported feature! (%s): %d", method, val);
+ ret = TRUE;
+ } else if (val < 0) {
+ _E("fail (%s): returned fail (%d)", method, val);
+ } else {
+ _I("success (%s): %d", method, val);
+ ret = TRUE;
+ }
+ }
+
+ dbus_message_unref(msg);
+ return ret;
+}
+
+static bool get_extcon_status(char *device_name)
+{
+ DBusMessage *msg;
+ int val;
+ bool ret = FALSE;
+ char *param[1];
+
+ param[0] = device_name;
+ msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_EXTCON,
+ DEVICED_INTERFACE_EXTCON,
+ METHOD_EXTCON_GETSTATUS, "s", param);
+ if (!msg) {
+ _E("fail : no reply");
+ return ret;
+ }
+
+ if (dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID) == 0)
+ _E("fail : no message");
+ else {
+ if ((val == -ENOTSUP) || (val == -ENOSYS)) {
+ _I("Not supported feature! : %d", val);
+ ret = TRUE;
+ } else if ((val == -EINVAL) || (val == -ENOENT)) {
+ _E("fail : returned fail (%d)", val);
+ } else {
+ _I("success : %d", val);
+ ret = TRUE;
+ }
+ }
+
+ dbus_message_unref(msg);
+ return ret;
+}
+
+static bool set_extcon_enable(char *device_name)
+{
+ char *param[1];
+
+ param[0] = device_name;
+ return request_extcon_method(METHOD_EXTCON_ENABLE, "s", param);
+}
+
+static bool set_extcon_disable(char *device_name)
+{
+ char *param[1];
+
+ param[0] = device_name;
+ return request_extcon_method(METHOD_EXTCON_DISABLE, "s", param);
+}
+
+
+void extcon_test_all(int *success, int *fail)
+{
+ int s = 0;
+ int f = 0;
+
+ (set_extcon_enable("Headphone")) ? s++ : f++;
+ (get_extcon_status("Headphone")) ? s++ : f++;
+ (set_extcon_disable("Headphone")) ? s++ : f++;
+
+ if (NULL != success) *success = s;
+ if (NULL != fail) *fail = f;
+}
+
+static void extcon_init(void *data)
+{
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+
+ extcon_test_all(&success, &fail);
+
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void extcon_exit(void *data)
+{
+ _I("end test");
+}
+
+static int extcon_unit(int argc, char **argv)
+{
+ if (argc < 4) {
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+ extcon_test_all(&success, &fail);
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+ } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_GETSTATUS)) {
+ get_extcon_status(argv[4]);
+ } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_ENABLE)) {
+ set_extcon_enable(argv[4]);
+ } else if (0 == strcasecmp(argv[3], METHOD_EXTCON_DISABLE)) {
+ set_extcon_disable(argv[4]);
+ } else {
+ _E("Unknown test case!!!");
+ }
+
+ return 0;
+}
+
+static const struct test_ops extcon_test_ops = {
+ .priority = TEST_PRIORITY_NORMAL,
+ .name = "extcon",
+ .init = extcon_init,
+ .exit = extcon_exit,
+ .unit = extcon_unit,
+};
+
+TEST_OPS_REGISTER(&extcon_test_ops)