diff options
author | Dennis Oberst <dennis.oberst@qt.io> | 2024-04-05 09:50:05 +0200 |
---|---|---|
committer | Dennis Oberst <dennis.oberst@qt.io> | 2024-04-10 18:02:36 +0200 |
commit | af7ad89abb5f66a59f7a2072bf49474a00ff1609 (patch) | |
tree | a8128e2e2fdcb46569bd2030dff6763d6a774b74 | |
parent | bbf73aea1331a42b8f4b349e9e2caf88b486241d (diff) |
QGrpcSerializationFormat: mark single arg ctor as explicit
Task-number: QTBUG-123625
Pick-to: 6.7
Change-Id: I9e156bfde5f47c206c92f9f3153f29e4acb842ef
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
-rw-r--r-- | src/grpc/qgrpchttp2channel.cpp | 13 | ||||
-rw-r--r-- | src/grpc/qgrpcserializationformat.h | 2 | ||||
-rw-r--r-- | src/grpcquick/qqmlgrpcchanneloptions.cpp | 19 | ||||
-rw-r--r-- | tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp | 125 |
4 files changed, 87 insertions, 72 deletions
diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index 2ccf7bd..f884b94 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -74,7 +74,7 @@ using namespace Qt::StringLiterals; }; auto channel = std::make_shared< QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } - .withSerializationFormat({ "dummy", + .withSerializationFormat(QGrpcSerializationFormat{ "dummy", std::make_shared<DummySerializer>() })); \endcode @@ -505,15 +505,16 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QGrpcChannelOptions &op if (it != channelOptions.metadata().end()) { if (formatSuffix.isEmpty() && it->second != DefaultContentType) { if (it->second == "application/grpc+json") { - channelOptions.withSerializationFormat({ QGrpcSerializationFormat::Format::Json }); + channelOptions.withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Json }); } else if (it->second == "application/grpc+proto" || it->second == DefaultContentType) { - channelOptions - .withSerializationFormat({ QGrpcSerializationFormat::Format::Protobuf }); + channelOptions.withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Protobuf }); } else { qGrpcWarning() << "Cannot choose the serializer for " << ContentTypeHeader << it->second << ". Using protobuf format as the default one."; - channelOptions - .withSerializationFormat({ QGrpcSerializationFormat::Format::Default }); + channelOptions.withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Default }); } } else if (it->second != contentTypeFromOptions) { warnAboutFormatConflict = true; diff --git a/src/grpc/qgrpcserializationformat.h b/src/grpc/qgrpcserializationformat.h index 0fb481c..2dd1a3d 100644 --- a/src/grpc/qgrpcserializationformat.h +++ b/src/grpc/qgrpcserializationformat.h @@ -24,7 +24,7 @@ public: Json, }; - QGrpcSerializationFormat(Format format = Format::Default); + explicit QGrpcSerializationFormat(Format format = Format::Default); QGrpcSerializationFormat(QByteArrayView suffix, std::shared_ptr<QAbstractProtobufSerializer> serializer); diff --git a/src/grpcquick/qqmlgrpcchanneloptions.cpp b/src/grpcquick/qqmlgrpcchanneloptions.cpp index 8eed153..ad07c98 100644 --- a/src/grpcquick/qqmlgrpcchanneloptions.cpp +++ b/src/grpcquick/qqmlgrpcchanneloptions.cpp @@ -24,9 +24,7 @@ public: #endif // QT_CONFIG(ssl) }; -QQmlGrpcChannelOptionsPrivate::QQmlGrpcChannelOptionsPrivate() - : QObjectPrivate(), - m_options(QUrl()) +QQmlGrpcChannelOptionsPrivate::QQmlGrpcChannelOptionsPrivate() : QObjectPrivate(), m_options(QUrl()) { } @@ -49,8 +47,8 @@ void QQmlGrpcChannelOptions::setHost(const QUrl &newUrl) qint64 QQmlGrpcChannelOptions::deadline() const { - std::chrono::milliseconds ms - = d_func()->m_options.deadline().value_or(std::chrono::milliseconds(0)); + std::chrono::milliseconds + ms = d_func()->m_options.deadline().value_or(std::chrono::milliseconds(0)); return ms.count(); } @@ -85,20 +83,19 @@ void QQmlGrpcChannelOptions::setMetadata(QQmlGrpcMetadata *value) } } -QQmlSerializationFormat::GrpcSerializationFormat -QQmlGrpcChannelOptions::serializationFormat() const +QQmlSerializationFormat::GrpcSerializationFormat QQmlGrpcChannelOptions::serializationFormat() const { return d_func()->m_format; } -void QQmlGrpcChannelOptions::setSerializationFormat( - QQmlSerializationFormat::GrpcSerializationFormat format) +void QQmlGrpcChannelOptions::setSerializationFormat(QQmlSerializationFormat::GrpcSerializationFormat + format) { Q_D(QQmlGrpcChannelOptions); if (d->m_format != format) { d->m_format = format; - d->m_options.withSerializationFormat( - {static_cast<QGrpcSerializationFormat::Format>(format)} ); + d->m_options.withSerializationFormat(QGrpcSerializationFormat{ + static_cast<QGrpcSerializationFormat::Format>(format) }); emit serializationFormatChanged(); } } diff --git a/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp b/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp index c906ef5..69d313f 100644 --- a/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp +++ b/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp @@ -30,14 +30,9 @@ public: virtual QString deserializationErrorString() const override { return {}; } protected: - virtual QByteArray - serializeMessage(const QProtobufMessage *) const override - { - return {}; - } + virtual QByteArray serializeMessage(const QProtobufMessage *) const override { return {}; } - virtual bool deserializeMessage(QProtobufMessage *, - QByteArrayView) const override + virtual bool deserializeMessage(QProtobufMessage *, QByteArrayView) const override { return true; } @@ -46,20 +41,14 @@ protected: const QtProtobufPrivate::QProtobufPropertyOrderingInfo &) const override { } - bool deserializeObject(QProtobufMessage *) const override - { - return true; - } + bool deserializeObject(QProtobufMessage *) const override { return true; } void serializeListObject(const QProtobufMessage *, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &) const override { } - bool deserializeListObject(QProtobufMessage *) const override - { - return true; - } + bool deserializeListObject(QProtobufMessage *) const override { return true; } void serializeMapPair(const QVariant &, const QVariant &, const QtProtobufPrivate::QProtobufPropertyOrderingInfo &) const override @@ -83,7 +72,7 @@ protected: return true; } }; -} +} // namespace class QGrpcHttp2ChannelTest : public QObject { @@ -106,7 +95,6 @@ void QGrpcHttp2ChannelTest::CheckMethodsGeneration() client.testMethod(request, &client, [](std::shared_ptr<QGrpcCallReply>) {}); } - void QGrpcHttp2ChannelTest::AttachChannelThreadTest() { std::shared_ptr<QGrpcHttp2Channel> channel; @@ -128,9 +116,9 @@ void QGrpcHttp2ChannelTest::AttachChannelThreadTest() QTRY_COMPARE_EQ(clientErrorSpy.count(), 1); QCOMPARE(qvariant_cast<QGrpcStatus>(clientErrorSpy.at(0).first()).code(), QGrpcStatus::Unknown); QVERIFY(qvariant_cast<QGrpcStatus>(clientErrorSpy.at(0).first()) - .message() - .startsWith("QAbstractGrpcClient::attachChannel is called from a different " - "thread.")); + .message() + .startsWith("QAbstractGrpcClient::attachChannel is called from a different " + "thread.")); } void QGrpcHttp2ChannelTest::SerializationFormat() @@ -142,14 +130,14 @@ void QGrpcHttp2ChannelTest::SerializationFormat() channel = std::make_shared< QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Json })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Json })); QVERIFY(dynamic_cast<QProtobufJsonSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Protobuf })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Protobuf })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< @@ -162,53 +150,68 @@ void QGrpcHttp2ChannelTest::SerializationFormat() void QGrpcHttp2ChannelTest::SerializationFormatWithHeaders() { std::shared_ptr<QAbstractGrpcChannel> channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc"_ba } })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); // Initialize with various content-type headers channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+json"_ba } })); QVERIFY(dynamic_cast<QProtobufJsonSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+proto"_ba } })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+unknown"_ba } })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); // Initialize with the default content-type header and various serialization formats channel = std::make_shared<QGrpcHttp2Channel>(QGrpcChannelOptions{ - QUrl("http://localhost:50051", QUrl::StrictMode) } + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc"_ba } }) - .withSerializationFormat({})); + .withSerializationFormat(QGrpcSerializationFormat{})); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc"_ba } }) - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Json })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Json })); QVERIFY(dynamic_cast<QProtobufJsonSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc"_ba } }) - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Protobuf })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Protobuf })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc"_ba } }) .withSerializationFormat({ "dummy", std::make_shared<DummySerializer>() })); @@ -216,19 +219,26 @@ void QGrpcHttp2ChannelTest::SerializationFormatWithHeaders() // Initialize with the content-type header incompatible with serialization format channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+json"_ba } }) - .withSerializationFormat({ QGrpcSerializationFormat::Format::Protobuf })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Protobuf })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+json"_ba } }) - .withSerializationFormat({})); + .withSerializationFormat(QGrpcSerializationFormat{})); QVERIFY(dynamic_cast<QProtobufJsonSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+json"_ba } }) .withSerializationFormat({ "dummy", std::make_shared<DummySerializer>() })); @@ -236,28 +246,35 @@ void QGrpcHttp2ChannelTest::SerializationFormatWithHeaders() // Initialize with the content-type header matching the serialization format channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+proto"_ba } }) - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Protobuf })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Protobuf })); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+json"_ba } }) - .withSerializationFormat({ QGrpcSerializationFormat::Format:: - Json })); + .withSerializationFormat(QGrpcSerializationFormat{ + QGrpcSerializationFormat::Format::Json })); QVERIFY(dynamic_cast<QProtobufJsonSerializer *>(channel->serializer().get()) != nullptr); - channel = std::make_shared<QGrpcHttp2Channel>(QGrpcChannelOptions{ - QUrl("http://localhost:50051", QUrl::StrictMode) } - .withMetadata({ { "content-type"_ba, - "application/grpc"_ba } }) - .withSerializationFormat({})); + channel = std::make_shared< + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } + .withMetadata({ { "content-type"_ba, "application/grpc"_ba } }) + .withSerializationFormat(QGrpcSerializationFormat{})); QVERIFY(dynamic_cast<QProtobufSerializer *>(channel->serializer().get()) != nullptr); channel = std::make_shared< - QGrpcHttp2Channel>(QGrpcChannelOptions{ QUrl("http://localhost:50051", QUrl::StrictMode) } + QGrpcHttp2Channel>(QGrpcChannelOptions{ + QUrl("http://localhost:50051", QUrl::StrictMode) + } .withMetadata({ { "content-type"_ba, "application/grpc+dummy"_ba } }) .withSerializationFormat({ "dummy", std::make_shared<DummySerializer>() })); |