diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index 565299b7a..e16b737da 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit 565299b7a18286802f0c49560f34b36835cf06de +Subproject commit e16b737daaf9ecd2a02f7ccc61a590e9df8b2050 diff --git a/scripts/compare_images.js b/scripts/compare_images.js index 258315756..ef854b038 100755 --- a/scripts/compare_images.js +++ b/scripts/compare_images.js @@ -33,33 +33,45 @@ function processFiles() { var name = files.shift(); var info = require(path.join(base_dir, name)); - var base = path.basename(name, '.info.json'); - var actual = path.join(base_dir, base + '.actual.png'); - var expected = path.join(base_dir, base + '.expected.png'); - var diff = path.join(base_dir, base + '.diff.png'); + var keys = Object.keys(info); - var compare = spawn('compare', ['-metric', 'MAE', actual, expected, diff ]); - var error = ''; - compare.stderr.on('data', function(data) { - error += data.toString(); - }); - compare.on('exit', function(code, signal) { - // The compare program returns 2 on error otherwise 0 if the images are similar or 1 if they are dissimilar. - if (code == 2) { - writeResult(base, info, error.trim(), Infinity); - exitCode = 2; - } else { - var difference = parseFloat(error.match(/^\d+(?:\.\d+)?\s+\(([^\)]+)\)\s*$/)[1]); - writeResult(base, info, '', difference); + processFileTest(); - } - return processFiles(); - }); - compare.stdin.end(); + function processFileTest() { + if (!keys.length) return processFiles(); + + var key = keys.shift(); + + var base = path.basename(name, '.info.json'); + + var actual = path.join(base_dir, base + '/' + key + '.actual.png'); + var expected = path.join(base_dir, base + '/' + key + '.expected.png'); + var diff = path.join(base_dir, base + '/' + key + '.diff.png'); + + var compare = spawn('compare', ['-metric', 'MAE', actual, expected, diff ]); + var error = ''; + compare.stderr.on('data', function(data) { + error += data.toString(); + }); + compare.on('exit', function(code, signal) { + // The compare program returns 2 on error otherwise 0 if the images are similar or 1 if they are dissimilar. + if (code == 2) { + writeResult(base, key, info[key], error.trim(), Infinity); + exitCode = 2; + } else { + var match = error.match(/^\d+(?:\.\d+)?\s+\(([^\)]+)\)\s*$/); + var difference = match ? parseFloat(match[1]) : Infinity; + writeResult(base, key, info[key], match ? '' : error, difference); + + } + processFileTest(); + }); + compare.stdin.end(); + } } -function writeResult(base, info, error, difference) { +function writeResult(base, key, info, error, difference) { var color = 'green'; var allowedDifference = ('diff' in info) ? info.diff : 0.01; if (difference > allowedDifference) { @@ -72,19 +84,18 @@ function writeResult(base, info, error, difference) { html += '\n' + - ' \n' + - ' \n' + + ' \n' + + ' \n' + ' \n' + - '

' + base + '

\n' + + '

' + base + '/' + key + '

\n' + (error ? '

' + error + '

\n' : '') + ' \n' + ' \n' + '\n' diff --git a/test/fixtures/styles/0.info.json b/test/fixtures/styles/0.info.json deleted file mode 100644 index 3501d30ed..000000000 --- a/test/fixtures/styles/0.info.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "zoom": 0, - "latitude": 0, - "longitude": 0, - "angle": 0, - "width": 512, - "height": 512 -} diff --git a/test/fixtures/styles/1.info.json b/test/fixtures/styles/1.info.json deleted file mode 100644 index 3501d30ed..000000000 --- a/test/fixtures/styles/1.info.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "zoom": 0, - "latitude": 0, - "longitude": 0, - "angle": 0, - "width": 512, - "height": 512 -} diff --git a/test/fixtures/styles/road-width.expected.png b/test/fixtures/styles/road-width.expected.png deleted file mode 100644 index 0c8205ad9..000000000 Binary files a/test/fixtures/styles/road-width.expected.png and /dev/null differ diff --git a/test/fixtures/styles/road-width.info.json b/test/fixtures/styles/road-width.info.json index 85808bb80..0c7033e4e 100644 --- a/test/fixtures/styles/road-width.info.json +++ b/test/fixtures/styles/road-width.info.json @@ -1,8 +1,22 @@ { - "zoom": 14, - "latitude": 52.499167, - "longitude": 13.418056, - "angle": 0, - "width": 512, - "height": 512 + "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 + } } diff --git a/test/fixtures/styles/road-width.style.json b/test/fixtures/styles/road-width.style.json index 469a376bc..5738546b3 100644 --- a/test/fixtures/styles/road-width.style.json +++ b/test/fixtures/styles/road-width.style.json @@ -24,7 +24,7 @@ "style": { "line-width": { "fn": "stops", - "stops": [[13, 0], [13.999, 0], [14, 4], [14.1, 100]] + "stops": [[13, 0], [13.999, 0], [14, 4], [14.1, 10], [14.2, 20]] } } } diff --git a/test/fixtures/styles/road-width/z13.9.expected.png b/test/fixtures/styles/road-width/z13.9.expected.png new file mode 100644 index 000000000..e65d3339d Binary files /dev/null and b/test/fixtures/styles/road-width/z13.9.expected.png differ diff --git a/test/fixtures/styles/road-width/z14.0.expected.png b/test/fixtures/styles/road-width/z14.0.expected.png new file mode 100644 index 000000000..01444c6f8 Binary files /dev/null and b/test/fixtures/styles/road-width/z14.0.expected.png differ diff --git a/test/fixtures/styles/road-width/z14.1.expected.png b/test/fixtures/styles/road-width/z14.1.expected.png new file mode 100644 index 000000000..3a28f3c4d Binary files /dev/null and b/test/fixtures/styles/road-width/z14.1.expected.png differ diff --git a/test/fixtures/styles/road-width/z14.2.expected.png b/test/fixtures/styles/road-width/z14.2.expected.png new file mode 100644 index 000000000..8cd62453c Binary files /dev/null and b/test/fixtures/styles/road-width/z14.2.expected.png differ diff --git a/test/fixtures/styles/world-aa.info.json b/test/fixtures/styles/world-aa.info.json new file mode 100644 index 000000000..3a61efdd1 --- /dev/null +++ b/test/fixtures/styles/world-aa.info.json @@ -0,0 +1,6 @@ +{ + "plain": { + "center": [0, 0], + "zoom": 0 + } +} diff --git a/test/fixtures/styles/1.style.json b/test/fixtures/styles/world-aa.style.json similarity index 100% rename from test/fixtures/styles/1.style.json rename to test/fixtures/styles/world-aa.style.json diff --git a/test/fixtures/styles/1.expected.png b/test/fixtures/styles/world-aa/plain.expected.png similarity index 100% rename from test/fixtures/styles/1.expected.png rename to test/fixtures/styles/world-aa/plain.expected.png diff --git a/test/fixtures/styles/world-no-aa.info.json b/test/fixtures/styles/world-no-aa.info.json new file mode 100644 index 000000000..3a61efdd1 --- /dev/null +++ b/test/fixtures/styles/world-no-aa.info.json @@ -0,0 +1,6 @@ +{ + "plain": { + "center": [0, 0], + "zoom": 0 + } +} diff --git a/test/fixtures/styles/0.style.json b/test/fixtures/styles/world-no-aa.style.json similarity index 100% rename from test/fixtures/styles/0.style.json rename to test/fixtures/styles/world-no-aa.style.json diff --git a/test/fixtures/styles/0.expected.png b/test/fixtures/styles/world-no-aa/plain.expected.png similarity index 100% rename from test/fixtures/styles/0.expected.png rename to test/fixtures/styles/world-no-aa/plain.expected.png diff --git a/test/headless.cpp b/test/headless.cpp index 71bef62b9..a93c03ce9 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -24,41 +24,49 @@ TEST_P(HeadlessTest, render) { 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"); - const std::string actual_image = base_directory + "/" + base + ".actual.png"; // 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; - // Run the loop. It will terminate when we don't have any further listeners. - map.run(); + map.setStyleJSON(style); - const std::unique_ptr 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); + + // Run the loop. It will terminate when we don't have any further listeners. + map.run(); + + const std::unique_ptr 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 image = llmr::util::compress_png(width, height, pixels.get(), true); - llmr::util::write_file(actual_image, image); } INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest, ::testing::ValuesIn([] {