Scope QAbstractProtobufSerializer::Error enum

All new enums should be scoped.

Drive-by change: Remove the redundant suffixes of the enum elements.
It's obvious from the scope that those are errors.

Pick-to: 6.8
Task-number: QTBUG-123626
Change-Id: Ided4ab4a1ddb2d14713f876ffe4fe339af39ae6b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Alexey Edelev 2024-09-04 18:17:06 +02:00
parent 74eda17cce
commit 97a99986c0
16 changed files with 75 additions and 75 deletions

View File

@ -24,9 +24,9 @@ void SensorClient::receive()
qt::examples::sensors::tlv::TlvMessage msg;
msg.deserialize(&m_serializer, datagram.data());
if (m_serializer.lastError()
!= QAbstractProtobufSerializer::NoError) {
!= QAbstractProtobufSerializer::Error::None) {
qWarning().nospace() << "Unable to deserialize datagram ("
<< m_serializer.lastError() << ")"
<< qToUnderlying(m_serializer.lastError()) << ")"
<< m_serializer.lastErrorString();
continue;
}
@ -56,9 +56,9 @@ void SensorClient::receive()
}
if (m_serializer.lastError()
!= QAbstractProtobufSerializer::NoError) {
!= QAbstractProtobufSerializer::Error::None) {
qWarning().nospace() << "Unable to deserialize message ("
<< m_serializer.lastError() << ")"
<< qToUnderlying(m_serializer.lastError()) << ")"
<< m_serializer.lastErrorString();
continue;
}

View File

@ -115,7 +115,7 @@ bool QGrpcOperation::read(QProtobufMessage *message) const
const auto ser = d->operationContext->serializer();
Q_ASSERT_X(ser, "QGrpcOperation", "The serializer is null");
if (!ser->deserialize(message, d->data)) {
qGrpcWarning() << "Unable to deserialize message("<< ser->lastError() <<"): "
qGrpcWarning() << "Unable to deserialize message(" << qToUnderlying(ser->lastError()) <<"): "
<< ser->lastErrorString();
return false;
}

View File

@ -40,15 +40,15 @@ QT_BEGIN_NAMESPACE
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
\value None No error occurred.
\value InvalidHeader Something went wrong while attempting to
decode a header in the message.
\value UnknownTypeError While serializing or deserializing a
\value UnknownType While serializing or deserializing a
message, no deserializer was found
for a message field.
\value UnexpectedEndOfStreamError While deserializing a message, the
\value UnexpectedEndOfStream While deserializing a message, the
stream ended unexpectedly.
\value InvalidFormatError The data has invalid format. For example
\value InvalidFormat The data has invalid format. For example
the JSON value doesn't match the field type.
*/

View File

