From 4630f179107a2b2548b68b3e7701c16ed2f8d52b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 21 Sep 2018 11:06:52 +0200 Subject: shiboken: Flip the default behavior the --api-version option When no option was passed, all type system entries with a "since" would be silently excluded. For example, the scriptable application would only see Qt API that does not have a "since" attribute. This could be fixed by adding version options for all dependent Qt libraries it uses to the build steps, but this is tedious and error-prone. Flip the behavior such that an empty version list specification means "latest". Add helper functionality to clear the versions to the TypeDatabase and use that in the tests to start out with a clean list. Change the tests to use a QString for the version. Add a test for the new behavior. Task-number: PYSIDE-814 Change-Id: Ie6137ba6095ce562813bacbadbf4028d0e2c061f Reviewed-by: Alexandru Croitor --- .../ApiExtractor/tests/testabstractmetatype.cpp | 6 ++-- .../ApiExtractor/tests/testaddfunction.cpp | 3 +- .../ApiExtractor/tests/testcodeinjection.cpp | 6 ++-- .../ApiExtractor/tests/testdroptypeentries.cpp | 6 ++-- sources/shiboken2/ApiExtractor/tests/testenum.cpp | 3 +- .../ApiExtractor/tests/testmodifyfunction.cpp | 9 ++++-- .../ApiExtractor/tests/testrefcounttag.cpp | 3 +- .../ApiExtractor/tests/testtyperevision.cpp | 34 ++++++++++++++++++++++ .../ApiExtractor/tests/testtyperevision.h | 2 ++ sources/shiboken2/ApiExtractor/tests/testutil.h | 8 +++-- 10 files changed, 65 insertions(+), 15 deletions(-) (limited to 'sources/shiboken2/ApiExtractor/tests') diff --git a/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp b/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp index 86bf64495..fc67ebba5 100644 --- a/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testabstractmetatype.cpp @@ -103,7 +103,8 @@ void TestAbstractMetaType::testApiVersionSupported() \n\ \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, "1.0")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + false, QLatin1String("1.0"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); @@ -121,7 +122,8 @@ void TestAbstractMetaType::testApiVersionNotSupported() const char* xmlCode = "\n\ \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + true, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); diff --git a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp index 2a953243e..db49942c9 100644 --- a/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testaddfunction.cpp @@ -366,7 +366,8 @@ void TestAddFunction::testAddFunctionWithApiVersion() custom_code();\n\ \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + true, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaFunctionList globalFuncs = builder->globalFunctions(); QCOMPARE(globalFuncs.count(), 1); diff --git a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp index 7bbde3bd4..bf1057ee9 100644 --- a/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testcodeinjection.cpp @@ -74,7 +74,8 @@ void TestCodeInjections::testInjectWithValidApiVersion() \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, "1.0")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + true, QLatin1String("1.0"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); @@ -93,7 +94,8 @@ void TestCodeInjections::testInjectWithInvalidApiVersion() \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + true, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); diff --git a/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp b/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp index b46c23f56..6abebb922 100644 --- a/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp @@ -70,7 +70,8 @@ void TestDropTypeEntries::testDropEntries() droppedEntries << QLatin1String("Foo.ObjectB") << QLatin1String("Foo.NamespaceA.InnerClassA"); droppedEntries << QLatin1String("Foo.NamespaceB") << QLatin1String("Foo.EnumB") << QLatin1String("Foo.funcB()"); droppedEntries << QLatin1String("Foo.NamespaceA.InnerNamespaceA"); - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, Q_NULLPTR, droppedEntries)); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, + QString(), droppedEntries)); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); @@ -129,7 +130,8 @@ static const char* xmlCode2 = "\ void TestDropTypeEntries::testDropEntryWithChildTags() { QStringList droppedEntries(QLatin1String("Foo.ValueA")); - QScopedPointer builder(TestUtil::parse(cppCode2, xmlCode2, false, Q_NULLPTR, droppedEntries)); + QScopedPointer builder(TestUtil::parse(cppCode2, xmlCode2, false, + QString(), droppedEntries)); QVERIFY(!builder.isNull()); QVERIFY(!AbstractMetaClass::findClass(builder->classes(), QLatin1String("ValueA"))); } diff --git a/sources/shiboken2/ApiExtractor/tests/testenum.cpp b/sources/shiboken2/ApiExtractor/tests/testenum.cpp index 87f2608a1..ebdcf8d81 100644 --- a/sources/shiboken2/ApiExtractor/tests/testenum.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testenum.cpp @@ -104,7 +104,8 @@ void TestEnum::testEnumWithApiVersion() \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + true, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); QCOMPARE(classes.count(), 1); diff --git a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp index 8bb63c6b1..33d75f804 100644 --- a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp @@ -136,7 +136,8 @@ void TestModifyFunction::invalidateAfterUse() \n\ \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + false, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); @@ -208,7 +209,8 @@ void TestModifyFunction::testWithApiVersion() \n\ \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + false, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); AbstractMetaClass* classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); @@ -242,7 +244,8 @@ struct A { )XML"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + false, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A")); diff --git a/sources/shiboken2/ApiExtractor/tests/testrefcounttag.cpp b/sources/shiboken2/ApiExtractor/tests/testrefcounttag.cpp index 11cda3317..38099c455 100644 --- a/sources/shiboken2/ApiExtractor/tests/testrefcounttag.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testrefcounttag.cpp @@ -82,7 +82,8 @@ void TestRefCountTag::testWithApiVersion() \n\ \n"; - QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, false, "0.1")); + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, + false, QLatin1String("0.1"))); QVERIFY(!builder.isNull()); AbstractMetaClassList classes = builder->classes(); const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B")); diff --git a/sources/shiboken2/ApiExtractor/tests/testtyperevision.cpp b/sources/shiboken2/ApiExtractor/tests/testtyperevision.cpp index a3130e499..a7e88e437 100644 --- a/sources/shiboken2/ApiExtractor/tests/testtyperevision.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testtyperevision.cpp @@ -31,6 +31,7 @@ #include "testutil.h" #include #include +#include void TestTypeRevision::testRevisionAttr() { @@ -67,6 +68,39 @@ void TestTypeRevision::testRevisionAttr() QCOMPARE(revEnumTypeEntry->flags()->revision(), 5); } + +void TestTypeRevision::testVersion_data() +{ + QTest::addColumn("version"); + QTest::addColumn("expectedClassCount"); + + QTest::newRow("none") << QString() << 2; + QTest::newRow("1.0") << QString::fromLatin1("1.0") << 1; // Bar20 excluded + QTest::newRow("2.0") << QString::fromLatin1("2.0") << 2; +} + +void TestTypeRevision::testVersion() +{ + QFETCH(QString, version); + QFETCH(int, expectedClassCount); + + const char cppCode[] = R"CPP( +class Bar {}; +class Bar20 {}; +)CPP"; + const char xmlCode[] = R"XML( + + + + +)XML"; + + QScopedPointer builder(TestUtil::parse(cppCode, xmlCode, true, version)); + QVERIFY(!builder.isNull()); + + QCOMPARE(builder->classes().size(), expectedClassCount); +} + QTEST_APPLESS_MAIN(TestTypeRevision) diff --git a/sources/shiboken2/ApiExtractor/tests/testtyperevision.h b/sources/shiboken2/ApiExtractor/tests/testtyperevision.h index 4dfa241e3..3832c3883 100644 --- a/sources/shiboken2/ApiExtractor/tests/testtyperevision.h +++ b/sources/shiboken2/ApiExtractor/tests/testtyperevision.h @@ -37,6 +37,8 @@ class TestTypeRevision : public QObject private slots: void testRevisionAttr(); + void testVersion_data(); + void testVersion(); }; #endif diff --git a/sources/shiboken2/ApiExtractor/tests/testutil.h b/sources/shiboken2/ApiExtractor/tests/testutil.h index dea6d92d8..c6ad19d7e 100644 --- a/sources/shiboken2/ApiExtractor/tests/testutil.h +++ b/sources/shiboken2/ApiExtractor/tests/testutil.h @@ -40,13 +40,15 @@ namespace TestUtil { static AbstractMetaBuilder *parse(const char *cppCode, const char *xmlCode, bool silent = true, - const char *apiVersion = Q_NULLPTR, + const QString &apiVersion = QString(), const QStringList &dropTypeEntries = QStringList()) { ReportHandler::setSilent(silent); TypeDatabase* td = TypeDatabase::instance(true); - if (apiVersion && !td->setApiVersion(QLatin1String("*"), QLatin1String(apiVersion))) - return Q_NULLPTR; + if (apiVersion.isEmpty()) + TypeDatabase::clearApiVersions(); + else if (!td->setApiVersion(QLatin1String("*"), apiVersion)) + return nullptr; td->setDropTypeEntries(dropTypeEntries); QBuffer buffer; // parse typesystem -- cgit v1.2.3