summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/cppeditor/cppdoxygen_test.cpp92
-rw-r--r--src/plugins/cppeditor/cppincludehierarchy_test.cpp21
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp311
-rw-r--r--src/plugins/cppeditor/fileandtokenactions_test.cpp72
-rw-r--r--src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp137
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp13
-rw-r--r--src/plugins/cpptools/cpplocatorfilter_test.cpp32
-rw-r--r--src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp121
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.cpp7
-rw-r--r--src/plugins/cpptools/cpptoolstestcase.h2
-rw-r--r--src/plugins/cpptools/symbolsearcher_test.cpp32
-rw-r--r--src/plugins/cpptools/typehierarchybuilder_test.cpp18
-rw-r--r--src/plugins/designer/gotoslot_test.cpp20
13 files changed, 355 insertions, 523 deletions
diff --git a/src/plugins/cppeditor/cppdoxygen_test.cpp b/src/plugins/cppeditor/cppdoxygen_test.cpp
index 87b78c6a79..d3b0abc615 100644
--- a/src/plugins/cppeditor/cppdoxygen_test.cpp
+++ b/src/plugins/cppeditor/cppdoxygen_test.cpp
@@ -62,56 +62,49 @@ typedef QByteArray _;
class DoxygenTestCase : public CppEditor::Internal::Tests::TestCase
{
public:
- DoxygenTestCase(const QByteArray &input);
- void run(const QByteArray &expected);
-
-private:
- CppEditor::Internal::Tests::TestDocument testDocument;
+ /// The '|' in the input denotes the cursor position.
+ DoxygenTestCase(const QByteArray &original, const QByteArray &expected)
+ {
+ QVERIFY(succeededSoFar());
+
+ CppEditor::Internal::Tests::TestDocument testDocument("file.cpp", original, '|');
+ QVERIFY(testDocument.hasCursorMarker());
+ testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
+ QVERIFY(testDocument.writeToDisk());
+
+ // Update Code Model
+ QVERIFY(parseFiles(testDocument.filePath()));
+
+ // Open Editor
+ QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor,
+ &testDocument.m_editorWidget));
+ closeEditorAtEndOfTestCase(testDocument.m_editor);
+
+ // We want to test documents that start with a comment. By default, the
+ // editor will fold the very first comment it encounters, assuming
+ // it is a license header. Currently unfoldAll() does not work as
+ // expected (some blocks are still hidden in some test cases, so the
+ // cursor movements are not as expected). For the time being, we just
+ // prepend a declaration before the initial test comment.
+ // testDocument.m_editorWidget->unfoldAll();
+ testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
+
+ waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
+
+ // Send 'ENTER' key press
+ QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
+ QCoreApplication::sendEvent(testDocument.m_editorWidget, &event);
+ const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
+
+ QCOMPARE(QLatin1String(result), QLatin1String(expected));
+
+ testDocument.m_editorWidget->undo();
+ const QByteArray contentsAfterUndo
+ = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
+ QCOMPARE(contentsAfterUndo, testDocument.m_source);
+ }
};
-/// The '|' in the input denotes the cursor position.
-DoxygenTestCase::DoxygenTestCase(const QByteArray &input)
- : testDocument("file.cpp", input, '|')
-{
- QVERIFY(testDocument.hasCursorMarker());
- testDocument.m_source.remove(testDocument.m_cursorPosition, 1);
- QVERIFY(testDocument.writeToDisk());
-
- // Update Code Model
- QVERIFY(parseFiles(testDocument.filePath()));
-
- // Open Editor
- QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor,
- &testDocument.m_editorWidget));
- closeEditorAtEndOfTestCase(testDocument.m_editor);
-
- // We want to test documents that start with a comment. By default, the
- // editor will fold the very first comment it encounters, assuming
- // it is a license header. Currently unfoldAll() does not work as
- // expected (some blocks are still hidden in some test cases, so the
- // cursor movements are not as expected). For the time being, we just
- // prepend a declaration before the initial test comment.
-// testDocument.m_editorWidget->unfoldAll();
- testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition);
-
- waitForRehighlightedSemanticDocument(testDocument.m_editorWidget);
-}
-
-void DoxygenTestCase::run(const QByteArray &expected)
-{
- // Send 'ENTER' key press
- QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
- QCoreApplication::sendEvent(testDocument.m_editorWidget, &event);
- const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8();
-
- QCOMPARE(QLatin1String(result), QLatin1String(expected));
-
- 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 +250,5 @@ void CppEditorPlugin::test_doxygen_comments()
{
QFETCH(QByteArray, given);
QFETCH(QByteArray, expected);
- DoxygenTestCase test(given);
- test.run(expected);
+ DoxygenTestCase(given, expected);
}
diff --git a/src/plugins/cppeditor/cppincludehierarchy_test.cpp b/src/plugins/cppeditor/cppincludehierarchy_test.cpp
index 784de18024..ef5f807e24 100644
--- a/src/plugins/cppeditor/cppincludehierarchy_test.cpp
+++ b/src/plugins/cppeditor/cppincludehierarchy_test.cpp
@@ -49,8 +49,12 @@ namespace {
class IncludeHierarchyTestCase: public CppEditor::Internal::Tests::TestCase
{
public:
- IncludeHierarchyTestCase(const QList<QByteArray> &sourceList)
+ IncludeHierarchyTestCase(const QList<QByteArray> &sourceList,
+ int includesCount,
+ int includedByCount)
{
+ QVERIFY(succeededSoFar());
+
QStringList filePaths;
const int sourceListSize = sourceList.size();
for (int i = 0; i < sourceListSize; ++i) {
@@ -66,16 +70,14 @@ public:
// Update Code Model
QVERIFY(parseFiles(filePaths));
- }
- void run(int includesCount, int includedByCount)
- {
+ // Open Editor
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
-
CPPEditor *editor;
QVERIFY(openCppEditor(fileName, &editor));
closeEditorAtEndOfTestCase(editor);
+ // Test model
CppIncludeHierarchyModel model(0);
model.buildHierarchy(editor, fileName);
QCOMPARE(model.rowCount(model.index(0, 0)), includesCount);
@@ -91,8 +93,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludes()
sourceList.append(QByteArray("#include \"file2.h\"\n"));
sourceList.append(QByteArray());
- IncludeHierarchyTestCase testCase(sourceList);
- testCase.run(1, 0);
+ IncludeHierarchyTestCase(sourceList, 1, 0);
}
void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy()
@@ -101,8 +102,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy()
sourceList.append(QByteArray());
sourceList.append(QByteArray("#include \"file1.h\"\n"));
- IncludeHierarchyTestCase testCase(sourceList);
- testCase.run(0, 1);
+ IncludeHierarchyTestCase(sourceList, 0, 1);
}
void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy()
@@ -112,6 +112,5 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy()
sourceList.append(QByteArray());
sourceList.append(QByteArray("#include \"file1.h\"\n"));
- IncludeHierarchyTestCase testCase(sourceList);
- testCase.run(1, 1);
+ IncludeHierarchyTestCase(sourceList, 1, 1);
}
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 2ff7fecfb9..988403638d 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -97,6 +97,11 @@ public:
QByteArray m_expectedSource;
};
+QList<TestDocumentPtr> singleDocument(const QByteArray &original, const QByteArray &expected)
+{
+ return QList<TestDocumentPtr>() << TestDocument::create("file.cpp", original, expected);
+}
+
/**
* Encapsulates the whole process of setting up an editor, getting the
* quick-fix, applying it, and checking the result.
@@ -104,19 +109,15 @@ public:
class QuickFixTestCase : public CppEditor::Internal::Tests::TestCase
{
public:
- QuickFixTestCase(const QByteArray &originalSource, const QByteArray &expectedSource,
- const QStringList &includePaths = QStringList());
QuickFixTestCase(const QList<TestDocumentPtr> theTestFiles,
- const QStringList &includePaths = QStringList());
+ CppQuickFixFactory *factory,
+ const QStringList &includePaths = QStringList(),
+ int resultIndex = 0);
~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<TestDocumentPtr> m_testFiles;
@@ -139,29 +140,38 @@ QuickFixOperation::Ptr QuickFixTestCase::getFix(CppQuickFixFactory *factory,
return results.isEmpty() ? QuickFixOperation::Ptr() : results.at(resultIndex);
}
-/// The '@' in the originalSource is the position from where the quick-fix discovery is triggered.
-QuickFixTestCase::QuickFixTestCase(const QByteArray &originalSource,
- const QByteArray &expectedSource,
- const QStringList &includePaths)
- : m_cppCodeStylePreferences(0)
- , m_restoreIncludePaths(false)
+/// Leading whitespace is not removed, so we can check if the indetation ranges
+/// have been set correctly by the quick-fix.
+QByteArray &removeTrailingWhitespace(QByteArray &input)
{
- m_testFiles << TestDocument::create("file.cpp", originalSource, expectedSource);
- init(includePaths);
+ QList<QByteArray> lines = input.split('\n');
+ input.resize(0);
+ foreach (QByteArray line, lines) {
+ while (line.length() > 0) {
+ char lastChar = line[line.length() - 1];
+ if (lastChar == ' ' || lastChar == '\t')
+ line = line.left(line.length() - 1);
+ else
+ break;
+ }
+ input.append(line);
+ input.append('\n');
+ }
+ return input;
}
+/// The '@' in the originalSource is the position from where the quick-fix discovery is triggered.
/// Exactly one TestFile must contain the cursor position marker '@' in the originalSource.
QuickFixTestCase::QuickFixTestCase(const QList<TestDocumentPtr> theTestFiles,
- const QStringList &includePaths)
+ CppQuickFixFactory *factory,
+ const QStringList &includePaths,
+ int resultIndex)
: m_testFiles(theTestFiles)
, m_cppCodeStylePreferences(0)
, m_restoreIncludePaths(false)
{
- init(includePaths);
-}
+ QVERIFY(succeededSoFar());
-void QuickFixTestCase::init(const QStringList &includePaths)
-{
// Check if there is exactly one cursor marker
unsigned cursorMarkersCount = 0;
foreach (const TestDocumentPtr testFile, m_testFiles) {
@@ -208,45 +218,7 @@ void QuickFixTestCase::init(const QStringList &includePaths)
QVERIFY(m_cppCodeStylePreferences);
m_cppCodeStylePreferencesOriginalDelegateId = m_cppCodeStylePreferences->currentDelegateId();
m_cppCodeStylePreferences->setCurrentDelegate("qt");
-}
-
-QuickFixTestCase::~QuickFixTestCase()
-{
- // Restore default cpp code style
- if (m_cppCodeStylePreferences)
- m_cppCodeStylePreferences->setCurrentDelegate(m_cppCodeStylePreferencesOriginalDelegateId);
-
- // Restore include paths
- if (m_restoreIncludePaths)
- m_modelManager->setIncludePaths(m_includePathsToRestore);
-
- // Remove created files from file system
- foreach (const TestDocumentPtr &testDocument, m_testFiles)
- QVERIFY(QFile::remove(testDocument->filePath()));
-}
-/// Leading whitespace is not removed, so we can check if the indetation ranges
-/// have been set correctly by the quick-fix.
-QByteArray &removeTrailingWhitespace(QByteArray &input)
-{
- QList<QByteArray> lines = input.split('\n');
- input.resize(0);
- foreach (QByteArray line, lines) {
- while (line.length() > 0) {
- char lastChar = line[line.length() - 1];
- if (lastChar == ' ' || lastChar == '\t')
- line = line.left(line.length() - 1);
- else
- break;
- }
- input.append(line);
- input.append('\n');
- }
- return input;
-}
-
-void QuickFixTestCase::run(CppQuickFixFactory *factory, int resultIndex)
-{
// Run the fix in the file having the cursor marker
TestDocumentPtr testFile;
foreach (const TestDocumentPtr file, m_testFiles) {
@@ -275,6 +247,21 @@ void QuickFixTestCase::run(CppQuickFixFactory *factory, int resultIndex)
}
}
+QuickFixTestCase::~QuickFixTestCase()
+{
+ // Restore default cpp code style
+ if (m_cppCodeStylePreferences)
+ m_cppCodeStylePreferences->setCurrentDelegate(m_cppCodeStylePreferencesOriginalDelegateId);
+
+ // Restore include paths
+ if (m_restoreIncludePaths)
+ m_modelManager->setIncludePaths(m_includePathsToRestore);
+
+ // Remove created files from file system
+ foreach (const TestDocumentPtr &testDocument, m_testFiles)
+ QVERIFY(QFile::remove(testDocument->filePath()));
+}
+
/// Delegates directly to AddIncludeForUndefinedIdentifierOp for easier testing.
class AddIncludeForUndefinedIdentifierTestFactory : public CppQuickFixFactory
{
@@ -1200,8 +1187,7 @@ void CppEditorPlugin::test_quickfix()
if (expected.isEmpty())
expected = original + '\n';
- QuickFixTestCase test(original, expected);
- test.run(factory.data());
+ QuickFixTestCase(singleDocument(original, expected), factory.data());
}
/// Checks: In addition to test_quickfix_GenerateGetterSetter_basicGetterWithPrefix
@@ -1254,8 +1240,7 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAn
testFiles << TestDocument::create("file.cpp", original, expected);
GenerateGetterSetter factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check if definition is inserted right after class for insert definition outside
@@ -1298,8 +1283,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory, 1);
+ QuickFixTestCase(testFiles, &factory, QStringList(), 1);
}
/// Check from header file: If there is a source file, insert the definition in the source file.
@@ -1332,8 +1316,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic1()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check from header file: If there is a source file, insert the definition in the source file.
@@ -1371,8 +1354,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic2()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check from source file: Insert in source file, not header file.
@@ -1403,8 +1385,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic3()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check from header file: If the class is in a namespace, the added function definition
@@ -1439,8 +1420,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace1()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check from header file: If the class is in namespace N and the source file has a
@@ -1479,8 +1459,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace2()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check definition insert inside class
@@ -1498,8 +1477,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_insideClass()
"};\n";
InsertDefFromDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory, 1);
+ QuickFixTestCase(singleDocument(original, expected), &factory, QStringList(), 1);
}
/// Check not triggering when definition exists
@@ -1513,8 +1491,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitio
const QByteArray expected = original + "\n";
InsertDefFromDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory, 1);
+ QuickFixTestCase test(singleDocument(original, expected), &factory, QStringList(), 1);
}
/// Find right implementation file.
@@ -1565,8 +1542,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
testFiles << TestDocument::create("file2.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Ignore generated functions declarations when looking at the surrounding
@@ -1622,8 +1598,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGenerated
testFiles << TestDocument::create("file2.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check if whitespace is respected for operator functions
@@ -1648,8 +1623,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1(
"\n";
InsertDefFromDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check if whitespace is respected for operator functions
@@ -1674,8 +1648,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2(
"\n";
InsertDefFromDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check if a function like macro use is not separated by the function to insert
@@ -1718,8 +1691,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile1()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check if a function like macro use is not separated by the function to insert
@@ -1760,8 +1732,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check if insertion happens before syntactically erroneous statements at end of file.
@@ -1799,8 +1770,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfF
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Respect rvalue references
@@ -1829,8 +1799,7 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference()
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDefFromDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
// Function for one of InsertDeclDef section cases
@@ -1867,8 +1836,7 @@ void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
testFiles << TestDocument::create("file.cpp", original, expected);
InsertDeclFromDef factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory, sectionIndex);
+ QuickFixTestCase(testFiles, &factory, QStringList(), sectionIndex);
}
/// Check from source file: Insert in header file.
@@ -2076,8 +2044,7 @@ 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;
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Ignore *.moc includes
@@ -2103,8 +2070,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_ignoremoc()
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert include at top for a sorted group
@@ -2130,8 +2096,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingTop(
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert include in the middle for a sorted group
@@ -2157,8 +2122,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingMidd
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert include at bottom for a sorted group
@@ -2184,8 +2148,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_sortingBott
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: For an unsorted group the new include is appended
@@ -2211,8 +2174,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_appendToUns
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert a local include at front if there are only global includes
@@ -2239,8 +2201,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstLocalI
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert a global include at back if there are only local includes
@@ -2270,8 +2231,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_firstGlobal
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<file.h>"));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Prefer group with longest matching prefix
@@ -2301,8 +2261,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_preferGroup
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"prefixc.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Create a new include group if there are only include groups with a different include dir
@@ -2329,8 +2288,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_newGroupIfO
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include dirs, sorted --> insert properly
@@ -2358,8 +2316,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsSo
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<firstlib/file.h>"));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include dirs, unsorted --> append
@@ -2387,8 +2344,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedDirsUn
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lastlib/file.h>"));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include types
@@ -2414,8 +2370,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"z.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include types
@@ -2441,8 +2396,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"a.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include types
@@ -2468,8 +2422,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"lib/file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Include group with mixed include types
@@ -2495,8 +2448,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_mixedInclud
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("<lib/file.h>"));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert very first include
@@ -2520,8 +2472,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_noinclude()
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert very first include if there is a c++ style comment on top
@@ -2551,8 +2502,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: Insert very first include if there is a c style comment on top
@@ -2586,8 +2536,7 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_veryFirstIn
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifierTestFactory factory(QLatin1String("\"file.h\""));
- QuickFixTestCase test(testFiles, QStringList(TestIncludePaths::globalIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory, QStringList(TestIncludePaths::globalIncludePath()));
}
/// Check: If a "Qt Class" was not found by the locator, check the header files in the Qt
@@ -2612,8 +2561,8 @@ void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_checkQSomet
+ "/file.cpp", original, expected);
AddIncludeForUndefinedIdentifier factory;
- QuickFixTestCase test(testFiles, QStringList(CppTools::Tests::TestIncludePaths::globalQtCoreIncludePath()));
- test.run(&factory);
+ QuickFixTestCase(testFiles,&factory,
+ QStringList(CppTools::Tests::TestIncludePaths::globalQtCoreIncludePath()));
}
/// Check: Move definition from header to cpp.
@@ -2656,8 +2605,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS()
@@ -2703,8 +2651,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppInsideNS()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move definition outside class
@@ -2738,8 +2685,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside1()
"void Foo::f4() {}\n\n";
MoveFuncDefOutside factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: Move definition outside class
@@ -2781,8 +2727,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory, 1);
+ QuickFixTestCase(testFiles, &factory, QStringList(), 1);
}
/// Check: Move definition from header to cpp (with namespace).
@@ -2825,8 +2770,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move definition from header to cpp (with namespace + using).
@@ -2871,8 +2815,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move definition outside class with Namespace
@@ -2899,8 +2842,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs()
"\n}\n";
MoveFuncDefOutside factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: Move free function from header to cpp.
@@ -2936,8 +2878,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCpp()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move free function from header to cpp (with namespace).
@@ -2977,8 +2918,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move Ctor with member initialization list (QTCREATORBUG-9157).
@@ -3018,8 +2958,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization1()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Move Ctor with member initialization list (QTCREATORBUG-9462).
@@ -3064,8 +3003,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization2()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check if definition is inserted right after class for move definition outside
@@ -3107,8 +3045,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefOutside factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory, 1);
+ QuickFixTestCase(testFiles, &factory, QStringList(), 1);
}
/// Check if whitespace is respected for operator functions
@@ -3130,8 +3067,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames1
"\n";
MoveFuncDefOutside factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check if whitespace is respected for operator functions
@@ -3153,8 +3089,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_respectWsInOperatorNames2
"\n";
MoveFuncDefOutside factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
@@ -3186,8 +3121,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncOutside()
@@ -3213,8 +3147,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncOutside()
"\n\n\n";
MoveFuncDefToDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCppNS()
@@ -3254,8 +3187,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNS()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCppNSUsing()
@@ -3299,8 +3231,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncToCppNSUsing()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncOutsideWithNs()
@@ -3327,8 +3258,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFuncOutsideWithNs()
"};\n\n\n}\n\n";
MoveFuncDefToDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_FreeFuncToCpp()
@@ -3360,8 +3290,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCpp()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_FreeFuncToCppNS()
@@ -3399,8 +3328,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_FreeFuncToCppNS()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: revert test_quickfix_MoveFuncDefOutside_CtorWithInitialization()
@@ -3439,8 +3367,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_CtorWithInitialization()
testFiles << TestDocument::create("file.cpp", original, expected);
MoveFuncDefToDecl factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Definition should not be placed behind the variable. QTCREATORBUG-10303
@@ -3466,8 +3393,7 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_structWithAssignedVariable
"} bar;\n\n\n";
MoveFuncDefToDecl factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
@@ -3504,8 +3430,7 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
testFiles << TestDocument::create("file.cpp", original, expected);
AssignToLocalVariable factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_typeDeduction_data()
@@ -3569,8 +3494,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_typeDeduction()
}
ExtractLiteralAsParameter factory;
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separateFiles()
@@ -3596,8 +3520,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_freeFunction_separ
testFiles << TestDocument::create("file.cpp", original, expected);
ExtractLiteralAsParameter factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_separateFiles()
@@ -3631,8 +3554,7 @@ void CppEditorPlugin::test_quickfix_ExtractLiteralAsParameter_memberFunction_sep
testFiles << TestDocument::create("file.cpp", original, expected);
ExtractLiteralAsParameter factory;
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
Q_DECLARE_METATYPE(InsertVirtualMethodsDialog::ImplementationMode)
@@ -3937,8 +3859,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods()
InsertVirtualMethods factory(
new InsertVirtualMethodsDialogTest(implementationMode, insertVirtualKeyword));
- QuickFixTestCase test(original, expected);
- test.run(&factory);
+ QuickFixTestCase(singleDocument(original, expected), &factory);
}
/// Check: Insert in implementation file
@@ -3984,8 +3905,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
/// Check: Qualified names.
@@ -4037,6 +3957,5 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
InsertVirtualMethods factory(new InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
- QuickFixTestCase test(testFiles);
- test.run(&factory);
+ QuickFixTestCase(testFiles, &factory);
}
diff --git a/src/plugins/cppeditor/fileandtokenactions_test.cpp b/src/plugins/cppeditor/fileandtokenactions_test.cpp
index 3b7306bffd..7f2ebeaadf 100644
--- a/src/plugins/cppeditor/fileandtokenactions_test.cpp
+++ b/src/plugins/cppeditor/fileandtokenactions_test.cpp
@@ -97,12 +97,10 @@ public:
typedef QList<ActionPointer> Actions;
public:
- TestActionsTestCase();
-
/// Run the given fileActions for each file and the given tokenActions for each token.
/// The cursor is positioned on the very first character of each token.
- void run(const Actions &tokenActions = Actions(),
- const Actions &fileActions = Actions());
+ TestActionsTestCase(const Actions &tokenActions = Actions(),
+ const Actions &fileActions = Actions());
/// Simulate pressing ESC, which will close popups, search results pane, etc...
/// This works only if the Qt Creator window is active.
@@ -136,13 +134,16 @@ bool TestActionsTestCase::allProjectsConfigured = false;
typedef TestActionsTestCase::Actions Actions;
typedef TestActionsTestCase::ActionPointer ActionPointer;
-TestActionsTestCase::TestActionsTestCase()
- : CppEditor::Internal::Tests::TestCase(/*runGarbageCollector=*/false)
+Actions singleAction(const ActionPointer &action)
{
+ return Actions() << action;
}
-void TestActionsTestCase::run(const Actions &tokenActions, const Actions &fileActions)
+TestActionsTestCase::TestActionsTestCase(const Actions &tokenActions, const Actions &fileActions)
+ : CppEditor::Internal::Tests::TestCase(/*runGarbageCollector=*/false)
{
+ QVERIFY(succeededSoFar());
+
// Collect files to process
QStringList filesToOpen;
QList<QPointer<ProjectExplorer::Project> > projects;
@@ -516,88 +517,51 @@ void SwitchHeaderSourceFileAction::run(CPPEditorWidget *)
void CppEditorPlugin::test_openEachFile()
{
- TestActionsTestCase test;
- test.run();
+ TestActionsTestCase();
}
void CppEditorPlugin::test_switchHeaderSourceOnEachFile()
{
- Actions fileActions;
- fileActions << ActionPointer(new SwitchHeaderSourceFileAction);
-
- TestActionsTestCase test;
- test.run(Actions(), fileActions);
+ TestActionsTestCase(Actions(), singleAction(ActionPointer(new SwitchHeaderSourceFileAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFile()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new NoOpTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new NoOpTokenAction)));
}
/// May block if file does not exists (e.g. a not generated ui_* file).
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFollowSymbol()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new FollowSymbolUnderCursorTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new FollowSymbolUnderCursorTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndSwitchDeclarationDefinition()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new SwitchDeclarationDefinitionTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new SwitchDeclarationDefinitionTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFindUsages()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new FindUsagesTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new FindUsagesTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndRenameUsages()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new RenameSymbolUnderCursorTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new RenameSymbolUnderCursorTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndOpenTypeHierarchy()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new OpenTypeHierarchyTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new OpenTypeHierarchyTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndInvokeCompletion()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new InvokeCompletionTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new InvokeCompletionTokenAction)));
}
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndTriggerQuickFixes()
{
- Actions tokenActions;
- tokenActions << ActionPointer(new RunAllQuickFixesTokenAction());
-
- TestActionsTestCase test;
- test.run(tokenActions);
+ TestActionsTestCase(singleAction(ActionPointer(new RunAllQuickFixesTokenAction)));
}
diff --git a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
index 0c8914db5a..73306532f7 100644
--- a/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
+++ b/src/plugins/cppeditor/followsymbol_switchmethoddecldef_test.cpp
@@ -206,6 +206,11 @@ public:
int m_targetCursorPosition;
};
+QList<TestDocumentPtr> singleDocument(const QByteArray &source)
+{
+ return QList<TestDocumentPtr>() << TestDocument::create(source, "file.cpp");
+}
+
/**
* Encapsulates the whole process of setting up several editors, positioning the cursor,
* executing Follow Symbol Under Cursor or Switch Between Function Declaration/Definition
@@ -219,71 +224,45 @@ public:
SwitchBetweenMethodDeclarationDefinitionAction
};
- F2TestCase(CppEditorAction action, const QByteArray &source,
+ F2TestCase(CppEditorAction action,
+ const QList<TestDocumentPtr> testFiles,
const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
- F2TestCase(CppEditorAction action, const QList<TestDocumentPtr> theTestFiles,
- const OverrideItemList &expectedVirtualFunctionProposal = OverrideItemList());
-
- void run();
-
-private:
- void init();
-
- TestDocumentPtr testFileWithInitialCursorMarker();
- TestDocumentPtr testFileWithTargetCursorMarker();
private:
- CppEditorAction m_action;
- QList<TestDocumentPtr> m_testFiles;
- OverrideItemList m_expectedVirtualFunctionProposal;
+ static TestDocumentPtr testFileWithInitialCursorMarker(const QList<TestDocumentPtr> &testFiles);
+ static TestDocumentPtr testFileWithTargetCursorMarker(const QList<TestDocumentPtr> &testFiles);
};
-/// Convenience function for creating a TestDocument.
-/// See TestDocument.
-F2TestCase::F2TestCase(CppEditorAction action,
- const QByteArray &source,
- const OverrideItemList &expectedVirtualFunctionProposal)
- : m_action(action)
- , m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal)
-{
- m_testFiles << TestDocument::create(source, "file.cpp");
- init();
-}
-
/// Creates a test case with multiple test files.
/// 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.
F2TestCase::F2TestCase(CppEditorAction action,
- const QList<TestDocumentPtr> theTestFiles,
+ const QList<TestDocumentPtr> testFiles,
const OverrideItemList &expectedVirtualFunctionProposal)
- : m_action(action)
- , m_testFiles(theTestFiles)
- , m_expectedVirtualFunctionProposal(expectedVirtualFunctionProposal)
{
- init();
-}
+ QVERIFY(succeededSoFar());
-void F2TestCase::init()
-{
// Check if there are initial and target position markers
- QVERIFY2(testFileWithInitialCursorMarker(),
+ TestDocumentPtr initialTestFile = testFileWithInitialCursorMarker(testFiles);
+ QVERIFY2(initialTestFile,
"No test file with initial cursor marker is provided.");
- QVERIFY2(testFileWithTargetCursorMarker(),
+ TestDocumentPtr targetTestFile = testFileWithTargetCursorMarker(testFiles);
+ QVERIFY2(targetTestFile,
"No test file with target cursor marker is provided.");
// Write files to disk
- foreach (TestDocumentPtr testFile, m_testFiles)
+ foreach (TestDocumentPtr testFile, testFiles)
QVERIFY(testFile->writeToDisk());
// Update Code Model
QStringList filePaths;
- foreach (const TestDocumentPtr &testFile, m_testFiles)
+ foreach (const TestDocumentPtr &testFile, testFiles)
filePaths << testFile->filePath();
QVERIFY(parseFiles(filePaths));
// Open Files
- foreach (TestDocumentPtr testFile, m_testFiles) {
+ foreach (TestDocumentPtr testFile, testFiles) {
QVERIFY(openCppEditor(testFile->filePath(), &testFile->m_editor,
&testFile->m_editorWidget));
closeEditorAtEndOfTestCase(testFile->m_editor);
@@ -300,32 +279,6 @@ void F2TestCase::init()
// Rehighlight
waitForRehighlightedSemanticDocument(testFile->m_editorWidget);
}
-}
-
-TestDocumentPtr F2TestCase::testFileWithInitialCursorMarker()
-{
- foreach (const TestDocumentPtr testFile, m_testFiles) {
- if (testFile->hasCursorMarker())
- return testFile;
- }
- return TestDocumentPtr();
-}
-
-TestDocumentPtr F2TestCase::testFileWithTargetCursorMarker()
-{
- foreach (const TestDocumentPtr testFile, m_testFiles) {
- if (testFile->hasTargetCursorMarker())
- return testFile;
- }
- return TestDocumentPtr();
-}
-
-void F2TestCase::run()
-{
- TestDocumentPtr initialTestFile = testFileWithInitialCursorMarker();
- QVERIFY(initialTestFile);
- TestDocumentPtr targetTestFile = testFileWithTargetCursorMarker();
- QVERIFY(targetTestFile);
// Activate editor of initial test file
EditorManager::activateEditor(initialTestFile->m_editor);
@@ -338,7 +291,7 @@ void F2TestCase::run()
OverrideItemList finalVirtualSymbolResults;
// Trigger the action
- switch (m_action) {
+ switch (action) {
case FollowSymbolUnderCursorAction: {
CPPEditorWidget *widget = initialTestFile->m_editorWidget;
FollowSymbolUnderCursor *delegate = widget->followSymbolUnderCursorDelegate();
@@ -385,12 +338,30 @@ void F2TestCase::run()
// qDebug() << immediateVirtualSymbolResults;
// qDebug() << finalVirtualSymbolResults;
OverrideItemList expectedImmediate;
- if (!m_expectedVirtualFunctionProposal.isEmpty()) {
- expectedImmediate << m_expectedVirtualFunctionProposal.first();
+ if (!expectedVirtualFunctionProposal.isEmpty()) {
+ expectedImmediate << expectedVirtualFunctionProposal.first();
expectedImmediate << OverrideItem(QLatin1String("...searching overrides"));
}
QCOMPARE(immediateVirtualSymbolResults, expectedImmediate);
- QCOMPARE(finalVirtualSymbolResults, m_expectedVirtualFunctionProposal);
+ QCOMPARE(finalVirtualSymbolResults, expectedVirtualFunctionProposal);
+}
+
+TestDocumentPtr F2TestCase::testFileWithInitialCursorMarker(const QList<TestDocumentPtr> &testFiles)
+{
+ foreach (const TestDocumentPtr testFile, testFiles) {
+ if (testFile->hasCursorMarker())
+ return testFile;
+ }
+ return TestDocumentPtr();
+}
+
+TestDocumentPtr F2TestCase::testFileWithTargetCursorMarker(const QList<TestDocumentPtr> &testFiles)
+{
+ foreach (const TestDocumentPtr testFile, testFiles) {
+ if (testFile->hasTargetCursorMarker())
+ return testFile;
+ }
+ return TestDocumentPtr();
}
} // anonymous namespace
@@ -492,8 +463,7 @@ void CppEditorPlugin::test_SwitchMethodDeclarationDefinition()
<< TestDocument::create(header, "file.h")
<< TestDocument::create(source, "file.cpp");
- F2TestCase test(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
- test.run();
+ F2TestCase(F2TestCase::SwitchBetweenMethodDeclarationDefinitionAction, testFiles);
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
@@ -853,8 +823,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
void CppEditorPlugin::test_FollowSymbolUnderCursor()
{
QFETCH(QByteArray, source);
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source));
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
@@ -881,9 +850,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments()
{
QFETCH(QList<TestDocumentPtr>, documents);
-
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, documents);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, documents);
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_QObject_connect_data()
@@ -972,8 +939,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_QObject_connect()
return;
}
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source));
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_onOperatorToken_data()
@@ -996,8 +962,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_onOperatorToken
"}\n";
if (toDeclaration)
source.replace('@', '#').replace('$', '@').replace('#', '$');
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source));
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_data()
@@ -1022,8 +987,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator()
else
source.replace("@2", QByteArray()).replace("$2", QByteArray())
.replace("@1", "@").replace("$1", "$");
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source));
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_inOp_data()
@@ -1048,8 +1012,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_classOperator_inOp()
else
source.replace("@2", QByteArray()).replace("$2", QByteArray())
.replace("@1", "@").replace("$1", "$");
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source));
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_data()
@@ -1302,8 +1265,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall()
QFETCH(QByteArray, source);
QFETCH(OverrideItemList, results);
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, source, results);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, singleDocument(source), results);
}
/// Check: Base classes can be found although these might be defined in distinct documents.
@@ -1324,8 +1286,7 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_virtualFunctionCall_multipleD
<< OverrideItem(QLatin1String("A::virt"), 1)
<< OverrideItem(QLatin1String("B::virt"), 2);
- F2TestCase test(F2TestCase::FollowSymbolUnderCursorAction, testFiles, finalResults);
- test.run();
+ F2TestCase(F2TestCase::FollowSymbolUnderCursorAction, testFiles, finalResults);
}
/*
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 173181c412..83387eaa70 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -63,6 +63,9 @@ public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
: m_position(-1), m_editorWidget(0), m_textDocument(0), m_editor(0)
{
+ QVERIFY(succeededSoFar());
+ m_succeededSoFar = false;
+
m_source = sourceText;
m_position = m_source.indexOf('@');
QVERIFY(m_position != -1);
@@ -89,6 +92,8 @@ public:
if (!textToInsert.isEmpty())
insertText(textToInsert);
+
+ m_succeededSoFar = true;
}
QStringList getCompletions(bool *replaceAccessOperator = 0) const
@@ -162,6 +167,7 @@ void CppToolsPlugin::test_completion_basic_1()
" @\n"
"}";
CompletionTestCase test(source);
+ QVERIFY(test.succeededSoFar());
QStringList basicCompletions = test.getCompletions();
QVERIFY(!basicCompletions.contains(QLatin1String("foo")));
@@ -189,6 +195,7 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_8737()
"}\n"
;
CompletionTestCase test(source, "a_c");
+ QVERIFY(test.succeededSoFar());
QStringList completions = test.getCompletions();
@@ -214,9 +221,9 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_9236()
"};\n"
;
CompletionTestCase test(source, "ret");
+ QVERIFY(test.succeededSoFar());
QStringList completions = test.getCompletions();
-
QVERIFY(completions.size() >= 2);
QCOMPARE(completions.at(0), QLatin1String("return"));
QCOMPARE(completions.at(1), QLatin1String("rETUCASE"));
@@ -233,9 +240,9 @@ void CppToolsPlugin::test_completion_template_function()
QFETCH(QStringList, expectedCompletions);
CompletionTestCase test(code);
+ QVERIFY(test.succeededSoFar());
QStringList actualCompletions = test.getCompletions();
-
QString errorPattern(QLatin1String("Completion not found: %1"));
foreach (const QString &completion, expectedCompletions) {
QByteArray errorMessage = errorPattern.arg(completion).toUtf8();
@@ -290,6 +297,7 @@ void CppToolsPlugin::test_completion()
QFETCH(QStringList, expectedCompletions);
CompletionTestCase test(code, prefix);
+ QVERIFY(test.succeededSoFar());
QStringList actualCompletions = test.getCompletions();
actualCompletions.sort();
@@ -2092,6 +2100,7 @@ void CppToolsPlugin::test_completion_member_access_operator()
QFETCH(bool, expectedReplaceAccessOperator);
CompletionTestCase test(code, prefix);
+ QVERIFY(test.succeededSoFar());
bool replaceAccessOperator = false;
QStringList completions = test.getCompletions(&replaceAccessOperator);
diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp
index 5a7e7f3a3a..9280fbcb72 100644
--- a/src/plugins/cpptools/cpplocatorfilter_test.cpp
+++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp
@@ -67,12 +67,21 @@ class CppLocatorFilterTestCase
, public CppTools::Tests::TestCase
{
public:
- CppLocatorFilterTestCase(ILocatorFilter *filter, const QString &fileName)
+ CppLocatorFilterTestCase(ILocatorFilter *filter,
+ const QString &fileName,
+ const QString &searchText,
+ const ResultDataList &expectedResults)
: BasicLocatorFilterTest(filter)
, m_fileName(fileName)
{
+ QVERIFY(succeededSoFar());
QVERIFY(!m_fileName.isEmpty());
QVERIFY(garbageCollectGlobalSnapshot());
+
+ ResultDataList results = ResultData::fromFilterEntryList(matchesFor(searchText));
+// ResultData::printFilterEntries(results);
+ QVERIFY(!results.isEmpty());
+ QCOMPARE(results, expectedResults);
}
private:
@@ -88,12 +97,19 @@ class CppCurrentDocumentFilterTestCase
, public CppTools::Tests::TestCase
{
public:
- CppCurrentDocumentFilterTestCase(const QString &fileName)
+ CppCurrentDocumentFilterTestCase(const QString &fileName,
+ const ResultDataList &expectedResults)
: BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>())
, m_editor(0)
, m_fileName(fileName)
{
+ QVERIFY(succeededSoFar());
QVERIFY(!m_fileName.isEmpty());
+
+ ResultDataList results = ResultData::fromFilterEntryList(matchesFor());
+// ResultData::printFilterEntries(results);
+ QVERIFY(!results.isEmpty());
+ QCOMPARE(results, expectedResults);
}
private:
@@ -130,11 +146,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter()
QFETCH(QString, searchText);
QFETCH(ResultDataList, expectedResults);
- CppLocatorFilterTestCase test(filter, testFile);
- ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor(searchText));
-// ResultData::printFilterEntries(results);
- QVERIFY(!results.isEmpty());
- QCOMPARE(results, expectedResults);
+ CppLocatorFilterTestCase(filter, testFile, searchText, expectedResults);
}
void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
@@ -277,9 +289,5 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
<< ResultData(_("main()"), _(""))
;
- CppCurrentDocumentFilterTestCase test(testFile);
- ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor());
-// ResultData::printFilterEntries(results);
- QVERIFY(!results.isEmpty());
- QCOMPARE(expectedResults, results);
+ CppCurrentDocumentFilterTestCase(testFile, expectedResults);
}
diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
index 45e87f2523..ffbffd7122 100644
--- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
+++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
@@ -70,8 +70,13 @@ QString stripCursor(const QString &source)
class PointerDeclarationFormatterTestCase : public CppTools::Tests::TestCase
{
public:
- PointerDeclarationFormatterTestCase(const QByteArray &source, Document::ParseMode parseMode)
+ PointerDeclarationFormatterTestCase(const QByteArray &source,
+ const QString &expectedSource,
+ Document::ParseMode parseMode,
+ PointerDeclarationFormatter::CursorHandling cursorHandling)
{
+ QVERIFY(succeededSoFar());
+
// Find cursor position and remove cursor marker '@'
int cursorPosition = 0;
QString sourceWithoutCursorMarker = QLatin1String(source);
@@ -83,58 +88,53 @@ public:
// Write source to temprorary file
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
- m_document = Document::create(filePath);
- QVERIFY(writeFile(m_document->fileName(), sourceWithoutCursorMarker.toLatin1()));
+ Document::Ptr document = Document::create(filePath);
+ QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1()));
// Preprocess source
- Preprocessor preprocess(0, &m_env);
+ Environment env;
+ Preprocessor preprocess(0, &env);
const QByteArray preprocessedSource = preprocess.run(filePath, sourceWithoutCursorMarker);
- 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);
+ document->setUtf8Source(preprocessedSource);
+ document->parse(parseMode);
+ document->check();
+ AST *ast = document->translationUnit()->ast();
+ QVERIFY(ast);
+
+ // Open file
+ QScopedPointer<TextEditor::BaseTextEditorWidget> editorWidget(
+ new TextEditor::PlainTextEditorWidget(0));
QString error;
- m_editor->open(&error, m_document->fileName(), m_document->fileName());
+ editorWidget->open(&error, document->fileName(), document->fileName());
+ QVERIFY(error.isEmpty());
// Set cursor position
- QTextCursor cursor = m_editor->textCursor();
+ QTextCursor cursor = editorWidget->textCursor();
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition);
- m_editor->setTextCursor(cursor);
+ editorWidget->setTextCursor(cursor);
- m_textDocument = m_editor->document();
- m_cppRefactoringFile = CppRefactoringChanges::file(m_editor, m_document);
- }
+ QTextDocument *textDocument = editorWidget->document();
+ CppRefactoringFilePtr cppRefactoringFile
+ = CppRefactoringChanges::file(editorWidget.data(), document);
- void applyFormatting(AST *ast, PointerDeclarationFormatter::CursorHandling cursorHandling)
- {
+ // Prepare for formatting
Overview overview;
overview.showReturnTypes = true;
overview.showArgumentNames = true;
overview.starBindFlags = Overview::StarBindFlags(0);
// Run the formatter
- PointerDeclarationFormatter formatter(m_cppRefactoringFile, overview, cursorHandling);
+ PointerDeclarationFormatter formatter(cppRefactoringFile, overview, cursorHandling);
ChangeSet change = formatter.format(ast); // ChangeSet may be empty.
// Apply change
- QTextCursor cursor(m_textDocument);
- change.apply(&cursor);
- }
+ QTextCursor changeCursor(textDocument);
+ change.apply(&changeCursor);
-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;
+ // Compare
+ QCOMPARE(textDocument->toPlainText(), expectedSource);
+ }
};
} // anonymous namespace
@@ -144,13 +144,10 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
- PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseDeclaration);
- AST *ast = test.m_translationUnit->ast();
- QVERIFY(ast);
-
- test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor);
-
- QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource);
+ PointerDeclarationFormatterTestCase(source.toLatin1(),
+ reformattedSource,
+ Document::ParseDeclaration,
+ PointerDeclarationFormatter::RespectCursor);
}
void CppToolsPlugin::test_format_pointerdeclaration_in_simpledeclarations_data()
@@ -371,13 +368,10 @@ void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
- PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseStatement);
- AST *ast = test.m_translationUnit->ast();
- QVERIFY(ast);
-
- test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor);
-
- QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource);
+ PointerDeclarationFormatterTestCase(source.toLatin1(),
+ reformattedSource,
+ Document::ParseStatement,
+ PointerDeclarationFormatter::RespectCursor);
}
void CppToolsPlugin::test_format_pointerdeclaration_in_controlflowstatements_data()
@@ -449,13 +443,10 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
- PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseDeclaration);
- AST *ast = test.m_translationUnit->ast();
- QVERIFY(ast);
-
- test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor);
-
- QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource);
+ PointerDeclarationFormatterTestCase(source.toLatin1(),
+ reformattedSource,
+ Document::ParseDeclaration,
+ PointerDeclarationFormatter::RespectCursor);
}
void CppToolsPlugin::test_format_pointerdeclaration_multiple_declarators_data()
@@ -507,13 +498,10 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
- PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseTranlationUnit);
- AST *ast = test.m_translationUnit->ast();
- QVERIFY(ast);
-
- test.applyFormatting(ast, PointerDeclarationFormatter::IgnoreCursor);
-
- QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource);
+ PointerDeclarationFormatterTestCase(source.toLatin1(),
+ reformattedSource,
+ Document::ParseTranlationUnit,
+ PointerDeclarationFormatter::IgnoreCursor);
}
void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches_data()
@@ -593,13 +581,10 @@ void CppToolsPlugin::test_format_pointerdeclaration_macros()
QFETCH(QString, source);
QFETCH(QString, reformattedSource);
- PointerDeclarationFormatterTestCase test(source.toLatin1(), Document::ParseTranlationUnit);
- AST *ast = test.m_translationUnit->ast();
- QVERIFY(ast);
-
- test.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor);
-
- QCOMPARE(test.m_textDocument->toPlainText(), reformattedSource);
+ PointerDeclarationFormatterTestCase(source.toLatin1(),
+ reformattedSource,
+ Document::ParseTranlationUnit,
+ PointerDeclarationFormatter::RespectCursor);
}
void CppToolsPlugin::test_format_pointerdeclaration_macros_data()
diff --git a/src/plugins/cpptools/cpptoolstestcase.cpp b/src/plugins/cpptools/cpptoolstestcase.cpp
index be9e61fb03..80de9dfc1d 100644
--- a/src/plugins/cpptools/cpptoolstestcase.cpp
+++ b/src/plugins/cpptools/cpptoolstestcase.cpp
@@ -70,10 +70,12 @@ bool TestDocument::writeToDisk() const
TestCase::TestCase(bool runGarbageCollector)
: m_modelManager(CppModelManagerInterface::instance())
+ , m_succeededSoFar(false)
, m_runGarbageCollector(runGarbageCollector)
{
if (m_runGarbageCollector)
QVERIFY(garbageCollectGlobalSnapshot());
+ m_succeededSoFar = true;
}
TestCase::~TestCase()
@@ -85,6 +87,11 @@ TestCase::~TestCase()
QVERIFY(garbageCollectGlobalSnapshot());
}
+bool TestCase::succeededSoFar() const
+{
+ return m_succeededSoFar;
+}
+
CPlusPlus::Snapshot TestCase::globalSnapshot()
{
return CppModelManagerInterface::instance()->snapshot();
diff --git a/src/plugins/cpptools/cpptoolstestcase.h b/src/plugins/cpptools/cpptoolstestcase.h
index 1c9b5b4f59..cdca7c3db7 100644
--- a/src/plugins/cpptools/cpptoolstestcase.h
+++ b/src/plugins/cpptools/cpptoolstestcase.h
@@ -70,6 +70,7 @@ public:
TestCase(bool runGarbageCollector = true);
~TestCase();
+ bool succeededSoFar() const;
void closeEditorAtEndOfTestCase(Core::IEditor *editor);
static bool parseFiles(const QString &filePath);
@@ -86,6 +87,7 @@ public:
protected:
CppModelManagerInterface *m_modelManager;
+ bool m_succeededSoFar;
private:
QList<Core::IEditor *> m_editorsToClose;
diff --git a/src/plugins/cpptools/symbolsearcher_test.cpp b/src/plugins/cpptools/symbolsearcher_test.cpp
index 22d3e4ad11..6f41179dba 100644
--- a/src/plugins/cpptools/symbolsearcher_test.cpp
+++ b/src/plugins/cpptools/symbolsearcher_test.cpp
@@ -91,37 +91,39 @@ class SymbolSearcherTestCase : public CppTools::Tests::TestCase
{
public:
/// Takes no ownership of indexingSupportToUse
- SymbolSearcherTestCase(const QString &testFile, CppIndexingSupport *indexingSupportToUse)
- : m_indexingSupportToUse(indexingSupportToUse)
- , m_testFile(testFile)
+ SymbolSearcherTestCase(const QString &testFile,
+ CppIndexingSupport *indexingSupportToUse,
+ const SymbolSearcher::Parameters &searchParameters,
+ const ResultDataList &expectedResults)
+ : m_indexingSupportToRestore(0)
+ , m_indexingSupportToUse(indexingSupportToUse)
{
+ QVERIFY(succeededSoFar());
+
QVERIFY(m_indexingSupportToUse);
- QVERIFY(parseFiles(m_testFile));
+ QVERIFY(parseFiles(testFile));
m_indexingSupportToRestore = m_modelManager->indexingSupport();
m_modelManager->setIndexingSupport(m_indexingSupportToUse);
- }
- ResultDataList run(const SymbolSearcher::Parameters &searchParameters) const
- {
CppIndexingSupport *indexingSupport = m_modelManager->indexingSupport();
SymbolSearcher *symbolSearcher = indexingSupport->createSymbolSearcher(searchParameters,
- QSet<QString>() << m_testFile);
+ QSet<QString>() << testFile);
QFuture<Find::SearchResultItem> search
= QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher);
search.waitForFinished();
ResultDataList results = ResultData::fromSearchResultList(search.results());
- return results;
+ QCOMPARE(results, expectedResults);
}
~SymbolSearcherTestCase()
{
- m_modelManager->setIndexingSupport(m_indexingSupportToRestore);
+ if (m_indexingSupportToRestore)
+ m_modelManager->setIndexingSupport(m_indexingSupportToRestore);
}
private:
CppIndexingSupport *m_indexingSupportToRestore;
CppIndexingSupport *m_indexingSupportToUse;
- const QString m_testFile;
};
} // anonymous namespace
@@ -148,10 +150,10 @@ void CppToolsPlugin::test_builtinsymbolsearcher()
QFETCH(ResultDataList, expectedResults);
QScopedPointer<CppIndexingSupport> builtinIndexingSupport(new BuiltinIndexingSupport);
-
- SymbolSearcherTestCase test(testFile, builtinIndexingSupport.data());
- const ResultDataList results = test.run(searchParameters);
- QCOMPARE(results, expectedResults);
+ SymbolSearcherTestCase(testFile,
+ builtinIndexingSupport.data(),
+ searchParameters,
+ expectedResults);
}
void CppToolsPlugin::test_builtinsymbolsearcher_data()
diff --git a/src/plugins/cpptools/typehierarchybuilder_test.cpp b/src/plugins/cpptools/typehierarchybuilder_test.cpp
index fc776f824b..1f57596c41 100644
--- a/src/plugins/cpptools/typehierarchybuilder_test.cpp
+++ b/src/plugins/cpptools/typehierarchybuilder_test.cpp
@@ -101,15 +101,12 @@ class TypeHierarchyBuilderTestCase : public CppTools::Tests::TestCase
public:
TypeHierarchyBuilderTestCase(const QList<Tests::TestDocument> &documents,
const QString &expectedHierarchy)
- : m_documents(documents),
- m_expectedHierarchy(expectedHierarchy)
- {}
-
- void run()
{
+ QVERIFY(succeededSoFar());
+
// Write files
QStringList filePaths;
- foreach (const Tests::TestDocument &document, m_documents) {
+ foreach (const Tests::TestDocument &document, documents) {
QVERIFY(document.writeToDisk());
filePaths << document.filePath();
}
@@ -130,12 +127,8 @@ public:
const QString actualHierarchy = toString(hierarchy);
// Uncomment for updating/generating reference data:
// qDebug() << actualHierarchy;
- QCOMPARE(actualHierarchy, m_expectedHierarchy);
+ QCOMPARE(actualHierarchy, expectedHierarchy);
}
-
-private:
- QList<Tests::TestDocument> m_documents;
- QString m_expectedHierarchy;
};
} // anonymous namespace
@@ -192,6 +185,5 @@ void CppToolsPlugin::test_typehierarchy()
QFETCH(QList<Tests::TestDocument>, documents);
QFETCH(QString, expectedHierarchy);
- TypeHierarchyBuilderTestCase testCase(documents, expectedHierarchy);
- testCase.run();
+ TypeHierarchyBuilderTestCase(documents, expectedHierarchy);
}
diff --git a/src/plugins/designer/gotoslot_test.cpp b/src/plugins/designer/gotoslot_test.cpp
index d4cc5e19db..833d69f969 100644
--- a/src/plugins/designer/gotoslot_test.cpp
+++ b/src/plugins/designer/gotoslot_test.cpp
@@ -154,15 +154,12 @@ class GoToSlotTestCase : public CppTools::Tests::TestCase
{
public:
GoToSlotTestCase(const QStringList &files)
- : m_files(files)
{
+ QVERIFY(succeededSoFar());
QCOMPARE(files.size(), 3);
- }
- void run()
- {
QList<TextEditor::BaseTextEditor *> editors;
- foreach (const QString &file, m_files) {
+ foreach (const QString &file, files) {
IEditor *editor = EditorManager::openEditor(file);
TextEditor::BaseTextEditor *e = qobject_cast<TextEditor::BaseTextEditor *>(editor);
QVERIFY(e);
@@ -172,10 +169,10 @@ public:
TextEditor::BaseTextEditor *cppFileEditor = editors.at(0);
TextEditor::BaseTextEditor *hFileEditor = editors.at(1);
- const QString cppFile = m_files.at(0);
- const QString hFile = m_files.at(1);
+ const QString cppFile = files.at(0);
+ const QString hFile = files.at(1);
- QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), m_files.size());
+ QCOMPARE(EditorManager::documentModel()->openedDocuments().size(), files.size());
waitForFilesInGlobalSnapshot(QStringList() << cppFile << hFile);
// Execute "Go To Slot"
@@ -206,9 +203,6 @@ public:
QVERIFY(documentContainsMemberFunctionDeclaration(hDocument,
QLatin1String("Form::on_pushButton_clicked")));
}
-
-private:
- QStringList m_files;
};
} // anonymous namespace
@@ -220,9 +214,7 @@ void Designer::Internal::FormEditorPlugin::test_gotoslot()
{
#if QT_VERSION >= 0x050000
QFETCH(QStringList, files);
-
- GoToSlotTestCase test(files);
- test.run();
+ (GoToSlotTestCase(files));
#else
QSKIP("Available only with >= Qt5", SkipSingle);
#endif