[qt] Make unit tests build and run (#1042)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
3
.github/actions/qt5-build/entrypoint.sh
vendored
3
.github/actions/qt5-build/entrypoint.sh
vendored
@@ -16,7 +16,6 @@ cmake ../source/ \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
ninja
|
||||
ninja install
|
||||
|
||||
3
.github/actions/qt6-build/entrypoint.sh
vendored
3
.github/actions/qt6-build/entrypoint.sh
vendored
@@ -14,8 +14,7 @@ qt-cmake ../source/ \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache" \
|
||||
-DCMAKE_INSTALL_PREFIX=../install \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
ninja
|
||||
ninja install
|
||||
cd ../install
|
||||
|
||||
6
.github/workflows/qt-ci.yml
vendored
6
.github/workflows/qt-ci.yml
vendored
@@ -195,8 +195,7 @@ jobs:
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET="${DEPLOYMENT_TARGET}" \
|
||||
-DCMAKE_OSX_ARCHITECTURES="${DEPLOYMENT_ARCH}" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
ninja
|
||||
ninja install
|
||||
|
||||
@@ -222,8 +221,7 @@ jobs:
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER="ccache.exe" \
|
||||
-DCMAKE_INSTALL_PREFIX="../install" \
|
||||
-DMLN_WITH_QT=ON \
|
||||
-DMLN_QT_DEPLOYMENT=ON \
|
||||
-DMLN_QT_LIBRARY_ONLY=ON
|
||||
-DMLN_QT_DEPLOYMENT=ON
|
||||
ninja.exe
|
||||
ninja.exe install
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public:
|
||||
class Impl {
|
||||
public:
|
||||
virtual ~Impl() = default;
|
||||
virtual bool glNeedsActiveContextOnDestruction() const { return false; }
|
||||
virtual gl::ProcAddress getExtensionFunctionPointer(const char*) = 0;
|
||||
virtual void activateContext() = 0;
|
||||
virtual void deactivateContext() {}
|
||||
|
||||
@@ -45,10 +45,19 @@ HeadlessBackend::HeadlessBackend(const Size size_,
|
||||
|
||||
HeadlessBackend::~HeadlessBackend() {
|
||||
gfx::BackendScope guard{*this, gfx::BackendScope::ScopeType::Implicit};
|
||||
// Some implementations require active context for GL functions to work
|
||||
if (impl != nullptr && impl->glNeedsActiveContextOnDestruction()) {
|
||||
impl->activateContext();
|
||||
}
|
||||
// Explicitly reset the renderable resource
|
||||
resource.reset();
|
||||
// Explicitly reset the context so that it is destructed and cleaned up
|
||||
// before we destruct the impl object.
|
||||
context.reset();
|
||||
// Deactivate the context
|
||||
if (impl != nullptr && impl->glNeedsActiveContextOnDestruction()) {
|
||||
impl->deactivateContext();
|
||||
}
|
||||
}
|
||||
|
||||
gl::ProcAddress HeadlessBackend::getExtensionFunctionPointer(const char* name) {
|
||||
|
||||
@@ -33,6 +33,8 @@ else()
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
option(MLN_QT_WITH_INTERNAL_ICU "Build MapLibre GL Qt bindings with internal ICU" OFF)
|
||||
if(NOT MLN_QT_WITH_INTERNAL_ICU)
|
||||
find_package(ICU COMPONENTS uc REQUIRED)
|
||||
@@ -134,6 +136,7 @@ endif()
|
||||
target_link_libraries(
|
||||
mbgl-core
|
||||
PRIVATE
|
||||
$<$<PLATFORM_ID:Linux>:${CMAKE_THREAD_LIBS_INIT}>
|
||||
$<$<NOT:$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Emscripten>>>:z>
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
@@ -356,22 +359,16 @@ if(NOT MLN_QT_LIBRARY_ONLY)
|
||||
|
||||
target_compile_definitions(
|
||||
mbgl-test-runner
|
||||
PRIVATE WORK_DIRECTORY=${PROJECT_SOURCE_DIR}
|
||||
PRIVATE
|
||||
WORK_DIRECTORY=${PROJECT_SOURCE_DIR}
|
||||
$<$<PLATFORM_ID:Windows>:MBGL_BUILDING_LIB>
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_compile_definitions(
|
||||
mbgl-test-runner
|
||||
PRIVATE MBGL_BUILDING_LIB
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(
|
||||
mbgl-test-runner
|
||||
PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
mbgl-compiler-options
|
||||
$<$<NOT:$<BOOL:MSVC>>:pthread>
|
||||
)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
@@ -379,15 +376,6 @@ if(NOT MLN_QT_LIBRARY_ONLY)
|
||||
mbgl-test-runner
|
||||
PRIVATE -Wl,-force_load mbgl-test
|
||||
)
|
||||
elseif(MSVC)
|
||||
target_link_options(
|
||||
mbgl-test-runner
|
||||
PRIVATE /WHOLEARCHIVE:mbgl-test.lib
|
||||
)
|
||||
target_link_libraries(
|
||||
mbgl-test-runner
|
||||
PRIVATE mbgl-test
|
||||
)
|
||||
else()
|
||||
target_link_libraries(
|
||||
mbgl-test-runner
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include <mbgl/text/bidi.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
// This stub implementation is stateless and doesn't implement the private
|
||||
@@ -11,6 +11,7 @@ class BiDiImpl {
|
||||
};
|
||||
|
||||
std::u16string applyArabicShaping(const std::u16string& input) {
|
||||
// Qt does not support raw Arabic shaping, so we just return the input
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ public:
|
||||
QtBackendImpl() {
|
||||
// QtBackendImpl must be created in the main/GUI thread on platforms
|
||||
// that have a QWindow-based QOffscreenSurface.
|
||||
surface.create();
|
||||
context.create();
|
||||
surface.create();
|
||||
}
|
||||
~QtBackendImpl() = default;
|
||||
|
||||
@@ -27,6 +27,8 @@ public:
|
||||
|
||||
void deactivateContext() { context.doneCurrent(); }
|
||||
|
||||
bool glNeedsActiveContextOnDestruction() const { return true; }
|
||||
|
||||
private:
|
||||
QOpenGLContext context;
|
||||
QOffscreenSurface surface;
|
||||
|
||||
@@ -61,7 +61,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
|
||||
$<$<NOT:$<PLATFORM_ID:Windows>>:${PROJECT_SOURCE_DIR}/test/text/bidi.test.cpp>
|
||||
$<$<AND:$<NOT:$<BOOL:MBGL_WITH_QT>>,$<NOT:$<PLATFORM_ID:Windows>>>:${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
|
||||
|
||||
3
test/fixtures/.gitignore
vendored
3
test/fixtures/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
diff.png
|
||||
actual.png
|
||||
actual.png
|
||||
*.db
|
||||
|
||||
BIN
test/fixtures/local_glyphs/ping_fang_qt/expected.png
vendored
BIN
test/fixtures/local_glyphs/ping_fang_qt/expected.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 28 KiB |
BIN
test/fixtures/offline_database/offline_sideload.db
vendored
BIN
test/fixtures/offline_database/offline_sideload.db
vendored
Binary file not shown.
@@ -7,6 +7,10 @@
|
||||
namespace mbgl {
|
||||
|
||||
int runTests(int argc, char *argv[]) {
|
||||
#if TEST_HAS_SERVER && defined(__QT__)
|
||||
auto server = std::make_unique<test::HttpServer>();
|
||||
#endif
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
// In order to run specific tests
|
||||
|
||||
@@ -685,7 +685,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) {
|
||||
|
||||
{ OfflineDatabase dbCreate(filename, fixture::tileServerOptions); }
|
||||
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
size_t initialSize = util::read_file(filename).size();
|
||||
#endif
|
||||
|
||||
{
|
||||
Response response;
|
||||
@@ -732,13 +734,17 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DeleteRegion)) {
|
||||
// The tiles from the offline region will migrate to the
|
||||
// ambient cache and shrink the database to the maximum
|
||||
// size defined by default.
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
EXPECT_LE(sizeWithoutRegions, util::DEFAULT_MAX_CACHE_SIZE);
|
||||
#endif
|
||||
|
||||
ASSERT_EQ(0u, db.listRegions().value().size());
|
||||
EXPECT_LT(sizeWithoutRegions, sizeWithOneRegion);
|
||||
}
|
||||
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
EXPECT_EQ(initialSize, util::read_file(filename).size());
|
||||
#endif
|
||||
EXPECT_EQ(0u, log.uncheckedCount());
|
||||
}
|
||||
|
||||
@@ -769,7 +775,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Pack)) {
|
||||
EXPECT_EQ(0u, log.uncheckedCount());
|
||||
|
||||
db.pack();
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
EXPECT_EQ(initialSize, util::read_file(filename).size());
|
||||
#endif
|
||||
EXPECT_EQ(0u, log.uncheckedCount());
|
||||
}
|
||||
|
||||
@@ -976,7 +984,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ClearAmbientCache)) {
|
||||
|
||||
{ OfflineDatabase dbCreate(filename, fixture::tileServerOptions); }
|
||||
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
size_t initialSize = util::read_file(filename).size();
|
||||
#endif
|
||||
|
||||
{
|
||||
Response response;
|
||||
@@ -996,7 +1006,9 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ClearAmbientCache)) {
|
||||
db.clearAmbientCache();
|
||||
}
|
||||
|
||||
#ifndef __QT__ // Qt doesn't decrease the size of the database file.
|
||||
EXPECT_EQ(initialSize, util::read_file(filename).size());
|
||||
#endif
|
||||
EXPECT_EQ(0u, log.uncheckedCount());
|
||||
}
|
||||
|
||||
@@ -1016,6 +1028,7 @@ TEST(OfflineDatabase, CreateRegionInfiniteMaxZoom) {
|
||||
});
|
||||
}
|
||||
|
||||
#ifndef __QT__ // Qt doesn't support concurrent access to the same database.
|
||||
TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) {
|
||||
FixtureLog log;
|
||||
deleteDatabaseFiles();
|
||||
@@ -1048,6 +1061,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(ConcurrentUse)) {
|
||||
|
||||
EXPECT_EQ(0u, log.uncheckedCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(OfflineDatabase, PutReturnsSize) {
|
||||
FixtureLog log;
|
||||
|
||||
Reference in New Issue
Block a user