From 74d3c1bb12280ffb2b810ee4bd1272ba6fb8127f Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Wed, 14 Apr 2010 19:32:37 -0300 Subject: 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: This is just the initial work for this tag, it is missign support for: - Function modifications. - Add a function overload with add-function tag. --- tests/CMakeLists.txt | 1 + tests/testabstractmetatype.cpp | 3 ++ tests/testenum.cpp | 7 ++--- tests/testfunctiontag.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++ tests/testfunctiontag.h | 36 ++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 tests/testfunctiontag.cpp create mode 100644 tests/testfunctiontag.h (limited to 'tests') 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 = "\ \ + \ "; TestUtil t(cppCode, xmlCode); QCOMPARE(t.builder()->globalFunctions().size(), 1); @@ -57,6 +58,7 @@ void TestAbstractMetaType::testCharType() const char* xmlCode = "\ \ \ + \ "; TestUtil t(cppCode, xmlCode); @@ -118,6 +120,7 @@ void TestAbstractMetaType::testTypedefWithTemplates() const char* xmlCode = "\ \ \ + \ "; 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() \ \ \ + \ "; 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 +* +* 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 +#include "testutil.h" + +void TestFunctionTag::testFunctionTagForSpecificSignature() +{ + const char cppCode[] = "void globalFunction(int); void globalFunction(float); void dummy()"; + const char xmlCode[] = "\ + \ + \ + \ + \ + "; + 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[] = "\ + \ + \ + \ + \ + \ + "; + 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 +* +* 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 + +class TestFunctionTag : public QObject +{ + Q_OBJECT +private slots: + void testFunctionTagForSpecificSignature(); + void testFunctionTagForAllSignatures(); +}; + +#endif -- cgit v1.2.3