From c7f3ac407394d3c4d7fe817a6a913cd3256c37e5 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 19 Dec 2013 01:30:49 +0100 Subject: CppEditor/CppTools: Clean up *Test* classes * Unify class names * Fix coding style Change-Id: I7498192ba9e6b9fc0e97d3d4f0dbb30f1853a0c9 Reviewed-by: Erik Verbruggen --- src/plugins/coreplugin/testdatadir.cpp | 2 +- src/plugins/coreplugin/testdatadir.h | 4 +- src/plugins/cppeditor/cppdoxygen_test.cpp | 18 +- src/plugins/cppeditor/cppincludehierarchy_test.cpp | 15 +- src/plugins/cppeditor/cppquickfix_test.cpp | 378 +++++++++++---------- .../followsymbol_switchmethoddecldef_test.cpp | 64 ++-- src/plugins/cpptools/cppcompletion_test.cpp | 61 ++-- src/plugins/cpptools/cppheadersource_test.cpp | 4 +- src/plugins/cpptools/cpplocatorfilter_test.cpp | 62 ++-- src/plugins/cpptools/cppmodelmanager_test.cpp | 2 +- .../cpppointerdeclarationformatter_test.cpp | 106 +++--- src/plugins/cpptools/cpppreprocessertesthelper.cpp | 11 +- src/plugins/cpptools/cpppreprocessertesthelper.h | 6 + src/plugins/cpptools/cpppreprocessor_test.cpp | 8 +- src/plugins/cpptools/symbolsearcher_test.cpp | 41 ++- src/plugins/cpptools/typehierarchybuilder_test.cpp | 15 +- src/plugins/designer/gotoslot_test.cpp | 8 +- src/plugins/locator/locator_test.cpp | 2 +- src/plugins/locator/locatorfiltertest.cpp | 3 +- src/plugins/locator/locatorfiltertest.h | 8 +- 20 files changed, 436 insertions(+), 382 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/coreplugin/testdatadir.cpp b/src/plugins/coreplugin/testdatadir.cpp index c049585f97..d9821e7249 100644 --- a/src/plugins/coreplugin/testdatadir.cpp +++ b/src/plugins/coreplugin/testdatadir.cpp @@ -35,7 +35,7 @@ #include #include -using namespace Core::Internal::Tests; +using namespace Core::Tests; static void maybeAppendSlash(QString *string) { diff --git a/src/plugins/coreplugin/testdatadir.h b/src/plugins/coreplugin/testdatadir.h index 867e2c781d..57c63f8c8a 100644 --- a/src/plugins/coreplugin/testdatadir.h +++ b/src/plugins/coreplugin/testdatadir.h @@ -36,7 +36,7 @@ #include #define QTC_DECLARE_MYTESTDATADIR(PATH) \ - class MyTestDataDir : public Core::Internal::Tests::TestDataDir \ + class MyTestDataDir : public Core::Tests::TestDataDir \ { \ public: \ MyTestDataDir(const QString &testDataDirectory = QString()) \ @@ -44,7 +44,6 @@ }; namespace Core { -namespace Internal { namespace Tests { class CORE_EXPORT TestDataDir @@ -61,7 +60,6 @@ private: }; } // namespace Tests -} // namespace Internal } // namespace Core #endif // TESTDATADIR_H diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp index 41d940e4cb..87b78c6a79 100644 --- a/src/plugins/cppeditor/cppdoxygen_test.cpp +++ b/src/plugins/cppeditor/cppdoxygen_test.cpp @@ -59,18 +59,18 @@ typedef QByteArray _; * Encapsulates the whole process of setting up an editor, * pressing ENTER and checking the result. */ -class TestCase : public CppEditor::Internal::Tests::TestCase +class DoxygenTestCase : public CppEditor::Internal::Tests::TestCase { public: - TestCase(const QByteArray &input); - void run(const QByteArray &expected, int undoCount = 1); + DoxygenTestCase(const QByteArray &input); + void run(const QByteArray &expected); private: CppEditor::Internal::Tests::TestDocument testDocument; }; /// The '|' in the input denotes the cursor position. -TestCase::TestCase(const QByteArray &input) +DoxygenTestCase::DoxygenTestCase(const QByteArray &input) : testDocument("file.cpp", input, '|') { QVERIFY(testDocument.hasCursorMarker()); @@ -97,7 +97,7 @@ TestCase::TestCase(const QByteArray &input) waitForRehighlightedSemanticDocument(testDocument.m_editorWidget); } -void TestCase::run(const QByteArray &expected, int undoCount) +void DoxygenTestCase::run(const QByteArray &expected) { // Send 'ENTER' key press QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); @@ -106,12 +106,12 @@ void TestCase::run(const QByteArray &expected, int undoCount) QCOMPARE(QLatin1String(result), QLatin1String(expected)); - for (int i = 0; i < undoCount; ++i) - testDocument.m_editorWidget->undo(); + testDocument.m_editorWidget->undo(); const QByteArray contentsAfterUndo = testDocument.m_editorWidget->document()->toPlainText().toUtf8(); QCOMPARE(contentsAfterUndo, testDocument.m_source); } + } // anonymous namespace void CppEditorPlugin::test_doxygen_comments_data() @@ -257,6 +257,6 @@ void CppEditorPlugin::test_doxygen_comments() { QFETCH(QByteArray, given); QFETCH(QByteArray, expected); - TestCase data(given); - data.run(expected); + DoxygenTestCase test(given); + test.run(expected); } diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp index f19f99106a..784de18024 100644 --- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp +++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp @@ -45,10 +45,11 @@ using namespace CppEditor::Internal; using namespace CppTools; namespace { -class TestCase : public CppEditor::Internal::Tests::TestCase + +class IncludeHierarchyTestCase: public CppEditor::Internal::Tests::TestCase { public: - TestCase(const QList &sourceList) + IncludeHierarchyTestCase(const QList &sourceList) { QStringList filePaths; const int sourceListSize = sourceList.size(); @@ -81,7 +82,8 @@ public: QCOMPARE(model.rowCount(model.index(1, 0)), includedByCount); } }; -} + +} // anonymous namespace void CppEditorPlugin::test_includeHierarchyModel_simpleIncludes() { @@ -89,7 +91,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludes() sourceList.append(QByteArray("#include \"file2.h\"\n")); sourceList.append(QByteArray()); - TestCase testCase(sourceList); + IncludeHierarchyTestCase testCase(sourceList); testCase.run(1, 0); } @@ -99,18 +101,17 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy() sourceList.append(QByteArray()); sourceList.append(QByteArray("#include \"file1.h\"\n")); - TestCase testCase(sourceList); + IncludeHierarchyTestCase testCase(sourceList); testCase.run(0, 1); } void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy() { QList sourceList; - QByteArray source; sourceList.append(QByteArray("#include \"file2.h\"\n")); sourceList.append(QByteArray()); sourceList.append(QByteArray("#include \"file1.h\"\n")); - TestCase testCase(sourceList); + IncludeHierarchyTestCase testCase(sourceList); testCase.run(1, 1); } diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 8335019012..2ff7fecfb9 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -59,6 +59,8 @@ using namespace CppTools; using namespace IncludeUtils; using namespace TextEditor; +using CppTools::Tests::TestIncludePaths; + namespace { typedef QByteArray _; @@ -91,8 +93,6 @@ public: return TestDocumentPtr(new TestDocument(fileName, source, expectedSource)); } - bool changesExpected() const { return m_source != m_expectedSource; } - public: QByteArray m_expectedSource; }; @@ -101,37 +101,37 @@ public: * Encapsulates the whole process of setting up an editor, getting the * quick-fix, applying it, and checking the result. */ -class TestCase : public CppEditor::Internal::Tests::TestCase +class QuickFixTestCase : public CppEditor::Internal::Tests::TestCase { public: - TestCase(const QByteArray &originalSource, const QByteArray &expectedSource, - const QStringList &includePaths = QStringList()); - TestCase(const QList theTestFiles, - const QStringList &includePaths = QStringList()); - ~TestCase(); - - QuickFixOperation::Ptr getFix(CppQuickFixFactory *factory, CPPEditorWidget *editorWidget, - int resultIndex = 0); - TestDocumentPtr testFileWithCursorMarker() const; + QuickFixTestCase(const QByteArray &originalSource, const QByteArray &expectedSource, + const QStringList &includePaths = QStringList()); + QuickFixTestCase(const QList theTestFiles, + const QStringList &includePaths = QStringList()); + ~QuickFixTestCase(); void run(CppQuickFixFactory *factory, int resultIndex = 0); private: + TestDocumentPtr testFileWithCursorMarker() const; + QuickFixOperation::Ptr getFix(CppQuickFixFactory *factory, CPPEditorWidget *editorWidget, + int resultIndex = 0); void init(const QStringList &includePaths); private: - QList testFiles; + QList m_testFiles; - CppCodeStylePreferences *cppCodeStylePreferences; - QByteArray cppCodeStylePreferencesOriginalDelegateId; + CppCodeStylePreferences *m_cppCodeStylePreferences; + QByteArray m_cppCodeStylePreferencesOriginalDelegateId; - QStringList includePathsToRestore; - bool restoreIncludePaths; + QStringList m_includePathsToRestore; + bool m_restoreIncludePaths; }; /// Apply the factory on the source and get back the resultIndex'th result or a null pointer. -QuickFixOperation::Ptr TestCase::getFix(CppQuickFixFactory *factory, CPPEditorWidget *editorWidget, - int resultIndex) +QuickFixOperation::Ptr QuickFixTestCase::getFix(CppQuickFixFactory *factory, + CPPEditorWidget *editorWidget, + int resultIndex) { CppQuickFixInterface qfi(new CppQuickFixAssistInterface(editorWidget, ExplicitlyInvoked)); TextEditor::QuickFixOperations results; @@ -140,51 +140,57 @@ QuickFixOperation::Ptr TestCase::getFix(CppQuickFixFactory *factory, CPPEditorWi } /// The '@' in the originalSource is the position from where the quick-fix discovery is triggered. -TestCase::TestCase(const QByteArray &originalSource, const QByteArray &expectedSource, - const QStringList &includePaths) - : cppCodeStylePreferences(0), restoreIncludePaths(false) +QuickFixTestCase::QuickFixTestCase(const QByteArray &originalSource, + const QByteArray &expectedSource, + const QStringList &includePaths) + : m_cppCodeStylePreferences(0) + , m_restoreIncludePaths(false) { - testFiles << TestDocument::create("file.cpp", originalSource, expectedSource); + m_testFiles << TestDocument::create("file.cpp", originalSource, expectedSource); init(includePaths); } /// Exactly one TestFile must contain the cursor position marker '@' in the originalSource. -TestCase::TestCase(const QList theTestFiles, const QStringList &includePaths) - : testFiles(theTestFiles), cppCodeStylePreferences(0), restoreIncludePaths(false) +QuickFixTestCase::QuickFixTestCase(const QList theTestFiles, + const QStringList &includePaths) + : m_testFiles(theTestFiles) + , m_cppCodeStylePreferences(0) + , m_restoreIncludePaths(false) { init(includePaths); } -void TestCase::init(const QStringList &includePaths) +void QuickFixTestCase::init(const QStringList &includePaths) { // Check if there is exactly one cursor marker unsigned cursorMarkersCount = 0; - foreach (const TestDocumentPtr testFile, testFiles) { + foreach (const TestDocumentPtr testFile, m_testFiles) { if (testFile->hasCursorMarker()) ++cursorMarkersCount; } QVERIFY2(cursorMarkersCount == 1, "Exactly one cursor marker is allowed."); // Write files to disk - foreach (TestDocumentPtr testFile, testFiles) + foreach (TestDocumentPtr testFile, m_testFiles) testFile->writeToDisk(); // Set appropriate include paths if (!includePaths.isEmpty()) { - restoreIncludePaths = true; - includePathsToRestore = m_modelManager->includePaths(); + m_restoreIncludePaths = true; + m_includePathsToRestore = m_modelManager->includePaths(); m_modelManager->setIncludePaths(includePaths); } // Update Code Model QStringList filePaths; - foreach (const TestDocumentPtr &testFile, testFiles) + foreach (const TestDocumentPtr &testFile, m_testFiles) filePaths << testFile->filePath(); QVERIFY(parseFiles(filePaths)); // Open Files - foreach (TestDocumentPtr testFile, testFiles) { - QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor, &testFile->m_editorWidget)); + foreach (TestDocumentPtr testFile, m_testFiles) { + QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor, + &testFile->m_editorWidget)); closeEditorAtEndOfTestCase(testFile->m_editor); // Set cursor position @@ -198,24 +204,24 @@ void TestCase::init(const QStringList &includePaths) // Enforce the default cpp code style, so we are independent of config file settings. // This is needed by e.g. the GenerateGetterSetter quick fix. - cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle(); - QVERIFY(cppCodeStylePreferences); - cppCodeStylePreferencesOriginalDelegateId = cppCodeStylePreferences->currentDelegateId(); - cppCodeStylePreferences->setCurrentDelegate("qt"); + m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle(); + QVERIFY(m_cppCodeStylePreferences); + m_cppCodeStylePreferencesOriginalDelegateId = m_cppCodeStylePreferences->currentDelegateId(); + m_cppCodeStylePreferences->setCurrentDelegate("qt"); } -TestCase::~TestCase() +QuickFixTestCase::~QuickFixTestCase() { // Restore default cpp code style - if (cppCodeStylePreferences) - cppCodeStylePreferences->setCurrentDelegate(cppCodeStylePreferencesOriginalDelegateId); + if (m_cppCodeStylePreferences) + m_cppCodeStylePreferences->setCurrentDelegate(m_cppCodeStylePreferencesOriginalDelegateId); // Restore include paths - if (restoreIncludePaths) - m_modelManager->setIncludePaths(includePathsToRestore); + if (m_restoreIncludePaths) + m_modelManager->setIncludePaths(m_includePathsToRestore); // Remove created files from file system - foreach (const TestDocumentPtr &testDocument, testFiles) + foreach (const TestDocumentPtr &testDocument, m_testFiles) QVERIFY(QFile::remove(testDocument->filePath())); } @@ -239,11 +245,11 @@ QByteArray &removeTrailingWhitespace(QByteArray &input) return input; } -void TestCase::run(CppQuickFixFactory *factory, int resultIndex) +void QuickFixTestCase::run(CppQuickFixFactory *factory, int resultIndex) { // Run the fix in the file having the cursor marker TestDocumentPtr testFile; - foreach (const TestDocumentPtr file, testFiles) { + foreach (const TestDocumentPtr file, m_testFiles) { if (file->hasCursorMarker()) testFile = file; } @@ -255,7 +261,7 @@ void TestCase::run(CppQuickFixFactory *factory, int resultIndex) qDebug() << "Quickfix was not triggered"; // Compare all files - foreach (const TestDocumentPtr testFile, testFiles) { + foreach (const TestDocumentPtr testFile, m_testFiles) { // Check QByteArray result = testFile->m_editorWidget->document()->toPlainText().toUtf8(); removeTrailingWhitespace(result); @@ -1194,8 +1200,8 @@ void CppEditorPlugin::test_quickfix() if (expected.isEmpty()) expected = original + '\n'; - TestCase data(original, expected); - data.run(factory.data()); + QuickFixTestCase test(original, expected); + test.run(factory.data()); } /// Checks: In addition to test_quickfix_GenerateGetterSetter_basicGetterWithPrefix @@ -1248,8 +1254,8 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAn testFiles << TestDocument::create("file.cpp", original, expected); GenerateGetterSetter factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check if definition is inserted right after class for insert definition outside @@ -1292,8 +1298,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory, 1); + QuickFixTestCase test(testFiles); + test.run(&factory, 1); } /// Check from header file: If there is a source file, insert the definition in the source file. @@ -1326,8 +1332,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic1() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check from header file: If there is a source file, insert the definition in the source file. @@ -1365,8 +1371,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic2() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check from source file: Insert in source file, not header file. @@ -1397,8 +1403,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic3() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check from header file: If the class is in a namespace, the added function definition @@ -1433,8 +1439,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace1() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check from header file: If the class is in namespace N and the source file has a @@ -1473,8 +1479,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace2() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check definition insert inside class @@ -1492,8 +1498,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_insideClass() "};\n"; InsertDefFromDecl factory; - TestCase data(original, expected); - data.run(&factory, 1); + QuickFixTestCase test(original, expected); + test.run(&factory, 1); } /// Check not triggering when definition exists @@ -1507,8 +1513,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitio const QByteArray expected = original + "\n"; InsertDefFromDecl factory; - TestCase data(original, expected); - data.run(&factory, 1); + QuickFixTestCase test(original, expected); + test.run(&factory, 1); } /// Find right implementation file. @@ -1559,8 +1565,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil testFiles << TestDocument::create("file2.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Ignore generated functions declarations when looking at the surrounding @@ -1616,8 +1622,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGenerated testFiles << TestDocument::create("file2.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check if whitespace is respected for operator functions @@ -1642,8 +1648,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1( "\n"; InsertDefFromDecl factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check if whitespace is respected for operator functions @@ -1668,8 +1674,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2( "\n"; InsertDefFromDecl factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check if a function like macro use is not separated by the function to insert @@ -1712,8 +1718,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check if a function like macro use is not separated by the function to insert @@ -1754,8 +1760,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check if insertion happens before syntactically erroneous statements at end of file. @@ -1793,8 +1799,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfF testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Respect rvalue references @@ -1823,8 +1829,8 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference() testFiles << TestDocument::create("file.cpp", original, expected); InsertDefFromDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } // Function for one of InsertDeclDef section cases @@ -1861,8 +1867,8 @@ void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex) testFiles << TestDocument::create("file.cpp", original, expected); InsertDeclFromDef factory; - TestCase data(testFiles); - data.run(&factory, sectionIndex); + QuickFixTestCase test(testFiles); + test.run(&factory, sectionIndex); } /// Check from source file: Insert in header file. @@ -1878,8 +1884,8 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef() QList includesForSource(const QByteArray &source) { - const QString fileName = TestIncludePaths::directoryOfTestFile() + QLatin1String("/file.cpp"); - TestCase::writeFile(fileName, source); + const QString fileName = TestIncludePaths::testFilePath(); + CppTools::Tests::TestCase::writeFile(fileName, source); using namespace CppTools::Internal; @@ -2070,8 +2076,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_normal() // Do not use the test factory, at least once we want to go through the "full stack". AddIncludeForUndefinedIdentifier factory; - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Ignore *.moc includes @@ -2097,8 +2103,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc() + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert include at top for a sorted group @@ -2124,8 +2130,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop( + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert include in the middle for a sorted group @@ -2151,8 +2157,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingMidd + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert include at bottom for a sorted group @@ -2178,8 +2184,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingBott + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: For an unsorted group the new include is appended @@ -2205,8 +2211,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_appendToUns + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert a local include at front if there are only global includes @@ -2233,8 +2239,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalI + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert a global include at back if there are only local includes @@ -2264,8 +2270,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobal + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Prefer group with longest matching prefix @@ -2295,8 +2301,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_preferGroup + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"prefixc.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Create a new include group if there are only include groups with a different include dir @@ -2323,8 +2329,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfO + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include dirs, sorted --> insert properly @@ -2352,8 +2358,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSo + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include dirs, unsorted --> append @@ -2381,8 +2387,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUn + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include types @@ -2408,8 +2414,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"z.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include types @@ -2435,8 +2441,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"a.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include types @@ -2462,8 +2468,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"lib/file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Include group with mixed include types @@ -2489,8 +2495,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert very first include @@ -2514,8 +2520,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noinclude() + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert very first include if there is a c++ style comment on top @@ -2545,8 +2551,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: Insert very first include if there is a c style comment on top @@ -2580,8 +2586,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\"")); - TestCase data(testFiles, QStringList(TestIncludePaths::globalIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath())); + test.run(&factory); } /// Check: If a "Qt Class" was not found by the locator, check the header files in the Qt @@ -2606,8 +2612,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomet + "/file.cpp", original, expected); AddIncludeForUndefinedIdentifier factory; - TestCase data(testFiles, QStringList(TestIncludePaths::globalQtCoreIncludePath())); - data.run(&factory); + QuickFixTestCase test(testFiles, QStringList(CppTools::Tests::TestIncludePaths::globalQtCoreIncludePath())); + test.run(&factory); } /// Check: Move definition from header to cpp. @@ -2650,8 +2656,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCpp() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS() @@ -2697,8 +2703,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move definition outside class @@ -2732,8 +2738,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside1() "void Foo::f4() {}\n\n"; MoveFuncDefOutside factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: Move definition outside class @@ -2775,8 +2781,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory, 1); + QuickFixTestCase test(testFiles); + test.run(&factory, 1); } /// Check: Move definition from header to cpp (with namespace). @@ -2819,8 +2825,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move definition from header to cpp (with namespace + using). @@ -2865,8 +2871,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move definition outside class with Namespace @@ -2893,8 +2899,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs() "\n}\n"; MoveFuncDefOutside factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: Move free function from header to cpp. @@ -2930,8 +2936,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCpp() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move free function from header to cpp (with namespace). @@ -2971,8 +2977,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move Ctor with member initialization list (QTCREATORBUG-9157). @@ -3012,8 +3018,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization1() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Move Ctor with member initialization list (QTCREATORBUG-9462). @@ -3058,8 +3064,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization2() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check if definition is inserted right after class for move definition outside @@ -3101,8 +3107,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefOutside factory; - TestCase data(testFiles); - data.run(&factory, 1); + QuickFixTestCase test(testFiles); + test.run(&factory, 1); } /// Check if whitespace is respected for operator functions @@ -3124,8 +3130,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1 "\n"; MoveFuncDefOutside factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check if whitespace is respected for operator functions @@ -3147,8 +3153,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2 "\n"; MoveFuncDefOutside factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp() @@ -3180,8 +3186,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncOutside() @@ -3207,8 +3213,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncOutside() "\n\n\n"; MoveFuncDefToDecl factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS() @@ -3248,8 +3254,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing() @@ -3293,8 +3299,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNSUsing() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs() @@ -3321,8 +3327,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncOutsideWithNs() "};\n\n\n}\n\n"; MoveFuncDefToDecl factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_FreeFuncToCpp() @@ -3354,8 +3360,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS() @@ -3393,8 +3399,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: revert test_quickfix_MoveFuncDefOutside_CtorWithInitialization() @@ -3433,8 +3439,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_CtorWithInitialization() testFiles << TestDocument::create("file.cpp", original, expected); MoveFuncDefToDecl factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Definition should not be placed behind the variable. QTCREATORBUG-10303 @@ -3460,8 +3466,8 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable "} bar;\n\n\n"; MoveFuncDefToDecl factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates() @@ -3498,8 +3504,8 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates() testFiles << TestDocument::create("file.cpp", original, expected); AssignToLocalVariable factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_typeDeduction_data() @@ -3563,8 +3569,8 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_typeDeduction() } ExtractLiteralAsParameter factory; - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separateFiles() @@ -3590,8 +3596,8 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separ testFiles << TestDocument::create("file.cpp", original, expected); ExtractLiteralAsParameter factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_separateFiles() @@ -3625,8 +3631,8 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_sep testFiles << TestDocument::create("file.cpp", original, expected); ExtractLiteralAsParameter factory; - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } Q_DECLARE_METATYPE(InsertVirtualMethodsDialog::ImplementationMode) @@ -3931,8 +3937,8 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods() InsertVirtualMethods factory( new InsertVirtualMethodsDialogTest(implementationMode, insertVirtualKeyword)); - TestCase data(original, expected); - data.run(&factory); + QuickFixTestCase test(original, expected); + test.run(&factory); } /// Check: Insert in implementation file @@ -3978,8 +3984,8 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile() InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest( InsertVirtualMethodsDialog::ModeImplementationFile, true)); - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } /// Check: Qualified names. @@ -4031,6 +4037,6 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace() InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest( InsertVirtualMethodsDialog::ModeImplementationFile, true)); - TestCase data(testFiles); - data.run(&factory); + QuickFixTestCase test(testFiles); + test.run(&factory); } diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp index 4e59cfce74..0c8914db5a 100644 --- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp +++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp @@ -44,7 +44,6 @@ #include #include - /*! Tests for Follow Symbol Under Cursor and Switch Between Function Declaration/Definition @@ -55,6 +54,7 @@ You can find potential test code for Follow Symbol Under Cursor on the bottom of this file. */ + using namespace CPlusPlus; using namespace CppEditor; using namespace CppEditor::Internal; @@ -211,7 +211,7 @@ public: * executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition * and checking the result. */ -class TestCase : public CppEditor::Internal::Tests::TestCase +class F2TestCase : public CppEditor::Internal::Tests::TestCase { public: enum CppEditorAction { @@ -219,17 +219,14 @@ public: SwitchBetweenMethodDeclarationDefinitionAction }; - TestCase(CppEditorAction action, const QByteArray &source, - const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList()); - TestCase(CppEditorAction action, const QList theTestFiles, - const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList()); + F2TestCase(CppEditorAction action, const QByteArray &source, + const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList()); + F2TestCase(CppEditorAction action, const QList theTestFiles, + const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList()); void run(); private: - TestCase(const TestCase &); - TestCase &operator=(const TestCase &); - void init(); TestDocumentPtr testFileWithInitialCursorMarker(); @@ -243,8 +240,9 @@ private: /// Convenience function for creating a TestDocument. /// See TestDocument. -TestCase::TestCase(CppEditorAction action, const QByteArray &source, - const OverrideItemList &expectedVirtualFunctionProposal) +F2TestCase::F2TestCase(CppEditorAction action, + const QByteArray &source, + const OverrideItemList &expectedVirtualFunctionProposal) : m_action(action) , m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal) { @@ -256,8 +254,9 @@ TestCase::TestCase(CppEditorAction action, const QByteArray &source, /// Exactly one test document must be provided that contains '@', the initial position marker. /// Exactly one test document must be provided that contains '$', the target position marker. /// It can be the same document. -TestCase::TestCase(CppEditorAction action, const QList theTestFiles, - const OverrideItemList &expectedVirtualFunctionProposal) +F2TestCase::F2TestCase(CppEditorAction action, + const QList theTestFiles, + const OverrideItemList &expectedVirtualFunctionProposal) : m_action(action) , m_testFiles(theTestFiles) , m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal) @@ -265,7 +264,7 @@ TestCase::TestCase(CppEditorAction action, const QList theTestF init(); } -void TestCase::init() +void F2TestCase::init() { // Check if there are initial and target position markers QVERIFY2(testFileWithInitialCursorMarker(), @@ -303,7 +302,7 @@ void TestCase::init() } } -TestDocumentPtr TestCase::testFileWithInitialCursorMarker() +TestDocumentPtr F2TestCase::testFileWithInitialCursorMarker() { foreach (const TestDocumentPtr testFile, m_testFiles) { if (testFile->hasCursorMarker()) @@ -312,7 +311,7 @@ TestDocumentPtr TestCase::testFileWithInitialCursorMarker() return TestDocumentPtr(); } -TestDocumentPtr TestCase::testFileWithTargetCursorMarker() +TestDocumentPtr F2TestCase::testFileWithTargetCursorMarker() { foreach (const TestDocumentPtr testFile, m_testFiles) { if (testFile->hasTargetCursorMarker()) @@ -321,7 +320,7 @@ TestDocumentPtr TestCase::testFileWithTargetCursorMarker() return TestDocumentPtr(); } -void TestCase::run() +void F2TestCase::run() { TestDocumentPtr initialTestFile = testFileWithInitialCursorMarker(); QVERIFY(initialTestFile); @@ -489,11 +488,11 @@ void CppEditorPlugin::test_SwitchMethodDeclarationDefinition() QFETCH(QByteArray, header); QFETCH(QByteArray, source); - QList testFiles; - testFiles << TestDocument::create(header, "file.h"); - testFiles << TestDocument::create(source, "file.cpp"); + const QList testFiles = QList() + << TestDocument::create(header, "file.h") + << TestDocument::create(source, "file.cpp"); - TestCase test(TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles); + F2TestCase test(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles); test.run(); } @@ -765,8 +764,8 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data() ); // 3.3.10 Name hiding (par 2.), from text - // A class name (9.1) or enumeration name (7.2) can be hidden by the name of a variable, data member, - // function, or enumerator declared in the same scope. + // A class name (9.1) or enumeration name (7.2) can be hidden by the name of a variable, + // data member, function, or enumerator declared in the same scope. QTest::newRow("funLocalVarHidesOuterClass") << _( "struct C {};\n" "\n" @@ -854,7 +853,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data() void CppEditorPlugin::test_FollowSymbolUnderCursor() { QFETCH(QByteArray, source); - TestCase test(TestCase::FollowSymbolUnderCursorAction, source); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source); test.run(); } @@ -883,7 +882,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments() { QFETCH(QList, documents); - TestCase test(TestCase::FollowSymbolUnderCursorAction, documents); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, documents); test.run(); } @@ -973,7 +972,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_QObject_connect() return; } - TestCase test(TestCase::FollowSymbolUnderCursorAction, source); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source); test.run(); } @@ -997,7 +996,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_onOperatorToken "}\n"; if (toDeclaration) source.replace('@', '#').replace('$', '@').replace('#', '$'); - TestCase test(TestCase::FollowSymbolUnderCursorAction, source); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source); test.run(); } @@ -1023,7 +1022,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator() else source.replace("@2", QByteArray()).replace("$2", QByteArray()) .replace("@1", "@").replace("$1", "$"); - TestCase test(TestCase::FollowSymbolUnderCursorAction, source); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source); test.run(); } @@ -1049,7 +1048,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_inOp() else source.replace("@2", QByteArray()).replace("$2", QByteArray()) .replace("@1", "@").replace("$1", "$"); - TestCase test(TestCase::FollowSymbolUnderCursorAction, source); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source); test.run(); } @@ -1109,7 +1108,8 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data() << OverrideItem(QLatin1String("CD1::virt"), 11) << OverrideItem(QLatin1String("CD2::virt"), 14)); - /// Check: Virtual function call in member of class hierarchy, only possible overrides are presented. + /// Check: Virtual function call in member of class hierarchy, + /// only possible overrides are presented. QTest::newRow("possibleOverrides2") << _( "struct A { virtual void virt(); };\n" "void A::virt() {}\n" @@ -1302,7 +1302,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall() QFETCH(QByteArray, source); QFETCH(OverrideItemList, results); - TestCase test(TestCase::FollowSymbolUnderCursorAction, source, results); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source, results); test.run(); } @@ -1324,7 +1324,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_multipleD << OverrideItem(QLatin1String("A::virt"), 1) << OverrideItem(QLatin1String("B::virt"), 2); - TestCase test(TestCase::FollowSymbolUnderCursorAction, testFiles, finalResults); + F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, testFiles, finalResults); test.run(); } diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index 4fc45144bb..173181c412 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -53,37 +53,39 @@ using namespace CppTools::Internal; using namespace TextEditor; using namespace Core; -namespace { typedef QByteArray _; } +namespace { + +typedef QByteArray _; class CompletionTestCase : public CppTools::Tests::TestCase { public: CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray()) - : position(-1), editorWidget(0), textDocument(0), editor(0) + : m_position(-1), m_editorWidget(0), m_textDocument(0), m_editor(0) { - source = sourceText; - position = source.indexOf('@'); - QVERIFY(position != -1); - source[position] = ' '; + m_source = sourceText; + m_position = m_source.indexOf('@'); + QVERIFY(m_position != -1); + m_source[m_position] = ' '; // Write source to file const QString fileName = QDir::tempPath() + QLatin1String("/file.h"); - QVERIFY(writeFile(fileName, source)); + QVERIFY(writeFile(fileName, m_source)); // Open in editor - editor = EditorManager::openEditor(fileName); - QVERIFY(editor); - closeEditorAtEndOfTestCase(editor); - editorWidget = qobject_cast(editor->widget()); - QVERIFY(editorWidget); + m_editor = EditorManager::openEditor(fileName); + QVERIFY(m_editor); + closeEditorAtEndOfTestCase(m_editor); + m_editorWidget = qobject_cast(m_editor->widget()); + QVERIFY(m_editorWidget); - textDocument = editorWidget->document(); + m_textDocument = m_editorWidget->document(); // Get Document waitForFileInGlobalSnapshot(fileName); const Document::Ptr document = globalSnapshot().document(fileName); - snapshot.insert(document); + m_snapshot.insert(document); if (!textToInsert.isEmpty()) insertText(textToInsert); @@ -93,9 +95,9 @@ public: { QStringList completions; CppCompletionAssistInterface *ai - = new CppCompletionAssistInterface(editorWidget->document(), position, - editorWidget->baseTextDocument()->filePath(), - ExplicitlyInvoked, snapshot, + = new CppCompletionAssistInterface(m_editorWidget->document(), m_position, + m_editorWidget->baseTextDocument()->filePath(), + ExplicitlyInvoked, m_snapshot, QStringList(), QStringList()); CppCompletionAssistProcessor processor; IAssistProposal *proposal = processor.perform(ai); @@ -109,8 +111,9 @@ public: return completions; const int pos = proposal->basePosition(); - const int length = position - pos; - const QString prefix = Convenience::textAt(QTextCursor(editorWidget->document()), pos, length); + const int length = m_position - pos; + const QString prefix = Convenience::textAt(QTextCursor(m_editorWidget->document()), pos, + length); if (!prefix.isEmpty()) listmodel->filter(prefix); if (listmodel->isSortable(prefix)) @@ -128,21 +131,23 @@ public: void insertText(const QByteArray &text) { Utils::ChangeSet change; - change.insert(position, QLatin1String(text)); - QTextCursor cursor(textDocument); + change.insert(m_position, QLatin1String(text)); + QTextCursor cursor(m_textDocument); change.apply(&cursor); - position += text.length(); + m_position += text.length(); } private: - QByteArray source; - int position; - Snapshot snapshot; - BaseTextEditorWidget *editorWidget; - QTextDocument *textDocument; - IEditor *editor; + QByteArray m_source; + int m_position; + Snapshot m_snapshot; + BaseTextEditorWidget *m_editorWidget; + QTextDocument *m_textDocument; + IEditor *m_editor; }; +} // anonymous namespace + void CppToolsPlugin::test_completion_basic_1() { const QByteArray source = diff --git a/src/plugins/cpptools/cppheadersource_test.cpp b/src/plugins/cpptools/cppheadersource_test.cpp index 26d833d1c4..55c6b0f04a 100644 --- a/src/plugins/cpptools/cppheadersource_test.cpp +++ b/src/plugins/cpptools/cppheadersource_test.cpp @@ -46,8 +46,8 @@ void CppToolsPlugin::test_headersource() QFETCH(QString, headerFileName); bool wasHeader; - Core::Internal::Tests::TestDataDir dataDir( - _(SRCDIR "/../../../tests/cppheadersource/") + _(QTest::currentDataTag())); + Core::Tests::TestDataDir dataDir(_(SRCDIR "/../../../tests/cppheadersource/") + + _(QTest::currentDataTag())); const QString sourcePath = dataDir.file(sourceFileName); const QString headerPath = dataDir.file(headerFileName); diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp index 8c7040e817..5a7e7f3a3a 100644 --- a/src/plugins/cpptools/cpplocatorfilter_test.cpp +++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp @@ -47,12 +47,11 @@ #include using namespace Core; -using namespace Core::Internal::Tests; +using namespace Core::Tests; using namespace CppTools::Internal; using namespace ExtensionSystem; using namespace Locator; -using namespace Locator::Internal; -using namespace Locator::Internal::Tests; +using namespace Locator::Tests; using namespace Utils; Q_DECLARE_METATYPE(ILocatorFilter *) @@ -63,12 +62,12 @@ QTC_DECLARE_MYTESTDATADIR("../../../tests/cpplocators/") inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } -} // anonymous namespace - -class CppLocatorFilterTest : public BasicLocatorFilterTest, public CppTools::Tests::TestCase +class CppLocatorFilterTestCase + : public BasicLocatorFilterTest + , public CppTools::Tests::TestCase { public: - CppLocatorFilterTest(ILocatorFilter *filter, const QString &fileName) + CppLocatorFilterTestCase(ILocatorFilter *filter, const QString &fileName) : BasicLocatorFilterTest(filter) , m_fileName(fileName) { @@ -77,18 +76,19 @@ public: } private: - virtual void doBeforeLocatorRun() { QVERIFY(parseFiles(m_fileName)); } - virtual void doAfterLocatorRun() { QVERIFY(garbageCollectGlobalSnapshot()); } + void doBeforeLocatorRun() { QVERIFY(parseFiles(m_fileName)); } + void doAfterLocatorRun() { QVERIFY(garbageCollectGlobalSnapshot()); } +private: const QString m_fileName; }; -class CppCurrentDocumentFilterTest +class CppCurrentDocumentFilterTestCase : public BasicLocatorFilterTest , public CppTools::Tests::TestCase { public: - CppCurrentDocumentFilterTest(const QString &fileName) + CppCurrentDocumentFilterTestCase(const QString &fileName) : BasicLocatorFilterTest(PluginManager::getObject()) , m_editor(0) , m_fileName(fileName) @@ -97,7 +97,7 @@ public: } private: - virtual void doBeforeLocatorRun() + void doBeforeLocatorRun() { QVERIFY(EditorManager::documentModel()->openedDocuments().isEmpty()); QVERIFY(garbageCollectGlobalSnapshot()); @@ -108,7 +108,7 @@ private: waitForFileInGlobalSnapshot(m_fileName); } - virtual void doAfterLocatorRun() + void doAfterLocatorRun() { EditorManager::closeEditor(m_editor, /*askAboutModifiedEditors=*/ false); QCoreApplication::processEvents(); @@ -116,10 +116,13 @@ private: QVERIFY(garbageCollectGlobalSnapshot()); } +private: IEditor *m_editor; const QString m_fileName; }; +} // anonymous namespace + void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter() { QFETCH(QString, testFile); @@ -127,7 +130,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter() QFETCH(QString, searchText); QFETCH(ResultDataList, expectedResults); - CppLocatorFilterTest test(filter, testFile); + CppLocatorFilterTestCase test(filter, testFile); ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor(searchText)); // ResultData::printFilterEntries(results); QVERIFY(!results.isEmpty()); @@ -152,15 +155,18 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() QTest::newRow("CppFunctionsFilter") << testFile << cppFunctionsFilter - << QString::fromLatin1("function") + << _("function") << (QList() << ResultData(_("functionDefinedInClass(bool, int)"), _("MyClass")) << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("::MyClass")) + << ResultData(_("functionDefinedInClass(bool, int)"), + _("::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClass(char)"), + _("::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("myFunction(bool, int)"), testFileShort) << ResultData(_("myFunction(bool, int)"), _("MyNamespace")) << ResultData(_("myFunction(bool, int)"), _("")) @@ -174,7 +180,8 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() << ResultData(_("MyClass()"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("myFunction(bool, int)"), _("MyNamespace")) ); @@ -204,7 +211,8 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() << (QList() << ResultData(_("::MyClass"), testFileShort) << ResultData(_("::MyClass::MyClass"), _("()")) - << ResultData(_("::MyClass::functionDefinedOutSideClass"), _("(char)")) + << ResultData(_("::MyClass::functionDefinedOutSideClass"), + _("(char)")) << ResultData(_("::MyEnum"), testFileShort) << ResultData(_("::myFunction"), _("(bool, int)")) << ResultData(_("MyClass"), testFileShort) @@ -213,8 +221,10 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() << ResultData(_("MyEnum"), testFileShort) << ResultData(_("MyNamespace::MyClass"), testFileShort) << ResultData(_("MyNamespace::MyClass::MyClass"), _("()")) - << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClass"), _("(char)")) - << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace"), _("(float)")) + << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClass"), + _("(char)")) + << ResultData(_("MyNamespace::MyClass::functionDefinedOutSideClassAndNamespace"), + _("(float)")) << ResultData(_("MyNamespace::MyEnum"), testFileShort) << ResultData(_("MyNamespace::myFunction"), _("(bool, int)")) << ResultData(_("myFunction"), _("(bool, int)")) @@ -248,9 +258,11 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter() << ResultData(_("functionDeclaredOnly()"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("int myVariable"), _("")) << ResultData(_("myFunction(bool, int)"), _("")) << ResultData(_("MyEnum"), _("")) @@ -265,7 +277,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter() << ResultData(_("main()"), _("")) ; - CppCurrentDocumentFilterTest test(testFile); + CppCurrentDocumentFilterTestCase test(testFile); ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor()); // ResultData::printFilterEntries(results); QVERIFY(!results.isEmpty()); diff --git a/src/plugins/cpptools/cppmodelmanager_test.cpp b/src/plugins/cpptools/cppmodelmanager_test.cpp index 235d4e5c56..fec382f7a4 100644 --- a/src/plugins/cpptools/cppmodelmanager_test.cpp +++ b/src/plugins/cpptools/cppmodelmanager_test.cpp @@ -63,7 +63,7 @@ namespace { inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } -class MyTestDataDir : public Core::Internal::Tests::TestDataDir +class MyTestDataDir : public Core::Tests::TestDataDir { public: MyTestDataDir(const QString &dir) diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp index 458b9d2fb8..45e87f2523 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp +++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp @@ -49,11 +49,14 @@ using namespace CppTools; using namespace CppTools::Internal; using Utils::ChangeSet; -typedef Utils::ChangeSet::Range Range; Q_DECLARE_METATYPE(Overview) -static QString stripCursor(const QString &source) +namespace { + +typedef Utils::ChangeSet::Range Range; + +QString stripCursor(const QString &source) { QString copy(source); const int pos = copy.indexOf(QLatin1Char('@')); @@ -64,19 +67,10 @@ static QString stripCursor(const QString &source) return copy; } -class TestEnvironment : public CppTools::Tests::TestCase +class PointerDeclarationFormatterTestCase : public CppTools::Tests::TestCase { public: - QByteArray source; - Snapshot snapshot; - CppRefactoringFilePtr cppRefactoringFile; - TextEditor::BaseTextEditorWidget *editor; - Document::Ptr document; - QTextDocument *textDocument; - TranslationUnit *translationUnit; - Environment env; - - TestEnvironment(const QByteArray &source, Document::ParseMode parseMode) + PointerDeclarationFormatterTestCase(const QByteArray &source, Document::ParseMode parseMode) { // Find cursor position and remove cursor marker '@' int cursorPosition = 0; @@ -89,29 +83,29 @@ public: // Write source to temprorary file const QString filePath = QDir::tempPath() + QLatin1String("/file.h"); - document = Document::create(filePath); - QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1())); + m_document = Document::create(filePath); + QVERIFY(writeFile(m_document->fileName(), sourceWithoutCursorMarker.toLatin1())); // Preprocess source - Preprocessor preprocess(0, &env); + Preprocessor preprocess(0, &m_env); const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker); - document->setUtf8Source(preprocessedSource); - document->parse(parseMode); - document->check(); - translationUnit = document->translationUnit(); - snapshot.insert(document); - editor = new TextEditor::PlainTextEditorWidget(0); + m_document->setUtf8Source(preprocessedSource); + m_document->parse(parseMode); + m_document->check(); + m_translationUnit = m_document->translationUnit(); + m_snapshot.insert(m_document); + m_editor = new TextEditor::PlainTextEditorWidget(0); QString error; - editor->open(&error, document->fileName(), document->fileName()); + m_editor->open(&error, m_document->fileName(), m_document->fileName()); // Set cursor position - QTextCursor cursor = editor->textCursor(); + QTextCursor cursor = m_editor->textCursor(); cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition); - editor->setTextCursor(cursor); + m_editor->setTextCursor(cursor); - textDocument = editor->document(); - cppRefactoringFile = CppRefactoringChanges::file(editor, document); + m_textDocument = m_editor->document(); + m_cppRefactoringFile = CppRefactoringChanges::file(m_editor, m_document); } void applyFormatting(AST *ast, PointerDeclarationFormatter::CursorHandling cursorHandling) @@ -122,27 +116,41 @@ public: overview.starBindFlags = Overview::StarBindFlags(0); // Run the formatter - PointerDeclarationFormatter formatter(cppRefactoringFile, overview, cursorHandling); + PointerDeclarationFormatter formatter(m_cppRefactoringFile, overview, cursorHandling); ChangeSet change = formatter.format(ast); // ChangeSet may be empty. // Apply change - QTextCursor cursor(textDocument); + QTextCursor cursor(m_textDocument); change.apply(&cursor); } + +public: + QTextDocument *m_textDocument; + TranslationUnit *m_translationUnit; + +private: + QByteArray m_source; + Snapshot m_snapshot; + CppRefactoringFilePtr m_cppRefactoringFile; + TextEditor::BaseTextEditorWidget *m_editor; + Document::Ptr m_document; + Environment m_env; }; +} // anonymous namespace + void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations() { QFETCH(QString, source); QFETCH(QString, reformattedSource); - TestEnvironment env(source.toLatin1(), Document::ParseDeclaration); - AST *ast = env.translationUnit->ast(); + PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseDeclaration); + AST *ast = test.m_translationUnit->ast(); QVERIFY(ast); - env.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); + test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); - QCOMPARE(env.textDocument->toPlainText(), reformattedSource); + QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource); } void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations_data() @@ -363,13 +371,13 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements() QFETCH(QString, source); QFETCH(QString, reformattedSource); - TestEnvironment env(source.toLatin1(), Document::ParseStatement); - AST *ast = env.translationUnit->ast(); + PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseStatement); + AST *ast = test.m_translationUnit->ast(); QVERIFY(ast); - env.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); + test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); - QCOMPARE(env.textDocument->toPlainText(), reformattedSource); + QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource); } void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements_data() @@ -441,13 +449,13 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators() QFETCH(QString, source); QFETCH(QString, reformattedSource); - TestEnvironment env(source.toLatin1(), Document::ParseDeclaration); - AST *ast = env.translationUnit->ast(); + PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseDeclaration); + AST *ast = test.m_translationUnit->ast(); QVERIFY(ast); - env.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); + test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); - QCOMPARE(env.textDocument->toPlainText(), reformattedSource); + QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource); } void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators_data() @@ -499,13 +507,13 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches() QFETCH(QString, source); QFETCH(QString, reformattedSource); - TestEnvironment env(source.toLatin1(), Document::ParseTranlationUnit); - AST *ast = env.translationUnit->ast(); + PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseTranlationUnit); + AST *ast = test.m_translationUnit->ast(); QVERIFY(ast); - env.applyFormatting(ast, PointerDeclarationFormatter::IgnoreCursor); + test.applyFormatting(ast, PointerDeclarationFormatter::IgnoreCursor); - QCOMPARE(env.textDocument->toPlainText(), reformattedSource); + QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource); } void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches_data() @@ -585,13 +593,13 @@ void CppToolsPlugin::test_format_pointerdeclaration_macros() QFETCH(QString, source); QFETCH(QString, reformattedSource); - TestEnvironment env(source.toLatin1(), Document::ParseTranlationUnit); - AST *ast = env.translationUnit->ast(); + PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseTranlationUnit); + AST *ast = test.m_translationUnit->ast(); QVERIFY(ast); - env.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); + test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); - QCOMPARE(env.textDocument->toPlainText(), reformattedSource); + QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource); } void CppToolsPlugin::test_format_pointerdeclaration_macros_data() diff --git a/src/plugins/cpptools/cpppreprocessertesthelper.cpp b/src/plugins/cpptools/cpppreprocessertesthelper.cpp index dc1f48df35..64831295b1 100644 --- a/src/plugins/cpptools/cpppreprocessertesthelper.cpp +++ b/src/plugins/cpptools/cpppreprocessertesthelper.cpp @@ -32,7 +32,8 @@ #include -using namespace CppTools; +namespace CppTools { +namespace Tests { QString TestIncludePaths::includeBaseDirectory() { @@ -54,3 +55,11 @@ QString TestIncludePaths::directoryOfTestFile() { return QDir::cleanPath(includeBaseDirectory() + QLatin1String("/local")); } + +QString TestIncludePaths::testFilePath(const QString &fileName) +{ + return Tests::TestIncludePaths::directoryOfTestFile() + QLatin1Char('/') + fileName; +} + +} // namespace Tests +} // namespace CppTools diff --git a/src/plugins/cpptools/cpppreprocessertesthelper.h b/src/plugins/cpptools/cpppreprocessertesthelper.h index c4eea5059e..0a571d65a0 100644 --- a/src/plugins/cpptools/cpppreprocessertesthelper.h +++ b/src/plugins/cpptools/cpppreprocessertesthelper.h @@ -34,20 +34,26 @@ #include "cpptools_global.h" #include +#include QT_FORWARD_DECLARE_CLASS(QString) namespace CppTools { +namespace Tests { class CPPTOOLS_EXPORT TestIncludePaths { + Q_DISABLE_COPY(TestIncludePaths) + public: static QString includeBaseDirectory(); static QString globalQtCoreIncludePath(); static QString globalIncludePath(); static QString directoryOfTestFile(); + static QString testFilePath(const QString &fileName = QLatin1String("file.cpp")); }; +} // namespace Tests } // namespace CppTools #endif // CPPPREPROCESSERTESTHELPER_H diff --git a/src/plugins/cpptools/cpppreprocessor_test.cpp b/src/plugins/cpptools/cpppreprocessor_test.cpp index 7316fa3393..9fd95d49ab 100644 --- a/src/plugins/cpptools/cpppreprocessor_test.cpp +++ b/src/plugins/cpptools/cpppreprocessor_test.cpp @@ -43,6 +43,7 @@ using namespace CPlusPlus; using namespace CppTools; +using namespace CppTools::Tests; using namespace CppTools::Internal; typedef Document::Include Include; @@ -58,12 +59,11 @@ public: Document::Ptr run(const QByteArray &source) { - const QString fileName = TestIncludePaths::directoryOfTestFile() - + QLatin1String("/file.cpp"); + const QString fileName = TestIncludePaths::testFilePath(); if (QFileInfo(fileName).exists()) return Document::Ptr(); // Test file was not removed. - CppTools::Tests::TestCase::writeFile(fileName, source); + TestCase::writeFile(fileName, source); CppPreprocessor pp((QPointer(m_cmm))); pp.setIncludePaths(QStringList(TestIncludePaths::directoryOfTestFile())); @@ -107,7 +107,7 @@ void CppToolsPlugin::test_cpppreprocessor_includes() QVERIFY(resolvedIncludes.at(0).type() == Client::IncludeLocal); QCOMPARE(resolvedIncludes.at(0).unresolvedFileName(), QLatin1String("header.h")); const QString expectedResolvedFileName - = TestIncludePaths::directoryOfTestFile() + QLatin1String("/header.h"); + = TestIncludePaths::testFilePath(QLatin1String("header.h")); QCOMPARE(resolvedIncludes.at(0).resolvedFileName(), expectedResolvedFileName); const QList unresolvedIncludes = document->unresolvedIncludes(); diff --git a/src/plugins/cpptools/symbolsearcher_test.cpp b/src/plugins/cpptools/symbolsearcher_test.cpp index f75da4c23c..22d3e4ad11 100644 --- a/src/plugins/cpptools/symbolsearcher_test.cpp +++ b/src/plugins/cpptools/symbolsearcher_test.cpp @@ -46,6 +46,8 @@ namespace { QTC_DECLARE_MYTESTDATADIR("../../../tests/cppsymbolsearcher/") +inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } + class ResultData { public: @@ -78,17 +80,18 @@ public: } } +public: QString m_symbolName; QString m_scope; }; typedef ResultData::ResultDataList ResultDataList; -class SymbolSearcherTest : public CppTools::Tests::TestCase +class SymbolSearcherTestCase : public CppTools::Tests::TestCase { public: /// Takes no ownership of indexingSupportToUse - SymbolSearcherTest(const QString &testFile, CppIndexingSupport *indexingSupportToUse) + SymbolSearcherTestCase(const QString &testFile, CppIndexingSupport *indexingSupportToUse) : m_indexingSupportToUse(indexingSupportToUse) , m_testFile(testFile) { @@ -101,8 +104,8 @@ public: ResultDataList run(const SymbolSearcher::Parameters &searchParameters) const { CppIndexingSupport *indexingSupport = m_modelManager->indexingSupport(); - SymbolSearcher *symbolSearcher - = indexingSupport->createSymbolSearcher(searchParameters, QSet() << m_testFile); + SymbolSearcher *symbolSearcher = indexingSupport->createSymbolSearcher(searchParameters, + QSet() << m_testFile); QFuture search = QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher); search.waitForFinished(); @@ -110,7 +113,7 @@ public: return results; } - ~SymbolSearcherTest() + ~SymbolSearcherTestCase() { m_modelManager->setIndexingSupport(m_indexingSupportToRestore); } @@ -121,8 +124,6 @@ private: const QString m_testFile; }; -inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } - } // anonymous namespace Q_DECLARE_METATYPE(ResultData) @@ -148,7 +149,7 @@ void CppToolsPlugin::test_builtinsymbolsearcher() QScopedPointer builtinIndexingSupport(new BuiltinIndexingSupport); - SymbolSearcherTest test(testFile, builtinIndexingSupport.data()); + SymbolSearcherTestCase test(testFile, builtinIndexingSupport.data()); const ResultDataList results = test.run(searchParameters); QCOMPARE(results, expectedResults); } @@ -197,9 +198,11 @@ void CppToolsPlugin::test_builtinsymbolsearcher_data() << ResultData(_("functionDeclaredOnly()"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("int myVariable"), _("")) << ResultData(_("myFunction(bool, int)"), _("")) << ResultData(_("MyEnum"), _("")) @@ -208,9 +211,12 @@ void CppToolsPlugin::test_builtinsymbolsearcher_data() << ResultData(_("MyClass"), _("")) << ResultData(_("MyClass()"), _("::MyClass")) << ResultData(_("functionDeclaredOnly()"), _("::MyClass")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("::MyClass")) + << ResultData(_("functionDefinedInClass(bool, int)"), + _("::MyClass")) + << ResultData(_("functionDefinedOutSideClass(char)"), + _("::MyClass")) + << ResultData(_("functionDefinedOutSideClass(char)"), + _("::MyClass")) << ResultData(_("main()"), _("")) ); @@ -246,10 +252,13 @@ void CppToolsPlugin::test_builtinsymbolsearcher_data() << ResultData(_("myFunction(bool, int)"), _("MyNamespace")) << ResultData(_("functionDefinedInClass(bool, int)"), _("MyNamespace::MyClass")) << ResultData(_("functionDefinedOutSideClass(char)"), _("MyNamespace::MyClass")) - << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), _("MyNamespace::MyClass")) + << ResultData(_("functionDefinedOutSideClassAndNamespace(float)"), + _("MyNamespace::MyClass")) << ResultData(_("myFunction(bool, int)"), _("")) - << ResultData(_("functionDefinedInClass(bool, int)"), _("::MyClass")) - << ResultData(_("functionDefinedOutSideClass(char)"), _("::MyClass")) + << ResultData(_("functionDefinedInClass(bool, int)"), + _("::MyClass")) + << ResultData(_("functionDefinedOutSideClass(char)"), + _("::MyClass")) ); // Check Enums diff --git a/src/plugins/cpptools/typehierarchybuilder_test.cpp b/src/plugins/cpptools/typehierarchybuilder_test.cpp index d3175ede21..fc776f824b 100644 --- a/src/plugins/cpptools/typehierarchybuilder_test.cpp +++ b/src/plugins/cpptools/typehierarchybuilder_test.cpp @@ -44,6 +44,8 @@ using namespace CPlusPlus; using namespace CppTools; using namespace CppTools::Internal; +Q_DECLARE_METATYPE(QList) + namespace { bool hierarchySorter(const TypeHierarchy &h1, const TypeHierarchy &h2) @@ -90,14 +92,17 @@ private: return true; } +private: Class *m_clazz; }; -class TestCase : public CppTools::Tests::TestCase +class TypeHierarchyBuilderTestCase : public CppTools::Tests::TestCase { public: - TestCase(const QList &documents, const QString &expectedHierarchy) - : m_documents(documents), m_expectedHierarchy(expectedHierarchy) + TypeHierarchyBuilderTestCase(const QList &documents, + const QString &expectedHierarchy) + : m_documents(documents), + m_expectedHierarchy(expectedHierarchy) {} void run() @@ -135,8 +140,6 @@ private: } // anonymous namespace -Q_DECLARE_METATYPE(QList) - void CppToolsPlugin::test_typehierarchy_data() { QTest::addColumn >("documents"); @@ -189,6 +192,6 @@ void CppToolsPlugin::test_typehierarchy() QFETCH(QList, documents); QFETCH(QString, expectedHierarchy); - TestCase testCase(documents, expectedHierarchy); + TypeHierarchyBuilderTestCase testCase(documents, expectedHierarchy); testCase.run(); } diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp index facbd0c72e..d4cc5e19db 100644 --- a/src/plugins/designer/gotoslot_test.cpp +++ b/src/plugins/designer/gotoslot_test.cpp @@ -50,7 +50,7 @@ #include using namespace Core; -using namespace Core::Internal::Tests; +using namespace Core::Tests; using namespace CppTools; using namespace CPlusPlus; using namespace Designer; @@ -150,10 +150,10 @@ bool documentContainsMemberFunctionDeclaration(const Document::Ptr &document, return DocumentContainsDeclaration()(document->globalNamespace(), declaration); } -class GoToSlotTest : public CppTools::Tests::TestCase +class GoToSlotTestCase : public CppTools::Tests::TestCase { public: - GoToSlotTest(const QStringList &files) + GoToSlotTestCase(const QStringList &files) : m_files(files) { QCOMPARE(files.size(), 3); @@ -221,7 +221,7 @@ void Designer::Internal::FormEditorPlugin::test_gotoslot() #if QT_VERSION >= 0x050000 QFETCH(QStringList, files); - GoToSlotTest test(files); + GoToSlotTestCase test(files); test.run(); #else QSKIP("Available only with >= Qt5", SkipSingle); diff --git a/src/plugins/locator/locator_test.cpp b/src/plugins/locator/locator_test.cpp index b8a9e42a41..3f427391b2 100644 --- a/src/plugins/locator/locator_test.cpp +++ b/src/plugins/locator/locator_test.cpp @@ -40,7 +40,7 @@ #include #include -using namespace Locator::Internal::Tests; +using namespace Locator::Tests; namespace { diff --git a/src/plugins/locator/locatorfiltertest.cpp b/src/plugins/locator/locatorfiltertest.cpp index 692d213ef9..6335391aa7 100644 --- a/src/plugins/locator/locatorfiltertest.cpp +++ b/src/plugins/locator/locatorfiltertest.cpp @@ -39,8 +39,7 @@ #include using namespace Locator; -using namespace Locator::Internal; -using namespace Locator::Internal::Tests; +using namespace Locator::Tests; BasicLocatorFilterTest::BasicLocatorFilterTest(ILocatorFilter *filter) : m_filter(filter) { diff --git a/src/plugins/locator/locatorfiltertest.h b/src/plugins/locator/locatorfiltertest.h index df520adfdf..5b17bb1545 100644 --- a/src/plugins/locator/locatorfiltertest.h +++ b/src/plugins/locator/locatorfiltertest.h @@ -37,7 +37,6 @@ #include namespace Locator { -namespace Internal { namespace Tests { /// Runs a locator filter for a search text and returns the results. @@ -77,16 +76,15 @@ public: typedef ResultData::ResultDataList ResultDataList; } // namespace Tests -} // namespace Internal } // namespace Locator -Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultData) -Q_DECLARE_METATYPE(Locator::Internal::Tests::ResultDataList) +Q_DECLARE_METATYPE(Locator::Tests::ResultData) +Q_DECLARE_METATYPE(Locator::Tests::ResultDataList) QT_BEGIN_NAMESPACE namespace QTest { -template<> inline char *toString(const Locator::Internal::Tests::ResultData &data) +template<> inline char *toString(const Locator::Tests::ResultData &data) { QByteArray ba = "\"" + data.textColumn1.toUtf8() + "\", \"" + data.textColumn2.toUtf8() + "\""; return qstrdup(ba.data()); -- cgit v1.2.1