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_TIME_SET_DATETIME "set_datetime"
21 #define METHOD_TIME_SET_TIMEZONE "set_timezone"
23 static bool request_sysnoti_method(const char *method, GVariant *param)
29 err = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME,
31 DEVICED_INTERFACE_SYSNOTI,
36 _E("fail (%s): no reply", method);
40 if (!g_variant_get_safe(msg, "(i)", &val))
41 _E("fail (%s): no message", method);
43 if ((val == -ENOTSUP) || (val == -ENOSYS)) {
44 _I("Not supported feature! (%s): %d", method, val);
47 _E("fail (%s): returned fail (%d)", method, val);
49 _I("success (%s): %d", method, val);
58 static bool set_time_datetime(int date_time)
61 snprintf(str_time, sizeof(str_time) - 1, "%d", date_time);
62 return request_sysnoti_method(METHOD_TIME_SET_DATETIME, g_variant_new("(sis)", METHOD_TIME_SET_DATETIME, 1, str_time));
65 static bool set_time_timezone(char *localtime_path)
67 return request_sysnoti_method(METHOD_TIME_SET_TIMEZONE, g_variant_new("(sis)", METHOD_TIME_SET_TIMEZONE, 1, localtime_path));
70 void time_test_all(int *success, int *fail)
75 (set_time_datetime(time(NULL)-600)) ? s++ : f++;
76 (set_time_datetime(time(NULL))) ? s++ : f++;
77 (set_time_timezone("/usr/share/zoneinfo/America/Cancun")) ? s++ : f++;
78 (set_time_timezone("/usr/share/zoneinfo/Asia/Seoul")) ? s++ : f++;
80 if (NULL != success) *success = s;
81 if (NULL != fail) *fail = f;
84 static void time_init(void *data)
91 time_test_all(&success, &fail);
93 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
96 static void time_exit(void *data)
101 static int time_unit(int argc, char **argv)
108 time_test_all(&success, &fail);
109 _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
110 } else if (0 == strcasecmp(argv[3], METHOD_TIME_SET_DATETIME)) {
111 set_time_datetime(atoi(argv[4]));
112 } else if (0 == strcasecmp(argv[3], METHOD_TIME_SET_TIMEZONE)) {
113 set_time_timezone(argv[4]);
115 _E("Unknown test case!!!");
121 static const struct test_ops time_test_ops = {
122 .priority = TEST_PRIORITY_NORMAL,
129 TEST_OPS_REGISTER(&time_test_ops)