summaryrefslogtreecommitdiff
path: root/test/test_tz_info.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_tz_info.cc')
-rw-r--r--test/test_tz_info.cc114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/test_tz_info.cc b/test/test_tz_info.cc
new file mode 100644
index 0000000..962f903
--- /dev/null
+++ b/test/test_tz_info.cc
@@ -0,0 +1,114 @@
+#include "common.hh"
+
+#include "file_test.hh"
+#include "logger.hh"
+#include "tz_info.hh"
+
+#include <gtest/gtest.h>
+
+namespace {
+
+class TzInfoTest : public FileTest {
+public:
+ void Load(char const* data, size_t size) {
+ write(std::string_view(data, size));
+ close();
+ tz_info_ = TzInfo::create(logger_, path().parent_path());
+ }
+
+ std::optional<time_t> get_local_time(time_t utc) {
+ if (!tz_info_)
+ return std::nullopt;
+ return tz_info_->get_local_time(path().filename().c_str(), utc);
+ }
+
+private:
+ std::shared_ptr<Logger> logger_{Logger::create_null()};
+ std::unique_ptr<TzInfo> tz_info_;
+};
+
+constexpr const time_t kHour = 60 * 60;
+
+} // namespace
+
+TEST_F(TzInfoTest, v2_honolulu) {
+ char data[] =
+ "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\x6"
+ "\0\0\0\x6"
+ "\0\0\0\0"
+ "\0\0\0\x7"
+ "\0\0\0\x6"
+ "\0\0\0\x14"
+ "\x80\0\0\0"
+ "\xbb\x05\x43\x48"
+ "\xbb\x21\x71\x58"
+ "\xcb\x89\x3d\xc8"
+ "\xd2\x23\xf4\x70"
+ "\xd2\x61\x49\x38"
+ "\xd5\x8d\x73\x48"
+ "\1\2\1\3\4\1\5"
+ "\xff\xff\x6c\x02\0\x00"
+ "\xff\xff\x6c\x58\0\x04"
+ "\xff\xff\x7a\x68\1\x08"
+ "\xff\xff\x7a\x68\1\x0c"
+ "\xff\xff\x7a\x68\1\x10"
+ "\xff\xff\x73\x60\0\x04"
+ "LMT\0"
+ "HST\0"
+ "HDT\0"
+ "HWT\0"
+ "HPT\0"
+ "\0\0\0\0\1\0"
+ "\0\0\0\0\1\0"
+
+ "TZif2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+ "\0\0\0\x6"
+ "\0\0\0\x6"
+ "\0\0\0\0"
+ "\0\0\0\x7"
+ "\0\0\0\x6"
+ "\0\0\0\x14"
+ "\xff\xff\xff\xff"
+ "\x74\xe0\x70\xbe"
+ "\xff\xff\xff\xff"
+ "\xbb\x05\x43\x48"
+ "\xff\xff\xff\xff"
+ "\xbb\x21\x71\x58"
+ "\xff\xff\xff\xff"
+ "\xcb\x89\x3d\xc8"
+ "\xff\xff\xff\xff"
+ "\xd2\x23\xf4\x70"
+ "\xff\xff\xff\xff"
+ "\xd2\x61\x49\x38"
+ "\xff\xff\xff\xff"
+ "\xd5\x8d\x73\x48"
+ "\1\2\1\3\4\1\5"
+ "\xff\xff\x6c\x02\0\x00"
+ "\xff\xff\x6c\x58\0\x04"
+ "\xff\xff\x7a\x68\1\x08"
+ "\xff\xff\x7a\x68\1\x0c"
+ "\xff\xff\x7a\x68\1\x10"
+ "\xff\xff\x73\x60\0\x04"
+ "LMT\0"
+ "HST\0"
+ "HDT\0"
+ "HWT\0"
+ "HPT\0"
+ "\0\0\0\0\1\0"
+ "\0\0\0\0\1\0"
+ "\nHST10\n";
+ Load(data, sizeof(data) - 1);
+
+ auto ret = get_local_time(-1156939200); // 1933-05-04T12:00:00Z
+ EXPECT_TRUE(ret.has_value());
+ if (ret.has_value()) {
+ EXPECT_EQ(-1156939200 - 9.5 * kHour, ret.value());
+ }
+
+ ret = get_local_time(1546300800); // 2019-01-01T00:00:00Z
+ EXPECT_TRUE(ret.has_value());
+ if (ret.has_value()) {
+ EXPECT_EQ(1546300800 - 10 * kHour, ret.value());
+ }
+}