aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-11-05 20:20:58 -0200
committerHugo Lima <hugo.lima@openbossa.org>2009-11-09 15:46:13 -0200
commit85be0d4d548bef2b249026d80dfb59274253bb17 (patch)
treeaede83c7f66c126f01f9c2220615674e96a6e82d
parent6067084bbfb6d479bcb886c73dba402c71257765 (diff)
- All reverse operators are now properly tagged as "reverse operator".
- Reverse operators aren't tagged as static methods anymore. - Reverse operators now have just one parameter, the one that matters. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r--abstractmetabuilder.cpp8
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/testreverseoperators.cpp68
-rw-r--r--tests/testreverseoperators.h35
4 files changed, 108 insertions, 4 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index 9c739c633..e69fd03a9 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -194,10 +194,10 @@ void AbstractMetaBuilder::traverseOperatorFunction(FunctionModelItem item)
// not of the same type of its owning class we suppose that it
// must be an reverse operator (e.g. CLASS::operator(TYPE, CLASS)).
// All operator overloads that operate over a class are already
- // beign added as member functions of that class by the API Extractor,
- // in addition to this the reverse operators are marked as static
- // for identification purposes.
- *metaFunction += AbstractMetaAttributes::Static;
+ // beign added as member functions of that class by the API Extractor.
+ arguments.pop_back();
+ metaFunction->setArguments(arguments);
+ metaFunction->setReverseOperator(true);
}
metaFunction->setFunctionType(AbstractMetaFunction::NormalFunction);
metaFunction->setVisibility(AbstractMetaFunction::Public);
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