diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/testreverseoperators.cpp | 68 | ||||
-rw-r--r-- | tests/testreverseoperators.h | 35 |
3 files changed, 104 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6304c2433..5a104907d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,3 +13,4 @@ declare_test(testenum) declare_test(testmodifydocumentation) declare_test(testaddfunction) declare_test(testconversionruletag) +declare_test(testreverseoperators) diff --git a/tests/testreverseoperators.cpp b/tests/testreverseoperators.cpp new file mode 100644 index 000000000..70ca8d264 --- /dev/null +++ b/tests/testreverseoperators.cpp @@ -0,0 +1,68 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2009 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 "testreverseoperators.h" +#include <QtTest/QTest> +#include "testutil.h" + + +void TestReverseOperators::testReverseSum() +{ + const char cppCode[] = "struct A {\ + A& operator+(int);\ + };\ + A& operator+(int, const A&);"; + const char xmlCode[] = "\ + <typesystem package=\"Foo\">\ + <primitive-type name='int' />\ + <value-type name='A' />\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, false); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classA = classes.findClass("A"); + QVERIFY(classA); + QCOMPARE(classA->functions().count(), 3); + + const AbstractMetaFunction* reverseOp = 0; + const AbstractMetaFunction* normalOp = 0; + foreach(const AbstractMetaFunction* func, classA->functions()) { + if (func->name() == "operator+") { + if (func->isReverseOperator()) + reverseOp = func; + else + normalOp = func; + } + } + + QVERIFY(normalOp); + QVERIFY(!normalOp->isReverseOperator()); + QCOMPARE(normalOp->arguments().count(), 1); + QVERIFY(reverseOp); + QVERIFY(reverseOp->isReverseOperator()); + QCOMPARE(reverseOp->arguments().count(), 1); +} + +QTEST_APPLESS_MAIN(TestReverseOperators) + +#include "testreverseoperators.moc" diff --git a/tests/testreverseoperators.h b/tests/testreverseoperators.h new file mode 100644 index 000000000..470e576cc --- /dev/null +++ b/tests/testreverseoperators.h @@ -0,0 +1,35 @@ +/* +* This file is part of the API Extractor project. +* +* Copyright (C) 2009 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 TESTREVERSEOPERATORS_H +#define TESTREVERSEOPERATORS_H +#include <QObject> + +class TestReverseOperators : public QObject +{ + Q_OBJECT +private slots: + void testReverseSum(); +}; + +#endif |