Add multi-user support
[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 /* For multi-user support */
31 #include <tzplatform_config.h>
32
33 static void startup(void);
34 static void cleanup(void);
35
36 void (*tet_startup)(void) = startup;
37 void (*tet_cleanup)(void) = cleanup;
38
39
40 #define API_NAME_SETTINGS_SET_VALUE_STRING      "system_settings_set_value_string"
41 #define API_NAME_SETTINGS_GET_VALUE_STRING      "system_settings_get_value_string"
42 #define API_NAME_SETTINGS_SET_VALUE_INT         "system_settings_set_value_int"
43 #define API_NAME_SETTINGS_GET_VALUE_INT         "system_settings_get_value_int"
44 #define API_NAME_SETTINGS_SET_VALUE_BOOL        "system_settings_set_value_bool"
45 #define API_NAME_SETTINGS_GET_VALUE_BOOL        "system_settings_get_value_bool"
46 #define API_NAME_SETTINGS_SET_CHANGED_CB        "system_settings_set_changed_cb"
47 #define API_NAME_SETTINGS_UNSET_CHANGED_CB      "system_settings_unset_changed_cb"
48
49 static void utc_system_settings_set_string_p(void);
50 static void utc_system_settings_set_bool_p(void);
51 static void utc_system_settings_get_string_p(void);
52 static void utc_system_settings_get_int_p(void);
53 static void utc_system_settings_get_bool_p(void);
54 static void utc_system_settings_set_changed_cb(void);
55 static void utc_system_settings_unset_changed_cb(void);
56
57
58 struct tet_testlist tet_testlist[] = {
59         {utc_system_settings_set_string_p, 1},
60         {utc_system_settings_set_bool_p, 1},
61         {utc_system_settings_get_string_p, 1},
62         {utc_system_settings_get_int_p, 1},
63         {utc_system_settings_get_bool_p, 1},
64         {utc_system_settings_set_changed_cb, 1},
65         {utc_system_settings_unset_changed_cb, 1},
66         {NULL, 0},
67 };
68
69 static GMainLoop* main_loop;
70 static int timeout = 5;
71
72 static void startup(void)
73 {
74         main_loop = g_main_loop_new(NULL, FALSE);
75 }
76
77 static void cleanup(void)
78 {
79         /* end of TC */
80 }
81
82 static gboolean callback(gpointer data)
83 {
84         /*int ret =*/ system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, 1);
85
86         static int i = 0;
87
88         i++;
89         if(timeout == i){
90                 g_main_loop_quit((GMainLoop*)data);
91                 return FALSE;
92         }
93
94         return TRUE;
95 }
96
97 static void utc_system_settings_changed_motion_activation(system_settings_key_e key, void *user_data)
98 {
99
100 }
101
102 static void utc_system_settings_set_string_p(void)
103 {
104         const char *path_to_mp3 = tzplatform_mkpath(TZ_SYS_SHARE, "settings/Ringtones/General_Over the horizon.mp3");
105
106         int retcode = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, path_to_mp3);
107
108         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
109                 dts_pass(API_NAME_SETTINGS_SET_VALUE_STRING, "passed");
110         }
111         else {
112                 dts_fail(API_NAME_SETTINGS_SET_VALUE_STRING, "failed");
113         }
114 }
115
116 static void utc_system_settings_set_bool_p(void)
117 {
118         int retcode = system_settings_set_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, true);
119
120         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
121                 dts_pass(API_NAME_SETTINGS_SET_VALUE_BOOL, "passed");
122         }
123         else {
124                 dts_fail(API_NAME_SETTINGS_SET_VALUE_BOOL, "failed");
125         }
126 }
127
128 static void utc_system_settings_get_string_p(void)
129 {
130         char *value = NULL;
131         int retcode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
132
133         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
134                 dts_pass(API_NAME_SETTINGS_GET_VALUE_STRING, "passed");
135         }
136         else {
137                 dts_fail(API_NAME_SETTINGS_GET_VALUE_STRING, "failed");
138         }
139 }
140
141 static void utc_system_settings_get_int_p(void)
142 {
143         int value = -1;
144         int retcode = system_settings_get_value_int(SYSTEM_SETTINGS_KEY_FONT_SIZE, &value);
145
146         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
147                 dts_pass(API_NAME_SETTINGS_GET_VALUE_INT, "passed");
148         }
149         else {
150                 dts_fail(API_NAME_SETTINGS_GET_VALUE_INT, "failed");
151         }
152 }
153
154 static void utc_system_settings_get_bool_p(void)
155 {
156         bool value = false;
157         int retcode = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, &value);
158
159         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
160                 dts_pass(API_NAME_SETTINGS_GET_VALUE_BOOL, "passed");
161         }
162         else {
163                 dts_fail(API_NAME_SETTINGS_GET_VALUE_BOOL, "failed");
164         }
165 }
166
167 static void utc_system_settings_set_changed_cb(void)
168 {
169         int retcode = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION, utc_system_settings_changed_motion_activation, NULL);
170
171         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
172                 dts_pass(API_NAME_SETTINGS_SET_CHANGED_CB, "passed");
173         }
174         else {
175                 dts_fail(API_NAME_SETTINGS_SET_CHANGED_CB, "failed");
176         }
177
178         g_timeout_add_seconds(5, callback, main_loop);
179         g_main_loop_run(main_loop);
180         g_main_loop_unref(main_loop);
181 }
182
183 static void utc_system_settings_unset_changed_cb(void)
184 {
185         int retcode = system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION);
186
187         if (retcode == SYSTEM_SETTINGS_ERROR_NONE) {
188                 dts_pass(API_NAME_SETTINGS_UNSET_CHANGED_CB, "passed");
189         }
190         else {
191                 dts_fail(API_NAME_SETTINGS_UNSET_CHANGED_CB, "failed");
192         }
193 }