summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-03-02 15:18:36 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-03-06 13:51:19 -0800
commita3d76dad1064d3020f8b972ed5e7427966f30983 (patch)
treed2a8a03dd09393aa14f7f19fd19f63fbd9e31031 /test
parenta6c8a76694489d9ba81554fd19fd85d755eeead2 (diff)
downloadqtlocation-mapboxgl-a3d76dad1064d3020f8b972ed5e7427966f30983.tar.gz
Ported util::mapbox tests from mapbox-gl-js
Left out several tests that were redundant because mapbox.cpp only looks at the passed in access token.
Diffstat (limited to 'test')
-rw-r--r--test/miscellaneous/mapbox.cpp61
-rw-r--r--test/test.gyp1
2 files changed, 62 insertions, 0 deletions
diff --git a/test/miscellaneous/mapbox.cpp b/test/miscellaneous/mapbox.cpp
new file mode 100644
index 0000000000..62344e016b
--- /dev/null
+++ b/test/miscellaneous/mapbox.cpp
@@ -0,0 +1,61 @@
+#include "../fixtures/util.hpp"
+
+#include <mbgl/util/mapbox.hpp>
+#include <regex>
+#include <iostream>
+
+using namespace mbgl;
+
+TEST(Mapbox, SourceURL) {
+ EXPECT_EQ(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "key"), "https://api.tiles.mapbox.com/v4/user.map.json?access_token=key");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", "token"), "https://api.tiles.mapbox.com/v4/user.map.json?access_token=token");
+ EXPECT_THROW(mbgl::util::mapbox::normalizeSourceURL("mapbox://user.map", ""), std::runtime_error);
+}
+
+TEST(Mapbox, GlyphsURL) {
+ EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("mapbox://fontstack/{fontstack}/{range}.pbf", "key"), "https://api.tiles.mapbox.com/v4/fontstack/{fontstack}/{range}.pbf?access_token=key");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeGlyphsURL("http://path", "key"), "http://path");
+}
+
+TEST(Mapbox, TileURL) {
+ try {
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png/tile.png", "mapbox://user.map"), "http://path.png/tile{ratio}.png");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png/tile.png32", "mapbox://user.map"), "http://path.png/tile{ratio}.png32");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png/tile.png70", "mapbox://user.map"), "http://path.png/tile{ratio}.png70");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png/tile.png?access_token=foo", "mapbox://user.map"), "http://path.png/tile{ratio}.png?access_token=foo");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png", "http://path"), "http://path.png");
+ EXPECT_EQ(mbgl::util::mapbox::normalizeTileURL("http://path.png", ""), "http://path.png");
+ } catch (const std::regex_error& e) {
+ std::cout << "regex_error caught: " << e.what() << '\n';
+ std::cout << e.code() << '\n';
+ switch (e.code()) {
+ case std::regex_constants::error_collate:
+ std::cout << "error_collate" << '\n'; break;
+ case std::regex_constants::error_ctype:
+ std::cout << "error_ctype" << '\n'; break;
+ case std::regex_constants::error_escape:
+ std::cout << "error_escape" << '\n'; break;
+ case std::regex_constants::error_backref:
+ std::cout << "error_backref" << '\n'; break;
+ case std::regex_constants::error_paren:
+ std::cout << "error_paren" << '\n'; break;
+ case std::regex_constants::error_brace:
+ std::cout << "error_brace" << '\n'; break;
+ case std::regex_constants::error_badbrace:
+ std::cout << "error_badbrace" << '\n'; break;
+ case std::regex_constants::error_range:
+ std::cout << "error_range" << '\n'; break;
+ case std::regex_constants::error_space:
+ std::cout << "error_space" << '\n'; break;
+ case std::regex_constants::error_badrepeat:
+ std::cout << "error_badrepeat" << '\n'; break;
+ case std::regex_constants::error_complexity:
+ std::cout << "error_complexity" << '\n'; break;
+ case std::regex_constants::error_stack:
+ std::cout << "error_stack" << '\n'; break;
+
+ default:
+ break;
+ }
+ }
+}
diff --git a/test/test.gyp b/test/test.gyp
index 7759caced8..bee2f4c4ef 100644
--- a/test/test.gyp
+++ b/test/test.gyp
@@ -41,6 +41,7 @@
'miscellaneous/comparisons.cpp',
'miscellaneous/enums.cpp',
'miscellaneous/functions.cpp',
+ 'miscellaneous/mapbox.cpp',
'miscellaneous/merge_lines.cpp',
'miscellaneous/rotation_range.cpp',
'miscellaneous/style_parser.cpp',