Calculate in a different way the number of messages shown.
[modest] / tests / check_modest-utils.c
1 /* Copyright (c) 2009, 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 <gtk/gtk.h>
33 #include <string.h>
34 #include <modest-init.h>
35 #include <modest-utils.h>
36
37 static void
38 fx_setup_modest_utils ()
39 {
40         fail_unless (gtk_init_check (NULL, NULL));
41
42         fail_unless (g_setenv (MODEST_DIR_ENV, ".modesttest", TRUE));
43         fail_unless (g_setenv (MODEST_NAMESPACE_ENV, "/apps/modesttest", TRUE));
44
45         fail_unless (modest_init (0, NULL), "Failed running modest_init");
46
47 }
48
49 START_TEST (test_modest_utils_folder_writable)
50 {
51         gboolean result;
52         const gchar *path;
53
54         result = modest_utils_folder_writable(NULL);
55         fail_unless (result == FALSE,
56                      "modest_utils_folder_writeable should return FALSE for NULL");
57
58         path = g_getenv ("HOME");
59         result = modest_utils_folder_writable(path);
60         fail_unless (result == TRUE,
61                      "modest_utils_folder_writeable should return TRUE for HOME");
62 }
63 END_TEST
64
65 START_TEST (test_modest_utils_file_exists)
66 {
67         gboolean result;
68
69         result = modest_utils_file_exists(NULL);
70         fail_unless (result == FALSE,
71                      "modest_utils_file_exists should return FALSE for NULL");
72
73         result = modest_utils_file_exists("/etc/host.conf");
74         fail_unless (result == TRUE,
75                      "modest_utils_file_exists should return FALSE for hostname");
76
77         result = modest_utils_file_exists("/etc/does-not-exist");
78         fail_unless (result == FALSE,
79                      "modest_utils_folder_writeable should return FALSE for /");
80
81 }
82 END_TEST
83
84
85 static Suite*
86 modest_utils_suite (void)
87 {
88         Suite *suite = suite_create ("ModestUtils");
89
90         TCase *tc_core = tcase_create ("core");
91         tcase_add_checked_fixture (tc_core,
92                                    fx_setup_modest_utils,
93                                    NULL);
94         tcase_add_test (tc_core, test_modest_utils_folder_writable);
95         tcase_add_test (tc_core, test_modest_utils_file_exists);
96
97         suite_add_tcase (suite, tc_core);
98
99         return suite;
100 }
101
102
103 int
104 main ()
105 {
106         SRunner *srunner;
107         Suite   *suite;
108         int     failures;
109         
110         g_type_init();
111
112         suite   = modest_utils_suite ();
113         srunner = srunner_create (suite);
114
115         srunner_run_all (srunner, CK_ENV);
116         failures = srunner_ntests_failed (srunner);
117         srunner_free (srunner);
118         
119         return failures;
120 }