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/cppchecksymbols.h>
|
||||||
#include <cpptools/cppsemanticinfo.h>
|
#include <cpptools/cppsemanticinfo.h>
|
||||||
|
#include <cpptools/cpptoolstestcase.h>
|
||||||
#include <texteditor/semantichighlighter.h>
|
#include <texteditor/semantichighlighter.h>
|
||||||
#include <utils/fileutils.h>
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -116,28 +116,15 @@ public:
|
|||||||
{
|
{
|
||||||
// Write source to temprorary file
|
// Write source to temprorary file
|
||||||
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
|
const QString filePath = QDir::tempPath() + QLatin1String("/file.h");
|
||||||
Document::Ptr document = Document::create(filePath);
|
CppTools::Tests::TestCase::writeFile(filePath, source);
|
||||||
Utils::FileSaver documentSaver(document->fileName());
|
|
||||||
documentSaver.write(source);
|
|
||||||
documentSaver.finalize();
|
|
||||||
|
|
||||||
// Preprocess source
|
// Processs source
|
||||||
Environment env;
|
const Document::Ptr document = createDocument(filePath, source);
|
||||||
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());
|
|
||||||
Snapshot snapshot;
|
Snapshot snapshot;
|
||||||
snapshot.insert(document);
|
snapshot.insert(document);
|
||||||
|
|
||||||
// Collect symbols
|
// Collect symbols
|
||||||
LookupContext context(document, snapshot);
|
CheckSymbols::Future future = runCheckSymbols(document, snapshot, expectedUsesMacros);
|
||||||
CheckSymbols::Future future = CheckSymbols::go(document, context, expectedUsesMacros);
|
|
||||||
future.waitForFinished();
|
|
||||||
|
|
||||||
const int resultCount = future.resultCount();
|
const int resultCount = future.resultCount();
|
||||||
UseList actualUses;
|
UseList actualUses;
|
||||||
@@ -161,6 +148,34 @@ public:
|
|||||||
QCOMPARE(actualUse, expectedUse);
|
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
|
} // anonymous namespace
|
||||||
|
Reference in New Issue
Block a user