[core] Polyfill std::chrono::abs
This commit is contained in:
@@ -53,6 +53,14 @@ std::string iso8601(SystemTimePoint);
|
||||
|
||||
SystemTimePoint parseTimePoint(const char *);
|
||||
|
||||
// C++17 polyfill
|
||||
template <class Rep, class Period, class = std::enable_if_t<
|
||||
std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>>
|
||||
constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d)
|
||||
{
|
||||
return d >= d.zero() ? d : -d;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -39,15 +39,13 @@ TEST_F(Storage, HTTPCacheControlParsing) {
|
||||
util::RunLoop loop;
|
||||
OnlineFileSource fs(nullptr);
|
||||
|
||||
const Seconds now = toSeconds(SystemClock::now());
|
||||
|
||||
std::unique_ptr<FileRequest> req2 = fs.request({ Resource::Unknown, "http://127.0.0.1:3000/test?cachecontrol=max-age=120" },
|
||||
[&](Response res) {
|
||||
req2.reset();
|
||||
EXPECT_EQ(nullptr, res.error);
|
||||
ASSERT_TRUE(res.data.get());
|
||||
EXPECT_EQ("Hello World!", *res.data);
|
||||
EXPECT_GT(2, std::abs(toSeconds(*res.expires).count() - now.count() - 120)) << "Expiration date isn't about 120 seconds in the future";
|
||||
EXPECT_GT(Seconds(2), util::abs(*res.expires - SystemClock::now() - Seconds(120))) << "Expiration date isn't about 120 seconds in the future";
|
||||
EXPECT_FALSE(bool(res.modified));
|
||||
EXPECT_FALSE(bool(res.etag));
|
||||
loop.stop();
|
||||
|
||||
Reference in New Issue
Block a user