Commit 1f9bcd86 authored by Roberto Raggi's avatar Roberto Raggi

Added a simple auto test for the name lookup.

parent 47a85d5a
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#ifndef CPLUSPLUS_LOOKUPCONTEXT_H #ifndef CPLUSPLUS_LOOKUPCONTEXT_H
#define CPLUSPLUS_LOOKUPCONTEXT_H #define CPLUSPLUS_LOOKUPCONTEXT_H
#include <cplusplus/CppDocument.h> #include "CppDocument.h"
#include <QPair> #include <QPair>
namespace CPlusPlus { namespace CPlusPlus {
......
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
***************************************************************************/ ***************************************************************************/
#include "TypeOfExpression.h" #include "TypeOfExpression.h"
#include <TranslationUnit.h>
#include "LookupContext.h"
#include "ResolveExpression.h"
#include "pp.h"
#include <AST.h> #include <AST.h>
#include <TranslationUnit.h>
#include <cplusplus/LookupContext.h>
#include <cplusplus/ResolveExpression.h>
#include <cplusplus/pp.h>
#include <QSet> #include <QSet>
using namespace CPlusPlus; using namespace CPlusPlus;
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
#ifndef CPLUSPLUS_TYPEOFEXPRESSION_H #ifndef CPLUSPLUS_TYPEOFEXPRESSION_H
#define CPLUSPLUS_TYPEOFEXPRESSION_H #define CPLUSPLUS_TYPEOFEXPRESSION_H
#include <ASTfwd.h> #include "CppDocument.h"
#include <cplusplus/CppDocument.h> #include "LookupContext.h"
#include <cplusplus/LookupContext.h>
#include <ASTfwd.h>
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QString> #include <QtCore/QString>
......
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE CPLUSPLUS_BUILD_LIB
INCLUDEPATH += $$PWD
include(../../shared/cplusplus/cplusplus.pri)
HEADERS += \
$$PWD/SimpleLexer.h \
$$PWD/ExpressionUnderCursor.h \
$$PWD/TokenUnderCursor.h \
$$PWD/CppDocument.h \
$$PWD/Icons.h \
$$PWD/Overview.h \
$$PWD/OverviewModel.h \
$$PWD/NamePrettyPrinter.h \
$$PWD/TypeOfExpression.h \
$$PWD/TypePrettyPrinter.h \
$$PWD/ResolveExpression.h \
$$PWD/LookupContext.h \
$$PWD/PreprocessorClient.h \
$$PWD/PreprocessorEnvironment.h \
$$PWD/Macro.h \
$$PWD/pp.h \
$$PWD/pp-cctype.h \
$$PWD/pp-engine.h \
$$PWD/pp-macro-expander.h \
$$PWD/pp-scanner.h
SOURCES += \
$$PWD/SimpleLexer.cpp \
$$PWD/ExpressionUnderCursor.cpp \
$$PWD/TokenUnderCursor.cpp \
$$PWD/CppDocument.cpp \
$$PWD/Icons.cpp \
$$PWD/Overview.cpp \
$$PWD/OverviewModel.cpp \
$$PWD/NamePrettyPrinter.cpp \
$$PWD/TypeOfExpression.cpp \
$$PWD/TypePrettyPrinter.cpp \
$$PWD/ResolveExpression.cpp \
$$PWD/LookupContext.cpp \
$$PWD/PreprocessorClient.cpp \
$$PWD/PreprocessorEnvironment.cpp \
$$PWD/Macro.cpp \
$$PWD/pp-engine.cpp \
$$PWD/pp-macro-expander.cpp \
$$PWD/pp-scanner.cpp
RESOURCES += $$PWD/cplusplus.qrc
...@@ -2,53 +2,8 @@ TEMPLATE = lib ...@@ -2,53 +2,8 @@ TEMPLATE = lib
TARGET = CPlusPlus TARGET = CPlusPlus
DEFINES += HAVE_QT CPLUSPLUS_WITH_NAMESPACE CPLUSPLUS_BUILD_LIB
DEFINES += NDEBUG DEFINES += NDEBUG
unix:QMAKE_CXXFLAGS_DEBUG += -O3 unix:QMAKE_CXXFLAGS_DEBUG += -O3
include(../../qworkbenchlibrary.pri) include(../../qworkbenchlibrary.pri)
include(../../shared/cplusplus/cplusplus.pri) include(cplusplus-lib.pri)
HEADERS += \
SimpleLexer.h \
ExpressionUnderCursor.h \
TokenUnderCursor.h \
CppDocument.h \
Icons.h \
Overview.h \
OverviewModel.h \
NamePrettyPrinter.h \
TypeOfExpression.h \
TypePrettyPrinter.h \
ResolveExpression.h \
LookupContext.h \
PreprocessorClient.h \
PreprocessorEnvironment.h \
Macro.h \
pp.h \
pp-cctype.h \
pp-engine.h \
pp-macro-expander.h \
pp-scanner.h
SOURCES += \
SimpleLexer.cpp \
ExpressionUnderCursor.cpp \
TokenUnderCursor.cpp \
CppDocument.cpp \
Icons.cpp \
Overview.cpp \
OverviewModel.cpp \
NamePrettyPrinter.cpp \
TypeOfExpression.cpp \
TypePrettyPrinter.cpp \
ResolveExpression.cpp \
LookupContext.cpp \
PreprocessorClient.cpp \
PreprocessorEnvironment.cpp \
Macro.cpp \
pp-engine.cpp \
pp-macro-expander.cpp \
pp-scanner.cpp
RESOURCES += cplusplus.qrc
TEMPLATE = subdirs TEMPLATE = subdirs
SUBDIRS = shared ast semantic SUBDIRS = shared ast semantic lookup
CONFIG += ordered CONFIG += ordered
load(qttest_p4)
include(../../../../src/libs/cplusplus/cplusplus-lib.pri)
SOURCES += tst_lookup.cpp
#include <QtTest>
#include <QObject>
#include <CppDocument.h>
#include <LookupContext.h>
#include <Symbols.h>
#include <Overview.h>
CPLUSPLUS_USE_NAMESPACE
class tst_Lookup: public QObject
{
Q_OBJECT
private Q_SLOTS:
void base_class_defined_1();
};
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);
}
QTEST_APPLESS_MAIN(tst_Lookup)
#include "tst_lookup.moc"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment