summaryrefslogtreecommitdiff
path: root/lib/tests/test-mu-store-query.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test-mu-store-query.cc')
-rw-r--r--lib/tests/test-mu-store-query.cc90
1 files changed, 71 insertions, 19 deletions
diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc
index b308144..c22cc59 100644
--- a/lib/tests/test-mu-store-query.cc
+++ b/lib/tests/test-mu-store-query.cc
@@ -18,6 +18,7 @@
*/
+#include "utils/mu-result.hh"
#include <array>
#include <thread>
#include <string>
@@ -26,6 +27,7 @@
#include <unordered_map>
#include <mu-store.hh>
+#include <mu-maildir.hh>
#include <utils/mu-utils.hh>
#include <utils/mu-test-utils.hh>
#include <message/mu-message.hh>
@@ -523,7 +525,7 @@ Saludos,
static void
-test_duplicate_refresh()
+test_duplicate_refresh_real(bool rename)
{
g_test_bug("2327");
@@ -539,22 +541,51 @@ Boo!
)"},
}};
+ /* create maildir with message */
TempDir tdir;
auto store{make_test_store(tdir.path(), test_msgs, {})};
g_debug("%s", store.properties().root_maildir.c_str());
-
+ /* ensure we have a proper maildir, with new/, cur/ */
+ auto mres = maildir_mkdir(store.properties().root_maildir + "/inbox");
+ assert_valid_result(mres);
g_assert_cmpuint(store.size(), ==, 1U);
- {
- auto qr = store.run_query("Helsinki", Field::Id::Date, QueryFlags::None);
- g_assert_true(!!qr);
- g_assert_cmpuint(qr->size(), ==, 1);
-
- // /* mark as read */
- auto msg = store.move_message(qr->begin().doc_id(),
- Nothing, Flags::Seen);
- g_assert_cmpuint(store.size(), ==, 1);
- }
+ /*
+ * find the one msg with a query
+ */
+ auto qr = store.run_query("Helsinki", Field::Id::Date, QueryFlags::None);
+ g_assert_true(!!qr);
+ g_assert_cmpuint(qr->size(), ==, 1);
+ const auto old_path = qr->begin().path().value();
+ const auto old_docid = qr->begin().doc_id();
+ assert_equal(qr->begin().message()->path(), old_path);
+ g_assert_true(::access(old_path.c_str(), F_OK) == 0);
+
+ /*
+ * mark as read, i.e. move to cur/; ensure it really moved.
+ */
+ auto moved_msg = store.move_message(old_docid, Nothing, Flags::Seen, rename);
+ assert_valid_result(moved_msg);
+ const auto new_path = moved_msg->path();
+ if (!rename)
+ assert_equal(new_path, store.properties().root_maildir + "/inbox/cur/msg:2,S");
+ g_assert_cmpuint(store.size(), ==, 1);
+ g_assert_false(::access(old_path.c_str(), F_OK) == 0);
+ g_assert_true(::access(new_path.c_str(), F_OK) == 0);
+
+ /* also ensure thath the cached sexp for the message has been updated;
+ * that's what mu4e uses */
+ const auto moved_sexp{moved_msg->to_sexp().to_sexp_string()};
+ /* clumsy */
+ g_assert_true(moved_sexp.find(new_path) != std::string::npos);
+
+ /*
+ * find new message with query, ensure it's really that new one.
+ */
+ auto qr2 = store.run_query("Helsinki", Field::Id::Date, QueryFlags::None);
+ g_assert_true(!!qr2);
+ g_assert_cmpuint(qr2->size(), ==, 1);
+ assert_equal(qr2->begin().path().value(), new_path);
/* index the messages */
auto res = store.indexer().start({});
@@ -563,16 +594,35 @@ Boo!
using namespace std::chrono_literals;
std::this_thread::sleep_for(100ms);
}
-
- /* should be only one */
g_assert_cmpuint(store.size(), ==, 1);
- {
- auto qr = store.run_query("Helsinki", Field::Id::Date, QueryFlags::None);
- g_assert_true(!!qr);
- g_assert_cmpuint(qr->size(), ==, 1);
- }
+
+ /*
+ * ensure query still has the right results
+ */
+ auto qr3 = store.run_query("Helsinki", Field::Id::Date, QueryFlags::None);
+ g_assert_true(!!qr3);
+ g_assert_cmpuint(qr3->size(), ==, 1);
+ const auto path3{qr3->begin().path().value()};
+ assert_equal(path3, new_path);
+ assert_equal(qr3->begin().message()->path(), new_path);
+ g_assert_true(::access(path3.c_str(), F_OK) == 0);
+}
+
+
+static void
+test_duplicate_refresh()
+{
+ test_duplicate_refresh_real(false/*no rename*/);
}
+
+static void
+test_duplicate_refresh_rename()
+{
+ test_duplicate_refresh_real(true/*rename*/);
+}
+
+
int
main(int argc, char* argv[])
{
@@ -591,6 +641,8 @@ main(int argc, char* argv[])
test_body_matricula);
g_test_add_func("/store/query/duplicate-refresh",
test_duplicate_refresh);
+ g_test_add_func("/store/query/duplicate-refresh-rename",
+ test_duplicate_refresh_rename);
return g_test_run();
}