[core] Replace time_t with std::chrono::seconds

Added aliases for std::chrono typedefs (eg. 'Seconds' for
std::chrono::seconds). These aliases are used together with templated
helper functions to replace time_t with std::chrono::seconds for most
cases, in particular for 'modified' and 'expires' values in Response.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-25 13:30:32 +02:00
parent 4475f54860
commit 31fd2822f5
30 changed files with 184 additions and 121 deletions

View File

@@ -4,6 +4,7 @@
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/sqlite_cache.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/run_loop.hpp>
TEST_F(Storage, CacheRevalidateSame) {
@@ -31,8 +32,8 @@ TEST_F(Storage, CacheRevalidateSame) {
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Response", *res.data);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(0, res.modified);
EXPECT_EQ(Seconds::zero(), res.expires);
EXPECT_EQ(Seconds::zero(), res.modified);
EXPECT_EQ("snowfall", res.etag);
req2 = fs.request(revalidateSame, [&, res](Response res2) {
@@ -53,8 +54,8 @@ TEST_F(Storage, CacheRevalidateSame) {
EXPECT_EQ(res.data, res2.data);
EXPECT_EQ("Response", *res2.data);
// We use this to indicate that a 304 reply came back.
EXPECT_LT(0, res2.expires);
EXPECT_EQ(0, res2.modified);
EXPECT_LT(Seconds::zero(), res2.expires);
EXPECT_EQ(Seconds::zero(), res2.modified);
// We're not sending the ETag in the 304 reply, but it should still be there.
EXPECT_EQ("snowfall", res2.etag);
@@ -92,8 +93,8 @@ TEST_F(Storage, CacheRevalidateModified) {
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Response", *res.data);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(1420070400, res.modified);
EXPECT_EQ(Seconds::zero(), res.expires);
EXPECT_EQ(1420070400, res.modified.count());
EXPECT_EQ("", res.etag);
req2 = fs.request(revalidateModified, [&, res](Response res2) {
@@ -114,8 +115,8 @@ TEST_F(Storage, CacheRevalidateModified) {
EXPECT_EQ("Response", *res2.data);
EXPECT_EQ(res.data, res2.data);
// We use this to indicate that a 304 reply came back.
EXPECT_LT(0, res2.expires);
EXPECT_EQ(1420070400, res2.modified);
EXPECT_LT(Seconds::zero(), res2.expires);
EXPECT_EQ(1420070400, res2.modified.count());
EXPECT_EQ("", res2.etag);
loop.stop();
@@ -151,8 +152,8 @@ TEST_F(Storage, CacheRevalidateEtag) {
EXPECT_EQ(false, res.stale);
ASSERT_TRUE(res.data.get());
EXPECT_EQ("Response 1", *res.data);
EXPECT_EQ(0, res.expires);
EXPECT_EQ(0, res.modified);
EXPECT_EQ(Seconds::zero(), res.expires);
EXPECT_EQ(Seconds::zero(), res.modified);
EXPECT_EQ("response-1", res.etag);
req2 = fs.request(revalidateEtag, [&, res](Response res2) {
@@ -172,8 +173,8 @@ TEST_F(Storage, CacheRevalidateEtag) {
ASSERT_TRUE(res2.data.get());
EXPECT_NE(res.data, res2.data);
EXPECT_EQ("Response 2", *res2.data);
EXPECT_EQ(0, res2.expires);
EXPECT_EQ(0, res2.modified);
EXPECT_EQ(Seconds::zero(), res2.expires);
EXPECT_EQ(Seconds::zero(), res2.modified);
EXPECT_EQ("response-2", res2.etag);
loop.stop();