aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-09-04 17:43:47 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-09-10 10:40:38 -0300
commit5927c47bb5109aa49bba5ef6655b26684c62dd04 (patch)
treed8b211db71f343571cb86bb83fdf1c1010c1492a /tests
parent660237e4e259d5bdd7e299a3a828c39be0068621 (diff)
Added more tests for AbstractMetaClass and AbstractMetaEnum
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt16
-rw-r--r--tests/testabstractmetaclass.cpp123
-rw-r--r--tests/testabstractmetaclass.h11
-rw-r--r--tests/testabstractmetatype.cpp111
-rw-r--r--tests/testabstractmetatype.h38
-rw-r--r--tests/testenum.cpp81
-rw-r--r--tests/testenum.h35
-rw-r--r--tests/testutil.h63
8 files changed, 431 insertions, 47 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8517a28a9..adfb5865e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,6 +1,12 @@
-qt4_automoc(testabstractmetaclass.cpp)
-add_executable(testabstractmetaclass testabstractmetaclass.cpp)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${apiextractor_SOURCE_DIR})
-target_link_libraries(testabstractmetaclass ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} apiextractor)
-add_test("AbstractMetaClass" testabstractmetaclass)
+macro(declare_test testname)
+ qt4_automoc("${testname}.cpp")
+ add_executable(${testname} "${testname}.cpp")
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${apiextractor_SOURCE_DIR})
+ target_link_libraries(${testname} ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} apiextractor)
+ add_test(${testname} ${testname})
+endmacro(declare_test testname)
+
+declare_test(testabstractmetaclass)
+declare_test(testabstractmetatype)
+declare_test(testenum)
diff --git a/tests/testabstractmetaclass.cpp b/tests/testabstractmetaclass.cpp
index d7eb77ca2..2050fca20 100644
--- a/tests/testabstractmetaclass.cpp
+++ b/tests/testabstractmetaclass.cpp
@@ -24,42 +24,14 @@
#include "testabstractmetaclass.h"
#include "abstractmetabuilder.h"
#include <QtTest/QTest>
-#include <QBuffer>
-
-
-TestAbstractMetaClass::TestAbstractMetaClass() : m_builder(0)
-{
-}
-
-void TestAbstractMetaClass::init()
-{
- m_builder = new AbstractMetaBuilder;
-}
-
-void TestAbstractMetaClass::cleanup()
-{
- delete m_builder;
- m_builder = 0;
-}
-
-void TestAbstractMetaClass::processCode (const char* cppCode, const char* xmlCode )
-{
- QBuffer buffer;
- // parse typesystem
- buffer.setData(xmlCode);
- TypeDatabase::instance()->parseFile(&buffer);
- buffer.close();
- // parse C++ code
- buffer.setData(cppCode);
- m_builder->build(&buffer);
-}
+#include "testutil.h"
void TestAbstractMetaClass::testClassName()
{
const char* cppCode ="class ClassName {};";
const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"ClassName\"/></typesystem>";
- processCode(cppCode, xmlCode);
- AbstractMetaClassList classes = m_builder->classes();
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
QCOMPARE(classes.count(), 1);
QCOMPARE(classes[0]->name(), QString("ClassName"));
}
@@ -72,12 +44,97 @@ void TestAbstractMetaClass::testClassNameUnderNamespace()
<namespace-type name=\"Namespace\"/> \
<value-type name=\"Namespace::ClassName\"/> \
</typesystem>";
- processCode(cppCode, xmlCode);
- AbstractMetaClassList classes = m_builder->classes();
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
QCOMPARE(classes.count(), 2); // 1 namespace + 1 class
QCOMPARE(classes[0]->name(), QString("ClassName"));
QCOMPARE(classes[0]->qualifiedCppName(), QString("Namespace::ClassName"));
QCOMPARE(classes[1]->name(), QString("Namespace"));
+ QVERIFY(classes[1]->isNamespace());
+
+ // Check ctors info
+ QVERIFY(classes[0]->hasConstructors());
+ QCOMPARE(classes[0]->functions().size(), 1);
+ AbstractMetaFunctionList ctors = classes[0]->queryFunctions(AbstractMetaClass::Constructors);
+ QCOMPARE(ctors.size(), 1);
+ QCOMPARE(ctors[0]->arguments().size(), 0);
+ QVERIFY(!classes[0]->hasPrivateDestructor());
+
+ QVERIFY(classes[0]->hasCloneOperator()); // implicity default copy ctor
+ QVERIFY(!classes[0]->hasHashFunction());
+ QVERIFY(classes[0]->hasNonPrivateConstructor());
+}
+
+void TestAbstractMetaClass::testVirtualMethods()
+{
+ const char* cppCode ="\
+ class A {\
+ public:\
+ virtual int pureVirtual() const = 0;\
+ };\
+ class B : public A {};\
+ class C : public B {\
+ public:\
+ int pureVirtual() const { return 0; }\
+ };\
+ ";
+ const char* xmlCode = "\
+ <typesystem package=\"Foo\"> \
+ <primitive-type name='int' />\
+ <object-type name='A'/> \
+ <object-type name='B'/> \
+ <object-type name='C'/> \
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ QCOMPARE(classes.count(), 3);
+ AbstractMetaClass* a = classes.findClass("A");
+ AbstractMetaClass* b = classes.findClass("B");
+ AbstractMetaClass* c = classes.findClass("C");
+
+ AbstractMetaClass* no_class = 0;
+
+ QCOMPARE(a->baseClass(), no_class);
+ QCOMPARE(b->baseClass(), a);
+ QCOMPARE(c->baseClass(), b);
+
+ QCOMPARE(a->functions().size(), 2); // implicity ctor + the pv method
+ QCOMPARE(b->functions().size(), 2);
+ QCOMPARE(c->functions().size(), 2);
+
+ // implementing class, ownclass, declaringclass
+ AbstractMetaFunction* ctorA = a->queryFunctions(AbstractMetaClass::Constructors).first();
+ AbstractMetaFunction* ctorB = b->queryFunctions(AbstractMetaClass::Constructors).first();
+ AbstractMetaFunction* ctorC = c->queryFunctions(AbstractMetaClass::Constructors).first();
+ QVERIFY(ctorA->isConstructor());
+ QVERIFY(!ctorA->isVirtual());
+ QVERIFY(ctorB->isConstructor());
+ QVERIFY(!ctorB->isVirtual());
+ QVERIFY(ctorC->isConstructor());
+ QVERIFY(!ctorC->isVirtual());
+ QCOMPARE(ctorA->implementingClass(), a);
+ QCOMPARE(ctorA->ownerClass(), a);
+ QCOMPARE(ctorA->declaringClass(), a);
+
+ QCOMPARE(a->virtualFunctions().size(), 1); // Add a pureVirtualMethods method !?
+ QCOMPARE(b->virtualFunctions().size(), 1);
+ QCOMPARE(c->virtualFunctions().size(), 1);
+
+ AbstractMetaFunction* funcA = a->virtualFunctions().first();
+ AbstractMetaFunction* funcB = b->virtualFunctions().first();
+ AbstractMetaFunction* funcC = c->virtualFunctions().first();
+
+ QCOMPARE(funcA->ownerClass(), a);
+ QCOMPARE(funcB->ownerClass(), b);
+ QCOMPARE(funcC->ownerClass(), c);
+
+ QCOMPARE(funcA->declaringClass(), a);
+ QCOMPARE(funcB->declaringClass(), a);
+ QCOMPARE(funcC->declaringClass(), a);
+
+ QCOMPARE(funcA->implementingClass(), no_class);
+ QCOMPARE(funcB->implementingClass(), no_class);
+ QCOMPARE(funcC->implementingClass(), c);
}
diff --git a/tests/testabstractmetaclass.h b/tests/testabstractmetaclass.h
index a15061bbe..54336e7bf 100644
--- a/tests/testabstractmetaclass.h
+++ b/tests/testabstractmetaclass.h
@@ -24,24 +24,17 @@
#ifndef TESTABSTRACTMETACLASS_H
#define TESTABSTRACTMETACLASS_H
-#include <QtCore/QObject>
+#include <QObject>
class AbstractMetaBuilder;
class TestAbstractMetaClass : public QObject
{
Q_OBJECT
-public:
- TestAbstractMetaClass();
private slots:
- void init();
- void cleanup();
void testClassName();
void testClassNameUnderNamespace();
-private:
- AbstractMetaBuilder* m_builder;
-
- void processCode(const char* cppCode, const char* xmlCode);
+ void testVirtualMethods();
};
#endif // TESTABSTRACTMETACLASS_H
diff --git a/tests/testabstractmetatype.cpp b/tests/testabstractmetatype.cpp
new file mode 100644
index 000000000..fdd9a16b5
--- /dev/null
+++ b/tests/testabstractmetatype.cpp
@@ -0,0 +1,111 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include "testabstractmetatype.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+void TestAbstractMetaType::testConstCharPtrType()
+{
+ const char* cppCode ="const char* justAtest();";
+ const char* xmlCode = "<typesystem package=\"Foo\">\
+ <primitive-type name='char'/>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+ QCOMPARE(t.builder()->globalFunctions().size(), 1);
+ AbstractMetaFunction* func = t.builder()->globalFunctions().first();
+ AbstractMetaType* rtype = func->type();
+ // Test properties of const char*
+ QVERIFY(rtype);
+ QCOMPARE(rtype->package(), QString());
+ QCOMPARE(rtype->name(), QString("char"));
+ QVERIFY(rtype->isConstant());
+ QVERIFY(!rtype->isArray());
+ QVERIFY(!rtype->isContainer());
+ QVERIFY(!rtype->isObject());
+ QVERIFY(rtype->isPrimitive());
+ QVERIFY(rtype->isNativePointer());
+ QVERIFY(!rtype->isQObject());
+ QVERIFY(!rtype->isReference());
+ QVERIFY(rtype->isTargetLangChar());
+ QVERIFY(!rtype->isValue());
+ QVERIFY(!rtype->isValuePointer());
+}
+
+void TestAbstractMetaType::testCharType()
+{
+ const char* cppCode ="char justAtest(); class A {};";
+ const char* xmlCode = "<typesystem package=\"Foo\">\
+ <primitive-type name='char'/>\
+ <value-type name='A' />\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+
+ AbstractMetaClassList classes = t.builder()->classes();
+ QCOMPARE(classes.size(), 1);
+ QCOMPARE(classes.first()->package(), QString("Foo"));
+
+ AbstractMetaFunctionList functions = t.builder()->globalFunctions();
+ QCOMPARE(functions.size(), 1);
+ AbstractMetaFunction* func = functions.first();
+ AbstractMetaType* rtype = func->type();
+ // Test properties of const char*
+ QVERIFY(rtype);
+ QCOMPARE(rtype->package(), QString());
+ QCOMPARE(rtype->name(), QString("char"));
+ QVERIFY(!rtype->isConstant());
+ QVERIFY(!rtype->isArray());
+ QVERIFY(!rtype->isContainer());
+ QVERIFY(!rtype->isObject());
+ QVERIFY(rtype->isPrimitive());
+ QVERIFY(!rtype->isNativePointer());
+ QVERIFY(!rtype->isQObject());
+ QVERIFY(!rtype->isReference());
+ QVERIFY(rtype->isTargetLangChar());
+ QVERIFY(rtype->isValue());
+ QVERIFY(!rtype->isValuePointer());
+}
+
+void TestAbstractMetaType::testTypedef()
+{
+ const char* cppCode ="\
+ struct A {\
+ void someMethod();\
+ };\
+ typedef A B;\
+ typedef B C;";
+ const char* xmlCode = "<typesystem package=\"Foo\">\
+ <value-type name='C' />\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+
+ AbstractMetaClassList classes = t.builder()->classes();
+ QCOMPARE(classes.size(), 1);
+ AbstractMetaClass* c = classes.findClass("C");
+ QVERIFY(c);
+ QVERIFY(c->isTypeAlias());
+}
+
+QTEST_APPLESS_MAIN(TestAbstractMetaType)
+
+#include "testabstractmetatype.moc"
diff --git a/tests/testabstractmetatype.h b/tests/testabstractmetatype.h
new file mode 100644
index 000000000..3d741edf4
--- /dev/null
+++ b/tests/testabstractmetatype.h
@@ -0,0 +1,38 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#ifndef TESTABSTRACTMETATYPE_H
+#define TESTABSTRACTMETATYPE_H
+
+#include <QObject>
+
+class TestAbstractMetaType : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testConstCharPtrType();
+ void testCharType();
+ void testTypedef();
+};
+
+#endif
diff --git a/tests/testenum.cpp b/tests/testenum.cpp
new file mode 100644
index 000000000..93a678e73
--- /dev/null
+++ b/tests/testenum.cpp
@@ -0,0 +1,81 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#include "testenum.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+void TestEnum::testEnumCppSignature()
+{
+ const char* cppCode ="\
+ enum GlobalEnum { A, B };\
+ \
+ struct A {\
+ enum ClassEnum { A, B };\
+ void method(ClassEnum);\
+ };\
+ void func(A::ClassEnum);\
+ ";
+ const char* xmlCode = "\
+ <typesystem package=\"Foo\"> \
+ <value-type name='A'/> \
+ <enum-type name='GlobalEnum' />\
+ <enum-type name='A::ClassEnum' />\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ QCOMPARE(classes.count(), 1);
+
+ AbstractMetaEnumList globalEnums = t.builder()->globalEnums();
+ QCOMPARE(globalEnums.count(), 1);
+ QCOMPARE(globalEnums.first()->name(), QString("GlobalEnum"));
+
+ // enum as parameter of a function
+ AbstractMetaFunctionList functions = t.builder()->globalFunctions();
+ QCOMPARE(functions.count(), 1);
+ QCOMPARE(functions.first()->arguments().count(), 1);
+ QCOMPARE(functions.first()->arguments().first()->type()->cppSignature(), QString("A::ClassEnum"));
+
+ // enum as parameter of a method
+ AbstractMetaClass* classA = classes.findClass("A");
+ QCOMPARE(classA->enums().count(), 1);
+ AbstractMetaFunction* method = classA->queryFunctionsByName("method").first();
+ QVERIFY(method);
+ AbstractMetaArgument* arg = method->arguments().first();
+ QCOMPARE(arg->type()->name(), QString("ClassEnum"));
+ QCOMPARE(arg->type()->cppSignature(), QString("A::ClassEnum"));
+ QCOMPARE(functions.first()->arguments().count(), 1);
+ arg = functions.first()->arguments().first();
+ QCOMPARE(arg->type()->name(), QString("ClassEnum"));
+ QCOMPARE(arg->type()->cppSignature(), QString("A::ClassEnum"));
+
+ AbstractMetaEnumList classEnums = classA->enums();
+ QCOMPARE(classEnums.first()->name(), QString("ClassEnum"));
+
+
+}
+
+QTEST_APPLESS_MAIN(TestEnum)
+
+#include "testenum.moc"
diff --git a/tests/testenum.h b/tests/testenum.h
new file mode 100644
index 000000000..0fa026d27
--- /dev/null
+++ b/tests/testenum.h
@@ -0,0 +1,35 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#ifndef TESTENUM_H
+#define TESTENUM_H
+#include <QObject>
+
+class TestEnum : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testEnumCppSignature();
+};
+
+#endif \ No newline at end of file
diff --git a/tests/testutil.h b/tests/testutil.h
new file mode 100644
index 000000000..4ccf9a80c
--- /dev/null
+++ b/tests/testutil.h
@@ -0,0 +1,63 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+*
+* Contact: PySide team <contact@pyside.org>
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* version 2 as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA
+*
+*/
+
+#ifndef TESTUTIL_H
+#define TESTUTIL_H
+#include <QtCore/QBuffer>
+#include "abstractmetabuilder.h"
+#include "reporthandler.h"
+
+class TestUtil
+{
+public:
+ TestUtil(const char* cppCode, const char* xmlCode, bool silent = true) : m_builder(0)
+ {
+ ReportHandler::setSilent(silent);
+ m_builder = new AbstractMetaBuilder;
+ QBuffer buffer;
+ // parse typesystem
+ buffer.setData(xmlCode);
+ TypeDatabase::instance()->parseFile(&buffer);
+ buffer.close();
+ // parse C++ code
+ buffer.setData(cppCode);
+ bool res = m_builder->build(&buffer);
+ Q_ASSERT(res);
+ }
+
+ ~TestUtil()
+ {
+ delete m_builder;
+ m_builder = 0;
+ }
+
+ AbstractMetaBuilder* builder()
+ {
+ return m_builder;
+ }
+
+private:
+ AbstractMetaBuilder* m_builder;
+};
+
+#endif