migrate style_parser tests to use info and style json fixtures
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
|
||||
41
mapboxgl.gyp
41
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',
|
||||
@@ -78,35 +78,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',
|
||||
@@ -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'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
6
test/fixtures/style_parser/default.info.json
vendored
Normal file
6
test/fixtures/style_parser/default.info.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"default": {
|
||||
"log": [
|
||||
]
|
||||
}
|
||||
}
|
||||
101
test/style.cpp
101
test/style.cpp
@@ -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"}
|
||||
});
|
||||
}
|
||||
106
test/style_parser.cpp
Normal file
106
test/style_parser.cpp
Normal file
@@ -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;
|
||||
}()));
|
||||
@@ -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",
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user