1 /* Copyright (c) 2009, 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>
34 #include <modest-init.h>
35 #include <modest-utils.h>
38 fx_setup_modest_utils ()
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_utils_folder_writable)
54 result = modest_utils_folder_writable(NULL);
55 fail_unless (result == FALSE,
56 "modest_utils_folder_writeable should return FALSE for NULL");
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");
65 START_TEST (test_modest_utils_file_exists)
69 result = modest_utils_file_exists(NULL);
70 fail_unless (result == FALSE,
71 "modest_utils_file_exists should return FALSE for NULL");
73 result = modest_utils_file_exists("/etc/host.conf");
74 fail_unless (result == TRUE,
75 "modest_utils_file_exists should return FALSE for hostname");
77 result = modest_utils_file_exists("/etc/does-not-exist");
78 fail_unless (result == FALSE,
79 "modest_utils_folder_writeable should return FALSE for /");
86 modest_utils_suite (void)
88 Suite *suite = suite_create ("ModestUtils");
90 TCase *tc_core = tcase_create ("core");
91 tcase_add_checked_fixture (tc_core,
92 fx_setup_modest_utils,
94 tcase_add_test (tc_core, test_modest_utils_folder_writable);
95 tcase_add_test (tc_core, test_modest_utils_file_exists);
97 suite_add_tcase (suite, tc_core);
112 suite = modest_utils_suite ();
113 srunner = srunner_create (suite);
115 srunner_run_all (srunner, CK_ENV);
116 failures = srunner_ntests_failed (srunner);
117 srunner_free (srunner);