Commit 8dac5ff1 authored by Marco Bubke's avatar Marco Bubke

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's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 7376336e
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment