lib: xapian-db/config: more tests

...and xapian-db gets a small API update, update store as well.
This commit is contained in:
Dirk-Jan C. Binnema
2023-09-23 09:27:46 +03:00
parent 11003000e8
commit 655a6b0499
5 changed files with 121 additions and 31 deletions

View File

@ -90,8 +90,10 @@ make_db(const std::string& db_path, Flavor flavor)
return Xapian::WritableDatabase(db_path, Xapian::DB_OPEN);
case Flavor::CreateOverwrite:
return Xapian::WritableDatabase(db_path, Xapian::DB_CREATE_OR_OVERWRITE);
/* LCOV_EXCL_START*/
default:
throw std::logic_error("unknown flavor");
/* LCOV_EXCL_STOP*/
}
}
@ -104,3 +106,43 @@ XapianDb::XapianDb(const std::string& db_path, Flavor flavor) :
mu_debug("created {} / {}", flavor, *this);
}
#ifdef BUILD_TESTS
/*
* Tests.
*
*/
#include "utils/mu-test-utils.hh"
#include "config.h"
#include "mu-store.hh"
static void
test_errors()
{
allow_warnings();
TempDir tdir;
auto store = Store::make_new(tdir.path(), MU_TESTMAILDIR2);
assert_valid_result(store);
g_assert_true(store->empty());
XapianDb xdb(tdir.path(), Flavor::ReadOnly);
g_assert_true(xdb.read_only());
g_assert_false(!!xdb.delete_document("Boo"));
}
int
main(int argc, char* argv[])
{
mu_test_init(&argc, &argv);
g_test_add_func("/xapian-db/errors", test_errors);
return g_test_run();
}
#endif /*BUILD_TESTS*/