unit-tests: modernize
Use TempDir, join_paths etc.
This commit is contained in:
@ -28,130 +28,91 @@
|
|||||||
|
|
||||||
#include "utils/mu-test-utils.hh"
|
#include "utils/mu-test-utils.hh"
|
||||||
#include "mu-maildir.hh"
|
#include "mu-maildir.hh"
|
||||||
|
#include "utils/mu-utils.hh"
|
||||||
|
#include "utils/mu-utils-file.hh"
|
||||||
#include "utils/mu-result.hh"
|
#include "utils/mu-result.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_maildir_mkdir_01(void)
|
test_maildir_mkdir_01()
|
||||||
{
|
{
|
||||||
int i;
|
TempDir temp_dir;
|
||||||
gchar * tmpdir, *mdir, *tmp;
|
auto mdir = join_paths(temp_dir.path(), "cuux");
|
||||||
const gchar* subs[] = {"tmp", "cur", "new"};
|
auto res{maildir_mkdir(mdir, 0755, false/*!noindex*/)};
|
||||||
|
assert_valid_result(res);
|
||||||
|
|
||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
for (auto sub : {"tmp", "cur", "new"}) {
|
||||||
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
auto subpath = join_paths(mdir, sub);
|
||||||
|
g_assert_cmpuint(g_access(subpath.c_str(), R_OK), ==, 0);
|
||||||
g_assert_true(!!maildir_mkdir(mdir, 0755, FALSE));
|
g_assert_cmpuint(g_access(subpath.c_str(), W_OK), ==, 0);
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
||||||
gchar* dir;
|
|
||||||
|
|
||||||
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
||||||
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
|
||||||
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
||||||
g_free(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
auto noindex = join_paths(mdir, ".noindex");
|
||||||
g_assert_cmpuint(g_access(tmp, F_OK), !=, 0);
|
g_assert_cmpuint(g_access(noindex.c_str(), F_OK), !=, 0);
|
||||||
|
|
||||||
g_free(tmp);
|
|
||||||
g_free(tmpdir);
|
|
||||||
g_free(mdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_maildir_mkdir_02(void)
|
test_maildir_mkdir_02()
|
||||||
{
|
{
|
||||||
int i;
|
TempDir temp_dir;
|
||||||
gchar * tmpdir, *mdir, *tmp;
|
auto mdir = join_paths(temp_dir.path(), "cuux");
|
||||||
const gchar* subs[] = {"tmp", "cur", "new"};
|
auto res{maildir_mkdir(mdir, 0755, true/*noindex*/)};
|
||||||
|
assert_valid_result(res);
|
||||||
|
|
||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
for (auto sub : {"tmp", "cur", "new"}) {
|
||||||
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
auto subpath = join_paths(mdir, sub);
|
||||||
|
g_assert_cmpuint(g_access(subpath.c_str(), R_OK), ==, 0);
|
||||||
g_assert_true(!!maildir_mkdir(mdir, 0755, TRUE));
|
g_assert_cmpuint(g_access(subpath.c_str(), W_OK), ==, 0);
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
||||||
gchar* dir;
|
|
||||||
|
|
||||||
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
||||||
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
|
||||||
|
|
||||||
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
||||||
g_free(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
auto noindex = join_paths(mdir, ".noindex");
|
||||||
g_assert_cmpuint(g_access(tmp, F_OK), ==, 0);
|
g_assert_cmpuint(g_access(noindex.c_str(), F_OK), ==, 0);
|
||||||
|
|
||||||
g_free(tmp);
|
|
||||||
g_free(tmpdir);
|
|
||||||
g_free(mdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_maildir_mkdir_03(void)
|
test_maildir_mkdir_03()
|
||||||
{
|
{
|
||||||
int i;
|
TempDir temp_dir;
|
||||||
gchar * tmpdir, *mdir, *tmp;
|
auto mdir = join_paths(temp_dir.path(), "cuux");
|
||||||
const gchar* subs[] = {"tmp", "cur", "new"};
|
|
||||||
|
|
||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
// create part already
|
||||||
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
auto curdir = join_paths(mdir, "cur");
|
||||||
|
g_assert_cmpuint(g_mkdir_with_parents(curdir.c_str(), 0755), ==, 0);
|
||||||
|
|
||||||
/* create part of the structure already... */
|
auto res{maildir_mkdir(mdir, 0755, false/*!noindex*/)};
|
||||||
{
|
assert_valid_result(res);
|
||||||
gchar* dir;
|
|
||||||
dir = g_strdup_printf("%s%ccur", mdir, G_DIR_SEPARATOR);
|
// should still work.
|
||||||
g_assert_cmpuint(g_mkdir_with_parents(dir, 0755), ==, 0);
|
for (auto sub : {"tmp", "cur", "new"}) {
|
||||||
g_free(dir);
|
auto subpath = join_paths(mdir, sub);
|
||||||
|
g_assert_cmpuint(g_access(subpath.c_str(), R_OK), ==, 0);
|
||||||
|
g_assert_cmpuint(g_access(subpath.c_str(), W_OK), ==, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this should still work */
|
auto noindex = join_paths(mdir, ".noindex");
|
||||||
g_assert_true(!!maildir_mkdir(mdir, 0755, FALSE));
|
g_assert_cmpuint(g_access(noindex.c_str(), F_OK), !=, 0);
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(subs); ++i) {
|
|
||||||
gchar* dir;
|
|
||||||
|
|
||||||
dir = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, subs[i]);
|
|
||||||
g_assert_cmpuint(g_access(dir, R_OK), ==, 0);
|
|
||||||
g_assert_cmpuint(g_access(dir, W_OK), ==, 0);
|
|
||||||
g_free(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = g_strdup_printf("%s%c%s", mdir, G_DIR_SEPARATOR, ".noindex");
|
|
||||||
g_assert_cmpuint(g_access(tmp, F_OK), !=, 0);
|
|
||||||
|
|
||||||
g_free(tmp);
|
|
||||||
g_free(tmpdir);
|
|
||||||
g_free(mdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_maildir_mkdir_04(void)
|
test_maildir_mkdir_04()
|
||||||
{
|
{
|
||||||
gchar *tmpdir, *mdir;
|
if (geteuid() == 0) {
|
||||||
|
g_test_skip("not useful when run as root");
|
||||||
tmpdir = test_mu_common_get_random_tmpdir();
|
return;
|
||||||
mdir = g_strdup_printf("%s%c%s", tmpdir, G_DIR_SEPARATOR, "cuux");
|
|
||||||
|
|
||||||
/* create part of the structure already... */
|
|
||||||
{
|
|
||||||
gchar* dir;
|
|
||||||
g_assert_cmpuint(g_mkdir_with_parents(mdir, 0755), ==, 0);
|
|
||||||
dir = g_strdup_printf("%s%ccur", mdir, G_DIR_SEPARATOR);
|
|
||||||
g_assert_cmpuint(g_mkdir_with_parents(dir, 0000), ==, 0);
|
|
||||||
g_free(dir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TempDir temp_dir;
|
||||||
|
auto mdir = join_paths(temp_dir.path(), "cuux");
|
||||||
|
g_assert_cmpuint(g_mkdir_with_parents(mdir.c_str(), 0755), ==, 0);
|
||||||
|
|
||||||
|
auto curdir = join_paths(mdir, "cur");
|
||||||
|
g_assert_cmpuint(g_mkdir_with_parents(curdir.c_str(), 0000), ==, 0);
|
||||||
|
|
||||||
/* this should fail now, because cur is not read/writable */
|
/* this should fail now, because cur is not read/writable */
|
||||||
if (geteuid() != 0)
|
auto res = maildir_mkdir(mdir, 0755, false);
|
||||||
g_assert_false(!!maildir_mkdir(mdir, 0755, false));
|
g_assert_false(!!res);
|
||||||
|
|
||||||
g_free(tmpdir);
|
|
||||||
g_free(mdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
|||||||
@ -37,29 +37,27 @@ static void
|
|||||||
test_query()
|
test_query()
|
||||||
{
|
{
|
||||||
allow_warnings();
|
allow_warnings();
|
||||||
char* tdir;
|
TempDir temp_dir;
|
||||||
|
|
||||||
tdir = test_mu_common_get_random_tmpdir();
|
auto store = Store::make_new(temp_dir.path(), std::string{MU_TESTMAILDIR});
|
||||||
auto store = Store::make_new(tdir, std::string{MU_TESTMAILDIR});
|
|
||||||
assert_valid_result(store);
|
assert_valid_result(store);
|
||||||
g_free(tdir);
|
|
||||||
|
|
||||||
auto&& idx{store->indexer()};
|
auto&& idx{store->indexer()};
|
||||||
|
|
||||||
g_assert_true(idx.start(Indexer::Config{}));
|
g_assert_true(idx.start(Indexer::Config{}));
|
||||||
while (idx.is_running()) {
|
while (idx.is_running()) {
|
||||||
sleep(1);
|
g_usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dump_matches = [](const QueryResults& res) {
|
auto dump_matches = [](const QueryResults& res) {
|
||||||
size_t n{};
|
size_t n{};
|
||||||
for (auto&& item : res) {
|
for (auto&& item : res) {
|
||||||
std::cout << item.query_match() << '\n';
|
if (g_test_verbose()) {
|
||||||
if (g_test_verbose())
|
std::cout << item.query_match() << '\n';
|
||||||
g_debug("%02zu %s %s",
|
mu_debug("{:02d} {} {}",
|
||||||
++n,
|
++n,
|
||||||
item.path().value_or("<none>").c_str(),
|
item.path().value_or("<none>"),
|
||||||
item.message_id().value_or("<none>").c_str());
|
item.message_id().value_or("<none>"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,8 +82,8 @@ test_query()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char* argv[])
|
main(int argc, char* argv[]) try {
|
||||||
try {
|
|
||||||
mu_test_init(&argc, &argv);
|
mu_test_init(&argc, &argv);
|
||||||
|
|
||||||
g_test_add_func("/query", test_query);
|
g_test_add_func("/query", test_query);
|
||||||
|
|||||||
@ -189,14 +189,16 @@ Logger::~Logger()
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#include "mu-test-utils.hh"
|
#include "mu-test-utils.hh"
|
||||||
|
#include "mu-utils-file.hh"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_logger_threads(void)
|
test_logger_threads(void)
|
||||||
{
|
{
|
||||||
const auto testpath{test_random_tmpdir() + "/test.log"};
|
TempDir temp_dir;
|
||||||
|
const auto testpath{join_paths(temp_dir.path(), "test.log")};
|
||||||
mu_message("log-file: {}", testpath);
|
mu_message("log-file: {}", testpath);
|
||||||
|
|
||||||
auto logger = Logger::make(testpath.c_str(), Logger::Options::File | Logger::Options::Debug);
|
auto logger = Logger::make(testpath, Logger::Options::File | Logger::Options::Debug);
|
||||||
assert_valid_result(logger);
|
assert_valid_result(logger);
|
||||||
|
|
||||||
const auto thread_num = 16;
|
const auto thread_num = 16;
|
||||||
|
|||||||
@ -34,25 +34,15 @@
|
|||||||
#include "utils/mu-utils-file.hh"
|
#include "utils/mu-utils-file.hh"
|
||||||
#include "utils/mu-error.hh"
|
#include "utils/mu-error.hh"
|
||||||
|
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
|
|
||||||
std::string
|
bool
|
||||||
Mu::test_random_tmpdir()
|
Mu::mu_test_mu_hacker()
|
||||||
{
|
{
|
||||||
auto&& dir = mu_format("{}{}mu-test-{}{}test-{:x}",
|
return !!g_getenv("MU_HACKER");
|
||||||
g_get_tmp_dir(),
|
|
||||||
G_DIR_SEPARATOR,
|
|
||||||
getuid(),
|
|
||||||
G_DIR_SEPARATOR,
|
|
||||||
::random() * getpid() * ::time({}));
|
|
||||||
|
|
||||||
auto res = g_mkdir_with_parents(dir.c_str(), 0700);
|
|
||||||
g_assert(res != -1);
|
|
||||||
|
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
Mu::set_tz(const char* tz)
|
Mu::set_tz(const char* tz)
|
||||||
{
|
{
|
||||||
@ -92,11 +82,11 @@ black_hole(void)
|
|||||||
void
|
void
|
||||||
Mu::mu_test_init(int *argc, char ***argv)
|
Mu::mu_test_init(int *argc, char ***argv)
|
||||||
{
|
{
|
||||||
const auto tmpdir{test_random_tmpdir()};
|
TempDir temp_dir;
|
||||||
|
|
||||||
g_unsetenv("XAPIAN_CJK_NGRAM");
|
g_unsetenv("XAPIAN_CJK_NGRAM");
|
||||||
g_setenv("MU_TEST", "yes", TRUE);
|
g_setenv("MU_TEST", "yes", TRUE);
|
||||||
g_setenv("XDG_CACHE_HOME", tmpdir.c_str(), TRUE);
|
g_setenv("XDG_CACHE_HOME", temp_dir.path().c_str(), TRUE);
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
|||||||
@ -27,17 +27,6 @@
|
|||||||
|
|
||||||
namespace Mu {
|
namespace Mu {
|
||||||
|
|
||||||
/**
|
|
||||||
* get a dir name for a random temporary directory to do tests
|
|
||||||
*
|
|
||||||
* @return a random dir name
|
|
||||||
*/
|
|
||||||
std::string test_random_tmpdir(void);
|
|
||||||
|
|
||||||
inline gchar* test_mu_common_get_random_tmpdir() {
|
|
||||||
return g_strdup(test_random_tmpdir().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mu wrapper for g_test_init. Sets environment variable MU_TEST to 1.
|
* mu wrapper for g_test_init. Sets environment variable MU_TEST to 1.
|
||||||
*
|
*
|
||||||
@ -46,6 +35,14 @@ inline gchar* test_mu_common_get_random_tmpdir() {
|
|||||||
*/
|
*/
|
||||||
void mu_test_init(int *argc, char ***argv);
|
void mu_test_init(int *argc, char ***argv);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we running in a MU_HACKER environment?
|
||||||
|
*
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
bool mu_test_mu_hacker();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the timezone
|
* set the timezone
|
||||||
*
|
*
|
||||||
@ -62,6 +59,7 @@ const char* set_tz(const char* tz);
|
|||||||
*/
|
*/
|
||||||
bool set_en_us_utf8_locale();
|
bool set_en_us_utf8_locale();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For unit tests, assert two std::string's are equal.
|
* For unit tests, assert two std::string's are equal.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
#include "mu-query.hh"
|
#include "mu-query.hh"
|
||||||
#include "utils/mu-result.hh"
|
#include "utils/mu-result.hh"
|
||||||
#include "utils/mu-utils.hh"
|
#include "utils/mu-utils.hh"
|
||||||
|
#include "utils/mu-utils-file.hh"
|
||||||
#include "mu-store.hh"
|
#include "mu-store.hh"
|
||||||
|
|
||||||
using namespace Mu;
|
using namespace Mu;
|
||||||
@ -42,13 +43,10 @@ static std::string DB_PATH1;
|
|||||||
static std::string DB_PATH2;
|
static std::string DB_PATH2;
|
||||||
|
|
||||||
static std::string
|
static std::string
|
||||||
make_database(const std::string& testdir)
|
make_database(const std::string& dbdir, const std::string& testdir)
|
||||||
{
|
{
|
||||||
auto&& tmpdir{test_random_tmpdir()};
|
|
||||||
|
|
||||||
/* use the env var rather than `--muhome` */
|
/* use the env var rather than `--muhome` */
|
||||||
|
g_setenv("MUHOME", dbdir.c_str(), 1);
|
||||||
g_setenv("MUHOME", tmpdir.c_str(), 1);
|
|
||||||
const auto cmdline{mu_format(
|
const auto cmdline{mu_format(
|
||||||
"/bin/sh -c '"
|
"/bin/sh -c '"
|
||||||
"{} --quiet init --maildir={} ; "
|
"{} --quiet init --maildir={} ; "
|
||||||
@ -59,8 +57,7 @@ make_database(const std::string& testdir)
|
|||||||
mu_printerrln("\n{}", cmdline);
|
mu_printerrln("\n{}", cmdline);
|
||||||
|
|
||||||
g_assert(g_spawn_command_line_sync(cmdline.c_str(), NULL, NULL, NULL, NULL));
|
g_assert(g_spawn_command_line_sync(cmdline.c_str(), NULL, NULL, NULL, NULL));
|
||||||
auto xpath = mu_format("{}{}{}",
|
auto xpath = join_paths(dbdir, "xapian");
|
||||||
tmpdir, G_DIR_SEPARATOR, "xapian");
|
|
||||||
/* ensure MUHOME worked */
|
/* ensure MUHOME worked */
|
||||||
g_assert_cmpuint(::access(xpath.c_str(), F_OK), ==, 0);
|
g_assert_cmpuint(::access(xpath.c_str(), F_OK), ==, 0);
|
||||||
|
|
||||||
@ -104,7 +101,6 @@ run_and_count_matches(const std::string& xpath,
|
|||||||
g_assert_true(!!qres);
|
g_assert_true(!!qres);
|
||||||
assert_no_dups(*qres);
|
assert_no_dups(*qres);
|
||||||
|
|
||||||
|
|
||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
mu_println("'{}' => {}\n", expr, qres->size());
|
mu_println("'{}' => {}\n", expr, qres->size());
|
||||||
|
|
||||||
@ -143,8 +139,7 @@ test_mu_query_01(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -186,8 +181,7 @@ test_mu_query_03(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -213,8 +207,7 @@ test_mu_query_04(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -231,8 +224,7 @@ test_mu_query_logic(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -272,8 +264,7 @@ test_mu_query_accented_chars_02(void)
|
|||||||
mu_warning("query '{}'; expected {} but got {}",
|
mu_warning("query '{}'; expected {} but got {}",
|
||||||
queries[i].query, queries[i].count, count);
|
queries[i].query, queries[i].count, count);
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,8 +286,7 @@ test_mu_query_accented_chars_fraiche(void)
|
|||||||
mu_println("{}", queries[i].query);
|
mu_println("{}", queries[i].query);
|
||||||
|
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,8 +305,7 @@ test_mu_query_wildcards(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -338,14 +327,13 @@ test_mu_query_dates_helsinki(void)
|
|||||||
{"date:200808110801..now", 7}};
|
{"date:200808110801..now", 7}};
|
||||||
|
|
||||||
old_tz = set_tz(hki);
|
old_tz = set_tz(hki);
|
||||||
|
TempDir tdir;
|
||||||
const auto xpath{make_database(MU_TESTMAILDIR)};
|
const auto xpath{make_database(tdir.path(), MU_TESTMAILDIR)};
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
|
|
||||||
set_tz(old_tz);
|
set_tz(old_tz);
|
||||||
}
|
}
|
||||||
@ -368,13 +356,13 @@ test_mu_query_dates_sydney(void)
|
|||||||
{"date:200808110801..now", 7}};
|
{"date:200808110801..now", 7}};
|
||||||
old_tz = set_tz(syd);
|
old_tz = set_tz(syd);
|
||||||
|
|
||||||
const auto xpath{make_database(MU_TESTMAILDIR)};
|
TempDir tdir;
|
||||||
|
const auto xpath{make_database(tdir.path(), MU_TESTMAILDIR)};
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
set_tz(old_tz);
|
set_tz(old_tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,14 +387,14 @@ test_mu_query_dates_la(void)
|
|||||||
{"date:200808110801..now", 6}};
|
{"date:200808110801..now", 6}};
|
||||||
old_tz = set_tz(la);
|
old_tz = set_tz(la);
|
||||||
|
|
||||||
const auto xpath = make_database(MU_TESTMAILDIR);
|
TempDir tdir;
|
||||||
|
const auto xpath{make_database(tdir.path(), MU_TESTMAILDIR)};
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
/* g_print ("%s\n", queries[i].query); */
|
/* g_print ("%s\n", queries[i].query); */
|
||||||
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(xpath, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_tz(old_tz);
|
set_tz(old_tz);
|
||||||
@ -427,8 +415,7 @@ test_mu_query_sizes(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -441,8 +428,7 @@ test_mu_query_attach(void)
|
|||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
mu_println("query: {}", queries[i].query);
|
mu_println("query: {}", queries[i].query);
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,8 +450,7 @@ test_mu_query_msgid(void)
|
|||||||
if (g_test_verbose())
|
if (g_test_verbose())
|
||||||
mu_println("query: {}", queries[i].query);
|
mu_println("query: {}", queries[i].query);
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,8 +473,7 @@ test_mu_query_tags(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -504,8 +488,7 @@ test_mu_query_wom_bat(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -537,8 +520,7 @@ test_mu_query_multi_to_cc(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i)
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH1, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -554,8 +536,7 @@ test_mu_query_tags_02(void)
|
|||||||
|
|
||||||
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(queries); ++i) {
|
||||||
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
g_assert_cmpuint(run_and_count_matches(DB_PATH2, queries[i].query),
|
||||||
==,
|
==, queries[i].count);
|
||||||
queries[i].count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,27 +548,27 @@ test_mu_query_tags_02(void)
|
|||||||
static void
|
static void
|
||||||
test_mu_query_threads_compilation_error(void)
|
test_mu_query_threads_compilation_error(void)
|
||||||
{
|
{
|
||||||
const auto xpath = make_database(MU_TESTMAILDIR);
|
TempDir tdir;
|
||||||
|
const auto xpath = make_database(tdir.path(), MU_TESTMAILDIR);
|
||||||
|
|
||||||
g_assert_cmpuint(run_and_count_matches(xpath, "msgid:uwsireh25.fsf@one.dot.net"), ==, 1);
|
g_assert_cmpuint(run_and_count_matches(xpath, "msgid:uwsireh25.fsf@one.dot.net"), ==, 1);
|
||||||
|
|
||||||
g_assert_cmpuint(run_and_count_matches(xpath,
|
g_assert_cmpuint(run_and_count_matches(xpath,
|
||||||
"msgid:uwsireh25.fsf@one.dot.net",
|
"msgid:uwsireh25.fsf@one.dot.net",
|
||||||
QueryFlags::IncludeRelated),
|
QueryFlags::IncludeRelated), ==, 3);
|
||||||
==,
|
|
||||||
3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char* argv[])
|
main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int rv;
|
TempDir td1;
|
||||||
|
TempDir td2;
|
||||||
|
|
||||||
mu_test_init(&argc, &argv);
|
mu_test_init(&argc, &argv);
|
||||||
DB_PATH1 = make_database(MU_TESTMAILDIR);
|
DB_PATH1 = make_database(td1.path(), MU_TESTMAILDIR);
|
||||||
g_assert_false(DB_PATH1.empty());
|
g_assert_false(DB_PATH1.empty());
|
||||||
|
|
||||||
DB_PATH2 = make_database(MU_TESTMAILDIR2);
|
DB_PATH2 = make_database(td2.path(), MU_TESTMAILDIR2);
|
||||||
g_assert_false(DB_PATH2.empty());
|
g_assert_false(DB_PATH2.empty());
|
||||||
|
|
||||||
g_test_add_func("/mu-query/test-mu-query-01", test_mu_query_01);
|
g_test_add_func("/mu-query/test-mu-query-01", test_mu_query_01);
|
||||||
@ -624,7 +605,5 @@ main(int argc, char* argv[])
|
|||||||
g_test_add_func("/mu-query/test-mu-query-threads-compilation-error",
|
g_test_add_func("/mu-query/test-mu-query-threads-compilation-error",
|
||||||
test_mu_query_threads_compilation_error);
|
test_mu_query_threads_compilation_error);
|
||||||
|
|
||||||
rv = g_test_run();
|
return g_test_run();
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user