| 254 | } |
| 255 | |
| 256 | void TestProblems::testMissingInclude() |
| 257 | { |
| 258 | QFETCH(QString, includeFileContent); |
| 259 | QFETCH(QString, workingFileContent); |
| 260 | QFETCH(QString, dummyFileName); |
| 261 | QFETCH(QVector<ClangFixit>, fixits); |
| 262 | |
| 263 | TestFile include(includeFileContent, QStringLiteral("h")); |
| 264 | include.parse(TopDUContext::AllDeclarationsAndContexts); |
| 265 | |
| 266 | QScopedPointer<QTemporaryFile> dummyFile; |
| 267 | if (!dummyFileName.isEmpty()) { |
| 268 | dummyFile.reset(new QTemporaryFile(QDir::tempPath() + dummyFileName)); |
| 269 | QVERIFY(dummyFile->open()); |
| 270 | |
| 271 | workingFileContent.replace(QLatin1String("dummyInclude"), dummyFile->fileName()); |
| 272 | } |
| 273 | |
| 274 | TestFile workingFile(workingFileContent, QStringLiteral("cpp")); |
| 275 | workingFile.parse(TopDUContext::AllDeclarationsAndContexts); |
| 276 | |
| 277 | QCOMPARE(include.url().toUrl().adjusted(QUrl::RemoveFilename), workingFile.url().toUrl().adjusted(QUrl::RemoveFilename)); |
| 278 | QVERIFY(include.waitForParsed()); |
| 279 | QVERIFY(workingFile.waitForParsed()); |
| 280 | |
| 281 | DUChainReadLocker lock; |
| 282 | |
| 283 | QVERIFY(include.topContext()); |
| 284 | TopDUContext* includeTop = DUChainUtils::contentContextFromProxyContext(include.topContext().data()); |
| 285 | QVERIFY(includeTop); |
| 286 | |
| 287 | QVERIFY(workingFile.topContext()); |
| 288 | TopDUContext* top = DUChainUtils::contentContextFromProxyContext(workingFile.topContext()); |
| 289 | QVERIFY(top); |
| 290 | QCOMPARE(top->problems().size(), 1); |
| 291 | |
| 292 | auto problem = dynamic_cast<UnknownDeclarationProblem*>(top->problems().first().data()); |
| 293 | auto assistant = problem->solutionAssistant(); |
| 294 | auto clangFixitAssistant = qobject_cast<ClangFixitAssistant*>(assistant.data()); |
| 295 | QVERIFY(clangFixitAssistant); |
| 296 | |
| 297 | auto resolvedFixits = resolveFilenames(fixits, { |
| 298 | {"includeFile.h", include.url().toUrl().fileName()}, |
| 299 | {"workingFile.h", workingFile.url().toUrl().fileName()} |
| 300 | }); |
| 301 | compareFixitsWithoutDescription(clangFixitAssistant->fixits(), resolvedFixits); |
| 302 | } |
| 303 | |
| 304 | void TestProblems::testMissingInclude_data() |
| 305 | { |
nothing calls this directly
no test coverage detected