diff --git a/examples/protobuf/sensors/client/sensorclient.cpp b/examples/protobuf/sensors/client/sensorclient.cpp index 3d0f3b70..8aa2acbd 100644 --- a/examples/protobuf/sensors/client/sensorclient.cpp +++ b/examples/protobuf/sensors/client/sensorclient.cpp @@ -23,11 +23,11 @@ void SensorClient::receive() const auto datagram = m_client.receiveDatagram(); qt::examples::sensors::tlv::TlvMessage msg; msg.deserialize(&m_serializer, datagram.data()); - if (m_serializer.deserializationError() + if (m_serializer.lastError() != QAbstractProtobufSerializer::NoError) { qWarning().nospace() << "Unable to deserialize datagram (" - << m_serializer.deserializationError() << ")" - << m_serializer.deserializationErrorString(); + << m_serializer.lastError() << ")" + << m_serializer.lastErrorString(); continue; } //! [0] @@ -55,11 +55,11 @@ void SensorClient::receive() } } - if (m_serializer.deserializationError() + if (m_serializer.lastError() != QAbstractProtobufSerializer::NoError) { qWarning().nospace() << "Unable to deserialize message (" - << m_serializer.deserializationError() << ")" - << m_serializer.deserializationErrorString(); + << m_serializer.lastError() << ")" + << m_serializer.lastErrorString(); continue; } } diff --git a/src/protobuf/qabstractprotobufserializer.cpp b/src/protobuf/qabstractprotobufserializer.cpp index 52b74bcf..279b6eaf 100644 --- a/src/protobuf/qabstractprotobufserializer.cpp +++ b/src/protobuf/qabstractprotobufserializer.cpp @@ -33,18 +33,19 @@ QT_BEGIN_NAMESPACE */ /*! - \enum QAbstractProtobufSerializer::DeserializationError + \enum QAbstractProtobufSerializer::Error + \since 6.8 This enum contains possible errors that can occur during deserialization. - When an error occurs, call deserializationErrorString() to get a + When an error occurs, call lastErrorString() to get a human-readable error message. \value NoError No error occurred. \value InvalidHeaderError Something went wrong while attempting to decode a header in the message. - \value NoDeserializerError While deserializing a message, no - deserializer was found for a type in the - message. + \value UnknownTypeError While serializing or deserializing a + message, no deserializer was found + for a message field. \value UnexpectedEndOfStreamError While deserializing a message, the stream ended unexpectedly. \value InvalidFormatError The data has invalid format. For example @@ -77,15 +78,21 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QAbstractProtobufSerializer::DeserializationError QAbstractProtobufSerializer::deserializationError() const - Returns the last deserialization error for the serializer instance. - \sa deserializationErrorString() + \fn QAbstractProtobufSerializer::Error QAbstractProtobufSerializer::lastError() const + \since 6.8 + + Returns the last error for the serializer instance. + + \sa lastErrorString() */ /*! - \fn QString QAbstractProtobufSerializer::deserializationErrorString() const - Returns the last deserialization error string for the serializer instance. - \sa deserializationError() + \fn QString QAbstractProtobufSerializer::lastErrorString() const + \since 6.8 + + Returns the last error string for the serializer instance. + + \sa lastError() */ /*! diff --git a/src/protobuf/qabstractprotobufserializer.h b/src/protobuf/qabstractprotobufserializer.h index 11986c6d..f083f476 100644 --- a/src/protobuf/qabstractprotobufserializer.h +++ b/src/protobuf/qabstractprotobufserializer.h @@ -19,10 +19,10 @@ class QProtobufMessage; class Q_PROTOBUF_EXPORT QAbstractProtobufSerializer { public: - enum DeserializationError : uint8_t { + enum Error : uint8_t { NoError, InvalidHeaderError, - NoDeserializerError, + UnknownTypeError, UnexpectedEndOfStreamError, InvalidFormatError, }; @@ -32,8 +32,8 @@ public: virtual ~QAbstractProtobufSerializer(); - virtual DeserializationError deserializationError() const = 0; - virtual QString deserializationErrorString() const = 0; + virtual Error lastError() const = 0; + virtual QString lastErrorString() const = 0; protected: virtual QByteArray serializeMessage(const QProtobufMessage *message) const = 0; diff --git a/src/protobuf/qprotobufjsonserializer.cpp b/src/protobuf/qprotobufjsonserializer.cpp index ed7155cc..23372895 100644 --- a/src/protobuf/qprotobufjsonserializer.cpp +++ b/src/protobuf/qprotobufjsonserializer.cpp @@ -536,7 +536,7 @@ public: } while (!array.isEmpty() - && deserializationError == QAbstractProtobufSerializer::NoError) { + && lastError == QAbstractProtobufSerializer::NoError) { activeValue = array.takeAt(0); if (deserializeObject(&propertyIt.addNext())) propertyIt.push(); @@ -544,19 +544,19 @@ public: ok = propertyData.isValid(); } else { while (!activeValue.isNull() - && deserializationError == QAbstractProtobufSerializer::NoError) { + && lastError == QAbstractProtobufSerializer::NoError) { if (deserializeObject(&propertyIt.addNext())) propertyIt.push(); } } - ok = deserializationError == QAbstractProtobufSerializer::NoError; + ok = lastError == QAbstractProtobufSerializer::NoError; return propertyData; } auto handler = QtProtobufPrivate::findHandler(metaType); if (handler.deserializer) { while (!activeValue.isNull() - && deserializationError == QAbstractProtobufSerializer::NoError) { + && lastError == QAbstractProtobufSerializer::NoError) { handler .deserializer([this](QProtobufMessage *message) { return this->deserializeObject(message); }, @@ -571,7 +571,7 @@ public: if (!ok) setInvalidFormatError(); } else { - setDeserializationError(QAbstractProtobufSerializer::NoDeserializerError, + setDeserializationError(QAbstractProtobufSerializer::UnknownTypeError, QCoreApplication:: translate("QtProtobuf", "No deserializer is registered for type %1") @@ -682,11 +682,11 @@ public: return storeCachedValue(message); } - void setDeserializationError(QAbstractProtobufSerializer::DeserializationError error, + void setDeserializationError(QAbstractProtobufSerializer::Error error, const QString &errorString) { - deserializationError = error; - deserializationErrorString = errorString; + lastError = error; + lastErrorString = errorString; } void setUnexpectedEndOfStreamError() @@ -706,9 +706,8 @@ public: void clearError(); - QAbstractProtobufSerializer::DeserializationError deserializationError = - QAbstractProtobufSerializer::NoDeserializerError; - QString deserializationErrorString; + QAbstractProtobufSerializer::Error lastError = QAbstractProtobufSerializer::NoError; + QString lastErrorString; QJsonValue activeValue; static SerializerRegistry handlers; @@ -755,8 +754,8 @@ void QProtobufJsonSerializerPrivate::serializeObjectImpl(const QProtobufMessage void QProtobufJsonSerializerPrivate::clearError() { - deserializationError = QAbstractProtobufSerializer::NoError; - deserializationErrorString.clear(); + lastError = QAbstractProtobufSerializer::NoError; + lastErrorString.clear(); } QProtobufJsonSerializer::QProtobufJsonSerializer() : d_ptr(new QProtobufJsonSerializerPrivate) @@ -767,21 +766,20 @@ QProtobufJsonSerializer::~QProtobufJsonSerializer() = default; /*! Returns the last deserialization error for the serializer instance. - \sa deserializationErrorString() + \sa lastErrorString() */ -QAbstractProtobufSerializer::DeserializationError -QProtobufJsonSerializer::deserializationError() const +QAbstractProtobufSerializer::Error QProtobufJsonSerializer::lastError() const { - return d_ptr->deserializationError; + return d_ptr->lastError; } /*! Returns the last deserialization error string for the serializer instance. - \sa deserializationError() + \sa lastError() */ -QString QProtobufJsonSerializer::deserializationErrorString() const +QString QProtobufJsonSerializer::lastErrorString() const { - return d_ptr->deserializationErrorString; + return d_ptr->lastErrorString; } QByteArray QProtobufJsonSerializer::serializeMessage(const QProtobufMessage *message) const diff --git a/src/protobuf/qprotobufjsonserializer.h b/src/protobuf/qprotobufjsonserializer.h index 41e690b6..2fe8307c 100644 --- a/src/protobuf/qprotobufjsonserializer.h +++ b/src/protobuf/qprotobufjsonserializer.h @@ -21,8 +21,8 @@ public: QProtobufJsonSerializer(); ~QProtobufJsonSerializer() override; - DeserializationError deserializationError() const override; - QString deserializationErrorString() const override; + Error lastError() const override; + QString lastErrorString() const override; protected: QByteArray serializeMessage(const QProtobufMessage *message) const override; diff --git a/src/protobuf/qprotobufserializer.cpp b/src/protobuf/qprotobufserializer.cpp index d02048af..b2d6a0e8 100644 --- a/src/protobuf/qprotobufserializer.cpp +++ b/src/protobuf/qprotobufserializer.cpp @@ -231,8 +231,8 @@ void QProtobufSerializerPrivate::setUnexpectedEndOfStreamError() void QProtobufSerializerPrivate::clearError() { - deserializationError = QAbstractProtobufSerializer::NoError; - deserializationErrorString.clear(); + lastError = QAbstractProtobufSerializer::NoError; + lastErrorString.clear(); } bool QProtobufSerializer::deserializeMessage(QProtobufMessage *message, QByteArrayView data) const @@ -644,7 +644,7 @@ bool QProtobufSerializerPrivate::deserializeProperty(QProtobufMessage *message) qProtoWarning() << "No deserializer for type" << metaType.name(); QString error = QString::fromUtf8("No deserializer is registered for type %1") .arg(QString::fromUtf8(metaType.name())); - setDeserializationError(QAbstractProtobufSerializer::NoDeserializerError, + setDeserializationError(QAbstractProtobufSerializer::UnknownTypeError, QCoreApplication::translate("QtProtobuf", error.toUtf8().data())); return false; } @@ -678,27 +678,27 @@ void QProtobufSerializerPrivate::clearCachedValue() /*! Returns the last deserialization error for the serializer instance. - \sa deserializationErrorString() + \sa lastErrorString() */ -QAbstractProtobufSerializer::DeserializationError QProtobufSerializer::deserializationError() const +QAbstractProtobufSerializer::Error QProtobufSerializer::lastError() const { - return d_ptr->deserializationError; + return d_ptr->lastError; } /*! Returns the last deserialization error string for the serializer instance. - \sa deserializationError() + \sa lastError() */ -QString QProtobufSerializer::deserializationErrorString() const +QString QProtobufSerializer::lastErrorString() const { - return d_ptr->deserializationErrorString; + return d_ptr->lastErrorString; } void QProtobufSerializerPrivate::setDeserializationError( - QAbstractProtobufSerializer::DeserializationError error, const QString &errorString) + QAbstractProtobufSerializer::Error error, const QString &errorString) { - deserializationError = error; - deserializationErrorString = errorString; + lastError = error; + lastErrorString = errorString; } /*! diff --git a/src/protobuf/qprotobufserializer.h b/src/protobuf/qprotobufserializer.h index 5861ce45..dfaf265a 100644 --- a/src/protobuf/qprotobufserializer.h +++ b/src/protobuf/qprotobufserializer.h @@ -24,8 +24,8 @@ public: QProtobufSerializer(); ~QProtobufSerializer() override; - DeserializationError deserializationError() const override; - QString deserializationErrorString() const override; + Error lastError() const override; + QString lastErrorString() const override; void shouldPreserveUnknownFields(bool preserveUnknownFields); diff --git a/src/protobuf/qprotobufserializer_p.h b/src/protobuf/qprotobufserializer_p.h index 56893e0e..79a0a948 100644 --- a/src/protobuf/qprotobufserializer_p.h +++ b/src/protobuf/qprotobufserializer_p.h @@ -517,7 +517,7 @@ public: const QtProtobufPrivate::QProtobufFieldInfo &fieldInfo); [[nodiscard]] bool deserializeProperty(QProtobufMessage *message); - void setDeserializationError(QAbstractProtobufSerializer::DeserializationError error, + void setDeserializationError(QAbstractProtobufSerializer::Error error, const QString &errorString); void clearError(); void setUnexpectedEndOfStreamError(); @@ -525,9 +525,9 @@ public: [[nodiscard]] bool storeCachedValue(QProtobufMessage *message); void clearCachedValue(); - QAbstractProtobufSerializer::DeserializationError deserializationError = - QAbstractProtobufSerializer::NoDeserializerError; - QString deserializationErrorString; + QAbstractProtobufSerializer::Error lastError = + QAbstractProtobufSerializer::UnknownTypeError; + QString lastErrorString; QProtobufSelfcheckIterator it; QByteArray result; diff --git a/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp b/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp index 0e47ba59..880ea630 100644 --- a/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp +++ b/tests/auto/grpc/qgrpchttp2channel/tst_qgrpchttp2channel.cpp @@ -25,12 +25,12 @@ using namespace Qt::StringLiterals; class DummySerializer : public QAbstractProtobufSerializer { public: - virtual QAbstractProtobufSerializer::DeserializationError deserializationError() const override + virtual QAbstractProtobufSerializer::Error lastError() const override { - return QAbstractProtobufSerializer::NoDeserializerError; + return QAbstractProtobufSerializer::NoError; } - virtual QString deserializationErrorString() const override { return {}; } + virtual QString lastErrorString() const override { return {}; } protected: virtual QByteArray serializeMessage(const QProtobufMessage *) const override { return {}; } diff --git a/tests/auto/protobuf/basic/tst_protobuf_deserialization_complex_maptypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_deserialization_complex_maptypes.cpp index 7fca9dfd..3700d094 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_deserialization_complex_maptypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_deserialization_complex_maptypes.cpp @@ -46,7 +46,7 @@ void QtProtobufMapTypesDeserializationTest::simpleFixed32ComplexMapDeserializeTe QByteArray::fromHex("3a180d0a00000012110810120d320b74656e207369787465656e3a230" "d2a000000121c080a12183216666f757274792074776f2074656e2073" "69787465656e3a110d13000100120a080a120632045755543f")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -78,7 +78,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSFixed32ComplexMapDeserializeT QByteArray::fromHex("4a290dd6ffffff1222121e321c6d696e757320666f757274792074776f2074656e" "207369787465656e080a4a180d0a0000001211120d320b74656e20736978746565" "6e08104a110d13000100120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -110,7 +110,7 @@ void QtProtobufMapTypesDeserializationTest::simpleInt32ComplexMapDeserializeTest QByteArray::fromHex("1a2f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074" "776f2074656e207369787465656e080a1a15080a1211120d320b74656e20736978" "7465656e08101a1008938004120a120632045755543f080a")); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::NoError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::NoError); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -141,7 +141,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSInt32ComplexMapDeserializeTes QByteArray::fromHex("0a1608a580081210120c320a6d696e7573205755543f080a0a1508141" "211120d320b74656e207369787465656e08100a200854121c12183216" "666f757274792074776f2074656e207369787465656e080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -173,7 +173,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt32ComplexMapDeserializeTes QByteArray::fromHex( "2a15080a1211120d320b74656e207369787465656e08102a20082a121c12183216666f75727479" "2074776f2074656e207369787465656e080a2a1008938004120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -205,7 +205,7 @@ void QtProtobufMapTypesDeserializationTest::simpleFixed64ComplexMapDeserializeTe "421c090a000000000000001211120d320b74656e207369787465656e0810421509130" "0010000000000120a120632045755543f080a422b09ffffffffffffffff1220121c32" "1a6d696e757320666f757274792074776f2074656e204d41414158082a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -237,7 +237,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSFixed64ComplexMapDeserializeT "522d09d6ffffffffffffff1222121e321c6d696e757320666f757274792074776f207" "4656e207369787465656e080a521c090a000000000000001211120d320b74656e2073" "69787465656e08105215091300010000000000120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -269,7 +269,7 @@ void QtProtobufMapTypesDeserializationTest::simpleInt64ComplexMapDeserializeTest QByteArray::fromHex("222f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074" "776f2074656e207369787465656e080a2215080a1211120d320b74656e20736978" "7465656e0810221008938004120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -300,7 +300,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSInt64ComplexMapDeserializeTes QByteArray::fromHex("122608531222121e321c6d696e757320666f757274792074776f20746" "56e207369787465656e080a121508141211120d320b74656e20736978" "7465656e0810121008a68008120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -332,7 +332,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapDeserializeTes QByteArray::fromHex( "3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f7572747920" "74776f2074656e207369787465656e080a321008938004120a120632045755543f080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -364,7 +364,7 @@ void QtProtobufMapTypesDeserializationTest::simpleStringComplexMapDeserializeTes "6a140a055755543f3f120b120732053f5755543f080a6a170a0362656e1210120c320" "a74656e20656c6576656e080b6a350a157768657265206973206d7920636172206475" "64653f121c12183216666f757274792074776f2074656e207369787465656e080a")); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -395,7 +395,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapInvalidLengthD QByteArray::fromHex( "3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f7" "57274792074776f2074656e207369787465656e080a321008938004120a120")); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidHeaderError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidHeaderError); QVERIFY(test.mapField().isEmpty()); } @@ -407,7 +407,7 @@ void QtProtobufMapTypesDeserializationTest::simpleStringComplexMapInvalidLengthD "6a140a055755543f3f120b120732053f5755543f080a6a170a0362656e1210120c320" "a74656e20656c6576656e080b6a350a157768657265206973206d7920636172206475" "64653f121c12183216666f757274792074776f2074656e20736978746565")); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -435,7 +435,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapCorruptedDeser QByteArray::fromHex( "3214080a1210120c320a74656e20656c6576656e080b3221233522345b2183216666f757274792" "074776f2074656e207369787465656e080a321008938004120a120632045755543f080a")); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidHeaderError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidHeaderError); QVERIFY(test.mapField().isEmpty()); } diff --git a/tests/auto/protobuf/basic/tst_protobuf_deserialization_repeatedtypes.cpp b/tests/auto/protobuf/basic/tst_protobuf_deserialization_repeatedtypes.cpp index 3497e766..229667d1 100644 --- a/tests/auto/protobuf/basic/tst_protobuf_deserialization_repeatedtypes.cpp +++ b/tests/auto/protobuf/basic/tst_protobuf_deserialization_repeatedtypes.cpp @@ -194,7 +194,7 @@ void QtProtobufRepeatedTypesDeserializationTest::repeatedBoolMessageTest() { RepeatedBoolMessage boolMsg; boolMsg.deserialize(serializer.get(), QByteArray::fromHex("0a0d01010100000000000000000001")); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::NoError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::NoError); QtProtobuf::boolList expected{ true, true, true, false, false, false, false, false, false, false, false, false, true }; QCOMPARE(boolMsg.testRepeatedBool(), expected); diff --git a/tests/auto/protobuf/conformance/tst_protobuf_conformance.cpp b/tests/auto/protobuf/conformance/tst_protobuf_conformance.cpp index 50833f88..347d2122 100644 --- a/tests/auto/protobuf/conformance/tst_protobuf_conformance.cpp +++ b/tests/auto/protobuf/conformance/tst_protobuf_conformance.cpp @@ -116,8 +116,8 @@ QByteArray ConformaceServer::runTest(const QByteArray &reqData) QByteArray payload = isProtoInput ? request.protobufPayload() : request.jsonPayload().toUtf8(); if (!activeDeserializer->deserialize(msg.get(), payload) - || activeDeserializer->deserializationError() != QAbstractProtobufSerializer::NoError) { - response.setParseError(activeDeserializer->deserializationErrorString()); + || activeDeserializer->lastError() != QAbstractProtobufSerializer::NoError) { + response.setParseError(activeDeserializer->lastErrorString()); return response.serialize(&m_protoSerializer); } diff --git a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_basictypes.cpp b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_basictypes.cpp index d92e371e..8b680b2a 100644 --- a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_basictypes.cpp +++ b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_basictypes.cpp @@ -527,7 +527,7 @@ void QtProtobufTypesJsonDeserializationTest::malformedJsonTest() QCOMPARE(msg.testFieldInt(), 0); QCOMPARE(msg.testComplexField(), SimpleStringMessage()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); msg.deserialize(serializer.get(), @@ -535,7 +535,7 @@ void QtProtobufTypesJsonDeserializationTest::malformedJsonTest() "\"testComplexField\":{\"testFieldString\":\"qwerty\"}}]"_ba); QCOMPARE(msg.testFieldInt(), 0); QCOMPARE(msg.testComplexField(), SimpleStringMessage()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); } @@ -549,7 +549,7 @@ void QtProtobufTypesJsonDeserializationTest::invalidTypeTest() QCOMPARE(msg.testFieldInt(), -45); QCOMPARE(msg.testComplexField(), SimpleStringMessage()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); // Expected integer but the value is an array @@ -559,21 +559,21 @@ void QtProtobufTypesJsonDeserializationTest::invalidTypeTest() QCOMPARE(msg.testFieldInt(), 0); QCOMPARE(msg.testComplexField().testFieldString(), "qwerty"_L1); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); SimpleIntMessage intMsg; intMsg.deserialize(serializer.get(), "{\"testFieldInt\": 0.5}"); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidFormatError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); QCOMPARE(intMsg.testFieldInt(), 0); intMsg.deserialize(serializer.get(), "{\"testFieldInt\":4294967296}"); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidFormatError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); QCOMPARE(intMsg.testFieldInt(), 0); SimpleUIntMessage uintMsg; uintMsg.deserialize(serializer.get(), "{\"testFieldInt\":4294967296}"); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidFormatError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); QCOMPARE(uintMsg.testFieldInt(), 0u); } diff --git a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_enumtypes.cpp b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_enumtypes.cpp index 27dbd61f..07bd1ca1 100644 --- a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_enumtypes.cpp +++ b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_enumtypes.cpp @@ -56,7 +56,7 @@ void QtProtobufEnumTypesDeserializationTest::malformedJsonTest() // more braces test.deserialize(m_serializer.get(), "{\"localEnum\":\"LOCAL_ENUM_VALUE2\"}}"); - QCOMPARE(m_serializer->deserializationError(), + QCOMPARE(m_serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); RepeatedEnumMessage msg; @@ -67,7 +67,7 @@ void QtProtobufEnumTypesDeserializationTest::malformedJsonTest() "\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\"," "\"LOCAL_ENUM_VALUE3\"}"); - QCOMPARE(m_serializer->deserializationError(), + QCOMPARE(m_serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); } @@ -76,7 +76,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest() // no LOCAL_ENUM_VALUE240 SimpleEnumMessage invalidTest; invalidTest.deserialize(m_serializer.get(), "{\"localEnum\":\"LOCAL_ENUM_VALUE240\"}"); - QCOMPARE(m_serializer->deserializationError(), + QCOMPARE(m_serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); RepeatedEnumMessage msg, msg2; @@ -86,7 +86,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest() "\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\"," "\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\"," "\"LOCAL_ENUM_VALUE3\"]}"); - QCOMPARE(m_serializer->deserializationError(), + QCOMPARE(m_serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); // no LOCAL_ENUM_VALUE_100 @@ -95,7 +95,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest() "\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\"," "\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\"," "\"LOCAL_ENUM_VALUE3\"]}"); - QCOMPARE(m_serializer->deserializationError(), + QCOMPARE(m_serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); } diff --git a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_maptypes.cpp b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_maptypes.cpp index 6adb6fe9..74472232 100644 --- a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_maptypes.cpp +++ b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_maptypes.cpp @@ -178,7 +178,7 @@ void QtProtobufJsonMapTypesDeserializationTest::simpleFixed32ComplexMapDeseriali "\"testFieldInt\":16},\"42\":{\"testComplexField\":{\"testFieldString\":" "\"fourty two ten sixteen\"},\"testFieldInt\":10},\"65555\":{\"testComplexField\":" "{\"testFieldString\":\"WUT?\"},\"testFieldInt\":10}}}"_ba); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); qtprotobufnamespace::tests::SimpleStringMessage stringMsg; @@ -209,7 +209,7 @@ void QtProtobufJsonMapTypesDeserializationTest::boolBoolMapDeserializeTest() { BoolBoolMessageMapMessage test; test.deserialize(serializer.get(), "{\"mapField\":{\"true\":\"false\",\"false\":\"true\"}}"); - QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->deserializationError()); + QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError()); QCOMPARE(test.mapField().value(true), false); QCOMPARE(test.mapField().value(false), true); @@ -223,7 +223,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest() "{\"mapField\":{\"10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty two\"}"_ba); QVERIFY(test.mapField().empty()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); // skipped ':' @@ -233,7 +233,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest() "\"what is the answer?\":\"fourty two\"}}"_ba); QVERIFY(test2.mapField().empty()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); SimpleFixed32StringMapMessage test3; @@ -242,7 +242,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest() "{\"mapField\":{\"10\":\"ten\"\"15\":\"fifteen\",\"42\":\"fourty two\"}}"_ba); QVERIFY(test3.mapField().empty()); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); } @@ -254,7 +254,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest() serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42.3\":\"fourty two\"}}"_ba); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); // -10 for uint32 is used @@ -263,7 +263,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest() "{\"mapField\":{\"-10\":\"ten\",\"15\":\"fifteen\",\"42\":\"fourty" " two\"}}"_ba); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); // expected int, but bool is used @@ -271,7 +271,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest() serializer.get(), "{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"false\":\"fourty two\"}}"_ba); - QCOMPARE(serializer->deserializationError(), + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); } diff --git a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_repeatedtypes.cpp b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_repeatedtypes.cpp index d925ace5..9260fc77 100644 --- a/tests/auto/protobuf/json/tst_protobuf_deserialization_json_repeatedtypes.cpp +++ b/tests/auto/protobuf/json/tst_protobuf_deserialization_json_repeatedtypes.cpp @@ -232,7 +232,7 @@ void QtProtobufRepeatedTypesJsonDeserializationTest::repeatedBoolMessageTest() { RepeatedBoolMessage boolMsg; boolMsg.deserialize(serializer.get(), "{\"testRepeatedBool\":[true,true,true,false,false,false,false,false,false,false,false,false,true]}"_ba); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::NoError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::NoError); QtProtobuf::boolList expected({ true, true, true, false, false, false, false, false, false, false, false, false, true }); QCOMPARE(boolMsg.testRepeatedBool().count(), 13); @@ -245,13 +245,13 @@ void QtProtobufRepeatedTypesJsonDeserializationTest::malformedJsonTest() RepeatedBoolMessage boolMsg; boolMsg.deserialize(serializer.get(), "{\"testRepeatedBool\":true,true,true,false,false,false,false,false,false,false,false,false,true]}"_ba); QVERIFY(boolMsg.testRepeatedBool().size() == 0); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); // twice ] RepeatedSInt64Message test; test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]1,321,-65999,12324523123123,-3,3]}"_ba); QVERIFY(test.testRepeatedInt().size() == 0); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError); } @@ -261,14 +261,14 @@ void QtProtobufRepeatedTypesJsonDeserializationTest::invalidTypeTest() RepeatedSInt64Message test; test.deserialize(serializer.get(), "{\"testRepeatedInt\":[1,321,\"abcd\",12324523123123,-3,3]}"_ba); QVERIFY(test.testRepeatedInt().size() == 0); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidFormatError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); // expected bool, float is used RepeatedBoolMessage boolMsg; boolMsg.deserialize(serializer.get(), "{\"testRepeatedBool\":[true,true,true,7.8,false,false,false,false,false,false,false,false,true]}"_ba); QVERIFY(test.testRepeatedInt().size() == 0); - QCOMPARE(serializer->deserializationError(), QAbstractProtobufSerializer::InvalidFormatError); + QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError); } diff --git a/tests/auto/protobuf/wellknown/tst_protobuf_any.cpp b/tests/auto/protobuf/wellknown/tst_protobuf_any.cpp index 9d03bf84..fc05f299 100644 --- a/tests/auto/protobuf/wellknown/tst_protobuf_any.cpp +++ b/tests/auto/protobuf/wellknown/tst_protobuf_any.cpp @@ -95,7 +95,7 @@ void tst_protobuf_any::anyMessage() AnyMessage message; message.deserialize(&serializer, input); - QCOMPARE_EQ(serializer.deserializationError(), QAbstractProtobufSerializer::NoError); + QCOMPARE_EQ(serializer.lastError(), QAbstractProtobufSerializer::NoError); std::optional opt = message.field().unpack(&serializer); QVERIFY(opt.has_value()); @@ -140,8 +140,8 @@ void tst_protobuf_any::repeatedAnyMessage() // let's try to deserialize it again RepeatedAnyMessage message2; message2.deserialize(&serializer, input); - if (serializer.deserializationError() != QAbstractProtobufSerializer::NoError) - QFAIL(qPrintable(serializer.deserializationErrorString())); + if (serializer.lastError() != QAbstractProtobufSerializer::NoError) + QFAIL(qPrintable(serializer.lastErrorString())); QCOMPARE_EQ(message2.anys().size(), message.anys().size()); const auto anys = message.anys();