void tst_Lookup::base_class_defined_1() { Overview overview; const QByteArray source = "\n" "class base {};\n" "class derived: public base {};\n"; Document::Ptr doc = Document::create("base_class_defined_1"); doc->setSource(source); doc->parse(); doc->check(); QVERIFY(doc->diagnosticMessages().isEmpty()); QCOMPARE(doc->globalSymbolCount(), 2U); Snapshot snapshot; snapshot.insert(doc->fileName(), doc); Document::Ptr emptyDoc = Document::create("<empty>"); Class *baseClass = doc->globalSymbolAt(0)->asClass(); QVERIFY(baseClass); Class *derivedClass = doc->globalSymbolAt(1)->asClass(); QVERIFY(derivedClass); LookupContext ctx(derivedClass, emptyDoc, doc, snapshot); const QList<Symbol *> candidates = ctx.resolveClass(derivedClass->baseClassAt(0)->name()); QCOMPARE(candidates.size(), 1); QCOMPARE(candidates.at(0), baseClass); TranslationUnit *unit = doc->translationUnit(); QVERIFY(unit != 0); TranslationUnitAST *ast = unit->ast()->asTranslationUnit(); QVERIFY(ast != 0); ClassSymbols classSymbols(doc->control()); classSymbols(ast); QCOMPARE(classSymbols.size(), 2); const QMap<Class *, ClassSpecifierAST *> classToAST = invert(classSymbols.asMap()); QVERIFY(classToAST.value(baseClass) != 0); QVERIFY(classToAST.value(derivedClass) != 0); }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QStringList files = app.arguments(); files.removeFirst(); foreach (const QString &fileName, files) { QFile file(fileName); if (! file.open(QFile::ReadOnly)) continue; const QByteArray source = file.readAll(); file.close(); Document::Ptr doc = Document::create(fileName); doc->control()->setDiagnosticClient(0); doc->setSource(source); doc->parse(); }