aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-02-26 14:59:38 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-02-26 20:10:00 +0000
commite9c89837f91bf608371a7e39903ecd4038f769c1 (patch)
tree20b99ab6e2a1a21582e538a64a4951de952959e4 /sources/shiboken2
parent2dd12f480d35194eaa2c97638cf972a09803c68a (diff)
shiboken: Extend the exception handling test
Turn the test into a data driven test to also test modifications to the class and typesystem level and test more cases, for example overriding modifications on a higher level. This is a preparation for giving the allow-thread attribute, which can currently only be used at a function level, a similar handling. Task-number: PYSIDE-62 Task-number: PYSIDE-931 Change-Id: Id5fe65b7d0edb4279b47aaa6e59dfb6cda2d75a3 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp105
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testmodifyfunction.h3
2 files changed, 97 insertions, 11 deletions
diff --git a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp
index af24689fe..5016f38c5 100644
--- a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp
+++ b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.cpp
@@ -315,23 +315,108 @@ void TestModifyFunction::testGlobalFunctionModification()
QCOMPARE(arg->defaultValueExpression(), QLatin1String("A()"));
}
-void TestModifyFunction::testExceptionSpecification()
+void TestModifyFunction::testScopedModifications_data()
{
- const char cppCode[] = R"CPP(
-struct A {
+ QTest::addColumn<QByteArray>("cppCode");
+ QTest::addColumn<QByteArray>("xmlCode");
+ QTest::addColumn<bool>("expectedGenerateUnspecified");
+ QTest::addColumn<bool>("expectedGenerateNonThrowing");
+ QTest::addColumn<bool>("expectedGenerateThrowing");
+
+ const QByteArray cppCode = R"CPP(
+struct Base {
+};
+
+struct A : public Base {
void unspecified();
void nonThrowing() noexcept;
void throwing() throw(int);
};
)CPP";
- const char xmlCode[] = R"XML(
-<typesystem package="Foo">
+
+ // Default: Off
+ QTest::newRow("none")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package= 'Foo'>
+ <primitive-type name='int'/>
+ <object-type name='Base'/>
+ <object-type name='A'/>
+</typesystem>)XML")
+ << false << false << false;
+
+ // Modify one function
+ QTest::newRow("modify-function1")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package='Foo'>
<primitive-type name='int'/>
+ <object-type name='Base'/>
<object-type name='A'>
<modify-function signature='throwing()' exception-handling='auto-on'/>
</object-type>
-</typesystem>)XML";
- QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
+</typesystem>)XML")
+ << false << false << true;
+
+ // Flip defaults by modifying functions
+ QTest::newRow("modify-function2")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package='Foo'>
+ <primitive-type name='int'/>
+ <object-type name='Base'/>
+ <object-type name='A'>
+ <modify-function signature='unspecified()' exception-handling='auto-on'/>
+ <modify-function signature='throwing()' exception-handling='off'/>
+ </object-type>
+</typesystem>)XML")
+ << true << false << false;
+
+ // Activate on type system level
+ QTest::newRow("typesystem-on")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package='Foo' exception-handling='auto-on'>
+ <primitive-type name='int'/>
+ <object-type name='Base'/>
+ <object-type name='A'/>
+</typesystem>)XML")
+ << true << false << true;
+
+ // Activate on class level
+ QTest::newRow("class-on")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package='Foo'>
+ <primitive-type name='int'/>
+ <object-type name='Base'/>
+ <object-type name='A' exception-handling='auto-on'/>
+</typesystem>)XML")
+ << true << false << true;
+
+ // Override value on class level
+ QTest::newRow("override-class-on")
+ << cppCode
+ << QByteArray(R"XML(
+<typesystem package='Foo'>
+ <primitive-type name='int'/>
+ <object-type name='Base'/>
+ <object-type name='A' exception-handling='auto-on'>
+ <modify-function signature='throwing()' exception-handling='no'/>
+ </object-type>
+</typesystem>)XML")
+ << true << false << false;
+}
+
+void TestModifyFunction::testScopedModifications()
+{
+ QFETCH(QByteArray, cppCode);
+ QFETCH(QByteArray, xmlCode);
+ QFETCH(bool, expectedGenerateUnspecified);
+ QFETCH(bool, expectedGenerateNonThrowing);
+ QFETCH(bool, expectedGenerateThrowing);
+
+ QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode.constData(), xmlCode.constData(), false));
QVERIFY(!builder.isNull());
const AbstractMetaClass *classA = AbstractMetaClass::findClass(builder->classes(), QLatin1String("A"));
@@ -340,17 +425,17 @@ struct A {
const AbstractMetaFunction *f = classA->findFunction(QStringLiteral("unspecified"));
QVERIFY(f);
QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::Unknown);
- QVERIFY(!f->generateExceptionHandling());
+ QCOMPARE(f->generateExceptionHandling(), expectedGenerateUnspecified);
f = classA->findFunction(QStringLiteral("nonThrowing"));
QVERIFY(f);
QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::NoExcept);
- QVERIFY(!f->generateExceptionHandling());
+ QCOMPARE(f->generateExceptionHandling(), expectedGenerateNonThrowing);
f = classA->findFunction(QStringLiteral("throwing"));
QVERIFY(f);
QCOMPARE(f->exceptionSpecification(), ExceptionSpecification::Throws);
- QVERIFY(f->generateExceptionHandling());
+ QCOMPARE(f->generateExceptionHandling(), expectedGenerateThrowing);
}
QTEST_APPLESS_MAIN(TestModifyFunction)
diff --git a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.h b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.h
index 494f31991..375111e03 100644
--- a/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.h
+++ b/sources/shiboken2/ApiExtractor/tests/testmodifyfunction.h
@@ -42,7 +42,8 @@ class TestModifyFunction : public QObject
void testRenameArgument();
void invalidateAfterUse();
void testGlobalFunctionModification();
- void testExceptionSpecification();
+ void testScopedModifications_data();
+ void testScopedModifications();
};
#endif