From 53b5dfa2bca1eaca612f5523b0884d4e540546a2 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sat, 13 Aug 2011 02:25:03 +0300 Subject: [PATCH] * update maildir unit tests --- src/tests/test-mu-maildir.c | 91 +++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/src/tests/test-mu-maildir.c b/src/tests/test-mu-maildir.c index 8a99160d..9f663b65 100644 --- a/src/tests/test-mu-maildir.c +++ b/src/tests/test-mu-maildir.c @@ -151,7 +151,7 @@ static MuError dir_cb (const char *fullpath, gboolean enter, WalkData *data) { if (enter) - ++data->_dir_entered; + ++data->_dir_entered; else ++data->_dir_left; @@ -238,17 +238,27 @@ test_mu_maildir_get_flags_from_path (void) MuFlags flags; } paths[] = { { - "/home/foo/Maildir/test/cur/123456:2,FSR", - MU_FLAG_REPLIED | MU_FLAG_SEEN | MU_FLAG_FLAGGED}, { - "/home/foo/Maildir/test/new/123456", - MU_FLAG_NEW | MU_FLAG_UNREAD}, { - "/home/foo/Maildir/test/new/123456:2,FR", - MU_FLAG_NEW | MU_FLAG_UNREAD}, { - "/home/foo/Maildir/test/cur/123456:2,DTP", - MU_FLAG_DRAFT | MU_FLAG_TRASHED | - MU_FLAG_PASSED | MU_FLAG_UNREAD }, { - "/home/foo/Maildir/test/cur/123456:2,S", - MU_FLAG_SEEN} + "/home/foo/Maildir/test/cur/123456:2,FSR", + MU_FLAG_REPLIED | MU_FLAG_SEEN | MU_FLAG_FLAGGED + }, + { + "/home/foo/Maildir/test/new/123456", + MU_FLAG_NEW + }, + { + /* NOTE: when in new/, the :2,.. stuff is ignored */ + "/home/foo/Maildir/test/new/123456:2,FR", + MU_FLAG_NEW + }, + { + "/home/foo/Maildir/test/cur/123456:2,DTP", + MU_FLAG_DRAFT | MU_FLAG_TRASHED | + MU_FLAG_PASSED + }, + { + "/home/foo/Maildir/test/cur/123456:2,S", + MU_FLAG_SEEN + } }; for (i = 0; i != G_N_ELEMENTS(paths); ++i) { @@ -259,7 +269,7 @@ test_mu_maildir_get_flags_from_path (void) } static void -test_mu_maildir_get_path_from_flags (void) +test_mu_maildir_get_new_path_01 (void) { int i; @@ -275,7 +285,7 @@ test_mu_maildir_get_path_from_flags (void) }, { "/home/foo/Maildir/test/cur/123456:2,FR", MU_FLAG_NEW, - "/home/foo/Maildir/test/new/123456:2," + "/home/foo/Maildir/test/new/123456" }, { "/home/foo/Maildir/test/new/123456:2,FR", MU_FLAG_SEEN | MU_FLAG_REPLIED, @@ -293,8 +303,51 @@ test_mu_maildir_get_path_from_flags (void) for (i = 0; i != G_N_ELEMENTS(paths); ++i) { gchar *str; - str = mu_maildir_get_path_from_flags(paths[i].oldpath, - paths[i].flags); + str = mu_maildir_get_new_path(paths[i].oldpath, NULL, + paths[i].flags); + g_assert_cmpstr(str, ==, paths[i].newpath); + g_free(str); + } +} + + +static void +test_mu_maildir_get_new_path_02 (void) +{ + int i; + + struct { + const char *oldpath; + MuFlags flags; + const char *targetdir; + const char *newpath; + } paths[] = { + { + "/home/foo/Maildir/test/cur/123456:2,FR", + MU_FLAG_REPLIED, "/home/foo/Maildir/blabla", + "/home/foo/Maildir/blabla/cur/123456:2,R" + }, { + "/home/foo/Maildir/test/cur/123456:2,FR", + MU_FLAG_NEW, "/home/bar/Maildir/coffee", + "/home/bar/Maildir/coffee/new/123456" + }, { + "/home/foo/Maildir/test/new/123456", + MU_FLAG_SEEN | MU_FLAG_REPLIED, + "/home/cuux/Maildir/tea", + "/home/cuux/Maildir/tea/cur/123456:2,RS" + }, { + "/home/foo/Maildir/test/new/1313038887_0.697:2,", + MU_FLAG_SEEN | MU_FLAG_FLAGGED | MU_FLAG_PASSED, + "/home/boy/Maildir/stuff", + "/home/boy/Maildir/stuff/cur/1313038887_0.697:2,FPS" + } + }; + + for (i = 0; i != G_N_ELEMENTS(paths); ++i) { + gchar *str; + str = mu_maildir_get_new_path(paths[i].oldpath, + paths[i].targetdir, + paths[i].flags); g_assert_cmpstr(str, ==, paths[i].newpath); g_free(str); } @@ -321,8 +374,10 @@ main (int argc, char *argv[]) test_mu_maildir_walk_02); /* get/set flags */ - g_test_add_func("/mu-maildir/mu-maildir-get-path-from-flags", - test_mu_maildir_get_path_from_flags); + g_test_add_func("/mu-maildir/mu-maildir-get-new-path-01", + test_mu_maildir_get_new_path_01); + g_test_add_func("/mu-maildir/mu-maildir-get-new-path-02", + test_mu_maildir_get_new_path_02); g_test_add_func("/mu-maildir/mu-maildir-get-flags-from-path", test_mu_maildir_get_flags_from_path);