diff options
Diffstat (limited to 'sources/shiboken6/tests')
369 files changed, 6814 insertions, 12338 deletions
diff --git a/sources/shiboken6/tests/CMakeLists.txt b/sources/shiboken6/tests/CMakeLists.txt index bfa92e229..05f6e9e60 100644 --- a/sources/shiboken6/tests/CMakeLists.txt +++ b/sources/shiboken6/tests/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 3.16) +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.18) if(BUILD_TESTS) find_package(Qt${QT_MAJOR_VERSION}Test 6.0 REQUIRED) @@ -11,6 +14,8 @@ if(NOT DEFINED MINIMAL_TESTS) add_subdirectory(libother) endif() +shiboken_get_debug_level(debug_level) + if(WIN32 OR DEFINED AVOID_PROTECTED_HACK) message(STATUS "Tests will be generated avoiding the protected hack!") set(GENERATOR_EXTRA_FLAGS --avoid-protected-hack) @@ -18,6 +23,7 @@ else() message(STATUS "Tests will be generated using the protected hack!") set(GENERATOR_EXTRA_FLAGS ) endif() +list(APPEND GENERATOR_EXTRA_FLAGS ${SHIBOKEN_GENERATOR_EXTRA_FLAGS} ${debug_level}) add_subdirectory(minimalbinding) if(NOT DEFINED MINIMAL_TESTS) @@ -39,7 +45,21 @@ list(SORT TEST_FILES) set(test_blacklist "") -find_package(PythonInterp REQUIRED) +if(SHIBOKEN_IS_CROSS_BUILD) + # Python_EXECUTABLE will be empty when cross-building. + message(WARNING + "Running tests when cross-compiling is not supported because it would require running " + "a target python interpreter which might have a different architecture than the host." + ) +else() + find_package( + Python + ${USE_PYTHON_VERSION} + REQUIRED + COMPONENTS Interpreter Development + ) +endif() + if(NOT CTEST_TESTING_TIMEOUT) set(CTEST_TESTING_TIMEOUT 60) endif() @@ -51,7 +71,7 @@ foreach(test_file ${TEST_FILES}) string(REGEX MATCH "/([^/]+)(binding|module)/([^/]+)_test.py" tmp ${test_file}) set(test_name "${CMAKE_MATCH_1}_${CMAKE_MATCH_3}") list(FIND test_blacklist ${test_name} expect_fail) - add_test(${test_name} ${PYTHON_EXECUTABLE} ${test_file}) + add_test(${test_name} ${Python_EXECUTABLE} ${test_file}) set_tests_properties(${test_name} PROPERTIES ENVIRONMENT "BUILD_DIR=${BUILD_DIR}") set_tests_properties(${test_name} PROPERTIES TIMEOUT ${CTEST_TESTING_TIMEOUT}) if (${expect_fail} GREATER -1) @@ -59,7 +79,10 @@ foreach(test_file ${TEST_FILES}) endif() endforeach() -add_subdirectory(dumpcodemodel) +# dumpcodemodel depends on apiextractor which is not cross-built. +if(SHIBOKEN_BUILD_TOOLS) + add_subdirectory(dumpcodemodel) +endif() # FIXME Skipped until add an option to choose the generator # add_subdirectory(test_generator) diff --git a/sources/shiboken6/tests/dumpcodemodel/CMakeLists.txt b/sources/shiboken6/tests/dumpcodemodel/CMakeLists.txt index 5c5e2c7b0..e7dbef961 100644 --- a/sources/shiboken6/tests/dumpcodemodel/CMakeLists.txt +++ b/sources/shiboken6/tests/dumpcodemodel/CMakeLists.txt @@ -1,6 +1,16 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + add_executable(dumpcodemodel main.cpp) target_include_directories(dumpcodemodel - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${apiextractor_SOURCE_DIR}) + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../../ApiExtractor +) -target_link_libraries(dumpcodemodel PUBLIC apiextractor Qt${QT_MAJOR_VERSION}::Core) +target_link_libraries(dumpcodemodel + PRIVATE + apiextractor + Qt::Core +) diff --git a/sources/shiboken6/tests/dumpcodemodel/main.cpp b/sources/shiboken6/tests/dumpcodemodel/main.cpp index 527a81262..eb876634c 100644 --- a/sources/shiboken6/tests/dumpcodemodel/main.cpp +++ b/sources/shiboken6/tests/dumpcodemodel/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <abstractmetabuilder_p.h> #include <parser/codemodel.h> @@ -37,6 +12,7 @@ #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QFile> +#include <QtCore/QLibraryInfo> #include <QtCore/QVersionNumber> #include <QtCore/QXmlStreamWriter> @@ -44,13 +20,15 @@ #include <algorithm> #include <iterator> +using namespace Qt::StringLiterals; + static bool optJoinNamespaces = false; static inline QString languageLevelDescription() { - return QLatin1String("C++ Language level (c++11..c++17, default=") - + QLatin1String(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel())) - + QLatin1Char(')'); + return u"C++ Language level (c++11..c++20, default="_s + + QLatin1StringView(clang::languageLevelOption(clang::emulatedCompilerLanguageLevel())) + + u')'; } static void formatDebugOutput(const FileModelItem &dom, bool verbose) @@ -60,7 +38,7 @@ static void formatDebugOutput(const FileModelItem &dom, bool verbose) QDebug debug(&output); if (verbose) debug.setVerbosity(3); - debug << dom.data(); + debug << dom.get(); } std::cout << qPrintable(output) << '\n'; } @@ -70,14 +48,14 @@ static const char *primitiveTypes[] = { "float", "double" }; -static inline QString nameAttribute() { return QStringLiteral("name"); } +constexpr auto nameAttribute = "name"_L1; static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass); static void formatXmlEnum(QXmlStreamWriter &writer, const EnumModelItem &en) { - writer.writeStartElement(QStringLiteral("enum-type")); - writer.writeAttribute(nameAttribute(), en->name()); + writer.writeStartElement(u"enum-type"_s); + writer.writeAttribute(nameAttribute, en->name()); writer.writeEndElement(); } @@ -117,9 +95,9 @@ static void formatXmlClass(QXmlStreamWriter &writer, const ClassModelItem &klass const bool isValueType = std::any_of(functions.cbegin(), functions.cend(), isPublicCopyConstructor); formatXmlLocationComment(writer, klass); - writer.writeStartElement(isValueType ? QStringLiteral("value-type") - : QStringLiteral("object-type")); - writer.writeAttribute(nameAttribute(), klass->name()); + writer.writeStartElement(isValueType ? u"value-type"_s + : u"object-type"_s); + writer.writeAttribute(nameAttribute, klass->name()); formatXmlScopeMembers(writer, klass); writer.writeEndElement(); } @@ -139,14 +117,14 @@ static bool hasMembers(const NamespaceModelItem &nsp) static void startXmlNamespace(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) { formatXmlLocationComment(writer, nsp); - writer.writeStartElement(QStringLiteral("namespace-type")); - writer.writeAttribute(nameAttribute(), nsp->name()); + writer.writeStartElement(u"namespace-type"_s); + writer.writeAttribute(nameAttribute, nsp->name()); } static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceModelItem &nsp) { auto nestedNamespaces = nsp->namespaces(); - for (int i = nestedNamespaces.size() - 1; i >= 0; --i) { + for (auto i = nestedNamespaces.size() - 1; i >= 0; --i) { if (!hasMembers(nestedNamespaces.at(i))) nestedNamespaces.removeAt(i); } @@ -157,7 +135,7 @@ static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceM if (optJoinNamespaces) { // Write out members of identical namespaces and remove const QString name = current->name(); - for (int i = 0; i < nestedNamespaces.size(); ) { + for (qsizetype i = 0; i < nestedNamespaces.size(); ) { if (nestedNamespaces.at(i)->name() == name) { formatXmlNamespaceMembers(writer, nestedNamespaces.at(i)); nestedNamespaces.removeAt(i); @@ -171,9 +149,9 @@ static void formatXmlNamespaceMembers(QXmlStreamWriter &writer, const NamespaceM for (const auto &func : nsp->functions()) { const QString signature = func->typeSystemSignature(); - if (!signature.contains(QLatin1String("operator"))) { // Skip free operators - writer.writeStartElement(QStringLiteral("function")); - writer.writeAttribute(QStringLiteral("signature"), signature); + if (!signature.contains(u"operator")) { // Skip free operators + writer.writeStartElement(u"function"_s); + writer.writeAttribute(u"signature"_s, signature); writer.writeEndElement(); } } @@ -186,13 +164,13 @@ static void formatXmlOutput(const FileModelItem &dom) QXmlStreamWriter writer(&output); writer.setAutoFormatting(true); writer.writeStartDocument(); - writer.writeStartElement(QStringLiteral("typesystem")); - writer.writeAttribute(QStringLiteral("package"), QStringLiteral("insert_name")); - writer.writeComment(QStringLiteral("Auto-generated ") + + writer.writeStartElement(u"typesystem"_s); + writer.writeAttribute(u"package"_s, u"insert_name"_s); + writer.writeComment(u"Auto-generated "_s + QDateTime::currentDateTime().toString(Qt::ISODate)); for (auto p : primitiveTypes) { - writer.writeStartElement(QStringLiteral("primitive-type")); - writer.writeAttribute(nameAttribute(), QLatin1String(p)); + writer.writeStartElement(u"primitive-type"_s); + writer.writeAttribute(nameAttribute, QLatin1StringView(p)); writer.writeEndElement(); } formatXmlNamespaceMembers(writer, dom); @@ -220,29 +198,29 @@ int main(int argc, char **argv) parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments); const QString description = - QString::fromLatin1(descriptionFormat).arg(QLatin1String(qVersion()), + QString::fromLatin1(descriptionFormat).arg(QLatin1StringView(qVersion()), clang::libClangVersion().toString()); parser.setApplicationDescription(description); parser.addHelpOption(); parser.addVersionOption(); - QCommandLineOption verboseOption(QStringLiteral("verbose"), - QStringLiteral("Display verbose output about types")); + QCommandLineOption verboseOption(u"verbose"_s, + u"Display verbose output about types"_s); parser.addOption(verboseOption); - QCommandLineOption debugOption(QStringLiteral("debug"), - QStringLiteral("Display debug output")); + QCommandLineOption debugOption(u"debug"_s, + u"Display debug output"_s); parser.addOption(debugOption); - QCommandLineOption joinNamespacesOption({QStringLiteral("j"), QStringLiteral("join-namespaces")}, - QStringLiteral("Join namespaces")); + QCommandLineOption joinNamespacesOption({u"j"_s, u"join-namespaces"_s}, + u"Join namespaces"_s); parser.addOption(joinNamespacesOption); - QCommandLineOption languageLevelOption(QStringLiteral("std"), + QCommandLineOption languageLevelOption(u"std"_s, languageLevelDescription(), - QStringLiteral("level")); + u"level"_s); parser.addOption(languageLevelOption); - parser.addPositionalArgument(QStringLiteral("argument"), - QStringLiteral("C++ compiler argument"), - QStringLiteral("argument(s)")); + parser.addPositionalArgument(u"argument"_s, + u"C++ compiler argument"_s, + u"argument(s)"_s); parser.process(app); const QStringList &positionalArguments = parser.positionalArguments(); @@ -267,8 +245,8 @@ int main(int argc, char **argv) optJoinNamespaces = parser.isSet(joinNamespacesOption); const FileModelItem dom = AbstractMetaBuilderPrivate::buildDom(arguments, true, level, 0); - if (dom.isNull()) { - QString message = QLatin1String("Unable to parse ") + positionalArguments.join(QLatin1Char(' ')); + if (!dom) { + QString message = u"Unable to parse "_s + positionalArguments.join(u' '); std::cerr << qPrintable(message) << '\n'; return -2; } diff --git a/sources/shiboken6/tests/libminimal/CMakeLists.txt b/sources/shiboken6/tests/libminimal/CMakeLists.txt index f906bdb84..4a10f96bf 100644 --- a/sources/shiboken6/tests/libminimal/CMakeLists.txt +++ b/sources/shiboken6/tests/libminimal/CMakeLists.txt @@ -1,9 +1,17 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(libminimal) set(libminimal_SRC -obj.cpp -listuser.cpp -typedef.cpp +containeruser.cpp containeruser.h +libminimalmacros.h +listuser.cpp listuser.h +minbool.h +obj.cpp obj.h +spanuser.cpp spanuser.h +typedef.cpp typedef.h +val.h ) add_library(libminimal SHARED ${libminimal_SRC}) diff --git a/sources/shiboken6/tests/libminimal/containeruser.cpp b/sources/shiboken6/tests/libminimal/containeruser.cpp new file mode 100644 index 000000000..29af52aef --- /dev/null +++ b/sources/shiboken6/tests/libminimal/containeruser.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "containeruser.h" + +#include <algorithm> +#include <numeric> + +ContainerUser::ContainerUser() : m_intVector{1, 2, 3}, m_intArray{1, 2, 3} +{ +} + +ContainerUser::~ContainerUser() = default; + +std::vector<int> ContainerUser::createIntVector(int num) +{ + std::vector<int> retval(num); + std::iota(retval.begin(), retval.end(), 0); + return retval; +} + +int ContainerUser::sumIntVector(const std::vector<int> &intVector) +{ + return std::accumulate(intVector.cbegin(), intVector.cend(), 0); +} + +std::vector<int> &ContainerUser::intVector() +{ + return m_intVector; +} + +void ContainerUser::setIntVector(const std::vector<int> &v) +{ + m_intVector = v; +} + +std::array<int, 3> ContainerUser::createIntArray() +{ + return {1, 2, 3}; +} + +int ContainerUser::sumIntArray(const std::array<int, 3> &intArray) +{ + return std::accumulate(intArray.cbegin(), intArray.cend(), 0); +} + +std::array<int, 3> &ContainerUser::intArray() +{ + return m_intArray; +} + +void ContainerUser::setIntArray(const std::array<int, 3> &a) +{ + m_intArray = a; +} diff --git a/sources/shiboken6/tests/libminimal/containeruser.h b/sources/shiboken6/tests/libminimal/containeruser.h new file mode 100644 index 000000000..55e4020ec --- /dev/null +++ b/sources/shiboken6/tests/libminimal/containeruser.h @@ -0,0 +1,36 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef CONTAINERUSER_H +#define CONTAINERUSER_H + +#include "libminimalmacros.h" + +#include <array> +#include <vector> + +/// Exercise simple, sequential containers. More advanced tests are in ListUser +class LIBMINIMAL_API ContainerUser +{ +public: + ContainerUser(); + ~ContainerUser(); + + static std::vector<int> createIntVector(int num); + static int sumIntVector(const std::vector<int> &intVector); + + std::vector<int> &intVector(); + void setIntVector(const std::vector<int> &); + + static std::array<int, 3> createIntArray(); + static int sumIntArray(const std::array<int, 3> &intArray); + + std::array<int, 3> &intArray(); + void setIntArray(const std::array<int, 3> &); + +private: + std::vector<int> m_intVector; + std::array<int, 3> m_intArray; +}; + +#endif // CONTAINERUSER_H diff --git a/sources/shiboken6/tests/libminimal/libminimalmacros.h b/sources/shiboken6/tests/libminimal/libminimalmacros.h index 99ff667db..099c1f1de 100644 --- a/sources/shiboken6/tests/libminimal/libminimalmacros.h +++ b/sources/shiboken6/tests/libminimal/libminimalmacros.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef LIBMINIMALMACROS_H #define LIBMINIMALMACROS_H @@ -47,4 +22,28 @@ # define LIBMINIMAL_API LIBMINIMAL_IMPORT #endif +#define LIBMINIMAL_DEFAULT_COPY(Class) \ + Class(const Class &) noexcept = default; \ + Class &operator=(const Class &) noexcept = default; + +#define LIBMINIMAL_DISABLE_COPY(Class) \ + Class(const Class &) = delete;\ + Class &operator=(const Class &) = delete; + +#define LIBMINIMAL_DEFAULT_MOVE(Class) \ + Class(Class &&) noexcept = default; \ + Class &operator=(Class &&) noexcept = default; + +#define LIBMINIMAL_DEFAULT_COPY_MOVE(Class) \ + LIBMINIMAL_DEFAULT_COPY(Class) \ + LIBMINIMAL_DEFAULT_MOVE(Class) + +#define LIBMINIMAL_DISABLE_MOVE(Class) \ + Class(Class &&) = delete; \ + Class &operator=(Class &&) = delete; + +#define LIBMINIMAL_DISABLE_COPY_MOVE(Class) \ + LIBMINIMAL_DISABLE_COPY(Class) \ + LIBMINIMAL_DISABLE_MOVE(Class) + #endif // LIBMINIMALMACROS_H diff --git a/sources/shiboken6/tests/libminimal/listuser.cpp b/sources/shiboken6/tests/libminimal/listuser.cpp index 0d7721c3c..93c399542 100644 --- a/sources/shiboken6/tests/libminimal/listuser.cpp +++ b/sources/shiboken6/tests/libminimal/listuser.cpp @@ -1,54 +1,35 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <numeric> -#include <cstdlib> #include "listuser.h" #include <algorithm> +#include <cstdlib> #include <numeric> -std::list<int> -ListUser::createIntList(int num) +std::list<int> ListUser::createIntList(int num) { std::list<int> retval(num); std::iota(retval.begin(), retval.end(), 0); return retval; } -int -ListUser::sumIntList(std::list<int> intList) +int ListUser::sumIntList(std::list<int> intList) { return std::accumulate(intList.begin(), intList.end(), 0); } -std::list<MinBool> -ListUser::createMinBoolList(MinBool mb1, MinBool mb2) +int ListUser::sumIntListDefaultParamConstRef(const std::list<int> &intList) +{ + return sumIntList(intList); +} + +int ListUser::sumIntListDefaultParam(std::list<int> intList) +{ + return sumIntList(intList); +} + +std::list<MinBool> ListUser::createMinBoolList(MinBool mb1, MinBool mb2) { std::list<MinBool> retval; retval.push_back(mb1); @@ -56,8 +37,7 @@ ListUser::createMinBoolList(MinBool mb1, MinBool mb2) return retval; } -MinBool -ListUser::oredMinBoolList(std::list<MinBool> minBoolList) +MinBool ListUser::oredMinBoolList(std::list<MinBool> minBoolList) { MinBool result(false); for (const auto &m : minBoolList) @@ -65,8 +45,7 @@ ListUser::oredMinBoolList(std::list<MinBool> minBoolList) return result; } -std::list<Val> -ListUser::createValList(int num) +std::list<Val> ListUser::createValList(int num) { std::list<Val> retval; for (int i = 0; i < num; ++i) @@ -74,17 +53,14 @@ ListUser::createValList(int num) return retval; } -int -ListUser::sumValList(std::list<Val> valList) +int ListUser::sumValList(std::list<Val> valList) { int total = 0; for (const auto &v : valList) total += v.valId(); return total; } - -std::list<Obj*> -ListUser::createObjList(Obj* o1, Obj* o2) +std::list<Obj*> ListUser::createObjList(Obj* o1, Obj* o2) { std::list<Obj*> retval; retval.push_back(o1); @@ -92,8 +68,7 @@ ListUser::createObjList(Obj* o1, Obj* o2) return retval; } -int -ListUser::sumObjList(std::list<Obj*> objList) +int ListUser::sumObjList(std::list<Obj*> objList) { int total = 0; for (const auto *obj : objList) @@ -101,8 +76,7 @@ ListUser::sumObjList(std::list<Obj*> objList) return total; } -std::list<std::list<int> > -ListUser::createListOfIntLists(int num) +std::list<std::list<int> > ListUser::createListOfIntLists(int num) { std::list<std::list<int> > retval; for (int i = 0; i < num; ++i) @@ -110,8 +84,7 @@ ListUser::createListOfIntLists(int num) return retval; } -int -ListUser::sumListOfIntLists(std::list<std::list<int> > intListList) +int ListUser::sumListOfIntLists(std::list<std::list<int> > intListList) { int total = 0; for (const auto &list : intListList) @@ -119,3 +92,42 @@ ListUser::sumListOfIntLists(std::list<std::list<int> > intListList) return total; } +void ListUser::setStdIntList(const std::list<int> &l) +{ + m_stdIntList = l; +} + +std::list<int> &ListUser::getIntList() +{ + return m_stdIntList; +} + +const std::list<int> &ListUser::getConstIntList() const +{ + return m_stdIntList; +} + +int ListUser::modifyIntListPtr(std::list<int> *list) const +{ + const int oldSize = int(list->size()); + list->push_back(42); + return oldSize; +} + +std::list<int> *ListUser::returnIntListByPtr() const +{ + return nullptr; +} + +int ListUser::callReturnIntListByPtr() const +{ + auto *list = returnIntListByPtr(); + return list != nullptr ? int(list->size()) : 0; +} + +int ListUser::modifyDoubleListPtr(std::list<double> *list) const +{ + const int oldSize = int(list->size()); + list->push_back(42); + return oldSize; +} diff --git a/sources/shiboken6/tests/libminimal/listuser.h b/sources/shiboken6/tests/libminimal/listuser.h index 6c7e6aedd..9904ef27d 100644 --- a/sources/shiboken6/tests/libminimal/listuser.h +++ b/sources/shiboken6/tests/libminimal/listuser.h @@ -1,44 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef LISTUSER_H #define LISTUSER_H -#include <list> #include "obj.h" #include "val.h" #include "minbool.h" #include "libminimalmacros.h" +#include <list> + struct LIBMINIMAL_API ListUser { - virtual ~ListUser() {} + LIBMINIMAL_DEFAULT_COPY(ListUser) + LIBMINIMAL_DISABLE_MOVE(ListUser) + + ListUser() noexcept = default; + virtual ~ListUser() = default; // List of C++ primitive type items virtual std::list<int> createIntList(int num); @@ -46,6 +26,9 @@ struct LIBMINIMAL_API ListUser virtual int sumIntList(std::list<int> intList); int callSumIntList(std::list<int> intList) { return sumIntList(intList); } + int sumIntListDefaultParamConstRef(const std::list<int> &intList = {1, 2, 3}); + int sumIntListDefaultParam(std::list<int> intList = {1, 2, 3}); + // List of C++ MinBool objects used as primitives in Python virtual std::list<MinBool> createMinBoolList(MinBool mb1, MinBool mb2); std::list<MinBool> callCreateMinBoolList(MinBool mb1, MinBool mb2) { return createMinBoolList(mb1, mb2); } @@ -69,6 +52,20 @@ struct LIBMINIMAL_API ListUser std::list<std::list<int> > callCreateListOfIntLists(int num) { return createListOfIntLists(num); } virtual int sumListOfIntLists(std::list<std::list<int> > intListList); int callSumListOfIntLists(std::list<std::list<int> > intListList) { return sumListOfIntLists(intListList); } + + void setStdIntList(const std::list<int> &l); + std::list<int> &getIntList(); + const std::list<int> &getConstIntList() const; + + int modifyIntListPtr(std::list<int> *list) const; + + virtual std::list<int> *returnIntListByPtr() const; + + int callReturnIntListByPtr() const; + + int modifyDoubleListPtr(std::list<double> *list) const; + + std::list<int> m_stdIntList; }; #endif // LISTUSER_H diff --git a/sources/shiboken6/tests/libminimal/minbool.h b/sources/shiboken6/tests/libminimal/minbool.h index 72a2cbabe..e460f466b 100644 --- a/sources/shiboken6/tests/libminimal/minbool.h +++ b/sources/shiboken6/tests/libminimal/minbool.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MINBOOL_H #define MINBOOL_H @@ -38,9 +13,10 @@ public: bool value() const { return m_value; } inline MinBool operator!() const { return MinBool(!m_value); } inline MinBool& operator|=(const MinBool& other) { - m_value = m_value | other.m_value; + m_value |= other.m_value; return *this; } + private: bool m_value; }; @@ -55,12 +31,16 @@ inline bool operator!=(MinBool b1, MinBool b2) { return (!b1).value() != (!b2).v class LIBMINIMAL_API MinBoolUser { public: - MinBoolUser() : m_minbool(MinBool(false)) {} - virtual ~MinBoolUser() {} + LIBMINIMAL_DEFAULT_COPY(MinBoolUser) + LIBMINIMAL_DISABLE_MOVE(MinBoolUser) + + MinBoolUser() noexcept : m_minbool(MinBool(false)) {} + virtual ~MinBoolUser() = default; inline MinBool minBool() { return m_minbool; } inline void setMinBool(MinBool minBool) { m_minbool = minBool; } virtual MinBool invertedMinBool() { return !m_minbool; } inline MinBool callInvertedMinBool() { return invertedMinBool(); } + private: MinBool m_minbool; }; diff --git a/sources/shiboken6/tests/libminimal/obj.cpp b/sources/shiboken6/tests/libminimal/obj.cpp index eb7af3a74..a63a9c3c9 100644 --- a/sources/shiboken6/tests/libminimal/obj.cpp +++ b/sources/shiboken6/tests/libminimal/obj.cpp @@ -1,41 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "obj.h" -Obj::Obj(int objId) : m_objId(objId) +Obj::Obj(int objId) noexcept : m_objId(objId) { } Obj::~Obj() = default; -bool -Obj::virtualMethod(int val) +bool Obj::virtualMethod(int val) { return !bool(val%2); } diff --git a/sources/shiboken6/tests/libminimal/obj.h b/sources/shiboken6/tests/libminimal/obj.h index b868bbcbf..be0bfb52b 100644 --- a/sources/shiboken6/tests/libminimal/obj.h +++ b/sources/shiboken6/tests/libminimal/obj.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJ_H #define OBJ_H @@ -34,7 +9,9 @@ class LIBMINIMAL_API Obj { public: - explicit Obj(int objId); + LIBMINIMAL_DISABLE_COPY_MOVE(Obj) + + explicit Obj(int objId) noexcept; virtual ~Obj(); int objId() const { return m_objId; } @@ -50,8 +27,6 @@ public: Obj* callPassObjectTypeReference(Obj& obj) { return passObjectTypeReference(obj); } private: - Obj(const Obj&); - Obj& operator=(const Obj&); int m_objId; }; diff --git a/sources/shiboken6/tests/libminimal/spanuser.cpp b/sources/shiboken6/tests/libminimal/spanuser.cpp new file mode 100644 index 000000000..fea9cd68e --- /dev/null +++ b/sources/shiboken6/tests/libminimal/spanuser.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "spanuser.h" + +#include <numeric> + +SpanUser::SpanUser() = default; + +bool SpanUser::enabled() +{ +#if __cplusplus >= 202002L + return true; +#else + return false; +#endif +} + +#if __cplusplus >= 202002L +IntSpan3 SpanUser::getIntSpan3() +{ + static int iv[] = {1, 2, 3}; + return IntSpan3(iv); +} + +IntSpan SpanUser::getIntSpan() +{ + static int iv[] = {1, 2, 3}; + return IntSpan(iv); +} + +ConstIntSpan3 SpanUser::getConstIntSpan3() +{ + static const int civ[] = {1, 2, 3}; + return ConstIntSpan3(civ); +} + +IntSpan3 SpanUser::getIntSpan3_OpaqueContainer() +{ + static int iv[] = {1, 2, 3}; + return IntSpan3(iv); +} + +int SpanUser::sumIntSpan3(IntSpan3 isp3) +{ + return std::accumulate(isp3.begin(), isp3.end(), 0); +} + +int SpanUser::sumIntSpan(IntSpan isp) +{ + return std::accumulate(isp.begin(), isp.end(), 0); +} + +int SpanUser::sumConstIntSpan3(ConstIntSpan3 ispc3) +{ + return std::accumulate(ispc3.begin(), ispc3.end(), 0); +} +#endif // C++ 20 diff --git a/sources/shiboken6/tests/libminimal/spanuser.h b/sources/shiboken6/tests/libminimal/spanuser.h new file mode 100644 index 000000000..c78ba35e7 --- /dev/null +++ b/sources/shiboken6/tests/libminimal/spanuser.h @@ -0,0 +1,35 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef SPANUSER_H +#define SPANUSER_H + +#include "libminimalmacros.h" + +#if __cplusplus >= 202002L +# include <span> + +using IntSpan3 = std::span<int, 3>; +using IntSpan = std::span<int>; +using ConstIntSpan3 = std::span<const int, 3>; +#endif + +struct LIBMINIMAL_API SpanUser +{ + SpanUser(); + + static bool enabled(); + +#if __cplusplus >= 202002L + static IntSpan3 getIntSpan3(); + static IntSpan getIntSpan(); + static ConstIntSpan3 getConstIntSpan3(); + static IntSpan3 getIntSpan3_OpaqueContainer(); + + static int sumIntSpan3(IntSpan3 isp3); + static int sumIntSpan(IntSpan isp); + static int sumConstIntSpan3(ConstIntSpan3 ispc3); +#endif // C++ 20 +}; + +#endif // SPANUSER_H diff --git a/sources/shiboken6/tests/libminimal/typedef.cpp b/sources/shiboken6/tests/libminimal/typedef.cpp index e0886d982..115b7be0a 100644 --- a/sources/shiboken6/tests/libminimal/typedef.cpp +++ b/sources/shiboken6/tests/libminimal/typedef.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "typedef.h" diff --git a/sources/shiboken6/tests/libminimal/typedef.h b/sources/shiboken6/tests/libminimal/typedef.h index b8d6faacd..7116db1b8 100644 --- a/sources/shiboken6/tests/libminimal/typedef.h +++ b/sources/shiboken6/tests/libminimal/typedef.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef TYPEDEF_H #define TYPEDEF_H diff --git a/sources/shiboken6/tests/libminimal/val.h b/sources/shiboken6/tests/libminimal/val.h index c43302317..50f090a7d 100644 --- a/sources/shiboken6/tests/libminimal/val.h +++ b/sources/shiboken6/tests/libminimal/val.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef VAL_H #define VAL_H @@ -34,8 +9,10 @@ class LIBMINIMAL_API Val { public: - explicit Val(int valId) : m_valId(valId) {} - virtual ~Val() {} + explicit Val(int valId) noexcept : m_valId(valId) {} + LIBMINIMAL_DEFAULT_COPY_MOVE(Val) + + virtual ~Val() = default; int valId() const { return m_valId; } void setValId(int valId) { m_valId = valId; } diff --git a/sources/shiboken6/tests/libother/CMakeLists.txt b/sources/shiboken6/tests/libother/CMakeLists.txt index c078d3546..0379d740b 100644 --- a/sources/shiboken6/tests/libother/CMakeLists.txt +++ b/sources/shiboken6/tests/libother/CMakeLists.txt @@ -1,12 +1,17 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(libother) set(libother_SRC -number.cpp -otherderived.cpp -otherobjecttype.cpp -othermultiplederived.cpp -smartptrtester.cpp -othertypesystypedef.cpp +extendsnoimplicitconversion.h +libothermacros.h +number.cpp number.h +otherderived.cpp otherderived.h +othermultiplederived.cpp othermultiplederived.h +otherobjecttype.cpp otherobjecttype.h +othertypesystypedef.cpp othertypesystypedef.h +smartptrtester.cpp smartptrtester.h ) add_library(libother SHARED ${libother_SRC}) diff --git a/sources/shiboken6/tests/libother/extendsnoimplicitconversion.h b/sources/shiboken6/tests/libother/extendsnoimplicitconversion.h index e1bcf0961..36d503fe8 100644 --- a/sources/shiboken6/tests/libother/extendsnoimplicitconversion.h +++ b/sources/shiboken6/tests/libother/extendsnoimplicitconversion.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef EXTENDSNOIMPLICITCONVERSION_H #define EXTENDSNOIMPLICITCONVERSION_H @@ -38,8 +13,9 @@ public: explicit ExtendsNoImplicitConversion(int objId) : m_objId(objId) {}; inline int objId() const { return m_objId; } inline operator NoImplicitConversion() const { return NoImplicitConversion(m_objId); } + private: int m_objId; }; -#endif // EXTENDSNOIMPLICITCONVERSION_H +#endif // EXTENDSNOIMPLICITCONVERSION_H diff --git a/sources/shiboken6/tests/libother/libothermacros.h b/sources/shiboken6/tests/libother/libothermacros.h index e5207064f..567757abd 100644 --- a/sources/shiboken6/tests/libother/libothermacros.h +++ b/sources/shiboken6/tests/libother/libothermacros.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef LIBOTHERMACROS_H #define LIBOTHERMACROS_H diff --git a/sources/shiboken6/tests/libother/number.cpp b/sources/shiboken6/tests/libother/number.cpp index bc97de6a6..fbf50dc4a 100644 --- a/sources/shiboken6/tests/libother/number.cpp +++ b/sources/shiboken6/tests/libother/number.cpp @@ -1,59 +1,28 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "number.h" -#include <cstring> -#include <sstream> -using namespace std; +#include <sstream> -Str -Number::toStr() const +Str Number::toStr() const { - ostringstream in; + std::ostringstream in; in << m_value; return in.str().c_str(); } -Point -operator*(const Point& p, const Number& n) +Point operator*(const Point &p, const Number &n) { - return Point(p.x() * n.value(), p.y() * n.value()); + return {p.x() * n.value(), p.y() * n.value()}; } -Complex -Number::toComplex() const +Complex Number::toComplex() const { return Complex(m_value); } -Number -Number::fromComplex(Complex cpx) +Number Number::fromComplex(Complex cpx) { return Number(cpx.real()); } diff --git a/sources/shiboken6/tests/libother/number.h b/sources/shiboken6/tests/libother/number.h index 222c6e1a6..2c480e7f2 100644 --- a/sources/shiboken6/tests/libother/number.h +++ b/sources/shiboken6/tests/libother/number.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef NUMBER_H #define NUMBER_H @@ -43,7 +18,7 @@ public: Str toStr() const; inline operator Str() const { return toStr(); } - friend LIBOTHER_API Point operator*(const Point&, const Number&); + friend LIBOTHER_API Point operator*(const Point &, const Number &); Complex toComplex() const; static Number fromComplex(Complex cpx); @@ -52,6 +27,6 @@ private: int m_value; }; -LIBOTHER_API Point operator*(const Point&, const Number&); +LIBOTHER_API Point operator*(const Point &, const Number &); #endif // NUMBER_H diff --git a/sources/shiboken6/tests/libother/otherderived.cpp b/sources/shiboken6/tests/libother/otherderived.cpp index d23f6ad23..93a18876e 100644 --- a/sources/shiboken6/tests/libother/otherderived.cpp +++ b/sources/shiboken6/tests/libother/otherderived.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "otherderived.h" @@ -32,30 +7,24 @@ OtherDerived::OtherDerived(int id) : Abstract(id) { } -OtherDerived::~OtherDerived() -{ -} +OtherDerived::~OtherDerived() = default; -Abstract* -OtherDerived::createObject() +Abstract *OtherDerived::createObject() { static int id = 100; return new OtherDerived(id++); } -void -OtherDerived::pureVirtual() +void OtherDerived::pureVirtual() { } -void* -OtherDerived::pureVirtualReturningVoidPtr() +void *OtherDerived::pureVirtualReturningVoidPtr() { return nullptr; } -void -OtherDerived::unpureVirtual() +void OtherDerived::unpureVirtual() { } diff --git a/sources/shiboken6/tests/libother/otherderived.h b/sources/shiboken6/tests/libother/otherderived.h index 72e1e2302..d6bde8808 100644 --- a/sources/shiboken6/tests/libother/otherderived.h +++ b/sources/shiboken6/tests/libother/otherderived.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OTHERDERIVED_H #define OTHERDERIVED_H @@ -43,26 +18,26 @@ public: OtherDerived(int id = -1); ~OtherDerived() override; void pureVirtual() override; - void* pureVirtualReturningVoidPtr() override; + void *pureVirtualReturningVoidPtr() override; void unpureVirtual() override; PrintFormat returnAnEnum() override { return Short; } - inline void useObjectTypeFromOtherModule(ObjectType*) {} - inline Event useValueTypeFromOtherModule(const Event& e) { return e; } - inline Complex useValueTypeFromOtherModule(const Complex& c) { return c; } + inline void useObjectTypeFromOtherModule(ObjectType *) {} + inline Event useValueTypeFromOtherModule(const Event &e) { return e; } + inline Complex useValueTypeFromOtherModule(const Complex &c) { return c; } inline void useEnumTypeFromOtherModule(OverloadedFuncEnum) {} // factory method - static Abstract* createObject(); + static Abstract *createObject(); void hideFunction(HideType*) override {} protected: - inline const char* getClassName() { return className(); } - virtual const char* className() override { return "OtherDerived"; } + inline const char *getClassName() { return className(); } + const char *className() const override { return "OtherDerived"; } private: void pureVirtualPrivate() override; }; -#endif // OTHERDERIVED_H +#endif // OTHERDERIVED_H diff --git a/sources/shiboken6/tests/libother/othermultiplederived.cpp b/sources/shiboken6/tests/libother/othermultiplederived.cpp index e7ee4f96d..cfbbfb2c2 100644 --- a/sources/shiboken6/tests/libother/othermultiplederived.cpp +++ b/sources/shiboken6/tests/libother/othermultiplederived.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "othermultiplederived.h" @@ -33,18 +8,17 @@ VirtualMethods OtherMultipleDerived::returnUselessClass() return VirtualMethods(); } -Base1* OtherMultipleDerived::createObject(const std::string& objName) +Base1 *OtherMultipleDerived::createObject(const std::string &objName) { if (objName == "Base1") return new Base1; - else if (objName == "MDerived1") + if (objName == "MDerived1") return new MDerived1; - else if (objName == "SonOfMDerived1") + if (objName == "SonOfMDerived1") return new SonOfMDerived1; - else if (objName == "MDerived3") + if (objName == "MDerived3") return new MDerived3; - else if (objName == "OtherMultipleDerived") + if (objName == "OtherMultipleDerived") return new OtherMultipleDerived; return nullptr; } - diff --git a/sources/shiboken6/tests/libother/othermultiplederived.h b/sources/shiboken6/tests/libother/othermultiplederived.h index 84a426ac9..a8e265388 100644 --- a/sources/shiboken6/tests/libother/othermultiplederived.h +++ b/sources/shiboken6/tests/libother/othermultiplederived.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OTHERMULTIPLEDERIVED_H #define OTHERMULTIPLEDERIVED_H @@ -40,7 +15,7 @@ class LIBOTHER_API OtherMultipleDerived : public MDerived1 public: // this will use CppCopier from other module (bug#142) VirtualMethods returnUselessClass(); - static Base1* createObject(const std::string& objName); + static Base1 *createObject(const std::string &objName); }; -#endif +#endif // OTHERMULTIPLEDERIVED_H diff --git a/sources/shiboken6/tests/libother/otherobjecttype.cpp b/sources/shiboken6/tests/libother/otherobjecttype.cpp index c7778e7c9..eaaa231be 100644 --- a/sources/shiboken6/tests/libother/otherobjecttype.cpp +++ b/sources/shiboken6/tests/libother/otherobjecttype.cpp @@ -1,37 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "otherobjecttype.h" -Collector& -operator<<(Collector& collector, const OtherObjectType& obj) +Collector &operator<<(Collector &collector, const OtherObjectType &obj) { - collector << obj.identifier()*2; + collector << obj.identifier() * 2; return collector; } diff --git a/sources/shiboken6/tests/libother/otherobjecttype.h b/sources/shiboken6/tests/libother/otherobjecttype.h index a9362c370..844795118 100644 --- a/sources/shiboken6/tests/libother/otherobjecttype.h +++ b/sources/shiboken6/tests/libother/otherobjecttype.h @@ -1,44 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OTHEROBJECTTYPE_H #define OTHEROBJECTTYPE_H -#include <list> -#include "str.h" - #include "libothermacros.h" #include "objecttype.h" #include "collector.h" #include "samplenamespace.h" #include "removednamespaces.h" - class LIBOTHER_API OtherObjectType : public ObjectType { public: @@ -46,8 +17,6 @@ public: static int enumAsIntForInvisibleNamespace(RemovedNamespace1::RemovedNamespace1_Enum value); }; - -LIBOTHER_API Collector& operator<<(Collector&, const OtherObjectType&); +LIBOTHER_API Collector &operator<<(Collector &, const OtherObjectType &); #endif // OTHEROBJECTTYPE_H - diff --git a/sources/shiboken6/tests/libother/othertypesystypedef.cpp b/sources/shiboken6/tests/libother/othertypesystypedef.cpp index 7e6e1ff64..1a50c4edf 100644 --- a/sources/shiboken6/tests/libother/othertypesystypedef.cpp +++ b/sources/shiboken6/tests/libother/othertypesystypedef.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "othertypesystypedef.h" diff --git a/sources/shiboken6/tests/libother/othertypesystypedef.h b/sources/shiboken6/tests/libother/othertypesystypedef.h index e3f434613..999b71fd3 100644 --- a/sources/shiboken6/tests/libother/othertypesystypedef.h +++ b/sources/shiboken6/tests/libother/othertypesystypedef.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef OTHERTYPESYSTYPEDEF_H #define OTHERTYPESYSTYPEDEF_H diff --git a/sources/shiboken6/tests/libother/smartptrtester.cpp b/sources/shiboken6/tests/libother/smartptrtester.cpp index 9636c7521..1c6496b1a 100644 --- a/sources/shiboken6/tests/libother/smartptrtester.cpp +++ b/sources/shiboken6/tests/libother/smartptrtester.cpp @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "smartptrtester.h" SharedPtr<Str> SmartPtrTester::createSharedPtrStr(const char *what) { - return SharedPtr<Str>(new Str(what)); + return {new Str(what)}; } std::string SmartPtrTester::valueOfSharedPtrStr(const SharedPtr<Str> &str) diff --git a/sources/shiboken6/tests/libother/smartptrtester.h b/sources/shiboken6/tests/libother/smartptrtester.h index a560bcf2f..6d7991c06 100644 --- a/sources/shiboken6/tests/libother/smartptrtester.h +++ b/sources/shiboken6/tests/libother/smartptrtester.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMARTPTRTESTER_H #define SMARTPTRTESTER_H diff --git a/sources/shiboken6/tests/libsample/CMakeLists.txt b/sources/shiboken6/tests/libsample/CMakeLists.txt index 6e436ee1f..926972340 100644 --- a/sources/shiboken6/tests/libsample/CMakeLists.txt +++ b/sources/shiboken6/tests/libsample/CMakeLists.txt @@ -1,63 +1,93 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(libsample) set(libsample_SRC -abstract.cpp -blackbox.cpp -bytearray.cpp -bucket.cpp -collector.cpp -complex.cpp -ctparam.cpp -onlycopy.cpp -derived.cpp -derivedusingct.cpp -echo.cpp -exceptiontest.cpp -functions.cpp -handle.cpp -implicitconv.cpp -intwrapper.cpp -injectcode.cpp -listuser.cpp -modifications.cpp -mapuser.cpp -modified_constructor.cpp -multiple_derived.cpp -oddbool.cpp -objectmodel.cpp -objecttype.cpp -objecttypeholder.cpp -objecttypelayout.cpp -objecttypeoperators.cpp -objectview.cpp -overload.cpp -overloadsort.cpp -pairuser.cpp -pen.cpp -photon.cpp -point.cpp -pointf.cpp -polygon.cpp -protected.cpp -reference.cpp -renaming.cpp -sample.cpp -samplenamespace.cpp -sbkdate.cpp -simplefile.cpp -size.cpp -snakecasetest.cpp -sometime.cpp -str.cpp -strlist.cpp -templateptr.cpp -transform.cpp -typesystypedef.cpp -virtualmethods.cpp -expression.cpp -filter.cpp +abstract.cpp abstract.h +blackbox.cpp blackbox.h +bucket.cpp bucket.h +bytearray.cpp bytearray.h +collector.cpp collector.h +complex.cpp complex.h +ctorconvrule.h +ctparam.cpp ctparam.h +cvlist.h +derived.cpp derived.h +derivedusingct.cpp derivedusingct.h +echo.cpp echo.h +exceptiontest.cpp exceptiontest.h +expression.cpp expression.h +filter.cpp filter.h +functions.cpp functions.h +handle.cpp handle.h +implicitconv.cpp implicitconv.h +injectcode.cpp injectcode.h +intwrapper.cpp intwrapper.h +libsamplemacros.h +list.h +listuser.cpp listuser.h +mapuser.cpp mapuser.h +modelindex.h +modifications.cpp modifications.h +modified_constructor.cpp modified_constructor.h +multiple_derived.cpp multiple_derived.h +noimplicitconversion.h +nondefaultctor.h +nontypetemplate.h +null.h +objectmodel.cpp objectmodel.h +objecttype.cpp objecttype.h +objecttypebyvalue.h +objecttypeholder.cpp objecttypeholder.h +objecttypelayout.cpp objecttypelayout.h +objecttypeoperators.cpp objecttypeoperators.h +objectview.cpp objectview.h +oddbool.cpp oddbool.h +onlycopy.cpp onlycopy.h +overload.cpp overload.h +overloadsort.cpp overloadsort.h +pairuser.cpp pairuser.h +pen.cpp pen.h +photon.cpp photon.h +point.cpp point.h +pointerholder.h +pointf.cpp pointf.h +polygon.cpp polygon.h +privatector.h +privatedtor.h +protected.cpp protected.h +rect.h +reference.cpp reference.h +removednamespaces.h +renaming.cpp renaming.h +sample.cpp sample.h +samplenamespace.cpp samplenamespace.h +sbkdate.cpp sbkdate.h +stdcomplex.cpp stdcomplex.h +simplefile.cpp simplefile.h +size.cpp size.h +snakecasetest.cpp snakecasetest.h +sometime.cpp sometime.h +str.cpp str.h +strlist.cpp strlist.h +templateptr.cpp templateptr.h +transform.cpp transform.h +typesystypedef.cpp typesystypedef.h +valueandvirtual.h +virtualmethods.cpp virtualmethods.h +voidholder.h ) +# Includes windows.h which is causing clashes between class Polygon and +# wingdi.h's Polygon() function. + +if(WIN32) + set_source_files_properties( + bucket.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON + ) +endif() + add_library(libsample SHARED ${libsample_SRC}) target_include_directories(libsample PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(libsample PRIVATE LIBSAMPLE_BUILD) diff --git a/sources/shiboken6/tests/libsample/abstract.cpp b/sources/shiboken6/tests/libsample/abstract.cpp index 3b2b1ef0a..0d67d8630 100644 --- a/sources/shiboken6/tests/libsample/abstract.cpp +++ b/sources/shiboken6/tests/libsample/abstract.cpp @@ -1,89 +1,64 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "abstract.h" -#include "objecttype.h" -using namespace std; +#include <iostream> const int Abstract::staticPrimitiveField = 0; -Abstract::Abstract(int id) : m_id(id) +Abstract::Abstract(int id) noexcept : m_id(id) { - toBeRenamedField = readOnlyField = primitiveField = 123; - valueTypeField = Point(12, 34); - objectTypeField = nullptr; bitField = 0; } -Abstract::~Abstract() -{ -} +Abstract::~Abstract() = default; -void -Abstract::unpureVirtual() +void Abstract::unpureVirtual() { } -void -Abstract::callUnpureVirtual() +void Abstract::callUnpureVirtual() { this->unpureVirtual(); } - -void -Abstract::callPureVirtual() +void Abstract::callPureVirtual() { this->pureVirtual(); } -void -Abstract::show(PrintFormat format) +void Abstract::show(PrintFormat format) const { - cout << '<'; + std::cout << '<'; switch(format) { - case Short: - cout << this; - break; - case Verbose: - cout << "class " << className() << " | cptr: " << this; - cout << ", id: " << m_id; - break; - case OnlyId: - cout << "id: " << m_id; - break; - case ClassNameAndId: - cout << className() << " - id: " << m_id; - break; + case Short: + std::cout << this; + break; + case Verbose: + std::cout << "class " << className() << " | cptr: " << this + << ", id: " << m_id; + break; + case OnlyId: + std::cout << "id: " << m_id; + break; + case ClassNameAndId: + std::cout << className() << " - id: " << m_id; + break; } - cout << '>'; + std::cout << '>'; +} + +void Abstract::virtualWithOutParameter(int &x) const +{ + x = 42; +} + +int Abstract::callVirtualWithOutParameter() const +{ + int x; + virtualWithOutParameter(x); + return x; } void Abstract::callVirtualGettingEnum(PrintFormat p) @@ -91,7 +66,6 @@ void Abstract::callVirtualGettingEnum(PrintFormat p) virtualGettingAEnum(p); } -void Abstract::virtualGettingAEnum(Abstract::PrintFormat p) +void Abstract::virtualGettingAEnum(Abstract::PrintFormat) { } - diff --git a/sources/shiboken6/tests/libsample/abstract.h b/sources/shiboken6/tests/libsample/abstract.h index 746107c71..4c1b98d90 100644 --- a/sources/shiboken6/tests/libsample/abstract.h +++ b/sources/shiboken6/tests/libsample/abstract.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef ABSTRACT_H #define ABSTRACT_H @@ -49,6 +24,8 @@ private: PrivValue2 = PrivValue1 + 2 }; public: + LIBMINIMAL_DISABLE_COPY_MOVE(Abstract) + enum PrintFormat { Short, Verbose, @@ -63,26 +40,26 @@ public: }; static const int staticPrimitiveField; - int primitiveField; + int primitiveField = 123; Complex userPrimitiveField; - Point valueTypeField; - ObjectType* objectTypeField; - int toBeRenamedField; - int readOnlyField; + Point valueTypeField{12, 34}; + ObjectType *objectTypeField = nullptr; + int toBeRenamedField = 123; + int readOnlyField = 123; - Abstract(int id = -1); + explicit Abstract(int id = -1) noexcept; virtual ~Abstract(); - inline int id() { return m_id; } + inline int id() const { return m_id; } // factory method - inline static Abstract* createObject() { return nullptr; } + inline static Abstract *createObject() { return nullptr; } // method that receives an Object Type - inline static int getObjectId(Abstract* obj) { return obj->id(); } + inline static int getObjectId(Abstract *obj) { return obj->id(); } virtual void pureVirtual() = 0; - virtual void* pureVirtualReturningVoidPtr() = 0; + virtual void *pureVirtualReturningVoidPtr() = 0; virtual void unpureVirtual(); virtual PrintFormat returnAnEnum() = 0; @@ -92,13 +69,16 @@ public: void callPureVirtual(); void callUnpureVirtual(); - void show(PrintFormat format = Verbose); + void show(PrintFormat format = Verbose) const; virtual Type type() const { return TpAbstract; } - virtual void hideFunction(HideType* arg) = 0; + virtual void hideFunction(HideType *arg) = 0; + + virtual void virtualWithOutParameter(int &x) const; + int callVirtualWithOutParameter() const; protected: - virtual const char* className() { return "Abstract"; } + virtual const char *className() const { return "Abstract"; } // Protected bit-field structure member. unsigned int bitField: 1; @@ -107,4 +87,5 @@ private: virtual void pureVirtualPrivate() = 0; int m_id; }; + #endif // ABSTRACT_H diff --git a/sources/shiboken6/tests/libsample/blackbox.cpp b/sources/shiboken6/tests/libsample/blackbox.cpp index 425476672..2ac435d3d 100644 --- a/sources/shiboken6/tests/libsample/blackbox.cpp +++ b/sources/shiboken6/tests/libsample/blackbox.cpp @@ -1,129 +1,81 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "blackbox.h" -using namespace std; - BlackBox::~BlackBox() { // Free all maps. - while (!m_objects.empty()) { - delete (*m_objects.begin()).second; - m_objects.erase(m_objects.begin()); - } - while (!m_points.empty()) { - delete (*m_points.begin()).second; - m_points.erase(m_points.begin()); - } + for (const auto &p :m_objects) + delete p.second; + for (const auto &p : m_points) + delete p.second; } -int -BlackBox::keepObjectType(ObjectType* object) +int BlackBox::keepObjectType(ObjectType *object) { - m_ticket++; - std::pair<int, ObjectType*> item(m_ticket, object); - m_objects.insert(item); + ++m_ticket; + m_objects.insert({m_ticket, object}); object->setParent(nullptr); return m_ticket; } -ObjectType* -BlackBox::retrieveObjectType(int ticket) +ObjectType *BlackBox::retrieveObjectType(int ticket) { const auto it = m_objects.find(ticket); if (it != m_objects.end()) { - ObjectType* second = it->second; + ObjectType *second = it->second; m_objects.erase(it); return second; } return nullptr; } -void -BlackBox::disposeObjectType(int ticket) +void BlackBox::disposeObjectType(int ticket) { - ObjectType* object = retrieveObjectType(ticket); - if (object) - delete object; + delete retrieveObjectType(ticket); } -int -BlackBox::keepPoint(Point* point) +int BlackBox::keepPoint(Point *point) { - m_ticket++; - std::pair<int, Point*> item(m_ticket, point); - m_points.insert(item); - + ++m_ticket; + m_points.insert({m_ticket, point}); return m_ticket; } -Point* -BlackBox::retrievePoint(int ticket) +Point *BlackBox::retrievePoint(int ticket) { const auto it = m_points.find(ticket); if (it != m_points.end()) { - Point* second = it->second; + Point *second = it->second; m_points.erase(it); return second; } return nullptr; } -void -BlackBox::disposePoint(int ticket) +void BlackBox::disposePoint(int ticket) { - Point* point = retrievePoint(ticket); - if (point) - delete point; + delete retrievePoint(ticket); } - -std::list<ObjectType*> -BlackBox::objects() +std::list<ObjectType*> BlackBox::objects() { std::list<ObjectType*> l; - for (auto it = m_objects.begin(), end = m_objects.end(); it != end; ++it) - l.push_back((*it).second); + for (const auto &p : m_objects) + l.push_back(p.second); return l; } -std::list<Point*> -BlackBox::points() +std::list<Point*> BlackBox::points() { std::list<Point*> l; - for (auto it = m_points.begin(), end = m_points.end(); it != end; ++it) - l.push_back((*it).second); + for (const auto &p : m_points) + l.push_back(p.second); return l; } - diff --git a/sources/shiboken6/tests/libsample/blackbox.h b/sources/shiboken6/tests/libsample/blackbox.h index 629a217cc..9d32670dd 100644 --- a/sources/shiboken6/tests/libsample/blackbox.h +++ b/sources/shiboken6/tests/libsample/blackbox.h @@ -1,54 +1,32 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef BLACKBOX_H #define BLACKBOX_H #include "libsamplemacros.h" -#include <map> #include "objecttype.h" #include "point.h" +#include <list> +#include <map> + class LIBSAMPLE_API BlackBox { public: - typedef std::map<int, ObjectType*> ObjectTypeMap; - typedef std::map<int, Point*> PointMap; + using ObjectTypeMap = std::map<int, ObjectType*>; + using PointMap = std::map<int, Point*>; - BlackBox() { m_ticket = -1;} + LIBMINIMAL_DEFAULT_COPY_MOVE(BlackBox) + BlackBox() noexcept = default; ~BlackBox(); - int keepObjectType(ObjectType* object); - ObjectType* retrieveObjectType(int ticket); + int keepObjectType(ObjectType *object); + ObjectType *retrieveObjectType(int ticket); void disposeObjectType(int ticket); - int keepPoint(Point* point); - Point* retrievePoint(int ticket); + int keepPoint(Point *point); + Point *retrievePoint(int ticket); void disposePoint(int ticket); std::list<ObjectType*> objects(); @@ -60,8 +38,7 @@ public: private: ObjectTypeMap m_objects; PointMap m_points; - int m_ticket; + int m_ticket = -1; }; #endif // BLACKBOX_H - diff --git a/sources/shiboken6/tests/libsample/bucket.cpp b/sources/shiboken6/tests/libsample/bucket.cpp index 91e546d6e..cafd382a9 100644 --- a/sources/shiboken6/tests/libsample/bucket.cpp +++ b/sources/shiboken6/tests/libsample/bucket.cpp @@ -1,49 +1,21 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "bucket.h" + #include <iostream> #ifdef _WIN32 // _WIN32 is defined by all Windows 32 and 64 bit compilers, but not by others. -#include <windows.h> -#define SLEEP(x) Sleep(x) +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include <windows.h> +# define SLEEP(x) Sleep(x) #else -#include <unistd.h> -#define SLEEP(x) usleep(x) +# include <unistd.h> +# define SLEEP(x) usleep(x) #endif - -using namespace std; - -Bucket::Bucket() : m_locked(false) -{ -} - void Bucket::push(int x) { m_data.push_back(x); @@ -53,7 +25,7 @@ int Bucket::pop(void) { int x = 0; - if (m_data.size() > 0) { + if (!m_data.empty()) { x = m_data.front(); m_data.pop_front(); } @@ -69,7 +41,9 @@ bool Bucket::empty() void Bucket::lock() { m_locked = true; - while (m_locked) { SLEEP(300); } + while (m_locked) { + SLEEP(300); + } } void Bucket::unlock() @@ -83,4 +57,3 @@ bool Bucket::virtualBlockerMethod() // The return value was added just for diversity sake. return true; } - diff --git a/sources/shiboken6/tests/libsample/bucket.h b/sources/shiboken6/tests/libsample/bucket.h index 09f933863..73e8edd78 100644 --- a/sources/shiboken6/tests/libsample/bucket.h +++ b/sources/shiboken6/tests/libsample/bucket.h @@ -1,36 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef BUCKET_H #define BUCKET_H #include "libsamplemacros.h" #include "objecttype.h" + #include <list> class ObjectType; @@ -38,7 +14,7 @@ class ObjectType; class LIBSAMPLE_API Bucket : public ObjectType { public: - Bucket(); + Bucket() = default; void push(int); int pop(); bool empty(); @@ -52,8 +28,7 @@ public: private: std::list<int> m_data; - volatile bool m_locked; + volatile bool m_locked = false; }; #endif // BUCKET_H - diff --git a/sources/shiboken6/tests/libsample/bytearray.cpp b/sources/shiboken6/tests/libsample/bytearray.cpp index 021d2a079..78d5162b0 100644 --- a/sources/shiboken6/tests/libsample/bytearray.cpp +++ b/sources/shiboken6/tests/libsample/bytearray.cpp @@ -1,38 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <cstring> #include "bytearray.h" -ByteArray::ByteArray() +#include <algorithm> +#include <iterator> +#include <cstring> + +ByteArray::ByteArray() : m_data(1, '\0') { - m_data = std::vector<char>(1); - m_data[0] = '\0'; } ByteArray::ByteArray(char c) @@ -42,48 +18,37 @@ ByteArray::ByteArray(char c) m_data[1] = '\0'; } -ByteArray::ByteArray(const char* data) +ByteArray::ByteArray(const char *data) { - size_t len = strlen(data); + size_t len = std::strlen(data); m_data = std::vector<char>(len + 1); memcpy(&m_data[0], data, len); m_data[len] = '\0'; } -ByteArray::ByteArray(const char* data, int len) +ByteArray::ByteArray(const char *data, int len) { m_data = std::vector<char>(len + 1); memcpy(&m_data[0], data, len); m_data[len] = '\0'; } -ByteArray::ByteArray(const ByteArray& other) -{ - m_data = std::vector<char>(other.size() + 1); - memcpy(&m_data[0], &other.m_data[0], other.size()); - m_data[other.size()] = '\0'; -} - -int -ByteArray::size() const +int ByteArray::size() const { return m_data.size() - 1; } -char -ByteArray::at(int pos) const +char ByteArray::at(int pos) const { return m_data[pos]; } -const char* -ByteArray::data() const +const char *ByteArray::data() const { return &(m_data[0]); } -ByteArray& -ByteArray::append(char c) +ByteArray &ByteArray::append(char c) { m_data.pop_back(); m_data.push_back(c); @@ -91,37 +56,30 @@ ByteArray::append(char c) return *this; } -ByteArray& -ByteArray::append(const char* data) +ByteArray &ByteArray::append(const char *data) { m_data.pop_back(); - for (int i = 0; i < (int)strlen(data); ++i) - m_data.push_back(data[i]); + std::copy(data, data + strlen(data), std::back_inserter(m_data)); m_data.push_back('\0'); return *this; } -ByteArray& -ByteArray::append(const char* data, int len) +ByteArray &ByteArray::append(const char *data, int len) { m_data.pop_back(); - for (int i = 0; i < len; ++i) - m_data.push_back(data[i]); + std::copy(data, data + len, std::back_inserter(m_data)); m_data.push_back('\0'); return *this; } -ByteArray& -ByteArray::append(const ByteArray& other) +ByteArray &ByteArray::append(const ByteArray &other) { m_data.pop_back(); - for (int i = 0; i < (int)other.m_data.size(); ++i) - m_data.push_back(other.m_data[i]); - m_data.push_back('\0'); + std::copy(other.m_data.begin(), other.m_data.end(), std::back_inserter(m_data)); return *this; } -static bool compare(const std::vector<char>& mine, const char* other) +static bool compare(const std::vector<char> &mine, const char *other) { for (int i = 0; i < (int)mine.size() - 1; ++i) { if (mine[i] != other[i]) @@ -130,85 +88,79 @@ static bool compare(const std::vector<char>& mine, const char* other) return true; } -bool -ByteArray::operator==(const ByteArray& other) const +bool ByteArray::operator==(const ByteArray &other) const { - return compare(m_data, &other.m_data[0]); + return m_data == other.m_data; } -bool -operator==(const ByteArray& ba1, const char* ba2) +bool operator==(const ByteArray &ba1, const char *ba2) { return compare(ba1.m_data, ba2); } -bool -operator==(const char* ba1, const ByteArray& ba2) + +bool operator==(const char *ba1, const ByteArray &ba2) { return compare(ba2.m_data, ba1); } -bool -ByteArray::operator!=(const ByteArray& other) const +bool ByteArray::operator!=(const ByteArray &other) const { - return !(m_data == other.m_data); + return m_data != other.m_data; } -bool -operator!=(const ByteArray& ba1, const char* ba2) + +bool operator!=(const ByteArray &ba1, const char *ba2) { return !(ba1 == ba2); } -bool -operator!=(const char* ba1, const ByteArray& ba2) + +bool operator!=(const char *ba1, const ByteArray &ba2) { return !(ba1 == ba2); } -ByteArray& -ByteArray::operator+=(char c) +ByteArray &ByteArray::operator+=(char c) { return append(c); } -ByteArray& -ByteArray::operator+=(const char* data) + +ByteArray &ByteArray::operator+=(const char *data) { return append(data); } -ByteArray& -ByteArray::operator+=(const ByteArray& other) + +ByteArray &ByteArray::operator+=(const ByteArray &other) { return append(other); } -ByteArray -operator+(const ByteArray& ba1, const ByteArray& ba2) +ByteArray operator+(const ByteArray &ba1, const ByteArray &ba2) { return ByteArray(ba1) += ba2; } -ByteArray -operator+(const ByteArray& ba1, const char* ba2) + +ByteArray operator+(const ByteArray &ba1, const char *ba2) { return ByteArray(ba1) += ByteArray(ba2); } -ByteArray -operator+(const char* ba1, const ByteArray& ba2) + +ByteArray operator+(const char *ba1, const ByteArray &ba2) { return ByteArray(ba1) += ba2; } -ByteArray -operator+(const ByteArray& ba1, char ba2) + +ByteArray operator+(const ByteArray &ba1, char ba2) { return ByteArray(ba1) += ByteArray(ba2); } -ByteArray -operator+(char ba1, const ByteArray& ba2) + +ByteArray operator+(char ba1, const ByteArray &ba2) { return ByteArray(ba1) += ba2; } -unsigned int -ByteArray::hash(const ByteArray& byteArray) +unsigned int ByteArray::hash(const ByteArray &byteArray) { unsigned int result = 0; - for (int i = 0; i < (int)byteArray.m_data.size(); ++i) - result = 5 * result + byteArray.m_data[i]; + for (char c : byteArray.m_data) + result = 5U * result + unsigned(c); return result; } diff --git a/sources/shiboken6/tests/libsample/bytearray.h b/sources/shiboken6/tests/libsample/bytearray.h index 5dfb63fd5..35ff22367 100644 --- a/sources/shiboken6/tests/libsample/bytearray.h +++ b/sources/shiboken6/tests/libsample/bytearray.h @@ -1,89 +1,64 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef BYTEARRAY_H #define BYTEARRAY_H #include "str.h" #include "libsamplemacros.h" + #include <vector> class LIBSAMPLE_API ByteArray { public: ByteArray(); - ByteArray(char data); - ByteArray(const char* data); - ByteArray(const char* data, int len); - ByteArray(const ByteArray& other); + explicit ByteArray(char data); + explicit ByteArray(const char *data); + explicit ByteArray(const char *data, int len); int size() const; char at(int i) const; char operator[](int i) const; - const char* data() const; + const char *data() const; - ByteArray& append(char c); - ByteArray& append(const char* data); - ByteArray& append(const char* data, int len); - ByteArray& append(const ByteArray& other); + ByteArray &append(char c); + ByteArray &append(const char *data); + ByteArray &append(const char *data, int len); + ByteArray &append(const ByteArray &other); - bool operator==(const ByteArray& other) const; - bool operator!=(const ByteArray& other) const; + bool operator==(const ByteArray &other) const; + bool operator!=(const ByteArray &other) const; - ByteArray& operator+=(char c); - ByteArray& operator+=(const char* data); - ByteArray& operator+=(const ByteArray& other); + ByteArray &operator+=(char c); + ByteArray &operator+=(const char *data); + ByteArray &operator+=(const ByteArray &other); - static unsigned int hash(const ByteArray& byteArray); + static unsigned int hash(const ByteArray &byteArray); private: std::vector<char> m_data; - friend LIBSAMPLE_API bool operator==(const ByteArray& ba1, const char* ba2); - friend LIBSAMPLE_API bool operator==(const char* ba1, const ByteArray& ba2); - friend LIBSAMPLE_API bool operator!=(const ByteArray& ba1, const char* ba2); - friend LIBSAMPLE_API bool operator!=(const char* ba1, const ByteArray& ba2); + friend LIBSAMPLE_API bool operator==(const ByteArray &ba1, const char *ba2); + friend LIBSAMPLE_API bool operator==(const char *ba1, const ByteArray &ba2); + friend LIBSAMPLE_API bool operator!=(const ByteArray &ba1, const char *ba2); + friend LIBSAMPLE_API bool operator!=(const char *ba1, const ByteArray &ba2); - friend LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, const ByteArray& ba2); - friend LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, const char* ba2); - friend LIBSAMPLE_API ByteArray operator+(const char* ba1, const ByteArray& ba2); - friend LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, char ba2); - friend LIBSAMPLE_API ByteArray operator+(char ba1, const ByteArray& ba2); + friend LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, const ByteArray &ba2); + friend LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, const char *ba2); + friend LIBSAMPLE_API ByteArray operator+(const char *ba1, const ByteArray &ba2); + friend LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, char ba2); + friend LIBSAMPLE_API ByteArray operator+(char ba1, const ByteArray &ba2); }; -LIBSAMPLE_API bool operator==(const ByteArray& ba1, const char* ba2); -LIBSAMPLE_API bool operator==(const char* ba1, const ByteArray& ba2); -LIBSAMPLE_API bool operator!=(const ByteArray& ba1, const char* ba2); -LIBSAMPLE_API bool operator!=(const char* ba1, const ByteArray& ba2); +LIBSAMPLE_API bool operator==(const ByteArray &ba1, const char *ba2); +LIBSAMPLE_API bool operator==(const char *ba1, const ByteArray &ba2); +LIBSAMPLE_API bool operator!=(const ByteArray &ba1, const char *ba2); +LIBSAMPLE_API bool operator!=(const char *ba1, const ByteArray &ba2); -LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, const ByteArray& ba2); -LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, const char* ba2); -LIBSAMPLE_API ByteArray operator+(const char* ba1, const ByteArray& ba2); -LIBSAMPLE_API ByteArray operator+(const ByteArray& ba1, char ba2); -LIBSAMPLE_API ByteArray operator+(char ba1, const ByteArray& ba2); +LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, const ByteArray &ba2); +LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, const char *ba2); +LIBSAMPLE_API ByteArray operator+(const char *ba1, const ByteArray &ba2); +LIBSAMPLE_API ByteArray operator+(const ByteArray &ba1, char ba2); +LIBSAMPLE_API ByteArray operator+(char ba1, const ByteArray &ba2); #endif // BYTEARRAY_H diff --git a/sources/shiboken6/tests/libsample/collector.cpp b/sources/shiboken6/tests/libsample/collector.cpp index aca24e355..579239bcb 100644 --- a/sources/shiboken6/tests/libsample/collector.cpp +++ b/sources/shiboken6/tests/libsample/collector.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "collector.h" @@ -33,13 +8,13 @@ void Collector::clear() m_items.clear(); } -Collector& Collector::operator<<(ObjectType::Identifier item) +Collector &Collector::operator<<(ObjectType::Identifier item) { m_items.push_back(item); return *this; } -Collector& Collector::operator<<(const ObjectType *obj) +Collector &Collector::operator<<(const ObjectType *obj) { m_items.push_back(obj->identifier()); return *this; @@ -50,9 +25,9 @@ std::list<ObjectType::Identifier> Collector::items() return m_items; } -int Collector::size() +int Collector::size() const { - return (int) m_items.size(); + return int(m_items.size()); } Collector &operator<<(Collector &s, const IntWrapper &w) diff --git a/sources/shiboken6/tests/libsample/collector.h b/sources/shiboken6/tests/libsample/collector.h index bc10a7481..26766847a 100644 --- a/sources/shiboken6/tests/libsample/collector.h +++ b/sources/shiboken6/tests/libsample/collector.h @@ -1,64 +1,37 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef COLLECTOR_H #define COLLECTOR_H -#include <list> #include "libsamplemacros.h" - #include "intwrapper.h" #include "objecttype.h" +#include <list> + class LIBSAMPLE_API Collector { public: - Collector() {} - virtual ~Collector() {} + Collector() noexcept = default; + virtual ~Collector() = default; + LIBMINIMAL_DISABLE_COPY_MOVE(Collector) void clear(); - Collector& operator<<(ObjectType::Identifier item); + Collector &operator<<(ObjectType::Identifier item); - Collector& operator<<(const ObjectType *); + Collector &operator<<(const ObjectType *); std::list<ObjectType::Identifier> items(); - int size(); + int size() const; private: std::list<ObjectType::Identifier> m_items; - - Collector(const Collector&); - Collector& operator=(const Collector&); }; /* Helper for testing external operators */ -LIBSAMPLE_API Collector &operator<<(Collector&, const IntWrapper&); +LIBSAMPLE_API Collector &operator<<(Collector &, const IntWrapper &); #endif // COLLECTOR_H diff --git a/sources/shiboken6/tests/libsample/complex.cpp b/sources/shiboken6/tests/libsample/complex.cpp index a9b7f03c3..e3bec9aae 100644 --- a/sources/shiboken6/tests/libsample/complex.cpp +++ b/sources/shiboken6/tests/libsample/complex.cpp @@ -1,43 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "complex.h" -using namespace std; +#include <iostream> -Complex::Complex(double real, double imag) +Complex::Complex(double real, double imag) noexcept : m_real(real), m_imag(imag) { } -Complex -Complex::operator+(Complex& other) +Complex Complex::operator+(const Complex &other) { Complex result; result.setReal(m_real + other.real()); @@ -45,10 +18,7 @@ Complex::operator+(Complex& other) return result; } -void -Complex::show() +void Complex::show() const { - cout << "(real: " << m_real << ", imag: " << m_imag << ")"; + std::cout << "(real: " << m_real << ", imag: " << m_imag << ")"; } - - diff --git a/sources/shiboken6/tests/libsample/complex.h b/sources/shiboken6/tests/libsample/complex.h index d0f6c1408..168fe5c44 100644 --- a/sources/shiboken6/tests/libsample/complex.h +++ b/sources/shiboken6/tests/libsample/complex.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef COMPLEX_H #define COMPLEX_H @@ -34,17 +9,19 @@ class LIBSAMPLE_API Complex { public: - Complex(double real = 0.0, double imag = 0.0); - ~Complex() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(Complex) + + explicit Complex(double real = 0.0, double imag = 0.0) noexcept; + ~Complex() = default; inline double real() const { return m_real; } inline void setReal(double real) { m_real = real; } inline double imag() const { return m_imag; } inline void setImaginary(double imag) { m_imag = imag; } - Complex operator+(Complex& other); + Complex operator+(const Complex &other); - void show(); + void show() const; private: double m_real; diff --git a/sources/shiboken6/tests/libsample/ctorconvrule.h b/sources/shiboken6/tests/libsample/ctorconvrule.h index ceab8d6dc..a5411b749 100644 --- a/sources/shiboken6/tests/libsample/ctorconvrule.h +++ b/sources/shiboken6/tests/libsample/ctorconvrule.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef CTORCONVRULE_H #define CTORCONVRULE_H @@ -34,8 +9,10 @@ class CtorConvRule { public: - explicit CtorConvRule(long value) : m_value(value) {} - virtual ~CtorConvRule() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(CtorConvRule) + + explicit CtorConvRule(long value) noexcept : m_value(value) {} + virtual ~CtorConvRule() = default; virtual void dummyVirtualMethod() {} long value() { return m_value; } private: diff --git a/sources/shiboken6/tests/libsample/ctparam.cpp b/sources/shiboken6/tests/libsample/ctparam.cpp index 89d4dd744..9bbbcfc3f 100644 --- a/sources/shiboken6/tests/libsample/ctparam.cpp +++ b/sources/shiboken6/tests/libsample/ctparam.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "ctparam.h" diff --git a/sources/shiboken6/tests/libsample/ctparam.h b/sources/shiboken6/tests/libsample/ctparam.h index 8acf14aaf..fa241b587 100644 --- a/sources/shiboken6/tests/libsample/ctparam.h +++ b/sources/shiboken6/tests/libsample/ctparam.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef CTPARAM_H #define CTPARAM_H diff --git a/sources/shiboken6/tests/libsample/cvlist.h b/sources/shiboken6/tests/libsample/cvlist.h index 50ad8bfe8..e09c7d943 100644 --- a/sources/shiboken6/tests/libsample/cvlist.h +++ b/sources/shiboken6/tests/libsample/cvlist.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef CONSTVALUELIST_H #define CONSTVALUELIST_H @@ -37,7 +12,7 @@ class CVValueType CVValueType(); }; -typedef std::list<const CVValueType*> const_ptr_value_list; +using const_ptr_value_list = std::list<const CVValueType*>; // This tests binding generation for a container of a const value type. The // class doesn't need to do anything; this is just to verify that the generated @@ -46,8 +21,8 @@ typedef std::list<const CVValueType*> const_ptr_value_list; class CVListUser { public: - static const_ptr_value_list produce() { return const_ptr_value_list(); } - static void consume(const const_ptr_value_list& l) { (void)l; } + static const_ptr_value_list produce() { return {}; } + static void consume(const const_ptr_value_list &l) { (void)l; } }; #endif // LIST_H diff --git a/sources/shiboken6/tests/libsample/derived.cpp b/sources/shiboken6/tests/libsample/derived.cpp index 0dc026876..d20880431 100644 --- a/sources/shiboken6/tests/libsample/derived.cpp +++ b/sources/shiboken6/tests/libsample/derived.cpp @@ -1,69 +1,36 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "derived.h" -using namespace std; +#include <iostream> -Derived::Derived(int id) : Abstract(id) +Derived::Derived(int id) noexcept : Abstract(id) { } -Derived::~Derived() -{ -} +Derived::~Derived() = default; -Abstract* -Derived::createObject() +Abstract *Derived::createObject() { static int id = 100; return new Derived(id++); } -void -Derived::pureVirtual() +void Derived::pureVirtual() { } -void* -Derived::pureVirtualReturningVoidPtr() +void *Derived::pureVirtualReturningVoidPtr() { return nullptr; } -void -Derived::unpureVirtual() +void Derived::unpureVirtual() { } -bool -Derived::singleArgument(bool b) +bool Derived::singleArgument(bool b) { return !b; } @@ -74,40 +41,36 @@ Derived::defaultValue(int n) return ((double) n) + 0.1; } -OverloadedFuncEnum -Derived::overloaded(int i, int d) +OverloadedFuncEnum Derived::overloaded(int, int) { return OverloadedFunc_ii; } -OverloadedFuncEnum -Derived::overloaded(double n) +OverloadedFuncEnum Derived::overloaded(double) { return OverloadedFunc_d; } -Derived::OtherOverloadedFuncEnum -Derived::otherOverloaded(int a, int b, bool c, double d) +Derived::OtherOverloadedFuncEnum Derived::otherOverloaded(int, int, bool, double) { return OtherOverloadedFunc_iibd; } -Derived::OtherOverloadedFuncEnum -Derived::otherOverloaded(int a, double b) +Derived::OtherOverloadedFuncEnum Derived::otherOverloaded(int, double) { return OtherOverloadedFunc_id; } struct SecretClass : public Abstract { - virtual void pureVirtual() {} - virtual void *pureVirtualReturningVoidPtr() { return nullptr; } - virtual PrintFormat returnAnEnum() { return Short; } - void hideFunction(HideType*){}; + void pureVirtual() override {} + void *pureVirtualReturningVoidPtr() override { return nullptr; } + PrintFormat returnAnEnum() override { return Short; } + void hideFunction(HideType*) override {}; private: - virtual void pureVirtualPrivate() {} + void pureVirtualPrivate() override {} }; -Abstract* Derived::triggerImpossibleTypeDiscovery() +Abstract *Derived::triggerImpossibleTypeDiscovery() { return new SecretClass; } @@ -115,7 +78,7 @@ Abstract* Derived::triggerImpossibleTypeDiscovery() struct AnotherSecretClass : public Derived { }; -Abstract* Derived::triggerAnotherImpossibleTypeDiscovery() +Abstract *Derived::triggerAnotherImpossibleTypeDiscovery() { return new AnotherSecretClass; } diff --git a/sources/shiboken6/tests/libsample/derived.h b/sources/shiboken6/tests/libsample/derived.h index 783a6dc50..b7736c37a 100644 --- a/sources/shiboken6/tests/libsample/derived.h +++ b/sources/shiboken6/tests/libsample/derived.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef DERIVED_H #define DERIVED_H @@ -40,6 +15,8 @@ enum OverloadedFuncEnum { class LIBSAMPLE_API Derived : public Abstract { public: + LIBMINIMAL_DISABLE_COPY_MOVE(Derived) + enum OtherOverloadedFuncEnum { OtherOverloadedFunc_iibd, OtherOverloadedFunc_id @@ -48,21 +25,21 @@ public: class SomeInnerClass { public: void uselessMethod() {} - SomeInnerClass operator+(const SomeInnerClass& other) { return other; } - bool operator==(const SomeInnerClass& other) { return true; } + SomeInnerClass operator+(const SomeInnerClass &other) { return other; } + bool operator==(const SomeInnerClass &) { return true; } }; - Derived(int id = -1); + explicit Derived(int id = -1) noexcept; ~Derived() override; void pureVirtual() override; - void* pureVirtualReturningVoidPtr() override; + void *pureVirtualReturningVoidPtr() override; void unpureVirtual() override; PrintFormat returnAnEnum() override { return Short; } Type type() const override { return TpDerived; } // factory method - static Abstract* createObject(); + static Abstract *createObject(); // single argument bool singleArgument(bool b); @@ -78,15 +55,15 @@ public: OtherOverloadedFuncEnum otherOverloaded(int a, int b, bool c, double d); OtherOverloadedFuncEnum otherOverloaded(int a, double b); - inline SomeInnerClass returnMyParameter(const SomeInnerClass& s) { return s; } + inline SomeInnerClass returnMyParameter(const SomeInnerClass &s) { return s; } - static Abstract* triggerImpossibleTypeDiscovery(); - static Abstract* triggerAnotherImpossibleTypeDiscovery(); + static Abstract *triggerImpossibleTypeDiscovery(); + static Abstract *triggerAnotherImpossibleTypeDiscovery(); void hideFunction(HideType*) override {} protected: - const char* getClassName() { return className(); } - virtual const char* className() override { return "Derived"; } + const char *getClassName() { return className(); } + virtual const char *className() const override { return "Derived"; } private: void pureVirtualPrivate() override; diff --git a/sources/shiboken6/tests/libsample/derivedusingct.cpp b/sources/shiboken6/tests/libsample/derivedusingct.cpp index 3ee5f2cb4..720d0ed96 100644 --- a/sources/shiboken6/tests/libsample/derivedusingct.cpp +++ b/sources/shiboken6/tests/libsample/derivedusingct.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "derivedusingct.h" diff --git a/sources/shiboken6/tests/libsample/derivedusingct.h b/sources/shiboken6/tests/libsample/derivedusingct.h index ae0682cfd..6bc026d08 100644 --- a/sources/shiboken6/tests/libsample/derivedusingct.h +++ b/sources/shiboken6/tests/libsample/derivedusingct.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef DERIVEDUSINGCT_H #define DERIVEDUSINGCT_H diff --git a/sources/shiboken6/tests/libsample/echo.cpp b/sources/shiboken6/tests/libsample/echo.cpp index 55e2a461e..7fa8433d3 100644 --- a/sources/shiboken6/tests/libsample/echo.cpp +++ b/sources/shiboken6/tests/libsample/echo.cpp @@ -1,29 +1,4 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "echo.h" diff --git a/sources/shiboken6/tests/libsample/echo.h b/sources/shiboken6/tests/libsample/echo.h index 3f645694a..01b11a4a6 100644 --- a/sources/shiboken6/tests/libsample/echo.h +++ b/sources/shiboken6/tests/libsample/echo.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef ECHO_H #define ECHO_H @@ -37,19 +12,49 @@ class ObjectType; class Echo { public: - Echo(){} - ~Echo(){} + LIBMINIMAL_DEFAULT_COPY_MOVE(Echo) - void doNothingWithConstBool(const bool hi) {} - void methodWithNamedArg(const Str& string = Str("")) {} + Echo() noexcept = default; + ~Echo() = default; - Str operator()(const Str& s, const int i) { return s + i; } + void doNothingWithConstBool(const bool hi); + void methodWithNamedArg(const Str &string = Str{}); + + Str operator()(const Str &s, const int i) { return s + i; } // These method are here just for compilation test purposes - Echo& operator<<(unsigned int item) { return *this; } - Echo& operator<<(signed int item) { return *this; } - Echo& operator<<(const ObjectType* item) { return *this; } - Echo& operator<<(Str str) { return *this; } + Echo &operator<<(unsigned int item); + Echo &operator<<(signed int item); + Echo &operator<<(const ObjectType *item); + Echo &operator<<(Str str); }; -#endif +inline void Echo::doNothingWithConstBool(const bool) +{ +} + +inline void Echo::methodWithNamedArg(const Str &) +{ +} + +inline Echo &Echo::operator<<(unsigned int) +{ + return *this; +} + +inline Echo &Echo::operator<<(signed int) +{ + return *this; +} + +inline Echo &Echo::operator<<(const ObjectType *) +{ + return *this; +} + +inline Echo &Echo::operator<<(Str) +{ + return *this; +} + +#endif // ECHO_H diff --git a/sources/shiboken6/tests/libsample/exceptiontest.cpp b/sources/shiboken6/tests/libsample/exceptiontest.cpp index 1302a8e43..56144e086 100644 --- a/sources/shiboken6/tests/libsample/exceptiontest.cpp +++ b/sources/shiboken6/tests/libsample/exceptiontest.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "exceptiontest.h" @@ -62,3 +37,10 @@ void ExceptionTest::voidThrowInt(bool doThrow) if (doThrow) throw 42; } + +ExceptionTest *ExceptionTest::create(bool doThrow) +{ + if (doThrow) + throw TestException(); + return new ExceptionTest; +} diff --git a/sources/shiboken6/tests/libsample/exceptiontest.h b/sources/shiboken6/tests/libsample/exceptiontest.h index 8ab3e2b67..b5812a090 100644 --- a/sources/shiboken6/tests/libsample/exceptiontest.h +++ b/sources/shiboken6/tests/libsample/exceptiontest.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef EXCEPTIONTEST_H #define EXCEPTIONTEST_H @@ -43,6 +18,8 @@ class LIBSAMPLE_API ExceptionTest int intThrowInt(bool doThrow); void voidThrowInt(bool doThrow); + + static ExceptionTest *create(bool doThrow); }; #endif // EXCEPTIONTEST_H diff --git a/sources/shiboken6/tests/libsample/expression.cpp b/sources/shiboken6/tests/libsample/expression.cpp index 0b0bcdefe..6f3c5fdc5 100644 --- a/sources/shiboken6/tests/libsample/expression.cpp +++ b/sources/shiboken6/tests/libsample/expression.cpp @@ -1,139 +1,79 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "expression.h" -#include <sstream> - -Expression::Expression() : m_value(0), m_operation(None), m_operand1(nullptr), m_operand2(nullptr) -{ -} - -Expression::Expression(int number) : m_value(number), m_operation(None), m_operand1(nullptr), m_operand2(nullptr) -{ -} -Expression::Expression(const Expression& other) -{ - m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : nullptr; - m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : nullptr; - m_value = other.m_value; - m_operation = other.m_operation; -} +#include <sstream> -Expression& Expression::operator=(const Expression& other) -{ - if (&other == this) - return *this; - delete m_operand1; - delete m_operand2; - m_operand1 = other.m_operand1 ? new Expression(*other.m_operand1) : nullptr; - m_operand2 = other.m_operand2 ? new Expression(*other.m_operand2) : nullptr; - m_operation = other.m_operation; - m_value = other.m_value; - return *this; -} +Expression::Expression() noexcept = default; -Expression::~Expression() +Expression::Expression(int number) noexcept : m_value(number) { - delete m_operand1; - delete m_operand2; } -Expression Expression::operator+(const Expression& other) +Expression Expression::operator+(const Expression &other) { Expression expr; expr.m_operation = Add; - expr.m_operand1 = new Expression(*this); - expr.m_operand2 = new Expression(other); + expr.m_operand1 = std::make_shared<Expression>(*this); + expr.m_operand2 = std::make_shared<Expression>(other); return expr; } -Expression Expression::operator-(const Expression& other) +Expression Expression::operator-(const Expression &other) { Expression expr; expr.m_operation = Add; - expr.m_operand1 = new Expression(*this); - expr.m_operand2 = new Expression(other); + expr.m_operand1 = std::make_shared<Expression>(*this); + expr.m_operand2 = std::make_shared<Expression>(other); return expr; } -Expression Expression::operator<(const Expression& other) +Expression Expression::operator<(const Expression &other) { Expression expr; expr.m_operation = LessThan; - expr.m_operand1 = new Expression(*this); - expr.m_operand2 = new Expression(other); + expr.m_operand1 = std::make_shared<Expression>(*this); + expr.m_operand2 = std::make_shared<Expression>(other); return expr; } -Expression Expression::operator>(const Expression& other) +Expression Expression::operator>(const Expression &other) { Expression expr; expr.m_operation = GreaterThan; - expr.m_operand1 = new Expression(*this); - expr.m_operand2 = new Expression(other); + expr.m_operand1 = std::make_shared<Expression>(*this); + expr.m_operand2 = std::make_shared<Expression>(other); return expr; } std::string Expression::toString() const { + std::ostringstream s; if (m_operation == None) { - std::ostringstream s; s << m_value; return s.str(); } - std::string result; - result += '('; - result += m_operand1->toString(); - char op; + s << '(' << m_operand1->toString(); switch (m_operation) { case Add: - op = '+'; + s << '+'; break; case Sub: - op = '-'; + s << '-'; break; case LessThan: - op = '<'; + s << '<'; break; case GreaterThan: - op = '<'; + s << '<'; break; - case None: // just to avoid the compiler warning default: - op = '?'; + s << '?'; break; } - result += op; - result += m_operand2->toString(); - result += ')'; - return result; + s << m_operand2->toString() << ')'; + return s.str(); } - diff --git a/sources/shiboken6/tests/libsample/expression.h b/sources/shiboken6/tests/libsample/expression.h index 3add5572e..e7c5b7306 100644 --- a/sources/shiboken6/tests/libsample/expression.h +++ b/sources/shiboken6/tests/libsample/expression.h @@ -1,64 +1,40 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef EXPRESSION_H #define EXPRESSION_H #include "libsamplemacros.h" + +#include <memory> #include <string> class LIBSAMPLE_API Expression { public: + LIBMINIMAL_DEFAULT_COPY_MOVE(Expression) + enum Operation { None, Add, Sub, LessThan, GreaterThan }; - Expression(int number); - Expression(const Expression& other); - Expression& operator=(const Expression& other); - - ~Expression(); + explicit Expression(int number) noexcept; + ~Expression() = default; - Expression operator>(const Expression& other); - Expression operator<(const Expression& other); - Expression operator+(const Expression& other); - Expression operator-(const Expression& other); + Expression operator>(const Expression &other); + Expression operator<(const Expression &other); + Expression operator+(const Expression &other); + Expression operator-(const Expression &other); std::string toString() const; private: - int m_value; - Operation m_operation; - Expression* m_operand1; - Expression* m_operand2; + int m_value = 0; + Operation m_operation = None; + std::shared_ptr<Expression> m_operand1; + std::shared_ptr<Expression> m_operand2; - Expression(); + Expression() noexcept; }; #endif // EXPRESSION_H diff --git a/sources/shiboken6/tests/libsample/filter.cpp b/sources/shiboken6/tests/libsample/filter.cpp index f862babd2..950847985 100644 --- a/sources/shiboken6/tests/libsample/filter.cpp +++ b/sources/shiboken6/tests/libsample/filter.cpp @@ -1,69 +1,34 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <string> #include "filter.h" + Data::Data(Field field, std::string value) : m_field(field), m_value(value) { } -Union::Union(const Data& filter) +Union::Union(const Data &filter) { m_filters.push_back(filter); } -Union::Union(const Intersection& filter) +Union::Union(const Intersection &filter) { m_filters.push_back(filter); } -Union::Union(const Union& filter) -{ - m_filters = filter.filters(); -} - -Intersection::Intersection(const Data& filter) +Intersection::Intersection(const Data &filter) { m_filters.push_back(filter); } -Intersection::Intersection(const Union& filter) +Intersection::Intersection(const Union &filter) { m_filters.push_back(filter); } -Intersection::Intersection(const Intersection& filter) -{ - m_filters = filter.filters(); -} - -Intersection operator&(const Intersection& a, const Intersection& b) +Intersection operator&(const Intersection &a, const Intersection &b) { Intersection filter; filter.addFilter(a); diff --git a/sources/shiboken6/tests/libsample/filter.h b/sources/shiboken6/tests/libsample/filter.h index e318cba20..d82d38eb8 100644 --- a/sources/shiboken6/tests/libsample/filter.h +++ b/sources/shiboken6/tests/libsample/filter.h @@ -1,39 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef FILTER_H #define FILTER_H +#include "libsamplemacros.h" + #include <string> #include <list> -#include "libsamplemacros.h" - class Intersection; class LIBSAMPLE_API Filter @@ -42,7 +17,6 @@ class LIBSAMPLE_API Filter class LIBSAMPLE_API Data : public Filter { - public: enum Field { Name, @@ -50,7 +24,7 @@ public: Year }; - Data(Field field, std::string value); + explicit Data(Field field, std::string value); Field field() const { return m_field; } std::string value() const { return m_value; } @@ -64,13 +38,12 @@ class LIBSAMPLE_API Union : public Filter { public: - Union(const Data&); - Union(const Intersection&); - Union() {}; - Union(const Union&); + Union(const Data &); + Union(const Intersection &); + Union() = default; std::list<Filter> filters() const { return m_filters; } - void addFilter(const Filter& data) { m_filters.push_back(data); } + void addFilter(const Filter &data) { m_filters.push_back(data); } private: std::list<Filter> m_filters; @@ -79,20 +52,18 @@ private: class LIBSAMPLE_API Intersection : public Filter { public: - - Intersection(const Data&); - Intersection(const Union&); - Intersection() {}; - Intersection(const Intersection&); + Intersection(const Data &); + Intersection(const Union &); + Intersection() = default; std::list<Filter> filters() const { return m_filters; } - void addFilter(const Filter& data) { m_filters.push_back(data); } + void addFilter(const Filter &data) { m_filters.push_back(data); } private: std::list<Filter> m_filters; }; -LIBSAMPLE_API Intersection operator&(const Intersection& a, const Intersection& b); +LIBSAMPLE_API Intersection operator&(const Intersection &a, const Intersection &b); #endif // FILTER_H diff --git a/sources/shiboken6/tests/libsample/functions.cpp b/sources/shiboken6/tests/libsample/functions.cpp index 288fa96ee..ad2f4dd5a 100644 --- a/sources/shiboken6/tests/libsample/functions.cpp +++ b/sources/shiboken6/tests/libsample/functions.cpp @@ -1,63 +1,34 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "functions.h" -#include <string.h> +#include "polygon.h" + +#include <cstring> #include <algorithm> #include <iostream> #include <numeric> -using namespace std; - -void -printSomething() +void printSomething() { - cout << __FUNCTION__ << endl; + std::cout << __FUNCTION__ << std::endl; } -int -gimmeInt() +int gimmeInt() { static int val = 2; val = val * 1.3; return val; } -double -gimmeDouble() +double gimmeDouble() { static double val = 7.77; val = val * 1.3; return val; } -std::list<Complex> -gimmeComplexList() +std::list<Complex> gimmeComplexList() { std::list<Complex> lst; lst.push_back(Complex()); @@ -66,135 +37,114 @@ gimmeComplexList() return lst; } -Complex -sumComplexPair(std::pair<Complex, Complex> cpx_pair) +Complex sumComplexPair(std::pair<Complex, Complex> cpx_pair) { return cpx_pair.first + cpx_pair.second; } -double -multiplyPair(std::pair<double, double> pair) +double multiplyPair(std::pair<double, double> pair) { return pair.first * pair.second; } -int -countCharacters(const char* text) +int countCharacters(const char *text) { - if (!text) - return -1; - int count; - for(count = 0; text[count] != '\0'; count++) - ; - return count; + return text != nullptr ? int(std::strlen(text)) : -1; } -char* -makeCString() +char *makeCString() { - char* string = new char[strlen(__FUNCTION__) + 1]; - strcpy(string, __FUNCTION__); + char *string = new char[std::strlen(__FUNCTION__) + 1]; + std::strcpy(string, __FUNCTION__); return string; } -const char* -returnCString() +const char *returnCString() { return __FUNCTION__; } -GlobalOverloadFuncEnum -overloadedFunc(int val) +GlobalOverloadFuncEnum overloadedFunc(int) { return GlobalOverloadFunc_i; } -GlobalOverloadFuncEnum -overloadedFunc(double val) +GlobalOverloadFuncEnum overloadedFunc(double) { return GlobalOverloadFunc_d; } -char* -returnNullPrimitivePointer() +char *returnNullPrimitivePointer() { return nullptr; } -ObjectType* -returnNullObjectTypePointer() +ObjectType *returnNullObjectTypePointer() { return nullptr; } -Event* -returnNullValueTypePointer() +Event *returnNullValueTypePointer() { return nullptr; } -unsigned int -doubleUnsignedInt(unsigned int value) +unsigned int doubleUnsignedInt(unsigned int value) { return value * 2; } -long long -doubleLongLong(long long value) +long long doubleLongLong(long long value) { return value * 2; } -unsigned long long -doubleUnsignedLongLong(unsigned long long value) +unsigned long long doubleUnsignedLongLong(unsigned long long value) { return value * 2; } -short -doubleShort(short value) +short doubleShort(short value) { return value * 2; } -int -acceptInt(int x) +int acceptInt(int x) { return x; } -unsigned int -acceptUInt(unsigned int x) +const int *acceptIntReturnPtr(int x) +{ + return new int(x); +} + +unsigned int acceptUInt(unsigned int x) { return x; } -long -acceptLong(long x) +long acceptLong(long x) { return x; } -unsigned long -acceptULong(unsigned long x) +unsigned long acceptULong(unsigned long x) { return x; } -double -acceptDouble(double x) +double acceptDouble(double x) { return x; } -int -acceptIntReference(int& x) +int acceptIntReference(int &x) { return x; } -OddBool -acceptOddBoolReference(OddBool& x) +OddBool acceptOddBoolReference(OddBool &x) { return x; } @@ -229,9 +179,7 @@ double sumDoubleMatrix(double m[2][3]) return result; } -ArrayModifyTest::ArrayModifyTest() -{ -} +ArrayModifyTest::ArrayModifyTest() = default; int ArrayModifyTest::sumIntArray(int n, int *array) { @@ -253,3 +201,32 @@ void ClassWithFunctionPointer::doNothing(void *operand) { (void) operand; } + +std::string addStdStrings(const std::string &s1, const std::string &s2) +{ + return s1 + s2; +} + +std::wstring addStdWStrings(const std::wstring &s1, const std::wstring &s2) +{ + return s1 + s2; +} + +void testNullPtrT(std::nullptr_t) +{ + std::cout << __FUNCTION__ << '\n'; +} + +int takePolygon(Polygon &&p) +{ + auto p2 = std::move(p); + std::cout << __FUNCTION__ << ' ' << p2.points().size() << " points\n"; + return int(p2.points().size()); +} + +int takeObjectType(ObjectType &&o) +{ + auto o2 = std::move(o); + std::cout << __FUNCTION__ << ' ' << o2.objectName().cstring() << '\n'; + return o2.objectName().size(); +} diff --git a/sources/shiboken6/tests/libsample/functions.h b/sources/shiboken6/tests/libsample/functions.h index cad8b2a33..b745aed6b 100644 --- a/sources/shiboken6/tests/libsample/functions.h +++ b/sources/shiboken6/tests/libsample/functions.h @@ -1,41 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef FUNCTIONS_H #define FUNCTIONS_H #include "libsamplemacros.h" -#include <list> -#include <utility> #include "oddbool.h" #include "complex.h" #include "objecttype.h" +#include <list> +#include <utility> + +class Polygon; + enum GlobalEnum { NoThing, FirstThing, @@ -55,13 +33,13 @@ LIBSAMPLE_API double multiplyPair(std::pair<double, double> pair); LIBSAMPLE_API std::list<Complex> gimmeComplexList(); LIBSAMPLE_API Complex sumComplexPair(std::pair<Complex, Complex> cpx_pair); -LIBSAMPLE_API int countCharacters(const char* text); -LIBSAMPLE_API char* makeCString(); -LIBSAMPLE_API const char* returnCString(); +LIBSAMPLE_API int countCharacters(const char *text); +LIBSAMPLE_API char *makeCString(); +LIBSAMPLE_API const char *returnCString(); -LIBSAMPLE_API char* returnNullPrimitivePointer(); -LIBSAMPLE_API ObjectType* returnNullObjectTypePointer(); -LIBSAMPLE_API Event* returnNullValueTypePointer(); +LIBSAMPLE_API char *returnNullPrimitivePointer(); +LIBSAMPLE_API ObjectType *returnNullObjectTypePointer(); +LIBSAMPLE_API Event *returnNullValueTypePointer(); // Tests overloading on functions (!methods) LIBSAMPLE_API GlobalOverloadFuncEnum overloadedFunc(int val); @@ -73,19 +51,28 @@ LIBSAMPLE_API unsigned long long doubleUnsignedLongLong(unsigned long long value LIBSAMPLE_API short doubleShort(short value); LIBSAMPLE_API int acceptInt(int x); +LIBSAMPLE_API const int *acceptIntReturnPtr(int x); LIBSAMPLE_API unsigned int acceptUInt(unsigned int x); LIBSAMPLE_API long acceptLong(long x); LIBSAMPLE_API unsigned long acceptULong(unsigned long x); LIBSAMPLE_API double acceptDouble(double x); -LIBSAMPLE_API int acceptIntReference(int& x); -LIBSAMPLE_API OddBool acceptOddBoolReference(OddBool& x); +LIBSAMPLE_API int acceptIntReference(int &x); +LIBSAMPLE_API OddBool acceptOddBoolReference(OddBool &x); LIBSAMPLE_API int sumIntArray(int array[4]); LIBSAMPLE_API double sumDoubleArray(double array[4]); LIBSAMPLE_API int sumIntMatrix(int m[2][3]); LIBSAMPLE_API double sumDoubleMatrix(double m[2][3]); +LIBSAMPLE_API std::string addStdStrings(const std::string &s1, const std::string &s2); +LIBSAMPLE_API std::wstring addStdWStrings(const std::wstring &s1, const std::wstring &s2); + +LIBSAMPLE_API void testNullPtrT(std::nullptr_t); + +LIBSAMPLE_API int takePolygon(Polygon &&p); +LIBSAMPLE_API int takeObjectType(ObjectType &&o); + class LIBSAMPLE_API ArrayModifyTest { public: diff --git a/sources/shiboken6/tests/libsample/handle.cpp b/sources/shiboken6/tests/libsample/handle.cpp index 643eac458..93c2abe47 100644 --- a/sources/shiboken6/tests/libsample/handle.cpp +++ b/sources/shiboken6/tests/libsample/handle.cpp @@ -1,44 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "handle.h" -HANDLE HandleHolder::createHandle() +SAMPLE_HANDLE HandleHolder::createHandle() { - return (HANDLE) new OBJ; + return (SAMPLE_HANDLE) new OBJ; } -bool HandleHolder::compare(HandleHolder* other) +bool HandleHolder::compare(HandleHolder *other) { return other->m_handle == m_handle; } -bool HandleHolder::compare2(HandleHolder* other) +bool HandleHolder::compare2(HandleHolder *other) { return other->m_handle2 == m_handle2; } diff --git a/sources/shiboken6/tests/libsample/handle.h b/sources/shiboken6/tests/libsample/handle.h index 824c28b9a..07fc89d15 100644 --- a/sources/shiboken6/tests/libsample/handle.h +++ b/sources/shiboken6/tests/libsample/handle.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef HANDLE_H #define HANDLE_H @@ -33,35 +8,41 @@ /* See http://bugs.pyside.org/show_bug.cgi?id=1105. */ namespace Foo { - using HANDLE = unsigned long; + using SAMPLE_HANDLE = unsigned long; } class LIBSAMPLE_API OBJ { }; -using HANDLE = OBJ *; +using SAMPLE_HANDLE = OBJ *; class LIBSAMPLE_API HandleHolder { public: - explicit HandleHolder(HANDLE ptr = nullptr) : m_handle(ptr) {} - explicit HandleHolder(Foo::HANDLE val): m_handle2(val) {} + explicit HandleHolder(SAMPLE_HANDLE ptr = nullptr) : m_handle(ptr) {} + explicit HandleHolder(Foo::SAMPLE_HANDLE val): m_handle2(val) {} - inline void set(HANDLE ptr) { HANDLE tmp; tmp = m_handle; m_handle = tmp; } - inline void set(const Foo::HANDLE& val) { m_handle2 = val; } - inline HANDLE handle() { return m_handle; } - inline Foo::HANDLE handle2() { return m_handle2; } + void set(SAMPLE_HANDLE ptr); + inline void set(const Foo::SAMPLE_HANDLE &val) { m_handle2 = val; } + inline SAMPLE_HANDLE handle() const { return m_handle; } + inline Foo::SAMPLE_HANDLE handle2() const { return m_handle2; } - static HANDLE createHandle(); - bool compare(HandleHolder* other); - bool compare2(HandleHolder* other); + static SAMPLE_HANDLE createHandle(); + bool compare(HandleHolder *other); + bool compare2(HandleHolder *other); private: - HANDLE m_handle; - Foo::HANDLE m_handle2; + SAMPLE_HANDLE m_handle = nullptr; + Foo::SAMPLE_HANDLE m_handle2 = 0; }; +inline void HandleHolder::set(SAMPLE_HANDLE) +{ + SAMPLE_HANDLE tmp = m_handle; + m_handle = tmp; +} + struct LIBSAMPLE_API PrimitiveStruct {}; using PrimitiveStructPtr = struct PrimitiveStruct *; struct LIBSAMPLE_API PrimitiveStructPointerHolder diff --git a/sources/shiboken6/tests/libsample/implicitconv.cpp b/sources/shiboken6/tests/libsample/implicitconv.cpp index 88af0d936..887fa6b1c 100644 --- a/sources/shiboken6/tests/libsample/implicitconv.cpp +++ b/sources/shiboken6/tests/libsample/implicitconv.cpp @@ -1,66 +1,39 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "implicitconv.h" -ImplicitConv -ImplicitConv::implicitConvCommon(ImplicitConv implicit) +ImplicitConv::ImplicitConv(const Null &) : + m_ctorEnum(CtorPrimitiveType) +{ +} + +ImplicitConv ImplicitConv::implicitConvCommon(ImplicitConv implicit) { return implicit; } -ImplicitConv -ImplicitConv::implicitConvDefault(ImplicitConv implicit) +ImplicitConv ImplicitConv::implicitConvDefault(ImplicitConv implicit) { return implicit; } -ImplicitConv::ICOverloadedFuncEnum -ImplicitConv::implicitConvOverloading(ImplicitConv implicit, int dummyArg) +ImplicitConv::ICOverloadedFuncEnum ImplicitConv::implicitConvOverloading(ImplicitConv, int) { return ImplicitConv::OverFunc_Ii; } -ImplicitConv::ICOverloadedFuncEnum -ImplicitConv::implicitConvOverloading(ImplicitConv implicit, bool dummyArg) +ImplicitConv::ICOverloadedFuncEnum ImplicitConv::implicitConvOverloading(ImplicitConv, bool) { return ImplicitConv::OverFunc_Ib; } -ImplicitConv::ICOverloadedFuncEnum -ImplicitConv::implicitConvOverloading(int dummyArg) +ImplicitConv::ICOverloadedFuncEnum ImplicitConv::implicitConvOverloading(int) { return ImplicitConv::OverFunc_i; } -ImplicitConv::ICOverloadedFuncEnum -ImplicitConv::implicitConvOverloading(CtorEnum dummyArg) +ImplicitConv::ICOverloadedFuncEnum ImplicitConv::implicitConvOverloading(CtorEnum) { return ImplicitConv::OverFunc_C; } - diff --git a/sources/shiboken6/tests/libsample/implicitconv.h b/sources/shiboken6/tests/libsample/implicitconv.h index ea859a1a6..5d69eb487 100644 --- a/sources/shiboken6/tests/libsample/implicitconv.h +++ b/sources/shiboken6/tests/libsample/implicitconv.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef IMPLICITCONV_H #define IMPLICITCONV_H @@ -37,6 +12,8 @@ class ObjectType; class LIBSAMPLE_API ImplicitConv { public: + LIBMINIMAL_DEFAULT_COPY_MOVE(ImplicitConv) + enum CtorEnum { CtorNone, CtorOne, @@ -53,17 +30,17 @@ public: OverFunc_C }; - ImplicitConv() : m_ctorEnum(CtorNone), m_objId(-1), m_value(-1.0) {} - ImplicitConv(int objId) : m_ctorEnum(CtorOne), m_objId(objId), m_value(-1.0) {} - ImplicitConv(CtorEnum ctorEnum) : m_ctorEnum(ctorEnum), m_objId(-1), m_value(-1.0) {} - ImplicitConv(ObjectType&) : m_ctorEnum(CtorObjectTypeReference), m_objId(-1), m_value(-1.0) {} + ImplicitConv() noexcept = default; + ImplicitConv(int objId) noexcept : m_ctorEnum(CtorOne), m_objId(objId) {} + ImplicitConv(CtorEnum ctorEnum) : m_ctorEnum(ctorEnum) {} + ImplicitConv(ObjectType&) : m_ctorEnum(CtorObjectTypeReference) {} ImplicitConv(double value, bool=true) : m_ctorEnum(CtorNone), m_value(value) {} - ImplicitConv(const Null& null) : m_ctorEnum(CtorPrimitiveType) {} - ~ImplicitConv() {} + ImplicitConv(const Null &null); + ~ImplicitConv() = default; - inline CtorEnum ctorEnum() { return m_ctorEnum; } - inline int objId() { return m_objId; } - inline double value() { return m_value; } + inline CtorEnum ctorEnum() const { return m_ctorEnum; } + inline int objId() const { return m_objId; } + inline double value() const { return m_value; } static ImplicitConv implicitConvCommon(ImplicitConv implicit); @@ -75,9 +52,9 @@ public: static ICOverloadedFuncEnum implicitConvOverloading(CtorEnum dummyArg); private: - CtorEnum m_ctorEnum; - int m_objId; - double m_value; + CtorEnum m_ctorEnum = CtorNone; + int m_objId = -1; + double m_value = -1.0; }; #endif // IMPLICITCONV_H diff --git a/sources/shiboken6/tests/libsample/injectcode.cpp b/sources/shiboken6/tests/libsample/injectcode.cpp index b1cf2d26b..707d14ed8 100644 --- a/sources/shiboken6/tests/libsample/injectcode.cpp +++ b/sources/shiboken6/tests/libsample/injectcode.cpp @@ -1,46 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "injectcode.h" -#include <sstream> -using namespace std; +#include <sstream> -InjectCode::InjectCode() -{ -} +InjectCode::InjectCode() noexcept = default; -InjectCode::~InjectCode() -{ -} +InjectCode::~InjectCode() = default; template<typename T> -const char* InjectCode::toStr(const T& value) +const char *InjectCode::toStr(const T &value) { std::ostringstream s; s << value; @@ -48,41 +18,41 @@ const char* InjectCode::toStr(const T& value) return m_valueHolder.c_str(); } -const char* InjectCode::simpleMethod1(int arg0, int arg1) +const char *InjectCode::simpleMethod1(int arg0, int arg1) { return toStr(arg0 + arg1); } -const char* InjectCode::simpleMethod2() +const char *InjectCode::simpleMethod2() { return "_"; } -const char* InjectCode::simpleMethod3(int argc, char** argv) +const char *InjectCode::simpleMethod3(int argc, char **argv) { for (int i = 0; i < argc; ++i) m_valueHolder += argv[i]; return m_valueHolder.c_str(); } -const char* InjectCode::overloadedMethod(int arg0, bool arg1) +const char *InjectCode::overloadedMethod(int arg0, bool arg1) { toStr(arg0); m_valueHolder += arg1 ? "true" : "false"; return m_valueHolder.c_str(); } -const char* InjectCode::overloadedMethod(int arg0, double arg1) +const char *InjectCode::overloadedMethod(int arg0, double arg1) { return toStr(arg0 + arg1); } -const char* InjectCode::overloadedMethod(int argc, char** argv) +const char *InjectCode::overloadedMethod(int argc, char **argv) { return simpleMethod3(argc, argv); } -const char* InjectCode::virtualMethod(int arg) +const char *InjectCode::virtualMethod(int arg) { return toStr(arg); } @@ -95,13 +65,13 @@ int InjectCode::arrayMethod(int count, int *values) const return ret; } -int InjectCode::sumArrayAndLength(int* values) const +int InjectCode::sumArrayAndLength(int *values) const { int sum = 0; - while(*values) { + while (*values) { sum = sum + *values + 1; - values++; + ++values; } return sum; diff --git a/sources/shiboken6/tests/libsample/injectcode.h b/sources/shiboken6/tests/libsample/injectcode.h index 927721f8f..74046dad5 100644 --- a/sources/shiboken6/tests/libsample/injectcode.h +++ b/sources/shiboken6/tests/libsample/injectcode.h @@ -1,56 +1,35 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef INJECTCODE_H #define INJECTCODE_H #include "libsamplemacros.h" + #include <utility> #include <string> class LIBSAMPLE_API InjectCode { public: - InjectCode(); + LIBMINIMAL_DEFAULT_COPY_MOVE(InjectCode) + + InjectCode() noexcept; virtual ~InjectCode(); - const char* simpleMethod1(int arg0, int arg1); - const char* simpleMethod2(); - const char* simpleMethod3(int argc, char** argv); + const char *simpleMethod1(int arg0, int arg1); + const char *simpleMethod2(); + const char *simpleMethod3(int argc, char **argv); - const char* overloadedMethod(int argc, char** argv); - const char* overloadedMethod(int arg0, double arg1); - const char* overloadedMethod(int arg0, bool arg1); + const char *overloadedMethod(int argc, char **argv); + const char *overloadedMethod(int arg0, double arg1); + const char *overloadedMethod(int arg0, bool arg1); - virtual int arrayMethod(int count, int* values) const; + virtual int arrayMethod(int count, int *values) const; inline int callArrayMethod(int count, int *values) const { return arrayMethod(count, values); } - virtual const char* virtualMethod(int arg); - int sumArrayAndLength(int* values) const; + virtual const char *virtualMethod(int arg); + int sumArrayAndLength(int *values) const; + private: // This attr is just to retain the memory pointed by all return values, // So, the memory returned by all methods will be valid until someone call @@ -58,7 +37,7 @@ private: std::string m_valueHolder; template<typename T> - const char* toStr(const T& value); + const char *toStr(const T &value); }; #endif // INJECTCODE_H diff --git a/sources/shiboken6/tests/libsample/intwrapper.cpp b/sources/shiboken6/tests/libsample/intwrapper.cpp index aa1a22874..0eaf30465 100644 --- a/sources/shiboken6/tests/libsample/intwrapper.cpp +++ b/sources/shiboken6/tests/libsample/intwrapper.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "intwrapper.h" diff --git a/sources/shiboken6/tests/libsample/intwrapper.h b/sources/shiboken6/tests/libsample/intwrapper.h index 158cff8e1..cfda5adc7 100644 --- a/sources/shiboken6/tests/libsample/intwrapper.h +++ b/sources/shiboken6/tests/libsample/intwrapper.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef INTWRAPPER_H #define INTWRAPPER_H diff --git a/sources/shiboken6/tests/libsample/libsamplemacros.h b/sources/shiboken6/tests/libsample/libsamplemacros.h index e85b0fd5b..93e549bfb 100644 --- a/sources/shiboken6/tests/libsample/libsamplemacros.h +++ b/sources/shiboken6/tests/libsample/libsamplemacros.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef LIBSAMPLEMACROS_H #define LIBSAMPLEMACROS_H diff --git a/sources/shiboken6/tests/libsample/list.h b/sources/shiboken6/tests/libsample/list.h index f4970d947..5e06d2a66 100644 --- a/sources/shiboken6/tests/libsample/list.h +++ b/sources/shiboken6/tests/libsample/list.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef LIST_H #define LIST_H @@ -43,6 +18,8 @@ class List : public std::list<T> class IntList : public List<int> { public: + LIBMINIMAL_DEFAULT_MOVE(IntList) + enum CtorEnum { NoParamsCtor, IntCtor, @@ -50,10 +27,13 @@ public: ListOfIntCtor }; - inline IntList() : m_ctorUsed(NoParamsCtor) {} + inline IntList() noexcept : m_ctorUsed(NoParamsCtor) {} inline explicit IntList(int val) : m_ctorUsed(IntCtor) { push_back(val); } - inline IntList(const IntList& lst) : List<int>(lst), m_ctorUsed(CopyCtor) {} - inline IntList(const List<int>& lst) : List<int>(lst), m_ctorUsed(ListOfIntCtor) {} + inline IntList(const List<int> &lst) : List<int>(lst), m_ctorUsed(ListOfIntCtor) {} + ~IntList() = default; + + inline IntList(const IntList &lst) : List<int>(lst), m_ctorUsed(CopyCtor) {} + IntList &operator=(const IntList &) = default; inline void append(int v) { insert(end(), v); } CtorEnum constructorUsed() { return m_ctorUsed; } @@ -64,6 +44,8 @@ private: class PointValueList : public List<Point> { public: + LIBMINIMAL_DEFAULT_MOVE(PointValueList) + enum CtorEnum { NoParamsCtor, PointCtor, @@ -71,10 +53,13 @@ public: ListOfPointValuesCtor }; - inline PointValueList() : m_ctorUsed(NoParamsCtor) {} + inline PointValueList() noexcept : m_ctorUsed(NoParamsCtor) {} inline explicit PointValueList(Point val) : m_ctorUsed(PointCtor) { push_back(val); } - inline PointValueList(const PointValueList& lst) : List<Point>(lst), m_ctorUsed(CopyCtor) {} - inline PointValueList(const List<Point>& lst) : List<Point>(lst), m_ctorUsed(ListOfPointValuesCtor) {} + inline PointValueList(const List<Point> &lst) : List<Point>(lst), m_ctorUsed(ListOfPointValuesCtor) {} + + inline PointValueList(const PointValueList &lst) : List<Point>(lst), m_ctorUsed(CopyCtor) {} + PointValueList &operator=(const PointValueList &) = default; + ~PointValueList() = default; inline void append(Point v) { insert(end(), v); } CtorEnum constructorUsed() { return m_ctorUsed; } @@ -85,6 +70,8 @@ private: class ObjectTypePtrList : public List<ObjectType*> { public: + LIBMINIMAL_DEFAULT_MOVE(ObjectTypePtrList) + enum CtorEnum { NoParamsCtor, ObjectTypeCtor, @@ -92,15 +79,21 @@ public: ListOfObjectTypePtrCtor }; - inline ObjectTypePtrList() : m_ctorUsed(NoParamsCtor) {} - inline explicit ObjectTypePtrList(ObjectType* val) : m_ctorUsed(ObjectTypeCtor) { push_back(val); } - inline ObjectTypePtrList(const ObjectTypePtrList& lst) : List<ObjectType*>(lst), m_ctorUsed(CopyCtor) {} - inline ObjectTypePtrList(const List<ObjectType*>& lst) : List<ObjectType*>(lst), m_ctorUsed(ListOfObjectTypePtrCtor) {} + inline ObjectTypePtrList() = default; + inline ObjectTypePtrList(const ObjectTypePtrList &lst) : + List<ObjectType*>(lst), m_ctorUsed(CopyCtor) {} + inline explicit ObjectTypePtrList(ObjectType *val) : + m_ctorUsed(ObjectTypeCtor) { push_back(val); } + inline ObjectTypePtrList(const List<ObjectType*> &lst) : + List<ObjectType*>(lst), m_ctorUsed(ListOfObjectTypePtrCtor) {} + ~ObjectTypePtrList() = default; + + ObjectTypePtrList &operator=(const ObjectTypePtrList &) = default; - inline void append(ObjectType* v) { insert(end(), v); } + inline void append(ObjectType *v) { insert(end(), v); } CtorEnum constructorUsed() { return m_ctorUsed; } private: - CtorEnum m_ctorUsed; + CtorEnum m_ctorUsed = NoParamsCtor; }; #endif // LIST_H diff --git a/sources/shiboken6/tests/libsample/listuser.cpp b/sources/shiboken6/tests/libsample/listuser.cpp index 995220b6f..9bb7f7798 100644 --- a/sources/shiboken6/tests/libsample/listuser.cpp +++ b/sources/shiboken6/tests/libsample/listuser.cpp @@ -1,45 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <numeric> -#include <cstdlib> #include "listuser.h" -using namespace std; +#include <numeric> +#include <cstdlib> -std::list<int> -ListUser::callCreateList() +std::list<int> ListUser::callCreateList() { return createList(); } -std::list<int> -ListUser::createList() +ListUser::ListUser() = default; +ListUser::ListUser(const ListUser &other) = default; +ListUser::ListUser(ListUser &&other) noexcept = default; +ListUser &ListUser::operator=(const ListUser &other) = default; +ListUser &ListUser::operator=(ListUser &&other) noexcept = default; +ListUser::~ListUser() = default; + +std::list<int> ListUser::createList() { std::list<int> retval; for (int i = 0; i < 4; i++) @@ -47,8 +26,7 @@ ListUser::createList() return retval; } -std::list<Complex> -ListUser::createComplexList(Complex cpx0, Complex cpx1) +std::list<Complex> ListUser::createComplexList(Complex cpx0, Complex cpx1) { std::list<Complex> retval; retval.push_back(cpx0); @@ -56,36 +34,30 @@ ListUser::createComplexList(Complex cpx0, Complex cpx1) return retval; } -double -ListUser::sumList(std::list<int> vallist) +double ListUser::sumList(std::list<int> vallist) { return std::accumulate(vallist.begin(), vallist.end(), 0.0); } -double -ListUser::sumList(std::list<double> vallist) +double ListUser::sumList(std::list<double> vallist) { return std::accumulate(vallist.begin(), vallist.end(), 0.0); } -ListUser::ListOfSomething -ListUser::listOfPoints(const std::list<Point>& pointlist) +ListUser::ListOfSomething ListUser::listOfPoints(const std::list<Point> &) { return ListOfPoint; } -ListUser::ListOfSomething -ListUser::listOfPoints(const std::list<PointF>& pointlist) +ListUser::ListOfSomething ListUser::listOfPoints(const std::list<PointF> &) { return ListOfPointF; } -void -ListUser::multiplyPointList(PointList& points, double multiplier) +void ListUser::multiplyPointList(PointList &points, double multiplier) { for (auto *point : points) { point->setX(point->x() * multiplier); point->setY(point->y() * multiplier); } } - diff --git a/sources/shiboken6/tests/libsample/listuser.h b/sources/shiboken6/tests/libsample/listuser.h index 7e67039d9..96781ed16 100644 --- a/sources/shiboken6/tests/libsample/listuser.h +++ b/sources/shiboken6/tests/libsample/listuser.h @@ -1,41 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef LISTUSER_H #define LISTUSER_H -#include <list> #include "complex.h" #include "point.h" #include "pointf.h" #include "libsamplemacros.h" +#include <list> + class LIBSAMPLE_API ListUser { public: @@ -46,9 +22,12 @@ public: ListOfPointF }; - ListUser() {} - ListUser(const ListUser& other) : m_lst(other.m_lst) {} - virtual ~ListUser() {} + ListUser(); + ListUser(const ListUser &other); + ListUser(ListUser &&other) noexcept; + ListUser &operator=(const ListUser &other); + ListUser &operator=(ListUser &&other) noexcept; + virtual ~ListUser(); virtual std::list<int> createList(); std::list<int> callCreateList(); @@ -58,13 +37,13 @@ public: double sumList(std::list<int> vallist); double sumList(std::list<double> vallist); - static ListOfSomething listOfPoints(const std::list<Point>& pointlist); - static ListOfSomething listOfPoints(const std::list<PointF>& pointlist); + static ListOfSomething listOfPoints(const std::list<Point> &pointlist); + static ListOfSomething listOfPoints(const std::list<PointF> &pointlist); - static void multiplyPointList(PointList& points, double multiplier); + static void multiplyPointList(PointList &points, double multiplier); inline void setList(std::list<int> lst) { m_lst = lst; } - inline std::list<int> getList() { return m_lst; } + inline std::list<int> getList() const { return m_lst; } private: std::list<int> m_lst; diff --git a/sources/shiboken6/tests/libsample/main.cpp b/sources/shiboken6/tests/libsample/main.cpp index 336551ea2..1b44642ae 100644 --- a/sources/shiboken6/tests/libsample/main.cpp +++ b/sources/shiboken6/tests/libsample/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include <iostream> #include <list> @@ -37,207 +12,197 @@ #include "listuser.h" #include "samplenamespace.h" -using namespace std; - int main(int argv, char **argc) { - cout << endl; + std::cout << std::endl; Derived derived; - cout << endl; + std::cout << std::endl; derived.unpureVirtual(); derived.pureVirtual(); derived.callPureVirtual(); - cout << endl; - Abstract* abs; - abs = Abstract::createObject(); - cout << "Abstract::createObject(): " << abs << endl << endl; + std::cout << std::endl; + auto *abs = Abstract::createObject(); + std::cout << "Abstract::createObject(): " << abs << std::endl << std::endl; delete abs; abs = Derived::createObject(); - cout << "Derived::createObject() : "; + std::cout << "Derived::createObject() : "; abs->show(); - cout << endl; + std::cout << std::endl; delete abs; - cout << endl; + std::cout << std::endl; abs = Derived::createObject(); - cout << "Derived::createObject() : "; + std::cout << "Derived::createObject() : "; abs->show(); - cout << endl; + std::cout << std::endl; delete abs; - cout << endl; + std::cout << std::endl; - cout << endl << "-----------------------------------------" << endl; + std::cout << "\n-----------------------------------------\n"; KinderGarten kg; - Derived* d[] = { 0, 0, 0 }; + Derived *d[] = { 0, 0, 0 }; for (int i = 0; i < 3; i++) { d[i] = new Derived(i); d[i]->show(); - cout << endl; + std::cout << std::endl; kg.addChild(d[i]); } kg.show(); - cout << endl; + std::cout << std::endl; - cout << endl << "* kill child "; + std::cout << "\n* kill child "; d[2]->show(); - cout << " ----------------" << endl; + std::cout << " ----------------\n"; kg.killChild(d[2]); kg.show(); - cout << endl; + std::cout << std::endl; - cout << endl << "* release child "; + std::cout << "\n* release child "; d[1]->show(); - cout << " -------------" << endl; - Abstract* released = kg.releaseChild(d[1]); - cout << "released: "; + std::cout << " -------------\n"; + Abstract *released = kg.releaseChild(d[1]); + std::cout << "released: "; released->show(); - cout << endl; + std::cout << std::endl; kg.show(); - cout << endl; - - cout << endl << "* kill children ------------------------------------" << endl; + std::cout << "\n\n* kill children ------------------------------------\n"; kg.killChildren(); kg.show(); - cout << endl << endl; - - cout << "-----------------------------------------" << endl; + std::cout << "\n\n-----------------------------------------\n"; ListUser lu; - cout << "ListUser::createList()" << endl; + std::cout << "ListUser::createList()\n"; std::list<int> intlist = lu.createList(); - for (std::list<int>::iterator it = intlist.begin(); it != intlist.end(); it++) { - cout << "* " << *it << endl; - } + for (std::list<int>::iterator it = intlist.begin(); it != intlist.end(); it++) + std::cout << "* " << *it << std::endl; - cout << "ListUser::createComplexList" << endl; + std::cout << "ListUser::createComplexList\n"; std::list<Complex> cpxlist = ListUser::createComplexList(Complex(1.1, 2.2), Complex(3.3, 4.4)); for (std::list<Complex>::iterator it = cpxlist.begin(); it != cpxlist.end(); it++) { - cout << "* "; + std::cout << "* "; (*it).show(); - cout << endl; + std::cout << std::endl; } - cout << endl; - - cout << "-----------------------------------------" << endl; - cout << "SampleNamespace" << endl; - - cout << "SampleNamespace::RandomNumber: "; - cout << SampleNamespace::getNumber(SampleNamespace::RandomNumber); - cout << endl; - cout << "SampleNamespace::UnixTime: "; - cout << SampleNamespace::getNumber(SampleNamespace::UnixTime); - cout << endl; + std::cout << "\n-----------------------------------------\n" + << "SampleNamespace\n"; + + std::cout << "SampleNamespace::RandomNumber: "; + std::cout << SampleNamespace::getNumber(SampleNamespace::RandomNumber); + std::cout << std::endl; + std::cout << "SampleNamespace::UnixTime: "; + std::cout << SampleNamespace::getNumber(SampleNamespace::UnixTime); + std::cout << std::endl; double val_d = 1.3; - cout << "SampleNamespace::powerOfTwo(" << val_d << "): "; - cout << SampleNamespace::powerOfTwo(val_d) << endl; + std::cout << "SampleNamespace::powerOfTwo(" << val_d << "): "; + std::cout << SampleNamespace::powerOfTwo(val_d) << std::endl; int val_i = 7; - cout << "SampleNamespace::powerOfTwo(" << val_i << "): "; - cout << SampleNamespace::powerOfTwo(val_i) << endl; - cout << endl; + std::cout << "SampleNamespace::powerOfTwo(" << val_i << "): "; + std::cout << SampleNamespace::powerOfTwo(val_i) << std::endl; + std::cout << std::endl; - cout << "-----------------------------------------" << endl; - cout << "Point" << endl; + std::cout << "-----------------------------------------" << std::endl; + std::cout << "Point" << std::endl; Point p1(1.1, 2.2); - cout << "p1: "; + std::cout << "p1: "; p1.show(); - cout << endl; + std::cout << std::endl; Point p2(3.4, 5.6); - cout << "p2: "; + std::cout << "p2: "; p2.show(); - cout << endl; + std::cout << std::endl; - cout << "p1 + p2 == "; + std::cout << "p1 + p2 == "; (p1 + p2).show(); - cout << endl; + std::cout << std::endl; - cout << "p1 * 2.0 == "; + std::cout << "p1 * 2.0 == "; (p1 * 2.0).show(); - cout << endl; + std::cout << std::endl; - cout << "1.5 * p2 == "; + std::cout << "1.5 * p2 == "; (1.5 * p2).show(); - cout << endl; + std::cout << std::endl; - cout << "p1: "; + std::cout << "p1: "; p1.show(); - cout << endl << "p2: "; + std::cout << std::endl << "p2: "; p2.show(); - cout << endl << "p1 += p2" << endl; + std::cout << std::endl << "p1 += p2" << std::endl; p1 += p2; - cout << "p1: "; + std::cout << "p1: "; p1.show(); - cout << endl; + std::cout << std::endl; - cout << "p1 == p2 ? " << ((p1 == p2) ? "true" : "false") << endl; - cout << "p1 == p1 ? " << ((p1 == p1) ? "true" : "false") << endl; - cout << "p2 == p2 ? " << ((p2 == p2) ? "true" : "false") << endl; + std::cout << "p1 == p2 ? " << ((p1 == p2) ? "true" : "false") << std::endl; + std::cout << "p1 == p1 ? " << ((p1 == p1) ? "true" : "false") << std::endl; + std::cout << "p2 == p2 ? " << ((p2 == p2) ? "true" : "false") << std::endl; - cout << "-----------------------------------------" << endl; - cout << "Size" << endl; + std::cout << "-----------------------------------------" << std::endl; + std::cout << "Size" << std::endl; Size s1(2, 2); - cout << "s1: "; + std::cout << "s1: "; s1.show(); - cout << ", area: " << s1.calculateArea(); - cout << endl; + std::cout << ", area: " << s1.calculateArea(); + std::cout << std::endl; Size s2(3, 5); - cout << "s2: "; + std::cout << "s2: "; s2.show(); - cout << ", area: " << s2.calculateArea(); - cout << endl; - - cout << endl; - - cout << "s1 == s2 ? " << ((s1 == s2) ? "true" : "false") << endl; - cout << "s1 != s2 ? " << ((s1 != s2) ? "true" : "false") << endl; - - cout << "s1 < s2 ? " << ((s1 < s2) ? "true" : "false") << endl; - cout << "s1 <= s2 ? " << ((s1 <= s2) ? "true" : "false") << endl; - cout << "s1 > s2 ? " << ((s1 > s2) ? "true" : "false") << endl; - cout << "s1 >= s2 ? " << ((s1 >= s2) ? "true" : "false") << endl; - - cout << "s1 < 10 ? " << ((s1 < 10) ? "true" : "false") << endl; - cout << "s1 <= 10 ? " << ((s1 <= 10) ? "true" : "false") << endl; - cout << "s1 > 10 ? " << ((s1 > 10) ? "true" : "false") << endl; - cout << "s1 >= 10 ? " << ((s1 >= 10) ? "true" : "false") << endl; - cout << "s2 < 10 ? " << ((s2 < 10) ? "true" : "false") << endl; - cout << "s2 <= 10 ? " << ((s2 <= 10) ? "true" : "false") << endl; - cout << "s2 > 10 ? " << ((s2 > 10) ? "true" : "false") << endl; - cout << "s2 >= 10 ? " << ((s2 >= 10) ? "true" : "false") << endl; - cout << endl; - - cout << "s1: "; + std::cout << ", area: " << s2.calculateArea(); + std::cout << std::endl; + + std::cout << std::endl; + + std::cout << "s1 == s2 ? " << ((s1 == s2) ? "true" : "false") << std::endl; + std::cout << "s1 != s2 ? " << ((s1 != s2) ? "true" : "false") << std::endl; + + std::cout << "s1 < s2 ? " << ((s1 < s2) ? "true" : "false") << std::endl; + std::cout << "s1 <= s2 ? " << ((s1 <= s2) ? "true" : "false") << std::endl; + std::cout << "s1 > s2 ? " << ((s1 > s2) ? "true" : "false") << std::endl; + std::cout << "s1 >= s2 ? " << ((s1 >= s2) ? "true" : "false") << std::endl; + + std::cout << "s1 < 10 ? " << ((s1 < 10) ? "true" : "false") << std::endl; + std::cout << "s1 <= 10 ? " << ((s1 <= 10) ? "true" : "false") << std::endl; + std::cout << "s1 > 10 ? " << ((s1 > 10) ? "true" : "false") << std::endl; + std::cout << "s1 >= 10 ? " << ((s1 >= 10) ? "true" : "false") << std::endl; + std::cout << "s2 < 10 ? " << ((s2 < 10) ? "true" : "false") << std::endl; + std::cout << "s2 <= 10 ? " << ((s2 <= 10) ? "true" : "false") << std::endl; + std::cout << "s2 > 10 ? " << ((s2 > 10) ? "true" : "false") << std::endl; + std::cout << "s2 >= 10 ? " << ((s2 >= 10) ? "true" : "false") << std::endl; + std::cout << std::endl; + + std::cout << "s1: "; s1.show(); - cout << endl << "s2: "; + std::cout << std::endl << "s2: "; s2.show(); - cout << endl << "s1 += s2" << endl; + std::cout << std::endl << "s1 += s2" << std::endl; s1 += s2; - cout << "s1: "; + std::cout << "s1: "; s1.show(); - cout << endl; + std::cout << std::endl; - cout << endl; + std::cout << std::endl; - cout << "s1: "; + std::cout << "s1: "; s1.show(); - cout << endl << "s1 *= 2.0" << endl; + std::cout << std::endl << "s1 *= 2.0" << std::endl; s1 *= 2.0; - cout << "s1: "; + std::cout << "s1: "; s1.show(); - cout << endl; + std::cout << std::endl; - cout << endl; + std::cout << std::endl; return 0; } diff --git a/sources/shiboken6/tests/libsample/mapuser.cpp b/sources/shiboken6/tests/libsample/mapuser.cpp index e2a0f7181..40059bbcd 100644 --- a/sources/shiboken6/tests/libsample/mapuser.cpp +++ b/sources/shiboken6/tests/libsample/mapuser.cpp @@ -1,69 +1,44 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "mapuser.h" -using namespace std; +#include <iostream> -std::map<std::string, std::pair<Complex, int> > -MapUser::callCreateMap() +std::map<std::string, std::pair<Complex, int> > MapUser::callCreateMap() { return createMap(); } - -std::map<std::string, std::pair<Complex, int> > -MapUser::createMap() +std::map<std::string, std::pair<Complex, int> > MapUser::createMap() { std::map<std::string, std::pair<Complex, int> > retval; - std::pair<std::string, std::pair<Complex, int> > - item0("zero", std::pair<Complex, int>(Complex(1.2, 3.4), 2)); - retval.insert(item0); + std::pair<Complex, int> value{Complex(1.2, 3.4), 2}; + retval.insert({"zero", value}); - std::pair<std::string, std::pair<Complex, int> > - item1("one", std::pair<Complex, int>(Complex(5.6, 7.8), 3)); - retval.insert(item1); + value = {Complex(5.6, 7.8), 3}; + retval.insert({"one", value}); - std::pair<std::string, std::pair<Complex, int> > - item2("two", std::pair<Complex, int>(Complex(9.1, 2.3), 5)); - retval.insert(item2); + value = {Complex(9.1, 2.3), 5}; + retval.insert({"two", value}); return retval; } -void -MapUser::showMap(std::map<std::string, int> mapping) +void MapUser::showMap(std::map<std::string, int> mapping) +{ + std::cout << __FUNCTION__ << std::endl; + for (const auto &p : mapping) + std::cout << p.first << " => " << p.second << std::endl; +} + +void MapUser::pointerToMap(std::map<std::string, std::string> *) +{ +} + +void MapUser::referenceToMap(std::map<std::string, std::string> &) { - cout << __FUNCTION__ << endl; - for (auto it = mapping.begin(), end = mapping.end(); it != end; ++it) - cout << (*it).first << " => " << (*it).second << endl; } std::map<int, std::list<std::list<double> > > MapUser::foo() const diff --git a/sources/shiboken6/tests/libsample/mapuser.h b/sources/shiboken6/tests/libsample/mapuser.h index ad434b957..1677a4bfb 100644 --- a/sources/shiboken6/tests/libsample/mapuser.h +++ b/sources/shiboken6/tests/libsample/mapuser.h @@ -1,48 +1,26 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MAPUSER_H #define MAPUSER_H +#include "libsamplemacros.h" + +#include "complex.h" +#include "bytearray.h" + #include <map> #include <list> #include <utility> #include <string> -#include "complex.h" -#include "bytearray.h" - -#include "libsamplemacros.h" class LIBSAMPLE_API MapUser { public: - MapUser() {} - virtual ~MapUser() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(MapUser) + + MapUser() noexcept = default; + virtual ~MapUser() = default; virtual std::map<std::string, std::pair<Complex, int> > createMap(); std::map<std::string, std::pair<Complex, int> > callCreateMap(); @@ -53,10 +31,10 @@ public: inline std::map<std::string, std::list<int> > getMap() { return m_map; } // Compile test - static void pointerToMap(std::map<std::string, std::string>* arg) {} - static void referenceToMap(std::map<std::string, std::string>& arg) {} + static void pointerToMap(std::map<std::string, std::string> *arg); + static void referenceToMap(std::map<std::string, std::string> &arg); - inline const std::map<int, ByteArray>& passMapIntValueType(const std::map<int, ByteArray>& arg) { return arg; } + inline const std::map<int, ByteArray> &passMapIntValueType(const std::map<int, ByteArray>& arg) { return arg; } std::map<int, std::list<std::list<double> > > foo() const; diff --git a/sources/shiboken6/tests/libsample/modelindex.h b/sources/shiboken6/tests/libsample/modelindex.h index dd3ddc089..48e1b7de3 100644 --- a/sources/shiboken6/tests/libsample/modelindex.h +++ b/sources/shiboken6/tests/libsample/modelindex.h @@ -1,57 +1,33 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MODELINDEX_H #define MODELINDEX_H -#include "libsamplemacros.h" - class ModelIndex { public: - ModelIndex() : m_value(0) {} - ModelIndex(const ModelIndex& other) { m_value = other.m_value; } + ModelIndex() = default; + inline void setValue(int value) { m_value = value; } inline int value() const { return m_value; } - static int getValue(const ModelIndex& index) { return index.value(); } + static int getValue(const ModelIndex &index) { return index.value(); } + private: - int m_value; + int m_value = 0; }; class ReferentModelIndex { public: - ReferentModelIndex() {} - ReferentModelIndex(const ModelIndex& index) : m_index(index) {} - ReferentModelIndex(const ReferentModelIndex& other) { m_index = other.m_index; } + ReferentModelIndex() = default; + + explicit ReferentModelIndex(const ModelIndex &index) : m_index(index) {} + inline void setValue(int value) { m_index.setValue(value); } inline int value() const { return m_index.value(); } operator const ModelIndex&() const { return m_index; } + private: ModelIndex m_index; }; @@ -59,14 +35,16 @@ private: class PersistentModelIndex { public: - PersistentModelIndex() {} - PersistentModelIndex(const ModelIndex& index) : m_index(index) {} - PersistentModelIndex(const PersistentModelIndex& other) { m_index = other.m_index; } + PersistentModelIndex() = default; + + explicit PersistentModelIndex(const ModelIndex &index) : m_index(index) {} + inline void setValue(int value) { m_index.setValue(value); } inline int value() const { return m_index.value(); } operator ModelIndex() const { return m_index; } + private: ModelIndex m_index; }; -#endif +#endif // MODELINDEX_H diff --git a/sources/shiboken6/tests/libsample/modifications.cpp b/sources/shiboken6/tests/libsample/modifications.cpp index 627d17b45..6d627c4c1 100644 --- a/sources/shiboken6/tests/libsample/modifications.cpp +++ b/sources/shiboken6/tests/libsample/modifications.cpp @@ -1,40 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "modifications.h" #include "objecttype.h" -using namespace std; +#include <iostream> Modifications::Modifications() + : m_object(new ObjectType()) { - m_object = new ObjectType(); m_object->setObjectName("MyObject"); } @@ -43,30 +17,87 @@ Modifications::~Modifications() delete m_object; } -std::pair<double, double> -Modifications::pointToPair(Point pt, bool* ok) +Modifications::OverloadedModFunc Modifications::overloaded(int, bool, Point, Point) +{ + return Overloaded_ibPP; +} + +Modifications::OverloadedModFunc Modifications::overloaded(int, bool, int, int) +{ + return Overloaded_ibii; +} + +Modifications::OverloadedModFunc Modifications::overloaded(int, bool, int, Point) +{ + return Overloaded_ibiP; +} + +Modifications::OverloadedModFunc Modifications::overloaded(int, bool, int, bool) +{ + return Overloaded_ibib; +} + +Modifications::OverloadedModFunc Modifications::overloaded(int, bool, int, double) +{ + return Overloaded_ibid; +} + +void Modifications::argRemoval0(int, bool, int, int) +{ +} + +void Modifications::argRemoval0(int, bool, int, bool) +{ +} + +void Modifications::argRemoval1(int, bool, Point, Point, int) +{ +} + +void Modifications::argRemoval1(int, bool, int, bool) +{ +} + +void Modifications::argRemoval2(int, bool, Point, Point, int) +{ +} + +void Modifications::argRemoval3(int, Point, bool, Point, int) +{ +} + +void Modifications::argRemoval4(int, Point, bool, Point, int) +{ +} + +void Modifications::argRemoval5(int, bool, Point, Point, int) +{ +} + +void Modifications::argRemoval5(int, bool, int, bool) +{ +} + +std::pair<double, double> Modifications::pointToPair(Point pt, bool *ok) { std::pair<double, double> retval(pt.x(), pt.y()); *ok = true; return retval; } -double -Modifications::multiplyPointCoordsPlusValue(bool* ok, Point pt, double value) +double Modifications::multiplyPointCoordsPlusValue(bool *ok, Point pt, double value) { double retval = (pt.x() * pt.y()) + value; *ok = true; return retval; } -int -Modifications::doublePlus(int value, int plus) +int Modifications::doublePlus(int value, int plus) { return (2 * value) + plus; } -int -Modifications::power(int base, int exponent) +int Modifications::power(int base, int exponent) { if (exponent == 0) return 1; @@ -76,38 +107,32 @@ Modifications::power(int base, int exponent) return retval; } -int -Modifications::timesTen(int number) +int Modifications::timesTen(int number) { return number * 10; } -int -Modifications::increment(int number) +int Modifications::increment(int number) { return ++number; } -void -Modifications::exclusiveCppStuff() +void Modifications::exclusiveCppStuff() { - cout << __FUNCTION__ << endl; + std::cout << __FUNCTION__ << std::endl; } -int -Modifications::cppMultiply(int a, int b) +int Modifications::cppMultiply(int a, int b) { return a * b; } -const char* -Modifications::className() +const char *Modifications::className() { return "Modifications"; } -Point -Modifications::sumPointArray(int arraySize, const Point pointArray[]) +Point Modifications::sumPointArray(int arraySize, const Point pointArray[]) { Point point; for (int i = 0; i < arraySize; ++i) @@ -115,21 +140,18 @@ Modifications::sumPointArray(int arraySize, const Point pointArray[]) return point; } -int -Modifications::getSize(const void* data, int size) +int Modifications::getSize(const void *data, int size) { (void)data; return size; } -int -Modifications::sumPointCoordinates(const Point* point) +int Modifications::sumPointCoordinates(const Point *point) { return point->x() + point->y(); } -double -Modifications::differenceOfPointCoordinates(const Point* pt, bool* ok) +double Modifications::differenceOfPointCoordinates(const Point *pt, bool *ok) { if (!pt) { *ok = false; @@ -142,8 +164,7 @@ Modifications::differenceOfPointCoordinates(const Point* pt, bool* ok) return result; } -bool -Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object) +bool Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType **object) { if (object) *object = m_object; diff --git a/sources/shiboken6/tests/libsample/modifications.h b/sources/shiboken6/tests/libsample/modifications.h index 888c66d18..5bd1bac47 100644 --- a/sources/shiboken6/tests/libsample/modifications.h +++ b/sources/shiboken6/tests/libsample/modifications.h @@ -1,44 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MODIFICATIONS_H #define MODIFICATIONS_H #include "libsamplemacros.h" -#include <utility> #include "point.h" #include "oddbool.h" +#include <utility> + class ObjectType; class LIBSAMPLE_API Modifications { public: + LIBMINIMAL_DISABLE_COPY_MOVE(Modifications) + Modifications(); virtual ~Modifications(); @@ -58,34 +36,38 @@ public: // those overloaded methods should be heavily modified // to push the overload decisor to its limits - inline OverloadedModFunc overloaded(int a0, bool b0, int c0, double d0) { return Overloaded_ibid; } - inline OverloadedModFunc overloaded(int a1, bool b1, int c1, bool d1) { return Overloaded_ibib; } - inline OverloadedModFunc overloaded(int a2, bool b2, int c2, Point d2) { return Overloaded_ibiP; } - inline OverloadedModFunc overloaded(int a3, bool b3, int c3 = 123, int d3 = 456) { return Overloaded_ibii; } - inline OverloadedModFunc overloaded(int a4, bool b4, Point c4, Point d4) { return Overloaded_ibPP; } + OverloadedModFunc overloaded(int a0, bool b0, int c0, double d0); + OverloadedModFunc overloaded(int a1, bool b1, int c1, bool d1); + OverloadedModFunc overloaded(int a2, bool b2, int c2, Point d2); + OverloadedModFunc overloaded(int a3, bool b3, int c3 = 123, int d3 = 456); + OverloadedModFunc overloaded(int a4, bool b4, Point c4, Point d4); - inline void argRemoval0(int a0, bool a1, int a2 = 123, int a3 = 456) {} - inline void argRemoval0(int a0, bool a1, int a2, bool a3) {} + void argRemoval0(int a0, bool a1, int a2 = 123, int a3 = 456); + void argRemoval0(int a0, bool a1, int a2, bool a3); - inline void argRemoval1(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), int a4 = 333) {} - inline void argRemoval1(int a0, bool a1, int a2, bool a3) {} + void argRemoval1(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), + int a4 = 333); + void argRemoval1(int a0, bool a1, int a2, bool a3); - inline void argRemoval2(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), int a4 = 333) {} + void argRemoval2(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), + int a4 = 333); - inline void argRemoval3(int a0, Point a1 = Point(1, 2), bool a2 = true, Point a3 = Point(3, 4), int a4 = 333) {} + void argRemoval3(int a0, Point a1 = Point(1, 2), bool a2 = true, Point a3 = Point(3, 4), + int a4 = 333); - inline void argRemoval4(int a0, Point a1, bool a2, Point a3 = Point(3, 4), int a4 = 333) {} + void argRemoval4(int a0, Point a1, bool a2, Point a3 = Point(3, 4), int a4 = 333); - inline void argRemoval5(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), int a4 = 333) {} - inline void argRemoval5(int a0, bool a1, int a2, bool a3) {} + void argRemoval5(int a0, bool a1, Point a2 = Point(1, 2), Point a3 = Point(3, 4), + int a4 = 333); + void argRemoval5(int a0, bool a1, int a2, bool a3); // 'ok' must be removed and the return value will be changed // to a tuple (PyObject*) containing the expected result plus // the 'ok' value as a Python boolean - std::pair<double, double> pointToPair(Point pt, bool* ok); + std::pair<double, double> pointToPair(Point pt, bool *ok); // same as 'pointToPair' except that this time 'ok' is the first argument - double multiplyPointCoordsPlusValue(bool* ok, Point pt, double value); + double multiplyPointCoordsPlusValue(bool *ok, Point pt, double value); // completely remove 'plus' from the Python side int doublePlus(int value, int plus = 0); @@ -106,24 +88,25 @@ public: int cppMultiply(int a, int b); // change the name of this virtual method - virtual const char* className(); + virtual const char *className(); Point sumPointArray(int arraySize, const Point pointArray[]); // Replace 'const void*' by 'ByteArray&'. - int getSize(const void* data, int size); + int getSize(const void *data, int size); // Mark the argument with a <no-null-pointer/> tag; // the test implementation must expect point never to be null. - int sumPointCoordinates(const Point* point); + int sumPointCoordinates(const Point *point); // Modify the return value of a virtual method. - virtual double differenceOfPointCoordinates(const Point* pt, bool* ok); - double callDifferenceOfPointCoordinates(const Point* pt, bool* ok) { return differenceOfPointCoordinates(pt, ok); } + virtual double differenceOfPointCoordinates(const Point *pt, bool *ok); + double callDifferenceOfPointCoordinates(const Point *pt, bool *ok) + { return differenceOfPointCoordinates(pt, ok); } // Sets an ObjectType in the argument and returns true. bool nonConversionRuleForArgumentWithDefaultValue(ObjectType **object = nullptr); - ObjectType* getObject() const { return m_object; } + ObjectType *getObject() const { return m_object; } // Inject code with a %CONVERTTOPYTHON that receives an user's primitive type. static inline OddBool passOddBool(OddBool ob) { return ob; } @@ -139,7 +122,7 @@ public: void notifySetAttroCalled(); private: - ObjectType* m_object; + ObjectType *m_object; TestEnum m_enumValue = TestEnumValue1; bool m_getAttroCalled = false; bool m_setAttroCalled = false; @@ -148,8 +131,10 @@ private: class LIBSAMPLE_API AbstractModifications : public Modifications { public: - AbstractModifications() {} - virtual ~AbstractModifications() {} + LIBMINIMAL_DISABLE_COPY_MOVE(AbstractModifications) + + AbstractModifications() noexcept = default; + ~AbstractModifications() override = default; inline bool invert(bool value) { return !value; } diff --git a/sources/shiboken6/tests/libsample/modified_constructor.cpp b/sources/shiboken6/tests/libsample/modified_constructor.cpp index 015cf4e80..c39c97738 100644 --- a/sources/shiboken6/tests/libsample/modified_constructor.cpp +++ b/sources/shiboken6/tests/libsample/modified_constructor.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "modified_constructor.h" @@ -33,8 +8,7 @@ ModifiedConstructor::ModifiedConstructor(int first_arg) m_stored_value = first_arg; } -int -ModifiedConstructor::retrieveValue() +int ModifiedConstructor::retrieveValue() const { return m_stored_value; } diff --git a/sources/shiboken6/tests/libsample/modified_constructor.h b/sources/shiboken6/tests/libsample/modified_constructor.h index ccf23a1a3..a27899f3f 100644 --- a/sources/shiboken6/tests/libsample/modified_constructor.h +++ b/sources/shiboken6/tests/libsample/modified_constructor.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MODIFIEDCONSTRUCTOR_H #define MODIFIEDCONSTRUCTOR_H @@ -35,8 +10,8 @@ class LIBSAMPLE_API ModifiedConstructor { public: - ModifiedConstructor(int first_arg); - int retrieveValue(); + explicit ModifiedConstructor(int first_arg); + int retrieveValue() const; private: int m_stored_value; diff --git a/sources/shiboken6/tests/libsample/multiple_derived.cpp b/sources/shiboken6/tests/libsample/multiple_derived.cpp index 2c6a0b8bb..be535c62f 100644 --- a/sources/shiboken6/tests/libsample/multiple_derived.cpp +++ b/sources/shiboken6/tests/libsample/multiple_derived.cpp @@ -1,64 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "multiple_derived.h" -MDerived1::MDerived1() : m_value(100) -{ -} +MDerived1::MDerived1() noexcept = default; -MDerived2::MDerived2() : m_value(200) -{ -} +MDerived2::MDerived2() noexcept = default; -MDerived3::MDerived3() : m_value(3000) -{ -} +MDerived3::MDerived3() noexcept = default; -MDerived4::MDerived4() -{ -} +MDerived4::MDerived4() noexcept = default; -MDerived5::MDerived5() -{ -} +MDerived5::MDerived5() noexcept = default; -MDerived1* -MDerived1::transformFromBase1(Base1* self) +MDerived1 *MDerived1::transformFromBase1(Base1 *self) { - MDerived1* ptr = dynamic_cast<MDerived1*>(self); - return ptr; + return dynamic_cast<MDerived1*>(self); } -MDerived1* -MDerived1::transformFromBase2(Base2* self) +MDerived1 *MDerived1::transformFromBase2(Base2 *self) { - MDerived1* ptr = dynamic_cast<MDerived1*>(self); - return ptr; + return dynamic_cast<MDerived1*>(self); } - diff --git a/sources/shiboken6/tests/libsample/multiple_derived.h b/sources/shiboken6/tests/libsample/multiple_derived.h index b551eda74..8c2143ed6 100644 --- a/sources/shiboken6/tests/libsample/multiple_derived.h +++ b/sources/shiboken6/tests/libsample/multiple_derived.h @@ -1,99 +1,90 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef MDERIVED_H #define MDERIVED_H #include "libsamplemacros.h" + #include <string> class Base1 { public: - Base1() : m_value(1) {} - virtual ~Base1() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base1) + + Base1() noexcept = default; + virtual ~Base1() = default; + virtual int base1Method() { return m_value; } virtual void publicMethod() {}; + private: - int m_value; + int m_value = 1; }; class Base2 { public: - Base2() : m_value(2) {} - virtual ~Base2() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base2) + + Base2() noexcept = default; + virtual ~Base2() = default; virtual int base2Method() { return m_value; } + private: - int m_value; + int m_value = 2; }; class LIBSAMPLE_API MDerived1 : public Base1, public Base2 { public: - MDerived1(); - ~MDerived1() override {} + LIBMINIMAL_DISABLE_COPY_MOVE(MDerived1) + + MDerived1() noexcept; + ~MDerived1() override = default; int mderived1Method() { return m_value; } int base1Method () override { return Base1::base1Method() * 10; } int base2Method() override { return Base2::base2Method() * 10; } - inline Base1* castToBase1() { return (Base1*) this; } - inline Base2* castToBase2() { return (Base2*) this; } + inline Base1 *castToBase1() { return (Base1*) this; } + inline Base2 *castToBase2() { return (Base2*) this; } - static MDerived1* transformFromBase1(Base1 *self); - static MDerived1* transformFromBase2(Base2 *self); + static MDerived1 *transformFromBase1(Base1 *self); + static MDerived1 *transformFromBase2(Base2 *self); private: void publicMethod() override {} - int m_value; + int m_value = 100; }; class SonOfMDerived1 : public MDerived1 { public: - SonOfMDerived1() : m_value(0) {} - ~SonOfMDerived1() {} + LIBMINIMAL_DISABLE_COPY_MOVE(SonOfMDerived1) + + SonOfMDerived1() noexcept = default; + ~SonOfMDerived1() = default; - inline MDerived1* castToMDerived1() { return (MDerived1*) this; } + inline MDerived1 *castToMDerived1() { return this; } int sonOfMDerived1Method() { return m_value; } + private: - int m_value; + int m_value = 0; }; class Base3 { public: - explicit Base3(int val = 3) : m_value(val) {} - virtual ~Base3() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base3) + + explicit Base3(int val = 3) noexcept : m_value(val) {} + virtual ~Base3() = default; int base3Method() { return m_value; } + private: int m_value; }; @@ -101,80 +92,95 @@ private: class Base4 { public: - Base4() : m_value(4) {} - virtual ~Base4() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base4) + + Base4() noexcept = default; + virtual ~Base4() = default; int base4Method() { return m_value; } + private: - int m_value; + int m_value = 4; }; class Base5 { public: - Base5() : m_value(5) {} - virtual ~Base5() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base5) + + Base5() noexcept = default; + virtual ~Base5() = default; virtual int base5Method() { return m_value; } + private: - int m_value; + int m_value = 5; }; class Base6 { public: - Base6() : m_value(6) {} - virtual ~Base6() {} + LIBMINIMAL_DISABLE_COPY_MOVE(Base6) + + Base6() noexcept = default; + virtual ~Base6() = default; virtual int base6Method() { return m_value; } + private: - int m_value; + int m_value = 6; }; - class LIBSAMPLE_API MDerived2 : public Base3, public Base4, public Base5, public Base6 { public: - MDerived2(); - virtual ~MDerived2() {} + LIBMINIMAL_DISABLE_COPY_MOVE(MDerived2) + + MDerived2() noexcept; + virtual ~MDerived2() = default; inline int base4Method() { return Base3::base3Method() * 10; } inline int mderived2Method() { return m_value; } - inline Base3* castToBase3() { return (Base3*) this; } - inline Base4* castToBase4() { return (Base4*) this; } - inline Base5* castToBase5() { return (Base5*) this; } - inline Base6* castToBase6() { return (Base6*) this; } + inline Base3 *castToBase3() { return this; } + inline Base4 *castToBase4() { return this; } + inline Base5 *castToBase5() { return this; } + inline Base6 *castToBase6() { return this; } private: - int m_value; + int m_value = 200; }; class LIBSAMPLE_API MDerived3 : public MDerived1, public MDerived2 { public: - MDerived3(); - virtual ~MDerived3() {} + LIBMINIMAL_DISABLE_COPY_MOVE(MDerived3) + + MDerived3() noexcept; + virtual ~MDerived3() = default; inline virtual int mderived3Method() { return m_value; } - inline MDerived1* castToMDerived1() { return (MDerived1*) this; } - inline MDerived2* castToMDerived2() { return (MDerived2*) this; } + inline MDerived1 *castToMDerived1() { return this; } + inline MDerived2 *castToMDerived2() { return this; } - inline Base3* castToBase3() { return (Base3*) this; } + inline Base3 *castToBase3() { return (Base3*) this; } private: - int m_value; + int m_value = 3000; }; class LIBSAMPLE_API MDerived4 : public Base3, public Base4 { public: - MDerived4(); - ~MDerived4() {} + LIBMINIMAL_DISABLE_COPY_MOVE(MDerived4) + + MDerived4() noexcept; + ~MDerived4() = default; inline int mderived4Method() { return 0; } inline int justDummyMethod() { return m_value; } - inline Base3* castToBase3() { return (Base3*) this; } - inline Base4* castToBase4() { return (Base4*) this; } + inline Base3 *castToBase3() { return this; } + inline Base4 *castToBase4() { return this; } + private: int m_value; }; @@ -182,14 +188,15 @@ private: class LIBSAMPLE_API MDerived5 : public Base3, public Base4 { public: - MDerived5(); - virtual ~MDerived5() {} + LIBMINIMAL_DISABLE_COPY_MOVE(MDerived5) + + MDerived5() noexcept; + virtual ~MDerived5() = default; virtual int mderived5Method() { return 0; } - inline Base3* castToBase3() { return (Base3*) this; } - inline Base4* castToBase4() { return (Base4*) this; } + inline Base3 *castToBase3() { return this; } + inline Base4 *castToBase4() { return this; } }; #endif // MDERIVED_H - diff --git a/sources/shiboken6/tests/libsample/noimplicitconversion.h b/sources/shiboken6/tests/libsample/noimplicitconversion.h index 3173f4609..a0b91380b 100644 --- a/sources/shiboken6/tests/libsample/noimplicitconversion.h +++ b/sources/shiboken6/tests/libsample/noimplicitconversion.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef NOIMPLICITCONVERSION_H #define NOIMPLICITCONVERSION_H @@ -38,9 +13,12 @@ class NoImplicitConversion public: explicit NoImplicitConversion(int objId) : m_objId(objId) {} inline int objId() const { return m_objId; } - inline static int receivesNoImplicitConversionByValue(NoImplicitConversion arg) { return arg.m_objId; } - inline static int receivesNoImplicitConversionByPointer(NoImplicitConversion* arg) { return arg->m_objId; } - inline static int receivesNoImplicitConversionByReference(NoImplicitConversion& arg) { return arg.m_objId; } + inline static int receivesNoImplicitConversionByValue(NoImplicitConversion arg) + { return arg.m_objId; } + inline static int receivesNoImplicitConversionByPointer(NoImplicitConversion *arg) + { return arg->m_objId; } + inline static int receivesNoImplicitConversionByReference(NoImplicitConversion &arg) + { return arg.m_objId; } private: int m_objId; }; diff --git a/sources/shiboken6/tests/libsample/nondefaultctor.h b/sources/shiboken6/tests/libsample/nondefaultctor.h index bfdcbcf5b..fa97b8859 100644 --- a/sources/shiboken6/tests/libsample/nondefaultctor.h +++ b/sources/shiboken6/tests/libsample/nondefaultctor.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef NONDEFAULTCTOR_H #define NONDEFAULTCTOR_H @@ -33,13 +8,16 @@ class NonDefaultCtor { - int m_value; public: - NonDefaultCtor(int value) : m_value(value) + LIBMINIMAL_DEFAULT_COPY_MOVE(NonDefaultCtor) + + explicit NonDefaultCtor(int value) noexcept : m_value(value) { } - inline int value() + virtual ~NonDefaultCtor() = default; + + inline int value() const { return m_value; } @@ -69,7 +47,8 @@ public: return returnMyselfVirtual(); } - virtual ~NonDefaultCtor() {} +private: + int m_value; }; -#endif +#endif // NONDEFAULTCTOR_H diff --git a/sources/shiboken6/tests/libsample/nontypetemplate.h b/sources/shiboken6/tests/libsample/nontypetemplate.h index 5a9e670c6..e41c21604 100644 --- a/sources/shiboken6/tests/libsample/nontypetemplate.h +++ b/sources/shiboken6/tests/libsample/nontypetemplate.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef NONTYPETEMPLATE_H #define NONTYPETEMPLATE_H @@ -46,7 +21,7 @@ private: int m_array[Size]; }; -typedef IntArray<2> IntArray2; -typedef IntArray<3> IntArray3; +using IntArray2 = IntArray<2>; +using IntArray3 = IntArray<3>; #endif // NONTYPETEMPLATE_H diff --git a/sources/shiboken6/tests/libsample/null.h b/sources/shiboken6/tests/libsample/null.h index ea34ff5a0..945a89fa2 100644 --- a/sources/shiboken6/tests/libsample/null.h +++ b/sources/shiboken6/tests/libsample/null.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef NULL_H #define NULL_H @@ -33,12 +8,12 @@ class Null { public: Null(bool value) : m_isNull(value) {} - Null() : m_isNull(false) {} + Null() = default; + void setIsNull(bool flag) { m_isNull = flag; } private: - bool m_isNull; + bool m_isNull = false; }; -#endif // STR_H - +#endif // NULL_H diff --git a/sources/shiboken6/tests/libsample/objectmodel.cpp b/sources/shiboken6/tests/libsample/objectmodel.cpp index c92fb2ec2..56ed86577 100644 --- a/sources/shiboken6/tests/libsample/objectmodel.cpp +++ b/sources/shiboken6/tests/libsample/objectmodel.cpp @@ -1,42 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objectmodel.h" -void -ObjectModel::setData(ObjectType* data) +void ObjectModel::setData(ObjectType *data) { m_data = data; } -ObjectType* -ObjectModel::data() const +ObjectType *ObjectModel::data() const { return m_data; } +ObjectModel::MethodCalled ObjectModel::receivesObjectTypeFamily(const ObjectModel &) +{ + return ObjectModel::ObjectModelCalled; +} + +ObjectModel::MethodCalled ObjectModel::receivesObjectTypeFamily(const ObjectType &) +{ + return ObjectModel::ObjectTypeCalled; +} diff --git a/sources/shiboken6/tests/libsample/objectmodel.h b/sources/shiboken6/tests/libsample/objectmodel.h index 1890ac47f..6d2f97aee 100644 --- a/sources/shiboken6/tests/libsample/objectmodel.h +++ b/sources/shiboken6/tests/libsample/objectmodel.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTMODEL_H #define OBJECTMODEL_H @@ -36,23 +11,21 @@ class LIBSAMPLE_API ObjectModel : public ObjectType { public: explicit ObjectModel(ObjectType *parent = nullptr) - : ObjectType(parent), m_data(nullptr) - {} + : ObjectType(parent) {} - void setData(ObjectType* data); - virtual ObjectType* data() const; + void setData(ObjectType *data); + virtual ObjectType *data() const; // The MethodCalled enum and related static methods were created to // test bug #630 [http://bugs.openbossa.org/show_bug.cgi?id=630] enum MethodCalled { ObjectTypeCalled, ObjectModelCalled }; - static MethodCalled receivesObjectTypeFamily(const ObjectType& object) { return ObjectModel::ObjectTypeCalled; } - static MethodCalled receivesObjectTypeFamily(const ObjectModel& object) { return ObjectModel::ObjectModelCalled; } + static MethodCalled receivesObjectTypeFamily(const ObjectType &object); + static MethodCalled receivesObjectTypeFamily(const ObjectModel &object); private: // The model holds only one piece of data. // (This is just a test after all.) - ObjectType* m_data; + ObjectType *m_data = nullptr; }; #endif // OBJECTMODEL_H - diff --git a/sources/shiboken6/tests/libsample/objecttype.cpp b/sources/shiboken6/tests/libsample/objecttype.cpp index e5926d0c2..fa3e7357c 100644 --- a/sources/shiboken6/tests/libsample/objecttype.cpp +++ b/sources/shiboken6/tests/libsample/objecttype.cpp @@ -1,71 +1,38 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objecttype.h" #include "objecttypelayout.h" + #include <algorithm> #include <iostream> #include <string> #include <assert.h> -#include <algorithm> - -using namespace std; - -ObjectType::ObjectType(ObjectType* parent) : m_parent(nullptr), m_layout(nullptr), m_call_id(-1) +ObjectType::ObjectType(ObjectType *parent) { setParent(parent); } +ObjectType::ObjectType(ObjectType &&) noexcept = default; +ObjectType &ObjectType::operator=(ObjectType &&) noexcept = default; + ObjectType::~ObjectType() { for (auto *o : m_children) delete o; } -ObjectType* -ObjectType::createWithChild() +ObjectType *ObjectType::createWithChild() { - ObjectType* parent = create(); - ObjectType* child = create(); + ObjectType *parent = create(); + ObjectType *child = create(); child->setObjectName("child"); child->setParent(parent); return parent; } -const ObjectType *ObjectType::defaultInstance() -{ - static ObjectType result; - return &result; -} - -void -ObjectType::removeChild(ObjectType* child) +void ObjectType::removeChild(ObjectType *child) { if (!child) return; @@ -77,8 +44,7 @@ ObjectType::removeChild(ObjectType* child) } } -ObjectType* -ObjectType::takeChild(ObjectType* child) +ObjectType *ObjectType::takeChild(ObjectType *child) { if (!child) return nullptr; @@ -92,8 +58,7 @@ ObjectType::takeChild(ObjectType* child) return nullptr; } -ObjectType* -ObjectType::takeChild(const Str& name) +ObjectType *ObjectType::takeChild(const Str &name) { return takeChild(findChild(name)); @@ -107,15 +72,13 @@ ObjectTypeList::iterator ObjectType::findChildByName(const Str &name) }); } -ObjectType* -ObjectType::findChild(const Str& name) +ObjectType *ObjectType::findChild(const Str &name) { auto it = findChildByName(name); return it != m_children.end() ? *it : nullptr; } -void -ObjectType::killChild(const Str& name) +void ObjectType::killChild(const Str &name) { auto it = findChildByName(name); if (it != m_children.end()) { @@ -125,8 +88,7 @@ ObjectType::killChild(const Str& name) } } -void -ObjectType::setParent(ObjectType* parent) +void ObjectType::setParent(ObjectType *parent) { if (m_parent == parent) return; @@ -139,33 +101,28 @@ ObjectType::setParent(ObjectType* parent) m_parent->m_children.push_back(this); } -void -ObjectType::setObjectName(const Str& name) +void ObjectType::setObjectName(const Str &name) { m_objectName = name; } -Str -ObjectType::objectName() const +Str ObjectType::objectName() const { return m_objectName; } -bool -ObjectType::causeEvent(Event::EventType eventType) +bool ObjectType::causeEvent(Event::EventType eventType) { Event e(eventType); return event(&e); } -bool -ObjectType::event(Event* event) +bool ObjectType::event(Event *) { return true; } -int -ObjectType::processEvent(ObjectTypeList objects, Event *event) +int ObjectType::processEvent(ObjectTypeList objects, Event *event) { return std::count_if(objects.begin(), objects.end(), [event] (ObjectType *o) { @@ -173,38 +130,43 @@ ObjectType::processEvent(ObjectTypeList objects, Event *event) }); } -void -ObjectType::callInvalidateEvent(Event* event) +void ObjectType::callInvalidateEvent(Event *event) { invalidateEvent(event); } -void -ObjectType::setLayout(ObjectTypeLayout* l) +void ObjectType::invalidateEvent(Event *) +{ +} + +void ObjectType::setLayout(ObjectTypeLayout *l) { if (!l) { - cerr << "[WARNING] ObjectType::setLayout: Cannot set layout to 0." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Cannot set layout to 0.\n"; return; } if (layout()) { if (layout() != l) { - cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring(); - cerr << "' on ObjectType '" << objectName().cstring() << "', which already has a layout." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" + << l->objectName().cstring() + << "' on ObjectType '" << objectName().cstring() + << "', which already has a layout.\n"; } return; } - ObjectType* oldParent = l->parent(); + ObjectType *oldParent = l->parent(); if (oldParent && oldParent != this) { if (oldParent->isLayoutType()) { - cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" << l->objectName().cstring(); - cerr << "' on ObjectType '" << objectName().cstring() << "', when the ObjectTypeLayout already has a parent layout." << endl; + std::cerr << "[WARNING] ObjectType::setLayout: Attempting to set ObjectTypeLayout '" + << l->objectName().cstring() + << "' on ObjectType '" << objectName().cstring() + << "', when the ObjectTypeLayout already has a parent layout.\n"; return; - } else { - // Steal the layout from an ObjectType parent. - oldParent->takeLayout(); } + // Steal the layout from an ObjectType parent. + oldParent->takeLayout(); } m_layout = l; @@ -214,9 +176,9 @@ ObjectType::setLayout(ObjectTypeLayout* l) } } -ObjectTypeLayout* ObjectType::takeLayout() +ObjectTypeLayout *ObjectType::takeLayout() { - ObjectTypeLayout* l = layout(); + ObjectTypeLayout *l = layout(); if (!l) return nullptr; m_layout = nullptr; @@ -224,39 +186,35 @@ ObjectTypeLayout* ObjectType::takeLayout() return l; } -unsigned int -objectTypeHash(const ObjectType* objectType) +unsigned int objectTypeHash(const ObjectType *objectType) { return reinterpret_cast<std::size_t>(objectType); } -unsigned char -ObjectType::callWithEnum(const Str& prefix, Event::EventType type, unsigned char value){ - return value*value; +unsigned char ObjectType::callWithEnum(const Str &, Event::EventType, unsigned char value) +{ + return value * value; } -unsigned char -ObjectType::callWithEnum(const Str& prefix, unsigned char value) { +unsigned char ObjectType::callWithEnum(const Str &, unsigned char value) +{ return value; } -void -ObjectType::setObjectSplittedName(const char*, const Str& prefix, const Str& suffix) +void ObjectType::setObjectSplittedName(const char *, const Str &prefix, const Str &suffix) { std::string result(prefix.cstring()); result += suffix.cstring(); m_objectName = result.c_str(); } -void -ObjectType::setObjectNameWithSize(const char*, int size, const Str& name) +void ObjectType::setObjectNameWithSize(const char *, int size, const Str &name) { std::string result(name.cstring(), size); m_objectName = result.c_str(); } -void -ObjectType::setObjectNameWithSize(const Str& name, int size) +void ObjectType::setObjectNameWithSize(const Str &name, int size) { setObjectNameWithSize("", size, name); } @@ -276,37 +234,31 @@ int ObjectType::callId() const return m_call_id; } - void ObjectType::callVirtualCreateChild() { - ObjectType* fake_parent = new ObjectType(); - ObjectType* fake_child = createChild(fake_parent); + auto *fake_parent = new ObjectType(); + ObjectType *fake_child = createChild(fake_parent); assert(fake_child->isPython()); (void)fake_child; delete fake_parent; } -ObjectType* ObjectType::createChild(ObjectType* parent) +ObjectType *ObjectType::createChild(ObjectType *parent) { return new ObjectType(parent); } std::size_t ObjectType::createObjectType() { - void* addr = new ObjectType(); + void *addr = new ObjectType(); return (std::size_t) addr; } -OtherBase::~OtherBase() -{ -} +OtherBase::~OtherBase() = default; -ObjectTypeDerived::~ObjectTypeDerived() -{ -} +ObjectTypeDerived::~ObjectTypeDerived() = default; -bool -ObjectTypeDerived::event(Event* event) +bool ObjectTypeDerived::event(Event *) { return true; } diff --git a/sources/shiboken6/tests/libsample/objecttype.h b/sources/shiboken6/tests/libsample/objecttype.h index 5863d5f2d..498556459 100644 --- a/sources/shiboken6/tests/libsample/objecttype.h +++ b/sources/shiboken6/tests/libsample/objecttype.h @@ -1,41 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTTYPE_H #define OBJECTTYPE_H -#include <list> #include "str.h" #include "null.h" #include "libsamplemacros.h" -#include <stddef.h> +#include <list> struct Event { @@ -51,11 +25,12 @@ struct Event Value2 }; - Event(EventType eventType) : m_eventType(eventType) {} - EventType eventType() { return m_eventType; } + explicit Event(EventType eventType) : m_eventType(eventType) {} + EventType eventType() const { return m_eventType; } void setEventType(EventType et) { m_eventType = et; } void setEventTypeByConstRef(const EventType &et) { m_eventType = et; } + void setEventTypeByConstPtr(const EventType *etPtr) { m_eventType = *etPtr; } private: EventType m_eventType; @@ -73,67 +48,72 @@ public: explicit ObjectType(ObjectType *parent = nullptr); virtual ~ObjectType(); + ObjectType(const ObjectType &) = delete; + ObjectType &operator=(const ObjectType &) = delete; + ObjectType(ObjectType &&) noexcept; + ObjectType &operator=(ObjectType &&) noexcept; // factory method - inline static ObjectType* create() { return new ObjectType(); } - static ObjectType* createWithChild(); - - static const ObjectType *defaultInstance(); - - void setParent(ObjectType* parent); - inline ObjectType* parent() const { return m_parent; } - inline const ObjectTypeList& children() const { return m_children; } - void killChild(const Str& name); - void removeChild(ObjectType* child); - ObjectType* takeChild(ObjectType* child); - virtual ObjectType* takeChild(const Str& name); - ObjectType* findChild(const Str& name); + inline static ObjectType *create() { return new ObjectType(); } + static ObjectType *createWithChild(); + + void setParent(ObjectType *parent); + inline ObjectType *parent() const { return m_parent; } + inline const ObjectTypeList &children() const { return m_children; } + void killChild(const Str &name); + void removeChild(ObjectType *child); + ObjectType *takeChild(ObjectType *child); + virtual ObjectType *takeChild(const Str &name); + ObjectType *findChild(const Str &name); Str objectName() const; - void setObjectName(const Str& name); + void setObjectName(const Str &name); inline Identifier identifier() const { return reinterpret_cast<Identifier>(this); } bool causeEvent(Event::EventType eventType); // Returns true if the event is processed. - virtual bool event(Event* event); + virtual bool event(Event *event); static int processEvent(ObjectTypeList objects, Event *event); - void callInvalidateEvent(Event* event); - virtual void invalidateEvent(Event* event) {} + void callInvalidateEvent(Event *event); + virtual void invalidateEvent(Event *event); // This nonsense method emulate QWidget.setLayout method // All layout objects will became children of this object. - void setLayout(ObjectTypeLayout* layout); - inline ObjectTypeLayout* layout() const { return m_layout; } + void setLayout(ObjectTypeLayout *layout); + inline ObjectTypeLayout *layout() const { return m_layout; } // This method should be reimplemented by ObjectTypeLayout. virtual bool isLayoutType() { return false; } - unsigned char callWithEnum(const Str& prefix, Event::EventType type, unsigned char value=80); - unsigned char callWithEnum(const Str& prefix, unsigned char value=0); + unsigned char callWithEnum(const Str &prefix, Event::EventType type, + unsigned char value=80); + unsigned char callWithEnum(const Str &prefix, unsigned char value=0); //Functions used in test with named arguments - void setObjectSplittedName(const char*, const Str& prefix = Str("<unk"), const Str& suffix = Str("nown>")); - void setObjectNameWithSize(const char*, int size=9, const Str& name = Str("<unknown>")); - void setObjectNameWithSize(const Str& name = Str("<unknown>"), int size=9); + void setObjectSplittedName(const char *, const Str &prefix = Str("<unk"), + const Str &suffix = Str("nown>")); + void setObjectNameWithSize(const char *, int size=9, + const Str &name = Str("<unknown>")); + void setObjectNameWithSize(const Str &name = Str("<unknown>"), int size = 9); //Function used to confuse the generator when two values accept Null as arg void setObject(ObjectType *); - void setObject(const Null&); + void setObject(const Null &); int callId() const; //Function used to create a parent from C++ virtual bool isPython() { return false; } void callVirtualCreateChild(); - virtual ObjectType* createChild(ObjectType* parent); + virtual ObjectType *createChild(ObjectType *parent); static std::size_t createObjectType(); //return a parent from C++ - ObjectType* getCppParent() { + ObjectType *getCppParent() { if (!m_parent) { - ObjectType* parent = new ObjectType(); + ObjectType *parent = new ObjectType(); setParent(parent); } return m_parent; @@ -148,41 +128,39 @@ public: // nextInFocusChain simply returns the parent to test object cycles; the parent // may be returned by the QWidget's implementation but isn't always returned - ObjectType* nextInFocusChain() { return m_parent; } + ObjectType *nextInFocusChain() { return m_parent; } private: - ObjectType(const ObjectType&); - ObjectType& operator=(const ObjectType&); - - ObjectTypeLayout* takeLayout(); + ObjectTypeLayout *takeLayout(); ObjectTypeList::iterator findChildByName(const Str &name); Str m_objectName; - ObjectType* m_parent; + ObjectType *m_parent = nullptr; ObjectTypeList m_children; - ObjectTypeLayout* m_layout; - - + ObjectTypeLayout *m_layout = nullptr; //used on overload null test - int m_call_id; + int m_call_id = -1; }; -LIBSAMPLE_API unsigned int objectTypeHash(const ObjectType* objectType); +LIBSAMPLE_API unsigned int objectTypeHash(const ObjectType *objectType); class LIBSAMPLE_API OtherBase { public: - OtherBase() {}; + LIBMINIMAL_DISABLE_COPY_MOVE(OtherBase) + + OtherBase() noexcept = default; virtual ~OtherBase(); }; class LIBSAMPLE_API ObjectTypeDerived: public ObjectType, public OtherBase { public: - ObjectTypeDerived(): ObjectType(), OtherBase() {}; + LIBMINIMAL_DISABLE_COPY_MOVE(ObjectTypeDerived) - bool event(Event* event) override; + ObjectTypeDerived() noexcept = default; + + bool event(Event *event) override; ~ObjectTypeDerived() override; }; #endif // OBJECTTYPE_H - diff --git a/sources/shiboken6/tests/libsample/objecttypebyvalue.h b/sources/shiboken6/tests/libsample/objecttypebyvalue.h index 64fa78c83..7b12ff945 100644 --- a/sources/shiboken6/tests/libsample/objecttypebyvalue.h +++ b/sources/shiboken6/tests/libsample/objecttypebyvalue.h @@ -1,46 +1,31 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTTYPEBYVALUE_H #define OBJECTTYPEBYVALUE_H -#include <list> + #include "protected.h" +#include <list> + class ObjectTypeByValue { public: - ObjectTypeByValue returnSomeKindOfMe() { return ObjectTypeByValue(); } - void acceptKindOfMeAsValue(ObjectTypeByValue kindOfMe) {} + ObjectTypeByValue returnSomeKindOfMe() { return {}; } + void acceptKindOfMeAsValue(ObjectTypeByValue kindOfMe); - void acceptListOfObjectTypeByValue(std::list<ObjectTypeByValue> listOfMe) {} + void acceptListOfObjectTypeByValue(std::list<ObjectTypeByValue> listOfMe); // prop used to check for segfaults ProtectedProperty prop; }; -#endif +inline void ObjectTypeByValue::acceptKindOfMeAsValue(ObjectTypeByValue) +{ +} + +inline void ObjectTypeByValue::acceptListOfObjectTypeByValue(std::list<ObjectTypeByValue>) +{ +} + +#endif // OBJECTTYPEBYVALUE_H diff --git a/sources/shiboken6/tests/libsample/objecttypeholder.cpp b/sources/shiboken6/tests/libsample/objecttypeholder.cpp index be225a0d2..c0950d09c 100644 --- a/sources/shiboken6/tests/libsample/objecttypeholder.cpp +++ b/sources/shiboken6/tests/libsample/objecttypeholder.cpp @@ -1,41 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objecttypeholder.h" -ObjectTypeHolder::ObjectTypeHolder(const char* objectName) +ObjectTypeHolder::ObjectTypeHolder(const char *objectName) { - auto object = new ObjectType(); + auto *object = new ObjectType(); object->setObjectName(objectName); m_objectType = object; } -ObjectTypeHolder::ObjectTypeHolder(const ObjectType *object) : +ObjectTypeHolder::ObjectTypeHolder(const ObjectType *object) noexcept : m_objectType(object) { } @@ -45,14 +20,12 @@ ObjectTypeHolder::~ObjectTypeHolder() delete m_objectType; } -Str -ObjectTypeHolder::passObjectTypeAsReference(const ObjectType& objectType) +Str ObjectTypeHolder::passObjectTypeAsReference(const ObjectType &objectType) { return objectType.objectName(); } -Str -ObjectTypeHolder::callPassObjectTypeAsReference() +Str ObjectTypeHolder::callPassObjectTypeAsReference() { return passObjectTypeAsReference(*m_objectType); } diff --git a/sources/shiboken6/tests/libsample/objecttypeholder.h b/sources/shiboken6/tests/libsample/objecttypeholder.h index 7558b11ee..190664608 100644 --- a/sources/shiboken6/tests/libsample/objecttypeholder.h +++ b/sources/shiboken6/tests/libsample/objecttypeholder.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTTYPEHOLDER_H #define OBJECTTYPEHOLDER_H @@ -36,17 +11,19 @@ class LIBSAMPLE_API ObjectTypeHolder { public: - explicit ObjectTypeHolder(const char* objectName); - explicit ObjectTypeHolder(const ObjectType *object = ObjectType::defaultInstance()); + LIBMINIMAL_DISABLE_COPY_MOVE(ObjectTypeHolder) + + explicit ObjectTypeHolder(const char *objectName); + explicit ObjectTypeHolder(const ObjectType *object) noexcept; virtual ~ObjectTypeHolder(); - const ObjectType* getObjecType() { return m_objectType; } + const ObjectType *getObjectType() const { return m_objectType; } - virtual Str passObjectTypeAsReference(const ObjectType& objectType); + virtual Str passObjectTypeAsReference(const ObjectType &objectType); Str callPassObjectTypeAsReference(); private: const ObjectType *m_objectType; }; -#endif +#endif // OBJECTTYPEHOLDER_H diff --git a/sources/shiboken6/tests/libsample/objecttypelayout.cpp b/sources/shiboken6/tests/libsample/objecttypelayout.cpp index f06ede758..3fa02917c 100644 --- a/sources/shiboken6/tests/libsample/objecttypelayout.cpp +++ b/sources/shiboken6/tests/libsample/objecttypelayout.cpp @@ -1,43 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objecttypelayout.h" -#include <iostream> -using namespace std; +#include <iostream> -void ObjectTypeLayout::addObject(ObjectType* obj) +void ObjectTypeLayout::addObject(ObjectType *obj) { if (obj->isLayoutType()) { - ObjectTypeLayout* l = reinterpret_cast<ObjectTypeLayout*>(obj); + auto *l = reinterpret_cast<ObjectTypeLayout*>(obj); if (l->parent()) { - cerr << "[WARNING] ObjectTypeLayout::addObject: layout '" << l->objectName().cstring(); - cerr << "' already has a parent." << endl; + std::cerr << "[WARNING] ObjectTypeLayout::addObject: layout '" + << l->objectName().cstring() << "' already has a parent.\n"; return; } @@ -50,12 +24,12 @@ void ObjectTypeLayout::addObject(ObjectType* obj) m_objects.push_back(obj); } -std::list< ObjectType* > ObjectTypeLayout::objects() const +std::list<ObjectType*> ObjectTypeLayout::objects() const { return m_objects; } -void ObjectTypeLayout::reparentChildren(ObjectType* parent) +void ObjectTypeLayout::reparentChildren(ObjectType *parent) { for (auto *o : m_objects) { if (o->isLayoutType()) @@ -64,4 +38,3 @@ void ObjectTypeLayout::reparentChildren(ObjectType* parent) o->setParent(parent); } } - diff --git a/sources/shiboken6/tests/libsample/objecttypelayout.h b/sources/shiboken6/tests/libsample/objecttypelayout.h index eb099313c..0aa9fad6e 100644 --- a/sources/shiboken6/tests/libsample/objecttypelayout.h +++ b/sources/shiboken6/tests/libsample/objecttypelayout.h @@ -1,36 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTTYPELAYOUT_H #define OBJECTTYPELAYOUT_H #include "libsamplemacros.h" #include "objecttype.h" + #include <list> class ObjectType; @@ -38,19 +14,19 @@ class ObjectType; class LIBSAMPLE_API ObjectTypeLayout : public ObjectType { public: - void addObject(ObjectType* obj); + void addObject(ObjectType *obj); std::list<ObjectType*> objects() const; bool isLayoutType() override { return true; } - inline static ObjectTypeLayout* create() { return new ObjectTypeLayout(); } + inline static ObjectTypeLayout *create() { return new ObjectTypeLayout(); } + + ObjectType *takeChild(const Str &name) override { return ObjectType::takeChild(name); } - ObjectType* takeChild(const Str& name) override { return ObjectType::takeChild(name); } private: std::list<ObjectType*> m_objects; - void reparentChildren(ObjectType* parent); - friend LIBSAMPLE_API void ObjectType::setLayout(ObjectTypeLayout* l); + void reparentChildren(ObjectType *parent); + friend LIBSAMPLE_API void ObjectType::setLayout(ObjectTypeLayout *l); }; #endif // OBJECTTYPELAYOUT_H - diff --git a/sources/shiboken6/tests/libsample/objecttypeoperators.cpp b/sources/shiboken6/tests/libsample/objecttypeoperators.cpp index dc5243f2e..c78387a3e 100644 --- a/sources/shiboken6/tests/libsample/objecttypeoperators.cpp +++ b/sources/shiboken6/tests/libsample/objecttypeoperators.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objecttypeoperators.h" @@ -32,32 +7,32 @@ ObjectTypeOperators::ObjectTypeOperators(const std::string key) : m_key(key) { } -bool ObjectTypeOperators::operator==(const ObjectTypeOperators& other) const +bool ObjectTypeOperators::operator==(const ObjectTypeOperators &other) const { return m_key == other.m_key; } -const ObjectTypeOperators& ObjectTypeOperators::operator<(const ObjectTypeOperators& other) const +const ObjectTypeOperators &ObjectTypeOperators::operator<(const ObjectTypeOperators &other) const { return m_key < other.m_key ? *this : other; } -bool operator==(const ObjectTypeOperators* obj, const std::string& str) +bool operator==(const ObjectTypeOperators *obj, const std::string &str) { return obj->key() == str; } -bool operator==(const std::string& str, const ObjectTypeOperators* obj) +bool operator==(const std::string &str, const ObjectTypeOperators *obj) { return str == obj->key(); } -std::string operator+(const ObjectTypeOperators* obj, const std::string& str) +std::string operator+(const ObjectTypeOperators *obj, const std::string &str) { return obj->key() + str; } -std::string operator+(const std::string& str, const ObjectTypeOperators* obj) +std::string operator+(const std::string &str, const ObjectTypeOperators *obj) { return str + obj->key(); } diff --git a/sources/shiboken6/tests/libsample/objecttypeoperators.h b/sources/shiboken6/tests/libsample/objecttypeoperators.h index 6bb54d600..6144952ca 100644 --- a/sources/shiboken6/tests/libsample/objecttypeoperators.h +++ b/sources/shiboken6/tests/libsample/objecttypeoperators.h @@ -1,61 +1,36 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTTYPEOPERATORS_H #define OBJECTTYPEOPERATORS_H #include "libsamplemacros.h" + #include <string> class LIBSAMPLE_API ObjectTypeOperators { public: + LIBMINIMAL_DISABLE_COPY_MOVE(ObjectTypeOperators) + explicit ObjectTypeOperators(const std::string key); - virtual ~ObjectTypeOperators() {} + virtual ~ObjectTypeOperators() = default; - bool operator==(const ObjectTypeOperators& other) const; - const ObjectTypeOperators& operator<(const ObjectTypeOperators& other) const; + bool operator==(const ObjectTypeOperators &other) const; + const ObjectTypeOperators &operator<(const ObjectTypeOperators &other) const; // chaos! - virtual void operator>(const ObjectTypeOperators&) { m_key.append("operator>"); } + virtual void operator>(const ObjectTypeOperators &) { m_key.append("operator>"); } std::string key() const { return m_key; } private: std::string m_key; - - ObjectTypeOperators(ObjectTypeOperators&); - ObjectTypeOperators& operator=(ObjectTypeOperators&); }; -LIBSAMPLE_API bool operator==(const ObjectTypeOperators* obj, const std::string& str); -LIBSAMPLE_API bool operator==(const std::string& str, const ObjectTypeOperators* obj); -LIBSAMPLE_API std::string operator+(const ObjectTypeOperators* obj, const std::string& str); -LIBSAMPLE_API std::string operator+(const std::string& str, const ObjectTypeOperators* obj); +LIBSAMPLE_API bool operator==(const ObjectTypeOperators *obj, const std::string &str); +LIBSAMPLE_API bool operator==(const std::string &str, const ObjectTypeOperators *obj); +LIBSAMPLE_API std::string operator+(const ObjectTypeOperators *obj, const std::string &str); +LIBSAMPLE_API std::string operator+(const std::string &str, const ObjectTypeOperators *obj); #endif // OBJECTTYPEOPERATORS_H diff --git a/sources/shiboken6/tests/libsample/objectview.cpp b/sources/shiboken6/tests/libsample/objectview.cpp index d640c406e..1b727f88c 100644 --- a/sources/shiboken6/tests/libsample/objectview.cpp +++ b/sources/shiboken6/tests/libsample/objectview.cpp @@ -1,54 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "objectview.h" #include "objectmodel.h" #include "str.h" -Str -ObjectView::displayModelData() +Str ObjectView::displayModelData() { if (!m_model) - return Str("(NULL)"); + return {"(NULL)"}; return Str("Name: %VAR").arg(m_model->objectName()); } -void -ObjectView::modifyModelData(Str& data) +void ObjectView::modifyModelData(Str &data) { if (m_model) m_model->setObjectName(data); } - -ObjectType* -ObjectView::getRawModelData() +ObjectType *ObjectView::getRawModelData() { return m_model->data(); } - diff --git a/sources/shiboken6/tests/libsample/objectview.h b/sources/shiboken6/tests/libsample/objectview.h index b68d031e9..2567deee5 100644 --- a/sources/shiboken6/tests/libsample/objectview.h +++ b/sources/shiboken6/tests/libsample/objectview.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OBJECTVIEW_H #define OBJECTVIEW_H @@ -38,21 +13,19 @@ class ObjectModel; class LIBSAMPLE_API ObjectView : public ObjectType { public: - ObjectView(ObjectModel *model = nullptr, ObjectType *parent = nullptr) - : ObjectType(parent), m_model(model) - {} + explicit ObjectView(ObjectModel *model = nullptr, ObjectType *parent = nullptr) + : ObjectType(parent), m_model(model) {} - inline void setModel(ObjectModel* model) { m_model = model; } - inline ObjectModel* model() const { return m_model; } + inline void setModel(ObjectModel *model) { m_model = model; } + inline ObjectModel *model() const { return m_model; } Str displayModelData(); - void modifyModelData(Str& data); + void modifyModelData(Str &data); - ObjectType* getRawModelData(); + ObjectType *getRawModelData(); private: - ObjectModel* m_model; + ObjectModel *m_model; }; #endif // OBJECTVIEW_H - diff --git a/sources/shiboken6/tests/libsample/oddbool.cpp b/sources/shiboken6/tests/libsample/oddbool.cpp index 4f491dd96..bc1ee833f 100644 --- a/sources/shiboken6/tests/libsample/oddbool.cpp +++ b/sources/shiboken6/tests/libsample/oddbool.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "oddbool.h" @@ -32,7 +7,7 @@ ComparisonTester::ComparisonTester(int v) : m_value(v) { } -ComparisonTester& ComparisonTester::operator=(int v) +ComparisonTester &ComparisonTester::operator=(int v) { m_value = v; return *this; @@ -46,3 +21,7 @@ int ComparisonTester::compare(const ComparisonTester &rhs) const return 1; return 0; } + +SpaceshipComparisonTester::SpaceshipComparisonTester(int v) : m_value(v) +{ +} diff --git a/sources/shiboken6/tests/libsample/oddbool.h b/sources/shiboken6/tests/libsample/oddbool.h index f7d77c0b3..dd2d32604 100644 --- a/sources/shiboken6/tests/libsample/oddbool.h +++ b/sources/shiboken6/tests/libsample/oddbool.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef ODDBOOL_H #define ODDBOOL_H @@ -33,11 +8,15 @@ #include <type_traits> +#if __cplusplus >= 202002 || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002) +# include <compare> +#endif + class OddBool { public: - inline explicit OddBool(bool b) : m_value(b) {} + inline explicit OddBool(bool b) noexcept : m_value(b) {} bool value() const { return m_value; } inline OddBool operator!() const { return OddBool(!m_value); } @@ -56,9 +35,11 @@ inline bool operator!=(OddBool b1, OddBool b2) { return (!b1).value() != (!b2).v class OddBoolUser { public: - OddBoolUser() : m_oddbool(OddBool(false)) {} - OddBoolUser(const OddBool& oddBool) : m_oddbool(oddBool) {} - virtual ~OddBoolUser() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(OddBoolUser) + + OddBoolUser() noexcept : m_oddbool(OddBool(false)) {} + OddBoolUser(const OddBool &oddBool) : m_oddbool(oddBool) {} + virtual ~OddBoolUser() = default; inline OddBool oddBool() { return m_oddbool; } inline void setOddBool(OddBool oddBool) { m_oddbool = oddBool; } @@ -73,7 +54,7 @@ public: return invertedOddBool(); } - static inline OddBool getOddBool(const OddBoolUser& oddBoolUser) + static inline OddBool getOddBool(const OddBoolUser &oddBoolUser) { return oddBoolUser.m_oddbool; } @@ -105,4 +86,21 @@ inline std::enable_if<std::is_assignable<ComparisonTester, int>::value, bool>::t operator!=(const ComparisonTester &c1, const ComparisonTester &c2) { return c1.compare(c2) != 0; } +class LIBSAMPLE_API SpaceshipComparisonTester +{ +public: + explicit SpaceshipComparisonTester(int v); + +#if __cplusplus >= 202002 || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002) + auto operator<=>(const SpaceshipComparisonTester &rhs) const = default; + + enum Enabled { HasSpaceshipOperator = 1 }; +#else + enum Enabled { HasSpaceshipOperator = 0 }; +#endif // C++ 20 + +private: + int m_value; +}; + #endif // ODDBOOL_H diff --git a/sources/shiboken6/tests/libsample/onlycopy.cpp b/sources/shiboken6/tests/libsample/onlycopy.cpp index cfc7c9d99..981ea88a4 100644 --- a/sources/shiboken6/tests/libsample/onlycopy.cpp +++ b/sources/shiboken6/tests/libsample/onlycopy.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "onlycopy.h" @@ -36,45 +11,23 @@ public: int value; }; -OnlyCopy::OnlyCopy(int value) : d(new OnlyCopyPrivate(value)) +OnlyCopy::OnlyCopy(int value) : d(std::make_shared<OnlyCopyPrivate>(value)) { - } -OnlyCopy::OnlyCopy(OnlyCopyPrivate *dIn) : d(dIn) -{ -} - -OnlyCopy::~OnlyCopy() -{ - delete d; -} - -OnlyCopy::OnlyCopy(const OnlyCopy& other) : d(new OnlyCopyPrivate(other.value())) -{ -} - -OnlyCopy& -OnlyCopy::operator=(const OnlyCopy& other) -{ - d->value = other.d->value; - return *this; -} +OnlyCopy::~OnlyCopy() = default; int OnlyCopy::value() const { return d->value; } -OnlyCopy -FriendOfOnlyCopy::createOnlyCopy(int value) +OnlyCopy FriendOfOnlyCopy::createOnlyCopy(int value) { - return OnlyCopy(value); } -std::list<OnlyCopy> -FriendOfOnlyCopy::createListOfOnlyCopy(int quantity) +std::list<OnlyCopy> FriendOfOnlyCopy::createListOfOnlyCopy(int quantity) { std::list<OnlyCopy> list; for (int i = 0; i < quantity; ++i) diff --git a/sources/shiboken6/tests/libsample/onlycopy.h b/sources/shiboken6/tests/libsample/onlycopy.h index 84a32a951..7dc3e0069 100644 --- a/sources/shiboken6/tests/libsample/onlycopy.h +++ b/sources/shiboken6/tests/libsample/onlycopy.h @@ -1,36 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef ONLYCOPYCLASS_H #define ONLYCOPYCLASS_H #include "libsamplemacros.h" + #include <list> +#include <memory> // These classes simulate a situation found in QWebEngineHistoryItem. @@ -39,18 +16,20 @@ class OnlyCopyPrivate; class LIBSAMPLE_API OnlyCopy { public: - OnlyCopy(const OnlyCopy& other); - OnlyCopy& operator=(const OnlyCopy& other); + LIBMINIMAL_DEFAULT_COPY_MOVE(OnlyCopy) + ~OnlyCopy(); int value() const; static int getValue(OnlyCopy onlyCopy) { return onlyCopy.value(); } - static int getValueFromReference(const OnlyCopy& onlyCopy) { return onlyCopy.value(); } + static int getValueFromReference(const OnlyCopy &onlyCopy) { return onlyCopy.value(); } + private: - OnlyCopyPrivate *d; - explicit OnlyCopy(int value); - explicit OnlyCopy(OnlyCopyPrivate *d); // rejected due to unknown OnlyCopyPrivate friend class FriendOfOnlyCopy; + + explicit OnlyCopy(int value); + + std::shared_ptr<OnlyCopyPrivate> d; }; class LIBSAMPLE_API FriendOfOnlyCopy @@ -60,4 +39,4 @@ public: static std::list<OnlyCopy> createListOfOnlyCopy(int quantity); }; -#endif +#endif // ONLYCOPYCLASS_H diff --git a/sources/shiboken6/tests/libsample/overload.cpp b/sources/shiboken6/tests/libsample/overload.cpp index ebf19586e..34da28e03 100644 --- a/sources/shiboken6/tests/libsample/overload.cpp +++ b/sources/shiboken6/tests/libsample/overload.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "overload.h" @@ -33,18 +8,196 @@ Overload::FunctionEnum Overload::overloaded() return Function0; } -Overload::FunctionEnum Overload::overloaded(Size* size) +Overload::FunctionEnum Overload::overloaded(Size *) { return Function1; } -Overload::FunctionEnum Overload::overloaded(Point* point, ParamEnum param) +Overload::FunctionEnum Overload::overloaded(Point *, ParamEnum) { return Function2; } -Overload::FunctionEnum Overload::overloaded(const Point& point) +Overload::FunctionEnum Overload::overloaded(const Point &) { return Function3; } +void Overload::differentReturnTypes(ParamEnum) +{ + +} + +int Overload::differentReturnTypes(ParamEnum, int val) +{ + return val; +} + +int Overload::intOverloads(const Point &, double) +{ + return 1; +} + +int Overload::intOverloads(int, int) +{ + return 2; +} + +int Overload::intOverloads(int, int, double) +{ + return 3; +} + +Overload::FunctionEnum Overload::intDoubleOverloads(double, double) const +{ + return Function1; +} + +Overload::FunctionEnum Overload::intDoubleOverloads(int, int) const +{ + return Function0; +} + +void Overload::singleOverload(Point *) +{ +} + +Overload::FunctionEnum Overload::wrapperIntIntOverloads(const Polygon &, int, int) +{ + return Function1; +} + +Overload::FunctionEnum Overload::wrapperIntIntOverloads(const Point &, int, int) +{ + return Function0; +} + +Overload::FunctionEnum Overload::strBufferOverloads(const Str &, const char *, bool) +{ + return Function0; +} + +Overload::FunctionEnum Overload::strBufferOverloads(unsigned char *, int) +{ + return Function1; +} + +Overload::FunctionEnum Overload::drawText(const PointF &, const Str &) +{ + return Function1; +} + +Overload::FunctionEnum Overload::drawText(const Point &, const Str &) +{ + return Function0; +} + +Overload::FunctionEnum Overload::drawText(const RectF &, const Str &, const Echo &) +{ + return Function4; +} + +Overload::FunctionEnum Overload::drawText(const RectF &, int, const Str &) +{ + return Function3; +} + +Overload::FunctionEnum Overload::drawText(const Rect &, int, const Str &) +{ + return Function2; +} + +Overload::FunctionEnum Overload::drawText(int, int, const Str &) +{ + return Function5; +} + +Overload::FunctionEnum Overload::drawText(int, int, int, int, int, const Str &) +{ + return Function6; +} + +Overload::FunctionEnum Overload::drawText2(const PointF &, const Str &) +{ + return Function1; +} + +Overload::FunctionEnum Overload::drawText2(const Point &, const Str &) +{ + return Function0; +} + +Overload::FunctionEnum Overload::drawText2(int, int, const Str &) +{ + return Function5; +} + +Overload::FunctionEnum Overload::drawText2(const RectF &, const Str &, const Echo &) +{ + return Function4; +} + +Overload::FunctionEnum Overload::drawText2(const RectF &, int, const Str &) +{ + return Function3; +} + +Overload::FunctionEnum Overload::drawText2(const Rect &, int, const Str &) +{ + return Function2; +} + +Overload::FunctionEnum Overload::drawText2(int, int, int, int, int, const Str &) +{ + return Function6; +} + +Overload::FunctionEnum Overload::drawText3(const Str &, const Str &, const Str &) +{ + return Function0; +} + +Overload::FunctionEnum Overload::drawText3(int, int, int, int, int) +{ + return Function1; +} + +Overload::FunctionEnum Overload::drawText4(int, int, int) +{ + return Function0; +} + +Overload::FunctionEnum Overload::drawText4(int, int, int, int, int) +{ + return Function1; +} + +Overload::FunctionEnum Overload::acceptSequence() +{ + return Function0; +} + +Overload::FunctionEnum Overload::acceptSequence(const Str &, ParamEnum) +{ + return Function2; +} + +Overload::FunctionEnum Overload::acceptSequence(int, int) +{ + return Function1; +} + +Overload::FunctionEnum Overload::acceptSequence(void *) +{ + return Function5; +} + +Overload::FunctionEnum Overload::acceptSequence(const char *const[]) +{ + return Function4; +} + +Overload::FunctionEnum Overload::acceptSequence(const Size &) +{ + return Function3; +} diff --git a/sources/shiboken6/tests/libsample/overload.h b/sources/shiboken6/tests/libsample/overload.h index aa2572d50..b640bf7c7 100644 --- a/sources/shiboken6/tests/libsample/overload.h +++ b/sources/shiboken6/tests/libsample/overload.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OVERLOAD_H #define OVERLOAD_H @@ -42,6 +17,8 @@ class LIBSAMPLE_API Overload { public: + LIBMINIMAL_DISABLE_COPY_MOVE(Overload) + enum FunctionEnum { Function0, Function1, @@ -57,69 +34,71 @@ public: Param1 }; - Overload() {} - virtual ~Overload() {} + Overload() noexcept = default; + virtual ~Overload() = default; FunctionEnum overloaded(); - FunctionEnum overloaded(Size* size); - FunctionEnum overloaded(Point* point, ParamEnum param); - FunctionEnum overloaded(const Point& point); + FunctionEnum overloaded(Size *size); + FunctionEnum overloaded(Point *point, ParamEnum param); + FunctionEnum overloaded(const Point &point); - inline void differentReturnTypes(ParamEnum param = Param0) {} - inline int differentReturnTypes(ParamEnum param, int val) { return val; } + void differentReturnTypes(ParamEnum param = Param0); + int differentReturnTypes(ParamEnum param, int val); - inline int intOverloads(const Point& p, double d) { return 1; } - inline int intOverloads(int i, int i2) { return 2; } - inline int intOverloads(int i, int removedArg, double d) { return 3; } + int intOverloads(const Point &p, double d); + int intOverloads(int i, int i2); + int intOverloads(int i, int removedArg, double d); - inline FunctionEnum intDoubleOverloads(int a0, int a1) const { return Function0; } - inline FunctionEnum intDoubleOverloads(double a0, double a1) const { return Function1; } + FunctionEnum intDoubleOverloads(int a0, int a1) const; + FunctionEnum intDoubleOverloads(double a0, double a1) const; - void singleOverload(Point* x) {} - Point* singleOverload() {return new Point();} + void singleOverload(Point *x); + Point *singleOverload() { return new Point(); } // Similar to QImage::trueMatrix(QMatrix,int,int) and QImage::trueMatrix(QTransform,int,int) - FunctionEnum wrapperIntIntOverloads(const Point& arg0, int arg1, int arg2) { return Function0; } - FunctionEnum wrapperIntIntOverloads(const Polygon& arg0, int arg1, int arg2) { return Function1; } + FunctionEnum wrapperIntIntOverloads(const Point &arg0, int arg1, int arg2); + FunctionEnum wrapperIntIntOverloads(const Polygon &arg0, int arg1, int arg2); // Similar to QImage constructor - FunctionEnum strBufferOverloads(const Str &arg0, const char *arg1 = nullptr, bool arg2 = true) { return Function0; } - FunctionEnum strBufferOverloads(unsigned char* arg0, int arg1) { return Function1; } + FunctionEnum strBufferOverloads(const Str &arg0, const char *arg1 = nullptr, + bool arg2 = true); + FunctionEnum strBufferOverloads(unsigned char *arg0, int arg1); FunctionEnum strBufferOverloads() { return Function2; } // Similar to QPainter::drawText(...) - FunctionEnum drawText(const Point& a0, const Str& a1) { return Function0; } - FunctionEnum drawText(const PointF& a0, const Str& a1) { return Function1; } - FunctionEnum drawText(const Rect& a0, int a1, const Str& a2) { return Function2; } - FunctionEnum drawText(const RectF& a0, int a1, const Str& a2) { return Function3; } - FunctionEnum drawText(const RectF& a0, const Str& a1, const Echo& a2 = Echo()) { return Function4; } - FunctionEnum drawText(int a0, int a1, const Str& a2) { return Function5; } - FunctionEnum drawText(int a0, int a1, int a2, int a3, int a4, const Str& a5) { return Function6; } + FunctionEnum drawText(const Point &a0, const Str &a1); + FunctionEnum drawText(const PointF &a0, const Str &a1); + FunctionEnum drawText(const Rect &a0, int a1, const Str &a2); + FunctionEnum drawText(const RectF &a0, int a1, const Str &a2); + FunctionEnum drawText(const RectF &a0, const Str &a1, const Echo &a2 = Echo()); + FunctionEnum drawText(int a0, int a1, const Str &a2); + FunctionEnum drawText(int a0, int a1, int a2, int a3, int a4, const Str &a5); // A variant of the one similar to QPainter::drawText(...) - FunctionEnum drawText2(const Point& a0, const Str& a1) { return Function0; } - FunctionEnum drawText2(const PointF& a0, const Str& a1) { return Function1; } - FunctionEnum drawText2(const Rect& a0, int a1, const Str& a2) { return Function2; } - FunctionEnum drawText2(const RectF& a0, int a1, const Str& a2) { return Function3; } - FunctionEnum drawText2(const RectF& a0, const Str& a1, const Echo& a2 = Echo()) { return Function4; } - FunctionEnum drawText2(int a0, int a1, const Str& a2) { return Function5; } - FunctionEnum drawText2(int a0, int a1, int a2, int a3 = 0, int a4 = 0, const Str& a5 = Str()) { return Function6; } + FunctionEnum drawText2(const Point &a0, const Str &a1); + FunctionEnum drawText2(const PointF &a0, const Str &a1); + FunctionEnum drawText2(const Rect &a0, int a1, const Str &a2); + FunctionEnum drawText2(const RectF &a0, int a1, const Str &a2); + FunctionEnum drawText2(const RectF &a0, const Str &a1, const Echo &a2 = Echo()); + FunctionEnum drawText2(int a0, int a1, const Str &a2); + FunctionEnum drawText2(int a0, int a1, int a2, int a3 = 0, int a4 = 0, + const Str &a5 = Str()); // A simpler variant of the one similar to QPainter::drawText(...) - FunctionEnum drawText3(const Str& a0, const Str& a1, const Str& a2) { return Function0; } - FunctionEnum drawText3(int a0, int a1, int a2, int a3, int a4) { return Function1; } + FunctionEnum drawText3(const Str &a0, const Str &a1, const Str &a2); + FunctionEnum drawText3(int a0, int a1, int a2, int a3, int a4); // Another simpler variant of the one similar to QPainter::drawText(...) - FunctionEnum drawText4(int a0, int a1, int a2) { return Function0; } - FunctionEnum drawText4(int a0, int a1, int a2, int a3, int a4) { return Function1; } + FunctionEnum drawText4(int a0, int a1, int a2); + FunctionEnum drawText4(int a0, int a1, int a2, int a3, int a4); - FunctionEnum acceptSequence() { return Function0; } - FunctionEnum acceptSequence(int a0, int a1) { return Function1; } - FunctionEnum acceptSequence(const Str& a0, ParamEnum a1 = Param0) { return Function2; } - FunctionEnum acceptSequence(const Size& a0) { return Function3; } + FunctionEnum acceptSequence(); + FunctionEnum acceptSequence(int a0, int a1); + FunctionEnum acceptSequence(const Str &a0, ParamEnum a1 = Param0); + FunctionEnum acceptSequence(const Size &a0); // The type must be changed to PySequence. - FunctionEnum acceptSequence(const char* const a0[]) { return Function4; } - FunctionEnum acceptSequence(void* a0) { return Function5; } + FunctionEnum acceptSequence(const char *const a0[]); + FunctionEnum acceptSequence(void *a0); }; class LIBSAMPLE_API Overload2 : public Overload @@ -140,4 +119,3 @@ private: }; #endif // OVERLOAD_H - diff --git a/sources/shiboken6/tests/libsample/overloadsort.cpp b/sources/shiboken6/tests/libsample/overloadsort.cpp index 8534ef0f1..a9b4b0972 100644 --- a/sources/shiboken6/tests/libsample/overloadsort.cpp +++ b/sources/shiboken6/tests/libsample/overloadsort.cpp @@ -1,33 +1,43 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "overloadsort.h" +const char *SortedOverload::overload(int) +{ + return "int"; +} + +const char *SortedOverload::overload(double) +{ + return "double"; +} + +const char *SortedOverload::overload(ImplicitBase) +{ + return "ImplicitBase"; +} + +const char *SortedOverload::overload(ImplicitTarget) +{ + return "ImplicitTarget"; +} + +const char *SortedOverload::overload(const std::list<ImplicitBase> &) +{ + return "list(ImplicitBase)"; +} + +int SortedOverload::implicit_overload(const ImplicitBase &) +{ + return 1; +} + +const char *SortedOverload::overloadDeep(int, ImplicitBase &) +{ + return "ImplicitBase"; +} + int CustomOverloadSequence::overload(short v) const { return v + int(sizeof(v)); diff --git a/sources/shiboken6/tests/libsample/overloadsort.h b/sources/shiboken6/tests/libsample/overloadsort.h index ad720222c..ee269cc21 100644 --- a/sources/shiboken6/tests/libsample/overloadsort.h +++ b/sources/shiboken6/tests/libsample/overloadsort.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef OVERLOADSORT_H #define OVERLOADSORT_H @@ -36,52 +11,37 @@ class ImplicitTarget { public: - ImplicitTarget(){} + ImplicitTarget() = default; }; class ImplicitBase { public: - ImplicitBase(){} - ImplicitBase(const ImplicitTarget &b){} + ImplicitBase() = default; + ImplicitBase(const ImplicitTarget &b); }; -class SortedOverload +inline ImplicitBase::ImplicitBase(const ImplicitTarget &) { -public: - - inline const char *overload(int x) { - return "int"; - } - - inline const char *overload(double x) { - return "double"; - } - - inline const char *overload(ImplicitBase x) { - return "ImplicitBase"; - } - - inline const char *overload(ImplicitTarget x) { - return "ImplicitTarget"; - } +} - inline const char *overload(const std::list<ImplicitBase> &x) { - return "list(ImplicitBase)"; - } - - inline int implicit_overload(const ImplicitBase &x) { - return 1; - } +class LIBSAMPLE_API SortedOverload +{ +public: - inline const char *overloadDeep(int x, ImplicitBase &y) { - return "ImplicitBase"; - } + const char *overload(int x); + const char *overload(double x); + const char *overload(ImplicitBase x); + const char *overload(ImplicitTarget x); + const char *overload(const std::list<ImplicitBase> &x); + int implicit_overload(const ImplicitBase &x); - inline const char* pyObjOverload(int, int) { return "int,int"; } - inline const char* pyObjOverload(unsigned char*, int) { return "PyObject,int"; } + const char *overloadDeep(int x, ImplicitBase &y); + inline const char *pyObjOverload(int, int) { return "int,int"; } + inline const char *pyObjOverload(unsigned char *, int) + { return "PyObject,int"; } }; class LIBSAMPLE_API CustomOverloadSequence @@ -92,4 +52,3 @@ public: }; #endif // OVERLOADSORT_H - diff --git a/sources/shiboken6/tests/libsample/pairuser.cpp b/sources/shiboken6/tests/libsample/pairuser.cpp index 661988445..5b7eb4d8c 100644 --- a/sources/shiboken6/tests/libsample/pairuser.cpp +++ b/sources/shiboken6/tests/libsample/pairuser.cpp @@ -1,57 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "pairuser.h" -using namespace std; - -std::pair<int, int> -PairUser::callCreatePair() +std::pair<int, int> PairUser::callCreatePair() { return createPair(); } -std::pair<int, int> -PairUser::createPair() +std::pair<int, int> PairUser::createPair() { - return std::pair<int, int>(10, 20); + return {10, 20}; } -std::pair<Complex, Complex> -PairUser::createComplexPair(Complex cpx0, Complex cpx1) +std::pair<Complex, Complex> PairUser::createComplexPair(Complex cpx0, Complex cpx1) { - return std::pair<Complex, Complex>(cpx0, cpx1); + return {cpx0, cpx1}; } -double -PairUser::sumPair(std::pair<int, double> pair) +double PairUser::sumPair(std::pair<int, double> pair) { return ((double) pair.first) + pair.second; } - diff --git a/sources/shiboken6/tests/libsample/pairuser.h b/sources/shiboken6/tests/libsample/pairuser.h index 37219f724..ee51d818e 100644 --- a/sources/shiboken6/tests/libsample/pairuser.h +++ b/sources/shiboken6/tests/libsample/pairuser.h @@ -1,44 +1,21 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PAIRUSER_H #define PAIRUSER_H -#include <utility> +#include "libsamplemacros.h" #include "complex.h" -#include "libsamplemacros.h" +#include <utility> class LIBSAMPLE_API PairUser { public: - PairUser() {} - virtual ~PairUser() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(PairUser) + + PairUser() noexcept = default; + virtual ~PairUser() = default; virtual std::pair<int, int> createPair(); std::pair<int, int> callCreatePair(); @@ -51,5 +28,5 @@ public: private: std::pair<int, int> m_pair; }; -#endif // PAIRUSER_H +#endif // PAIRUSER_H diff --git a/sources/shiboken6/tests/libsample/pen.cpp b/sources/shiboken6/tests/libsample/pen.cpp index e538a6a49..76473a264 100644 --- a/sources/shiboken6/tests/libsample/pen.cpp +++ b/sources/shiboken6/tests/libsample/pen.cpp @@ -1,42 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "pen.h" -Color::Color() : m_null(true) +Color::Color(SampleNamespace::InValue) : m_null(false) { } -Color::Color(SampleNamespace::InValue arg) : m_null(false) -{ -} - -Color::Color(unsigned int arg) : m_null(false) +Color::Color(unsigned int) : m_null(false) { } @@ -74,28 +45,30 @@ void Brush::setColor(const Color &newColor) m_color = newColor; } -Pen::Pen() : m_ctor(EmptyCtor) -{ -} +Pen::Pen() = default; -Pen::Pen(SampleNamespace::Option option) : m_ctor(EnumCtor) +Pen::Pen(SampleNamespace::Option) : m_ctor(EnumCtor) { } -Pen::Pen(const Color& color) : m_ctor(ColorCtor) +Pen::Pen(const Color &) : m_ctor(ColorCtor) { } -Pen::Pen(const Pen& pen) : m_ctor(CopyCtor) +Pen::Pen(const Pen &) : m_ctor(CopyCtor) { } +Pen::Pen(Pen &&) noexcept = default; +Pen &Pen::operator=(const Pen &pen) = default; +Pen &Pen::operator=(Pen &&) noexcept = default; + int Pen::ctorType() { return m_ctor; } -void Pen::drawLine(int x1, int y1, int x2, int y2, RenderHints renderHints) +void Pen::drawLine(int, int, int, int, RenderHints) { } diff --git a/sources/shiboken6/tests/libsample/pen.h b/sources/shiboken6/tests/libsample/pen.h index 4feb9f540..6f528f0f9 100644 --- a/sources/shiboken6/tests/libsample/pen.h +++ b/sources/shiboken6/tests/libsample/pen.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PEN_H #define PEN_H @@ -35,13 +10,14 @@ class LIBSAMPLE_API Color { public: - Color(); + Color() = default; Color(SampleNamespace::InValue arg); Color(unsigned int arg); bool isNull() const; + private: - bool m_null; + bool m_null = true; }; class LIBSAMPLE_API Brush @@ -73,8 +49,12 @@ public: Pen(); Pen(SampleNamespace::Option option); - Pen(const Color& color); - Pen(const Pen& pen); + Pen(const Color &color); + Pen(const Pen &pen); + Pen(Pen &&) noexcept; + Pen &operator=(const Pen &pen); + Pen &operator=(Pen &&) noexcept; + ~Pen() = default; // PYSIDE-1325, default initializer void drawLine(int x1, int y1, int x2, int y2, RenderHints renderHints = {}); @@ -85,7 +65,7 @@ public: void setRenderHints(RenderHints h); private: - int m_ctor; + int m_ctor = EmptyCtor; RenderHints m_renderHints = None; }; diff --git a/sources/shiboken6/tests/libsample/photon.cpp b/sources/shiboken6/tests/libsample/photon.cpp index e61fd5969..2a7f20e33 100644 --- a/sources/shiboken6/tests/libsample/photon.cpp +++ b/sources/shiboken6/tests/libsample/photon.cpp @@ -1,50 +1,31 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "photon.h" namespace Photon { + const ClassType Base::staticType; -int callCalculateForValueDuplicatorPointer(ValueDuplicator* value) + +int callCalculateForValueDuplicatorPointer(ValueDuplicator *value) { return value->calculate(); } -int callCalculateForValueDuplicatorReference(ValueDuplicator& value) + +int callCalculateForValueDuplicatorReference(ValueDuplicator &value) { return value.calculate(); } -int countValueIdentities(const std::list<ValueIdentity>& values) + +int countValueIdentities(const std::list<ValueIdentity> &values) { return values.size(); } -int countValueDuplicators(const std::list<TemplateBase<DuplicatorType> >& values) + +int countValueDuplicators(const std::list<TemplateBase<DuplicatorType> > &values) { return values.size(); } + } // namespace Photon diff --git a/sources/shiboken6/tests/libsample/photon.h b/sources/shiboken6/tests/libsample/photon.h index 1dcb4f83e..2debe47d1 100644 --- a/sources/shiboken6/tests/libsample/photon.h +++ b/sources/shiboken6/tests/libsample/photon.h @@ -1,37 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PHOTON_H #define PHOTON_H -#include <list> #include "libsamplemacros.h" +#include <list> + // This namespace and classes simulate // situations found in Qt's phonon module. @@ -47,8 +23,11 @@ enum ClassType { class LIBSAMPLE_API Base { public: - explicit Base(int value) : m_value(value) {} - virtual ~Base() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(Base) + + explicit Base(int value) noexcept : m_value(value) {} + virtual ~Base() = default; + inline void setValue(int value) { m_value = value; } inline int value() const { return m_value; } @@ -67,12 +46,14 @@ class LIBSAMPLE_API TemplateBase : public Base { public: explicit TemplateBase(int value) : Base(value) {} - inline int multiplicator() const { return (int)CLASS_TYPE; } - inline int calculate() const { return m_value * ((int)CLASS_TYPE); } + inline int multiplicator() const { return int(CLASS_TYPE); } + inline int calculate() const { return m_value * (int(CLASS_TYPE)); } static inline ClassType classType() { return CLASS_TYPE; } - inline int sumValueUsingPointer(TemplateBase<CLASS_TYPE>* other) const { return m_value + other->m_value; } - inline int sumValueUsingReference(TemplateBase<CLASS_TYPE>& other) const { return m_value + other.m_value; } + inline int sumValueUsingPointer(TemplateBase<CLASS_TYPE> *other) const + { return m_value + other->m_value; } + inline int sumValueUsingReference(TemplateBase<CLASS_TYPE> &other) const + { return m_value + other.m_value; } inline std::list<TemplateBase<CLASS_TYPE> > getListOfThisTemplateBase() { @@ -82,7 +63,8 @@ public: return objs; } - static inline TemplateBase<CLASS_TYPE>* passPointerThrough(TemplateBase<CLASS_TYPE>* obj) { return obj; } + static inline TemplateBase<CLASS_TYPE> *passPointerThrough(TemplateBase<CLASS_TYPE> *obj) + { return obj; } ClassType type() const override { return CLASS_TYPE; } static const ClassType staticType = CLASS_TYPE; @@ -96,43 +78,31 @@ template class LIBSAMPLE_API TemplateBase<DuplicatorType>; using ValueIdentity = TemplateBase<IdentityType>; using ValueDuplicator = TemplateBase<DuplicatorType>; -LIBSAMPLE_API int callCalculateForValueDuplicatorPointer(ValueDuplicator* value); -LIBSAMPLE_API int callCalculateForValueDuplicatorReference(ValueDuplicator& value); -LIBSAMPLE_API int countValueIdentities(const std::list<ValueIdentity>& values); -LIBSAMPLE_API int countValueDuplicators(const std::list<TemplateBase<DuplicatorType> >& values); - -// This simulates an internal error (SEGV) caused by 'noexcept' in -// boost::intrusive_ptr before support for 'noexcept' was added. The ENTIRE -// code below is needed to trigger the exception; it isn't seen with just a -// 'noexcept' following a declaration. -// -// NOTE: For reasons that should be fairly obvious, this test unfortunately can -// only be "run" when building in C++11 mode. -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) -# define PHOTON_NOEXCEPT noexcept -#else -# define PHOTON_NOEXCEPT -#endif +LIBSAMPLE_API int callCalculateForValueDuplicatorPointer(ValueDuplicator *value); +LIBSAMPLE_API int callCalculateForValueDuplicatorReference(ValueDuplicator &value); +LIBSAMPLE_API int countValueIdentities(const std::list<ValueIdentity> &values); +LIBSAMPLE_API int countValueDuplicators(const std::list<TemplateBase<DuplicatorType> > &values); + class Pointer { public: - Pointer() PHOTON_NOEXCEPT : px(nullptr) {} - Pointer(int* p) : px(p) {} + Pointer() noexcept = default; + explicit Pointer(int *p) : px(p) {} - void reset() PHOTON_NOEXCEPT { Pointer().swap(*this); } + void reset() noexcept { Pointer().swap(*this); } - int* get() const PHOTON_NOEXCEPT { return px; } - int& operator*() const { return *px; } + int *get() const noexcept { return px; } + int &operator*() const { return *px; } - void swap(Pointer& rhs) PHOTON_NOEXCEPT + void swap(Pointer &rhs) noexcept { - int* tmp = px; + int *tmp = px; px = rhs.px; rhs.px = tmp; } private: - int* px; + int *px = nullptr; }; } // namespace Photon diff --git a/sources/shiboken6/tests/libsample/point.cpp b/sources/shiboken6/tests/libsample/point.cpp index 75e015e07..b8630eb1e 100644 --- a/sources/shiboken6/tests/libsample/point.cpp +++ b/sources/shiboken6/tests/libsample/point.cpp @@ -1,46 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "point.h" -using namespace std; +#include <iostream> -Point::Point(int x, int y) : m_x(x), m_y(y) +Point::Point(int x, int y) noexcept : m_x(x), m_y(y) { } -Point::Point(double x, double y) : m_x(x), m_y(y) +Point::Point(double x, double y) noexcept : m_x(x), m_y(y) { } -void -Point::midpoint(const Point& other, Point* midpoint) const +void Point::midpoint(const Point &other, Point *midpoint) const { if (!midpoint) return; @@ -48,108 +21,91 @@ Point::midpoint(const Point& other, Point* midpoint) const midpoint->setY((m_y + other.m_y) / 2.0); } -Point* -Point::copy() const +Point *Point::copy() const { - Point* pt = new Point(); + Point *pt = new Point(); pt->m_x = m_x; pt->m_y = m_y; return pt; } -void -Point::show() +void Point::show() const { - cout << "(x: " << m_x << ", y: " << m_y << ")"; + std::cout << "(x: " << m_x << ", y: " << m_y << ")"; } -bool -Point::operator==(const Point& other) +bool Point::operator==(const Point &other) { return m_x == other.m_x && m_y == other.m_y; } -Point -Point::operator+(const Point& other) +Point Point::operator+(const Point &other) { - return Point(m_x + other.m_x, m_y + other.m_y); + return {m_x + other.m_x, m_y + other.m_y}; } -Point -Point::operator-(const Point& other) +Point Point::operator-(const Point &other) { - return Point(m_x - other.m_x, m_y - other.m_y); + return {m_x - other.m_x, m_y - other.m_y}; } -Point& -Point::operator+=(Point &other) +Point &Point::operator+=(Point &other) { m_x += other.m_x; m_y += other.m_y; return *this; } -Point& -Point::operator-=(Point &other) +Point &Point::operator-=(Point &other) { m_x -= other.m_x; m_y -= other.m_y; return *this; } -Point -operator*(const Point& pt, double mult) +Point operator*(const Point &pt, double mult) { return Point(pt.m_x * mult, pt.m_y * mult); } -Point -operator*(const Point& pt, int mult) +Point operator*(const Point &pt, int mult) { - return Point(((int) pt.m_x) * mult, ((int) pt.m_y) * mult); + return {int(pt.m_x) * mult, int(pt.m_y) * mult}; } -Point -operator*(double mult, const Point& pt) +Point operator*(double mult, const Point &pt) { - return Point(pt.m_x * mult, pt.m_y * mult); + return {pt.m_x * mult, pt.m_y * mult}; } -Point -operator*(int mult, const Point& pt) +Point operator*(int mult, const Point &pt) { - return Point(((int) pt.m_x) * mult, ((int) pt.m_y) * mult); + return {int(pt.m_x) * mult, int(pt.m_y) * mult}; } -Point -operator-(const Point& pt) +Point operator-(const Point &pt) { - return Point(-pt.m_x, -pt.m_y); + return {-pt.m_x, -pt.m_y}; } -bool -operator!(const Point& pt) +bool operator!(const Point &pt) { - return (pt.m_x == 0.0 && pt.m_y == 0.0); + return pt.m_x == 0.0 && pt.m_y == 0.0; } -Point -Point::operator/(int operand) +Point Point::operator/(int operand) { - return Point(m_x/operand, m_y/operand); + return {m_x/operand, m_y/operand}; } -Complex -transmutePointIntoComplex(const Point& point) +Complex transmutePointIntoComplex(const Point &point) { Complex cpx(point.x(), point.y()); return cpx; } -Point -transmuteComplexIntoPoint(const Complex& cpx) +Point transmuteComplexIntoPoint(const Complex &cpx) { Point pt(cpx.real(), cpx.imag()); return pt; } - diff --git a/sources/shiboken6/tests/libsample/point.h b/sources/shiboken6/tests/libsample/point.h index 579bcd515..59e0236d5 100644 --- a/sources/shiboken6/tests/libsample/point.h +++ b/sources/shiboken6/tests/libsample/point.h @@ -1,45 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef POINT_H #define POINT_H +#include "libsamplemacros.h" #include "complex.h" -#include <utility> -#include "libsamplemacros.h" +#include <utility> class LIBSAMPLE_API Point { public: - Point(int x = 0, int y = 0); - Point(double x, double y); - ~Point() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(Point) + + Point(int x = 0, int y = 0) noexcept; + Point(double x, double y) noexcept; + ~Point() = default; inline double x() const { return m_x; } inline double y() const { return m_y; } @@ -52,48 +29,48 @@ public: // This method could simply return the midpoint, // but the interesting part of the test is to set the // result in the pointer argument. - void midpoint(const Point& other, Point* midpoint) const; + void midpoint(const Point &other, Point *midpoint) const; - Point* copy() const; + Point *copy() const; - inline const Point& getConstReferenceToSelf() const { return *this; } - inline const Point* getSelf() const { return this; } + inline const Point &getConstReferenceToSelf() const { return *this; } + inline const Point *getSelf() const { return this; } // The != operator is not implemented for the purpose of testing // for the absense of the __ne__ method in the Python binding. - bool operator==(const Point& other); + bool operator==(const Point &other); - Point operator+(const Point& other); - Point operator-(const Point& other); + Point operator+(const Point &other); + Point operator-(const Point &other); Point operator/(int operand); - friend LIBSAMPLE_API Point operator*(const Point& pt, double mult); - friend LIBSAMPLE_API Point operator*(const Point& pt, int mult); - friend LIBSAMPLE_API Point operator*(double mult, const Point& pt); - friend LIBSAMPLE_API Point operator*(int mult, const Point& pt); - friend LIBSAMPLE_API Point operator-(const Point& pt); - friend LIBSAMPLE_API bool operator!(const Point& pt); + friend LIBSAMPLE_API Point operator*(const Point &pt, double mult); + friend LIBSAMPLE_API Point operator*(const Point &pt, int mult); + friend LIBSAMPLE_API Point operator*(double mult, const Point &pt); + friend LIBSAMPLE_API Point operator*(int mult, const Point &pt); + friend LIBSAMPLE_API Point operator-(const Point &pt); + friend LIBSAMPLE_API bool operator!(const Point &pt); - Point& operator+=(Point &other); - Point& operator-=(Point &other); + Point &operator+=(Point &other); + Point &operator-=(Point &other); - void show(); + void show() const; private: double m_x; double m_y; }; -LIBSAMPLE_API Point operator*(const Point& pt, double mult); -LIBSAMPLE_API Point operator*(const Point& pt, int mult); -LIBSAMPLE_API Point operator*(double mult, const Point& pt); -LIBSAMPLE_API Point operator*(int mult, const Point& pt); -LIBSAMPLE_API Point operator-(const Point& pt); -LIBSAMPLE_API bool operator!(const Point& pt); +LIBSAMPLE_API Point operator*(const Point &pt, double mult); +LIBSAMPLE_API Point operator*(const Point &pt, int mult); +LIBSAMPLE_API Point operator*(double mult, const Point &pt); +LIBSAMPLE_API Point operator*(int mult, const Point &pt); +LIBSAMPLE_API Point operator-(const Point &pt); +LIBSAMPLE_API bool operator!(const Point &pt); -LIBSAMPLE_API Complex transmutePointIntoComplex(const Point& point); -LIBSAMPLE_API Point transmuteComplexIntoPoint(const Complex& cpx); +LIBSAMPLE_API Complex transmutePointIntoComplex(const Point &point); +LIBSAMPLE_API Point transmuteComplexIntoPoint(const Complex &cpx); -LIBSAMPLE_API Point operator*(const Point& pt, double multiplier); +LIBSAMPLE_API Point operator*(const Point &pt, double multiplier); #endif // POINT_H diff --git a/sources/shiboken6/tests/libsample/pointerholder.h b/sources/shiboken6/tests/libsample/pointerholder.h index b872ceb5c..26f1cf0a6 100644 --- a/sources/shiboken6/tests/libsample/pointerholder.h +++ b/sources/shiboken6/tests/libsample/pointerholder.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef POINTERHOLDER_H #define POINTERHOLDER_H @@ -34,12 +9,15 @@ class PointerHolder { public: - explicit PointerHolder(void* ptr) : m_pointer(ptr) {} - ~PointerHolder() {} - inline void* pointer() const { return m_pointer; } + LIBMINIMAL_DEFAULT_COPY_MOVE(PointerHolder) + + explicit PointerHolder(void *ptr) : m_pointer(ptr) {} + ~PointerHolder() = default; + + inline void *pointer() const { return m_pointer; } + private: - void* m_pointer; + void *m_pointer; }; #endif // POINTERHOLDER_H - diff --git a/sources/shiboken6/tests/libsample/pointf.cpp b/sources/shiboken6/tests/libsample/pointf.cpp index fadf3e591..6b39f73a9 100644 --- a/sources/shiboken6/tests/libsample/pointf.cpp +++ b/sources/shiboken6/tests/libsample/pointf.cpp @@ -1,46 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "pointf.h" -using namespace std; +#include <iostream> -PointF::PointF(const Point& point) : m_x(point.x()), m_y(point.y()) +PointF::PointF(const Point &point) noexcept : m_x(point.x()), m_y(point.y()) { } -PointF::PointF(double x, double y) : m_x(x), m_y(y) +PointF::PointF(double x, double y) noexcept : m_x(x), m_y(y) { } -void -PointF::midpoint(const PointF& other, PointF* midpoint) const +void PointF::midpoint(const PointF &other, PointF *midpoint) const { if (!midpoint) return; @@ -48,79 +21,66 @@ PointF::midpoint(const PointF& other, PointF* midpoint) const midpoint->setY((m_y + other.m_y) / 2.0); } -void -PointF::show() +void PointF::show() const { - cout << "(x: " << m_x << ", y: " << m_y << ")"; + std::cout << "(x: " << m_x << ", y: " << m_y << ")"; } -bool -PointF::operator==(const PointF& other) +bool PointF::operator==(const PointF &other) { return m_x == other.m_x && m_y == other.m_y; } -PointF -PointF::operator+(const PointF& other) +PointF PointF::operator+(const PointF &other) { - return PointF(m_x + other.m_x, m_y + other.m_y); + return {m_x + other.m_x, m_y + other.m_y}; } -PointF -PointF::operator-(const PointF& other) +PointF PointF::operator-(const PointF &other) { - return PointF(m_x - other.m_x, m_y - other.m_y); + return {m_x - other.m_x, m_y - other.m_y}; } -PointF& -PointF::operator+=(PointF &other) +PointF &PointF::operator+=(PointF &other) { m_x += other.m_x; m_y += other.m_y; return *this; } -PointF& -PointF::operator-=(PointF &other) +PointF &PointF::operator-=(PointF &other) { m_x -= other.m_x; m_y -= other.m_y; return *this; } -PointF -operator*(const PointF& pt, double mult) +PointF operator*(const PointF &pt, double mult) { - return PointF(pt.m_x * mult, pt.m_y * mult); + return {pt.m_x * mult, pt.m_y * mult}; } -PointF -operator*(const PointF& pt, int mult) +PointF operator*(const PointF &pt, int mult) { - return PointF(((int) pt.m_x) * mult, ((int) pt.m_y) * mult); + return PointF(int(pt.m_x) * mult, int(pt.m_y) * mult); } -PointF -operator*(double mult, const PointF& pt) +PointF operator*(double mult, const PointF &pt) { - return PointF(pt.m_x * mult, pt.m_y * mult); + return {pt.m_x * mult, pt.m_y * mult}; } -PointF -operator*(int mult, const PointF& pt) +PointF operator*(int mult, const PointF &pt) { - return PointF(((int) pt.m_x) * mult, ((int) pt.m_y) * mult); + return PointF(int(pt.m_x) * mult, int(pt.m_y) * mult); } -PointF -operator-(const PointF& pt) +PointF operator-(const PointF &pt) { - return PointF(-pt.m_x, -pt.m_y); + return {-pt.m_x, -pt.m_y}; } -bool -operator!(const PointF& pt) +bool operator!(const PointF &pt) { - return (pt.m_x == 0.0 && pt.m_y == 0.0); + return pt.m_x == 0.0 && pt.m_y == 0.0; } - diff --git a/sources/shiboken6/tests/libsample/pointf.h b/sources/shiboken6/tests/libsample/pointf.h index f90125c8a..bb50b5c6d 100644 --- a/sources/shiboken6/tests/libsample/pointf.h +++ b/sources/shiboken6/tests/libsample/pointf.h @@ -1,45 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef POINTF_H #define POINTF_H +#include "libsamplemacros.h" #include "point.h" -#include <utility> -#include "libsamplemacros.h" +#include <utility> class LIBSAMPLE_API PointF { public: - PointF(const Point& point); - PointF(double x = 0.0, double y = 0.0); - ~PointF() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(PointF) + + PointF(const Point &point) noexcept; + PointF(double x = 0.0, double y = 0.0) noexcept; + ~PointF() noexcept = default; inline double x() const { return m_x; } inline double y() const { return m_y; } @@ -50,39 +27,39 @@ public: // This method could simply return the midpoint, // but the interesting part of the test is to set the // result in the pointer argument. - void midpoint(const PointF& other, PointF* midpoint) const; + void midpoint(const PointF &other, PointF *midpoint) const; // The != operator is not implemented for the purpose of testing // for the absence of the __ne__ method in the Python binding. - bool operator==(const PointF& other); + bool operator==(const PointF &other); - PointF operator+(const PointF& other); - PointF operator-(const PointF& other); + PointF operator+(const PointF &other); + PointF operator-(const PointF &other); - friend LIBSAMPLE_API PointF operator*(const PointF& pt, double mult); - friend LIBSAMPLE_API PointF operator*(const PointF& pt, int mult); - friend LIBSAMPLE_API PointF operator*(double mult, const PointF& pt); - friend LIBSAMPLE_API PointF operator*(int mult, const PointF& pt); - friend LIBSAMPLE_API PointF operator-(const PointF& pt); - friend LIBSAMPLE_API bool operator!(const PointF& pt); + friend LIBSAMPLE_API PointF operator*(const PointF &pt, double mult); + friend LIBSAMPLE_API PointF operator*(const PointF &pt, int mult); + friend LIBSAMPLE_API PointF operator*(double mult, const PointF &pt); + friend LIBSAMPLE_API PointF operator*(int mult, const PointF &pt); + friend LIBSAMPLE_API PointF operator-(const PointF &pt); + friend LIBSAMPLE_API bool operator!(const PointF &pt); - PointF& operator+=(PointF &other); - PointF& operator-=(PointF &other); + PointF &operator+=(PointF &other); + PointF &operator-=(PointF &other); - void show(); + void show() const; private: double m_x; double m_y; }; -LIBSAMPLE_API PointF operator*(const PointF& pt, double mult); -LIBSAMPLE_API PointF operator*(const PointF& pt, int mult); -LIBSAMPLE_API PointF operator*(double mult, const PointF& pt); -LIBSAMPLE_API PointF operator*(int mult, const PointF& pt); -LIBSAMPLE_API PointF operator-(const PointF& pt); -LIBSAMPLE_API bool operator!(const PointF& pt); +LIBSAMPLE_API PointF operator*(const PointF &pt, double mult); +LIBSAMPLE_API PointF operator*(const PointF &pt, int mult); +LIBSAMPLE_API PointF operator*(double mult, const PointF &pt); +LIBSAMPLE_API PointF operator*(int mult, const PointF &pt); +LIBSAMPLE_API PointF operator-(const PointF &pt); +LIBSAMPLE_API bool operator!(const PointF &pt); -LIBSAMPLE_API PointF operator*(const PointF& pt, double multiplier); +LIBSAMPLE_API PointF operator*(const PointF &pt, double multiplier); #endif // POINTF_H diff --git a/sources/shiboken6/tests/libsample/polygon.cpp b/sources/shiboken6/tests/libsample/polygon.cpp index a86bf6483..6af597192 100644 --- a/sources/shiboken6/tests/libsample/polygon.cpp +++ b/sources/shiboken6/tests/libsample/polygon.cpp @@ -1,59 +1,26 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "polygon.h" -using namespace std; - -Polygon::Polygon(double x, double y) +Polygon::Polygon(double x, double y) : m_points({Point(x, y)}) { - m_points.push_back(Point(x, y)); } -Polygon::Polygon(Point point) +Polygon::Polygon(Point point) : m_points({point}) { - m_points.push_back(point); } -Polygon::Polygon(PointList points) +Polygon::Polygon(PointList points) : m_points(points) { - m_points = points; } -void -Polygon::addPoint(Point point) +void Polygon::addPoint(Point point) { m_points.push_back(point); } -Polygon -Polygon::doublePolygonScale(Polygon polygon) +Polygon Polygon::doublePolygonScale(Polygon polygon) { Polygon result; for (const auto &point : polygon.points()) @@ -61,15 +28,12 @@ Polygon::doublePolygonScale(Polygon polygon) return result; } -void -Polygon::stealOwnershipFromPython(Point* point) +void Polygon::stealOwnershipFromPython(Point *point) { delete point; } -void -Polygon::stealOwnershipFromPython(Polygon* polygon) +void Polygon::stealOwnershipFromPython(Polygon *polygon) { delete polygon; } - diff --git a/sources/shiboken6/tests/libsample/polygon.h b/sources/shiboken6/tests/libsample/polygon.h index 728332d1a..2424ddd51 100644 --- a/sources/shiboken6/tests/libsample/polygon.h +++ b/sources/shiboken6/tests/libsample/polygon.h @@ -1,66 +1,39 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef POLYGON_H #define POLYGON_H -#include <list> +#include "libsamplemacros.h" #include "point.h" -#include "libsamplemacros.h" +#include <list> -class LIBSAMPLE_API Polygon +class LIBSAMPLE_API Polygon // should be moveable { public: using PointList = std::list<Point>; - Polygon() {} + Polygon() noexcept = default; Polygon(double x, double y); Polygon(Point point); Polygon(PointList points); - ~Polygon() {} void addPoint(Point point); - inline const PointList& points() const { return m_points; } + inline const PointList &points() const { return m_points; } // This method intentionally receives and returns copies of a Polygon object. static Polygon doublePolygonScale(Polygon polygon); // This method invalidates the argument to be used for Polygon(Point) implicit conversion. - static void stealOwnershipFromPython(Point* point); + static void stealOwnershipFromPython(Point *point); // This method invalidates the argument to be used in a call to doublePolygonScale(Polygon). - static void stealOwnershipFromPython(Polygon* polygon); + static void stealOwnershipFromPython(Polygon *polygon); private: PointList m_points; }; #endif // POLYGON_H - diff --git a/sources/shiboken6/tests/libsample/privatector.h b/sources/shiboken6/tests/libsample/privatector.h index f168fdacd..3b38414f8 100644 --- a/sources/shiboken6/tests/libsample/privatector.h +++ b/sources/shiboken6/tests/libsample/privatector.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PRIVATECTOR_H #define PRIVATECTOR_H @@ -34,22 +9,34 @@ class PrivateCtor { public: - inline static PrivateCtor* instance() + inline static PrivateCtor *instance() { static PrivateCtor self; - self.m_instanciations++; + self.m_instantiations++; return &self; } inline int instanceCalls() { - return m_instanciations; + return m_instantiations; } private: - int m_instanciations; + int m_instantiations = 0; - PrivateCtor() : m_instanciations(0) {} + PrivateCtor() = default; }; -#endif +class DeletedDefaultCtor +{ +public: + DeletedDefaultCtor() = delete; + + DeletedDefaultCtor(const DeletedDefaultCtor &) = default; + DeletedDefaultCtor(DeletedDefaultCtor &&) = default; + DeletedDefaultCtor &operator=(const DeletedDefaultCtor &) = default; + DeletedDefaultCtor &operator=(DeletedDefaultCtor &&) = default; + ~DeletedDefaultCtor() = default; +}; + +#endif // PRIVATECTOR_H diff --git a/sources/shiboken6/tests/libsample/privatedtor.h b/sources/shiboken6/tests/libsample/privatedtor.h index 64b8652f6..05f18ea53 100644 --- a/sources/shiboken6/tests/libsample/privatedtor.h +++ b/sources/shiboken6/tests/libsample/privatedtor.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PRIVATEDTOR_H #define PRIVATEDTOR_H @@ -34,27 +9,28 @@ class PrivateDtor { public: - inline static PrivateDtor* instance() + LIBMINIMAL_DISABLE_COPY_MOVE(PrivateDtor) + + inline static PrivateDtor *instance() { static PrivateDtor self; - self.m_instanciations++; + self.m_instantiations++; return &self; } inline int instanceCalls() { - return m_instanciations; + return m_instantiations; } protected: - inline int protectedInstanceCalls() { return m_instanciations; } + inline int protectedInstanceCalls() { return m_instantiations; } private: - int m_instanciations; + int m_instantiations = 0; - PrivateDtor() : m_instanciations(0) {} - PrivateDtor(const PrivateDtor&) {} - ~PrivateDtor() {} + PrivateDtor() noexcept = default; + ~PrivateDtor() = default; }; -#endif +#endif // PRIVATEDTOR_H diff --git a/sources/shiboken6/tests/libsample/protected.cpp b/sources/shiboken6/tests/libsample/protected.cpp index b0f3f1cdc..7ab52d22b 100644 --- a/sources/shiboken6/tests/libsample/protected.cpp +++ b/sources/shiboken6/tests/libsample/protected.cpp @@ -1,32 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "protected.h" int ProtectedVirtualDestructor::dtor_called = 0; +const char *ProtectedNonPolymorphic::dataTypeName(void *) const +{ + return "pointer"; +} + +const char *ProtectedNonPolymorphic::dataTypeName(int) const +{ + return "integer"; +} diff --git a/sources/shiboken6/tests/libsample/protected.h b/sources/shiboken6/tests/libsample/protected.h index 0f4fbf299..059cced5d 100644 --- a/sources/shiboken6/tests/libsample/protected.h +++ b/sources/shiboken6/tests/libsample/protected.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef PROTECTED_H #define PROTECTED_H @@ -32,26 +7,30 @@ #include "libsamplemacros.h" #include "objecttype.h" #include "point.h" + #include <string> #include <list> class LIBSAMPLE_API ProtectedNonPolymorphic { public: + LIBMINIMAL_DEFAULT_COPY_MOVE(ProtectedNonPolymorphic) + explicit ProtectedNonPolymorphic(const char *name) : m_name(name) {} - ~ProtectedNonPolymorphic() {} + ~ProtectedNonPolymorphic() = default; - inline const char* publicName() { return m_name.c_str(); } + inline const char *publicName() { return m_name.c_str(); } - inline static ProtectedNonPolymorphic* create() { return new ProtectedNonPolymorphic("created"); } + inline static ProtectedNonPolymorphic *create() + { return new ProtectedNonPolymorphic("created"); } protected: - inline const char* protectedName() { return m_name.c_str(); } + inline const char *protectedName() { return m_name.c_str(); } inline int protectedSum(int a0, int a1) { return a0 + a1; } inline int modifiedProtectedSum(int a0, int a1) { return a0 + a1; } - inline static const char* protectedStatic() { return "protectedStatic"; } - inline const char* dataTypeName(void *data = nullptr) const { return "pointer"; } - inline const char* dataTypeName(int data) const { return "integer"; } + inline static const char *protectedStatic() { return "protectedStatic"; } + const char *dataTypeName(void *data = nullptr) const; + const char *dataTypeName(int data) const; private: std::string m_name; @@ -60,15 +39,18 @@ private: class LIBSAMPLE_API ProtectedPolymorphic { public: + LIBMINIMAL_DEFAULT_COPY_MOVE(ProtectedPolymorphic) + explicit ProtectedPolymorphic(const char *name) : m_name(name) {} - virtual ~ProtectedPolymorphic() {} + virtual ~ProtectedPolymorphic() = default; - inline static ProtectedPolymorphic* create() { return new ProtectedPolymorphic("created"); } - inline const char* publicName() { return m_name.c_str(); } - inline const char* callProtectedName() { return protectedName(); } + inline static ProtectedPolymorphic *create() + { return new ProtectedPolymorphic("created"); } + inline const char *publicName() { return m_name.c_str(); } + inline const char *callProtectedName() { return protectedName(); } protected: - virtual const char* protectedName() { return m_name.c_str(); } + virtual const char *protectedName() { return m_name.c_str(); } private: std::string m_name; @@ -77,22 +59,29 @@ private: class LIBSAMPLE_API ProtectedPolymorphicDaughter : public ProtectedPolymorphic { public: - explicit ProtectedPolymorphicDaughter(const char *name) : ProtectedPolymorphic(name) {} - inline static ProtectedPolymorphicDaughter* create() { return new ProtectedPolymorphicDaughter("created"); } + explicit ProtectedPolymorphicDaughter(const char *name) : + ProtectedPolymorphic(name) {} + inline static ProtectedPolymorphicDaughter *create() + { return new ProtectedPolymorphicDaughter("created"); } }; class LIBSAMPLE_API ProtectedPolymorphicGrandDaughter: public ProtectedPolymorphicDaughter { public: - explicit ProtectedPolymorphicGrandDaughter(const char *name) : ProtectedPolymorphicDaughter(name) {} - inline static ProtectedPolymorphicGrandDaughter* create() { return new ProtectedPolymorphicGrandDaughter("created"); } + explicit ProtectedPolymorphicGrandDaughter(const char *name) : + ProtectedPolymorphicDaughter(name) {} + inline static ProtectedPolymorphicGrandDaughter *create() + { return new ProtectedPolymorphicGrandDaughter("created"); } }; class LIBSAMPLE_API ProtectedVirtualDestructor { public: - ProtectedVirtualDestructor() {} - inline static ProtectedVirtualDestructor* create() { return new ProtectedVirtualDestructor(); } + LIBMINIMAL_DISABLE_COPY_MOVE(ProtectedVirtualDestructor) + + ProtectedVirtualDestructor() noexcept = default; + inline static ProtectedVirtualDestructor *create() + { return new ProtectedVirtualDestructor(); } inline static int dtorCalled() { return dtor_called; } inline static void resetDtorCounter() { dtor_called = 0; } protected: @@ -104,8 +93,10 @@ private: class LIBSAMPLE_API ProtectedEnumClass { public: - ProtectedEnumClass() {} - virtual ~ProtectedEnumClass() {} + LIBMINIMAL_DISABLE_COPY_MOVE(ProtectedEnumClass) + + ProtectedEnumClass() noexcept = default; + virtual ~ProtectedEnumClass() = default; enum PublicEnum { PublicItem0, PublicItem1 @@ -115,36 +106,33 @@ protected: ProtectedItem0, ProtectedItem1 }; - ProtectedEnum callProtectedEnumMethod(ProtectedEnum in) { return protectedEnumMethod(in); } - inline PublicEnum callPublicEnumMethod(PublicEnum in) { return publicEnumMethod(in); } + ProtectedEnum callProtectedEnumMethod(ProtectedEnum in) + { return protectedEnumMethod(in); } + inline PublicEnum callPublicEnumMethod(PublicEnum in) + { return publicEnumMethod(in); } virtual ProtectedEnum protectedEnumMethod(ProtectedEnum in) { return in; } virtual PublicEnum publicEnumMethod(PublicEnum in) { return in; } }; - class LIBSAMPLE_API ProtectedProperty { public: - ProtectedProperty() - : protectedValueTypeProperty(Point(0, 0)), - protectedProperty(0), - protectedEnumProperty(Event::NO_EVENT), - protectedValueTypePointerProperty(nullptr), - protectedObjectTypeProperty(nullptr) - {} + ProtectedProperty() = default; + protected: // This is deliberately the first member to test wrapper registration // for value type members sharing the same memory address. - Point protectedValueTypeProperty; - int protectedProperty; + Point protectedValueTypeProperty{0, 0}; + int protectedProperty = 0; std::list<int> protectedContainerProperty; - Event::EventType protectedEnumProperty; - Point* protectedValueTypePointerProperty; - ObjectType* protectedObjectTypeProperty; + Event::EventType protectedEnumProperty = Event::NO_EVENT; + Point *protectedValueTypePointerProperty = nullptr; + ObjectType *protectedObjectTypeProperty = nullptr; }; -LIBSAMPLE_API inline ProtectedProperty* createProtectedProperty() { +LIBSAMPLE_API inline ProtectedProperty *createProtectedProperty() +{ return new ProtectedProperty; } diff --git a/sources/shiboken6/tests/libsample/rect.h b/sources/shiboken6/tests/libsample/rect.h index 1897a8dce..53296d26c 100644 --- a/sources/shiboken6/tests/libsample/rect.h +++ b/sources/shiboken6/tests/libsample/rect.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef RECT_H #define RECT_H @@ -34,53 +9,46 @@ class LIBSAMPLE_API Rect { public: - Rect() - { - m_left = m_top = 0; - m_right = m_bottom = -1; - } - Rect(int left, int top, int right, int bottom) + LIBMINIMAL_DEFAULT_COPY_MOVE(Rect) + + Rect() noexcept = default; + explicit Rect(int left, int top, int right, int bottom) noexcept : m_left(left), m_top(top), m_right(right), m_bottom(bottom) { } - ~Rect() {} + ~Rect() = default; + inline int left() const { return m_left; } inline int top() const { return m_top; } inline int right() const { return m_right; } inline int bottom() const { return m_bottom; } private: - int m_left; - int m_top; - int m_right; - int m_bottom; + int m_left = 0; + int m_top = 0; + int m_right = -1; + int m_bottom = -1; }; class LIBSAMPLE_API RectF { public: - RectF() - { - m_left = m_top = 0; - m_right = m_bottom = -1; - } - RectF(int left, int top, int right, int bottom) + LIBMINIMAL_DEFAULT_COPY_MOVE(RectF) + + RectF() noexcept = default; + explicit RectF(int left, int top, int right, int bottom) noexcept : m_left(left), m_top(top), m_right(right), m_bottom(bottom) { } - RectF(const Rect& other) - { - m_left = other.left(); - m_top = other.top(); - m_right = other.right(); - m_bottom = other.bottom(); - } - ~RectF() {} + RectF(const Rect &other) noexcept : + m_left(other.left()), m_top(other.top()), + m_right(other.right()), m_bottom(other.bottom()) {} + ~RectF() = default; + inline double left() const { return m_left; } inline double top() const { return m_top; } inline double right() const { return m_right; } inline double bottom() const { return m_bottom; } private: - double m_left; - double m_top; - double m_right; - double m_bottom; + double m_left = 0; + double m_top = 0; + double m_right = -1; + double m_bottom = -1; }; #endif // RECT_H - diff --git a/sources/shiboken6/tests/libsample/reference.cpp b/sources/shiboken6/tests/libsample/reference.cpp index 37ce1a590..29dcfc054 100644 --- a/sources/shiboken6/tests/libsample/reference.cpp +++ b/sources/shiboken6/tests/libsample/reference.cpp @@ -1,78 +1,53 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "reference.h" -using namespace std; +#include <iostream> + +void Reference::show() const +{ + std::cout << "Reference.objId: " << m_objId << ", address: " << this; +} -void -Reference::show() const +Reference &Reference::returnMySecondArg(int, Reference &ref) { - cout << "Reference.objId: " << m_objId << ", address: " << this; + return ref; } -int -Reference::usesReferenceVirtual(Reference& r, int inc) +int Reference::usesReferenceVirtual(Reference &r, int inc) { return r.m_objId + inc; } -int -Reference::usesConstReferenceVirtual(const Reference& r, int inc) +int Reference::usesConstReferenceVirtual(const Reference &r, int inc) { return r.m_objId + inc; } -int -Reference::callUsesReferenceVirtual(Reference& r, int inc) +int Reference::callUsesReferenceVirtual(Reference &r, int inc) { return usesReferenceVirtual(r, inc); } -int -Reference::callUsesConstReferenceVirtual(const Reference& r, int inc) +int Reference::callUsesConstReferenceVirtual(const Reference &r, int inc) { return usesConstReferenceVirtual(r, inc); } -void -Reference::alterReferenceIdVirtual(Reference& r) +void Reference::alterReferenceIdVirtual(Reference &r) { r.setObjId(r.objId() * Reference::multiplier()); } -void -Reference::callAlterReferenceIdVirtual(Reference& r) +void Reference::callAlterReferenceIdVirtual(Reference &r) { alterReferenceIdVirtual(r); } -ObjTypeReference::~ObjTypeReference() +ObjTypeReference::~ObjTypeReference() = default; + +ObjTypeReference &ObjTypeReference::returnMySecondArg(int, ObjTypeReference &ref) { + return ref; } diff --git a/sources/shiboken6/tests/libsample/reference.h b/sources/shiboken6/tests/libsample/reference.h index 2c0498c6f..52818d9ea 100644 --- a/sources/shiboken6/tests/libsample/reference.h +++ b/sources/shiboken6/tests/libsample/reference.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef REFERENCE_H #define REFERENCE_H @@ -34,34 +9,37 @@ class LIBSAMPLE_API Reference { public: - explicit Reference(int objId = -1) + LIBMINIMAL_DEFAULT_COPY_MOVE(Reference) + + explicit Reference(int objId = -1) noexcept : m_objId(objId) {} - virtual ~Reference() {} + virtual ~Reference() = default; - inline int objId() { return m_objId; } + inline int objId() const { return m_objId; } inline void setObjId(int objId) { m_objId = objId; } - inline static int usesReference(Reference& r) { return r.m_objId; } - inline static int usesConstReference(const Reference& r) { return r.m_objId; } + inline static int usesReference(Reference &r) { return r.m_objId; } + inline static int usesConstReference(const Reference &r) { return r.m_objId; } - virtual int usesReferenceVirtual(Reference& r, int inc); - virtual int usesConstReferenceVirtual(const Reference& r, int inc); + virtual int usesReferenceVirtual(Reference &r, int inc); + virtual int usesConstReferenceVirtual(const Reference &r, int inc); - int callUsesReferenceVirtual(Reference& r, int inc); - int callUsesConstReferenceVirtual(const Reference& r, int inc); + int callUsesReferenceVirtual(Reference &r, int inc); + int callUsesConstReferenceVirtual(const Reference &r, int inc); - virtual void alterReferenceIdVirtual(Reference& r); - void callAlterReferenceIdVirtual(Reference& r); + virtual void alterReferenceIdVirtual(Reference &r); + void callAlterReferenceIdVirtual(Reference &r); void show() const; inline static int multiplier() { return 10; } - virtual Reference& returnMyFirstArg(Reference& ref) { return ref; } - virtual Reference& returnMySecondArg(int a, Reference& ref) { return ref; } + virtual Reference &returnMyFirstArg(Reference &ref) { return ref; } + virtual Reference &returnMySecondArg(int a, Reference &ref); // nonsense operator to test if Shiboken is ignoring dereference operators. int operator*() { return m_objId; } + private: int m_objId; }; @@ -69,13 +47,16 @@ private: class LIBSAMPLE_API ObjTypeReference { public: - ObjTypeReference() {} - ObjTypeReference(const ObjTypeReference&) {} + LIBMINIMAL_DISABLE_MOVE(ObjTypeReference) + + ObjTypeReference() noexcept = default; + ObjTypeReference(const ObjTypeReference &) noexcept = default; + ObjTypeReference &operator=(const ObjTypeReference &) = delete; virtual ~ObjTypeReference(); - virtual ObjTypeReference& returnMyFirstArg(ObjTypeReference& ref) { return ref; } - virtual ObjTypeReference& returnMySecondArg(int a, ObjTypeReference& ref) { return ref; } - virtual ObjTypeReference& justAPureVirtualFunc(ObjTypeReference& ref) = 0; + + virtual ObjTypeReference &returnMyFirstArg(ObjTypeReference &ref) { return ref; } + virtual ObjTypeReference &returnMySecondArg(int a, ObjTypeReference &ref); + virtual ObjTypeReference &justAPureVirtualFunc(ObjTypeReference &ref) = 0; }; #endif // REFERENCE_H - diff --git a/sources/shiboken6/tests/libsample/removednamespaces.h b/sources/shiboken6/tests/libsample/removednamespaces.h index 47c18c049..669f2ebf0 100644 --- a/sources/shiboken6/tests/libsample/removednamespaces.h +++ b/sources/shiboken6/tests/libsample/removednamespaces.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef REMOVEDNAMESPACE_H #define REMOVEDNAMESPACE_H @@ -71,4 +46,3 @@ namespace RemovedNamespace3 } // namespace UnremovedNamespace #endif // REMOVEDNAMESPACE_H - diff --git a/sources/shiboken6/tests/libsample/renaming.cpp b/sources/shiboken6/tests/libsample/renaming.cpp index 30586e1db..d67b42a51 100644 --- a/sources/shiboken6/tests/libsample/renaming.cpp +++ b/sources/shiboken6/tests/libsample/renaming.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "renaming.h" diff --git a/sources/shiboken6/tests/libsample/renaming.h b/sources/shiboken6/tests/libsample/renaming.h index cd88b36bf..787ccc2f7 100644 --- a/sources/shiboken6/tests/libsample/renaming.h +++ b/sources/shiboken6/tests/libsample/renaming.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef RENAMING_H #define RENAMING_H diff --git a/sources/shiboken6/tests/libsample/sample.cpp b/sources/shiboken6/tests/libsample/sample.cpp index 638413fd2..5b5f8588b 100644 --- a/sources/shiboken6/tests/libsample/sample.cpp +++ b/sources/shiboken6/tests/libsample/sample.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "sample.h" @@ -40,7 +15,7 @@ int sample::value() const return m_value; } -bool operator==(const sample&s1, const sample&s2) +bool operator==(const sample &s1, const sample &s2) { return s1.value() == s2.value(); } diff --git a/sources/shiboken6/tests/libsample/sample.h b/sources/shiboken6/tests/libsample/sample.h index a6a0ff154..27909571a 100644 --- a/sources/shiboken6/tests/libsample/sample.h +++ b/sources/shiboken6/tests/libsample/sample.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SAMPLE_H #define SAMPLE_H @@ -45,9 +20,9 @@ namespace sample }; // shiboken must not generate richcompare for namespace sample - LIBSAMPLE_API bool operator==(const sample&s1, const sample&s2); + LIBSAMPLE_API bool operator==(const sample &s1, const sample &s2); const int INT_CONSTANT = 42; } -#endif +#endif // SAMPLE_H diff --git a/sources/shiboken6/tests/libsample/samplenamespace.cpp b/sources/shiboken6/tests/libsample/samplenamespace.cpp index b3ef96f5a..eae5af2d2 100644 --- a/sources/shiboken6/tests/libsample/samplenamespace.cpp +++ b/sources/shiboken6/tests/libsample/samplenamespace.cpp @@ -1,37 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> -#include <cstdlib> -#include <time.h> #include "samplenamespace.h" -using namespace std; +#include <iostream> +#include <cstdlib> +#include <ctime> namespace SampleNamespace { @@ -43,91 +17,81 @@ SomeClass::PublicScopedEnum SomeClass::protectedMethodReturningPublicScopedEnum( return PublicScopedEnum::v1; } -OutValue -enumInEnumOut(InValue in) +OutValue enumInEnumOut(InValue in) { - OutValue retval; + auto retval = OutValue(-1); switch(in) { - case ZeroIn: - retval = ZeroOut; - break; - case OneIn: - retval = OneOut; - break; - case TwoIn: - retval = TwoOut; - break; - default: - retval = (OutValue) -1; + case ZeroIn: + retval = ZeroOut; + break; + case OneIn: + retval = OneOut; + break; + case TwoIn: + retval = TwoOut; + break; + default: + break; } return retval; } -Option -enumArgumentWithDefaultValue(Option opt) +Option enumArgumentWithDefaultValue(Option opt) { return opt; } -int -getNumber(Option opt) +int getNumber(Option opt) { int retval; switch(opt) { - case RandomNumber: - retval = rand() % 100; - break; - case UnixTime: - retval = (int) time(nullptr); - break; - default: - retval = 0; + case RandomNumber: + retval = rand() % 100; + break; + case UnixTime: + retval = int(std::time(nullptr)); + break; + default: + retval = 0; + break; } return retval; } -void -doSomethingWithArray(const unsigned char* data, unsigned int size, const char* format) +void doSomethingWithArray(const unsigned char *, unsigned int, const char *) { // This function does nothing in fact. // It is here as a dummy copy of QPixmap.loadFromData method // to check compilation issues, i.e. if it compiles, it's ok. } -int -enumItemAsDefaultValueToIntArgument(int value) +int enumItemAsDefaultValueToIntArgument(int value) { return value; } -void -forceDecisorSideA(ObjectType* object) +void forceDecisorSideA(ObjectType *) { } -void -forceDecisorSideA(const Point& pt, const Str& text, ObjectType* object) +void forceDecisorSideA(const Point &, const Str &, ObjectType *) { } -void -forceDecisorSideB(int a, ObjectType* object) +void forceDecisorSideB(int, ObjectType *) { } -void -forceDecisorSideB(int a, const Point& pt, const Str& text, ObjectType* object) +void forceDecisorSideB(int, const Point &, const Str &, ObjectType *) { } -double -passReferenceToValueType(const Point& point, double multiplier) +double passReferenceToValueType(const Point &point, double multiplier) { return (point.x() + point.y()) * multiplier; } -int -passReferenceToObjectType(const ObjectType& obj, int multiplier) +int passReferenceToObjectType(const ObjectType &obj, int multiplier) { return obj.objectName().size() * multiplier; } diff --git a/sources/shiboken6/tests/libsample/samplenamespace.h b/sources/shiboken6/tests/libsample/samplenamespace.h index 5fe269c5e..99a0787ee 100644 --- a/sources/shiboken6/tests/libsample/samplenamespace.h +++ b/sources/shiboken6/tests/libsample/samplenamespace.h @@ -1,40 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SAMPLENAMESPACE_H #define SAMPLENAMESPACE_H -#include <list> #include "libsamplemacros.h" #include "str.h" #include "point.h" #include "objecttype.h" +#include <list> + // Anonymous global enum enum { AnonymousGlobalEnum_Value0, @@ -44,6 +20,25 @@ enum { namespace SampleNamespace { +inline namespace InlineNamespace +{ + enum EnumWithinInlineNamespace { EWIN_Value0, EWIN_Value1 }; + + class LIBSAMPLE_API ClassWithinInlineNamespace { + public: + LIBMINIMAL_DEFAULT_COPY_MOVE(ClassWithinInlineNamespace) + + ClassWithinInlineNamespace() noexcept = default; + ~ClassWithinInlineNamespace() = default; + + void setValue(EnumWithinInlineNamespace v) { m_value = v; } + EnumWithinInlineNamespace value() const { return m_value; } + + private: + EnumWithinInlineNamespace m_value = EWIN_Value0; + }; +} // inline ns + enum Option { None_, RandomNumber, @@ -80,7 +75,8 @@ inline double powerOfTwo(double num) { return num * num; } -LIBSAMPLE_API void doSomethingWithArray(const unsigned char *data, unsigned int size, const char *format = nullptr); +LIBSAMPLE_API void doSomethingWithArray(const unsigned char *data, unsigned int size, + const char *format = nullptr); LIBSAMPLE_API int enumItemAsDefaultValueToIntArgument(int value = ZeroIn); @@ -95,7 +91,10 @@ public: class OkThisIsRecursiveEnough { public: - virtual ~OkThisIsRecursiveEnough() {} + LIBMINIMAL_DISABLE_COPY_MOVE(OkThisIsRecursiveEnough) + + OkThisIsRecursiveEnough() noexcept = default; + virtual ~OkThisIsRecursiveEnough() = default; enum NiceEnum { NiceValue1, NiceValue2 }; @@ -104,8 +103,9 @@ public: NiceClassValue1, NiceClassValue2 }; - inline int someMethod(SomeInnerClass*) { return 0; } - virtual OkThisIsRecursiveEnough* someVirtualMethod(OkThisIsRecursiveEnough* arg) { return arg; } + inline int someMethod(SomeInnerClass *) { return 0; } + virtual OkThisIsRecursiveEnough *someVirtualMethod(OkThisIsRecursiveEnough *arg) + { return arg; } }; protected: enum ProtectedEnum { @@ -125,7 +125,8 @@ protected: PublicScopedEnum protectedMethodReturningPublicScopedEnum() const; }; -LIBSAMPLE_API inline int enumAsInt(SomeClass::PublicScopedEnum value) { return static_cast<int>(value); } +LIBSAMPLE_API inline int enumAsInt(SomeClass::PublicScopedEnum value) +{ return static_cast<int>(value); } class DerivedFromNamespace : public SomeClass::SomeInnerClass::OkThisIsRecursiveEnough { @@ -134,29 +135,30 @@ public: // only to cause namespace confusion // enum SampleNamespace { // }; - virtual OkThisIsRecursiveEnough* someVirtualMethod(OkThisIsRecursiveEnough* arg) { return arg; } + virtual OkThisIsRecursiveEnough *someVirtualMethod(OkThisIsRecursiveEnough *arg) { return arg; } inline OkThisIsRecursiveEnough *methodReturningTypeFromParentScope() { return nullptr; } }; // The combination of the following two overloaded methods could trigger a // problematic behaviour on the overload decisor, if it isn't working properly. LIBSAMPLE_API void forceDecisorSideA(ObjectType *object = nullptr); -LIBSAMPLE_API void forceDecisorSideA(const Point& pt, const Str& text, ObjectType* object = 0); +LIBSAMPLE_API void forceDecisorSideA(const Point &pt, const Str &text, + ObjectType *object = nullptr); // The combination of the following two overloaded methods could trigger a // problematic behaviour on the overload decisor, if it isn't working properly. // This is a variation of forceDecisorSideB. LIBSAMPLE_API void forceDecisorSideB(int a, ObjectType *object = nullptr); -LIBSAMPLE_API void forceDecisorSideB(int a, const Point &pt, const Str &text, ObjectType *object = nullptr); +LIBSAMPLE_API void forceDecisorSideB(int a, const Point &pt, const Str &text, + ObjectType *object = nullptr); // Add a new signature on type system with only a Point value as parameter. -LIBSAMPLE_API double passReferenceToValueType(const Point& point, double multiplier); +LIBSAMPLE_API double passReferenceToValueType(const Point &point, double multiplier); // Add a new signature on type system with only a ObjectType pointer as parameter. -LIBSAMPLE_API int passReferenceToObjectType(const ObjectType& obj, int multiplier); +LIBSAMPLE_API int passReferenceToObjectType(const ObjectType &obj, int multiplier); extern LIBSAMPLE_API int variableInNamespace; } // namespace SampleNamespace #endif // SAMPLENAMESPACE_H - diff --git a/sources/shiboken6/tests/libsample/sbkdate.cpp b/sources/shiboken6/tests/libsample/sbkdate.cpp index 8ba18af43..fd408f637 100644 --- a/sources/shiboken6/tests/libsample/sbkdate.cpp +++ b/sources/shiboken6/tests/libsample/sbkdate.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "sbkdate.h" diff --git a/sources/shiboken6/tests/libsample/sbkdate.h b/sources/shiboken6/tests/libsample/sbkdate.h index bbe3d3ca8..5e1dd0b84 100644 --- a/sources/shiboken6/tests/libsample/sbkdate.h +++ b/sources/shiboken6/tests/libsample/sbkdate.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SBKDATE_H #define SBKDATE_H @@ -34,7 +9,7 @@ class LIBSAMPLE_API SbkDate { public: - SbkDate(int d, int m, int y); + explicit SbkDate(int d, int m, int y); int day() const; int month() const; @@ -47,4 +22,3 @@ private: }; #endif // SBKDATE_H - diff --git a/sources/shiboken6/tests/libsample/simplefile.cpp b/sources/shiboken6/tests/libsample/simplefile.cpp index 3b68e02c3..e51b14088 100644 --- a/sources/shiboken6/tests/libsample/simplefile.cpp +++ b/sources/shiboken6/tests/libsample/simplefile.cpp @@ -1,108 +1,73 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <stdlib.h> -#include <string.h> -#include <fstream> #include "simplefile.h" -class SimpleFile_p +#include <cstdlib> +#include <cstdio> +#include <string> +#include <filesystem> + +class SimpleFilePrivate { public: - SimpleFile_p(const char* filename) : m_descriptor(nullptr), m_size(0) - { - m_filename = strdup(filename); - } + LIBMINIMAL_DISABLE_COPY_MOVE(SimpleFilePrivate) - ~SimpleFile_p() - { - free(m_filename); - } + SimpleFilePrivate(const char *filename) : m_filename(filename) {} + ~SimpleFilePrivate() = default; - char* m_filename; - FILE* m_descriptor; - long m_size; + std::string m_filename; + FILE *m_descriptor = nullptr; + long m_size = 0; }; -SimpleFile::SimpleFile(const char* filename) +SimpleFile::SimpleFile(const char *filename) : + p(std::make_unique<SimpleFilePrivate>(filename)) { - p = new SimpleFile_p(filename); } SimpleFile::~SimpleFile() { close(); - delete p; } -const char* SimpleFile::filename() +const char *SimpleFile::filename() { - return p->m_filename; + return p->m_filename.c_str(); } -long SimpleFile::size() +long SimpleFile::size() const { return p->m_size; } -bool -SimpleFile::open() +bool SimpleFile::open() { - if ((p->m_descriptor = fopen(p->m_filename, "rb")) == nullptr) + auto *descriptor = std::fopen(p->m_filename.c_str(), "rb"); + if (descriptor == nullptr) return false; - fseek(p->m_descriptor, 0, SEEK_END); - p->m_size = ftell(p->m_descriptor); - rewind(p->m_descriptor); + p->m_descriptor = descriptor; + const auto size = std::filesystem::file_size(std::filesystem::path(p->m_filename)); + p->m_size = long(size); return true; } -void -SimpleFile::close() +void SimpleFile::close() { - if (p->m_descriptor) { - fclose(p->m_descriptor); + if (p->m_descriptor != nullptr) { + std::fclose(p->m_descriptor); p->m_descriptor = nullptr; } } -bool -SimpleFile::exists() const +bool SimpleFile::exists() const { - std::ifstream ifile(p->m_filename); - return !ifile.fail(); + return std::filesystem::exists(std::filesystem::path(p->m_filename)); } -bool -SimpleFile::exists(const char* filename) +bool SimpleFile::exists(const char *filename) { - std::ifstream ifile(filename); - return !ifile.fail(); + return std::filesystem::exists(std::filesystem::path(filename)); } - diff --git a/sources/shiboken6/tests/libsample/simplefile.h b/sources/shiboken6/tests/libsample/simplefile.h index 7a437a99d..e4612c944 100644 --- a/sources/shiboken6/tests/libsample/simplefile.h +++ b/sources/shiboken6/tests/libsample/simplefile.h @@ -1,56 +1,34 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SIMPLEFILE_H #define SIMPLEFILE_H #include "libsamplemacros.h" -#include <stdio.h> -class SimpleFile_p; +#include <memory> + +class SimpleFilePrivate; class LIBSAMPLE_API SimpleFile { public: - explicit SimpleFile(const char* filename); + LIBMINIMAL_DISABLE_COPY(SimpleFile) + LIBMINIMAL_DEFAULT_MOVE(SimpleFile) + + explicit SimpleFile(const char *filename); ~SimpleFile(); - const char* filename(); - long size(); + const char *filename(); + long size() const; bool open(); void close(); bool exists() const; - static bool exists(const char* filename); + static bool exists(const char *filename); private: - SimpleFile_p *p; + std::unique_ptr<SimpleFilePrivate> p; }; #endif // SIMPLEFILE_H - diff --git a/sources/shiboken6/tests/libsample/size.cpp b/sources/shiboken6/tests/libsample/size.cpp index 4c195161e..0291d6e86 100644 --- a/sources/shiboken6/tests/libsample/size.cpp +++ b/sources/shiboken6/tests/libsample/size.cpp @@ -1,39 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 -#include <iostream> #include "size.h" -using namespace std; +#include <iostream> -void -Size::show() const +void Size::show() const { - cout << "(width: " << m_width << ", height: " << m_height << ")"; + std::cout << "(width: " << m_width << ", height: " << m_height << ")"; } - diff --git a/sources/shiboken6/tests/libsample/size.h b/sources/shiboken6/tests/libsample/size.h index 76502b416..2d194e96b 100644 --- a/sources/shiboken6/tests/libsample/size.h +++ b/sources/shiboken6/tests/libsample/size.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SIZE_H #define SIZE_H @@ -34,28 +9,26 @@ class LIBSAMPLE_API Size { public: - Size(double width = 0.0, double height = 0.0) : m_width(width), m_height(height) {} - ~Size() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(Size) - inline double width() { return m_width; } + explicit Size(double width = 0.0, double height = 0.0) noexcept : + m_width(width), m_height(height) {} + ~Size() = default; + + inline double width() const { return m_width; } inline void setWidth(double width) { m_width = width; } - inline double height() { return m_height; } + inline double height() const { return m_height; } inline void setHeight(double height) { m_height = height; } inline double calculateArea() const { return m_width * m_height; } // Comparison Operators - inline bool operator==(const Size& other) - { - return m_width == other.m_width && m_height == other.m_height; - } - - inline bool operator<(const Size& other) + inline bool operator<(const Size &other) { return calculateArea() < other.calculateArea(); } - inline bool operator>(const Size& other) + inline bool operator>(const Size &other) { // On some x86 hardware and compiler combinations, floating point // comparisons may fail due to a hardware bug. One workaround is to @@ -67,7 +40,7 @@ public: return a > b; } - inline bool operator<=(const Size& other) + inline bool operator<=(const Size &other) { // See comments for operator>() double a = calculateArea(); @@ -75,7 +48,7 @@ public: return a <= b; } - inline bool operator>=(const Size& other) + inline bool operator>=(const Size &other) { return calculateArea() >= other.calculateArea(); } @@ -86,28 +59,28 @@ public: inline bool operator>=(double area) { return calculateArea() >= area; } // Arithmetic Operators - inline Size& operator+=(const Size& s) + inline Size &operator+=(const Size &s) { m_width += s.m_width; m_height += s.m_height; return *this; } - inline Size& operator-=(const Size& s) + inline Size &operator-=(const Size &s) { m_width -= s.m_width; m_height -= s.m_height; return *this; } - inline Size& operator*=(double mult) + inline Size &operator*=(double mult) { m_width *= mult; m_height *= mult; return *this; } - inline Size& operator/=(double div) + inline Size &operator/=(double div) { m_width /= div; m_height /= div; @@ -117,12 +90,13 @@ public: // TODO: add ++size, size++, --size, size-- // External operators + friend inline bool operator==(const Size&, const Size&); friend inline bool operator!=(const Size&, const Size&); - friend inline const Size operator+(const Size&, const Size&); - friend inline const Size operator-(const Size&, const Size&); - friend inline const Size operator*(const Size&, double); - friend inline const Size operator*(double, const Size&); - friend inline const Size operator/(const Size&, double); + friend inline Size operator+(const Size&, const Size&); + friend inline Size operator-(const Size&, const Size&); + friend inline Size operator*(const Size&, double); + friend inline Size operator*(double, const Size&); + friend inline Size operator/(const Size&, double); friend inline bool operator<(double, const Size&); friend inline bool operator>(double, const Size&); @@ -137,65 +111,71 @@ private: }; // Comparison Operators -inline bool operator!=(const Size& s1, const Size& s2) +inline bool operator!=(const Size &s1, const Size &s2) { return s1.m_width != s2.m_width || s1.m_height != s2.m_height; } -inline bool operator<(double area, const Size& s) +inline bool operator==(const Size &s1, const Size &s2) +{ + return s1.m_width == s2.m_width && s1.m_height == s2.m_height; +} + +inline bool operator<(double area, const Size &s) { return area < s.calculateArea(); } -inline bool operator>(double area, const Size& s) +inline bool operator>(double area, const Size &s) { return area > s.calculateArea(); } -inline bool operator<=(double area, const Size& s) +inline bool operator<=(double area, const Size &s) { return area <= s.calculateArea(); } -inline bool operator>=(double area, const Size& s) +inline bool operator>=(double area, const Size &s) { return area >= s.calculateArea(); } // Arithmetic Operators -inline const Size operator+(const Size& s1, const Size& s2) +inline Size operator+(const Size &s1, const Size &s2) { return Size(s1.m_width + s2.m_width, s1.m_height + s2.m_height); } -inline const Size operator-(const Size& s1, const Size& s2) +inline Size operator-(const Size &s1, const Size &s2) { return Size(s1.m_width - s2.m_width, s1.m_height - s2.m_height); } -inline const Size operator*(const Size& s, double mult) +inline Size operator*(const Size &s, double mult) { return Size(s.m_width * mult, s.m_height * mult); } -inline const Size operator*(double mult, const Size& s) +inline Size operator*(double mult, const Size &s) { return Size(s.m_width * mult, s.m_height * mult); } -inline const Size operator/(const Size& s, double div) +inline Size operator/(const Size &s, double div) { return Size(s.m_width / div, s.m_height / div); } using real = double; using ushort = unsigned short; + class LIBSAMPLE_API SizeF { public: - SizeF(real width, real height) : m_width(width), m_height(height) {} - real width() { return m_width; } - real height() { return m_height; } + explicit SizeF(real width, real height) : m_width(width), m_height(height) {} + real width() const { return m_width; } + real height() const { return m_height; } static inline ushort passTypedefOfUnsignedShort(ushort value) { return value; } private: real m_width; @@ -203,4 +183,3 @@ private: }; #endif // SIZE_H - diff --git a/sources/shiboken6/tests/libsample/snakecasetest.cpp b/sources/shiboken6/tests/libsample/snakecasetest.cpp index d82984e6f..8240308b4 100644 --- a/sources/shiboken6/tests/libsample/snakecasetest.cpp +++ b/sources/shiboken6/tests/libsample/snakecasetest.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "snakecasetest.h" diff --git a/sources/shiboken6/tests/libsample/snakecasetest.h b/sources/shiboken6/tests/libsample/snakecasetest.h index 8900c2eec..757dd23b2 100644 --- a/sources/shiboken6/tests/libsample/snakecasetest.h +++ b/sources/shiboken6/tests/libsample/snakecasetest.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SNAKECASETEST_H #define SNAKECASETEST_H diff --git a/sources/shiboken6/tests/libsample/sometime.cpp b/sources/shiboken6/tests/libsample/sometime.cpp index 851b3b913..ad9a0d81c 100644 --- a/sources/shiboken6/tests/libsample/sometime.cpp +++ b/sources/shiboken6/tests/libsample/sometime.cpp @@ -1,36 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "sometime.h" -#include <stdio.h> -void -Time::setTime() +#include <cstdio> + +void Time::setTime() { m_hour = 0; m_minute = 0; @@ -39,8 +14,7 @@ Time::setTime() m_is_null = true; } -void -Time::setTime(int h, int m, int s, int ms) +void Time::setTime(int h, int m, int s, int ms) { m_hour = h; m_minute = m; @@ -49,15 +23,12 @@ Time::setTime(int h, int m, int s, int ms) m_is_null = false; } - -Time::NumArgs -Time::somethingCompletelyDifferent() +Time::NumArgs Time::somethingCompletelyDifferent() { return ZeroArgs; } -Time::NumArgs -Time::somethingCompletelyDifferent(int h, int m, ImplicitConv ic, ObjectType* type) +Time::NumArgs Time::somethingCompletelyDifferent(int, int, ImplicitConv ic, ObjectType *type) { if (type) return FourArgs; @@ -66,18 +37,17 @@ Time::somethingCompletelyDifferent(int h, int m, ImplicitConv ic, ObjectType* ty return ThreeArgs; } -Str -Time::toString() const +Str Time::toString() const { if (m_is_null) return Str(); char buffer[13]; - sprintf(buffer, "%02d:%02d:%02d.%03d", m_hour, m_minute, m_second, m_msec); + std::snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d.%03d", + m_hour, m_minute, m_second, m_msec); return Str(buffer); } -bool -Time::operator==(const Time& other) const +bool Time::operator==(const Time &other) const { return m_hour == other.m_hour && m_minute == other.m_minute @@ -86,8 +56,7 @@ Time::operator==(const Time& other) const && m_is_null == other.m_is_null; } -bool -Time::operator!=(const Time& other) const +bool Time::operator!=(const Time &other) const { return !operator==(other); } @@ -96,4 +65,3 @@ Time::operator Str() const { return Time::toString(); } - diff --git a/sources/shiboken6/tests/libsample/sometime.h b/sources/shiboken6/tests/libsample/sometime.h index ef16efa29..575d4b136 100644 --- a/sources/shiboken6/tests/libsample/sometime.h +++ b/sources/shiboken6/tests/libsample/sometime.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef SOMETIME_H #define SOMETIME_H @@ -37,6 +12,8 @@ class LIBSAMPLE_API Time { public: + LIBMINIMAL_DEFAULT_COPY_MOVE(Time) + enum NumArgs { ZeroArgs, TwoArgs, @@ -44,14 +21,12 @@ public: FourArgs }; - Time() - : m_hour(0), m_minute(0), m_second(0), m_msec(0), m_is_null(true) - {} - Time(int h, int m, int s = 0, int ms = 0) - : m_hour(h), m_minute(m), m_second(s), m_msec(ms), m_is_null(false) + Time() noexcept = default; + explicit Time(int h, int m, int s = 0, int ms = 0) noexcept: + m_hour(h), m_minute(m), m_second(s), m_msec(ms), m_is_null(false) {} - ~Time() {} + ~Time() = default; inline bool isNull() const { return m_is_null; } @@ -73,20 +48,19 @@ public: ObjectType *type = nullptr); Str toString() const; - bool operator==(const Time& other) const; - bool operator!=(const Time& other) const; + bool operator==(const Time &other) const; + bool operator!=(const Time &other) const; // This cast operator must become an implicit conversion of Str. operator Str() const; private: - int m_hour; - int m_minute; - int m_second; - int m_msec; + int m_hour = 0; + int m_minute = 0; + int m_second = 0; + int m_msec = 0; - bool m_is_null; + bool m_is_null = true; }; #endif // SOMETIME_H - diff --git a/sources/shiboken6/tests/libsample/stdcomplex.cpp b/sources/shiboken6/tests/libsample/stdcomplex.cpp new file mode 100644 index 000000000..847174387 --- /dev/null +++ b/sources/shiboken6/tests/libsample/stdcomplex.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "stdcomplex.h" + +#include <iostream> + +StdComplex::StdComplex() noexcept = default; + +StdComplex::StdComplex(double re, double img) noexcept : m_impl(re, img) +{ +} + +StdComplex::operator int() const +{ + return std::lround(abs_value()); +} + +StdComplex::StdComplex(const Impl &impl) noexcept : m_impl(impl) +{ +} + +StdComplex StdComplex::pow(const StdComplex &exp) const +{ + return StdComplex(std::pow(m_impl, exp.m_impl)); +} + +std::ostream &operator<<(std::ostream &str, const StdComplex &c) +{ + str << "Complex(" << c.real() << ", " << c.imag() << ')'; + return str; +} diff --git a/sources/shiboken6/tests/libsample/stdcomplex.h b/sources/shiboken6/tests/libsample/stdcomplex.h new file mode 100644 index 000000000..b39b80612 --- /dev/null +++ b/sources/shiboken6/tests/libsample/stdcomplex.h @@ -0,0 +1,55 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef STDCOMPLEX_H +#define STDCOMPLEX_H + +#include "libsamplemacros.h" + +#include <complex> +#include <iosfwd> + +// A complex number based on std::complex for exercising esoteric number +// protocols (Py_nb_). For standard number protocols, see Point. + +class LIBSAMPLE_API StdComplex +{ + using Impl = std::complex<double>; + +public: + StdComplex() noexcept; + explicit StdComplex(double re, double img) noexcept; + + double real() const { return m_impl.real(); } + double imag() const { return m_impl.imag(); } + + double abs_value() const { return std::abs(m_impl); } // abs() is reserved Python word + + StdComplex pow(const StdComplex &exp) const; + + operator double() const { return abs_value(); } + operator int() const; + + friend inline bool operator==(const StdComplex &c1, const StdComplex &c2) noexcept + { return c1.m_impl == c2.m_impl; } + friend inline bool operator!=(const StdComplex &c1, const StdComplex &c2) noexcept + { return c1.m_impl != c2.m_impl; } + + friend inline StdComplex operator+(const StdComplex &c1, const StdComplex &c2) noexcept + { return StdComplex(c1.m_impl + c2.m_impl); } + friend inline StdComplex operator-(const StdComplex &c1, const StdComplex &c2) noexcept + { return StdComplex(c1.m_impl - c2.m_impl); } + friend inline StdComplex operator*(const StdComplex &c1, const StdComplex &c2) noexcept + { return StdComplex(c1.m_impl * c2.m_impl); } + friend inline StdComplex operator/(const StdComplex &c1, const StdComplex &c2) noexcept + { return StdComplex(c1.m_impl / c2.m_impl); } + +private: + explicit StdComplex(const Impl &impl) noexcept; + + Impl m_impl; +}; + +std::ostream &operator<<(std::ostream &str, const StdComplex &c); + +#endif // STDCOMPLEX_H diff --git a/sources/shiboken6/tests/libsample/str.cpp b/sources/shiboken6/tests/libsample/str.cpp index 0411569b2..742c0bb01 100644 --- a/sources/shiboken6/tests/libsample/str.cpp +++ b/sources/shiboken6/tests/libsample/str.cpp @@ -1,117 +1,74 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "str.h" + #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> -using namespace std; - -Str::Str(const Str& s) -{ - init(s.cstring()); -} - Str::Str(char c) { char str[2] = { c, 0 }; init(str); } -Str::Str(const char* cstr) +Str::Str(const char *cstr) { init(cstr); } -void -Str::init(const char* cstr) +void Str::init(const char *cstr) { if (cstr) m_str = cstr; } -Str::~Str() -{ -} - -Str -Str::arg(const Str& s) const +Str Str::arg(const Str &s) const { size_t idx = m_str.find_first_of("%VAR"); - if (idx == std::string::npos) { + if (idx == std::string::npos) return *this; - } else { - std::string result = m_str; - result.replace(idx, 4, s.m_str); - return result.c_str(); - } + + std::string result = m_str; + result.replace(idx, 4, s.m_str); + return result.c_str(); } -Str& -Str::append(const Str& s) +Str &Str::append(const Str &s) { m_str += s.m_str; return *this; } -Str& -Str::prepend(const Str& s) +Str &Str::prepend(const Str &s) { m_str = s.m_str + m_str; return *this; } -const char* -Str::cstring() const +const char *Str::cstring() const { return m_str.c_str(); } -int -Str::toInt(bool* ok, int base) const +int Str::toInt(bool *ok, int base) const { - bool my_ok; int result = 0; - istringstream conv(m_str); + std::istringstream conv(m_str); switch (base) { - case 8: - conv >> std::oct >> result; - break; - case 10: - conv >> std::dec >> result; - break; - case 16: - conv >> std::hex >> result; - break; + case 8: + conv >> std::oct >> result; + break; + case 10: + conv >> std::dec >> result; + break; + case 16: + conv >> std::hex >> result; + break; } - my_ok = istringstream::eofbit & conv.rdstate(); + const bool my_ok = std::istringstream::eofbit & conv.rdstate(); if (!my_ok) result = 0; if (ok) @@ -119,20 +76,17 @@ Str::toInt(bool* ok, int base) const return result; } -void -Str::show() const +void Str::show() const { - printf("%s", cstring()); + std::printf("%s", cstring()); } -char -Str::get_char(int pos) const +char Str::get_char(int pos) const { return m_str[pos]; } -bool -Str::set_char(int pos, char ch) +bool Str::set_char(int pos, char ch) { m_str[pos] = ch; return true; @@ -140,42 +94,42 @@ Str::set_char(int pos, char ch) Str Str::operator+(int number) const { - ostringstream in; + std::ostringstream in; in << m_str << number; return in.str().c_str(); } -bool Str::operator==(const Str& other) const +bool Str::operator==(const Str &other) const { return m_str == other.m_str; } -Str operator+(int number, const Str& str) +Str operator+(int number, const Str &str) { - ostringstream in; + std::ostringstream in; in << number << str.m_str; return in.str().c_str(); } -bool Str::operator<(const Str& other) const +bool Str::operator<(const Str &other) const { return m_str < other.m_str; } -unsigned int strHash(const Str& str) +unsigned int strHash(const Str &str) { unsigned int result = 0; for (char c : str.m_str) - result = 5u * result + unsigned(c); + result = 5U * result + unsigned(c); return result; } -void changePStr(PStr* pstr, const char* suffix) +void changePStr(PStr *pstr, const char *suffix) { pstr->append(suffix); } -void duplicatePStr(PStr* pstr) +void duplicatePStr(PStr *pstr) { if (!pstr) return; diff --git a/sources/shiboken6/tests/libsample/str.h b/sources/shiboken6/tests/libsample/str.h index 2f7cee8c3..6b3386cef 100644 --- a/sources/shiboken6/tests/libsample/str.h +++ b/sources/shiboken6/tests/libsample/str.h @@ -1,51 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef STR_H #define STR_H -#include <string> #include "libsamplemacros.h" +#include <string> + class LIBSAMPLE_API Str { public: - Str(const Str& s); Str(char c); - Str(const char* cstr = ""); - ~Str(); + Str(const char *cstr = ""); - Str arg(const Str& s) const; + Str arg(const Str &s) const; - Str& append(const Str& s); - Str& prepend(const Str& s); + Str &append(const Str &s); + Str &prepend(const Str &s); - const char* cstring() const; + const char *cstring() const; char get_char(int pos) const; bool set_char(int pos, char ch); @@ -53,26 +27,26 @@ public: void show() const; - inline int size() const { return m_str.size(); } + inline int size() const { return int(m_str.size()); } // nonsense operator just to test reverse operators Str operator+(int number) const; - bool operator==(const Str& other) const; - bool operator<(const Str& other) const; + bool operator==(const Str &other) const; + bool operator<(const Str &other) const; private: - void init(const char* cstr); + void init(const char *cstr); std::string m_str; - friend LIBSAMPLE_API Str operator+(int number, const Str& str); - friend LIBSAMPLE_API unsigned int strHash(const Str& str); + friend LIBSAMPLE_API Str operator+(int number, const Str &str); + friend LIBSAMPLE_API unsigned int strHash(const Str &str); }; -LIBSAMPLE_API Str operator+(int number, const Str& str); -LIBSAMPLE_API unsigned int strHash(const Str& str); +LIBSAMPLE_API Str operator+(int number, const Str &str); +LIBSAMPLE_API unsigned int strHash(const Str &str); using PStr = Str; -LIBSAMPLE_API void changePStr(PStr* pstr, const char* suffix); +LIBSAMPLE_API void changePStr(PStr *pstr, const char *suffix); LIBSAMPLE_API void duplicatePStr(PStr *pstr = nullptr); #endif // STR_H diff --git a/sources/shiboken6/tests/libsample/strlist.cpp b/sources/shiboken6/tests/libsample/strlist.cpp index f3e8ac96b..5840a0516 100644 --- a/sources/shiboken6/tests/libsample/strlist.cpp +++ b/sources/shiboken6/tests/libsample/strlist.cpp @@ -1,44 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "strlist.h" #include <algorithm> -bool -StrList::operator==(const std::list<Str>& other) const +bool StrList::operator==(const std::list<Str> &other) const { return size() == other.size() && std::equal(begin(), end(), other.begin()); } -Str -StrList::join(const Str& sep) const +Str StrList::join(const Str &sep) const { Str result; const auto i1 = begin(); diff --git a/sources/shiboken6/tests/libsample/strlist.h b/sources/shiboken6/tests/libsample/strlist.h index 43aa15390..01865a5b4 100644 --- a/sources/shiboken6/tests/libsample/strlist.h +++ b/sources/shiboken6/tests/libsample/strlist.h @@ -1,38 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef STRLIST_H #define STRLIST_H -#include <list> +#include "libsamplemacros.h" #include "str.h" -#include "libsamplemacros.h" +#include <list> class LIBSAMPLE_API StrList : public std::list<Str> { @@ -44,20 +19,29 @@ public: ListOfStrCtor }; - inline StrList() : m_ctorUsed(NoParamsCtor) {} - inline explicit StrList(const Str& str) : m_ctorUsed(StrCtor) { push_back(str); } - inline StrList(const StrList& lst) : std::list<Str>(lst), m_ctorUsed(CopyCtor) {} - inline StrList(const std::list<Str>& lst) : std::list<Str>(lst), m_ctorUsed(ListOfStrCtor) {} + inline StrList() = default; + inline StrList(const std::list<Str> &lst) : + std::list<Str>(lst), m_ctorUsed(ListOfStrCtor) {} + inline explicit StrList(const Str &str) : + m_ctorUsed(StrCtor) { push_back(str); } + inline StrList(const StrList &lst) : + std::list<Str>(lst), m_ctorUsed(CopyCtor) {} + + StrList(StrList &&) = default; + StrList &operator=(const StrList &) = default; + StrList &operator=(StrList &&) = default; + ~StrList() = default; + + inline void append(const Str &str) { push_back(str); } + Str join(const Str &sep) const; - inline void append(Str str) { push_back(str); } - Str join(const Str& sep) const; + bool operator==(const std::list<Str> &other) const; + inline bool operator!=(const std::list<Str> &other) const { return !(*this == other); } - bool operator==(const std::list<Str>& other) const; - inline bool operator!=(const std::list<Str>& other) const { return !(*this == other); } + CtorEnum constructorUsed() const { return m_ctorUsed; } - CtorEnum constructorUsed() { return m_ctorUsed; } private: - CtorEnum m_ctorUsed; + CtorEnum m_ctorUsed = NoParamsCtor; }; using PStrList = StrList; diff --git a/sources/shiboken6/tests/libsample/templateptr.cpp b/sources/shiboken6/tests/libsample/templateptr.cpp index fa5bb8206..a73f78417 100644 --- a/sources/shiboken6/tests/libsample/templateptr.cpp +++ b/sources/shiboken6/tests/libsample/templateptr.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 Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "templateptr.h" -void TemplatePtr::dummy(std::list<std::pair<BlackBox *, BlackBox *> > & items) +void TemplatePtr::dummy(std::list<std::pair<BlackBox *, BlackBox *> > &) { -}
\ No newline at end of file +} diff --git a/sources/shiboken6/tests/libsample/templateptr.h b/sources/shiboken6/tests/libsample/templateptr.h index 584b64185..bf230c363 100644 --- a/sources/shiboken6/tests/libsample/templateptr.h +++ b/sources/shiboken6/tests/libsample/templateptr.h @@ -1,43 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef TEMPLATEPTR_H #define TEMPLATEPTR_H -#include <utility> -#include <list> #include "libsamplemacros.h" #include "blackbox.h" +#include <utility> +#include <list> + class LIBSAMPLE_API TemplatePtr { public: - void dummy(std::list<std::pair<BlackBox *, BlackBox *> > & items); + void dummy(std::list<std::pair<BlackBox *, BlackBox *> > &items); }; -#endif +#endif // TEMPLATEPTR_H diff --git a/sources/shiboken6/tests/libsample/transform.cpp b/sources/shiboken6/tests/libsample/transform.cpp index 840f1feac..5ccf5d1ed 100644 --- a/sources/shiboken6/tests/libsample/transform.cpp +++ b/sources/shiboken6/tests/libsample/transform.cpp @@ -1,65 +1,28 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2013 Kitware, Inc. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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. +// Copyright (C) 2013 Kitware, Inc. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "transform.h" -#ifdef _WIN32 -#include <math.h> -#include <float.h> -static inline bool isfinite(double a) { return _finite(a); } -#else #include <cmath> -#endif -using namespace std; - -Point applyHomogeneousTransform( - const Point& in, - double m11, double m12, double m13, - double m21, double m22, double m23, - double m31, double m32, double m33, - bool* okay) +Point applyHomogeneousTransform(const Point &in, + double m11, double m12, double m13, + double m21, double m22, double m23, + double m31, double m32, double m33, + bool *okay) { double x = m11 * in.x() + m12 * in.y() + m13; double y = m21 * in.x() + m22 * in.y() + m23; double w = m31 * in.x() + m32 * in.y() + m33; - if (isfinite(w) && fabs(w) > 1e-10) - { + if (std::isfinite(w) && fabs(w) > 1e-10) { if (okay) *okay = true; - return Point(x / w, y / w); - } - else - { - if (okay) - *okay = false; - return Point(); + return {x / w, y / w}; } + + if (okay) + *okay = false; + return {}; } diff --git a/sources/shiboken6/tests/libsample/transform.h b/sources/shiboken6/tests/libsample/transform.h index d9ec98dd4..34ebf40d3 100644 --- a/sources/shiboken6/tests/libsample/transform.h +++ b/sources/shiboken6/tests/libsample/transform.h @@ -1,31 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2013 Kitware, Inc. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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. +// Copyright (C) 2013 Kitware, Inc. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef TRANSFORM_H #define TRANSFORM_H @@ -34,12 +9,10 @@ #include "libsamplemacros.h" -LIBSAMPLE_API Point -applyHomogeneousTransform( - const Point& in, - double m11, double m12, double m13, - double m21, double m22, double m23, - double m31, double m32, double m33, - bool* okay); +LIBSAMPLE_API Point applyHomogeneousTransform(const Point &in, + double m11, double m12, double m13, + double m21, double m22, double m23, + double m31, double m32, double m33, + bool *okay); #endif // TRANSFORM_H diff --git a/sources/shiboken6/tests/libsample/typesystypedef.cpp b/sources/shiboken6/tests/libsample/typesystypedef.cpp index 16777bf32..d9c9a92fc 100644 --- a/sources/shiboken6/tests/libsample/typesystypedef.cpp +++ b/sources/shiboken6/tests/libsample/typesystypedef.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "typesystypedef.h" diff --git a/sources/shiboken6/tests/libsample/typesystypedef.h b/sources/shiboken6/tests/libsample/typesystypedef.h index 228381c5f..be42fbefe 100644 --- a/sources/shiboken6/tests/libsample/typesystypedef.h +++ b/sources/shiboken6/tests/libsample/typesystypedef.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef TYPESYSTYPEDEF_H #define TYPESYSTYPEDEF_H diff --git a/sources/shiboken6/tests/libsample/valueandvirtual.h b/sources/shiboken6/tests/libsample/valueandvirtual.h index 34a6788e2..799e11e40 100644 --- a/sources/shiboken6/tests/libsample/valueandvirtual.h +++ b/sources/shiboken6/tests/libsample/valueandvirtual.h @@ -1,47 +1,25 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef VALUEANDVIRTUAL_H #define VALUEANDVIRTUAL_H +#include "libsamplemacros.h" + class ValueAndVirtual { public: - ValueAndVirtual(int id) : m_id(id) {} - ValueAndVirtual(const ValueAndVirtual &other) { m_id = other.m_id; } + LIBMINIMAL_DEFAULT_COPY_MOVE(ValueAndVirtual) + + explicit ValueAndVirtual(int id) noexcept : m_id(id) {} + virtual ~ValueAndVirtual() = default; bool operator()(int id, int id2) { return id == id2; } - inline int id() { return m_id; } - virtual ~ValueAndVirtual() {}; + inline int id() const { return m_id; } + private: int m_id; }; #endif // VALUEANDVIRTUAL_H - diff --git a/sources/shiboken6/tests/libsample/virtualmethods.cpp b/sources/shiboken6/tests/libsample/virtualmethods.cpp index 705835c0b..515564664 100644 --- a/sources/shiboken6/tests/libsample/virtualmethods.cpp +++ b/sources/shiboken6/tests/libsample/virtualmethods.cpp @@ -1,43 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "virtualmethods.h" int VirtualDtor::dtor_called = 0; -double -VirtualMethods::virtualMethod0(Point pt, int val, Complex cpx, bool b) +double VirtualMethods::virtualMethod0(Point pt, int val, Complex cpx, bool b) { return (pt.x() * pt.y() * val) + cpx.imag() + ((int) b); } -bool -VirtualMethods::createStr(const char* text, Str*& ret) +bool VirtualMethods::createStr(const char *text, Str *&ret) { if (!text) { ret = nullptr; @@ -48,8 +21,7 @@ VirtualMethods::createStr(const char* text, Str*& ret) return true; } -void -VirtualMethods::getMargins(int* left, int* top, int* right, int* bottom) const +void VirtualMethods::getMargins(int *left, int *top, int *right, int *bottom) const { *left = m_left; *top = m_top; @@ -57,6 +29,11 @@ VirtualMethods::getMargins(int* left, int* top, int* right, int* bottom) const *bottom = m_bottom; } +int VirtualMethods::recursionOnModifiedVirtual(Str) const +{ + return 0; +} + const Str & VirtualMethods::returnConstRef() const { static const Str result; diff --git a/sources/shiboken6/tests/libsample/virtualmethods.h b/sources/shiboken6/tests/libsample/virtualmethods.h index 577f6919e..b7172ad0d 100644 --- a/sources/shiboken6/tests/libsample/virtualmethods.h +++ b/sources/shiboken6/tests/libsample/virtualmethods.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef VIRTUALMETHODS_H #define VIRTUALMETHODS_H @@ -42,11 +17,10 @@ class LIBSAMPLE_API VirtualMethods { public: - VirtualMethods(Str name = "VirtualMethods") : m_name(name) - { - m_left = m_top = m_right = m_bottom = 0; - } - virtual ~VirtualMethods() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(VirtualMethods) + + explicit VirtualMethods(Str name = "VirtualMethods") : m_name(name) {} + virtual ~VirtualMethods() = default; virtual double virtualMethod0(Point pt, int val, Complex cpx, bool b); double callVirtualMethod0(Point pt, int val, Complex cpx, bool b) @@ -86,12 +60,14 @@ public: void callCallMe() { callMe(); } // Passing reference to pointers. - virtual bool createStr(const char* text, Str*& ret); - bool callCreateStr(const char* text, Str*& ret) { return createStr(text, ret); } + virtual bool createStr(const char *text, Str *&ret); + bool callCreateStr(const char *text, Str *&ret) { return createStr(text, ret); } // Return a non-binded method - std::list<Str> callStrListToStdList(const StrList& strList) { return strListToStdList(strList); } - virtual std::list<Str> strListToStdList(const StrList& strList ) { return strList; } + std::list<Str> callStrListToStdList(const StrList &strList) + { return strListToStdList(strList); } + virtual std::list<Str> strListToStdList(const StrList &strList ) + { return strList; } void setMargins(int left, int top, int right, int bottom) { @@ -100,16 +76,16 @@ public: m_right = right; m_bottom = bottom; } - virtual void getMargins(int* left, int* top, int* right, int* bottom) const; - void callGetMargins(int* left, int* top, int* right, int* bottom) const + virtual void getMargins(int *left, int *top, int *right, int *bottom) const; + void callGetMargins(int *left, int *top, int *right, int *bottom) const { getMargins(left, top, right, bottom); } - virtual int recursionOnModifiedVirtual(Str arg) const { return 0; } + virtual int recursionOnModifiedVirtual(Str arg) const; int callRecursionOnModifiedVirtual(Str arg) const { return recursionOnModifiedVirtual(arg); } - virtual const Str & returnConstRef() const; + virtual const Str &returnConstRef() const; virtual int stringViewLength(std::string_view in) const; @@ -119,10 +95,10 @@ protected: private: Str m_name; - int m_left; - int m_top; - int m_right; - int m_bottom; + int m_left = 0; + int m_top = 0; + int m_right = 0; + int m_bottom = 0; }; class LIBSAMPLE_API VirtualDaughter : public VirtualMethods @@ -153,10 +129,12 @@ public: class LIBSAMPLE_API VirtualDtor { public: - VirtualDtor() {} + LIBMINIMAL_DEFAULT_COPY_MOVE(VirtualDtor) + + VirtualDtor() noexcept = default; virtual ~VirtualDtor() { dtor_called++; } - static VirtualDtor* create() { return new VirtualDtor(); } + static VirtualDtor *create() { return new VirtualDtor(); } static int dtorCalled() { return dtor_called; } static void resetDtorCounter() { dtor_called = 0; } @@ -165,4 +143,3 @@ private: }; #endif // VIRTUALMETHODS_H - diff --git a/sources/shiboken6/tests/libsample/voidholder.h b/sources/shiboken6/tests/libsample/voidholder.h index 367e99ddf..3f0f4d973 100644 --- a/sources/shiboken6/tests/libsample/voidholder.h +++ b/sources/shiboken6/tests/libsample/voidholder.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef VOIDHOLDER_H #define VOIDHOLDER_H @@ -34,21 +9,24 @@ class VoidHolder { public: - explicit VoidHolder(void *ptr = nullptr) : m_ptr(ptr) {} - ~VoidHolder() {} - inline void* voidPointer() { return m_ptr; } - inline static void* gimmeMeSomeVoidPointer() + LIBMINIMAL_DEFAULT_COPY_MOVE(VoidHolder) + + explicit VoidHolder(void *ptr = nullptr) noexcept : m_ptr(ptr) {} + ~VoidHolder() = default; + + inline void *voidPointer() { return m_ptr; } + inline static void *gimmeMeSomeVoidPointer() { - static void* pointerToSomething = new VoidHolder(); + static void *pointerToSomething = new VoidHolder(); return pointerToSomething; } void *takeVoidPointer(void *item) { return item; } + private: - void* m_ptr; + void *m_ptr; }; #endif // VOIDHOLDER_H - diff --git a/sources/shiboken6/tests/libsmart/CMakeLists.txt b/sources/shiboken6/tests/libsmart/CMakeLists.txt index 152c57f25..95f0cffd6 100644 --- a/sources/shiboken6/tests/libsmart/CMakeLists.txt +++ b/sources/shiboken6/tests/libsmart/CMakeLists.txt @@ -1,7 +1,19 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(libsmart) set(libsmart_SRC -smart.cpp +libsmartmacros.h +smart.cpp smart.h +smart_integer.h +smart_obj.h +smart_registry.h +smart_sharedptr.h +smart_test.h +stdoptionaltestbench.cpp stdoptionaltestbench.h +stdsharedptrtestbench.cpp stdsharedptrtestbench.h +stduniqueptrtestbench.cpp stduniqueptrtestbench.h ) add_library(libsmart SHARED ${libsmart_SRC}) diff --git a/sources/shiboken6/tests/libsmart/libsmartmacros.h b/sources/shiboken6/tests/libsmart/libsmartmacros.h index 03edab049..c1f229b6c 100644 --- a/sources/shiboken6/tests/libsmart/libsmartmacros.h +++ b/sources/shiboken6/tests/libsmart/libsmartmacros.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef LIB_SMART_MACROS_H #define LIB_SMART_MACROS_H diff --git a/sources/shiboken6/tests/libsmart/smart.cpp b/sources/shiboken6/tests/libsmart/smart.cpp index 81fa30c7e..2273040f9 100644 --- a/sources/shiboken6/tests/libsmart/smart.cpp +++ b/sources/shiboken6/tests/libsmart/smart.cpp @@ -1,75 +1,53 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "smart.h" #include <algorithm> #include <iostream> -static inline bool shouldPrint() +static inline bool verbose() { - return Registry::getInstance()->shouldPrint(); + return Registry::getInstance()->verbose(); } -void SharedPtrBase::logDefaultConstructor(const void *t) +void SharedPtrBase::logDefaultConstructor(const char *instantiation, const void *t) { - if (shouldPrint()) - std::cout << "shared_ptr default constructor " << t << '\n'; + if (verbose()) + std::cout << "SharedPtr<" << instantiation << "> default constructor " << t << '\n'; } -void SharedPtrBase::logConstructor(const void *t, const void *pointee) +void SharedPtrBase::logConstructor(const char *instantiation, const void *t, + const void *pointee) { - if (shouldPrint()) { - std::cout << "shared_ptr constructor " << t << " with pointer " - << pointee << '\n'; + if (verbose()) { + std::cout << "SharedPtr<" << instantiation << "> constructor " + << t << " with pointer " << pointee << '\n'; } } -void SharedPtrBase::logCopyConstructor(const void *t, const void *refData) +void SharedPtrBase::logCopyConstructor(const char *instantiation, const void *t, + const void *refData) { - if (shouldPrint()) { - std::cout << "shared_ptr copy constructor " << t << " with pointer " - << refData << '\n'; + if (verbose()) { + std::cout << "SharedPtr<" << instantiation << ">) copy constructor " + << t << " with pointer " << refData << '\n'; } } -void SharedPtrBase::logAssignment(const void *t, const void *refData) +void SharedPtrBase::logAssignment(const char *instantiation, const void *t, const void *refData) { - if (shouldPrint()) { - std::cout << "shared_ptr assignment operator " << t << " with pointer " - << refData << "\n"; + if (verbose()) { + std::cout << "SharedPtr<" << instantiation << ">::operator= " << t + << " with pointer " << refData << "\n"; } } -void SharedPtrBase::logDestructor(const void *t, int remainingRefCount) +void SharedPtrBase::logDestructor(const char *instantiation, const void *t, + int remainingRefCount) { - if (shouldPrint()) { - std::cout << "shared_ptr destructor " << t << " remaining refcount " + if (verbose()) { + std::cout << "~SharedPtr<" << instantiation << "> " << t << ", remaining refcount " << remainingRefCount << '\n'; } } @@ -77,49 +55,49 @@ void SharedPtrBase::logDestructor(const void *t, int remainingRefCount) Obj::Obj() : m_integer(123), m_internalInteger(new Integer) { Registry::getInstance()->add(this); - if (shouldPrint()) - std::cout << "Object constructor " << this << '\n'; + if (verbose()) + std::cout << "Obj constructor " << this << '\n'; } Obj::~Obj() { Registry::getInstance()->remove(this); delete m_internalInteger; - if (shouldPrint()) - std::cout << "Object destructor " << this << '\n'; + if (verbose()) + std::cout << "~Obj " << this << '\n'; } void Obj::printObj() { - if (shouldPrint()) { - std::cout << "integer value: " << m_integer + if (verbose()) { + std::cout << "Obj::printObj(): integer value: " << m_integer << " internal integer value: " << m_internalInteger->value() << '\n'; } } -SharedPtr<Obj> Obj::giveSharedPtrToObj() +SharedPtr<Obj> Obj::createSharedPtrObj() { SharedPtr<Obj> o(new Obj); return o; } -std::vector<SharedPtr<Obj> > Obj::giveSharedPtrToObjList(int size) +std::vector<SharedPtr<Obj> > Obj::createSharedPtrObjList(int size) { std::vector<SharedPtr<Obj> > r; for (int i=0; i < size; i++) - r.push_back(giveSharedPtrToObj()); + r.push_back(createSharedPtrObj()); return r; } -SharedPtr<Integer> Obj::giveSharedPtrToInteger() +SharedPtr<Integer> Obj::createSharedPtrInteger() { SharedPtr<Integer> o(new Integer); return o; } -SharedPtr<Smart::Integer2> Obj::giveSharedPtrToInteger2() +SharedPtr<Smart::Integer2> Obj::createSharedPtrInteger2() { SharedPtr<Smart::Integer2> o(new Smart::Integer2); return o; @@ -133,11 +111,37 @@ int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj) int Obj::takeSharedPtrToInteger(SharedPtr<Integer> pInt) { + if (pInt.isNull()) { + std::cout << "SharedPtr<Integer>(nullptr) passed!\n"; + return -1; + } pInt->printInteger(); return pInt->value(); } -SharedPtr<const Integer> Obj::giveSharedPtrToConstInteger() +int Obj::takeSharedPtrToIntegerByConstRef(const SharedPtr<Integer> &pInt) +{ + if (pInt.isNull()) { + std::cout << "SharedPtr<Integer>(nullptr) passed!\n"; + return -1; + } + pInt->printInteger(); + return pInt->value(); +} + +SharedPtr<Integer> Obj::createSharedPtrInteger(int value) +{ + auto *i = new Integer; + i->setValue(value); + return SharedPtr<Integer>(i); +} + +SharedPtr<Integer> Obj::createNullSharedPtrInteger() +{ + return {}; +} + +SharedPtr<const Integer> Obj::createSharedPtrConstInteger() { SharedPtr<const Integer> co(new Integer); return co; @@ -156,14 +160,14 @@ Integer Obj::takeInteger(Integer val) Integer::Integer() : m_int(456) { Registry::getInstance()->add(this); - if (shouldPrint()) + if (verbose()) std::cout << "Integer constructor " << this << '\n'; } Integer::Integer(const Integer &other) { Registry::getInstance()->add(this); - if (shouldPrint()) + if (verbose()) std::cout << "Integer copy constructor " << this << '\n'; m_int = other.m_int; } @@ -171,7 +175,7 @@ Integer::Integer(const Integer &other) Integer &Integer::operator=(const Integer &other) { Registry::getInstance()->add(this); - if (shouldPrint()) + if (verbose()) std::cout << "Integer operator= " << this << '\n'; m_int = other.m_int; return *this; @@ -180,8 +184,8 @@ Integer &Integer::operator=(const Integer &other) Integer::~Integer() { Registry::getInstance()->remove(this); - if (shouldPrint()) - std::cout << "Integer destructor " << this << '\n'; + if (verbose()) + std::cout << "~Integer " << this << " (" << m_int << ")\n"; } int Integer::value() const @@ -192,11 +196,20 @@ int Integer::value() const void Integer::setValue(int v) { m_int = v; + if (verbose()) + std::cout << "Integer::setValue(" << v << ") " << this << '\n'; +} + +int Integer::compare(const Integer &rhs) const +{ + if (m_int < rhs.m_int) + return -1; + return m_int > rhs.m_int ? 1 : 0; } void Integer::printInteger() const { - if (shouldPrint()) + if (verbose()) std::cout << "Integer value for object " << this << " is " << m_int << '\n'; } @@ -240,14 +253,14 @@ int Registry::countIntegers() const return static_cast<int>(m_integers.size()); } -bool Registry::shouldPrint() const +bool Registry::verbose() const { - return m_printStuff; + return m_verbose; } -void Registry::setShouldPrint(bool flag) +void Registry::setVerbose(bool flag) { - m_printStuff = flag; + m_verbose = flag; } Smart::Integer2::Integer2() @@ -255,7 +268,5 @@ Smart::Integer2::Integer2() { } -Smart::Integer2::Integer2(const Smart::Integer2 &other) - : Integer (other) -{ -} +Smart::Integer2::Integer2(const Smart::Integer2 &) = default; +Smart::Integer2 &Smart::Integer2::operator=(const Integer2 &) = default; diff --git a/sources/shiboken6/tests/libsmart/smart.h b/sources/shiboken6/tests/libsmart/smart.h index 6238f27d5..1f610b302 100644 --- a/sources/shiboken6/tests/libsmart/smart.h +++ b/sources/shiboken6/tests/libsmart/smart.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMART_H #define SMART_H @@ -33,5 +8,9 @@ #include "smart_integer.h" #include "smart_obj.h" #include "smart_registry.h" +#include "smart_test.h" +#include "stdsharedptrtestbench.h" +#include "stdoptionaltestbench.h" +#include "stduniqueptrtestbench.h" #endif // SMART_H diff --git a/sources/shiboken6/tests/libsmart/smart_integer.h b/sources/shiboken6/tests/libsmart/smart_integer.h index 126894120..42a441a00 100644 --- a/sources/shiboken6/tests/libsmart/smart_integer.h +++ b/sources/shiboken6/tests/libsmart/smart_integer.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMART_INTEGER_H #define SMART_INTEGER_H @@ -36,20 +11,58 @@ public: Integer(); Integer(const Integer &other); Integer &operator=(const Integer &other); + Integer(Integer &&other) noexcept = default; + Integer &operator=(Integer &&other) noexcept = default; ~Integer(); void printInteger() const; int value() const; void setValue(int v); + int compare(const Integer &rhs) const; + int m_int; // public for testing member field access. }; +inline bool operator==(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) == 0; +} + +inline bool operator!=(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) != 0; +} + +inline bool operator<(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) < 0; +} + +inline bool operator<=(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) <= 0; +} + +inline bool operator>(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) > 0; +} + +inline bool operator>=(const Integer &lhs, const Integer &rhs) +{ + return lhs.compare(rhs) >= 0; +} + namespace Smart { class LIB_SMART_API Integer2 : public Integer { public: Integer2(); - Integer2(const Integer2 &other); + Integer2(const Integer2 &); + Integer2 &operator=(const Integer2 &); + Integer2(Integer2 &&other) = delete; + Integer2 &operator=(Integer2 &&other) = delete; + ~Integer2() = default; }; } // namespace Smart diff --git a/sources/shiboken6/tests/libsmart/smart_obj.h b/sources/shiboken6/tests/libsmart/smart_obj.h index 8fe45993f..9f4f8425d 100644 --- a/sources/shiboken6/tests/libsmart/smart_obj.h +++ b/sources/shiboken6/tests/libsmart/smart_obj.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMART_OBJ_H #define SMART_OBJ_H @@ -42,18 +17,26 @@ namespace Smart { class Integer2; } class LIB_SMART_API Obj { public: Obj(); + Obj(const Obj &other) = delete; + Obj &operator=(const Obj &other) = delete; + Obj(Obj &&other) = delete; + Obj &operator=(Obj &&other) = delete; virtual ~Obj(); void printObj(); Integer takeInteger(Integer val); - SharedPtr<Obj> giveSharedPtrToObj(); - std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); - virtual SharedPtr<Integer> giveSharedPtrToInteger(); // virtual for PYSIDE-1188 - SharedPtr<const Integer> giveSharedPtrToConstInteger(); + static SharedPtr<Obj> createSharedPtrObj(); + std::vector<SharedPtr<Obj> > createSharedPtrObjList(int size); + virtual SharedPtr<Integer> createSharedPtrInteger(); // virtual for PYSIDE-1188 + SharedPtr<const Integer> createSharedPtrConstInteger(); int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt); - SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); + SharedPtr<Smart::Integer2> createSharedPtrInteger2(); int takeSharedPtrToObj(SharedPtr<Obj> pObj); int takeSharedPtrToInteger(SharedPtr<Integer> pInt); + int takeSharedPtrToIntegerByConstRef(const SharedPtr<Integer> &pInt); + + static SharedPtr<Integer> createSharedPtrInteger(int value); + static SharedPtr<Integer> createNullSharedPtrInteger(); int m_integer; // public for testing member field access. Integer *m_internalInteger; diff --git a/sources/shiboken6/tests/libsmart/smart_registry.h b/sources/shiboken6/tests/libsmart/smart_registry.h index 6171ddb59..abf7edc84 100644 --- a/sources/shiboken6/tests/libsmart/smart_registry.h +++ b/sources/shiboken6/tests/libsmart/smart_registry.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMART_REGISTRY_H #define SMART_REGISTRY_H @@ -53,8 +28,8 @@ public: void remove(Integer *p); int countObjects() const; int countIntegers() const; - bool shouldPrint() const; - void setShouldPrint(bool flag); + bool verbose() const; + void setVerbose(bool flag); protected: Registry(); @@ -62,7 +37,7 @@ protected: private: std::vector<Obj *> m_objects; std::vector<Integer *> m_integers; - bool m_printStuff = false; + bool m_verbose = false; }; #endif // SMART_REGISTRY_H diff --git a/sources/shiboken6/tests/libsmart/smart_sharedptr.h b/sources/shiboken6/tests/libsmart/smart_sharedptr.h index 65a489c68..dc665810a 100644 --- a/sources/shiboken6/tests/libsmart/smart_sharedptr.h +++ b/sources/shiboken6/tests/libsmart/smart_sharedptr.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2019 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef SMART_SHARED_PTR_H #define SMART_SHARED_PTR_H @@ -35,37 +10,40 @@ struct SharedPtrBase { - LIB_SMART_API static void logDefaultConstructor(const void *t); - LIB_SMART_API static void logConstructor(const void *t, const void *pointee); - LIB_SMART_API static void logCopyConstructor(const void *t, const void *refData); - LIB_SMART_API static void logAssignment(const void *t, const void *refData); - LIB_SMART_API static void logDestructor(const void *t, int remainingRefCount); + LIB_SMART_API static void logDefaultConstructor(const char *instantiation, const void *t); + LIB_SMART_API static void logConstructor(const char *instantiation, const void *t, const void *pointee); + LIB_SMART_API static void logCopyConstructor(const char *instantiation, const void *t, const void *refData); + LIB_SMART_API static void logAssignment(const char *instantiation, const void *t, const void *refData); + LIB_SMART_API static void logDestructor(const char *instantiation, const void *t, int remainingRefCount); }; template <class T> class SharedPtr : public SharedPtrBase { public: - SharedPtr() { logDefaultConstructor(this); } + LIBMINIMAL_DEFAULT_MOVE(SharedPtr) + + SharedPtr() { logDefaultConstructor(typeid(T).name(), this); } SharedPtr(T *v) : mPtr(v) { - logConstructor(this, v); + logConstructor(typeid(T).name(), this, v); } SharedPtr(const SharedPtr<T> &other) : mPtr(other.mPtr) { - logCopyConstructor(this, data()); + logCopyConstructor(typeid(T).name(), this, data()); } template<class X> SharedPtr(const SharedPtr<X> &other) : mPtr(other.mPtr) { - logCopyConstructor(this, data()); + logCopyConstructor(typeid(T).name(), this, data()); } - SharedPtr& operator=(const SharedPtr& other) + SharedPtr &operator=(const SharedPtr &other) { - mPtr = other.mPtr; + if (this != &other) + mPtr = other.mPtr; return *this; } @@ -107,7 +85,7 @@ public: ~SharedPtr() { if (mPtr.use_count() >= 1) - logDestructor(this, mPtr.use_count() - 1); + logDestructor(typeid(T).name(), this, mPtr.use_count() - 1); } std::shared_ptr<T> mPtr; diff --git a/sources/shiboken6/tests/libsmart/smart_test.h b/sources/shiboken6/tests/libsmart/smart_test.h new file mode 100644 index 000000000..89d8cbc7c --- /dev/null +++ b/sources/shiboken6/tests/libsmart/smart_test.h @@ -0,0 +1,13 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef SMART_TEST_H +#define SMART_TEST_H + +namespace Test { + +enum DummyEnum { Dummy1, Dummy2 }; + +} + +#endif // SMART_TEST_H diff --git a/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp new file mode 100644 index 000000000..69100720c --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp @@ -0,0 +1,58 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "stdoptionaltestbench.h" + +#include <iostream> + +std::ostream &operator<<(std::ostream &str, const Integer &i) +{ + str << i.value(); + return str; +} + +template <class T> +std::ostream &operator<<(std::ostream &str, const std::optional<T> &o) +{ + if (o.has_value()) + str << o.value(); + else + str << "nullopt"; + return str; +} + +StdOptionalTestBench::StdOptionalTestBench() = default; + +std::optional<int> StdOptionalTestBench::optionalInt() const +{ + return m_optionalInt; +} + +void StdOptionalTestBench::setOptionalInt(const std::optional<int> &i) +{ + std::cout << __FUNCTION__ << ' ' << i << '\n'; + m_optionalInt = i; +} + +void StdOptionalTestBench::setOptionalIntValue(int i) +{ + std::cout << __FUNCTION__ << ' ' << i << '\n'; + m_optionalInt.emplace(i); +} + +std::optional<Integer> StdOptionalTestBench::optionalInteger() const +{ + return m_optionalInteger; +} + +void StdOptionalTestBench::setOptionalInteger(const std::optional<Integer> &s) +{ + std::cout << __FUNCTION__ << ' ' << s << '\n'; + m_optionalInteger = s; +} + +void StdOptionalTestBench::setOptionalIntegerValue(Integer &s) +{ + std::cout << __FUNCTION__ << ' ' << s << '\n'; + m_optionalInteger.emplace(s); +} diff --git a/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h new file mode 100644 index 000000000..baa709821 --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h @@ -0,0 +1,30 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef OPTIONALTEST_H +#define OPTIONALTEST_H + +#include "libsmartmacros.h" +#include "smart_integer.h" + +#include <optional> + +class LIB_SMART_API StdOptionalTestBench +{ +public: + StdOptionalTestBench(); + + std::optional<int> optionalInt() const; + void setOptionalInt(const std::optional<int> &i); + void setOptionalIntValue(int i); + + std::optional<Integer> optionalInteger() const; + void setOptionalInteger(const std::optional<Integer> &s); + void setOptionalIntegerValue(Integer &s); + +private: + std::optional<int> m_optionalInt; + std::optional<Integer> m_optionalInteger; +}; + +#endif // OPTIONALTEST_H diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp new file mode 100644 index 000000000..a7b73cc81 --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp @@ -0,0 +1,66 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "stdsharedptrtestbench.h" +#include "smart_integer.h" + +#include <iostream> + +StdSharedPtrTestBench::StdSharedPtrTestBench() = default; +StdSharedPtrTestBench::~StdSharedPtrTestBench() = default; + +std::shared_ptr<Integer> StdSharedPtrTestBench::createInteger(int v) +{ + auto result = std::make_shared<Integer>(); + result->setValue(v); + return result; +} + +std::shared_ptr<Integer> StdSharedPtrTestBench::createNullInteger() +{ + return {}; +} + +void StdSharedPtrTestBench::printInteger(const std::shared_ptr<Integer> &p) +{ + std::cerr << __FUNCTION__ << ' '; + if (p.get()) + std::cerr << p->value(); + else + std::cerr << "nullptr"; + std::cerr << '\n'; +} + +std::shared_ptr<int> StdSharedPtrTestBench::createInt(int v) +{ + return std::make_shared<int>(v); +} + +std::shared_ptr<int> StdSharedPtrTestBench::createNullInt() +{ + return {}; +} + +void StdSharedPtrTestBench::printInt(const std::shared_ptr<int> &p) +{ + std::cerr << __FUNCTION__ << ' '; + if (p.get()) + std::cerr << *p; + else + std::cerr << "nullptr"; + std::cerr << '\n'; +} + +StdSharedPtrVirtualMethodTester::StdSharedPtrVirtualMethodTester() = default; +StdSharedPtrVirtualMethodTester::~StdSharedPtrVirtualMethodTester() = default; + +std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::callModifyInteger(const std::shared_ptr<Integer> &p) +{ + return doModifyInteger(p); +} + +std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::doModifyInteger(std::shared_ptr<Integer> p) +{ + p->setValue(p->value() + 1); + return p; +} diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h new file mode 100644 index 000000000..8991cded6 --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h @@ -0,0 +1,40 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef STDSHAREDPTRTESTBENCH_H +#define STDSHAREDPTRTESTBENCH_H + +#include "libsmartmacros.h" + +#include <memory> + +class Integer; + +class LIB_SMART_API StdSharedPtrTestBench +{ +public: + StdSharedPtrTestBench(); + ~StdSharedPtrTestBench(); + + static std::shared_ptr<Integer> createInteger(int v = 42); + static std::shared_ptr<Integer> createNullInteger(); + static void printInteger(const std::shared_ptr<Integer> &); + + static std::shared_ptr<int> createInt(int v = 42); + static std::shared_ptr<int> createNullInt(); + static void printInt(const std::shared_ptr<int> &); +}; + +class LIB_SMART_API StdSharedPtrVirtualMethodTester +{ +public: + StdSharedPtrVirtualMethodTester(); + virtual ~StdSharedPtrVirtualMethodTester(); + + std::shared_ptr<Integer> callModifyInteger(const std::shared_ptr<Integer> &p); + +protected: + virtual std::shared_ptr<Integer> doModifyInteger(std::shared_ptr<Integer> p); +}; + +#endif // STDSHAREDPTRTESTBENCH_H diff --git a/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp new file mode 100644 index 000000000..df4b566fa --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp @@ -0,0 +1,133 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "stduniqueptrtestbench.h" +#include "smart_integer.h" + +#include <iostream> + +std::ostream &operator<<(std::ostream &str, const std::unique_ptr<Integer> &p) +{ + str << "unique_ptr<Integer>("; + if (p.get()) + str << p->value(); + else + str << "nullptr"; + str << ')'; + return str; +} + +std::ostream &operator<<(std::ostream &str, const std::unique_ptr<Smart::Integer2> &p) +{ + str << "unique_ptr<Integer>("; + if (p.get()) + str << p->value(); + else + str << "nullptr"; + str << ')'; + return str; +} + +std::ostream &operator<<(std::ostream &str, const std::unique_ptr<int> &p) +{ + str << "unique_ptr<int>("; + if (p.get()) + str << *p; + else + str << "nullptr"; + str << ')'; + return str; +} + +StdUniquePtrTestBench::StdUniquePtrTestBench() = default; +StdUniquePtrTestBench::~StdUniquePtrTestBench() = default; + +std::unique_ptr<Integer> StdUniquePtrTestBench::createInteger(int v) +{ + auto result = std::make_unique<Integer>(); + result->setValue(v); + return result; +} + +std::unique_ptr<Integer> StdUniquePtrTestBench::createNullInteger() +{ + return {}; +} + +void StdUniquePtrTestBench::printInteger(const std::unique_ptr<Integer> &p) +{ + std::cerr << __FUNCTION__ << ' ' << p << '\n'; +} + +void StdUniquePtrTestBench::takeInteger(std::unique_ptr<Integer> p) +{ + std::cerr << __FUNCTION__ << ' ' << p << '\n'; +} + +std::unique_ptr<int> StdUniquePtrTestBench::createInt(int v) +{ + return std::make_unique<int>(v); +} + +std::unique_ptr<int> StdUniquePtrTestBench::createNullInt() +{ + return {}; +} + +void StdUniquePtrTestBench::printInt(const std::unique_ptr<int> &p) +{ + std::cerr << __FUNCTION__ << ' ' << p << '\n'; +} + +void StdUniquePtrTestBench::takeInt(std::unique_ptr<int> p) +{ + std::cerr << __FUNCTION__ << ' ' << p << '\n'; +} + +StdUniquePtrVirtualMethodTester::StdUniquePtrVirtualMethodTester() = default; + +StdUniquePtrVirtualMethodTester::~StdUniquePtrVirtualMethodTester() = default; + +bool StdUniquePtrVirtualMethodTester::testModifyIntegerByRef(int value, int expectedValue) +{ + auto p = std::make_unique<Integer>(); + p->setValue(value); + const int actualValue = doModifyIntegerByRef(p); + return p.get() != nullptr && actualValue == expectedValue; +} + +bool StdUniquePtrVirtualMethodTester::testModifyIntegerValue(int value, int expectedValue) +{ + auto p = std::make_unique<Integer>(); + p->setValue(value); + const int actualValue = doModifyIntegerByValue(std::move(p)); + return p.get() == nullptr && actualValue == expectedValue; +} + +bool StdUniquePtrVirtualMethodTester::testCreateInteger(int value, int expectedValue) +{ + auto p = doCreateInteger(value); + return p.get() != nullptr && p->value() == expectedValue; +} + +std::unique_ptr<Integer> StdUniquePtrVirtualMethodTester::doCreateInteger(int v) +{ + auto result = std::make_unique<Integer>(); + result->setValue(v); + return result; +} + +int StdUniquePtrVirtualMethodTester::doModifyIntegerByRef(const std::unique_ptr<Integer> &p) +{ + return p->value() + 1; +} + +int StdUniquePtrVirtualMethodTester::doModifyIntegerByValue(std::unique_ptr<Integer> p) +{ + return p->value() + 1; +} + +void StdUniquePtrTestBench::printInteger2(const std::unique_ptr<Smart::Integer2> &p) +{ + std::cerr << __FUNCTION__ << ' ' << p << '\n'; +} diff --git a/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h new file mode 100644 index 000000000..868c6d08c --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h @@ -0,0 +1,50 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef STDUNIQUEPTRTESTBENCH_H +#define STDUNIQUEPTRTESTBENCH_H + +#include "libsmartmacros.h" + +#include <memory> + +class Integer; +namespace Smart { +class Integer2; +} + +class LIB_SMART_API StdUniquePtrTestBench +{ +public: + StdUniquePtrTestBench(); + ~StdUniquePtrTestBench(); + + static std::unique_ptr<Integer> createInteger(int v = 42); + static std::unique_ptr<Integer> createNullInteger(); + static void printInteger2(const std::unique_ptr<Smart::Integer2> &p); + static void printInteger(const std::unique_ptr<Integer> &p); + static void takeInteger(std::unique_ptr<Integer> p); // Call with std::move() + + static std::unique_ptr<int> createInt(int v = 42); + static std::unique_ptr<int> createNullInt(); + static void printInt(const std::unique_ptr<int> &p); + static void takeInt(std::unique_ptr<int> p); // Call with std::move() +}; + +class LIB_SMART_API StdUniquePtrVirtualMethodTester +{ +public: + StdUniquePtrVirtualMethodTester(); + virtual ~StdUniquePtrVirtualMethodTester(); + + bool testModifyIntegerByRef(int value, int expectedValue); + bool testModifyIntegerValue(int value, int expectedValue); + bool testCreateInteger(int value, int expectedValue); + +protected: + virtual std::unique_ptr<Integer> doCreateInteger(int v); + virtual int doModifyIntegerByRef(const std::unique_ptr<Integer> &p); + virtual int doModifyIntegerByValue(std::unique_ptr<Integer> p); +}; + +#endif // STDUNIQUEPTRTESTBENCH_H diff --git a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt index 63ad8a577..7f132bd34 100644 --- a/sources/shiboken6/tests/minimalbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/minimalbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(minimal) set(minimal_TYPESYSTEM @@ -6,22 +9,30 @@ ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_minimal.xml set(minimal_SRC ${CMAKE_CURRENT_BINARY_DIR}/minimal/minimal_module_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/minimal/containeruser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/obj_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/val_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/listuser_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/minimal/spanuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/minbooluser_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/minimal-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${minimal_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'minimal' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${minimal_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/minimal-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${minimal_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'minimal' test binding..." ) add_library(minimal MODULE ${minimal_SRC}) diff --git a/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py index e036eafb9..946a869db 100644 --- a/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py +++ b/sources/shiboken6/tests/minimalbinding/brace_pattern_test.py @@ -1,41 +1,5 @@ -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of Qt for Python. -## -## $QT_BEGIN_LICENSE:LGPL$ -## 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 Lesser General Public License Usage -## Alternatively, this file may be used under the terms of the GNU Lesser -## General Public License version 3 as published by the Free Software -## Foundation and appearing in the file LICENSE.LGPL3 included in the -## packaging of this file. Please review the following information to -## ensure the GNU Lesser General Public License version 3 requirements -## will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 2.0 or (at your option) the GNU General -## Public license version 3 or any later version approved by the KDE Free -## Qt Foundation. The licenses are as published by the Free Software -## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -## 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-2.0.html and -## https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only import os import re @@ -47,8 +11,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from shiboken6 import Shiboken -_init_pyside_extension() # trigger bootstrap +from shiboken6 import Shiboken # noqa: F401 from shibokensupport.signature.lib.tool import build_brace_pattern @@ -58,8 +21,9 @@ against a slower reference implementation. The pattern is crucial, because it is used heavily in signature.parser . """ -# A slow reference parser for braces and strings + def check(s): + """A slow reference parser for braces and strings""" open, close = "[{(<", "]})>" escape, quote = "\\", '"' instring = blind = False @@ -78,8 +42,7 @@ def check(s): stack.append(c) elif c in close: pos = close.index(c) - if ((len(stack) > 0) and - (open[pos] == stack[len(stack)-1])): + if len(stack) > 0 and open[pos] == stack[len(stack) - 1]: stack.pop() else: return False diff --git a/sources/shiboken6/tests/minimalbinding/containeruser_test.py b/sources/shiboken6/tests/minimalbinding/containeruser_test.py new file mode 100644 index 000000000..25d683957 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/containeruser_test.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from minimal import ContainerUser + + +class ContainerTest(unittest.TestCase): + """Simple test for converting std::vector and using an opaque container. + For advanced tests, see ListUser.""" + def testVectorConversion(self): + v = ContainerUser.createIntVector(4) + self.assertEqual(ContainerUser.sumIntVector(v), 6) + + def testVectorOpaqueContainer(self): + cu = ContainerUser() + oc = cu.intVector() + self.assertEqual(oc[0], 1) + oc[0] = 42 + self.assertEqual(cu.intVector()[0], 42) + + def testArrayConversion(self): + v = ContainerUser.createIntArray() + self.assertEqual(ContainerUser.sumIntArray(v), 6) + + def testArrayOpaqueContainer(self): + cu = ContainerUser() + oc = cu.intArray() + self.assertEqual(oc[0], 1) + oc[0] = 42 + self.assertEqual(cu.intArray()[0], 42) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/global.h b/sources/shiboken6/tests/minimalbinding/global.h index 1b06245c4..fc5c59a26 100644 --- a/sources/shiboken6/tests/minimalbinding/global.h +++ b/sources/shiboken6/tests/minimalbinding/global.h @@ -1,33 +1,10 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "obj.h" +#include "containeruser.h" #include "val.h" #include "minbool.h" #include "listuser.h" +#include "spanuser.h" #include "typedef.h" diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py index b5048aa44..b30bb653a 100644 --- a/sources/shiboken6/tests/minimalbinding/listuser_test.py +++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from functools import reduce import os @@ -39,12 +12,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from minimal import ListUser, Val, Obj +from minimal import ListUser, Val, Obj, StdIntList class ExtListUser(ListUser): def __init__(self): - ListUser.__init__(self) + super().__init__() + self._stdIntList = StdIntList() + self._stdIntList.append(1) + self._stdIntList.append(2) def createIntList(self, num): return list(range(0, num * 2, 2)) @@ -56,7 +32,7 @@ class ExtListUser(ListUser): return [not mb1, not mb2] def oredMinBoolList(self, minBoolList): - return not reduce(lambda a, b: a|b, minBoolList) + return not reduce(lambda a, b: a | b, minBoolList) def createValList(self, num): return [Val(i) for i in range(0, num * 2, 2)] @@ -78,6 +54,9 @@ class ExtListUser(ListUser): def sumListOfIntLists(self, intListList): return sum([sum(line) for line in intListList]) * 2 + def returnIntListByPtr(self): + return self._stdIntList + class IntListConversionTest(unittest.TestCase): @@ -116,8 +95,14 @@ class IntListConversionTest(unittest.TestCase): def testSumIntList(self): lu = ListUser() lst = range(4) - self.assertEqual(lu.sumIntList(lst), sum(lst)) - self.assertEqual(lu.callSumIntList(lst), sum(lst)) + expected = sum(lst) + self.assertEqual(lu.sumIntList(lst), expected) + self.assertEqual(lu.callSumIntList(lst), expected) + self.assertEqual(lu.sumIntListDefaultParam(lst), expected) + self.assertEqual(lu.sumIntListDefaultParamConstRef(lst), expected) + # PYSIDE-2454: Check container default parameters (1,2,3) + self.assertEqual(lu.sumIntListDefaultParam(), 6) + self.assertEqual(lu.sumIntListDefaultParamConstRef(), 6) def testSumIntListFromExtendedClass(self): lu = ExtListUser() @@ -318,10 +303,74 @@ class ListOfIntListConversionTest(unittest.TestCase): def testSumListOfIntListsFromExtendedClass(self): lu = ExtListUser() lst = [range(4)] * 4 - self.assertEqual(lu.sumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) - self.assertEqual(lu.callSumListOfIntLists(lst), sum([sum(line) for line in [range(4)] * 4]) * 2) + self.assertEqual(lu.sumListOfIntLists(lst), + sum([sum(line) for line in [range(4)] * 4]) * 2) + self.assertEqual(lu.callSumListOfIntLists(lst), + sum([sum(line) for line in [range(4)] * 4]) * 2) + + def testOpaqueContainer(self): + lu = ListUser() + + # Set via Python + python_list = [1, 2] + lu.setStdIntList(python_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 1) + self.assertEqual(lu.m_stdIntList[1], 2) + + # Set via C++ + cpp_list = StdIntList() + cpp_list.append(3) + cpp_list.append(4) + lu.setStdIntList(cpp_list) + self.assertEqual(len(lu.m_stdIntList), 2) + self.assertEqual(lu.m_stdIntList[0], 3) + self.assertEqual(lu.m_stdIntList[1], 4) + + # Access field directly via reference + lu.m_stdIntList.append(5) + self.assertEqual(len(lu.m_stdIntList), 3) + self.assertEqual(lu.m_stdIntList[2], 5) + + # Access list via getter + il = lu.getIntList() + il.append(6) + self.assertEqual(len(lu.m_stdIntList), 4) + self.assertEqual(lu.m_stdIntList[3], 6) + + # Access a const list via getter and verify that it cannot be modified + const_l = lu.getConstIntList() + self.assertEqual(len(const_l), 4) + self.assertRaises(TypeError, const_l.append, 6) + + def testListByPtrOpaque(self): + """Test a function taking C++ list by pointer for which an opaque + container exists.""" + lu = ListUser() + python_list = [1, 2] + self.assertEqual(lu.modifyIntListPtr(python_list), 2) + + # Pass an opaque container and verify whether it is modified by C++ + cpp_list = StdIntList() + cpp_list.append(1) + cpp_list.append(2) + self.assertEqual(lu.modifyIntListPtr(cpp_list), 2) + self.assertEqual(len(cpp_list), 3) + + def testListByPtr(self): + """Test a function taking C++ list by pointer for which no opaque + container exists.""" + lu = ListUser() + python_list = [1.1, 22.2] + self.assertEqual(lu.modifyDoubleListPtr(python_list), 2) + + def testReturnListByPtr(self): + """Test that a virtual function returning a list by pointer can be + reimplemented by a Python function returning an opaque container.""" + lu = ExtListUser() + size = lu.callReturnIntListByPtr() # Call virtual from C++ + self.assertEqual(size, 2) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/minbool_test.py b/sources/shiboken6/tests/minimalbinding/minbool_test.py index 789803371..d9ce0eac0 100644 --- a/sources/shiboken6/tests/minimalbinding/minbool_test.py +++ b/sources/shiboken6/tests/minimalbinding/minbool_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,32 +13,34 @@ init_paths() from minimal import MinBoolUser + class DerivedMinBoolUser (MinBoolUser): def returnMyselfVirtual(self): return MinBoolUser() + class MinBoolTest(unittest.TestCase): def testMinBoolUser(self): mbuTrue = MinBoolUser() mbuFalse = MinBoolUser() mbuTrue.setMinBool(True) - self.assertEqual(mbuFalse.minBool(), False) - self.assertEqual(mbuTrue.minBool(), True) - self.assertEqual(mbuTrue.callInvertedMinBool(), False) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool()) + self.assertFalse(mbuTrue.callInvertedMinBool()) - self.assertEqual(mbuTrue.minBool() == True, True) - self.assertEqual(False == mbuFalse.minBool(), True) - self.assertEqual(mbuTrue.minBool() == mbuFalse.minBool(), False) + self.assertTrue(mbuTrue.minBool()) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool() != mbuFalse.minBool()) - self.assertEqual(mbuFalse.minBool() != True, True) - self.assertEqual(True != mbuFalse.minBool(), True) - self.assertEqual(mbuTrue.minBool() != mbuFalse.minBool(), True) + self.assertFalse(mbuFalse.minBool()) + self.assertFalse(mbuFalse.minBool()) + self.assertTrue(mbuTrue.minBool() != mbuFalse.minBool()) def testVirtuals(self): dmbu = DerivedMinBoolUser() self.assertEqual(dmbu.invertedMinBool(), True) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in b/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in index 85b139676..101567070 100644 --- a/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in +++ b/sources/shiboken6/tests/minimalbinding/minimal-binding.txt.in @@ -13,3 +13,4 @@ typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ enable-parent-ctor-heuristic use-isnull-as-nb_nonzero +lean-headers diff --git a/sources/shiboken6/tests/minimalbinding/minimalbinding.pyproject b/sources/shiboken6/tests/minimalbinding/minimalbinding.pyproject new file mode 100644 index 000000000..ab19dc443 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/minimalbinding.pyproject @@ -0,0 +1,10 @@ +{ + "files": ["brace_pattern_test.py", + "containeruser_test.py", + "listuser_test.py", + "minbool_test.py", + "obj_test.py", + "typedef_test.py", + "val_test.py", + "typesystem_minimal.xml"] +} diff --git a/sources/shiboken6/tests/minimalbinding/obj_test.py b/sources/shiboken6/tests/minimalbinding/obj_test.py index 1abd6e04c..e873845de 100644 --- a/sources/shiboken6/tests/minimalbinding/obj_test.py +++ b/sources/shiboken6/tests/minimalbinding/obj_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from minimal import Obj + class ExtObj(Obj): def __init__(self, objId): Obj.__init__(self, objId) @@ -118,4 +92,3 @@ class ObjTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/minimalbinding/spanuser_test.py b/sources/shiboken6/tests/minimalbinding/spanuser_test.py new file mode 100644 index 000000000..6db6aa616 --- /dev/null +++ b/sources/shiboken6/tests/minimalbinding/spanuser_test.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from minimal import SpanUser + + +class IntSpanTest(unittest.TestCase): + + def testCreateIntSpan(self): + if not SpanUser.enabled(): + return + expected = [1, 2, 3] + self.assertEqual(SpanUser.getIntSpan3(), expected) + self.assertEqual(SpanUser.getIntSpan(), expected) + self.assertEqual(SpanUser.getConstIntSpan3(), expected) + + self.assertEqual(SpanUser.sumIntSpan3(expected), 6) + self.assertEqual(SpanUser.sumIntSpan(expected), 6) + self.assertEqual(SpanUser.sumConstIntSpan3(expected), 6) + + def testSpanOpaqueContainer(self): + if not SpanUser.enabled(): + return + oc = SpanUser.getIntSpan3_OpaqueContainer() # 1,2,3 + oc[1] = 10 + oc = SpanUser.getIntSpan3_OpaqueContainer() + # note: This converts to std::vector + self.assertEqual(SpanUser.sumIntSpan3(oc), 14) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/typedef_test.py b/sources/shiboken6/tests/minimalbinding/typedef_test.py index 9076cbe5e..c2fc8fc12 100644 --- a/sources/shiboken6/tests/minimalbinding/typedef_test.py +++ b/sources/shiboken6/tests/minimalbinding/typedef_test.py @@ -1,35 +1,7 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -from functools import reduce +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + import os import sys import unittest @@ -38,7 +10,9 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from minimal import * +from minimal import (arrayFunc, arrayFuncInt, arrayFuncIntReturn, + arrayFuncIntReturnTypedef, arrayFuncIntTypedef, + arrayFuncReturn, arrayFuncReturnTypedef, arrayFuncTypedef) try: import numpy as np @@ -58,29 +32,37 @@ class TypedefTest(unittest.TestCase): self.assertTrue(arrayFuncInt(none), "None is empty, arrayFuncInt should return true") self.assertFalse(arrayFuncInt(full), "Full is NOT empty, arrayFuncInt should return false") - self.assertTrue(arrayFuncInt(np.array(none)), "None is empty, arrayFuncInt should return true") - self.assertFalse(arrayFuncInt(np.array(full)), "Full is NOT empty, arrayFuncInt should return false") + self.assertTrue(arrayFuncInt(np.array(none)), + "None is empty, arrayFuncInt should return true") + self.assertFalse(arrayFuncInt(np.array(full)), + "Full is NOT empty, arrayFuncInt should return false") def test_arrayFuncIntTypedef(self): none = () full = (1, 2, 3) - self.assertTrue(arrayFuncIntTypedef(none), "None is empty, arrayFuncIntTypedef should return true") - self.assertFalse(arrayFuncIntTypedef(full), "Full is NOT empty, arrayFuncIntTypedef should return false") + self.assertTrue(arrayFuncIntTypedef(none), + "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(full), + "Full is NOT empty, arrayFuncIntTypedef should return false") - self.assertTrue(arrayFuncIntTypedef(np.array(none)), "None is empty, arrayFuncIntTypedef should return true") - self.assertFalse(arrayFuncIntTypedef(np.array(full)), "Full is NOT empty, arrayFuncIntTypedef should return false") + self.assertTrue(arrayFuncIntTypedef(np.array(none)), + "None is empty, arrayFuncIntTypedef should return true") + self.assertFalse(arrayFuncIntTypedef(np.array(full)), + "Full is NOT empty, arrayFuncIntTypedef should return false") def test_arrayFuncIntReturn(self): none = arrayFuncIntReturn(0) full = arrayFuncIntReturn(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFuncIntReturnTypedef(self): none = arrayFuncIntReturnTypedef(0) full = arrayFuncIntReturnTypedef(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFunc(self): none = () @@ -89,30 +71,37 @@ class TypedefTest(unittest.TestCase): self.assertFalse(arrayFunc(full), "Full is NOT empty, arrayFunc should return false") self.assertTrue(arrayFunc(np.array(none)), "None is empty, arrayFunc should return true") - self.assertFalse(arrayFunc(np.array(full)), "Full is NOT empty, arrayFunc should return false") + self.assertFalse(arrayFunc(np.array(full)), + "Full is NOT empty, arrayFunc should return false") def test_arrayFuncTypedef(self): none = () full = (1, 2, 3) - self.assertTrue(arrayFuncTypedef(none), "None is empty, arrayFuncTypedef should return true") - self.assertFalse(arrayFuncTypedef(full), "Full is NOT empty, arrayFuncTypedef should return false") + self.assertTrue(arrayFuncTypedef(none), + "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(full), + "Full is NOT empty, arrayFuncTypedef should return false") - self.assertTrue(arrayFuncTypedef(np.array(none)), "None is empty, arrayFuncTypedef should return true") - self.assertFalse(arrayFuncTypedef(np.array(full)), "Full is NOT empty, arrayFuncTypedef should return false") + self.assertTrue(arrayFuncTypedef(np.array(none)), + "None is empty, arrayFuncTypedef should return true") + self.assertFalse(arrayFuncTypedef(np.array(full)), + "Full is NOT empty, arrayFuncTypedef should return false") def test_arrayFuncReturn(self): none = arrayFuncReturn(0) full = arrayFuncReturn(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") def test_arrayFuncReturnTypedef(self): none = arrayFuncReturnTypedef(0) full = arrayFuncReturnTypedef(self.the_size) self.assertTrue((len(none) == 0), "none should be empty") - self.assertTrue((len(full) == self.the_size), "full should have " + str(self.the_size) + " elements") + self.assertTrue((len(full) == self.the_size), + f"full should have {self.the_size} elements") if __name__ == '__main__': - if np != None: + if np is not None: unittest.main() diff --git a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml index 625615fa1..e18bf8686 100644 --- a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml +++ b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml @@ -1,7 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="minimal"> - <primitive-type name="bool"/> - <primitive-type name="int"/> <primitive-type name="MinBool" target-lang-api-name="PyBool" default-constructor="MinBool(false)"> <include file-name="minbool.h" location="global"/> @@ -17,65 +15,59 @@ </conversion-rule> </primitive-type> - <container-type name="std::list" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyList_New(Py_ssize_t(%in.size())); - Py_ssize_t idx = 0; - for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it, ++idx) { - %INTYPE_0 cppItem(*it); - PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); - for (Py_ssize_t i = 0; i < size; ++i) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> + <opaque-container name="std::list" opaque-containers="int:StdIntList"/> + + <opaque-container name="std::vector" opaque-containers="int:StdIntVector"/> + + <opaque-container name="std::array" opaque-containers="int,3:StdIntArray"/> + + <?if c++20?> <!-- FIXME PYSIDE 7: Remove "if" --> + <opaque-container name="std::span" opaque-containers="int,3:StdIntSpan3"/> + <?endif?> <object-type name="Obj"/> <value-type name="Val"> <enum-type name="ValEnum"/> </value-type> - <value-type name="ListUser"/> + <value-type name="ListUser"> + <modify-field name="m_stdIntList" opaque-container="yes"/> + <modify-function signature="getIntList()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntList"/> + </modify-argument> + </modify-function> + <modify-function signature="getConstIntList()const"> + <modify-argument index="return"> + <replace-type modified-type="StdIntList"/> + </modify-argument> + </modify-function> + </value-type> + + <value-type name="SpanUser"> + <?if c++20?> <!-- FIXME PYSIDE 7: Remove "if" --> + <modify-function signature="getIntSpan3_OpaqueContainer()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntSpan3"/> + </modify-argument> + </modify-function> + <?endif?> + </value-type> + <value-type name="MinBoolUser"/> - <container-type name="std::vector" type="vector"> - <include file-name="vector" location="global"/> - <conversion-rule> - <native-to-target> - %INTYPE::size_type vectorSize = %in.size(); - PyObject* %out = PyList_New(Py_ssize_t(vectorSize)); - for (%INTYPE::size_type idx = 0; idx < vectorSize; ++idx) { - %INTYPE_0 cppItem(%in[idx]); - PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t vectorSize = PySequence_Fast_GET_SIZE(seq.object()); - %out.reserve(vectorSize); - for (Py_ssize_t idx = 0; idx < vectorSize; ++idx ) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), idx); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> + <value-type name="ContainerUser"> + <modify-function signature="intVector()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntVector"/> + </modify-argument> + </modify-function> + <modify-function signature="intArray()"> + <modify-argument index="return"> + <replace-type modified-type="StdIntArray"/> + </modify-argument> + </modify-function> + </value-type> + <!-- Test wrapping of a typedef --> <function signature="arrayFuncInt(std::vector<int>)" /> <!-- Note manual expansion of the typedef --> diff --git a/sources/shiboken6/tests/minimalbinding/val_test.py b/sources/shiboken6/tests/minimalbinding/val_test.py index 63d2cf300..b8225a247 100644 --- a/sources/shiboken6/tests/minimalbinding/val_test.py +++ b/sources/shiboken6/tests/minimalbinding/val_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -119,4 +92,3 @@ class ValTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/CMakeLists.txt b/sources/shiboken6/tests/otherbinding/CMakeLists.txt index 7c8562abc..2172593d3 100644 --- a/sources/shiboken6/tests/otherbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/otherbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(other) set(other_TYPESYSTEM @@ -22,13 +25,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/other/valuewithunitintmillimeter_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/other-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${other_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'other' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${other_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/other-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${other_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'other' test binding..." ) add_library(other MODULE ${other_SRC}) diff --git a/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py b/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py index b059335de..2ba21653d 100644 --- a/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/collector_external_operator_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Collector shift operators defined in other modules.''' @@ -43,6 +16,7 @@ init_paths() from sample import Collector, ObjectType from other import OtherObjectType + class CollectorOtherObjectType(unittest.TestCase): '''Test cases for Collector << OtherObjectType''' @@ -60,6 +34,6 @@ class CollectorOtherObjectType(unittest.TestCase): collector << obj self.assertEqual(collector.items()[0], obj.identifier() * 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py b/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py index 79ae9de18..bd00b5892 100644 --- a/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py +++ b/sources/shiboken6/tests/otherbinding/conversion_operator_for_class_without_implicit_conversions_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests calling NoImplicitConversion using a ExtendsNoImplicitConversion parameter, being that the latter defines a new conversion operator for the former, and this one @@ -45,8 +18,10 @@ init_paths() from sample import NoImplicitConversion from other import ExtendsNoImplicitConversion + class ConversionOperatorForClassWithoutImplicitConversionsTest(unittest.TestCase): - '''Tests calling NoImplicitConversion constructor using a ExtendsNoImplicitConversion parameter.''' + '''Tests calling NoImplicitConversion constructor using a + ExtendsNoImplicitConversion parameter.''' def testNoImplicitConversion(self): '''Basic test to see if the NoImplicitConversion is Ok.''' @@ -54,27 +29,33 @@ class ConversionOperatorForClassWithoutImplicitConversionsTest(unittest.TestCase # NoImplicitConversion.receivesNoImplicitConversionByValue(NoImplicitConversion) self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByValue(obj)) # NoImplicitConversion.receivesNoImplicitConversionByPointer(NoImplicitConversion*) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByPointer(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByPointer(obj)) # NoImplicitConversion.receivesNoImplicitConversionByReference(NoImplicitConversion&) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByValue(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by value.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting a + NoImplicitConversion, passing by value.''' obj = ExtendsNoImplicitConversion(123) self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByValue(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByReference(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by reference.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting a + NoImplicitConversion, passing by reference.''' obj = ExtendsNoImplicitConversion(123) - self.assertEqual(obj.objId(), NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) + self.assertEqual(obj.objId(), + NoImplicitConversion.receivesNoImplicitConversionByReference(obj)) def testPassingExtendsNoImplicitConversionAsNoImplicitConversionByPointer(self): - '''Gives an ExtendsNoImplicitConversion object to a function expecting a NoImplicitConversion, passing by pointer. - This should not be accepted, since pointers should not be converted.''' + '''Gives an ExtendsNoImplicitConversion object to a function expecting + a NoImplicitConversion, passing by pointer. This should not be + accepted, since pointers should not be converted.''' obj = ExtendsNoImplicitConversion(123) - self.assertRaises(TypeError, NoImplicitConversion.receivesNoImplicitConversionByPointer, obj) + self.assertRaises(TypeError, + NoImplicitConversion.receivesNoImplicitConversionByPointer, obj) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py b/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py index e54e38e77..abbef6231 100644 --- a/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/extended_multiply_operator_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for libsample's Point multiply operator defined in libother module.''' @@ -43,6 +16,7 @@ init_paths() from sample import Point from other import Number + class PointOperationsWithNumber(unittest.TestCase): '''Test cases for libsample's Point multiply operator defined in libother module.''' @@ -66,6 +40,6 @@ class PointOperationsWithNumber(unittest.TestCase): num = Number(11) self.assertEqual(pt * num.value(), pt * 11) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/global.h b/sources/shiboken6/tests/otherbinding/global.h index 702fb9287..af796734a 100644 --- a/sources/shiboken6/tests/otherbinding/global.h +++ b/sources/shiboken6/tests/otherbinding/global.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "../samplebinding/global.h" #include "extendsnoimplicitconversion.h" diff --git a/sources/shiboken6/tests/otherbinding/module_reload_test.py b/sources/shiboken6/tests/otherbinding/module_reload_test.py index fe3a83533..bde2f5236 100644 --- a/sources/shiboken6/tests/otherbinding/module_reload_test.py +++ b/sources/shiboken6/tests/otherbinding/module_reload_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from importlib import reload import os @@ -48,6 +21,7 @@ dst = workdir / 'test_module.py' shutil.copyfile(src, dst) sys.path.append(os.fspath(workdir)) + class TestModuleReloading(unittest.TestCase): def testModuleReloading(self): @@ -59,5 +33,6 @@ class TestModuleReloading(unittest.TestCase): reload(test_module) self.assertFalse(oldObject is test_module.obj) + if __name__ == "__main__": unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py b/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py index c3a12d7ad..d6c356436 100644 --- a/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py +++ b/sources/shiboken6/tests/otherbinding/new_ctor_operator_test.py @@ -1,35 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -'''Tests calling Str constructor using a Number parameter, being that number defines a cast operator to Str.''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Tests calling Str constructor using a Number parameter, being that number defines + a cast operator to Str.''' import os import sys @@ -43,8 +17,10 @@ init_paths() from sample import Str from other import Number + class NewCtorOperatorTest(unittest.TestCase): - '''Tests calling Str constructor using a Number parameter, being that number defines a cast operator to Str.''' + '''Tests calling Str constructor using a Number parameter, being that number + defines a cast operator to Str.''' def testNumber(self): '''Basic test to see if the Number class is Ok.''' @@ -56,8 +32,8 @@ class NewCtorOperatorTest(unittest.TestCase): '''Try to build a Str from 'sample' module with a Number argument from 'other' module.''' value = 123 num = Number(value) - string = Str(num) + string = Str(num) # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/objtypehashes_test.py b/sources/shiboken6/tests/otherbinding/objtypehashes_test.py index 36c27b35d..d2cd7de5b 100644 --- a/sources/shiboken6/tests/otherbinding/objtypehashes_test.py +++ b/sources/shiboken6/tests/otherbinding/objtypehashes_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -34,10 +9,10 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * -from other import * +from sample import HandleHolder from shiboken6 import Shiboken + class TestHashFuncs (unittest.TestCase): def testIt(self): @@ -55,6 +30,5 @@ class TestHashFuncs (unittest.TestCase): self.assertEqual(hash1_2, hash1) - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/other-binding.txt.in b/sources/shiboken6/tests/otherbinding/other-binding.txt.in index dbe935a9f..d85f6030a 100644 --- a/sources/shiboken6/tests/otherbinding/other-binding.txt.in +++ b/sources/shiboken6/tests/otherbinding/other-binding.txt.in @@ -17,4 +17,4 @@ typesystem-path = @sample_SOURCE_DIR@ typesystem-path = @smart_SOURCE_DIR@ enable-parent-ctor-heuristic - +lean-headers diff --git a/sources/shiboken6/tests/otherbinding/otherbinding.pyproject b/sources/shiboken6/tests/otherbinding/otherbinding.pyproject new file mode 100644 index 000000000..d1bbee11e --- /dev/null +++ b/sources/shiboken6/tests/otherbinding/otherbinding.pyproject @@ -0,0 +1,17 @@ +{ + "files": ["collector_external_operator_test.py", + "conversion_operator_for_class_without_implicit_conversions_test.py", + "extended_multiply_operator_test.py", + "module_reload_test.py", + "new_ctor_operator_test.py", + "objtypehashes_test.py", + "otherderived_test.py", + "othertypesystypedef_test.py", + "signature_test.py", + "smartptr_test.py", + "test_module_template.py", + "typediscovery_test.py", + "usersprimitivefromothermodule_test.py", + "wrongctor_test.py", + "typesystem_other.xml"] +} diff --git a/sources/shiboken6/tests/otherbinding/otherderived_test.py b/sources/shiboken6/tests/otherbinding/otherderived_test.py index 9a68e2ad4..459f474f1 100644 --- a/sources/shiboken6/tests/otherbinding/otherderived_test.py +++ b/sources/shiboken6/tests/otherbinding/otherderived_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for OtherDerived class''' +import gc import os import sys import unittest @@ -43,6 +17,7 @@ init_paths() from sample import Abstract, Derived from other import OtherDerived, Number + class Multiple(Derived, Number): def __init__(self): Derived.__init__(self, 42) @@ -51,6 +26,7 @@ class Multiple(Derived, Number): def testCall(self): return True + class OtherDeviant(OtherDerived): def __init__(self): OtherDerived.__init__(self) @@ -66,6 +42,7 @@ class OtherDeviant(OtherDerived): def className(self): return 'OtherDeviant' + class MultipleTest(unittest.TestCase): '''Test case for Multiple derived class''' @@ -75,6 +52,8 @@ class MultipleTest(unittest.TestCase): self.assertTrue(isinstance(o, Number)) self.assertTrue(isinstance(o, Derived)) del o + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testMethodCall(self): o = Multiple() @@ -82,6 +61,7 @@ class MultipleTest(unittest.TestCase): self.assertTrue(o.value(), 42) self.assertTrue(o.testCall()) + class OtherDerivedTest(unittest.TestCase): '''Test case for OtherDerived class''' @@ -92,13 +72,15 @@ class OtherDerivedTest(unittest.TestCase): self.assertTrue(inherited_methods.issubset(dir(OtherDerived))) def testReimplementedPureVirtualMethodCall(self): - '''Test if a Python override of a implemented pure virtual method is correctly called from C++.''' + '''Test if a Python override of a implemented pure virtual method is + correctly called from C++.''' d = OtherDeviant() d.callPureVirtual() self.assertTrue(d.pure_virtual_called) def testReimplementedVirtualMethodCall(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = OtherDeviant() d.callUnpureVirtual() self.assertTrue(d.unpure_virtual_called) @@ -110,7 +92,8 @@ class OtherDerivedTest(unittest.TestCase): self.assertEqual(d.getClassName(), 'OtherDerived') def testReimplementedVirtualMethodCallReturningString(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = OtherDeviant() self.assertEqual(d.className(), 'OtherDeviant') self.assertEqual(d.getClassName(), 'OtherDeviant') @@ -121,6 +104,6 @@ class OtherDerivedTest(unittest.TestCase): d = OtherDerived(objId) self.assertEqual(Abstract.getObjectId(d), objId) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py b/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py index 05ac50c89..198c71693 100644 --- a/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py +++ b/sources/shiboken6/tests/otherbinding/othertypesystypedef_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a class that holds a void pointer.''' @@ -40,8 +13,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from other import (OtherValueWithUnitUser, ValueWithUnitIntInch, - ValueWithUnitIntMillimeter) +from other import (OtherValueWithUnitUser, ValueWithUnitIntMillimeter) from sample import (ValueWithUnitDoubleMillimeter) diff --git a/sources/shiboken6/tests/otherbinding/signature_test.py b/sources/shiboken6/tests/otherbinding/signature_test.py index 9f94edd34..8db3e566b 100644 --- a/sources/shiboken6/tests/otherbinding/signature_test.py +++ b/sources/shiboken6/tests/otherbinding/signature_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for functions signature''' @@ -43,13 +16,19 @@ init_paths() from other import OtherObjectType from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature + + class SignatureTest(unittest.TestCase): - # Check if the argument of 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)' + # Check if the argument of + # 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)' # has the correct representation def testNamespaceFromOtherModule(self): - argType = OtherObjectType.enumAsInt.__signature__.parameters['value'].annotation - self.assertEqual(objectFullname(argType), 'sample.SampleNamespace.SomeClass.PublicScopedEnum') + argType = get_signature(OtherObjectType.enumAsInt).parameters["value"].annotation + self.assertEqual(objectFullname(argType), + "sample.SampleNamespace.SomeClass.PublicScopedEnum") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/smartptr_test.py b/sources/shiboken6/tests/otherbinding/smartptr_test.py index a3a764629..fd5c7fa09 100644 --- a/sources/shiboken6/tests/otherbinding/smartptr_test.py +++ b/sources/shiboken6/tests/otherbinding/smartptr_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for the SmartPtrTester class''' @@ -40,8 +13,6 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from smart import Integer -from sample import Str from other import SmartPtrTester diff --git a/sources/shiboken6/tests/otherbinding/star_import_test.py b/sources/shiboken6/tests/otherbinding/star_import_test.py new file mode 100644 index 000000000..4b5f1d270 --- /dev/null +++ b/sources/shiboken6/tests/otherbinding/star_import_test.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# Copyright (C) 2024 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +"""PYSIDE-2404: Test whether star imports work as they require special handling + by the lazy initialization.""" + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +SHIBOKEN_NAME = "shiboken6.Shiboken" +MINIMAL_NAME = "minimal" +OTHER_NAME = "other" + +shiboken_loaded = 1 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded = 1 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded = 1 if sys.modules.get(OTHER_NAME) else 0 + +from minimal import * # noqa: F403 + +shiboken_loaded += 2 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded += 2 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded += 2 if sys.modules.get(OTHER_NAME) else 0 + +from other import Number # noqa: F403 +from other import * # noqa: F403 + +shiboken_loaded += 4 if sys.modules.get(SHIBOKEN_NAME) else 0 +minimal_loaded += 4 if sys.modules.get(MINIMAL_NAME) else 0 +other_loaded = +4 if sys.modules.get(OTHER_NAME) else 0 + +import shiboken6.Shiboken # noqa: F401 F403 + +shiboken_loaded += 8 if sys.modules.get(SHIBOKEN_NAME) else 0 + + +class ValTest(unittest.TestCase): + + def test(self): + val_id = 123 + val = Val(val_id) # noqa: F405 + self.assertEqual(val.valId(), val_id) + + +class Simple(Number): + + def __init__(self): + Number.__init__(self, 42) + + +class OtherTest(unittest.TestCase): + + def testConstructor(self): + o = Simple() + self.assertTrue(isinstance(o, Number)) + + +class StarImportTest(unittest.TestCase): + """ + This test is meant for Lazy Init. + We explicitly choose modules which are able to lazy load. + + The ValTest: + ------------ + We load something with `import *`. + There is no module from our known ones imported. + This means we need stack introspection to find out that this was + a star import and we must disable lazyness. + + The OtherTest: + -------------- + We load something normally that should be lazy. + After that, we follow with a star import. + Now the stack introspection does not work, because the loading is + cached. The first import did a lazy load. The following star import + needs to undo the lazyness. But now we have a redirected import. + + All tests simply check if the objects are real and not just names. + The <module>_loaded tests prevend upcoming internal dependencies. + + To make sure that Shiboken is really not involved, it is checked + and really imported afterwards (ensuring nothing is misspelled). + """ + + def testStar(self): + self.assertEqual(other_loaded, 4) + self.assertEqual(minimal_loaded, 6) + self.assertEqual(shiboken_loaded, 14) + # Interesting effect: Did not expect that shiboken is loaded at all. + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/test_module_template.py b/sources/shiboken6/tests/otherbinding/test_module_template.py index 5d08944f3..36ab43ae3 100644 --- a/sources/shiboken6/tests/otherbinding/test_module_template.py +++ b/sources/shiboken6/tests/otherbinding/test_module_template.py @@ -1,38 +1,22 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -from other import * -from sample import * +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from other import OtherObjectType +from sample import ObjectType class MyObjectType(ObjectType): pass + class MyOtherObjectType(OtherObjectType): value = 10 diff --git a/sources/shiboken6/tests/otherbinding/typediscovery_test.py b/sources/shiboken6/tests/otherbinding/typediscovery_test.py index fee4734ae..791d3bdce 100644 --- a/sources/shiboken6/tests/otherbinding/typediscovery_test.py +++ b/sources/shiboken6/tests/otherbinding/typediscovery_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for type discovery''' @@ -40,9 +13,10 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import Abstract, Base1, Derived, MDerived1, MDerived3, SonOfMDerived1 +from sample import Abstract, Base1, Derived from other import OtherMultipleDerived + class TypeDiscoveryTest(unittest.TestCase): def testPureVirtualsOfImpossibleTypeDiscovery(self): @@ -56,18 +30,19 @@ class TypeDiscoveryTest(unittest.TestCase): self.assertEqual(type(a), Derived) def testMultipleInheritance(self): - obj = OtherMultipleDerived.createObject("Base1"); + obj = OtherMultipleDerived.createObject("Base1") self.assertEqual(type(obj), Base1) # PYSIDE-868: In case of multiple inheritance, a factory # function will return the base class wrapper. - obj = OtherMultipleDerived.createObject("MDerived1"); + obj = OtherMultipleDerived.createObject("MDerived1") self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("SonOfMDerived1"); + obj = OtherMultipleDerived.createObject("SonOfMDerived1") self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("MDerived3"); + obj = OtherMultipleDerived.createObject("MDerived3") self.assertEqual(type(obj), Base1) - obj = OtherMultipleDerived.createObject("OtherMultipleDerived"); + obj = OtherMultipleDerived.createObject("OtherMultipleDerived") self.assertEqual(type(obj), Base1) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/typesystem_other.xml b/sources/shiboken6/tests/otherbinding/typesystem_other.xml index 4081548fc..ade1c8bad 100644 --- a/sources/shiboken6/tests/otherbinding/typesystem_other.xml +++ b/sources/shiboken6/tests/otherbinding/typesystem_other.xml @@ -17,8 +17,4 @@ <typedef-type name="ValueWithUnitIntInch" source="ValueWithUnit<int,LengthUnit::Inch>"/> <typedef-type name="ValueWithUnitIntMillimeter" source="ValueWithUnit<int,LengthUnit::Millimeter>"/> <value-type name="OtherValueWithUnitUser"/> - - <suppress-warning text="signature 'operator!=(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> - <suppress-warning text="signature 'operator+(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> - <suppress-warning text="signature 'operator==(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> </typesystem> diff --git a/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py b/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py index ec9e81080..15a988326 100644 --- a/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py +++ b/sources/shiboken6/tests/otherbinding/usersprimitivefromothermodule_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests user defined primitive type from a required module.''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from other import Number + class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): def testUsersPrimitiveFromRequiredModuleAsArgument(self): @@ -55,5 +29,6 @@ class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): cpx = number.toComplex() self.assertEqual(number.value(), int(cpx.real)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/otherbinding/wrongctor_test.py b/sources/shiboken6/tests/otherbinding/wrongctor_test.py index 1813671d7..b9251b428 100644 --- a/sources/shiboken6/tests/otherbinding/wrongctor_test.py +++ b/sources/shiboken6/tests/otherbinding/wrongctor_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -37,17 +10,19 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * -from other import * +from sample import Abstract, ObjectType +from other import OtherDerived + class Foo(OtherDerived): def __init__(self): - Abstract.__init__(self, 2) # this should raise an exception + Abstract.__init__(self, 2) # this should raise an exception + class Foo2(ObjectType, OtherDerived): def __init__(self): ObjectType.__init__(self) - Abstract.__init__(self, 2) # this should raise an exception + Abstract.__init__(self, 2) # this should raise an exception class WrongCtorTest(unittest.TestCase): diff --git a/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt b/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt new file mode 100644 index 000000000..11b22f038 --- /dev/null +++ b/sources/shiboken6/tests/qtxmltosphinx/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.18) + +# Standalone-buildable + +project(qtxmltosphinx) + +set(CMAKE_AUTOMOC ON) + +find_package(Qt6 COMPONENTS Core) + +set(generator_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../generator) +set(api_extractor_src_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../ApiExtractor) + +set(qtxmltosphinx_SRC + ${generator_src_dir}/qtdoc/qtxmltosphinx.cpp + ${api_extractor_src_dir}/codesniphelpers.cpp + ${api_extractor_src_dir}/textstream.cpp + main.cpp) + +add_executable(qtxmltosphinx ${qtxmltosphinx_SRC}) + +target_include_directories(qtxmltosphinx PRIVATE + ${CMAKE_CURRENT_BINARY_DIR} + ${api_extractor_src_dir} + ${generator_src_dir} + ${generator_src_dir}/shiboken + ${generator_src_dir}/qtdoc) + +target_link_libraries(qtxmltosphinx PRIVATE Qt::Core) diff --git a/sources/shiboken6/tests/qtxmltosphinx/main.cpp b/sources/shiboken6/tests/qtxmltosphinx/main.cpp new file mode 100644 index 000000000..27aaee7d1 --- /dev/null +++ b/sources/shiboken6/tests/qtxmltosphinx/main.cpp @@ -0,0 +1,107 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "qtxmltosphinxinterface.h" +#include "qtxmltosphinx.h" + +#include <QtCore/QCommandLineParser> +#include <QtCore/QCoreApplication> +#include <QtCore/QDebug> +#include <QtCore/QFile> +#include <QtCore/QLoggingCategory> + +#include <exception> +#include <iostream> + +using namespace Qt::StringLiterals; + +static const char help[] = R"(QtXmlToSphinx WebXML to rst converter + +A manual test for converting WebXML files to rst files for checking +formatting. +)"; + +Q_LOGGING_CATEGORY(lcQtXmlToSphinx, "qt.xmltosphinx"); + +static std::ostream &operator<<(std::ostream &str, const QString &s) +{ + str << s.toUtf8().constData(); + return str; +} + +class QtXmlToSphinxDocGenerator : public QtXmlToSphinxDocGeneratorInterface +{ +public: + QtXmlToSphinxDocGenerator() = default; + + QString expandFunction(const QString &) const override; + QString expandClass(const QString &, const QString &) const override; + QString resolveContextForMethod(const QString &, + const QString &) const override; + const QLoggingCategory &loggingCategory() const override; + QtXmlToSphinxLink resolveLink(const QtXmlToSphinxLink &link) const override; +}; + +// QtXmlToSphinxDocGeneratorInterface +QString QtXmlToSphinxDocGenerator::expandFunction(const QString &) const +{ + return {}; +} + +QString QtXmlToSphinxDocGenerator::expandClass(const QString &, const QString &) const +{ + return {}; +} + +QString QtXmlToSphinxDocGenerator::resolveContextForMethod(const QString &, const QString &) const +{ + return {}; +} + +const QLoggingCategory &QtXmlToSphinxDocGenerator::loggingCategory() const +{ + return lcQtXmlToSphinx(); +} + +QtXmlToSphinxLink QtXmlToSphinxDocGenerator::resolveLink(const QtXmlToSphinxLink &link) const +{ + return link; +} + +static bool run(const QString &fileName) +{ + QtXmlToSphinxDocGenerator generator; + QtXmlToSphinxParameters parameters; + + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + std::cerr << "Cannot open " << fileName << ": " << file.errorString() << '\n'; + return false; + } + const QString xml = QString::fromUtf8(file.readAll()); + file.close(); + std::cout << QtXmlToSphinx(&generator, parameters, xml).result(); + return true; +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QCommandLineParser commandLineParser; + commandLineParser.setApplicationDescription(QString::fromLatin1(help)); + commandLineParser.addHelpOption(); + commandLineParser.addPositionalArgument(u"[file]"_s, u"WebXML file to process."_s); + commandLineParser.process(QCoreApplication::arguments()); + if (commandLineParser.positionalArguments().isEmpty()) + commandLineParser.showHelp(0); // quits + + int exitCode = 1; + try { + if (run(commandLineParser.positionalArguments().constFirst())) + exitCode = 0; + } catch (const std::exception &e) { + std::cerr << "An exception occurred: " << e.what() << '\n'; + } + return exitCode; +} diff --git a/sources/shiboken6/tests/qtxmltosphinxtest/CMakeLists.txt b/sources/shiboken6/tests/qtxmltosphinxtest/CMakeLists.txt index 940a171b5..25074e716 100644 --- a/sources/shiboken6/tests/qtxmltosphinxtest/CMakeLists.txt +++ b/sources/shiboken6/tests/qtxmltosphinxtest/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 3.16) +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.18) project(qtxmltosphinxtest) diff --git a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp index ea60d36b5..45cecd1a1 100644 --- a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp +++ b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.cpp @@ -1,38 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "qtxmltosphinxtest.h" #include "qtxmltosphinx.h" #include <QtTest/QTest> +#include <QtCore/QBuffer> #include <QtCore/QDebug> #include <QtCore/QLoggingCategory> +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcQtXmlToSphinxTest, "qt.sphinxtabletest"); // QtXmlToSphinxDocGeneratorInterface @@ -74,285 +52,322 @@ void QtXmlToSphinxTest::testTable_data() QTest::newRow("emptyString") << QString() << QString(); // testSimpleTable - const char *xml = "\ -<table>\ - <header>\ - <item>\ - <para>Header 1</para>\ - </item>\ - <item>\ - <para>Header 2</para>\ - </item>\ - </header>\ - <row>\ - <item>\ - <para>1 1</para>\ - </item>\ - <item>\ - <para>1 2</para>\ - </item>\ - </row>\ - <row>\ - <item>\ - <para>2 1</para>\ - </item>\ - <item>\ - <para>2 2</para>\ - </item>\ - </row>\ -</table>"; - - const char *expected = "\n\ - +--------+--------+\n\ - |Header 1|Header 2|\n\ - +--------+--------+\n\ - |1 1 |1 2 |\n\ - +--------+--------+\n\ - |2 1 |2 2 |\n\ - +--------+--------+\n\ -\n"; + const char *xml = R"(<table> + <header> + <item> + <para>Header 1</para> + </item> + <item> + <para>Header 2</para> + </item> + </header> + <row> + <item> + <para>1 1</para> + </item> + <item> + <para>1 2</para> + </item> + </row> + <row> + <item> + <para>2 1</para> + </item> + <item> + <para>2 2</para> + </item> + </row> +</table>)"; + + const char *expected = R"( + +--------+--------+ + |Header 1|Header 2| + +========+========+ + |1 1 |1 2 | + +--------+--------+ + |2 1 |2 2 | + +--------+--------+ + +)"; QTest::newRow("testSimpleTable") << QString::fromLatin1(xml) << QString::fromLatin1(expected); // testRowSpan - xml = "\ -<table>\ - <header>\ - <item>\ - <para>Header 1</para>\ - </item>\ - <item>\ - <para>Header 2</para>\ - </item>\ - </header>\ - <row>\ - <item colspan=\"2\">\ - <para>I'm a big text!</para>\ - </item>\ - </row>\ - <row>\ - <item>\ - <para>2 1</para>\ - </item>\ - <item>\ - <para>2 2</para>\ - </item>\ - </row>\ -</table>"; - - expected = "\n\ - +---------------+--------+\n\ - |Header 1 |Header 2|\n\ - +---------------+--------+\n\ - |I'm a big text! |\n\ - +---------------+--------+\n\ - |2 1 |2 2 |\n\ - +---------------+--------+\n\ -\n"; + xml = R"(<table> + <header> + <item> + <para>Header 1</para> + </item> + <item> + <para>Header 2</para> + </item> + </header> + <row> + <item colspan="2"> + <para>I'm a big text!</para> + </item> + </row> + <row> + <item> + <para>2 1</para> + </item> + <item> + <para>2 2</para> + </item> + </row> +</table>)"; + + expected = R"( + +---------------+--------+ + |Header 1 |Header 2| + +===============+========+ + |I'm a big text! | + +---------------+--------+ + |2 1 |2 2 | + +---------------+--------+ + +)"; QTest::newRow("testColSpan") << QString::fromLatin1(xml) << QString::fromLatin1(expected); // testRowSpan - xml = "\ -<table>\ - <header>\ - <item>\ - <para>Header 1</para>\ - </item>\ - <item>\ - <para>Header 2</para>\ - </item>\ - </header>\ - <row>\ - <item rowspan=\"2\">\ - <para>1.1</para>\ - </item>\ - <item>\ - <para>1.2</para>\ - </item>\ - </row>\ - <row>\ - <item>\ - <para>2 2</para>\ - </item>\ - </row>\ -</table>"; - - expected = "\n\ - +--------+--------+\n\ - |Header 1|Header 2|\n\ - +--------+--------+\n\ - |1.1 |1.2 |\n\ - + +--------+\n\ - | |2 2 |\n\ - +--------+--------+\n\ -\n"; + xml = R"(<table> + <header> + <item> + <para>Header 1</para> + </item> + <item> + <para>Header 2</para> + </item> + </header> + <row> + <item rowspan="2"> + <para>1.1</para> + </item> + <item> + <para>1.2</para> + </item> + </row> + <row> + <item> + <para>2 2</para> + </item> + </row> +</table>)"; + + expected = R"( + +--------+--------+ + |Header 1|Header 2| + +========+========+ + |1.1 |1.2 | + + +--------+ + | |2 2 | + +--------+--------+ + +)"; QTest::newRow("testRowSpan") << QString::fromLatin1(xml) << QString::fromLatin1(expected); // testComplexTable - xml = "\ -<table>\ - <header>\ - <item>\ - <para>Header 1</para>\ - </item>\ - <item>\ - <para>Header 2</para>\ - </item>\ - <item>\ - <para>Header 3</para>\ - </item>\ - </header>\ - <row>\ - <item rowspan=\"2\">\ - <para>1.1</para>\ - </item>\ - <item colspan=\"2\">\ - <para>1.2</para>\ - </item>\ - </row>\ - <row>\ - <item>\ - <para>2 2</para>\ - </item>\ - <item>\ - <para>2 3</para>\ - </item>\ - </row>\ -</table>"; - - expected = "\n\ - +--------+--------+--------+\n\ - |Header 1|Header 2|Header 3|\n\ - +--------+--------+--------+\n\ - |1.1 |1.2 |\n\ - + +--------+--------+\n\ - | |2 2 |2 3 |\n\ - +--------+--------+--------+\n\ -\n"; + xml = R"(<table> + <header> + <item> + <para>Header 1</para> + </item> + <item> + <para>Header 2</para> + </item> + <item> + <para>Header 3</para> + </item> + </header> + <row> + <item rowspan="2"> + <para>1.1</para> + </item> + <item colspan="2"> + <para>1.2</para> + </item> + </row> + <row> + <item> + <para>2 2</para> + </item> + <item> + <para>2 3</para> + </item> + </row> +</table>)"; + + expected = R"( + +--------+--------+--------+ + |Header 1|Header 2|Header 3| + +========+========+========+ + |1.1 |1.2 | + + +--------+--------+ + | |2 2 |2 3 | + +--------+--------+--------+ + +)"; QTest::newRow("testComplexTable") << QString::fromLatin1(xml) << QString::fromLatin1(expected); // testRowSpan2 - xml = "\ -<table>\ - <header>\ - <item><para>h1</para></item>\ - <item><para>h2</para></item>\ - <item><para>h3</para></item>\ - <item><para>h4</para></item>\ - </header>\ - <row>\ - <item rowspan=\"6\"><para>A</para></item>\ - <item rowspan=\"6\"><para>B</para></item>\ - <item><para>C</para></item>\ - <item><para>D</para></item>\ - </row>\ - <row>\ - <item><para>E</para></item>\ - <item><para>F</para></item>\ - </row>\ - <row>\ - <item><para>E</para></item>\ - <item><para>F</para></item>\ - </row>\ - <row>\ - <item><para>E</para></item>\ - <item><para>F</para></item>\ - </row>\ - <row>\ - <item><para>E</para></item>\ - <item><para>F</para></item>\ - </row>\ - <row>\ - <item><para>E</para></item>\ - <item><para>F</para></item>\ - </row>\ -</table>"; - - expected = "\n\ - +--+--+--+--+\n\ - |h1|h2|h3|h4|\n\ - +--+--+--+--+\n\ - |A |B |C |D |\n\ - + + +--+--+\n\ - | | |E |F |\n\ - + + +--+--+\n\ - | | |E |F |\n\ - + + +--+--+\n\ - | | |E |F |\n\ - + + +--+--+\n\ - | | |E |F |\n\ - + + +--+--+\n\ - | | |E |F |\n\ - +--+--+--+--+\n\ -\n"; + xml = R"(<table> + <header> + <item><para>h1</para></item> + <item><para>h2</para></item> + <item><para>h3</para></item> + <item><para>h4</para></item> + </header> + <row> + <item rowspan="6"><para>A</para></item> + <item rowspan="6"><para>B</para></item> + <item><para>C</para></item> + <item><para>D</para></item> + </row> + <row> + <item><para>E</para></item> + <item><para>F</para></item> + </row> + <row> + <item><para>E</para></item> + <item><para>F</para></item> + </row> + <row> + <item><para>E</para></item> + <item><para>F</para></item> + </row> + <row> + <item><para>E</para></item> + <item><para>F</para></item> + </row> + <row> + <item><para>E</para></item> + <item><para>F</para></item> + </row> +</table>)"; + + expected = R"( + +--+--+--+--+ + |h1|h2|h3|h4| + +==+==+==+==+ + |A |B |C |D | + + + +--+--+ + | | |E |F | + + + +--+--+ + | | |E |F | + + + +--+--+ + | | |E |F | + + + +--+--+ + | | |E |F | + + + +--+--+ + | | |E |F | + +--+--+--+--+ + +)"; QTest::newRow("testRowSpan2") << QString::fromLatin1(xml) << QString::fromLatin1(expected); + // testNestedList + xml = R"(<table> + <row> + <item> + <list type="bullet"> + <item> + <para>I11</para> + </item> + <item> + <para>I21</para> + </item> + </list> + </item> + <item> + <list type="bullet"> + <item> + <para>I12</para> + </item> + <item> + <para>I22</para> + </item> + </list> + </item> + </row> +</table>)"; + + expected = R"( + +---------+---------+ + | * I11| * I12| + | * I21| * I22| + +---------+---------+ + +)"; + + QTest::newRow("testNestedList") + << QString::fromLatin1(xml) << QString::fromLatin1(expected); + // testBrokenTable - xml = "\ -<table>\ - <header>\ - <item>\ - <para>Header 1</para>\ - </item>\ - <item>\ - <para>Header 2</para>\ - </item>\ - </header>\ - <row>\ - <item>\ - <para>1.1</para>\ - </item>\ - <item>\ - <para>1.2</para>\ - </item>\ - </row>\ - <row>\ - <item colspan=\"2\">\ - <para>2 2</para>\ - </item>\ - <item>\ - <para>2 3</para>\ - </item>\ - <item>\ - <para>2 4</para>\ - </item>\ - <item>\ - <para>2 5</para>\ - </item>\ - </row>\ - <row>\ - <item>\ - <para>3 1</para>\ - </item>\ - <item>\ - <para>3 2</para>\ - </item>\ - <item>\ - <para>3 3</para>\ - </item>\ - </row>\ -</table>"; - - expected = "\n\ - +--------+------------+\n\ - |Header 1|Header 2 |\n\ - +--------+------------+\n\ - |1.1 |1.2 |\n\ - +--------+------------+\n\ - |2 2 2 3 2 4 2 5|\n\ - +--------+------------+\n\ - |3 1 |3 2 3 3 |\n\ - +--------+------------+\n\ -\n"; + xml = R"(<table> + <header> + <item> + <para>Header 1</para> + </item> + <item> + <para>Header 2</para> + </item> + </header> + <row> + <item> + <para>1.1</para> + </item> + <item> + <para>1.2</para> + </item> + </row> + <row> + <item colspan="2"> + <para>2 2</para> + </item> + <item> + <para>2 3</para> + </item> + <item> + <para>2 4</para> + </item> + <item> + <para>2 5</para> + </item> + </row> + <row> + <item> + <para>3 1</para> + </item> + <item> + <para>3 2</para> + </item> + <item> + <para>3 3</para> + </item> + </row> +</table>)"; + + expected = R"( + +--------+------------+ + |Header 1|Header 2 | + +========+============+ + |1.1 |1.2 | + +--------+------------+ + |2 2 2 3 2 4 2 5| + +--------+------------+ + |3 1 |3 2 3 3 | + +--------+------------+ + +)"; QTest::newRow("testBrokenTable") << QString::fromLatin1(xml) << QString::fromLatin1(expected); @@ -369,26 +384,20 @@ void QtXmlToSphinxTest::testTable() QCOMPARE(actual, expected); } -using TablePtr = QSharedPointer<QtXmlToSphinx::Table>; +using TablePtr = std::shared_ptr<QtXmlToSphinx::Table>; Q_DECLARE_METATYPE(TablePtr); void QtXmlToSphinxTest::testTableFormatting_data() { - using TableRow = QtXmlToSphinx::TableRow; using TableCell = QtXmlToSphinx::TableCell; QTest::addColumn<TablePtr>("table"); QTest::addColumn<QString>("expected"); TablePtr table(new QtXmlToSphinx::Table); - TableRow row; - row << TableCell("item11") << TableCell("item12"); - table->appendRow(row); - row.clear(); - row << TableCell("") << TableCell("item22"); - table->appendRow(row); - row.clear(); + table->appendRow({TableCell("item11"), TableCell("item12")}); + table->appendRow({TableCell(""), TableCell("item22")}); table->normalize(); const char *expected = R"(+------+------+ @@ -402,12 +411,8 @@ void QtXmlToSphinxTest::testTableFormatting_data() QTest::newRow("normal") << table << QString::fromLatin1(expected); table.reset(new QtXmlToSphinx::Table); - row << TableCell("item11") << TableCell("item12\nline2"); - table->appendRow(row); - row.clear(); - row << TableCell("") << TableCell("item22\nline2\nline3"); - table->appendRow(row); - row.clear(); + table->appendRow({TableCell("item11"), TableCell("item12\nline2")}); + table->appendRow({TableCell(""), TableCell("item22\nline2\nline3")}); table->normalize(); expected = R"(+------+------+ @@ -456,4 +461,51 @@ void QtXmlToSphinxTest::testTableFormattingIoDevice() QCOMPARE(actual, expected); } +void QtXmlToSphinxTest::testSnippetExtraction_data() +{ + QTest::addColumn<QByteArray>("file"); + QTest::addColumn<QLatin1StringView>("id"); + QTest::addColumn<QString>("expected"); + + const char *fileCpp = R"(bla +// ![snip1] +snip1_line1 +// ![snip1] // ![snip2] +snip2_line1 +snip2_line2 +// ![snip2] // ![snip3] +)"; + + constexpr auto id = "snip2"_L1; + const QString expected = uR"(snip2_line1 +snip2_line2 +)"_s; + + const char *filePython = R"(bla +# ![snip1] +snip1_line1 +# ![snip1] # ![snip2] +snip2_line1 +snip2_line2 +# ![snip2] # ![snip3] +)"; + + QTest::newRow("c++") << QByteArray(fileCpp) << id << expected; + QTest::newRow("Python") << QByteArray(filePython) << id << expected; +} + +void QtXmlToSphinxTest::testSnippetExtraction() +{ + QFETCH(QByteArray, file); + QFETCH(QLatin1StringView, id); + QFETCH(QString, expected); + + QBuffer buffer(&file); + QVERIFY(buffer.open(QIODevice::ReadOnly)); + QString errorMessage; + QString actual = QtXmlToSphinx::readSnippet(buffer, id, &errorMessage); + QVERIFY2(errorMessage.isEmpty(), qPrintable(errorMessage)); + QCOMPARE(actual, expected); +} + QTEST_APPLESS_MAIN( QtXmlToSphinxTest) diff --git a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.h b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.h index 8f74baaf5..0a210b7a0 100644 --- a/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.h +++ b/sources/shiboken6/tests/qtxmltosphinxtest/qtxmltosphinxtest.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #ifndef QTXMLTOSPHINXTEST_H #define QTXMLTOSPHINXTEST_H @@ -52,6 +27,8 @@ private slots: void testTableFormatting(); void testTableFormattingIoDevice_data(); void testTableFormattingIoDevice(); + void testSnippetExtraction_data(); + void testSnippetExtraction(); private: QString transformXml(const QString &xml) const; diff --git a/sources/shiboken6/tests/samplebinding/CMakeLists.txt b/sources/shiboken6/tests/samplebinding/CMakeLists.txt index 558140279..fc812feb8 100644 --- a/sources/shiboken6/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken6/tests/samplebinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(sample) set(sample_TYPESYSTEM @@ -27,6 +30,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/customoverloadsequence_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/cvlistuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/cvvaluetype_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sbkdate_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/deleteddefaultctor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derivedusingct_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_someinnerclass_wrapper.cpp @@ -106,17 +110,20 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_sample_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_ctparam_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_inlinenamespace_classwithininlinenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someinnerclass_okthisisrecursiveenough_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someinnerclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someotherinnerclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_derivedfromnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/stdcomplex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/simplefile_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/size_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sizef_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/snakecasetest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/snakecasederivedtest_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sonofmderived1_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/spaceshipcomparisontester_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/str_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/strlist_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/time_wrapper.cpp @@ -141,13 +148,19 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/union_wrapper.cpp configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${sample_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'sample' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${sample_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/sample-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${sample_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'sample' test binding..." ) add_library(sample MODULE ${sample_SRC}) diff --git a/sources/shiboken6/tests/samplebinding/__del___test.py b/sources/shiboken6/tests/samplebinding/__del___test.py index 146e6e409..456886614 100644 --- a/sources/shiboken6/tests/samplebinding/__del___test.py +++ b/sources/shiboken6/tests/samplebinding/__del___test.py @@ -1,34 +1,8 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import gc import os import sys import unittest @@ -42,17 +16,21 @@ import sample delCalled = False + class MyObject(sample.ObjectType): def __del__(self): global delCalled delCalled = True + class TestDel(unittest.TestCase): def testIt(self): a = MyObject() del a + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(delCalled) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/abstract_test.py b/sources/shiboken6/tests/samplebinding/abstract_test.py index 7fa0a0012..89e87be1d 100644 --- a/sources/shiboken6/tests/samplebinding/abstract_test.py +++ b/sources/shiboken6/tests/samplebinding/abstract_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Abstract class''' @@ -42,10 +15,12 @@ init_paths() from sample import Abstract + class Incomplete(Abstract): def __init__(self): Abstract.__init__(self) + class Concrete(Abstract): def __init__(self): Abstract.__init__(self) @@ -87,12 +62,7 @@ class AbstractTest(unittest.TestCase): # Python and calling it from C++ is undefined until it's decided how to # cast the Python data types to void pointers c = Concrete() - self.assertEqual(c.pureVirtualReturningVoidPtr(),42) - - def testReimplementedVirtualMethodCall(self): - '''Test if instanciation of an abstract class raises the correct exception.''' - i = Concrete() - self.assertRaises(NotImplementedError, i.callPureVirtual) + self.assertEqual(c.pureVirtualReturningVoidPtr(), 42) def testReimplementedVirtualMethodCall(self): '''Test if a Python override of a virtual method is correctly called from C++.''' @@ -112,6 +82,6 @@ class AbstractTest(unittest.TestCase): c.callVirtualGettingEnum(Abstract.Short) self.assertTrue(c.virtual_getting_enum) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/addedfunction_test.py b/sources/shiboken6/tests/samplebinding/addedfunction_test.py index 134e73c55..0b5680143 100644 --- a/sources/shiboken6/tests/samplebinding/addedfunction_test.py +++ b/sources/shiboken6/tests/samplebinding/addedfunction_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for added functions.''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from sample import SampleNamespace, ObjectType, Point + class TestAddedFunctionsWithSimilarTypes(unittest.TestCase): '''Adds new signatures very similar to already existing ones.''' @@ -65,5 +39,6 @@ class TestAddedFunctionsWithSimilarTypes(unittest.TestCase): control = len(obj.objectName()) self.assertEqual(SampleNamespace.passReferenceToObjectType(obj), control) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py b/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py index 570d3ddd9..2a739033b 100644 --- a/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py +++ b/sources/shiboken6/tests/samplebinding/addedfunction_with_container_args_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for added functions with nested and multi-argument container types.''' @@ -41,18 +14,20 @@ from shiboken_paths import init_paths init_paths() from sample import sum2d, sumproduct + class TestAddedFunctionsWithContainerArgs(unittest.TestCase): '''Tests added functions with nested and multi-argument container types.''' def testNestedContainerType(self): '''Test added function with single-argument containers.''' - values = [[1,2],[3,4,5],[6]] + values = [[1, 2], [3, 4, 5], [6]] self.assertEqual(sum2d(values), 21) def testMultiArgContainerType(self): '''Test added function with a two-argument container.''' - values = [(1,2),(3,4),(5,6)] + values = [(1, 2), (3, 4), (5, 6)] self.assertEqual(sumproduct(values), 44) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py index 86d0a4731..b0ca56a6d 100644 --- a/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py +++ b/sources/shiboken6/tests/samplebinding/argumentmodifications_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for method arguments modifications performed as described on typesystem.''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import Modifications, Point + class ArgumentModificationsTest(unittest.TestCase): '''Test cases for method arguments modifications performed as described on typesystem.''' @@ -50,6 +25,8 @@ class ArgumentModificationsTest(unittest.TestCase): def tearDown(self): del self.mods + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testArgRemoval0(self): '''Tests argument removal modifications on Modifications.argRemoval0.''' @@ -64,7 +41,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval1(self): '''Tests argument removal modifications on Modifications.argRemoval1.''' - # void [-> PyObject*] argRemoval1(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval1(int, bool, Point = Point(1, 2) [removed], + # Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval1(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) @@ -75,7 +53,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval2(self): '''Tests argument removal modifications on Modifications.argRemoval2.''' - # void [-> PyObject*] argRemoval2(int, bool, Point = Point(1, 2) [removed], Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval2(int, bool, Point = Point(1, 2) + # [removed], Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval2(a0, a1), (a0, a1, Point(1, 2), Point(3, 4), 333)) @@ -83,7 +62,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval3(self): '''Tests argument removal modifications on Modifications.argRemoval3.''' - # void [-> PyObject*] argRemoval3(int, Point = Point(1, 2) [removed], bool = true, Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval3(int, Point = Point(1, 2) [removed], + # bool = true, Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertEqual(self.mods.argRemoval3(a0), (a0, Point(1, 2), True, Point(3, 4), 333)) @@ -92,7 +72,8 @@ class ArgumentModificationsTest(unittest.TestCase): def testArgRemoval4(self): '''Tests argument removal modifications on Modifications.argRemoval4.''' - # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, Point = Point(3, 4) [removed], int = 333) + # void [-> PyObject*] argRemoval4(int, Point [removed, new val = Point(6, 9)], bool, + # Point = Point(3, 4) [removed], int = 333) # code-injection: returns tuple with received parameters plus removed ones a0, a1, a2 = 1, True, 2 self.assertRaises(TypeError, self.mods.argRemoval4, a0) @@ -112,6 +93,6 @@ class ArgumentModificationsTest(unittest.TestCase): # code-injection: returns tuple with received parameters plus removed ones self.assertEqual(self.mods.argRemoval5(a0, a1, a2), (200, a0, a1, a2)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/array_numpy_test.py b/sources/shiboken6/tests/samplebinding/array_numpy_test.py index c3d438a88..0d73bca1c 100644 --- a/sources/shiboken6/tests/samplebinding/array_numpy_test.py +++ b/sources/shiboken6/tests/samplebinding/array_numpy_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2017 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for NumPy Array types.''' @@ -48,24 +22,26 @@ try: except ImportError: pass + class ArrayTester(unittest.TestCase): '''Test case for NumPy arrays.''' def testIntArray(self): - intList = numpy.array([1, 2, 3, 4], dtype = 'int32') + intList = numpy.array([1, 2, 3, 4], dtype='int32') self.assertEqual(sample.sumIntArray(intList), 10) def testDoubleArray(self): - doubleList = numpy.array([1, 2, 3, 4], dtype = 'double') + doubleList = numpy.array([1, 2, 3, 4], dtype='double') self.assertEqual(sample.sumDoubleArray(doubleList), 10) def testIntMatrix(self): - intMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'int32') + intMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype='int32') self.assertEqual(sample.sumIntMatrix(intMatrix), 21) def testDoubleMatrix(self): - doubleMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype = 'double') + doubleMatrix = numpy.array([[1, 2, 3], [4, 5, 6]], dtype='double') self.assertEqual(sample.sumDoubleMatrix(doubleMatrix), 21) + if __name__ == '__main__' and hasNumPy: unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/array_sequence_test.py b/sources/shiboken6/tests/samplebinding/array_sequence_test.py index e39c2733c..ad65d58db 100644 --- a/sources/shiboken6/tests/samplebinding/array_sequence_test.py +++ b/sources/shiboken6/tests/samplebinding/array_sequence_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2017 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for Array types (PySequence).''' @@ -40,6 +14,7 @@ from shiboken_paths import init_paths init_paths() import sample + class ArrayTester(unittest.TestCase): '''Test case for arrays.''' @@ -56,5 +31,6 @@ class ArrayTester(unittest.TestCase): doubleList = [1.2, 2.3, 3.4, 4.5] self.assertEqual(sample.sumDoubleArray(doubleList), 11.4) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/bug_554_test.py b/sources/shiboken6/tests/samplebinding/bug_554_test.py index f3950af9c..a7e7a7210 100644 --- a/sources/shiboken6/tests/samplebinding/bug_554_test.py +++ b/sources/shiboken6/tests/samplebinding/bug_554_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Unit test for bug#554''' @@ -38,15 +11,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType + class Bug554: def crash(self): class Crasher(ObjectType): pass + if __name__ == '__main__': bug = Bug554() bug.crash() - - diff --git a/sources/shiboken6/tests/samplebinding/bug_704_test.py b/sources/shiboken6/tests/samplebinding/bug_704_test.py index 365941b46..c470fe723 100644 --- a/sources/shiboken6/tests/samplebinding/bug_704_test.py +++ b/sources/shiboken6/tests/samplebinding/bug_704_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -52,13 +25,12 @@ def defineNewStyle(): class ObjectTypeTest(unittest.TestCase): - '''Test cases to avoid declaring Shiboken classes with multiple inheritance from old style classes.''' + '''Test cases to avoid declaring Shiboken classes with multiple inheritance + from old style classes.''' def testObjectTypeNewStype(self): defineNewStyle() - if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/bytearray_test.py b/sources/shiboken6/tests/samplebinding/bytearray_test.py index bcf61a2d5..e51a899fa 100644 --- a/sources/shiboken6/tests/samplebinding/bytearray_test.py +++ b/sources/shiboken6/tests/samplebinding/bytearray_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -61,7 +34,7 @@ class ByteArrayConcatenationOperatorTest(unittest.TestCase): def testConcatPythonStringAndByteArray(self): # Test concatenation of a Python string with a ByteArray, in this order. - concat_python_string_add_qbytearray_worked = True + concat_python_string_add_qbytearray_worked = True # noqa: F841 ba = ByteArray('foo') result = 'bar\x00' + ba self.assertEqual(type(result), ByteArray) @@ -107,14 +80,14 @@ class ByteArrayOperatorAt(unittest.TestCase): # ByteArray[x] where x is a valid index (reverse order). string = 'abcdefgh' obj = ByteArray(string) - for i in range(len(string)-1, 0, -1): + for i in range(len(string) - 1, 0, -1): self.assertEqual(obj[i], bytes(string[i], "UTF8")) def testOutOfRange(self): # ByteArray[x] where x is out of index. string = '1234567' obj = ByteArray(string) - self.assertRaises(IndexError, lambda :obj[len(string)]) + self.assertRaises(IndexError, lambda: obj[len(string)]) def testNullStrings(self): ba = ByteArray('\x00') diff --git a/sources/shiboken6/tests/samplebinding/child_return_test.py b/sources/shiboken6/tests/samplebinding/child_return_test.py index 4b9a18e7b..f0ac70626 100644 --- a/sources/shiboken6/tests/samplebinding/child_return_test.py +++ b/sources/shiboken6/tests/samplebinding/child_return_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -40,7 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType + class ReturnOfChildTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between C++ and Python.''' @@ -50,6 +25,8 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.children()[0] del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) def testKillParentKeepingChild2(self): @@ -57,8 +34,10 @@ class ReturnOfChildTest(unittest.TestCase): o1 = ObjectType.createWithChild() child = o1.findChild("child") del o1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/class_fields_test.py b/sources/shiboken6/tests/samplebinding/class_fields_test.py index a29c84b1a..1eeb3d446 100644 --- a/sources/shiboken6/tests/samplebinding/class_fields_test.py +++ b/sources/shiboken6/tests/samplebinding/class_fields_test.py @@ -1,39 +1,11 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple test case for accessing the exposed C++ class fields.''' import os import sys -from sys import getrefcount import unittest from pathlib import Path @@ -43,6 +15,7 @@ init_paths() from sample import Derived, Point, ObjectType + class TestAccessingCppFields(unittest.TestCase): '''Simple test case for accessing the exposed C++ class fields.''' @@ -64,7 +37,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.primitiveField, int(value)) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'primitiveField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'primitiveField', None)) def testAccessingRenamedFields(self): '''Reads and writes a renamed field.''' @@ -100,7 +73,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertNotEqual(d.userPrimitiveField, old_value) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'userPrimitiveField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'userPrimitiveField', None)) def testAccessingValueTypeField(self): '''Reads and writes a value type (in this case a 'Point') field.''' @@ -108,7 +81,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(type(d.valueTypeField), Point) # attribution - old_value = d.valueTypeField + old_value = d.valueTypeField # noqa: F841 new_value = Point(-10, 537) d.valueTypeField = new_value self.assertEqual(d.valueTypeField, new_value) @@ -120,7 +93,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.valueTypeField.y(), 20) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'valueTypeField', 123)) + self.assertRaises(TypeError, lambda: setattr(d, 'valueTypeField', 123)) def testAccessingObjectTypeField(self): '''Reads and writes a object type (in this case an 'ObjectType') field.''' @@ -139,36 +112,40 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.objectTypeField, value) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'objectTypeField', 123)) + self.assertRaises(TypeError, lambda: setattr(d, 'objectTypeField', 123)) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRefCountingAccessingObjectTypeField(self): '''Accessing a object type field should respect the reference counting rules.''' d = Derived() # attributing object to instance's field should increase its reference count o1 = ObjectType() - refcount1 = getrefcount(o1) + refcount1 = sys.getrefcount(o1) d.objectTypeField = o1 self.assertEqual(d.objectTypeField, o1) - self.assertEqual(getrefcount(d.objectTypeField), refcount1 + 1) + self.assertEqual(sys.getrefcount(d.objectTypeField), refcount1 + 1) - # attributing a new object to instance's field should decrease the previous object's reference count + # attributing a new object to instance's field should decrease the previous + # object's reference count o2 = ObjectType() - refcount2 = getrefcount(o2) + refcount2 = sys.getrefcount(o2) d.objectTypeField = o2 self.assertEqual(d.objectTypeField, o2) - self.assertEqual(getrefcount(o1), refcount1) - self.assertEqual(getrefcount(d.objectTypeField), refcount2 + 1) + self.assertEqual(sys.getrefcount(o1), refcount1) + self.assertEqual(sys.getrefcount(d.objectTypeField), refcount2 + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRefCountingOfReferredObjectAfterDeletingReferrer(self): - '''Deleting the object referring to other object should decrease the reference count of the referee.''' + '''Deleting the object referring to other object should decrease the + reference count of the referee.''' d = Derived() o = ObjectType() - refcount = getrefcount(o) + refcount = sys.getrefcount(o) d.objectTypeField = o - self.assertEqual(getrefcount(o), refcount + 1) + self.assertEqual(sys.getrefcount(o), refcount + 1) del d - self.assertEqual(getrefcount(o), refcount) + self.assertEqual(sys.getrefcount(o), refcount) def testStaticField(self): self.assertEqual(Derived.staticPrimitiveField, 0) @@ -179,7 +156,7 @@ class TestAccessingCppFields(unittest.TestCase): # attribution old_value = d.bitField new_value = 1 - d.bitField= new_value + d.bitField = new_value self.assertEqual(d.bitField, new_value) self.assertNotEqual(d.bitField, old_value) @@ -189,7 +166,7 @@ class TestAccessingCppFields(unittest.TestCase): self.assertEqual(d.bitField, int(value)) # attribution with invalid type - self.assertRaises(TypeError, lambda : setattr(d, 'bitField', None)) + self.assertRaises(TypeError, lambda: setattr(d, 'bitField', None)) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/collector_test.py b/sources/shiboken6/tests/samplebinding/collector_test.py index c68230474..4caebc62a 100644 --- a/sources/shiboken6/tests/samplebinding/collector_test.py +++ b/sources/shiboken6/tests/samplebinding/collector_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Collector class' shift operators.''' @@ -60,6 +33,7 @@ class CollectorTest(unittest.TestCase): self.assertEqual(collector.size(), 5) self.assertEqual(collector.items(), [2, 3, 5, 7, 11]) + class CollectorExternalOperator(unittest.TestCase): '''Test cases for external operators of Collector''' @@ -84,4 +58,3 @@ class CollectorObjectType(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/complex_test.py b/sources/shiboken6/tests/samplebinding/complex_test.py index 272eee357..454aff100 100644 --- a/sources/shiboken6/tests/samplebinding/complex_test.py +++ b/sources/shiboken6/tests/samplebinding/complex_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Complex class''' @@ -43,6 +16,7 @@ init_paths() import sample from sample import Point + class ComplexTest(unittest.TestCase): '''Test case for conversions between C++ Complex class to Python complex class''' @@ -74,11 +48,14 @@ class ComplexTest(unittest.TestCase): def testUsingTuples(self): cpx1, cpx2 = (1.2, 3.4), (5.6, 7.8) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1, 3), (5, 7) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1.2, 3), (5.6, 7) - self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) + self.assertEqual(sample.sumComplexPair((cpx1, cpx2)), + sample.sumComplexPair((complex(*cpx1), complex(*cpx2)))) cpx1, cpx2 = (1, 2, 3), (4, 5, 7) self.assertRaises(TypeError, sample.sumComplexPair, (cpx1, cpx2)) cpx1, cpx2 = ('1', '2'), ('4', '5') @@ -87,4 +64,3 @@ class ComplexTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/conversion_operator_test.py b/sources/shiboken6/tests/samplebinding/conversion_operator_test.py index eb802f43b..7e76245b1 100644 --- a/sources/shiboken6/tests/samplebinding/conversion_operator_test.py +++ b/sources/shiboken6/tests/samplebinding/conversion_operator_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for implicit conversion generated by conversion operator.''' @@ -42,11 +15,13 @@ init_paths() from sample import Time, StrList + class ConversionOperatorTest(unittest.TestCase): '''Test cases for implicit conversion generated by conversion operator.''' def testConversionOperator(self): - '''Time defined an conversion operator for Str, so passing a Time object to a method expecting a Str should work.''' + '''Time defined an conversion operator for Str, so passing a Time object + to a method expecting a Str should work.''' t = Time(1, 2, 3) t_str = t.toString() sl = StrList() @@ -57,6 +32,6 @@ class ConversionOperatorTest(unittest.TestCase): self.assertEqual(len(sl), 1) self.assertEqual(sl[0], t_str) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/copy_test.py b/sources/shiboken6/tests/samplebinding/copy_test.py index 63d9163ba..db539d1b9 100644 --- a/sources/shiboken6/tests/samplebinding/copy_test.py +++ b/sources/shiboken6/tests/samplebinding/copy_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for deep copy of objects''' @@ -90,4 +63,3 @@ class PicklingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py b/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py index be8e11bc4..5e2695d72 100644 --- a/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py +++ b/sources/shiboken6/tests/samplebinding/ctorconvrule_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for proper generation of constructor altered by conversion-rule tag.''' @@ -42,6 +15,7 @@ init_paths() from sample import CtorConvRule + class TestCtorConvRule(unittest.TestCase): '''Simple test case for CtorConvRule''' @@ -51,6 +25,6 @@ class TestCtorConvRule(unittest.TestCase): obj = CtorConvRule(value) self.assertEqual(obj.value(), value + 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/cyclic_test.py b/sources/shiboken6/tests/samplebinding/cyclic_test.py index 5a20216b6..4e4ae2603 100644 --- a/sources/shiboken6/tests/samplebinding/cyclic_test.py +++ b/sources/shiboken6/tests/samplebinding/cyclic_test.py @@ -1,34 +1,8 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import gc import os import sys import unittest @@ -42,7 +16,6 @@ from sample import ObjectView from sample import ObjectModel - class ObjTest(unittest.TestCase): def test_cyclic_dependency_withParent(self): @@ -50,8 +23,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectType): def __init__(self, parent): super(CyclicChildObject, self).__init__(parent) @@ -65,7 +36,7 @@ class ObjTest(unittest.TestCase): # turn off automatic garbage collection, to be able to trigger it # at the 'right' time gc.disable() - alive = lambda :sum(isinstance(o, CyclicObject) for o in gc.get_objects() ) + alive = lambda: sum(isinstance(o, CyclicObject) for o in gc.get_objects()) # noqa: E731 # # first proof that the wizard is only destructed by the garbage @@ -74,7 +45,9 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) @@ -83,8 +56,6 @@ class ObjTest(unittest.TestCase): only be removed by the garbage collector, and then invoke the garbage collector in a different thread. """ - import gc - class CyclicChildObject(ObjectView): def __init__(self, model): super(CyclicChildObject, self).__init__(None) @@ -98,7 +69,7 @@ class ObjTest(unittest.TestCase): # turn off automatic garbage collection, to be able to trigger it # at the 'right' time gc.disable() - alive = lambda :sum(isinstance(o, CyclicObject) for o in gc.get_objects() ) + alive = lambda: sum(isinstance(o, CyclicObject) for o in gc.get_objects()) # noqa: E731 # # first proof that the wizard is only destructed by the garbage @@ -107,10 +78,12 @@ class ObjTest(unittest.TestCase): cycle = CyclicObject() self.assertTrue(alive()) del cycle - self.assertTrue(alive()) + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: the semantics of gc.enable/gc.disable is different for PyPy + self.assertTrue(alive()) gc.collect() self.assertFalse(alive()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/date_test.py b/sources/shiboken6/tests/samplebinding/date_test.py index ad1419391..2b6efcf18 100644 --- a/sources/shiboken6/tests/samplebinding/date_test.py +++ b/sources/shiboken6/tests/samplebinding/date_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for python conversions types ''' @@ -43,6 +16,7 @@ from datetime import date from sample import SbkDate + class DateConversionTest(unittest.TestCase): def testConstructorWithDateObject(self): @@ -59,6 +33,6 @@ class DateConversionTest(unittest.TestCase): self.assertTrue(cDate.month(), pyDate.month) self.assertTrue(cDate.year(), pyDate.year) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/decisor_test.py b/sources/shiboken6/tests/samplebinding/decisor_test.py index 128b3c913..0d39c5f96 100644 --- a/sources/shiboken6/tests/samplebinding/decisor_test.py +++ b/sources/shiboken6/tests/samplebinding/decisor_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for the method overload decisor.''' @@ -42,6 +15,7 @@ init_paths() from sample import SampleNamespace, Point, ObjectType, ObjectModel + class DecisorTest(unittest.TestCase): '''Test cases for the method overload decisor.''' @@ -64,11 +38,15 @@ class DecisorTest(unittest.TestCase): '''Call methods overloads that receive parent and inheritor classes' instances.''' objecttype = ObjectType() objectmodel = ObjectModel() - self.assertEqual(ObjectModel.receivesObjectTypeFamily(objecttype), ObjectModel.ObjectTypeCalled) - self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objecttype), ObjectModel.ObjectModelCalled) - self.assertEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), ObjectModel.ObjectModelCalled) - self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), ObjectModel.ObjectTypeCalled) + self.assertEqual(ObjectModel.receivesObjectTypeFamily(objecttype), + ObjectModel.ObjectTypeCalled) + self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objecttype), + ObjectModel.ObjectModelCalled) + self.assertEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), + ObjectModel.ObjectModelCalled) + self.assertNotEqual(ObjectModel.receivesObjectTypeFamily(objectmodel), + ObjectModel.ObjectTypeCalled) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/delete_test.py b/sources/shiboken6/tests/samplebinding/delete_test.py index 8fb663eb1..57a792ae2 100644 --- a/sources/shiboken6/tests/samplebinding/delete_test.py +++ b/sources/shiboken6/tests/samplebinding/delete_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,15 +14,15 @@ init_paths() import sample from shiboken6 import Shiboken + class DeleteTest(unittest.TestCase): def testNonCppWrapperClassDelete(self): - """Would segfault when shiboken.delete called on obj not created from - Python """ + """Would segfault when shiboken.delete called on obj not created from Python.""" obj = sample.ObjectType() child = obj.createChild(None) Shiboken.delete(child) assert not Shiboken.isValid(child) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/deprecated_test.py b/sources/shiboken6/tests/samplebinding/deprecated_test.py index 8a1d37cfc..c371df94f 100644 --- a/sources/shiboken6/tests/samplebinding/deprecated_test.py +++ b/sources/shiboken6/tests/samplebinding/deprecated_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,11 +14,13 @@ init_paths() from sample import ObjectType + class TestDeprecatedCall(unittest.TestCase): def testCallWithError(self): o = ObjectType() warnings.simplefilter('error') self.assertRaises(DeprecationWarning, o.deprecatedFunction) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/derived_test.py b/sources/shiboken6/tests/samplebinding/derived_test.py index 8bdb051a8..346f29136 100644 --- a/sources/shiboken6/tests/samplebinding/derived_test.py +++ b/sources/shiboken6/tests/samplebinding/derived_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Derived class''' @@ -43,6 +16,7 @@ init_paths() import sample from sample import Abstract, Derived, DerivedUsingCt, OverloadedFuncEnum + class Deviant(Derived): def __init__(self): Derived.__init__(self) @@ -58,6 +32,16 @@ class Deviant(Derived): def className(self): return 'Deviant' + +class ImplementVirtualWithOutParameter(Derived): + def __init__(self, value): + super().__init__() + self._value = value + + def virtualWithOutParameter(self): + return self._value + + class DerivedTest(unittest.TestCase): '''Test case for Derived class''' @@ -67,22 +51,6 @@ class DerivedTest(unittest.TestCase): 'id_', 'pureVirtual', 'unpureVirtual']) self.assertTrue(inherited_methods.issubset(dir(Derived))) - def testOverloadedMethodCall(self): - '''Test if the correct overloaded method is being called.''' - derived = Derived() - - result = derived.overloaded(1, 2) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(3) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) - - result = derived.overloaded(4.4) - self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_d) - def testOtherOverloadedMethodCall(self): '''Another test to check overloaded method calling, just to double check.''' derived = Derived() @@ -100,21 +68,23 @@ class DerivedTest(unittest.TestCase): derived = Derived() result = derived.overloaded(1.1, 2.2) self.assertEqual(type(result), OverloadedFuncEnum) - self.assertEqual(result, sample.OverloadedFunc_ii) def testOverloadedMethodCallWithWrongNumberOfArguments(self): - '''Test if a call to an overloaded method with the wrong number of arguments raises an exception.''' + '''Test if a call to an overloaded method with the wrong number of arguments + raises an exception.''' derived = Derived() self.assertRaises(TypeError, derived.otherOverloaded, 1, 2, True) def testReimplementedPureVirtualMethodCall(self): - '''Test if a Python override of a implemented pure virtual method is correctly called from C++.''' + '''Test if a Python override of a implemented pure virtual method is + correctly called from C++.''' d = Deviant() d.callPureVirtual() self.assertTrue(d.pure_virtual_called) def testReimplementedVirtualMethodCall(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() d.callUnpureVirtual() self.assertTrue(d.unpure_virtual_called) @@ -126,7 +96,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(d.getClassName(), 'Derived') def testReimplementedVirtualMethodCallReturningString(self): - '''Test if a Python override of a reimplemented virtual method is correctly called from C++.''' + '''Test if a Python override of a reimplemented virtual method is + correctly called from C++.''' d = Deviant() self.assertEqual(d.className(), 'Deviant') self.assertEqual(d.getClassName(), 'Deviant') @@ -150,7 +121,8 @@ class DerivedTest(unittest.TestCase): self.assertEqual(Abstract.getObjectId(d), objId) def testObjectCreationWithParentType(self): - '''Derived class creates an instance of itself in C++ and returns it as a pointer to its ancestor Abstract.''' + '''Derived class creates an instance of itself in C++ and returns it as + a pointer to its ancestor Abstract.''' obj = Derived.createObject() self.assertEqual(type(obj), Derived) @@ -159,7 +131,13 @@ class DerivedTest(unittest.TestCase): obj = DerivedUsingCt(42) self.assertEqual(obj.value(), 42) + def testVirtualWithOutParameter(self): + d = Derived() + self.assertEqual(d.callVirtualWithOutParameter(), 42) + + d = ImplementVirtualWithOutParameter(1) + self.assertEqual(d.callVirtualWithOutParameter(), 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/duck_punching_test.py b/sources/shiboken6/tests/samplebinding/duck_punching_test.py index 9b0d7a9ff..aa21a0f7e 100644 --- a/sources/shiboken6/tests/samplebinding/duck_punching_test.py +++ b/sources/shiboken6/tests/samplebinding/duck_punching_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods.''' @@ -43,6 +16,7 @@ init_paths() from sample import VirtualMethods, SimpleFile, Point + def MethodTypeCompat(func, instance): return types.MethodType(func, instance) @@ -51,10 +25,12 @@ class Duck(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) + class Monkey(SimpleFile): def __init__(self, filename): SimpleFile.__init__(self, filename) + class DuckPunchingTest(unittest.TestCase): '''Test case for duck punching (aka "monkey patching").''' @@ -83,7 +59,8 @@ class DuckPunchingTest(unittest.TestCase): result2 = vm.virtualMethod0(pt, val, cpx, b) self.assertEqual(result1, result2) - self.assertEqual(result1, VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier) + self.assertEqual(result1, + VirtualMethods.virtualMethod0(vm, pt, val, cpx, b) * self.multiplier) # This is done to decrease the refcount of the vm object # allowing the object wrapper to be deleted before the @@ -93,7 +70,8 @@ class DuckPunchingTest(unittest.TestCase): vm.virtualMethod0 = None def testMonkeyPatchOnVirtualMethodWithInheritance(self): - '''Injects new 'virtualMethod0' on an object that inherits from VirtualMethods and makes C++ call it.''' + '''Injects new 'virtualMethod0' on an object that inherits from + VirtualMethods and makes C++ call it.''' duck = Duck() pt, val, cpx, b = Point(1.1, 2.2), 4, complex(3.3, 4.4), True @@ -112,7 +90,8 @@ class DuckPunchingTest(unittest.TestCase): result2 = duck.virtualMethod0(pt, val, cpx, b) self.assertEqual(result1, result2) - self.assertEqual(result1, VirtualMethods.virtualMethod0(duck, pt, val, cpx, b) * self.multiplier) + self.assertEqual(result1, + VirtualMethods.virtualMethod0(duck, pt, val, cpx, b) * self.multiplier) duck.virtualMethod0 = None @@ -177,4 +156,3 @@ class DuckPunchingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/echo_test.py b/sources/shiboken6/tests/samplebinding/echo_test.py index 67be482f2..f1859260e 100644 --- a/sources/shiboken6/tests/samplebinding/echo_test.py +++ b/sources/shiboken6/tests/samplebinding/echo_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for <add-function> with const char* as argument''' @@ -42,6 +15,7 @@ init_paths() from sample import Echo + class TestEcho(unittest.TestCase): '''Simple test case for Echo.echo''' @@ -53,7 +27,8 @@ class TestEcho(unittest.TestCase): def testCallOperator(self): e = Echo() - self.assertEqual(e("Hello", 3), "Hello3"); + self.assertEqual(e("Hello", 3), "Hello3") + + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/enum_test.py b/sources/shiboken6/tests/samplebinding/enum_test.py index 66d7daf5b..276b8d894 100644 --- a/sources/shiboken6/tests/samplebinding/enum_test.py +++ b/sources/shiboken6/tests/samplebinding/enum_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Python representation of C++ enums.''' @@ -40,33 +13,27 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -import shiboken6 # This is needed after the introduction of BUILD_DIR. import sample from sample import SampleNamespace, ObjectType, Event + def createTempFile(): import tempfile return tempfile.SpooledTemporaryFile(mode='rw') + class EnumTest(unittest.TestCase): '''Test case for Python representation of C++ enums.''' - def testEnumRepr(self): - enum = SampleNamespace.Option(1) - self.assertEqual(eval(repr(enum)), enum) - - enum = SampleNamespace.Option(999) - self.assertEqual(eval(repr(enum)), enum) - def testHashability(self): self.assertEqual(hash(SampleNamespace.TwoIn), hash(SampleNamespace.TwoOut)) self.assertNotEqual(hash(SampleNamespace.TwoIn), hash(SampleNamespace.OneIn)) def testEnumValuesInsideEnum(self): '''Enum values should be accessible inside the enum as well as outside.''' - for value_name in SampleNamespace.Option.values: + for value_name in SampleNamespace.Option.__members__: enum_item1 = getattr(SampleNamespace.Option, value_name) enum_item2 = getattr(SampleNamespace, value_name) self.assertEqual(enum_item1, enum_item2) @@ -92,16 +59,18 @@ class EnumTest(unittest.TestCase): def testEnumConstructorWithTooManyParameters(self): '''Calling the constructor of non-extensible enum with the wrong number of parameters.''' - self.assertRaises(TypeError, SampleNamespace.InValue, 13, 14) + self.assertRaises((TypeError, ValueError), SampleNamespace.InValue, 13, 14) def testEnumConstructorWithNonNumberParameter(self): '''Calling the constructor of non-extensible enum with a string.''' - self.assertRaises(TypeError, SampleNamespace.InValue, '1') + self.assertRaises((TypeError, ValueError), SampleNamespace.InValue, '1') def testEnumItemAsDefaultValueToIntArgument(self): '''Calls function with an enum item as default value to an int argument.''' - self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(), SampleNamespace.ZeroIn) - self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(SampleNamespace.ZeroOut), SampleNamespace.ZeroOut) + self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(), + SampleNamespace.ZeroIn) + self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(SampleNamespace.ZeroOut), # noqa E:501 + SampleNamespace.ZeroOut) self.assertEqual(SampleNamespace.enumItemAsDefaultValueToIntArgument(123), 123) def testAnonymousGlobalEnums(self): @@ -126,49 +95,26 @@ class EnumTest(unittest.TestCase): self.assertEqual(event.eventType(), Event.BASIC_EVENT) event.setEventTypeByConstRef(Event.SOME_EVENT) self.assertEqual(event.eventType(), Event.SOME_EVENT) - - def testEnumTpPrintImplementation(self): - '''Without SbkEnum.tp_print 'print' returns the enum represented as an int.''' - tmpfile = createTempFile() - print(Event.ANY_EVENT, file=tmpfile) - tmpfile.seek(0) - text = tmpfile.read().strip() - tmpfile.close() - self.assertEqual(text, str(Event.ANY_EVENT)) - self.assertEqual(text, repr(Event.ANY_EVENT)) + event.setEventTypeByConstPtr(Event.BASIC_EVENT) + self.assertEqual(event.eventType(), Event.BASIC_EVENT) def testEnumArgumentWithDefaultValue(self): '''Option enumArgumentWithDefaultValue(Option opt = UnixTime);''' self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(), SampleNamespace.UnixTime) - self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(SampleNamespace.RandomNumber), SampleNamespace.RandomNumber) - - def testSignature(self): - enum = SampleNamespace.Option(1) - types = type(enum).mro() - klass = types[0] - base = types[1] - # The class has an empty signature. - self.assertEqual(klass.__signature__, None) - # The base class must be Enum - self.assertNotEqual(base.__signature__, None) - # It contains an int annotation. - param = base.__signature__.parameters["itemValue"] - self.assertEqual(param.annotation, int) + self.assertEqual(SampleNamespace.enumArgumentWithDefaultValue(SampleNamespace.RandomNumber), # noqa E:501 + SampleNamespace.RandomNumber) class MyEvent(Event): def __init__(self): - Event.__init__(self, Event.EventType(999)) + Event.__init__(self, Event.EventType(3)) + class OutOfBoundsTest(unittest.TestCase): def testValue(self): e = MyEvent() - self.assertEqual(repr(e.eventType()), 'sample.Event.EventType(999)') + self.assertEqual(repr(e.eventType()), "<EventType.ANY_EVENT: 3>") - def testNoneName(self): - e = MyEvent() - t = e.eventType() - self.assertEqual(t.name, None) class EnumOverloadTest(unittest.TestCase): '''Test case for overloads involving enums''' @@ -180,6 +126,7 @@ class EnumOverloadTest(unittest.TestCase): self.assertEqual(o.callWithEnum('', Event.ANY_EVENT, 9), 81) self.assertEqual(o.callWithEnum('', 9), 9) + class EnumOperators(unittest.TestCase): '''Test case for operations on enums''' @@ -189,4 +136,3 @@ class EnumOperators(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py index 72705c4c4..42ae23961 100644 --- a/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py +++ b/sources/shiboken6/tests/samplebinding/enumfromremovednamespace_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,15 +14,10 @@ init_paths() import sample from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature + class TestEnumFromRemovedNamespace(unittest.TestCase): - def testEnumPromotedToGlobal(self): - sample.RemovedNamespace1_Enum - self.assertEqual(sample.RemovedNamespace1_Enum_Value0, 0) - self.assertEqual(sample.RemovedNamespace1_Enum_Value1, 1) - sample.RemovedNamespace1_AnonymousEnum_Value0 - sample.RemovedNamespace2_Enum - sample.RemovedNamespace2_Enum_Value0 def testNames(self): # Test if invisible namespace does not appear on type name @@ -59,10 +27,10 @@ class TestEnumFromRemovedNamespace(unittest.TestCase): "sample.ObjectOnInvisibleNamespace") # Function arguments - signature = sample.ObjectOnInvisibleNamespace.toInt.__signature__ + signature = get_signature(sample.ObjectOnInvisibleNamespace.toInt) self.assertEqual(objectFullname(signature.parameters['e'].annotation), "sample.RemovedNamespace1_Enum") - signature = sample.ObjectOnInvisibleNamespace.consume.__signature__ + signature = get_signature(sample.ObjectOnInvisibleNamespace.consume) self.assertEqual(objectFullname(signature.parameters['other'].annotation), "sample.ObjectOnInvisibleNamespace") @@ -76,9 +44,8 @@ class TestEnumFromRemovedNamespace(unittest.TestCase): sample.UnremovedNamespace.RemovedNamespace3_AnonymousEnum_Value0 def testNestedFunctionFromRemovedNamespace(self): - self.assertEqual(sample.UnremovedNamespace.nestedMathSum(1, 2), 3) + self.assertEqual(sample.UnremovedNamespace.nestedMathSum(1, 2), 3) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py b/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py index 54ad28ff3..8e13d5d46 100644 --- a/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py +++ b/sources/shiboken6/tests/samplebinding/event_loop_call_virtual_test.py @@ -1,45 +1,17 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple event loop dispatcher test.''' import os import sys -import time import unittest from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from random import random from sample import ObjectType, Event @@ -67,7 +39,7 @@ class TestEventLoop(unittest.TestCase): objs = [ObjectType(), NoOverride(), Override()] evaluated = ObjectType.processEvent(objs, - Event(Event.BASIC_EVENT)) + Event(Event.BASIC_EVENT)) self.assertEqual(evaluated, 3) self.assertTrue(objs[2].called) diff --git a/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py b/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py index 12410ed88..8b854fca6 100644 --- a/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py +++ b/sources/shiboken6/tests/samplebinding/event_loop_thread_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os from random import random @@ -90,7 +64,7 @@ class TestEventLoopWithThread(unittest.TestCase): thread.start() evaluated = ObjectType.processEvent(objs, - Event(Event.BASIC_EVENT)) + Event(Event.BASIC_EVENT)) thread.join() diff --git a/sources/shiboken6/tests/samplebinding/exception_test.py b/sources/shiboken6/tests/samplebinding/exception_test.py index 96c389aa8..d9e6b377f 100644 --- a/sources/shiboken6/tests/samplebinding/exception_test.py +++ b/sources/shiboken6/tests/samplebinding/exception_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python -# -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +13,7 @@ init_paths() from sample import ExceptionTest + class CppExceptionTest(unittest.TestCase): def testVoid(self): @@ -49,14 +24,14 @@ class CppExceptionTest(unittest.TestCase): try: et.voidThrowStdException(True) - except: + except: # noqa: E722 exceptionCount += 1 et.voidThrowInt(False) try: et.voidThrowInt(True) - except: + except: # noqa: E722 exceptionCount += 1 self.assertEqual(exceptionCount, 2) @@ -65,21 +40,32 @@ class CppExceptionTest(unittest.TestCase): exceptionCount = 0 et = ExceptionTest() - result = et.intThrowStdException(False); + result = et.intThrowStdException(False) try: - result = et.intThrowStdException(True); - except: + result = et.intThrowStdException(True) + except: # noqa: E722 exceptionCount += 1 - result = et.intThrowInt(False); + result = et.intThrowInt(False) try: - result = et.intThrowInt(True); - except: + result = et.intThrowInt(True) # noqa: F841 + except: # noqa: E722 exceptionCount += 1 self.assertEqual(exceptionCount, 2) + def testModifications(self): + """PYSIDE-1995, test whether exceptions are propagated + when return ownership modifications are generated.""" + exceptionCount = 0 + try: + et = ExceptionTest.create(True) # noqa: F841 + except: # noqa: E722 + exceptionCount += 1 + self.assertEqual(exceptionCount, 1) + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/filter_test.py b/sources/shiboken6/tests/samplebinding/filter_test.py index e9c2d5ccc..df805093f 100644 --- a/sources/shiboken6/tests/samplebinding/filter_test.py +++ b/sources/shiboken6/tests/samplebinding/filter_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -37,6 +12,7 @@ init_paths() from sample import Data, Intersection, Union + class TestFilters(unittest.TestCase): def testAnd(self): @@ -48,5 +24,6 @@ class TestFilters(unittest.TestCase): self.assertEqual(type(inter), Intersection) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/global.h b/sources/shiboken6/tests/samplebinding/global.h index dd24f274b..64806417a 100644 --- a/sources/shiboken6/tests/samplebinding/global.h +++ b/sources/shiboken6/tests/samplebinding/global.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "abstract.h" #include "blackbox.h" @@ -81,6 +56,7 @@ #include "removednamespaces.h" #include "sample.h" #include "samplenamespace.h" +#include "stdcomplex.h" #include "simplefile.h" #include "size.h" #include "snakecasetest.h" diff --git a/sources/shiboken6/tests/samplebinding/handleholder_test.py b/sources/shiboken6/tests/samplebinding/handleholder_test.py index c1879e3e9..af22328c5 100644 --- a/sources/shiboken6/tests/samplebinding/handleholder_test.py +++ b/sources/shiboken6/tests/samplebinding/handleholder_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 ''' Test case for a class that holds a unknown handle object. Test case for BUG #1105. @@ -44,6 +17,7 @@ init_paths() from sample import HandleHolder + class HandleHolderTest(unittest.TestCase): def testCreation(self): holder = HandleHolder(HandleHolder.createHandle()) @@ -60,5 +34,6 @@ class HandleHolderTest(unittest.TestCase): holder2 = HandleHolder(holder.handle2()) self.assertTrue(holder.compare2(holder2)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/hashabletype_test.py b/sources/shiboken6/tests/samplebinding/hashabletype_test.py index fae9c724d..c41f5cc06 100644 --- a/sources/shiboken6/tests/samplebinding/hashabletype_test.py +++ b/sources/shiboken6/tests/samplebinding/hashabletype_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for __hash__''' @@ -40,7 +13,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, Str + class HashableTest(unittest.TestCase): @@ -56,6 +30,6 @@ class HashableTest(unittest.TestCase): h[o] = 2 self.assertTrue(h.get(o), 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ignorederefop_test.py b/sources/shiboken6/tests/samplebinding/ignorederefop_test.py index 5bd497e43..feb78d045 100644 --- a/sources/shiboken6/tests/samplebinding/ignorederefop_test.py +++ b/sources/shiboken6/tests/samplebinding/ignorederefop_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -34,12 +9,14 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Reference + class TestLackOfDereferenceOperators (unittest.TestCase): def testIf(self): r = Reference() self.assertFalse(hasattr(r, "__mul__")) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py b/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py index 0e3e99d64..081666281 100644 --- a/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py +++ b/sources/shiboken6/tests/samplebinding/implicitconv_numerical_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for inplicit converting C++ numeric types.''' @@ -54,9 +27,15 @@ if is64bitArchitecture and sys.platform != 'win32': cLongMin = -9223372036854775808 cLongMax = 9223372036854775807 + class NumericTester(unittest.TestCase): '''Helper class for numeric comparison testing''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def check_value(self, source, expected, callback, desired_type=None): result = callback(source) self.assertEqual(result, expected) diff --git a/sources/shiboken6/tests/samplebinding/implicitconv_test.py b/sources/shiboken6/tests/samplebinding/implicitconv_test.py index 782ddba2b..ebafe0c52 100644 --- a/sources/shiboken6/tests/samplebinding/implicitconv_test.py +++ b/sources/shiboken6/tests/samplebinding/implicitconv_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for implicit conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import ImplicitConv, ObjectType + class ImplicitConvTest(unittest.TestCase): '''Test case for implicit conversions''' @@ -70,4 +44,3 @@ class ImplicitConvTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py b/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py index 5d1bde31d..28d62486a 100644 --- a/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py +++ b/sources/shiboken6/tests/samplebinding/inheritanceandscope_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for finding scope in cases involving inheritance.''' @@ -42,14 +15,16 @@ init_paths() from sample import SampleNamespace + class ScopeAndInheritanceTest(unittest.TestCase): '''Test cases for finding scope in cases involving inheritance.''' def testMethodCorrectlyWrapper(self): '''A method returning a type declared in the scope of the method's class parent must be found and the method correctly exported.''' - meth = getattr(SampleNamespace.DerivedFromNamespace, 'methodReturningTypeFromParentScope') + meth = getattr(SampleNamespace.DerivedFromNamespace, # noqa: F841 + 'methodReturningTypeFromParentScope') + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/injectcode_test.py b/sources/shiboken6/tests/samplebinding/injectcode_test.py index a6fb7a5ef..f673a7807 100644 --- a/sources/shiboken6/tests/samplebinding/injectcode_test.py +++ b/sources/shiboken6/tests/samplebinding/injectcode_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::list container conversions''' @@ -41,6 +14,7 @@ from shiboken_paths import init_paths init_paths() from sample import InjectCode + class MyInjectCode(InjectCode): def __init__(self): InjectCode.__init__(self) @@ -49,8 +23,11 @@ class MyInjectCode(InjectCode): def arrayMethod(self, values): return self.multiplier * sum(values) + class InjectCodeTest(unittest.TestCase): + @unittest.skipIf(hasattr(sys, "pypy_version_info"), + "PyPy type objects cannot be modified (yet) after creation") def testTypeNativeBeginning_TypeTargetBeginning(self): ic = InjectCode() self.assertEqual(str(ic), "Hi! I'm the inject code dummy class.") @@ -96,22 +73,24 @@ class InjectCodeTest(unittest.TestCase): self.assertEqual(result, sum(values)) def testCallReimplementedVirtualMethodWithArgumentRemovalAndArgumentTypeModification(self): - '''Calls a reimplemented virtual method that had its first argument removed and the second modified.''' + '''Calls a reimplemented virtual method that had its first argument removed + and the second modified.''' ic = MyInjectCode() values = (1, 2, 3, 4, 5) result = ic.callArrayMethod(values) self.assertEqual(result, ic.multiplier * sum(values)) def testUsageOfTypeSystemCheckVariableOnPrimitiveType(self): - '''When the sequence item is convertible to an integer -1 is returned, or -2 if its not convertible.''' + '''When the sequence item is convertible to an integer -1 is returned, + or -2 if its not convertible.''' ic = InjectCode() values = (1, 2, 3, 4, '5', 6.7) result = ic.arrayMethod(values) - fixedValues = [v for v in values if isinstance(v, int)]\ - + [-1 for v in values if isinstance(v, float)]\ - + [-2 for v in values if not isinstance(v, int) and not isinstance(v, float)] - self.assertEqual(result, sum(fixedValues)) + ints = [v for v in values if isinstance(v, int)] + floats = [-1 for v in values if isinstance(v, float)] + other = [-2 for v in values if not isinstance(v, int) and not isinstance(v, float)] + self.assertEqual(result, sum(ints + floats + other)) class IntArrayTest(unittest.TestCase): @@ -135,5 +114,6 @@ class IntArrayTest(unittest.TestCase): ic = InjectCode() self.assertEqual(sum([1, 2]) + len([1, 2]), ic.sumArrayAndLength(args)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/innerclass_test.py b/sources/shiboken6/tests/samplebinding/innerclass_test.py index 6e5b23aa7..721f33483 100644 --- a/sources/shiboken6/tests/samplebinding/innerclass_test.py +++ b/sources/shiboken6/tests/samplebinding/innerclass_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,10 +13,11 @@ init_paths() from sample import Derived + class TestInnerClass(unittest.TestCase): def testInstaciate(self): - d = Derived.SomeInnerClass() + d = Derived.SomeInnerClass() # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/intlist_test.py b/sources/shiboken6/tests/samplebinding/intlist_test.py index 58e519d00..defa9ca71 100644 --- a/sources/shiboken6/tests/samplebinding/intlist_test.py +++ b/sources/shiboken6/tests/samplebinding/intlist_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import IntList + class IntListTest(unittest.TestCase): def testAutoFunctionsToBaseList(self): @@ -101,5 +75,6 @@ class IntListTest(unittest.TestCase): self.assertEqual(il[1], int(432.1)) self.assertRaises(TypeError, il.__setitem__, 2, '78') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/intwrapper_test.py b/sources/shiboken6/tests/samplebinding/intwrapper_test.py index a2fabf87f..d883adf47 100644 --- a/sources/shiboken6/tests/samplebinding/intwrapper_test.py +++ b/sources/shiboken6/tests/samplebinding/intwrapper_test.py @@ -1,32 +1,5 @@ -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2021 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -43,8 +16,8 @@ from sample import IntWrapper class IntWrapperTest(unittest.TestCase): def testOperators(self): - ten1 = IntWrapper(10) - ten2 = IntWrapper(10) + ten1 = IntWrapper(10) + ten2 = IntWrapper(10) twenty = IntWrapper(20) self.assertTrue(ten1 == ten2) self.assertTrue(ten1 != twenty) @@ -56,6 +29,11 @@ class IntWrapperTest(unittest.TestCase): i -= ten2 self.assertTrue(i == ten1) + def testAddPyMethodDef(self): + """Test of added free function (PYSIDE-1905).""" + i = IntWrapper(10) + self.assertEqual(i.add_ints(10, 20), 30) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py index 1456f5e7a..bb35b2bb1 100644 --- a/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py +++ b/sources/shiboken6/tests/samplebinding/invalid_virtual_return_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for returning invalid types in a virtual function''' @@ -65,7 +38,7 @@ class ModelWrongReturnTest(unittest.TestCase): def testWrongTypeReturn(self): model = ListModelWrong() view = ObjectView(model) - self.assertRaises(RuntimeWarning, view.getRawModelData) # calls model.data() + self.assertRaises(RuntimeWarning, view.getRawModelData) # calls model.data() if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/keep_reference_test.py b/sources/shiboken6/tests/samplebinding/keep_reference_test.py index b68b52e9d..10591fec6 100644 --- a/sources/shiboken6/tests/samplebinding/keep_reference_test.py +++ b/sources/shiboken6/tests/samplebinding/keep_reference_test.py @@ -1,39 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -'''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys -from sys import getrefcount import unittest from pathlib import Path @@ -43,46 +13,51 @@ init_paths() from sample import ObjectModel, ObjectView + class TestKeepReference(unittest.TestCase): - '''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' + '''Test case for objects that keep references to other object without + owning them (e.g. model/view relationships).''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCounting(self): '''Tests reference count of model-like object referred by view-like objects.''' model1 = ObjectModel() - refcount1 = getrefcount(model1) + refcount1 = sys.getrefcount(model1) view1 = ObjectView() view1.setModel(model1) - self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view1.model()), refcount1 + 1) view2 = ObjectView() view2.setModel(model1) - self.assertEqual(getrefcount(view2.model()), refcount1 + 2) + self.assertEqual(sys.getrefcount(view2.model()), refcount1 + 2) model2 = ObjectModel() view2.setModel(model2) - self.assertEqual(getrefcount(view1.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view1.model()), refcount1 + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCountingWhenDeletingReferrer(self): '''Tests reference count of model-like object referred by deceased view-like object.''' model = ObjectModel() - refcount1 = getrefcount(model) + refcount1 = sys.getrefcount(model) view = ObjectView() view.setModel(model) - self.assertEqual(getrefcount(view.model()), refcount1 + 1) + self.assertEqual(sys.getrefcount(view.model()), refcount1 + 1) del view - self.assertEqual(getrefcount(model), refcount1) + self.assertEqual(sys.getrefcount(model), refcount1) def testReferreedObjectSurvivalAfterContextEnd(self): - '''Model-like object assigned to a view-like object must survive after get out of context.''' + '''Model-like object assigned to a view-like object must survive + after get out of context.''' def createModelAndSetToView(view): model = ObjectModel() model.setObjectName('created model') view.setModel(model) view = ObjectView() createModelAndSetToView(view) - model = view.model() + model = view.model() # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/list_test.py b/sources/shiboken6/tests/samplebinding/list_test.py index b7257a320..b668bfd90 100644 --- a/sources/shiboken6/tests/samplebinding/list_test.py +++ b/sources/shiboken6/tests/samplebinding/list_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::list container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import ListUser, Point, PointF + class ExtendedListUser(ListUser): def __init__(self): ListUser.__init__(self) @@ -51,6 +25,7 @@ class ExtendedListUser(ListUser): self.create_list_called = True return [2, 3, 5, 7, 13] + class ListConversionTest(unittest.TestCase): '''Test case for std::list container conversions''' @@ -96,7 +71,8 @@ class ListConversionTest(unittest.TestCase): self.assertEqual(result, lst) def testConversionInBothDirectionsWithSimilarContainer(self): - '''Test converting a tuple, instead of the expected list, from Python to C++ and back again.''' + '''Test converting a tuple, instead of the expected list, + from Python to C++ and back again.''' lu = ListUser() lst = (3, 5, 7) lu.setList(lst) @@ -123,6 +99,6 @@ class ListConversionTest(unittest.TestCase): self.assertEqual(ListUser.ListOfPointF, ListUser.listOfPoints([PointF()])) self.assertEqual(ListUser.ListOfPoint, ListUser.listOfPoints([Point()])) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/lock_test.py b/sources/shiboken6/tests/samplebinding/lock_test.py index eaaf4ca05..acd47634a 100644 --- a/sources/shiboken6/tests/samplebinding/lock_test.py +++ b/sources/shiboken6/tests/samplebinding/lock_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python - -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Simple test with a blocking C++ method that should allow python threads to run.''' @@ -89,7 +63,8 @@ class TestLockUnlock(unittest.TestCase): self.assertTrue(result) def testReimplementedVirtualBlocker(self): - '''Same as the basic case but blocker method is a C++ virtual reimplemented in Python and called from C++.''' + '''Same as the basic case but blocker method is a C++ virtual reimplemented + in Python and called from C++.''' mybucket = MyBucket() unlocker = Unlocker(mybucket) @@ -98,5 +73,6 @@ class TestLockUnlock(unittest.TestCase): unlocker.join() self.assertTrue(result) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/map_test.py b/sources/shiboken6/tests/samplebinding/map_test.py index 205075bc3..fa99ad2e7 100644 --- a/sources/shiboken6/tests/samplebinding/map_test.py +++ b/sources/shiboken6/tests/samplebinding/map_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::map container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import MapUser + class ExtendedMapUser(MapUser): def __init__(self): MapUser.__init__(self) @@ -49,10 +23,11 @@ class ExtendedMapUser(MapUser): def createMap(self): self.create_map_called = True - return {'two' : (complex(2.2, 2.2), 2), - 'three' : (complex(3.3, 3.3), 3), - 'five' : (complex(5.5, 5.5), 5), - 'seven' : (complex(7.7, 7.7), 7)} + return {'two': (complex(2.2, 2.2), 2), + 'three': (complex(3.3, 3.3), 3), + 'five': (complex(5.5, 5.5), 5), + 'seven': (complex(7.7, 7.7), 7)} + class MapConversionTest(unittest.TestCase): '''Test case for std::map container conversions''' @@ -71,7 +46,7 @@ class MapConversionTest(unittest.TestCase): def testConversionInBothDirections(self): '''Test converting a map from Python to C++ and back again.''' mu = MapUser() - map_ = {'odds' : [2, 4, 6], 'evens' : [3, 5, 7], 'primes' : [3, 4, 6]} + map_ = {'odds': [2, 4, 6], 'evens': [3, 5, 7], 'primes': [3, 4, 6]} mu.setMap(map_) result = mu.getMap() self.assertEqual(result, map_) @@ -79,9 +54,10 @@ class MapConversionTest(unittest.TestCase): def testConversionMapIntKeyValueTypeValue(self): '''C++ signature: MapUser::passMapIntValueType(const std::map<int, const ByteArray>&)''' mu = MapUser() - map_ = {0 : 'string'} + map_ = {0: 'string'} result = mu.passMapIntValueType(map_) self.assertEqual(map_, result) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/metaclass_test.py b/sources/shiboken6/tests/samplebinding/metaclass_test.py index ed07626a0..4d7eeda96 100644 --- a/sources/shiboken6/tests/samplebinding/metaclass_test.py +++ b/sources/shiboken6/tests/samplebinding/metaclass_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,32 +10,40 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point + class MetaA(type): pass + class A(object): __metaclass__ = MetaA + MetaB = type(Point) B = Point + class MetaC(MetaA, MetaB): pass + + class C(A, B): __metaclass__ = MetaC + class D(C): pass + class TestMetaClass(unittest.TestCase): def testIt(self): - w1 = C() # works + w1 = C() # works w1.setX(1) w1.setY(2) - w2 = D() # should work! + w2 = D() # should work! w2.setX(3) w2.setY(4) diff --git a/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py b/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py index ba92bdb85..8d324db59 100644 --- a/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py +++ b/sources/shiboken6/tests/samplebinding/mi_virtual_methods_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods in multiple inheritance scenarios''' diff --git a/sources/shiboken6/tests/samplebinding/mixed_mi_test.py b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py index f303ea0db..fa8481600 100644 --- a/sources/shiboken6/tests/samplebinding/mixed_mi_test.py +++ b/sources/shiboken6/tests/samplebinding/mixed_mi_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance in mixed Python/C++ scenarios''' @@ -79,5 +52,3 @@ class MixedInheritanceTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - - diff --git a/sources/shiboken6/tests/samplebinding/modelindex_test.py b/sources/shiboken6/tests/samplebinding/modelindex_test.py index 1a4ed2407..e23503eff 100644 --- a/sources/shiboken6/tests/samplebinding/modelindex_test.py +++ b/sources/shiboken6/tests/samplebinding/modelindex_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import ModelIndex, ReferentModelIndex, PersistentModelIndex + class TestCastOperator(unittest.TestCase): def testCastOperatorReturningValue(self): @@ -57,4 +31,3 @@ class TestCastOperator(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modelview_test.py b/sources/shiboken6/tests/samplebinding/modelview_test.py index dff7b68fb..b5663a04e 100644 --- a/sources/shiboken6/tests/samplebinding/modelview_test.py +++ b/sources/shiboken6/tests/samplebinding/modelview_test.py @@ -1,35 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -'''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test case for objects that keep references to other object without owning them + (e.g. model/view relationships).''' import os import sys @@ -44,9 +18,11 @@ from sample import ObjectModel, ObjectType, ObjectView object_name = 'test object' + class MyObject(ObjectType): pass + class ListModelKeepsReference(ObjectModel): def __init__(self, parent=None): ObjectModel.__init__(self, parent) @@ -56,6 +32,7 @@ class ListModelKeepsReference(ObjectModel): def data(self): return self.obj + class ListModelDoesntKeepsReference(ObjectModel): def data(self): obj = MyObject() @@ -82,4 +59,3 @@ class ModelViewTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modifications_test.py b/sources/shiboken6/tests/samplebinding/modifications_test.py index 3429ccd0f..dced14396 100644 --- a/sources/shiboken6/tests/samplebinding/modifications_test.py +++ b/sources/shiboken6/tests/samplebinding/modifications_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for method modifications performed as described on type system. ''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import Modifications, Point, ByteArray + class ExtModifications(Modifications): def __init__(self): Modifications.__init__(self) @@ -64,25 +39,18 @@ class ModificationsTest(unittest.TestCase): def tearDown(self): del self.mods - - def testClassMembersAvailability(self): - '''Test if Modified class really have the expected members.''' - expected_members = set(['OverloadedModFunc', 'OverloadedNone', - 'Overloaded_ibiP', 'Overloaded_ibib', - 'Overloaded_ibid', 'Overloaded_ibii', - 'calculateArea', 'doublePlus', 'increment', - 'multiplyPointCoordsPlusValue', 'name', - 'pointToPair', 'overloaded', 'power', - 'timesTen']) - self.assertTrue(expected_members.issubset(dir(Modifications))) + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testRenamedMethodAvailability(self): - '''Test if Modification class really have renamed the 'className' virtual method to 'name'.''' + '''Test if Modification class really have renamed the 'className' + virtual method to 'name'.''' self.assertTrue('className' not in dir(Modifications)) self.assertTrue('name' in dir(Modifications)) def testReimplementationOfRenamedVirtualMethod(self): - '''Test if class inheriting from Modification class have the reimplementation of renamed virtual method called.''' + '''Test if class inheriting from Modification class have the reimplementation + of renamed virtual method called.''' em = ExtModifications() self.assertEqual(self.mods.name(), 'Modifications') self.assertEqual(em.name(), 'ExtModifications') @@ -103,12 +71,14 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.doublePlus(7), 14) def testDefaultValueRemoval(self): - '''Test if default value was removed from first argument of Modifications::increment(int).''' + '''Test if default value was removed from first argument of + Modifications::increment(int).''' self.assertRaises(TypeError, self.mods.increment) self.assertEqual(self.mods.increment(7), 8) def testDefaultValueReplacement(self): - '''Test if default values for both arguments of Modifications::power(int, int) were modified.''' + '''Test if default values for both arguments of Modifications::power(int, int) + were modified.''' # original default values: int power(int base = 1, int exponent = 0); self.assertNotEqual(self.mods.power(4), 1) # modified default values: int power(int base = 2, int exponent = 1); @@ -117,12 +87,14 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.power(5, 3), 5**3) def testSetNewDefaultValue(self): - '''Test if default value was correctly set to 10 for first argument of Modifications::timesTen(int).''' + '''Test if default value was correctly set to 10 for first argument of + Modifications::timesTen(int).''' self.assertEqual(self.mods.timesTen(7), 70) self.assertEqual(self.mods.timesTen(), 100) def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates1(self): - '''Test modifications to method signature and return value using type system templates (case 1).''' + '''Test modifications to method signature and return value using type + system templates (case 1).''' result, ok = self.mods.pointToPair(Point(2, 5)) self.assertEqual(type(ok), bool) self.assertEqual(type(result), tuple) @@ -133,7 +105,8 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(result[1], 5.0) def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates2(self): - '''Test modifications to method signature and return value using type system templates (case 2).''' + '''Test modifications to method signature and return value using + type system templates (case 2).''' result, ok = self.mods.multiplyPointCoordsPlusValue(Point(2, 5), 4.1) self.assertEqual(type(ok), bool) self.assertEqual(type(result), float) @@ -147,9 +120,11 @@ class ModificationsTest(unittest.TestCase): self.assertEqual(self.mods.overloaded(1, True, 2), Modifications.Overloaded_ibii) # the others weren't modified self.assertEqual(self.mods.overloaded(1, True, 2, False), Modifications.Overloaded_ibib) - self.assertEqual(self.mods.overloaded(1, False, 2, Point(3, 4)), Modifications.Overloaded_ibiP) + self.assertEqual(self.mods.overloaded(1, False, 2, Point(3, 4)), + Modifications.Overloaded_ibiP) self.assertRaises(TypeError, self.mods.overloaded, 1, True, Point(2, 3), Point(4, 5)) - self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), Modifications.Overloaded_ibPP) + self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), + Modifications.Overloaded_ibPP) def testPointArrayModification(self): points = (Point(1, 1), Point(2, 2)) diff --git a/sources/shiboken6/tests/samplebinding/modified_constructor_test.py b/sources/shiboken6/tests/samplebinding/modified_constructor_test.py index 63cec6556..9791a3491 100644 --- a/sources/shiboken6/tests/samplebinding/modified_constructor_test.py +++ b/sources/shiboken6/tests/samplebinding/modified_constructor_test.py @@ -1,37 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests cases for ConstructorWithModifiedArgument class.''' -import sys import os import sys import unittest @@ -41,7 +13,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ModifiedConstructor class ConstructorWithModifiedArgumentTest(unittest.TestCase): @@ -51,6 +23,6 @@ class ConstructorWithModifiedArgumentTest(unittest.TestCase): sampleClass = ModifiedConstructor("10") self.assertTrue(sampleClass.retrieveValue(), 10) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py index b59e64a00..dcb487f1a 100644 --- a/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/modifiedvirtualmethods_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for modified virtual methods.''' +import gc import os import sys import unittest @@ -42,6 +16,7 @@ init_paths() from sample import VirtualMethods, Str + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -87,7 +62,7 @@ class ExtendedVirtualMethods(VirtualMethods): self.callMe_called += 1 def getMargins(self): - return tuple([m*2 for m in VirtualMethods.getMargins(self)]) + return tuple([m * 2 for m in VirtualMethods.getMargins(self)]) class VirtualMethodsTest(unittest.TestCase): @@ -100,6 +75,8 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.vm del self.evm + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testModifiedVirtualMethod0(self): '''Renamed virtual method.''' @@ -209,7 +186,8 @@ class VirtualMethodsTest(unittest.TestCase): removed_arg_value = 2011 default_value = 3000 result = self.evm.callSum4(a0, removed_arg_value, a1) - self.assertEqual(result, (a0 - removed_arg_value + a1 + default_value) * self.evm.multiplier) + self.assertEqual(result, + (a0 - removed_arg_value + a1 + default_value) * self.evm.multiplier) self.assertTrue(self.evm.sum4_called) def testOverridenMethodResultModification(self): @@ -241,15 +219,15 @@ class VirtualMethodsTest(unittest.TestCase): def testExtendedAllArgumentsRemoved(self): values = (10, 20, 30, 40) self.evm.setMargins(*values) - double = tuple([m*2 for m in values]) + double = tuple([m * 2 for m in values]) self.assertEqual(self.evm.getMargins(), double) def testExtendedAllArgumentsRemovedCallVirtual(self): values = (10, 20, 30, 40) self.evm.setMargins(*values) - double = tuple([m*2 for m in values]) + double = tuple([m * 2 for m in values]) self.assertEqual(self.evm.callGetMargins(), double) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py b/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py index c522d0e38..fc6b26c3f 100644 --- a/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py +++ b/sources/shiboken6/tests/samplebinding/multi_cpp_inheritance_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance''' @@ -40,72 +13,85 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, Point, Str + class SimpleUseCase(ObjectType, Str): def __init__(self, name): ObjectType.__init__(self) Str.__init__(self, name) + class SimpleUseCaseReverse(Str, ObjectType): def __init__(self, name): ObjectType.__init__(self) Str.__init__(self, name) + class SimpleUseCase2(SimpleUseCase): def __init__(self, name): SimpleUseCase.__init__(self, name) + class ComplexUseCase(SimpleUseCase2, Point): def __init__(self, name): SimpleUseCase2.__init__(self, name) Point.__init__(self) + class ComplexUseCaseReverse(Point, SimpleUseCase2): def __init__(self, name): SimpleUseCase2.__init__(self, name) Point.__init__(self) + class MultipleCppDerivedTest(unittest.TestCase): - def testInstanciation(self): + def testInstantiation(self): s = SimpleUseCase("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testInstanciation2(self): + def testInstantiation2(self): s = SimpleUseCase2("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testComplexInstanciation(self): + def testComplexInstantiation(self): c = ComplexUseCase("Hi") self.assertEqual(c, "Hi") c.setObjectName(c) self.assertEqual(c.objectName(), "Hi") - c.setX(2); + c.setX(2) self.assertEqual(c.x(), 2) + class MultipleCppDerivedReverseTest(unittest.TestCase): - def testInstanciation(self): + def testInstantiation(self): s = SimpleUseCaseReverse("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testInstanciation2(self): + def testInstantiation2(self): s = SimpleUseCase2("Hi") self.assertEqual(s, "Hi") s.setObjectName(s) self.assertEqual(s.objectName(), "Hi") - def testComplexInstanciation(self): - c = ComplexUseCaseReverse("Hi") - c.setObjectName(c) - self.assertEqual(c.objectName(), "Hi") - c.setX(2); - self.assertEqual(c, Point(2, 0)) + def testComplexInstantiation(self): + # PYSIDE-1564: This test can no longer work because of this MRO: + # ('ComplexUseCaseReverse', 'Point', 'SimpleUseCase2', 'SimpleUseCase', + # 'ObjectType', 'Str', 'Object', 'object') + # By multiple inheritance Point would be called first but has no argument. + with self.assertRaises(TypeError): + c = ComplexUseCaseReverse("Hi") # noqa: F841 + # c.setObjectName(c) + # self.assertEqual(c.objectName(), "Hi") + # c.setX(2); + # self.assertEqual(c, Point(2, 0)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/multiple_derived_test.py b/sources/shiboken6/tests/samplebinding/multiple_derived_test.py index 08a13445d..7497714a8 100644 --- a/sources/shiboken6/tests/samplebinding/multiple_derived_test.py +++ b/sources/shiboken6/tests/samplebinding/multiple_derived_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for multiple inheritance''' @@ -40,17 +13,20 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import Base1, Base2, Base3, Base4, Base5, Base6 +from sample import Base1, Base2 from sample import MDerived1, MDerived2, MDerived3, MDerived4, MDerived5, SonOfMDerived1 + class ExtMDerived1(MDerived1): def __init__(self): MDerived1.__init__(self) self.multiplier = 20 self.base2Method_called = False + def base2Method(self): return Base2.base2Method(self) * self.multiplier + class MultipleDerivedTest(unittest.TestCase): '''Test cases for multiple inheritance''' @@ -67,19 +43,22 @@ class MultipleDerivedTest(unittest.TestCase): self.assertTrue(issubclass(MDerived1, Base2)) def testCallToFunctionWithBase1ArgumentThatCastsBackToMDerived1(self): - '''MDerived1 is passed as an Base1 argument to a method that returns it casted back to MDerived1.''' + '''MDerived1 is passed as an Base1 argument to a method that returns + it casted back to MDerived1.''' a = MDerived1() b = MDerived1.transformFromBase1(a) self.assertEqual(a, b) def testCallToFunctionWithBase2ArgumentThatCastsBackToMDerived1(self): - '''MDerived1 is passed as an Base2 argument to a method that returns it casted back to MDerived1.''' + '''MDerived1 is passed as an Base2 argument to a method that returns + it casted back to MDerived1.''' a = MDerived1() b = MDerived1.transformFromBase2(a) self.assertEqual(a, b) def testPythonClassIsInstance(self): - '''Python defined class ExtMDerived1 is instance of its parents MDerived1, Base1 and Base2.''' + '''Python defined class ExtMDerived1 is instance of its parents + MDerived1, Base1 and Base2.''' a = ExtMDerived1() self.assertTrue(isinstance(a, ExtMDerived1)) self.assertTrue(isinstance(a, MDerived1)) @@ -87,13 +66,16 @@ class MultipleDerivedTest(unittest.TestCase): self.assertTrue(isinstance(a, Base2)) def testPythonClassIsSubclass(self): - '''Python defined class ExtMDerived1 is subclass of its parents MDerived1, Base1 and Base2.''' + '''Python defined class ExtMDerived1 is subclass of its parents + MDerived1, Base1 and Base2.''' self.assertTrue(issubclass(ExtMDerived1, MDerived1)) self.assertTrue(issubclass(ExtMDerived1, Base1)) self.assertTrue(issubclass(ExtMDerived1, Base2)) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived1ToBases(self): - '''MDerived1 is casted by C++ to its parents and the binding must return the MDerived1 wrapper.''' + '''MDerived1 is casted by C++ to its parents and the binding must return the + MDerived1 wrapper.''' a = MDerived1() refcnt = sys.getrefcount(a) b1 = a.castToBase1() @@ -104,8 +86,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b2) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromExtMDerived1ToMDerived1Bases(self): - '''Python defined class ExtMDerived1 is casted by C++ to MDerived1 parents and the binding must return the correct ExtMDerived1 instance.''' + '''Python defined class ExtMDerived1 is casted by C++ to MDerived1 parents + and the binding must return the correct ExtMDerived1 instance.''' a = ExtMDerived1() refcnt = sys.getrefcount(a) b1 = a.castToBase1() @@ -118,8 +102,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b2) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromSonOfMDerived1ToBases(self): - '''SonOfMDerived1 is casted by C++ to its parents and the binding must return the SonOfMDerived1 wrapper.''' + '''SonOfMDerived1 is casted by C++ to its parents and the binding must return + the SonOfMDerived1 wrapper.''' a = SonOfMDerived1() refcnt = sys.getrefcount(a) md1 = a.castToMDerived1() @@ -138,8 +124,10 @@ class MultipleDerivedTest(unittest.TestCase): value = a.base2Method() self.assertTrue(value, Base2.base2Method(a) * a.multiplier) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived2ToBases(self): - '''MDerived2 is casted by C++ to its parents and the binding must return the MDerived2 wrapper.''' + '''MDerived2 is casted by C++ to its parents and the binding must + return the MDerived2 wrapper.''' a = MDerived2() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -156,8 +144,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b6) self.assertEqual(sys.getrefcount(a), refcnt + 4) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived3ToBases(self): - '''MDerived3 is casted by C++ to its parents and the binding must return the MDerived3 wrapper.''' + '''MDerived3 is casted by C++ to its parents and the binding must + return the MDerived3 wrapper.''' a = MDerived3() refcnt = sys.getrefcount(a) md1 = a.castToMDerived1() @@ -186,8 +176,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b6) self.assertEqual(sys.getrefcount(a), refcnt + 8) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived4ToBases(self): - '''MDerived4 is casted by C++ to its parents and the binding must return the MDerived4 wrapper.''' + '''MDerived4 is casted by C++ to its parents and the binding must + return the MDerived4 wrapper.''' a = MDerived4() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -198,8 +190,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b4) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived5ToBases(self): - '''MDerived5 is casted by C++ to its parents and the binding must return the MDerived5 wrapper.''' + '''MDerived5 is casted by C++ to its parents and the binding must + return the MDerived5 wrapper.''' a = MDerived5() refcnt = sys.getrefcount(a) b3 = a.castToBase3() @@ -210,8 +204,10 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b4) self.assertEqual(sys.getrefcount(a), refcnt + 2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testCastFromMDerived3ToBase3(self): - '''MDerived3 is casted by C++ to Base3 grandparent using both the inherited and reimplement castToBase3 methods.''' + '''MDerived3 is casted by C++ to Base3 grandparent using both the inherited + and reimplement castToBase3 methods.''' a = MDerived3() refcnt = sys.getrefcount(a) b3_reimplemented = a.castToBase3() @@ -222,6 +218,6 @@ class MultipleDerivedTest(unittest.TestCase): self.assertEqual(a, b3_inherited) self.assertEqual(sys.getrefcount(a), refcnt + 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/namespace_test.py b/sources/shiboken6/tests/samplebinding/namespace_test.py index 3dc79fa96..64a6792ac 100644 --- a/sources/shiboken6/tests/samplebinding/namespace_test.py +++ b/sources/shiboken6/tests/samplebinding/namespace_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::map container conversions''' @@ -40,9 +13,10 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import SampleNamespace from shiboken_test_helper import objectFullname +from shibokensupport.signature import get_signature # For tests of invisible namespaces, see # enumfromremovednamespace_test.py / removednamespaces.h @@ -50,17 +24,17 @@ from shiboken_test_helper import objectFullname class TestVariablesUnderNamespace(unittest.TestCase): def testIt(self): - self.assertEqual(SampleNamespace.variableInNamespace, 42) + self.assertEqual(SampleNamespace.variableInNamespace, 42) class TestClassesUnderNamespace(unittest.TestCase): def testIt(self): - c1 = SampleNamespace.SomeClass() - e1 = SampleNamespace.SomeClass.ProtectedEnum() - c2 = SampleNamespace.SomeClass.SomeInnerClass() - e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() - c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() - e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum() + c1 = SampleNamespace.SomeClass() # noqa F841 + e1 = SampleNamespace.SomeClass.ProtectedEnum() # noqa F841 + c2 = SampleNamespace.SomeClass.SomeInnerClass() # noqa F841 + e2 = SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum() # noqa F841 + c3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough() # noqa F841 + e3 = SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum(0) # noqa F841 def testFunctionAddedOnNamespace(self): res = SampleNamespace.ImInsideANamespace(2, 2) @@ -68,21 +42,26 @@ class TestClassesUnderNamespace(unittest.TestCase): def testTpNames(self): self.assertEqual(str(SampleNamespace.SomeClass), - "<class 'sample.SampleNamespace.SomeClass'>") + "<class 'sample.SampleNamespace.SomeClass'>") self.assertEqual(str(SampleNamespace.SomeClass.ProtectedEnum), - "<class 'sample.SampleNamespace.SomeClass.ProtectedEnum'>") + "<enum 'ProtectedEnum'>") self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.ProtectedEnum'>") + "<enum 'ProtectedEnum'>") self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough'>") - self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum), - "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum'>") + "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough'>") # noqa: E501 + self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum), # noqa: E501 + "<enum 'NiceEnum'>") # Test if enum inside of class is correct represented - self.assertEqual(objectFullname(SampleNamespace.enumInEnumOut.__signature__.parameters['in_'].annotation), - "sample.SampleNamespace.InValue") - self.assertEqual(objectFullname(SampleNamespace.enumAsInt.__signature__.parameters['value'].annotation), - "sample.SampleNamespace.SomeClass.PublicScopedEnum") + an = objectFullname(get_signature(SampleNamespace.enumInEnumOut).parameters['in_'].annotation) # noqa: E501 + self.assertEqual(an, "sample.SampleNamespace.InValue") + an = objectFullname(get_signature(SampleNamespace.enumAsInt).parameters['value'].annotation) + self.assertEqual(an, "sample.SampleNamespace.SomeClass.PublicScopedEnum") + + def testInlineNamespaces(self): + cls = SampleNamespace.ClassWithinInlineNamespace() + cls.setValue(SampleNamespace.EWIN_Value1) + self.assertEqual(cls.value(), SampleNamespace.EWIN_Value1) if __name__ == '__main__': diff --git a/sources/shiboken6/tests/samplebinding/newdivision_test.py b/sources/shiboken6/tests/samplebinding/newdivision_test.py index a9152f4a1..0e7dfbee1 100644 --- a/sources/shiboken6/tests/samplebinding/newdivision_test.py +++ b/sources/shiboken6/tests/samplebinding/newdivision_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,16 +10,16 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point class TestNewDivision(unittest.TestCase): def testIt(self): p = Point(4, 4) - p2 = p/2 + p2 = p / 2 self.assertEqual(p2, Point(2, 2)) + if __name__ == "__main__": unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py b/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py index 31a51995e..bc8d29e50 100644 --- a/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py +++ b/sources/shiboken6/tests/samplebinding/nondefaultctor_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for ...''' @@ -42,14 +15,17 @@ init_paths() from sample import NonDefaultCtor + class DerivedNonDefaultCtor (NonDefaultCtor): def returnMyselfVirtual(self): - return NonDefaultCtor(self.value()+1) + return NonDefaultCtor(self.value() + 1) + class AnotherDerivedNonDefaultCtor (NonDefaultCtor): def __init__(self, some_string): pass + class NonDefaultCtorTest(unittest.TestCase): def testNonDefaultCtor(self): @@ -70,8 +46,8 @@ class NonDefaultCtorTest(unittest.TestCase): self.assertEqual(c.callReturnMyselfVirtual().value(), 4) def testCtorOverload(self): - c = AnotherDerivedNonDefaultCtor("testing") + c = AnotherDerivedNonDefaultCtor("testing") # noqa: F841 + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py b/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py index b329f5672..a10547728 100644 --- a/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py +++ b/sources/shiboken6/tests/samplebinding/nontypetemplate_test.py @@ -1,32 +1,6 @@ #!/usr/bin/env python -# -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 hasNumPy = False @@ -47,6 +21,7 @@ init_paths() from sample import IntArray2, IntArray3 + class NonTypeTemplateTest(unittest.TestCase): def testNonTypeTemplate(self): @@ -58,7 +33,7 @@ class NonTypeTemplateTest(unittest.TestCase): def testArrayInitializer(self): if not hasNumPy: return - array3 = IntArray3(numpy.array([1, 2, 3], dtype = 'int32')) + array3 = IntArray3(numpy.array([1, 2, 3], dtype='int32')) self.assertEqual(array3.sum(), 6) diff --git a/sources/shiboken6/tests/samplebinding/nonzero_test.py b/sources/shiboken6/tests/samplebinding/nonzero_test.py index 16f675547..7be239fc4 100644 --- a/sources/shiboken6/tests/samplebinding/nonzero_test.py +++ b/sources/shiboken6/tests/samplebinding/nonzero_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import Color, Brush + class TestNonZeroOperator(unittest.TestCase): def testColor(self): """Color has a Qt-style isNull()""" diff --git a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py index 5512a2de6..f714a4fc8 100644 --- a/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py +++ b/sources/shiboken6/tests/samplebinding/numericaltypedef_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import SizeF + class NumericalTypedefTest(unittest.TestCase): def testNumericalTypedefExact(self): @@ -59,5 +33,6 @@ class NumericalTypedefTest(unittest.TestCase): self.assertEqual(SizeF.passTypedefOfUnsignedShort(321), 321) self.assertNotEqual(SizeF.passTypedefOfUnsignedShort(123), 0) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/numpy_test.py b/sources/shiboken6/tests/samplebinding/numpy_test.py index 61f8c7103..42094a463 100644 --- a/sources/shiboken6/tests/samplebinding/numpy_test.py +++ b/sources/shiboken6/tests/samplebinding/numpy_test.py @@ -1,39 +1,14 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import sys try: - from distutils import sysconfig + import sysconfig if bool(sysconfig.get_config_var('Py_DEBUG')): sys.exit(0) import numpy -except: +except: # noqa: E722 sys.exit(0) import os @@ -46,6 +21,7 @@ from shiboken_paths import init_paths init_paths() from sample import PointF + class TestNumpyTypes(unittest.TestCase): def testNumpyConverted(self): @@ -60,6 +36,6 @@ class TestNumpyTypes(unittest.TestCase): self.assertAlmostEqual(p.x(), x) self.assertAlmostEqual(p.y(), y) + if __name__ == "__main__": unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttype_test.py b/sources/shiboken6/tests/samplebinding/objecttype_test.py index fb655c435..ead68ba13 100644 --- a/sources/shiboken6/tests/samplebinding/objecttype_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttype_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests ObjectType class of object-type with privates copy constructor and = operator.''' @@ -75,6 +48,7 @@ class ObjectTypeTest(unittest.TestCase): o.setNullObject(None) self.assertEqual(o.callId(), 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentFromCpp(self): o = ObjectType() self.assertEqual(sys.getrefcount(o), 2) @@ -94,7 +68,7 @@ class ObjectTypeTest(unittest.TestCase): def testNextInFocusChainCycle(self): parent = ObjectType() child = ObjectType(parent) - next_focus = child.nextInFocusChain() + next_focus = child.nextInFocusChain() # noqa: F841 Shiboken.invalidate(parent) @@ -113,6 +87,7 @@ class ObjectTypeTest(unittest.TestCase): Shiboken.invalidate(parents) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testClassDecref(self): # Bug was that class PyTypeObject wasn't decrefed when instance died before = sys.getrefcount(ObjectType) @@ -127,11 +102,9 @@ class ObjectTypeTest(unittest.TestCase): def testInvalidProperty(self): o = ObjectType() - try: + with self.assertRaises(AttributeError): o.typo - self.assertFail() - except AttributeError as error: - self.assertEqual(error.args[0], "'sample.ObjectType' object has no attribute 'typo'") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py b/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py index f9944e61b..285e2313b 100644 --- a/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttype_with_named_args_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import ObjectType + class NamedArgsTest(unittest.TestCase): def testOneArgument(self): @@ -62,18 +36,15 @@ class NamedArgsTest(unittest.TestCase): o.setObjectNameWithSize(size=6, name="pyside") self.assertEqual(o.objectName(), "pyside") - def testUseDefaultValues(self): o = ObjectType() o.setObjectNameWithSize(size=3) - self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument + self.assertEqual(o.objectName(), "<un") # use name='unknown' default argument o.setObjectSplittedName("") - self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>' - + self.assertEqual(o.objectName(), "<unknown>") # user prefix='<unk' and suffix='nown>' if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py b/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py index 52253f241..8f74af3ab 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypebyvalue_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -35,7 +10,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectTypeByValue class ObjectTypeByValueTest (unittest.TestCase): @@ -47,5 +22,6 @@ class ObjectTypeByValueTest (unittest.TestCase): # just to make sure it will segfault obj.prop.protectedValueTypeProperty.setY(2.0) + if __name__ == "__main__": unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py index 76f028f51..677b89281 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypelayout_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests cases for ObjectTypeLayout class.''' +import gc import os import sys import unittest @@ -40,23 +14,23 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectType, ObjectTypeLayout class ObjectTypeLayoutTest(unittest.TestCase): '''Test cases for ObjectTypeLayout class.''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipOverride(self): - l = ObjectTypeLayout() + lt = ObjectTypeLayout() - o1 = ObjectType(l) + o1 = ObjectType(lt) o1.setObjectName('o1') self.assertEqual(sys.getrefcount(o1), 3) - l.takeChild('o1') + lt.takeChild('o1') self.assertEqual(sys.getrefcount(o1), 2) - def testSetNullLayout(self): '''ObjectType.setLayout(0).''' o2 = ObjectType() @@ -82,7 +56,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -104,7 +80,9 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(c3.parent(), None) p1.setLayout(layout) - del p1 # This must kill c1, c2 and c3 + del p1 # This must kill c1, c2 and c3 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -112,7 +90,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, layout.objectName) def testObjectTypeLayoutTransference(self): - '''Transfer a layout from one ObjectType to another, so that all the items in the layout get reparented.''' + '''Transfer a layout from one ObjectType to another, so that all the items in + the layout get reparented.''' p1 = ObjectType() p2 = ObjectType() c1 = ObjectType() @@ -164,6 +143,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -173,7 +154,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testObjectTypeLayoutInsideAnotherLayoutAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. + All the objects are created in C++.''' p1 = ObjectType.create() l1 = ObjectTypeLayout.create() @@ -200,6 +182,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -209,7 +193,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjects(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType + and then transfer it to another object.''' p1 = ObjectType() p2 = ObjectType() @@ -238,6 +223,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -247,6 +234,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -256,8 +245,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l2.objectName) def testTransferNestedLayoutsBetweenObjectsAndEveryoneCreatedInCpp(self): - '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object. - All the objects are created in C++.''' + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then + transfer it to another object. All the objects are created in C++.''' p1 = ObjectType.create() p2 = ObjectType.create() @@ -286,6 +275,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): p2.setLayout(l1) del p1 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(c1.parent(), p2) self.assertEqual(c2.parent(), p2) @@ -295,6 +286,8 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l2.parent(), l1) del p2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, c1.objectName) self.assertRaises(RuntimeError, c2.objectName) @@ -303,6 +296,6 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertRaises(RuntimeError, l1.objectName) self.assertRaises(RuntimeError, l2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py b/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py index a82c54b7e..ceeee6c8d 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypeoperators_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -37,7 +10,8 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import ObjectTypeOperators + class ObjectTypeOperatorsTest(unittest.TestCase): @@ -53,7 +27,7 @@ class ObjectTypeOperatorsTest(unittest.TestCase): def testPointerOpeators(self): a = ObjectTypeOperators("a") - b = ObjectTypeOperators("b") + b = ObjectTypeOperators("b") # noqa: F841 self.assertEqual(a + "bc", "abc") self.assertEqual("bc" + a, "bca") self.assertEqual("a", a) @@ -63,5 +37,6 @@ class ObjectTypeOperatorsTest(unittest.TestCase): a = ObjectTypeOperators("a") self.assertNotEqual(a, "b") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py b/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py index cb270c69b..5fa6f824e 100644 --- a/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py +++ b/sources/shiboken6/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from sample import ObjectTypeHolder + class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): def testBasic(self): @@ -52,5 +26,6 @@ class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): holder = Holder('TheObjectFromC++') self.assertEqual(holder.callPassObjectTypeAsReference(), 'ThisIsTheObjectFromC++') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/oddbool_test.py b/sources/shiboken6/tests/samplebinding/oddbool_test.py index a65b1228c..87a8cdb1f 100644 --- a/sources/shiboken6/tests/samplebinding/oddbool_test.py +++ b/sources/shiboken6/tests/samplebinding/oddbool_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for OddBool user's primitive type conversion.''' @@ -40,13 +13,15 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import OddBoolUser, ComparisonTester +from sample import OddBoolUser, ComparisonTester, SpaceshipComparisonTester + class DerivedOddBoolUser (OddBoolUser): def returnMyselfVirtual(self): return OddBoolUser() pass + class OddBoolTest(unittest.TestCase): def testOddBoolUser(self): @@ -57,13 +32,13 @@ class OddBoolTest(unittest.TestCase): self.assertEqual(obuTrue.oddBool(), True) self.assertEqual(obuTrue.callInvertedOddBool(), False) - self.assertEqual(obuTrue.oddBool() == True, True) - self.assertEqual(False == obuFalse.oddBool(), True) - self.assertEqual(obuTrue.oddBool() == obuFalse.oddBool(), False) + self.assertTrue(obuTrue.oddBool()) + self.assertFalse(obuFalse.oddBool()) + self.assertTrue(obuTrue.oddBool() != obuFalse.oddBool()) - self.assertEqual(obuFalse.oddBool() != True, True) - self.assertEqual(True != obuFalse.oddBool(), True) - self.assertEqual(obuTrue.oddBool() != obuFalse.oddBool(), True) + self.assertFalse(obuFalse.oddBool()) + self.assertFalse(obuFalse.oddBool()) + self.assertTrue(obuTrue.oddBool() != obuFalse.oddBool()) def testVirtuals(self): dobu = DerivedOddBoolUser() @@ -86,6 +61,19 @@ class OddBoolTest(unittest.TestCase): t2 = ComparisonTester(42) self.assertEqual(t1, t2) + def testSpaceshipOperator(self): + if not SpaceshipComparisonTester.HasSpaceshipOperator: + print("Skipping Spaceship Operator test") + return + t1 = SpaceshipComparisonTester(42) + t2 = SpaceshipComparisonTester(42) + self.assertEqual(t1, t2) + self.assertTrue(t1 <= t2) + self.assertTrue(t1 >= t2) + t2 = SpaceshipComparisonTester(43) + self.assertTrue(t1 < t2) + self.assertFalse(t1 > t2) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py index 65ec14cd7..bcb154c52 100644 --- a/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py +++ b/sources/shiboken6/tests/samplebinding/onlycopyclass_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,6 +13,7 @@ init_paths() from sample import OnlyCopy, FriendOfOnlyCopy + class ClassWithOnlyCopyCtorTest(unittest.TestCase): def testGetOne(self): obj = FriendOfOnlyCopy.createOnlyCopy(123) @@ -61,5 +35,6 @@ class ClassWithOnlyCopyCtorTest(unittest.TestCase): obj = FriendOfOnlyCopy.createOnlyCopy(123) self.assertEqual(obj.value(), OnlyCopy.getValueFromReference(obj)) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/overflow_test.py b/sources/shiboken6/tests/samplebinding/overflow_test.py index 5635eeed2..84442306a 100644 --- a/sources/shiboken6/tests/samplebinding/overflow_test.py +++ b/sources/shiboken6/tests/samplebinding/overflow_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for overflowing C++ numeric types.''' @@ -40,21 +13,29 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import (Point, doubleLongLong, doubleShort, doubleUnsignedInt, + doubleUnsignedLongLong) class OverflowTest(unittest.TestCase): '''Test case for overflowing C++ numeric types.''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testUnsignedInt(self): - '''C++ function receives an unsigned int argument and raise OverflowError if the value is negative.''' + '''C++ function receives an unsigned int argument and raise OverflowError + if the value is negative.''' val = 100 self.assertEqual(doubleUnsignedInt(val), 2 * val) val *= -1 self.assertRaises(OverflowError, doubleUnsignedInt, val) def testLongLong(self): - '''C++ function receives an long long argument and raise OverflowError if the value is negative.''' + '''C++ function receives an long long argument and raise OverflowError + if the value is negative.''' val = 100 self.assertEqual(doubleLongLong(val), 2 * val) val = int(100) @@ -63,7 +44,8 @@ class OverflowTest(unittest.TestCase): self.assertRaises(OverflowError, doubleLongLong, val) def testUnsignedLongLong(self): - '''C++ function receives an unsigned long long argument and raise OverflowError if the value is negative.''' + '''C++ function receives an unsigned long long argument and raise OverflowError + if the value is negative.''' val = 100 self.assertEqual(doubleUnsignedLongLong(val), 2 * val) val = int(100) @@ -81,13 +63,13 @@ class OverflowTest(unittest.TestCase): def testShortOverflow(self): '''Calls function with short parameter using an overflowing value.''' doubleShort(-3) - self.assertRaises(OverflowError, doubleShort, 0xFFFF*-1) + self.assertRaises(OverflowError, doubleShort, 0xFFFF * -1) self.assertRaises(OverflowError, doubleShort, 0xFFFF + 1) def testOverflowOnCtor(self): '''Calls object ctor with int parameter using overflowing values.''' self.assertRaises(OverflowError, Point, 42415335332353253, 42415335332353253) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/overload_sorting_test.py b/sources/shiboken6/tests/samplebinding/overload_sorting_test.py index ff941e016..060d91510 100644 --- a/sources/shiboken6/tests/samplebinding/overload_sorting_test.py +++ b/sources/shiboken6/tests/samplebinding/overload_sorting_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for overload sorting''' @@ -40,11 +13,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import (CustomOverloadSequence, ImplicitBase, ImplicitConv, + ImplicitTarget, SortedOverload) + class Dummy(object): pass + class SimpleOverloadSorting(unittest.TestCase): def setUp(self): @@ -90,6 +66,7 @@ class DeepOverloadSorting(unittest.TestCase): '''Deep Overload - (int, ImplicitBase *)''' self.assertEqual(self.obj.overloadDeep(1, ImplicitBase()), "ImplicitBase") + class EnumOverIntSorting(unittest.TestCase): def testEnumOverInt(self): ic = ImplicitConv(ImplicitConv.CtorTwo) diff --git a/sources/shiboken6/tests/samplebinding/overload_test.py b/sources/shiboken6/tests/samplebinding/overload_test.py index 50f587eec..62fa8d8d2 100644 --- a/sources/shiboken6/tests/samplebinding/overload_test.py +++ b/sources/shiboken6/tests/samplebinding/overload_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Overload class''' @@ -48,11 +21,10 @@ def raisesWithErrorMessage(func, arguments, errorType, errorMsg): try: func(*arguments) return False - except Exception as err: - if type(err) != TypeError: - return False - if not errorMsg in str(err): - return False + except TypeError as err: + return errorMsg in str(err) + except Exception: + return False return True @@ -205,12 +177,13 @@ class OverloadTest(unittest.TestCase): def testAcceptSequencePyObject(self): # Overload.acceptSequence(void*) overload = Overload() + class Foo(object): pass + foo = Foo() self.assertEqual(overload.acceptSequence(foo), Overload.Function5) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py b/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py index 9d8b0aeab..269b97299 100644 --- a/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py +++ b/sources/shiboken6/tests/samplebinding/overloadwithdefault_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -66,6 +39,6 @@ class OverloadTest(unittest.TestCase): overload = Overload() self.assertEqual(overload.strBufferOverloads(bytes('', "UTF-8"), 0), Overload.Function1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py b/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py index 3b5ae5c8e..8a55d3ab8 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_argument_invalidation_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Wrapper validity tests for arguments.''' @@ -42,6 +15,7 @@ init_paths() from sample import Polygon, Point + class WrapperValidityOfArgumentsTest(unittest.TestCase): '''Wrapper validity tests for arguments.''' @@ -52,17 +26,19 @@ class WrapperValidityOfArgumentsTest(unittest.TestCase): self.assertRaises(RuntimeError, Polygon.doublePolygonScale, poly) def testInvalidArgumentToConstructor(self): - '''Call to constructor using invalidated Python wrapper as argument should raise RuntimeError.''' + '''Call to constructor using invalidated Python wrapper as argument + should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) self.assertRaises(RuntimeError, Polygon, pt) def testInvalidArgumentWithImplicitConversion(self): - '''Call to method using invalidated Python wrapper to be implicitly converted should raise RuntimeError.''' + '''Call to method using invalidated Python wrapper to be implicitly converted + should raise RuntimeError.''' pt = Point(1, 2) Polygon.stealOwnershipFromPython(pt) self.assertRaises(RuntimeError, Polygon.doublePolygonScale, pt) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py index be010c84b..25c6fea26 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_cpp_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for destroy a child object in C++''' @@ -57,5 +30,6 @@ class DeleteChildInCpp(unittest.TestCase): self.assertRaises(RuntimeError, child.objectName) self.assertEqual(parent.objectName(), 'parent') + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py index 10535f272..3ae186815 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_child_in_python_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for deleting a child object in python''' +import gc import os import random import string @@ -56,8 +30,11 @@ class DeleteChildInPython(unittest.TestCase): child.setObjectName(name) del child + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() new_child = parent.children()[0] self.assertEqual(new_child.objectName(), name) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py index 1f0d76cce..8f654639c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_delete_parent_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for destroying the parent''' +import gc import os import sys import unittest @@ -46,6 +20,7 @@ from sample import ObjectType class DeleteParentTest(unittest.TestCase): '''Test case for deleting a parent object''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentDestructor(self): '''Delete parent object should invalidate child''' parent = ObjectType() @@ -55,9 +30,12 @@ class DeleteParentTest(unittest.TestCase): refcount_before = sys.getrefcount(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) - self.assertEqual(sys.getrefcount(child), refcount_before-1) + self.assertEqual(sys.getrefcount(child), refcount_before - 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testParentDestructorMultipleChildren(self): '''Delete parent object should invalidate all children''' parent = ObjectType() @@ -67,10 +45,13 @@ class DeleteParentTest(unittest.TestCase): child.setParent(parent) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() for i, child in enumerate(children): self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 4) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testRecursiveParentDelete(self): '''Delete parent should invalidate grandchildren''' parent = ObjectType() @@ -78,6 +59,8 @@ class DeleteParentTest(unittest.TestCase): grandchild = ObjectType(child) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, child.objectName) self.assertEqual(sys.getrefcount(child), 2) self.assertRaises(RuntimeError, grandchild.objectName) diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py index e4a59426e..37b7591e4 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_after_use_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Ownership tests for cases of invalidation of Python wrapper after use.''' @@ -48,11 +21,13 @@ class ExtObjectType(ObjectType): ObjectType.__init__(self) self.type_of_last_event = None self.last_event = None + def event(self, event): self.last_event = event self.type_of_last_event = event.eventType() return True + class MyObjectType (ObjectType): def __init__(self): super(MyObjectType, self).__init__() @@ -62,7 +37,7 @@ class MyObjectType (ObjectType): self.callInvalidateEvent(ev) try: ev.eventType() - except: + except: # noqa: E722 self.fail = True raise return True @@ -70,21 +45,25 @@ class MyObjectType (ObjectType): def invalidateEvent(self, ev): pass + class ExtObjectTypeDerived(ObjectTypeDerived): def __init__(self): ObjectTypeDerived.__init__(self) self.type_of_last_event = None self.last_event = None + def event(self, event): self.last_event = event self.type_of_last_event = event.eventType() return True + class OwnershipInvalidateAfterUseTest(unittest.TestCase): '''Ownership tests for cases of invalidation of Python wrapper after use.''' def testInvalidateAfterUse(self): - '''In ObjectType.event(Event*) the wrapper object created for Event must me marked as invalid after the method is called.''' + '''In ObjectType.event(Event*) the wrapper object created for Event + must me marked as invalid after the method is called.''' eot = ExtObjectType() eot.causeEvent(Event.SOME_EVENT) self.assertEqual(eot.type_of_last_event, Event.SOME_EVENT) @@ -111,6 +90,6 @@ class OwnershipInvalidateAfterUseTest(unittest.TestCase): self.assertEqual(eot.type_of_last_event, Event.SOME_EVENT) self.assertRaises(RuntimeError, eot.last_event.eventType) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py index 6ffa6629b..77b7c576c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_child_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for invalidating a C++ created child that was already on the care of a parent.''' +import gc import os import sys import unittest @@ -67,10 +41,14 @@ class InvalidateChildTest(unittest.TestCase): self.assertEqual(parent.children(), []) del parent + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + # PYSIDE-535: Why do I need to do it twice, here? + gc.collect() self.assertEqual(child1.objectName(), 'child1') self.assertRaises(RuntimeError, child2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py index efc3afd38..8cbefc30c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_nonpolymorphic_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between Python and C++.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point, BlackBox + class OwnershipInvalidateNonPolymorphicTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between Python and C++.''' @@ -54,6 +28,6 @@ class OwnershipInvalidateNonPolymorphicTest(unittest.TestCase): p1_ret = bb.retrievePoint(p1_ticket) self.assertEqual(p1_ret, Point(10, 20)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py b/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py index d34eeedd2..c721a212c 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_invalidate_parent_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for invalidating a parent of other objects.''' @@ -61,7 +34,7 @@ class InvalidateParentTest(unittest.TestCase): grandchild2.setParent(child2) bbox = BlackBox() - bbox.keepObjectType(parent) # Should invalidate the parent + bbox.keepObjectType(parent) # Should invalidate the parent self.assertRaises(RuntimeError, parent.objectName) # some children still valid they are wrapper classes @@ -70,6 +43,6 @@ class InvalidateParentTest(unittest.TestCase): self.assertEqual(grandchild1.objectName(), "grandchild1") self.assertRaises(RuntimeError, grandchild2.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py b/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py index d0b363790..304223063 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_reparenting_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests for object reparenting.''' @@ -43,6 +16,7 @@ import sys from sample import ObjectType + class ExtObjectType(ObjectType): def __init__(self): ObjectType.__init__(self) @@ -65,6 +39,7 @@ class ReparentingTest(unittest.TestCase): for child in new_parent.children(): self.assertTrue(child in object_list) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReparentWithTheSameParent(self): '''Set the same parent twice to check if the ref continue the same''' obj = ObjectType() @@ -134,4 +109,3 @@ class ReparentingTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py index 3cea6b3fb..0e9f08b72 100644 --- a/sources/shiboken6/tests/samplebinding/ownership_transference_test.py +++ b/sources/shiboken6/tests/samplebinding/ownership_transference_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''The BlackBox class has cases of ownership transference between C++ and Python.''' +import gc import os import sys import unittest @@ -42,9 +16,11 @@ init_paths() from sample import ObjectType, BlackBox + class BlackBoxTest(unittest.TestCase): '''The BlackBox class has cases of ownership transference between C++ and Python.''' + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipTransference(self): '''Ownership transference from Python to C++ and back again.''' o1 = ObjectType() @@ -54,16 +30,19 @@ class BlackBoxTest(unittest.TestCase): o2.setObjectName('object2') o2_refcnt = sys.getrefcount(o2) bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 o2_ticket = bb.keepObjectType(o2) self.assertEqual(set(bb.objects()), set([o1, o2])) self.assertEqual(str(o1.objectName()), 'object1') self.assertEqual(str(o2.objectName()), 'object2') - self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) # PySide give +1 ref to object with c++ ownership + # PySide give +1 ref to object with c++ ownership + self.assertEqual(sys.getrefcount(o1), o1_refcnt + 1) self.assertEqual(sys.getrefcount(o2), o2_refcnt + 1) o2 = bb.retrieveObjectType(o2_ticket) self.assertEqual(sys.getrefcount(o2), o2_refcnt) del bb + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertRaises(RuntimeError, o1.objectName) self.assertEqual(str(o2.objectName()), 'object2') self.assertEqual(sys.getrefcount(o2), o2_refcnt) @@ -71,21 +50,22 @@ class BlackBoxTest(unittest.TestCase): def testBlackBoxReleasingUnknownObjectType(self): '''Asks BlackBox to release an unknown ObjectType.''' o1 = ObjectType() - o2 = ObjectType() + o2 = ObjectType() # noqa: F841 bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 o3 = bb.retrieveObjectType(-5) self.assertEqual(o3, None) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testOwnershipTransferenceCppCreated(self): '''Ownership transference using a C++ created object.''' o1 = ObjectType.create() o1.setObjectName('object1') - o1_refcnt = sys.getrefcount(o1) + o1_refcnt = sys.getrefcount(o1) # noqa: F841 bb = BlackBox() - o1_ticket = bb.keepObjectType(o1) + o1_ticket = bb.keepObjectType(o1) # noqa: F841 self.assertRaises(RuntimeError, o1.objectName) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pair_test.py b/sources/shiboken6/tests/samplebinding/pair_test.py index 559f15ba2..4bd5c697c 100644 --- a/sources/shiboken6/tests/samplebinding/pair_test.py +++ b/sources/shiboken6/tests/samplebinding/pair_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for std::pair container conversions''' @@ -42,6 +15,7 @@ init_paths() from sample import PairUser + class ExtendedPairUser(PairUser): def __init__(self): PairUser.__init__(self) @@ -51,6 +25,7 @@ class ExtendedPairUser(PairUser): self.create_pair_called = True return (7, 13) + class PairConversionTest(unittest.TestCase): '''Test case for std::pair container conversions''' @@ -75,14 +50,16 @@ class PairConversionTest(unittest.TestCase): self.assertEqual(cp, (cpx0, cpx1)) def testSumPair(self): - '''Test method that sums the items of a pair using values of the types expected by C++ (int and double)''' + '''Test method that sums the items of a pair using values of the types + expected by C++ (int and double)''' pu = PairUser() pair = (3, 7.13) result = pu.sumPair(pair) self.assertEqual(result, sum(pair)) def testSumPairDifferentTypes(self): - '''Test method that sums the items of a pair using values of types different from the ones expected by C++ (int and double)''' + '''Test method that sums the items of a pair using values of types different + from the ones expected by C++ (int and double)''' pu = PairUser() pair = (3.3, 7) result = pu.sumPair(pair) @@ -98,7 +75,8 @@ class PairConversionTest(unittest.TestCase): self.assertEqual(result, pair) def testConversionInBothDirectionsWithSimilarContainer(self): - '''Test converting a list, instead of the expected tuple, from Python to C++ and the other way around.''' + '''Test converting a list, instead of the expected tuple, from Python to C++ + and the other way around.''' pu = PairUser() pair = [3, 5] pu.setPair(pair) @@ -106,6 +84,6 @@ class PairConversionTest(unittest.TestCase): self.assertNotEqual(result, pair) self.assertEqual(result, tuple(pair)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pen_test.py b/sources/shiboken6/tests/samplebinding/pen_test.py index 9cd1be2f6..106f3bd61 100644 --- a/sources/shiboken6/tests/samplebinding/pen_test.py +++ b/sources/shiboken6/tests/samplebinding/pen_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for <add-function> with const char* as argument''' @@ -42,6 +15,7 @@ init_paths() from sample import Color, Pen, SampleNamespace + class TestPen(unittest.TestCase): '''Simple test case for Pen.''' diff --git a/sources/shiboken6/tests/samplebinding/point_test.py b/sources/shiboken6/tests/samplebinding/point_test.py index bffaba6df..f86c0f423 100644 --- a/sources/shiboken6/tests/samplebinding/point_test.py +++ b/sources/shiboken6/tests/samplebinding/point_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for Point class''' @@ -42,9 +15,15 @@ init_paths() from sample import Point + class PointTest(unittest.TestCase): '''Test case for Point class, including operator overloads.''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testConstructor(self): '''Test Point class constructor.''' pt = Point(5.0, 2.3) @@ -84,6 +63,7 @@ class PointTest(unittest.TestCase): pt2 += pt1 self.assertFalse(pt1 == pt2) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReturnConstPointer(self): '''Point returns a const pointer for itself.''' pt1 = Point(5.0, 2.3) @@ -113,5 +93,6 @@ class PointTest(unittest.TestCase): expected = Point((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/pointerholder_test.py b/sources/shiboken6/tests/samplebinding/pointerholder_test.py index 3468ceedc..633525a9c 100644 --- a/sources/shiboken6/tests/samplebinding/pointerholder_test.py +++ b/sources/shiboken6/tests/samplebinding/pointerholder_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class that holds an arbitraty pointer and is modified to hold an PyObject.''' @@ -42,8 +15,10 @@ init_paths() from sample import PointerHolder + class TestPointerHolder(unittest.TestCase): - '''Test cases for a class that holds an arbitraty pointer and is modified to hold an PyObject.''' + '''Test cases for a class that holds an arbitraty pointer and + is modified to hold an PyObject.''' def testStoringAndRetrievingPointer(self): ph = PointerHolder('Hello') @@ -52,14 +27,15 @@ class TestPointerHolder(unittest.TestCase): ph = PointerHolder(a) self.assertEqual(ph.pointer(), a) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testReferenceCounting(self): '''Test reference counting when retrieving data with PointerHolder.pointer().''' a = (1, 2, 3) refcnt = sys.getrefcount(a) ph = PointerHolder(a) - ptr = ph.pointer() + ptr = ph.pointer() # noqa: F841 self.assertEqual(sys.getrefcount(a), refcnt + 1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py index ad3bd899a..4da1a89c6 100644 --- a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 """ pointerprimitivetype_test.py @@ -54,8 +27,8 @@ from shiboken_paths import init_paths init_paths() from sample import IntArray2, VirtualMethods -import shiboken6 -_init_pyside_extension() # trigger init, which does not happen in tests +from shibokensupport.signature import get_signature + import typing @@ -64,7 +37,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): def testArraySignature(self): # signature="IntArray2(const int*)" found = False - for sig in IntArray2.__signature__: + for sig in get_signature(IntArray2): if "data" in sig.parameters: found = True break @@ -75,7 +48,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): def testReturnVarSignature(self): # signature="getMargins(int*,int*,int*,int*)const"> - ann = VirtualMethods.getMargins.__signature__.return_annotation + ann = get_signature(VirtualMethods.getMargins).return_annotation self.assertEqual(ann, typing.Tuple[int, int, int, int]) diff --git a/sources/shiboken6/tests/samplebinding/pointf_test.py b/sources/shiboken6/tests/samplebinding/pointf_test.py index 3b8285b0b..91c58eb1d 100644 --- a/sources/shiboken6/tests/samplebinding/pointf_test.py +++ b/sources/shiboken6/tests/samplebinding/pointf_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for PointF class''' @@ -42,6 +15,7 @@ init_paths() from sample import PointF + class PointFTest(unittest.TestCase): '''Test case for PointF class, including operator overloads.''' @@ -72,5 +46,6 @@ class PointFTest(unittest.TestCase): expected = PointF((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) self.assertEqual(pt1.midpoint(pt2), expected) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py index 26dd3046b..0b9fe2249 100644 --- a/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py +++ b/sources/shiboken6/tests/samplebinding/primitivereferenceargument_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,12 +12,17 @@ from shiboken_paths import init_paths init_paths() import sample + class PrimitiveReferenceArgumentTest(unittest.TestCase): def testIntReferenceArgument(self): '''C++ signature: int acceptIntReference(int&)''' self.assertEqual(sample.acceptIntReference(123), 123) + def testIntReturnPtr(self): + '''C++ signature: const int *acceptIntReturnPtr(int x)''' + self.assertEqual(sample.acceptIntReturnPtr(123), 123) + def testOddBoolReferenceArgument(self): '''C++ signature: OddBool acceptOddBoolReference(OddBool&)''' self.assertEqual(sample.acceptOddBoolReference(True), True) @@ -52,5 +30,6 @@ class PrimitiveReferenceArgumentTest(unittest.TestCase): self.assertNotEqual(sample.acceptOddBoolReference(True), False) self.assertNotEqual(sample.acceptOddBoolReference(False), True) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/privatector_test.py b/sources/shiboken6/tests/samplebinding/privatector_test.py index c5f7ee58a..63040388d 100644 --- a/sources/shiboken6/tests/samplebinding/privatector_test.py +++ b/sources/shiboken6/tests/samplebinding/privatector_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class with only a private constructor.''' @@ -47,6 +20,11 @@ from sample import PrivateCtor class PrivateCtorTest(unittest.TestCase): '''Test case for PrivateCtor class''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testPrivateCtorInstanciation(self): '''Test if instanciation of class with a private constructor raises an exception.''' self.assertRaises(TypeError, PrivateCtor) @@ -67,6 +45,7 @@ class PrivateCtorTest(unittest.TestCase): self.assertEqual(pd2, pd1) self.assertEqual(pd2.instanceCalls(), calls + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testPrivateCtorRefCounting(self): '''Test refcounting of the singleton returned by PrivateCtor.instance().''' pd1 = PrivateCtor.instance() @@ -85,6 +64,6 @@ class PrivateCtorTest(unittest.TestCase): self.assertEqual(pd3.instanceCalls(), calls + 2) self.assertEqual(sys.getrefcount(pd3), refcnt) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/privatedtor_test.py b/sources/shiboken6/tests/samplebinding/privatedtor_test.py index f310ec51d..651f63b15 100644 --- a/sources/shiboken6/tests/samplebinding/privatedtor_test.py +++ b/sources/shiboken6/tests/samplebinding/privatedtor_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a class with a private destructor.''' @@ -48,6 +21,11 @@ from sample import PrivateDtor class PrivateDtorTest(unittest.TestCase): '''Test case for PrivateDtor class''' + def assertRaises(self, *args, **kwds): + if not hasattr(sys, "pypy_version_info"): + # PYSIDE-535: PyPy complains "Fatal RPython error: NotImplementedError" + return super().assertRaises(*args, **kwds) + def testPrivateDtorInstanciation(self): '''Test if instanciation of class with a private destructor raises an exception.''' self.assertRaises(TypeError, PrivateDtor) @@ -68,6 +46,7 @@ class PrivateDtorTest(unittest.TestCase): self.assertEqual(pd2, pd1) self.assertEqual(pd2.instanceCalls(), calls + 1) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testPrivateDtorRefCounting(self): '''Test refcounting of the singleton returned by PrivateDtor.instance().''' pd1 = PrivateDtor.instance() @@ -86,6 +65,7 @@ class PrivateDtorTest(unittest.TestCase): self.assertEqual(pd3.instanceCalls(), calls + 2) self.assertEqual(sys.getrefcount(pd3), refcnt) + @unittest.skipUnless(hasattr(sys, "getrefcount"), f"{sys.implementation.name} has no refcount") def testClassDecref(self): # Bug was that class PyTypeObject wasn't decrefed when instance # was invalidated @@ -100,6 +80,6 @@ class PrivateDtorTest(unittest.TestCase): self.assertLess(abs(before - after), 5) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/protected_test.py b/sources/shiboken6/tests/samplebinding/protected_test.py index 096eb615d..e4ccf721d 100644 --- a/sources/shiboken6/tests/samplebinding/protected_test.py +++ b/sources/shiboken6/tests/samplebinding/protected_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for protected methods.''' +import gc import os import sys import unittest @@ -42,46 +16,57 @@ init_paths() from sample import cacheSize from sample import ProtectedNonPolymorphic, ProtectedVirtualDestructor -from sample import ProtectedPolymorphic, ProtectedPolymorphicDaughter, ProtectedPolymorphicGrandDaughter +from sample import (ProtectedPolymorphic, ProtectedPolymorphicDaughter, + ProtectedPolymorphicGrandDaughter) from sample import createProtectedProperty, ProtectedProperty, ProtectedEnumClass from sample import PrivateDtor from sample import Event, ObjectType, Point + class ExtendedProtectedPolymorphic(ProtectedPolymorphic): def __init__(self, name): ProtectedPolymorphic.__init__(self, name) self.protectedName_called = False + def protectedName(self): self.protectedName_called = True self._name = 'Extended' + ProtectedPolymorphic.protectedName(self) return self._name + class ExtendedProtectedPolymorphicDaughter(ProtectedPolymorphicDaughter): def __init__(self, name): self.protectedName_called = False ProtectedPolymorphicDaughter.__init__(self, name) + def protectedName(self): self.protectedName_called = True self._name = 'ExtendedDaughter' + ProtectedPolymorphicDaughter.protectedName(self) return self._name + class ExtendedProtectedPolymorphicGrandDaughter(ProtectedPolymorphicGrandDaughter): def __init__(self, name): self.protectedName_called = False ProtectedPolymorphicGrandDaughter.__init__(self, name) + def protectedName(self): self.protectedName_called = True self._name = 'ExtendedGrandDaughter' + ProtectedPolymorphicGrandDaughter.protectedName(self) return self._name + class ExtendedProtectedVirtualDestructor(ProtectedVirtualDestructor): def __init__(self): ProtectedVirtualDestructor.__init__(self) + class ProtectedNonPolymorphicTest(unittest.TestCase): '''Test cases for protected method in a class without virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCall(self): @@ -105,10 +90,13 @@ class ProtectedNonPolymorphicTest(unittest.TestCase): self.assertEqual(p.dataTypeName(1), 'integer') self.assertEqual(p.dataTypeName(Point(1, 2)), 'pointer') + class ProtectedPolymorphicTest(unittest.TestCase): '''Test cases for protected method in a class with virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCall(self): @@ -132,6 +120,8 @@ class ProtectedPolymorphicTest(unittest.TestCase): self.assertTrue(p.protectedName_called) self.assertEqual(p.protectedName(), name) self.assertEqual(ProtectedPolymorphic.protectedName(p), original_name) + + class ProtectedPolymorphicDaugherTest(unittest.TestCase): '''Test cases for protected method in a class inheriting for a class with virtual methods.''' @@ -156,6 +146,8 @@ class ProtectedPolymorphicGrandDaugherTest(unittest.TestCase): another with protected virtual methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedCallWithInstanceCreatedOnCpp(self): @@ -173,6 +165,7 @@ class ProtectedPolymorphicGrandDaugherTest(unittest.TestCase): self.assertEqual(p.protectedName(), name) self.assertEqual(ProtectedPolymorphicGrandDaughter.protectedName(p), original_name) + class ProtectedVirtualDtorTest(unittest.TestCase): '''Test cases for protected virtual destructor.''' @@ -180,6 +173,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): ProtectedVirtualDestructor.resetDtorCounter() def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testVirtualProtectedDtor(self): @@ -187,7 +182,11 @@ class ProtectedVirtualDtorTest(unittest.TestCase): dtor_called = ProtectedVirtualDestructor.dtorCalled() for i in range(1, 10): pvd = ProtectedVirtualDestructor() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testVirtualProtectedDtorOnCppCreatedObject(self): @@ -196,6 +195,8 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ProtectedVirtualDestructor.create() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ProtectedVirtualDestructor.dtorCalled(), dtor_called + i) def testProtectedDtorOnDerivedClass(self): @@ -204,25 +205,32 @@ class ProtectedVirtualDtorTest(unittest.TestCase): for i in range(1, 10): pvd = ExtendedProtectedVirtualDestructor() del pvd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedProtectedVirtualDestructor.dtorCalled(), dtor_called + i) class ExtendedProtectedEnumClass(ProtectedEnumClass): def __init__(self): ProtectedEnumClass.__init__(self) + def protectedEnumMethod(self, value): if value == ProtectedEnumClass.ProtectedItem0: return ProtectedEnumClass.ProtectedItem1 return ProtectedEnumClass.ProtectedItem0 + def publicEnumMethod(self, value): if value == ProtectedEnumClass.PublicItem0: return ProtectedEnumClass.PublicItem1 return ProtectedEnumClass.PublicItem0 + class ProtectedEnumTest(unittest.TestCase): '''Test cases for protected enum.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedMethodWithProtectedEnumArgument(self): @@ -231,47 +239,66 @@ class ProtectedEnumTest(unittest.TestCase): self.assertEqual(type(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedEnum) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) - - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem1) def testProtectedMethodWithPublicEnumArgument(self): '''Calls protected method with public enum argument.''' obj = ProtectedEnumClass() - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) def testOverriddenProtectedMethodWithProtectedEnumArgument(self): '''Calls overridden protected method with protected enum argument.''' obj = ExtendedProtectedEnumClass() - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.protectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem0) - self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem0) - self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) + self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, ProtectedEnumClass.ProtectedItem0), # noqa: E501 + ProtectedEnumClass.ProtectedItem0) + self.assertEqual(ProtectedEnumClass.protectedEnumMethod(obj, + ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), ProtectedEnumClass.ProtectedItem1) - self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), ProtectedEnumClass.ProtectedItem0) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem0), + ProtectedEnumClass.ProtectedItem1) + self.assertEqual(obj.callProtectedEnumMethod(ProtectedEnumClass.ProtectedItem1), + ProtectedEnumClass.ProtectedItem0) def testOverriddenProtectedMethodWithPublicEnumArgument(self): '''Calls overridden protected method with public enum argument.''' obj = ExtendedProtectedEnumClass() - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.publicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem0) - self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem0) - self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem1) + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem0) + self.assertEqual(ProtectedEnumClass.publicEnumMethod(obj, ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), ProtectedEnumClass.PublicItem1) - self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), ProtectedEnumClass.PublicItem0) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem0), + ProtectedEnumClass.PublicItem1) + self.assertEqual(obj.callPublicEnumMethod(ProtectedEnumClass.PublicItem1), + ProtectedEnumClass.PublicItem0) class ProtectedPropertyTest(unittest.TestCase): @@ -282,6 +309,8 @@ class ProtectedPropertyTest(unittest.TestCase): def tearDown(self): del self.obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedProperty(self): @@ -323,6 +352,8 @@ class ProtectedPropertyTest(unittest.TestCase): pointProperty = obj.protectedValueTypeProperty self.assertTrue(obj.protectedValueTypeProperty is pointProperty) del obj, point, pointProperty + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), cache_size) def testProtectedValueTypePointerProperty(self): @@ -334,18 +365,24 @@ class ProtectedPropertyTest(unittest.TestCase): self.assertEqual(self.obj.protectedValueTypePointerProperty, pt2) self.assertTrue(self.obj.protectedValueTypePointerProperty is pt1) self.assertFalse(self.obj.protectedValueTypePointerProperty is pt2) + # PYSIDE-535: Need to assign None to break the cycle + self.obj.protectedValueTypePointerProperty = None def testProtectedObjectTypeProperty(self): '''Writes and reads a protected object type property.''' obj = ObjectType() self.obj.protectedObjectTypeProperty = obj self.assertEqual(self.obj.protectedObjectTypeProperty, obj) + # PYSIDE-535: Need to assign None to break the cycle + self.obj.protectedObjectTypeProperty = None class PrivateDtorProtectedMethodTest(unittest.TestCase): '''Test cases for classes with private destructors and protected methods.''' def tearDown(self): + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(cacheSize(), 0) def testProtectedMethod(self): @@ -359,6 +396,6 @@ class PrivateDtorProtectedMethodTest(unittest.TestCase): self.assertEqual(obj.instanceCalls(), 2) self.assertEqual(obj.instanceCalls(), obj.protectedInstanceCalls()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/pstrlist_test.py b/sources/shiboken6/tests/samplebinding/pstrlist_test.py index 2d2ae5942..d60f9cf35 100644 --- a/sources/shiboken6/tests/samplebinding/pstrlist_test.py +++ b/sources/shiboken6/tests/samplebinding/pstrlist_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() import sample + class PStrListTest(unittest.TestCase): def testPStrList(self): @@ -53,5 +27,6 @@ class PStrListTest(unittest.TestCase): lst = sample.createListOfPStr(a, b) self.assertEqual(lst, [a, b]) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/pystr_test.py b/sources/shiboken6/tests/samplebinding/pystr_test.py index d19715e7c..ec64c1e31 100644 --- a/sources/shiboken6/tests/samplebinding/pystr_test.py +++ b/sources/shiboken6/tests/samplebinding/pystr_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for definition of __str__ method.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point + class PyStrTest(unittest.TestCase): '''Test case for definition of __str__ method.''' @@ -50,6 +24,6 @@ class PyStrTest(unittest.TestCase): pt = Point(5, 2) self.assertEqual(str(pt), 'Point(5.0, 2.0)') + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/python_thread_test.py b/sources/shiboken6/tests/samplebinding/python_thread_test.py index 7b5b773e8..65398b5c6 100644 --- a/sources/shiboken6/tests/samplebinding/python_thread_test.py +++ b/sources/shiboken6/tests/samplebinding/python_thread_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #!/usr/bin/env python @@ -61,7 +36,7 @@ class Producer(threading.Thread): def run(self): while self.runs < self.max_runs: - value = int(random()*10) % 10 + value = int(random() * 10) % 10 self.bucket.push(value) self.production_list.append(value) logging.debug(f'PRODUCER - pushed {value}') @@ -91,6 +66,7 @@ class Consumer(threading.Thread): logging.debug('CONSUMER - empty bucket') time.sleep(0.01) + class ProducerConsumer(unittest.TestCase): '''Basic test case for producer-consumer QThread''' @@ -116,8 +92,5 @@ class ProducerConsumer(unittest.TestCase): self.assertEqual(prod.production_list, cons.consumption_list) - - - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py b/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py index f8519165b..1d19de941 100644 --- a/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py +++ b/sources/shiboken6/tests/samplebinding/receive_null_cstring_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' @@ -42,8 +15,10 @@ init_paths() from sample import countCharacters + class ReceiveNullCStringTest(unittest.TestCase): - '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' + '''Test case for a function that could receive a NULL pointer in a '[const] char*' + parameter.''' def testBasic(self): '''The test function should be working for the basic cases.''' @@ -56,6 +31,6 @@ class ReceiveNullCStringTest(unittest.TestCase): '''The test function returns '-1' when receives a None value instead of a string.''' self.assertEqual(countCharacters(None), -1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/reference_test.py b/sources/shiboken6/tests/samplebinding/reference_test.py index 4255f1921..1b6dd3a7a 100644 --- a/sources/shiboken6/tests/samplebinding/reference_test.py +++ b/sources/shiboken6/tests/samplebinding/reference_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for methods that receive references to objects.''' @@ -40,7 +13,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Reference, Str + class ExtendedReference(Reference): def __init__(self): @@ -75,7 +49,7 @@ class ReferenceTest(unittest.TestCase): def testCantSegFaultWhenReceiveNone(self): '''do not segfault when receiving None as argument.''' s = Str() - self.assertTrue(None == s) + self.assertFalse(bool(s)) def testMethodThatReceivesConstReference(self): '''Test a method that receives a const reference to an object as argument.''' @@ -84,29 +58,33 @@ class ReferenceTest(unittest.TestCase): self.assertEqual(Reference.usesConstReference(r), objId) def testModificationOfReference(self): - '''Tests if the identity of a reference argument is preserved when passing it to be altered in C++.''' + '''Tests if the identity of a reference argument is preserved when passing + it to be altered in C++.''' objId = 123 r1 = Reference(objId) r1.alterReferenceIdVirtual(r1) self.assertEqual(r1.objId(), objId * Reference.multiplier()) def testModificationOfReferenceCallingAVirtualIndirectly(self): - '''Tests if the identity of a reference argument is preserved when passing it to be altered in C++ through a method that calls a virtual method.''' + '''Tests if the identity of a reference argument is preserved when passing it + to be altered in C++ through a method that calls a virtual method.''' objId = 123 r1 = Reference(objId) r1.callAlterReferenceIdVirtual(r1) self.assertEqual(r1.objId(), objId * Reference.multiplier()) def testModificationOfReferenceCallingAReimplementedVirtualIndirectly(self): - '''Test if a Python override of a virtual method with a reference parameter called from C++ alters the argument properly.''' + '''Test if a Python override of a virtual method with a reference parameter + called from C++ alters the argument properly.''' objId = 123 r = Reference(objId) er = ExtendedReference() - result = er.callAlterReferenceIdVirtual(r) + result = er.callAlterReferenceIdVirtual(r) # noqa: F841 self.assertEqual(r.objId(), objId * er.multiplier) def testReimplementedVirtualMethodCallWithReferenceParameter(self): - '''Test if a Python override of a virtual method with a reference parameter is correctly called from C++.''' + '''Test if a Python override of a virtual method with a reference parameter + is correctly called from C++.''' inc = 9 objId = 123 r = Reference(objId) @@ -115,7 +93,8 @@ class ReferenceTest(unittest.TestCase): self.assertEqual(result, objId + inc + er.reference_inc) def testReimplementedVirtualMethodCallWithConstReferenceParameter(self): - '''Test if a Python override of a virtual method with a const reference parameter is correctly called from C++.''' + '''Test if a Python override of a virtual method with a const reference + parameter is correctly called from C++.''' inc = 9 objId = 123 r = Reference(objId) @@ -123,6 +102,6 @@ class ReferenceTest(unittest.TestCase): result = er.callUsesConstReferenceVirtual(r, inc) self.assertEqual(result, objId + inc + er.const_reference_inc) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/referencetopointer_test.py b/sources/shiboken6/tests/samplebinding/referencetopointer_test.py index 48893173b..942c7ea29 100644 --- a/sources/shiboken6/tests/samplebinding/referencetopointer_test.py +++ b/sources/shiboken6/tests/samplebinding/referencetopointer_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for a reference to pointer argument type.''' @@ -42,6 +15,7 @@ init_paths() from sample import VirtualMethods, Str + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -99,6 +73,6 @@ class ReferenceToPointerTest(unittest.TestCase): self.assertTrue(ok) self.assertEqual(string, Str(obj.prefix + 'foo')) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/renaming_test.py b/sources/shiboken6/tests/samplebinding/renaming_test.py index a31dceb35..b08438ef3 100644 --- a/sources/shiboken6/tests/samplebinding/renaming_test.py +++ b/sources/shiboken6/tests/samplebinding/renaming_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for renaming using target-lang-name attribute.''' @@ -43,6 +16,9 @@ init_paths() from sample import RenamedValue, RenamedUser +from shibokensupport.signature import get_signature + + class RenamingTest(unittest.TestCase): def test(self): '''Tests whether the C++ class ToBeRenamedValue renamed via attribute @@ -54,11 +30,10 @@ class RenamingTest(unittest.TestCase): "<class 'sample.RenamedValue'>") rename_user = RenamedUser() rename_user.useRenamedValue(renamed_value) - actual_signature = str(rename_user.useRenamedValue.__signature__) + actual_signature = str(get_signature(rename_user.useRenamedValue)) self.assertTrue(re.match(r"^\(self,\s*?v:\s*?sample.RenamedValue\)\s*?->\s*?None$", actual_signature)) - if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/return_null_test.py b/sources/shiboken6/tests/samplebinding/return_null_test.py index 3ca3f2731..2c4f07c65 100644 --- a/sources/shiboken6/tests/samplebinding/return_null_test.py +++ b/sources/shiboken6/tests/samplebinding/return_null_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for functions that could return a NULL pointer.''' @@ -40,7 +13,9 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import returnNullPrimitivePointer, returnNullValueTypePointer, returnNullObjectTypePointer +from sample import (returnNullPrimitivePointer, returnNullValueTypePointer, + returnNullObjectTypePointer) + class ReturnNullTest(unittest.TestCase): '''Test case for functions that could return a NULL pointer.''' @@ -60,6 +35,6 @@ class ReturnNullTest(unittest.TestCase): o = returnNullValueTypePointer() self.assertEqual(o, None) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/richcompare_test.py b/sources/shiboken6/tests/samplebinding/richcompare_test.py index 5a5fab646..3146d0faf 100644 --- a/sources/shiboken6/tests/samplebinding/richcompare_test.py +++ b/sources/shiboken6/tests/samplebinding/richcompare_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -38,7 +11,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Expression + class TestRichCompare(unittest.TestCase): @@ -49,5 +23,6 @@ class TestRichCompare(unittest.TestCase): d = a + c < b + a self.assertEqual(d.toString(), "((2+(2+3))<(3+2))") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/sample-binding.txt.in b/sources/shiboken6/tests/samplebinding/sample-binding.txt.in index 317f76f09..bcf9de90f 100644 --- a/sources/shiboken6/tests/samplebinding/sample-binding.txt.in +++ b/sources/shiboken6/tests/samplebinding/sample-binding.txt.in @@ -13,3 +13,4 @@ typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ enable-parent-ctor-heuristic use-isnull-as-nb_nonzero +lean-headers diff --git a/sources/shiboken6/tests/samplebinding/sample_test.py b/sources/shiboken6/tests/samplebinding/sample_test.py index 24e4354c5..19b2f708d 100644 --- a/sources/shiboken6/tests/samplebinding/sample_test.py +++ b/sources/shiboken6/tests/samplebinding/sample_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for libsample bindings module''' @@ -42,32 +15,10 @@ init_paths() import sample + class ModuleTest(unittest.TestCase): '''Test case for module and global functions''' - def testModuleMembers(self): - '''Test availability of classes, global functions and other members on binding''' - expected_members = set(['Abstract', 'Derived', 'Point', - 'ListUser', 'PairUser', 'MapUser', - 'gimmeComplexList', 'gimmeDouble', 'gimmeInt', - 'makeCString', 'multiplyPair', 'returnCString', - 'SampleNamespace', 'transmuteComplexIntoPoint', - 'transmutePointIntoComplex', 'sumComplexPair', - 'FirstThing', 'SecondThing', 'ThirdThing', - 'GlobalEnum', 'NoThing']) - self.assertTrue(expected_members.issubset(dir(sample))) - - def testAbstractPrintFormatEnum(self): - '''Test availability of PrintFormat enum from Abstract class''' - enum_members = set(['PrintFormat', 'Short', 'Verbose', - 'OnlyId', 'ClassNameAndId']) - self.assertTrue(enum_members.issubset(dir(sample.Abstract))) - - def testSampleNamespaceOptionEnum(self): - '''Test availability of Option enum from SampleNamespace namespace''' - enum_members = set(['Option', 'None_', 'RandomNumber', 'UnixTime']) - self.assertTrue(enum_members.issubset(dir(sample.SampleNamespace))) - def testAddedFunctionAtModuleLevel(self): '''Calls function added to module from type system description.''' str1 = 'Foo' @@ -80,10 +31,46 @@ class ModuleTest(unittest.TestCase): self.assertEqual(sample.countVarargs(1, 2), 1) self.assertEqual(sample.countVarargs(1, 2, 3, 'a', 'b', 4, (5, 6)), 6) + def testSampleComparisonOpInNamespace(self): + s1 = sample.sample.sample(10) + s2 = sample.sample.sample(10) + self.assertEqual(s1, s2) + def testConstant(self): self.assertEqual(sample.sample.INT_CONSTANT, 42) + def testStringFunctions(self): + # Test plain ASCII, UCS1 and UCS4 encoding which have different + # representations in the PyUnicode objects. + for t1 in ["ascii", "Ümläut", "😀"]: + expected = t1 + t1 + self.assertEqual(sample.addStdStrings(t1, t1), expected) + self.assertEqual(sample.addStdWStrings(t1, t1), expected) + + def testNullPtrT(self): + sample.testNullPtrT(None) + self.assertRaises(TypeError, sample.testNullPtrT, 42) + + def testRValueRefsWithValueTypes(self): + """Passing value types by rvalue refs: For value types, nothing should + happen since the argument is copied in the call and the copy is + moved from.""" + polygon = sample.Polygon() + polygon.addPoint(sample.Point(1, 2)) + polygon.addPoint(sample.Point(3, 4)) + point_count = len(polygon.points()) + self.assertEqual(point_count, sample.takePolygon(polygon)) + + def testRValueRefsWithObjectTypes(self): + """Passing object types by rvalue refs: The underlying object should + be moved from.""" + o = sample.ObjectType() + object_name = "Name" + o.setObjectName(object_name) + self.assertEqual(len(object_name), sample.takeObjectType(o)) + # o should be moved from, name is now empty + self.assertEqual(len(o.objectName()), 0) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/samplebinding.pyproject b/sources/shiboken6/tests/samplebinding/samplebinding.pyproject new file mode 100644 index 000000000..ba6ba6f8f --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/samplebinding.pyproject @@ -0,0 +1,131 @@ +{ + "files": ["__del___test.py", + "abstract_test.py", + "addedfunction_test.py", + "addedfunction_with_container_args_test.py", + "argumentmodifications_test.py", + "array_numpy_test.py", + "array_sequence_test.py", + "bug_554_test.py", + "bug_704_test.py", + "bytearray_test.py", + "child_return_test.py", + "class_fields_test.py", + "collector_test.py", + "complex_test.py", + "conversion_operator_test.py", + "copy_test.py", + "ctorconvrule_test.py", + "cyclic_test.py", + "date_test.py", + "decisor_test.py", + "delete_test.py", + "deprecated_test.py", + "derived_test.py", + "duck_punching_test.py", + "echo_test.py", + "enum_test.py", + "enumfromremovednamespace_test.py", + "event_loop_call_virtual_test.py", + "event_loop_thread_test.py", + "exception_test.py", + "filter_test.py", + "handleholder_test.py", + "hashabletype_test.py", + "ignorederefop_test.py", + "implicitconv_numerical_test.py", + "implicitconv_test.py", + "inheritanceandscope_test.py", + "injectcode_test.py", + "innerclass_test.py", + "intlist_test.py", + "intwrapper_test.py", + "invalid_virtual_return_test.py", + "keep_reference_test.py", + "list_test.py", + "lock_test.py", + "map_test.py", + "metaclass_test.py", + "mi_virtual_methods_test.py", + "mixed_mi_test.py", + "modelindex_test.py", + "modelview_test.py", + "modifications_test.py", + "modified_constructor_test.py", + "modifiedvirtualmethods_test.py", + "multi_cpp_inheritance_test.py", + "multiple_derived_test.py", + "namespace_test.py", + "newdivision_test.py", + "nondefaultctor_test.py", + "nontypetemplate_test.py", + "nonzero_test.py", + "numericaltypedef_test.py", + "numpy_test.py", + "objecttype_test.py", + "objecttype_with_named_args_test.py", + "objecttypebyvalue_test.py", + "objecttypelayout_test.py", + "objecttypeoperators_test.py", + "objecttypereferenceasvirtualmethodargument_test.py", + "oddbool_test.py", + "onlycopyclass_test.py", + "overflow_test.py", + "overload_sorting_test.py", + "overload_test.py", + "overloadwithdefault_test.py", + "ownership_argument_invalidation_test.py", + "ownership_delete_child_in_cpp_test.py", + "ownership_delete_child_in_python_test.py", + "ownership_delete_parent_test.py", + "ownership_invalidate_after_use_test.py", + "ownership_invalidate_child_test.py", + "ownership_invalidate_nonpolymorphic_test.py", + "ownership_invalidate_parent_test.py", + "ownership_reparenting_test.py", + "ownership_transference_test.py", + "pair_test.py", + "pen_test.py", + "point_test.py", + "pointerholder_test.py", + "pointerprimitivetype_test.py", + "pointf_test.py", + "primitivereferenceargument_test.py", + "privatector_test.py", + "privatedtor_test.py", + "protected_test.py", + "pstrlist_test.py", + "pystr_test.py", + "python_thread_test.py", + "receive_null_cstring_test.py", + "reference_test.py", + "referencetopointer_test.py", + "renaming_test.py", + "return_null_test.py", + "richcompare_test.py", + "sample_test.py", + "samplesnippets.cpp", + "simplefile_glue.cpp", + "simplefile_test.py", + "size_test.py", + "snakecase_test.py", + "static_nonstatic_methods_test.py", + "str_test.py", + "strlist_test.py", + "templateinheritingclass_test.py", + "time_test.py", + "transform_test.py", + "typeconverters_test.py", + "typedealloc_test.py", + "typedtordoublefree_test.py", + "typesystypedef_test.py", + "unsafe_parent_test.py", + "useraddedctor_test.py", + "virtualdtor_test.py", + "virtualmethods_test.py", + "visibilitychange_test.py", + "voidholder_test.py", + "weakref_test.py", + "writableclassdict_test.py", + "typesystem_sample.xml"] +} diff --git a/sources/shiboken6/tests/samplebinding/samplesnippets.cpp b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp new file mode 100644 index 000000000..43e6b08de --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +// @snippet intwrapper_add_ints +extern "C" { +static PyObject *Sbk_IntWrapper_add_ints(PyObject * /* self */, PyObject *args) +{ + PyObject *result = nullptr; + if (PyTuple_Check(args) != 0 && PyTuple_Size(args) == 2) { + PyObject *arg1 = PyTuple_GetItem(args, 0); + PyObject *arg2 = PyTuple_GetItem(args, 1); + if (PyLong_Check(arg1) != 0 && PyLong_Check(arg2) != 0) + result = PyLong_FromLong(PyLong_AsLong(arg1) + PyLong_AsLong(arg2)); + } + if (result == nullptr) + PyErr_SetString(PyExc_TypeError, "expecting 2 ints"); + return result; +} +} +// @snippet intwrapper_add_ints + +// @snippet stdcomplex_floor +%PYARG_0 = PyFloat_FromDouble(std::floor(%CPPSELF.abs_value())); +// @snippet stdcomplex_floor + +// @snippet stdcomplex_ceil +%PYARG_0 = PyFloat_FromDouble(std::ceil(%CPPSELF.abs_value())); +// @snippet stdcomplex_ceil + +// @snippet stdcomplex_abs +%PYARG_0 = PyFloat_FromDouble(%CPPSELF.abs_value()); +// @snippet stdcomplex_abs + +// @snippet stdcomplex_pow +%RETURN_TYPE %0 = %CPPSELF.pow(%1); +%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); +// @snippet stdcomplex_pow + +// @snippet size_char_ct +// Convert a string "{width}x{height}" specification +{ + double width = -1; + double height = -1; + const std::string s = %1; + const auto pos = s.find('x'); + if (pos != std::string::npos) { + std::istringstream wstr(s.substr(0, pos)); + wstr >> width; + std::istringstream hstr(s.substr(pos + 1, s.size() - pos - 1)); + hstr >> height; + } + %0 = new %TYPE(width, height); +} +// @snippet size_char_ct diff --git a/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp b/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp index bccd51534..76c0cfaf2 100644 --- a/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp +++ b/sources/shiboken6/tests/samplebinding/simplefile_glue.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 if (!%CPPSELF.%FUNCTION_NAME()) { PyObject* error_msg = PyBytes_FromFormat( diff --git a/sources/shiboken6/tests/samplebinding/simplefile_test.py b/sources/shiboken6/tests/samplebinding/simplefile_test.py index 1f5561f77..55c894a35 100644 --- a/sources/shiboken6/tests/samplebinding/simplefile_test.py +++ b/sources/shiboken6/tests/samplebinding/simplefile_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for SimpleFile class''' @@ -42,6 +15,7 @@ init_paths() from sample import SimpleFile + class SimpleFileTest(unittest.TestCase): '''Test cases for SimpleFile class.''' @@ -81,6 +55,6 @@ class SimpleFileTest(unittest.TestCase): self.assertRaises(IOError, f.open) self.assertEqual(f.size(), 0) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/size_test.py b/sources/shiboken6/tests/samplebinding/size_test.py index 4df438e2b..069ce59b3 100644 --- a/sources/shiboken6/tests/samplebinding/size_test.py +++ b/sources/shiboken6/tests/samplebinding/size_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for operator overloads on Size class''' @@ -42,6 +15,7 @@ init_paths() from sample import Size + class PointTest(unittest.TestCase): '''Test case for Size class, including operator overloads.''' @@ -121,6 +95,6 @@ class PointTest(unittest.TestCase): self.assertTrue(s1 > s2) self.assertFalse(s2 > s1) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/snakecase_test.py b/sources/shiboken6/tests/samplebinding/snakecase_test.py index 2147b2c5b..a1538796a 100644 --- a/sources/shiboken6/tests/samplebinding/snakecase_test.py +++ b/sources/shiboken6/tests/samplebinding/snakecase_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for snake case generation''' diff --git a/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py index 200b0e4c0..cf0889299 100644 --- a/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py +++ b/sources/shiboken6/tests/samplebinding/static_nonstatic_methods_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for overloads involving static and non-static versions of a method.''' @@ -42,16 +15,20 @@ init_paths() from sample import SimpleFile + class SimpleFile2 (SimpleFile): def exists(self): return "Mooo" + class SimpleFile3 (SimpleFile): pass + class SimpleFile4 (SimpleFile): exists = 5 + class StaticNonStaticMethodsTest(unittest.TestCase): '''Test cases for overloads involving static and non-static versions of a method.''' @@ -106,9 +83,9 @@ class StaticNonStaticMethodsTest(unittest.TestCase): def testDuckPunchingStaticNonStaticMethod(self): f = SimpleFile(os.fspath(self.existing_filename)) - f.exists = lambda : "Meee" + f.exists = lambda: "Meee" self.assertEqual(f.exists(), "Meee") + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/stdcomplex_test.py b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py new file mode 100644 index 000000000..0caa9764d --- /dev/null +++ b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test cases for StdComplex class''' + +import os +import math +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() + +from sample import StdComplex + + +REAL = 5.0 +IMAG = 2.3 + + +class StdComplexTest(unittest.TestCase): + '''Test case for StdComplex class, exercising esoteric number + protocols (Py_nb_). For standard number protocols, see Point.''' + + def testConversion(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(int(pt), int(round(pt.abs_value()))) + self.assertEqual(float(pt), pt.abs_value()) + + def testAbs(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(abs(pt), pt.abs_value()) + + def testPow(self): + '''Compare pow() function to builtin Python type.''' + pt = StdComplex(REAL, IMAG) + result = pow(pt, StdComplex(2.0, 0)) + py_pt = complex(REAL, IMAG) + py_result = pow(py_pt, complex(2.0, 0)) + self.assertAlmostEqual(result.real(), py_result.real) + self.assertAlmostEqual(result.imag(), py_result.imag) + + def testFloor(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(math.floor(pt), math.floor(pt.abs_value())) + + def testCeil(self): + pt = StdComplex(REAL, IMAG) + self.assertEqual(math.ceil(pt), math.ceil(pt.abs_value())) + + def testPlusOperator(self): + '''Test StdComplex class + operator.''' + pt1 = StdComplex(REAL, IMAG) + pt2 = StdComplex(0.5, 3.2) + self.assertEqual(pt1 + pt2, StdComplex(REAL + 0.5, IMAG + 3.2)) + + def testEqualOperator(self): + '''Test StdComplex class == operator.''' + pt1 = StdComplex(REAL, IMAG) + pt2 = StdComplex(REAL, IMAG) + pt3 = StdComplex(0.5, 3.2) + self.assertTrue(pt1 == pt1) + self.assertTrue(pt1 == pt2) + self.assertFalse(pt1 == pt3) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/str_test.py b/sources/shiboken6/tests/samplebinding/str_test.py index a2c092bb8..c06fd6428 100644 --- a/sources/shiboken6/tests/samplebinding/str_test.py +++ b/sources/shiboken6/tests/samplebinding/str_test.py @@ -1,35 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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$ -## -############################################################################# - -'''Test cases for a method that receives a reference to class that is implicitly convertible from a Python native type.''' +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +'''Test cases for a method that receives a reference to class that is implicitly + convertible from a Python native type.''' import os import sys @@ -42,6 +16,7 @@ init_paths() from sample import Str + class StrTest(unittest.TestCase): '''Test cases for thr Str class.''' @@ -58,39 +33,39 @@ class StrTest(unittest.TestCase): self.assertEqual(str(s1), 'This is Sparta!') def testPassPythonTypeImplictlyConvertibleToAClassUsedAsReference(self): - '''Test passing a Python class implicitly convertible to a wrapped class that is expected to be passed as reference.''' + '''Test passing a Python class implicitly convertible to a wrapped class + that is expected to be passed as reference.''' s1 = Str('This is %VAR!').arg('Athens') self.assertEqual(str(s1), 'This is Athens!') def testSequenceOperators(self): s1 = Str("abcdef") - self.assertEqual(len(s1), 6); - self.assertEqual(len(Str()), 0); + self.assertEqual(len(s1), 6) + self.assertEqual(len(Str()), 0) # getitem - self.assertEqual(s1[0], "a"); - self.assertEqual(s1[1], "b"); - self.assertEqual(s1[2], "c"); - self.assertEqual(s1[3], "d"); - self.assertEqual(s1[4], "e"); - self.assertEqual(s1[5], "f"); - self.assertEqual(s1[-1], "f"); - self.assertEqual(s1[-2], "e"); + self.assertEqual(s1[0], "a") + self.assertEqual(s1[1], "b") + self.assertEqual(s1[2], "c") + self.assertEqual(s1[3], "d") + self.assertEqual(s1[4], "e") + self.assertEqual(s1[5], "f") + self.assertEqual(s1[-1], "f") + self.assertEqual(s1[-2], "e") self.assertRaises(TypeError, s1.__getitem__, 6) # setitem s1[0] = 'A' s1[1] = 'B' - self.assertEqual(s1[0], 'A'); - self.assertEqual(s1[1], 'B'); + self.assertEqual(s1[0], 'A') + self.assertEqual(s1[1], 'B') self.assertRaises(TypeError, s1.__setitem__(6, 67)) def testReverseOperator(self): s1 = Str("hello") - n1 = 2 - self.assertEqual(s1+2, "hello2") - self.assertEqual(2+s1, "2hello") + self.assertEqual(s1 + 2, "hello2") + self.assertEqual(2 + s1, "2hello") def testToIntError(self): self.assertEqual(Str('Z').toInt(), (0, False)) @@ -117,6 +92,6 @@ class StrTest(unittest.TestCase): self.assertEqual(val, int(str(hexa), 16)) self.assertEqual(hexa.toInt(), (0, False)) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/strlist_test.py b/sources/shiboken6/tests/samplebinding/strlist_test.py index c3eb02b8e..2bfb80b67 100644 --- a/sources/shiboken6/tests/samplebinding/strlist_test.py +++ b/sources/shiboken6/tests/samplebinding/strlist_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for StrList class that inherits from std::list<Str>.''' @@ -42,6 +15,7 @@ init_paths() from sample import Str, StrList + class StrListTest(unittest.TestCase): '''Test cases for StrList class that inherits from std::list<Str>.''' @@ -115,5 +89,6 @@ class StrListTest(unittest.TestCase): self.assertEqual(len(sl), 2) self.assertEqual(sl, (Str('Foo'), 'Bar')) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py b/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py index f0bb1f762..11279c7ec 100644 --- a/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py +++ b/sources/shiboken6/tests/samplebinding/templateinheritingclass_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -41,7 +14,8 @@ init_paths() from sample import Photon '''This tests classes that inherit from template classes, -simulating a situation found in Qt's phonon module.''' + simulating a situation found in Qt's phonon module.''' + class TemplateInheritingClassTest(unittest.TestCase): def testClassBasics(self): @@ -84,5 +58,6 @@ class TemplateInheritingClassTest(unittest.TestCase): self.assertEqual(obj2, obj2.passPointerThrough(obj2)) self.assertRaises(TypeError, obj1.passPointerThrough, obj2) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/time_test.py b/sources/shiboken6/tests/samplebinding/time_test.py index 5552457ab..6283a6744 100644 --- a/sources/shiboken6/tests/samplebinding/time_test.py +++ b/sources/shiboken6/tests/samplebinding/time_test.py @@ -1,37 +1,9 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for constructor and method signature decisor on Time class.''' -import sys import os import sys import unittest @@ -44,6 +16,7 @@ import datetime from sample import Time, ImplicitConv, ObjectType + class TimeTest(unittest.TestCase): '''Test cases for constructor and method signature decisor on Time class. The constructor and one method have these signatures: CTORMETHOD() and @@ -131,6 +104,7 @@ class TimeTest(unittest.TestCase): result = time.somethingCompletelyDifferent(1, 2, ImplicitConv.CtorOne) self.assertEqual(result, Time.ThreeArgs) + # PYSIDE-1436: These tests crash at shutdown due to `assert(Not)?Equal`. def testCompareWithPythonTime(self): time = Time(12, 32, 5) py = datetime.time(12, 32, 5) @@ -141,6 +115,6 @@ class TimeTest(unittest.TestCase): py = datetime.time(12, 32, 5) self.assertNotEqual(time, py) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/transform_test.py b/sources/shiboken6/tests/samplebinding/transform_test.py index 5d55d9d77..7dfd18a4a 100644 --- a/sources/shiboken6/tests/samplebinding/transform_test.py +++ b/sources/shiboken6/tests/samplebinding/transform_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for argument modification with more than nine arguments.''' @@ -42,6 +15,7 @@ init_paths() from sample import Point, applyHomogeneousTransform + class TransformTest(unittest.TestCase): '''Test cases for modifying a function with > 9 arguments.''' @@ -59,5 +33,6 @@ class TransformTest(unittest.TestCase): r = applyHomogeneousTransform(p, 1, 0, 0, 0, 1, 0, 0, 0, 0) self.assertTrue(r is None) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typeconverters_test.py b/sources/shiboken6/tests/samplebinding/typeconverters_test.py index 141da0860..987ba6dfd 100644 --- a/sources/shiboken6/tests/samplebinding/typeconverters_test.py +++ b/sources/shiboken6/tests/samplebinding/typeconverters_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Tests various usages of the type converters.''' @@ -42,6 +15,7 @@ init_paths() import sample + class GetPythonTypeByNameTest(unittest.TestCase): '''Uses an added function with inject code that uses the libshiboken @@ -186,12 +160,31 @@ class StringBasedConversionTest(unittest.TestCase): self.assertTrue(len(result), 1) self.assertTrue(lst, result[0]) + +class PrimitiveConversionTest(unittest.TestCase): + def testCppPrimitiveType(self): integers = (12, 34) result = sample.convertIntegersToCppAndThenToPython(integers[0], integers[1]) for orig, new in zip(integers, result): self.assertEqual(orig, new) + def testLargeIntAsFloat(self): + """PYSIDE-2417: When passing an int to a function taking float, + a 64bit conversion should be done.""" + point = sample.PointF(1, 2) + large_int = 2**31 + 2 + point.setX(large_int) + self.assertEqual(round(point.x()), large_int) + + def testUnsignedLongLongAsFloat(self): + """PYSIDE-2652: When passing an unsigned long long to a function taking float, + an unsigned 64bit conversion should be done.""" + point = sample.PointF(1, 2) + large_int = 2**63 + point.setX(large_int) + self.assertEqual(round(point.x()), large_int) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typedealloc_test.py b/sources/shiboken6/tests/samplebinding/typedealloc_test.py index 32a15e300..ce881e802 100644 --- a/sources/shiboken6/tests/samplebinding/typedealloc_test.py +++ b/sources/shiboken6/tests/samplebinding/typedealloc_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test deallocation of type extended in Python.''' @@ -52,18 +25,24 @@ class TypeDeallocTest(unittest.TestCase): def tearDown(self): del self.called + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def callback(self, *args): self.called = True def testScopeEnd(self): ref = None + def scope(): + class Ext(Point): pass - o = Ext() + + o = Ext() # noqa: F841 global ref ref = weakref.ref(Ext, self.callback) + scope() gc.collect() self.assertTrue(self.called) @@ -71,7 +50,7 @@ class TypeDeallocTest(unittest.TestCase): def testDeleteType(self): class Ext(Point): pass - ref = weakref.ref(Ext, self.callback) + ref = weakref.ref(Ext, self.callback) # noqa: F841 del Ext gc.collect() self.assertTrue(self.called) @@ -79,4 +58,3 @@ class TypeDeallocTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py b/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py index 983633a7f..ab8e535b5 100644 --- a/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py +++ b/sources/shiboken6/tests/samplebinding/typedtordoublefree_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -39,6 +12,7 @@ from shiboken_paths import init_paths init_paths() from sample import ObjectType + class TestTypeDestructorDoubleFree(unittest.TestCase): def testTypeDestructorDoubleFree(self): '''Causes the type destructors of two derived classes to be called.''' @@ -49,13 +23,16 @@ class TestTypeDestructorDoubleFree(unittest.TestCase): obj = ExtObj1() child = ObjectType(parent=obj) self.assertEqual(obj.takeChild(child), child) + class ExtObj2(ObjectType): def __init__(self): ObjectType.__init__(self) + obj = ExtObj2() child = ObjectType(parent=obj) self.assertEqual(obj.takeChild(child), child) scope() + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml index e479256b7..e315e599e 100644 --- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml @@ -1,34 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="sample"> - <suppress-warning text="Duplicate type entry: 'sample'" /> - <suppress-warning text="Duplicate type entry: 'SampleNamespace'" /> - - <custom-type name="str"/> - <custom-type name="PyBytes"/> - <custom-type name="PyDate"/> - <custom-type name="PyObject"/> - <custom-type name="PyUnicode"/> - - <primitive-type name="bool"/> - <primitive-type name="double"/> - <primitive-type name="real"/> - <primitive-type name="int"/> - <primitive-type name="short"/> - <primitive-type name="unsigned short"/> - <primitive-type name="ushort"/> - <primitive-type name="unsigned int" /> - <primitive-type name="signed int" /> - <primitive-type name="char"/> - <primitive-type name="unsigned char"/> - <primitive-type name="long"/> - <primitive-type name="unsigned long"/> - <primitive-type name="long long"/> - <primitive-type name="unsigned long long"/> - <primitive-type name="std::string"/> - <primitive-type name="std::string_view" view-on="std::string"/> <primitive-type name="ObjectType::Identifier"/> + <primitive-type name="std::nullptr_t"/> - <primitive-type name="Foo::HANDLE" target-lang-api-name="PyLong"/> + <primitive-type name="Foo::SAMPLE_HANDLE" target-lang-api-name="PyLong"/> <primitive-type name="std::size_t" target-lang-api-name="PyLong"> <conversion-rule> @@ -48,10 +23,10 @@ if (!PySequence_Check(pyIn) || !(PySequence_Size(pyIn) == 2)) return false; Shiboken::AutoDecRef pyReal(PySequence_GetItem(pyIn, 0)); - if (!SbkNumber_Check(pyReal)) + if (!PyNumber_Check(pyReal)) return false; Shiboken::AutoDecRef pyImag(PySequence_GetItem(pyIn, 1)); - if (!SbkNumber_Check(pyImag)) + if (!PyNumber_Check(pyImag)) return false; return true; } @@ -96,7 +71,7 @@ </conversion-rule> </primitive-type> - <primitive-type name="HANDLE" target-lang-api-name="PyComplex"> + <primitive-type name="SAMPLE_HANDLE" target-lang-api-name="PyComplex"> <include file-name="handle.h" location="local"/> <conversion-rule> <native-to-target> @@ -106,6 +81,7 @@ </native-to-target> <target-to-native> <add-conversion type="PyNone"> + SBK_UNUSED(%in) %out = 0; </add-conversion> <add-conversion check="checkPyCapsuleOrPyCObject(%in)" type="PyObject"> @@ -132,7 +108,7 @@ <target-to-native> <add-conversion check="checkPyCapsuleOrPyCObject(%in)" type="PyObject"> void *ptr = PyCapsule_GetPointer(%in, nullptr); - %out = *((%OUTTYPE*)ptr); + %out = *reinterpret_cast<%OUTTYPE*>(ptr); </add-conversion> </target-to-native> </conversion-rule> @@ -174,6 +150,9 @@ <add-function signature="operator==(const ComparisonTester&)" return-type="bool"/> <add-function signature="operator!=(const ComparisonTester&)" return-type="bool"/> </value-type> + <value-type name="SpaceshipComparisonTester"> + <enum-type name="Enabled"/> + </value-type> <primitive-type name="PStr"> <include file-name="str.h" location="global"/> @@ -187,6 +166,7 @@ %out = %OUTTYPE(str); </add-conversion> <add-conversion type="Py_None"> + SBK_UNUSED(%in) %out = %OUTTYPE(); </add-conversion> </target-to-native> @@ -275,6 +255,7 @@ <add-function signature="getPythonType(const char*)" return-type="PyObject"> <inject-code class="target" position="beginning"> + SBK_UNUSED(self) %PYARG_0 = (PyObject*) Shiboken::Conversions::getPythonTypeObject(%1); if (!%PYARG_0) %PYARG_0 = Py_None; @@ -370,24 +351,7 @@ </inject-code> </add-function> - <container-type name="std::pair" type="pair"> - <include file-name="utility" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyTuple_New(2); - PyTuple_SET_ITEM(%out, 0, %CONVERTTOPYTHON[%INTYPE_0](%in.first)); - PyTuple_SET_ITEM(%out, 1, %CONVERTTOPYTHON[%INTYPE_1](%in.second)); - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - %out.first = %CONVERTTOCPP[%OUTTYPE_0](PySequence_Fast_GET_ITEM(%in, 0)); - %out.second = %CONVERTTOCPP[%OUTTYPE_1](PySequence_Fast_GET_ITEM(%in, 1)); - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - <template name="cpplist_to_pylist_convertion"> + <template name="cpp_indexed_list_to_pylist_conversion"> PyObject *%out = PyList_New(Py_ssize_t(%in.size())); Py_ssize_t idx = 0; for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it, ++idx) { @@ -396,70 +360,19 @@ } return %out; </template> - <template name="pyseq_to_cpplist_convertion"> - Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - const Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); - for (Py_ssize_t i = 0; i < size; ++i) { - PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); - %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out.push_back(cppItem); - } - </template> - <container-type name="std::list" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> <container-type name="List" type="list"> <include file-name="list" location="global"/> <conversion-rule> <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> + <insert-template name="cpp_indexed_list_to_pylist_conversion"/> </native-to-target> <target-to-native> <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> + <insert-template name="shiboken_conversion_pyiterable_to_cppsequentialcontainer"/> </add-conversion> </target-to-native> </conversion-rule> </container-type> - <container-type name="std::map" type="map"> - <include file-name="map" location="global"/> - <conversion-rule> - <native-to-target> - PyObject* %out = PyDict_New(); - for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it) { - %INTYPE_0 key = it->first; - %INTYPE_1 value = it->second; - PyDict_SetItem(%out, - %CONVERTTOPYTHON[%INTYPE_0](key), - %CONVERTTOPYTHON[%INTYPE_1](value)); - } - return %out; - </native-to-target> - <target-to-native> - <add-conversion type="PyDict"> - PyObject* key; - PyObject* value; - Py_ssize_t pos = 0; - while (PyDict_Next(%in, &pos, &key, &value)) { - %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key); - %OUTTYPE_1 cppValue = %CONVERTTOCPP[%OUTTYPE_1](value); - %out.insert({cppKey, cppValue}); - } - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - <add-function signature="cacheSize()" return-type="int"> <inject-code class="target"> %RETURN_TYPE %0 = Shiboken::BindingManager::instance().getAllPyObjects().size(); @@ -484,6 +397,7 @@ <function signature="returnNullValueTypePointer()" /> <function signature="returnNullObjectTypePointer()" /> <function signature="acceptInt(int)" /> + <function signature="acceptIntReturnPtr(int)"/> <function signature="acceptUInt(unsigned int)" /> <function signature="acceptLong(long)" /> <function signature="acceptULong(unsigned long)" /> @@ -502,6 +416,11 @@ <function signature="returnCString()" /> <function signature="overloadedFunc(double)" /> <function signature="overloadedFunc(int)" /> + <function signature="addStdStrings(const std::string&, const std::string&)"/> + <function signature="addStdWStrings(const std::wstring&, const std::wstring&)"/> + <function signature="testNullPtrT(std::nullptr_t)"/> + <function signature="takePolygon(Polygon&&)"/> + <function signature="takeObjectType(ObjectType&&)"/> <value-type name="ArrayModifyTest"> <modify-function signature="sumIntArray(int, int*)"> @@ -510,7 +429,7 @@ </value-type> <value-type name="ClassWithFunctionPointer"> - <suppress-warning text="skipping function 'ClassWithFunctionPointer::callFunctionPointer', unmatched parameter type 'void (*)(void*)'" /> + <suppress-warning text="^skipping public function 'void ClassWithFunctionPointer::callFunctionPointer.*$" /> </value-type> <value-type name="IntArray" generate="no"/> @@ -538,6 +457,10 @@ <enum-type identified-by-value="AnonymousGlobalEnum_Value0"/> <namespace-type name="SampleNamespace"> + <namespace-type name="InlineNamespace"> + <value-type name="ClassWithinInlineNamespace"/> + <enum-type name="EnumWithinInlineNamespace"/> + </namespace-type> <enum-type name="Option"/> <enum-type name="InValue"/> <enum-type name="OutValue"/> @@ -562,8 +485,12 @@ <modify-function signature="doSomethingWithArray(const unsigned char*, unsigned int, const char*)"> <modify-argument index="1"> <replace-type modified-type="const char*"/> - <conversion-rule class="native"> - const unsigned char* %out = reinterpret_cast<const unsigned char*>(Shiboken::String::toCString(%PYARG_1)); + <conversion-rule> + <target-to-native> + <add-conversion> + const unsigned char* %out = reinterpret_cast<const unsigned char*>(Shiboken::String::toCString(%PYARG_1)); + </add-conversion> + </target-to-native> </conversion-rule> </modify-argument> <modify-argument index="2"> @@ -644,6 +571,14 @@ <modify-function signature="hideFunction(HideType*)" remove="all"/> <modify-field name="toBeRenamedField" rename="renamedField"/> <modify-field name="readOnlyField" write="false"/> + <modify-function signature="virtualWithOutParameter(int&)const"> + <inject-code class="shell" position="override"> + x = virtualWithOutParameterPyOverride(gil, pyOverride.object()); + return; + </inject-code> + </modify-function> + <add-function signature="virtualWithOutParameterPyOverride()" + return-type="int" python-override="true"/> </object-type> <object-type name="Derived" polymorphic-id-expression="%1->type() == Derived::TpDerived"> @@ -665,7 +600,7 @@ </modify-function> </object-type> - <object-type name="ObjectType" hash-function="objectTypeHash"> + <object-type name="ObjectType" hash-function="objectTypeHash" parent-management="yes"> <modify-function signature="deprecatedFunction()" deprecated="yes" /> <!-- rename function to avoid Python signature conflit --> <modify-function signature="setObject(const Null&)" rename="setNullObject" /> @@ -706,8 +641,8 @@ // CHECKTYPE and ISCONVERTIBLE are used here for test purposes, don't change them. if (!%CHECKTYPE[ObjectTypeLayout*](layout) && !%ISCONVERTIBLE[ObjectTypeLayout*](layout)) return; - // %CHECKTYPE[ObjectTypeLayout*](layout) - // %ISCONVERTIBLE[ObjectTypeLayout*](layout) + /* %CHECKTYPE[ObjectTypeLayout*](layout) */ + /* %ISCONVERTIBLE[ObjectTypeLayout*](layout) */ ObjectTypeLayout* var; var = %CONVERTTOCPP[ObjectTypeLayout*](layout); // TODO-CONVERTER: erase this @@ -794,7 +729,7 @@ </modify-function> </object-type> - <value-type name="ObjectTypeHolder"/> + <object-type name="ObjectTypeHolder"/> <value-type name="OnlyCopy"/> <value-type name="FriendOfOnlyCopy"/> @@ -1187,14 +1122,14 @@ <modify-argument index="1"> <remove-argument/> <conversion-rule class="native"> - int %out = PySequence_Size(%PYARG_1); + const auto %out = PySequence_Size(%PYARG_1); </conversion-rule> </modify-argument> <modify-argument index="2"> <replace-type modified-type="PySequence" /> <conversion-rule class="native"> Shiboken::AutoArrayPointer<Point> %out(%1); - for (int i = 0; i < %1; ++i) + for (Py_ssize_t i = 0; i < %1; ++i) %out[i] = %CONVERTTOCPP[Point](PySequence_Fast_GET_ITEM(%PYARG_1, i)); </conversion-rule> </modify-argument> @@ -1237,14 +1172,18 @@ </modify-argument> <modify-argument index="return"> <replace-type modified-type="PySequence"/> - <conversion-rule class="native"> - Shiboken::AutoDecRef _py_ok_(PySequence_GetItem(%PYARG_0, 0)); - Shiboken::AutoDecRef _py_ret_(PySequence_GetItem(%PYARG_0, 1)); - *%2 = %CONVERTTOCPP[bool](_py_ok_); - %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](_py_ret_); - </conversion-rule> - <conversion-rule class="target"> - <insert-template name="differenceOfPointCoordinates_returnTarget"/> + <conversion-rule> + <target-to-native> + <add-conversion> + Shiboken::AutoDecRef _py_ok_(PySequence_GetItem(%PYARG_0, 0)); + Shiboken::AutoDecRef _py_ret_(PySequence_GetItem(%PYARG_0, 1)); + *%2 = %CONVERTTOCPP[bool](_py_ok_); + %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](_py_ret_); + </add-conversion> + </target-to-native> + <native-to-target> + <insert-template name="differenceOfPointCoordinates_returnTarget"/> + </native-to-target> </conversion-rule> </modify-argument> </modify-function> @@ -1374,7 +1313,7 @@ <replace-default-expression with="3000"/> </modify-argument> <inject-code class="native" position="beginning"> - PyObject* new_arg0 = PyInt_FromLong(PyInt_AS_LONG(%PYARG_1) - %2); + PyObject* new_arg0 = PyLong_FromLong(PyLong_AS_LONG(%PYARG_1) - %2); Py_DECREF(%PYARG_1); %PYARG_1 = new_arg0; </inject-code> @@ -1445,13 +1384,13 @@ PyTuple_SET_ITEM(%PYARG_0, 3, %CONVERTTOPYTHON[int](a3)); </template> <template name="fix_native_return_int*,int*,int*,int*"> - PyObject* _obj = %PYARG_0.object(); + PyObject* _obj = %PYARG_0; if (!PySequence_Check(_obj) || PySequence_Fast_GET_SIZE(_obj) != 4 - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 0)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 1)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 2)) - || !SbkNumber_Check(PySequence_Fast_GET_ITEM(_obj, 3))) { + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 0)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 1)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 2)) + || !PyNumber_Check(PySequence_Fast_GET_ITEM(_obj, 3))) { PyErr_SetString(PyExc_TypeError, "Sequence of 4 numbers expected"); } else { *%1 = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(_obj, 0)); @@ -1461,7 +1400,7 @@ } </template> <modify-function signature="getMargins(int*,int*,int*,int*)const"> - <modify-argument index="0"> + <modify-argument index="return" pyi-type="Tuple[int, int, int, int]"> <replace-type modified-type="PyObject" /> </modify-argument> <modify-argument index="1"> @@ -1638,15 +1577,15 @@ <modify-argument index="1"> <remove-argument/> <conversion-rule class="native"> - int %out = PySequence_Size(%PYARG_1); + const auto %out = PySequence_Size(%PYARG_1); </conversion-rule> </modify-argument> <modify-argument index="2"> <replace-type modified-type="PySequence"/> <conversion-rule class="native"> - int numItems = PySequence_Size(%PYARG_1); + const auto numItems = PySequence_Size(%PYARG_1); Shiboken::AutoArrayPointer<int> %out(numItems); - for (int i = 0; i < numItems; ++i) { + for (Py_ssize_t i = 0; i < numItems; ++i) { if (%CHECKTYPE[int](PySequence_Fast_GET_ITEM(%PYARG_1, i))) %out[i] = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(%PYARG_1, i)); else if (%ISCONVERTIBLE[int](PySequence_Fast_GET_ITEM(%PYARG_1, i))) @@ -1938,6 +1877,7 @@ %PYARG_0 = Py_False; else %PYARG_0 = Py_True; + Py_INCREF(%PYARG_0); } </inject-code> </add-function> @@ -1955,19 +1895,20 @@ %PYARG_0 = Py_True; else %PYARG_0 = Py_False; + Py_INCREF(%PYARG_0); } </inject-code> </add-function> </value-type> <value-type name="Size"> + <extra-includes> + <include file-name="string" location="global"/> + <include file-name="sstream" location="global"/> + </extra-includes> <add-function signature="Size(const char*)"> - <inject-code class="target" position="beginning"> - %0 = new %TYPE(); - </inject-code> - <inject-code class="target" position="end"> - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, const_cast<char*>("setHeight"), const_cast<char*>("i"), 2)); - </inject-code> + <inject-code class="target" position="beginning" + file="samplesnippets.cpp" snippet="size_char_ct"/> </add-function> </value-type> <value-type name="SizeF"/> @@ -2018,6 +1959,9 @@ } } } + // PySIDE-1735: Enums are now implemented in Python, so we need to avoid asserts. + if (PyErr_Occurred()) + break; const char** %out = 0; </conversion-rule> </modify-argument> @@ -2066,7 +2010,12 @@ <object-type name="Collector" stream="yes"/> - <value-type name="IntWrapper" /> + <value-type name="IntWrapper"> + <inject-code class="native" position="beginning" + file="samplesnippets.cpp" snippet="intwrapper_add_ints"/> + <add-pymethoddef name="add_ints" function="Sbk_IntWrapper_add_ints" + flags="METH_VARARGS"/> + </value-type> <value-type name="Str" hash-function="strHash"> <add-function signature="__str__" return-type="PyObject*"> @@ -2124,6 +2073,7 @@ <conversion-rule> <target-to-native> <add-conversion type="Py_None"> + SBK_UNUSED(%in) %out = %OUTTYPE(); </add-conversion> <add-conversion type="PyObject" check="Shiboken::String::check(%in) || PyBytes_Check(%in)"> @@ -2275,19 +2225,20 @@ </add-function> </value-type> - <value-type name="SimpleFile"> + <object-type name="SimpleFile"> <modify-function signature="open()"> <modify-argument index="return"> <remove-argument/> </modify-argument> <inject-code class="target" position="end" file="simplefile_glue.cpp"/> </modify-function> - </value-type> + </object-type> <value-type name="VoidHolder" /> <object-type name="PrivateCtor" /> <object-type name="PrivateDtor" /> + <value-type name="DeletedDefaultCtor"/> <object-type name="Base1"/> <object-type name="Base2"/> @@ -2340,7 +2291,7 @@ <conversion-rule class="native"> // Does nothing really, just test the code generation // of constructors whose arguments where - long %out = PyInt_AS_LONG(%PYARG_1) + 1; + long %out = PyLong_AS_LONG(%PYARG_1) + 1; </conversion-rule> </modify-argument> </modify-function> @@ -2428,15 +2379,24 @@ <value-type name="Expression" /> - <object-type name="ExceptionTest" exception-handling="auto-on"/> - - <value-type name="ModelIndex" /> - <value-type name="ReferentModelIndex"> - <modify-function signature="operator const ModelIndex&()const"> + <object-type name="ExceptionTest" exception-handling="auto-on"> + <modify-function signature="create(bool)"> <modify-argument index="return"> <define-ownership owner="c++"/> </modify-argument> + <inject-code class="target" position="end"> + // Test comment + </inject-code> </modify-function> + </object-type> + + <value-type name="ModelIndex" /> + <value-type name="ReferentModelIndex"> + <modify-function signature="operator const ModelIndex&()const"> + <modify-argument index="return"> + <define-ownership owner="c++"/> + </modify-argument> + </modify-function> </value-type> <value-type name="PersistentModelIndex" /> @@ -2449,6 +2409,31 @@ <object-type name="ObjectTypeByValue" /> + <value-type name="StdComplex"> + <extra-includes> + <include file-name="cmath" location="global"/> + </extra-includes> + <!-- PYSIDE-2446: number protocols without a Py_nb_ constant. --> + <add-function signature="__floor__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_floor"/> + </add-function> + <add-function signature="__ceil__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_ceil"/> + </add-function> + <!-- PYSIDE-2446: number protocols with Py_nb_ constants. --> + <add-function signature="__abs__()" return-type="double"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_abs"/> + </add-function> + <add-function signature="__pow__(StdComplex@exp@)" return-type="StdComplex"> + <inject-code class="target" position="end" + file="samplesnippets.cpp" snippet="stdcomplex_pow"/> + </add-function> + + </value-type> + <object-type name="TemplatePtr"> <modify-function signature="dummy(std::list<std::pair<BlackBox *, BlackBox *> > &)" rename="dummy_method" /> </object-type> @@ -2464,20 +2449,9 @@ <suppress-warning text="horribly broken type '__off64_t'" /> <suppress-warning text="enum '__codecvt_result' does not have a type entry or is not an enum" /> - <suppress-warning text="Pure virtual method "Abstract::hideFunction(HideType*)" must be implement but was completely removed on typesystem." /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectType'" /> + <suppress-warning text="Pure virtual method 'Abstract::hideFunction(HideType*)' must be implemented but was completely removed on type system." /> <suppress-warning text="Shadowing: MDerived2::castToBase3() and MDerived3::castToBase3()" /> - <suppress-warning text="hiding of function 'takeChild' in class 'Bucket'" /> - <suppress-warning text="visibility of function 'publicMethod' modified in class 'MDerived1'" /> - <suppress-warning text="hiding of function 'doNothingInPublic3' in class 'Overload2'" /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectModel'" /> - <suppress-warning text="hiding of function 'takeChild' in class 'ObjectView'" /> - <suppress-warning text="visibility of function 'publicMethod' modified in class 'MDerived3'" /> - <suppress-warning text="skipping function 'InjectCode::toStr', unmatched parameter type 'T const&'" /> - - <suppress-warning text="^skipping function 'std::enable_if.*ComparisonTester::operator[!=]=.*ComparisonTester.*$"/> - - <!-- Do not fix this warning, the generator should be able to handle this situation for Object Types. --> - <suppress-warning text="Argument in position 1 of added function 'SampleNamespace::passReferenceToObjectType(ObjectType * arg__1)', has a type that is not a reference, while the argument in the corresponding position in C++ function 'SampleNamespace::passReferenceToObjectType(const ObjectType & obj, int multiplier)' is a reference." /> + <suppress-warning text="Visibility of function 'publicMethod' modified in class 'MDerived1'" /> + <suppress-warning text="^skipping public function 'std::enable_if.*ComparisonTester::operator[!=]=.*ComparisonTester.*$"/> </typesystem> diff --git a/sources/shiboken6/tests/samplebinding/typesystypedef_test.py b/sources/shiboken6/tests/samplebinding/typesystypedef_test.py index 70c22f657..f7f5342ee 100644 --- a/sources/shiboken6/tests/samplebinding/typesystypedef_test.py +++ b/sources/shiboken6/tests/samplebinding/typesystypedef_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a class that holds a void pointer.''' @@ -40,8 +13,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import (ValueWithUnitUser, ValueWithUnitDoubleInch, - ValueWithUnitDoubleMillimeter) +from sample import ValueWithUnitUser, ValueWithUnitDoubleInch class TypeSysTypeDefTest(unittest.TestCase): diff --git a/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py b/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py index ab9895f1f..2a7e5cac7 100644 --- a/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py +++ b/sources/shiboken6/tests/samplebinding/unsafe_parent_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for ...''' @@ -42,6 +15,7 @@ init_paths() from sample import ObjectType + class DerivedObjectType(ObjectType): def isPython(self): return True @@ -49,12 +23,13 @@ class DerivedObjectType(ObjectType): def createChild(self, parent): return DerivedObjectType(parent) + class ParentTest(unittest.TestCase): def testUunsafeParent(self): o = DerivedObjectType() o.callVirtualCreateChild() + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py index 910037cd5..45d4095b6 100644 --- a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py +++ b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for user added constructors''' @@ -39,14 +12,15 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Size + class PointTest(unittest.TestCase): def testUsingSelfOnCtor(self): # This is a user added ctor and no errors should happen! - s = Size("oi") + s = Size("3x2") self.assertEqual(s.height(), 2) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py index 8f29eca3c..6be870269 100644 --- a/sources/shiboken6/tests/samplebinding/virtualdtor_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualdtor_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual destructor.''' +import gc import os import sys import unittest @@ -42,10 +16,12 @@ init_paths() from sample import VirtualDtor + class ExtendedVirtualDtor(VirtualDtor): def __init__(self): VirtualDtor.__init__(self) + class VirtualDtorTest(unittest.TestCase): '''Test case for virtual destructor.''' @@ -58,6 +34,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testVirtualDtorOnCppCreatedObject(self): @@ -66,6 +44,8 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): vd = VirtualDtor.create() del vd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(VirtualDtor.dtorCalled(), dtor_called + i) def testDtorOnDerivedClass(self): @@ -74,9 +54,10 @@ class VirtualDtorTest(unittest.TestCase): for i in range(1, 10): evd = ExtendedVirtualDtor() del evd + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(ExtendedVirtualDtor.dtorCalled(), dtor_called + i) if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py index 1c842993c..52dc66c90 100644 --- a/sources/shiboken6/tests/samplebinding/virtualmethods_test.py +++ b/sources/shiboken6/tests/samplebinding/virtualmethods_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test cases for virtual methods.''' +import gc import os import sys import unittest @@ -40,10 +14,11 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Point, Str, StrList, VirtualDaughter, VirtualMethods import warnings + class ExtendedVirtualMethods(VirtualMethods): def __init__(self): VirtualMethods.__init__(self) @@ -62,6 +37,7 @@ class ExtendedVirtualMethods(VirtualMethods): # check if recursion is caused by injected code that calls C++. return VirtualMethods.recursionOnModifiedVirtual(self, arg) + 10 + class ExtendedVirtualDaughter(VirtualDaughter): def __init__(self, name): VirtualDaughter.__init__(self, name) @@ -71,6 +47,7 @@ class ExtendedVirtualDaughter(VirtualDaughter): self.grand_daughter_name_called = True return VirtualDaughter.name(self).prepend('Extended') + class ExtendedExtendedVirtualDaughter(ExtendedVirtualDaughter): def __init__(self, name): ExtendedVirtualDaughter.__init__(self, name) @@ -80,6 +57,7 @@ class ExtendedExtendedVirtualDaughter(ExtendedVirtualDaughter): self.grand_grand_daughter_name_called = True return ExtendedVirtualDaughter.name(self).prepend('Extended') + class VirtualMethodsTest(unittest.TestCase): '''Test case for virtual methods''' @@ -88,9 +66,12 @@ class VirtualMethodsTest(unittest.TestCase): def tearDown(self): del self.prefix_from_codeinjection + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() def testReimplementedVirtualMethod0(self): - '''Test Python override of a virtual method with various different parameters is correctly called from C++.''' + '''Test Python override of a virtual method with various different parameters + is correctly called from C++.''' vm = VirtualMethods() evm = ExtendedVirtualMethods() pt = Point(1.1, 2.2) @@ -144,6 +125,6 @@ class PrettyErrorMessageTest(unittest.TestCase): obj = ExtendedVirtualMethods() self.assertRaises(RuntimeWarning, obj.callStrListToStdList, StrList()) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/visibilitychange_test.py b/sources/shiboken6/tests/samplebinding/visibilitychange_test.py index 918d957b2..becdf7423 100644 --- a/sources/shiboken6/tests/samplebinding/visibilitychange_test.py +++ b/sources/shiboken6/tests/samplebinding/visibilitychange_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -38,17 +11,17 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Base1, MDerived1 + class VisibilityChangeTest(unittest.TestCase): def testVisibilityChange(self): b1 = Base1() - b1.publicMethod() # ok... + b1.publicMethod() # ok... d1 = MDerived1() - self.assertRaises(TypeError, d1.publicMethod); + self.assertRaises(TypeError, d1.publicMethod) + if __name__ == '__main__': unittest.main() - - diff --git a/sources/shiboken6/tests/samplebinding/voidholder_test.py b/sources/shiboken6/tests/samplebinding/voidholder_test.py index da4042a98..186cb473e 100644 --- a/sources/shiboken6/tests/samplebinding/voidholder_test.py +++ b/sources/shiboken6/tests/samplebinding/voidholder_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test case for a class that holds a void pointer.''' @@ -43,6 +16,7 @@ init_paths() from sample import VoidHolder, Point from shiboken6 import Shiboken + class VoidHolderTest(unittest.TestCase): '''Test case for void pointer manipulation.''' @@ -71,6 +45,6 @@ class VoidHolderTest(unittest.TestCase): voidholder = VoidHolder() self.assertEqual(voidholder.voidPointer(), None) + if __name__ == '__main__': unittest.main() - diff --git a/sources/shiboken6/tests/samplebinding/weakref_test.py b/sources/shiboken6/tests/samplebinding/weakref_test.py index 6ca031c0d..01c6d58d5 100644 --- a/sources/shiboken6/tests/samplebinding/weakref_test.py +++ b/sources/shiboken6/tests/samplebinding/weakref_test.py @@ -1,36 +1,10 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 '''Test weakref support''' +import gc import os import sys import unittest @@ -56,15 +30,19 @@ class WeakrefBasicTest(unittest.TestCase): def testBasic(self): '''ObjectType weakref''' obj = ObjectType() - ref = weakref.ref(obj, self.cb) + ref = weakref.ref(obj, self.cb) # noqa: F841 del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) def testPrivateDtor(self): '''PrivateDtor weakref''' obj = PrivateDtor.instance() - ref = weakref.ref(obj, self.cb) + ref = weakref.ref(obj, self.cb) # noqa: F841 del obj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertTrue(self.called) diff --git a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py index b7668e497..dfc962db9 100644 --- a/sources/shiboken6/tests/samplebinding/writableclassdict_test.py +++ b/sources/shiboken6/tests/samplebinding/writableclassdict_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -40,7 +13,10 @@ init_paths() from sample import Point -class ExtPoint(Point): pass + +class ExtPoint(Point): + pass + class TestWritableClassDict(unittest.TestCase): def testSetattrOnClass(self): @@ -56,5 +32,6 @@ class TestWritableClassDict(unittest.TestCase): pt = ExtPoint() self.assertEqual(pt.bar, 321) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/shiboken_paths.py b/sources/shiboken6/tests/shiboken_paths.py index c829c0ab9..3ec940f2e 100644 --- a/sources/shiboken6/tests/shiboken_paths.py +++ b/sources/shiboken6/tests/shiboken_paths.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2020 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os diff --git a/sources/shiboken6/tests/shiboken_test_helper.py b/sources/shiboken6/tests/shiboken_test_helper.py index 793baf4ad..14fe6a2d1 100644 --- a/sources/shiboken6/tests/shiboken_test_helper.py +++ b/sources/shiboken6/tests/shiboken_test_helper.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2019 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 def objectFullname(t): diff --git a/sources/shiboken6/tests/shibokenmodule/module_test.py b/sources/shiboken6/tests/shibokenmodule/module_test.py index b3c28688d..9f9f8f5a4 100644 --- a/sources/shiboken6/tests/shibokenmodule/module_test.py +++ b/sources/shiboken6/tests/shibokenmodule/module_test.py @@ -1,30 +1,5 @@ -############################################################################# -## -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os import sys @@ -32,17 +7,19 @@ import unittest from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) -from shiboken_paths import init_paths +from shiboken_paths import init_paths # noqa: E402 init_paths() -from shiboken6 import Shiboken -from sample import * +from shiboken6 import Shiboken # noqa: E402 +from sample import BlackBox, ObjectType, ObjectModel, ObjectView, Point # noqa: E402 + class MultipleInherited (ObjectType, Point): def __init__(self): ObjectType.__init__(self) Point.__init__(self) + class TestShiboken(unittest.TestCase): def testIsValid(self): self.assertTrue(Shiboken.isValid(object())) @@ -68,6 +45,16 @@ class TestShiboken(unittest.TestCase): self.assertTrue(Shiboken.createdByPython(bb)) bb.disposeObjectType(bb.keepObjectType(obj)) + def testWrapInstancePreserveId(self): + """PYSIDE-31: Verify that wrapInstance() returns the existing wrapper + even if a base class type is specified.""" + v = ObjectView() # inherits ObjectType + addresses = Shiboken.getCppPointer(v) + self.assertTrue(addresses) + address = addresses[0] + wrapped = Shiboken.wrapInstance(address, ObjectType) + self.assertEqual(id(wrapped), id(v)) + def testIsOwnedByPython(self): obj = ObjectType() self.assertTrue(Shiboken.ownedByPython(obj)) @@ -80,7 +67,7 @@ class TestShiboken(unittest.TestCase): p = ObjectType() obj = ObjectType(p) obj2 = ObjectType(obj) - obj3 = ObjectType(obj) + obj3 = ObjectType(obj) # noqa: F841 self.assertEqual(Shiboken.dump(None), "Ordinary Python type.") Shiboken.dump(obj) @@ -94,9 +81,9 @@ class TestShiboken(unittest.TestCase): # Don't crash even after deleting an object Shiboken.invalidate(obj) - Shiboken.dump(obj) # deleted - Shiboken.dump(p) # child deleted - Shiboken.dump(obj2) # parent deleted + Shiboken.dump(obj) # deleted + Shiboken.dump(p) # child deleted + Shiboken.dump(obj2) # parent deleted def testDelete(self): obj = ObjectType() @@ -120,12 +107,6 @@ class TestShiboken(unittest.TestCase): Shiboken.delete(obj) self.assertFalse(obj in Shiboken.getAllValidWrappers()) - # PYSIDE-1514: Check if shiboken6.shiboken6 exists for versions < 6.2 - def testOldShibokenName(self): - if Shiboken.__version_info__[:2] < (6, 2): - import shiboken6.shiboken6 - else: - self.assertRaises(ImportError, __import__, "shiboken6.shiboken6") if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index 637420651..2e729321e 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + project(smart) set(smart_TYPESYSTEM @@ -13,18 +16,38 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/registry_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrtestbench_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrvirtualmethodtester_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_int_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_optional_int_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_optional_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_integer2_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_unique_ptr_int_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stdoptionaltestbench_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stduniqueptrtestbench_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stduniqueptrvirtualmethodtester_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/test_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in" "${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt" @ONLY) +shiboken_get_tool_shell_wrapper(shiboken tool_wrapper) + add_custom_command( -OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" -BYPRODUCTS ${smart_SRC} -COMMAND shiboken6 --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt ${GENERATOR_EXTRA_FLAGS} -DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h shiboken6 -WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -COMMENT "Running generator for 'smart' test binding..." + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mjb_rejected_classes.log" + BYPRODUCTS ${smart_SRC} + COMMAND + ${tool_wrapper} + $<TARGET_FILE:Shiboken6::shiboken6> + --project-file=${CMAKE_CURRENT_BINARY_DIR}/smart-binding.txt + ${GENERATOR_EXTRA_FLAGS} + DEPENDS ${smart_TYPESYSTEM} ${CMAKE_CURRENT_SOURCE_DIR}/global.h Shiboken6::shiboken6 + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Running generator for 'smart' test binding..." ) add_library(smart MODULE ${smart_SRC}) diff --git a/sources/shiboken6/tests/smartbinding/global.h b/sources/shiboken6/tests/smartbinding/global.h index 959859b40..5bec15063 100644 --- a/sources/shiboken6/tests/smartbinding/global.h +++ b/sources/shiboken6/tests/smartbinding/global.h @@ -1,29 +1,4 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "smart.h" diff --git a/sources/shiboken6/tests/smartbinding/smart-binding.txt.in b/sources/shiboken6/tests/smartbinding/smart-binding.txt.in index 699f0bfe6..a2c73c6bf 100644 --- a/sources/shiboken6/tests/smartbinding/smart-binding.txt.in +++ b/sources/shiboken6/tests/smartbinding/smart-binding.txt.in @@ -13,3 +13,4 @@ typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ enable-parent-ctor-heuristic use-isnull-as-nb_nonzero +lean-headers diff --git a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py index 1bdce333e..8d4272558 100644 --- a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py @@ -1,33 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -# -############################################################################# -## -## Copyright (C) 2017 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of Qt for Python. -## -## $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) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import gc import os @@ -39,32 +12,49 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() from copy import copy -from smart import Obj, Registry, Integer +from smart import (Obj, Registry, Integer, SharedPtr_Integer, std) + def objCount(): return Registry.getInstance().countObjects() + def integerCount(): return Registry.getInstance().countIntegers() + +def integerFromValue(v): + result = Integer() + result.setValue(v) + return result + + class SmartPointerTests(unittest.TestCase): - def testObjSmartPointer(self): - # Uncomment to see more debug info about creation of objects and ref counts. - # Registry.getInstance().setShouldPrint(True) + def setUp(self): + super().setUp() + if os.environ.get("VERBOSE"): + Registry.getInstance().setVerbose(True) + + def testObjSmartPointer(self): # Create Obj. o = Obj() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) # Create a shared pointer to an Obj together with an Obj. - ptrToObj = o.giveSharedPtrToObj() + ptrToObj = o.createSharedPtrObj() self.assertEqual(objCount(), 2) # Delete the old Obj. o = None + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) - # Get a wrapper to the Obj inside of the shared pointer, object count should not change. + # Get a wrapper to the Obj inside of the shared pointer, object count + # should not change. obj = ptrToObj.data() self.assertEqual(objCount(), 1) obj.m_integer = 50 @@ -74,12 +64,13 @@ class SmartPointerTests(unittest.TestCase): ptrToObj.m_integer = 100 self.assertEqual(ptrToObj.m_integer, 100) - # Get inner PyObject via shared pointer (like operator->) and set value in it. + # Get inner PyObject via shared pointer (like operator->) and set + # value in it. ptrToObj.m_internalInteger.m_int = 200 self.assertEqual(ptrToObj.m_internalInteger.m_int, 200) - # Pass smart pointer as argument to a method, return value is the value of m_integer of - # passed Obj inside the smart pointer. + # Pass smart pointer as argument to a method, return value is the value + # of m_integer of passed Obj inside the smart pointer. result = ptrToObj.takeSharedPtrToObj(ptrToObj) self.assertEqual(result, 100) @@ -89,38 +80,42 @@ class SmartPointerTests(unittest.TestCase): result = None if integerCount() > 1: gc.collect() - print('Running garbage collector for reference test', file=sys.stderr) + print('Running garbage collector for reference test', + file=sys.stderr) self.assertEqual(integerCount(), 1) # Make a copy of the shared pointer, object count should not change. ptrToObj2 = copy(ptrToObj) self.assertEqual(objCount(), 1) - # Delete the first shared pointer, object count should not change because the second - # one still has a reference. + # Delete the first shared pointer, object count should not change + # because the second one still has a reference. del ptrToObj + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) # Delete the second smart pointer, object should be deleted. del ptrToObj2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 0) self.assertEqual(integerCount(), 0) def testIntegerSmartPointer(self): - # Uncomment to see more debug info about creation of objects and ref counts. - # Registry.getInstance().setShouldPrint(True) - # Create Obj. o = Obj() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) # Create a shared pointer to an Integer together with an Integer. - ptrToInteger = o.giveSharedPtrToInteger() + ptrToInteger = o.createSharedPtrInteger() self.assertEqual(objCount(), 1) self.assertEqual(integerCount(), 2) - # Get a wrapper to the Integer inside of the shared pointer, integer count should not - # change. + # Get a wrapper to the Integer inside of the shared pointer, integer + # count should not change. integer = ptrToInteger.data() self.assertEqual(integerCount(), 2) integer.m_int = 50 @@ -134,8 +129,8 @@ class SmartPointerTests(unittest.TestCase): ptrToInteger.m_int = 100 self.assertEqual(ptrToInteger.m_int, 100) - # Pass smart pointer as argument to a method, return value is the value of m_int of - # passed Integer inside the smart pointer. + # Pass smart pointer as argument to a method, return value is the + # value of m_int of passed Integer inside the smart pointer. result = o.takeSharedPtrToInteger(ptrToInteger) self.assertEqual(result, 100) @@ -143,28 +138,31 @@ class SmartPointerTests(unittest.TestCase): ptrToInteger2 = copy(ptrToInteger) self.assertEqual(integerCount(), 2) - # Delete the first shared pointer, integer count should not change because the second - # one still has a reference. + # Delete the first shared pointer, integer count should not change + # because the second one still has a reference. del ptrToInteger + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(integerCount(), 2) # Delete the second smart pointer, integer should be deleted. del ptrToInteger2 + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) self.assertEqual(integerCount(), 1) # Delete the original object which was used to create the integer. del o + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 0) self.assertEqual(integerCount(), 0) def testConstIntegerSmartPointer(self): - # Uncomment to see more debug info about creation of objects and ref counts. - # Registry.getInstance().setShouldPrint(True) - # Create Obj. o = Obj() - ptrToConstInteger = o.giveSharedPtrToConstInteger() + ptrToConstInteger = o.createSharedPtrConstInteger() self.assertEqual(ptrToConstInteger.m_int, 456) result = o.takeSharedPtrToConstInteger(ptrToConstInteger) self.assertEqual(result, 456) @@ -173,10 +171,12 @@ class SmartPointerTests(unittest.TestCase): def testSmartPointersWithNamespace(self): # Create the main object o = Obj() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) # Create a shared pointer to an Integer together with an Integer. - ptrToInteger = o.giveSharedPtrToInteger2() + ptrToInteger = o.createSharedPtrInteger2() self.assertEqual(objCount(), 1) self.assertEqual(integerCount(), 2) @@ -188,17 +188,25 @@ class SmartPointerTests(unittest.TestCase): o = Obj() # Create a list of shared objects - ptrToObjList = o.giveSharedPtrToObjList(10) + ptrToObjList = o.createSharedPtrObjList(10) self.assertEqual(len(ptrToObjList), 10) + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 11) # Remove one from the list ptrToObjList.pop() self.assertEqual(len(ptrToObjList), 9) + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + # PYSIDE-535: Why do I need to do it twice, here? + gc.collect() self.assertEqual(objCount(), 10) # clear and delete all objects in the list del ptrToObjList[:] # Python 2.7 lists have no clear method + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(len(ptrToObjList), 0) self.assertEqual(objCount(), 1) @@ -206,7 +214,7 @@ class SmartPointerTests(unittest.TestCase): # Create Obj. o = Obj() # Create a shared pointer to an Obj together with an Obj. - ptrToObj = o.giveSharedPtrToObj() + ptrToObj = o.createSharedPtrObj() try: ptrToObj.typo self.assertFail() @@ -216,16 +224,79 @@ class SmartPointerTests(unittest.TestCase): def testSmartPointerConversions(self): # Create Obj. o = Obj() + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() self.assertEqual(objCount(), 1) self.assertEqual(integerCount(), 1) # Create a shared pointer to an Integer2 - integer2 = o.giveSharedPtrToInteger2() + integer2 = o.createSharedPtrInteger2() + # User defined name + self.assertEqual(type(integer2).__name__, "SmartInteger2Ptr") + self.assertTrue("smart.Test.SmartInteger2Ptr" in repr(type(integer2))) self.assertEqual(integer2.value(), 456) # pass Smart<Integer2> to a function that accepts Smart<Integer> r = o.takeSharedPtrToInteger(integer2) self.assertEqual(r, integer2.value()) + def testSmartPointerValueComparison(self): + """Test a pointee class with comparison operators.""" + four = Obj.createSharedPtrInteger(4) + four2 = Obj.createSharedPtrInteger(4) + five = Obj.createSharedPtrInteger(5) + self.assertTrue(four == four) + self.assertTrue(four == four2) + self.assertFalse(four != four) + self.assertFalse(four != four2) + self.assertFalse(four < four) + self.assertTrue(four <= four) + self.assertFalse(four > four) + self.assertTrue(four >= four) + self.assertFalse(four == five) + self.assertTrue(four != five) + self.assertTrue(four < five) + self.assertTrue(four <= five) + self.assertFalse(four > five) + self.assertFalse(four >= five) + self.assertTrue(five > four) + + self.assertRaises(NotImplementedError, + lambda: Obj.createNullSharedPtrInteger() == four) + + def testSmartPointerObjectComparison(self): + """Test a pointee class without comparison operators.""" + o1 = Obj.createSharedPtrObj() + o2 = Obj.createSharedPtrObj() + self.assertTrue(o1 == o1) + self.assertFalse(o1 != o1) + self.assertFalse(o1 == o2) + self.assertTrue(o1 != o2) + + def testOperatorNbBool(self): + null_ptr = Obj.createNullSharedPtrInteger() + self.assertFalse(null_ptr) + zero = Obj.createSharedPtrInteger(0) + self.assertTrue(zero) + + def testParameterNone(self): + o = Obj() + null_ptr = Obj.createNullSharedPtrInteger() + o.takeSharedPtrToInteger(null_ptr) + o.takeSharedPtrToIntegerByConstRef(null_ptr) + o.takeSharedPtrToInteger(None) + o.takeSharedPtrToIntegerByConstRef(None) + + def testConstruction(self): + p1 = SharedPtr_Integer(integerFromValue(42)) + self.assertEqual(p1.value(), 42) + + p2 = std.shared_ptr_Integer(integerFromValue(42)) + self.assertEqual(p2.value(), 42) + p2.reset(integerFromValue(43)) + self.assertEqual(p2.value(), 43) + gc.collect() + + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/smartbinding.pyproject b/sources/shiboken6/tests/smartbinding/smartbinding.pyproject new file mode 100644 index 000000000..d0855ef82 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/smartbinding.pyproject @@ -0,0 +1,7 @@ +{ + "files": ["smart_pointer_test.py", + "std_optional_test.py", + "std_shared_ptr_test.py", + "std_unique_ptr_test.py", + "typesystem_smart.xml"] +} diff --git a/sources/shiboken6/tests/smartbinding/std_optional_test.py b/sources/shiboken6/tests/smartbinding/std_optional_test.py new file mode 100644 index 000000000..bee573548 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/std_optional_test.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() +from smart import Integer, StdOptionalTestBench, std + + +def call_func_on_optional(o): + o.printInteger() + + +def integer_from_value(v): + result = Integer() + result.setValue(v) + return result + + +class StdOptionalTests(unittest.TestCase): + + def testCInt(self): + b = StdOptionalTestBench() + ci = b.optionalInt() + self.assertFalse(ci.has_value()) + b.setOptionalIntValue(42) + ci = b.optionalInt() + self.assertTrue(ci.has_value()) + self.assertEqual(ci.value(), 42) + b.setOptionalInt(ci) + ci = b.optionalInt() + self.assertTrue(ci.has_value()) + self.assertEqual(ci.value(), 42) + + ci = std.optional_int(43) + self.assertEqual(ci.value(), 43) + + def testInteger(self): + b = StdOptionalTestBench() + i = b.optionalInteger() + self.assertFalse(i.has_value()) + self.assertFalse(i) + # Must not throw a C++ exception + self.assertRaises(AttributeError, call_func_on_optional, i) + + b.setOptionalIntegerValue(integer_from_value(42)) + i = b.optionalInteger() + self.assertTrue(i.has_value()) + self.assertEqual(i.value().value(), 42) + i.printInteger() + print(i) + b.setOptionalInteger(i) + i = b.optionalInteger() + self.assertTrue(i.has_value()) + self.assertEqual(i.value().value(), 42) + call_func_on_optional(i) + + i = std.optional_Integer(integer_from_value(43)) + self.assertEqual(i.value().value(), 43) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py new file mode 100644 index 000000000..2e6aea3d9 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() +from smart import Integer, StdSharedPtrTestBench, StdSharedPtrVirtualMethodTester, std + + +def call_func_on_ptr(ptr): + ptr.printInteger() + + +class VirtualTester(StdSharedPtrVirtualMethodTester): + + def doModifyInteger(self, p): + p.setValue(p.value() * 2) + return p + + +class StdSharedPtrTests(unittest.TestCase): + def testInteger(self): + p = StdSharedPtrTestBench.createInteger() + # PYSIDE-2462: Ensure Integer's __dir__ entries in the pointer's + self.assertTrue("printInteger" in dir(p)) + StdSharedPtrTestBench.printInteger(p) + self.assertTrue(p) + call_func_on_ptr(p) + + np = StdSharedPtrTestBench.createNullInteger() + StdSharedPtrTestBench.printInteger(np) + self.assertFalse(np) + self.assertRaises(AttributeError, call_func_on_ptr, np) + + iv = Integer() + iv.setValue(42) + np = std.shared_ptr_Integer(iv) + self.assertEqual(np.value(), 42) + + def testInt(self): + np = StdSharedPtrTestBench.createNullInt() + StdSharedPtrTestBench.printInt(np) + self.assertFalse(np) + p = StdSharedPtrTestBench.createInt() + StdSharedPtrTestBench.printInt(p) + + def testVirtuals(self): + """Test whether code generating virtual function overrides is generated + correctly.""" + p = StdSharedPtrTestBench.createInteger() + p.setValue(42) + v = StdSharedPtrVirtualMethodTester() + r = v.callModifyInteger(p) # Base implementation increments + self.assertEqual(r.value(), 43) + + p.setValue(42) + v = VirtualTester() + r = v.callModifyInteger(p) # Derived implementation doubles + self.assertEqual(r.value(), 84) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py new file mode 100644 index 000000000..9c7ef2f01 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/std_unique_ptr_test.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() +from smart import Integer, Integer2, StdUniquePtrTestBench, StdUniquePtrVirtualMethodTester, std + + +def call_func_on_ptr(ptr): + ptr.printInteger() + + +class VirtualTester(StdUniquePtrVirtualMethodTester): + + def doCreateInteger(self, v): + iv = Integer() # Construct from pointee + iv.setValue(2 * v) + return std.unique_ptr_Integer(iv) + + def doModifyIntegerByRef(self, p): + return 2 * p.value() + + def doModifyIntegerByValue(self, p): + return 2 * p.value() + + +class StdUniquePtrTests(unittest.TestCase): + def testInteger(self): + p = StdUniquePtrTestBench.createInteger() + StdUniquePtrTestBench.printInteger(p) # unique_ptr by ref + self.assertTrue(p) + + call_func_on_ptr(p) + self.assertTrue(p) + + StdUniquePtrTestBench.takeInteger(p) # unique_ptr by value, takes pointee + self.assertFalse(p) + + np = StdUniquePtrTestBench.createNullInteger() + StdUniquePtrTestBench.printInteger(np) + self.assertFalse(np) + self.assertRaises(AttributeError, call_func_on_ptr, np) + + iv = Integer() # Construct from pointee + iv.setValue(42) + np = std.unique_ptr_Integer(iv) + self.assertEqual(np.value(), 42) + + def test_derived(self): + iv2 = Integer2() # Construct from pointee + iv2.setValue(42) + p = std.unique_ptr_Smart_Integer2(iv2) + self.assertEqual(p.value(), 42) + StdUniquePtrTestBench.printInteger2(p) # unique_ptr by ref + self.assertTrue(p) + StdUniquePtrTestBench.printInteger(p) # conversion + # FIXME: This fails, pointer is moved in value conversion + # self.assertTrue(p) + + def testInt(self): + p = StdUniquePtrTestBench.createInt() # unique_ptr by ref + StdUniquePtrTestBench.printInt(p) + StdUniquePtrTestBench.takeInt(p) # unique_ptr by value, takes pointee + self.assertFalse(p) + + np = StdUniquePtrTestBench.createNullInt() + StdUniquePtrTestBench.printInt(np) + self.assertFalse(np) + + def testVirtuals(self): + """Test whether code generating virtual function overrides is generated + correctly.""" + p = StdUniquePtrTestBench.createInteger() + p.setValue(42) + v = StdUniquePtrVirtualMethodTester() + self.assertTrue(v.testCreateInteger(42, 42)) + self.assertTrue(v.testModifyIntegerByRef(42, 43)) # Default implementation increments + self.assertTrue(v.testModifyIntegerValue(42, 43)) + + v = VirtualTester() # Reimplemented methods double values + self.assertTrue(v.testCreateInteger(42, 84)) + self.assertTrue(v.testModifyIntegerByRef(42, 84)) + self.assertTrue(v.testModifyIntegerValue(42, 84)) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 46cb08267..261d5f15d 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -1,9 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="smart"> - <primitive-type name="int" /> - <primitive-type name="char" /> - <primitive-type name="float" /> - <primitive-type name="bool" /> + <rejection class="*" argument-type="^std::nullptr_t&?$"/> <template name="cpplist_to_pylist_convertion"> PyObject *%out = PyList_New(int(%in.size())); @@ -20,21 +17,6 @@ %out.push_back(cppItem); } </template> - <container-type name="std::vector" type="list"> - <include file-name="list" location="global"/> - <conversion-rule> - <native-to-target> - <insert-template name="cpplist_to_pylist_convertion"/> - </native-to-target> - <target-to-native> - <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> - </add-conversion> - </target-to-native> - </conversion-rule> - </container-type> - - <custom-type name="std::shared_ptr" /> <!-- Used in tests to check what C++ objects are allocated. --> <object-type name="Registry" /> @@ -45,7 +27,8 @@ won't work. --> <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" - instantiations="Integer,Smart::Integer2,Obj"/> + null-check-method="isNull" + instantiations="Integer,Smart::Integer2=Test::SmartInteger2Ptr,Obj"/> <object-type name="Obj" /> <value-type name="Integer" /> @@ -54,4 +37,45 @@ </namespace-type> <!-- Just used to silence the warnings that shiboken doens't know what to do with this type --> <custom-type name="RefData" /> + + <value-type name="StdOptionalTestBench"/> + + <system-include file-name="memory"/> + + <namespace-type name="std"> + <include file-name="memory" location="global"/> + <modify-function signature="^.*$" remove="all"/> + <enum-type name="pointer_safety"/> + <smart-pointer-type name="shared_ptr" type="shared" getter="get" + value-check-method="operator bool" + ref-count-method="use_count" + reset-method="reset" + instantiations="Integer,int"> + <include file-name="memory" location="global"/> + </smart-pointer-type> + + <smart-pointer-type name="unique_ptr" type="unique" getter="get" + value-check-method="operator bool" + reset-method="reset" + instantiations="Integer,Smart::Integer2,int"> + <include file-name="memory" location="global"/> + </smart-pointer-type> + + <smart-pointer-type name="optional" type="value-handle" getter="value" + value-check-method="has_value" + instantiations="Integer,int"> + <include file-name="optional" location="global"/> + </smart-pointer-type> + + </namespace-type> + <object-type name="StdSharedPtrTestBench"/> + <object-type name="StdSharedPtrVirtualMethodTester"/> + + <object-type name="StdUniquePtrTestBench"/> + <object-type name="StdUniquePtrVirtualMethodTester"/> + + <namespace-type name="Test"> + <enum-type name="DummyEnum"/> + </namespace-type> + </typesystem> diff --git a/sources/shiboken6/tests/test_generator/CMakeLists.txt b/sources/shiboken6/tests/test_generator/CMakeLists.txt index b48ae37da..e1d078894 100644 --- a/sources/shiboken6/tests/test_generator/CMakeLists.txt +++ b/sources/shiboken6/tests/test_generator/CMakeLists.txt @@ -1,4 +1,7 @@ -cmake_minimum_required(VERSION 3.16) +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required(VERSION 3.18) project(test_generator) set(dummy_generator_SRC dummygenerator.cpp) diff --git a/sources/shiboken6/tests/test_generator/dummygenerator.cpp b/sources/shiboken6/tests/test_generator/dummygenerator.cpp index ef82c11c9..8a5079820 100644 --- a/sources/shiboken6/tests/test_generator/dummygenerator.cpp +++ b/sources/shiboken6/tests/test_generator/dummygenerator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include <iostream> #include "dummygenerator.h" @@ -36,7 +11,7 @@ using namespace std; QString DummyGenerator::fileNameForClass(const AbstractMetaClass* metaClass) const { - return QString("%1_generated.txt").arg(metaClass->name().toLower()); + return metaClass->name().toLower() + u"_generated.txt"_qs; } void diff --git a/sources/shiboken6/tests/test_generator/dummygenerator.h b/sources/shiboken6/tests/test_generator/dummygenerator.h index e768e7643..d17206809 100644 --- a/sources/shiboken6/tests/test_generator/dummygenerator.h +++ b/sources/shiboken6/tests/test_generator/dummygenerator.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef DUMMYGENERATOR_H #define DUMMYGENERATOR_H diff --git a/sources/shiboken6/tests/test_generator/dummygentest.cpp b/sources/shiboken6/tests/test_generator/dummygentest.cpp index c09cdfb82..d439e3d8c 100644 --- a/sources/shiboken6/tests/test_generator/dummygentest.cpp +++ b/sources/shiboken6/tests/test_generator/dummygentest.cpp @@ -1,37 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include "dummygentest.h" #include "dummygenerator.h" #include "dummygentestconfig.h" -#include <QTemporaryFile> + +#include <QtCore/QProcess> +#include <QtCore/QTemporaryFile> #include <QtTest/QTest> -#include <QProcess> #define GENERATED_CONTENTS "// Generated code for class: Dummy" @@ -45,14 +21,14 @@ void DummyGenTest::initTestCase() headerFilePath = workDir + "/test_global.h"; typesystemFilePath = workDir + "/test_typesystem.xml"; projectFilePath = workDir + "/dummygentest-project.txt"; - generatedFilePath = QString("%1/dummy/dummy_generated.txt").arg(QDir::tempPath()); + generatedFilePath = QDir::tempPath() + u"/dummy/dummy_generated.txt"_qs; } void DummyGenTest::testCallGenRunnerWithFullPathToDummyGenModule() { QStringList args; args.append("--generator-set=" DUMMYGENERATOR_BINARY_DIR "/dummy_generator" MODULE_EXTENSION); - args.append(QString("--output-directory=%1").arg(QDir::tempPath())); + args.append(u"--output-directory="_qs + QDir::tempPath()); args.append(headerFilePath); args.append(typesystemFilePath); int result = QProcess::execute("generatorrunner", args); @@ -70,7 +46,7 @@ void DummyGenTest::testCallGenRunnerWithNameOfDummyGenModule() { QStringList args; args.append("--generator-set=dummy"); - args.append(QString("--output-directory=%1").arg(QDir::tempPath())); + args.append(u"--output-directory="_qs + QDir::tempPath()); args.append(headerFilePath); args.append(typesystemFilePath); int result = QProcess::execute("generatorrunner", args); @@ -87,7 +63,7 @@ void DummyGenTest::testCallGenRunnerWithNameOfDummyGenModule() void DummyGenTest::testCallDummyGeneratorExecutable() { QStringList args; - args.append(QString("--output-directory=%1").arg(QDir::tempPath())); + args.append(u"--output-directory="_qs + QDir::tempPath()); args.append(headerFilePath); args.append(typesystemFilePath); int result = QProcess::execute(DUMMYGENERATOR_BINARY, args); @@ -103,7 +79,7 @@ void DummyGenTest::testCallDummyGeneratorExecutable() void DummyGenTest::testProjectFileArgumentsReading() { - QStringList args(QString("--project-file=%1/dummygentest-project.txt").arg(workDir)); + QStringList args(u"--project-file="_qs + workDir + u"/dummygentest-project.txt"_qs); int result = QProcess::execute("generatorrunner", args); QCOMPARE(result, 0); diff --git a/sources/shiboken6/tests/test_generator/dummygentest.h b/sources/shiboken6/tests/test_generator/dummygentest.h index 78bae1d52..1b1143b0a 100644 --- a/sources/shiboken6/tests/test_generator/dummygentest.h +++ b/sources/shiboken6/tests/test_generator/dummygentest.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #ifndef DUMMYGENTABLETEST_H #define DUMMYGENTABLETEST_H diff --git a/sources/shiboken6/tests/test_generator/main.cpp b/sources/shiboken6/tests/test_generator/main.cpp index f928b4d2c..ba4440b2f 100644 --- a/sources/shiboken6/tests/test_generator/main.cpp +++ b/sources/shiboken6/tests/test_generator/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $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 WITH Qt-GPL-exception-1.0 #include <QtCore> diff --git a/sources/shiboken6/tests/test_generator/run_test.cmake b/sources/shiboken6/tests/test_generator/run_test.cmake index 34a821d80..37e40b993 100644 --- a/sources/shiboken6/tests/test_generator/run_test.cmake +++ b/sources/shiboken6/tests/test_generator/run_test.cmake @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + # The tests are run through this script due to a limitation # on versions of CMake lesser than 2.8, that prevent setting # environment variables for tests from working. |