aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-02-26 20:21:11 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-02-26 20:24:28 -0300
commit3f6b0576c90960d4474623987ccac2877a34869c (patch)
tree956d6a4848dbec230714cbdf8aad3b0e68524fde /tests
parenteaec9c4a8ace3a91fccb12492d445fc939cb8bf5 (diff)
Added method AbstractMetaBuilder::fixReturnTypeOfConversionOperator(func).
The new method fixes the return type of conversion operators: they should return the target of the conversion as type and not the type of its owner class. fixReturnTypeOfConversionOperator is used in traverseFunctions. An unit test was added for this case. Note that this behaviour could be fixed in the parser. I dare you!
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testconversionoperator.cpp71
-rw-r--r--tests/testconversionoperator.h35
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 961f80d3f..71efb9e90 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -11,6 +11,7 @@ declare_test(testabstractmetaclass)
declare_test(testabstractmetatype)
declare_test(testaddfunction)
declare_test(testcodeinjection)
+declare_test(testconversionoperator)
declare_test(testconversionruletag)
declare_test(testdtorinformation)
declare_test(testenum)
diff --git a/tests/testconversionoperator.cpp b/tests/testconversionoperator.cpp
new file mode 100644
index 000000000..cd4026bbd
--- /dev/null
+++ b/tests/testconversionoperator.cpp
@@ -0,0 +1,71 @@
+/*
+* 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 "testconversionoperator.h"
+#include <QtTest/QTest>
+#include "testutil.h"
+
+
+void TestConversionOperator::testConversionOperator()
+{
+ const char cppCode[] = "struct A {\
+ };\
+ struct B {\
+ operator A() const;\
+ };\
+ struct C {\
+ operator A() const;\
+ };";
+ const char xmlCode[] = "\
+ <typesystem package=\"Foo\">\
+ <value-type name='A' />\
+ <value-type name='B' />\
+ <value-type name='C' />\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* classA = classes.findClass("A");
+ AbstractMetaClass* classB = classes.findClass("B");
+ AbstractMetaClass* classC = classes.findClass("C");
+ QVERIFY(classA);
+ QVERIFY(classB);
+ QVERIFY(classC);
+ QCOMPARE(classA->functions().count(), 1);
+ QCOMPARE(classB->functions().count(), 2);
+ QCOMPARE(classC->functions().count(), 2);
+ QCOMPARE(classA->externalConversionOperators().count(), 2);
+
+ const AbstractMetaFunction* convOp = 0;
+ foreach(const AbstractMetaFunction* func, classB->functions()) {
+ if (func->isConversionOperator())
+ convOp = func;
+ }
+ QVERIFY(convOp);
+ const AbstractMetaFunction* externalConvOp = classA->externalConversionOperators().first();
+ QCOMPARE(convOp, externalConvOp);
+}
+
+QTEST_APPLESS_MAIN(TestConversionOperator)
+
+#include "testconversionoperator.moc"
diff --git a/tests/testconversionoperator.h b/tests/testconversionoperator.h
new file mode 100644
index 000000000..79963db1e
--- /dev/null
+++ b/tests/testconversionoperator.h
@@ -0,0 +1,35 @@
+/*
+* 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 TESTCONVERSIONOPERATOR_H
+#define TESTCONVERSIONOPERATOR_H
+#include <QObject>
+
+class TestConversionOperator : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testConversionOperator();
+};
+
+#endif