diff options
author | Marco Bubke <marco.bubke@qt.io> | 2017-11-29 16:37:27 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2017-12-05 10:26:06 +0000 |
commit | 409fecd3a056ed3212f3b7b001e62839335825ac (patch) | |
tree | e2f5be4d9fb2066349c267f0d5215ce8a0e810a2 | |
parent | 872f3ee9c3f532b023099fdfa0001cd4fe8b378b (diff) | |
download | qt-creator-409fecd3a056ed3212f3b7b001e62839335825ac.tar.gz |
UnitTests: Cleanup SupportiveTranslationUnitInitializer test
Change-Id: I0c43baeb13fe2a1004622267deb4e588f941d254
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
-rw-r--r-- | src/tools/clangbackend/source/clangjobqueue.cpp | 5 | ||||
-rw-r--r-- | src/tools/clangbackend/source/clangjobqueue.h | 1 | ||||
-rw-r--r-- | src/tools/clangbackend/source/clangjobs.cpp | 5 | ||||
-rw-r--r-- | src/tools/clangbackend/source/clangjobs.h | 1 | ||||
-rw-r--r-- | tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp | 68 | ||||
-rw-r--r-- | tests/unit/unittest/runprojectcreateorupdate-utility.h | 41 | ||||
-rw-r--r-- | tests/unit/unittest/unittest.pro | 4 |
7 files changed, 81 insertions, 44 deletions
diff --git a/src/tools/clangbackend/source/clangjobqueue.cpp b/src/tools/clangbackend/source/clangjobqueue.cpp index 4ea098db3a..6fb1c7ecf2 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 0d9c49ef04..05c48e5bd2 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 033dc4ef1a..7bec5cdc1c 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 d154d401e8..a0f8449396 100644 --- a/src/tools/clangbackend/source/clangjobs.h +++ b/src/tools/clangbackend/source/clangjobs.h @@ -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; diff --git a/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp b/tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp index cb6610921a..540fcf7fdc 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 <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()}}); diff --git a/tests/unit/unittest/runprojectcreateorupdate-utility.h b/tests/unit/unittest/runprojectcreateorupdate-utility.h new file mode 100644 index 0000000000..e4ee9a3b17 --- /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 <projects.h> + +namespace UnitTest { + +struct RunProjectCreateOrUpdate +{ + RunProjectCreateOrUpdate(ClangBackEnd::ProjectParts &projects, + const QVector<ClangBackEnd::ProjectPartContainer> &projectContainers) + { + projects.createOrUpdate(projectContainers); + } +}; + +} // namespace UnitTest diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 8ca648b766..63c368468a 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 \ |