summaryrefslogtreecommitdiff
path: root/test/storage/headers.test.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-28 11:45:33 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-28 16:34:22 +0200
commit3f3fc7b7723698e44427e2a14a2f4906832800bf (patch)
tree5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/storage/headers.test.cpp
parenta8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff)
downloadqtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/storage/headers.test.cpp')
-rw-r--r--test/storage/headers.test.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/test/storage/headers.test.cpp b/test/storage/headers.test.cpp
new file mode 100644
index 0000000000..b7dcfc025d
--- /dev/null
+++ b/test/storage/headers.test.cpp
@@ -0,0 +1,69 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/util/http_header.hpp>
+
+TEST(HTTPHeader, Parsing) {
+ using namespace mbgl;
+
+ http::CacheControl cc;
+
+ cc = http::CacheControl::parse(R"#()#");
+ ASSERT_FALSE(bool(cc.maxAge));
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age =34)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(34u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(,max-age=1)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(1u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age=-1)#");
+ ASSERT_FALSE(bool(cc.maxAge));
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age=foo)#");
+ ASSERT_FALSE(bool(cc.maxAge));
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age="34,max-age="22,max-age=28)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(28u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age=3,max-age="34)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(3u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age="\",max-age=4,")#");
+ ASSERT_FALSE(bool(cc.maxAge));
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(private, max-age=0, no-cache)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(0u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age=0, no-cache, no-store)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(0u, *cc.maxAge);
+ EXPECT_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(32u, *cc.maxAge);
+ EXPECT_FALSE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(max-age=3600, must-revalidate)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(3600u, *cc.maxAge);
+ EXPECT_TRUE(cc.mustRevalidate);
+
+ cc = http::CacheControl::parse(R"#(no-cache="Expires,Via",max-age=3600, must-revalidate)#");
+ ASSERT_TRUE(bool(cc.maxAge));
+ EXPECT_EQ(3600u, *cc.maxAge);
+ EXPECT_TRUE(cc.mustRevalidate);
+}