diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-16 13:32:25 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-06-16 14:09:51 +0300 |
commit | 4623baa1a5f549f90e5066672890714647d0fb1a (patch) | |
tree | fdb2dba0012123f7e5c0b94acf1013be14ccd455 /test/api | |
parent | 57c34747a24bc2c3e5b27e17c1991d6b9a4aa68c (diff) | |
download | qtlocation-mapboxgl-4623baa1a5f549f90e5066672890714647d0fb1a.tar.gz |
Add tests for renderStill() misuse
Diffstat (limited to 'test/api')
-rw-r--r-- | test/api/api_misuse.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/api/api_misuse.cpp b/test/api/api_misuse.cpp new file mode 100644 index 0000000000..a98cf04101 --- /dev/null +++ b/test/api/api_misuse.cpp @@ -0,0 +1,60 @@ +#include "../fixtures/util.hpp" +#include "../fixtures/fixture_log_observer.hpp" + +#include <mbgl/map/map.hpp> +#include <mbgl/map/still_image.hpp> +#include <mbgl/platform/default/headless_display.hpp> +#include <mbgl/platform/default/headless_view.hpp> +#include <mbgl/storage/default_file_source.hpp> +#include <mbgl/util/exception.hpp> + +#include <future> + +using namespace mbgl; + +TEST(API, RenderWithoutCallback) { + FixtureLogObserver* log = new FixtureLogObserver(); + Log::setObserver(std::unique_ptr<Log::Observer>(log)); + + auto display = std::make_shared<mbgl::HeadlessDisplay>(); + HeadlessView view(display); + DefaultFileSource fileSource(nullptr); + + std::unique_ptr<Map> map = std::make_unique<Map>(view, fileSource, MapMode::Still); + map->resize(128, 512, 1); + 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) { + auto display = std::make_shared<mbgl::HeadlessDisplay>(); + HeadlessView view(display); + DefaultFileSource fileSource(nullptr); + + Map map(view, fileSource, MapMode::Still); + map.resize(128, 512, 1); + + std::promise<std::exception_ptr> promise; + map.renderStill([&promise](std::exception_ptr error, std::unique_ptr<const StillImage>) { + promise.set_value(error); + }); + + try { + std::rethrow_exception(promise.get_future().get()); + } 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."; + } +} |