MCPcopy Create free account
hub / github.com/KDE/kdevelop / testMissingInclude

Method testMissingInclude

plugins/clang/tests/test_problems.cpp:256–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void 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
304void TestProblems::testMissingInclude_data()
305{

Callers

nothing calls this directly

Calls 15

resolveFilenamesFunction · 0.85
waitForParsedMethod · 0.80
fixitsMethod · 0.80
parseMethod · 0.45
isEmptyMethod · 0.45
resetMethod · 0.45
openMethod · 0.45
replaceMethod · 0.45
fileNameMethod · 0.45
toUrlMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected