aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-11-29 16:37:27 +0100
committerMarco Bubke <marco.bubke@qt.io>2017-12-05 10:26:06 +0000
commit409fecd3a056ed3212f3b7b001e62839335825ac (patch)
treee2f5be4d9fb2066349c267f0d5215ce8a0e810a2 /tests
parent872f3ee9c3f532b023099fdfa0001cd4fe8b378b (diff)
UnitTests: Cleanup SupportiveTranslationUnitInitializer test
Change-Id: I0c43baeb13fe2a1004622267deb4e588f941d254 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/clangsupportivetranslationunitinitializer-test.cpp68
-rw-r--r--tests/unit/unittest/runprojectcreateorupdate-utility.h41
-rw-r--r--tests/unit/unittest/unittest.pro4
3 files changed, 69 insertions, 44 deletions
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 <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 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 <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 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 \