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 START_TEST (test_modest_conf_new)
37 ModestConf *conf = modest_conf_new ();
38 fail_unless (MODEST_IS_CONF(conf),
39 "modest_conf_new should return a valid"
40 " ModestConf instance");
41 g_object_unref (conf);
46 START_TEST (test_modest_conf_store_retrieve_string)
48 ModestConf *conf = modest_conf_new ();
49 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
50 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
52 const gchar *data = "hello in Korean: 안녕하세요";
55 fail_unless (MODEST_IS_CONF(conf),
56 "modest_conf_new should return a valid"
57 " ModestConf instance");
59 fail_unless (modest_conf_set_string (
60 conf, key, data, NULL),
61 "modest_conf_set_string should return TRUE");
63 fail_unless (modest_conf_key_exists(conf, key, NULL),
64 "modest_conf_key_exists should return TRUE for <key>");
65 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
66 "modest_conf_key_exists should return FALSE for <key2>");
68 data2 = modest_conf_get_string (conf, key, NULL);
69 fail_unless (data2 && strcmp (data2, data) == 0,
70 "modest_conf_get_string should return what we put there");
73 fail_unless (modest_conf_remove_key (conf, key, NULL),
74 "modest_conf_remove_key should return TRUE");
76 fail_unless (!modest_conf_key_exists(conf, key, NULL),
77 "modest_conf_key should return FALSE after we"
80 g_object_unref (conf);
86 START_TEST (test_modest_conf_store_retrieve_bool)
88 ModestConf *conf = modest_conf_new ();
89 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
90 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
92 gboolean data = TRUE, data2;
94 fail_unless (MODEST_IS_CONF(conf),
95 "modest_conf_new should return a valid"
96 " ModestConf instance");
98 fail_unless (modest_conf_set_bool (conf, key, data, NULL),
99 "modest_conf_set_bool should return TRUE");
101 fail_unless (modest_conf_key_exists(conf, key, NULL),
102 "modest_conf_key_exists should return TRUE for <key>");
103 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
104 "modest_conf_key_exists should return FALSE for <key2>");
106 data2 = modest_conf_get_bool (conf, key, NULL);
107 fail_unless (data2 == data,
108 "modest_conf_get_bool should return what we put there");
109 fail_unless (modest_conf_remove_key (conf, key, NULL),
110 "modest_conf_remove_key should return TRUE");
112 fail_unless (!modest_conf_key_exists(conf, key, NULL),
113 "modest_conf_key should return FALSE after we"
116 g_object_unref (conf);
121 START_TEST (test_modest_conf_store_retrieve_int)
123 ModestConf *conf = modest_conf_new ();
124 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
125 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
127 gint data = 99, data2;
129 fail_unless (MODEST_IS_CONF(conf),
130 "modest_conf_new should return a valid"
131 " ModestConf instance");
133 fail_unless (modest_conf_set_int (conf, key, data, NULL),
134 "modest_conf_set_int should return TRUE");
136 fail_unless (modest_conf_key_exists(conf, key, NULL),
137 "modest_conf_key_exists should return TRUE for <key>");
138 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
139 "modest_conf_key_exists should return FALSE for <key2>");
141 data2 = modest_conf_get_int (conf, key, NULL);
142 fail_unless (data2 == data,
143 "modest_conf_get_int should return what we put there");
144 fail_unless (modest_conf_remove_key (conf, key, NULL),
145 "modest_conf_remove_key should return TRUE");
147 fail_unless (!modest_conf_key_exists(conf, key, NULL),
148 "modest_conf_key should return FALSE after we"
151 g_object_unref (conf);
158 modest_conf_suite (void)
160 Suite *suite = suite_create ("ModestConf");
162 TCase *tc_core = tcase_create ("core");
163 tcase_add_test (tc_core, test_modest_conf_new);
164 tcase_add_test (tc_core, test_modest_conf_store_retrieve_string);
165 tcase_add_test (tc_core, test_modest_conf_store_retrieve_bool);
166 tcase_add_test (tc_core, test_modest_conf_store_retrieve_int);
168 suite_add_tcase (suite, tc_core);
183 suite = modest_conf_suite ();
184 srunner = srunner_create (suite);
186 srunner_run_all (srunner, CK_NORMAL);
187 failures = srunner_ntests_failed (srunner);
188 srunner_free (srunner);