1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <modest-defs.h>
32 #include <modest-conf.h>
35 #include <modest-init.h>
38 fx_setup_modest_conf ()
40 fail_unless (gtk_init_check (NULL, NULL));
42 fail_unless (g_setenv (MODEST_DIR_ENV, ".modesttest", TRUE));
43 fail_unless (g_setenv (MODEST_NAMESPACE_ENV, "/apps/modesttest", TRUE));
45 fail_unless (modest_init (0, NULL), "Failed running modest_init");
49 START_TEST (test_modest_conf_new)
51 ModestConf *conf = modest_conf_new ();
52 fail_unless (MODEST_IS_CONF(conf),
53 "modest_conf_new should return a valid"
54 " ModestConf instance");
55 g_object_unref (conf);
60 START_TEST (test_modest_conf_store_retrieve_string)
62 ModestConf *conf = modest_conf_new ();
63 const gchar *key = modest_defs_namespace ("/teststring");
64 const gchar *key2 = modest_defs_namespace ("/teststring2");
66 const gchar *data = "hello in Korean: 안녕하세요";
69 fail_unless (MODEST_IS_CONF(conf),
70 "modest_conf_new should return a valid"
71 " ModestConf instance");
73 fail_unless (modest_conf_set_string (
74 conf, key, data, NULL),
75 "modest_conf_set_string should return TRUE");
77 fail_unless (modest_conf_key_exists(conf, key, NULL),
78 "modest_conf_key_exists should return TRUE for <key>");
79 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
80 "modest_conf_key_exists should return FALSE for <key2>");
82 data2 = modest_conf_get_string (conf, key, NULL);
83 fail_unless (data2 && strcmp (data2, data) == 0,
84 "modest_conf_get_string should return what we put there");
87 fail_unless (modest_conf_remove_key (conf, key, NULL),
88 "modest_conf_remove_key should return TRUE");
90 fail_unless (!modest_conf_key_exists(conf, key, NULL),
91 "modest_conf_key should return FALSE after we"
94 g_object_unref (conf);
100 START_TEST (test_modest_conf_store_retrieve_bool)
102 ModestConf *conf = modest_conf_new ();
103 const gchar *key = modest_defs_namespace ("/teststring");
104 const gchar *key2 = modest_defs_namespace ("/teststring2");
106 gboolean data = TRUE, data2;
108 fail_unless (MODEST_IS_CONF(conf),
109 "modest_conf_new should return a valid"
110 " ModestConf instance");
112 fail_unless (modest_conf_set_bool (conf, key, data, NULL),
113 "modest_conf_set_bool should return TRUE");
115 fail_unless (modest_conf_key_exists(conf, key, NULL),
116 "modest_conf_key_exists should return TRUE for <key>");
117 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
118 "modest_conf_key_exists should return FALSE for <key2>");
120 data2 = modest_conf_get_bool (conf, key, NULL);
121 fail_unless (data2 == data,
122 "modest_conf_get_bool should return what we put there");
123 fail_unless (modest_conf_remove_key (conf, key, NULL),
124 "modest_conf_remove_key should return TRUE");
126 fail_unless (!modest_conf_key_exists(conf, key, NULL),
127 "modest_conf_key should return FALSE after we"
130 g_object_unref (conf);
135 START_TEST (test_modest_conf_store_retrieve_int)
137 ModestConf *conf = modest_conf_new ();
138 const gchar *key = modest_defs_namespace ("/teststring");
139 const gchar *key2 = modest_defs_namespace ("/teststring2");
141 gint data = 99, data2;
143 fail_unless (MODEST_IS_CONF(conf),
144 "modest_conf_new should return a valid"
145 " ModestConf instance");
147 fail_unless (modest_conf_set_int (conf, key, data, NULL),
148 "modest_conf_set_int should return TRUE");
150 fail_unless (modest_conf_key_exists(conf, key, NULL),
151 "modest_conf_key_exists should return TRUE for <key>");
152 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
153 "modest_conf_key_exists should return FALSE for <key2>");
155 data2 = modest_conf_get_int (conf, key, NULL);
156 fail_unless (data2 == data,
157 "modest_conf_get_int should return what we put there");
158 fail_unless (modest_conf_remove_key (conf, key, NULL),
159 "modest_conf_remove_key should return TRUE");
161 fail_unless (!modest_conf_key_exists(conf, key, NULL),
162 "modest_conf_key should return FALSE after we"
165 g_object_unref (conf);
172 modest_conf_suite (void)
174 Suite *suite = suite_create ("ModestConf");
176 TCase *tc_core = tcase_create ("core");
177 tcase_add_checked_fixture (tc_core,
178 fx_setup_modest_conf,
180 tcase_add_test (tc_core, test_modest_conf_new);
181 tcase_add_test (tc_core, test_modest_conf_store_retrieve_string);
182 tcase_add_test (tc_core, test_modest_conf_store_retrieve_bool);
183 tcase_add_test (tc_core, test_modest_conf_store_retrieve_int);
185 suite_add_tcase (suite, tc_core);
200 suite = modest_conf_suite ();
201 srunner = srunner_create (suite);
203 srunner_run_all (srunner, CK_ENV);
204 failures = srunner_ntests_failed (srunner);
205 srunner_free (srunner);