aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-07-25 16:28:10 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-09 19:10:17 -0300
commitdda325de53c44decafe8f95a803e561b66dbe43f (patch)
treeeafb14d5c62496cc87922922de4135dcc52e734c
parent4430af6307cc0aa599f99eb7aaa5570eb80a7bc2 (diff)
Fixed TypeEntry::isCppPrimitive() to process typedefs and "long long" type.
And added an unit test.
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testnumericaltypedef.cpp71
-rw-r--r--tests/testnumericaltypedef.h36
-rw-r--r--typesystem.cpp9
4 files changed, 115 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 02537dea..d2e84c60 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -31,6 +31,7 @@ declare_test(testmodifyfunction)
declare_test(testmultipleinheritance)
declare_test(testnamespace)
declare_test(testnestedtypes)
+declare_test(testnumericaltypedef)
declare_test(testprimitivetypetag)
declare_test(testrefcounttag)
declare_test(testreferencetopointer)
diff --git a/tests/testnumericaltypedef.cpp b/tests/testnumericaltypedef.cpp
new file mode 100644
index 00000000..c479b8d6
--- /dev/null
+++ b/tests/testnumericaltypedef.cpp
@@ -0,0 +1,71 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2011 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 "testnumericaltypedef.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+void TestNumericalTypedef::testNumericalTypedef()
+{
+ const char* cppCode ="\
+ typedef double real;\
+ void funcDouble(double);\
+ void funcReal(real);\
+ ";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <primitive-type name='double' /> \
+ <primitive-type name='real' /> \
+ <function signature='funcDouble(double)' />\
+ <function signature='funcReal(real)' />\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode, false);
+
+ QCOMPARE(t.builder()->globalFunctions().size(), 2);
+ const AbstractMetaFunction* funcDouble = t.builder()->globalFunctions().first();
+ QVERIFY(funcDouble);
+ const AbstractMetaFunction* funcReal = t.builder()->globalFunctions().last();
+ QVERIFY(funcReal);
+
+ if (funcDouble->name() == "funcReal")
+ std::swap(funcDouble, funcReal);
+
+ QCOMPARE(funcDouble->minimalSignature(), QString("funcDouble(double)"));
+ QCOMPARE(funcReal->minimalSignature(), QString("funcReal(real)"));
+
+ const AbstractMetaType* doubleType = funcDouble->arguments().first()->type();
+ QVERIFY(doubleType);
+ QCOMPARE(doubleType->cppSignature(), QString("double"));
+ QVERIFY(doubleType->isPrimitive());
+ QVERIFY(doubleType->typeEntry()->isCppPrimitive());
+
+ const AbstractMetaType* realType = funcReal->arguments().first()->type();
+ QVERIFY(realType);
+ QCOMPARE(realType->cppSignature(), QString("real"));
+ QVERIFY(realType->isPrimitive());
+ QVERIFY(realType->typeEntry()->isCppPrimitive());
+}
+
+QTEST_APPLESS_MAIN(TestNumericalTypedef)
+
+#include "testnumericaltypedef.moc"
diff --git a/tests/testnumericaltypedef.h b/tests/testnumericaltypedef.h
new file mode 100644
index 00000000..ee11e63e
--- /dev/null
+++ b/tests/testnumericaltypedef.h
@@ -0,0 +1,36 @@
+/*
+* This file is part of the API Extractor project.
+*
+* Copyright (C) 2011 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 TESTNUMERICALTYPEDEF_H
+#define TESTNUMERICALTYPEDEF_H
+
+#include <QObject>
+
+class TestNumericalTypedef : public QObject
+{
+ Q_OBJECT
+ private slots:
+ void testNumericalTypedef();
+};
+
+#endif
diff --git a/typesystem.cpp b/typesystem.cpp
index b653bd57..c54a12db 100644
--- a/typesystem.cpp
+++ b/typesystem.cpp
@@ -2095,13 +2095,18 @@ static bool strLess(const char* a, const char* b)
bool TypeEntry::isCppPrimitive() const
{
+ if (!isPrimitive())
+ return false;
if (m_name.contains(' ') || m_type == VoidType)
return true;
// Keep this sorted!!
- static const char* cppTypes[] = { "bool", "char", "double", "float", "int", "long", "short", "wchar_t"};
+ static const char* cppTypes[] = { "bool", "char", "double", "float", "int", "long", "long long", "short", "wchar_t"};
const int N = sizeof(cppTypes)/sizeof(char*);
- const char** res = qBinaryFind(&cppTypes[0], &cppTypes[N], m_name.toAscii().constData(), strLess);
+ PrimitiveTypeEntry* aliasedType = ((PrimitiveTypeEntry*)this)->basicAliasedTypeEntry();
+ QString typeName = aliasedType ? aliasedType->name() : m_name;
+
+ const char** res = qBinaryFind(&cppTypes[0], &cppTypes[N], typeName.toAscii().constData(), strLess);
return res != &cppTypes[N];
}