mirror of https://github.com/djcb/mu.git
tests: skip missing timezones in queries, too
This commit is contained in:
parent
33d30775ee
commit
b03590cca8
|
@ -625,3 +625,19 @@ Mu::locale_workaround()
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
Mu::timezone_available(const std::string& tz)
|
||||||
|
{
|
||||||
|
const auto old_tz = g_getenv("TZ");
|
||||||
|
|
||||||
|
g_setenv("TZ", tz.c_str(), TRUE);
|
||||||
|
|
||||||
|
auto tzone = g_time_zone_new_local ();
|
||||||
|
bool have_tz = g_strcmp0(g_time_zone_get_identifier(tzone), tz.c_str()) == 0;
|
||||||
|
g_time_zone_unref (tzone);
|
||||||
|
|
||||||
|
g_setenv("TZ", old_tz, TRUE);
|
||||||
|
|
||||||
|
return have_tz;
|
||||||
|
}
|
||||||
|
|
|
@ -155,6 +155,17 @@ std::string time_to_string(const std::string& frm, time_t t, bool utc = false) G
|
||||||
bool locale_workaround();
|
bool locale_workaround();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the given timezone available? For tests
|
||||||
|
*
|
||||||
|
* @param tz a timezone, such as Europe/Helsinki
|
||||||
|
*
|
||||||
|
* @return true or false
|
||||||
|
*/
|
||||||
|
bool timezone_available(const std::string& tz);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/19053351/how-do-i-use-a-custom-deleter-with-a-stdunique-ptr-member
|
// https://stackoverflow.com/questions/19053351/how-do-i-use-a-custom-deleter-with-a-stdunique-ptr-member
|
||||||
template <auto fn>
|
template <auto fn>
|
||||||
struct deleter_from_fn {
|
struct deleter_from_fn {
|
||||||
|
|
|
@ -56,22 +56,15 @@ test_cases(const CaseVec& cases, ProcFunc proc)
|
||||||
static void
|
static void
|
||||||
test_date_basic()
|
test_date_basic()
|
||||||
{
|
{
|
||||||
// ensure we have the needed TZ or skip the test.
|
|
||||||
const auto hki = "Europe/Helsinki";
|
const auto hki = "Europe/Helsinki";
|
||||||
g_setenv("TZ", hki, TRUE);
|
|
||||||
|
|
||||||
{
|
// ensure we have the needed TZ or skip the test.
|
||||||
auto tz = g_time_zone_new_local ();
|
if (!timezone_available(hki)) {
|
||||||
bool have_hki = g_strcmp0(g_time_zone_get_identifier(tz), hki) == 0;
|
g_test_skip("timezone Europe/Helsinki not available");
|
||||||
g_time_zone_unref (tz);
|
return;
|
||||||
|
|
||||||
if (!have_hki) {
|
|
||||||
g_test_skip("timezone Europe/Helsinki not available");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_setenv("TZ", hki, TRUE);
|
||||||
constexpr std::array<std::tuple<const char*, bool, int64_t>, 9> cases = {{
|
constexpr std::array<std::tuple<const char*, bool, int64_t>, 9> cases = {{
|
||||||
{"2015-09-18T09:10:23", true, 1442556623},
|
{"2015-09-18T09:10:23", true, 1442556623},
|
||||||
{"1972-12-14T09:10:23", true, 93165023},
|
{"1972-12-14T09:10:23", true, 93165023},
|
||||||
|
|
|
@ -323,6 +323,12 @@ test_mu_query_wildcards(void)
|
||||||
static void
|
static void
|
||||||
test_mu_query_dates_helsinki(void)
|
test_mu_query_dates_helsinki(void)
|
||||||
{
|
{
|
||||||
|
const auto hki = "Europe/Helsinki";
|
||||||
|
if (!timezone_available(hki)) {
|
||||||
|
g_test_skip("timezone not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
const char* old_tz;
|
const char* old_tz;
|
||||||
|
|
||||||
|
@ -332,7 +338,7 @@ test_mu_query_dates_helsinki(void)
|
||||||
{"date:200808110803..today", 7},
|
{"date:200808110803..today", 7},
|
||||||
{"date:200808110801..now", 7}};
|
{"date:200808110801..now", 7}};
|
||||||
|
|
||||||
old_tz = set_tz("Europe/Helsinki");
|
old_tz = set_tz(hki);
|
||||||
|
|
||||||
const auto xpath{make_database(MU_TESTMAILDIR)};
|
const auto xpath{make_database(MU_TESTMAILDIR)};
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
@ -348,6 +354,12 @@ test_mu_query_dates_helsinki(void)
|
||||||
static void
|
static void
|
||||||
test_mu_query_dates_sydney(void)
|
test_mu_query_dates_sydney(void)
|
||||||
{
|
{
|
||||||
|
const auto syd = "Australia/Sydney";
|
||||||
|
if (!timezone_available(syd)) {
|
||||||
|
g_test_skip("timezone not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
const char* old_tz;
|
const char* old_tz;
|
||||||
QResults queries[] = {{"date:20080731..20080804", 5},
|
QResults queries[] = {{"date:20080731..20080804", 5},
|
||||||
|
@ -355,8 +367,7 @@ test_mu_query_dates_sydney(void)
|
||||||
{"date:200808110803..now", 7},
|
{"date:200808110803..now", 7},
|
||||||
{"date:200808110803..today", 7},
|
{"date:200808110803..today", 7},
|
||||||
{"date:200808110801..now", 7}};
|
{"date:200808110801..now", 7}};
|
||||||
|
old_tz = set_tz(syd);
|
||||||
old_tz = set_tz("Australia/Sydney");
|
|
||||||
|
|
||||||
const auto xpath{make_database(MU_TESTMAILDIR)};
|
const auto xpath{make_database(MU_TESTMAILDIR)};
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
@ -371,6 +382,12 @@ test_mu_query_dates_sydney(void)
|
||||||
static void
|
static void
|
||||||
test_mu_query_dates_la(void)
|
test_mu_query_dates_la(void)
|
||||||
{
|
{
|
||||||
|
const auto la = "America/Los_Angeles";
|
||||||
|
if (!timezone_available(la)) {
|
||||||
|
g_test_skip("timezone not available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
const char* old_tz;
|
const char* old_tz;
|
||||||
|
|
||||||
|
@ -381,8 +398,7 @@ test_mu_query_dates_la(void)
|
||||||
{"date:200808110803..now", 6},
|
{"date:200808110803..now", 6},
|
||||||
{"date:200808110803..today", 6},
|
{"date:200808110803..today", 6},
|
||||||
{"date:200808110801..now", 6}};
|
{"date:200808110801..now", 6}};
|
||||||
|
old_tz = set_tz(la);
|
||||||
old_tz = set_tz("America/Los_Angeles");
|
|
||||||
|
|
||||||
const auto xpath = make_database(MU_TESTMAILDIR);
|
const auto xpath = make_database(MU_TESTMAILDIR);
|
||||||
g_assert_false(xpath.empty());
|
g_assert_false(xpath.empty());
|
||||||
|
@ -605,7 +621,7 @@ main(int argc, char* argv[])
|
||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, nullptr);
|
||||||
DB_PATH1 = make_database(MU_TESTMAILDIR);
|
DB_PATH1 = make_database(MU_TESTMAILDIR);
|
||||||
g_assert_false(DB_PATH1.empty());
|
g_assert_false(DB_PATH1.empty());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue