diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor/tests')
72 files changed, 2180 insertions, 3161 deletions
diff --git a/sources/shiboken6/ApiExtractor/tests/CMakeLists.txt b/sources/shiboken6/ApiExtractor/tests/CMakeLists.txt index 97ae0f850..76c014fbb 100644 --- a/sources/shiboken6/ApiExtractor/tests/CMakeLists.txt +++ b/sources/shiboken6/ApiExtractor/tests/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + set(CMAKE_AUTORCC ON) macro(declare_test testname) @@ -15,7 +18,7 @@ macro(declare_test testname) ${CMAKE_CURRENT_BINARY_DIR} ${apiextractor_SOURCE_DIR} ) - target_link_libraries(${testname} PRIVATE apiextractor Qt${QT_MAJOR_VERSION}::Test) + target_link_libraries(${testname} PRIVATE apiextractor Qt::Test) add_test(${testname} ${testname}) if (INSTALL_TESTS) install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${testname} diff --git a/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.cpp b/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.cpp index 850df753f..4b5da0c3a 100644 --- a/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.cpp @@ -1,95 +1,77 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testabstractmetaclass.h" #include "abstractmetabuilder.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <usingmember.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestAbstractMetaClass::testClassName() { - const char* cppCode ="class ClassName {};"; - const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"ClassName\"/></typesystem>"; + const char cppCode[] = "class ClassName {};"; + const char xmlCode[] = R"(<typesystem package="Foo"> + <value-type name="ClassName"/> +</typesystem>)"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - QCOMPARE(classes[0]->name(), QLatin1String("ClassName")); + QCOMPARE(classes.size(), 1); + QCOMPARE(classes[0]->name(), u"ClassName"); } void TestAbstractMetaClass::testClassNameUnderNamespace() { - const char* cppCode ="namespace Namespace { class ClassName {}; }\n"; - const char* xmlCode = R"XML( + const char cppCode[] = "namespace Namespace { class ClassName {}; }\n"; + const char xmlCode[] = R"XML( <typesystem package="Foo"> <namespace-type name="Namespace"> <value-type name="ClassName"/> </namespace-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); // 1 namespace + 1 class - if (classes.constFirst()->name() != QLatin1String("ClassName")) + QCOMPARE(classes.size(), 2); // 1 namespace + 1 class + if (classes.constFirst()->name() != u"ClassName") qSwap(classes[0], classes[1]); - QCOMPARE(classes[0]->name(), QLatin1String("ClassName")); - QCOMPARE(classes[0]->qualifiedCppName(), QLatin1String("Namespace::ClassName")); - QCOMPARE(classes[1]->name(), QLatin1String("Namespace")); + QCOMPARE(classes[0]->name(), u"ClassName"); + QCOMPARE(classes[0]->qualifiedCppName(), u"Namespace::ClassName"); + QCOMPARE(classes[1]->name(), u"Namespace"); QVERIFY(classes[1]->isNamespace()); // Check ctors info QVERIFY(classes[0]->hasConstructors()); QCOMPARE(classes[0]->functions().size(), 2); // default ctor + copy ctor - auto ctors = classes[0]->queryFunctions(FunctionQueryOption::Constructors); + auto ctors = classes[0]->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); - if (ctors.constFirst()->minimalSignature() != QLatin1String("ClassName()")) + if (ctors.constFirst()->minimalSignature() != u"ClassName()") qSwap(ctors[0], ctors[1]); QCOMPARE(ctors[0]->arguments().size(), 0); - QCOMPARE(ctors[0]->minimalSignature(), QLatin1String("ClassName()")); + QCOMPARE(ctors[0]->minimalSignature(), u"ClassName()"); QCOMPARE(ctors[1]->arguments().size(), 1); - QCOMPARE(ctors[1]->minimalSignature(), QLatin1String("ClassName(Namespace::ClassName)")); + QCOMPARE(ctors[1]->minimalSignature(), u"ClassName(Namespace::ClassName)"); QVERIFY(!classes[0]->hasPrivateDestructor()); - QVERIFY(classes[0]->hasCloneOperator()); // implicit default copy ctor - QVERIFY(!classes[0]->hasHashFunction()); + QVERIFY(classes[0]->isCopyConstructible()); // implicit default copy ctor // This method is buggy and nobody wants to fix it or needs it fixed :-/ // QVERIFY(classes[0]->hasNonPrivateConstructor()); } -static AbstractMetaFunctionCList virtualFunctions(const AbstractMetaClass *c) +static AbstractMetaFunctionCList virtualFunctions(const AbstractMetaClassCPtr &c) { AbstractMetaFunctionCList result; const auto &functions = c->functions(); @@ -128,18 +110,16 @@ public: </typesystem> )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 4); - AbstractMetaClass* a = AbstractMetaClass::findClass(classes, QLatin1String("A")); - AbstractMetaClass* b = AbstractMetaClass::findClass(classes, QLatin1String("B")); - AbstractMetaClass* c = AbstractMetaClass::findClass(classes, QLatin1String("C")); - const AbstractMetaClass *f = AbstractMetaClass::findClass(classes, QLatin1String("F")); + QCOMPARE(classes.size(), 4); + const auto a = AbstractMetaClass::findClass(classes, "A"); + const auto b = AbstractMetaClass::findClass(classes, "B"); + const auto c = AbstractMetaClass::findClass(classes, "C"); + const auto f = AbstractMetaClass::findClass(classes, "F"); QVERIFY(f); - AbstractMetaClass* no_class = nullptr; - - QCOMPARE(a->baseClass(), no_class); + QCOMPARE(a->baseClass(), nullptr); QCOMPARE(b->baseClass(), a); QCOMPARE(c->baseClass(), b); QCOMPARE(f->baseClass(), c); @@ -179,11 +159,11 @@ public: const auto funcF = virtualFunctionsF.constFirst(); QCOMPARE(funcA->ownerClass(), a); - QVERIFY(funcC->attributes().testFlag(AbstractMetaFunction::VirtualCppMethod)); + QVERIFY(funcC->isVirtual()); QCOMPARE(funcB->ownerClass(), b); QCOMPARE(funcC->ownerClass(), c); - QVERIFY(funcC->attributes().testFlag(AbstractMetaFunction::OverriddenCppMethod)); - QVERIFY(funcF->attributes().testFlag(AbstractMetaFunction::FinalCppMethod)); + QVERIFY(funcC->cppAttributes().testFlag(FunctionAttribute::Override)); + QVERIFY(funcF->cppAttributes().testFlag(FunctionAttribute::Final)); QCOMPARE(funcA->declaringClass(), a); QCOMPARE(funcB->declaringClass(), a); @@ -214,48 +194,49 @@ class Derived : public Base {}; </typesystem> )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - auto base = AbstractMetaClass::findClass(classes, QLatin1String("Base")); + const auto base = AbstractMetaClass::findClass(classes, "Base"); QVERIFY(base); QVERIFY(base->isPolymorphic()); - auto derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived")); + const auto derived = AbstractMetaClass::findClass(classes, "Derived"); QVERIFY(derived); QVERIFY(derived->isPolymorphic()); } void TestAbstractMetaClass::testDefaultValues() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ class B {};\n\ void method(B b = B());\n\ };\n"; - const char* xmlCode = R"XML( + const char xmlCode[] = R"XML( <typesystem package="Foo"> <value-type name='A'> <value-type name='B'/> </value-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - QCOMPARE(classA->queryFunctionsByName(QLatin1String("method")).count(), 1); - const auto method = classA->queryFunctionsByName(QLatin1String("method")).constFirst(); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto candidates = classA->queryFunctionsByName(u"method"_s); + QCOMPARE(candidates.size(), 1); + const auto &method = candidates.constFirst(); const AbstractMetaArgument &arg = method->arguments().constFirst(); QCOMPARE(arg.defaultValueExpression(), arg.originalDefaultValueExpression()); } void TestAbstractMetaClass::testModifiedDefaultValues() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ class B {};\n\ void method(B b = B());\n\ };\n"; - const char* xmlCode = R"XML( + const char xmlCode[] = R"XML( <typesystem package="Foo"> <value-type name='A'> <modify-function signature='method(A::B)'> @@ -267,39 +248,39 @@ void TestAbstractMetaClass::testModifiedDefaultValues() </value-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const auto methodMatches = classA->queryFunctionsByName(QLatin1String("method")); - QCOMPARE(methodMatches.count(), 1); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto methodMatches = classA->queryFunctionsByName(u"method"_s); + QCOMPARE(methodMatches.size(), 1); const auto method = methodMatches.constFirst(); const AbstractMetaArgument &arg = method->arguments().constFirst(); - QCOMPARE(arg.defaultValueExpression(), QLatin1String("Hello")); - QCOMPARE(arg.originalDefaultValueExpression(), QLatin1String("A::B()")); + QCOMPARE(arg.defaultValueExpression(), u"Hello"); + QCOMPARE(arg.originalDefaultValueExpression(), u"A::B()"); } void TestAbstractMetaClass::testInnerClassOfAPolymorphicOne() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ class B {};\n\ virtual void method();\n\ };\n"; - const char* xmlCode = R"XML( + const char xmlCode[] = R"XML( <typesystem package="Foo"> <object-type name='A'> <value-type name='B'/> </object-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QVERIFY(classA->isPolymorphic()); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("A::B")); + const auto classB = AbstractMetaClass::findClass(classes, "A::B"); QVERIFY(classB); QVERIFY(!classB->isPolymorphic()); } @@ -321,15 +302,15 @@ void TestAbstractMetaClass::testForwardDeclaredInnerClass() </value-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("A::B")); + const auto classB = AbstractMetaClass::findClass(classes, "A::B"); QVERIFY(classB); - const auto fooF = classB->findFunction(QLatin1String("foo")); - QVERIFY(!fooF.isNull()); + const auto fooF = classB->findFunction("foo"); + QVERIFY(fooF); } void TestAbstractMetaClass::testSpecialFunctions() @@ -352,35 +333,35 @@ void TestAbstractMetaClass::testSpecialFunctions() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); + QCOMPARE(classes.size(), 2); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - auto ctors = classA->queryFunctions(FunctionQueryOption::Constructors); + auto ctors = classA->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); QCOMPARE(ctors.constFirst()->functionType(), AbstractMetaFunction::ConstructorFunction); QCOMPARE(ctors.at(1)->functionType(), AbstractMetaFunction::CopyConstructorFunction); - auto assigmentOps = classA->queryFunctionsByName(QLatin1String("operator=")); + auto assigmentOps = classA->queryFunctionsByName(u"operator="_s); QCOMPARE(assigmentOps.size(), 1); QCOMPARE(assigmentOps.constFirst()->functionType(), AbstractMetaFunction::AssignmentOperatorFunction); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); - ctors = classB->queryFunctions(FunctionQueryOption::Constructors); + ctors = classB->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); QCOMPARE(ctors.constFirst()->functionType(), AbstractMetaFunction::ConstructorFunction); QCOMPARE(ctors.at(1)->functionType(), AbstractMetaFunction::CopyConstructorFunction); - assigmentOps = classA->queryFunctionsByName(QLatin1String("operator=")); + assigmentOps = classA->queryFunctionsByName(u"operator="_s); QCOMPARE(assigmentOps.size(), 1); QCOMPARE(assigmentOps.constFirst()->functionType(), AbstractMetaFunction::AssignmentOperatorFunction); } void TestAbstractMetaClass::testClassDefaultConstructors() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ \n\ struct B {\n\ @@ -406,7 +387,7 @@ void TestAbstractMetaClass::testClassDefaultConstructors() struct F {\n\ F(int, int);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <value-type name='A'/>\n\ @@ -418,163 +399,163 @@ void TestAbstractMetaClass::testClassDefaultConstructors() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 6); + QCOMPARE(classes.size(), 6); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QCOMPARE(classA->functions().size(), 2); - auto ctors = classA->queryFunctions(FunctionQueryOption::Constructors); + auto ctors = classA->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); - if (ctors.constFirst()->minimalSignature() != QLatin1String("A()")) + if (ctors.constFirst()->minimalSignature() != u"A()") qSwap(ctors[0], ctors[1]); QCOMPARE(ctors[0]->arguments().size(), 0); - QCOMPARE(ctors[0]->minimalSignature(), QLatin1String("A()")); + QCOMPARE(ctors[0]->minimalSignature(), u"A()"); QCOMPARE(ctors[1]->arguments().size(), 1); - QCOMPARE(ctors[1]->minimalSignature(), QLatin1String("A(A)")); + QCOMPARE(ctors[1]->minimalSignature(), u"A(A)"); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); QCOMPARE(classB->functions().size(), 2); - QCOMPARE(classB->functions().constFirst()->minimalSignature(), QLatin1String("B()")); + QCOMPARE(classB->functions().constFirst()->minimalSignature(), u"B()"); - AbstractMetaClass* classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto classC = AbstractMetaClass::findClass(classes, "C"); QVERIFY(classC); QCOMPARE(classC->functions().size(), 1); - QCOMPARE(classC->functions().constFirst()->minimalSignature(), QLatin1String("C(C)")); + QCOMPARE(classC->functions().constFirst()->minimalSignature(), u"C(C)"); - AbstractMetaClass* classD = AbstractMetaClass::findClass(classes, QLatin1String("D")); + const auto classD = AbstractMetaClass::findClass(classes, "D"); QVERIFY(classD); QCOMPARE(classD->functions().size(), 1); - QCOMPARE(classD->functions().constFirst()->minimalSignature(), QLatin1String("D(D)")); + QCOMPARE(classD->functions().constFirst()->minimalSignature(), u"D(D)"); QVERIFY(classD->functions().constFirst()->isPrivate()); - AbstractMetaClass* classE = AbstractMetaClass::findClass(classes, QLatin1String("E")); + const auto classE = AbstractMetaClass::findClass(classes, "E"); QVERIFY(classE); QVERIFY(classE->hasPrivateDestructor()); QCOMPARE(classE->functions().size(), 0); - AbstractMetaClass* classF = AbstractMetaClass::findClass(classes, QLatin1String("F")); + const auto classF = AbstractMetaClass::findClass(classes, "F"); QVERIFY(classF); - ctors = classF->queryFunctions(FunctionQueryOption::Constructors); + ctors = classF->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); - if (ctors.constFirst()->minimalSignature() != QLatin1String("F(int,int)")) + if (ctors.constFirst()->minimalSignature() != u"F(int,int)") qSwap(ctors[0], ctors[1]); QCOMPARE(ctors[0]->arguments().size(), 2); - QCOMPARE(ctors[0]->minimalSignature(), QLatin1String("F(int,int)")); + QCOMPARE(ctors[0]->minimalSignature(), u"F(int,int)"); QCOMPARE(ctors[1]->arguments().size(), 1); - QCOMPARE(ctors[1]->minimalSignature(), QLatin1String("F(F)")); + QCOMPARE(ctors[1]->minimalSignature(), u"F(F)"); } void TestAbstractMetaClass::testClassInheritedDefaultConstructors() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ A();\n\ private: \n\ A(const A&);\n\ };\n\ struct B : public A {};\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <object-type name='A'/>\n\ <object-type name='B'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - auto ctors = classA->queryFunctions(FunctionQueryOption::Constructors); + auto ctors = classA->queryFunctions(FunctionQueryOption::AnyConstructor); QCOMPARE(ctors.size(), 2); - if (ctors.constFirst()->minimalSignature() != QLatin1String("A()")) + if (ctors.constFirst()->minimalSignature() != u"A()") qSwap(ctors[0], ctors[1]); QCOMPARE(ctors[0]->arguments().size(), 0); - QCOMPARE(ctors[0]->minimalSignature(), QLatin1String("A()")); + QCOMPARE(ctors[0]->minimalSignature(), u"A()"); QCOMPARE(ctors[1]->arguments().size(), 1); - QCOMPARE(ctors[1]->minimalSignature(), QLatin1String("A(A)")); + QCOMPARE(ctors[1]->minimalSignature(), u"A(A)"); QVERIFY(ctors[1]->isPrivate()); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); ctors = classB->queryFunctions(FunctionQueryOption::Constructors); QCOMPARE(ctors.size(), 1); QCOMPARE(ctors.constFirst()->arguments().size(), 0); - QCOMPARE(ctors.constFirst()->minimalSignature(), QLatin1String("B()")); + QCOMPARE(ctors.constFirst()->minimalSignature(), u"B()"); } void TestAbstractMetaClass::testAbstractClassDefaultConstructors() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ virtual void method() = 0;\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <object-type name='A'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 1); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); const auto ctors = classA->queryFunctions(FunctionQueryOption::Constructors); QCOMPARE(ctors.size(), 1); QCOMPARE(ctors.constFirst()->arguments().size(), 0); - QCOMPARE(ctors.constFirst()->minimalSignature(), QLatin1String("A()")); + QCOMPARE(ctors.constFirst()->minimalSignature(), u"A()"); } void TestAbstractMetaClass::testObjectTypesMustNotHaveCopyConstructors() { - const char* cppCode ="struct A {};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A {};\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <object-type name='A'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 1); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); const auto ctors = classA->queryFunctions(FunctionQueryOption::Constructors); QCOMPARE(ctors.size(), 1); QCOMPARE(ctors.constFirst()->arguments().size(), 0); - QCOMPARE(ctors.constFirst()->minimalSignature(), QLatin1String("A()")); + QCOMPARE(ctors.constFirst()->minimalSignature(), u"A()"); } void TestAbstractMetaClass::testIsPolymorphic() { - const char* cppCode = "\ + const char cppCode[] = "\ class A\n\ {\n\ public:\n\ A();\n\ - inline bool abc() const {}\n\ + inline bool abc() const { return false; }\n\ };\n\ \n\ class B : public A\n\ {\n\ public:\n\ B();\n\ - inline bool abc() const {}\n\ + inline bool abc() const { return false; }\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='bool'/>\n\ <value-type name='A'/>\n\ @@ -582,13 +563,13 @@ void TestAbstractMetaClass::testIsPolymorphic() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - AbstractMetaClass* b = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 2); + const auto b = AbstractMetaClass::findClass(classes, "A"); QVERIFY(!b->isPolymorphic()); - AbstractMetaClass* a = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto a = AbstractMetaClass::findClass(classes, "B"); QVERIFY(!a->isPolymorphic()); } @@ -612,12 +593,12 @@ class Derived : public BaseAlias2 { )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - auto base = AbstractMetaClass::findClass(classes, QLatin1String("Base")); + QCOMPARE(classes.size(), 2); + const auto base = AbstractMetaClass::findClass(classes, "Base"); QVERIFY(base); - auto derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived")); + const auto derived = AbstractMetaClass::findClass(classes, "Derived"); QVERIFY(derived); QCOMPARE(derived->baseClasses().value(0), base); } @@ -663,7 +644,7 @@ void TestAbstractMetaClass::testFreeOperators() </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(code.constData(), xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); const auto classes = builder->classes(); QCOMPARE(classes.size(), 1); QVERIFY(classes.constFirst()->hasArithmeticOperatorOverload()); @@ -697,15 +678,15 @@ public: )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - auto base = AbstractMetaClass::findClass(classes, QLatin1String("Base")); + QCOMPARE(classes.size(), 2); + const auto base = AbstractMetaClass::findClass(classes, "Base"); QVERIFY(base); - auto derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived")); + const auto derived = AbstractMetaClass::findClass(classes, "Derived"); QVERIFY(derived); const auto usingMembers = derived->usingMembers(); - QCOMPARE(usingMembers.count(), 2); + QCOMPARE(usingMembers.size(), 2); for (const auto &um : usingMembers) { QCOMPARE(um.access, Access::Public); QCOMPARE(um.baseClass, base); @@ -752,13 +733,46 @@ void TestAbstractMetaClass::testUsingTemplateMembers() )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(code.constData(), xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - auto valueList = AbstractMetaClass::findClass(classes, QLatin1String("ValueList")); + const auto valueList = AbstractMetaClass::findClass(classes, "ValueList"); QVERIFY(valueList); auto list = valueList->templateBaseClass(); - QVERIFY(valueList->isUsingMember(list, QLatin1String("append"), Access::Public)); - QCOMPARE(valueList->queryFunctionsByName(QLatin1String("append")).size(), 2); + QVERIFY(valueList->isUsingMember(list, u"append"_s, Access::Public)); + QCOMPARE(valueList->queryFunctionsByName(u"append"_s).size(), 2); +} + +void TestAbstractMetaClass::testGenerateFunctions() +{ + const char cppCode[] = R"CPP( +class TestClass { +public: + TestClass(); + + void alpha(int); + void beta(int); + void beta(double); + void gamma(int); +}; +)CPP"; + + const char xmlCode[] = R"XML( +<typesystem package='Foo'> + <object-type name='TestClass' generate-functions='beta(double);gamma'/> +</typesystem> +)XML"; + + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); + QVERIFY(builder); + AbstractMetaClassList classes = builder->classes(); + const auto tc = AbstractMetaClass::findClass(classes, "TestClass"); + // Verify that the constructor and 2 functions are generated. + const auto &functions = tc->functions(); + QCOMPARE(functions.size(), 5); + const auto generateCount = + std::count_if(functions.cbegin(), functions.cend(), + [](const auto &af) { return af->generateBinding(); }); + QCOMPARE(generateCount, 3); } QTEST_APPLESS_MAIN(TestAbstractMetaClass) diff --git a/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.h b/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.h index ab171d6b7..a6bd2bf06 100644 --- a/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.h +++ b/sources/shiboken6/ApiExtractor/tests/testabstractmetaclass.h @@ -1,35 +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 #ifndef TESTABSTRACTMETACLASS_H #define TESTABSTRACTMETACLASS_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; @@ -57,6 +32,7 @@ private slots: void testUsingMembers(); void testUsingTemplateMembers_data(); void testUsingTemplateMembers(); + void testGenerateFunctions(); }; #endif // TESTABSTRACTMETACLASS_H diff --git a/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.cpp b/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.cpp index 897940cd5..2c320c874 100644 --- a/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.cpp @@ -1,40 +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 #include "testabstractmetatype.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> #include <typesystem.h> #include <parser/codemodel.h> #include <typeparser.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestAbstractMetaType::parsing_data() { QTest::addColumn<QString>("input"); @@ -66,20 +48,20 @@ void TestAbstractMetaType::parsing() void TestAbstractMetaType::testConstCharPtrType() { - const char* cppCode ="const char* justAtest();\n"; - const char* xmlCode = "<typesystem package=\"Foo\">\n\ + const char cppCode[] = "const char* justAtest();\n"; + const char xmlCode[] = "<typesystem package=\"Foo\">\n\ <primitive-type name='char'/>\n\ <function signature='justAtest()' />\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->globalFunctions().size(), 1); const auto func = builder->globalFunctions().constFirst(); AbstractMetaType rtype = func->type(); // Test properties of const char* QVERIFY(!rtype.isVoid()); - QCOMPARE(rtype.package(), QLatin1String("Foo")); - QCOMPARE(rtype.name(), QLatin1String("char")); + QCOMPARE(rtype.package(), u"Foo"); + QCOMPARE(rtype.name(), u"char"); QVERIFY(rtype.isConstant()); QVERIFY(!rtype.isArray()); QVERIFY(!rtype.isContainer()); @@ -93,9 +75,9 @@ void TestAbstractMetaType::testConstCharPtrType() void TestAbstractMetaType::testApiVersionSupported() { - const char* cppCode ="class foo {}; class foo2 {};\n\ + const char cppCode[] = "class foo {}; class foo2 {};\n\ void justAtest(); void justAtest3();\n"; - const char* xmlCode = "<typesystem package='Foo'>\n\ + const char xmlCode[] = "<typesystem package='Foo'>\n\ <value-type name='foo' since='0.1'/>\n\ <value-type name='foo2' since='1.0'/>\n\ <value-type name='foo3' since='1.1'/>\n\ @@ -104,8 +86,8 @@ void TestAbstractMetaType::testApiVersionSupported() <function signature='justAtest3()'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - false, QLatin1String("1.0"))); - QVERIFY(!builder.isNull()); + false, u"1.0"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 2); @@ -117,13 +99,13 @@ void TestAbstractMetaType::testApiVersionSupported() void TestAbstractMetaType::testApiVersionNotSupported() { - const char* cppCode ="class object {};\n"; - const char* xmlCode = "<typesystem package='Foo'>\n\ + const char cppCode[] = "class object {};\n"; + const char xmlCode[] = "<typesystem package='Foo'>\n\ <value-type name='object' since='0.1'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - true, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + true, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 1); @@ -131,18 +113,18 @@ void TestAbstractMetaType::testApiVersionNotSupported() void TestAbstractMetaType::testCharType() { - const char* cppCode ="char justAtest(); class A {};\n"; - const char* xmlCode = "<typesystem package=\"Foo\">\n\ + const char cppCode[] = "char justAtest(); class A {};\n"; + const char xmlCode[] = "<typesystem package=\"Foo\">\n\ <primitive-type name='char'/>\n\ <value-type name='A'/>\n\ <function signature='justAtest()'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 1); - QCOMPARE(classes.constFirst()->package(), QLatin1String("Foo")); + QCOMPARE(classes.constFirst()->package(), u"Foo"); const auto functions = builder->globalFunctions(); QCOMPARE(functions.size(), 1); @@ -150,8 +132,8 @@ void TestAbstractMetaType::testCharType() AbstractMetaType rtype = func->type(); // Test properties of const char* QVERIFY(!rtype.isVoid()); - QCOMPARE(rtype.package(), QLatin1String("Foo")); - QCOMPARE(rtype.name(), QLatin1String("char")); + QCOMPARE(rtype.package(), u"Foo"); + QCOMPARE(rtype.name(), u"char"); QVERIFY(!rtype.isConstant()); QVERIFY(!rtype.isArray()); QVERIFY(!rtype.isContainer()); @@ -165,28 +147,28 @@ void TestAbstractMetaType::testCharType() void TestAbstractMetaType::testTypedef() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ void someMethod();\n\ };\n\ typedef A B;\n\ typedef B C;\n"; - const char* xmlCode = "<typesystem package=\"Foo\">\n\ + const char xmlCode[] = "<typesystem package=\"Foo\">\n\ <value-type name='C' />\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 1); - const AbstractMetaClass *c = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto c = AbstractMetaClass::findClass(classes, "C"); QVERIFY(c); QVERIFY(c->isTypeDef()); } void TestAbstractMetaType::testTypedefWithTemplates() { - const char* cppCode ="\ + const char cppCode[] = "\ template<typename T>\n\ class A {};\n\ \n\ @@ -194,52 +176,52 @@ void TestAbstractMetaType::testTypedefWithTemplates() typedef A<B> C;\n\ \n\ void func(C c);\n"; - const char* xmlCode = "<typesystem package=\"Foo\">\n\ + const char xmlCode[] = "<typesystem package=\"Foo\">\n\ <container-type name='A' type='list'/>\n\ <value-type name='B' />\n\ <function signature='func(A<B>)'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 1); const auto functions = builder->globalFunctions(); - QCOMPARE(functions.count(), 1); + QCOMPARE(functions.size(), 1); const auto function = functions.constFirst(); AbstractMetaArgumentList args = function->arguments(); - QCOMPARE(args.count(), 1); + QCOMPARE(args.size(), 1); const AbstractMetaArgument &arg = args.constFirst(); AbstractMetaType metaType = arg.type(); - QCOMPARE(metaType.cppSignature(), QLatin1String("A<B >")); + QCOMPARE(metaType.cppSignature(), u"A<B>"); } void TestAbstractMetaType::testObjectTypeUsedAsValue() { - const char* cppCode ="\ + const char cppCode[] = "\ class A {\n\ void method(A);\n\ };\n"; - const char* xmlCode = "<typesystem package='Foo'>\n\ + const char xmlCode[] = "<typesystem package='Foo'>\n\ <object-type name='A'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.size(), 1); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto overloads = classA->queryFunctionsByName(QLatin1String("method")); - QCOMPARE(overloads.count(), 1); + const auto overloads = classA->queryFunctionsByName(u"method"_s); + QCOMPARE(overloads.size(), 1); const auto method = overloads.constFirst(); QVERIFY(method); AbstractMetaArgumentList args = method->arguments(); - QCOMPARE(args.count(), 1); + QCOMPARE(args.size(), 1); const AbstractMetaArgument &arg = args.constFirst(); AbstractMetaType metaType = arg.type(); - QCOMPARE(metaType.cppSignature(), QLatin1String("A")); + QCOMPARE(metaType.cppSignature(), u"A"); QVERIFY(metaType.isValue()); QVERIFY(metaType.typeEntry()->isObject()); } diff --git a/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.h b/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.h index b39a27a54..fdcf0c787 100644 --- a/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/tests/testabstractmetatype.h @@ -1,35 +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 #ifndef TESTABSTRACTMETATYPE_H #define TESTABSTRACTMETATYPE_H -#include <QObject> +#include <QtCore/QObject> class TestAbstractMetaType : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp index 1c5e31f35..a891e1e28 100644 --- a/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testaddfunction.cpp @@ -1,80 +1,67 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testaddfunction.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <modifications.h> -#include <modifications_p.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <codesnip.h> +#include <addedfunction.h> +#include <addedfunction_p.h> +#include <complextypeentry.h> +#include <primitivetypeentry.h> + +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + +static constexpr auto voidT = "void"_L1; void TestAddFunction::testParsingFuncNameAndConstness() { // generic test... - const char sig1[] = "func(type1, const type2, const type3* const)"; + static constexpr auto sig1 = "func(type1, const type2, const type3* const)"_L1; QString errorMessage; - auto f1 = AddedFunction::createAddedFunction(QLatin1String(sig1), QLatin1String("void"), - &errorMessage); - QVERIFY2(!f1.isNull(), qPrintable(errorMessage)); - QCOMPARE(f1->name(), QLatin1String("func")); - QCOMPARE(f1->arguments().count(), 3); + auto f1 = AddedFunction::createAddedFunction(sig1, voidT, &errorMessage); + QVERIFY2(f1, qPrintable(errorMessage)); + QCOMPARE(f1->name(), u"func"); + QCOMPARE(f1->arguments().size(), 3); TypeInfo retval = f1->returnType(); - QCOMPARE(retval.qualifiedName(), QStringList{QLatin1String("void")}); + QCOMPARE(retval.qualifiedName(), QStringList{voidT}); QCOMPARE(retval.indirections(), 0); QCOMPARE(retval.isConstant(), false); QCOMPARE(retval.referenceType(), NoReference); // test with a ugly template as argument and other ugly stuff - const char sig2[] = " _fu__nc_ ( type1, const type2, const Abc<int& , C<char*> * > * *@my_name@, const type3* const ) const "; - auto f2 = AddedFunction::createAddedFunction(QLatin1String(sig2), - QLatin1String("const Abc<int& , C<char*> * > * *"), + static constexpr auto sig2 = + " _fu__nc_ ( type1, const type2, const Abc<int& , C<char*> * >" + " * *@my_name@, const type3* const ) const "_L1; + auto f2 = AddedFunction::createAddedFunction(sig2, + u"const Abc<int& , C<char*> * > * *"_s, &errorMessage); - QVERIFY2(!f2.isNull(), qPrintable(errorMessage)); - QCOMPARE(f2->name(), QLatin1String("_fu__nc_")); + QVERIFY2(f2, qPrintable(errorMessage)); + QCOMPARE(f2->name(), u"_fu__nc_"); const auto &args = f2->arguments(); - QCOMPARE(args.count(), 4); + QCOMPARE(args.size(), 4); retval = f2->returnType(); - QCOMPARE(retval.qualifiedName(), QStringList{QLatin1String("Abc")}); + QCOMPARE(retval.qualifiedName(), QStringList{u"Abc"_s}); QCOMPARE(retval.instantiations().size(), 2); - QCOMPARE(retval.toString(), QLatin1String("const Abc<int&, C<char*>*>**")); + QCOMPARE(retval.toString(), u"const Abc<int&, C<char*>*>**"); QCOMPARE(retval.indirections(), 2); QCOMPARE(retval.isConstant(), true); QCOMPARE(retval.referenceType(), NoReference); QVERIFY(args.at(0).name.isEmpty()); QVERIFY(args.at(1).name.isEmpty()); - QCOMPARE(args.at(2).name, QLatin1String("my_name")); + QCOMPARE(args.at(2).name, u"my_name"); auto arg2Type = args.at(2).typeInfo; - QCOMPARE(arg2Type.qualifiedName(), QStringList{QLatin1String("Abc")}); + QCOMPARE(arg2Type.qualifiedName(), QStringList{u"Abc"_s}); QCOMPARE(arg2Type.instantiations().size(), 2); - QCOMPARE(arg2Type.toString(), QLatin1String("const Abc<int&, C<char*>*>**")); + QCOMPARE(arg2Type.toString(), u"const Abc<int&, C<char*>*>**"); QCOMPARE(arg2Type.indirections(), 2); QCOMPARE(arg2Type.isConstant(), true); QCOMPARE(arg2Type.referenceType(), NoReference); @@ -82,20 +69,17 @@ void TestAddFunction::testParsingFuncNameAndConstness() QVERIFY(args.at(3).name.isEmpty()); // function with no args. - const char sig3[] = "func()"; - auto f3 = AddedFunction::createAddedFunction(QLatin1String(sig3), QLatin1String("void"), - &errorMessage); - QVERIFY2(!f3.isNull(), qPrintable(errorMessage)); - QCOMPARE(f3->name(), QLatin1String("func")); - QCOMPARE(f3->arguments().count(), 0); + auto f3 = AddedFunction::createAddedFunction("func()"_L1, voidT, &errorMessage); + QVERIFY2(f3, qPrintable(errorMessage)); + QCOMPARE(f3->name(), u"func"); + QCOMPARE(f3->arguments().size(), 0); // const call operator - const char sig4[] = "operator()(int)const"; - auto f4 = AddedFunction::createAddedFunction(QLatin1String(sig4), QLatin1String("int"), - &errorMessage); - QVERIFY2(!f4.isNull(), qPrintable(errorMessage)); - QCOMPARE(f4->name(), QLatin1String("operator()")); - QCOMPARE(f4->arguments().count(), 1); + auto f4 = AddedFunction::createAddedFunction("operator()(int)const"_L1, + "int"_L1, &errorMessage); + QVERIFY2(f4, qPrintable(errorMessage)); + QCOMPARE(f4->name(), u"operator()"); + QCOMPARE(f4->arguments().size(), 1); QVERIFY(f4->isConstant()); } @@ -118,14 +102,15 @@ struct A { </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); - TypeDatabase* typeDb = TypeDatabase::instance(); + QVERIFY(builder); + auto *typeDb = TypeDatabase::instance(); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 5); // default ctor, default copy ctor, func a() and the added functions + // default ctor, default copy ctor, func a() and the added functions + QCOMPARE(classA->functions().size(), 5); - auto addedFunc = classA->findFunction(QLatin1String("b")); + auto addedFunc = classA->findFunction("b"); QVERIFY(addedFunc); QCOMPARE(addedFunc->access(), Access::Protected); QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::NormalFunction); @@ -139,14 +124,14 @@ struct A { QVERIFY(!addedFunc->isStatic()); AbstractMetaType returnType = addedFunc->type(); - QCOMPARE(returnType.typeEntry(), typeDb->findPrimitiveType(QLatin1String("int"))); + QCOMPARE(returnType.typeEntry(), typeDb->findPrimitiveType(u"int"_s)); const AbstractMetaArgumentList &args = addedFunc->arguments(); - QCOMPARE(args.count(), 3); + QCOMPARE(args.size(), 3); QCOMPARE(args.at(0).type().typeEntry(), returnType.typeEntry()); - QCOMPARE(args.at(1).defaultValueExpression(), QLatin1String("4.6")); - QCOMPARE(args.at(2).type().typeEntry(), typeDb->findType(QLatin1String("B"))); + QCOMPARE(args.at(1).defaultValueExpression(), u"4.6"); + QCOMPARE(args.at(2).type().typeEntry(), typeDb->findType(u"B"_s)); - auto addedCallOperator = classA->findFunction(QLatin1String("operator()")); + auto addedCallOperator = classA->findFunction("operator()"); QVERIFY(addedCallOperator); } @@ -161,11 +146,11 @@ void TestAddFunction::testAddFunctionConstructor() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 3); // default and added ctors + QCOMPARE(classA->functions().size(), 3); // default and added ctors const auto addedFunc = classA->functions().constLast(); QCOMPARE(addedFunc->access(), Access::Public); QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::ConstructorFunction); @@ -184,11 +169,12 @@ void TestAddFunction::testAddFunctionTagDefaultValues() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 3); // default ctor, default copy ctor and the added function + // default ctor, default copy ctor and the added function + QCOMPARE(classA->functions().size(), 3); const auto addedFunc = classA->functions().constLast(); QCOMPARE(addedFunc->access(), Access::Public); QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::NormalFunction); @@ -209,9 +195,9 @@ void TestAddFunction::testAddFunctionCodeSnippets() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); const auto addedFunc = classA->functions().constLast(); QVERIFY(addedFunc->hasInjectedCode()); @@ -219,13 +205,12 @@ void TestAddFunction::testAddFunctionCodeSnippets() void TestAddFunction::testAddFunctionWithoutParenteses() { - const char sig1[] = "func"; + static constexpr auto sig1 = "func"_L1; QString errorMessage; - auto f1 = AddedFunction::createAddedFunction(QLatin1String(sig1), QLatin1String("void"), - &errorMessage); - QVERIFY2(!f1.isNull(), qPrintable(errorMessage)); - QCOMPARE(f1->name(), QLatin1String("func")); - QCOMPARE(f1->arguments().count(), 0); + auto f1 = AddedFunction::createAddedFunction(sig1, voidT, &errorMessage); + QVERIFY2(f1, qPrintable(errorMessage)); + QCOMPARE(f1->name(), u"func"); + QCOMPARE(f1->arguments().size(), 0); QCOMPARE(f1->isConstant(), false); const char cppCode[] = "struct A {};\n"; @@ -239,25 +224,26 @@ void TestAddFunction::testAddFunctionWithoutParenteses() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("func")); - QVERIFY(!addedFunc.isNull()); + const auto addedFunc = classA->findFunction(sig1); + QVERIFY(addedFunc); QVERIFY(addedFunc->hasInjectedCode()); - QCOMPARE(addedFunc->injectedCodeSnips(TypeSystem::CodeSnipPositionAny, TypeSystem::TargetLangCode).count(), 1); + const auto snips = addedFunc->injectedCodeSnips(TypeSystem::CodeSnipPositionAny, + TypeSystem::TargetLangCode); + QCOMPARE(snips.size(), 1); } void TestAddFunction::testAddFunctionWithDefaultArgs() { - const char sig1[] = "func"; + static constexpr auto sig1 = "func"_L1; QString errorMessage; - auto f1 = AddedFunction::createAddedFunction(QLatin1String(sig1), QLatin1String("void"), - &errorMessage); - QVERIFY2(!f1.isNull(), qPrintable(errorMessage)); - QCOMPARE(f1->name(), QLatin1String("func")); - QCOMPARE(f1->arguments().count(), 0); + auto f1 = AddedFunction::createAddedFunction(sig1, voidT, &errorMessage); + QVERIFY2(f1, qPrintable(errorMessage)); + QCOMPARE(f1->name(), u"func"); + QCOMPARE(f1->arguments().size(), 0); QCOMPARE(f1->isConstant(), false); const char cppCode[] = "struct A { };\n"; @@ -274,14 +260,14 @@ void TestAddFunction::testAddFunctionWithDefaultArgs() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("func")); - QVERIFY(!addedFunc.isNull()); + const auto addedFunc = classA->findFunction(sig1); + QVERIFY(addedFunc); const AbstractMetaArgument &arg = addedFunc->arguments().at(1); - QCOMPARE(arg.defaultValueExpression(), QLatin1String("2")); + QCOMPARE(arg.defaultValueExpression(), u"2"); } void TestAddFunction::testAddFunctionAtModuleLevel() @@ -297,34 +283,33 @@ void TestAddFunction::testAddFunctionAtModuleLevel() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - TypeDatabase* typeDb = TypeDatabase::instance(); + auto *typeDb = TypeDatabase::instance(); - AddedFunctionList addedFuncs = typeDb->findGlobalUserFunctions(QLatin1String("func")); + AddedFunctionList addedFuncs = typeDb->findGlobalUserFunctions(u"func"_s); QCOMPARE(addedFuncs.size(), 1); - const FunctionModificationList mods = addedFuncs.constFirst()->modifications; + auto &mods = addedFuncs.constFirst()->modifications(); QCOMPARE(mods.size(), 1); QVERIFY(mods.constFirst().isCodeInjection()); CodeSnip snip = mods.constFirst().snips().constFirst(); - QCOMPARE(snip.code().trimmed(), QLatin1String("custom_code();")); + QCOMPARE(snip.code().trimmed(), u"custom_code();"); } void TestAddFunction::testAddFunctionWithVarargs() { - const char sig1[] = "func(int,char,...)"; QString errorMessage; - auto f1 = AddedFunction::createAddedFunction(QLatin1String(sig1), QLatin1String("void"), + auto f1 = AddedFunction::createAddedFunction("func(int,char,...)"_L1, voidT, &errorMessage); - QVERIFY2(!f1.isNull(), qPrintable(errorMessage)); - QCOMPARE(f1->name(), QLatin1String("func")); - QCOMPARE(f1->arguments().count(), 3); + QVERIFY2(f1, qPrintable(errorMessage)); + QCOMPARE(f1->name(), u"func"); + QCOMPARE(f1->arguments().size(), 3); QVERIFY(!f1->isConstant()); const char cppCode[] = "struct A {};\n"; @@ -338,12 +323,12 @@ void TestAddFunction::testAddFunctionWithVarargs() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("func")); - QVERIFY(!addedFunc.isNull()); + const auto addedFunc = classA->findFunction("func"); + QVERIFY(addedFunc); const AbstractMetaArgument &arg = addedFunc->arguments().constLast(); QVERIFY(arg.type().isVarargs()); QVERIFY(arg.type().typeEntry()->isVarargs()); @@ -362,12 +347,12 @@ void TestAddFunction::testAddStaticFunction() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("func")); - QVERIFY(!addedFunc.isNull()); + const auto addedFunc = classA->findFunction("func"); + QVERIFY(addedFunc); QVERIFY(addedFunc->isStatic()); } @@ -387,13 +372,13 @@ void TestAddFunction::testAddGlobalFunction() <value-type name='B'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); const auto globalFuncs = builder->globalFunctions(); - QCOMPARE(globalFuncs.count(), 2); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(builder->classes(), QLatin1String("B")); + QCOMPARE(globalFuncs.size(), 2); + const auto classB = AbstractMetaClass::findClass(builder->classes(), "B"); QVERIFY(classB); - QVERIFY(!classB->findFunction(QLatin1String("globalFunc"))); - QVERIFY(!classB->findFunction(QLatin1String("globalFunc2"))); + QVERIFY(!classB->findFunction("globalFunc")); + QVERIFY(!classB->findFunction("globalFunc2")); QVERIFY(!globalFuncs[0]->injectedCodeSnips().isEmpty()); QVERIFY(!globalFuncs[1]->injectedCodeSnips().isEmpty()); } @@ -412,10 +397,10 @@ void TestAddFunction::testAddFunctionWithApiVersion() </add-function>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - true, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + true, u"0.1"_s)); + QVERIFY(builder); const auto globalFuncs = builder->globalFunctions(); - QCOMPARE(globalFuncs.count(), 1); + QCOMPARE(globalFuncs.size(), 1); } void TestAddFunction::testModifyAddedFunction() @@ -436,16 +421,16 @@ void TestAddFunction::testModifyAddedFunction() </typesystem> )"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* foo = AbstractMetaClass::findClass(classes, QLatin1String("Foo")); - const auto method = foo->findFunction(QLatin1String("method")); - QVERIFY(!method.isNull()); + const auto foo = AbstractMetaClass::findClass(classes, "Foo"); + const auto method = foo->findFunction("method"); + QVERIFY(method); QCOMPARE(method->arguments().size(), 2); const AbstractMetaArgument &arg = method->arguments().at(1); - QCOMPARE(arg.defaultValueExpression(), QLatin1String("0")); - QCOMPARE(arg.name(), QLatin1String("varName")); - QCOMPARE(method->argumentName(2), QLatin1String("varName")); + QCOMPARE(arg.defaultValueExpression(), u"0"); + QCOMPARE(arg.name(), u"varName"); + QCOMPARE(method->argumentName(2), u"varName"); } void TestAddFunction::testAddFunctionOnTypedef() @@ -453,8 +438,6 @@ void TestAddFunction::testAddFunctionOnTypedef() const char cppCode[] = "template<class T> class Foo { }; typedef Foo<int> FooInt;\n"; const char xmlCode[] = "\ <typesystem package='Package'>\n\ - <custom-type name='PySequence'/>\n\ - <primitive-type name='int'/>\n\ <value-type name='FooInt'>\n\ <add-function signature='FooInt(PySequence)'>\n\ <inject-code class='target' position='beginning'>custom_code();</inject-code>\n\ @@ -465,17 +448,17 @@ void TestAddFunction::testAddFunctionOnTypedef() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* foo = AbstractMetaClass::findClass(classes, QLatin1String("FooInt")); + const auto foo = AbstractMetaClass::findClass(classes, "FooInt"); QVERIFY(foo); QVERIFY(foo->hasNonPrivateConstructor()); - const auto &lst = foo->queryFunctions(FunctionQueryOption::Constructors); + const auto &lst = foo->queryFunctions(FunctionQueryOption::AnyConstructor); for (const auto &f : lst) QVERIFY(f->signature().startsWith(f->name())); QCOMPARE(lst.size(), 2); - const auto method = foo->findFunction(QLatin1String("method")); - QVERIFY(!method.isNull()); + const auto method = foo->findFunction("method"); + QVERIFY(method); } void TestAddFunction::testAddFunctionWithTemplateArg() @@ -489,11 +472,11 @@ void TestAddFunction::testAddFunctionWithTemplateArg() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->globalFunctions().size(), 1); const auto func = builder->globalFunctions().constFirst(); const AbstractMetaArgument &arg = func->arguments().constFirst(); - QCOMPARE(arg.type().instantiations().count(), 1); + QCOMPARE(arg.type().instantiations().size(), 1); } // Test splitting of <add-function> parameter lists. @@ -512,18 +495,18 @@ void TestAddFunction::testAddFunctionTypeParser_data() QTest::newRow("1-arg") << QString::fromLatin1("int @a@=42") - << Arguments{{QLatin1String("int"), QLatin1String("a"), QLatin1String("42")}}; + << Arguments{{u"int"_s, u"a"_s, u"42"_s}}; QTest::newRow("2-args") << QString::fromLatin1("double @d@, int @a@=42") - << Arguments{{QLatin1String("double"), QLatin1String("d"), {}}, - {QLatin1String("int"), QLatin1String("a"), QLatin1String("42")}}; + << Arguments{{u"double"_s, u"d"_s, {}}, + {u"int"_s, u"a"_s, u"42"_s}}; QTest::newRow("template-var_args") << QString::fromLatin1("const QList<X,Y> &@list@ = QList<X,Y>{1,2}, int @b@=5, ...") - << Arguments{{QLatin1String("const QList<X,Y> &"), QLatin1String("list"), QLatin1String("QList<X,Y>{1,2}")}, - {QLatin1String("int"), QLatin1String("b"), QLatin1String("5")}, - {QLatin1String("..."), {}, {}}}; + << Arguments{{u"const QList<X,Y> &"_s, u"list"_s, u"QList<X,Y>{1,2}"_s}, + {u"int"_s, u"b"_s, u"5"_s}, + {u"..."_s, {}, {}}}; } void TestAddFunction::testAddFunctionTypeParser() diff --git a/sources/shiboken6/ApiExtractor/tests/testaddfunction.h b/sources/shiboken6/ApiExtractor/tests/testaddfunction.h index 195633030..77339609f 100644 --- a/sources/shiboken6/ApiExtractor/tests/testaddfunction.h +++ b/sources/shiboken6/ApiExtractor/tests/testaddfunction.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTADDFUNCTION_H #define TESTADDFUNCTION_H -#include <QObject> +#include <QtCore/QObject> class TestAddFunction : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testarrayargument.cpp b/sources/shiboken6/ApiExtractor/tests/testarrayargument.cpp index 22cf7ab40..6e1820bed 100644 --- a/sources/shiboken6/ApiExtractor/tests/testarrayargument.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testarrayargument.cpp @@ -1,48 +1,30 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testarrayargument.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetaenum.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <primitivetypeentry.h> #include <parser/enumvalue.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestArrayArgument::testArrayArgumentWithSizeDefinedByInteger() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ enum SomeEnum { Value0, Value1, NValues };\n\ void method(double[3]);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='double'/>\n\ <object-type name='A'>\n\ @@ -52,19 +34,19 @@ void TestArrayArgument::testArrayArgumentWithSizeDefinedByInteger() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); const AbstractMetaArgument &arg = classA->functions().constLast()->arguments().constFirst(); QVERIFY(arg.type().isArray()); QCOMPARE(arg.type().arrayElementCount(), 3); - QCOMPARE(arg.type().arrayElementType()->name(), QLatin1String("double")); + QCOMPARE(arg.type().arrayElementType()->name(), u"double"); } -static QString functionMinimalSignature(const AbstractMetaClass *c, const QString &name) +static QString functionMinimalSignature(const AbstractMetaClassCPtr &c, const QString &name) { const auto f = c->findFunction(name); - return f.isNull() ? QString() : f->minimalSignature(); + return f ? f->minimalSignature() : QString(); } void TestArrayArgument::testArraySignature() @@ -90,33 +72,33 @@ void TestArrayArgument::testArraySignature() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mi1")), - QLatin1String("mi1(int[5])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mi1c")), - QLatin1String("mi1c(const int[5])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mi1cu")), - QLatin1String("mi1cu(const int[])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mc1cu")), - QLatin1String("mc1cu(const char*)")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mc1cup")), - QLatin1String("mc1cup(const char*[])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("muc2")), - QLatin1String("muc2(unsigned char*[2][3])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mc2c")), - QLatin1String("mc2c(const char*[5][6])")); - QCOMPARE(functionMinimalSignature(classA, QLatin1String("mc2cu")), - QLatin1String("mc2cu(const char[][2])")); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); + QCOMPARE(functionMinimalSignature(classA, u"mi1"_s), + u"mi1(int[5])"); + QCOMPARE(functionMinimalSignature(classA, u"mi1c"_s), + u"mi1c(const int[5])"); + QCOMPARE(functionMinimalSignature(classA, u"mi1cu"_s), + u"mi1cu(const int[])"); + QCOMPARE(functionMinimalSignature(classA, u"mc1cu"_s), + u"mc1cu(const char*)"); + QCOMPARE(functionMinimalSignature(classA, u"mc1cup"_s), + u"mc1cup(const char*[])"); + QCOMPARE(functionMinimalSignature(classA, u"muc2"_s), + u"muc2(unsigned char*[2][3])"); + QCOMPARE(functionMinimalSignature(classA, u"mc2c"_s), + u"mc2c(const char*[5][6])"); + QCOMPARE(functionMinimalSignature(classA, u"mc2cu"_s), + u"mc2cu(const char[][2])"); } void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValue() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ enum SomeEnum { Value0, Value1, NValues };\n\ void method(double[NValues]);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='double'/>\n\ <object-type name='A'>\n\ @@ -126,28 +108,28 @@ void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValue() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + AbstractMetaClassPtr classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); - auto someEnum = classA->findEnum(QLatin1String("SomeEnum")); + auto someEnum = classA->findEnum(u"SomeEnum"_s); QVERIFY(someEnum.has_value()); - auto nvalues = classA->findEnumValue(QLatin1String("NValues")); + auto nvalues = classA->findEnumValue(u"NValues"_s); QVERIFY(nvalues.has_value()); const AbstractMetaArgument &arg = classA->functions().constLast()->arguments().constFirst(); QVERIFY(arg.type().isArray()); QCOMPARE(arg.type().arrayElementCount(), nvalues->value().value()); - QCOMPARE(arg.type().arrayElementType()->name(), QLatin1String("double")); + QCOMPARE(arg.type().arrayElementType()->name(), u"double"); }; void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValueFromGlobalEnum() { - const char* cppCode ="\ + const char cppCode[] = "\ enum SomeEnum { Value0, Value1, NValues };\n\ struct A {\n\ void method(double[NValues]);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='double'/>\n\ <enum-type name='SomeEnum'/>\n\ @@ -156,8 +138,8 @@ void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValueFromGlobalEnu </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + QVERIFY(builder); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); AbstractMetaEnum someEnum = builder->globalEnums().constFirst(); @@ -167,7 +149,7 @@ void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValueFromGlobalEnu const AbstractMetaArgument &arg = classA->functions().constLast()->arguments().constFirst(); QVERIFY(arg.type().isArray()); QCOMPARE(arg.type().arrayElementCount(), nvalues->value().value()); - QCOMPARE(arg.type().arrayElementType()->name(), QLatin1String("double")); + QCOMPARE(arg.type().arrayElementType()->name(), u"double"); }; QTEST_APPLESS_MAIN(TestArrayArgument) diff --git a/sources/shiboken6/ApiExtractor/tests/testarrayargument.h b/sources/shiboken6/ApiExtractor/tests/testarrayargument.h index 2e58ae6ee..75ef0f792 100644 --- a/sources/shiboken6/ApiExtractor/tests/testarrayargument.h +++ b/sources/shiboken6/ApiExtractor/tests/testarrayargument.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTARRAYARGUMENT_H #define TESTARRAYARGUMENT_H -#include <QObject> +#include <QtCore/QObject> class TestArrayArgument : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp index 1d7ba9666..4829e6c33 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp @@ -1,40 +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 #include "testcodeinjection.h" -#include <QFileInfo> -#include <QDir> -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> +#include <codesnip.h> #include <modifications.h> #include <textstream.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <valuetypeentry.h> + +#include <qtcompat.h> + +#include <QtCore/QDir> +#include <QtCore/QFileInfo> +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; void TestCodeInjections::testReadFile_data() { @@ -59,38 +41,40 @@ void TestCodeInjections::testReadFile() QFETCH(QString, snippet); QFETCH(QString, expected); - const char* cppCode ="struct A {};\n"; + const char cppCode[] = "struct A {};\n"; int argc = 0; char *argv[] = {nullptr}; QCoreApplication app(argc, argv); - QString attribute = QLatin1String("file='") + filePath + QLatin1Char('\''); + QString attribute = u"file='"_s + filePath + u'\''; if (!snippet.isEmpty()) - attribute += QLatin1String(" snippet='") + snippet + QLatin1Char('\''); + attribute += u" snippet='"_s + snippet + u'\''; - QString xmlCode = QLatin1String("\ + QString xmlCode = u"\ <typesystem package=\"Foo\">\n\ <value-type name='A'>\n\ - <conversion-rule class='target' ") + attribute + QLatin1String("/>\n\ - <inject-code class='target' ") + attribute + QLatin1String("/>\n\ + <conversion-rule class='target' "_s + attribute + u"/>\n\ + <inject-code class='target' "_s + attribute + u"/>\n\ <value-type name='B'/>\n\ </value-type>\n\ - </typesystem>\n"); + </typesystem>\n"_s; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode.toLocal8Bit().constData())); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - QCOMPARE(classA->typeEntry()->codeSnips().count(), 1); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + QCOMPARE(classA->typeEntry()->codeSnips().size(), 1); QString code = classA->typeEntry()->codeSnips().constFirst().code(); QVERIFY(code.indexOf(expected) != -1); - code = classA->typeEntry()->targetConversionRule(); + QVERIFY(classA->typeEntry()->isValue()); + auto vte = std::static_pointer_cast<const ValueTypeEntry>(classA->typeEntry()); + code = vte->targetConversionRule(); QVERIFY(code.indexOf(expected) != -1); } void TestCodeInjections::testInjectWithValidApiVersion() { - const char* cppCode ="struct A {};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A {};\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <value-type name='A'>\n\ <inject-code class='target' since='1.0'>\n\ @@ -100,17 +84,17 @@ void TestCodeInjections::testInjectWithValidApiVersion() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - true, QLatin1String("1.0"))); - QVERIFY(!builder.isNull()); + true, u"1.0"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - QCOMPARE(classA->typeEntry()->codeSnips().count(), 1); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + QCOMPARE(classA->typeEntry()->codeSnips().size(), 1); } void TestCodeInjections::testInjectWithInvalidApiVersion() { - const char* cppCode ="struct A {};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A {};\n"; + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <value-type name='A'>\n\ <inject-code class='target' since='1.0'>\n\ @@ -120,31 +104,28 @@ void TestCodeInjections::testInjectWithInvalidApiVersion() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - true, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + true, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - QCOMPARE(classA->typeEntry()->codeSnips().count(), 0); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + QCOMPARE(classA->typeEntry()->codeSnips().size(), 0); } void TestCodeInjections::testTextStream() { StringStream str(TextStream::Language::Cpp); - str << "void foo(int a, int b) {\n"; - { - Indentation i(str); - str << "if (a == b)\n" << indent << "return a;\n" << outdent - << "#if Q_OS_WIN\nprint()\n#endif\nreturn a + b;\n"; - } - str << "}\n\n// A table\n|" + str << "void foo(int a, int b) {\n" << indent + << "if (a == b)\n" << indent << "return a;\n" << outdent + << "#if Q_OS_WIN\nprint()\n#endif\nreturn a + b;\n" << outdent + << "}\n\n// A table\n|" << AlignedField("bla", 40, QTextStream::AlignRight) << "|\n|" << AlignedField("bla", 40, QTextStream::AlignLeft) << "|\n|" << AlignedField(QString(), 40, QTextStream::AlignLeft) << "|\n"; str << "\n2nd table\n|" << AlignedField("bla", 3, QTextStream::AlignLeft) << '|' << AlignedField(QString{}, 0, QTextStream::AlignLeft) << "|\n"; -static const char expected[] = R"(void foo(int a, int b) { +constexpr auto expected = R"(void foo(int a, int b) { if (a == b) return a; #if Q_OS_WIN @@ -160,9 +141,24 @@ static const char expected[] = R"(void foo(int a, int b) { 2nd table |bla|| -)"; +)"_L1; + + QCOMPARE(str.toString(), expected); +} + +void TestCodeInjections::testTextStreamRst() +{ + // Test that sphinx error: "Inline strong start-string without end-string." + // is avoided, that is, characters following a formatting end are escaped. + + StringStream str; + str << rstBold << "QObject" << rstBoldOff << "'s properties..." + << rstItalic << "some italic" << rstItalicOff << " followed by space."; + + static const char16_t expected[] = + uR"(**QObject**\'s properties...*some italic* followed by space.)"; - QCOMPARE(str.toString(), QLatin1String(expected)); + QCOMPARE(str.toString(), expected); } QTEST_APPLESS_MAIN(TestCodeInjections) diff --git a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.h b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.h index 05b95a11e..a164ea36e 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.h +++ b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.h @@ -1,35 +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 #ifndef TESTCODEINJECTIONS_H #define TESTCODEINJECTIONS_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; @@ -42,6 +17,7 @@ private slots: void testInjectWithValidApiVersion(); void testInjectWithInvalidApiVersion(); void testTextStream(); + void testTextStreamRst(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp b/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp index 3ee39e4ec..0bb72b3c1 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp @@ -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 #include "testcontainer.h" #include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> #include <abstractmetatype.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <containertypeentry.h> void TestContainer::testContainerType() { - const char* cppCode ="\ + const char cppCode[] = "\ namespace std {\n\ template<class T>\n\ class list {\n\ @@ -44,7 +20,7 @@ void TestContainer::testContainerType() }\n\ class A : public std::list<int> {\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='std' generate='no' />\n\ <container-type name='std::list' type='list' />\n\ @@ -52,21 +28,21 @@ void TestContainer::testContainerType() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); + QCOMPARE(classes.size(), 2); //search for class A - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); auto baseContainer = classA->typeEntry()->baseContainerType(); QVERIFY(baseContainer); - QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer)->containerKind(), + QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer.get())->containerKind(), ContainerTypeEntry::ListContainer); } void TestContainer::testListOfValueType() { - const char* cppCode ="\ + const char cppCode[] = "\ namespace std {\n\ template<class T>\n\ class list {\n\ @@ -76,7 +52,7 @@ void TestContainer::testListOfValueType() class ValueType {};\n\ class A : public std::list<ValueType> {\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='std' generate='no'/>\n\ <container-type name='std::list' type='list'/>\n\ @@ -85,13 +61,13 @@ void TestContainer::testListOfValueType() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); + QCOMPARE(classes.size(), 3); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->templateBaseClassInstantiations().count(), 1); + QCOMPARE(classA->templateBaseClassInstantiations().size(), 1); const AbstractMetaType templateInstanceType = classA->templateBaseClassInstantiations().constFirst(); diff --git a/sources/shiboken6/ApiExtractor/tests/testcontainer.h b/sources/shiboken6/ApiExtractor/tests/testcontainer.h index 44e6636aa..3fd23c3f0 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcontainer.h +++ b/sources/shiboken6/ApiExtractor/tests/testcontainer.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTCONTAINER_H #define TESTCONTAINER_H -#include <QObject> +#include <QtCore/QObject> class TestContainer : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testconversionoperator.cpp b/sources/shiboken6/ApiExtractor/tests/testconversionoperator.cpp index 32071f533..8f2b277af 100644 --- a/sources/shiboken6/ApiExtractor/tests/testconversionoperator.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testconversionoperator.cpp @@ -1,38 +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 "testconversionoperator.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestConversionOperator::testConversionOperator() { const char cppCode[] = "\ @@ -52,18 +33,18 @@ void TestConversionOperator::testConversionOperator() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - const AbstractMetaClass *classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + const auto classC = AbstractMetaClass::findClass(classes, "C"); QVERIFY(classA); QVERIFY(classB); QVERIFY(classC); - QCOMPARE(classA->functions().count(), 2); - QCOMPARE(classB->functions().count(), 3); - QCOMPARE(classC->functions().count(), 3); - QCOMPARE(classA->externalConversionOperators().count(), 2); + QCOMPARE(classA->functions().size(), 2); + QCOMPARE(classB->functions().size(), 3); + QCOMPARE(classC->functions().size(), 3); + QCOMPARE(classA->externalConversionOperators().size(), 2); AbstractMetaFunctionCPtr convOp; for (const auto &func : classB->functions()) { @@ -72,7 +53,7 @@ void TestConversionOperator::testConversionOperator() break; } } - QVERIFY(!convOp.isNull()); + QVERIFY(convOp); QVERIFY(classA->externalConversionOperators().contains(convOp)); } @@ -90,11 +71,11 @@ void TestConversionOperator::testConversionOperatorOfDiscardedClass() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->externalConversionOperators().count(), 0); + QCOMPARE(classA->externalConversionOperators().size(), 0); } void TestConversionOperator::testRemovedConversionOperator() @@ -114,16 +95,16 @@ void TestConversionOperator::testRemovedConversionOperator() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classA); QVERIFY(classB); - QCOMPARE(classA->functions().count(), 2); - QCOMPARE(classB->functions().count(), 3); - QCOMPARE(classA->externalConversionOperators().count(), 0); - QCOMPARE(classA->implicitConversions().count(), 0); + QCOMPARE(classA->functions().size(), 2); + QCOMPARE(classB->functions().size(), 3); + QCOMPARE(classA->externalConversionOperators().size(), 0); + QCOMPARE(classA->implicitConversions().size(), 0); } void TestConversionOperator::testConversionOperatorReturningReference() @@ -140,24 +121,24 @@ void TestConversionOperator::testConversionOperatorReturningReference() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classA); QVERIFY(classB); - QCOMPARE(classA->functions().count(), 2); - QCOMPARE(classB->functions().count(), 3); - QCOMPARE(classA->externalConversionOperators().count(), 1); + QCOMPARE(classA->functions().size(), 2); + QCOMPARE(classB->functions().size(), 3); + QCOMPARE(classA->externalConversionOperators().size(), 1); QCOMPARE(classA->externalConversionOperators().constFirst()->type().cppSignature(), - QLatin1String("A")); + u"A"); QCOMPARE(classA->externalConversionOperators().constFirst()->ownerClass()->name(), - QLatin1String("B")); - QCOMPARE(classA->implicitConversions().count(), 1); + u"B"); + QCOMPARE(classA->implicitConversions().size(), 1); QCOMPARE(classA->implicitConversions().constFirst()->type().cppSignature(), - QLatin1String("A")); + u"A"); QCOMPARE(classA->implicitConversions().constFirst()->ownerClass()->name(), - QLatin1String("B")); + u"B"); } void TestConversionOperator::testConversionOperatorReturningConstReference() @@ -174,24 +155,24 @@ void TestConversionOperator::testConversionOperatorReturningConstReference() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classA); QVERIFY(classB); - QCOMPARE(classA->functions().count(), 2); - QCOMPARE(classB->functions().count(), 3); - QCOMPARE(classA->externalConversionOperators().count(), 1); + QCOMPARE(classA->functions().size(), 2); + QCOMPARE(classB->functions().size(), 3); + QCOMPARE(classA->externalConversionOperators().size(), 1); QCOMPARE(classA->externalConversionOperators().constFirst()->type().cppSignature(), - QLatin1String("A")); + u"A"_s); QCOMPARE(classA->externalConversionOperators().constFirst()->ownerClass()->name(), - QLatin1String("B")); - QCOMPARE(classA->implicitConversions().count(), 1); + u"B"_s); + QCOMPARE(classA->implicitConversions().size(), 1); QCOMPARE(classA->implicitConversions().constFirst()->type().cppSignature(), - QLatin1String("A")); + u"A"_s); QCOMPARE(classA->implicitConversions().constFirst()->ownerClass()->name(), - QLatin1String("B")); + u"B"_s); } QTEST_APPLESS_MAIN(TestConversionOperator) diff --git a/sources/shiboken6/ApiExtractor/tests/testconversionoperator.h b/sources/shiboken6/ApiExtractor/tests/testconversionoperator.h index b571a57a0..68288d240 100644 --- a/sources/shiboken6/ApiExtractor/tests/testconversionoperator.h +++ b/sources/shiboken6/ApiExtractor/tests/testconversionoperator.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTCONVERSIONOPERATOR_H #define TESTCONVERSIONOPERATOR_H -#include <QObject> +#include <QtCore/QObject> class TestConversionOperator : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp index 1f244bd83..b5efd92a6 100644 --- a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp @@ -1,64 +1,49 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testconversionruletag.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> -#include <typesystem.h> -#include <QFile> -#include <QTemporaryFile> +#include <complextypeentry.h> +#include <customconversion.h> +#include <primitivetypeentry.h> +#include <valuetypeentry.h> + +#include <qtcompat.h> + +#include <QtCore/QFile> +#include <QtCore/QTemporaryFile> +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; void TestConversionRuleTag::testConversionRuleTagWithFile() { // FIXME PYSIDE7 remove // temp file used later - const char conversionData[] = "Hi! I'm a conversion rule."; + constexpr auto conversionData = "Hi! I'm a conversion rule."_L1; QTemporaryFile file; - file.open(); - QCOMPARE(file.write(conversionData), qint64(sizeof(conversionData)-1)); + QVERIFY(file.open()); + QCOMPARE(file.write(conversionData.constData()), conversionData.size()); file.close(); const char cppCode[] = "struct A {};\n"; - QString xmlCode = QLatin1String("\ + QString xmlCode = u"\ <typesystem package='Foo'>\n\ <value-type name='A'>\n\ - <conversion-rule class='target' file='") + file.fileName() + QLatin1String("'/>\n\ + <conversion-rule class='target' file='"_s + file.fileName() + u"'/>\n\ </value-type>\n\ - </typesystem>\n"); + </typesystem>\n"_s; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode.toLocal8Bit().data())); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const ComplexTypeEntry* typeEntry = classA->typeEntry(); - QVERIFY(typeEntry->hasTargetConversionRule()); - QCOMPARE(typeEntry->targetConversionRule(), QLatin1String(conversionData)); + const auto typeEntry = classA->typeEntry(); + QVERIFY(typeEntry->isValue()); + auto vte = std::static_pointer_cast<const ValueTypeEntry>(typeEntry); + QVERIFY(vte->hasTargetConversionRule()); + QCOMPARE(vte->targetConversionRule(), conversionData); } void TestConversionRuleTag::testConversionRuleTagReplace() @@ -71,7 +56,7 @@ void TestConversionRuleTag::testConversionRuleTagReplace() struct B {\n\ A createA();\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <primitive-type name='char'/>\n\ @@ -100,48 +85,49 @@ void TestConversionRuleTag::testConversionRuleTagReplace() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); - TypeDatabase* typeDb = TypeDatabase::instance(); - PrimitiveTypeEntry* typeA = typeDb->findPrimitiveType(QLatin1String("A")); + QVERIFY(builder); + auto *typeDb = TypeDatabase::instance(); + auto typeA = typeDb->findPrimitiveType(u"A"_s); QVERIFY(typeA); - CustomConversion* conversion = typeA->customConversion(); - QVERIFY(conversion); + QVERIFY(typeA->hasCustomConversion()); + auto conversion = typeA->customConversion(); QCOMPARE(typeA, conversion->ownerType()); QCOMPARE(conversion->nativeToTargetConversion().simplified(), - QLatin1String("DoThis(); return ConvertFromCppToPython(%IN);")); + u"DoThis(); return ConvertFromCppToPython(%IN);"); QVERIFY(conversion->replaceOriginalTargetToNativeConversions()); QVERIFY(conversion->hasTargetToNativeConversions()); QCOMPARE(conversion->targetToNativeConversions().size(), 3); - CustomConversion::TargetToNativeConversion* toNative = conversion->targetToNativeConversions().at(0); - QVERIFY(toNative); - QCOMPARE(toNative->sourceTypeName(), QLatin1String("TargetNone")); - QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), nullptr); - QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("%IN == Target_None")); - QCOMPARE(toNative->conversion().simplified(), - QLatin1String("DoThat(); DoSomething(); %OUT = A();")); + QVERIFY(!conversion->targetToNativeConversions().isEmpty()); + auto toNative = conversion->targetToNativeConversions().at(0); + QCOMPARE(toNative.sourceTypeName(), u"TargetNone"); + QVERIFY(toNative.isCustomType()); + QCOMPARE(toNative.sourceType(), nullptr); + QCOMPARE(toNative.sourceTypeCheck(), u"%IN == Target_None"); + QCOMPARE(toNative.conversion().simplified(), + u"DoThat(); DoSomething(); %OUT = A();"); + QVERIFY(conversion->targetToNativeConversions().size() > 1); toNative = conversion->targetToNativeConversions().at(1); - QVERIFY(toNative); - QCOMPARE(toNative->sourceTypeName(), QLatin1String("B")); - QVERIFY(!toNative->isCustomType()); - TypeEntry* typeB = typeDb->findType(QLatin1String("B")); + QCOMPARE(toNative.sourceTypeName(), u"B"); + QVERIFY(!toNative.isCustomType()); + auto typeB = typeDb->findType(u"B"_s); QVERIFY(typeB); - QCOMPARE(toNative->sourceType(), typeB); - QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("CheckIfInputObjectIsB(%IN)")); - QCOMPARE(toNative->conversion().trimmed(), QLatin1String("%OUT = %IN.createA();")); + QCOMPARE(toNative.sourceType(), typeB); + QCOMPARE(toNative.sourceTypeCheck(), u"CheckIfInputObjectIsB(%IN)"); + QCOMPARE(toNative.conversion().trimmed(), u"%OUT = %IN.createA();"); + QVERIFY(conversion->targetToNativeConversions().size() > 2); toNative = conversion->targetToNativeConversions().at(2); - QVERIFY(toNative); - QCOMPARE(toNative->sourceTypeName(), QLatin1String("String")); - QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), nullptr); - QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("String_Check(%IN)")); - QCOMPARE(toNative->conversion().trimmed(), QLatin1String("%OUT = new A(String_AsString(%IN), String_GetSize(%IN));")); + QCOMPARE(toNative.sourceTypeName(), u"String"); + QVERIFY(toNative.isCustomType()); + QCOMPARE(toNative.sourceType(), nullptr); + QCOMPARE(toNative.sourceTypeCheck(), u"String_Check(%IN)"); + QCOMPARE(toNative.conversion().trimmed(), + u"%OUT = new A(String_AsString(%IN), String_GetSize(%IN));"); } void TestConversionRuleTag::testConversionRuleTagAdd() @@ -151,7 +137,7 @@ void TestConversionRuleTag::testConversionRuleTagAdd() Date();\n\ Date(int, int, int);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <value-type name='Date'>\n\ @@ -167,12 +153,14 @@ if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("Date")); + QVERIFY(builder); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "Date"); QVERIFY(classA); - CustomConversion* conversion = classA->typeEntry()->customConversion(); - QVERIFY(conversion); + QVERIFY(classA->typeEntry()->isValue()); + auto vte = std::static_pointer_cast<const ValueTypeEntry>(classA->typeEntry()); + QVERIFY(vte->hasCustomConversion()); + auto conversion = vte->customConversion(); QCOMPARE(conversion->nativeToTargetConversion(), QString()); @@ -180,21 +168,21 @@ if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n\ QVERIFY(conversion->hasTargetToNativeConversions()); QCOMPARE(conversion->targetToNativeConversions().size(), 1); - CustomConversion::TargetToNativeConversion *toNative = - conversion->targetToNativeConversions().constFirst(); - QVERIFY(toNative); - QCOMPARE(toNative->sourceTypeName(), QLatin1String("TargetDate")); - QVERIFY(toNative->isCustomType()); - QCOMPARE(toNative->sourceType(), nullptr); - QCOMPARE(toNative->sourceTypeCheck(), QLatin1String("TargetDate_Check(%IN)")); - QCOMPARE(toNative->conversion().trimmed(), - QLatin1String("if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n%OUT = new Date(TargetDate_Day(%IN), TargetDate_Month(%IN), TargetDate_Year(%IN));")); + QVERIFY(!conversion->targetToNativeConversions().isEmpty()); + const auto &toNative = conversion->targetToNativeConversions().constFirst(); + QCOMPARE(toNative.sourceTypeName(), u"TargetDate"); + QVERIFY(toNative.isCustomType()); + QCOMPARE(toNative.sourceType(), nullptr); + QCOMPARE(toNative.sourceTypeCheck(), u"TargetDate_Check(%IN)"); + QCOMPARE(toNative.conversion().trimmed(), + uR"(if (!TargetDateTimeAPI) TargetDateTime_IMPORT; +%OUT = new Date(TargetDate_Day(%IN), TargetDate_Month(%IN), TargetDate_Year(%IN));)"); } void TestConversionRuleTag::testConversionRuleTagWithInsertTemplate() { const char cppCode[] = "struct A {};"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <!-- single line -->\n\ @@ -228,25 +216,25 @@ void TestConversionRuleTag::testConversionRuleTagWithInsertTemplate() "// TEMPLATE - target_to_native - END"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); - TypeDatabase* typeDb = TypeDatabase::instance(); - PrimitiveTypeEntry* typeA = typeDb->findPrimitiveType(QLatin1String("A")); + QVERIFY(builder); + auto *typeDb = TypeDatabase::instance(); + auto typeA = typeDb->findPrimitiveType(u"A"_s); QVERIFY(typeA); - CustomConversion* conversion = typeA->customConversion(); - QVERIFY(conversion); + QVERIFY(typeA->hasCustomConversion()); + auto conversion = typeA->customConversion(); QCOMPARE(typeA, conversion->ownerType()); QCOMPARE(conversion->nativeToTargetConversion().trimmed(), - QLatin1String(nativeToTargetExpected)); + QLatin1StringView(nativeToTargetExpected)); QVERIFY(conversion->hasTargetToNativeConversions()); QCOMPARE(conversion->targetToNativeConversions().size(), 1); - CustomConversion::TargetToNativeConversion* toNative = conversion->targetToNativeConversions().constFirst(); - QVERIFY(toNative); - QCOMPARE(toNative->conversion().trimmed(), - QLatin1String(targetToNativeExpected)); + QVERIFY(!conversion->targetToNativeConversions().isEmpty()); + const auto &toNative = conversion->targetToNativeConversions().constFirst(); + QCOMPARE(toNative.conversion().trimmed(), + QLatin1StringView(targetToNativeExpected)); } QTEST_APPLESS_MAIN(TestConversionRuleTag) diff --git a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.h b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.h index 894bd3d71..64d496cc3 100644 --- a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.h +++ b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.h @@ -1,34 +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 #ifndef TESTCONVERSIONRULE_H #define TESTCONVERSIONRULE_H -#include <QObject> + +#include <QtCore/QObject> class TestConversionRuleTag : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testctorinformation.cpp b/sources/shiboken6/ApiExtractor/tests/testctorinformation.cpp index 7718d3df6..c3a3ebef0 100644 --- a/sources/shiboken6/ApiExtractor/tests/testctorinformation.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testctorinformation.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 "testctorinformation.h" #include "abstractmetabuilder.h" @@ -35,41 +10,47 @@ void TestCtorInformation::testCtorIsPrivate() { - const char* cppCode = "class Control { public: Control() {} };\n\ + const char cppCode[] = "class Control { public: Control() {} };\n\ class Subject { private: Subject() {} };\n\ class CtorLess { };\n"; - const char* xmlCode = "<typesystem package='Foo'>\n\ + const char xmlCode[] = "<typesystem package='Foo'>\n\ <value-type name='Control'/>\n\ <object-type name='Subject'/>\n\ <value-type name='CtorLess'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Control"))->hasNonPrivateConstructor(), true); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Subject"))->hasNonPrivateConstructor(), false); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("CtorLess"))->hasNonPrivateConstructor(), true); + QCOMPARE(classes.size(), 3); + auto klass = AbstractMetaClass::findClass(classes, "Control"); + QVERIFY(klass); + QVERIFY(klass->hasNonPrivateConstructor()); + klass = AbstractMetaClass::findClass(classes, "Subject"); + QVERIFY(klass); + QVERIFY(!klass->hasNonPrivateConstructor()); + klass = AbstractMetaClass::findClass(classes, "CtorLess"); + QVERIFY(klass); + QVERIFY(klass->hasNonPrivateConstructor()); } void TestCtorInformation::testHasNonPrivateCtor() { - const char* cppCode = "template<typename T>\n\ + const char cppCode[] = "template<typename T>\n\ struct Base { Base(double) {} };\n\ typedef Base<int> Derived;\n"; - const char* xmlCode = "<typesystem package='Foo'>\n\ + const char xmlCode[] = "<typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <primitive-type name='double'/>\n\ <object-type name='Base' generate='no'/>\n\ <object-type name='Derived'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - const AbstractMetaClass *base = AbstractMetaClass::findClass(classes, QLatin1String("Base")); + QCOMPARE(classes.size(), 2); + const auto base = AbstractMetaClass::findClass(classes, "Base"); QCOMPARE(base->hasNonPrivateConstructor(), true); - const AbstractMetaClass *derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived")); + const auto derived = AbstractMetaClass::findClass(classes, "Derived"); QCOMPARE(derived->hasNonPrivateConstructor(), true); } diff --git a/sources/shiboken6/ApiExtractor/tests/testctorinformation.h b/sources/shiboken6/ApiExtractor/tests/testctorinformation.h index ee655d450..58f1648e4 100644 --- a/sources/shiboken6/ApiExtractor/tests/testctorinformation.h +++ b/sources/shiboken6/ApiExtractor/tests/testctorinformation.h @@ -1,35 +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 #ifndef TESTCTORINFORMATION_H #define TESTCTORINFORMATION_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; diff --git a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp index 1b03f9353..16f50e69d 100644 --- a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.cpp @@ -1,40 +1,20 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testdroptypeentries.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetaenum.h> #include <abstractmetalang.h> #include <typesystem.h> #include <conditionalstreamreader.h> -static const char* cppCode ="\ +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + +static const char cppCode[] = "\ struct ValueA {};\n\ struct ValueB {};\n\ struct ObjectA {};\n\ @@ -49,7 +29,7 @@ static const char* cppCode ="\ void funcA();\n\ void funcB();\n"; -static const char* xmlCode = "\ +static const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <value-type name='ValueA'/>\n\ <value-type name='ValueB'/>\n\ @@ -68,61 +48,61 @@ static const char* xmlCode = "\ void TestDropTypeEntries::testDropEntries() { - const QStringList droppedEntries{QLatin1String("Foo.ValueB"), - QLatin1String("ObjectB"), // Check whether module can be omitted - QLatin1String("Foo.NamespaceA.InnerClassA"), - QLatin1String("Foo.NamespaceB"), QLatin1String("Foo.EnumB"), - QLatin1String("Foo.funcB()"), - QLatin1String("Foo.NamespaceA.InnerNamespaceA")}; + const QStringList droppedEntries{u"Foo.ValueB"_s, + u"ObjectB"_s, // Check whether module can be omitted + u"Foo.NamespaceA.InnerClassA"_s, + u"Foo.NamespaceB"_s, u"Foo.EnumB"_s, + u"Foo.funcB()"_s, + u"Foo.NamespaceA.InnerNamespaceA"_s}; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false, QString(), droppedEntries)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ValueA"))); - QVERIFY(!AbstractMetaClass::findClass(classes, QLatin1String("ValueB"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ObjectA"))); - QVERIFY(!AbstractMetaClass::findClass(classes, QLatin1String("ObjectB"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("NamespaceA"))); - QVERIFY(!AbstractMetaClass::findClass(classes, QLatin1String("NamespaceA::InnerClassA"))); - QVERIFY(!AbstractMetaClass::findClass(classes, QLatin1String("NamespaceB"))); + QVERIFY(AbstractMetaClass::findClass(classes, "ValueA")); + QVERIFY(!AbstractMetaClass::findClass(classes, "ValueB")); + QVERIFY(AbstractMetaClass::findClass(classes, "ObjectA")); + QVERIFY(!AbstractMetaClass::findClass(classes, "ObjectB")); + QVERIFY(AbstractMetaClass::findClass(classes, "NamespaceA")); + QVERIFY(!AbstractMetaClass::findClass(classes, "NamespaceA::InnerClassA")); + QVERIFY(!AbstractMetaClass::findClass(classes, "NamespaceB")); AbstractMetaEnumList globalEnums = builder->globalEnums(); - QCOMPARE(globalEnums.count(), 1); - QCOMPARE(globalEnums.constFirst().name(), QLatin1String("EnumA")); + QCOMPARE(globalEnums.size(), 1); + QCOMPARE(globalEnums.constFirst().name(), u"EnumA"); - TypeDatabase* td = TypeDatabase::instance(); - QVERIFY(td->findType(QLatin1String("funcA"))); - QVERIFY(!td->findType(QLatin1String("funcB"))); + auto *td = TypeDatabase::instance(); + QVERIFY(td->findType(u"funcA"_s)); + QVERIFY(!td->findType(u"funcB"_s)); } void TestDropTypeEntries::testDontDropEntries() { QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ValueA"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ValueB"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ObjectA"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("ObjectB"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("NamespaceA"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("NamespaceA::InnerClassA"))); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("NamespaceB"))); + QVERIFY(AbstractMetaClass::findClass(classes, "ValueA")); + QVERIFY(AbstractMetaClass::findClass(classes, "ValueB")); + QVERIFY(AbstractMetaClass::findClass(classes, "ObjectA")); + QVERIFY(AbstractMetaClass::findClass(classes, "ObjectB")); + QVERIFY(AbstractMetaClass::findClass(classes, "NamespaceA")); + QVERIFY(AbstractMetaClass::findClass(classes, "NamespaceA::InnerClassA")); + QVERIFY(AbstractMetaClass::findClass(classes, "NamespaceB")); QCOMPARE(builder->globalEnums().size(), 2); - TypeDatabase* td = TypeDatabase::instance(); - QVERIFY(td->findType(QLatin1String("funcA"))); - QVERIFY(td->findType(QLatin1String("funcB"))); + auto *td = TypeDatabase::instance(); + QVERIFY(td->findType(u"funcA"_s)); + QVERIFY(td->findType(u"funcB"_s)); } -static const char* cppCode2 ="\ +static const char cppCode2[] = "\ struct ValueA {\n\ void func();\n\ };\n"; -static const char* xmlCode2 = R"( +static const char xmlCode2[] = R"( <typesystem package='Foo'> <value-type name='ValueA'> <modify-function signature='func()' remove='all'/> @@ -132,24 +112,24 @@ static const char* xmlCode2 = R"( void TestDropTypeEntries::testDropEntryWithChildTags() { - QStringList droppedEntries(QLatin1String("Foo.ValueA")); + QStringList droppedEntries(u"Foo.ValueA"_s); QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode2, xmlCode2, false, QString(), droppedEntries)); - QVERIFY(!builder.isNull()); - QVERIFY(!AbstractMetaClass::findClass(builder->classes(), QLatin1String("ValueA"))); + QVERIFY(builder); + QVERIFY(!AbstractMetaClass::findClass(builder->classes(), "ValueA")); } void TestDropTypeEntries::testDontDropEntryWithChildTags() { QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode2, xmlCode2, false)); - QVERIFY(!builder.isNull()); - QVERIFY(AbstractMetaClass::findClass(builder->classes(), QLatin1String("ValueA"))); + QVERIFY(builder); + QVERIFY(AbstractMetaClass::findClass(builder->classes(), "ValueA")); } void TestDropTypeEntries::testConditionalParsing_data() { - const QString xml = QStringLiteral(R"(<?xml version="1.0" encoding="UTF-8"?> + const QString xml = R"(<?xml version="1.0" encoding="UTF-8"?> <root> <tag1>text</tag1> <?if keyword1?> @@ -162,31 +142,35 @@ void TestDropTypeEntries::testConditionalParsing_data() <?endif?> <?endif?> <tag5>text</tag5> -</root>)"); - - const QString root = QStringLiteral("root"); - const QString tag1 = QStringLiteral("tag1"); - const QString tag2 = QStringLiteral("tag2"); - const QString tag3 = QStringLiteral("tag3"); - const QString tag4 = QStringLiteral("tag4"); - const QString tag5 = QStringLiteral("tag5"); - const QString keyword1 = QStringLiteral("keyword1"); - const QString keyword2 = QStringLiteral("keyword2"); + <?if !keyword99?> <!-- Exclusion only --> + <tag6>text</tag6> + <?endif?> +</root>)"_L1; + + constexpr auto root = "root"_L1; + constexpr auto tag1 = "tag1"_L1; + constexpr auto tag2 = "tag2"_L1; + constexpr auto tag3 = "tag3"_L1; + constexpr auto tag4 = "tag4"_L1; + constexpr auto tag5 = "tag5"_L1; + constexpr auto tag6 = "tag6"_L1; + constexpr auto keyword1 = "keyword1"_L1; + constexpr auto keyword2 = "keyword2"_L1; QTest::addColumn<QString>("xml"); QTest::addColumn<QStringList>("keywords"); QTest::addColumn<QStringList>("expectedTags"); QTest::newRow("no-keywords") - << xml << QStringList{} << QStringList{root, tag1, tag5}; + << xml << QStringList{} << QStringList{root, tag1, tag5, tag6}; QTest::newRow("skip-nested-condition") << xml << QStringList{keyword1} - << QStringList{root, tag1, tag2, tag4, tag5}; + << QStringList{root, tag1, tag2, tag4, tag5, tag6}; QTest::newRow("both/check-not") << xml << QStringList{keyword1, keyword2} - << QStringList{root, tag1, tag2, tag3, tag5}; + << QStringList{root, tag1, tag2, tag3, tag5, tag6}; } // Parse XML and return a list of tags encountered @@ -218,4 +202,27 @@ void TestDropTypeEntries::testConditionalParsing() QCOMPARE(actualTags, expectedTags); } +void TestDropTypeEntries::testEntityParsing() +{ + const QString xml = R"(<?xml version="1.0" encoding="UTF-8"?> +<root> + <?entity testentity word1 word2?> + <text>bla &testentity;</text> +</root>)"_L1; + + QString actual; + ConditionalStreamReader reader(xml); + while (!reader.atEnd()) { + auto t = reader.readNext(); + switch (t) { + case QXmlStreamReader::Characters: + actual.append(reader.text()); + default: + break; + } + } + QVERIFY2(!reader.hasError(), qPrintable(reader.errorString())); + QCOMPARE(actual.trimmed(), u"bla word1 word2"); +} + QTEST_APPLESS_MAIN(TestDropTypeEntries) diff --git a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.h b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.h index 7746234ba..98717bd21 100644 --- a/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.h +++ b/sources/shiboken6/ApiExtractor/tests/testdroptypeentries.h @@ -1,35 +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 #ifndef TESTDROPTYPEENTRIES_H #define TESTDROPTYPEENTRIES_H -#include <QObject> +#include <QtCore/QObject> class TestDropTypeEntries : public QObject { @@ -41,6 +16,7 @@ class TestDropTypeEntries : public QObject void testDontDropEntryWithChildTags(); void testConditionalParsing_data(); void testConditionalParsing(); + void testEntityParsing(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testdtorinformation.cpp b/sources/shiboken6/ApiExtractor/tests/testdtorinformation.cpp index 0eee8af24..2152d39de 100644 --- a/sources/shiboken6/ApiExtractor/tests/testdtorinformation.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testdtorinformation.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 "testdtorinformation.h" #include "abstractmetabuilder.h" @@ -35,83 +10,147 @@ void TestDtorInformation::testDtorIsPrivate() { - const char* cppCode ="class Control { public: ~Control() {} }; class Subject { private: ~Subject() {} };"; - const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + const char cppCode[] = R"(class Control { +public: + ~Control() {} +}; +class Subject { +private: + ~Subject() {} +}; +)"; + const char xmlCode[] = R"(<typesystem package="Foo"> + <value-type name="Control"/> + <value-type name="Subject"/> +</typesystem>)"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Control"))->hasPrivateDestructor(), false); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Subject"))->hasPrivateDestructor(), true); + QCOMPARE(classes.size(), 2); + auto klass = AbstractMetaClass::findClass(classes, "Control"); + QVERIFY(klass); + QVERIFY(!klass->hasPrivateDestructor()); + klass = AbstractMetaClass::findClass(classes, "Subject"); + QVERIFY(klass); + QVERIFY(klass->hasPrivateDestructor()); } void TestDtorInformation::testDtorIsProtected() { - const char* cppCode ="class Control { public: ~Control() {} }; class Subject { protected: ~Subject() {} };"; - const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + const char cppCode[] = R"(class Control { +public: + ~Control() {} +}; +class Subject { +protected: + ~Subject() {} +}; +)"; + const char xmlCode[] = R"(<typesystem package="Foo"> + <value-type name="Control"/> + <value-type name="Subject"/> +</typesystem>)"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Control"))->hasProtectedDestructor(), false); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Subject"))->hasProtectedDestructor(), true); + QCOMPARE(classes.size(), 2); + auto klass = AbstractMetaClass::findClass(classes, "Control"); + QVERIFY(klass); + QVERIFY(!klass->hasProtectedDestructor()); + klass = AbstractMetaClass::findClass(classes, "Subject"); + QVERIFY(klass); + QVERIFY(klass->hasProtectedDestructor()); } void TestDtorInformation::testDtorIsVirtual() { - const char* cppCode ="class Control { public: ~Control() {} }; class Subject { protected: virtual ~Subject() {} };"; - const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + const char cppCode[] = R"(class Control { +public: + ~Control() {} +}; +class Subject { +protected: + virtual ~Subject() {} +}; +)"; + const char xmlCode[] = R"(<typesystem package="Foo"> + <value-type name="Control"/> + <value-type name="Subject"/> +</typesystem>)"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Control"))->hasVirtualDestructor(), false); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Subject"))->hasVirtualDestructor(), true); + QCOMPARE(classes.size(), 2); + auto klass = AbstractMetaClass::findClass(classes, "Control"); + QVERIFY(klass); + QVERIFY(!klass->hasVirtualDestructor()); + klass = AbstractMetaClass::findClass(classes, "Subject"); + QVERIFY(klass); + QVERIFY(klass->hasVirtualDestructor()); } void TestDtorInformation::testDtorFromBaseIsVirtual() { - const char* cppCode = R"CPP(class ControlBase { public: ~ControlBase() {} }; + const char cppCode[] = R"CPP(class ControlBase { public: ~ControlBase() {} }; class Control : public ControlBase {}; class SubjectBase { public: virtual ~SubjectBase() {} }; class Subject : public SubjectBase {}; )CPP"; - const char* xmlCode = R"XML(<typesystem package="Foo"><value-type name="ControlBase"/> + const char xmlCode[] = R"XML(<typesystem package="Foo"><value-type name="ControlBase"/> <value-type name="Control"/>" <value-type name="SubjectBase"/>" <value-type name="Subject"/> </typesystem> )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 4); + QCOMPARE(classes.size(), 4); - auto klass = AbstractMetaClass::findClass(classes, QLatin1String("ControlBase")); + auto klass = AbstractMetaClass::findClass(classes, "ControlBase"); QVERIFY(klass); QVERIFY(!klass->hasVirtualDestructor()); - klass = AbstractMetaClass::findClass(classes, QLatin1String("Control")); + klass = AbstractMetaClass::findClass(classes, "Control"); QVERIFY(klass); QVERIFY(!klass->hasVirtualDestructor()); - klass = AbstractMetaClass::findClass(classes, QLatin1String("SubjectBase")); + klass = AbstractMetaClass::findClass(classes, "SubjectBase"); QVERIFY(klass); QVERIFY(klass->hasVirtualDestructor()); - klass = AbstractMetaClass::findClass(classes, QLatin1String("Subject")); + klass = AbstractMetaClass::findClass(classes, "Subject"); QVERIFY(klass); QVERIFY(klass->hasVirtualDestructor()); } void TestDtorInformation::testClassWithVirtualDtorIsPolymorphic() { - const char* cppCode ="class Control { public: virtual ~Control() {} }; class Subject { protected: virtual ~Subject() {} };"; - const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"Control\"/><value-type name=\"Subject\"/></typesystem>"; + const char cppCode[] = R"(class Control { +public: + virtual ~Control() {} +}; +class Subject { +protected: + virtual ~Subject() {} +}; +)"; + const char xmlCode[] = R"(<typesystem package="Foo"> + <value-type name="Control"/> + <value-type name="Subject"/> +</typesystem>)"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Control"))->isPolymorphic(), true); - QCOMPARE(AbstractMetaClass::findClass(classes, QLatin1String("Subject"))->isPolymorphic(), true); + QCOMPARE(classes.size(), 2); + auto klass = AbstractMetaClass::findClass(classes, "Control"); + QVERIFY(klass); + QVERIFY(klass->isPolymorphic()); + klass = AbstractMetaClass::findClass(classes, "Subject"); + QVERIFY(klass); + QVERIFY(klass->isPolymorphic()); } QTEST_APPLESS_MAIN(TestDtorInformation) diff --git a/sources/shiboken6/ApiExtractor/tests/testdtorinformation.h b/sources/shiboken6/ApiExtractor/tests/testdtorinformation.h index 0a57dd8d1..0f8cb59b3 100644 --- a/sources/shiboken6/ApiExtractor/tests/testdtorinformation.h +++ b/sources/shiboken6/ApiExtractor/tests/testdtorinformation.h @@ -1,35 +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 #ifndef TESTDTORINFORMATION_H #define TESTDTORINFORMATION_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; diff --git a/sources/shiboken6/ApiExtractor/tests/testenum.cpp b/sources/shiboken6/ApiExtractor/tests/testenum.cpp index df744e994..c7c2b8b3b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testenum.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testenum.cpp @@ -1,43 +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 "testenum.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetaenum.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetabuilder_p.h> +#include <enumtypeentry.h> +#include <flagstypeentry.h> #include <parser/enumvalue.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestEnum::testEnumCppSignature() { - const char* cppCode ="\ + const char cppCode[] = "\ enum GlobalEnum { A, B };\n\ \n\ struct A {\n\ @@ -45,7 +28,7 @@ void TestEnum::testEnumCppSignature() void method(ClassEnum);\n\ };\n\ void func(A::ClassEnum);\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <enum-type name='GlobalEnum'/>\n\ <value-type name='A'>\n\ @@ -55,52 +38,52 @@ void TestEnum::testEnumCppSignature() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); + QCOMPARE(classes.size(), 1); AbstractMetaEnumList globalEnums = builder->globalEnums(); - QCOMPARE(globalEnums.count(), 1); - QCOMPARE(globalEnums.constFirst().name(), QLatin1String("GlobalEnum")); + QCOMPARE(globalEnums.size(), 1); + QCOMPARE(globalEnums.constFirst().name(), u"GlobalEnum"); // enum as parameter of a function const auto functions = builder->globalFunctions(); - QCOMPARE(functions.count(), 1); - QCOMPARE(functions.constFirst()->arguments().count(), 1); + QCOMPARE(functions.size(), 1); + QCOMPARE(functions.constFirst()->arguments().size(), 1); QCOMPARE(functions.constFirst()->arguments().constFirst().type().cppSignature(), - QLatin1String("A::ClassEnum")); + u"A::ClassEnum"); // enum as parameter of a method - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - QCOMPARE(classA->enums().count(), 1); - const auto funcs = classA->queryFunctionsByName(QLatin1String("method")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + QCOMPARE(classA->enums().size(), 1); + const auto funcs = classA->queryFunctionsByName(u"method"_s); QVERIFY(!funcs.isEmpty()); const auto method = funcs.constFirst(); AbstractMetaArgument arg = method->arguments().constFirst(); - QCOMPARE(arg.type().name(), QLatin1String("ClassEnum")); - QCOMPARE(arg.type().cppSignature(), QLatin1String("A::ClassEnum")); - QCOMPARE(functions.constFirst()->arguments().count(), 1); + QCOMPARE(arg.type().name(), u"ClassEnum"); + QCOMPARE(arg.type().cppSignature(), u"A::ClassEnum"); + QCOMPARE(functions.constFirst()->arguments().size(), 1); arg = functions.constFirst()->arguments().constFirst(); - QCOMPARE(arg.type().name(), QLatin1String("ClassEnum")); - QCOMPARE(arg.type().cppSignature(), QLatin1String("A::ClassEnum")); + QCOMPARE(arg.type().name(), u"ClassEnum"); + QCOMPARE(arg.type().cppSignature(), u"A::ClassEnum"); AbstractMetaEnumList classEnums = classA->enums(); QVERIFY(!classEnums.isEmpty()); - QCOMPARE(classEnums.constFirst().name(), QLatin1String("ClassEnum")); - auto e = AbstractMetaClass::findEnumValue(classes, QLatin1String("CA")); + QCOMPARE(classEnums.constFirst().name(), u"ClassEnum"); + auto e = AbstractMetaClass::findEnumValue(classes, u"CA"_s); QVERIFY(e.has_value()); - e = AbstractMetaClass::findEnumValue(classes, QLatin1String("ClassEnum::CA")); + e = AbstractMetaClass::findEnumValue(classes, u"ClassEnum::CA"_s); QVERIFY(e.has_value()); } void TestEnum::testEnumWithApiVersion() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ enum ClassEnum { EnumA, EnumB };\n\ enum ClassEnum2 { EnumC, EnumD };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <value-type name='A'>\n\ <enum-type name='ClassEnum' since='0.1'/>\n\ @@ -109,22 +92,22 @@ void TestEnum::testEnumWithApiVersion() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - true, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + true, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - QCOMPARE(classes[0]->enums().count(), 1); + QCOMPARE(classes.size(), 1); + QCOMPARE(classes[0]->enums().size(), 1); } void TestEnum::testAnonymousEnum() { - const char* cppCode ="\ + const char cppCode[] = "\ enum { Global0, Global1 };\n\ struct A {\n\ enum { A0, A1 };\n\ enum { isThis = true, isThat = false };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <!-- Uses the first value of the enum to identify it. -->\n\ <enum-type identified-by-value='Global0'/>\n\ @@ -136,101 +119,101 @@ void TestEnum::testAnonymousEnum() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaEnumList globalEnums = builder->globalEnums(); - QCOMPARE(globalEnums.count(), 1); + QCOMPARE(globalEnums.size(), 1); QCOMPARE(globalEnums.constFirst().typeEntry()->qualifiedCppName(), - QLatin1String("Global0")); + u"Global0"); QVERIFY(globalEnums.constFirst().isAnonymous()); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - QCOMPARE(classes[0]->enums().count(), 2); + QCOMPARE(classes.size(), 1); + QCOMPARE(classes[0]->enums().size(), 2); - auto anonEnumA1 = classes[0]->findEnum(QLatin1String("A1")); + auto anonEnumA1 = classes[0]->findEnum(u"A1"_s); QVERIFY(anonEnumA1.has_value()); QVERIFY(anonEnumA1->isAnonymous()); - QCOMPARE(anonEnumA1->typeEntry()->qualifiedCppName(), QLatin1String("A::A1")); + QCOMPARE(anonEnumA1->typeEntry()->qualifiedCppName(), u"A::A1"); AbstractMetaEnumValue enumValueA0 = anonEnumA1->values().constFirst(); - QCOMPARE(enumValueA0.name(), QLatin1String("A0")); + QCOMPARE(enumValueA0.name(), u"A0"); QCOMPARE(enumValueA0.value().value(), 0); QCOMPARE(enumValueA0.stringValue(), QString()); AbstractMetaEnumValue enumValueA1 = anonEnumA1->values().constLast(); - QCOMPARE(enumValueA1.name(), QLatin1String("A1")); + QCOMPARE(enumValueA1.name(), u"A1"); QCOMPARE(enumValueA1.value().value(), 1); QCOMPARE(enumValueA1.stringValue(), QString()); - auto anonEnumIsThis = classes[0]->findEnum(QLatin1String("isThis")); + auto anonEnumIsThis = classes[0]->findEnum(u"isThis"_s); QVERIFY(anonEnumIsThis.has_value()); QVERIFY(anonEnumIsThis->isAnonymous()); - QCOMPARE(anonEnumIsThis->typeEntry()->qualifiedCppName(), QLatin1String("A::isThis")); + QCOMPARE(anonEnumIsThis->typeEntry()->qualifiedCppName(), u"A::isThis"); AbstractMetaEnumValue enumValueIsThis = anonEnumIsThis->values().constFirst(); - QCOMPARE(enumValueIsThis.name(), QLatin1String("isThis")); + QCOMPARE(enumValueIsThis.name(), u"isThis"); QCOMPARE(enumValueIsThis.value().value(), static_cast<int>(true)); - QCOMPARE(enumValueIsThis.stringValue(), QLatin1String("true")); + QCOMPARE(enumValueIsThis.stringValue(), u"true"); AbstractMetaEnumValue enumValueIsThat = anonEnumIsThis->values().constLast(); - QCOMPARE(enumValueIsThat.name(), QLatin1String("isThat")); + QCOMPARE(enumValueIsThat.name(), u"isThat"); QCOMPARE(enumValueIsThat.value().value(), static_cast<int>(false)); - QCOMPARE(enumValueIsThat.stringValue(), QLatin1String("false")); + QCOMPARE(enumValueIsThat.stringValue(), u"false"); } void TestEnum::testGlobalEnums() { - const char* cppCode ="\ + const char cppCode[] = "\ enum EnumA { A0, A1 };\n\ enum EnumB { B0 = 2, B1 = 0x4 };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <enum-type name='EnumA'/>\n\ <enum-type name='EnumB'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaEnumList globalEnums = builder->globalEnums(); - QCOMPARE(globalEnums.count(), 2); + QCOMPARE(globalEnums.size(), 2); AbstractMetaEnum enumA = globalEnums.constFirst(); - QCOMPARE(enumA.typeEntry()->qualifiedCppName(), QLatin1String("EnumA")); + QCOMPARE(enumA.typeEntry()->qualifiedCppName(), u"EnumA"); AbstractMetaEnumValue enumValueA0 = enumA.values().constFirst(); - QCOMPARE(enumValueA0.name(), QLatin1String("A0")); + QCOMPARE(enumValueA0.name(), u"A0"); QCOMPARE(enumValueA0.value().value(), 0); QCOMPARE(enumValueA0.stringValue(), QString()); AbstractMetaEnumValue enumValueA1 = enumA.values().constLast(); - QCOMPARE(enumValueA1.name(), QLatin1String("A1")); + QCOMPARE(enumValueA1.name(), u"A1"); QCOMPARE(enumValueA1.value().value(), 1); QCOMPARE(enumValueA1.stringValue(), QString()); AbstractMetaEnum enumB = globalEnums.constLast(); - QCOMPARE(enumB.typeEntry()->qualifiedCppName(), QLatin1String("EnumB")); + QCOMPARE(enumB.typeEntry()->qualifiedCppName(), u"EnumB"); AbstractMetaEnumValue enumValueB0 = enumB.values().constFirst(); - QCOMPARE(enumValueB0.name(), QLatin1String("B0")); + QCOMPARE(enumValueB0.name(), u"B0"); QCOMPARE(enumValueB0.value().value(), 2); - QCOMPARE(enumValueB0.stringValue(), QLatin1String("2")); + QCOMPARE(enumValueB0.stringValue(), u"2"); AbstractMetaEnumValue enumValueB1 = enumB.values().constLast(); - QCOMPARE(enumValueB1.name(), QLatin1String("B1")); + QCOMPARE(enumValueB1.name(), u"B1"); QCOMPARE(enumValueB1.value().value(), 4); - QCOMPARE(enumValueB1.stringValue(), QLatin1String("0x4")); + QCOMPARE(enumValueB1.stringValue(), u"0x4"); } void TestEnum::testEnumValueFromNeighbourEnum() { - const char* cppCode ="\ + const char cppCode[] = "\ namespace A {\n\ enum EnumA { ValueA0, ValueA1 };\n\ enum EnumB { ValueB0 = A::ValueA1, ValueB1 = ValueA0 };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <namespace-type name='A'>\n\ <enum-type name='EnumA'/>\n\ @@ -239,44 +222,44 @@ void TestEnum::testEnumValueFromNeighbourEnum() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - QCOMPARE(classes[0]->enums().count(), 2); + QCOMPARE(classes.size(), 1); + QCOMPARE(classes[0]->enums().size(), 2); - auto enumA = classes[0]->findEnum(QLatin1String("EnumA")); + auto enumA = classes[0]->findEnum(u"EnumA"_s); QVERIFY(enumA.has_value()); - QCOMPARE(enumA->typeEntry()->qualifiedCppName(), QLatin1String("A::EnumA")); + QCOMPARE(enumA->typeEntry()->qualifiedCppName(), u"A::EnumA"); AbstractMetaEnumValue enumValueA0 = enumA->values().constFirst(); - QCOMPARE(enumValueA0.name(), QLatin1String("ValueA0")); + QCOMPARE(enumValueA0.name(), u"ValueA0"); QCOMPARE(enumValueA0.value().value(), 0); QCOMPARE(enumValueA0.stringValue(), QString()); AbstractMetaEnumValue enumValueA1 = enumA->values().constLast(); - QCOMPARE(enumValueA1.name(), QLatin1String("ValueA1")); + QCOMPARE(enumValueA1.name(), u"ValueA1"); QCOMPARE(enumValueA1.value().value(), 1); QCOMPARE(enumValueA1.stringValue(), QString()); - auto enumB = classes[0]->findEnum(QLatin1String("EnumB")); + auto enumB = classes[0]->findEnum(u"EnumB"_s); QVERIFY(enumB.has_value()); - QCOMPARE(enumB->typeEntry()->qualifiedCppName(), QLatin1String("A::EnumB")); + QCOMPARE(enumB->typeEntry()->qualifiedCppName(), u"A::EnumB"); AbstractMetaEnumValue enumValueB0 = enumB->values().constFirst(); - QCOMPARE(enumValueB0.name(), QLatin1String("ValueB0")); + QCOMPARE(enumValueB0.name(), u"ValueB0"); QCOMPARE(enumValueB0.value().value(), 1); - QCOMPARE(enumValueB0.stringValue(), QLatin1String("A::ValueA1")); + QCOMPARE(enumValueB0.stringValue(), u"A::ValueA1"); AbstractMetaEnumValue enumValueB1 = enumB->values().constLast(); - QCOMPARE(enumValueB1.name(), QLatin1String("ValueB1")); + QCOMPARE(enumValueB1.name(), u"ValueB1"); QCOMPARE(enumValueB1.value().value(), 0); - QCOMPARE(enumValueB1.stringValue(), QLatin1String("ValueA0")); + QCOMPARE(enumValueB1.stringValue(), u"ValueA0"); } void TestEnum::testEnumValueFromExpression() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ enum EnumA : unsigned {\n\ ValueA0 = 3u,\n\ @@ -292,7 +275,7 @@ void TestEnum::testEnumValueFromExpression() ValueB0 = ~3,\n\ };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <value-type name='A'>\n\ <enum-type name='EnumA'/>\n\ @@ -301,77 +284,77 @@ void TestEnum::testEnumValueFromExpression() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + AbstractMetaClassPtr classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); - auto enumA = classA->findEnum(QLatin1String("EnumA")); + auto enumA = classA->findEnum(u"EnumA"_s); QVERIFY(enumA.has_value()); QVERIFY(!enumA->isSigned()); - QCOMPARE(enumA->typeEntry()->qualifiedCppName(), QLatin1String("A::EnumA")); + QCOMPARE(enumA->typeEntry()->qualifiedCppName(), u"A::EnumA"); AbstractMetaEnumValue valueA0 = enumA->values().at(0); - QCOMPARE(valueA0.name(), QLatin1String("ValueA0")); - QCOMPARE(valueA0.stringValue(), QLatin1String("3u")); + QCOMPARE(valueA0.name(), u"ValueA0"); + QCOMPARE(valueA0.stringValue(), u"3u"); QCOMPARE(valueA0.value().unsignedValue(), 3u); AbstractMetaEnumValue valueA1 = enumA->values().at(1); - QCOMPARE(valueA1.name(), QLatin1String("ValueA1")); - QCOMPARE(valueA1.stringValue(), QLatin1String("~3u")); + QCOMPARE(valueA1.name(), u"ValueA1"); + QCOMPARE(valueA1.stringValue(), u"~3u"); QCOMPARE(valueA1.value().unsignedValue(), ~3u); AbstractMetaEnumValue valueA2 = enumA->values().at(2); - QCOMPARE(valueA2.name(), QLatin1String("ValueA2")); - QCOMPARE(valueA2.stringValue(), QLatin1String("0xffffffff")); + QCOMPARE(valueA2.name(), u"ValueA2"); + QCOMPARE(valueA2.stringValue(), u"0xffffffff"); QCOMPARE(valueA2.value().unsignedValue(), 0xffffffffu); AbstractMetaEnumValue valueA3 = enumA->values().at(3); - QCOMPARE(valueA3.name(), QLatin1String("ValueA3")); - QCOMPARE(valueA3.stringValue(), QLatin1String("0xf0")); + QCOMPARE(valueA3.name(), u"ValueA3"); + QCOMPARE(valueA3.stringValue(), u"0xf0"); QCOMPARE(valueA3.value().unsignedValue(), 0xf0u); AbstractMetaEnumValue valueA4 = enumA->values().at(4); - QCOMPARE(valueA4.name(), QLatin1String("ValueA4")); - QCOMPARE(valueA4.stringValue(), QLatin1String("8 |ValueA3")); + QCOMPARE(valueA4.name(), u"ValueA4"); + QCOMPARE(valueA4.stringValue(), u"8 |ValueA3"); QCOMPARE(valueA4.value().unsignedValue(), 8|0xf0u); AbstractMetaEnumValue valueA5 = enumA->values().at(5); - QCOMPARE(valueA5.name(), QLatin1String("ValueA5")); - QCOMPARE(valueA5.stringValue(), QLatin1String("ValueA3|32")); + QCOMPARE(valueA5.name(), u"ValueA5"); + QCOMPARE(valueA5.stringValue(), u"ValueA3|32"); QCOMPARE(valueA5.value().unsignedValue(), 0xf0u|32); AbstractMetaEnumValue valueA6 = enumA->values().at(6); - QCOMPARE(valueA6.name(), QLatin1String("ValueA6")); - QCOMPARE(valueA6.stringValue(), QLatin1String("ValueA3 >> 1")); + QCOMPARE(valueA6.name(), u"ValueA6"); + QCOMPARE(valueA6.stringValue(), u"ValueA3 >> 1"); QCOMPARE(valueA6.value().unsignedValue(), 0xf0u >> 1); AbstractMetaEnumValue valueA7 = enumA->values().at(7); - QCOMPARE(valueA7.name(), QLatin1String("ValueA7")); - QCOMPARE(valueA7.stringValue(), QLatin1String("ValueA3 << 1")); + QCOMPARE(valueA7.name(), u"ValueA7"); + QCOMPARE(valueA7.stringValue(), u"ValueA3 << 1"); QCOMPARE(valueA7.value().unsignedValue(), 0xf0u << 1); - const auto enumB = classA->findEnum(QLatin1String("EnumB")); + const auto enumB = classA->findEnum(u"EnumB"_s); QVERIFY(enumB.has_value()); QVERIFY(enumB->isSigned()); - QCOMPARE(enumB->typeEntry()->qualifiedCppName(), QLatin1String("A::EnumB")); + QCOMPARE(enumB->typeEntry()->qualifiedCppName(), u"A::EnumB"); QCOMPARE(enumB->values().size(), 1); const AbstractMetaEnumValue valueB0 = enumB->values().at(0); - QCOMPARE(valueB0.name(), QLatin1String("ValueB0")); - QCOMPARE(valueB0.stringValue(), QLatin1String("~3")); + QCOMPARE(valueB0.name(), u"ValueB0"); + QCOMPARE(valueB0.stringValue(), u"~3"); QCOMPARE(valueB0.value().value(), ~3); } void TestEnum::testPrivateEnum() { - const char* cppCode ="\ + const char cppCode[] = "\ class A {\n\ private:\n\ enum PrivateEnum { Priv0 = 0x0f, Priv1 = 0xf0 };\n\ public:\n\ enum PublicEnum { Pub0 = Priv0, Pub1 = A::Priv1 };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <value-type name='A'>\n\ <enum-type name='PublicEnum'/>\n\ @@ -379,62 +362,216 @@ void TestEnum::testPrivateEnum() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); - QCOMPARE(classA->enums().count(), 2); + QCOMPARE(classA->enums().size(), 2); - auto privateEnum = classA->findEnum(QLatin1String("PrivateEnum")); + auto privateEnum = classA->findEnum(u"PrivateEnum"_s); QVERIFY(privateEnum.has_value()); QVERIFY(privateEnum->isPrivate()); - QCOMPARE(privateEnum->typeEntry()->qualifiedCppName(), QLatin1String("A::PrivateEnum")); + QCOMPARE(privateEnum->typeEntry()->qualifiedCppName(), u"A::PrivateEnum"); - auto publicEnum = classA->findEnum(QLatin1String("PublicEnum")); + auto publicEnum = classA->findEnum(u"PublicEnum"_s); QVERIFY(publicEnum.has_value()); - QCOMPARE(publicEnum->typeEntry()->qualifiedCppName(), QLatin1String("A::PublicEnum")); + QCOMPARE(publicEnum->typeEntry()->qualifiedCppName(), u"A::PublicEnum"); AbstractMetaEnumValue pub0 = publicEnum->values().constFirst(); - QCOMPARE(pub0.name(), QLatin1String("Pub0")); + QCOMPARE(pub0.name(), u"Pub0"); QCOMPARE(pub0.value().value(), 0x0f); - QCOMPARE(pub0.stringValue(), QLatin1String("Priv0")); + QCOMPARE(pub0.stringValue(), u"Priv0"); AbstractMetaEnumValue pub1 = publicEnum->values().constLast(); - QCOMPARE(pub1.name(), QLatin1String("Pub1")); + QCOMPARE(pub1.name(), u"Pub1"); QCOMPARE(pub1.value().value(), 0xf0); - QCOMPARE(pub1.stringValue(), QLatin1String("A::Priv1")); + QCOMPARE(pub1.stringValue(), u"A::Priv1"); } void TestEnum::testTypedefEnum() { - const char* cppCode ="\ + const char cppCode[] = "\ typedef enum EnumA {\n\ A0,\n\ A1,\n\ } EnumA;\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <enum-type name='EnumA'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaEnumList globalEnums = builder->globalEnums(); - QCOMPARE(globalEnums.count(), 1); + QCOMPARE(globalEnums.size(), 1); AbstractMetaEnum enumA = globalEnums.constFirst(); - QCOMPARE(enumA.typeEntry()->qualifiedCppName(), QLatin1String("EnumA")); + QCOMPARE(enumA.typeEntry()->qualifiedCppName(), u"EnumA"); AbstractMetaEnumValue enumValueA0 = enumA.values().constFirst(); - QCOMPARE(enumValueA0.name(), QLatin1String("A0")); + QCOMPARE(enumValueA0.name(), u"A0"); QCOMPARE(enumValueA0.value().value(), 0); - QCOMPARE(enumValueA0.stringValue(), QLatin1String("")); + QCOMPARE(enumValueA0.stringValue(), u""); AbstractMetaEnumValue enumValueA1 = enumA.values().constLast(); - QCOMPARE(enumValueA1.name(), QLatin1String("A1")); + QCOMPARE(enumValueA1.name(), u"A1"); QCOMPARE(enumValueA1.value().value(), 1); QCOMPARE(enumValueA1.stringValue(), QString()); } +// Helper classes and functions for testing enum default value fixing. +// Put the AbstractMetaBuilder into test fixture struct to avoid having +// to re-parse for each data row. + +struct EnumDefaultValuesFixture +{ + std::shared_ptr<AbstractMetaBuilder> builder; + + AbstractMetaType globalEnum; + AbstractMetaType testEnum; + AbstractMetaType testOptions; +}; + +Q_DECLARE_METATYPE(EnumDefaultValuesFixture) +Q_DECLARE_METATYPE(AbstractMetaType) + +static int populateDefaultValuesFixture(EnumDefaultValuesFixture *fixture) +{ + static const char cppCode[] =R"( +enum GlobalEnum { GE1, GE2 }; +namespace Test1 +{ +namespace Test2 +{ + enum Enum1 { E1, E2 }; + enum Option { O1, O2 }; +} // namespace Test2 +} // namespace Test1 +)"; + static const char xmlCode[] = R"( +<typesystem package="Foo"> + <enum-type name='GlobalEnum'/> + <namespace-type name='Test1'> + <namespace-type name='Test2'> + <enum-type name='Enum1'/> + <enum-type name='Option' flags='Options'/> + </namespace-type> + </namespace-type> +</typesystem> +)"; + + fixture->builder.reset(TestUtil::parse(cppCode, xmlCode, false)); + if (!fixture->builder) + return -1; + + const auto globalEnums = fixture->builder->globalEnums(); + if (globalEnums.size() != 1) + return -2; + + fixture->globalEnum = AbstractMetaType(globalEnums.constFirst().typeEntry()); + fixture->globalEnum.decideUsagePattern(); + + AbstractMetaClassCPtr testNamespace; + for (const auto &c : fixture->builder->classes()) { + if (c->name() == u"Test2") { + testNamespace = c; + break; + } + } + if (!testNamespace) + return -3; + + const auto namespaceEnums = testNamespace->enums(); + if (namespaceEnums.size() != 2) + return -4; + QList<EnumTypeEntryCPtr > enumTypeEntries{ + std::static_pointer_cast<const EnumTypeEntry>(namespaceEnums.at(0).typeEntry()), + std::static_pointer_cast<const EnumTypeEntry>(namespaceEnums.at(1).typeEntry())}; + if (enumTypeEntries.constFirst()->flags()) + std::swap(enumTypeEntries[0], enumTypeEntries[1]); + fixture->testEnum = AbstractMetaType(enumTypeEntries.at(0)); + fixture->testEnum.decideUsagePattern(); + fixture->testOptions = AbstractMetaType(enumTypeEntries.at(1)->flags()); + fixture->testOptions.decideUsagePattern(); + return 0; +} + +void TestEnum::testEnumDefaultValues_data() +{ + EnumDefaultValuesFixture fixture; + const int setupOk = populateDefaultValuesFixture(&fixture); + + QTest::addColumn<EnumDefaultValuesFixture>("fixture"); + QTest::addColumn<int>("setupOk"); // To verify setup + QTest::addColumn<AbstractMetaType>("metaType"); // Type and parameters for fixup + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expected"); + + // Global should just remain unmodified + QTest::newRow("global") << fixture << setupOk + << fixture.globalEnum << "GE1" << "GE1"; + QTest::newRow("global-int") << fixture << setupOk + << fixture.globalEnum << "42" << "42"; + QTest::newRow("global-hex-int") << fixture << setupOk + << fixture.globalEnum << "0x10" << "0x10"; + QTest::newRow("global-int-cast") << fixture << setupOk + << fixture.globalEnum << "GlobalEnum(-1)" << "GlobalEnum(-1)"; + + // Namespaced enum as number should remain unmodified + QTest::newRow("namespace-enum-int") << fixture << setupOk + << fixture.testEnum << "42" << "42"; + QTest::newRow("namespace-enum-hex-int") << fixture << setupOk + << fixture.testEnum << "0x10" << "0x10"; + // Partial qualification of namespaced enum + QTest::newRow("namespace-enum-qualified") << fixture << setupOk + << fixture.testEnum << "Enum1::E1" << "Test1::Test2::Enum1::E1"; + // Unqualified namespaced enums + QTest::newRow("namespace-enum-unqualified") << fixture << setupOk + << fixture.testEnum << "E1" << "Test1::Test2::Enum1::E1"; + // Namespaced enums cast from int should be qualified by scope + QTest::newRow("namespace-enum-int-cast") << fixture << setupOk + << fixture.testEnum << "Enum1(-1)" << "Test1::Test2::Enum1(-1)"; + + // Namespaced option as number should remain unmodified + QTest::newRow("namespace-option-int") << fixture << setupOk + << fixture.testOptions << "0x10" << "0x10"; + QTest::newRow("namespace-option-expression") << fixture << setupOk + << fixture.testOptions << "0x10 | 0x20" << "0x10 | 0x20"; + QTest::newRow("namespace-option-expression1") << fixture << setupOk + << fixture.testOptions << "0x10 | Test1::Test2::Option::O1" + << "0x10 | Test1::Test2::Option::O1"; + QTest::newRow("namespace-option-expression2") << fixture << setupOk + << fixture.testOptions << "0x10 | O1" << "0x10 | Test1::Test2::Option::O1"; + // Complicated expressions - should remain unmodified + QTest::newRow("namespace-option-expression-paren") << fixture << setupOk + << fixture.testOptions << "0x10 | (0x20 | 0x40 | O1)" + << "0x10 | (0x20 | 0x40 | O1)"; + + // Option: Cast Enum from int should be qualified + QTest::newRow("namespace-option-int-cast") << fixture << setupOk + << fixture.testOptions << "Option(0x10)" << "Test1::Test2::Option(0x10)"; + // Option: Cast Flags from int should be qualified + QTest::newRow("namespace-options-int-cast") << fixture << setupOk + << fixture.testOptions << "Options(0x10 | 0x20)" << "Test1::Test2::Options(0x10 | 0x20)"; + QTest::newRow("namespace-option-cast-expression1") << fixture << setupOk + << fixture.testOptions << "Test1::Test2::Options(0x10 | Test1::Test2::Option::O1)" + << "Test1::Test2::Options(0x10 | Test1::Test2::Option::O1)"; + QTest::newRow("namespace-option-cast-expression2") << fixture << setupOk + << fixture.testOptions << "Options(0x10 | O1)" + << "Test1::Test2::Options(0x10 | Test1::Test2::Option::O1)"; +} + +void TestEnum::testEnumDefaultValues() +{ + QFETCH(EnumDefaultValuesFixture, fixture); + QFETCH(int, setupOk); + QFETCH(AbstractMetaType, metaType); + QFETCH(QString, input); + QFETCH(QString, expected); + QCOMPARE(setupOk, 0); + const QString actual = fixture.builder->fixEnumDefault(metaType, input); + QCOMPARE(actual, expected); +} + QTEST_APPLESS_MAIN(TestEnum) diff --git a/sources/shiboken6/ApiExtractor/tests/testenum.h b/sources/shiboken6/ApiExtractor/tests/testenum.h index 312551763..452755490 100644 --- a/sources/shiboken6/ApiExtractor/tests/testenum.h +++ b/sources/shiboken6/ApiExtractor/tests/testenum.h @@ -1,34 +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 #ifndef TESTENUM_H #define TESTENUM_H -#include <QObject> + +#include <QtCore/QObject> class TestEnum : public QObject { @@ -42,6 +18,8 @@ private slots: void testEnumValueFromExpression(); void testPrivateEnum(); void testTypedefEnum(); + void testEnumDefaultValues_data(); + void testEnumDefaultValues(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp b/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp index 90a6cd312..fcc409a42 100644 --- a/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp @@ -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 #include "testextrainclude.h" #include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <typesystemtypeentry.h> void TestExtraInclude::testClassExtraInclude() { - const char* cppCode ="struct A {};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A {};\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <value-type name='A'>\n\ <extra-includes>\n\ @@ -45,20 +21,20 @@ void TestExtraInclude::testClassExtraInclude() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QList<Include> includes = classA->typeEntry()->extraIncludes(); - QCOMPARE(includes.count(), 1); - QCOMPARE(includes.constFirst().name(), QLatin1String("header.h")); + QCOMPARE(includes.size(), 1); + QCOMPARE(includes.constFirst().name(), u"header.h"); } void TestExtraInclude::testGlobalExtraIncludes() { - const char* cppCode ="struct A {};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A {};\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <extra-includes>\n\ <include file-name='header1.h' location='global'/>\n\ @@ -68,19 +44,19 @@ void TestExtraInclude::testGlobalExtraIncludes() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("A"))); + QVERIFY(AbstractMetaClass::findClass(classes, "A")); - TypeDatabase* td = TypeDatabase::instance(); - const TypeSystemTypeEntry *module = td->defaultTypeSystemType(); + auto *td = TypeDatabase::instance(); + TypeSystemTypeEntryCPtr module = td->defaultTypeSystemType(); QVERIFY(module); - QCOMPARE(module->name(), QLatin1String("Foo")); + QCOMPARE(module->name(), u"Foo"); QList<Include> includes = module->extraIncludes(); - QCOMPARE(includes.count(), 2); - QCOMPARE(includes.constFirst().name(), QLatin1String("header1.h")); - QCOMPARE(includes.constLast().name(), QLatin1String("header2.h")); + QCOMPARE(includes.size(), 2); + QCOMPARE(includes.constFirst().name(), u"header1.h"); + QCOMPARE(includes.constLast().name(), u"header2.h"); } QTEST_APPLESS_MAIN(TestExtraInclude) diff --git a/sources/shiboken6/ApiExtractor/tests/testextrainclude.h b/sources/shiboken6/ApiExtractor/tests/testextrainclude.h index 33c5377c7..6bcb57993 100644 --- a/sources/shiboken6/ApiExtractor/tests/testextrainclude.h +++ b/sources/shiboken6/ApiExtractor/tests/testextrainclude.h @@ -1,35 +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 #ifndef TESTEXTRAINCLUDE_H #define TESTEXTRAINCLUDE_H -#include <QObject> +#include <QtCore/QObject> class TestExtraInclude : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp index f58ea6f64..18eaf5774 100644 --- a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp @@ -1,38 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testfunctiontag.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetafunction.h> #include <modifications.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestFunctionTag::testFunctionTagForSpecificSignature() { const char cppCode[] = "void globalFunction(int); void globalFunction(float); void dummy();\n"; @@ -43,9 +23,9 @@ void TestFunctionTag::testFunctionTagForSpecificSignature() <function signature='globalFunction(int)'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - const TypeEntry *func = TypeDatabase::instance()->findType(QLatin1String("globalFunction")); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"globalFunction"_s); QVERIFY(func); QCOMPARE(builder->globalFunctions().size(), 1); } @@ -61,24 +41,24 @@ void TestFunctionTag::testFunctionTagForAllSignatures() <function signature='globalFunction(float)'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - const TypeEntry *func = TypeDatabase::instance()->findType(QLatin1String("globalFunction")); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"globalFunction"_s); QVERIFY(func); QCOMPARE(builder->globalFunctions().size(), 2); } void TestFunctionTag::testRenameGlobalFunction() { - const char* cppCode ="void global_function_with_ugly_name();\n"; - const char* xmlCode = "\ + const char cppCode[] = "void global_function_with_ugly_name();\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <function signature='global_function_with_ugly_name()' rename='smooth'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - const TypeEntry *func = TypeDatabase::instance()->findType(QLatin1String("global_function_with_ugly_name")); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"global_function_with_ugly_name"_s); QVERIFY(func); QCOMPARE(builder->globalFunctions().size(), 1); @@ -88,11 +68,11 @@ void TestFunctionTag::testRenameGlobalFunction() QCOMPARE(metaFunc->modifications().size(), 1); QVERIFY(metaFunc->modifications().constFirst().isRenameModifier()); QCOMPARE(metaFunc->modifications().constFirst().renamedToName(), - QLatin1String("smooth")); + u"smooth"); - QCOMPARE(metaFunc->name(), QLatin1String("smooth")); - QCOMPARE(metaFunc->originalName(), QLatin1String("global_function_with_ugly_name")); - QCOMPARE(metaFunc->minimalSignature(), QLatin1String("global_function_with_ugly_name()")); + QCOMPARE(metaFunc->name(), u"smooth"); + QCOMPARE(metaFunc->originalName(), u"global_function_with_ugly_name"); + QCOMPARE(metaFunc->minimalSignature(), u"global_function_with_ugly_name()"); } QTEST_APPLESS_MAIN(TestFunctionTag) diff --git a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.h b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.h index d68499cd9..7c60cb4e0 100644 --- a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.h +++ b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.h @@ -1,34 +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 #ifndef TESTFUNCTIONTAG_H #define TESTFUNCTIONTAG_H -#include <QObject> + +#include <QtCore/QObject> class TestFunctionTag : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp index 9dcdec975..899d00ad4 100644 --- a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.cpp @@ -1,41 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testimplicitconversions.h" #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <complextypeentry.h> #include <QtTest/QTest> void TestImplicitConversions::testWithPrivateCtors() { - const char* cppCode ="\ + const char cppCode[] = "\ class B;\n\ class C;\n\ class A {\n\ @@ -45,35 +22,35 @@ void TestImplicitConversions::testWithPrivateCtors() };\n\ class B {};\n\ class C {};\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <value-type name='A'/>\n\ <value-type name='B'/>\n\ <value-type name='C'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); + QCOMPARE(classes.size(), 3); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classC = AbstractMetaClass::findClass(classes, "C"); const auto implicitConvs = classA->implicitConversions(); - QCOMPARE(implicitConvs.count(), 1); + QCOMPARE(implicitConvs.size(), 1); QCOMPARE(implicitConvs.constFirst()->arguments().constFirst().type().typeEntry(), classC->typeEntry()); } void TestImplicitConversions::testWithModifiedVisibility() { - const char* cppCode ="\ + const char cppCode[] = "\ class B;\n\ class A {\n\ public:\n\ A(const B&);\n\ };\n\ class B {};\n"; - const char* xmlCode = R"( + const char xmlCode[] = R"( <typesystem package='Foo'> <value-type name='A'> <modify-function signature='A(const B&)' access='private'/> @@ -82,13 +59,13 @@ void TestImplicitConversions::testWithModifiedVisibility() </typesystem> )"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); const auto implicitConvs = classA->implicitConversions(); - QCOMPARE(implicitConvs.count(), 1); + QCOMPARE(implicitConvs.size(), 1); QCOMPARE(implicitConvs.constFirst()->arguments().constFirst().type().typeEntry(), classB->typeEntry()); } @@ -96,7 +73,7 @@ void TestImplicitConversions::testWithModifiedVisibility() void TestImplicitConversions::testWithAddedCtor() { - const char* cppCode ="\ + const char cppCode[] = "\ class B;\n\ class A {\n\ public:\n\ @@ -104,7 +81,7 @@ void TestImplicitConversions::testWithAddedCtor() };\n\ class B {};\n\ class C {};\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <custom-type name='TARGETLANGTYPE'/>\n\ <value-type name='A'>\n\ @@ -116,49 +93,49 @@ void TestImplicitConversions::testWithAddedCtor() <value-type name='C'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); + QCOMPARE(classes.size(), 3); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); auto implicitConvs = classA->implicitConversions(); - QCOMPARE(implicitConvs.count(), 2); + QCOMPARE(implicitConvs.size(), 2); // Added constructors with custom types should never result in implicit converters. - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); implicitConvs = classB->implicitConversions(); - QCOMPARE(implicitConvs.count(), 0); + QCOMPARE(implicitConvs.size(), 0); } void TestImplicitConversions::testWithExternalConversionOperator() { - const char* cppCode ="\ + const char cppCode[] = "\ class A {};\n\ struct B {\n\ operator A() const;\n\ };\n"; - const char* xmlCode = "\n\ + const char xmlCode[] = "\n\ <typesystem package='Foo'>\n\ <value-type name='A'/>\n\ <value-type name='B'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + QCOMPARE(classes.size(), 2); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto classB = AbstractMetaClass::findClass(classes, "B"); const auto implicitConvs = classA->implicitConversions(); - QCOMPARE(implicitConvs.count(), 1); + QCOMPARE(implicitConvs.size(), 1); const auto &externalConvOps = classA->externalConversionOperators(); - QCOMPARE(externalConvOps.count(), 1); + QCOMPARE(externalConvOps.size(), 1); AbstractMetaFunctionCPtr convOp; for (const auto &func : classB->functions()) { if (func->isConversionOperator()) convOp = func; } - QVERIFY(!convOp.isNull()); + QVERIFY(convOp); QCOMPARE(implicitConvs.constFirst(), convOp); } diff --git a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.h b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.h index da8ae4597..e0678c5f5 100644 --- a/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.h +++ b/sources/shiboken6/ApiExtractor/tests/testimplicitconversions.h @@ -1,35 +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 #ifndef TESTIMPLICITCONVERSIONS_H #define TESTIMPLICITCONVERSIONS_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; diff --git a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp index fda6614f0..23cf0f9ea 100644 --- a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp @@ -1,42 +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 "testinserttemplate.h" #include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> +#include <codesnip.h> #include <modifications.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <typesystemtypeentry.h> void TestInsertTemplate::testInsertTemplateOnClassInjectCode() { - const char* cppCode ="struct A{};\n"; - const char* xmlCode = "\ + const char cppCode[] = "struct A{};\n"; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <template name='code_template'>\n\ code template content\n\ @@ -48,20 +25,20 @@ void TestInsertTemplate::testInsertTemplateOnClassInjectCode() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 1); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->typeEntry()->codeSnips().count(), 1); + QCOMPARE(classA->typeEntry()->codeSnips().size(), 1); QString code = classA->typeEntry()->codeSnips().constFirst().code(); - QVERIFY(code.contains(QLatin1String("code template content"))); + QVERIFY(code.contains(u"code template content")); } void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() { - const char* cppCode =""; - const char* xmlCode = "\ + const char cppCode[] = ""; + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <template name='code_template'>\n\ code template content\n\ @@ -71,17 +48,16 @@ void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() </inject-code>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); QVERIFY(classes.isEmpty()); - const TypeSystemTypeEntry *module = TypeDatabase::instance()->defaultTypeSystemType(); + TypeSystemTypeEntryCPtr module = TypeDatabase::instance()->defaultTypeSystemType(); QVERIFY(module); - QCOMPARE(module->name(), QLatin1String("Foo")); - QVERIFY(module); - QCOMPARE(module->codeSnips().count(), 1); + QCOMPARE(module->name(), u"Foo"); + QCOMPARE(module->codeSnips().size(), 1); QString code = module->codeSnips().constFirst().code().trimmed(); - QVERIFY(code.contains(QLatin1String("code template content"))); + QVERIFY(code.contains(u"code template content")); } QTEST_APPLESS_MAIN(TestInsertTemplate) diff --git a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.h b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.h index 99b171933..f4f67abc0 100644 --- a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.h +++ b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.h @@ -1,35 +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 #ifndef TESTINSERTTEMPLATE_H #define TESTINSERTTEMPLATE_H -#include <QObject> +#include <QtCore/QObject> class TestInsertTemplate : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.cpp b/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.cpp index 521f8d665..9cf2e0cc7 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.cpp @@ -1,46 +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 "testmodifydocumentation.h" - -#include <QCoreApplication> -#include <QtCore/QTemporaryDir> -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> +#include <abstractmetafunction.h> #include <documentation.h> #include <modifications.h> -#include <typesystem.h> +#include <complextypeentry.h> #include <qtdocparser.h> +#include <qtcompat.h> + +#include <QtCore/QCoreApplication> +#include <QtCore/QTemporaryDir> +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestModifyDocumentation::testModifyDocumentation() { - const char* cppCode ="struct B { void b(); }; class A {};\n"; + const char cppCode[] = "struct B { void b(); }; class A {};\n"; const char xmlCode[] = R"(<typesystem package="Foo"> <value-type name='B'> @@ -53,22 +33,22 @@ R"(<typesystem package="Foo"> </typesystem> )"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); - AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + QVERIFY(builder); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); DocModificationList docMods = classA->typeEntry()->docModifications(); - QCOMPARE(docMods.count(), 2); - QCOMPARE(docMods[0].code().trimmed(), QLatin1String("<brief>Modified Brief</brief>")); + QCOMPARE(docMods.size(), 2); + QCOMPARE(docMods[0].code().trimmed(), u"<brief>Modified Brief</brief>"); QCOMPARE(docMods[0].signature(), QString()); - QCOMPARE(docMods[1].code().trimmed(), QLatin1String("<para>Some changed contents here</para>")); + QCOMPARE(docMods[1].code().trimmed(), u"<para>Some changed contents here</para>"); QCOMPARE(docMods[1].signature(), QString()); // Create a temporary directory for the documentation file since libxml2 // cannot handle Qt resources. - QTemporaryDir tempDir(QDir::tempPath() + QLatin1String("/shiboken_testmodifydocXXXXXX")); + QTemporaryDir tempDir(QDir::tempPath() + u"/shiboken_testmodifydocXXXXXX"_s); QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); - const QString docFileName = QLatin1String("a.xml"); - QVERIFY(QFile::copy(QLatin1String(":/") + docFileName, tempDir.filePath(docFileName))); + constexpr auto docFileName = "a.xml"_L1; + QVERIFY(QFile::copy(u":/"_s + docFileName, tempDir.filePath(docFileName))); QtDocParser docParser; docParser.setDocumentationDataDirectory(tempDir.path()); @@ -89,7 +69,7 @@ R"(<?xml version="1.0"?> )"; const QString expectedDocSimplified = QString::fromLatin1(expectedDoc).simplified(); // Check whether the first modification worked. - QVERIFY(actualBriefSimplified.contains(QLatin1String("Modified Brief"))); + QVERIFY(actualBriefSimplified.contains(u"Modified Brief")); #ifndef HAVE_LIBXSLT // QtXmlPatterns is unable to handle para[3] in style sheets, @@ -99,6 +79,33 @@ R"(<?xml version="1.0"?> QCOMPARE(actualDocSimplified, expectedDocSimplified); } +void TestModifyDocumentation::testInjectAddedFunctionDocumentation() +{ + const char cppCode[] ="class A {};\n"; + const char xmlCode[] = R"XML( +<typesystem package="Foo"> + <value-type name='A'> + <add-function signature="foo(int@parameter_name@)"> + <inject-documentation format="target" mode="append"> + Injected documentation of added function foo. + </inject-documentation> + </add-function> + </value-type> +</typesystem> +)XML"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); + QVERIFY(builder); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); + QVERIFY(classA); + const auto f = classA->findFunction("foo"); + QVERIFY(f); + QVERIFY(f->isUserAdded()); + auto docMods = f->addedFunctionDocModifications(); + QCOMPARE(docMods.size(), 1); + const QString code = docMods.constFirst().code(); + QVERIFY(code.contains(u"Injected documentation of added function foo.")); +} + // We expand QTEST_MAIN macro but using QCoreApplication instead of QApplication // because this test needs an event loop but can't use QApplication to avoid a crash // on our ARMEL/FRAMANTLE buildbot diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.h b/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.h index 6428a5697..c1cc8f480 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.h +++ b/sources/shiboken6/ApiExtractor/tests/testmodifydocumentation.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 TESTMODIFYDOCUMENTATION_H #define TESTMODIFYDOCUMENTATION_H -#include <QObject> +#include <QtCore/QObject> class TestModifyDocumentation : public QObject { Q_OBJECT private slots: void testModifyDocumentation(); + void testInjectAddedFunctionDocumentation(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp index 0d95d5abb..a7d40f70a 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.cpp @@ -1,40 +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 #include "testmodifyfunction.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetabuilder_p.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> #include <modifications.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestModifyFunction::testRenameArgument_data() { QTest::addColumn<QByteArray>("pattern"); @@ -46,7 +28,7 @@ void TestModifyFunction::testRenameArgument() { QFETCH(QByteArray, pattern); - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ void method(int=0);\n\ };\n"; @@ -64,23 +46,23 @@ void TestModifyFunction::testRenameArgument() const QByteArray xmlCode = QByteArray(xmlCode1) + pattern + QByteArray(xmlCode2); QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode.constData(), false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); - const auto func = classA->findFunction(QLatin1String("method")); - QVERIFY(!func.isNull()); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + const auto func = classA->findFunction("method"); + QVERIFY(func); - QCOMPARE(func->argumentName(1), QLatin1String("otherArg")); + QCOMPARE(func->argumentName(1), u"otherArg"); } void TestModifyFunction::testOwnershipTransfer() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {\n\ virtual A* method();\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <object-type name='A' />\n\ <object-type name='B'>\n\ @@ -92,11 +74,11 @@ void TestModifyFunction::testOwnershipTransfer() </object-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - const auto func = classB->findFunction(QLatin1String("method")); - QVERIFY(!func.isNull()); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + const auto func = classB->findFunction("method"); + QVERIFY(func); QCOMPARE(func->argumentTargetOwnership(func->ownerClass(), 0), TypeSystem::CppOwnership); @@ -105,7 +87,7 @@ void TestModifyFunction::testOwnershipTransfer() void TestModifyFunction::invalidateAfterUse() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ virtual void call(int *a);\n\ };\n\ @@ -119,7 +101,7 @@ void TestModifyFunction::invalidateAfterUse() };\n\ struct E : D {\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='int'/>\n\ <object-type name='A'>\n\ @@ -141,48 +123,48 @@ void TestModifyFunction::invalidateAfterUse() <object-type name='E' />\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - false, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + false, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - auto func = classB->findFunction(QLatin1String("call")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + auto func = classB->findFunction("call"); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - const AbstractMetaClass *classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto classC = AbstractMetaClass::findClass(classes, "C"); QVERIFY(classC); - func = classC->findFunction(QLatin1String("call")); + func = classC->findFunction("call"); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - func = classC->findFunction(QLatin1String("call2")); + func = classC->findFunction("call2"); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - const AbstractMetaClass *classD = AbstractMetaClass::findClass(classes, QLatin1String("D")); + AbstractMetaClassCPtr classD = AbstractMetaClass::findClass(classes, "D"); QVERIFY(classD); - func = classD->findFunction(QLatin1String("call")); + func = classD->findFunction("call"); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - func = classD->findFunction(QLatin1String("call2")); + func = classD->findFunction("call2"); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - const AbstractMetaClass *classE = AbstractMetaClass::findClass(classes, QLatin1String("E")); + const auto classE = AbstractMetaClass::findClass(classes, "E"); QVERIFY(classE); - func = classE->findFunction(QLatin1String("call")); + func = classE->findFunction("call"); QVERIFY(func); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); QVERIFY(func->modifications().at(0).argument_mods().at(0).resetAfterUse()); - func = classE->findFunction(QLatin1String("call2")); + func = classE->findFunction("call2"); QVERIFY(func); QCOMPARE(func->modifications().size(), 1); QCOMPARE(func->modifications().at(0).argument_mods().size(), 1); @@ -191,13 +173,13 @@ void TestModifyFunction::invalidateAfterUse() void TestModifyFunction::testWithApiVersion() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {\n\ virtual A* method();\n\ virtual B* methodB();\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <object-type name='A' />\n\ <object-type name='B'>\n\ @@ -214,16 +196,16 @@ void TestModifyFunction::testWithApiVersion() </object-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - false, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + false, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - auto func = classB->findFunction(QLatin1String("method")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + auto func = classB->findFunction("method"); auto returnOwnership = func->argumentTargetOwnership(func->ownerClass(), 0); QCOMPARE(returnOwnership, TypeSystem::CppOwnership); - func = classB->findFunction(QLatin1String("methodB")); + func = classB->findFunction("methodB"); returnOwnership = func->argumentTargetOwnership(func->ownerClass(), 0); QVERIFY(returnOwnership != TypeSystem::CppOwnership); } @@ -253,44 +235,44 @@ struct A { </typesystem> )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - false, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + false, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); // Nothing specified, true - const auto f1 = classA->findFunction(QLatin1String("f1")); - QVERIFY(!f1.isNull()); + const auto f1 = classA->findFunction("f1"); + QVERIFY(f1); QVERIFY(!f1->allowThread()); // 'auto' specified, should be false for nontrivial function - const auto f2 = classA->findFunction(QLatin1String("f2")); - QVERIFY(!f2.isNull()); + const auto f2 = classA->findFunction("f2"); + QVERIFY(f2); QVERIFY(f2->allowThread()); // 'no' specified, should be false - const auto f3 = classA->findFunction(QLatin1String("f3")); - QVERIFY(!f3.isNull()); + const auto f3 = classA->findFunction("f3"); + QVERIFY(f3); QVERIFY(!f3->allowThread()); // Nothing specified, should be false for simple getter - const auto getter1 = classA->findFunction(QLatin1String("getter1")); - QVERIFY(!getter1.isNull()); + const auto getter1 = classA->findFunction("getter1"); + QVERIFY(getter1); QVERIFY(!getter1->allowThread()); // Forced to true simple getter - const auto getter2 = classA->findFunction(QLatin1String("getter2")); - QVERIFY(!getter2.isNull()); + const auto getter2 = classA->findFunction("getter2"); + QVERIFY(getter2); QVERIFY(getter2->allowThread()); // Forced to true simple getter } void TestModifyFunction::testGlobalFunctionModification() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ void function(A* a = 0);\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='A'/>\n\ <function signature='function(A*)'>\n\ @@ -304,23 +286,24 @@ void TestModifyFunction::testGlobalFunctionModification() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->globalFunctions().size(), 1); - FunctionModificationList mods = TypeDatabase::instance()->functionModifications(QLatin1String("function(A*)")); - QCOMPARE(mods.count(), 1); + auto *td = TypeDatabase::instance(); + FunctionModificationList mods = td->globalFunctionModifications({u"function(A*)"_s}); + QCOMPARE(mods.size(), 1); const QList<ArgumentModification> &argMods = mods.constFirst().argument_mods(); - QCOMPARE(argMods.count(), 1); + QCOMPARE(argMods.size(), 1); ArgumentModification argMod = argMods.constFirst(); - QCOMPARE(argMod.replacedDefaultExpression(), QLatin1String("A()")); + QCOMPARE(argMod.replacedDefaultExpression(), u"A()"); QVERIFY(!builder->globalFunctions().isEmpty()); const auto func = builder->globalFunctions().constFirst(); - QCOMPARE(func->arguments().count(), 1); + QCOMPARE(func->arguments().size(), 1); const AbstractMetaArgument &arg = func->arguments().constFirst(); - QCOMPARE(arg.type().cppSignature(), QLatin1String("A *")); - QCOMPARE(arg.originalDefaultValueExpression(), QLatin1String("0")); - QCOMPARE(arg.defaultValueExpression(), QLatin1String("A()")); + QCOMPARE(arg.type().cppSignature(), u"A *"); + QCOMPARE(arg.originalDefaultValueExpression(), u"0"); + QCOMPARE(arg.defaultValueExpression(), u"A()"); } // Tests modifications of exception handling and allow-thread @@ -451,44 +434,44 @@ void TestModifyFunction::testScopedModifications() QFETCH(bool, expectedAllowThread); QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode.constData(), xmlCode.constData(), false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(builder->classes(), "A"); QVERIFY(classA); - auto f = classA->findFunction(QStringLiteral("unspecified")); - QVERIFY(!f.isNull()); + auto f = classA->findFunction("unspecified"); + QVERIFY(f); QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::Unknown); QCOMPARE(f->generateExceptionHandling(), expectedGenerateUnspecified); QCOMPARE(f->allowThread(), expectedAllowThread); - f = classA->findFunction(QStringLiteral("nonThrowing")); - QVERIFY(!f.isNull()); + f = classA->findFunction("nonThrowing"); + QVERIFY(f); QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::NoExcept); QCOMPARE(f->generateExceptionHandling(), expectedGenerateNonThrowing); - f = classA->findFunction(QStringLiteral("throwing")); - QVERIFY(!f.isNull()); + f = classA->findFunction("throwing"); + QVERIFY(f); QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::Throws); QCOMPARE(f->generateExceptionHandling(), expectedGenerateThrowing); } void TestModifyFunction::testSnakeCaseRenaming_data() { - QTest::addColumn<QString>("name"); - QTest::addColumn<QString>("expected"); + QTest::addColumn<QLatin1StringView>("name"); + QTest::addColumn<QLatin1StringView>("expected"); QTest::newRow("s1") - << QStringLiteral("snakeCaseFunc") << QStringLiteral("snake_case_func"); + << "snakeCaseFunc"_L1 << "snake_case_func"_L1; QTest::newRow("s2") - << QStringLiteral("SnakeCaseFunc") << QStringLiteral("snake_case_func"); + << "SnakeCaseFunc"_L1 << "snake_case_func"_L1; QTest::newRow("consecutive-uppercase") - << QStringLiteral("snakeCAseFunc") << QStringLiteral("snakeCAseFunc"); + << "snakeCAseFunc"_L1 << "snakeCAseFunc"_L1; } void TestModifyFunction::testSnakeCaseRenaming() { - QFETCH(QString, name); - QFETCH(QString, expected); + QFETCH(QLatin1StringView, name); + QFETCH(QLatin1StringView, expected); const QString actual = AbstractMetaBuilder::getSnakeCaseName(name); QCOMPARE(actual, expected); diff --git a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h index a9a13a82b..8a4f5d826 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h +++ b/sources/shiboken6/ApiExtractor/tests/testmodifyfunction.h @@ -1,35 +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 #ifndef TESTABSTRACTMETACLASS_H #define TESTABSTRACTMETACLASS_H -#include <QObject> +#include <QtCore/QObject> class TestModifyFunction : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.cpp b/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.cpp index 748adfc39..1cf4c8e0f 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.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 "testmultipleinheritance.h" #include <QtTest/QTest> @@ -35,7 +10,7 @@ void TestMultipleInheritance::testVirtualClass() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ virtual ~A();\n\ virtual void theBug();\n\ @@ -47,7 +22,7 @@ void TestMultipleInheritance::testVirtualClass() };\n\ struct D : C {\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <object-type name='A' />\n\ <object-type name='B' />\n\ @@ -56,14 +31,14 @@ void TestMultipleInheritance::testVirtualClass() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 4); + QCOMPARE(classes.size(), 4); - const AbstractMetaClass *classD = AbstractMetaClass::findClass(classes, QLatin1String("D")); + const auto classD = AbstractMetaClass::findClass(classes, "D"); bool functionFound = false; for (const auto &f : classD->functions()) { - if (f->name() == QLatin1String("theBug")) { + if (f->name() == u"theBug") { functionFound = true; break; } diff --git a/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.h b/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.h index 5ee8a21ea..ec9935305 100644 --- a/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.h +++ b/sources/shiboken6/ApiExtractor/tests/testmultipleinheritance.h @@ -1,35 +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 #ifndef TESTMULTIPLEINHERITANCE_H #define TESTMULTIPLEINHERITANCE_H -#include <QObject> +#include <QtCore/QObject> class AbstractMetaBuilder; diff --git a/sources/shiboken6/ApiExtractor/tests/testnamespace.cpp b/sources/shiboken6/ApiExtractor/tests/testnamespace.cpp index 99aabe780..3773e614a 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnamespace.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testnamespace.cpp @@ -1,41 +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 "testnamespace.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> #include <abstractmetaenum.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void NamespaceTest::testNamespaceMembers() { - const char* cppCode = "\ + const char cppCode[] = "\ namespace Namespace\n\ {\n\ enum Option {\n\ @@ -44,26 +24,26 @@ void NamespaceTest::testNamespaceMembers() };\n\ void foo(Option opt);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='Namespace'>\n\ <enum-type name='Option' />\n\ </namespace-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass *ns = AbstractMetaClass::findClass(classes, QLatin1String("Namespace")); + const auto ns = AbstractMetaClass::findClass(classes, "Namespace"); QVERIFY(ns); - auto metaEnum = ns->findEnum(QLatin1String("Option")); + auto metaEnum = ns->findEnum(u"Option"_s); QVERIFY(metaEnum.has_value()); - const auto func = ns->findFunction(QLatin1String("foo")); - QVERIFY(!func.isNull()); + const auto func = ns->findFunction("foo"); + QVERIFY(func); } void NamespaceTest::testNamespaceInnerClassMembers() { - const char* cppCode = "\ + const char cppCode[] = "\ namespace OuterNamespace\n\ {\n\ namespace InnerNamespace {\n\ @@ -72,7 +52,7 @@ void NamespaceTest::testNamespaceInnerClassMembers() };\n\ };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='OuterNamespace'>\n\ <namespace-type name='InnerNamespace'>\n\ @@ -81,16 +61,16 @@ void NamespaceTest::testNamespaceInnerClassMembers() </namespace-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *ons = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace")); + const auto ons = AbstractMetaClass::findClass(classes, "OuterNamespace"); QVERIFY(ons); - const AbstractMetaClass *ins = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace")); + const auto ins = AbstractMetaClass::findClass(classes, "OuterNamespace::InnerNamespace"); QVERIFY(ins); - const AbstractMetaClass *sc = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace::SomeClass")); + const auto sc = AbstractMetaClass::findClass(classes, "OuterNamespace::InnerNamespace::SomeClass"); QVERIFY(sc); - const auto meth = sc->findFunction(QLatin1String("method")); - QVERIFY(!meth.isNull()); + const auto meth = sc->findFunction("method"); + QVERIFY(meth); } QTEST_APPLESS_MAIN(NamespaceTest) diff --git a/sources/shiboken6/ApiExtractor/tests/testnamespace.h b/sources/shiboken6/ApiExtractor/tests/testnamespace.h index 5153a28a3..af46bdea3 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnamespace.h +++ b/sources/shiboken6/ApiExtractor/tests/testnamespace.h @@ -1,35 +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 #ifndef TESTNAMESPACE_H #define TESTNAMESPACE_H -#include <QObject> +#include <QtCore/QObject> // The class is named 'NamespaceTest' to avoid clashes with Qt COIN using // '-qtnamespace TestNamespace'. diff --git a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp index d536c0538..10ca1a0f6 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp @@ -1,42 +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 #include "testnestedtypes.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> +#include <codesnip.h> #include <modifications.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <primitivetypeentry.h> + +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; void TestNestedTypes::testNestedTypesModifications() { - const char* cppCode ="\ + const char cppCode[] = "\ namespace OuterNamespace {\n\ namespace InnerNamespace {\n\ struct SomeClass {\n\ @@ -44,7 +27,7 @@ void TestNestedTypes::testNestedTypesModifications() };\n\ };\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='OuterNamespace'>\n\ <namespace-type name='InnerNamespace'>\n\ @@ -60,34 +43,35 @@ void TestNestedTypes::testNestedTypesModifications() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *ons = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace")); + const auto ons = AbstractMetaClass::findClass(classes, "OuterNamespace"); QVERIFY(ons); - const AbstractMetaClass *ins = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace")); + const auto ins = AbstractMetaClass::findClass(classes, "OuterNamespace::InnerNamespace"); QVERIFY(ins); - QCOMPARE(ins->functions().count(), 1); - QCOMPARE(ins->typeEntry()->codeSnips().count(), 1); + QCOMPARE(ins->functions().size(), 1); + QCOMPARE(ins->typeEntry()->codeSnips().size(), 1); CodeSnip snip = ins->typeEntry()->codeSnips().constFirst(); - QCOMPARE(snip.code().trimmed(), QLatin1String("custom_code1();")); + QCOMPARE(snip.code().trimmed(), u"custom_code1();"); const auto addedFunc = ins->functions().constFirst(); QVERIFY(addedFunc->isUserAdded()); QCOMPARE(addedFunc->access(), Access::Public); QCOMPARE(addedFunc->functionType(), AbstractMetaFunction::NormalFunction); QCOMPARE(addedFunc->type().minimalSignature(), - QLatin1String("OuterNamespace::InnerNamespace::SomeClass")); + u"OuterNamespace::InnerNamespace::SomeClass"); QCOMPARE(addedFunc->modifications().size(), 1); QVERIFY(addedFunc->modifications().constFirst().isCodeInjection()); snip = addedFunc->modifications().constFirst().snips().constFirst(); - QCOMPARE(snip.code().trimmed(), QLatin1String("custom_code2();")); + QCOMPARE(snip.code().trimmed(), u"custom_code2();"); - const AbstractMetaClass *sc = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace::SomeClass")); - QVERIFY(ins); - QCOMPARE(sc->functions().count(), 2); // default constructor and removed method + const auto sc = + AbstractMetaClass::findClass(classes, "OuterNamespace::InnerNamespace::SomeClass"); + QVERIFY(sc); + QCOMPARE(sc->functions().size(), 2); // default constructor and removed method const auto removedFunc = sc->functions().constLast(); QVERIFY(removedFunc->isModifiedRemoved()); } @@ -95,11 +79,11 @@ void TestNestedTypes::testNestedTypesModifications() void TestNestedTypes::testDuplicationOfNestedTypes() { - const char* cppCode ="\ + const char cppCode[] = "\ namespace Namespace {\n\ class SomeClass {};\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <namespace-type name='Namespace'>\n\ <value-type name='SomeClass'>\n\ @@ -109,22 +93,22 @@ void TestNestedTypes::testDuplicationOfNestedTypes() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 2); - const AbstractMetaClass *nspace = AbstractMetaClass::findClass(classes, QLatin1String("Namespace")); + QCOMPARE(classes.size(), 2); + const auto nspace = AbstractMetaClass::findClass(classes, "Namespace"); QVERIFY(nspace); - const AbstractMetaClass *cls1 = AbstractMetaClass::findClass(classes, QLatin1String("SomeClass")); + const auto cls1 = AbstractMetaClass::findClass(classes, "SomeClass"); QVERIFY(cls1); - const AbstractMetaClass *cls2 = AbstractMetaClass::findClass(classes, QLatin1String("Namespace::SomeClass")); + const auto cls2 = AbstractMetaClass::findClass(classes, "Namespace::SomeClass"); QVERIFY(cls2); QCOMPARE(cls1, cls2); - QCOMPARE(cls1->name(), QLatin1String("SomeClass")); - QCOMPARE(cls1->qualifiedCppName(), QLatin1String("Namespace::SomeClass")); + QCOMPARE(cls1->name(), u"SomeClass"); + QCOMPARE(cls1->qualifiedCppName(), u"Namespace::SomeClass"); - TypeEntry* t1 = TypeDatabase::instance()->findType(QLatin1String("Namespace::SomeClass")); + auto t1 = TypeDatabase::instance()->findType(u"Namespace::SomeClass"_s); QVERIFY(t1); - TypeEntry* t2 = TypeDatabase::instance()->findType(QLatin1String("SomeClass")); + auto t2 = TypeDatabase::instance()->findType(u"SomeClass"_s); QVERIFY(!t2); } diff --git a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.h b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.h index a870511ff..544ea05ab 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.h +++ b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.h @@ -1,34 +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 #ifndef TESTNESTEDTYPES_H #define TESTNESTEDTYPES_H -#include <QObject> + +#include <QtCore/QObject> class TestNestedTypes : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp index de2f30135..9eef7ec47 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp @@ -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 #include "testnumericaltypedef.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> #include <typesystem.h> void TestNumericalTypedef::testNumericalTypedef() { - const char* cppCode ="\ + const char cppCode[] = "\ typedef double real;\n\ void funcDouble(double);\n\ void funcReal(real);\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='double'/>\n\ <primitive-type name='real'/>\n\ @@ -47,37 +24,37 @@ void TestNumericalTypedef::testNumericalTypedef() <function signature='funcReal(real)'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->globalFunctions().size(), 2); auto funcDouble = builder->globalFunctions().constFirst(); auto funcReal = builder->globalFunctions().constLast(); QVERIFY(funcReal); - if (funcDouble->name() == QLatin1String("funcReal")) + if (funcDouble->name() == u"funcReal") std::swap(funcDouble, funcReal); - QCOMPARE(funcDouble->minimalSignature(), QLatin1String("funcDouble(double)")); - QCOMPARE(funcReal->minimalSignature(), QLatin1String("funcReal(real)")); + QCOMPARE(funcDouble->minimalSignature(), u"funcDouble(double)"); + QCOMPARE(funcReal->minimalSignature(), u"funcReal(real)"); const AbstractMetaType doubleType = funcDouble->arguments().constFirst().type(); - QCOMPARE(doubleType.cppSignature(), QLatin1String("double")); + QCOMPARE(doubleType.cppSignature(), u"double"); QVERIFY(doubleType.isPrimitive()); - QVERIFY(doubleType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(doubleType.typeEntry())); const AbstractMetaType realType = funcReal->arguments().constFirst().type(); - QCOMPARE(realType.cppSignature(), QLatin1String("real")); + QCOMPARE(realType.cppSignature(), u"real"); QVERIFY(realType.isPrimitive()); - QVERIFY(realType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(realType.typeEntry())); } void TestNumericalTypedef::testUnsignedNumericalTypedef() { - const char* cppCode ="\ + const char cppCode[] = "\ typedef unsigned short custom_ushort;\n\ void funcUnsignedShort(unsigned short);\n\ void funcUShort(custom_ushort);\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='short'/>\n\ <primitive-type name='unsigned short'/>\n\ @@ -86,27 +63,27 @@ void TestNumericalTypedef::testUnsignedNumericalTypedef() <function signature='funcUShort(custom_ushort)'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->globalFunctions().size(), 2); auto funcUnsignedShort = builder->globalFunctions().constFirst(); auto funcUShort = builder->globalFunctions().constLast(); - if (funcUnsignedShort->name() == QLatin1String("funcUShort")) + if (funcUnsignedShort->name() == u"funcUShort") std::swap(funcUnsignedShort, funcUShort); - QCOMPARE(funcUnsignedShort->minimalSignature(), QLatin1String("funcUnsignedShort(unsigned short)")); - QCOMPARE(funcUShort->minimalSignature(), QLatin1String("funcUShort(custom_ushort)")); + QCOMPARE(funcUnsignedShort->minimalSignature(), u"funcUnsignedShort(unsigned short)"); + QCOMPARE(funcUShort->minimalSignature(), u"funcUShort(custom_ushort)"); const AbstractMetaType unsignedShortType = funcUnsignedShort->arguments().constFirst().type(); - QCOMPARE(unsignedShortType.cppSignature(), QLatin1String("unsigned short")); + QCOMPARE(unsignedShortType.cppSignature(), u"unsigned short"); QVERIFY(unsignedShortType.isPrimitive()); - QVERIFY(unsignedShortType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(unsignedShortType.typeEntry())); const AbstractMetaType ushortType = funcUShort->arguments().constFirst().type(); - QCOMPARE(ushortType.cppSignature(), QLatin1String("custom_ushort")); + QCOMPARE(ushortType.cppSignature(), u"custom_ushort"); QVERIFY(ushortType.isPrimitive()); - QVERIFY(ushortType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(ushortType.typeEntry())); } QTEST_APPLESS_MAIN(TestNumericalTypedef) diff --git a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.h b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.h index e4e051077..32f549836 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.h +++ b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.h @@ -1,35 +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 #ifndef TESTNUMERICALTYPEDEF_H #define TESTNUMERICALTYPEDEF_H -#include <QObject> +#include <QtCore/QObject> class TestNumericalTypedef : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp index e78f9f274..99cced09d 100644 --- a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp @@ -1,59 +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 "testprimitivetypetag.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> -#include <typesystem.h> +#include <primitivetypeentry.h> + +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; void TestPrimitiveTypeTag::testPrimitiveTypeDefaultConstructor() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {};\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <primitive-type name='A' default-constructor='A()'/>\n\ <object-type name='B'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + QCOMPARE(classes.size(), 1); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); - PrimitiveTypeEntry* typeEntry = TypeDatabase::instance()->findPrimitiveType(QLatin1String("A")); + auto typeEntry = TypeDatabase::instance()->findPrimitiveType(u"A"_s); QVERIFY(typeEntry); QVERIFY(typeEntry->hasDefaultConstructor()); - QCOMPARE(typeEntry->defaultConstructor(), QLatin1String("A()")); + QCOMPARE(typeEntry->defaultConstructor(), u"A()"); } QTEST_APPLESS_MAIN(TestPrimitiveTypeTag) diff --git a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.h b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.h index ee5f5159f..3a0e05138 100644 --- a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.h +++ b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.h @@ -1,35 +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 #ifndef TESTPRIMITIVETYPETAG_H #define TESTPRIMITIVETYPETAG_H -#include <QObject> +#include <QtCore/QObject> class TestPrimitiveTypeTag : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp index f3ffd0edf..f2e261624 100644 --- a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.cpp @@ -1,46 +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 "testrefcounttag.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <modifications.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestRefCountTag::testReferenceCountTag() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {\n\ void keepObject(B* b);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <object-type name='A'/>\n\ <object-type name='B'>\n\ @@ -52,11 +32,11 @@ void TestRefCountTag::testReferenceCountTag() </object-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - const auto func = classB->findFunction(QLatin1String("keepObject")); - QVERIFY(!func.isNull()); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + const auto func = classB->findFunction("keepObject"); + QVERIFY(func); const auto refCount = func->modifications().constFirst().argument_mods().constFirst().referenceCounts().constFirst(); QCOMPARE(refCount.action, ReferenceCount::Add); @@ -64,12 +44,12 @@ void TestRefCountTag::testReferenceCountTag() void TestRefCountTag::testWithApiVersion() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {\n\ void keepObject(B*, B*);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <object-type name='A'/>\n\ <object-type name='B'>\n\ @@ -85,12 +65,12 @@ void TestRefCountTag::testWithApiVersion() </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, - false, QLatin1String("0.1"))); - QVERIFY(!builder.isNull()); + false, u"0.1"_s)); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); - const auto func = classB->findFunction(QLatin1String("keepObject")); - QVERIFY(!func.isNull()); + const auto classB = AbstractMetaClass::findClass(classes, "B"); + const auto func = classB->findFunction("keepObject"); + QVERIFY(func); const auto refCount = func->modifications().constFirst().argument_mods().constFirst().referenceCounts().constFirst(); QCOMPARE(refCount.action, ReferenceCount::Add); diff --git a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.h b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.h index 4acbddcfc..6093c6f7b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testrefcounttag.h +++ b/sources/shiboken6/ApiExtractor/tests/testrefcounttag.h @@ -1,35 +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 #ifndef TESTREFCOUNTTAG_H #define TESTREFCOUNTTAG_H -#include <QObject> +#include <QtCore/QObject> class TestRefCountTag : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.cpp b/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.cpp index b929ebd66..ae85c5a86 100644 --- a/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.cpp @@ -1,58 +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 "testreferencetopointer.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> +#include <abstractmetatype.h> #include <typesystem.h> void TestReferenceToPointer::testReferenceToPointerArgument() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {\n\ void dummy(A*&);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <object-type name='A'/>\n\ <object-type name='B'/>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); - const auto func = classB->findFunction(QLatin1String("dummy")); - QVERIFY(!func.isNull()); - QCOMPARE(func->arguments().constFirst().type().minimalSignature(), QLatin1String("A*&")); + const auto func = classB->findFunction("dummy"); + QVERIFY(func); + QCOMPARE(func->arguments().constFirst().type().minimalSignature(), u"A*&"); } QTEST_APPLESS_MAIN(TestReferenceToPointer) diff --git a/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.h b/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.h index 0f717b55d..2a7b34807 100644 --- a/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.h +++ b/sources/shiboken6/ApiExtractor/tests/testreferencetopointer.h @@ -1,35 +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 #ifndef TESTREFERENCETOPOINTER_H #define TESTREFERENCETOPOINTER_H -#include <QObject> +#include <QtCore/QObject> class TestReferenceToPointer : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testremovefield.cpp b/sources/shiboken6/ApiExtractor/tests/testremovefield.cpp index 5fb2ff687..2cc82071b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremovefield.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testremovefield.cpp @@ -1,46 +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 "testremovefield.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafield.h> +#include <abstractmetafunction.h> +#include <abstractmetatype.h> #include <abstractmetalang.h> #include <typesystem.h> +using namespace Qt::StringLiterals; + void TestRemoveField::testRemoveField() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {\n\ int fieldA;\n\ int fieldB;\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <primitive-type name='int'/>\n\ <value-type name='A'>\n\ @@ -48,13 +28,47 @@ void TestRemoveField::testRemoveField() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QCOMPARE(classA->fields().size(), 1); const AbstractMetaField &fieldA = classA->fields().constFirst(); - QCOMPARE(fieldA.name(), QLatin1String("fieldA")); + QCOMPARE(fieldA.name(), u"fieldA"); +} + +// Verify that 'static constexpr' fields are seen as static/const and +// appear fully qualified for function parameter default values. +void TestRemoveField::testConstExprField() +{ + const char cppCode[] = R"( +struct A { + static constexpr int constExprField = 44; + + void f(int iParam=constExprField); +}; +)"; + + const char xmlCode[] = R"( +<typesystem package="Foo"> + <value-type name='A'/> +</typesystem> +)"; + + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); + QVERIFY(builder); + AbstractMetaClassList classes = builder->classes(); + const auto classA = AbstractMetaClass::findClass(classes, "A"); + QVERIFY(classA); + const auto &fields = classA->fields(); + QCOMPARE(fields.size(), 1); + QVERIFY(fields.constFirst().isStatic()); + QVERIFY(fields.constFirst().type().isConstant()); + const auto function = classA->findFunction("f"_L1); + QVERIFY(function); + const auto &arguments = function->arguments(); + QCOMPARE(arguments.size(), 1); + QCOMPARE(arguments.constFirst().defaultValueExpression(), "A::constExprField"_L1); } QTEST_APPLESS_MAIN(TestRemoveField) diff --git a/sources/shiboken6/ApiExtractor/tests/testremovefield.h b/sources/shiboken6/ApiExtractor/tests/testremovefield.h index 8b52cc32f..05912d99e 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremovefield.h +++ b/sources/shiboken6/ApiExtractor/tests/testremovefield.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 TESTREMOVEFIELD_H #define TESTREMOVEFIELD_H -#include <QObject> +#include <QtCore/QObject> class TestRemoveField : public QObject { Q_OBJECT private slots: void testRemoveField(); + void testConstExprField(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.cpp b/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.cpp index 41103c24e..87e318e95 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.cpp @@ -1,50 +1,27 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testremoveimplconv.h" #include "testutil.h" #include <QtTest/QTest> +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <complextypeentry.h> // When a constructor able to trigger implicity conversions is removed // it should not appear in the implicity conversion list. void TestRemoveImplConv::testRemoveImplConv() { - const char* cppCode ="\ + const char cppCode[] = "\ struct A {};\n\ struct B {};\n\ struct C {\n\ C(const A&);\n\ C(const B&);\n\ };\n"; - const char* xmlCode = "\ + const char xmlCode[] = "\ <typesystem package=\"Foo\">\n\ <value-type name='A'/>\n\ <value-type name='B'/>\n\ @@ -53,17 +30,17 @@ void TestRemoveImplConv::testRemoveImplConv() </value-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + QCOMPARE(classes.size(), 3); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); - const AbstractMetaClass *classC = AbstractMetaClass::findClass(classes, QLatin1String("C")); + const auto classC = AbstractMetaClass::findClass(classes, "C"); QVERIFY(classC); const auto implConv = classC->implicitConversions(); - QCOMPARE(implConv.count(), 1); + QCOMPARE(implConv.size(), 1); QCOMPARE(implConv.constFirst()->arguments().constFirst().type().typeEntry(), classB->typeEntry()); } diff --git a/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.h b/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.h index 9e96dc2e9..d11d30633 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.h +++ b/sources/shiboken6/ApiExtractor/tests/testremoveimplconv.h @@ -1,35 +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 #ifndef TESTREMOVEIMPLCONV_H #define TESTREMOVEIMPLCONV_H -#include <QObject> +#include <QtCore/QObject> class TestRemoveImplConv : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp index 9824d1bf0..17a069b5e 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.cpp @@ -1,63 +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 "testremoveoperatormethod.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <typesystem.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestRemoveOperatorMethod::testRemoveOperatorMethod() { - const char* cppCode ="\ - #include <stdint.h>\n\ - \n\ - struct Char {};\n\ - struct ByteArray {};\n\ - struct String {};\n\ - \n\ - struct A {\n\ - A& operator>>(char&);\n\ - A& operator>>(char*);\n\ - A& operator>>(short&);\n\ - A& operator>>(unsigned short&);\n\ - A& operator>>(int&);\n\ - A& operator>>(unsigned int&);\n\ - A& operator>>(int64_t&);\n\ - A& operator>>(uint64_t&);\n\ - A& operator>>(float&);\n\ - A& operator>>(double&);\n\ - A& operator>>(Char&);\n\ - A& operator>>(ByteArray&);\n\ - A& operator>>(String&);\n\ - };\n"; - const char* xmlCode = "\ + const char cppCode[] = R"(#include <cstdint> + +struct Char {}; +struct ByteArray {}; +struct String {}; + +struct A { + A& operator>>(char&); + A& operator>>(char*); + A& operator>>(short&); + A& operator>>(unsigned short&); + A& operator>>(int&); + A& operator>>(unsigned int&); + A& operator>>(int64_t&); + A& operator>>(uint64_t&); + A& operator>>(float&); + A& operator>>(double&); + A& operator>>(Char&); + A& operator>>(ByteArray&); + A& operator>>(String&); +}; +)"; + + const char xmlCode[] = "\ <typesystem package='Foo'>\n\ <primitive-type name='char'/>\n\ <primitive-type name='short'/>\n\ @@ -87,25 +68,25 @@ void TestRemoveOperatorMethod::testRemoveOperatorMethod() </object-type>\n\ </typesystem>\n"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QCOMPARE(classA->functions().size(), 14); QStringList removedSignatures; - removedSignatures.append(QLatin1String("operator>>(char&)")); - removedSignatures.append(QLatin1String("operator>>(char*)")); - removedSignatures.append(QLatin1String("operator>>(short&)")); - removedSignatures.append(QLatin1String("operator>>(unsigned short&)")); - removedSignatures.append(QLatin1String("operator>>(int&)")); - removedSignatures.append(QLatin1String("operator>>(unsigned int&)")); - removedSignatures.append(QLatin1String("operator>>(int64_t&)")); - removedSignatures.append(QLatin1String("operator>>(uint64_t&)")); - removedSignatures.append(QLatin1String("operator>>(float&)")); - removedSignatures.append(QLatin1String("operator>>(double&)")); - removedSignatures.append(QLatin1String("operator>>(Char&)")); - removedSignatures.append(QLatin1String("operator>>(String&)")); - int notRemoved = classA->functions().size(); + removedSignatures.append(u"operator>>(char&)"_s); + removedSignatures.append(u"operator>>(char*)"_s); + removedSignatures.append(u"operator>>(short&)"_s); + removedSignatures.append(u"operator>>(unsigned short&)"_s); + removedSignatures.append(u"operator>>(int&)"_s); + removedSignatures.append(u"operator>>(unsigned int&)"_s); + removedSignatures.append(u"operator>>(int64_t&)"_s); + removedSignatures.append(u"operator>>(uint64_t&)"_s); + removedSignatures.append(u"operator>>(float&)"_s); + removedSignatures.append(u"operator>>(double&)"_s); + removedSignatures.append(u"operator>>(Char&)"_s); + removedSignatures.append(u"operator>>(String&)"_s); + auto notRemoved = classA->functions().size(); for (const auto &f : classA->functions()) { QCOMPARE(f->isModifiedRemoved(), bool(removedSignatures.contains(f->minimalSignature()))); notRemoved -= int(f->isModifiedRemoved()); diff --git a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.h b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.h index 23c3e5144..6ec335e0c 100644 --- a/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.h +++ b/sources/shiboken6/ApiExtractor/tests/testremoveoperatormethod.h @@ -1,35 +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 #ifndef TESTREMOVEOPERATORMETHOD_H #define TESTREMOVEOPERATORMETHOD_H -#include <QObject> +#include <QtCore/QObject> class TestRemoveOperatorMethod : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp index 4c2930234..67ebcc606 100644 --- a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp @@ -1,40 +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 #include "testresolvetype.h" -#include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> +#include <abstractmetaenum.h> +#include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <complextypeentry.h> +#include <enumtypeentry.h> +#include <primitivetypeentry.h> +#include <typedatabase.h> + +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + +void TestResolveType::initTestCase() +{ + // For enum lookup in testFixDefaultArguments() + AbstractMetaBuilder::setCodeModelTestMode(true); +} void TestResolveType::testResolveReturnTypeFromParentScope() { - const char* cppCode = "\n\ + const char cppCode[] = "\n\ namespace A {\n\ struct B {\n\ struct C {};\n\ @@ -44,7 +37,7 @@ void TestResolveType::testResolveReturnTypeFromParentScope() C* method();\n\ };\n\ };"; - const char* xmlCode = R"XML( + const char xmlCode[] = R"XML( <typesystem package='Foo'> <namespace-type name='A'> <value-type name='B'> @@ -54,14 +47,235 @@ void TestResolveType::testResolveReturnTypeFromParentScope() </namespace-type> </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classD = AbstractMetaClass::findClass(classes, QLatin1String("A::D")); + const auto classD = AbstractMetaClass::findClass(classes, "A::D"); QVERIFY(classD); - const auto meth = classD->findFunction(QLatin1String("method")); - QVERIFY(!meth.isNull()); + const auto meth = classD->findFunction("method"); + QVERIFY(meth); QVERIFY(meth); } -QTEST_APPLESS_MAIN(TestResolveType) +// Helper classes and functions for testing default value fixing. +// Put the AbstractMetaBuilder into test fixture struct to avoid having +// to re-parse for each data row. + +struct DefaultValuesFixture +{ + std::shared_ptr<AbstractMetaBuilder> builder; + + AbstractMetaType intType; + AbstractMetaType stringType; + AbstractMetaType classType; + AbstractMetaType listType; + AbstractMetaType enumType; + AbstractMetaClassCPtr klass{}; +}; + +Q_DECLARE_METATYPE(DefaultValuesFixture) +Q_DECLARE_METATYPE(AbstractMetaType) + +static int populateDefaultValuesFixture(DefaultValuesFixture *fixture) +{ + static const char cppCode[] =R"( +#include <string> +#include <list> + +namespace Namespace { +class Test +{ +public: + enum Enum { enumValue1, enumValue2 }; + + explicit Test(int x = INT_FIELD_1); + explicit Test(const std::string &t = std::string(CHAR_FIELD_1)); + + static void listFunc(std::list<Test> list = std::list<Test>()); + + static const int INT_FIELD_1 = 42; + static const char *CHAR_FIELD_1; + static const Enum DefaultValue = enumValue1; +}; +} // Namespace +)"; + static const char xmlCode[] = R"( +<typesystem package="Foo"> + <namespace-type name='Namespace'> + <value-type name='Test'> + <enum-type name='Enum'/> + </value-type> + </namespace-type> + <container-type name="std::list" type="list"/> +</typesystem> +)"; + + fixture->builder.reset(TestUtil::parse(cppCode, xmlCode, false)); + if (!fixture->builder) + return -1; + + for (const auto &klass : fixture->builder->classes()) { + if (klass->name() == u"Test") { + fixture->klass = klass; + break; + } + } + if (!fixture->klass) + return -2; + + fixture->classType = AbstractMetaType(fixture->klass->typeEntry()); + fixture->classType.decideUsagePattern(); + + for (const auto &f : fixture->klass->findFunctions("Test")) { + if (f->functionType() == AbstractMetaFunction::ConstructorFunction + && f->arguments().size() == 1) { + const auto type = f->arguments().constFirst().type(); + if (type.name() == u"int") + fixture->intType = type; + else + fixture->stringType = type; + } + } + if (fixture->intType.isVoid() || fixture->stringType.isVoid()) + return -3; + + auto listFunc = fixture->klass->findFunction("listFunc"); + if (!listFunc || listFunc->arguments().size() != 1) + return -3; + fixture->listType = listFunc->arguments().constFirst().type(); + + fixture->enumType = AbstractMetaType(fixture->klass->enums().constFirst().typeEntry()); + fixture->enumType.decideUsagePattern(); + return 0; +} + +void TestResolveType::testFixDefaultArguments_data() +{ + DefaultValuesFixture fixture; + const int setupOk = populateDefaultValuesFixture(&fixture); + + QTest::addColumn<DefaultValuesFixture>("fixture"); + QTest::addColumn<int>("setupOk"); // To verify setup + QTest::addColumn<AbstractMetaType>("metaType"); // Type and parameters for fixup + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expected"); + + QTest::newRow("int") << fixture << setupOk + << fixture.intType << "1" << "1"; + QTest::newRow("int-macro") << fixture << setupOk + << fixture.intType << "GL_MACRO" << "GL_MACRO"; + QTest::newRow("int-enum") << fixture << setupOk + << fixture.intType << "enumValue1" << "Namespace::Test::Enum::enumValue1"; + + // Test expansion of container types + QString expected = u"std::list<Namespace::Test>()"_s; + QTest::newRow("list") + << fixture << setupOk << fixture.listType + << expected << expected; + QTest::newRow("partially qualified list") + << fixture << setupOk << fixture.listType + << "std::list<Test>()" << expected; + + // Test field expansion + expected = u"Namespace::Test::INT_FIELD_1"_s; + QTest::newRow("qualified class field") + << fixture << setupOk << fixture.intType + << expected << expected; + QTest::newRow("partially qualified class field") + << fixture << setupOk << fixture.intType + << "Test::INT_FIELD_1" << expected; + QTest::newRow("unqualified class field") + << fixture << setupOk << fixture.intType + << "INT_FIELD_1" << expected; + + // Test field expansion when constructing some class + expected = u"QLatin1String(Namespace::Test::CHAR_FIELD_1)"_s; + QTest::newRow("class from qualified class field") + << fixture << setupOk << fixture.classType + << expected << expected; + QTest::newRow("class from partially qualified class field") + << fixture << setupOk << fixture.classType + << "QLatin1String(Test::CHAR_FIELD_1)" << expected; + QTest::newRow("class from unqualified class field") + << fixture << setupOk << fixture.classType + << "QLatin1String(CHAR_FIELD_1)" << expected; + + // Test field expansion when constructing class itself + expected = u"Namespace::Test(Namespace::Test::CHAR_FIELD_1)"_s; + QTest::newRow("self from qualified class field") + << fixture << setupOk << fixture.classType + << expected << expected; + QTest::newRow("self from partially qualified class field") + << fixture << setupOk << fixture.classType + << "Test(Test::CHAR_FIELD_1)" << expected; + QTest::newRow("self from unqualified class field") + << fixture << setupOk << fixture.classType + << "Test(CHAR_FIELD_1)" << expected; + + // Test enum expansion when constructing class itself + expected = u"Namespace::Test(Namespace::Test::Enum::enumValue1)"_s; + QTest::newRow("self from qualified enum") + << fixture << setupOk << fixture.classType + << expected << expected; + QTest::newRow("self from enum") + << fixture << setupOk << fixture.classType + << "Test(enumValue1)" << expected; + + // Don't qualify fields to "Test::Enum::DefaultValue" + QTest::newRow("enum from static field") + << fixture << setupOk << fixture.enumType + << "DefaultValue" << u"Namespace::Test::DefaultValue"_s; +} + +void TestResolveType::testFixDefaultArguments() +{ + QFETCH(DefaultValuesFixture, fixture); + QFETCH(int, setupOk); + QFETCH(AbstractMetaType, metaType); + QFETCH(QString, input); + QFETCH(QString, expected); + QCOMPARE(setupOk, 0); + const QString actual = fixture.builder->fixDefaultValue(input, metaType, fixture.klass); + QCOMPARE(actual, expected); +} + +// Verify that the typedefs of the C++ 11 integer types (int32_t, ...) +// are seen by the C++ parser, otherwise they are handled as unknown +// primitive types, causing invalid code to be generated. +// (see BuilderPrivate::visitHeader(), +// sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp). +void TestResolveType::testCppTypes() +{ + static const char cppCode[] =R"( +#include <cstdint> + +class Test +{ +public: + explicit Test(int32_t v); +}; +)"; + static const char xmlCode[] = R"( +<typesystem package="Foo"> + <value-type name='Test'/> + <primitive-type name='int32_t'/> +</typesystem> +)"; + + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); + QVERIFY(builder); + AbstractMetaClassList classes = builder->classes(); + const auto testClass = AbstractMetaClass::findClass(classes, "Test"); + QVERIFY(testClass); + + auto *tdb = TypeDatabase::instance(); + auto int32TEntry = tdb->findType(u"int32_t"_s); + QVERIFY2(int32TEntry, "int32_t not found"); + QVERIFY(int32TEntry->isPrimitive()); + auto int32T = std::static_pointer_cast<const PrimitiveTypeEntry>(int32TEntry); + auto basicType = basicReferencedTypeEntry(int32T); + QVERIFY2(basicType != int32T, + "Typedef for int32_t not found. Check the system include paths."); +} + +QTEST_APPLESS_MAIN(TestResolveType) diff --git a/sources/shiboken6/ApiExtractor/tests/testresolvetype.h b/sources/shiboken6/ApiExtractor/tests/testresolvetype.h index 62c08bcd7..a07855eab 100644 --- a/sources/shiboken6/ApiExtractor/tests/testresolvetype.h +++ b/sources/shiboken6/ApiExtractor/tests/testresolvetype.h @@ -1,41 +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 TESTRESOLVETYPE_H #define TESTRESOLVETYPE_H -#include <QObject> +#include <QtCore/QObject> class TestResolveType : public QObject { Q_OBJECT private slots: + void initTestCase(); + void testResolveReturnTypeFromParentScope(); + void testFixDefaultArguments_data(); + void testFixDefaultArguments(); + void testCppTypes(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp index 3ad77c86f..f4eecff2c 100644 --- a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp @@ -1,37 +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 "testreverseoperators.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <typesystem.h> +#include <clangparser/compilersupport.h> + +#include <algorithm> void TestReverseOperators::testReverseSum() { @@ -46,16 +25,16 @@ void TestReverseOperators::testReverseSum() </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 4); + QCOMPARE(classA->functions().size(), 4); AbstractMetaFunctionCPtr reverseOp; AbstractMetaFunctionCPtr normalOp; for (const auto &func : classA->functions()) { - if (func->name() == QLatin1String("operator+")) { + if (func->name() == u"operator+") { if (func->isReverseOperator()) reverseOp = func; else @@ -63,12 +42,12 @@ void TestReverseOperators::testReverseSum() } } - QVERIFY(!normalOp.isNull()); + QVERIFY(normalOp); QVERIFY(!normalOp->isReverseOperator()); - QCOMPARE(normalOp->arguments().count(), 1); - QVERIFY(!reverseOp.isNull()); + QCOMPARE(normalOp->arguments().size(), 1); + QVERIFY(reverseOp); QVERIFY(reverseOp->isReverseOperator()); - QCOMPARE(reverseOp->arguments().count(), 1); + QCOMPARE(reverseOp->arguments().size(), 1); } void TestReverseOperators::testReverseSumWithAmbiguity() @@ -88,37 +67,63 @@ void TestReverseOperators::testReverseSumWithAmbiguity() </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - QCOMPARE(classA->functions().count(), 4); + QCOMPARE(classA->functions().size(), 4); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); - QCOMPARE(classB->functions().count(), 4); + QCOMPARE(classB->functions().size(), 4); AbstractMetaFunctionCPtr reverseOp; AbstractMetaFunctionCPtr normalOp; for (const auto &func : classB->functions()) { - if (func->name() == QLatin1String("operator+")) { + if (func->name() == u"operator+") { if (func->isReverseOperator()) reverseOp = func; else normalOp = func; } } - QVERIFY(!normalOp.isNull()); + QVERIFY(normalOp); QVERIFY(!normalOp->isReverseOperator()); - QCOMPARE(normalOp->arguments().count(), 1); - QCOMPARE(normalOp->minimalSignature(), QLatin1String("operator+(B,A)")); - QVERIFY(!reverseOp.isNull()); + QCOMPARE(normalOp->arguments().size(), 1); + QCOMPARE(normalOp->minimalSignature(), u"operator+(B,A)"); + QVERIFY(reverseOp); QVERIFY(reverseOp->isReverseOperator()); - QCOMPARE(reverseOp->arguments().count(), 1); - QCOMPARE(reverseOp->minimalSignature(), QLatin1String("operator+(A,B)")); + QCOMPARE(reverseOp->arguments().size(), 1); + QCOMPARE(reverseOp->minimalSignature(), u"operator+(A,B)"); } - +void TestReverseOperators::testSpaceshipOperator() +{ + const char cppCode[] = R"( + class Test { + public: + explicit Test(int v); + int operator<=>(const Test &rhs) const = default; + };)"; + const char xmlCode[] = R"( + <typesystem package="Foo"> + <value-type name='Test'/> + </typesystem>)"; + QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false, + {}, {}, LanguageLevel::Cpp20)); + QVERIFY(builder); + AbstractMetaClassList classes = builder->classes(); + QCOMPARE(classes.size(), 1); + const auto testClass = AbstractMetaClass::findClass(classes, "Test"); + QVERIFY(testClass); + const auto &functions = testClass->functions(); + // 6 operators should be synthesized + const auto count = std::count_if(functions.cbegin(), functions.cend(), + [](const AbstractMetaFunctionCPtr &f) { + return f->isComparisonOperator(); + }); + QCOMPARE(count, 6); +} QTEST_APPLESS_MAIN(TestReverseOperators) diff --git a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.h b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.h index ba3b43cfb..fb8d97c97 100644 --- a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.h +++ b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTREVERSEOPERATORS_H #define TESTREVERSEOPERATORS_H -#include <QObject> +#include <QtCore/QObject> class TestReverseOperators : public QObject { @@ -36,6 +11,7 @@ class TestReverseOperators : public QObject private slots: void testReverseSum(); void testReverseSumWithAmbiguity(); + void testSpaceshipOperator(); }; #endif diff --git a/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp b/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp index 2a5bd750d..ea37c6255 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp @@ -1,40 +1,23 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testtemplates.h" -#include <QtTest/QTest> -#include <QtCore/QTextStream> -#include <QTemporaryFile> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafield.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <abstractmetatype.h> +#include <complextypeentry.h> +#include <containertypeentry.h> + +#include <qtcompat.h> + +#include <QtCore/QTemporaryFile> +#include <QtCore/QTextStream> +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; void TestTemplates::testTemplateWithNamespace() { @@ -72,16 +55,16 @@ namespace Internet { </typesystem>)XML").arg(file.fileName()); QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, qPrintable(xmlCode1), false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("Bookmarks")); + const auto classB = AbstractMetaClass::findClass(classes, "Bookmarks"); QVERIFY(classB); - const auto func = classB->findFunction(QLatin1String("list")); - QVERIFY(!func.isNull()); + const auto func = classB->findFunction("list"); + QVERIFY(func); AbstractMetaType funcType = func->type(); QVERIFY(!funcType.isVoid()); - QCOMPARE(funcType.cppSignature(), QLatin1String("QList<Internet::Url >")); + QCOMPARE(funcType.cppSignature(), u"QList<Internet::Url>"); } void TestTemplates::testTemplateOnContainers() @@ -110,26 +93,26 @@ namespace Namespace { </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); QVERIFY(!classB->baseClass()); QVERIFY(classB->baseClassName().isEmpty()); - const auto func = classB->findFunction(QLatin1String("foo")); - QVERIFY(!func.isNull()); + const auto func = classB->findFunction("foo"); + QVERIFY(func); AbstractMetaType argType = func->arguments().constFirst().type(); - QCOMPARE(argType.instantiations().count(), 1); - QCOMPARE(argType.typeEntry()->qualifiedCppName(), QLatin1String("QList")); + QCOMPARE(argType.instantiations().size(), 1); + QCOMPARE(argType.typeEntry()->qualifiedCppName(), u"QList"); const AbstractMetaType &instance1 = argType.instantiations().constFirst(); - QCOMPARE(instance1.instantiations().count(), 1); - QCOMPARE(instance1.typeEntry()->qualifiedCppName(), QLatin1String("Namespace::A")); + QCOMPARE(instance1.instantiations().size(), 1); + QCOMPARE(instance1.typeEntry()->qualifiedCppName(), u"Namespace::A"); const AbstractMetaType &instance2 = instance1.instantiations().constFirst(); - QCOMPARE(instance2.instantiations().count(), 0); - QCOMPARE(instance2.typeEntry()->qualifiedCppName(), QLatin1String("Namespace::E1")); + QCOMPARE(instance2.instantiations().size(), 0); + QCOMPARE(instance2.typeEntry()->qualifiedCppName(), u"Namespace::E1"); } void TestTemplates::testTemplateValueAsArgument() @@ -147,14 +130,14 @@ void func(List<int> arg) {} </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); const auto globalFuncs = builder->globalFunctions(); - QCOMPARE(globalFuncs.count(), 1); + QCOMPARE(globalFuncs.size(), 1); const auto func = globalFuncs.constFirst(); - QCOMPARE(func->minimalSignature(), QLatin1String("func(List<int>)")); + QCOMPARE(func->minimalSignature(), u"func(List<int>)"); QCOMPARE(func->arguments().constFirst().type().cppSignature(), - QLatin1String("List<int >")); + u"List<int>"); } void TestTemplates::testTemplatePointerAsArgument() @@ -172,14 +155,14 @@ void func(List<int>* arg) {} </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaFunctionCList globalFuncs = builder->globalFunctions(); - QCOMPARE(globalFuncs.count(), 1); + QCOMPARE(globalFuncs.size(), 1); const auto func = globalFuncs.constFirst(); - QCOMPARE(func->minimalSignature(), QLatin1String("func(List<int>*)")); + QCOMPARE(func->minimalSignature(), u"func(List<int>*)"); QCOMPARE(func->arguments().constFirst().type().cppSignature(), - QLatin1String("List<int > *")); + u"List<int> *"); } void TestTemplates::testTemplateReferenceAsArgument() @@ -197,14 +180,14 @@ void func(List<int>& arg) {} </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); const auto globalFuncs = builder->globalFunctions(); - QCOMPARE(globalFuncs.count(), 1); + QCOMPARE(globalFuncs.size(), 1); const auto func = globalFuncs.constFirst(); - QCOMPARE(func->minimalSignature(), QLatin1String("func(List<int>&)")); + QCOMPARE(func->minimalSignature(), u"func(List<int>&)"); QCOMPARE(func->arguments().constFirst().type().cppSignature(), - QLatin1String("List<int > &")); + u"List<int> &"); } void TestTemplates::testTemplateParameterFixup() @@ -226,22 +209,21 @@ struct List { </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); const AbstractMetaClassList templates = builder->templates(); - QCOMPARE(templates.count(), 1); - const AbstractMetaClass *list = templates.constFirst(); - // Verify that the parameter of "void append(List l)" gets fixed to "List<T >" - const auto append = list->findFunction(QStringLiteral("append")); - QVERIFY(!append.isNull()); + QCOMPARE(templates.size(), 1); + AbstractMetaClassCPtr list = templates.constFirst(); + // Verify that the parameter of "void append(List l)" gets fixed to "List<T>" + const auto append = list->findFunction("append"); + QVERIFY(append); QCOMPARE(append->arguments().size(), 1); - QCOMPARE(append->arguments().at(0).type().cppSignature(), QLatin1String("List<T >")); + QCOMPARE(append->arguments().at(0).type().cppSignature(), u"List<T>"); // Verify that the parameter of "void erase(Iterator)" is not modified - const auto erase = list->findFunction(QStringLiteral("erase")); - QVERIFY(!erase.isNull()); + const auto erase = list->findFunction("erase"); + QVERIFY(erase); QCOMPARE(erase->arguments().size(), 1); - QEXPECT_FAIL("", "Clang: Some other code changes the parameter type", Abort); - QCOMPARE(erase->arguments().at(0).type().cppSignature(), QLatin1String("List::Iterator")); + QCOMPARE(erase->arguments().at(0).type().cppSignature(), u"List::Iterator"); } void TestTemplates::testInheritanceFromContainterTemplate() @@ -267,17 +249,17 @@ struct FooBars : public ListContainer<FooBar> {}; </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); AbstractMetaClassList templates = builder->templates(); - QCOMPARE(classes.count(), 2); - QCOMPARE(templates.count(), 1); + QCOMPARE(classes.size(), 2); + QCOMPARE(templates.size(), 1); - const AbstractMetaClass* foobars = AbstractMetaClass::findClass(classes, QLatin1String("FooBars")); - QCOMPARE(foobars->functions().count(), 4); + const auto foobars = AbstractMetaClass::findClass(classes, "FooBars"); + QCOMPARE(foobars->functions().size(), 4); - const AbstractMetaClass *lc = templates.constFirst(); - QCOMPARE(lc->functions().count(), 2); + AbstractMetaClassCPtr lc = templates.constFirst(); + QCOMPARE(lc->functions().size(), 2); } void TestTemplates::testTemplateInheritanceMixedWithForwardDeclaration() @@ -304,15 +286,15 @@ template<SomeEnum type> struct Future {}; </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); QVERIFY(!classB->baseClass()); QVERIFY(classB->baseClassName().isEmpty()); // 3 functions: simple constructor, copy constructor and "method()". - QCOMPARE(classB->functions().count(), 3); + QCOMPARE(classB->functions().size(), 3); } void TestTemplates::testTemplateInheritanceMixedWithNamespaceAndForwardDeclaration() @@ -343,15 +325,15 @@ template<SomeEnum type> struct Future {}; </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("Namespace::B")); + const auto classB = AbstractMetaClass::findClass(classes, "Namespace::B"); QVERIFY(classB); QVERIFY(!classB->baseClass()); QVERIFY(classB->baseClassName().isEmpty()); // 3 functions: simple constructor, copy constructor and "method()". - QCOMPARE(classB->functions().count(), 3); + QCOMPARE(classB->functions().size(), 3); } void TestTemplates::testTypedefOfInstantiationOfTemplateClass() @@ -363,7 +345,7 @@ enum ClassType { }; template<ClassType CLASS_TYPE> struct BaseTemplateClass { - inline ClassType getClassType() const { CLASS_TYPE; } + inline ClassType getClassType() const { return CLASS_TYPE; } }; typedef BaseTemplateClass<TypeOne> TypeOneClass; } @@ -379,30 +361,30 @@ typedef BaseTemplateClass<TypeOne> TypeOneClass; </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 3); + QCOMPARE(classes.size(), 3); - const AbstractMetaClass* base = AbstractMetaClass::findClass(classes, QLatin1String("BaseTemplateClass")); + const auto base = AbstractMetaClass::findClass(classes, "BaseTemplateClass"); QVERIFY(base); - const AbstractMetaClass* one = AbstractMetaClass::findClass(classes, QLatin1String("TypeOneClass")); + const auto one = AbstractMetaClass::findClass(classes, "TypeOneClass"); QVERIFY(one); QCOMPARE(one->templateBaseClass(), base); - QCOMPARE(one->functions().count(), base->functions().count()); + QCOMPARE(one->functions().size(), base->functions().size()); QVERIFY(one->isTypeDef()); - const ComplexTypeEntry* oneType = one->typeEntry(); - const ComplexTypeEntry* baseType = base->typeEntry(); + auto oneType = one->typeEntry(); + auto baseType = base->typeEntry(); QCOMPARE(oneType->baseContainerType(), baseType); - QCOMPARE(one->baseClassNames(), QStringList(QLatin1String("BaseTemplateClass<TypeOne>"))); + QCOMPARE(one->baseClassNames(), QStringList(u"NSpace::BaseTemplateClass<NSpace::TypeOne>"_s)); QVERIFY(one->hasTemplateBaseClassInstantiations()); AbstractMetaTypeList instantiations = one->templateBaseClassInstantiations(); - QCOMPARE(instantiations.count(), 1); + QCOMPARE(instantiations.size(), 1); const AbstractMetaType &inst = instantiations.constFirst(); QVERIFY(!inst.isEnum()); QVERIFY(!inst.typeEntry()->isEnum()); QVERIFY(inst.typeEntry()->isEnumValue()); - QCOMPARE(inst.cppSignature(), QLatin1String("NSpace::TypeOne")); + QCOMPARE(inst.cppSignature(), u"NSpace::TypeOne"); } void TestTemplates::testContainerTypeIncompleteArgument() @@ -428,27 +410,27 @@ typedef Vector<int> IntVector; </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - QCOMPARE(classes.count(), 1); + QCOMPARE(classes.size(), 1); - AbstractMetaClass* vector = AbstractMetaClass::findClass(classes, QLatin1String("IntVector")); + const auto vector = AbstractMetaClass::findClass(classes, "IntVector"); QVERIFY(vector); auto baseContainer = vector->typeEntry()->baseContainerType(); QVERIFY(baseContainer); - QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer)->containerKind(), - ContainerTypeEntry::VectorContainer); - QCOMPARE(vector->functions().count(), 4); + QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer.get())->containerKind(), + ContainerTypeEntry::ListContainer); + QCOMPARE(vector->functions().size(), 4); - const auto method = vector->findFunction(QLatin1String("method")); - QVERIFY(!method.isNull()); - QCOMPARE(method->signature(), QLatin1String("method(const Vector<int > & vector)")); + const auto method = vector->findFunction("method"); + QVERIFY(method); + QCOMPARE(method->signature(), u"method(const Vector<int> & vector)"); - const auto otherMethod = vector->findFunction(QLatin1String("otherMethod")); - QVERIFY(!otherMethod.isNull()); - QCOMPARE(otherMethod->signature(), QLatin1String("otherMethod()")); + const auto otherMethod = vector->findFunction("otherMethod"); + QVERIFY(otherMethod); + QCOMPARE(otherMethod->signature(), u"otherMethod()"); QVERIFY(!otherMethod->type().isVoid()); - QCOMPARE(otherMethod->type().cppSignature(), QLatin1String("Vector<int >")); + QCOMPARE(otherMethod->type().cppSignature(), u"Vector<int>"); } void TestTemplates::testNonTypeTemplates() @@ -472,12 +454,12 @@ Array<int, 2> foo(); </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); auto functions = builder->globalFunctions(); - QCOMPARE(functions.count(), 1); + QCOMPARE(functions.size(), 1); auto foo = functions.constFirst(); - QCOMPARE(foo->name(), QLatin1String("foo")); - QCOMPARE(foo->type().name(), QLatin1String("Array")); + QCOMPARE(foo->name(), u"foo"); + QCOMPARE(foo->type().name(), u"Array"); } // Perform checks on template inheritance; a typedef of a template class @@ -555,44 +537,42 @@ void TestTemplates::testTemplateTypeDefs() const QByteArray cppBa = cpp.toLocal8Bit(); const QByteArray xmlBa = xml.toLocal8Bit(); QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppBa.constData(), xmlBa.constData(), true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *optional = AbstractMetaClass::findClass(classes, QLatin1String("Optional")); + const auto optional = AbstractMetaClass::findClass(classes, "Optional"); QVERIFY(optional); // Find the typedef'ed class - const AbstractMetaClass *optionalInt = - AbstractMetaClass::findClass(classes, QLatin1String("IntOptional")); + const auto optionalInt = AbstractMetaClass::findClass(classes, "IntOptional"); QVERIFY(optionalInt); QCOMPARE(optionalInt->templateBaseClass(), optional); // Find the class typedef'ed in the typesystem XML - const AbstractMetaClass *xmlOptionalInt = - AbstractMetaClass::findClass(classes, QLatin1String("XmlIntOptional")); + const auto xmlOptionalInt = AbstractMetaClass::findClass(classes, "XmlIntOptional"); QVERIFY(xmlOptionalInt); QCOMPARE(xmlOptionalInt->templateBaseClass(), optional); // Check whether the value() method now has an 'int' return - const auto valueMethod = optionalInt->findFunction(QLatin1String("value")); - QVERIFY(!valueMethod.isNull()); - QCOMPARE(valueMethod->type().cppSignature(), QLatin1String("int")); + const auto valueMethod = optionalInt->findFunction("value"); + QVERIFY(valueMethod); + QCOMPARE(valueMethod->type().cppSignature(), u"int"); // ditto for typesystem XML - const auto xmlValueMethod = xmlOptionalInt->findFunction(QLatin1String("value")); - QVERIFY(!xmlValueMethod.isNull()); - QCOMPARE(xmlValueMethod->type().cppSignature(), QLatin1String("int")); + const auto xmlValueMethod = xmlOptionalInt->findFunction("value"); + QVERIFY(xmlValueMethod); + QCOMPARE(xmlValueMethod->type().cppSignature(), u"int"); // Check whether the m_value field is of type 'int' - const auto valueField = optionalInt->findField(QLatin1String("m_value")); + const auto valueField = optionalInt->findField(u"m_value"); QVERIFY(valueField.has_value()); - QCOMPARE(valueField->type().cppSignature(), QLatin1String("int")); + QCOMPARE(valueField->type().cppSignature(), u"int"); // ditto for typesystem XML const auto xmlValueField = - xmlOptionalInt->findField(QLatin1String("m_value")); + xmlOptionalInt->findField(u"m_value"); QVERIFY(xmlValueField.has_value()); - QCOMPARE(xmlValueField->type().cppSignature(), QLatin1String("int")); + QCOMPARE(xmlValueField->type().cppSignature(), u"int"); } void TestTemplates::testTemplateTypeAliases() @@ -626,22 +606,23 @@ public: </typesystem>)XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - auto testClass = AbstractMetaClass::findClass(classes, QLatin1String("Test")); + const auto testClass = AbstractMetaClass::findClass(classes, "Test"); QVERIFY(testClass); auto fields = testClass->fields(); - QCOMPARE(fields.count(), 1); + QCOMPARE(fields.size(), 1); auto fieldType = testClass->fields().at(0).type(); - QCOMPARE(fieldType.name(), QLatin1String("Container1")); + QCOMPARE(fieldType.name(), u"Container1"); QCOMPARE(fieldType.instantiations().size(), 1); - auto derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived")); + const auto derived = AbstractMetaClass::findClass(classes, "Derived"); QVERIFY(derived); auto base = derived->templateBaseClass(); - QCOMPARE(base->name(), QLatin1String("Container1")); + QVERIFY(base); + QCOMPARE(base->name(), u"Container1"); } QTEST_APPLESS_MAIN(TestTemplates) diff --git a/sources/shiboken6/ApiExtractor/tests/testtemplates.h b/sources/shiboken6/ApiExtractor/tests/testtemplates.h index c96e7fe4a..36800f723 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtemplates.h +++ b/sources/shiboken6/ApiExtractor/tests/testtemplates.h @@ -1,35 +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 #ifndef TESTTEMPLATES_H #define TESTTEMPLATES_H -#include <QObject> +#include <QtCore/QObject> class TestTemplates : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testtoposort.cpp b/sources/shiboken6/ApiExtractor/tests/testtoposort.cpp index 6126c2b42..50cefcfe9 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtoposort.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testtoposort.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 "testtoposort.h" #include "graph.h" diff --git a/sources/shiboken6/ApiExtractor/tests/testtoposort.h b/sources/shiboken6/ApiExtractor/tests/testtoposort.h index 012156dc9..4271d6a0e 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtoposort.h +++ b/sources/shiboken6/ApiExtractor/tests/testtoposort.h @@ -1,35 +1,10 @@ -/**************************************************************************** -** -** 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 TESTTOPOSORT_H #define TESTTOPOSORT_H -#include <QObject> +#include <QtCore/QObject> class TestTopoSort : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp b/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp index d8170f5e8..72dae8cc5 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp @@ -1,45 +1,27 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 "testtyperevision.h" -#include <QtTest/QTest> #include "testutil.h" #include <abstractmetaenum.h> #include <abstractmetalang.h> -#include <typesystem.h> +#include <complextypeentry.h> +#include <enumtypeentry.h> +#include <flagstypeentry.h> #include <typedatabase.h> +#include <qtcompat.h> + +#include <QtTest/QTest> + +using namespace Qt::StringLiterals; + void TestTypeRevision::testRevisionAttr() { - const char* cppCode = "class Rev_0 {};" + const char cppCode[] = "class Rev_0 {};" "class Rev_1 {};" "class Rev_2 { public: enum Rev_3 { X }; enum Rev_5 { Y }; };"; - const char* xmlCode = "<typesystem package=\"Foo\">" + const char xmlCode[] = "<typesystem package=\"Foo\">" "<value-type name=\"Rev_0\"/>" "<value-type name=\"Rev_1\" revision=\"1\"/>" "<object-type name=\"Rev_2\" revision=\"2\">" @@ -48,25 +30,25 @@ void TestTypeRevision::testRevisionAttr() "</object-type>" "</typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *rev0 = AbstractMetaClass::findClass(classes, QLatin1String("Rev_0")); + const auto rev0 = AbstractMetaClass::findClass(classes, "Rev_0"); QCOMPARE(rev0->typeEntry()->revision(), 0); - const AbstractMetaClass *rev1 = AbstractMetaClass::findClass(classes, QLatin1String("Rev_1")); + const auto rev1 = AbstractMetaClass::findClass(classes, "Rev_1"); QCOMPARE(rev1->typeEntry()->revision(), 1); - AbstractMetaClass *rev2 = AbstractMetaClass::findClass(classes, QLatin1String("Rev_2")); + const auto rev2 = AbstractMetaClass::findClass(classes, "Rev_2"); QCOMPARE(rev2->typeEntry()->revision(), 2); - auto rev3 = rev2->findEnum(QLatin1String("Rev_3")); + auto rev3 = rev2->findEnum(u"Rev_3"_s); QVERIFY(rev3.has_value()); QCOMPARE(rev3->typeEntry()->revision(), 3); - FlagsTypeEntry* rev4 = rev3->typeEntry()->flags(); + auto rev4 = rev3->typeEntry()->flags(); QCOMPARE(rev4->revision(), 4); - auto rev5 = rev2->findEnum(QLatin1String("Rev_5")); + auto rev5 = rev2->findEnum(u"Rev_5"_s); QVERIFY(rev5.has_value()); - const EnumTypeEntry *revEnumTypeEntry = rev5->typeEntry(); + EnumTypeEntryCPtr revEnumTypeEntry = rev5->typeEntry(); QCOMPARE(revEnumTypeEntry->revision(), 5); QCOMPARE(revEnumTypeEntry->flags()->revision(), 5); } @@ -100,7 +82,7 @@ class Bar20 {}; )XML"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true, version)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); QCOMPARE(builder->classes().size(), expectedClassCount); } diff --git a/sources/shiboken6/ApiExtractor/tests/testtyperevision.h b/sources/shiboken6/ApiExtractor/tests/testtyperevision.h index 3832c3883..84af839d2 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtyperevision.h +++ b/sources/shiboken6/ApiExtractor/tests/testtyperevision.h @@ -1,35 +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 #ifndef TESTTYPEREVISION_H #define TESTTYPEREVISION_H -#include <QObject> +#include <QtCore/QObject> class TestTypeRevision : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testutil.h b/sources/shiboken6/ApiExtractor/tests/testutil.h index 56ce8a72e..dc4e3b2da 100644 --- a/sources/shiboken6/ApiExtractor/tests/testutil.h +++ b/sources/shiboken6/ApiExtractor/tests/testutil.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 TESTUTIL_H #define TESTUTIL_H @@ -43,27 +18,28 @@ namespace TestUtil { static AbstractMetaBuilder *parse(const char *cppCode, const char *xmlCode, bool silent = true, - const QString &apiVersion = QString(), - const QStringList &dropTypeEntries = QStringList()) + const QString &apiVersion = {}, + const QStringList &dropTypeEntries = {}, + LanguageLevel languageLevel = LanguageLevel::Default) { ReportHandler::setSilent(silent); ReportHandler::startTimer(); - TypeDatabase* td = TypeDatabase::instance(true); + auto *td = TypeDatabase::instance(true); if (apiVersion.isEmpty()) TypeDatabase::clearApiVersions(); - else if (!TypeDatabase::setApiVersion(QLatin1String("*"), apiVersion)) + else if (!TypeDatabase::setApiVersion(QLatin1StringView("*"), apiVersion)) return nullptr; td->setDropTypeEntries(dropTypeEntries); QBuffer buffer; // parse typesystem buffer.setData(xmlCode); if (!buffer.open(QIODevice::ReadOnly)) - return Q_NULLPTR; + return nullptr; if (!td->parseFile(&buffer)) return nullptr; buffer.close(); // parse C++ code - QTemporaryFile tempSource(QDir::tempPath() + QLatin1String("/st_XXXXXX_main.cpp")); + QTemporaryFile tempSource(QDir::tempPath() + QLatin1StringView("/st_XXXXXX_main.cpp")); if (!tempSource.open()) { qWarning().noquote().nospace() << "Creation of temporary file failed: " << tempSource.errorString(); @@ -76,7 +52,7 @@ namespace TestUtil auto builder = std::make_unique<AbstractMetaBuilder>(); try { - if (!builder->build(arguments)) + if (!builder->build(arguments, {}, true, languageLevel)) return nullptr; } catch (const std::exception &e) { qWarning("%s", e.what()); diff --git a/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.cpp b/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.cpp index 1850025d6..98e30eac2 100644 --- a/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.cpp @@ -1,62 +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 #include "testvaluetypedefaultctortag.h" #include <QtTest/QTest> #include "testutil.h" #include <abstractmetalang.h> -#include <typesystem.h> +#include <complextypeentry.h> void TestValueTypeDefaultCtorTag::testValueTypeDefaultCtorTagArgument() { - const char* cppCode ="\n\ + const char cppCode[] = "\n\ struct A {\n\ A(int,int);\n\ };\n\ struct B {};\n\ "; - const char* xmlCode = "\n\ + const char xmlCode[] = "\n\ <typesystem package='Foo'>\n\ <primitive-type name='int' />\n\ <value-type name='A' default-constructor='A(0, 0)' />\n\ <value-type name='B' />\n\ </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); QVERIFY(classA->typeEntry()->hasDefaultConstructor()); - QCOMPARE(classA->typeEntry()->defaultConstructor(), QLatin1String("A(0, 0)")); + QCOMPARE(classA->typeEntry()->defaultConstructor(), u"A(0, 0)"); - const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); + const auto classB = AbstractMetaClass::findClass(classes, "B"); QVERIFY(classB); QVERIFY(!classB->typeEntry()->hasDefaultConstructor()); } diff --git a/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.h b/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.h index 244181707..192c07c1d 100644 --- a/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.h +++ b/sources/shiboken6/ApiExtractor/tests/testvaluetypedefaultctortag.h @@ -1,35 +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 #ifndef TESTVALUETYPEDEFAULTCTORTAG_H #define TESTVALUETYPEDEFAULTCTORTAG_H -#include <QObject> +#include <QtCore/QObject> class TestValueTypeDefaultCtorTag : public QObject { diff --git a/sources/shiboken6/ApiExtractor/tests/testvoidarg.cpp b/sources/shiboken6/ApiExtractor/tests/testvoidarg.cpp index 6d155dacc..a600181a5 100644 --- a/sources/shiboken6/ApiExtractor/tests/testvoidarg.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testvoidarg.cpp @@ -1,34 +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 "testvoidarg.h" #include <QtTest/QTest> #include "testutil.h" +#include <abstractmetaargument.h> #include <abstractmetafunction.h> #include <abstractmetalang.h> #include <typesystem.h> @@ -41,13 +17,13 @@ void TestVoidArg::testVoidParsedFunction() <value-type name='A'/>\n\ </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("a")); - QVERIFY(!addedFunc.isNull()); - QCOMPARE(addedFunc->arguments().count(), 0); + const auto addedFunc = classA->findFunction("a"); + QVERIFY(addedFunc); + QCOMPARE(addedFunc->arguments().size(), 0); } void TestVoidArg::testVoidAddedFunction() @@ -60,13 +36,13 @@ void TestVoidArg::testVoidAddedFunction() </value-type>\n\ </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("a")); - QVERIFY(!addedFunc.isNull()); - QCOMPARE(addedFunc->arguments().count(), 0); + const auto addedFunc = classA->findFunction("a"); + QVERIFY(addedFunc); + QCOMPARE(addedFunc->arguments().size(), 0); } @@ -78,13 +54,13 @@ void TestVoidArg::testVoidPointerParsedFunction() <value-type name='A' />\n\ </typesystem>"; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); - QVERIFY(!builder.isNull()); + QVERIFY(builder); AbstractMetaClassList classes = builder->classes(); - const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); + const auto classA = AbstractMetaClass::findClass(classes, "A"); QVERIFY(classA); - const auto addedFunc = classA->findFunction(QLatin1String("a")); - QVERIFY(!addedFunc.isNull()); - QCOMPARE(addedFunc->arguments().count(), 1); + const auto addedFunc = classA->findFunction("a"); + QVERIFY(addedFunc); + QCOMPARE(addedFunc->arguments().size(), 1); } diff --git a/sources/shiboken6/ApiExtractor/tests/testvoidarg.h b/sources/shiboken6/ApiExtractor/tests/testvoidarg.h index 44d90d075..191b9cfb2 100644 --- a/sources/shiboken6/ApiExtractor/tests/testvoidarg.h +++ b/sources/shiboken6/ApiExtractor/tests/testvoidarg.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to 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 TESTVOIDARG_H #define TESTVOIDARG_H -#include <QObject> +#include <QtCore/QObject> class TestVoidArg : public QObject { |