diff --git a/src/grpc/qgrpccalloptions.cpp b/src/grpc/qgrpccalloptions.cpp index 23715477..6cb8a59f 100644 --- a/src/grpc/qgrpccalloptions.cpp +++ b/src/grpc/qgrpccalloptions.cpp @@ -16,6 +16,7 @@ using namespace Qt::StringLiterals; /*! \class QGrpcCallOptions \inmodule QtGrpc + \compares equality \brief The QGrpcCallOptions class offers various options for fine-tuning individual RPCs. \since 6.6 @@ -299,6 +300,13 @@ QGrpcCallOptions &QGrpcCallOptions::setFilterServerMetadata(bool value) return *this; } +bool comparesEqual(const QGrpcCallOptions &lhs, const QGrpcCallOptions &rhs) +{ + return lhs.deadlineTimeout() == rhs.deadlineTimeout() + && lhs.filterServerMetadata() == rhs.filterServerMetadata() + && lhs.metadata(QtGrpc::MultiValue) == rhs.metadata(QtGrpc::MultiValue); +} + #ifndef QT_NO_DEBUG_STREAM /*! \since 6.8 diff --git a/src/grpc/qgrpccalloptions.h b/src/grpc/qgrpccalloptions.h index 79e090ef..aa935912 100644 --- a/src/grpc/qgrpccalloptions.h +++ b/src/grpc/qgrpccalloptions.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,10 @@ public: private: QExplicitlySharedDataPointer d_ptr; + friend Q_GRPC_EXPORT bool comparesEqual(const QGrpcCallOptions &lhs, + const QGrpcCallOptions &rhs); + Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QGrpcCallOptions) + #ifndef QT_NO_DEBUG_STREAM friend Q_GRPC_EXPORT QDebug operator<<(QDebug debug, const QGrpcCallOptions &callOpts); #endif diff --git a/src/grpc/qgrpcchanneloptions.cpp b/src/grpc/qgrpcchanneloptions.cpp index 0ad997a7..975f8b8a 100644 --- a/src/grpc/qgrpcchanneloptions.cpp +++ b/src/grpc/qgrpcchanneloptions.cpp @@ -19,6 +19,7 @@ using namespace QtGrpc; \class QGrpcChannelOptions \inmodule QtGrpc \since 6.6 + \compares equality \brief The QGrpcChannelOptions class offers various options for fine-tuning a gRPC channel. @@ -380,6 +381,18 @@ std::optional QGrpcChannelOptions::sslConfiguration() const } #endif +bool comparesEqual(const QGrpcChannelOptions &lhs, const QGrpcChannelOptions &rhs) +{ + return lhs.deadlineTimeout() == rhs.deadlineTimeout() + && lhs.filterServerMetadata() == rhs.filterServerMetadata() + && lhs.metadata(QtGrpc::MultiValue) == rhs.metadata(QtGrpc::MultiValue) + && lhs.serializationFormat() == rhs.serializationFormat() +#if QT_CONFIG(ssl) + && lhs.sslConfiguration() == rhs.sslConfiguration() +#endif + ; +} + #ifndef QT_NO_DEBUG_STREAM /*! \since 6.8 diff --git a/src/grpc/qgrpcchanneloptions.h b/src/grpc/qgrpcchanneloptions.h index 7957515a..30616eb7 100644 --- a/src/grpc/qgrpcchanneloptions.h +++ b/src/grpc/qgrpcchanneloptions.h @@ -11,6 +11,7 @@ # include #endif +#include #include #include #include @@ -86,6 +87,10 @@ public: private: QExplicitlySharedDataPointer d_ptr; + friend Q_GRPC_EXPORT bool comparesEqual(const QGrpcChannelOptions &lhs, + const QGrpcChannelOptions &rhs); + Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QGrpcChannelOptions) + #ifndef QT_NO_DEBUG_STREAM friend Q_GRPC_EXPORT QDebug operator<<(QDebug debug, const QGrpcChannelOptions &chOpts); #endif diff --git a/tests/auto/grpc/qgrpccalloptions/CMakeLists.txt b/tests/auto/grpc/qgrpccalloptions/CMakeLists.txt index 21837c30..429e6283 100644 --- a/tests/auto/grpc/qgrpccalloptions/CMakeLists.txt +++ b/tests/auto/grpc/qgrpccalloptions/CMakeLists.txt @@ -15,5 +15,6 @@ qt_internal_add_test(tst_qgrpccalloptions LIBRARIES Qt::Core Qt::Test + Qt::TestPrivate Qt::Grpc ) diff --git a/tests/auto/grpc/qgrpccalloptions/tst_qgrpccalloptions.cpp b/tests/auto/grpc/qgrpccalloptions/tst_qgrpccalloptions.cpp index 5aeff9e7..71a558ea 100644 --- a/tests/auto/grpc/qgrpccalloptions/tst_qgrpccalloptions.cpp +++ b/tests/auto/grpc/qgrpccalloptions/tst_qgrpccalloptions.cpp @@ -23,6 +23,7 @@ private Q_SLOTS: void propertyDeadline() const { common.propertyDeadline(); } void propertyFilterServerMetadata() const { common.propertyFilterServerMetadata(); } void streamsToDebug() const { common.streamsToDebug(); } + void comparesEqual() const { common.comparesEqual(); } private: GrpcCommonOptionsTest common; diff --git a/tests/auto/grpc/qgrpcchanneloptions/CMakeLists.txt b/tests/auto/grpc/qgrpcchanneloptions/CMakeLists.txt index 6ba70100..84f68e2f 100644 --- a/tests/auto/grpc/qgrpcchanneloptions/CMakeLists.txt +++ b/tests/auto/grpc/qgrpcchanneloptions/CMakeLists.txt @@ -15,5 +15,6 @@ qt_internal_add_test(tst_qgrpcchanneloptions LIBRARIES Qt::Core Qt::Test + Qt::TestPrivate Qt::Grpc ) diff --git a/tests/auto/grpc/qgrpcchanneloptions/tst_qgrpcchanneloptions.cpp b/tests/auto/grpc/qgrpcchanneloptions/tst_qgrpcchanneloptions.cpp index 82ad8c53..ad021620 100644 --- a/tests/auto/grpc/qgrpcchanneloptions/tst_qgrpcchanneloptions.cpp +++ b/tests/auto/grpc/qgrpcchanneloptions/tst_qgrpcchanneloptions.cpp @@ -26,6 +26,7 @@ private Q_SLOTS: void propertyDeadline() const { common.propertyDeadline(); } void propertyFilterServerMetadata() const { common.propertyFilterServerMetadata(); } void streamsToDebug() const { common.streamsToDebug(); } + void comparesEqual() const { common.comparesEqual(); } void propertySerializationFormat() const; #if QT_CONFIG(ssl) diff --git a/tests/auto/grpc/shared/grpccommonoptions.h b/tests/auto/grpc/shared/grpccommonoptions.h index 9d81e174..a3cbb42d 100644 --- a/tests/auto/grpc/shared/grpccommonoptions.h +++ b/tests/auto/grpc/shared/grpccommonoptions.h @@ -1,13 +1,19 @@ // Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#include #include +#include #include +#if QT_CONFIG(ssl) +# include +#endif + #include -#include #include +#include using namespace std::chrono_literals; @@ -253,4 +259,33 @@ QT_WARNING_POP std::unique_ptr ustr(QTest::toString(o)); QCOMPARE_EQ(storage, QString::fromUtf8(ustr.get())); } + void comparesEqual() const + { + QTestPrivate::testEqualityOperatorsCompile(); + T o1; + T o2 = o1; + + QT_TEST_EQUALITY_OPS(o1, o2, true); + auto updateComparisonCheck = [&] { + QT_TEST_EQUALITY_OPS(o1, o2, false); + o2 = o1; + QT_TEST_EQUALITY_OPS(o1, o2, true); + }; + + o1.addMetadata("new", "value"); + updateComparisonCheck(); + o1.setDeadlineTimeout(1s); + updateComparisonCheck(); + o1.setFilterServerMetadata(true); + updateComparisonCheck(); + + if constexpr (std::is_same_v) { + o1.setSerializationFormat(QtGrpc::SerializationFormat::Protobuf); + updateComparisonCheck(); +#if QT_CONFIG(ssl) + o1.setSslConfiguration(QSslConfiguration::defaultConfiguration()); + updateComparisonCheck(); +#endif + } + } };