aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testconversionoperator.cpp
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/testconversionoperator.cpp
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/testconversionoperator.cpp')
-rw-r--r--tests/testconversionoperator.cpp71
1 files changed, 71 insertions, 0 deletions
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"