Merge branch 'stylesource' into fuzz-pipe
Conflicts: src/map/source.cpp src/style/style_layer.cpp
5
test/fixtures/fixture_request.cpp
vendored
@@ -40,6 +40,7 @@ platform::request_http(const std::string &url,
|
||||
if (err < 0) {
|
||||
req->res->code = err;
|
||||
req->res->error_message = uv_strerror(err);
|
||||
fprintf(stderr, "[WARNING] fixture request: %s\n", uv_strerror(err));
|
||||
req->complete();
|
||||
return req;
|
||||
}
|
||||
@@ -52,6 +53,7 @@ platform::request_http(const std::string &url,
|
||||
if (err < 0) {
|
||||
req->res->code = err;
|
||||
req->res->error_message = uv_strerror(err);
|
||||
fprintf(stderr, "[WARNING] fixture request: %s\n", uv_strerror(err));
|
||||
req->complete();
|
||||
return req;
|
||||
}
|
||||
@@ -69,6 +71,7 @@ platform::request_http(const std::string &url,
|
||||
if (err < 0) {
|
||||
req->res->code = err;
|
||||
req->res->error_message = uv_strerror(err);
|
||||
fprintf(stderr, "[WARNING] fixture request: %s\n", uv_strerror(err));
|
||||
req->complete();
|
||||
return req;
|
||||
}
|
||||
@@ -80,12 +83,14 @@ platform::request_http(const std::string &url,
|
||||
if (err < 0) {
|
||||
req->res->code = err;
|
||||
req->res->error_message = uv_strerror(err);
|
||||
fprintf(stderr, "[WARNING] fixture request: %s\n", uv_strerror(err));
|
||||
req->complete();
|
||||
return req;
|
||||
}
|
||||
|
||||
req->res->body.swap(body);
|
||||
req->res->code = 200;
|
||||
fprintf(stderr, "[INFO] fixture request completed: %s\n", clean_url.c_str());
|
||||
req->complete();
|
||||
|
||||
return req;
|
||||
|
||||
8
test/fixtures/styles/0.info.json
vendored
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"zoom": 0,
|
||||
"latitude": 0,
|
||||
"longitude": 0,
|
||||
"angle": 0,
|
||||
"width": 512,
|
||||
"height": 512
|
||||
}
|
||||
8
test/fixtures/styles/1.info.json
vendored
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"zoom": 0,
|
||||
"latitude": 0,
|
||||
"longitude": 0,
|
||||
"angle": 0,
|
||||
"width": 512,
|
||||
"height": 512
|
||||
}
|
||||
13
test/fixtures/styles/line-color.info.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"default": {
|
||||
"zoom": 14,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256
|
||||
},
|
||||
"colored": {
|
||||
"zoom": 14,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256,
|
||||
"classes": ["colored"]
|
||||
}
|
||||
}
|
||||
33
test/fixtures/styles/line-color.style.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": {
|
||||
"mapbox": {
|
||||
"type": "vector",
|
||||
"url": "tiles/{z}-{x}-{y}.vector.pbf",
|
||||
"tileSize": 512,
|
||||
"maxZoom": 14
|
||||
}
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"style": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "road",
|
||||
"source": "mapbox",
|
||||
"source-layer": "road",
|
||||
"type": "line",
|
||||
"style": {
|
||||
"line-width": 2,
|
||||
"line-color": "#3590db"
|
||||
},
|
||||
"style.colored": {
|
||||
"line-color": "#222222"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
test/fixtures/styles/line-color/colored.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
test/fixtures/styles/line-color/default.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 78 KiB |
22
test/fixtures/styles/road-width.info.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"z13.9": {
|
||||
"zoom": 13.9,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256
|
||||
},
|
||||
"z14.0": {
|
||||
"zoom": 14,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256
|
||||
},
|
||||
"z14.1": {
|
||||
"zoom": 14.1,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256
|
||||
},
|
||||
"z14.2": {
|
||||
"zoom": 14.2,
|
||||
"center": [52.499167, 13.418056],
|
||||
"height": 256
|
||||
}
|
||||
}
|
||||
32
test/fixtures/styles/road-width.style.json
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": {
|
||||
"mapbox": {
|
||||
"type": "vector",
|
||||
"url": "tiles/{z}-{x}-{y}.vector.pbf",
|
||||
"tileSize": 512,
|
||||
"maxZoom": 14
|
||||
}
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"style": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "road",
|
||||
"source": "mapbox",
|
||||
"source-layer": "road",
|
||||
"type": "line",
|
||||
"style": {
|
||||
"line-width": {
|
||||
"fn": "stops",
|
||||
"stops": [[13, 0], [13.999, 0], [14, 4], [14.1, 10], [14.2, 20]]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
test/fixtures/styles/road-width/z13.9.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
test/fixtures/styles/road-width/z14.0.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
test/fixtures/styles/road-width/z14.1.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
test/fixtures/styles/road-width/z14.2.expected.png
vendored
Normal file
|
After Width: | Height: | Size: 23 KiB |
6
test/fixtures/styles/world-aa.info.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plain": {
|
||||
"center": [0, 0],
|
||||
"zoom": 0
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
6
test/fixtures/styles/world-no-aa.info.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"plain": {
|
||||
"center": [0, 0],
|
||||
"zoom": 0
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
BIN
test/fixtures/tiles/14-8802-5374.vector.pbf
vendored
Normal file
BIN
test/fixtures/tiles/14-8802-5375.vector.pbf
vendored
Normal file
BIN
test/fixtures/tiles/14-8803-5374.vector.pbf
vendored
Normal file
BIN
test/fixtures/tiles/14-8803-5375.vector.pbf
vendored
Normal file
@@ -63,7 +63,7 @@ TEST(Function, Linear) {
|
||||
|
||||
|
||||
TEST(Function, Exponential) {
|
||||
llmr::ExponentialFunction<float> slope_1(/* val */ 7.5, /* z_base */ 4, /* slope */ 2, /* min */ 7.5, /* max */ 20);
|
||||
llmr::ExponentialFunction<float> slope_1(/* val */ 7.5, /* z_base */ 4, /* exp_base */ 1.75, /* slope */ 2, /* min */ 7.5, /* max */ 20);
|
||||
ASSERT_FLOAT_EQ(8.6428576, slope_1.evaluate(3)); // 7.5 + 1.75^(3 - 4) * 2
|
||||
ASSERT_FLOAT_EQ(9.5, slope_1.evaluate(4)); // 7.5 + 1.75^(4 - 4) * 2
|
||||
ASSERT_FLOAT_EQ(10.145751, slope_1.evaluate(4.5)); // 7.5 + 1.75^(4.5 - 4) * 2
|
||||
|
||||
@@ -9,61 +9,94 @@
|
||||
|
||||
#include "../common/headless_view.hpp"
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
const std::string base_directory = []{
|
||||
std::string fn = __FILE__;
|
||||
fn.erase(fn.find_last_of("/"));
|
||||
return fn;
|
||||
return fn + "/fixtures/styles";
|
||||
}();
|
||||
|
||||
class HeadlessTest : public ::testing::TestWithParam<const char *> {};
|
||||
class HeadlessTest : public ::testing::TestWithParam<std::string> {};
|
||||
|
||||
TEST_P(HeadlessTest, render) {
|
||||
const char *base = GetParam();
|
||||
const std::string &base = GetParam();
|
||||
|
||||
const std::string style = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".style.json");
|
||||
const std::string info = llmr::util::read_file(base_directory + "/fixtures/styles/" + base + ".info.json");
|
||||
const std::string expected_image = base_directory + "/fixtures/styles/" + base + ".expected.png";
|
||||
const std::string actual_image = base_directory + "/fixtures/styles/" + base + ".actual.png";
|
||||
const std::string style = llmr::util::read_file(base_directory + "/" + base + ".style.json");
|
||||
const std::string info = llmr::util::read_file(base_directory + "/" + base + ".info.json");
|
||||
|
||||
// Parse settings.
|
||||
rapidjson::Document doc;
|
||||
doc.Parse<0>((const char *const)info.c_str());
|
||||
ASSERT_EQ(false, doc.HasParseError());
|
||||
|
||||
const double zoom = doc.HasMember("zoom") ? doc["zoom"].GetDouble() : 0;
|
||||
const double angle = doc.HasMember("angle") ? doc["angle"].GetDouble() : 0;
|
||||
const double longitude = doc.HasMember("longitude") ? doc["longitude"].GetDouble() : 0;
|
||||
const double latitude = doc.HasMember("latitude") ? doc["latitude"].GetDouble() : 0;
|
||||
const unsigned int width = doc.HasMember("width") ? doc["width"].GetUint() : 0;
|
||||
const unsigned int height = doc.HasMember("height") ? doc["height"].GetUint() : 0;
|
||||
ASSERT_EQ(true, doc.IsObject());
|
||||
|
||||
// Setup OpenGL
|
||||
llmr::HeadlessView view;
|
||||
llmr::Map map(view);
|
||||
|
||||
view.resize(width, height);
|
||||
map.resize(width, height);
|
||||
for (auto it = doc.MemberBegin(), end = doc.MemberEnd(); it != end; it++) {
|
||||
const std::string name { it->name.GetString(), it->name.GetStringLength() };
|
||||
const rapidjson::Value &value = it->value;
|
||||
ASSERT_EQ(true, value.IsObject());
|
||||
if (value.HasMember("center")) ASSERT_EQ(true, value["center"].IsArray());
|
||||
|
||||
map.setStyleJSON(style);
|
||||
const std::string actual_image = base_directory + "/" + base + "/" + name + ".actual.png";
|
||||
|
||||
map.setLonLatZoom(longitude, latitude, zoom);
|
||||
map.setAngle(angle);
|
||||
map.setDebug(false);
|
||||
const double zoom = value.HasMember("zoom") ? value["zoom"].GetDouble() : 0;
|
||||
const double bearing = value.HasMember("bearing") ? value["bearing"].GetDouble() : 0;
|
||||
const double latitude = value.HasMember("center") ? value["center"][rapidjson::SizeType(0)].GetDouble() : 0;
|
||||
const double longitude = value.HasMember("center") ? value["center"][rapidjson::SizeType(1)].GetDouble() : 0;
|
||||
const unsigned int width = value.HasMember("width") ? value["width"].GetUint() : 512;
|
||||
const unsigned int height = value.HasMember("height") ? value["height"].GetUint() : 512;
|
||||
std::vector<std::string> classes;
|
||||
if (value.HasMember("classes")) {
|
||||
const rapidjson::Value &js_classes = value["classes"];
|
||||
ASSERT_EQ(true, js_classes.IsArray());
|
||||
for (rapidjson::SizeType i = 0; i < js_classes.Size(); i++) {
|
||||
const rapidjson::Value &js_class = js_classes[i];
|
||||
ASSERT_EQ(true, js_class.IsString());
|
||||
classes.push_back({ js_class.GetString(), js_class.GetStringLength() });
|
||||
}
|
||||
}
|
||||
|
||||
// Run the loop. It will terminate when we don't have any further listeners.
|
||||
map.run();
|
||||
map.setStyleJSON(style);
|
||||
map.setAppliedClasses(classes);
|
||||
|
||||
const std::unique_ptr<uint32_t[]> pixels(new uint32_t[width * height]);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
|
||||
view.resize(width, height);
|
||||
map.resize(width, height);
|
||||
map.setLonLatZoom(longitude, latitude, zoom);
|
||||
map.setAngle(bearing);
|
||||
|
||||
const std::string image = llmr::util::compress_png(width, height, pixels.get(), true);
|
||||
llmr::util::write_file(actual_image, image);
|
||||
// Run the loop. It will terminate when we don't have any further listeners.
|
||||
map.run();
|
||||
|
||||
const std::unique_ptr<uint32_t[]> pixels(new uint32_t[width * height]);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
|
||||
|
||||
const std::string image = llmr::util::compress_png(width, height, pixels.get(), true);
|
||||
llmr::util::write_file(actual_image, image);
|
||||
}
|
||||
|
||||
const std::string expected_image_data(llmr::util::read_file(expected_image));
|
||||
const llmr::util::Image expected(expected_image_data, true);
|
||||
ASSERT_EQ(width, expected.getWidth());
|
||||
ASSERT_EQ(height, expected.getHeight());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest,
|
||||
::testing::Values("0", "1"));
|
||||
INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest, ::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;
|
||||
}()));
|
||||
|
||||