forked from qt-creator/qt-creator
UnitTests: Cleanup SupportiveTranslationUnitInitializer test
Change-Id: I0c43baeb13fe2a1004622267deb4e588f941d254 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -310,4 +310,9 @@ JobRequests &JobQueue::queue()
|
|||||||
return m_queue;
|
return m_queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const JobRequests &JobQueue::queue() const
|
||||||
|
{
|
||||||
|
return m_queue;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
|
|
||||||
public: // for tests
|
public: // for tests
|
||||||
JobRequests &queue();
|
JobRequests &queue();
|
||||||
|
const JobRequests &queue() const;
|
||||||
int size() const;
|
int size() const;
|
||||||
void prioritizeRequests();
|
void prioritizeRequests();
|
||||||
|
|
||||||
|
|||||||
@@ -179,6 +179,11 @@ JobRequests &Jobs::queue()
|
|||||||
return m_queue.queue();
|
return m_queue.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const JobRequests &Jobs::queue() const
|
||||||
|
{
|
||||||
|
return m_queue.queue();
|
||||||
|
}
|
||||||
|
|
||||||
bool Jobs::isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const
|
bool Jobs::isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const
|
||||||
{
|
{
|
||||||
const auto hasTranslationUnitId = [translationUnitId](const RunningJob &runningJob) {
|
const auto hasTranslationUnitId = [translationUnitId](const RunningJob &runningJob) {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public:
|
|||||||
public /*for tests*/:
|
public /*for tests*/:
|
||||||
QList<RunningJob> runningJobs() const;
|
QList<RunningJob> runningJobs() const;
|
||||||
JobRequests &queue();
|
JobRequests &queue();
|
||||||
|
const JobRequests &queue() const;
|
||||||
bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const;
|
bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const;
|
||||||
bool isJobRunningForJobRequest(const JobRequest &jobRequest) const;
|
bool isJobRunningForJobRequest(const JobRequest &jobRequest) const;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "dummyclangipcclient.h"
|
#include "dummyclangipcclient.h"
|
||||||
#include "processevents-utilities.h"
|
#include "processevents-utilities.h"
|
||||||
|
#include "runprojectcreateorupdate-utility.h"
|
||||||
|
|
||||||
#include <clangbackend_global.h>
|
#include <clangbackend_global.h>
|
||||||
#include <clangdocuments.h>
|
#include <clangdocuments.h>
|
||||||
@@ -47,43 +48,10 @@ using testing::Eq;
|
|||||||
|
|
||||||
namespace {
|
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
|
class SupportiveTranslationUnitInitializer : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
void SetUp() override;
|
||||||
void parse();
|
void parse();
|
||||||
Jobs::RunningJob createRunningJob(JobRequest::Type type) const;
|
Jobs::RunningJob createRunningJob(JobRequest::Type type) const;
|
||||||
|
|
||||||
@@ -93,16 +61,20 @@ protected:
|
|||||||
bool waitUntilJobChainFinished(int timeOutInMs = 10000) const;
|
bool waitUntilJobChainFinished(int timeOutInMs = 10000) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Data d;
|
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp")};
|
||||||
|
Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")};
|
||||||
|
|
||||||
Utf8String &filePath = d.filePath;
|
ProjectParts projects;
|
||||||
Utf8String &projectPartId = d.projectPartId;
|
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;
|
||||||
|
|
||||||
ProjectParts projects = d.projects;
|
Jobs jobs{documents, unsavedFiles, projects, dummyClientInterface};
|
||||||
Document &document = d.document;
|
|
||||||
Documents &documents = d.documents;
|
ClangBackEnd::SupportiveTranslationUnitInitializer initializer{document, jobs};
|
||||||
Jobs &jobs = d.jobs;
|
|
||||||
ClangBackEnd::SupportiveTranslationUnitInitializer &initializer = *d.initializer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using SupportiveTranslationUnitInitializerSlowTest = SupportiveTranslationUnitInitializer;
|
using SupportiveTranslationUnitInitializerSlowTest = SupportiveTranslationUnitInitializer;
|
||||||
@@ -199,6 +171,18 @@ TEST_F(SupportiveTranslationUnitInitializerSlowTest, FullRun)
|
|||||||
ASSERT_THAT(initializer.state(), Eq(ClangBackEnd::SupportiveTranslationUnitInitializer::State::Initialized));
|
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()
|
void SupportiveTranslationUnitInitializer::parse()
|
||||||
{
|
{
|
||||||
projects.createOrUpdate({ProjectPartContainer{projectPartId, Utf8StringVector()}});
|
projects.createOrUpdate({ProjectPartContainer{projectPartId, Utf8StringVector()}});
|
||||||
|
|||||||
41
tests/unit/unittest/runprojectcreateorupdate-utility.h
Normal file
41
tests/unit/unittest/runprojectcreateorupdate-utility.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 \
|
mockfilepathcaching.h \
|
||||||
mocksqlitestatement.h \
|
mocksqlitestatement.h \
|
||||||
unittest-utility-functions.h \
|
unittest-utility-functions.h \
|
||||||
mocksymbolquery.h
|
mocksymbolquery.h \
|
||||||
|
runprojectcreateorupdate-utility.h
|
||||||
!isEmpty(LIBCLANG_LIBS) {
|
!isEmpty(LIBCLANG_LIBS) {
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
chunksreportedmonitor.h \
|
chunksreportedmonitor.h \
|
||||||
|
|||||||
Reference in New Issue
Block a user