aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangcodemodel/test
diff options
context:
space:
mode:
authorhjk <[email protected]>2023-01-12 15:30:01 +0100
committerhjk <[email protected]>2023-01-13 10:46:13 +0000
commit33cdb052ba865287c26108d9b126ab43f57a8631 (patch)
tree0c9babb1344f4a55d90e5f2a9efb9d07636097a8 /src/plugins/clangcodemodel/test
parent2ce413112b00fb29c979f1ebfaf55c690330ebda (diff)
FilePathify some testing code
Change-Id: I3739a6eb3c2172078e9519e8186daf94ec74d99a Reviewed-by: Alessandro Portale <[email protected]>
Diffstat (limited to 'src/plugins/clangcodemodel/test')
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp14
-rw-r--r--src/plugins/clangcodemodel/test/clangfixittest.cpp15
-rw-r--r--src/plugins/clangcodemodel/test/clangfixittest.h2
3 files changed, 14 insertions, 17 deletions
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index 4636b6cd26a..affeb8db5f1 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -64,9 +64,9 @@ namespace Tests {
const Usage::Tags Initialization{Usage::Tag::Declaration, Usage::Tag::Write};
-static QString qrcPath(const QByteArray &relativeFilePath)
+static QString qrcPath(const QString &relativeFilePath)
{
- return QLatin1String(":/unittests/ClangCodeModel/") + QString::fromUtf8(relativeFilePath);
+ return ":/unittests/ClangCodeModel/" + relativeFilePath;
}
ClangdTest::~ClangdTest()
@@ -79,7 +79,7 @@ ClangdTest::~ClangdTest()
Utils::FilePath ClangdTest::filePath(const QString &fileName) const
{
- return Utils::FilePath::fromString(m_projectDir->absolutePath(fileName.toLocal8Bit()));
+ return m_projectDir->absolutePath(fileName);
}
void ClangdTest::waitForNewClient(bool withIndex)
@@ -133,11 +133,10 @@ void ClangdTest::initTestCase()
QSKIP("The test requires at least one valid kit with a valid Qt");
// Copy project out of qrc file, open it, and set up target.
- m_projectDir = new TemporaryCopiedDir(qrcPath(QFileInfo(m_projectFileName)
- .baseName().toLocal8Bit()));
+ m_projectDir = new TemporaryCopiedDir(qrcPath(QFileInfo(m_projectFileName).baseName()));
QVERIFY(m_projectDir->isValid());
const auto openProjectResult = ProjectExplorerPlugin::openProject(
- Utils::FilePath::fromString(m_projectDir->absolutePath(m_projectFileName.toUtf8())));
+ m_projectDir->absolutePath(m_projectFileName));
QVERIFY2(openProjectResult, qPrintable(openProjectResult.errorMessage()));
m_project = openProjectResult.project();
m_project->configureAsExampleProject(m_kit);
@@ -147,8 +146,7 @@ void ClangdTest::initTestCase()
// Open cpp documents.
for (const QString &sourceFileName : std::as_const(m_sourceFileNames)) {
- const auto sourceFilePath = Utils::FilePath::fromString(
- m_projectDir->absolutePath(sourceFileName.toLocal8Bit()));
+ const auto sourceFilePath = m_projectDir->absolutePath(sourceFileName);
QVERIFY2(sourceFilePath.exists(), qPrintable(sourceFilePath.toUserOutput()));
IEditor * const editor = EditorManager::openEditor(sourceFilePath);
QVERIFY(editor);
diff --git a/src/plugins/clangcodemodel/test/clangfixittest.cpp b/src/plugins/clangcodemodel/test/clangfixittest.cpp
index 7cb58151d87..c41b9613b4d 100644
--- a/src/plugins/clangcodemodel/test/clangfixittest.cpp
+++ b/src/plugins/clangcodemodel/test/clangfixittest.cpp
@@ -29,21 +29,20 @@ void ClangFixItTest::testDescription()
Utils::FilePath ClangFixItTest::semicolonFilePath() const
{
- return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp"));
+ return m_dataDir->absolutePath("diagnostic_semicolon_fixit.cpp");
}
Utils::FilePath ClangFixItTest::compareFilePath() const
{
- return Utils::FilePath::fromString(m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp"));
+ return m_dataDir->absolutePath("diagnostic_comparison_fixit.cpp");
}
-QString ClangFixItTest::fileContent(const QByteArray &relFilePath) const
+QString ClangFixItTest::fileContent(const QString &relFilePath) const
{
- QFile file(m_dataDir->absolutePath(relFilePath));
- const bool isOpen = file.open(QFile::ReadOnly | QFile::Text);
- if (!isOpen)
- qDebug() << "File with the unsaved content cannot be opened!";
- return QString::fromUtf8(file.readAll());
+ Utils::expected_str<QByteArray> data = m_dataDir->absolutePath(relFilePath).fileContents();
+ if (!data)
+ qDebug() << "File with the unsaved content cannot be opened!" << data.error();
+ return QString::fromUtf8(*data);
}
ClangFixIt ClangFixItTest::semicolonFixIt() const
diff --git a/src/plugins/clangcodemodel/test/clangfixittest.h b/src/plugins/clangcodemodel/test/clangfixittest.h
index 8f7c0de96e8..28cff4e0fe9 100644
--- a/src/plugins/clangcodemodel/test/clangfixittest.h
+++ b/src/plugins/clangcodemodel/test/clangfixittest.h
@@ -30,7 +30,7 @@ private slots:
private:
Utils::FilePath semicolonFilePath() const;
Utils::FilePath compareFilePath() const;
- QString fileContent(const QByteArray &relFilePath) const;
+ QString fileContent(const QString &relFilePath) const;
ClangFixIt semicolonFixIt() const;