1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "../cpptoolstestcase.h"
#include "../cppcodestylesettings.h"
#include "cppquickfixsettings.h"
#include <projectexplorer/headerpath.h>
#include <QByteArray>
#include <QHash>
#include <QList>
#include <QObject>
#include <QSharedPointer>
#include <QStringList>
#include <QVariantMap>
#include <memory>
namespace TextEditor { class QuickFixOperation; }
namespace CppEditor {
class CppQuickFixFactory;
namespace Internal {
namespace Tests {
class QuickFixSettings
{
const CppQuickFixSettings original = *CppQuickFixSettings::instance();
public:
CppQuickFixSettings *operator->() { return CppQuickFixSettings::instance(); }
~QuickFixSettings() { *CppQuickFixSettings::instance() = original; }
};
class BaseQuickFixTestCase : public CppEditor::Tests::TestCase
{
public:
/// Exactly one QuickFixTestDocument must contain the cursor position marker '@'
/// or "@{start}" and "@{end}"
BaseQuickFixTestCase(const QList<TestDocumentPtr> &testDocuments,
const ProjectExplorer::HeaderPaths &headerPaths,
const QByteArray &clangFormatSettings = {});
~BaseQuickFixTestCase();
protected:
TestDocumentPtr m_documentWithMarker;
QList<TestDocumentPtr> m_testDocuments;
private:
QScopedPointer<CppEditor::Tests::TemporaryDir> m_temporaryDirectory;
CppCodeStylePreferences *m_cppCodeStylePreferences;
QByteArray m_cppCodeStylePreferencesOriginalDelegateId;
ProjectExplorer::HeaderPaths m_headerPathsToRestore;
bool m_restoreHeaderPaths;
};
/// Tests the offered operations provided by a given CppQuickFixFactory
class QuickFixOfferedOperationsTest : public BaseQuickFixTestCase
{
public:
QuickFixOfferedOperationsTest(const QList<TestDocumentPtr> &testDocuments,
CppQuickFixFactory *factory,
const ProjectExplorer::HeaderPaths &headerPaths = {},
const QStringList &expectedOperations = {});
};
/// Tests a concrete QuickFixOperation of a given CppQuickFixFactory
class QuickFixOperationTest : public BaseQuickFixTestCase
{
public:
QuickFixOperationTest(const QList<TestDocumentPtr> &testDocuments,
CppQuickFixFactory *factory,
const ProjectExplorer::HeaderPaths &headerPaths
= ProjectExplorer::HeaderPaths(),
int operationIndex = 0,
const QByteArray &expectedFailMessage = {},
const QByteArray &clangFormatSettings = {});
static void run(const QList<TestDocumentPtr> &testDocuments,
CppQuickFixFactory *factory,
const Utils::FilePath &headerPath,
int operationIndex = 0);
};
class CppQuickFixTestObject : public QObject
{
Q_OBJECT
public:
CppQuickFixTestObject(std::unique_ptr<CppQuickFixFactory> &&factory);
~CppQuickFixTestObject();
private slots:
void initTestCase();
void cleanupTestCase();
void test_data();
void test();
private:
const std::unique_ptr<CppQuickFixFactory> m_factory;
class TestData
{
public:
QByteArray tag;
QHash<QString, std::pair<QByteArray, QByteArray>> files;
QByteArray failMessage;
QVariantMap properties;
int opIndex = 0;
};
QList<TestData> m_testData;
};
QList<TestDocumentPtr> singleDocument(
const QByteArray &original, const QByteArray &expected, const QByteArray fileName = "file.cpp");
} // namespace Tests
} // namespace Internal
} // namespace CppEditor
|