summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-28 16:29:54 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-29 14:50:15 -0800
commitb41a73e1c1dfea982df4a0326d45a48babc22dd4 (patch)
treefc744d5953ad6ecf8e52d5653c499760b148cb5c /test
parent849e8b32b4b2febc63ad3df8539b483ccc67ac63 (diff)
downloadqtlocation-mapboxgl-b41a73e1c1dfea982df4a0326d45a48babc22dd4.tar.gz
[core] Rationalize Resource initialization
Diffstat (limited to 'test')
-rw-r--r--test/storage/resource.cpp50
-rw-r--r--test/test.gypi1
2 files changed, 51 insertions, 0 deletions
diff --git a/test/storage/resource.cpp b/test/storage/resource.cpp
new file mode 100644
index 0000000000..30c1597df2
--- /dev/null
+++ b/test/storage/resource.cpp
@@ -0,0 +1,50 @@
+#include <mbgl/storage/resource.hpp>
+
+#include <gtest/gtest.h>
+
+TEST(Resource, Style) {
+ using namespace mbgl;
+ Resource resource = Resource::style("http://example.com");
+ EXPECT_EQ(Resource::Kind::Style, resource.kind);
+ EXPECT_EQ("http://example.com", resource.url);
+}
+
+TEST(Resource, Source) {
+ using namespace mbgl;
+ Resource resource = Resource::source("http://example.com");
+ EXPECT_EQ(Resource::Kind::Source, resource.kind);
+ EXPECT_EQ("http://example.com", resource.url);
+}
+
+TEST(Resource, Tile) {
+ using namespace mbgl;
+ Resource resource = Resource::tile("http://example.com/{z}/{x}/{y}{ratio}.png", 2.0, 1, 2, 3);
+ EXPECT_EQ(Resource::Kind::Tile, resource.kind);
+ EXPECT_EQ("http://example.com/3/1/2@2x.png", resource.url);
+ EXPECT_EQ("http://example.com/{z}/{x}/{y}{ratio}.png", resource.tileData->urlTemplate);
+ EXPECT_EQ(2.0, resource.tileData->pixelRatio);
+ EXPECT_EQ(1, resource.tileData->x);
+ EXPECT_EQ(2, resource.tileData->y);
+ EXPECT_EQ(3, resource.tileData->z);
+}
+
+TEST(Resource, Glyphs) {
+ using namespace mbgl;
+ Resource resource = Resource::glyphs("http://example.com/{fontstack}/{range}", "stack", {0, 255});
+ EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
+ EXPECT_EQ("http://example.com/stack/0-255", resource.url);
+}
+
+TEST(Resource, SpriteImage) {
+ using namespace mbgl;
+ Resource resource = Resource::spriteImage("http://example.com/sprite", 2.0);
+ EXPECT_EQ(Resource::Kind::SpriteImage, resource.kind);
+ EXPECT_EQ("http://example.com/sprite@2x.png", resource.url);
+}
+
+TEST(Resource, SpriteJSON) {
+ using namespace mbgl;
+ Resource resource = Resource::spriteJSON("http://example.com/sprite", 2.0);
+ EXPECT_EQ(Resource::Kind::SpriteJSON, resource.kind);
+ EXPECT_EQ("http://example.com/sprite@2x.json", resource.url);
+}
diff --git a/test/test.gypi b/test/test.gypi
index e0d0951759..628ae3eb3e 100644
--- a/test/test.gypi
+++ b/test/test.gypi
@@ -87,6 +87,7 @@
'storage/http_retry_network_status.cpp',
'storage/http_reading.cpp',
'storage/http_timeout.cpp',
+ 'storage/resource.cpp',
'style/glyph_store.cpp',
'style/pending_resources.cpp',