mirror of https://github.com/djcb/mu.git
tests: threads: Test if 1st child message promotes its thread
This commit is contained in:
parent
80a484dc3f
commit
22927a7dcf
|
@ -0,0 +1,7 @@
|
||||||
|
From: testfrom@example.com
|
||||||
|
To: testto@example.com
|
||||||
|
Subject: A
|
||||||
|
Message-Id: <A@msg.id>
|
||||||
|
Date: Sat, 17 May 2014 10:00:00 +0000
|
||||||
|
|
||||||
|
A
|
|
@ -0,0 +1,7 @@
|
||||||
|
From: testfrom@example.com
|
||||||
|
To: testto@example.com
|
||||||
|
Subject: B
|
||||||
|
Message-Id: <B@msg.id>
|
||||||
|
Date: Sat, 17 May 2014 10:00:00 +0000
|
||||||
|
|
||||||
|
B
|
|
@ -0,0 +1,7 @@
|
||||||
|
From: testfrom@example.com
|
||||||
|
To: testto@example.com
|
||||||
|
Subject: C
|
||||||
|
Message-Id: <C@msg.id>
|
||||||
|
Date: Sat, 17 May 2014 10:00:00 +0000
|
||||||
|
|
||||||
|
C
|
|
@ -0,0 +1,9 @@
|
||||||
|
From: testfrom@example.com
|
||||||
|
To: testto@example.com
|
||||||
|
Subject: D
|
||||||
|
Message-Id: <D@msg.id>
|
||||||
|
References: <B@msg.id>
|
||||||
|
In-reply-to: <B@msg.id>
|
||||||
|
Date: Sat, 17 May 2014 10:00:00 +0000
|
||||||
|
|
||||||
|
D
|
|
@ -117,7 +117,8 @@ fill_database (const char *testdir)
|
||||||
|
|
||||||
/* note: this also *moves the iter* */
|
/* note: this also *moves the iter* */
|
||||||
static MuMsgIter*
|
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;
|
MuQuery *mquery;
|
||||||
MuStore *store;
|
MuStore *store;
|
||||||
|
@ -130,14 +131,21 @@ run_and_get_iter (const char *xpath, const char *query)
|
||||||
mu_store_unref (store);
|
mu_store_unref (store);
|
||||||
g_assert (query);
|
g_assert (query);
|
||||||
|
|
||||||
iter = mu_query_run (mquery, query, MU_MSG_FIELD_ID_DATE,
|
flags |= MU_QUERY_FLAG_THREADS;
|
||||||
-1, MU_QUERY_FLAG_THREADS, NULL);
|
iter = mu_query_run (mquery, query, sort_field, -1, flags, NULL);
|
||||||
mu_query_destroy (mquery);
|
mu_query_destroy (mquery);
|
||||||
g_assert (iter);
|
g_assert (iter);
|
||||||
|
|
||||||
return 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
|
static void
|
||||||
test_mu_threads_01 (void)
|
test_mu_threads_01 (void)
|
||||||
{
|
{
|
||||||
|
@ -216,6 +224,76 @@ test_mu_threads_rogue (void)
|
||||||
mu_msg_iter_destroy (iter);
|
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
|
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-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-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_set_handler (NULL,
|
||||||
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,
|
||||||
|
|
Loading…
Reference in New Issue