diff --git a/src/tools/clangbackend/source/clangjobqueue.cpp b/src/tools/clangbackend/source/clangjobqueue.cpp index 4ea098db3ac..6fb1c7ecf28 100644 --- a/src/tools/clangbackend/source/clangjobqueue.cpp +++ b/src/tools/clangbackend/source/clangjobqueue.cpp @@ -310,4 +310,9 @@ JobRequests &JobQueue::queue() return m_queue; } +const JobRequests &JobQueue::queue() const +{ + return m_queue; +} + } // namespace ClangBackEnd diff --git a/src/tools/clangbackend/source/clangjobqueue.h b/src/tools/clangbackend/source/clangjobqueue.h index 0d9c49ef042..05c48e5bd29 100644 --- a/src/tools/clangbackend/source/clangjobqueue.h +++ b/src/tools/clangbackend/source/clangjobqueue.h @@ -56,6 +56,7 @@ public: public: // for tests JobRequests &queue(); + const JobRequests &queue() const; int size() const; void prioritizeRequests(); diff --git a/src/tools/clangbackend/source/clangjobs.cpp b/src/tools/clangbackend/source/clangjobs.cpp index 033dc4ef1a4..7bec5cdc1cc 100644 --- a/src/tools/clangbackend/source/clangjobs.cpp +++ b/src/tools/clangbackend/source/clangjobs.cpp @@ -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) { diff --git a/src/tools/clangbackend/source/clangjobs.h b/src/tools/clangbackend/source/clangjobs.h index d154d401e88..a0f84493965 100644 --- a/src/tools/clangbackend/source/clangjobs.h +++ b/src/tools/clangbackend/source/clangjobs.h @@ -76,6 +76,7 @@ public: public /*for tests*/: QList runningJobs() const; JobRequests &queue(); + const JobRequests &queue() const; bool isJobRunningForTranslationUnit(const Utf8String &translationUnitId) const; bool isJobRunningForJobRequest(const JobRequest &jobRequest) const; diff --git a/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp b/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp index cb6610921a2..540fcf7fdc7 100644 --- a/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp +++ b/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp @@ -27,6 +27,7 @@ #include "dummyclangipcclient.h" #include "processevents-utilities.h" +#include "runprojectcreateorupdate-utility.h" #include #include @@ -47,43 +48,10 @@ using testing::Eq; namespace { -class Data { -public: - Data() - { - projects.createOrUpdate({ProjectPartContainer(projectPartId)}); - - const QVector 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 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")}; - Utf8String &filePath = d.filePath; - Utf8String &projectPartId = d.projectPartId; + ProjectParts projects; + UnitTest::RunProjectCreateOrUpdate _1{projects, {ProjectPartContainer(projectPartId)}}; + UnsavedFiles unsavedFiles; + const QVector fileContainer{FileContainer(filePath, projectPartId)}; + Documents documents{projects, unsavedFiles}; + Document document{documents.create(fileContainer).front()}; + DummyIpcClient dummyClientInterface; - ProjectParts projects = d.projects; - Document &document = d.document; - Documents &documents = d.documents; - Jobs &jobs = d.jobs; - ClangBackEnd::SupportiveTranslationUnitInitializer &initializer = *d.initializer; + Jobs jobs{documents, unsavedFiles, projects, dummyClientInterface}; + + 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()}}); diff --git a/tests/unit/unittest/runprojectcreateorupdate-utility.h b/tests/unit/unittest/runprojectcreateorupdate-utility.h new file mode 100644 index 00000000000..e4ee9a3b17b --- /dev/null +++ b/tests/unit/unittest/runprojectcreateorupdate-utility.h @@ -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 + +namespace UnitTest { + +struct RunProjectCreateOrUpdate +{ + RunProjectCreateOrUpdate(ClangBackEnd::ProjectParts &projects, + const QVector &projectContainers) + { + projects.createOrUpdate(projectContainers); + } +}; + +} // namespace UnitTest diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 8ca648b7662..63c368468a6 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -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 \