summaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/bench-indexer.cc2
-rw-r--r--lib/tests/meson.build14
-rw-r--r--lib/tests/test-mu-common.cc89
-rw-r--r--lib/tests/test-mu-common.hh58
-rw-r--r--lib/tests/test-mu-container.cc2
-rw-r--r--lib/tests/test-mu-maildir.cc2
-rw-r--r--lib/tests/test-mu-msg-fields.cc2
-rw-r--r--lib/tests/test-mu-msg.cc26
-rw-r--r--lib/tests/test-mu-store-query.cc14
-rw-r--r--lib/tests/test-mu-store.cc13
-rw-r--r--lib/tests/test-parser.cc2
-rw-r--r--lib/tests/test-query.cc14
12 files changed, 27 insertions, 211 deletions
diff --git a/lib/tests/bench-indexer.cc b/lib/tests/bench-indexer.cc
index c857847..b83bd90 100644
--- a/lib/tests/bench-indexer.cc
+++ b/lib/tests/bench-indexer.cc
@@ -28,7 +28,7 @@
#include <mu-store.hh>
#include "mu-maildir.hh"
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
using namespace Mu;
diff --git a/lib/tests/meson.build b/lib/tests/meson.build
index ab233f2..17a9b72 100644
--- a/lib/tests/meson.build
+++ b/lib/tests/meson.build
@@ -21,40 +21,40 @@ test('test-maildir',
executable('test-maildir',
'test-mu-maildir.cc',
install: false,
- dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, lib_mu_dep]))
test('test-msg',
executable('test-msg',
'test-mu-msg.cc',
install: false,
- dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, lib_mu_dep]))
test('test-store',
executable('test-store',
'test-mu-store.cc',
install: false,
- dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, lib_mu_dep]))
test('test-query',
executable('test-query',
'test-query.cc',
install: false,
- dependencies: [glib_dep, gmime_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, gmime_dep, lib_mu_dep]))
test('test-tokenizer',
executable('test-tokenizer',
'test-tokenizer.cc',
install: false,
- dependencies: [glib_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, lib_mu_dep]))
test('test-parser',
executable('test-parser',
'test-parser.cc',
install: false,
- dependencies: [glib_dep, gmime_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, gmime_dep, lib_mu_dep]))
test('test-store-query',
executable('test-store-query',
'test-mu-store-query.cc',
install: false,
- dependencies: [glib_dep, gmime_dep, lib_mu_dep, lib_test_mu_common_dep]))
+ dependencies: [glib_dep, gmime_dep, lib_mu_dep]))
#
# benchmarks
#
diff --git a/lib/tests/test-mu-common.cc b/lib/tests/test-mu-common.cc
deleted file mode 100644
index 92d706f..0000000
--- a/lib/tests/test-mu-common.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
-** Copyright (C) 2008-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
-**
-** This program is free software; you can redistribute it and/or modify it
-** under the terms of the GNU General Public License as published by the
-** Free Software Foundation; either version 3, or (at your option) any
-** later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software Foundation,
-** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-**
-*/
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif /*HAVE_CONFIG_H*/
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <langinfo.h>
-#include <locale.h>
-
-#include "test-mu-common.hh"
-
-char*
-test_mu_common_get_random_tmpdir(void)
-{
- char* dir;
- int res;
-
- dir = g_strdup_printf("%s%cmu-test-%d%ctest-%x",
- g_get_tmp_dir(),
- G_DIR_SEPARATOR,
- getuid(),
- G_DIR_SEPARATOR,
- (int)random() * getpid() * (int)time(NULL));
-
- res = g_mkdir_with_parents(dir, 0700);
- g_assert(res != -1);
-
- return dir;
-}
-
-const char*
-set_tz(const char* tz)
-{
- static const char* oldtz;
-
- oldtz = getenv("TZ");
- if (tz)
- setenv("TZ", tz, 1);
- else
- unsetenv("TZ");
-
- tzset();
- return oldtz;
-}
-
-gboolean
-set_en_us_utf8_locale(void)
-{
- setenv("LC_ALL", "en_US.UTF-8", 1);
- setlocale(LC_ALL, "en_US.UTF-8");
-
- if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0) {
- g_print("Note: Unit tests require the en_US.utf8 locale. "
- "Ignoring test cases.\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-void
-black_hole(void)
-{
- return; /* do nothing */
-}
diff --git a/lib/tests/test-mu-common.hh b/lib/tests/test-mu-common.hh
deleted file mode 100644
index cfb427f..0000000
--- a/lib/tests/test-mu-common.hh
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
-**
-** This program is free software; you can redistribute it and/or modify it
-** under the terms of the GNU General Public License as published by the
-** Free Software Foundation; either version 3, or (at your option) any
-** later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software Foundation,
-** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-**
-*/
-
-#ifndef __TEST_MU_COMMON_H__
-#define __TEST_MU_COMMON_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-/**
- * get a dir name for a random temporary directory to do tests
- *
- * @return a random dir name, g_free when it's no longer needed
- */
-char* test_mu_common_get_random_tmpdir(void);
-
-/**
- * set the output to /dev/null
- *
- */
-void black_hole(void);
-
-/**
- * set the timezone
- *
- * @param tz timezone
- *
- * @return the old timezone
- */
-const char* set_tz(const char* tz);
-
-/**
- * switch the locale to en_US.utf8, return TRUE if it succeeds
- *
- * @return TRUE if the switch succeeds, FALSE otherwise
- */
-gboolean set_en_us_utf8_locale(void);
-
-G_END_DECLS
-
-#endif /*__TEST_MU_COMMON_H__*/
diff --git a/lib/tests/test-mu-container.cc b/lib/tests/test-mu-container.cc
index 925de1a..4fb1939 100644
--- a/lib/tests/test-mu-container.cc
+++ b/lib/tests/test-mu-container.cc
@@ -20,7 +20,7 @@
#include "config.h"
#include <glib.h>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "mu-container.hh"
static gboolean
diff --git a/lib/tests/test-mu-maildir.cc b/lib/tests/test-mu-maildir.cc
index 23b36b3..d3713f6 100644
--- a/lib/tests/test-mu-maildir.cc
+++ b/lib/tests/test-mu-maildir.cc
@@ -26,7 +26,7 @@
#include <vector>
#include <fstream>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "mu-maildir.hh"
#include "utils/mu-result.hh"
#include "utils/mu-util.h"
diff --git a/lib/tests/test-mu-msg-fields.cc b/lib/tests/test-mu-msg-fields.cc
index 770689d..5f5df16 100644
--- a/lib/tests/test-mu-msg-fields.cc
+++ b/lib/tests/test-mu-msg-fields.cc
@@ -28,7 +28,7 @@
#include <locale.h>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "mu-message-fields.hh"
static void
diff --git a/lib/tests/test-mu-msg.cc b/lib/tests/test-mu-msg.cc
index cd3ec40..9056e07 100644
--- a/lib/tests/test-mu-msg.cc
+++ b/lib/tests/test-mu-msg.cc
@@ -28,7 +28,7 @@
#include <locale.h>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "utils/mu-result.hh"
#include "utils/mu-utils.hh"
@@ -207,12 +207,8 @@ test_mu_msg_references(void)
"non-exist-04@msg.id"
};
- g_assert_cmpuint(msg.references().size(), == , expected_refs.size());
- size_t n{};
- for (auto&& ref: msg.references()) {
- assert_equal(ref, expected_refs.at(n));
- ++n;
- };
+ assert_equal_seq_str(msg.references(), expected_refs);
+ assert_equal(msg.thread_id(), expected_refs[0]);
}
static void
@@ -230,12 +226,8 @@ test_mu_msg_references_dups(void)
"20051211184308.GB13513@gauss.org"
};
- g_assert_cmpuint(msg.references().size(), == , expected_refs.size());
- size_t n{};
- for (auto&& ref: msg.references()) {
- assert_equal(ref, expected_refs.at(n));
- ++n;
- };
+ assert_equal_seq_str(msg.references(), expected_refs);
+ assert_equal(msg.thread_id(), expected_refs[0]);
}
static void
@@ -258,12 +250,8 @@ test_mu_msg_references_many(void)
"8ioh48-8mu.ln1@leafnode-msgid.gclare.org.uk"
};
- g_assert_cmpuint(msg.references().size(), == , expected_refs.size());
- size_t n{};
- for (auto&& ref: msg.references()) {
- assert_equal(ref, expected_refs.at(n));
- ++n;
- };
+ assert_equal_seq_str(msg.references(), expected_refs);
+ assert_equal(msg.thread_id(), expected_refs[0]);
}
static void
diff --git a/lib/tests/test-mu-store-query.cc b/lib/tests/test-mu-store-query.cc
index 0331271..e24b7c2 100644
--- a/lib/tests/test-mu-store-query.cc
+++ b/lib/tests/test-mu-store-query.cc
@@ -17,7 +17,7 @@
**
*/
-#include "test-mu-common.hh"
+
#include <array>
#include <thread>
#include <string>
@@ -27,6 +27,7 @@
#include <mu-store.hh>
#include <utils/mu-utils.hh>
+#include <utils/mu-test-utils.hh>
#include <message/mu-message.hh>
using namespace Mu;
@@ -338,22 +339,15 @@ Child
int
main(int argc, char* argv[])
{
- g_test_init(&argc, &argv, NULL);
+ mu_test_init(&argc, &argv);
g_test_bug_base("https://github.com/djcb/mu/issues/");
- g_test_add_func("/store/query/simple", test_simple);
+ g_test_add_func("/store/query/simple", test_simple);
g_test_add_func("/store/query/spam-address-components",
test_spam_address_components);
g_test_add_func("/store/query/dups-related",
test_dups_related);
- if (!g_test_verbose())
- g_log_set_handler(
- NULL,
- (GLogLevelFlags)(G_LOG_LEVEL_MASK |
- G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
- (GLogFunc)black_hole, NULL);
-
return g_test_run();
}
diff --git a/lib/tests/test-mu-store.cc b/lib/tests/test-mu-store.cc
index 3e281d9..1a140e3 100644
--- a/lib/tests/test-mu-store.cc
+++ b/lib/tests/test-mu-store.cc
@@ -28,7 +28,7 @@
#include <locale.h>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "mu-store.hh"
#include "utils/mu-result.hh"
#include <utils/mu-utils.hh>
@@ -343,7 +343,6 @@ test_store_fail()
"/../../root/non-existent-path/54321",
{}, {});
g_assert_false(!!store);
-
}
}
@@ -351,7 +350,7 @@ test_store_fail()
int
main(int argc, char* argv[])
{
- g_test_init(&argc, &argv, NULL);
+ mu_test_init(&argc, &argv);
g_test_add_func("/store/ctor-dtor", test_store_ctor_dtor);
g_test_add_func("/store/add-count-remove", test_store_add_count_remove);
@@ -362,13 +361,5 @@ main(int argc, char* argv[])
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(
- NULL,
- (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
- G_LOG_FLAG_RECURSION),
- (GLogFunc)black_hole,
- NULL);
-
return g_test_run();
}
diff --git a/lib/tests/test-parser.cc b/lib/tests/test-parser.cc
index 4429040..74b5522 100644
--- a/lib/tests/test-parser.cc
+++ b/lib/tests/test-parser.cc
@@ -23,7 +23,7 @@
#include <iostream>
#include <sstream>
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
#include "mu-parser.hh"
#include "utils/mu-result.hh"
diff --git a/lib/tests/test-query.cc b/lib/tests/test-query.cc
index 2ebcdd1..d1ca0bb 100644
--- a/lib/tests/test-query.cc
+++ b/lib/tests/test-query.cc
@@ -30,7 +30,7 @@
#include "index/mu-indexer.hh"
#include "utils/mu-result.hh"
#include "utils/mu-utils.hh"
-#include "test-mu-common.hh"
+#include "utils/mu-test-utils.hh"
using namespace Mu;
@@ -87,20 +87,10 @@ test_query()
int
main(int argc, char* argv[])
try {
- g_test_init(&argc, &argv, NULL);
+ mu_test_init(&argc, &argv);
g_test_add_func("/query", test_query);
-
- if (!g_test_verbose())
- g_log_set_handler(
- NULL,
- (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL |
- G_LOG_FLAG_RECURSION),
- (GLogFunc)black_hole,
- NULL);
-
-
return g_test_run();
} catch (const std::runtime_error& re) {