lib: improve test coverage

Add a bunch of tests
This commit is contained in:
Dirk-Jan C. Binnema
2022-06-02 21:02:11 +03:00
parent 63521300a3
commit 13f0e24241
12 changed files with 275 additions and 54 deletions

View File

@ -278,6 +278,77 @@ test_determine_target_ok(void)
}
static void
test_determine_target_fail(void)
{
struct TestCase {
std::string old_path;
std::string root_maildir;
std::string target_maildir;
Flags new_flags;
bool new_name;
std::string expected;
};
const std::vector<TestCase> testcases = {
TestCase{ /* fail: no absolute path */
"../foo/Maildir/test/cur/123456:2,FR-not-absolute",
"/home/foo/Maildir",
{},
Flags::Seen | Flags::Passed,
false,
"/home/foo/Maildir/test/cur/123456:2,PS"
},
TestCase{ /* fail: no absolute root */
"/home/foo/Maildir/test/cur/123456:2,FR",
"../foo/Maildir-not-absolute",
{},
Flags::New,
false,
"/home/foo/Maildir/test/new/123456"
},
TestCase{ /* fail: maildir must start with '/' */
"/home/foo/Maildir/test/cur/123456",
"/home/foo/Maildir",
"mymaildirwithoutslash",
Flags::Seen | Flags::Flagged,
false,
"/home/foo/Maildir/test/cur/123456:2,FS"
},
TestCase{ /* fail: path must be below maildir */
"/home/foo/Maildir/test/cur/123456:2,FR",
"/home/bar/Maildir",
"/test2",
Flags::Flagged | Flags::Replied,
false,
"/home/foo/Maildir/test2/cur/123456:2,FR"
},
TestCase{ /* fail: New cannot be combined */
"/home/foo/Maildir/test/new/123456",
"/home/foo/Maildir",
{},
Flags::New | Flags::Replied,
false,
"/home/foo/Maildir/test/cur/123456:2,"
},
};
for (auto&& testcase: testcases) {
const auto res = maildir_determine_target(
testcase.old_path,
testcase.root_maildir,
testcase.target_maildir,
testcase.new_flags,
testcase.new_name);
g_assert_false(!!res);
}
}
static void
test_maildir_get_new_path_01(void)
{
@ -428,6 +499,8 @@ main(int argc, char* argv[])
g_test_add_func("/mu-maildir/mu-maildir-determine-target-ok",
test_determine_target_ok);
g_test_add_func("/mu-maildir/mu-maildir-determine-target-fail",
test_determine_target_fail);
// /* get/set flags */
g_test_add_func("/mu-maildir/mu-maildir-get-new-path-01", test_maildir_get_new_path_01);

View File

@ -139,6 +139,12 @@ goto * instructions[pOp->opcode];
assert_valid_result(docid);
g_assert_cmpuint(store->size(),==, 1);
/* ensure 'update' dtrt, i.e., nothing. */
const auto docid2 = store->update_message(*message, *docid);
assert_valid_result(docid2);
g_assert_cmpuint(store->size(),==, 1);
g_assert_cmpuint(*docid,==,*docid2);
auto msg2{store->find_message(*docid)};
g_assert_true(!!msg2);
assert_equal(message->path(), msg2->path());
@ -228,6 +234,11 @@ World!
// for (auto&& term = msg2->document().xapian_document().termlist_begin();
// term != msg2->document().xapian_document().termlist_end(); ++term)
// g_message(">>> %s", (*term).c_str());
const auto stats{store->statistics()};
g_assert_cmpuint(stats.size,==,store->size());
g_assert_cmpuint(stats.last_index,==,0);
g_assert_cmpuint(stats.last_change,>=,::time({}));
}
@ -319,6 +330,23 @@ Yes, that would be excellent.
}
static void
test_store_fail()
{
{
const auto store = Store::make("/root/non-existent-path/12345");
g_assert_false(!!store);
}
{
const auto store = Store::make_new("/../../root/non-existent-path/12345",
"/../../root/non-existent-path/54321",
{}, {});
g_assert_false(!!store);
}
}
int
main(int argc, char* argv[])
@ -331,8 +359,8 @@ main(int argc, char* argv[])
test_message_mailing_list);
g_test_add_func("/store/message/attachments",
test_message_attachments);
g_test_add_func("/store/index/move",
test_index_move);
g_test_add_func("/store/index/move", test_index_move);
g_test_add_func("/store/index/fail", test_store_fail);
if (!g_test_verbose())
g_log_set_handler(