| 636 | } |
| 637 | |
| 638 | void TestAssistants::testMoveIntoSource() |
| 639 | { |
| 640 | QFETCH(QString, origHeader); |
| 641 | QFETCH(QString, origImpl); |
| 642 | QFETCH(QString, newHeader); |
| 643 | QFETCH(QString, newImpl); |
| 644 | QFETCH(QualifiedIdentifier, id); |
| 645 | |
| 646 | TestFile header(origHeader, QStringLiteral("h")); |
| 647 | TestFile impl("#include \"" + header.url().byteArray() + "\"\n" + origImpl, QStringLiteral("cpp"), &header); |
| 648 | |
| 649 | { |
| 650 | TopDUContext* headerCtx = nullptr; |
| 651 | { |
| 652 | DUChainReadLocker lock; |
| 653 | headerCtx = DUChain::self()->chainForDocument(header.url()); |
| 654 | } |
| 655 | // Here is a problem: when launching tests one by one, we can reuse the same tmp file for headers. |
| 656 | // But because of document chain for header wasn't unloaded properly in previous run we reuse it here |
| 657 | // Therefore when using headerCtx->findDeclarations below we find declarations from the previous launch -> tests fail |
| 658 | if (headerCtx) { |
| 659 | // TODO: Investigate why this chain doesn't get updated when parsing source file |
| 660 | DUChainWriteLocker lock; |
| 661 | DUChain::self()->removeDocumentChain(headerCtx); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | impl.parse(KDevelop::TopDUContext::AllDeclarationsContextsAndUses); |
| 666 | QVERIFY(impl.waitForParsed()); |
| 667 | |
| 668 | IndexedDeclaration declaration; |
| 669 | { |
| 670 | DUChainReadLocker lock; |
| 671 | auto headerCtx = DUChain::self()->chainForDocument(header.url()); |
| 672 | QVERIFY(headerCtx); |
| 673 | auto decls = headerCtx->findDeclarations(id); |
| 674 | Q_ASSERT(!decls.isEmpty()); |
| 675 | declaration = IndexedDeclaration(decls.first()); |
| 676 | QVERIFY(declaration.isValid()); |
| 677 | } |
| 678 | CodeRepresentation::setDiskChangesForbidden(false); |
| 679 | ClangRefactoring refactoring; |
| 680 | QCOMPARE(refactoring.moveIntoSource(declaration), QString()); |
| 681 | CodeRepresentation::setDiskChangesForbidden(true); |
| 682 | |
| 683 | QCOMPARE(header.fileContents(), newHeader); |
| 684 | QVERIFY(impl.fileContents().endsWith(newImpl)); |
| 685 | } |
| 686 | |
| 687 | void TestAssistants::testMoveIntoSource_data() |
| 688 | { |
nothing calls this directly
no test coverage detected