Commit 50e4203b authored by Roberto Raggi's avatar Roberto Raggi
Browse files

More testing

parent 864f07d4
......@@ -8,6 +8,7 @@
#include <Semantic.h>
#include <Scope.h>
#include <Symbols.h>
#include <CoreTypes.h>
#include <Names.h>
#include <Literals.h>
......@@ -66,10 +67,12 @@ public:
}
private slots:
void function_declarations();
void function_declaration_1();
void function_declaration_2();
void function_definition_1();
};
void tst_Semantic::function_declarations()
void tst_Semantic::function_declaration_1()
{
QSharedPointer<Document> doc = document("void foo();");
QCOMPARE(doc->globals->symbolCount(), 1U);
......@@ -91,6 +94,65 @@ void tst_Semantic::function_declarations()
QCOMPARE(foo, QByteArray("foo"));
}
void tst_Semantic::function_declaration_2()
{
QSharedPointer<Document> doc = document("void foo(const QString &s);");
QCOMPARE(doc->globals->symbolCount(), 1U);
Declaration *decl = doc->globals->symbolAt(0)->asDeclaration();
QVERIFY(decl);
FullySpecifiedType declTy = decl->type();
Function *funTy = declTy->asFunction();
QVERIFY(funTy);
QVERIFY(funTy->returnType()->isVoidType());
QCOMPARE(funTy->argumentCount(), 1U);
// check the formal argument.
Argument *arg = funTy->argumentAt(0)->asArgument();
QVERIFY(arg);
QVERIFY(arg->name());
QVERIFY(! arg->hasInitializer());
// check the argument's name.
NameId *argNameId = arg->name()->asNameId();
QVERIFY(argNameId);
Identifier *argId = argNameId->identifier();
QVERIFY(argId);
QCOMPARE(QByteArray(argId->chars(), argId->size()), QByteArray("s"));
// check the type of the formal argument
FullySpecifiedType argTy = arg->type();
QVERIFY(argTy->isReferenceType());
QVERIFY(argTy->asReferenceType()->elementType().isConst());
QVERIFY(decl->name()->isNameId());
Identifier *funId = decl->name()->asNameId()->identifier();
QVERIFY(funId);
const QByteArray foo(funId->chars(), funId->size());
QCOMPARE(foo, QByteArray("foo"));
}
void tst_Semantic::function_definition_1()
{
QSharedPointer<Document> doc = document("void foo() {}");
QCOMPARE(doc->globals->symbolCount(), 1U);
Function *funTy = doc->globals->symbolAt(0)->asFunction();
QVERIFY(funTy);
QVERIFY(funTy->returnType()->isVoidType());
QCOMPARE(funTy->argumentCount(), 0U);
QVERIFY(funTy->name()->isNameId());
Identifier *funId = funTy->name()->asNameId()->identifier();
QVERIFY(funId);
const QByteArray foo(funId->chars(), funId->size());
QCOMPARE(foo, QByteArray("foo"));
}
QTEST_APPLESS_MAIN(tst_Semantic)
#include "tst_semantic.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