diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-09-07 11:39:33 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-09-08 08:03:14 +0000 |
commit | 473746e8fde6cabe05c36a78e517f8115d5e4e30 (patch) | |
tree | 3c2bf49ffd039859698c860dd2d0d2b42e95247a /src | |
parent | a09ec2e0e98046291dfa4c28223666f2673546ab (diff) |
CppEditor: Merge two TestCase classes
Change-Id: I53c7db9cda0a82706bee898d091f128c2c4bf32f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/cppeditor/cppdoxygen_test.cpp | 1 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditortestcase.cpp | 38 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppeditortestcase.h | 13 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppfunctiondecldeflink.h | 1 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppincludehierarchy_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppmodelmanager_test.cpp | 4 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppquickfix_test.h | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppsourceprocessor_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpptoolstestcase.cpp | 34 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpptoolstestcase.h | 6 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppuseselections_test.cpp | 2 | ||||
-rw-r--r-- | src/plugins/cppeditor/fileandtokenactions_test.cpp | 4 | ||||
-rw-r--r-- | src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp | 2 |
13 files changed, 43 insertions, 68 deletions
diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp index 78c03686090..6878201b2e7 100644 --- a/src/plugins/cppeditor/cppdoxygen_test.cpp +++ b/src/plugins/cppeditor/cppdoxygen_test.cpp @@ -41,6 +41,7 @@ namespace { typedef QByteArray _; } using CppEditor::Tests::TemporaryDir; +using CppEditor::Tests::TestCase; using CppEditor::Tests::VerifyCleanCppModelManager; namespace CppEditor { diff --git a/src/plugins/cppeditor/cppeditortestcase.cpp b/src/plugins/cppeditor/cppeditortestcase.cpp index a327ed329b0..f397cb74584 100644 --- a/src/plugins/cppeditor/cppeditortestcase.cpp +++ b/src/plugins/cppeditor/cppeditortestcase.cpp @@ -34,7 +34,6 @@ #include <coreplugin/editormanager/editormanager.h> #include <cplusplus/CppDocument.h> -#include <texteditor/storagesettings.h> #include <texteditor/texteditor.h> #include <QDir> @@ -78,43 +77,6 @@ bool GenericCppTestDocument::hasCursorMarker() const { return m_cursorPosition ! bool GenericCppTestDocument::hasAnchorMarker() const { return m_anchorPosition != -1; } -TestCase::TestCase(bool runGarbageCollector) : CppEditor::Tests::TestCase(runGarbageCollector) -{ -} - -bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, - CppEditorWidget **editorWidget) -{ - if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditor(fileName))) { - if (editor) { - *editor = e; - TextEditor::StorageSettings s = e->textDocument()->storageSettings(); - s.m_addFinalNewLine = false; - e->textDocument()->setStorageSettings(s); - } - if (editorWidget) { - if (CppEditorWidget *w = dynamic_cast<CppEditorWidget *>(e->editorWidget())) { - *editorWidget = w; - return true; - } else { - return false; // no or wrong widget - } - } else { - return true; // ok since no widget requested - } - } else { - return false; // no or wrong editor - } -} - -CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument( - CppEditorWidget *editorWidget) -{ - while (!editorWidget->isSemanticInfoValid()) - QCoreApplication::processEvents(); - return editorWidget->semanticInfo().doc; -} - } // namespace Tests } // namespace Internal } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppeditortestcase.h b/src/plugins/cppeditor/cppeditortestcase.h index dc0b240793a..8d950b2980e 100644 --- a/src/plugins/cppeditor/cppeditortestcase.h +++ b/src/plugins/cppeditor/cppeditortestcase.h @@ -57,19 +57,6 @@ public: using TestDocuments = QVector<GenericCppTestDocument>; -class TestCase : public CppEditor::Tests::TestCase -{ -public: - TestCase(bool runGarbageCollector = true); - - static bool openCppEditor(const QString &fileName, - TextEditor::BaseTextEditor **editor, - CppEditorWidget **editorWidget = 0); - - static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument( - CppEditorWidget *editorWidget); -}; - } // namespace Tests } // namespace Internal } // namespace CppEditor diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.h b/src/plugins/cppeditor/cppfunctiondecldeflink.h index 959b38b3070..f2e8d2e77a9 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.h +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.h @@ -38,7 +38,6 @@ namespace CppEditor { class CppEditorWidget; namespace Internal { - class FunctionDeclDefLink; class FunctionDeclDefLinkFinder : public QObject diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp index b66cf5ae2dd..18e3dd78289 100644 --- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp @@ -70,7 +70,7 @@ QString toString(CppIncludeHierarchyModel &model) + toString(model, model.index(1, 0)); } -class IncludeHierarchyTestCase : public Tests::TestCase +class IncludeHierarchyTestCase : public CppEditor::Tests::TestCase { public: IncludeHierarchyTestCase(const QList<QByteArray> &sourceList, diff --git a/src/plugins/cppeditor/cppmodelmanager_test.cpp b/src/plugins/cppeditor/cppmodelmanager_test.cpp index a72f0e02561..88ce87b99ac 100644 --- a/src/plugins/cppeditor/cppmodelmanager_test.cpp +++ b/src/plugins/cppeditor/cppmodelmanager_test.cpp @@ -1182,7 +1182,7 @@ void ModelManagerTest::testDocumentsAndRevisions() // Open editor for file 1 TextEditor::BaseTextEditor *editor1; - QVERIFY(helper.openBaseTextEditor(filePath1, &editor1)); + QVERIFY(helper.openCppEditor(filePath1, &editor1)); helper.closeEditorAtEndOfTestCase(editor1); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath1)); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 2U); @@ -1195,7 +1195,7 @@ void ModelManagerTest::testDocumentsAndRevisions() // Open editor for file 2 TextEditor::BaseTextEditor *editor2; - QVERIFY(helper.openBaseTextEditor(filePath2, &editor2)); + QVERIFY(helper.openCppEditor(filePath2, &editor2)); helper.closeEditorAtEndOfTestCase(editor2); QVERIFY(TestCase::waitForProcessedEditorDocument(filePath2)); VERIFY_DOCUMENT_REVISION(modelManager->document(filePath1), 3U); diff --git a/src/plugins/cppeditor/cppquickfix_test.h b/src/plugins/cppeditor/cppquickfix_test.h index 9347be1a985..04b6cee81a6 100644 --- a/src/plugins/cppeditor/cppquickfix_test.h +++ b/src/plugins/cppeditor/cppquickfix_test.h @@ -69,7 +69,7 @@ public: QString m_expectedSource; }; -class BaseQuickFixTestCase : public TestCase +class BaseQuickFixTestCase : public CppEditor::Tests::TestCase { public: /// Exactly one QuickFixTestDocument must contain the cursor position marker '@' diff --git a/src/plugins/cppeditor/cppsourceprocessor_test.cpp b/src/plugins/cppeditor/cppsourceprocessor_test.cpp index dc010432ad0..f381cf4d6d6 100644 --- a/src/plugins/cppeditor/cppsourceprocessor_test.cpp +++ b/src/plugins/cppeditor/cppsourceprocessor_test.cpp @@ -126,7 +126,7 @@ void SourceProcessorTest::testIncludesCyclic() // Open editor TextEditor::BaseTextEditor *editor; - QVERIFY(testCase.openBaseTextEditor(fileName1, &editor)); + QVERIFY(testCase.openCppEditor(fileName1, &editor)); testCase.closeEditorAtEndOfTestCase(editor); // Check editor snapshot diff --git a/src/plugins/cppeditor/cpptoolstestcase.cpp b/src/plugins/cppeditor/cpptoolstestcase.cpp index 89c49b48ccc..f66fc9d027c 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.cpp +++ b/src/plugins/cppeditor/cpptoolstestcase.cpp @@ -27,9 +27,10 @@ #include "baseeditordocumentparser.h" #include "baseeditordocumentprocessor.h" -#include "editordocumenthandle.h" +#include "cppeditorwidget.h" #include "cppmodelmanager.h" #include "cppworkingcopy.h" +#include "editordocumenthandle.h" #include "projectinfo.h" #include <coreplugin/editormanager/editormanager.h> @@ -40,6 +41,7 @@ #include <texteditor/texteditor.h> #include <texteditor/codeassist/iassistproposal.h> #include <texteditor/codeassist/iassistproposalmodel.h> +#include <texteditor/storagesettings.h> #include <cplusplus/CppDocument.h> #include <utils/executeondestruction.h> @@ -119,16 +121,29 @@ bool TestCase::succeededSoFar() const return m_succeededSoFar; } -bool TestCase::openBaseTextEditor(const QString &fileName, TextEditor::BaseTextEditor **editor) +bool TestCase::openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, + CppEditorWidget **editorWidget) { - using BTEditor = TextEditor::BaseTextEditor; - if (auto e = qobject_cast<BTEditor *>(Core::EditorManager::openEditor(fileName))) { + if (const auto e = dynamic_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::openEditor(fileName))) { if (editor) { *editor = e; - return true; + TextEditor::StorageSettings s = e->textDocument()->storageSettings(); + s.m_addFinalNewLine = false; + e->textDocument()->setStorageSettings(s); + } + if (editorWidget) { + if (CppEditorWidget *w = dynamic_cast<CppEditorWidget *>(e->editorWidget())) { + *editorWidget = w; + return true; + } else { + return false; // no or wrong widget + } + } else { + return true; // ok since no widget requested } + } else { + return false; // no or wrong editor } - return false; } CPlusPlus::Snapshot TestCase::globalSnapshot() @@ -167,6 +182,13 @@ bool TestCase::waitForProcessedEditorDocument(const QString &filePath, int timeO return waitForProcessedEditorDocument_internal(editorDocument, timeOutInMs); } +CPlusPlus::Document::Ptr TestCase::waitForRehighlightedSemanticDocument(CppEditorWidget *editorWidget) +{ + while (!editorWidget->isSemanticInfoValid()) + QCoreApplication::processEvents(); + return editorWidget->semanticInfo().doc; +} + bool TestCase::parseFiles(const QSet<QString> &filePaths) { CppModelManager::instance()->updateSourceFiles(filePaths).waitForFinished(); diff --git a/src/plugins/cppeditor/cpptoolstestcase.h b/src/plugins/cppeditor/cpptoolstestcase.h index bd91202fc7f..e732610364b 100644 --- a/src/plugins/cppeditor/cpptoolstestcase.h +++ b/src/plugins/cppeditor/cpptoolstestcase.h @@ -53,6 +53,7 @@ class IAssistProposal; } namespace CppEditor { +class CppEditorWidget; class CppModelManager; namespace Tests { @@ -102,7 +103,8 @@ public: ~TestCase(); bool succeededSoFar() const; - bool openBaseTextEditor(const QString &fileName, TextEditor::BaseTextEditor **editor); + static bool openCppEditor(const QString &fileName, TextEditor::BaseTextEditor **editor, + CppEditorWidget **editorWidget = nullptr); void closeEditorAtEndOfTestCase(Core::IEditor *editor); static bool closeEditorWithoutGarbageCollectorInvocation(Core::IEditor *editor); @@ -114,6 +116,8 @@ public: static bool garbageCollectGlobalSnapshot(); static bool waitForProcessedEditorDocument(const QString &filePath, int timeOutInMs = 5000); + static CPlusPlus::Document::Ptr waitForRehighlightedSemanticDocument( + CppEditorWidget *editorWidget); enum { defaultTimeOutInMs = 30 * 1000 /*= 30 secs*/ }; static bool waitUntilProjectIsFullyOpened(ProjectExplorer::Project *project, diff --git a/src/plugins/cppeditor/cppuseselections_test.cpp b/src/plugins/cppeditor/cppuseselections_test.cpp index 48a826243d4..a0742f186df 100644 --- a/src/plugins/cppeditor/cppuseselections_test.cpp +++ b/src/plugins/cppeditor/cppuseselections_test.cpp @@ -65,7 +65,7 @@ namespace Tests { // Check: If the user puts the cursor on e.g. a function-local variable, // a type name or a macro use, all occurrences of that entity are highlighted. -class UseSelectionsTestCase : public TestCase +class UseSelectionsTestCase : public CppEditor::Tests::TestCase { public: UseSelectionsTestCase(GenericCppTestDocument &testDocument, diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp index e32ab937183..c6a487ffbad 100644 --- a/src/plugins/cppeditor/fileandtokenactions_test.cpp +++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp @@ -77,7 +77,7 @@ namespace CppEditor::Internal::Tests { namespace { -class TestActionsTestCase : public Tests::TestCase +class TestActionsTestCase : public CppEditor::Tests::TestCase { public: class AbstractAction @@ -141,7 +141,7 @@ static bool waitUntilAProjectIsLoaded(int timeOutInMs = 30000) } TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions) - : Tests::TestCase(/*runGarbageCollector=*/false) + : CppEditor::Tests::TestCase(/*runGarbageCollector=*/false) { QVERIFY(succeededSoFar()); diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 053653e2cac..5d89129b4d9 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -245,7 +245,7 @@ QList<TestDocumentPtr> singleDocument(const QByteArray &source) * executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition * and checking the result. */ -class F2TestCase : public Tests::TestCase +class F2TestCase : public CppEditor::Tests::TestCase { public: enum CppEditorAction { |