Add tests for renderStill() misuse

This commit is contained in:
Thiago Marcos P. Santos
2015-06-16 13:32:25 +03:00
parent 57c34747a2
commit 4623baa1a5
2 changed files with 62 additions and 1 deletions

60
test/api/api_misuse.cpp Normal file
View File

@@ -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.";
}
}