From 22927a7dcff87ce8f7e4017a752cd208eed91f46 Mon Sep 17 00:00:00 2001 From: Jakub Sitnicki Date: Tue, 15 Jul 2014 07:22:11 +0200 Subject: [PATCH] tests: threads: Test if 1st child message promotes its thread --- .../sort/1st-child-promotes-thread/cur/A | 7 ++ .../sort/1st-child-promotes-thread/cur/B | 7 ++ .../sort/1st-child-promotes-thread/cur/C | 7 ++ .../sort/1st-child-promotes-thread/cur/D | 9 ++ .../1st-child-promotes-thread/new/.noindex | 0 .../1st-child-promotes-thread/tmp/.noindex | 0 mu/tests/test-mu-threads.c | 86 ++++++++++++++++++- 7 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/cur/A create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/cur/B create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/cur/C create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/cur/D create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/new/.noindex create mode 100644 lib/tests/testdir3/sort/1st-child-promotes-thread/tmp/.noindex diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/A b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/A new file mode 100644 index 00000000..85130e80 --- /dev/null +++ b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/A @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: A +Message-Id: +Date: Sat, 17 May 2014 10:00:00 +0000 + +A diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/B b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/B new file mode 100644 index 00000000..254aeb72 --- /dev/null +++ b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/B @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: B +Message-Id: +Date: Sat, 17 May 2014 10:00:00 +0000 + +B diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/C b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/C new file mode 100644 index 00000000..60b7db56 --- /dev/null +++ b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/C @@ -0,0 +1,7 @@ +From: testfrom@example.com +To: testto@example.com +Subject: C +Message-Id: +Date: Sat, 17 May 2014 10:00:00 +0000 + +C diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/D b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/D new file mode 100644 index 00000000..1e4861df --- /dev/null +++ b/lib/tests/testdir3/sort/1st-child-promotes-thread/cur/D @@ -0,0 +1,9 @@ +From: testfrom@example.com +To: testto@example.com +Subject: D +Message-Id: +References: +In-reply-to: +Date: Sat, 17 May 2014 10:00:00 +0000 + +D diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/new/.noindex b/lib/tests/testdir3/sort/1st-child-promotes-thread/new/.noindex new file mode 100644 index 00000000..e69de29b diff --git a/lib/tests/testdir3/sort/1st-child-promotes-thread/tmp/.noindex b/lib/tests/testdir3/sort/1st-child-promotes-thread/tmp/.noindex new file mode 100644 index 00000000..e69de29b diff --git a/mu/tests/test-mu-threads.c b/mu/tests/test-mu-threads.c index d56d56b7..8bfd3fe7 100644 --- a/mu/tests/test-mu-threads.c +++ b/mu/tests/test-mu-threads.c @@ -117,7 +117,8 @@ fill_database (const char *testdir) /* note: this also *moves the iter* */ static MuMsgIter* -run_and_get_iter (const char *xpath, const char *query) +run_and_get_iter_full (const char *xpath, const char *query, + MuMsgFieldId sort_field, MuQueryFlags flags) { MuQuery *mquery; MuStore *store; @@ -130,14 +131,21 @@ run_and_get_iter (const char *xpath, const char *query) mu_store_unref (store); g_assert (query); - iter = mu_query_run (mquery, query, MU_MSG_FIELD_ID_DATE, - -1, MU_QUERY_FLAG_THREADS, NULL); + flags |= MU_QUERY_FLAG_THREADS; + iter = mu_query_run (mquery, query, sort_field, -1, flags, NULL); mu_query_destroy (mquery); g_assert (iter); return iter; } +static MuMsgIter* +run_and_get_iter (const char *xpath, const char *query) +{ + return run_and_get_iter_full (xpath, query, MU_MSG_FIELD_ID_DATE, + MU_QUERY_FLAG_NONE); +} + static void test_mu_threads_01 (void) { @@ -216,6 +224,76 @@ test_mu_threads_rogue (void) mu_msg_iter_destroy (iter); } +static MuMsgIter* +query_testdir (const char *query, MuMsgFieldId sort_field, gboolean descending) +{ + MuMsgIter *iter; + gchar *xpath; + MuQueryFlags flags; + + flags = MU_QUERY_FLAG_NONE; + if (descending) + flags |= MU_QUERY_FLAG_DESCENDING; + + xpath = fill_database (MU_TESTMAILDIR3); + g_assert (xpath != NULL); + + iter = run_and_get_iter_full (xpath, query, sort_field, flags); + g_assert (iter != NULL); + g_assert (!mu_msg_iter_is_done (iter)); + + g_free (xpath); + return iter; +} + +static void +check_sort_by_subject (const char *query, const tinfo expected[], + guint n_expected, gboolean descending) +{ + MuMsgIter *iter; + + iter = query_testdir (query, MU_MSG_FIELD_ID_SUBJECT, descending); + foreach_assert_tinfo_equal (iter, expected, n_expected); + mu_msg_iter_destroy (iter); +} + +static void +check_sort_by_subject_asc (const char *query, const tinfo expected[], + guint n_expected) +{ + check_sort_by_subject (query, expected, n_expected, FALSE); +} + +static void +check_sort_by_subject_desc (const char *query, const tinfo expected[], + guint n_expected) +{ + check_sort_by_subject (query, expected, n_expected, TRUE); +} + +static void +test_mu_threads_sort_1st_child_promotes_thread (void) +{ + const char *query = "maildir:/sort/1st-child-promotes-thread"; + + const tinfo expected_asc [] = { + { "0", "A@msg.id", "A"}, + { "1", "C@msg.id", "C"}, + { "2", "B@msg.id", "B"}, + { "2:0", "D@msg.id", "D"}, + }; + const tinfo expected_desc [] = { + { "0", "B@msg.id", "B"}, + { "0:0", "D@msg.id", "D"}, + { "1", "C@msg.id", "C"}, + { "2", "A@msg.id", "A"}, + }; + + check_sort_by_subject_asc (query, expected_asc, + G_N_ELEMENTS (expected_asc)); + check_sort_by_subject_desc (query, expected_desc, + G_N_ELEMENTS (expected_desc)); +} int @@ -227,6 +305,8 @@ main (int argc, char *argv[]) g_test_add_func ("/mu-query/test-mu-threads-01", test_mu_threads_01); g_test_add_func ("/mu-query/test-mu-threads-rogue", test_mu_threads_rogue); + g_test_add_func ("/mu-query/test-mu-threads-sort-1st-child-promotes-thread", + test_mu_threads_sort_1st_child_promotes_thread); g_log_set_handler (NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,