aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-09-23 17:19:15 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:10 -0300
commiteac6125bac2029389594c8bad0b0fa48cffe1d6b (patch)
tree410eef5116d5523b947ed6864a50a2d35dfb420f
parent5633a2dbe3aba94292e1e3d03ccabe8cf25b802a (diff)
Argument types that are arrays with specified sizes are correctly recognized.
The AbstractMetaBuilder::translateType method now tries to figure out properly the size of array argument types specified with enum items instead of literal numbers. Test cases were also added. Reviewed by Luciano Wolf <luciano.wolf@openbossa.org> Reviewed by Renato Araújo <renato.filho@openbossa.org>
-rw-r--r--abstractmetabuilder.cpp24
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testarrayargument.cpp121
-rw-r--r--tests/testarrayargument.h37
4 files changed, 180 insertions, 3 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index d5a2bb131..6b22a6ddf 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -401,6 +401,8 @@ bool AbstractMetaBuilder::build(QIODevice* input)
}
ReportHandler::flush();
+ figureOutEnumValues();
+
foreach (ClassModelItem item, typeValues)
traverseClassMembers(item);
foreach (NamespaceModelItem item, namespaceTypeValues)
@@ -560,7 +562,6 @@ bool AbstractMetaBuilder::build(QIODevice* input)
traverseStreamOperator(item);
}
- figureOutEnumValues();
figureOutDefaultEnumArguments();
checkFunctionModifications();
@@ -1943,8 +1944,25 @@ AbstractMetaType* AbstractMetaBuilder::translateType(const TypeInfo& _typei, boo
bool ok;
int elems = s.toInt(&ok);
- if (!ok)
- return 0;
+ if (!ok) {
+ AbstractMetaEnumValue* enumValue = m_metaClasses.findEnumValue(s);
+ if (!enumValue) {
+ foreach (AbstractMetaEnum* metaEnum, m_globalEnums) {
+ foreach (AbstractMetaEnumValue* ev, metaEnum->values()) {
+ if (ev->name() == s) {
+ enumValue = ev;
+ break;
+ }
+ }
+ if (enumValue)
+ break;
+ }
+ }
+
+ if (!enumValue)
+ return 0;
+ elems = enumValue->value();
+ }
AbstractMetaType* arrayType = createMetaType();
arrayType->setArrayElementCount(elems);
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a4cb4a13b..5646b3780 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -10,6 +10,7 @@ endmacro(declare_test testname)
declare_test(testabstractmetaclass)
declare_test(testabstractmetatype)
declare_test(testaddfunction)
+declare_test(testarrayargument)
declare_test(testcodeinjection)
declare_test(testcontainer)
declare_test(testconversionoperator)
diff --git a/tests/testarrayargument.cpp b/tests/testarrayargument.cpp
new file mode 100644
index 000000000..7750ded59
--- /dev/null
+++ b/tests/testarrayargument.cpp
@@ -0,0 +1,121 @@
+/*
+* 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 "testarrayargument.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+void TestArrayArgument::testArrayArgumentWithSizeDefinedByInteger()
+{
+ const char* cppCode ="\
+ struct A { \
+ enum SomeEnum { Value0, Value1, NValues }; \
+ void method(double[3]); \
+ };";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <primitive-type name='double'/>\
+ <object-type name='A'>\
+ <enum-type name='SomeEnum'/>\
+ </object-type>\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClass* classA = t.builder()->classes().findClass("A");
+ QVERIFY(classA);
+
+ const AbstractMetaArgument* arg = classA->functions().last()->arguments().first();
+ QVERIFY(arg->type()->isArray());
+ QCOMPARE(arg->type()->arrayElementCount(), 3);
+ QCOMPARE(arg->type()->arrayElementType()->name(), QString("double"));
+}
+
+void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValue()
+{
+ const char* cppCode ="\
+ struct A { \
+ enum SomeEnum { Value0, Value1, NValues }; \
+ void method(double[NValues]); \
+ };";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <primitive-type name='double'/>\
+ <object-type name='A'>\
+ <enum-type name='SomeEnum'/>\
+ </object-type>\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClass* classA = t.builder()->classes().findClass("A");
+ QVERIFY(classA);
+
+ AbstractMetaEnum* someEnum = classA->findEnum("SomeEnum");
+ QVERIFY(someEnum);
+ AbstractMetaEnumValue* nvalues = classA->findEnumValue("NValues", someEnum);
+ QVERIFY(nvalues);
+
+ const AbstractMetaArgument* arg = classA->functions().last()->arguments().first();
+ QVERIFY(arg->type()->isArray());
+ QCOMPARE(arg->type()->arrayElementCount(), nvalues->value());
+ QCOMPARE(arg->type()->arrayElementType()->name(), QString("double"));
+};
+
+void TestArrayArgument::testArrayArgumentWithSizeDefinedByEnumValueFromGlobalEnum()
+{
+ const char* cppCode ="\
+ enum SomeEnum { Value0, Value1, NValues }; \
+ struct A { \
+ void method(double[NValues]); \
+ };";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <primitive-type name='double'/>\
+ <enum-type name='SomeEnum'/>\
+ <object-type name='A'>\
+ </object-type>\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClass* classA = t.builder()->classes().findClass("A");
+ QVERIFY(classA);
+
+ AbstractMetaEnum* someEnum = t.builder()->globalEnums().first();
+ QVERIFY(someEnum);
+ AbstractMetaEnumValue* nvalues = 0;
+ foreach (AbstractMetaEnumValue* enumValue, someEnum->values()) {
+ if (enumValue->name() == "NValues") {
+ nvalues = enumValue;
+ break;
+ }
+ }
+ QVERIFY(nvalues);
+
+ const AbstractMetaArgument* arg = classA->functions().last()->arguments().first();
+ QVERIFY(arg->type()->isArray());
+ QCOMPARE(arg->type()->arrayElementCount(), nvalues->value());
+ QCOMPARE(arg->type()->arrayElementType()->name(), QString("double"));
+};
+
+QTEST_APPLESS_MAIN(TestArrayArgument)
+
+#include "testarrayargument.moc"
diff --git a/tests/testarrayargument.h b/tests/testarrayargument.h
new file mode 100644
index 000000000..44cb6a6cb
--- /dev/null
+++ b/tests/testarrayargument.h
@@ -0,0 +1,37 @@
+/*
+* 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 TESTARRAYARGUMENT_H
+#define TESTARRAYARGUMENT_H
+#include <QObject>
+
+class TestArrayArgument : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testArrayArgumentWithSizeDefinedByInteger();
+ void testArrayArgumentWithSizeDefinedByEnumValue();
+ void testArrayArgumentWithSizeDefinedByEnumValueFromGlobalEnum();
+};
+
+#endif