summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-07-18 14:09:33 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-07-18 14:09:33 -0400
commit54a81d0f9b9903213c55d89ee87eeacbadd5486c (patch)
tree064e86dd0b806c4cfca0082e255edc989a17cfe6
parent4d4fd3155c9d649628f776ed298d3812f363b354 (diff)
downloadqtlocation-mapboxgl-54a81d0f9b9903213c55d89ee87eeacbadd5486c.tar.gz
migrate style_parser tests to use info and style json fixtures
-rw-r--r--.gitignore1
-rwxr-xr-xbin/default.style.json (renamed from bin/style.json)0
-rw-r--r--mapboxgl.gyp41
-rw-r--r--test/fixtures/style_parser/default.info.json6
-rw-r--r--test/style.cpp101
-rw-r--r--test/style_parser.cpp106
-rw-r--r--test/test.gyp10
7 files changed, 123 insertions, 142 deletions
diff --git a/.gitignore b/.gitignore
index c69b0331ef..7eb63a1250 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@
/src/shader/shaders_gles2.cpp
/bin/style.bin.js
/test/fixtures/styles/index.html
+/test/fixtures/style_parser/default.style.json
diff --git a/bin/style.json b/bin/default.style.json
index aea2a1a3ac..aea2a1a3ac 100755
--- a/bin/style.json
+++ b/bin/default.style.json
diff --git a/mapboxgl.gyp b/mapboxgl.gyp
index e8a217a3f9..0c08989ce8 100644
--- a/mapboxgl.gyp
+++ b/mapboxgl.gyp
@@ -64,7 +64,7 @@
{
'action_name': 'Build Stylesheet',
'inputs': [
- 'bin/style.json',
+ 'bin/default.style.json',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/bin/style.min.js',
@@ -79,35 +79,6 @@
}
},
{
- 'target_name': 'build_stylesheet_fixtures',
- 'type': 'none',
- 'hard_dependency': 1,
- 'dependencies': [
- 'npm_install'
- ],
- 'actions': [
- {
- 'action_name': 'Build Stylesheet Fixtures',
- 'inputs': [
- 'bin/style.json',
- ],
- 'outputs': [
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js',
- ],
- 'action': ['<@(node)', 'bin/build-fixtures.js', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)/bin']
- }
- ],
- 'direct_dependent_settings': {
- 'sources': [
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js',
- ],
- }
- },
- {
'target_name': 'copy_default_stylesheet',
'type': 'none',
'hard_dependency': 1,
@@ -124,20 +95,18 @@
]
},
{
- 'target_name': 'copy_stylesheet_fixtures',
+ 'target_name': 'copy_default_stylesheet_fixtures',
'type': 'none',
'hard_dependency': 1,
'dependencies': [
- 'build_stylesheet_fixtures'
+ 'build_stylesheet'
],
'copies': [
{
'files': [
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-colors.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-functions.min.js',
- '<(SHARED_INTERMEDIATE_DIR)/bin/fuzz-layers.min.js',
+ 'bin/default.style.json',
],
- 'destination': '<(PRODUCT_DIR)'
+ 'destination': 'test/fixtures/style_parser'
}
]
},
diff --git a/test/fixtures/style_parser/default.info.json b/test/fixtures/style_parser/default.info.json
new file mode 100644
index 0000000000..9c25a2f488
--- /dev/null
+++ b/test/fixtures/style_parser/default.info.json
@@ -0,0 +1,6 @@
+{
+ "default": {
+ "log": [
+ ]
+ }
+}
diff --git a/test/style.cpp b/test/style.cpp
deleted file mode 100644
index e98740e40e..0000000000
--- a/test/style.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-#include "gtest/gtest.h"
-
-#include <mbgl/style/style.hpp>
-#include "./fixtures/fixture_log.hpp"
-
-#include <iostream>
-#include <fstream>
-
-using namespace mbgl;
-
-typedef std::vector<std::pair<uint32_t, std::string>> Messages;
-
-void checkMessages(const FixtureLogBackend &log, Messages messages) {
- for (auto &it : messages) {
- const FixtureLogBackend::LogMessage message {
- EventSeverityClass("WARNING"),
- EventClass("ParseStyle"),
- it.second
- };
-
- EXPECT_EQ(it.first, log.count(message)) << "Message: "
- << message << std::endl;
- }
-
- const auto &unchecked = log.unchecked();
- if (unchecked.size()) {
- std::cerr << "Unchecked Log Messages: " << std::endl
- << unchecked;
- }
-
- ASSERT_EQ(0, unchecked.size());
-}
-
-TEST(Style, Style) {
- const FixtureLogBackend &log = Log::Set<FixtureLogBackend>();
-
- std::ifstream stylefile("./style.min.js");
- ASSERT_TRUE(stylefile.good());
- std::stringstream stylejson;
- stylejson << stylefile.rdbuf();
-
- Style style;
- style.loadJSON((const uint8_t *)stylejson.str().c_str());
-
- checkMessages(log, {});
-}
-
-TEST(Style, Colors) {
- const FixtureLogBackend &log = Log::Set<FixtureLogBackend>();
-
- std::ifstream stylefile("./fuzz-colors.min.js");
- ASSERT_TRUE(stylefile.good());
- std::stringstream stylejson;
- stylejson << stylefile.rdbuf();
-
- Style style;
- style.loadJSON((const uint8_t *)stylejson.str().c_str());
-
- checkMessages(log, {
- {84, "value of 'line-width' must be a number, or a number function"},
- {6, "value of 'line-opacity' must be a number, or a number function"},
- {12, "value of 'text-size' must be a number, or a number function"}
- });
-}
-
-TEST(Style, Functions) {
- const FixtureLogBackend &log = Log::Set<FixtureLogBackend>();
-
- std::ifstream stylefile("./fuzz-functions.min.js");
- ASSERT_TRUE(stylefile.good());
- std::stringstream stylejson;
- stylejson << stylefile.rdbuf();
-
- Style style;
- style.loadJSON((const uint8_t *)stylejson.str().c_str());
-
- checkMessages(log, {
- {28, "stop must have zoom level and value specification"},
- {12, "function must specify a function type"}
- });
-}
-
-TEST(Style, Layers) {
- const FixtureLogBackend &log = Log::Set<FixtureLogBackend>();
-
- std::ifstream stylefile("./fuzz-layers.min.js");
- ASSERT_TRUE(stylefile.good());
- std::stringstream stylejson;
- stylejson << stylefile.rdbuf();
-
- Style style;
- style.loadJSON((const uint8_t *)stylejson.str().c_str());
-
- checkMessages(log, {
- {20, "stop must have zoom level and value specification"},
- {6, "function must specify a function type"},
- {1, "value of 'line-width' must be a number, or a number function"},
- {1, "array value has unexpected number of elements"},
- {1, "value of 'line-opacity' must be a number, or a number function"}
- });
-}
diff --git a/test/style_parser.cpp b/test/style_parser.cpp
new file mode 100644
index 0000000000..ccc1ec5350
--- /dev/null
+++ b/test/style_parser.cpp
@@ -0,0 +1,106 @@
+#include "gtest/gtest.h"
+
+#include <mbgl/style/style.hpp>
+#include <mbgl/util/io.hpp>
+
+#include <rapidjson/document.h>
+
+#include "./fixtures/fixture_log.hpp"
+
+#include <iostream>
+#include <fstream>
+
+#include <dirent.h>
+
+const std::string base_directory = []{
+ std::string fn = __FILE__;
+ fn.erase(fn.find_last_of("/"));
+ return fn + "/fixtures/style_parser";
+}();
+
+using namespace mbgl;
+
+typedef std::pair<uint32_t, std::string> Message;
+typedef std::vector<Message> Messages;
+
+class StyleParserTest : public ::testing::TestWithParam<std::string> {};
+
+TEST_P(StyleParserTest, render) {
+ const std::string &base = base_directory + "/" + GetParam();
+
+ const std::string style_path = base + ".style.json";
+ const std::string info = util::read_file(base + ".info.json");
+
+ // Parse settings.
+ rapidjson::Document doc;
+ doc.Parse<0>((const char *const)info.c_str());
+ ASSERT_EQ(false, doc.HasParseError());
+ ASSERT_EQ(true, doc.IsObject());
+
+ std::ifstream stylefile(style_path);
+ ASSERT_TRUE(stylefile.good());
+ std::stringstream stylejson;
+ stylejson << stylefile.rdbuf();
+
+ Style style;
+ style.loadJSON((const uint8_t *)stylejson.str().c_str());
+
+ for (auto it = doc.MemberBegin(), end = doc.MemberEnd(); it != end; it++) {
+ const FixtureLogBackend &log = Log::Set<FixtureLogBackend>();
+
+ const std::string name { it->name.GetString(), it->name.GetStringLength() };
+ const rapidjson::Value &value = it->value;
+ ASSERT_EQ(true, value.IsObject());
+
+ if (value.HasMember("log")) {
+ const rapidjson::Value &js_log = value["log"];
+ ASSERT_EQ(true, js_log.IsArray());
+ for (rapidjson::SizeType i = 0; i < js_log.Size(); i++) {
+ const rapidjson::Value &js_entry = js_log[i];
+ ASSERT_EQ(true, js_entry.IsArray());
+ if (js_entry.Size() == 4) {
+ const uint32_t count = js_entry[rapidjson::SizeType(0)].GetUint();
+ if (js_entry[rapidjson::SizeType(3)].IsString()) {
+ const FixtureLogBackend::LogMessage message {
+ EventSeverityClass(js_entry[rapidjson::SizeType(1)].GetString()),
+ EventClass(js_entry[rapidjson::SizeType(2)].GetString()),
+ js_entry[rapidjson::SizeType(3)].GetString()
+ };
+ EXPECT_EQ(count, log.count(message)) << "Message: " << message << std::endl;
+ }
+ } else {
+ FAIL();
+ }
+ }
+ }
+
+ const auto &unchecked = log.unchecked();
+ if (unchecked.size()) {
+ std::cerr << "Unchecked Log Messages (" << base << "): "
+ << std::endl << unchecked;
+ }
+
+ ASSERT_EQ(0, unchecked.size());
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] {
+ std::vector<std::string> names;
+ const std::string ending = ".info.json";
+
+ DIR *dir = opendir(base_directory.c_str());
+ if (dir == nullptr) {
+ return names;
+ }
+
+ for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) {
+ const std::string name = dp->d_name;
+ if (name.length() >= ending.length() && name.compare(name.length() - ending.length(), ending.length(), ending) == 0) {
+ names.push_back(name.substr(0, name.length() - ending.length()));
+ }
+ }
+
+ closedir(dir);
+
+ return names;
+}()));
diff --git a/test/test.gyp b/test/test.gyp
index 8ecce6a325..f91f118080 100644
--- a/test/test.gyp
+++ b/test/test.gyp
@@ -107,22 +107,22 @@
]
},
{
- "target_name": "style",
- "product_name": "test_style",
+ "target_name": "style_parser",
+ "product_name": "test_style_parser",
"type": "executable",
"libraries": [
"-lpthread",
],
"sources": [
"./main.cpp",
- "./style.cpp",
+ "./style_parser.cpp",
"./fixtures/fixture_log.hpp",
"./fixtures/fixture_log.cpp",
],
"dependencies": [
"../deps/gtest/gtest.gyp:gtest",
"../mapboxgl.gyp:mapboxgl",
- "../mapboxgl.gyp:copy_stylesheet_fixtures",
+ "../mapboxgl.gyp:copy_default_stylesheet_fixtures",
]
},
{
@@ -223,7 +223,7 @@
"tile",
"functions",
"headless",
- "style",
+ "style_parser",
"comparisons",
],
}