diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-09-02 16:53:41 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-09-04 10:52:14 -0700 |
commit | 15a66b8989645b702d207d96f6693ea3ddd93bdc (patch) | |
tree | 8f60f1e62f54a8a3afce280ddc48a1a3bef5da70 /test | |
parent | e49ef97a500d7c0afa5bf55d311dc5239ccddd2a (diff) | |
download | qtlocation-mapboxgl-15a66b8989645b702d207d96f6693ea3ddd93bdc.tar.gz |
Consolidate test-suite rendering harnesses (#2236)
Diffstat (limited to 'test')
-rw-r--r-- | test/api/repeated_render.cpp | 2 | ||||
-rw-r--r-- | test/api/set_style.cpp | 2 | ||||
-rw-r--r-- | test/headless/headless.cpp | 184 | ||||
-rwxr-xr-x | test/headless/server.js | 19 | ||||
-rw-r--r-- | test/miscellaneous/custom_sprites.cpp (renamed from test/headless/custom_sprites.cpp) | 2 | ||||
m--------- | test/suite | 0 | ||||
-rw-r--r-- | test/test.gypi | 3 |
7 files changed, 4 insertions, 208 deletions
diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp index f8b92b85b8..3317b4e3a4 100644 --- a/test/api/repeated_render.cpp +++ b/test/api/repeated_render.cpp @@ -25,7 +25,7 @@ TEST(API, RepeatedRender) { Map map(view, fileSource, MapMode::Still); { - map.setStyleJSON(style, "test/suite"); + map.setStyleJSON(style, ""); std::promise<std::unique_ptr<const StillImage>> promise; map.renderStill([&promise](std::exception_ptr, std::unique_ptr<const StillImage> image) { promise.set_value(std::move(image)); diff --git a/test/api/set_style.cpp b/test/api/set_style.cpp index db31254dbb..c3e62def20 100644 --- a/test/api/set_style.cpp +++ b/test/api/set_style.cpp @@ -18,7 +18,7 @@ TEST(API, SetStyle) { { Map map(view, fileSource, MapMode::Still); - map.setStyleJSON("invalid", "test/suite"); + map.setStyleJSON("invalid", ""); } auto observer = Log::removeObserver(); diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp deleted file mode 100644 index 80951433ed..0000000000 --- a/test/headless/headless.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include "../fixtures/util.hpp" -#include "../fixtures/fixture_log_observer.hpp" - -#include <mbgl/map/map.hpp> -#include <mbgl/map/still_image.hpp> -#include <mbgl/util/image.hpp> - -#include <mbgl/util/io.hpp> -#include <rapidjson/document.h> -#include <rapidjson/writer.h> -#include <rapidjson/stringbuffer.h> - -#include <mbgl/platform/platform.hpp> -#include <mbgl/platform/default/headless_view.hpp> -#include <mbgl/platform/default/headless_display.hpp> -#include <mbgl/storage/default_file_source.hpp> - -#include <dirent.h> - -#include <future> - -void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator) { - ASSERT_TRUE(value.IsString()); - auto string = std::string { value.GetString(),value.GetStringLength() }; - if (string.compare(0, 8, "local://") == 0) { - string.replace(0, 8, "http://127.0.0.1:2900/"); - value.SetString(string.data(), string.size(), allocator); - } -} - - -class HeadlessTest : public ::testing::TestWithParam<std::string> { -public: - static void SetUpTestCase() { - const auto server = mbgl::platform::applicationRoot() + "/TEST_DATA/headless/server.js"; - pid = mbgl::test::startServer(server.c_str()); - display = std::make_shared<mbgl::HeadlessDisplay>(); - } - - static void TearDownTestCase() { - display.reset(); - mbgl::test::stopServer(pid); - } - -protected: - static pid_t pid; - static std::shared_ptr<mbgl::HeadlessDisplay> display; -}; - -pid_t HeadlessTest::pid = 0; -std::shared_ptr<mbgl::HeadlessDisplay> HeadlessTest::display; - -TEST_P(HeadlessTest, render) { - using namespace mbgl; - - const std::string& base = GetParam(); - - std::string style = util::read_file("test/suite/tests/" + base + "/style.json"); - std::string info = util::read_file("test/suite/tests/" + base + "/info.json"); - - // Parse style. - rapidjson::Document styleDoc; - styleDoc.Parse<0>((const char *const)style.c_str()); - ASSERT_FALSE(styleDoc.HasParseError()); - ASSERT_TRUE(styleDoc.IsObject()); - - // Rewrite "local://" to "http://127.0.0.1:2900/". - if (styleDoc.HasMember("sprite")) { - rewriteLocalScheme(styleDoc["sprite"], styleDoc.GetAllocator()); - } - - if (styleDoc.HasMember("glyphs")) { - rewriteLocalScheme(styleDoc["glyphs"], styleDoc.GetAllocator()); - } - - if (styleDoc.HasMember("sources")) { - auto &sources = styleDoc["sources"]; - ASSERT_TRUE(sources.IsObject()); - for (auto source = sources.MemberBegin(), end = sources.MemberEnd(); source != end; source++) { - if (source->value.HasMember("tiles")) { - auto &tiles = source->value["tiles"]; - ASSERT_TRUE(tiles.IsArray()); - for (rapidjson::SizeType i = 0; i < tiles.Size(); i++) { - rewriteLocalScheme(tiles[i], styleDoc.GetAllocator()); - } - } - - if (source->value.HasMember("url") && source->value["url"].IsString()) { - rewriteLocalScheme(source->value["url"], styleDoc.GetAllocator()); - } - } - } - - // Convert the JSON object back into a stringified version. - rapidjson::StringBuffer buffer; - rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); - styleDoc.Accept(writer); - style = buffer.GetString(); - - // Parse settings. - rapidjson::Document infoDoc; - infoDoc.Parse<0>((const char *const)info.c_str()); - ASSERT_FALSE(infoDoc.HasParseError()); - ASSERT_TRUE(infoDoc.IsObject()); - - for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) { - const std::string name { - it->name.GetString(), it->name.GetStringLength() - }; - - Log::Info(Event::General, "%s %s", base.c_str(), name.c_str()); - - const rapidjson::Value& value = it->value; - ASSERT_TRUE(value.IsObject()); - - if (value.HasMember("native") && !value["native"].GetBool()) - continue; - - if (value.HasMember("center")) ASSERT_TRUE(value["center"].IsArray()); - - const std::string actual_image = "test/suite/tests/" + base + "/" + name + "/actual.png"; - - 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; - const unsigned int pixelRatio = value.HasMember("pixelRatio") ? value["pixelRatio"].GetUint() : 1; - - std::vector<std::string> classes; - if (value.HasMember("classes")) { - const rapidjson::Value& js_classes = value["classes"]; - ASSERT_TRUE(js_classes.IsArray()); - for (rapidjson::SizeType i = 0; i < js_classes.Size(); i++) { - const rapidjson::Value& js_class = js_classes[i]; - ASSERT_TRUE(js_class.IsString()); - classes.push_back({ js_class.GetString(), js_class.GetStringLength() }); - } - } - - std::promise<void> promise; - - HeadlessView view(display, pixelRatio, width, height); - DefaultFileSource fileSource(nullptr); - Map map(view, fileSource, MapMode::Still); - - map.setClasses(classes); - map.setStyleJSON(style, "test/suite"); - map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom); - map.setBearing(bearing); - - map.renderStill([&](std::exception_ptr error, std::unique_ptr<const StillImage> image) { - if (error) { - promise.set_exception(error); - return; - } - const std::string png = util::compress_png(image->width, image->height, image->pixels.get()); - util::write_file("test/suite/tests/" + base + "/" + name + "/actual.png", png); - promise.set_value(); - }); - - promise.get_future().get(); - } -} - -INSTANTIATE_TEST_CASE_P(Headless, HeadlessTest, ::testing::ValuesIn([] { - std::vector<std::string> names; - - const auto tests = mbgl::platform::applicationRoot() + "/TEST_DATA/suite/tests"; - DIR *dir = opendir(tests.c_str()); - if (dir != nullptr) { - for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) { - const std::string name = dp->d_name; - if (name != "index.html" && !(name.size() >= 1 && name[0] == '.')) { - names.push_back(name); - } - } - closedir(dir); - } - - EXPECT_GT(names.size(), 0ul); - return names; -}())); diff --git a/test/headless/server.js b/test/headless/server.js deleted file mode 100755 index ff349b050e..0000000000 --- a/test/headless/server.js +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env node -/* jshint node: true */ -'use strict'; - -var express = require('express'); -var app = express(); - -app.use(express.static('test/suite')); - -var server = app.listen(2900, function () { - var host = server.address().address; - var port = server.address().port; - console.log('Test server listening at http://%s:%s', host, port); - - if (process.argv[2]) { - // Allow the test to continue running. - process.stdin.write("Go!\n"); - } -}); diff --git a/test/headless/custom_sprites.cpp b/test/miscellaneous/custom_sprites.cpp index e2c479a5c2..a72119ea61 100644 --- a/test/headless/custom_sprites.cpp +++ b/test/miscellaneous/custom_sprites.cpp @@ -30,7 +30,7 @@ TEST(Headless, CustomSpriteImages) { map.setLatLngZoom(LatLng{ 52.499167, 13.418056 }, 15); - map.setStyleJSON(style, "test/suite"); + map.setStyleJSON(style, ""); map.setSprite("cafe", std::make_shared<SpriteImage>(12, 12, 1, std::string(12 * 12 * 4, '\xFF'))); std::promise<std::unique_ptr<const StillImage>> promise; diff --git a/test/suite b/test/suite deleted file mode 160000 -Subproject 023eb9512a2f73389f00e38fd9da272833992b3 diff --git a/test/test.gypi b/test/test.gypi index 4e669aee1d..a35b00133b 100644 --- a/test/test.gypi +++ b/test/test.gypi @@ -50,13 +50,12 @@ 'api/repeated_render.cpp', 'api/set_style.cpp', - 'headless/custom_sprites.cpp', - 'headless/headless.cpp', 'miscellaneous/clip_ids.cpp', 'miscellaneous/binpack.cpp', 'miscellaneous/bilinear.cpp', 'miscellaneous/comparisons.cpp', + 'miscellaneous/custom_sprites.cpp', 'miscellaneous/enums.cpp', 'miscellaneous/functions.cpp', 'miscellaneous/geo.cpp', |