summaryrefslogtreecommitdiff
path: root/test/api/api_misuse.test.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-28 11:45:33 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-28 16:34:22 +0200
commit3f3fc7b7723698e44427e2a14a2f4906832800bf (patch)
tree5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/api/api_misuse.test.cpp
parenta8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff)
downloadqtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/api/api_misuse.test.cpp')
-rw-r--r--test/api/api_misuse.test.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/api/api_misuse.test.cpp b/test/api/api_misuse.test.cpp
new file mode 100644
index 0000000000..e9fe307718
--- /dev/null
+++ b/test/api/api_misuse.test.cpp
@@ -0,0 +1,67 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/test/stub_file_source.hpp>
+#include <mbgl/test/fixture_log_observer.hpp>
+
+#include <mbgl/map/map.hpp>
+#include <mbgl/platform/default/headless_display.hpp>
+#include <mbgl/storage/online_file_source.hpp>
+#include <mbgl/util/exception.hpp>
+#include <mbgl/util/run_loop.hpp>
+
+#include <future>
+
+using namespace mbgl;
+
+TEST(API, RenderWithoutCallback) {
+ auto log = new FixtureLogObserver();
+ Log::setObserver(std::unique_ptr<Log::Observer>(log));
+
+ util::RunLoop loop;
+
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ view.resize(128, 512);
+ StubFileSource fileSource;
+
+ std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still);
+ map->renderStill(nullptr);
+
+ // Force Map thread to join.
+ map.reset();
+
+ const FixtureLogObserver::LogMessage logMessage {
+ EventSeverity::Error,
+ Event::General,
+ int64_t(-1),
+ "StillImageCallback not set",
+ };
+
+ EXPECT_EQ(log->count(logMessage), 1u);
+}
+
+TEST(API, RenderWithoutStyle) {
+ util::RunLoop loop;
+
+ auto display = std::make_shared<mbgl::HeadlessDisplay>();
+ HeadlessView view(display, 1);
+ view.resize(128, 512);
+ StubFileSource fileSource;
+
+ Map map(view, fileSource, MapMode::Still);
+
+ std::exception_ptr error;
+ map.renderStill([&](std::exception_ptr error_, PremultipliedImage&&) {
+ error = error_;
+ loop.stop();
+ });
+
+ loop.run();
+
+ try {
+ std::rethrow_exception(error);
+ } catch (const util::MisuseException& ex) {
+ EXPECT_EQ(std::string(ex.what()), "Map doesn't have a style");
+ } catch (const std::exception&) {
+ EXPECT_TRUE(false) << "Unhandled exception.";
+ }
+}