Commit 21ce7386 authored by Marco Bubke's avatar Marco Bubke

UnitTests: Cleanup SourceRange test

Change-Id: Icd9ef74385bb35a4fe1f2f8142b4bf677eb7d389
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent f3164c5a
......@@ -24,6 +24,7 @@
****************************************************************************/
#include "googletest.h"
#include "documentparser-utility.h"
#include "testenvironment.h"
#include <clangtranslationunit.h>
......@@ -72,28 +73,7 @@ MATCHER_P4(IsSourceLocation, filePath, line, column, offset,
return true;
}
struct SourceRangeData {
SourceRangeData(Document &document)
: diagnosticSet{document.translationUnit().diagnostics()}
, diagnostic{diagnosticSet.front()}
, diagnosticWithFilteredOutInvalidRange{diagnosticSet.at(1)}
, sourceRange{diagnostic.ranges().front()}
{
}
DiagnosticSet diagnosticSet;
Diagnostic diagnostic;
Diagnostic diagnosticWithFilteredOutInvalidRange;
::SourceRange sourceRange;
};
struct Data {
Data()
{
document.parse();
d.reset(new SourceRangeData(document));
}
ProjectPart projectPart{Utf8StringLiteral("projectPartId"),
TestEnvironment::addPlatformArguments({Utf8StringLiteral("-pedantic")})};
ClangBackEnd::ProjectParts projects;
......@@ -104,12 +84,15 @@ struct Data {
projectPart,
Utf8StringVector(),
documents};
UnitTest::DocumentParser documentParser{document};
TranslationUnit translationUnit{filePath,
filePath,
document.translationUnit().cxIndex(),
document.translationUnit().cxTranslationUnit()};
std::unique_ptr<SourceRangeData> d;
DiagnosticSet diagnosticSet{document.translationUnit().diagnostics()};
Diagnostic diagnostic{diagnosticSet.front()};
Diagnostic diagnosticWithFilteredOutInvalidRange{diagnosticSet.at(1)};
ClangBackEnd::SourceRange sourceRange{diagnostic.ranges().front()};
};
class SourceRange : public ::testing::Test
......@@ -119,11 +102,11 @@ public:
static void TearDownTestCase();
protected:
static Data *d;
const ::SourceRange &sourceRange = d->d->sourceRange;
const Diagnostic &diagnostic = d->d->diagnostic;
const Diagnostic &diagnosticWithFilteredOutInvalidRange = d->d->diagnosticWithFilteredOutInvalidRange;
const TranslationUnit &translationUnit = d->translationUnit;
static std::unique_ptr<const Data> data;
const ::SourceRange &sourceRange = data->sourceRange;
const Diagnostic &diagnostic = data->diagnostic;
const Diagnostic &diagnosticWithFilteredOutInvalidRange = data->diagnosticWithFilteredOutInvalidRange;
const TranslationUnit &translationUnit = data->translationUnit;
};
TEST_F(SourceRange, IsNull)
......@@ -178,17 +161,16 @@ TEST_F(SourceRange, InvalidRangeIsFilteredOut)
ASSERT_THAT(diagnosticWithFilteredOutInvalidRange.ranges(), IsEmpty());
}
Data *SourceRange::d;
std::unique_ptr<const Data> SourceRange::data;
void SourceRange::SetUpTestCase()
{
d = new Data;
data = std::make_unique<const Data>();
}
void SourceRange::TearDownTestCase()
{
delete d;
d = nullptr;
data.reset();
}
}
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