diff --git a/src/mu-util.h b/src/mu-util.h index 03516410..42488968 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -57,11 +57,12 @@ gboolean mu_util_create_dir_maybe (const gchar *path); /** - * check whether path is readable and/or writeable + * check whether path is a directory, and optionally, if it's readable + * and/or writeable * * @param path dir path * @param readable check for readability - * @param writeable check fro writability + * @param writeable check for writability * * @return TRUE if dir exist and has the specified properties */ diff --git a/src/tests/test-util b/src/tests/test-util index 4140bf7e..c32e390b 100755 Binary files a/src/tests/test-util and b/src/tests/test-util differ diff --git a/src/tests/test-util.c b/src/tests/test-util.c index adabb289..a09db336 100644 --- a/src/tests/test-util.c +++ b/src/tests/test-util.c @@ -102,6 +102,54 @@ test_mu_util_guess_maildir_02 (void) } +static void +test_mu_util_check_dir_01 (void) +{ + if (g_access ("/usr/bin", F_OK) == 0) { + g_assert_cmpuint ( + mu_util_check_dir ("/usr/bin", TRUE, FALSE) == TRUE, + ==, + g_access ("/usr/bin", R_OK) == 0); + } +} + + +static void +test_mu_util_check_dir_02 (void) +{ + if (g_access ("/tmp", F_OK) == 0) { + g_assert_cmpuint ( + mu_util_check_dir ("/tmp", FALSE, TRUE) == TRUE, + ==, + g_access ("/tmp", W_OK) == 0); + } +} + + +static void +test_mu_util_check_dir_03 (void) +{ + if (g_access (".", F_OK) == 0) { + g_assert_cmpuint ( + mu_util_check_dir (".", TRUE, TRUE) == TRUE, + ==, + g_access (".", W_OK | R_OK) == 0); + } +} + + +static void +test_mu_util_check_dir_04 (void) +{ + /* not a dir, so it must be false */ + g_assert_cmpuint ( + mu_util_check_dir ("test-util.c", TRUE, TRUE), + ==, + FALSE); +} + + + @@ -124,6 +172,17 @@ main (int argc, char *argv[]) test_mu_util_guess_maildir_01); g_test_add_func ("/mu-util/mu-util-guess-maildir-02", test_mu_util_guess_maildir_02); + + /* mu_util_check_dir */ + g_test_add_func ("/mu-util/mu-util-check-dir-01", + test_mu_util_check_dir_01); + g_test_add_func ("/mu-util/mu-util-check-dir-02", + test_mu_util_check_dir_02); + g_test_add_func ("/mu-util/mu-util-check-dir-03", + test_mu_util_check_dir_03); + g_test_add_func ("/mu-util/mu-util-check-dir-04", + test_mu_util_check_dir_04); + g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG|