aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-22 11:09:18 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-05 14:11:33 +0100
commit2a7f16dccfa1986bb79d08c90ed2ef56133994e8 (patch)
treec72a427ce7e873e739d059ee7a85c8b2e42a9ca1 /sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp
parent8b414806b80683e162133338c4b3ca0816746aaa (diff)
shiboken6: Remove ShibokenGenerator::guessScopeForDefaultValue()
Move resolving of class fields and enum values as argument default values into AbstractMetaBuilder. Handling of static class field constants was spread between AbstractMetaBuilderPrivate::fixDefaultValue() and ShibokenGenerator::guessScopeForDefaultValue(). The former was handling it for arguments of non-primitive type only and not completely expanding namespaces. The latter was handling it for arguments of primitive types, too, but also added some code for non-static fields, which cannot be used as default arguments in C++. ShibokenGenerator::guessScopeForDefaultValue() was handling enum values for primitive and values, excluding macros by regex, but otherwise not checking if the term is really an enum value. Rewrite the code in AbstractMetaBuilderPrivate::fixDefaultValue() without regexes for clarity, let it check fields and enum values correctly via code model and fully expand namespaces. Add tests. Adapt the signature module to the now fully qualified signatures. [ChangeLog][shiboken6] When qualifying function argument default values for the generated code, shiboken no longer considers each identifier it cannot otherwise find as an enum value and no longer adds the class scope to it. This may require manually adding some replace-default-expression modifications. Task-number: PYSIDE-1691 Pick-to: 6.2 Change-Id: Id4cd2ca1f91db8c1663d7fc31e4b4ef72a5690f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp61
1 files changed, 60 insertions, 1 deletions
diff --git a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp
index 7fc55b254..c4d6238b3 100644
--- a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp
@@ -34,6 +34,12 @@
#include <abstractmetatype.h>
#include <typesystem.h>
+void TestResolveType::initTestCase()
+{
+ // For enum lookup in testFixDefaultArguments()
+ AbstractMetaBuilder::setCodeModelTestMode(true);
+}
+
void TestResolveType::testResolveReturnTypeFromParentScope()
{
const char* cppCode = "\n\
@@ -93,6 +99,8 @@ 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));
@@ -106,7 +114,9 @@ public:
static const char xmlCode[] = R"(
<typesystem package="Foo">
<namespace-type name='Namespace'>
- <value-type name='Test'/>
+ <value-type name='Test'>
+ <enum-type name='Enum'/>
+ </value-type>
</namespace-type>
<container-type name="std::list" type="list"/>
</typesystem>
@@ -162,6 +172,10 @@ void TestResolveType::testFixDefaultArguments_data()
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>()"_qs;
@@ -171,6 +185,51 @@ void TestResolveType::testFixDefaultArguments_data()
QTest::newRow("partially qualified list")
<< fixture << setupOk << fixture.listType
<< "std::list<Test>()" << expected;
+
+ // Test field expansion
+ expected = u"Namespace::Test::INT_FIELD_1"_qs;
+ 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)"_qs;
+ 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)"_qs;
+ 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)"_qs;
+ QTest::newRow("self from qualified enum")
+ << fixture << setupOk << fixture.classType
+ << expected << expected;
+ QTest::newRow("self from enum")
+ << fixture << setupOk << fixture.classType
+ << "Test(enumValue1)" << expected;
}
void TestResolveType::testFixDefaultArguments()