diff options
author | Christian Stenger <christian.stenger@qt.io> | 2022-04-06 09:07:04 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2022-04-11 10:44:15 +0000 |
commit | 2f64cf477955fcb56bfe9037269578918882a8e3 (patch) | |
tree | f5599e378fa012020cdc277fb900d6f4ffc0a12e /src/plugins/cppeditor/cppquickfix_test.cpp | |
parent | 0180f245526649780bf9bf980e515f60d2bf7c25 (diff) | |
download | qt-creator-2f64cf477955fcb56bfe9037269578918882a8e3.tar.gz |
CppEditor: Do not crash on anonymous classes
While performing generate getters and setters we crashed
when using members of anonymous classes.
Change-Id: I27dc8da950345aa4e26ddb1da3914edcffad5af3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppquickfix_test.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppquickfix_test.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 6a6b27b383..ce17fbdf9b 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -3273,6 +3273,58 @@ void QuickfixTest::testGenerateGetterSetterOnlySetter() QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 0); } +void QuickfixTest::testGenerateGetterSetterAnonymousClass() +{ + QList<TestDocumentPtr> testDocuments; + QByteArray original; + QByteArray expected; + QuickFixSettings s; + s->setterInCppFileFrom = 1; + s->setterParameterNameTemplate = "value"; + + // Header File + original = R"( + class { + int @m_foo; + } bar; +)"; + expected = R"( + class { + int m_foo; + + public: + int foo() const + { + return m_foo; + } + void setFoo(int value) + { + if (m_foo == value) + return; + m_foo = value; + emit fooChanged(); + } + void resetFoo() + { + setFoo({}); // TODO: Adapt to use your actual default defaultValue + } + + signals: + void fooChanged(); + + private: + Q_PROPERTY(int foo READ foo WRITE setFoo RESET resetFoo NOTIFY fooChanged) + } bar; +)"; + testDocuments << CppTestDocument::create("file.h", original, expected); + + // Source File + testDocuments << CppTestDocument::create("file.cpp", {}, {}); + + GenerateGetterSetter factory; + QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 4); +} + void QuickfixTest::testGenerateGetterSetterInlineInHeaderFile() { QList<TestDocumentPtr> testDocuments; |