From 1c920c433274095af37a3da89207e9ea03df64ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 16 Apr 2015 16:11:40 +0200 Subject: [PATCH] don't throw an exception in the map thread for bad styles --- src/mbgl/style/style.cpp | 3 +-- src/mbgl/util/error.hpp | 20 -------------------- test/api/set_style.cpp | 32 ++++++++++++++++++++++++++++++++ test/test.gyp | 2 ++ 4 files changed, 35 insertions(+), 22 deletions(-) delete mode 100644 src/mbgl/util/error.hpp create mode 100644 test/api/set_style.cpp diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 2fb3ccabc..0a2a53075 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -75,7 +74,7 @@ void Style::loadJSON(const uint8_t *const data) { doc.Parse<0>((const char *const)data); if (doc.HasParseError()) { Log::Error(Event::ParseStyle, "Error parsing style JSON at %i: %s", doc.GetErrorOffset(), doc.GetParseError()); - throw error::style_parse(doc.GetErrorOffset(), doc.GetParseError()); + return; } StyleParser parser; diff --git a/src/mbgl/util/error.hpp b/src/mbgl/util/error.hpp deleted file mode 100644 index 09fa8d3e2..000000000 --- a/src/mbgl/util/error.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MBGL_UTIL_ERROR -#define MBGL_UTIL_ERROR - -#include -#include - -namespace mbgl { -namespace error { - -struct style_parse : std::exception { - inline style_parse(size_t offset_, const char *msg_) : offset(offset_), msg(msg_) {} - inline const char* what() const noexcept { return msg.c_str(); } - const size_t offset; - const std::string msg; -}; -} - -} - -#endif \ No newline at end of file diff --git a/test/api/set_style.cpp b/test/api/set_style.cpp new file mode 100644 index 000000000..5a5013acc --- /dev/null +++ b/test/api/set_style.cpp @@ -0,0 +1,32 @@ +#include "../fixtures/util.hpp" +#include "../fixtures/fixture_log_observer.hpp" + +#include +#include +#include +#include + + +TEST(API, SetStyle) { + using namespace mbgl; + + auto display = std::make_shared(); + HeadlessView view(display); + DefaultFileSource fileSource(nullptr); + + Log::setObserver(util::make_unique()); + + Map map(view, fileSource); + + map.start(Map::Mode::Static); + + map.setStyleJSON("invalid", "test/suite"); + + map.stop(); + + auto observer = Log::removeObserver(); + auto flo = dynamic_cast(observer.get()); + EXPECT_EQ(1ul, flo->count({ EventSeverity::Error, Event::ParseStyle, -1, + "Error parsing style JSON at 0: Expect either an object or array at root" })); + EXPECT_TRUE(flo->unchecked().empty()); +} diff --git a/test/test.gyp b/test/test.gyp index d9e234fe0..2f14a4477 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -35,6 +35,8 @@ 'fixtures/fixture_log_observer.hpp', 'fixtures/fixture_log_observer.cpp', + 'api/set_style.cpp', + 'headless/headless.cpp', 'miscellaneous/clip_ids.cpp',