Commit 3d96108b authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Fix reparsing of header files...



...when having split source and headers and defining test data functions
inside the source file.
If we just reparse a header file (e.g. when opening the respective file
inside the editor) we have no explicit information where the definition
of the functions is. This lead to not finding the information necessary
for displaying data tags and throwing away old information as they have
been marked for removal.

Change-Id: Ieb8ed9f7c758fe2c793e60ca2c30b4025106363b
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 8390f9e8
......@@ -404,31 +404,31 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
return declaringDoc;
}
static bool hasFunctionWithDataTagUsage(const QMap<QString, TestCodeLocationAndType> &testFunctions)
static QSet<QString> filesWithDataFunctionDefinitions(
const QMap<QString, TestCodeLocationAndType> &testFunctions)
{
foreach (const QString &functionName, testFunctions.keys()) {
if (functionName.endsWith(QLatin1String("_data")) &&
testFunctions.contains(functionName.left(functionName.size() - 5))) {
return true;
}
QSet<QString> result;
QMap<QString, TestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
const QMap<QString, TestCodeLocationAndType>::ConstIterator end = testFunctions.end();
for ( ; it != end; ++it) {
const QString &key = it.key();
if (key.endsWith(QLatin1String("_data")) && testFunctions.contains(key.left(key.size() - 5)))
result.insert(it.value().m_name);
}
return false;
return result;
}
static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileName,
const QMap<QString, TestCodeLocationAndType> &testFunctions)
static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileName)
{
if (hasFunctionWithDataTagUsage(testFunctions)) {
const CPlusPlus::Snapshot snapshot = CPlusPlus::CppModelManagerBase::instance()->snapshot();
const QByteArray fileContent = getFileContent(fileName);
CPlusPlus::Document::Ptr document = snapshot.preprocessedDocument(fileContent, fileName);
document->check();
CPlusPlus::AST *ast = document->translationUnit()->ast();
TestDataFunctionVisitor visitor(document);
visitor.accept(ast);
return visitor.dataTags();
}
return QMap<QString, TestCodeLocationList>();
const CPlusPlus::Snapshot snapshot = CPlusPlus::CppModelManagerBase::instance()->snapshot();
const QByteArray fileContent = getFileContent(fileName);
CPlusPlus::Document::Ptr document = snapshot.preprocessedDocument(fileContent, fileName);
document->check();
CPlusPlus::AST *ast = document->translationUnit()->ast();
TestDataFunctionVisitor visitor(document);
visitor.accept(ast);
return visitor.dataTags();
}
/****** end of helpers ******/
......@@ -549,12 +549,11 @@ static void checkDocumentForTestCode(QFutureInterface<TestParseResult> futureInt
return;
const QMap<QString, TestCodeLocationAndType> testFunctions = visitor.privateSlots();
const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions);
QMap<QString, TestCodeLocationList> dataTags =
checkForDataTags(declaringDoc->fileName(), testFunctions);
if (declaringDoc->fileName() != document->fileName())
dataTags.unite(checkForDataTags(document->fileName(), testFunctions));
QMap<QString, TestCodeLocationList> dataTags;
foreach (const QString &file, files)
dataTags.unite(checkForDataTags(file));
TestParseResult parseResult(TestTreeModel::AutoTest);
parseResult.fileName = declaringDoc->fileName();
......
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