* Fixes NB#96696, do not use -export-dynamic to reduce the symbols to be exported
[modest] / tests / check_modest-conf.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <check.h>
31 #include <modest-defs.h>
32 #include <modest-conf.h>
33 #include <string.h>
34
35 START_TEST (test_modest_conf_new)
36 {
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);
42 }
43 END_TEST
44
45
46 START_TEST (test_modest_conf_store_retrieve_string)
47 {
48         ModestConf *conf  = modest_conf_new ();
49         const gchar *key  =  MODEST_CONF_NAMESPACE "/teststring";
50         const gchar *key2 =  MODEST_CONF_NAMESPACE "/teststring2";
51
52         const gchar *data = "hello in Korean:  안녕하세요";
53         gchar *data2;
54         
55         fail_unless (MODEST_IS_CONF(conf),
56                      "modest_conf_new should return a valid"
57                      " ModestConf instance");
58
59         fail_unless (modest_conf_set_string (
60                              conf, key, data, NULL),
61                      "modest_conf_set_string should return TRUE");
62
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>");
67         
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");                                 
71         g_free (data2);
72         
73         fail_unless (modest_conf_remove_key (conf, key, NULL),
74                      "modest_conf_remove_key should return TRUE");
75         
76         fail_unless (!modest_conf_key_exists(conf, key, NULL),
77                      "modest_conf_key should return FALSE after we"
78                      "removed the key");
79         
80         g_object_unref (conf);
81 }
82 END_TEST
83
84
85
86 START_TEST (test_modest_conf_store_retrieve_bool)
87 {
88         ModestConf *conf  = modest_conf_new ();
89         const gchar *key  =  MODEST_CONF_NAMESPACE "/teststring";
90         const gchar *key2 =  MODEST_CONF_NAMESPACE "/teststring2";
91
92         gboolean data = TRUE, data2;
93         
94         fail_unless (MODEST_IS_CONF(conf),
95                      "modest_conf_new should return a valid"
96                      " ModestConf instance");
97
98         fail_unless (modest_conf_set_bool (conf, key, data, NULL),
99                      "modest_conf_set_bool should return TRUE");
100         
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>");
105         
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");
111         
112         fail_unless (!modest_conf_key_exists(conf, key, NULL),
113                      "modest_conf_key should return FALSE after we"
114                      "removed the key");
115
116         g_object_unref (conf);
117 }
118 END_TEST
119
120
121 START_TEST (test_modest_conf_store_retrieve_int)
122 {
123         ModestConf *conf  = modest_conf_new ();
124         const gchar *key  =  MODEST_CONF_NAMESPACE "/teststring";
125         const gchar *key2 =  MODEST_CONF_NAMESPACE "/teststring2";
126
127         gint data = 99, data2;
128         
129         fail_unless (MODEST_IS_CONF(conf),
130                      "modest_conf_new should return a valid"
131                      " ModestConf instance");
132
133         fail_unless (modest_conf_set_int (conf, key, data, NULL),
134                      "modest_conf_set_int should return TRUE");
135         
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>");
140         
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");
146         
147         fail_unless (!modest_conf_key_exists(conf, key, NULL),
148                      "modest_conf_key should return FALSE after we"
149                      "removed the key");
150
151         g_object_unref (conf);
152 }
153 END_TEST
154
155
156
157 static Suite*
158 modest_conf_suite (void)
159 {
160         Suite *suite = suite_create ("ModestConf");
161
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);
167
168         suite_add_tcase (suite, tc_core);
169
170         return suite;
171 }
172
173
174 int
175 main ()
176 {
177         SRunner *srunner;
178         Suite   *suite;
179         int     failures;
180         
181         g_type_init();
182
183         suite   = modest_conf_suite ();
184         srunner = srunner_create (suite);
185
186         srunner_run_all (srunner, CK_NORMAL);
187         failures = srunner_ntests_failed (srunner);
188         srunner_free (srunner);
189         
190         return failures;
191 }