forked from qt-creator/qt-creator
C++: Tests: Extract some functions in tst_checksymbols
...so we can use them in a follow-up change. Change-Id: I0ddc5bb966e72ab5c527f6814650d70492bbbdb5 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -34,8 +34,8 @@
|
||||
|
||||
#include <cpptools/cppchecksymbols.h>
|
||||
#include <cpptools/cppsemanticinfo.h>
|
||||
#include <cpptools/cpptoolstestcase.h>
|
||||
#include <texteditor/semantichighlighter.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@@ -116,28 +116,15 @@ public:
|
||||
{
|
||||
// Write source to temprorary file
|
||||
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
|
||||
Document::Ptr document = Document::create(filePath);
|
||||
Utils::FileSaver documentSaver(document->fileName());
|
||||
documentSaver.write(source);
|
||||
documentSaver.finalize();
|
||||
CppTools::Tests::TestCase::writeFile(filePath, source);
|
||||
|
||||
// Preprocess source
|
||||
Environment env;
|
||||
Preprocessor preprocess(0, &env);
|
||||
preprocess.setKeepComments(true);
|
||||
const QByteArray preprocessedSource = preprocess.run(filePath, source);
|
||||
|
||||
document->setUtf8Source(preprocessedSource);
|
||||
QVERIFY(document->parse());
|
||||
document->check();
|
||||
QVERIFY(document->diagnosticMessages().isEmpty());
|
||||
// Processs source
|
||||
const Document::Ptr document = createDocument(filePath, source);
|
||||
Snapshot snapshot;
|
||||
snapshot.insert(document);
|
||||
|
||||
// Collect symbols
|
||||
LookupContext context(document, snapshot);
|
||||
CheckSymbols::Future future = CheckSymbols::go(document, context, expectedUsesMacros);
|
||||
future.waitForFinished();
|
||||
CheckSymbols::Future future = runCheckSymbols(document, snapshot, expectedUsesMacros);
|
||||
|
||||
const int resultCount = future.resultCount();
|
||||
UseList actualUses;
|
||||
@@ -161,6 +148,34 @@ public:
|
||||
QCOMPARE(actualUse, expectedUse);
|
||||
}
|
||||
}
|
||||
|
||||
static CheckSymbols::Future runCheckSymbols(const Document::Ptr &document,
|
||||
const Snapshot &snapshot,
|
||||
const UseList &expectedUsesMacros = UseList())
|
||||
{
|
||||
LookupContext context(document, snapshot);
|
||||
CheckSymbols::Future future = CheckSymbols::go(document, context, expectedUsesMacros);
|
||||
future.waitForFinished();
|
||||
return future;
|
||||
}
|
||||
|
||||
static Document::Ptr createDocument(const QString &filePath, const QByteArray &source)
|
||||
{
|
||||
Environment env;
|
||||
Preprocessor preprocess(0, &env);
|
||||
preprocess.setKeepComments(true);
|
||||
const QByteArray preprocessedSource = preprocess.run(filePath, source);
|
||||
|
||||
Document::Ptr document = Document::create(filePath);
|
||||
document->setUtf8Source(preprocessedSource);
|
||||
if (!document->parse())
|
||||
return Document::Ptr();
|
||||
document->check();
|
||||
if (!document->diagnosticMessages().isEmpty())
|
||||
return Document::Ptr();
|
||||
|
||||
return document;
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
Reference in New Issue
Block a user