Commit c58b0293 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

CppEditor: Tests: Refactor out BaseQuickFixTestCase



We will add another type of test case that allows us to test the list of
offered operations.

Change-Id: I528b3844181c139c8955091ac0bbcf6475fd8a4f
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 315fb037
......@@ -1637,7 +1637,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods()
InsertVirtualMethods factory(
new Tests::InsertVirtualMethodsDialogTest(implementationMode, insertVirtualKeyword));
Tests::QuickFixTestCase(Tests::singleDocument(original, expected), &factory);
Tests::QuickFixOperationTest(Tests::singleDocument(original, expected), &factory);
}
/// Check: Insert in implementation file
......@@ -1683,7 +1683,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_implementationFile()
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
Tests::QuickFixTestCase(testFiles, &factory);
Tests::QuickFixOperationTest(testFiles, &factory);
}
/// Check: Qualified names.
......@@ -1735,7 +1735,7 @@ void CppEditorPlugin::test_quickfix_InsertVirtualMethods_BaseClassInNamespace()
InsertVirtualMethods factory(new Tests::InsertVirtualMethodsDialogTest(
InsertVirtualMethodsDialog::ModeImplementationFile, true));
Tests::QuickFixTestCase(testFiles, &factory);
Tests::QuickFixOperationTest(testFiles, &factory);
}
#endif // WITH_TESTS
......
This diff is collapsed.
......@@ -44,13 +44,14 @@ namespace CppEditor {
namespace Internal {
namespace Tests {
/**
* Represents a test document before and after applying the quick fix.
*
* A TestDocument's source may contain an '@' character to denote
* the cursor position. This marker is removed before the Editor reads
* the document.
*/
///
/// Represents a test document before and after applying the quick fix.
///
/// A TestDocument's source may contain an '@' character to denote
/// the cursor position. This marker is removed before the Editor reads
/// the document.
///
class QuickFixTestDocument : public TestDocument
{
public:
......@@ -60,37 +61,27 @@ public:
const QByteArray &expectedSource);
static Ptr create(const QByteArray &fileName, const QByteArray &source,
const QByteArray &expectedSource);
const QByteArray &expectedSource);
public:
QString m_expectedSource;
};
/**
* Encapsulates the whole process of setting up an editor, getting the
* quick-fix, applying it, and checking the result.
*/
class QuickFixTestCase : public TestCase
class BaseQuickFixTestCase : public TestCase
{
public:
QuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
CppQuickFixFactory *factory,
const CppTools::ProjectPart::HeaderPaths &includePaths =
CppTools::ProjectPart::HeaderPaths(),
int resultIndex = 0,
const QByteArray &expectedFailMessage = QByteArray());
~QuickFixTestCase();
static void run(const QList<QuickFixTestDocument::Ptr> &theTestFiles,
CppQuickFixFactory *factory, const QString &incPath, int resultIndex = 0);
private:
QSharedPointer<TextEditor::QuickFixOperation> getFix(CppQuickFixFactory *factory,
CppEditorWidget *editorWidget,
int resultIndex = 0);
/// Exactly one QuickFixTestDocument must contain the cursor position marker '@'.
BaseQuickFixTestCase(const QList<QuickFixTestDocument::Ptr> &testDocuments,
const CppTools::ProjectPart::HeaderPaths &headerPaths
= CppTools::ProjectPart::HeaderPaths());
private:
QList<QuickFixTestDocument::Ptr> m_testFiles;
~BaseQuickFixTestCase();
protected:
QuickFixTestDocument::Ptr m_documentWithMarker;
QList<QuickFixTestDocument::Ptr> m_testDocuments;
private:
CppTools::CppCodeStylePreferences *m_cppCodeStylePreferences;
QByteArray m_cppCodeStylePreferencesOriginalDelegateId;
......@@ -98,6 +89,23 @@ private:
bool m_restoreHeaderPaths;
};
/// Tests a concrete QuickFixOperation of a given CppQuickFixFactory
class QuickFixOperationTest : public BaseQuickFixTestCase
{
public:
QuickFixOperationTest(const QList<QuickFixTestDocument::Ptr> &testDocuments,
CppQuickFixFactory *factory,
const CppTools::ProjectPart::HeaderPaths &headerPaths
= CppTools::ProjectPart::HeaderPaths(),
int operationIndex = 0,
const QByteArray &expectedFailMessage = QByteArray());
static void run(const QList<QuickFixTestDocument::Ptr> &testDocuments,
CppQuickFixFactory *factory,
const QString &headerPath,
int operationIndex = 0);
};
QList<QuickFixTestDocument::Ptr> singleDocument(const QByteArray &original,
const QByteArray &expected);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment