From 7c22792bdfa1f89990736bd8ef67cb4e5e64220f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 22 Dec 2015 16:32:25 -0800 Subject: [PATCH] [tests] Rewrite resource loading test Make it more readable and easier to debug. --- include/mbgl/platform/log.hpp | 6 + include/mbgl/util/string.hpp | 9 + test/fixtures/resources/style.json | 2 +- test/style/resource_loading.cpp | 253 +++++++++++++---------------- 4 files changed, 131 insertions(+), 139 deletions(-) diff --git a/include/mbgl/platform/log.hpp b/include/mbgl/platform/log.hpp index a2a911990..cd072c37d 100644 --- a/include/mbgl/platform/log.hpp +++ b/include/mbgl/platform/log.hpp @@ -21,6 +21,12 @@ public: virtual bool onRecord(EventSeverity severity, Event event, int64_t code, const std::string &msg) = 0; }; + class NullObserver : public Observer { + bool onRecord(EventSeverity, Event, int64_t, const std::string&) override { + return true; + } + }; + static void setObserver(std::unique_ptr Observer); static std::unique_ptr removeObserver(); diff --git a/include/mbgl/util/string.hpp b/include/mbgl/util/string.hpp index 9e2b2d881..bc6b3b1ef 100644 --- a/include/mbgl/util/string.hpp +++ b/include/mbgl/util/string.hpp @@ -22,6 +22,15 @@ inline std::string toString(int8_t num) { return boost::lexical_cast(int(num)); } +inline std::string toString(std::exception_ptr error) { + try { + std::rethrow_exception(error); + } catch (const std::exception& ex) { + return ex.what(); + } catch (...) { + return "Unknown exception type"; + } +} template inline std::string sprintf(const char *msg, Args... args) { diff --git a/test/fixtures/resources/style.json b/test/fixtures/resources/style.json index f794d54fa..858e2de03 100644 --- a/test/fixtures/resources/style.json +++ b/test/fixtures/resources/style.json @@ -9,7 +9,7 @@ "rastersource": { "url": "test/fixtures/resources/source_raster.json", "type": "raster", - "tileSize": 256 + "tileSize": 512 } }, "sprite": "test/fixtures/resources/sprite", diff --git a/test/style/resource_loading.cpp b/test/style/resource_loading.cpp index ba6a138b5..833087984 100644 --- a/test/style/resource_loading.cpp +++ b/test/style/resource_loading.cpp @@ -11,164 +11,141 @@ #include #include #include - -#include +#include using namespace mbgl; -namespace { - -class MockMapContext : public Style::Observer { +class StyleObserver : public Style::Observer { public: - MockMapContext(View& view, - FileSource& fileSource, - const std::function& callback) - : data_(MapMode::Still, GLContextMode::Unique, view.getPixelRatio()), - transform_(view, ConstrainMode::HeightOnly), - callback_(callback) { - util::ThreadContext::setFileSource(&fileSource); - - transform_.resize({{ 1000, 1000 }}); - transform_.setLatLngZoom({0, 0}, 16); - - const std::string style = util::read_file("test/fixtures/resources/style.json"); - style_ = std::make_unique