| 1175 | } |
| 1176 | |
| 1177 | void TestDUChain::testReparseInclude() |
| 1178 | { |
| 1179 | TestFile header(QStringLiteral("int foo() { return 42; }\n"), QStringLiteral("h")); |
| 1180 | TestFile impl("#include \"" + header.url().str() + "\"\n" |
| 1181 | "int main() { return foo(); }", QStringLiteral("cpp"), &header); |
| 1182 | |
| 1183 | // Use TopDUContext::AST to imitate that document is opened in the editor, so that ClangParseJob can store translation unit, that'll be used for reparsing. |
| 1184 | impl.parse(TopDUContext::AllDeclarationsAndContexts | TopDUContext::AST); |
| 1185 | QVERIFY(impl.waitForParsed(5000)); |
| 1186 | { |
| 1187 | DUChainReadLocker lock; |
| 1188 | auto implCtx = impl.topContext(); |
| 1189 | QVERIFY(implCtx); |
| 1190 | QCOMPARE(implCtx->importedParentContexts().size(), 1); |
| 1191 | } |
| 1192 | |
| 1193 | impl.parse(TopDUContext::AllDeclarationsContextsAndUses | TopDUContext::AST); |
| 1194 | QVERIFY(impl.waitForParsed(5000)); |
| 1195 | |
| 1196 | DUChainReadLocker lock; |
| 1197 | auto implCtx = impl.topContext(); |
| 1198 | QVERIFY(implCtx); |
| 1199 | QCOMPARE(implCtx->localDeclarations().size(), 1); |
| 1200 | |
| 1201 | QCOMPARE(implCtx->importedParentContexts().size(), 1); |
| 1202 | |
| 1203 | auto headerCtx = DUChain::self()->chainForDocument(header.url()); |
| 1204 | QVERIFY(headerCtx); |
| 1205 | QVERIFY(!headerCtx->parsingEnvironmentFile()->needsUpdate()); |
| 1206 | QCOMPARE(headerCtx->localDeclarations().size(), 1); |
| 1207 | |
| 1208 | QVERIFY(implCtx->imports(headerCtx, CursorInRevision(0, 10))); |
| 1209 | |
| 1210 | Declaration* foo = headerCtx->localDeclarations().first(); |
| 1211 | QCOMPARE(foo->uses().size(), 1); |
| 1212 | QCOMPARE(foo->uses().begin().key(), impl.url()); |
| 1213 | QCOMPARE(foo->uses().begin()->size(), 1); |
| 1214 | QCOMPARE(foo->uses().begin()->first(), RangeInRevision(1, 20, 1, 23)); |
| 1215 | |
| 1216 | QCOMPARE(DUChain::self()->allEnvironmentFiles(header.url()).size(), 1); |
| 1217 | QCOMPARE(DUChain::self()->allEnvironmentFiles(impl.url()).size(), 1); |
| 1218 | QCOMPARE(DUChain::self()->chainsForDocument(header.url()).size(), 1); |
| 1219 | QCOMPARE(DUChain::self()->chainsForDocument(impl.url()).size(), 1); |
| 1220 | } |
| 1221 | |
| 1222 | void TestDUChain::testReparseChangeEnvironment() |
| 1223 | { |
nothing calls this directly
no test coverage detected