diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2021-11-17 22:34:57 +0100 |
| commit | 6232d13f5321b87ddf12a1aa36b4545da45f173d (patch) | |
| tree | 23f3316470a14136debd9d02f9e920ca2b06f4cc /test/test_tz_str.cc | |
Travel3: Simple image and video display site
Reads the images and videos from filesystem and builds a site in
memroy.
Diffstat (limited to 'test/test_tz_str.cc')
| -rw-r--r-- | test/test_tz_str.cc | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/test_tz_str.cc b/test/test_tz_str.cc new file mode 100644 index 0000000..a96c4ea --- /dev/null +++ b/test/test_tz_str.cc @@ -0,0 +1,97 @@ +#include "common.hh" + +#include "tz_str.hh" + +#include <gtest/gtest.h> + +namespace { + +constexpr const time_t kMin = 60; +constexpr const time_t kHour = 60 * kMin; +constexpr const time_t kDay = 24 * kHour; + +} // namespace + +TEST(tz_str, get_local_time_no_dst) { + auto ret = tz::get_local_time("HST10", 0); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(0 - 10 * kHour, ret.value()); + } + + ret = tz::get_local_time("HST10", kDay * 180); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(kDay * 180 - 10 * kHour, ret.value()); + } +} + +TEST(tz_str, get_local_time_quote) { + auto ret = tz::get_local_time("<HST-FOO>10", 0); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(0 - 10 * kHour, ret.value()); + } +} + +TEST(tz_str, get_local_time_dst) { + auto ret = tz::get_local_time("IST-1GMT0,M10.5.0,M3.5.0/1", 0); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(0 * kHour, ret.value()); + } + + ret = tz::get_local_time("IST-1GMT0,M10.5.0,M3.5.0/1", kDay * 180); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(kDay * 180 + 1 * kHour, ret.value()); + } + + ret = tz::get_local_time("GMT0IST,M3.5.0/1,M10.5.0", 0); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(0 * kHour, ret.value()); + } + + ret = tz::get_local_time("GMT0IST,M3.5.0/1,M10.5.0", kDay * 180); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(kDay * 180 + 1 * kHour, ret.value()); + } + + ret = tz::get_local_time("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0", 0); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(13 * kHour, ret.value()); + } + + ret = tz::get_local_time("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0", + kDay * 180); + EXPECT_TRUE(ret.has_value()); + if (ret.has_value()) { + EXPECT_EQ(kDay * 180 + 12 * kHour, ret.value()); + } +} + +TEST(tz_str, get_local_time_bad) { + auto ret = tz::get_local_time("<HST-", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("< >1", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("HS10", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("HST", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("HST-300", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("HST-10:300", 0); + EXPECT_FALSE(ret.has_value()); + + ret = tz::get_local_time("HST-10:00:300", 0); + EXPECT_FALSE(ret.has_value()); +} |
