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-conf.h>
34 START_TEST (test_modest_conf_new)
36 ModestConf *conf = modest_conf_new ();
37 fail_unless (MODEST_IS_CONF(conf),
38 "modest_conf_new should return a valid"
39 " ModestConf instance");
40 g_object_unref (conf);
45 START_TEST (test_modest_conf_store_retrieve_string)
47 ModestConf *conf = modest_conf_new ();
48 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
49 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
51 const gchar *data = "hello in Korean: 안녕하세요";
54 fail_unless (MODEST_IS_CONF(conf),
55 "modest_conf_new should return a valid"
56 " ModestConf instance");
58 fail_unless (modest_conf_set_string (
59 conf, key, data, NULL),
60 "modest_conf_set_string should return TRUE");
62 fail_unless (modest_conf_key_exists(conf, key, NULL),
63 "modest_conf_key_exists should return TRUE for <key>");
64 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
65 "modest_conf_key_exists should return FALSE for <key2>");
67 data2 = modest_conf_get_string (conf, key, NULL);
68 fail_unless (data2 && strcmp (data2, data) == 0,
69 "modest_conf_get_string should return what we put there");
72 fail_unless (modest_conf_remove_key (conf, key, NULL),
73 "modest_conf_remove_key should return TRUE");
75 fail_unless (!modest_conf_key_exists(conf, key, NULL),
76 "modest_conf_key should return FALSE after we"
79 g_object_unref (conf);
85 START_TEST (test_modest_conf_store_retrieve_bool)
87 ModestConf *conf = modest_conf_new ();
88 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
89 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
91 gboolean data = TRUE, data2;
93 fail_unless (MODEST_IS_CONF(conf),
94 "modest_conf_new should return a valid"
95 " ModestConf instance");
97 fail_unless (modest_conf_set_bool (conf, key, data, NULL),
98 "modest_conf_set_bool should return TRUE");
100 fail_unless (modest_conf_key_exists(conf, key, NULL),
101 "modest_conf_key_exists should return TRUE for <key>");
102 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
103 "modest_conf_key_exists should return FALSE for <key2>");
105 data2 = modest_conf_get_bool (conf, key, NULL);
106 fail_unless (data2 == data,
107 "modest_conf_get_bool should return what we put there");
108 fail_unless (modest_conf_remove_key (conf, key, NULL),
109 "modest_conf_remove_key should return TRUE");
111 fail_unless (!modest_conf_key_exists(conf, key, NULL),
112 "modest_conf_key should return FALSE after we"
115 g_object_unref (conf);
120 START_TEST (test_modest_conf_store_retrieve_int)
122 ModestConf *conf = modest_conf_new ();
123 const gchar *key = MODEST_CONF_NAMESPACE "/teststring";
124 const gchar *key2 = MODEST_CONF_NAMESPACE "/teststring2";
126 gint data = 99, data2;
128 fail_unless (MODEST_IS_CONF(conf),
129 "modest_conf_new should return a valid"
130 " ModestConf instance");
132 fail_unless (modest_conf_set_int (conf, key, data, NULL),
133 "modest_conf_set_int should return TRUE");
135 fail_unless (modest_conf_key_exists(conf, key, NULL),
136 "modest_conf_key_exists should return TRUE for <key>");
137 fail_unless (!modest_conf_key_exists(conf, key2, NULL),
138 "modest_conf_key_exists should return FALSE for <key2>");
140 data2 = modest_conf_get_int (conf, key, NULL);
141 fail_unless (data2 == data,
142 "modest_conf_get_int should return what we put there");
143 fail_unless (modest_conf_remove_key (conf, key, NULL),
144 "modest_conf_remove_key should return TRUE");
146 fail_unless (!modest_conf_key_exists(conf, key, NULL),
147 "modest_conf_key should return FALSE after we"
150 g_object_unref (conf);
157 modest_conf_suite (void)
159 Suite *suite = suite_create ("ModestConf");
161 TCase *tc_core = tcase_create ("core");
162 tcase_add_test (tc_core, test_modest_conf_new);
163 tcase_add_test (tc_core, test_modest_conf_store_retrieve_string);
164 tcase_add_test (tc_core, test_modest_conf_store_retrieve_bool);
165 tcase_add_test (tc_core, test_modest_conf_store_retrieve_int);
167 suite_add_tcase (suite, tc_core);
182 suite = modest_conf_suite ();
183 srunner = srunner_create (suite);
185 srunner_run_all (srunner, CK_NORMAL);
186 failures = srunner_ntests_failed (srunner);
187 srunner_free (srunner);