From 8f03d437601953d82d5eb34f8f20c37e1fb3c25d Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Wed, 2 Jun 2021 21:41:25 -0500 Subject: [PATCH 01/10] [qt] Updating CMake project files for Qt6 --- CMakeLists.txt | 2 +- platform/qt/qt.cmake | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad989ba8386..46972698292 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) if(MBGL_WITH_QT) - find_package(Qt5Core REQUIRED) + find_package(Qt6Core REQUIRED) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) endif() diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 8184d5079c5..dbf5b9873e6 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -1,9 +1,9 @@ # Note: Using Sqlite instead of QSqlDatabase for better compatibility. -find_package(Qt5Gui REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5OpenGL REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt6Gui REQUIRED) +find_package(Qt6Network REQUIRED) +find_package(Qt6OpenGL REQUIRED) +find_package(Qt6Widgets REQUIRED) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_definitions("-DQT_COMPILING_QIMAGE_COMPAT_CPP") @@ -88,10 +88,10 @@ target_link_libraries( PRIVATE $<$>:z> $<$>:mbgl-vendor-icu> - Qt5::Core - Qt5::Gui - Qt5::Network - Qt5::OpenGL + Qt6::Core + Qt6::Gui + Qt6::Network + Qt6::OpenGL mbgl-vendor-nunicode mbgl-vendor-sqlite ) @@ -135,8 +135,8 @@ target_compile_definitions( target_link_libraries( qmapboxgl PRIVATE - Qt5::Core - Qt5::Gui + Qt6::Core + Qt6::Gui mbgl-compiler-options mbgl-core ) @@ -155,8 +155,8 @@ set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98) target_link_libraries( mbgl-qt PRIVATE - Qt5::Widgets - Qt5::Gui + Qt6::Widgets + Qt6::Gui mbgl-compiler-options qmapboxgl ) @@ -179,8 +179,8 @@ target_compile_definitions( target_link_libraries( mbgl-test-runner PRIVATE - Qt5::Gui - Qt5::OpenGL + Qt6::Gui + Qt6::OpenGL mbgl-compiler-options pthread ) From a780f90f441cf23ba32369e10590137335b4a701 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 4 Jun 2021 21:59:51 -0500 Subject: [PATCH 02/10] [qt] Updating non-test projects for Qt6 and msvc2019 --- include/mbgl/style/expression/expression.hpp | 3 ++ include/mbgl/style/expression/value.hpp | 3 ++ include/mbgl/util/enum.hpp | 32 +++++++++---------- .../default/src/mbgl/gl/headless_backend.cpp | 2 ++ platform/default/src/mbgl/storage/sqlite3.cpp | 8 +++-- .../default/src/mbgl/util/compression.cpp | 8 ++++- platform/qt/app/mapwindow.cpp | 8 ++--- platform/qt/qt.cmake | 9 +++++- platform/qt/src/headless_backend_qt.cpp | 4 +-- platform/qt/src/http_file_source.cpp | 1 - platform/qt/src/local_glyph_rasterizer.cpp | 6 ++-- platform/qt/src/qmapboxgl.cpp | 4 +-- platform/qt/src/qt_image.cpp | 4 +-- platform/qt/test/main.cpp | 7 +++- src/mbgl/gfx/attribute.hpp | 24 ++++++++------ src/mbgl/gl/context.cpp | 3 +- src/mbgl/gl/context.hpp | 4 +-- src/mbgl/gl/index_buffer_resource.cpp | 2 +- src/mbgl/gl/index_buffer_resource.hpp | 2 +- src/mbgl/gl/offscreen_texture.cpp | 2 ++ src/mbgl/gl/renderbuffer_resource.hpp | 2 ++ src/mbgl/gl/texture_resource.cpp | 2 +- src/mbgl/gl/texture_resource.hpp | 2 +- src/mbgl/gl/vertex_buffer_resource.cpp | 2 +- src/mbgl/gl/vertex_buffer_resource.hpp | 2 +- src/mbgl/layout/symbol_layout.cpp | 8 ++--- src/mbgl/layout/symbol_projection.cpp | 2 +- src/mbgl/style/expression/coercion.cpp | 4 +-- .../style/expression/compound_expression.cpp | 2 +- src/mbgl/util/geometry_util.cpp | 6 ++-- src/mbgl/util/tile_cover_impl.cpp | 1 + vendor/icu.cmake | 4 ++- vendor/nunicode.cmake | 4 ++- 33 files changed, 110 insertions(+), 67 deletions(-) diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 51cc3b0f159..a413b30f7ef 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -78,6 +78,9 @@ class Result : private variant { Result() = default; + template + VARIANT_INLINE Result(U&& val) : variant(val) {} + explicit operator bool () const { return this->template is(); } diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index ad11d1ceb42..3dbb7a8009a 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -34,6 +34,9 @@ using ValueBase = variant + VARIANT_INLINE Value(T&& val) : ValueBase(val) {} + // Javascript's Number.MAX_SAFE_INTEGER static uint64_t maxSafeInteger() { return 9007199254740991ULL; } diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp index 608befd3c4e..6b08b00edaa 100644 --- a/include/mbgl/util/enum.hpp +++ b/include/mbgl/util/enum.hpp @@ -16,22 +16,22 @@ class Enum { static optional toEnum(const std::string&); }; -#define MBGL_DEFINE_ENUM(T, values...) \ - \ -static const constexpr std::pair T##_names[] = values; \ - \ -template <> \ -const char * Enum::toString(T t) { \ - auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ - [&] (const auto& v) { return t == v.first; }); \ - assert(it != std::end(T##_names)); return it->second; \ -} \ - \ -template <> \ -optional Enum::toEnum(const std::string& s) { \ - auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ - [&] (const auto& v) { return s == v.second; }); \ - return it == std::end(T##_names) ? optional() : it->first; \ +#define MBGL_DEFINE_ENUM(T, ...) \ + \ +static const constexpr std::pair T##_names[] = __VA_ARGS__; \ + \ +template <> \ +const char * Enum::toString(T t) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&] (const auto& v) { return t == v.first; }); \ + assert(it != std::end(T##_names)); return it->second; \ +} \ + \ +template <> \ +optional Enum::toEnum(const std::string& s) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&] (const auto& v) { return s == v.second; }); \ + return it == std::end(T##_names) ? optional() : it->first; \ } } // namespace mbgl diff --git a/platform/default/src/mbgl/gl/headless_backend.cpp b/platform/default/src/mbgl/gl/headless_backend.cpp index 697c560f76a..61cb2fa8da9 100644 --- a/platform/default/src/mbgl/gl/headless_backend.cpp +++ b/platform/default/src/mbgl/gl/headless_backend.cpp @@ -19,6 +19,8 @@ class HeadlessRenderableResource final : public gl::RenderableResource { depthStencil(context.createRenderbuffer(size_)), framebuffer(context.createFramebuffer(color, depthStencil)) {} + ~HeadlessRenderableResource() noexcept override = default; + void bind() override { context.bindFramebuffer = framebuffer.framebuffer; context.scissorTest = false; diff --git a/platform/default/src/mbgl/storage/sqlite3.cpp b/platform/default/src/mbgl/storage/sqlite3.cpp index de389e54314..c1be6a7a797 100644 --- a/platform/default/src/mbgl/storage/sqlite3.cpp +++ b/platform/default/src/mbgl/storage/sqlite3.cpp @@ -11,6 +11,11 @@ #include #include +#define MBGL_CONSTRUCTOR(f) \ + static void f(void); \ + struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \ + static void f(void) + namespace mapbox { namespace sqlite { @@ -102,8 +107,7 @@ void logSqlMessage(void *, const int err, const char *msg) { } #endif -__attribute__((constructor)) -static void initalize() { +MBGL_CONSTRUCTOR(initialize) { if (sqlite3_libversion_number() / 1000000 != SQLITE_VERSION_NUMBER / 1000000) { char message[96]; snprintf(message, 96, diff --git a/platform/default/src/mbgl/util/compression.cpp b/platform/default/src/mbgl/util/compression.cpp index bd498ae4714..dbf2c9f2cd8 100644 --- a/platform/default/src/mbgl/util/compression.cpp +++ b/platform/default/src/mbgl/util/compression.cpp @@ -10,8 +10,14 @@ #include #include +#if defined(__GNUC__) +#define MBGL_UNUSED __attribute__((unused)) +#else +#define MBGL_UNUSED +#endif + // Check zlib library version. -const static bool zlibVersionCheck __attribute__((unused)) = []() { +const static bool zlibVersionCheck MBGL_UNUSED = []() { const char *const version = zlibVersion(); if (version[0] != ZLIB_VERSION[0]) { char message[96]; diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 0a143280d30..0d586fbeb2a 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -448,16 +448,16 @@ void MapWindow::mouseMoveEvent(QMouseEvent *ev) void MapWindow::wheelEvent(QWheelEvent *ev) { - if (ev->orientation() == Qt::Horizontal) { + if (ev->angleDelta().y() == 0) { return; } - float factor = ev->delta() / 1200.; - if (ev->delta() < 0) { + float factor = ev->angleDelta().y() / 1200.; + if (ev->angleDelta().y() < 0) { factor = factor > -1 ? factor : 1 / factor; } - m_map->scaleBy(1 + factor, ev->pos()); + m_map->scaleBy(1 + factor, ev->position()); ev->accept(); } diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index dbf5b9873e6..5ead90b211f 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -3,9 +3,13 @@ find_package(Qt6Gui REQUIRED) find_package(Qt6Network REQUIRED) find_package(Qt6OpenGL REQUIRED) +find_package(Qt6OpenGLWidgets REQUIRED) find_package(Qt6Widgets REQUIRED) -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") +if(MSVC) + add_definitions("/DQT_COMPILING_QIMAGE_COMPAT_CPP") + add_definitions("/D_USE_MATH_DEFINES") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") add_definitions("-DQT_COMPILING_QIMAGE_COMPAT_CPP") add_definitions("-D_USE_MATH_DEFINES") add_definitions("-Wno-deprecated-declarations") @@ -92,6 +96,7 @@ target_link_libraries( Qt6::Gui Qt6::Network Qt6::OpenGL + Qt6::OpenGLWidgets mbgl-vendor-nunicode mbgl-vendor-sqlite ) @@ -157,6 +162,7 @@ target_link_libraries( PRIVATE Qt6::Widgets Qt6::Gui + Qt6::OpenGLWidgets mbgl-compiler-options qmapboxgl ) @@ -179,6 +185,7 @@ target_compile_definitions( target_link_libraries( mbgl-test-runner PRIVATE + Qt6::Widgets Qt6::Gui Qt6::OpenGL mbgl-compiler-options diff --git a/platform/qt/src/headless_backend_qt.cpp b/platform/qt/src/headless_backend_qt.cpp index 1d62afabffb..bed07c7fd2a 100644 --- a/platform/qt/src/headless_backend_qt.cpp +++ b/platform/qt/src/headless_backend_qt.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -26,7 +26,7 @@ class QtBackendImpl final : public HeadlessBackend::Impl { } private: - QGLWidget widget; + QOpenGLWidget widget; }; void HeadlessBackend::createImpl() { diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index e4d89e3d644..5f2033337ac 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -29,7 +29,6 @@ void HTTPFileSource::Impl::request(HTTPRequest* req) } QNetworkRequest networkRequest = req->networkRequest(); - networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); data.first = m_manager->get(networkRequest); connect(data.first, SIGNAL(finished()), this, SLOT(onReplyFinished())); diff --git a/platform/qt/src/local_glyph_rasterizer.cpp b/platform/qt/src/local_glyph_rasterizer.cpp index 31abfd4503b..2f7662ea47c 100644 --- a/platform/qt/src/local_glyph_rasterizer.cpp +++ b/platform/qt/src/local_glyph_rasterizer.cpp @@ -52,7 +52,7 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { return glyph; } - glyph.metrics.width = impl->metrics->width(glyphID); + glyph.metrics.width = impl->metrics->horizontalAdvance(glyphID); glyph.metrics.height = impl->metrics->height(); glyph.metrics.left = 3; glyph.metrics.top = -8; @@ -68,8 +68,8 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { // Render at constant baseline, to align with glyphs that are rendered by node-fontnik. painter.drawText(QPointF(0, 20), QString(QChar(glyphID))); - auto img = std::make_unique(image.byteCount()); - memcpy(img.get(), image.constBits(), image.byteCount()); + auto img = std::make_unique(image.sizeInBytes()); + memcpy(img.get(), image.constBits(), image.sizeInBytes()); glyph.bitmap = AlphaImage { size, std::move(img) }; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 14e9d575582..aa3b535d799 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -108,8 +108,8 @@ std::unique_ptr toStyleImage(const QString &id, const QImage .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); - auto img = std::make_unique(swapped.byteCount()); - memcpy(img.get(), swapped.constBits(), swapped.byteCount()); + auto img = std::make_unique(swapped.sizeInBytes()); + memcpy(img.get(), swapped.constBits(), swapped.sizeInBytes()); return std::make_unique( id.toStdString(), diff --git a/platform/qt/src/qt_image.cpp b/platform/qt/src/qt_image.cpp index 302d3987391..519e9df4f8f 100644 --- a/platform/qt/src/qt_image.cpp +++ b/platform/qt/src/qt_image.cpp @@ -45,8 +45,8 @@ PremultipliedImage decodeImage(const std::string& string) { throw std::runtime_error("Unsupported image type"); } - auto img = std::make_unique(image.byteCount()); - memcpy(img.get(), image.constBits(), image.byteCount()); + auto img = std::make_unique(image.sizeInBytes()); + memcpy(img.get(), image.constBits(), image.sizeInBytes()); return { { static_cast(image.width()), static_cast(image.height()) }, std::move(img) }; diff --git a/platform/qt/test/main.cpp b/platform/qt/test/main.cpp index d9f7d480e54..73ca7f403a0 100644 --- a/platform/qt/test/main.cpp +++ b/platform/qt/test/main.cpp @@ -1,11 +1,16 @@ #include #include -#include #include #include #include +#if defined(_MSC_VER) && !defined(__clang__) +#include +#else +#include +#endif + #define xstr(s) str(s) #define str(s) #s diff --git a/src/mbgl/gfx/attribute.hpp b/src/mbgl/gfx/attribute.hpp index 907087d8bb3..62873d971ee 100644 --- a/src/mbgl/gfx/attribute.hpp +++ b/src/mbgl/gfx/attribute.hpp @@ -19,7 +19,11 @@ } \ } +#if defined(_MSC_VER) && !defined(__clang__) +#define MBGL_VERTEX_ALIGN __declspec(align(4)) +#else #define MBGL_VERTEX_ALIGN __attribute__((aligned(4))) +#endif namespace mbgl { namespace gfx { @@ -106,44 +110,44 @@ template struct VertexType; template -struct VertexType { +struct MBGL_VERTEX_ALIGN VertexType { using Type = VertexType; typename A1::Value a1; -} MBGL_VERTEX_ALIGN; +}; template -struct VertexType { +struct MBGL_VERTEX_ALIGN VertexType { using Type = VertexType; typename A1::Value a1; typename A2::Value a2; -} MBGL_VERTEX_ALIGN; +}; template -struct VertexType { +struct MBGL_VERTEX_ALIGN VertexType { using Type = VertexType; typename A1::Value a1; typename A2::Value a2; typename A3::Value a3; -} MBGL_VERTEX_ALIGN; +}; template -struct VertexType { +struct MBGL_VERTEX_ALIGN VertexType { using Type = VertexType; typename A1::Value a1; typename A2::Value a2; typename A3::Value a3; typename A4::Value a4; -} MBGL_VERTEX_ALIGN; +}; template -struct VertexType { +struct MBGL_VERTEX_ALIGN VertexType { using Type = VertexType; typename A1::Value a1; typename A2::Value a2; typename A3::Value a3; typename A4::Value a4; typename A5::Value a5; -} MBGL_VERTEX_ALIGN; +}; template struct Descriptor; diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 9c7898cc1df..4ae114e05bb 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -14,6 +14,7 @@ #include #include +#include namespace mbgl { namespace gl { @@ -58,7 +59,7 @@ Context::Context(RendererBackend& backend_) backend(backend_), stats() {} -Context::~Context() { +Context::~Context() noexcept { if (cleanupOnDestruction) { reset(); assert(stats.isZero()); diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index f9ca036d2c9..c16fc6cb98e 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -37,7 +37,7 @@ class Debugging; class Context final : public gfx::Context { public: Context(RendererBackend&); - ~Context() override; + ~Context() noexcept override; Context(const Context&) = delete; Context& operator=(const Context& other) = delete; @@ -149,7 +149,7 @@ class Context final : public gfx::Context { State vertexBuffer; State bindVertexArray { *this }; - VertexArrayState globalVertexArrayState { UniqueVertexArray(0, { this }) }; + VertexArrayState globalVertexArrayState { UniqueVertexArray(0, { const_cast(this) }) }; State pixelStorePack; State pixelStoreUnpack; diff --git a/src/mbgl/gl/index_buffer_resource.cpp b/src/mbgl/gl/index_buffer_resource.cpp index 2ef178846b3..616fbf5e679 100644 --- a/src/mbgl/gl/index_buffer_resource.cpp +++ b/src/mbgl/gl/index_buffer_resource.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace gl { -IndexBufferResource::~IndexBufferResource() { +IndexBufferResource::~IndexBufferResource() noexcept { auto& stats = buffer.get_deleter().context.renderingStats(); stats.memIndexBuffers -= byteSize; assert(stats.memIndexBuffers >= 0); diff --git a/src/mbgl/gl/index_buffer_resource.hpp b/src/mbgl/gl/index_buffer_resource.hpp index 4187994a225..10d9bfc8014 100644 --- a/src/mbgl/gl/index_buffer_resource.hpp +++ b/src/mbgl/gl/index_buffer_resource.hpp @@ -9,7 +9,7 @@ namespace gl { class IndexBufferResource : public gfx::IndexBufferResource { public: IndexBufferResource(UniqueBuffer&& buffer_, int byteSize_) : buffer(std::move(buffer_)), byteSize(byteSize_) {} - ~IndexBufferResource() override; + ~IndexBufferResource() noexcept override; UniqueBuffer buffer; int byteSize; diff --git a/src/mbgl/gl/offscreen_texture.cpp b/src/mbgl/gl/offscreen_texture.cpp index 92f80a87b43..cba697558da 100644 --- a/src/mbgl/gl/offscreen_texture.cpp +++ b/src/mbgl/gl/offscreen_texture.cpp @@ -15,6 +15,8 @@ class OffscreenTextureResource final : public gl::RenderableResource { assert(!size.isEmpty()); } + ~OffscreenTextureResource() noexcept override = default; + void bind() override { if (!framebuffer) { assert(!texture); diff --git a/src/mbgl/gl/renderbuffer_resource.hpp b/src/mbgl/gl/renderbuffer_resource.hpp index 52865b42f74..9a318cbd48a 100644 --- a/src/mbgl/gl/renderbuffer_resource.hpp +++ b/src/mbgl/gl/renderbuffer_resource.hpp @@ -12,6 +12,8 @@ class RenderbufferResource final : public gfx::RenderbufferResource { : renderbuffer(std::move(renderbuffer_)) { } + ~RenderbufferResource() noexcept override = default; + UniqueRenderbuffer renderbuffer; }; diff --git a/src/mbgl/gl/texture_resource.cpp b/src/mbgl/gl/texture_resource.cpp index b9bf620eeab..ffdd4c7d887 100644 --- a/src/mbgl/gl/texture_resource.cpp +++ b/src/mbgl/gl/texture_resource.cpp @@ -31,7 +31,7 @@ static int channelStorageSize(gfx::TextureChannelDataType type) { } } -TextureResource::~TextureResource() { +TextureResource::~TextureResource() noexcept { auto& stats = texture.get_deleter().context->renderingStats(); stats.memTextures -= byteSize; assert(stats.memTextures >= 0); diff --git a/src/mbgl/gl/texture_resource.hpp b/src/mbgl/gl/texture_resource.hpp index fd4f69084f1..e2162beb8a5 100644 --- a/src/mbgl/gl/texture_resource.hpp +++ b/src/mbgl/gl/texture_resource.hpp @@ -9,7 +9,7 @@ namespace gl { class TextureResource : public gfx::TextureResource { public: TextureResource(UniqueTexture&& texture_, int byteSize_) : texture(std::move(texture_)), byteSize(byteSize_) {} - ~TextureResource() override; + ~TextureResource() noexcept override; static int getStorageSize(const Size& size, gfx::TexturePixelType format, gfx::TextureChannelDataType type); diff --git a/src/mbgl/gl/vertex_buffer_resource.cpp b/src/mbgl/gl/vertex_buffer_resource.cpp index cddbdd43d0a..f44464fdbc3 100644 --- a/src/mbgl/gl/vertex_buffer_resource.cpp +++ b/src/mbgl/gl/vertex_buffer_resource.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace gl { -VertexBufferResource::~VertexBufferResource() { +VertexBufferResource::~VertexBufferResource() noexcept { auto& stats = buffer.get_deleter().context.renderingStats(); stats.memVertexBuffers -= byteSize; assert(stats.memVertexBuffers >= 0); diff --git a/src/mbgl/gl/vertex_buffer_resource.hpp b/src/mbgl/gl/vertex_buffer_resource.hpp index cbd73482a3f..c14ac00cfab 100644 --- a/src/mbgl/gl/vertex_buffer_resource.hpp +++ b/src/mbgl/gl/vertex_buffer_resource.hpp @@ -9,7 +9,7 @@ namespace gl { class VertexBufferResource : public gfx::VertexBufferResource { public: VertexBufferResource(UniqueBuffer&& buffer_, int byteSize_) : buffer(std::move(buffer_)), byteSize(byteSize_) {} - ~VertexBufferResource() override; + ~VertexBufferResource() noexcept override; UniqueBuffer buffer; int byteSize; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 48e2f9d5c5a..b35719b988f 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -645,8 +645,8 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, Anchors anchors = getAnchors(line, symbolSpacing, textMaxAngle, - (shapedTextOrientations.vertical ?: getDefaultHorizontalShaping(shapedTextOrientations)).left, - (shapedTextOrientations.vertical ?: getDefaultHorizontalShaping(shapedTextOrientations)).right, + (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).left, + (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).right, (shapedIcon ? shapedIcon->left() : 0), (shapedIcon ? shapedIcon->right() : 0), glyphSize, @@ -666,8 +666,8 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, if (line.size() > 1) { optional anchor = getCenterAnchor(line, textMaxAngle, - (shapedTextOrientations.vertical ?: getDefaultHorizontalShaping(shapedTextOrientations)).left, - (shapedTextOrientations.vertical ?: getDefaultHorizontalShaping(shapedTextOrientations)).right, + (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).left, + (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).right, (shapedIcon ? shapedIcon->left() : 0), (shapedIcon ? shapedIcon->right() : 0), glyphSize, diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp index eecaced8244..fef602aa4a5 100644 --- a/src/mbgl/layout/symbol_projection.cpp +++ b/src/mbgl/layout/symbol_projection.cpp @@ -95,7 +95,7 @@ namespace mbgl { PointAndCameraDistance project(const Point& point, const mat4& matrix) { vec4 pos = {{ point.x, point.y, 0, 1 }}; matrix::transformMat4(pos, pos, matrix); - return {{ static_cast(pos[0] / pos[3]), static_cast(pos[1] / pos[3]) }, pos[3] }; + return {{ static_cast(pos[0] / pos[3]), static_cast(pos[1] / pos[3]) }, static_cast(pos[3]) }; } float evaluateSizeForFeature(const ZoomEvaluatedSize& zoomEvaluatedSize, const PlacedSymbol& placedSymbol) { diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp index 518d1277200..5cfe6c2b434 100644 --- a/src/mbgl/style/expression/coercion.cpp +++ b/src/mbgl/style/expression/coercion.cpp @@ -53,9 +53,9 @@ EvaluationResult toColor(const Value& colorValue) { }; } }, - [&](const std::vector& components) -> EvaluationResult { + [&colorValue](const std::vector& components) -> EvaluationResult { std::size_t len = components.size(); - bool isNumeric = std::all_of(components.begin(), components.end(), [](const Value& item) { + bool isNumeric = std::all_of(components.begin(), components.end(), [](const Value& item) -> bool { return item.template is(); }); if ((len == 3 || len == 4) && isNumeric) { diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index bae0258aa0c..21df82257a6 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -225,7 +225,7 @@ Value featureIdAsExpressionValue(const EvaluationContext& params) { optional featurePropertyAsExpressionValue(const EvaluationContext& params, const std::string& key) { assert(params.feature); auto property = params.feature->getValue(key); - return property ? toExpressionValue(*property) : optional(); + return property ? optional(toExpressionValue(*property)) : optional(); }; optional featureTypeAsString(FeatureType type) { diff --git a/src/mbgl/util/geometry_util.cpp b/src/mbgl/util/geometry_util.cpp index 5cade1eff8f..f354359f7f5 100644 --- a/src/mbgl/util/geometry_util.cpp +++ b/src/mbgl/util/geometry_util.cpp @@ -149,10 +149,10 @@ template bool pointOnBoundary(const Point& p, const Point& p1, template bool lineIntersectPolygon(const Point& p1, const Point& p2, const Polygon& polygon); template bool pointWithinPolygon(const Point& point, const Polygon& polygon, - bool trueOnBoundary = false); + bool trueOnBoundary); template bool pointWithinPolygons(const Point& point, const MultiPolygon& polygons, - bool trueOnBoundary = false); + bool trueOnBoundary); template bool lineStringWithinPolygon(const LineString& line, const Polygon& polygon); template bool lineStringWithinPolygons(const LineString& line, const MultiPolygon& polygons); @@ -164,6 +164,6 @@ template bool segmentIntersectSegment(const Point& a, const Point& d); template bool pointWithinPolygon(const Point& point, const Polygon& polygon, - bool trueOnBoundary = false); + bool trueOnBoundary); } // namespace mbgl diff --git a/src/mbgl/util/tile_cover_impl.cpp b/src/mbgl/util/tile_cover_impl.cpp index cca58ca7e87..e6f0516d503 100644 --- a/src/mbgl/util/tile_cover_impl.cpp +++ b/src/mbgl/util/tile_cover_impl.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace mbgl { namespace util { diff --git a/vendor/icu.cmake b/vendor/icu.cmake index 0ae1593e5e5..f3f3d76e255 100644 --- a/vendor/icu.cmake +++ b/vendor/icu.cmake @@ -33,7 +33,9 @@ target_compile_definitions( _REENTRANT ) -target_compile_options(mbgl-vendor-icu PRIVATE -Wno-error -Wno-shorten-64-to-32) +if(NOT MSVC) + target_compile_options(mbgl-vendor-icu PRIVATE -Wno-error -Wno-shorten-64-to-32) +endif() target_include_directories( mbgl-vendor-icu SYSTEM diff --git a/vendor/nunicode.cmake b/vendor/nunicode.cmake index f13492de78d..40dcd75138d 100644 --- a/vendor/nunicode.cmake +++ b/vendor/nunicode.cmake @@ -18,7 +18,9 @@ target_compile_definitions( PRIVATE NU_BUILD_STATIC ) -target_compile_options(mbgl-vendor-nunicode PRIVATE -Wno-error) +if(NOT MSVC) + target_compile_options(mbgl-vendor-nunicode PRIVATE -Wno-error) +endif() target_include_directories( mbgl-vendor-nunicode SYSTEM From ef1619e1677b6b88cdc4245ec46e221f9f73960b Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 5 Jun 2021 00:00:51 -0500 Subject: [PATCH 03/10] [qt] Updating QNetworkReply error signal name for Qt6 --- platform/qt/src/http_file_source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index 5f2033337ac..48c4dfd018f 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -32,7 +32,7 @@ void HTTPFileSource::Impl::request(HTTPRequest* req) data.first = m_manager->get(networkRequest); connect(data.first, SIGNAL(finished()), this, SLOT(onReplyFinished())); - connect(data.first, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); + connect(data.first, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); } void HTTPFileSource::Impl::cancel(HTTPRequest* req) From 7118f9985e576fcc3b7b2f805d8da0104b38fb1c Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 5 Jun 2021 00:39:53 -0500 Subject: [PATCH 04/10] [qt] Test fixes for Qt6 and msvc2019 --- platform/qt/qt.cmake | 29 ++++++++++++++++------- test/storage/local_file_source.test.cpp | 14 +++++++++-- test/storage/offline_database.test.cpp | 8 ++++++- test/style/expression/expression.test.cpp | 6 +++++ test/style/style_parser.test.cpp | 5 ++++ test/util/memory.test.cpp | 5 ++++ test/util/thread.test.cpp | 8 +++++++ 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 5ead90b211f..c9036710844 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -182,15 +182,26 @@ target_compile_definitions( PRIVATE WORK_DIRECTORY=${PROJECT_SOURCE_DIR} ) -target_link_libraries( - mbgl-test-runner - PRIVATE - Qt6::Widgets - Qt6::Gui - Qt6::OpenGL - mbgl-compiler-options - pthread -) +if (MSVC) + target_link_libraries( + mbgl-test-runner + PRIVATE + Qt6::Widgets + Qt6::Gui + Qt6::OpenGL + mbgl-compiler-options + ) +else() + target_link_libraries( + mbgl-test-runner + PRIVATE + Qt6::Widgets + Qt6::Gui + Qt6::OpenGL + mbgl-compiler-options + pthread + ) +endif() if(CMAKE_SYSTEM_NAME STREQUAL Darwin) target_link_libraries( diff --git a/test/storage/local_file_source.test.cpp b/test/storage/local_file_source.test.cpp index 45c8c54d917..7822bc15a2f 100644 --- a/test/storage/local_file_source.test.cpp +++ b/test/storage/local_file_source.test.cpp @@ -3,10 +3,18 @@ #include #include -#include #include #include +#if defined(WIN32) +#include +#ifndef PATH_MAX +#define PATH_MAX MAX_PATH +#endif /* PATH_MAX */ +#else +#include +#endif + namespace { std::string toAbsoluteURL(const std::string& fileName) { @@ -135,11 +143,13 @@ TEST(LocalFileSource, URLLimit) { size_t length = PATH_MAX - toAbsoluteURL("").size(); LocalFileSource fs; - char filename[length]; + char* filename = new char[length]; memset(filename, 'x', length); std::string url(filename, length); + delete[] filename; + std::unique_ptr req = fs.request({ Resource::Unknown, toAbsoluteURL(url) }, [&](Response res) { req.reset(); ASSERT_NE(nullptr, res.error); diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 6b444bf3d1a..1acdc0881ae 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -12,6 +12,12 @@ #include #include +#if defined(__GNUC__) +#define MBGL_UNUSED __attribute__((unused)) +#else +#define MBGL_UNUSED +#endif + using namespace std::literals::string_literals; using namespace mbgl; using mapbox::sqlite::ResultCode; @@ -44,7 +50,7 @@ static FixtureLog::Message error(ResultCode code, const char* message) { return { EventSeverity::Error, Event::Database, static_cast(code), message }; } -static __attribute__((unused)) FixtureLog::Message warning(ResultCode code, const char* message) { +static MBGL_UNUSED FixtureLog::Message warning(ResultCode code, const char* message) { return { EventSeverity::Warning, Event::Database, static_cast(code), message }; } diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp index 07f6cf173aa..bb378f7b25f 100644 --- a/test/style/expression/expression.test.cpp +++ b/test/style/expression/expression.test.cpp @@ -9,7 +9,10 @@ #include #include + +#if !defined(_MSC_VER) || defined(__clang__) #include +#endif using namespace mbgl; @@ -79,6 +82,8 @@ TEST_P(ExpressionEqualityTest, ExpressionEquality) { EXPECT_TRUE(*expression_a1 != *expression_b); } +// TODO: Microsoft Visual Studio complains about lambda in declaration +#if !defined(_MSC_VER) || defined(__clang__) INSTANTIATE_TEST_SUITE_P(Expression, ExpressionEqualityTest, ::testing::ValuesIn([] { std::vector names; const std::string ending = ".a.json"; @@ -105,3 +110,4 @@ INSTANTIATE_TEST_SUITE_P(Expression, ExpressionEqualityTest, ::testing::ValuesIn EXPECT_GT(names.size(), 0u); return names; }())); +#endif diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp index 7607dbd0777..5c9859d60ec 100644 --- a/test/style/style_parser.test.cpp +++ b/test/style/style_parser.test.cpp @@ -13,7 +13,9 @@ #include #include +#if !defined(_MSC_VER) || defined(__clang__) #include +#endif using namespace mbgl; @@ -74,6 +76,8 @@ TEST_P(StyleParserTest, ParseStyle) { } } +// TODO: Microsoft Visual Studio complains about lambda in declaration +#if !defined(_MSC_VER) || defined(__clang__) INSTANTIATE_TEST_SUITE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] { std::vector names; const std::string ending = ".info.json"; @@ -94,6 +98,7 @@ INSTANTIATE_TEST_SUITE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] { EXPECT_GT(names.size(), 0u); return names; }())); +#endif TEST(StyleParser, FontStacks) { style::Parser parser; diff --git a/test/util/memory.test.cpp b/test/util/memory.test.cpp index bf14c704195..64f50d0ba07 100644 --- a/test/util/memory.test.cpp +++ b/test/util/memory.test.cpp @@ -1,3 +1,5 @@ +#define NOMINMAX + #include #include #include @@ -18,7 +20,10 @@ #include #include + +#if !defined(_MSC_VER) || defined(__clang__) #include +#endif using namespace mbgl; using namespace std::literals::string_literals; diff --git a/test/util/thread.test.cpp b/test/util/thread.test.cpp index 49735585c6a..9990aea31cd 100644 --- a/test/util/thread.test.cpp +++ b/test/util/thread.test.cpp @@ -9,6 +9,10 @@ #include #include +#if defined(WIN32) +#include +#endif + using namespace mbgl; using namespace mbgl::util; @@ -198,7 +202,11 @@ TEST(Thread, ReferenceCanOutliveThread) { worker.invoke(&TestWorker::send, [&] { ADD_FAILURE() << "Should never happen"; }); } +#if defined(WIN32) + Sleep(10); +#else usleep(10000); +#endif } TEST(Thread, DeletePausedThread) { From 1b1d42972cdaaccdc2bb8a00bf047332481f4bcf Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 5 Jun 2021 09:49:49 -0500 Subject: [PATCH 05/10] [qt] Link whole test archive for Qt and msvc2019 --- platform/qt/qt.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index c9036710844..41aa013997e 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -208,6 +208,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin) mbgl-test-runner PRIVATE -Wl,-force_load mbgl-test ) +elseif(MSVC) + target_link_options( + mbgl-test-runner + PRIVATE /WHOLEARCHIVE:../../lib/mbgl-test.lib + ) + target_link_libraries( + mbgl-test-runner + PRIVATE mbgl-test + ) else() target_link_libraries( mbgl-test-runner From c9afe4bc5885fef85ef52ca09decf09b95a866f8 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 5 Jun 2021 12:57:05 -0500 Subject: [PATCH 06/10] [qt] Fixing Qt6 headless backend renderer --- platform/qt/src/headless_backend_qt.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/platform/qt/src/headless_backend_qt.cpp b/platform/qt/src/headless_backend_qt.cpp index bed07c7fd2a..03bf3bfb16b 100644 --- a/platform/qt/src/headless_backend_qt.cpp +++ b/platform/qt/src/headless_backend_qt.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -10,6 +10,12 @@ namespace gl { class QtBackendImpl final : public HeadlessBackend::Impl { public: + QtBackendImpl() { + // QtBackendImpl must be created in the main/GUI thread on platforms + // that have a QWindow-based QOffscreenSurface. + surface.create(); + context.create(); + } ~QtBackendImpl() = default; gl::ProcAddress getExtensionFunctionPointer(const char* name) { @@ -18,15 +24,16 @@ class QtBackendImpl final : public HeadlessBackend::Impl { } void activateContext() { - widget.makeCurrent(); + context.makeCurrent(&surface); } void deactivateContext() { - widget.doneCurrent(); + context.doneCurrent(); } private: - QOpenGLWidget widget; + QOpenGLContext context; + QOffscreenSurface surface; }; void HeadlessBackend::createImpl() { From e2d7967072e758318f5611dfc18785df8b31920b Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 6 Jun 2021 00:50:52 -0500 Subject: [PATCH 07/10] [qt] Fixes for test failures --- platform/qt/src/bidi.cpp | 10 ++-- src/mbgl/util/io.cpp | 8 ++- test/CMakeLists.txt | 2 +- test/map/transform.test.cpp | 50 ++++++++-------- test/src/mbgl/test/fake_file_source.hpp | 6 +- test/storage/local_file_source.test.cpp | 5 ++ test/storage/offline_database.test.cpp | 4 ++ test/style/style.test.cpp | 8 +++ test/util/camera.test.cpp | 78 ++++++++++++------------- 9 files changed, 99 insertions(+), 72 deletions(-) diff --git a/platform/qt/src/bidi.cpp b/platform/qt/src/bidi.cpp index 6b680a97691..57e61d33427 100644 --- a/platform/qt/src/bidi.cpp +++ b/platform/qt/src/bidi.cpp @@ -39,10 +39,12 @@ std::vector BiDi::processStyledText(const StyledText& input, std::se std::vector transformedLines; std::size_t start = 0; for (std::size_t lineBreakPoint : lineBreakPoints) { - transformedLines.emplace_back( - input.first.substr(start, lineBreakPoint - start), - std::vector(input.second.begin() + start, input.second.begin() + lineBreakPoint)); - start = lineBreakPoint; + if (lineBreakPoint <= input.second.size()) { + transformedLines.emplace_back( + input.first.substr(start, lineBreakPoint - start), + std::vector(input.second.begin() + start, input.second.begin() + lineBreakPoint)); + start = lineBreakPoint; + } } return transformedLines; diff --git a/src/mbgl/util/io.cpp b/src/mbgl/util/io.cpp index 5c385140ba3..5225e29521f 100644 --- a/src/mbgl/util/io.cpp +++ b/src/mbgl/util/io.cpp @@ -7,6 +7,12 @@ #include #include +#ifdef __GNUC__ +#define MBGL_FOPEN_MODE_WBE "wbe" +#else +#define MBGL_FOPEN_MODE_WBE "wb" +#endif + namespace mbgl { namespace util { @@ -15,7 +21,7 @@ IOException::IOException(int err, const std::string& msg) } void write_file(const std::string &filename, const std::string &data) { - FILE *fd = fopen(filename.c_str(), "wbe"); + FILE *fd = fopen(filename.c_str(), MBGL_FOPEN_MODE_WBE); if (fd) { fwrite(data.data(), sizeof(std::string::value_type), data.size(), fd); fclose(fd); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2ead99e4d83..d90f14f7407 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -59,7 +59,7 @@ add_library( ${PROJECT_SOURCE_DIR}/test/style/style_image.test.cpp ${PROJECT_SOURCE_DIR}/test/style/style_layer.test.cpp ${PROJECT_SOURCE_DIR}/test/style/style_parser.test.cpp - ${PROJECT_SOURCE_DIR}/test/text/bidi.test.cpp + $<$>:${PROJECT_SOURCE_DIR}/test/text/bidi.test.cpp> ${PROJECT_SOURCE_DIR}/test/text/calculate_tile_distances.test.cpp ${PROJECT_SOURCE_DIR}/test/text/cross_tile_symbol_index.test.cpp ${PROJECT_SOURCE_DIR}/test/text/formatted.test.cpp diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index f14099d2fbb..b80869f3ed6 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -874,7 +874,7 @@ TEST(Transform, MinMaxPitch) { static const double abs_double_error = 1e-5; -MATCHER_P(Vec3NearEquals, vec, "") { +MATCHER_P(Vec3NearEquals1E5, vec, "") { return std::fabs(vec[0] - arg[0]) <= abs_double_error && std::fabs(vec[1] - arg[1]) <= abs_double_error && std::fabs(vec[2] - arg[2]) <= abs_double_error; } @@ -895,7 +895,7 @@ TEST(Transform, FreeCameraOptionsInvalidSize) { EXPECT_DOUBLE_EQ(0.0, updatedOrientation[2]); EXPECT_DOUBLE_EQ(1.0, updatedOrientation[3]); - EXPECT_THAT(updatedPosition, Vec3NearEquals(vec3{{0.0, 0.0, 0.0}})); + EXPECT_THAT(updatedPosition, Vec3NearEquals1E5(vec3{{0.0, 0.0, 0.0}})); } TEST(Transform, FreeCameraOptionsNanInput) { @@ -914,7 +914,7 @@ TEST(Transform, FreeCameraOptionsNanInput) { options.position = vec3{{0.3, 0.1, 0.2}}; options.orientation = vec4{{NAN, 0.0, NAN, 0.0}}; transform.setFreeCameraOptions(options); - EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals(vec3{{0.3, 0.1, 0.2}})); + EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals1E5(vec3{{0.3, 0.1, 0.2}})); EXPECT_EQ(Quaternion::identity.m, transform.getFreeCameraOptions().orientation.value()); } @@ -1008,9 +1008,9 @@ TEST(Transform, FreeCameraOptionsClampPitch) { transform.setFreeCameraOptions(options); EXPECT_DOUBLE_EQ(util::PITCH_MAX, transform.getState().getPitch()); std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value()); - EXPECT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - EXPECT_THAT(up, Vec3NearEquals(vec3{{0, -0.5, 0.866025}})); - EXPECT_THAT(forward, Vec3NearEquals(vec3{{0, -0.866025, -0.5}})); + EXPECT_THAT(right, Vec3NearEquals1E5(vec3{{1.0, 0.0, 0.0}})); + EXPECT_THAT(up, Vec3NearEquals1E5(vec3{{0, -0.5, 0.866025}})); + EXPECT_THAT(forward, Vec3NearEquals1E5(vec3{{0, -0.866025, -0.5}})); } TEST(Transform, FreeCameraOptionsClampToBounds) { @@ -1034,10 +1034,10 @@ TEST(Transform, FreeCameraOptionsClampToBounds) { vec3 right, up, forward; std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value()); EXPECT_THAT(transform.getFreeCameraOptions().position.value(), - Vec3NearEquals(vec3{{0.0976562, 0.304816, 0.20716}})); - EXPECT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - EXPECT_THAT(up, Vec3NearEquals(vec3{{0, -0.707107, 0.707107}})); - EXPECT_THAT(forward, Vec3NearEquals(vec3{{0, -0.707107, -0.707107}})); + Vec3NearEquals1E5(vec3{{0.0976562, 0.304816, 0.20716}})); + EXPECT_THAT(right, Vec3NearEquals1E5(vec3{{1.0, 0.0, 0.0}})); + EXPECT_THAT(up, Vec3NearEquals1E5(vec3{{0, -0.707107, 0.707107}})); + EXPECT_THAT(forward, Vec3NearEquals1E5(vec3{{0, -0.707107, -0.707107}})); } TEST(Transform, FreeCameraOptionsInvalidState) { @@ -1050,7 +1050,7 @@ TEST(Transform, FreeCameraOptionsInvalidState) { EXPECT_DOUBLE_EQ(0.0, transform.getState().getPitch()); const auto options = transform.getFreeCameraOptions(); - EXPECT_THAT(options.position.value(), Vec3NearEquals(vec3{{0.0, 0.0, 0.0}})); + EXPECT_THAT(options.position.value(), Vec3NearEquals1E5(vec3{{0.0, 0.0, 0.0}})); } TEST(Transform, FreeCameraOptionsOrientationRoll) { @@ -1083,31 +1083,31 @@ TEST(Transform, FreeCameraOptionsStateSynchronization) { transform.jumpTo(CameraOptions().withPitch(0.0).withBearing(0.0)); std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value()); - EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals(vec3{{0.5, 0.5, 0.29296875}})); - EXPECT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - EXPECT_THAT(up, Vec3NearEquals(vec3{{0.0, -1.0, 0.0}})); - EXPECT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals1E5(vec3{{0.5, 0.5, 0.29296875}})); + EXPECT_THAT(right, Vec3NearEquals1E5(vec3{{1.0, 0.0, 0.0}})); + EXPECT_THAT(up, Vec3NearEquals1E5(vec3{{0.0, -1.0, 0.0}})); + EXPECT_THAT(forward, Vec3NearEquals1E5(vec3{{0.0, 0.0, -1.0}})); transform.jumpTo(CameraOptions().withCenter(LatLng{60.1699, 24.9384})); EXPECT_THAT(transform.getFreeCameraOptions().position.value(), - Vec3NearEquals(vec3{{0.569273, 0.289453, 0.292969}})); + Vec3NearEquals1E5(vec3{{0.569273, 0.289453, 0.292969}})); transform.jumpTo(CameraOptions().withPitch(20.0).withBearing(77.0).withCenter(LatLng{-20.0, 20.0})); - EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals(vec3{{0.457922, 0.57926, 0.275301}})); + EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals1E5(vec3{{0.457922, 0.57926, 0.275301}})); // Invalid pitch transform.jumpTo(CameraOptions().withPitch(-10.0).withBearing(0.0)); std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value()); EXPECT_THAT(transform.getFreeCameraOptions().position.value(), - Vec3NearEquals(vec3{{0.555556, 0.556719, 0.292969}})); - EXPECT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - EXPECT_THAT(up, Vec3NearEquals(vec3{{0.0, -1.0, 0.0}})); - EXPECT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + Vec3NearEquals1E5(vec3{{0.555556, 0.556719, 0.292969}})); + EXPECT_THAT(right, Vec3NearEquals1E5(vec3{{1.0, 0.0, 0.0}})); + EXPECT_THAT(up, Vec3NearEquals1E5(vec3{{0.0, -1.0, 0.0}})); + EXPECT_THAT(forward, Vec3NearEquals1E5(vec3{{0.0, 0.0, -1.0}})); transform.jumpTo(CameraOptions().withPitch(85.0).withBearing(0.0).withCenter(LatLng{-80.0, 0.0})); std::tie(right, up, forward) = rotatedFrame(transform.getFreeCameraOptions().orientation.value()); - EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals(vec3{{0.5, 1.14146, 0.146484}})); - EXPECT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - EXPECT_THAT(up, Vec3NearEquals(vec3{{0, -0.5, 0.866025}})); - EXPECT_THAT(forward, Vec3NearEquals(vec3{{0, -0.866025, -0.5}})); + EXPECT_THAT(transform.getFreeCameraOptions().position.value(), Vec3NearEquals1E5(vec3{{0.5, 1.14146, 0.146484}})); + EXPECT_THAT(right, Vec3NearEquals1E5(vec3{{1.0, 0.0, 0.0}})); + EXPECT_THAT(up, Vec3NearEquals1E5(vec3{{0, -0.5, 0.866025}})); + EXPECT_THAT(forward, Vec3NearEquals1E5(vec3{{0, -0.866025, -0.5}})); } \ No newline at end of file diff --git a/test/src/mbgl/test/fake_file_source.hpp b/test/src/mbgl/test/fake_file_source.hpp index 7c5adbfff4f..1cac5716a30 100644 --- a/test/src/mbgl/test/fake_file_source.hpp +++ b/test/src/mbgl/test/fake_file_source.hpp @@ -51,13 +51,15 @@ class FakeFileSource : public FileSource { return fakeRequest->resource.kind == kind; }); - if (it != requests.end()) { + const bool requestFound = (it != requests.end()); + + if (requestFound) { // Copy the callback, in case calling it deallocates the AsyncRequest. Callback callback_ = (*it)->callback; callback_(response); } - return it != requests.end(); + return requestFound; } std::list requests; diff --git a/test/storage/local_file_source.test.cpp b/test/storage/local_file_source.test.cpp index 7822bc15a2f..f5445b2e7e1 100644 --- a/test/storage/local_file_source.test.cpp +++ b/test/storage/local_file_source.test.cpp @@ -153,7 +153,12 @@ TEST(LocalFileSource, URLLimit) { std::unique_ptr req = fs.request({ Resource::Unknown, toAbsoluteURL(url) }, [&](Response res) { req.reset(); ASSERT_NE(nullptr, res.error); +#if defined(_MSC_VER) && !defined(__clang__) + // Microsoft Visual Studio defines PATH_MAX as 260, less than the limit to trigger an error with reason "Other" + EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason); +#else EXPECT_EQ(Response::Error::Reason::Other, res.error->reason); +#endif ASSERT_FALSE(res.data.get()); loop.stop(); }); diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 1acdc0881ae..41a3abee29c 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -1851,6 +1851,7 @@ TEST(OfflineDatabase, MergeDatabaseWithSingleRegionTooManyExistingTiles) { EXPECT_EQ(0u, log.uncheckedCount()); } +#ifndef WIN32 // Windows cannot copy a folder as a file TEST(OfflineDatabase, MergeDatabaseWithInvalidPath) { FixtureLog log; @@ -1865,6 +1866,7 @@ TEST(OfflineDatabase, MergeDatabaseWithInvalidPath) { EXPECT_EQ(1u, log.count({ EventSeverity::Error, Event::Database, -1, "Merge database has incorrect user_version" })); EXPECT_EQ(0u, log.uncheckedCount()); } +#endif TEST(OfflineDatabase, MergeDatabaseWithInvalidDb) { FixtureLog log; @@ -1908,7 +1910,9 @@ TEST(OfflineDatabase, ChangePath) { OfflineDatabase db(":memory:"); db.changePath(newPath); mapbox::sqlite::Database::open(newPath, mapbox::sqlite::ReadOnly); +#ifndef WIN32 // Windows will fail to delete an open file util::deleteFile(newPath); +#endif WIN32 } TEST(OfflineDatabase, ResetDatabase) { diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index e47ae542bbe..fada9cbabcb 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -12,6 +12,10 @@ #include +#ifdef WIN32 +#include +#endif + using namespace mbgl; using namespace mbgl::style; @@ -101,6 +105,10 @@ TEST(Style, RemoveSourceInUse) { "Source 'sourceId' is in use, cannot remove", }; +#if defined(WIN32) + Sleep(1000); +#endif + EXPECT_EQ(log->count(logMessage), 1u); } diff --git a/test/util/camera.test.cpp b/test/util/camera.test.cpp index ceed437a397..c1f732d2074 100644 --- a/test/util/camera.test.cpp +++ b/test/util/camera.test.cpp @@ -10,7 +10,7 @@ using namespace mbgl; static const double abs_double_error = 1e-7; -MATCHER_P(Vec3NearEquals, vec, "") { +MATCHER_P(Vec3NearEquals1E7, vec, "") { return std::fabs(vec[0] - arg[0]) <= abs_double_error && std::fabs(vec[1] - arg[1]) <= abs_double_error && std::fabs(vec[2] - arg[2]) <= abs_double_error; } @@ -20,21 +20,21 @@ TEST(FreeCameraOptions, SetLocation) { options.setLocation({{0.0, 0.0}, util::EARTH_RADIUS_M * M_PI}); ASSERT_TRUE(options.position); - ASSERT_THAT(options.position.value(), Vec3NearEquals(vec3{{0.5, 0.5, 0.5}})); + ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 0.5, 0.5}})); options.setLocation({{25.0, -180.0}, 1000.0}); ASSERT_TRUE(options.position); - ASSERT_THAT(options.position.value(), Vec3NearEquals(vec3{{0.0, 0.4282409625, 0.000027532812465}})); + ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.0, 0.4282409625, 0.000027532812465}})); options.setLocation( {{util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * M_PI * std::cos(util::LATITUDE_MAX * util::DEG2RAD)}); ASSERT_TRUE(options.position); - ASSERT_THAT(options.position.value(), Vec3NearEquals(vec3{{0.5, 0.0, 0.5}})); + ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 0.0, 0.5}})); options.setLocation( {{-util::LATITUDE_MAX, 0.0}, util::EARTH_RADIUS_M * M_PI * std::cos(-util::LATITUDE_MAX * util::DEG2RAD)}); ASSERT_TRUE(options.position); - ASSERT_THAT(options.position.value(), Vec3NearEquals(vec3{{0.5, 1.0, 0.5}})); + ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{0.5, 1.0, 0.5}})); } TEST(FreeCameraOptions, SetLocationNegativeAltitude) { @@ -49,7 +49,7 @@ TEST(FreeCameraOptions, SetLocationUnwrappedLocation) { options.setLocation({{0.0, -540.0}, 0.0}); ASSERT_TRUE(options.position); - ASSERT_THAT(options.position.value(), Vec3NearEquals(vec3{{-1.0, 0.5, 0.0}})); + ASSERT_THAT(options.position.value(), Vec3NearEquals1E7(vec3{{-1.0, 0.5, 0.0}})); } TEST(FreeCameraOptions, GetLocation) { @@ -126,9 +126,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, -cosPi4, cosPi4}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, -cosPi4, -cosPi4}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, -cosPi4, cosPi4}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, -cosPi4, -cosPi4}})); // Look directly to east options.position = vec3{{0.5, 0.5, 0.0}}; @@ -136,9 +136,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{0.0, 1.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, 0.0, 1.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, 0.0, 1.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); // Pitch: 0, bearing: 0 options.setLocation({{60.1699, 24.9384}, 100.0}); @@ -146,9 +146,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, -1.0, 0.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, -1.0, 0.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 0.0, -1.0}})); // Pitch: 0, bearing: 45 options.setLocation({{60.1699, 24.9384}, 100.0}); @@ -156,9 +156,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{cosPi4, -cosPi4, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{-cosPi4, -cosPi4, 0.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{cosPi4, -cosPi4, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{-cosPi4, -cosPi4, 0.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 0.0, -1.0}})); // Looking south, up vector almost same as forward vector options.setLocation({{37.7749, 122.4194}, 0.0}); @@ -166,9 +166,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{-1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, 0.0, 1.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, 1.0, 0.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{-1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, 0.0, 1.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}})); // Orientation with roll-component options.setLocation({{-33.8688, 151.2093}, 0.0}); @@ -176,9 +176,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{0.0, 1.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, 0.0, 1.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, 0.0, 1.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); // Up vector pointing downwards options.position = vec3{{0.5, 0.5, 0.5}}; @@ -186,9 +186,9 @@ TEST(FreeCameraOptions, LookAtPoint) { ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, -cosPi4, cosPi4}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, -cosPi4, -cosPi4}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, -cosPi4, cosPi4}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, -cosPi4, -cosPi4}})); } TEST(FreeCameraOptions, LookAtPointInvalidInput) { @@ -229,16 +229,16 @@ TEST(FreeCameraOptions, SetPitchBearing) { options.setPitchBearing(0.0, 0.0); ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, -1.0, 0.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, -1.0, 0.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 0.0, -1.0}})); options.setPitchBearing(0.0, 180.0); ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{-1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, 1.0, 0.0}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, 0.0, -1.0}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{-1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, 0.0, -1.0}})); const double cos60 = std::cos(60.0 * util::DEG2RAD); const double sin60 = std::sin(60.0 * util::DEG2RAD); @@ -246,14 +246,14 @@ TEST(FreeCameraOptions, SetPitchBearing) { options.setPitchBearing(60.0, 0.0); ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{1.0, 0.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{0.0, -cos60, sin60}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{0.0, -sin60, -cos60}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{1.0, 0.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{0.0, -cos60, sin60}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{0.0, -sin60, -cos60}})); options.setPitchBearing(60.0, -450); ASSERT_TRUE(options.orientation); std::tie(right, up, forward) = rotatedFrame(options.orientation.value()); - ASSERT_THAT(right, Vec3NearEquals(vec3{{0.0, 1.0, 0.0}})); - ASSERT_THAT(up, Vec3NearEquals(vec3{{cos60, 0.0, sin60}})); - ASSERT_THAT(forward, Vec3NearEquals(vec3{{sin60, 0.0, -cos60}})); + ASSERT_THAT(right, Vec3NearEquals1E7(vec3{{0.0, 1.0, 0.0}})); + ASSERT_THAT(up, Vec3NearEquals1E7(vec3{{cos60, 0.0, sin60}})); + ASSERT_THAT(forward, Vec3NearEquals1E7(vec3{{sin60, 0.0, -cos60}})); } \ No newline at end of file From 4da4094a766069976a8a21b62d04c867d3bc36f9 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 6 Jun 2021 08:29:29 -0500 Subject: [PATCH 08/10] [qt] Expression and style parser test fixes --- test/style/expression/expression.test.cpp | 69 +++++++++++++++-------- test/style/style_parser.test.cpp | 65 ++++++++++++++------- 2 files changed, 92 insertions(+), 42 deletions(-) diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp index bb378f7b25f..e722288cd9a 100644 --- a/test/style/expression/expression.test.cpp +++ b/test/style/expression/expression.test.cpp @@ -10,7 +10,12 @@ #include #include -#if !defined(_MSC_VER) || defined(__clang__) +#if defined(_MSC_VER) && !defined(__clang__) +#include +#ifdef GetObject +#undef GetObject +#endif +#else #include #endif @@ -82,32 +87,50 @@ TEST_P(ExpressionEqualityTest, ExpressionEquality) { EXPECT_TRUE(*expression_a1 != *expression_b); } -// TODO: Microsoft Visual Studio complains about lambda in declaration -#if !defined(_MSC_VER) || defined(__clang__) -INSTANTIATE_TEST_SUITE_P(Expression, ExpressionEqualityTest, ::testing::ValuesIn([] { - std::vector names; - const std::string ending = ".a.json"; +static void populateNames(std::vector& names) { + const std::string ending = ".a.json"; + + std::string style_directory = "test/fixtures/expression_equality"; - const std::string style_directory = "test/fixtures/expression_equality"; - DIR* dir = opendir(style_directory.c_str()); - if (dir != nullptr) { - for (dirent* dp = nullptr; (dp = readdir(dir)) != nullptr;) { - const std::string name = dp->d_name; + auto testName = [&](const std::string& name) { + if (name.length() >= ending.length() && + name.compare(name.length() - ending.length(), ending.length(), ending) == 0) { + names.push_back(name.substr(0, name.length() - ending.length())); + } + }; + +#if defined(_MSC_VER) && !defined(__clang__) + style_directory += "/*"; + WIN32_FIND_DATA ffd; + HANDLE hFind = FindFirstFile(style_directory.c_str(), &ffd); + if (hFind != INVALID_HANDLE_VALUE) { + do { + const std::string name = ffd.cFileName; + testName(name); + } while (FindNextFile(hFind, &ffd) != 0); + FindClose(hFind); + } +#else + DIR* dir = opendir(style_directory.c_str()); + if (dir != nullptr) { + for (dirent* dp = nullptr; (dp = readdir(dir)) != nullptr;) { + const std::string name = dp->d_name; #if ANDROID - // Android unit test uses number-format stub implementation so skip the tests - if (name.find("number-format") != std::string::npos) { - continue; - } + // Android unit test uses number-format stub implementation so skip the tests + if (name.find("number-format") != std::string::npos) { + continue; + } +#endif + testName(name); + } + closedir(dir); + } #endif - if (name.length() >= ending.length() && - name.compare(name.length() - ending.length(), ending.length(), ending) == 0) { - names.push_back(name.substr(0, name.length() - ending.length())); - } - } - closedir(dir); - } +} +INSTANTIATE_TEST_SUITE_P(Expression, ExpressionEqualityTest, ::testing::ValuesIn([] { + std::vector names; + populateNames(names); EXPECT_GT(names.size(), 0u); return names; }())); -#endif diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp index 5c9859d60ec..976e7658605 100644 --- a/test/style/style_parser.test.cpp +++ b/test/style/style_parser.test.cpp @@ -13,7 +13,12 @@ #include #include -#if !defined(_MSC_VER) || defined(__clang__) +#if defined(_MSC_VER) && !defined(__clang__) +#include +#ifdef GetObject +#undef GetObject +#endif +#else #include #endif @@ -63,6 +68,10 @@ TEST_P(StyleParserTest, ParseStyle) { js_entry[rapidjson::SizeType(3)].GetString() }; +#if defined(WIN32) + Sleep(10); +#endif + EXPECT_EQ(count, observer->count(message)) << "Message: " << message << std::endl; } } @@ -76,29 +85,47 @@ TEST_P(StyleParserTest, ParseStyle) { } } -// TODO: Microsoft Visual Studio complains about lambda in declaration -#if !defined(_MSC_VER) || defined(__clang__) +static void populateNames(std::vector& names) { + const std::string ending = ".info.json"; + + std::string style_directory = "test/fixtures/style_parser"; + + auto testName = [&](const std::string& name) { + if (name.length() >= ending.length() && + name.compare(name.length() - ending.length(), ending.length(), ending) == 0) { + names.push_back(name.substr(0, name.length() - ending.length())); + } + }; + +#if defined(_MSC_VER) && !defined(__clang__) + style_directory += "/*"; + WIN32_FIND_DATA ffd; + HANDLE hFind = FindFirstFile(style_directory.c_str(), &ffd); + if (hFind != INVALID_HANDLE_VALUE) { + do { + const std::string name = ffd.cFileName; + testName(name); + } while (FindNextFile(hFind, &ffd) != 0); + FindClose(hFind); + } +#else + DIR *dir = opendir(style_directory.c_str()); + if (dir != nullptr) { + for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) { + const std::string name = dp->d_name; + testName(name); + } + closedir(dir); + } +#endif +} + INSTANTIATE_TEST_SUITE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] { std::vector names; - const std::string ending = ".info.json"; - - const std::string style_directory = "test/fixtures/style_parser"; - DIR *dir = opendir(style_directory.c_str()); - if (dir != nullptr) { - for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) { - const std::string name = dp->d_name; - if (name.length() >= ending.length() && - name.compare(name.length() - ending.length(), ending.length(), ending) == 0) { - names.push_back(name.substr(0, name.length() - ending.length())); - } - } - closedir(dir); - } - + populateNames(names); EXPECT_GT(names.size(), 0u); return names; }())); -#endif TEST(StyleParser, FontStacks) { style::Parser parser; From 4f7ff2069c72013fe523f9daa158844223671ae2 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 6 Jun 2021 10:13:50 -0500 Subject: [PATCH 09/10] [qt] Backwards compatibility with Qt5 and Qt6 Minimum version is Qt 5.4 due to use of QOpenGLWidget --- CMakeLists.txt | 4 +- platform/qt/README.md | 2 +- platform/qt/app/mapwindow.cpp | 5 +++ platform/qt/qt.cmake | 43 +++++++++++----------- platform/qt/src/http_file_source.cpp | 7 ++++ platform/qt/src/local_glyph_rasterizer.cpp | 10 +++++ platform/qt/src/qmapboxgl.cpp | 5 +++ platform/qt/src/qt_image.cpp | 5 +++ 8 files changed, 58 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46972698292..dcaecd819a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) if(MBGL_WITH_QT) - find_package(Qt6Core REQUIRED) + find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) + set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) endif() diff --git a/platform/qt/README.md b/platform/qt/README.md index 3cb49c2ff3e..c0351db7056 100644 --- a/platform/qt/README.md +++ b/platform/qt/README.md @@ -44,7 +44,7 @@ The Windows build will assume you have installed and on the default path: - Microsoft Visual Studio 2015 - [CMake 3.10.1+](https://cmake.org/download/) - [LLVM 5.0.0+](https://releases.llvm.org/download.html) -- [Qt 5+](https://www.qt.io/download) with "msvc2015" support. +- [Qt 5.4+](https://www.qt.io/download) with "msvc2015" (or later) support. At runtime, you will also need installed: diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index 0d586fbeb2a..f46d51429d9 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -457,7 +457,12 @@ void MapWindow::wheelEvent(QWheelEvent *ev) factor = factor > -1 ? factor : 1 / factor; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) m_map->scaleBy(1 + factor, ev->position()); +#else + m_map->scaleBy(1 + factor, ev->pos()); +#endif + ev->accept(); } diff --git a/platform/qt/qt.cmake b/platform/qt/qt.cmake index 41aa013997e..6e9c65e36bf 100644 --- a/platform/qt/qt.cmake +++ b/platform/qt/qt.cmake @@ -1,10 +1,12 @@ # Note: Using Sqlite instead of QSqlDatabase for better compatibility. -find_package(Qt6Gui REQUIRED) -find_package(Qt6Network REQUIRED) -find_package(Qt6OpenGL REQUIRED) -find_package(Qt6OpenGLWidgets REQUIRED) -find_package(Qt6Widgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} + COMPONENTS Gui + Network + OpenGL + OpenGLWidgets + Widgets + REQUIRED) if(MSVC) add_definitions("/DQT_COMPILING_QIMAGE_COMPAT_CPP") @@ -92,11 +94,10 @@ target_link_libraries( PRIVATE $<$>:z> $<$>:mbgl-vendor-icu> - Qt6::Core - Qt6::Gui - Qt6::Network - Qt6::OpenGL - Qt6::OpenGLWidgets + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::OpenGL mbgl-vendor-nunicode mbgl-vendor-sqlite ) @@ -140,8 +141,8 @@ target_compile_definitions( target_link_libraries( qmapboxgl PRIVATE - Qt6::Core - Qt6::Gui + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui mbgl-compiler-options mbgl-core ) @@ -160,9 +161,9 @@ set_property(TARGET mbgl-qt PROPERTY CXX_STANDARD 98) target_link_libraries( mbgl-qt PRIVATE - Qt6::Widgets - Qt6::Gui - Qt6::OpenGLWidgets + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::OpenGLWidgets mbgl-compiler-options qmapboxgl ) @@ -186,18 +187,18 @@ if (MSVC) target_link_libraries( mbgl-test-runner PRIVATE - Qt6::Widgets - Qt6::Gui - Qt6::OpenGL + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::OpenGL mbgl-compiler-options ) else() target_link_libraries( mbgl-test-runner PRIVATE - Qt6::Widgets - Qt6::Gui - Qt6::OpenGL + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::OpenGL mbgl-compiler-options pthread ) diff --git a/platform/qt/src/http_file_source.cpp b/platform/qt/src/http_file_source.cpp index 48c4dfd018f..f7063597359 100644 --- a/platform/qt/src/http_file_source.cpp +++ b/platform/qt/src/http_file_source.cpp @@ -29,10 +29,17 @@ void HTTPFileSource::Impl::request(HTTPRequest* req) } QNetworkRequest networkRequest = req->networkRequest(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Not needed in Qt6 due to default redirect policy + networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); +#endif data.first = m_manager->get(networkRequest); connect(data.first, SIGNAL(finished()), this, SLOT(onReplyFinished())); +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) connect(data.first, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); +#else + connect(data.first, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyFinished())); +#endif } void HTTPFileSource::Impl::cancel(HTTPRequest* req) diff --git a/platform/qt/src/local_glyph_rasterizer.cpp b/platform/qt/src/local_glyph_rasterizer.cpp index 2f7662ea47c..5b7d6b7d0f7 100644 --- a/platform/qt/src/local_glyph_rasterizer.cpp +++ b/platform/qt/src/local_glyph_rasterizer.cpp @@ -52,7 +52,12 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { return glyph; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) glyph.metrics.width = impl->metrics->horizontalAdvance(glyphID); +#else + glyph.metrics.width = impl->metrics->width(glyphID); +#endif + glyph.metrics.height = impl->metrics->height(); glyph.metrics.left = 3; glyph.metrics.top = -8; @@ -68,8 +73,13 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) { // Render at constant baseline, to align with glyphs that are rendered by node-fontnik. painter.drawText(QPointF(0, 20), QString(QChar(glyphID))); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto img = std::make_unique(image.sizeInBytes()); memcpy(img.get(), image.constBits(), image.sizeInBytes()); +#else + auto img = std::make_unique(image.byteCount()); + memcpy(img.get(), image.constBits(), image.byteCount()); +#endif glyph.bitmap = AlphaImage { size, std::move(img) }; diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index aa3b535d799..288d6b8bc90 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -108,8 +108,13 @@ std::unique_ptr toStyleImage(const QString &id, const QImage .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto img = std::make_unique(swapped.sizeInBytes()); memcpy(img.get(), swapped.constBits(), swapped.sizeInBytes()); +#else + auto img = std::make_unique(swapped.byteCount()); + memcpy(img.get(), swapped.constBits(), swapped.byteCount()); +#endif return std::make_unique( id.toStdString(), diff --git a/platform/qt/src/qt_image.cpp b/platform/qt/src/qt_image.cpp index 519e9df4f8f..4cec62aa86d 100644 --- a/platform/qt/src/qt_image.cpp +++ b/platform/qt/src/qt_image.cpp @@ -45,8 +45,13 @@ PremultipliedImage decodeImage(const std::string& string) { throw std::runtime_error("Unsupported image type"); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) auto img = std::make_unique(image.sizeInBytes()); memcpy(img.get(), image.constBits(), image.sizeInBytes()); +#else + auto img = std::make_unique(image.byteCount()); + memcpy(img.get(), image.constBits(), image.byteCount()); +#endif return { { static_cast(image.width()), static_cast(image.height()) }, std::move(img) }; From c63136af40ee5d3a26129dc9ee447e0120b14295 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sun, 6 Jun 2021 10:59:41 -0500 Subject: [PATCH 10/10] [qt] LLVM is no longer required for a Windows build --- platform/qt/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/qt/README.md b/platform/qt/README.md index c0351db7056..936f7b7bd86 100644 --- a/platform/qt/README.md +++ b/platform/qt/README.md @@ -43,7 +43,7 @@ The Windows build will assume you have installed and on the default path: - Microsoft Visual Studio 2015 - [CMake 3.10.1+](https://cmake.org/download/) -- [LLVM 5.0.0+](https://releases.llvm.org/download.html) +- [LLVM 5.0.0+](https://releases.llvm.org/download.html) (optional) - [Qt 5.4+](https://www.qt.io/download) with "msvc2015" (or later) support. At runtime, you will also need installed: