Esempio n. 1
0
TEST(API, RenderWithoutCallback) {
    auto log = new FixtureLogObserver();
    Log::setObserver(std::unique_ptr<Log::Observer>(log));

    util::RunLoop loop;

    HeadlessBackend backend { test::sharedDisplay() };
    OffscreenView view { backend.getContext(), { 128, 512 } };
    StubFileSource fileSource;
    ThreadPool threadPool(4);

    std::unique_ptr<Map> map =
        std::make_unique<Map>(backend, view.size, 1, fileSource, threadPool, MapMode::Still);
    map->renderStill(view, 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);
}
Esempio n. 2
0
TEST(API, RenderWithoutStyle) {
    util::RunLoop loop;

    HeadlessBackend backend { test::sharedDisplay() };
    OffscreenView view { backend.getContext(), { 128, 512 } };
    StubFileSource fileSource;
    ThreadPool threadPool(4);

    Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Still);

    std::exception_ptr error;
    map.renderStill(view, [&](std::exception_ptr error_) {
        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.";
    }
}
TEST(API, TEST_REQUIRES_SERVER(RenderMissingTile)) {
    using namespace mbgl;

    util::RunLoop loop;

    const auto style = util::read_file("test/fixtures/api/water_missing_tiles.json");

    HeadlessBackend backend;
    OffscreenView view(backend.getContext(), { 256, 512 });
#ifdef MBGL_ASSET_ZIP
    // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/`
    DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip");
#else
    DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
#endif

    ThreadPool threadPool(4);

    Log::setObserver(std::make_unique<FixtureLogObserver>());

    Map map(backend, view.size, 1, fileSource, threadPool, MapMode::Still);

    std::string message;

    // This host does not respond (== connection error).
    // Are you seeing this test fail? Make sure you don't have a server running on port 3001!
    map.setStyleJSON(style);
    map.renderStill(view, [&](std::exception_ptr err) {
        ASSERT_TRUE(err.operator bool());
        try {
            std::rethrow_exception(err);
        } catch (const std::exception& ex) {
            message = ex.what();
            EXPECT_TRUE(message.find("onnect") != std::string::npos); // [C|c]onnect
        }
        loop.stop();
    });

    loop.run();

    auto observer = Log::removeObserver();
    auto flo = dynamic_cast<FixtureLogObserver*>(observer.get());
    EXPECT_EQ(1u, flo->count(FixtureLog::Message(
                     EventSeverity::Error, Event::Style, -1,
                     std::string("Failed to load tile 0/0/0=>0 for source mapbox: " + message))));
    auto unchecked = flo->unchecked();
    EXPECT_TRUE(unchecked.empty()) << unchecked;
}
Esempio n. 4
0
TEST(GLObject, Store) {
    HeadlessBackend backend { test::sharedDisplay() };
    OffscreenView view(backend.getContext());

    gl::Context context;
    EXPECT_TRUE(context.empty());

    gl::UniqueTexture texture = context.createTexture();
    EXPECT_NE(texture.get(), 0u);
    texture.reset();
    EXPECT_FALSE(context.empty());
    context.performCleanup();
    EXPECT_FALSE(context.empty());
    context.reset();
    EXPECT_TRUE(context.empty());

    context.reset();
    EXPECT_TRUE(context.empty());

    backend.deactivate();
}