4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hakjoo ko <hakjoo.ko@samsung.com>
8 * This library is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; either version 2.1 of the License, or (at your option)
13 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 * License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this library; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gconf/gconf-client.h>
30 const char *vconfkeys[5][5]={
31 {"db", "db/unittest/key1", "db/unittest/key2", "db/unittest/key3", "db/unittest/key4"},
32 {"file", "file/unittest/key1", "file/unittest/key2", "file/unittest/key3", "file/unittest/key4"},
33 {"memory", "memory/unittest/key1", "memory/unittest/key2", "memory/unittest/key3", "memory/unittest/key4"},
34 {"gconf_l", "gconf_l/unittest/key1", "gconf_l/unittest/key2", "gconf_l/unittest/key3", "gconf_l/unittest/key4"},
35 {"gconf_d", "gconf_d/unittest/key1", "gconf_d/unittest/key2", "gconf_d/unittest/key3", "gconf_d/unittest/key4"}
38 #define EPRINT(FMT, ARG...) \
39 fprintf(stderr, "\x1b[31m[VConf Unit Test]\x1b[0m" FMT "\n", ##ARG)
41 #define PRINT(FMT, ARG...) \
42 fprintf(stdout, "\x1b[33m[VConf Unit Test]\x1b[0m" FMT "\n", ##ARG)
44 static GMainLoop *event_loop;
46 void test_cb(keynode_t *key, void* data)
48 switch(vconf_keynode_get_type(key))
51 printf("key = %s, value = %d(int)\n",
52 vconf_keynode_get_name(key), vconf_keynode_get_int(key));
55 printf("key = %s, value = %d(bool)\n",
56 vconf_keynode_get_name(key), vconf_keynode_get_bool(key));
58 case VCONF_TYPE_DOUBLE:
59 printf("key = %s, value = %f(double)\n",
60 vconf_keynode_get_name(key), vconf_keynode_get_dbl(key));
62 case VCONF_TYPE_STRING:
63 printf("key = %s, value = %s(string)\n",
64 vconf_keynode_get_name(key), vconf_keynode_get_str(key));
67 printf("key = %s, deleted\n", vconf_keynode_get_name(key));
68 if(data == (void *)vconfkeys[4][0]) g_main_loop_quit(event_loop);
71 fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key));
75 PRINT("%s Notification OK", (char *)data);
79 void set_operation(int i)
83 if(vconf_set_int(vconfkeys[i][1], 1))
84 EPRINT("vconf_set_int FAIL(%s)", vconfkeys[i][0]);
86 PRINT("vconf_set_int OK(%s)", vconfkeys[i][0]);
88 if(vconf_set_dbl(vconfkeys[i][2], 0.1))
89 EPRINT("vconf_set_dbl FAIL(%s)", vconfkeys[i][0]);
91 PRINT("vconf_set_dbl OK(%s)", vconfkeys[i][0]);
93 if(vconf_set_bool(vconfkeys[i][3], 1))
94 EPRINT("vconf_set_bool FAIL(%s)", vconfkeys[i][0]);
96 PRINT("vconf_set_bool OK(%s)", vconfkeys[i][0]);
98 if(vconf_set_str(vconfkeys[i][4], "This is UNIT test"))
99 EPRINT("vconf_set_str FAIL(%s)", vconfkeys[i][0]);
101 PRINT("vconf_set_str OK(%s)", vconfkeys[i][0]);
103 kl = vconf_keylist_new();
104 vconf_keylist_add_dbl(kl, vconfkeys[i][1], 0.2);
105 vconf_keylist_add_bool(kl, vconfkeys[i][2], 0);
106 vconf_keylist_add_str(kl, vconfkeys[i][3], "This is UNIT test");
107 vconf_keylist_add_int(kl, vconfkeys[i][4], 2);
109 EPRINT("vconf_set FAIL(%s)", vconfkeys[i][0]);
111 PRINT("vconf_set OK(%s)", vconfkeys[i][0]);
112 vconf_keylist_free(kl);
117 void get_operation(int i, const char* parent_dir)
120 keynode_t *temp_node;
125 if(vconf_get_dbl(vconfkeys[i][1], &get_dbl) || get_dbl != 0.2)
126 EPRINT("vconf_get_dbl FAIL(%s)", vconfkeys[i][0]);
128 PRINT("vconf_get_dbl OK(%s)", vconfkeys[i][0]);
130 if(vconf_get_bool(vconfkeys[i][2], &get_int) || get_int != 0)
131 EPRINT("vconf_get_bool FAIL(%s)", vconfkeys[i][0]);
133 PRINT("vconf_get_bool OK(%s)", vconfkeys[i][0]);
135 get_str=vconf_get_str(vconfkeys[i][3]);
136 if(get_str && !strcmp(get_str, "This is UNIT test"))
137 PRINT("vconf_get_str OK(%s)", vconfkeys[i][0]);
139 EPRINT("vconf_get_str FAIL(%s)", vconfkeys[i][0]);
140 if(get_str) free(get_str);
142 if(vconf_get_int(vconfkeys[i][4], &get_int) || get_int != 2)
143 EPRINT("vconf_get_int FAIL(%s)", vconfkeys[i][0]);
145 PRINT("vconf_get_int OK(%s)", vconfkeys[i][0]);
147 kl = vconf_keylist_new();
148 if(vconf_get(kl, parent_dir, 0))
149 EPRINT("vconf_get FAIL(%s)", vconfkeys[i][0]);
151 PRINT("vconf_get OK(%s)", vconfkeys[i][0]);
153 while((temp_node = vconf_keylist_nextnode(kl))) {
154 switch(vconf_keynode_get_type(temp_node)) {
156 printf("key = %s, value = %d\n",
157 vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node));
159 case VCONF_TYPE_BOOL:
160 printf("key = %s, value = %d\n",
161 vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node));
163 case VCONF_TYPE_DOUBLE:
164 printf("key = %s, value = %f\n",
165 vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node));
167 case VCONF_TYPE_STRING:
168 printf("key = %s, value = %s\n",
169 vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node));
172 printf("Unknown Type\n");
175 vconf_keylist_free(kl);
178 void unset_operation(int i)
180 if(vconf_unset(vconfkeys[i][1]))
181 EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]);
183 PRINT("vconf_unset OK(%s)", vconfkeys[i][0]);
184 if(vconf_unset(vconfkeys[i][2]))
185 EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]);
187 PRINT("vconf_unset OK(%s)", vconfkeys[i][0]);
188 if(vconf_unset(vconfkeys[i][3]))
189 EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]);
191 PRINT("vconf_unset OK(%s)", vconfkeys[i][0]);
192 if(vconf_unset(vconfkeys[i][4]))
193 EPRINT("vconf_unset FAIL(%s)", vconfkeys[i][0]);
195 PRINT("vconf_unset OK(%s)", vconfkeys[i][0]);
198 const char *test_dir[5]={
199 "/opt/var/kdb/db/unittest", "/opt/var/kdb/file/unittest", "/var/run/memory/unittest",
200 "/opt/var/gconf/local/unittest", "/opt/var/gconf/unittest"};
202 void recursive_unset_operation(void)
208 vconf_set_int(vconfkeys[i][j],1);
210 sprintf(parent, "%s/unittest", vconfkeys[i][0]);
211 if(vconf_unset_recursive(parent))
212 EPRINT("vconf_unset_recursive FAIL(%s)", parent);
214 if(opendir(test_dir[i]))
215 EPRINT("vconf_unset_recursive FAIL(%s)", parent);
217 PRINT("vconf_unset_recursive OK(%s)", parent);
222 void notify_operation(int i)
227 if(vconf_notify_key_changed(vconfkeys[i][j], test_cb, (void *)vconfkeys[i][0])) {
229 PRINT("vconf_notify_key_changed OK(%s)", vconfkeys[i][j]);
231 EPRINT("vconf_notify_key_changed FAIL(%s)", vconfkeys[i][j]);
234 EPRINT("vconf_notify_key_changed FAIL(%s)", vconfkeys[i][j]);
236 PRINT("vconf_notify_key_changed OK(%s)", vconfkeys[i][j]);
241 int main(int argc, char **argv)
250 get_operation(0, "db/unittest");
251 get_operation(1, "file/unittest");
252 get_operation(2, "memory/unittest");
253 get_operation(3, "gconf_l/unittest");
254 get_operation(4, "gconf_d/unittest");
260 recursive_unset_operation();
266 printf("For Notification TEST, You have to excute below command\n");
267 printf("vconftool set -t int db/unittest/key1 1\n");
268 printf("vconftool set -t int file/unittest/key2 1\n");
269 printf("vconftool set -t int memory/unittest/key3 1\n");
270 printf("vconftool set -t int gconf_d/unittest/key4 1\n");
271 printf("vconftool unset db/unittest/key1\n");
272 printf("vconftool unset file/unittest/key2\n");
273 printf("vconftool unset memory/unittest/key3\n");
274 printf("vconftool unset gconf_d/unittest/key4\n");
276 //ecore_main_loop_begin();
277 event_loop = g_main_loop_new(NULL, FALSE);
278 g_main_loop_run(event_loop);
280 EPRINT("Did you get 8 Notifications\n");