From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- test/test_tz_info.cc | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 test/test_tz_info.cc (limited to 'test/test_tz_info.cc') 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 + +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 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::create_null()}; + std::unique_ptr 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()); + } +} -- cgit v1.2.3-70-g09d2