tests: skip missing timezones in queries, too
This commit is contained in:
@ -625,3 +625,19 @@ Mu::locale_workaround()
|
||||
|
||||
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();
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
template <auto fn>
|
||||
struct deleter_from_fn {
|
||||
|
||||
@ -56,22 +56,15 @@ test_cases(const CaseVec& cases, ProcFunc proc)
|
||||
static void
|
||||
test_date_basic()
|
||||
{
|
||||
// ensure we have the needed TZ or skip the test.
|
||||
const auto hki = "Europe/Helsinki";
|
||||
g_setenv("TZ", hki, TRUE);
|
||||
|
||||
{
|
||||
auto tz = g_time_zone_new_local ();
|
||||
bool have_hki = g_strcmp0(g_time_zone_get_identifier(tz), hki) == 0;
|
||||
g_time_zone_unref (tz);
|
||||
|
||||
if (!have_hki) {
|
||||
g_test_skip("timezone Europe/Helsinki not available");
|
||||
return;
|
||||
}
|
||||
// ensure we have the needed TZ or skip the test.
|
||||
if (!timezone_available(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 = {{
|
||||
{"2015-09-18T09:10:23", true, 1442556623},
|
||||
{"1972-12-14T09:10:23", true, 93165023},
|
||||
|
||||
Reference in New Issue
Block a user