6bf37e4e57cf62156499389541cece9a9f9f0f28
[platform/core/api/system-settings.git] / TC / testcase / utc_system_settings.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <tet_api.h>
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <unistd.h>
22
23
24 #include <system_settings.h>
25
26 /* test loop code */
27 #include <glib.h>
28 #include <glib-object.h>
29
30 static void startup(void);
31 static void cleanup(void);
32
33 void (*tet_startup)(void) = startup;
34 void (*tet_cleanup)(void) = cleanup;
35
36
37 #define API_NAME_SETTINGS_SET_VALUE_STRING      "system_settings_set_value_string"
38 #define API_NAME_SETTINGS_GET_VALUE_STRING      "system_settings_get_value_string"
39 #define API_NAME_SETTINGS_SET_VALUE_INT         "system_settings_set_value_int"
40 #define API_NAME_SETTINGS_GET_VALUE_INT         "system_settings_get_value_int"
41 #define API_NAME_SETTINGS_SET_VALUE_BOOL        "system_settings_set_value_bool"
42 #define API_NAME_SETTINGS_GET_VALUE_BOOL        "system_settings_get_value_bool"
43 #define API_NAME_SETTINGS_SET_CHANGED_CB        "system_settings_set_changed_cb"
44 #define API_NAME_SETTINGS_UNSET_CHANGED_CB      "system_settings_unset_changed_cb"
45
46 static void utc_system_settings_set_string_p(void);
47 static void utc_system_settings_get_string_p(void);
48
49 static void utc_system_settings_set_bool_p(void);
50 static void utc_system_settings_get_bool_p(void);
51
52 static void utc_system_settings_get_int_p(void);
53 static void utc_system_settings_set_int_p(void);
54
55 static void utc_system_settings_set_changed_cb(void);
56 static void utc_system_settings_unset_changed_cb(void);
57
58
59 struct tet_testlist tet_testlist[] = {
60         {utc_system_settings_set_string_p, 1},
61         {utc_system_settings_set_bool_p, 1},
62         {utc_system_settings_get_string_p, 1},
63         {utc_system_settings_get_int_p, 1},
64         {utc_system_settings_get_bool_p, 1},
65         {utc_system_settings_set_int_p, 1},
66         {utc_system_settings_set_changed_cb, 1},
67         {utc_system_settings_unset_changed_cb, 1},
68         {NULL, 0},
69 };
70
71 static GMainLoop *main_loop;
72 static int timeout = 5;
73
74 static void startup(void)
75 {
76         main_loop = g_main_loop_new(NULL, FALSE);
77 }
78
79 static void cleanup(void)
80 {
81         /* end of TC */
82 }
83
84 static gboolean callback(gpointer data)
85 {
86         /*int ret =*/ system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 1);
87
88         static int i = 0;
89
90         i++;
91         if (timeout == i) {
92                 g_main_loop_quit((GMainLoop *)data);
93                 return FALSE;
94         }
95
96         return TRUE;
97 }
98
99 static void utc_system_settings_changed_motion_activation(system_settings_key_e key, void *user_data)
100 {
101
102 }
103
104 static void utc_system_settings_set_string_p(void)
105 {
106         int retcode = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, "/opt/share/settings/Ringtones/General_Over the horizon.mp3");
107
108         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
109                 dts_pass(API_NAME_SETTINGS_SET_VALUE_STRING, "passed");
110         } else {
111                 dts_fail(API_NAME_SETTINGS_SET_VALUE_STRING, "failed");
112         }
113 }
114
115 static void utc_system_settings_set_bool_p(void)
116 {
117         int retcode = system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, true);
118
119         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
120                 dts_pass(API_NAME_SETTINGS_SET_VALUE_BOOL, "passed");
121         } else {
122                 dts_fail(API_NAME_SETTINGS_SET_VALUE_BOOL, "failed");
123         }
124 }
125
126 static void utc_system_settings_get_string_p(void)
127 {
128         char *value = NULL;
129         int retcode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
130
131         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
132                 dts_pass(API_NAME_SETTINGS_GET_VALUE_STRING, "passed");
133         } else {
134                 dts_fail(API_NAME_SETTINGS_GET_VALUE_STRING, "failed");
135         }
136 }
137
138 static void utc_system_settings_get_int_p(void)
139 {
140         int value = -1;
141         int retcode = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &value);
142
143         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
144                 dts_pass(API_NAME_SETTINGS_GET_VALUE_INT, "passed");
145         } else {
146                 dts_fail(API_NAME_SETTINGS_GET_VALUE_INT, "failed");
147         }
148 }
149
150 static void utc_system_settings_get_bool_p(void)
151 {
152         bool value = false;
153         int retcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, &value);
154
155         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
156                 dts_pass(API_NAME_SETTINGS_GET_VALUE_BOOL, "passed");
157         } else {
158                 dts_fail(API_NAME_SETTINGS_GET_VALUE_BOOL, "failed");
159         }
160 }
161
162 static void utc_system_settings_set_int_p(void)
163 {
164         int retcode = system_settings_set_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, SYSTEM_SETTINGS_FONT_SIZE_NORMAL);
165
166         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
167                 dts_pass(API_NAME_SETTINGS_SET_VALUE_INT, "passed");
168         } else {
169                 dts_fail(API_NAME_SETTINGS_SET_VALUE_INT, "failed");
170         }
171 }
172
173
174 static void utc_system_settings_set_changed_cb(void)
175 {
176         int retcode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, utc_system_settings_changed_motion_activation, NULL);
177
178         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
179                 dts_pass(API_NAME_SETTINGS_SET_CHANGED_CB, "passed");
180         } else {
181                 dts_fail(API_NAME_SETTINGS_SET_CHANGED_CB, "failed");
182         }
183
184         g_timeout_add_seconds(5, callback, main_loop);
185         g_main_loop_run(main_loop);
186         g_main_loop_unref(main_loop);
187 }
188
189 static void utc_system_settings_unset_changed_cb(void)
190 {
191         int retcode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION);
192
193         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
194                 dts_pass(API_NAME_SETTINGS_UNSET_CHANGED_CB, "passed");
195         } else {
196                 dts_fail(API_NAME_SETTINGS_UNSET_CHANGED_CB, "failed");
197         }
198 }