diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-11-19 21:47:15 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-11-20 14:39:44 +0100 |
commit | b5f7cafab45471bd7d714fb2972e33603a4baaae (patch) | |
tree | aff2a9125627105e1bd977105df5175f332b89dc /test | |
parent | 94e2d8a02c321380e650d055e7e7d6d6ed1c529d (diff) | |
download | qtlocation-mapboxgl-b5f7cafab45471bd7d714fb2972e33603a4baaae.tar.gz |
[core] more robust max-age parsing
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/headers.cpp | 71 | ||||
-rw-r--r-- | test/test.gypi | 1 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/storage/headers.cpp b/test/storage/headers.cpp new file mode 100644 index 0000000000..a0b6ecd546 --- /dev/null +++ b/test/storage/headers.cpp @@ -0,0 +1,71 @@ +#include "storage.hpp" +#include "../fixtures/fixture_log_observer.hpp" + +#include <mbgl/util/http_header.hpp> + +TEST_F(Storage, HTTPHeaderParsing) { + using namespace mbgl; + + http::CacheControl cc; + + cc = http::CacheControl::parse(R"#()#"); + ASSERT_FALSE(bool(cc.maxAge)); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age =34)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(34, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(,max-age=1)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(1, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age=-1)#"); + ASSERT_FALSE(bool(cc.maxAge)); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age=foo)#"); + ASSERT_FALSE(bool(cc.maxAge)); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age="34,max-age="22,max-age=28)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(28, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age=3,max-age="34)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(3, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age="\",max-age=4,")#"); + ASSERT_FALSE(bool(cc.maxAge)); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(private, max-age=0, no-cache)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(0, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age=0, no-cache, no-store)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(0, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(, private , max-bar=3 , no-cache, "\,",,foo=",",,max-age=32)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(32, *cc.maxAge); + EXPECT_EQ(false, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(max-age=3600, must-revalidate)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(3600, *cc.maxAge); + EXPECT_EQ(true, cc.mustRevalidate); + + cc = http::CacheControl::parse(R"#(no-cache="Expires,Via",max-age=3600, must-revalidate)#"); + ASSERT_TRUE(bool(cc.maxAge)); + EXPECT_EQ(3600, *cc.maxAge); + EXPECT_EQ(true, cc.mustRevalidate); +} diff --git a/test/test.gypi b/test/test.gypi index 88448cc807..583474a988 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -72,6 +72,7 @@ 'storage/database.cpp', 'storage/directory_reading.cpp', 'storage/file_reading.cpp', + 'storage/headers.cpp', 'storage/http_cancel.cpp', 'storage/http_coalescing.cpp', 'storage/http_error.cpp', |