From: Jose Dapena Paz Date: Fri, 6 Feb 2009 10:20:07 +0000 (+0000) Subject: Some changes in unit tests. X-Git-Tag: git_migration_finished~659 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=7df0c91ceb0b50d52477369d559e4f202ba44c8b Some changes in unit tests. pmo-trunk-r7396 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 9469e50..ac98936 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,12 +15,14 @@ TESTS = \ check_text-utils \ check_modest-conf \ check_update-account \ + check_modest-utils \ check_account-mgr noinst_PROGRAMS= \ check_folder-xfer \ check_modest-conf \ check_text-utils \ + check_modest-utils \ check_update-account \ check_account-mgr @@ -61,6 +63,10 @@ check_modest_conf_SOURCES=\ check_modest-conf.c check_modest_conf_LDADD = $(objects) +check_modest_utils_SOURCES=\ + check_modest-utils.c +check_modest_utils_LDADD = $(objects) + check_text_utils_SOURCES=\ check_text-utils.c check_text_utils_LDADD = $(objects) diff --git a/tests/check_account-mgr.c b/tests/check_account-mgr.c index 369ac3b..1cd8d08 100644 --- a/tests/check_account-mgr.c +++ b/tests/check_account-mgr.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,19 @@ START_TEST (test_add_exists_remove_account_regular) fail_unless (result, "modest_account_mgr_account_exists failed: " \ "Account with name \"%s\" should exist.\n", name); + + /* Test 2b */ + gchar *account_name_from_recipient; + account_name_from_recipient = modest_utils_get_account_name_from_recipient ("user@email.com"); + fail_unless (account_name_from_recipient != NULL, + "modest_utils_get_account_name_from_recipient failed: "\ + "From user@email.com should match account"); + + /* Test 2c */ + account_name_from_recipient = modest_utils_get_account_name_from_recipient ("egg@egg.com"); + fail_unless (account_name_from_recipient == NULL, + "modest_utils_get_account_name_from_recipient failed: "\ + "From egg@egg.com shouldn't match account"); /* Test 3 */ @@ -367,7 +381,7 @@ account_mgr_suite (void) /* Tests case for "add/exists/remove account" */ tc = tcase_create ("add_exists_remove_account"); - tcase_add_unchecked_fixture (tc, + tcase_add_checked_fixture (tc, fx_setup_default_account_mgr, NULL); tcase_add_test (tc, test_add_exists_remove_account_regular); tcase_add_test (tc, test_add_exists_remove_account_invalid); diff --git a/tests/check_modest-utils.c b/tests/check_modest-utils.c new file mode 100644 index 0000000..4e8a00f --- /dev/null +++ b/tests/check_modest-utils.c @@ -0,0 +1,120 @@ +/* Copyright (c) 2009, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +static void +fx_setup_modest_utils () +{ + fail_unless (gtk_init_check (NULL, NULL)); + + fail_unless (g_setenv (MODEST_DIR_ENV, ".modesttest", TRUE)); + fail_unless (g_setenv (MODEST_NAMESPACE_ENV, "/apps/modesttest", TRUE)); + + fail_unless (modest_init (0, NULL), "Failed running modest_init"); + +} + +START_TEST (test_modest_utils_folder_writable) +{ + gboolean result; + const gchar *path; + + result = modest_utils_folder_writable(NULL); + fail_unless (result == FALSE, + "modest_utils_folder_writeable should return FALSE for NULL"); + + path = g_getenv ("HOME"); + result = modest_utils_folder_writable(path); + fail_unless (result == TRUE, + "modest_utils_folder_writeable should return TRUE for HOME"); +} +END_TEST + +START_TEST (test_modest_utils_file_exists) +{ + gboolean result; + + result = modest_utils_file_exists(NULL); + fail_unless (result == FALSE, + "modest_utils_file_exists should return FALSE for NULL"); + + result = modest_utils_file_exists("/etc/host.conf"); + fail_unless (result == TRUE, + "modest_utils_file_exists should return FALSE for hostname"); + + result = modest_utils_file_exists("/etc/does-not-exist"); + fail_unless (result == FALSE, + "modest_utils_folder_writeable should return FALSE for /"); + +} +END_TEST + + +static Suite* +modest_utils_suite (void) +{ + Suite *suite = suite_create ("ModestUtils"); + + TCase *tc_core = tcase_create ("core"); + tcase_add_checked_fixture (tc_core, + fx_setup_modest_utils, + NULL); + tcase_add_test (tc_core, test_modest_utils_folder_writable); + tcase_add_test (tc_core, test_modest_utils_file_exists); + + suite_add_tcase (suite, tc_core); + + return suite; +} + + +int +main () +{ + SRunner *srunner; + Suite *suite; + int failures; + + g_type_init(); + + suite = modest_utils_suite (); + srunner = srunner_create (suite); + + srunner_run_all (srunner, CK_ENV); + failures = srunner_ntests_failed (srunner); + srunner_free (srunner); + + return failures; +}