aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.lima@openbossa.org>2010-04-14 19:32:37 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:09:59 -0300
commit74d3c1bb12280ffb2b810ee4bd1272ba6fb8127f (patch)
treec87daaa1939b537b50ea94c824f620d236717003 /tests
parent46cd570358601d83be0e23a378fc688d8ed706b6 (diff)
Added the "function" tag to ApiExtractor.
This change the behaviour of ApiExtractor regarding to global functions. All global function you want to be exported to python *need* to be especified in the type system with the function tag, otherwise they wont be exported at all. The syntax for this new tag is: <function signature="..." /> This is just the initial work for this tag, it is missign support for: - Function modifications. - Add a function overload with add-function tag.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testabstractmetatype.cpp3
-rw-r--r--tests/testenum.cpp7
-rw-r--r--tests/testfunctiontag.cpp64
-rw-r--r--tests/testfunctiontag.h36
5 files changed, 107 insertions, 4 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 61f40ce2e..189ff42a7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,3 +24,4 @@ declare_test(testreferencetopointer)
declare_test(testremoveimplconv)
declare_test(testreverseoperators)
declare_test(testtoposort)
+declare_test(testfunctiontag)
diff --git a/tests/testabstractmetatype.cpp b/tests/testabstractmetatype.cpp
index 3e75539fb..81e194fd3 100644
--- a/tests/testabstractmetatype.cpp
+++ b/tests/testabstractmetatype.cpp
@@ -30,6 +30,7 @@ void TestAbstractMetaType::testConstCharPtrType()
const char* cppCode ="const char* justAtest();";
const char* xmlCode = "<typesystem package=\"Foo\">\
<primitive-type name='char'/>\
+ <function signature='justAtest()' />\
</typesystem>";
TestUtil t(cppCode, xmlCode);
QCOMPARE(t.builder()->globalFunctions().size(), 1);
@@ -57,6 +58,7 @@ void TestAbstractMetaType::testCharType()
const char* xmlCode = "<typesystem package=\"Foo\">\
<primitive-type name='char'/>\
<value-type name='A' />\
+ <function signature='justAtest()' />\
</typesystem>";
TestUtil t(cppCode, xmlCode);
@@ -118,6 +120,7 @@ void TestAbstractMetaType::testTypedefWithTemplates()
const char* xmlCode = "<typesystem package=\"Foo\">\
<container-type name='A' type='list'/>\
<value-type name='B' />\
+ <function signature='func(A&lt;B&gt;)' />\
</typesystem>";
TestUtil t(cppCode, xmlCode);
diff --git a/tests/testenum.cpp b/tests/testenum.cpp
index 93a678e73..24cb4d963 100644
--- a/tests/testenum.cpp
+++ b/tests/testenum.cpp
@@ -41,12 +41,13 @@ void TestEnum::testEnumCppSignature()
<value-type name='A'/> \
<enum-type name='GlobalEnum' />\
<enum-type name='A::ClassEnum' />\
+ <function signature='func(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"));
@@ -56,7 +57,7 @@ void TestEnum::testEnumCppSignature()
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);
@@ -72,8 +73,6 @@ void TestEnum::testEnumCppSignature()
AbstractMetaEnumList classEnums = classA->enums();
QCOMPARE(classEnums.first()->name(), QString("ClassEnum"));
-
-
}
QTEST_APPLESS_MAIN(TestEnum)
diff --git a/tests/testfunctiontag.cpp b/tests/testfunctiontag.cpp
new file mode 100644
index 000000000..79e3142a5
--- /dev/null
+++ b/tests/testfunctiontag.cpp
@@ -0,0 +1,64 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2010 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 "testfunctiontag.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+void TestFunctionTag::testFunctionTagForSpecificSignature()
+{
+ const char cppCode[] = "void globalFunction(int); void globalFunction(float); void dummy()";
+ const char xmlCode[] = "\
+ <typesystem package=\"Foo\">\
+ <primitive-type name='int'/> \
+ <primitive-type name='float'/> \
+ <function signature='globalFunction(int)'/>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode, false);
+
+ FunctionTypeEntry* func = (FunctionTypeEntry*) TypeDatabase::instance()->findType("globalFunction");
+ QVERIFY(func);
+ QCOMPARE(t.builder()->globalFunctions().size(), 1);
+}
+
+void TestFunctionTag::testFunctionTagForAllSignatures()
+{
+ const char cppCode[] = "void globalFunction(int); void globalFunction(float); void dummy();";
+ const char xmlCode[] = "\
+ <typesystem package=\"Foo\">\
+ <primitive-type name='int'/> \
+ <primitive-type name='float'/> \
+ <function signature='globalFunction(int)'/>\
+ <function signature='globalFunction(float)'/>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode, false);
+
+ FunctionTypeEntry* func = (FunctionTypeEntry*) TypeDatabase::instance()->findType("globalFunction");
+ QVERIFY(func);
+ QCOMPARE(t.builder()->globalFunctions().size(), 2);
+}
+
+QTEST_APPLESS_MAIN(TestFunctionTag)
+
+#include "testfunctiontag.moc"
+
diff --git a/tests/testfunctiontag.h b/tests/testfunctiontag.h
new file mode 100644
index 000000000..8f42774c6
--- /dev/null
+++ b/tests/testfunctiontag.h
@@ -0,0 +1,36 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2010 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 TESTFUNCTIONTAG_H
+#define TESTFUNCTIONTAG_H
+#include <QObject>
+
+class TestFunctionTag : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testFunctionTagForSpecificSignature();
+ void testFunctionTagForAllSignatures();
+};
+
+#endif