diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro index a78e22c7fe9..d646ca23b18 100644 --- a/src/plugins/cppeditor/cppeditor.pro +++ b/src/plugins/cppeditor/cppeditor.pro @@ -38,8 +38,11 @@ SOURCES += cppeditorplugin.cpp \ RESOURCES += cppeditor.qrc equals(TEST, 1) { + HEADERS += cppquickfix_test_utils.h + SOURCES += \ cppquickfix_test.cpp \ + cppquickfix_test_utils.cpp \ cppdoxygen_test.cpp \ fileandtokenactions_test.cpp \ followsymbol_switchmethoddecldef_test.cpp diff --git a/src/plugins/cppeditor/cppeditor.qbs b/src/plugins/cppeditor/cppeditor.qbs index 079025a112e..39533511cdb 100644 --- a/src/plugins/cppeditor/cppeditor.qbs +++ b/src/plugins/cppeditor/cppeditor.qbs @@ -59,6 +59,8 @@ QtcPlugin { files: [ "cppdoxygen_test.cpp", "cppquickfix_test.cpp", + "cppquickfix_test_utils.cpp", + "cppquickfix_test_utils.h", "fileandtokenactions_test.cpp", "followsymbol_switchmethoddecldef_test.cpp" ] diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 0bd5554f22b..351536db420 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -27,6 +27,8 @@ ** ****************************************************************************/ +#include "cppquickfix_test_utils.h" + #include "cppeditor.h" #include "cppeditorplugin.h" #include "cppquickfixassistant.h" @@ -3121,33 +3123,6 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noSignatureMatch() data.run(&factory); } -/// Test dialog for insert virtual functions -class InsertVirtualMethodsDialogTest : public InsertVirtualMethodsDialog -{ -public: - InsertVirtualMethodsDialogTest(ImplementationMode mode, bool virt, QWidget *parent = 0) - : InsertVirtualMethodsDialog(parent) - { - setImplementationsMode(mode); - setInsertKeywordVirtual(virt); - } - - bool gather() - { - return true; - } - - ImplementationMode implementationMode() const - { - return m_implementationMode; - } - - bool insertKeywordVirtual() const - { - return m_insertKeywordVirtual; - } -}; - /// Check: Insert only declarations void CppEditorPlugin::test_quickfix_InsertVirtualMethods_onlyDecl() { diff --git a/src/plugins/cppeditor/cppquickfix_test_utils.cpp b/src/plugins/cppeditor/cppquickfix_test_utils.cpp new file mode 100644 index 00000000000..c42a66a2576 --- /dev/null +++ b/src/plugins/cppeditor/cppquickfix_test_utils.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cppquickfix_test_utils.h" + +#include "cppquickfixes.h" + +using namespace CppEditor::Internal; + +InsertVirtualMethodsDialogTest::InsertVirtualMethodsDialogTest(ImplementationMode mode, + bool insertVirtualKeyword, + QWidget *parent) + : InsertVirtualMethodsDialog(parent) +{ + setImplementationsMode(mode); + setInsertKeywordVirtual(insertVirtualKeyword); +} + +InsertVirtualMethodsDialog::ImplementationMode InsertVirtualMethodsDialogTest::implementationMode() const +{ + return m_implementationMode; +} + +bool InsertVirtualMethodsDialogTest::insertKeywordVirtual() const +{ + return m_insertKeywordVirtual; +} + +bool InsertVirtualMethodsDialogTest::gather() +{ + return true; +} diff --git a/src/plugins/cppeditor/cppquickfix_test_utils.h b/src/plugins/cppeditor/cppquickfix_test_utils.h new file mode 100644 index 00000000000..e8ca190b929 --- /dev/null +++ b/src/plugins/cppeditor/cppquickfix_test_utils.h @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#ifndef CPPQUICKFIX_TEST_UTILS_H +#define CPPQUICKFIX_TEST_UTILS_H + +#include "cppquickfixes.h" + +/// Fake dialog of InsertVirtualMethodsDialog that does not pop up anything. +class InsertVirtualMethodsDialogTest : public CppEditor::Internal::InsertVirtualMethodsDialog +{ +public: + InsertVirtualMethodsDialogTest(ImplementationMode mode, bool insertVirtualKeyword, + QWidget *parent = 0); + + bool gather(); + ImplementationMode implementationMode() const; + bool insertKeywordVirtual() const; +}; + +#endif // CPPQUICKFIX_TEST_UTILS_H diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index 0538ad842f3..0670b0fa5bb 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -34,9 +34,11 @@ #include #include #include +#include #include -#include +#include #include +#include #include #include #include @@ -469,7 +471,19 @@ void RunAllQuickFixesTokenAction::run(CPPEditorWidget *editorWidget) foreach (CppQuickFixFactory *quickFixFactory, quickFixFactories) { TextEditor::QuickFixOperations operations; - quickFixFactory->match(qfi, operations); + // Some Quick Fixes pop up a dialog and are therefore inappropriate for this test. + // Where possible, use a guiless version of the factory. + if (qobject_cast(quickFixFactory)) { + QScopedPointer factoryProducingGuiLessOperations; + factoryProducingGuiLessOperations.reset( + new InsertVirtualMethods( + new InsertVirtualMethodsDialogTest( + InsertVirtualMethodsDialog::ModeOutsideClass, true))); + factoryProducingGuiLessOperations->match(qfi, operations); + } else { + quickFixFactory->match(qfi, operations); + } + foreach (QuickFixOperation::Ptr operation, operations) { qDebug() << " -- Performing Quick Fix" << operation->description(); operation->perform();