aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp101
1 files changed, 53 insertions, 48 deletions
diff --git a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp
index 3ad77c86f..f4eecff2c 100644
--- a/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp
+++ b/sources/shiboken6/ApiExtractor/tests/testreverseoperators.cpp
@@ -1,37 +1,16 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "testreverseoperators.h"
#include <QtTest/QTest>
#include "testutil.h"
+#include <abstractmetaargument.h>
#include <abstractmetafunction.h>
#include <abstractmetalang.h>
#include <typesystem.h>
+#include <clangparser/compilersupport.h>
+
+#include <algorithm>
void TestReverseOperators::testReverseSum()
{
@@ -46,16 +25,16 @@ void TestReverseOperators::testReverseSum()
</typesystem>";
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
- QVERIFY(!builder.isNull());
+ QVERIFY(builder);
AbstractMetaClassList classes = builder->classes();
- AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A"));
+ const auto classA = AbstractMetaClass::findClass(classes, "A");
QVERIFY(classA);
- QCOMPARE(classA->functions().count(), 4);
+ QCOMPARE(classA->functions().size(), 4);
AbstractMetaFunctionCPtr reverseOp;
AbstractMetaFunctionCPtr normalOp;
for (const auto &func : classA->functions()) {
- if (func->name() == QLatin1String("operator+")) {
+ if (func->name() == u"operator+") {
if (func->isReverseOperator())
reverseOp = func;
else
@@ -63,12 +42,12 @@ void TestReverseOperators::testReverseSum()
}
}
- QVERIFY(!normalOp.isNull());
+ QVERIFY(normalOp);
QVERIFY(!normalOp->isReverseOperator());
- QCOMPARE(normalOp->arguments().count(), 1);
- QVERIFY(!reverseOp.isNull());
+ QCOMPARE(normalOp->arguments().size(), 1);
+ QVERIFY(reverseOp);
QVERIFY(reverseOp->isReverseOperator());
- QCOMPARE(reverseOp->arguments().count(), 1);
+ QCOMPARE(reverseOp->arguments().size(), 1);
}
void TestReverseOperators::testReverseSumWithAmbiguity()
@@ -88,37 +67,63 @@ void TestReverseOperators::testReverseSumWithAmbiguity()
</typesystem>";
QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
- QVERIFY(!builder.isNull());
+ QVERIFY(builder);
AbstractMetaClassList classes = builder->classes();
- const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A"));
+ const auto classA = AbstractMetaClass::findClass(classes, "A");
QVERIFY(classA);
- QCOMPARE(classA->functions().count(), 4);
+ QCOMPARE(classA->functions().size(), 4);
- const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, QLatin1String("B"));
+ const auto classB = AbstractMetaClass::findClass(classes, "B");
QVERIFY(classB);
- QCOMPARE(classB->functions().count(), 4);
+ QCOMPARE(classB->functions().size(), 4);
AbstractMetaFunctionCPtr reverseOp;
AbstractMetaFunctionCPtr normalOp;
for (const auto &func : classB->functions()) {
- if (func->name() == QLatin1String("operator+")) {
+ if (func->name() == u"operator+") {
if (func->isReverseOperator())
reverseOp = func;
else
normalOp = func;
}
}
- QVERIFY(!normalOp.isNull());
+ QVERIFY(normalOp);
QVERIFY(!normalOp->isReverseOperator());
- QCOMPARE(normalOp->arguments().count(), 1);
- QCOMPARE(normalOp->minimalSignature(), QLatin1String("operator+(B,A)"));
- QVERIFY(!reverseOp.isNull());
+ QCOMPARE(normalOp->arguments().size(), 1);
+ QCOMPARE(normalOp->minimalSignature(), u"operator+(B,A)");
+ QVERIFY(reverseOp);
QVERIFY(reverseOp->isReverseOperator());
- QCOMPARE(reverseOp->arguments().count(), 1);
- QCOMPARE(reverseOp->minimalSignature(), QLatin1String("operator+(A,B)"));
+ QCOMPARE(reverseOp->arguments().size(), 1);
+ QCOMPARE(reverseOp->minimalSignature(), u"operator+(A,B)");
}
-
+void TestReverseOperators::testSpaceshipOperator()
+{
+ const char cppCode[] = R"(
+ class Test {
+ public:
+ explicit Test(int v);
+ int operator<=>(const Test &rhs) const = default;
+ };)";
+ const char xmlCode[] = R"(
+ <typesystem package="Foo">
+ <value-type name='Test'/>
+ </typesystem>)";
+ QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false,
+ {}, {}, LanguageLevel::Cpp20));
+ QVERIFY(builder);
+ AbstractMetaClassList classes = builder->classes();
+ QCOMPARE(classes.size(), 1);
+ const auto testClass = AbstractMetaClass::findClass(classes, "Test");
+ QVERIFY(testClass);
+ const auto &functions = testClass->functions();
+ // 6 operators should be synthesized
+ const auto count = std::count_if(functions.cbegin(), functions.cend(),
+ [](const AbstractMetaFunctionCPtr &f) {
+ return f->isComparisonOperator();
+ });
+ QCOMPARE(count, 6);
+}
QTEST_APPLESS_MAIN(TestReverseOperators)