From a22d281cc60532a8044add5a5abd7b5a59545b68 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 25 Jun 2014 18:17:58 +0300 Subject: [PATCH] CppEditor: Add failing tests for "Move Definition Outside Class"... ... when macros are used in function definition Task-number: QTCREATORBUG-12314 Change-Id: I811f93cde3dffa75fb71684569706f284939d7f5 Reviewed-by: Nikolai Kosjar --- src/plugins/cppeditor/cppeditorplugin.h | 2 + src/plugins/cppeditor/cppquickfix_test.cpp | 69 +++++++++++++++++++++- src/plugins/cppeditor/cppquickfix_test.h | 3 +- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index c6c2d77d3dd..ec1f6aa8eb9 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -182,6 +182,7 @@ private slots: void test_quickfix_MoveFuncDefOutside_afterClass(); void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1(); void test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2(); + void test_quickfix_MoveFuncDefOutside_macroUses(); void test_quickfix_MoveFuncDefToDecl_MemberFunc(); void test_quickfix_MoveFuncDefToDecl_MemberFuncOutside(); @@ -192,6 +193,7 @@ private slots: void test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS(); void test_quickfix_MoveFuncDefToDecl_CtorWithInitialization(); void test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable(); + void test_quickfix_MoveFuncDefToDecl_macroUses(); void test_quickfix_AssignToLocalVariable_templates(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 745362f4fe6..ce9853714b0 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -124,7 +124,8 @@ static QString &removeTrailingWhitespace(QString &input) QuickFixTestCase::QuickFixTestCase(const QList &theTestFiles, CppQuickFixFactory *factory, const ProjectPart::HeaderPaths &headerPaths, - int resultIndex) + int resultIndex, + const QByteArray &expectedFailMessage) : m_testFiles(theTestFiles) , m_cppCodeStylePreferences(0) , m_restoreHeaderPaths(false) @@ -196,6 +197,8 @@ QuickFixTestCase::QuickFixTestCase(const QList &theTe // Check QString result = testFile->m_editorWidget->document()->toPlainText(); removeTrailingWhitespace(result); + if (!expectedFailMessage.isEmpty()) + QEXPECT_FAIL("", expectedFailMessage.data(), Continue); QCOMPARE(result, testFile->m_expectedSource); // Undo the change @@ -3007,6 +3010,39 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2 QuickFixTestCase(singleDocument(original, expected), &factory); } +void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_macroUses() +{ + QByteArray original = + "#define CONST const\n" + "#define VOLATILE volatile\n" + "class Foo\n" + "{\n" + " int fu@nc(int a, int b) CONST VOLATILE\n" + " {\n" + " return 42;\n" + " }\n" + "};\n"; + QByteArray expected = + "#define CONST const\n" + "#define VOLATILE volatile\n" + "class Foo\n" + "{\n" + " int func(int a, int b) CONST VOLATILE;\n" + "};\n" + "\n" + "\n" + // const volatile become lowercase: QTCREATORBUG-12620 + "int Foo::func(int a, int b) const volatile\n" + "{\n" + " return 42;\n" + "}\n" + ; + + MoveFuncDefOutside factory; + QuickFixTestCase(singleDocument(original, expected), &factory, + ProjectPart::HeaderPaths(), 0, "QTCREATORBUG-12314"); +} + /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp() void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc() { @@ -3310,6 +3346,37 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable QuickFixTestCase(singleDocument(original, expected), &factory); } +void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_macroUses() +{ + QByteArray original = + "#define CONST const\n" + "#define VOLATILE volatile\n" + "class Foo\n" + "{\n" + " int func(int a, int b) CONST VOLATILE;\n" + "};\n" + "\n" + "\n" + "int Foo::fu@nc(int a, int b) CONST VOLATILE" + "{\n" + " return 42;\n" + "}\n"; + QByteArray expected = + "#define CONST const\n" + "#define VOLATILE volatile\n" + "class Foo\n" + "{\n" + " int func(int a, int b) CONST VOLATILE\n" + " {\n" + " return 42;\n" + " }\n" + "};\n\n\n\n"; + + MoveFuncDefToDecl factory; + QuickFixTestCase(singleDocument(original, expected), &factory, + ProjectPart::HeaderPaths(), 0, "QTCREATORBUG-12314"); +} + void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates() { diff --git a/src/plugins/cppeditor/cppquickfix_test.h b/src/plugins/cppeditor/cppquickfix_test.h index f15335cf0bc..a898c8bb36b 100644 --- a/src/plugins/cppeditor/cppquickfix_test.h +++ b/src/plugins/cppeditor/cppquickfix_test.h @@ -76,7 +76,8 @@ public: CppQuickFixFactory *factory, const CppTools::ProjectPart::HeaderPaths &includePaths = CppTools::ProjectPart::HeaderPaths(), - int resultIndex = 0); + int resultIndex = 0, + const QByteArray &expectedFailMessage = QByteArray()); ~QuickFixTestCase(); static void run(const QList &theTestFiles,