Commit 0bd59178 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor/CppTools: Don't continue in test function on failure

QVERIFY/QCOMPARE are meant to be called in the test function so that on
failure they just can "return" and thus skip subsequent code. Since we
use reusable test code in the test functions (the *TestCase classes), we
need to ensure that on failure no further test code is executed.

This mostly inlines the run function of the test classes into the
constructor.

Change-Id: I320ee032bdde0174ddfe3fdf3f9e18e19abf1d7f
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent c7f3ac40
...@@ -62,56 +62,49 @@ typedef QByteArray _; ...@@ -62,56 +62,49 @@ typedef QByteArray _;
class DoxygenTestCase : public CppEditor::Internal::Tests::TestCase class DoxygenTestCase : public CppEditor::Internal::Tests::TestCase
{ {
public: public:
DoxygenTestCase(const QByteArray &input); /// The '|' in the input denotes the cursor position.
void run(const QByteArray &expected); DoxygenTestCase(const QByteArray &original, const QByteArray &expected)
{
private: QVERIFY(succeededSoFar());
CppEditor::Internal::Tests::TestDocument testDocument;
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 } // anonymous namespace
void CppEditorPlugin::test_doxygen_comments_data() void CppEditorPlugin::test_doxygen_comments_data()
...@@ -257,6 +250,5 @@ void CppEditorPlugin::test_doxygen_comments() ...@@ -257,6 +250,5 @@ void CppEditorPlugin::test_doxygen_comments()
{ {
QFETCH(QByteArray, given); QFETCH(QByteArray, given);
QFETCH(QByteArray, expected); QFETCH(QByteArray, expected);
DoxygenTestCase test(given); DoxygenTestCase(given, expected);
test.run(expected);
} }
...@@ -49,8 +49,12 @@ namespace { ...@@ -49,8 +49,12 @@ namespace {
class IncludeHierarchyTestCase: public CppEditor::Internal::Tests::TestCase class IncludeHierarchyTestCase: public CppEditor::Internal::Tests::TestCase
{ {
public: public:
IncludeHierarchyTestCase(const QList<QByteArray> &sourceList) IncludeHierarchyTestCase(const QList<QByteArray> &sourceList,
int includesCount,
int includedByCount)
{ {
QVERIFY(succeededSoFar());
QStringList filePaths; QStringList filePaths;
const int sourceListSize = sourceList.size(); const int sourceListSize = sourceList.size();
for (int i = 0; i < sourceListSize; ++i) { for (int i = 0; i < sourceListSize; ++i) {
...@@ -66,16 +70,14 @@ public: ...@@ -66,16 +70,14 @@ public:
// Update Code Model // Update Code Model
QVERIFY(parseFiles(filePaths)); QVERIFY(parseFiles(filePaths));
}
void run(int includesCount, int includedByCount) // Open Editor
{
const QString fileName = QDir::tempPath() + QLatin1String("/file1.h"); const QString fileName = QDir::tempPath() + QLatin1String("/file1.h");
CPPEditor *editor; CPPEditor *editor;
QVERIFY(openCppEditor(fileName, &editor)); QVERIFY(openCppEditor(fileName, &editor));
closeEditorAtEndOfTestCase(editor); closeEditorAtEndOfTestCase(editor);
// Test model
CppIncludeHierarchyModel model(0); CppIncludeHierarchyModel model(0);
model.buildHierarchy(editor, fileName); model.buildHierarchy(editor, fileName);
QCOMPARE(model.rowCount(model.index(0, 0)), includesCount); QCOMPARE(model.rowCount(model.index(0, 0)), includesCount);
...@@ -91,8 +93,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludes() ...@@ -91,8 +93,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludes()
sourceList.append(QByteArray("#include \"file2.h\"\n")); sourceList.append(QByteArray("#include \"file2.h\"\n"));
sourceList.append(QByteArray()); sourceList.append(QByteArray());
IncludeHierarchyTestCase testCase(sourceList); IncludeHierarchyTestCase(sourceList, 1, 0);
testCase.run(1, 0);
} }
void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy() void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy()
...@@ -101,8 +102,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy() ...@@ -101,8 +102,7 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludedBy()
sourceList.append(QByteArray()); sourceList.append(QByteArray());
sourceList.append(QByteArray("#include \"file1.h\"\n")); sourceList.append(QByteArray("#include \"file1.h\"\n"));
IncludeHierarchyTestCase testCase(sourceList); IncludeHierarchyTestCase(sourceList, 0, 1);
testCase.run(0, 1);
} }
void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy() void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy()
...@@ -112,6 +112,5 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy() ...@@ -112,6 +112,5 @@ void CppEditorPlugin::test_includeHierarchyModel_simpleIncludesAndIncludedBy()
sourceList.append(QByteArray()); sourceList.append(QByteArray());
sourceList.append(QByteArray("#include \"file1.h\"\n")); sourceList.append(QByteArray("#include \"file1.h\"\n"));
IncludeHierarchyTestCase testCase(sourceList); IncludeHierarchyTestCase(sourceList, 1, 1);
testCase.run(1, 1);
} }
This diff is collapsed.
...@@ -97,12 +97,10 @@ public: ...@@ -97,12 +97,10 @@ public:
typedef QList<ActionPointer> Actions; typedef QList<ActionPointer> Actions;
public: public:
TestActionsTestCase();
/// Run the given fileActions for each file and the given tokenActions for each token. /// 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. /// The cursor is positioned on the very first character of each token.
void run(const Actions &tokenActions = Actions(), TestActionsTestCase(const Actions &tokenActions = Actions(),
const Actions &fileActions = Actions()); const Actions &fileActions = Actions());
/// Simulate pressing ESC, which will close popups, search results pane, etc... /// Simulate pressing ESC, which will close popups, search results pane, etc...
/// This works only if the Qt Creator window is active. /// This works only if the Qt Creator window is active.
...@@ -136,13 +134,16 @@ bool TestActionsTestCase::allProjectsConfigured = false; ...@@ -136,13 +134,16 @@ bool TestActionsTestCase::allProjectsConfigured = false;
typedef TestActionsTestCase::Actions Actions; typedef TestActionsTestCase::Actions Actions;
typedef TestActionsTestCase::ActionPointer ActionPointer; typedef TestActionsTestCase::ActionPointer ActionPointer;
TestActionsTestCase::TestActionsTestCase() Actions singleAction(const ActionPointer &action)
: CppEditor::Internal::Tests::TestCase(/*runGarbageCollector=*/false)
{ {
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 // Collect files to process
QStringList filesToOpen; QStringList filesToOpen;
QList<QPointer<ProjectExplorer::Project> > projects; QList<QPointer<ProjectExplorer::Project> > projects;
...@@ -516,88 +517,51 @@ void SwitchHeaderSourceFileAction::run(CPPEditorWidget *) ...@@ -516,88 +517,51 @@ void SwitchHeaderSourceFileAction::run(CPPEditorWidget *)
void CppEditorPlugin::test_openEachFile() void CppEditorPlugin::test_openEachFile()
{ {
TestActionsTestCase test; TestActionsTestCase();
test.run();
} }
void CppEditorPlugin::test_switchHeaderSourceOnEachFile() void CppEditorPlugin::test_switchHeaderSourceOnEachFile()
{ {
Actions fileActions; TestActionsTestCase(Actions(), singleAction(ActionPointer(new SwitchHeaderSourceFileAction)));
fileActions << ActionPointer(new SwitchHeaderSourceFileAction);
TestActionsTestCase test;
test.run(Actions(), fileActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFile() void CppEditorPlugin::test_moveTokenWiseThroughEveryFile()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new NoOpTokenAction)));
tokenActions << ActionPointer(new NoOpTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
/// May block if file does not exists (e.g. a not generated ui_* file). /// May block if file does not exists (e.g. a not generated ui_* file).
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFollowSymbol() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFollowSymbol()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new FollowSymbolUnderCursorTokenAction)));
tokenActions << ActionPointer(new FollowSymbolUnderCursorTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndSwitchDeclarationDefinition() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndSwitchDeclarationDefinition()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new SwitchDeclarationDefinitionTokenAction)));
tokenActions << ActionPointer(new SwitchDeclarationDefinitionTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFindUsages() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndFindUsages()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new FindUsagesTokenAction)));
tokenActions << ActionPointer(new FindUsagesTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndRenameUsages() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndRenameUsages()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new RenameSymbolUnderCursorTokenAction)));
tokenActions << ActionPointer(new RenameSymbolUnderCursorTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndOpenTypeHierarchy() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndOpenTypeHierarchy()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new OpenTypeHierarchyTokenAction)));
tokenActions << ActionPointer(new OpenTypeHierarchyTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndInvokeCompletion() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndInvokeCompletion()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new InvokeCompletionTokenAction)));
tokenActions << ActionPointer(new InvokeCompletionTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndTriggerQuickFixes() void CppEditorPlugin::test_moveTokenWiseThroughEveryFileAndTriggerQuickFixes()
{ {
Actions tokenActions; TestActionsTestCase(singleAction(ActionPointer(new RunAllQuickFixesTokenAction)));
tokenActions << ActionPointer(new RunAllQuickFixesTokenAction());
TestActionsTestCase test;
test.run(tokenActions);
} }
...@@ -63,6 +63,9 @@ public: ...@@ -63,6 +63,9 @@ public:
CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray()) CompletionTestCase(const QByteArray &sourceText, const QByteArray &textToInsert = QByteArray())
: m_position(-1), m_editorWidget(0), m_textDocument(0), m_editor(0) : m_position(-1), m_editorWidget(0), m_textDocument(0), m_editor(0)
{ {
QVERIFY(succeededSoFar());
m_succeededSoFar = false;
m_source = sourceText; m_source = sourceText;
m_position = m_source.indexOf('@'); m_position = m_source.indexOf('@');
QVERIFY(m_position != -1); QVERIFY(m_position != -1);
...@@ -89,6 +92,8 @@ public: ...@@ -89,6 +92,8 @@ public:
if (!textToInsert.isEmpty()) if (!textToInsert.isEmpty())
insertText(textToInsert); insertText(textToInsert);
m_succeededSoFar = true;
} }
QStringList getCompletions(bool *replaceAccessOperator = 0) const QStringList getCompletions(bool *replaceAccessOperator = 0) const
...@@ -162,6 +167,7 @@ void CppToolsPlugin::test_completion_basic_1() ...@@ -162,6 +167,7 @@ void CppToolsPlugin::test_completion_basic_1()
" @\n" " @\n"
"}"; "}";
CompletionTestCase test(source); CompletionTestCase test(source);
QVERIFY(test.succeededSoFar());
QStringList basicCompletions = test.getCompletions(); QStringList basicCompletions = test.getCompletions();
QVERIFY(!basicCompletions.contains(QLatin1String("foo"))); QVERIFY(!basicCompletions.contains(QLatin1String("foo")));
...@@ -189,6 +195,7 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_8737() ...@@ -189,6 +195,7 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_8737()
"}\n" "}\n"
; ;
CompletionTestCase test(source, "a_c"); CompletionTestCase test(source, "a_c");
QVERIFY(test.succeededSoFar());
QStringList completions = test.getCompletions(); QStringList completions = test.getCompletions();
...@@ -214,9 +221,9 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_9236() ...@@ -214,9 +221,9 @@ void CppToolsPlugin::test_completion_prefix_first_QTCREATORBUG_9236()
"};\n" "};\n"
; ;
CompletionTestCase test(source, "ret"); CompletionTestCase test(source, "ret");
QVERIFY(test.succeededSoFar());
QStringList completions = test.getCompletions(); QStringList completions = test.getCompletions();
QVERIFY(completions.size() >= 2); QVERIFY(completions.size() >= 2);
QCOMPARE(completions.at(0), QLatin1String("return")); QCOMPARE(completions.at(0), QLatin1String("return"));
QCOMPARE(completions.at(1), QLatin1String("rETUCASE")); QCOMPARE(completions.at(1), QLatin1String("rETUCASE"));
...@@ -233,9 +240,9 @@ void CppToolsPlugin::test_completion_template_function() ...@@ -233,9 +240,9 @@ void CppToolsPlugin::test_completion_template_function()
QFETCH(QStringList, expectedCompletions); QFETCH(QStringList, expectedCompletions);
CompletionTestCase test(code); CompletionTestCase test(code);
QVERIFY(test.succeededSoFar());
QStringList actualCompletions = test.getCompletions(); QStringList actualCompletions = test.getCompletions();
QString errorPattern(QLatin1String("Completion not found: %1")); QString errorPattern(QLatin1String("Completion not found: %1"));
foreach (const QString &completion, expectedCompletions) { foreach (const QString &completion, expectedCompletions) {
QByteArray errorMessage = errorPattern.arg(completion).toUtf8(); QByteArray errorMessage = errorPattern.arg(completion).toUtf8();
...@@ -290,6 +297,7 @@ void CppToolsPlugin::test_completion() ...@@ -290,6 +297,7 @@ void CppToolsPlugin::test_completion()
QFETCH(QStringList, expectedCompletions); QFETCH(QStringList, expectedCompletions);
CompletionTestCase test(code, prefix); CompletionTestCase test(code, prefix);
QVERIFY(test.succeededSoFar());
QStringList actualCompletions = test.getCompletions(); QStringList actualCompletions = test.getCompletions();
actualCompletions.sort(); actualCompletions.sort();
...@@ -2092,6 +2100,7 @@ void CppToolsPlugin::test_completion_member_access_operator() ...@@ -2092,6 +2100,7 @@ void CppToolsPlugin::test_completion_member_access_operator()
QFETCH(bool, expectedReplaceAccessOperator); QFETCH(bool, expectedReplaceAccessOperator);
CompletionTestCase test(code, prefix); CompletionTestCase test(code, prefix);
QVERIFY(test.succeededSoFar());
bool replaceAccessOperator = false; bool replaceAccessOperator = false;
QStringList completions = test.getCompletions(&replaceAccessOperator); QStringList completions = test.getCompletions(&replaceAccessOperator);
......
...@@ -67,12 +67,21 @@ class CppLocatorFilterTestCase ...@@ -67,12 +67,21 @@ class CppLocatorFilterTestCase
, public CppTools::Tests::TestCase , public CppTools::Tests::TestCase
{ {
public: public:
CppLocatorFilterTestCase(ILocatorFilter *filter, const QString &fileName) CppLocatorFilterTestCase(ILocatorFilter *filter,
const QString &fileName,
const QString &searchText,
const ResultDataList &expectedResults)
: BasicLocatorFilterTest(filter) : BasicLocatorFilterTest(filter)
, m_fileName(fileName) , m_fileName(fileName)
{ {
QVERIFY(succeededSoFar());
QVERIFY(!m_fileName.isEmpty()); QVERIFY(!m_fileName.isEmpty());
QVERIFY(garbageCollectGlobalSnapshot()); QVERIFY(garbageCollectGlobalSnapshot());
ResultDataList results = ResultData::fromFilterEntryList(matchesFor(searchText));
// ResultData::printFilterEntries(results);
QVERIFY(!results.isEmpty());
QCOMPARE(results, expectedResults);
} }
private: private:
...@@ -88,12 +97,19 @@ class CppCurrentDocumentFilterTestCase ...@@ -88,12 +97,19 @@ class CppCurrentDocumentFilterTestCase
, public CppTools::Tests::TestCase , public CppTools::Tests::TestCase
{ {
public: public:
CppCurrentDocumentFilterTestCase(const QString &fileName) CppCurrentDocumentFilterTestCase(const QString &fileName,
const ResultDataList &expectedResults)
: BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>()) : BasicLocatorFilterTest(PluginManager::getObject<CppCurrentDocumentFilter>())
, m_editor(0) , m_editor(0)
, m_fileName(fileName) , m_fileName(fileName)
{ {
QVERIFY(succeededSoFar());
QVERIFY(!m_fileName.isEmpty()); QVERIFY(!m_fileName.isEmpty());
ResultDataList results = ResultData::fromFilterEntryList(matchesFor());
// ResultData::printFilterEntries(results);
QVERIFY(!results.isEmpty());
QCOMPARE(results, expectedResults);
} }
private: private:
...@@ -130,11 +146,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter() ...@@ -130,11 +146,7 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter()
QFETCH(QString, searchText); QFETCH(QString, searchText);
QFETCH(ResultDataList, expectedResults); QFETCH(ResultDataList, expectedResults);
CppLocatorFilterTestCase test(filter, testFile); CppLocatorFilterTestCase(filter, testFile, searchText, expectedResults);
ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor(searchText));
// ResultData::printFilterEntries(results);
QVERIFY(!results.isEmpty());
QCOMPARE(results, expectedResults);
} }
void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data() void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
...@@ -277,9 +289,5 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter() ...@@ -277,9 +289,5 @@ void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
<< ResultData(_("main()"), _("")) << ResultData(_("main()"), _(""))
; ;
CppCurrentDocumentFilterTestCase test(testFile); CppCurrentDocumentFilterTestCase(testFile, expectedResults);
ResultDataList results = ResultData::fromFilterEntryList(test.matchesFor());
// ResultData::printFilterEntries(results);
QVERIFY(!results.isEmpty());
QCOMPARE(expectedResults, results);
} }
...@@ -70,8 +70,13 @@ QString stripCursor(const QString &source) ...@@ -70,8 +70,13 @@ QString stripCursor(const QString &source)
class PointerDeclarationFormatterTestCase : public CppTools::Tests::TestCase class PointerDeclarationFormatterTestCase : public CppTools::Tests::TestCase
{ {
public: 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 '@' // Find cursor position and remove cursor marker '@'
int cursorPosition = 0; int cursorPosition = 0;
QString sourceWithoutCursorMarker = QLatin1String(source); QString sourceWithoutCursorMarker = QLatin1String(source);
...@@ -83,58 +88,53 @@ public: ...@@ -83,58 +88,53 @@ public:
// Write source to temprorary file // Write source to temprorary file
const QString filePath = QDir::tempPath() + QLatin1String("/file.h"); const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
m_document = Document::create(filePath); Document::Ptr document = Document::create(filePath);
QVERIFY(writeFile(m_document->fileName(), sourceWithoutCursorMarker.toLatin1())); QVERIFY(writeFile(document->fileName(), sourceWithoutCursorMarker.toLatin1()));
// Preprocess source // Preprocess source
Preprocessor preprocess(0, &m_env);