Commit 409fecd3 authored by Marco Bubke's avatar Marco Bubke

UnitTests: Cleanup SupportiveTranslationUnitInitializer test

Change-Id: I0c43baeb13fe2a1004622267deb4e588f941d254
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 872f3ee9
......@@ -310,4 +310,9 @@ JobRequests &JobQueue::queue()
return m_queue;
}
const JobRequests &JobQueue::queue() const
{
return m_queue;
}
} // namespace ClangBackEnd
......@@ -56,6 +56,7 @@ public:
public: // for tests
JobRequests &queue();
const JobRequests &queue() const;
int size() const;
void prioritizeRequests();
......
......@@ -179,6 +179,11 @@ JobRequests &Jobs::queue()
return m_queue.queue();
}
const JobRequests &Jobs::queue() const
{
return m_queue.queue();
}
bool Jobs::isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const
{
const auto hasTranslationUnitId = [translationUnitId](const RunningJob &runningJob) {
......
......@@ -76,6 +76,7 @@ public:
public /*for tests*/:
QList<RunningJob> runningJobs() const;
JobRequests &queue();
const JobRequests &queue() const;
bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const;
bool isJobRunningForJobRequest(const JobRequest &jobRequest) const;
......
......@@ -27,6 +27,7 @@
#include "dummyclangipcclient.h"
#include "processevents-utilities.h"
#include "runprojectcreateorupdate-utility.h"
#include <clangbackend_global.h>
#include <clangdocuments.h>
......@@ -47,43 +48,10 @@ using testing::Eq;
namespace {
class Data {
public:
Data()
{
projects.createOrUpdate({ProjectPartContainer(projectPartId)});
const QVector<FileContainer> fileContainer{FileContainer(filePath, projectPartId)};
document = documents.create(fileContainer).front();
documents.setVisibleInEditors({filePath});
documents.setUsedByCurrentEditor(filePath);
const auto isDocumentClosed = [this](const Utf8String &filePath,
const Utf8String &projectPartId) {
return !documents.hasDocument(filePath, projectPartId);
};
initializer.reset(new ClangBackEnd::SupportiveTranslationUnitInitializer{document, jobs});
initializer->setIsDocumentClosedChecker(isDocumentClosed);
}
public:
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp")};
Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")};
ProjectParts projects;
UnsavedFiles unsavedFiles;
Documents documents{projects, unsavedFiles};
Document document;
DummyIpcClient dummyClientInterface;
Jobs jobs{documents, unsavedFiles, projects, dummyClientInterface};
std::unique_ptr<ClangBackEnd::SupportiveTranslationUnitInitializer> initializer;
};
class SupportiveTranslationUnitInitializer : public ::testing::Test
{
protected:
void SetUp() override;
void parse();
Jobs::RunningJob createRunningJob(JobRequest::Type type) const;
......@@ -93,16 +61,20 @@ protected:
bool waitUntilJobChainFinished(int timeOutInMs = 10000) const;
protected:
Data d;
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp")};
Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")};
ProjectParts projects;
UnitTest::RunProjectCreateOrUpdate _1{projects, {ProjectPartContainer(projectPartId)}};
UnsavedFiles unsavedFiles;
const QVector<FileContainer> fileContainer{FileContainer(filePath, projectPartId)};
Documents documents{projects, unsavedFiles};
Document document{documents.create(fileContainer).front()};
DummyIpcClient dummyClientInterface;
Utf8String &filePath = d.filePath;
Utf8String &projectPartId = d.projectPartId;
Jobs jobs{documents, unsavedFiles, projects, dummyClientInterface};
ProjectParts projects = d.projects;
Document &document = d.document;
Documents &documents = d.documents;
Jobs &jobs = d.jobs;
ClangBackEnd::SupportiveTranslationUnitInitializer &initializer = *d.initializer;
ClangBackEnd::SupportiveTranslationUnitInitializer initializer{document, jobs};
};
using SupportiveTranslationUnitInitializerSlowTest = SupportiveTranslationUnitInitializer;
......@@ -199,6 +171,18 @@ TEST_F(SupportiveTranslationUnitInitializerSlowTest, FullRun)
ASSERT_THAT(initializer.state(), Eq(ClangBackEnd::SupportiveTranslationUnitInitializer::State::Initialized));
}
void SupportiveTranslationUnitInitializer::SetUp()
{
documents.setVisibleInEditors({filePath});
documents.setUsedByCurrentEditor(filePath);
const auto isDocumentClosed = [this](const Utf8String &filePath,
const Utf8String &projectPartId) {
return !documents.hasDocument(filePath, projectPartId);
};
initializer.setIsDocumentClosedChecker(isDocumentClosed);
}
void SupportiveTranslationUnitInitializer::parse()
{
projects.createOrUpdate({ProjectPartContainer{projectPartId, Utf8StringVector()}});
......
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <projects.h>
namespace UnitTest {
struct RunProjectCreateOrUpdate
{
RunProjectCreateOrUpdate(ClangBackEnd::ProjectParts &projects,
const QVector<ClangBackEnd::ProjectPartContainer> &projectContainers)
{
projects.createOrUpdate(projectContainers);
}
};
} // namespace UnitTest
......@@ -219,8 +219,8 @@ HEADERS += \
mockfilepathcaching.h \
mocksqlitestatement.h \
unittest-utility-functions.h \
mocksymbolquery.h
mocksymbolquery.h \
runprojectcreateorupdate-utility.h
!isEmpty(LIBCLANG_LIBS) {
HEADERS += \
chunksreportedmonitor.h \
......
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