diff options
| author | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2010-01-25 13:27:02 +0200 |
|---|---|---|
| committer | Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> | 2010-01-25 13:27:02 +0200 |
| commit | 3b8f908fa6003d151cdb58b66fa8a27e786d9752 (patch) | |
| tree | bcd0f1d87ec183956048124c5fbeb7be4366d07f /src/tests | |
| parent | afcd800a2e779f6df7281d73c9d0bb801fb198bf (diff) | |
* tests: add tests for mu_util_dir_expand and mu_util_guess_maildir
Diffstat (limited to 'src/tests')
| -rwxr-xr-x | src/tests/test-util | bin | 19704 -> 21094 bytes | |||
| -rw-r--r-- | src/tests/test-util.c | 82 |
2 files changed, 78 insertions, 4 deletions
diff --git a/src/tests/test-util b/src/tests/test-util Binary files differindex 3d17a81..4140bf7 100755 --- a/src/tests/test-util +++ b/src/tests/test-util diff --git a/src/tests/test-util.c b/src/tests/test-util.c index 2f5ed7a..adabb28 100644 --- a/src/tests/test-util.c +++ b/src/tests/test-util.c @@ -23,25 +23,89 @@ #include <glib.h> #include <stdlib.h> +#include <unistd.h> #include "src/mu-util.h" static void -test_mu_util_dir_expand (void) +test_mu_util_dir_expand_01 (void) { gchar *got, *expected; got = mu_util_dir_expand ("~/Desktop"); expected = g_strdup_printf ("%s%cDesktop", getenv("HOME"), G_DIR_SEPARATOR); + + g_assert_cmpstr (got,==,expected); + + g_free (got); + g_free (expected); + +} +static void +test_mu_util_dir_expand_02 (void) +{ + gchar *got, *expected, *tmp; + + tmp = g_strdup_printf ("~%s/Desktop", getenv("LOGNAME")); + got = mu_util_dir_expand (tmp); + expected = g_strdup_printf ("%s%cDesktop", + getenv("HOME"), G_DIR_SEPARATOR); + g_assert_cmpstr (got,==,expected); + + g_free (tmp); g_free (got); g_free (expected); } static void +test_mu_util_guess_maildir_01 (void) +{ + char *got; + const char *expected; + + /* skip the test if there's no /tmp */ + if (access ("/tmp", F_OK)) + return; + + g_setenv ("MAILDIR", "/tmp", TRUE); + + got = mu_util_guess_maildir (); + expected = "/tmp"; + + g_assert_cmpstr (got,==,expected); + g_free (got); +} + + +static void +test_mu_util_guess_maildir_02 (void) +{ + char *got, *mdir; + + g_unsetenv ("MAILDIR"); + + mdir = g_strdup_printf ("%s%cMaildir", + getenv("HOME"), G_DIR_SEPARATOR); + got = mu_util_guess_maildir (); + + if (access (mdir, F_OK) == 0) + g_assert_cmpstr (got, ==, mdir); + else + g_assert_cmpstr (got, == , NULL); + + g_free (got); + g_free (mdir); +} + + + + + +static void shutup (void) {} int @@ -49,12 +113,22 @@ main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); + /* mu_util_dir_expand */ g_test_add_func ("/mu-util/mu-util-dir-expand-01", - test_mu_util_dir_expand); + test_mu_util_dir_expand_01); + g_test_add_func ("/mu-util/mu-util-dir-expand-02", + test_mu_util_dir_expand_02); + /* mu_util_guess_maildir */ + g_test_add_func ("/mu-util/mu-util-guess-maildir-01", + test_mu_util_guess_maildir_01); + g_test_add_func ("/mu-util/mu-util-guess-maildir-02", + test_mu_util_guess_maildir_02); + g_log_set_handler (NULL, - G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO, - (GLogFunc)shutup, NULL); + G_LOG_LEVEL_DEBUG| + G_LOG_LEVEL_MESSAGE| + G_LOG_LEVEL_INFO, (GLogFunc)shutup, NULL); return g_test_run (); } |