@ -19,12 +19,12 @@ class QProtobufMessage;
class Q_PROTOBUF_EXPORT QAbstractProtobufSerializer
{
public:
enum Error : uint8_t {
NoError,
InvalidHeaderError,
UnknownTypeError,
UnexpectedEndOfStreamError,
InvalidFormatError,
enum class Error : uint8_t {
None,
InvalidHeader,
UnknownType,
UnexpectedEndOfStream,
InvalidFormat,
};
QByteArray serialize(const QProtobufMessage *message) const;

View File

@ -536,7 +536,7 @@ public:
}
while (!array.isEmpty()
&& lastError == QAbstractProtobufSerializer::NoError) {
&& lastError == QAbstractProtobufSerializer::Error::None) {
activeValue = array.takeAt(0);
if (deserializeObject(&propertyIt.addNext()))
propertyIt.push();
@ -544,19 +544,19 @@ public:
ok = propertyData.isValid();
} else {
while (!activeValue.isNull()
&& lastError == QAbstractProtobufSerializer::NoError) {
&& lastError == QAbstractProtobufSerializer::Error::None) {
if (deserializeObject(&propertyIt.addNext()))
propertyIt.push();
}
}
ok = lastError == QAbstractProtobufSerializer::NoError;
ok = lastError == QAbstractProtobufSerializer::Error::None;
return propertyData;
}
auto handler = QtProtobufPrivate::findHandler(metaType);
if (handler.deserializer) {
while (!activeValue.isNull()
&& lastError == QAbstractProtobufSerializer::NoError) {
&& lastError == QAbstractProtobufSerializer::Error::None) {
handler
.deserializer([this](QProtobufMessage
*message) { return this->deserializeObject(message); },
@ -571,7 +571,7 @@ public:
if (!ok)
setInvalidFormatError();
} else {
setDeserializationError(QAbstractProtobufSerializer::UnknownTypeError,
setDeserializationError(QAbstractProtobufSerializer::Error::UnknownType,
QCoreApplication::
translate("QtProtobuf",
"No deserializer is registered for type %1")
@ -691,14 +691,14 @@ public:
void setUnexpectedEndOfStreamError()
{
setDeserializationError(QAbstractProtobufSerializer::UnexpectedEndOfStreamError,
setDeserializationError(QAbstractProtobufSerializer::Error::UnexpectedEndOfStream,
QCoreApplication::translate("QtProtobuf",
"JSON: Unexpected end of stream"));
}
void setInvalidFormatError()
{
setDeserializationError(QAbstractProtobufSerializer::InvalidFormatError,
setDeserializationError(QAbstractProtobufSerializer::Error::InvalidFormat,
QCoreApplication::
translate("QtProtobuf",
"JSON: One or more fields have invalid format"));
@ -706,7 +706,7 @@ public:
void clearError();
QAbstractProtobufSerializer::Error lastError = QAbstractProtobufSerializer::NoError;
QAbstractProtobufSerializer::Error lastError = QAbstractProtobufSerializer::Error::None;
QString lastErrorString;
QJsonValue activeValue;
@ -754,7 +754,7 @@ void QProtobufJsonSerializerPrivate::serializeObjectImpl(const QProtobufMessage
void QProtobufJsonSerializerPrivate::clearError()
{
lastError = QAbstractProtobufSerializer::NoError;
lastError = QAbstractProtobufSerializer::Error::None;
lastErrorString.clear();
}

View File

@ -225,13 +225,13 @@ void QProtobufSerializerPrivate::serializeMessage(const QProtobufMessage *messag
void QProtobufSerializerPrivate::setUnexpectedEndOfStreamError()
{
setDeserializationError(QAbstractProtobufSerializer::UnexpectedEndOfStreamError,
setDeserializationError(QAbstractProtobufSerializer::Error::UnexpectedEndOfStream,
QCoreApplication::translate("QtProtobuf", "Unexpected end of stream"));
}
void QProtobufSerializerPrivate::clearError()
{
lastError = QAbstractProtobufSerializer::NoError;
lastError = QAbstractProtobufSerializer::Error::None;
lastErrorString.clear();
}
@ -525,7 +525,7 @@ bool QProtobufSerializerPrivate::deserializeProperty(QProtobufMessage *message)
const QProtobufSelfcheckIterator itBeforeHeader = it; // copy this, we may need it later
if (!QProtobufSerializerPrivate::decodeHeader(it, fieldNumber, wireType)) {
setDeserializationError(
QAbstractProtobufSerializer::InvalidHeaderError,
QAbstractProtobufSerializer::Error::InvalidHeader,
QCoreApplication::translate("QtProtobuf",
"Message received doesn't contain valid header byte."));
return false;
@ -610,7 +610,7 @@ bool QProtobufSerializerPrivate::deserializeProperty(QProtobufMessage *message)
basicHandler = findIntegratedTypeHandler(metaType, !isNonPacked);
if (!basicHandler || basicHandler->wireType != wireType) {
setDeserializationError(
QAbstractProtobufSerializer::InvalidHeaderError,
QAbstractProtobufSerializer::Error::InvalidHeader,
QCoreApplication::translate("QtProtobuf",
"Message received has invalid wiretype for the "
"field number %1. Expected %2, received %3")
@ -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::UnknownTypeError,
setDeserializationError(QAbstractProtobufSerializer::Error::UnknownType,
QCoreApplication::translate("QtProtobuf", error.toUtf8().data()));
return false;
}

View File

@ -528,7 +528,7 @@ public:
void clearCachedValue();
QAbstractProtobufSerializer::Error lastError =
QAbstractProtobufSerializer::UnknownTypeError;
QAbstractProtobufSerializer::Error::UnknownType;
QString lastErrorString;
QProtobufSelfcheckIterator it;

View File

@ -27,7 +27,7 @@ class DummySerializer : public QAbstractProtobufSerializer
public:
virtual QAbstractProtobufSerializer::Error lastError() const override
{
return QAbstractProtobufSerializer::NoError;
return QAbstractProtobufSerializer::Error::None;
}
virtual QString lastErrorString() const override { return {}; }

View File

@ -46,7 +46,7 @@ void QtProtobufMapTypesDeserializationTest::simpleFixed32ComplexMapDeserializeTe
QByteArray::fromHex("3a180d0a00000012110810120d320b74656e207369787465656e3a230"
"d2a000000121c080a12183216666f757274792074776f2074656e2073"
"69787465656e3a110d13000100120a080a120632045755543f"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -78,7 +78,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSFixed32ComplexMapDeserializeT
QByteArray::fromHex("4a290dd6ffffff1222121e321c6d696e757320666f757274792074776f2074656e"
"207369787465656e080a4a180d0a0000001211120d320b74656e20736978746565"
"6e08104a110d13000100120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -110,7 +110,7 @@ void QtProtobufMapTypesDeserializationTest::simpleInt32ComplexMapDeserializeTest
QByteArray::fromHex("1a2f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074"
"776f2074656e207369787465656e080a1a15080a1211120d320b74656e20736978"
"7465656e08101a1008938004120a120632045755543f080a"));
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::NoError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::None);
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -141,7 +141,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSInt32ComplexMapDeserializeTes
QByteArray::fromHex("0a1608a580081210120c320a6d696e7573205755543f080a0a1508141"
"211120d320b74656e207369787465656e08100a200854121c12183216"
"666f757274792074776f2074656e207369787465656e080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -173,7 +173,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt32ComplexMapDeserializeTes
QByteArray::fromHex(
"2a15080a1211120d320b74656e207369787465656e08102a20082a121c12183216666f75727479"
"2074776f2074656e207369787465656e080a2a1008938004120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -205,7 +205,7 @@ void QtProtobufMapTypesDeserializationTest::simpleFixed64ComplexMapDeserializeTe
"421c090a000000000000001211120d320b74656e207369787465656e0810421509130"
"0010000000000120a120632045755543f080a422b09ffffffffffffffff1220121c32"
"1a6d696e757320666f757274792074776f2074656e204d41414158082a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -237,7 +237,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSFixed64ComplexMapDeserializeT
"522d09d6ffffffffffffff1222121e321c6d696e757320666f757274792074776f207"
"4656e207369787465656e080a521c090a000000000000001211120d320b74656e2073"
"69787465656e08105215091300010000000000120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -269,7 +269,7 @@ void QtProtobufMapTypesDeserializationTest::simpleInt64ComplexMapDeserializeTest
QByteArray::fromHex("222f08d6ffffffffffffffff011222121e321c6d696e757320666f757274792074"
"776f2074656e207369787465656e080a2215080a1211120d320b74656e20736978"
"7465656e0810221008938004120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -300,7 +300,7 @@ void QtProtobufMapTypesDeserializationTest::simpleSInt64ComplexMapDeserializeTes
QByteArray::fromHex("122608531222121e321c6d696e757320666f757274792074776f20746"
"56e207369787465656e080a121508141211120d320b74656e20736978"
"7465656e0810121008a68008120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -332,7 +332,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapDeserializeTes
QByteArray::fromHex(
"3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f7572747920"
"74776f2074656e207369787465656e080a321008938004120a120632045755543f080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -364,7 +364,7 @@ void QtProtobufMapTypesDeserializationTest::simpleStringComplexMapDeserializeTes
"6a140a055755543f3f120b120732053f5755543f080a6a170a0362656e1210120c320"
"a74656e20656c6576656e080b6a350a157768657265206973206d7920636172206475"
"64653f121c12183216666f757274792074776f2074656e207369787465656e080a"));
QCOMPARE(QAbstractProtobufSerializer::NoError, serializer->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -395,7 +395,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapInvalidLengthD
QByteArray::fromHex(
"3214080a1210120c320a74656e20656c6576656e080b3220082a121c12183216666f7"
"57274792074776f2074656e207369787465656e080a321008938004120a120"));
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidHeaderError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidHeader);
QVERIFY(test.mapField().isEmpty());
}
@ -408,7 +408,7 @@ void QtProtobufMapTypesDeserializationTest::simpleStringComplexMapInvalidLengthD
"a74656e20656c6576656e080b6a350a157768657265206973206d7920636172206475"
"64653f121c12183216666f757274792074776f2074656e20736978746565"));
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
qtprotobufnamespace::tests::SimpleStringMessage stringMsg;
@ -435,7 +435,7 @@ void QtProtobufMapTypesDeserializationTest::simpleUInt64ComplexMapCorruptedDeser
QByteArray::fromHex(
"3214080a1210120c320a74656e20656c6576656e080b3221233522345b2183216666f757274792"
"074776f2074656e207369787465656e080a321008938004120a120632045755543f080a"));
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidHeaderError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidHeader);
QVERIFY(test.mapField().isEmpty());
}

View File

@ -194,7 +194,7 @@ void QtProtobufRepeatedTypesDeserializationTest::repeatedBoolMessageTest()
{
RepeatedBoolMessage boolMsg;
boolMsg.deserialize(serializer.get(), QByteArray::fromHex("0a0d01010100000000000000000001"));
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::NoError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::None);
QtProtobuf::boolList expected{ true, true, true, false, false, false, false,
false, false, false, false, false, true };
QCOMPARE(boolMsg.testRepeatedBool(), expected);

View File

@ -119,7 +119,7 @@ QByteArray ConformaceServer::runTest(const QByteArray &reqData)
QByteArray payload = isProtoInput ? request.protobufPayload() : request.jsonPayload().toUtf8();
if (!activeDeserializer->deserialize(msg.get(), payload)
|| activeDeserializer->lastError() != QAbstractProtobufSerializer::NoError) {
|| activeDeserializer->lastError() != QAbstractProtobufSerializer::Error::None) {
response.setParseError(activeDeserializer->lastErrorString());
return response.serialize(&m_protoSerializer);
}

View File

@ -528,7 +528,7 @@ void QtProtobufTypesJsonDeserializationTest::malformedJsonTest()
QCOMPARE(msg.testFieldInt(), 0);
QCOMPARE(msg.testComplexField(), SimpleStringMessage());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
msg.deserialize(serializer.get(),
"[{\"testFieldInt\":-45,"
@ -536,7 +536,7 @@ void QtProtobufTypesJsonDeserializationTest::malformedJsonTest()
QCOMPARE(msg.testFieldInt(), 0);
QCOMPARE(msg.testComplexField(), SimpleStringMessage());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
}
void QtProtobufTypesJsonDeserializationTest::invalidTypeTest()
@ -550,7 +550,7 @@ void QtProtobufTypesJsonDeserializationTest::invalidTypeTest()
QCOMPARE(msg.testFieldInt(), -45);
QCOMPARE(msg.testComplexField(), SimpleStringMessage());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
// Expected integer but the value is an array
msg.deserialize(serializer.get(),
@ -560,20 +560,20 @@ void QtProtobufTypesJsonDeserializationTest::invalidTypeTest()
QCOMPARE(msg.testFieldInt(), 0);
QCOMPARE(msg.testComplexField().testFieldString(), "qwerty"_L1);
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
SimpleIntMessage intMsg;
intMsg.deserialize(serializer.get(), "{\"testFieldInt\": 0.5}");
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidFormat);
QCOMPARE(intMsg.testFieldInt(), 0);
intMsg.deserialize(serializer.get(), "{\"testFieldInt\":4294967296}");
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidFormat);
QCOMPARE(intMsg.testFieldInt(), 0);
SimpleUIntMessage uintMsg;
uintMsg.deserialize(serializer.get(), "{\"testFieldInt\":4294967296}");
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::InvalidFormatError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidFormat);
QCOMPARE(uintMsg.testFieldInt(), 0u);
}

View File

@ -57,7 +57,7 @@ void QtProtobufEnumTypesDeserializationTest::malformedJsonTest()
test.deserialize(m_serializer.get(), "{\"localEnum\":\"LOCAL_ENUM_VALUE2\"}}");
QCOMPARE(m_serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
RepeatedEnumMessage msg;
// no ']'
@ -68,7 +68,7 @@ void QtProtobufEnumTypesDeserializationTest::malformedJsonTest()
"\"LOCAL_ENUM_VALUE3\"}");
QCOMPARE(m_serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
}
void QtProtobufEnumTypesDeserializationTest::invalidTypeTest()
@ -77,7 +77,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest()
SimpleEnumMessage invalidTest;
invalidTest.deserialize(m_serializer.get(), "{\"localEnum\":\"LOCAL_ENUM_VALUE240\"}");
QCOMPARE(m_serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
RepeatedEnumMessage msg, msg2;
// 'false'
@ -87,7 +87,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest()
"\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\","
"\"LOCAL_ENUM_VALUE3\"]}");
QCOMPARE(m_serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
// no LOCAL_ENUM_VALUE_100
msg2.deserialize(m_serializer.get(),
@ -96,7 +96,7 @@ void QtProtobufEnumTypesDeserializationTest::invalidTypeTest()
"\"LOCAL_ENUM_VALUE1\",\"LOCAL_ENUM_VALUE2\","
"\"LOCAL_ENUM_VALUE3\"]}");
QCOMPARE(m_serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
}
QTEST_MAIN(QtProtobufEnumTypesDeserializationTest)

View File

@ -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->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, 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->lastError());
QCOMPARE(QAbstractProtobufSerializer::Error::None, serializer->lastError());
QCOMPARE(test.mapField().value(true), false);
QCOMPARE(test.mapField().value(false), true);
@ -224,7 +224,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest()
QVERIFY(test.mapField().empty());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
// skipped ':'
SimpleStringStringMapMessage test2;
@ -234,7 +234,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest()
QVERIFY(test2.mapField().empty());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
SimpleFixed32StringMapMessage test3;
// skipped ','
@ -243,7 +243,7 @@ void QtProtobufJsonMapTypesDeserializationTest::malformedJsonTest()
QVERIFY(test3.mapField().empty());
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
}
void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest()
@ -255,7 +255,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest()
"{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"42.3\":\"fourty two\"}}"_ba);
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
// -10 for uint32 is used
SimpleUInt32StringMapMessage uTest;
@ -264,7 +264,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest()
" two\"}}"_ba);
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
// expected int, but bool is used
bTest.deserialize(
@ -272,7 +272,7 @@ void QtProtobufJsonMapTypesDeserializationTest::invalidTypeTest()
"{\"mapField\":{\"-10\":\"minus ten\",\"15\":\"fifteen\",\"false\":\"fourty two\"}}"_ba);
QCOMPARE(serializer->lastError(),
QAbstractProtobufSerializer::InvalidFormatError);
QAbstractProtobufSerializer::Error::InvalidFormat);
}
QTEST_MAIN(QtProtobufJsonMapTypesDeserializationTest)

View File

@ -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->lastError(), QAbstractProtobufSerializer::NoError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::None);
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->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
// twice ]
RepeatedSInt64Message test;
test.deserialize(serializer.get(), "{\"testRepeatedInt\":[]1,321,-65999,12324523123123,-3,3]}"_ba);
QVERIFY(test.testRepeatedInt().size() == 0);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::UnexpectedEndOfStreamError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::UnexpectedEndOfStream);
}
@ -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->lastError(), QAbstractProtobufSerializer::InvalidFormatError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidFormat);
// 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->lastError(), QAbstractProtobufSerializer::InvalidFormatError);
QCOMPARE(serializer->lastError(), QAbstractProtobufSerializer::Error::InvalidFormat);
}

View File

@ -95,7 +95,7 @@ void tst_protobuf_any::anyMessage()
AnyMessage message;
message.deserialize(&serializer, input);
QCOMPARE_EQ(serializer.lastError(), QAbstractProtobufSerializer::NoError);
QCOMPARE_EQ(serializer.lastError(), QAbstractProtobufSerializer::Error::None);
std::optional<Example> opt = message.field().unpack<Example>(&serializer);
QVERIFY(opt.has_value());
@ -140,7 +140,7 @@ void tst_protobuf_any::repeatedAnyMessage()
// let's try to deserialize it again
RepeatedAnyMessage message2;
message2.deserialize(&serializer, input);
if (serializer.lastError() != QAbstractProtobufSerializer::NoError)
if (serializer.lastError() != QAbstractProtobufSerializer::Error::None)
QFAIL(qPrintable(serializer.lastErrorString()));
QCOMPARE_EQ(message2.anys().size(), message.anys().size());