blob: 820f8d2a70ba2d7236675863086be7109a1dbdc1 (
plain)
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
|
// Copyright (C) 2016 Orgad Shaneh <orgads@gmail.com>.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#include "cppheadersource_test.h"
#include "cppeditorplugin.h"
#include "cpptoolsreuse.h"
#include "cpptoolstestcase.h"
#include "cppfilesettingspage.h"
#include <utils/fileutils.h>
#include <utils/temporarydirectory.h>
#include <QDir>
#include <QtTest>
using namespace Utils;
static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
static void createTempFile(const FilePath &filePath)
{
QString fileName = filePath.toString();
QFile file(fileName);
QDir(QFileInfo(fileName).absolutePath()).mkpath(_("."));
file.open(QFile::WriteOnly);
file.close();
}
static QString baseTestDir()
{
return Utils::TemporaryDirectory::masterDirectoryPath() + "/qtc_cppheadersource/";
}
namespace CppEditor::Internal {
void HeaderSourceTest::test()
{
QFETCH(QString, sourceFileName);
QFETCH(QString, headerFileName);
CppEditor::Tests::TemporaryDir temporaryDir;
QVERIFY(temporaryDir.isValid());
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
const FilePath sourcePath = FilePath::fromString(path.absoluteFilePath(sourceFileName));
const FilePath headerPath = FilePath::fromString(path.absoluteFilePath(headerFileName));
createTempFile(sourcePath);
createTempFile(headerPath);
bool wasHeader;
CppEditorPlugin::clearHeaderSourceCache();
QCOMPARE(correspondingHeaderOrSource(sourcePath, &wasHeader), headerPath);
QVERIFY(!wasHeader);
CppEditorPlugin::clearHeaderSourceCache();
QCOMPARE(correspondingHeaderOrSource(headerPath, &wasHeader), sourcePath);
QVERIFY(wasHeader);
}
void HeaderSourceTest::test_data()
{
QTest::addColumn<QString>("sourceFileName");
QTest::addColumn<QString>("headerFileName");
QTest::newRow("samedir") << _("foo.cpp") << _("foo.h");
QTest::newRow("includesub") << _("foo.cpp") << _("include/foo.h");
QTest::newRow("headerprefix") << _("foo.cpp") << _("testh_foo.h");
QTest::newRow("sourceprefixwsub") << _("testc_foo.cpp") << _("include/foo.h");
QTest::newRow("sourceAndHeaderPrefixWithBothsub") << _("src/testc_foo.cpp") << _("include/testh_foo.h");
}
void HeaderSourceTest::initTestCase()
{
QDir(baseTestDir()).mkpath(_("."));
CppFileSettings *fs = CppEditorPlugin::fileSettings();
fs->headerSearchPaths.append(QLatin1String("include"));
fs->headerSearchPaths.append(QLatin1String("../include"));
fs->sourceSearchPaths.append(QLatin1String("src"));
fs->sourceSearchPaths.append(QLatin1String("../src"));
fs->headerPrefixes.append(QLatin1String("testh_"));
fs->sourcePrefixes.append(QLatin1String("testc_"));
}
void HeaderSourceTest::cleanupTestCase()
{
Utils::FilePath::fromString(baseTestDir()).removeRecursively();
CppFileSettings *fs = CppEditorPlugin::fileSettings();
fs->headerSearchPaths.removeLast();
fs->headerSearchPaths.removeLast();
fs->sourceSearchPaths.removeLast();
fs->sourceSearchPaths.removeLast();
fs->headerPrefixes.removeLast();
fs->sourcePrefixes.removeLast();
}
} // namespace CppEditor::Internal
|