| 48 | } |
| 49 | |
| 50 | void TestRefactoring::testClassRename() |
| 51 | { |
| 52 | const QString codeBefore(QStringLiteral(R"( |
| 53 | class Foo { |
| 54 | public: |
| 55 | Foo(); |
| 56 | ~Foo(); |
| 57 | }; |
| 58 | Foo::Foo() { |
| 59 | } |
| 60 | Foo::~Foo() { |
| 61 | } |
| 62 | )")); |
| 63 | |
| 64 | const QString codeAfter(QStringLiteral(R"( |
| 65 | class FooNew { |
| 66 | public: |
| 67 | FooNew(); |
| 68 | ~FooNew(); |
| 69 | }; |
| 70 | FooNew::FooNew() { |
| 71 | } |
| 72 | FooNew::~FooNew() { |
| 73 | } |
| 74 | )")); |
| 75 | |
| 76 | QTemporaryDir dir; |
| 77 | auto project = new TestProject(Path(dir.path()), this); |
| 78 | m_projectController->addProject(project); |
| 79 | |
| 80 | TestFile file(codeBefore, QStringLiteral("cpp"), project, dir.path()); |
| 81 | QVERIFY(file.parseAndWait(TopDUContext::AllDeclarationsContextsAndUses)); |
| 82 | |
| 83 | DUChainReadLocker lock; |
| 84 | |
| 85 | auto top = file.topContext(); |
| 86 | QVERIFY(top); |
| 87 | |
| 88 | auto declaration = top->localDeclarations().first(); |
| 89 | QVERIFY(declaration); |
| 90 | |
| 91 | const QString originalName = declaration->identifier().identifier().str(); |
| 92 | const QString newName = QStringLiteral("FooNew"); |
| 93 | |
| 94 | QSharedPointer<BasicRefactoringCollector> collector(new BasicRefactoringCollector(declaration)); |
| 95 | |
| 96 | // TODO: Do this without GUI? |
| 97 | UsesWidget uses(declaration, collector); |
| 98 | lock.unlock(); |
| 99 | |
| 100 | for (int i = 0; i < 30000; i += 1000) { |
| 101 | if (collector->isReady()) { |
| 102 | break; |
| 103 | } |
| 104 | QTest::qWait(1000); |
| 105 | } |
| 106 | QVERIFY(collector->isReady()); |
| 107 |
nothing calls this directly
no test coverage detected