aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2017-11-29 15:20:15 +0100
committerMarco Bubke <marco.bubke@qt.io>2017-12-05 10:25:26 +0000
commit8dac5ff1c474e9eb0ed1521a3821bcdaff532953 (patch)
tree11fa6608594214eddc3c54b4d793126f58fa89cc /tests
parent7376336e155e26afab87aa86d14018f5763200cf (diff)
UnitTests: Remove heap allocations in the DocumentProcessor test
A fixture class is called for every test, so we don't need that setup code. Change-Id: I7fb2ee8248a161f701292a90eb6b8b88e9df08a7 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/clangdocumentprocessor-test.cpp45
1 files changed, 15 insertions, 30 deletions
diff --git a/tests/unit/unittest/clangdocumentprocessor-test.cpp b/tests/unit/unittest/clangdocumentprocessor-test.cpp
index 7b9b73891d7..d18803eb4bb 100644
--- a/tests/unit/unittest/clangdocumentprocessor-test.cpp
+++ b/tests/unit/unittest/clangdocumentprocessor-test.cpp
@@ -41,39 +41,23 @@ using namespace ClangBackEnd;
namespace {
-struct Data {
- Data()
- {
- projects.createOrUpdate({ProjectPartContainer(projectPartId)});
-
- const QVector<FileContainer> fileContainer{FileContainer(filePath, projectPartId)};
- document = documents.create(fileContainer).front();
- documents.setVisibleInEditors({filePath});
- documents.setUsedByCurrentEditor(filePath);
- }
+class DocumentProcessor : public ::testing::Test
+{
+protected:
+ void SetUp() override;
+ void TearDown() override;
+ bool waitUntilAllJobsFinished(int timeOutInMs = 10000) const;
+protected:
ClangBackEnd::ProjectParts projects;
ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::Documents documents{projects, unsavedFiles};
- ClangBackEnd::Document document;
DummyIpcClient dummyIpcClient;
Utf8String filePath{Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp")};
Utf8String projectPartId{Utf8StringLiteral("/path/to/projectfile")};
-};
-
-class DocumentProcessor : public ::testing::Test
-{
-protected:
- void SetUp() override;
- void TearDown() override;
-
-protected:
- std::unique_ptr<Data> d;
std::unique_ptr<ClangBackEnd::DocumentProcessor> documentProcessor;
-
- bool waitUntilAllJobsFinished(int timeOutInMs = 10000) const;
};
using DocumentProcessorSlowTest = DocumentProcessor;
@@ -98,18 +82,19 @@ TEST_F(DocumentProcessorSlowTest, ProcessSingleJob)
void DocumentProcessor::SetUp()
{
- d.reset(new Data);
- documentProcessor.reset(new ClangBackEnd::DocumentProcessor(d->document,
- d->documents,
- d->unsavedFiles,
- d->projects,
- d->dummyIpcClient));
+ const QVector<FileContainer> fileContainer{FileContainer(filePath, projectPartId)};
+
+ projects.createOrUpdate({ProjectPartContainer(projectPartId)});
+ ClangBackEnd::Document document = {documents.create(fileContainer).front()};
+ documents.setVisibleInEditors({filePath});
+ documents.setUsedByCurrentEditor(filePath);
+ documentProcessor = std::make_unique<ClangBackEnd::DocumentProcessor>(
+ document, documents, unsavedFiles, projects, dummyIpcClient);
}
void DocumentProcessor::TearDown()
{
ASSERT_TRUE(waitUntilAllJobsFinished()); // QFuture/QFutureWatcher is implemented with events
- d.reset();
}
bool DocumentProcessor::waitUntilAllJobsFinished(int timeOutInMs) const