diff options
Diffstat (limited to 'tests/auto/corelib/plugin/qlibrary')
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/CMakeLists.txt | 9 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib/.prev_CMakeLists.txt | 34 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt | 58 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib/lib.pro | 21 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib/mylib.c | 29 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt | 114 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro | 53 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/lib2/mylib.c | 29 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/qlibrary.pro | 15 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/tst/.prev_CMakeLists.txt | 37 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt | 43 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/tst/tst.pro | 25 | ||||
-rw-r--r-- | tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp | 288 |
13 files changed, 330 insertions, 425 deletions
diff --git a/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt index c0faebc91d..b8f4af5aa8 100644 --- a/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qlibrary.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qlibrary LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(lib) add_subdirectory(lib2) diff --git a/tests/auto/corelib/plugin/qlibrary/lib/.prev_CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib/.prev_CMakeLists.txt deleted file mode 100644 index 93a2b1a455..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/lib/.prev_CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Generated from lib.pro. - -##################################################################### -## mylib Generic Library: -##################################################################### - -qt_internal_add_cmake_library(mylib - SHARED - INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/tst_qlibrary" - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - mylib.c - PUBLIC_LIBRARIES - Qt::Core -) - -#### Keys ignored in scope 1:.:.:lib.pro:<TRUE>: -# INSTALLS = "target" -# TEMPLATE = "lib" -# target.path = "$$[QT_INSTALL_TESTS]/tst_qlibrary" - -## Scopes: -##################################################################### - -qt_internal_extend_target(mylib CONDITION MSVC - DEFINES - WIN32_MSVC -) - -#### Keys ignored in scope 4:.:.:lib.pro:(CMAKE_BUILD_TYPE STREQUAL Debug): -# DESTDIR = "../debug/" - -#### Keys ignored in scope 5:.:.:lib.pro:else: -# DESTDIR = "../release/" diff --git a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt index 4b2e01d997..1a318e1483 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/lib/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from lib.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## mylib Generic Library: @@ -7,14 +8,12 @@ qt_internal_add_cmake_library(mylib SHARED INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/tst_qlibrary" - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES mylib.c - PUBLIC_LIBRARIES + LIBRARIES Qt::Core ) -# special case begin set_target_properties(mylib PROPERTIES VERSION 1.0.0 SOVERSION 1 @@ -27,12 +26,45 @@ if(WIN32) set_property(TARGET mylib PROPERTY PREFIX "") endif() -# special case end - -#### Keys ignored in scope 1:.:.:lib.pro:<TRUE>: -# INSTALLS = "target" -# TEMPLATE = "lib" -# target.path = "$$[QT_INSTALL_TESTS]/tst_qlibrary" +if(UNIX) + if(APPLE) + add_custom_command(TARGET mylib POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib> + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.1.0.0.dylib" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.1.0.0.dylib" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.1.dylib" + VERBATIM) + elseif(NOT ANDROID) + add_custom_command(TARGET mylib POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib> + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1.0.0" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.so.1.0.0" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.1" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.so.1.0.0" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so1" + VERBATIM) + else() + # Android does not use symlinks. Also, according to our conventions, + # libraries on Android MUST be named in the following pattern: + # lib*.so + add_custom_command(TARGET mylib POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib> + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" + VERBATIM) + endif() +else() #Win32 + add_custom_command(TARGET mylib POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib> + "${CMAKE_CURRENT_BINARY_DIR}/../mylib.dll" + VERBATIM) +endif() ## Scopes: ##################################################################### @@ -41,9 +73,3 @@ qt_internal_extend_target(mylib CONDITION MSVC DEFINES WIN32_MSVC ) - -#### Keys ignored in scope 4:.:.:lib.pro:(CMAKE_BUILD_TYPE STREQUAL Debug): -# DESTDIR = "../debug/" - -#### Keys ignored in scope 5:.:.:lib.pro:else: -# DESTDIR = "../release/" diff --git a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro deleted file mode 100644 index 2c3305e872..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro +++ /dev/null @@ -1,21 +0,0 @@ -TEMPLATE = lib -CONFIG += dll -CONFIG -= staticlib -SOURCES = mylib.c -TARGET = mylib -DESTDIR = ../ -QT = core - -msvc: DEFINES += WIN32_MSVC - -# This project is testdata for tst_qlibrary -target.path = $$[QT_INSTALL_TESTS]/tst_qlibrary -INSTALLS += target - -win32:debug_and_release { - CONFIG(debug, debug|release) { - DESTDIR = ../debug/ - } else { - DESTDIR = ../release/ - } -} diff --git a/tests/auto/corelib/plugin/qlibrary/lib/mylib.c b/tests/auto/corelib/plugin/qlibrary/lib/mylib.c index 419c22a446..61fe52d182 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/mylib.c +++ b/tests/auto/corelib/plugin/qlibrary/lib/mylib.c @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qglobal.h> diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt index f92cec8fb1..f6bdeb453a 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/lib2/CMakeLists.txt @@ -1,20 +1,20 @@ -# Generated from lib2.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## mylib Generic Library: ##################################################################### -qt_internal_add_cmake_library(mylib2 # special case +qt_internal_add_cmake_library(mylib2 SHARED INSTALL_DIRECTORY "${INSTALL_TESTSDIR}tst_qlibrary" - #OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case + #OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES mylib.c - PUBLIC_LIBRARIES + LIBRARIES Qt::Core ) -# special case begin # This test is very "annoying" to get working with CMake as it involves having # two targets with the same name on the parent scope, which is not possible with # CMake. Furthermore, on UNIX, this version of the library should override the @@ -39,27 +39,57 @@ if(WIN32) set_property(TARGET mylib2 PROPERTY PREFIX "") endif() -if (UNIX) - add_dependencies(mylib2 mylib) - add_custom_command(TARGET mylib2 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - $<TARGET_FILE:mylib2> - "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so" - COMMAND ${CMAKE_COMMAND} -E copy_if_different +if(UNIX) + if(APPLE) + add_custom_command(TARGET mylib2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib2> + "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so.dylib" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib2> + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.2.0.0.dylib" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.2.0.0.dylib" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.2.dylib" + COMMAND ${CMAKE_COMMAND} -E remove + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.dylib" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.2.0.0.dylib" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.dylib" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.2.0.0.dylib" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2.dylib" + VERBATIM) + elseif(NOT ANDROID) + add_custom_command(TARGET mylib2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib2> + "${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $<TARGET_FILE:mylib2> + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.so.2.0.0" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2" + COMMAND ${CMAKE_COMMAND} -E remove + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.so.2.0.0" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "libmylib.so.2.0.0" + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2" + VERBATIM) + else() + # Android does not use symlinks. Also, according to our conventions, + # libraries on Android MUST be named in the following pattern: + # lib*.so + add_custom_command(TARGET mylib2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:mylib2> - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0" - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0" - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2" - COMMAND ${CMAKE_COMMAND} -E remove - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0" - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so" - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so.2.0.0" - "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2" - ) + "${CMAKE_CURRENT_BINARY_DIR}/../libsystem.qt.test.mylib.so" + VERBATIM) + endif() else() #Win32 add_custom_command(TARGET mylib2 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different @@ -68,43 +98,13 @@ else() #Win32 COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:mylib2> "${CMAKE_CURRENT_BINARY_DIR}/../mylib.dl2" - ) + VERBATIM) endif() -# special case end - -#### Keys ignored in scope 1:.:.:lib2.pro:<TRUE>: -# INSTALLS = "target" "renamed_target" -# QMAKE_POST_LINK = "$$member(QMAKE_POST_LINK, 0, -2)" -# TEMPLATE = "lib" -# VERSION = "2" -# renamed_target.extra = "$$member(renamed_target.extra, 0, -2)" -# renamed_target.path = "$$target.path" -# target.path = "$$[QT_INSTALL_TESTS]$${QMAKE_DIR_SEP}tst_qlibrary" ## Scopes: ##################################################################### -qt_internal_extend_target(mylib2 CONDITION MSVC # special case +qt_internal_extend_target(mylib2 CONDITION MSVC DEFINES WIN32_MSVC ) - -#### Keys ignored in scope 3:.:.:lib2.pro:WIN32: -# DESTDIR = "../$$BUILD_FOLDER/" -# files = "$$BUILD_FOLDER$${QMAKE_DIR_SEP}mylib.dl2" "$$BUILD_FOLDER$${QMAKE_DIR_SEP}system.qt.test.mylib.dll" - -#### Keys ignored in scope 4:.:.:lib2.pro:(CMAKE_BUILD_TYPE STREQUAL Debug): -# BUILD_FOLDER = "debug" - -#### Keys ignored in scope 5:.:.:lib2.pro:else: -# BUILD_FOLDER = "release" - -#### Keys ignored in scope 6:.:.:lib2.pro:TEMPLATE___contains___vc._x_: -# src = "$(TargetPath)" - -#### Keys ignored in scope 7:.:.:lib2.pro:else: -# src = "$(DESTDIR_TARGET)" - -#### Keys ignored in scope 8:.:.:lib2.pro:else: -# files = "libmylib.so2" "system.qt.test.mylib.so" -# src = "$(DESTDIR)$(TARGET)" diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro deleted file mode 100644 index 3db4bed973..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro +++ /dev/null @@ -1,53 +0,0 @@ -TEMPLATE = lib -CONFIG += dll -CONFIG -= staticlib -SOURCES = mylib.c -TARGET = mylib -DESTDIR = ../ -VERSION = 2 -QT = core - -msvc: DEFINES += WIN32_MSVC - -# Force a copy of the library to have an extension that is non-standard. -# We want to test if we can load a shared library with *any* filename... - -win32 { - - debug_and_release { - CONFIG(debug, debug|release)) { - BUILD_FOLDER = debug - } else { - BUILD_FOLDER = release - } - DESTDIR = ../$$BUILD_FOLDER/ - } else { - BUILD_FOLDER = - DESTDIR = ../ - } - - # vcproj and Makefile generators refer to target differently - contains(TEMPLATE,vc.*) { - src = $(TargetPath) - } else { - src = $(DESTDIR_TARGET) - } - files = $$BUILD_FOLDER$${QMAKE_DIR_SEP}mylib.dl2 $$BUILD_FOLDER$${QMAKE_DIR_SEP}system.qt.test.mylib.dll -} else { - src = $(DESTDIR)$(TARGET) - files = libmylib.so2 system.qt.test.mylib.so -} - -# This project is testdata for tst_qlibrary -target.path = $$[QT_INSTALL_TESTS]$${QMAKE_DIR_SEP}tst_qlibrary -renamed_target.path = $$target.path - -for(file, files) { - QMAKE_POST_LINK += $$QMAKE_COPY $$src ..$$QMAKE_DIR_SEP$$file && - renamed_target.extra += $$QMAKE_COPY $$src $(INSTALL_ROOT)$${target.path}$$QMAKE_DIR_SEP$$file && - CLEAN_FILES += ..$$QMAKE_DIR_SEP$$file -} -renamed_target.extra = $$member(renamed_target.extra, 0, -2) -QMAKE_POST_LINK = $$member(QMAKE_POST_LINK, 0, -2) - -INSTALLS += target renamed_target diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c b/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c index 74eb68b2ac..5312a9355b 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c +++ b/tests/auto/corelib/plugin/qlibrary/lib2/mylib.c @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qglobal.h> diff --git a/tests/auto/corelib/plugin/qlibrary/qlibrary.pro b/tests/auto/corelib/plugin/qlibrary/qlibrary.pro deleted file mode 100644 index ec230601c4..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/qlibrary.pro +++ /dev/null @@ -1,15 +0,0 @@ -QT = core -TEMPLATE = subdirs - -tst.depends = lib lib2 -# lib2 has to be installed after lib, so that plain libmylib.so symlink points -# to version 2 as expected by the test -lib2.depends = lib - -SUBDIRS = lib \ - lib2 \ - tst -TARGET = tst_qlibrary - -# no special install rule for subdir -INSTALLS = diff --git a/tests/auto/corelib/plugin/qlibrary/tst/.prev_CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/tst/.prev_CMakeLists.txt deleted file mode 100644 index 6e4ce15f44..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/tst/.prev_CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Generated from tst.pro. - -##################################################################### -## tst_qlibrary Test: -##################################################################### - -# Collect test data -list(APPEND test_data "../library_path/invalid.so") - -qt_internal_add_test(tst_qlibrary - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - ../tst_qlibrary.cpp - TESTDATA ${test_data} -) - -## Scopes: -##################################################################### - -if(ANDROID) - # Resources: - set(qmake_libs_resource_files - ${CMAKE_CURRENT_BINARY_DIR}/../libmylib.prl - ${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so - ${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2 - ${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so - ) - - qt_internal_add_resource(tst_qlibrary "qmake_libs" - PREFIX - "android_test_data" - BASE - "${CMAKE_CURRENT_BINARY_DIR}/.." - FILES - ${qmake_libs_resource_files} - ) -endif() diff --git a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt index ef062a53a2..fc452f37f5 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt +++ b/tests/auto/corelib/plugin/qlibrary/tst/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from tst.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qlibrary Test: @@ -12,40 +13,16 @@ qt_internal_add_test(tst_qlibrary SOURCES ../tst_qlibrary.cpp TESTDATA ${test_data} - LIBRARIES mylib mylib2 # special case + LIBRARIES mylib mylib2 ) -## Scopes: -##################################################################### +add_dependencies(tst_qlibrary mylib mylib2) if(ANDROID) - # special case begin - set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so - PROPERTIES QT_RESOURCE_TARGET_DEPENDENCY mylib - ) - set_source_files_properties( - ${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so2 - ${CMAKE_CURRENT_BINARY_DIR}/../system.qt.test.mylib.so - PROPERTIES QT_RESOURCE_TARGET_DEPENDENCY mylib2 - ) - # special case end - # Resources: - set(qmake_libs_resource_files - # special case begin - #libmylib.prl - libmylib.so - libmylib.so2 - system.qt.test.mylib.so - # special case end - ) - - qt_internal_add_resource(tst_qlibrary "qmake_libs" - PREFIX - "android_test_data" - BASE - "${CMAKE_CURRENT_BINARY_DIR}/.." - FILES - ${qmake_libs_resource_files} - ) + list(APPEND extra_libs + "${CMAKE_CURRENT_BINARY_DIR}/../libmylib.so") + list(APPEND extra_libs + "${CMAKE_CURRENT_BINARY_DIR}/../libsystem.qt.test.mylib.so") + set_target_properties(tst_qlibrary PROPERTIES + QT_ANDROID_EXTRA_LIBS "${extra_libs}") endif() diff --git a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro b/tests/auto/corelib/plugin/qlibrary/tst/tst.pro deleted file mode 100644 index 5894bee9d5..0000000000 --- a/tests/auto/corelib/plugin/qlibrary/tst/tst.pro +++ /dev/null @@ -1,25 +0,0 @@ -CONFIG += testcase -TARGET = ../tst_qlibrary -QT = core testlib -SOURCES = ../tst_qlibrary.cpp - -win32:debug_and_release { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qlibrary - } else { - TARGET = ../../release/tst_qlibrary - } -} - -TESTDATA += ../library_path/invalid.so - -android { - libs.prefix = android_test_data - libs.base = $$OUT_PWD/.. - libs.files += $$OUT_PWD/../libmylib.so \ - $$OUT_PWD/../libmylib.so2 \ - $$OUT_PWD/../libmylib.prl \ - $$OUT_PWD/../system.qt.test.mylib.so - - RESOURCES += libs -} diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index 0898817240..28f4581997 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -1,33 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> #include <qdir.h> #include <qlibrary.h> #include <QtCore/QRegularExpression> @@ -104,24 +79,27 @@ enum QLibraryOperation { QString sys_qualifiedLibraryName(const QString &fileName); QString directory; -#ifdef Q_OS_ANDROID - QSharedPointer<QTemporaryDir> temporaryDir; -#endif private slots: void initTestCase(); + void cleanup(); - void load(); void load_data(); - void library_data(); + void load(); void resolve_data(); void resolve(); void unload_data(); void unload(); void unload_after_implicit_load(); + void setFilenameAfterFailedLoad(); + void loadAfterFailedLoad(); void isLibrary_data(); void isLibrary(); void version_data(); void version(); + void loadTwoVersions(); + void setFileNameAndVersionTwice(); + void setFileNameAndVersionAfterFailedLoad_data() { version_data(); } + void setFileNameAndVersionAfterFailedLoad(); void errorString_data(); void errorString(); void loadHints(); @@ -141,24 +119,9 @@ typedef int (*VersionFunction)(void); void tst_QLibrary::initTestCase() { #ifdef Q_OS_ANDROID - auto tempDir = QEXTRACTTESTDATA("android_test_data"); - - QVERIFY2(QDir::setCurrent(tempDir->path()), qPrintable("Could not chdir to " + tempDir->path())); - - // copy :/library_path into ./library_path - QVERIFY(QDir().mkdir("library_path")); - QDirIterator iterator(":/library_path", QDirIterator::Subdirectories); - while (iterator.hasNext()) { - iterator.next(); - QFileInfo sourceFileInfo(iterator.path()); - QFileInfo targetFileInfo("./library_path/" + sourceFileInfo.fileName()); - if (!targetFileInfo.exists()) { - QDir().mkpath(targetFileInfo.path()); - QVERIFY(QFile::copy(sourceFileInfo.filePath(), targetFileInfo.filePath())); - } - } - directory = tempDir->path(); - temporaryDir = std::move(tempDir); + const QStringList paths = QCoreApplication::libraryPaths(); + QVERIFY(!paths.isEmpty()); + directory = paths.first(); #else // chdir to our testdata directory, and use relative paths in some tests. QString testdatadir = QFileInfo(QFINDTESTDATA("library_path")).absolutePath(); @@ -167,6 +130,38 @@ void tst_QLibrary::initTestCase() #endif } +void tst_QLibrary::cleanup() +{ + // unload the libraries, if they are still loaded after the test ended + // (probably in a failure) + + static struct { + QString name; + int version = -1; + } libs[] = { + { directory + "/mylib" }, + { directory + "/mylib", 1 }, + { directory + "/mylib", 2 }, + { sys_qualifiedLibraryName("mylib") }, + + // stuff that load_data() succeeds with + { directory + "/" PREFIX "mylib" }, + { directory + "/" PREFIX "mylib" SUFFIX }, +#if defined(Q_OS_WIN32) + { directory + "/mylib.dl2" }, + { directory + "/system.qt.test.mylib.dll" }, +#elif !defined(Q_OS_ANDROID) + // .so even on macOS + { directory + "/libmylib.so2" }, + { directory + "/system.qt.test.mylib.so" }, +#endif + + }; + for (const auto &entry : libs) { + do {} while (QLibrary(entry.name, entry.version).unload()); + } +} + void tst_QLibrary::version_data() { #ifdef Q_OS_ANDROID @@ -203,6 +198,70 @@ void tst_QLibrary::version() #endif } +void tst_QLibrary::loadTwoVersions() +{ +#if defined(Q_OS_ANDROID) || defined(Q_OS_WIN) + QSKIP("Versioned files are not generated for this OS, so this test is not applicable."); +#endif + + QLibrary lib1(directory + "/mylib", 1); + QLibrary lib2(directory + "/mylib", 2); + QVERIFY(!lib1.isLoaded()); + QVERIFY(!lib2.isLoaded()); + + // load the first one + QVERIFY(lib1.load()); + QVERIFY(lib1.isLoaded()); + + // let's see if we can load the second one too + QVERIFY(lib2.load()); + QVERIFY(lib2.isLoaded()); + + auto p1 = (VersionFunction)lib1.resolve("mylibversion"); + QVERIFY(p1); + + auto p2 = (VersionFunction)lib2.resolve("mylibversion"); + QVERIFY(p2); + + QCOMPARE_NE(p1(), p2()); + + lib2.unload(); + lib1.unload(); +} + +void tst_QLibrary::setFileNameAndVersionTwice() +{ +#if defined(Q_OS_ANDROID) || defined(Q_OS_WIN) + QSKIP("Versioned files are not generated for this OS, so this test is not applicable."); +#endif + + QLibrary library(directory + "/mylib", 1); + QVERIFY(library.load()); + QVERIFY(library.isLoaded()); + + auto p1 = (VersionFunction)library.resolve("mylibversion"); + QVERIFY(p1); + // don't .unload() + + library.setFileNameAndVersion(directory + "/mylib", 2); + QVERIFY(!library.isLoaded()); + QVERIFY(library.load()); + QVERIFY(library.isLoaded()); + + auto p2 = (VersionFunction)library.resolve("mylibversion"); + QVERIFY(p2); + QCOMPARE_NE(p1(), p2()); + + QVERIFY(library.unload()); + QVERIFY(!library.isLoaded()); + + // set back + // it'll look like it isn't loaded, but it is and we can't unload it! + library.setFileNameAndVersion(directory + "/mylib", 1); + QVERIFY(!library.isLoaded()); + QVERIFY(!library.unload()); +} + void tst_QLibrary::load_data() { QTest::addColumn<QString>("lib"); @@ -214,7 +273,7 @@ void tst_QLibrary::load_data() QTest::newRow( "notexist" ) << appDir + "/nolib" << false; QTest::newRow( "badlibrary" ) << appDir + "/qlibrary.pro" << false; -#ifdef Q_OS_MAC +#ifdef Q_OS_DARWIN QTest::newRow("ok (libmylib ver. 1)") << appDir + "/libmylib" <<true; #endif @@ -224,7 +283,10 @@ void tst_QLibrary::load_data() QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << true; # elif defined Q_OS_UNIX QTest::newRow( "ok01 (with suffix)" ) << appDir + "/libmylib" SUFFIX << true; +#ifndef Q_OS_ANDROID + // We do not support non-standard suffixes on Android QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/libmylib.so2" << true; +#endif QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.so" << true; # endif // Q_OS_UNIX } @@ -280,6 +342,76 @@ void tst_QLibrary::unload_after_implicit_load() QCOMPARE(library.isLoaded(), false); } +void tst_QLibrary::setFilenameAfterFailedLoad() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID) + QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt"); +#endif + + QLibrary library(directory + "/nolib"); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + + library.setFileName(directory + "/mylib"); + QVERIFY(library.load()); + QVERIFY(library.isLoaded()); + auto p = (VersionFunction)library.resolve("mylibversion"); + QVERIFY(p); + QCOMPARE(p(), 2); + library.unload(); +} + +void tst_QLibrary::setFileNameAndVersionAfterFailedLoad() +{ + QLibrary library(directory + "/nolib"); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + +#if !defined(Q_OS_AIX) && !defined(Q_OS_WIN) + QFETCH(QString, lib); + QFETCH(int, loadversion); + QFETCH(int, resultversion); + + library.setFileNameAndVersion(directory + '/' + lib, loadversion); + QVERIFY(library.load()); + QVERIFY(library.isLoaded()); + auto p = (VersionFunction)library.resolve("mylibversion"); + QVERIFY(p); + QCOMPARE(p(), resultversion); + library.unload(); +#endif +} + +void tst_QLibrary::loadAfterFailedLoad() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_ANDROID) + QSKIP("### FIXME: The helper libraries are currently messed up in the CMakeLists.txt"); +#endif + + QTemporaryDir dir; + QLibrary library(dir.path() + "/mylib"); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + QVERIFY(!library.load()); + QVERIFY(!library.isLoaded()); + + // now copy the actual lib file into our dir + QString actualLib = PREFIX "mylib" SUFFIX; + QVERIFY(QFile::copy(directory + '/' + actualLib, dir.filePath(actualLib))); + + // try again, must succeed now + QVERIFY(library.load()); + QVERIFY(library.isLoaded()); + auto p = (VersionFunction)library.resolve("mylibversion"); + QVERIFY(p); + QCOMPARE(p(), 2); + library.unload(); +} + void tst_QLibrary::resolve_data() { QTest::addColumn<QString>("lib"); @@ -300,21 +432,27 @@ void tst_QLibrary::resolve() QFETCH( QString, symbol ); QFETCH( bool, goodPointer ); - QLibrary library( lib ); - testFunc func = (testFunc) library.resolve( symbol.toLatin1() ); - if ( goodPointer ) { - QVERIFY( func != 0 ); + QLibrary library(lib); + QVERIFY(!library.isLoaded()); + testFunc func = (testFunc) library.resolve(symbol.toLatin1()); + + if (goodPointer) { + QVERIFY(library.isLoaded()); + QVERIFY(func); + + QLibrary lib2(lib); + QVERIFY(!lib2.isLoaded()); + QVERIFY(lib2.load()); + + // this unload() won't unload and it must still be loaded + QVERIFY(!lib2.unload()); + func(); // doesn't crash } else { - QVERIFY( func == 0 ); + QVERIFY(func == nullptr); } library.unload(); } -void tst_QLibrary::library_data() -{ - QTest::addColumn<QString>("lib"); -} - void tst_QLibrary::isLibrary_data() { QTest::addColumn<QString>("filename"); @@ -335,7 +473,7 @@ void tst_QLibrary::isLibrary_data() QTest::newRow("version+.so+version") << QString("liboil-0.3.so.0.1.0") << so_VALID; // special tests: -#ifdef Q_OS_MAC +#ifdef Q_OS_DARWIN QTest::newRow("good (libmylib.1.0.0.dylib)") << QString("libmylib.1.0.0.dylib") << true; QTest::newRow("good (libmylib.dylib)") << QString("libmylib.dylib") << true; QTest::newRow("good (libmylib.so)") << QString("libmylib.so") << true; @@ -372,7 +510,7 @@ void tst_QLibrary::errorString_data() #ifdef Q_OS_WIN QTest::newRow("bad load() with .dll suffix") << (int)Load << QString("nosuchlib.dll") << false << QString("Cannot load library nosuchlib.dll: The specified module could not be found."); // QTest::newRow("bad unload") << (int)Unload << QString("nosuchlib.dll") << false << QString("QLibrary::unload_sys: Cannot unload nosuchlib.dll (The specified module could not be found.)"); -#elif defined Q_OS_MAC +#elif defined Q_OS_DARWIN #else QTest::newRow("load invalid file") << (int)Load << QFINDTESTDATA("library_path/invalid.so") << false << QString("Cannot load library.*"); #endif @@ -438,7 +576,10 @@ void tst_QLibrary::loadHints_data() QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << int(lh) << true; # elif defined Q_OS_UNIX QTest::newRow( "ok01 (with suffix)" ) << appDir + "/libmylib" SUFFIX << int(lh) << true; +#ifndef Q_OS_ANDROID + // We do not support non-standard suffixes on Android QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/libmylib.so2" << int(lh) << true; +#endif QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.so" << int(lh) << true; # endif // Q_OS_UNIX } @@ -517,7 +658,7 @@ void tst_QLibrary::multipleInstancesForOneLibrary() QCOMPARE(lib2.isLoaded(), false); lib1.load(); QCOMPARE(lib1.isLoaded(), true); - QCOMPARE(lib2.isLoaded(), true); + QCOMPARE(lib2.isLoaded(), false); // lib2 didn't call load() QCOMPARE(lib1.unload(), true); QCOMPARE(lib1.isLoaded(), false); QCOMPARE(lib2.isLoaded(), false); @@ -526,7 +667,7 @@ void tst_QLibrary::multipleInstancesForOneLibrary() QCOMPARE(lib1.isLoaded(), true); QCOMPARE(lib2.isLoaded(), true); QCOMPARE(lib1.unload(), false); - QCOMPARE(lib1.isLoaded(), true); + QCOMPARE(lib1.isLoaded(), false); // lib1 did call unload() QCOMPARE(lib2.isLoaded(), true); QCOMPARE(lib2.unload(), true); QCOMPARE(lib1.isLoaded(), false); @@ -535,17 +676,6 @@ void tst_QLibrary::multipleInstancesForOneLibrary() // Finally; unload on that is already unloaded QCOMPARE(lib1.unload(), false); } - - //now let's try with a 3rd one that will go out of scope - { - QLibrary lib1(lib); - QCOMPARE(lib1.isLoaded(), false); - lib1.load(); - QCOMPARE(lib1.isLoaded(), true); - } - QLibrary lib2(lib); - //lib2 should be loaded because lib1 was loaded and never unloaded - QCOMPARE(lib2.isLoaded(), true); } QTEST_MAIN(tst_QLibrary) |