From 51dab6dcb02dafc08c3207f81d85095a5db7d6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cl=C3=A8re?= Date: Sat, 30 Nov 2019 21:31:43 +0100 Subject: [PATCH] minor changes --- tests/QBind/QJson_impl.h | 4 ++-- tests/QBind/QValue.cpp | 43 ++++++++++++++++++------------------ tests/QBind/QValue.h | 47 ++++++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/tests/QBind/QJson_impl.h b/tests/QBind/QJson_impl.h index 4278fadf07..08dc69b9f6 100644 --- a/tests/QBind/QJson_impl.h +++ b/tests/QBind/QJson_impl.h @@ -539,8 +539,8 @@ struct QTransmogrifier { quint64 u; if ((r = v.bind(u))) { j = QJsonValue(double(u)); return r; } double d; if ((r = v.bind(d))) { j = QJsonValue( d ); return r; } v->setErrorHandler(suspended); - if (!(r = v.null())) r.handleError("ExpectedBoolDoubleQStringQJsonArrayQJsonOnjectNull"); - /**/ j = QJsonValue( ); return r; + if (!(r = v.null())) r.handleError(qBindExpectedValue); + /**/ j = QJsonValue( ); return r; } else { Q_ASSERT_X(!v, Q_FUNC_INFO, "Unsupported v->mode()"); return v.null(); } } diff --git a/tests/QBind/QValue.cpp b/tests/QBind/QValue.cpp index 85645ea5c6..8676a63f63 100644 --- a/tests/QBind/QValue.cpp +++ b/tests/QBind/QValue.cpp @@ -1,28 +1,29 @@ #include "QValue.h" -QIdentifierLiteral qBindExpectedItem ("ExpectedItem" ); -QIdentifierLiteral qBindExpectedNull ("ExpectedNull" ); -QIdentifierLiteral qBindExpectedSequence ("ExpectedSequence" ); -QIdentifierLiteral qBindExpectedRecord ("ExpectedRecord" ); -QIdentifierLiteral qBindExpectedText ("ExpectedText" ); -QIdentifierLiteral qBindExpectedBytes ("ExpectedBytes" ); -QIdentifierLiteral qBindExpectedInteger ("ExpectedInteger" ); -QIdentifierLiteral qBindExpectedDecimal ("ExpectedDecimal" ); -QIdentifierLiteral qBindExpectedSmallerNumber ("ExpectedSmallerNumber" ); +QIdentifierLiteral qBindExpectedValue ("ExpectedValue" ); +QIdentifierLiteral qBindExpectedItem ("ExpectedItem" ); +QIdentifierLiteral qBindExpectedNull ("ExpectedNull" ); +QIdentifierLiteral qBindExpectedSequence ("ExpectedSequence" ); +QIdentifierLiteral qBindExpectedRecord ("ExpectedRecord" ); +QIdentifierLiteral qBindExpectedText ("ExpectedText" ); +QIdentifierLiteral qBindExpectedBytes ("ExpectedBytes" ); +QIdentifierLiteral qBindExpectedInteger ("ExpectedInteger" ); +QIdentifierLiteral qBindExpectedDecimal ("ExpectedDecimal" ); +QIdentifierLiteral qBindExpectedSmallerNumber ("ExpectedSmallerNumber" ); QIdentifierLiteral qBindExpectedPositiveInteger("ExpectedPositiveInteger"); -QIdentifierLiteral qBindExpectedBoolean ("ExpectedBoolean" ); -QIdentifierLiteral qBindExpectedConstant ("ExpectedConstant" ); +QIdentifierLiteral qBindExpectedBoolean ("ExpectedBoolean" ); +QIdentifierLiteral qBindExpectedConstant ("ExpectedConstant" ); -QIdentifierLiteral qBindIgnoredItem ("IgnoredItem" ); -QIdentifierLiteral qBindIgnoredItemName ("IgnoredItemName" ); -QIdentifierLiteral qBindIgnoredCharacter ("IgnoredCharacter" ); -QIdentifierLiteral qBindIgnoredBytes ("IgnoredBytes" ); +QIdentifierLiteral qBindIgnoredItem ("IgnoredItem" ); +QIdentifierLiteral qBindIgnoredItemName ("IgnoredItemName" ); +QIdentifierLiteral qBindIgnoredCharacter ("IgnoredCharacter" ); +QIdentifierLiteral qBindIgnoredBytes ("IgnoredBytes" ); -QIdentifierLiteral qmDataStreamVersion ("qmDataStreamVersion" ); -QIdentifierLiteral qmColumns ("columns" ); -QIdentifierLiteral qmSizes ("sizes" ); -QIdentifierLiteral qmChildren ("children" ); -QIdentifierLiteral qmName ("name" ); -QIdentifierLiteral qmColor ("color" ); +QIdentifierLiteral qmDataStreamVersion ("qmDataStreamVersion" ); +QIdentifierLiteral qmColumns ("columns" ); +QIdentifierLiteral qmSizes ("sizes" ); +QIdentifierLiteral qmChildren ("children" ); +QIdentifierLiteral qmName ("name" ); +QIdentifierLiteral qmColor ("color" ); QValue QValueStatus::value() noexcept { return QValue(std::move(*this)); } diff --git a/tests/QBind/QValue.h b/tests/QBind/QValue.h index adc3a1ed17..870db0647d 100644 --- a/tests/QBind/QValue.h +++ b/tests/QBind/QValue.h @@ -52,23 +52,24 @@ // ////////////////////////////////////////////////////////////////////////// // Standard error names -extern QIdentifierLiteral qBindExpectedItem ; -extern QIdentifierLiteral qBindExpectedNull ; -extern QIdentifierLiteral qBindExpectedSequence ; -extern QIdentifierLiteral qBindExpectedRecord ; -extern QIdentifierLiteral qBindExpectedText ; -extern QIdentifierLiteral qBindExpectedBytes ; -extern QIdentifierLiteral qBindExpectedInteger ; -extern QIdentifierLiteral qBindExpectedDecimal ; -extern QIdentifierLiteral qBindExpectedSmallerNumber ; +extern QIdentifierLiteral qBindExpectedValue; +extern QIdentifierLiteral qBindExpectedItem; +extern QIdentifierLiteral qBindExpectedNull; +extern QIdentifierLiteral qBindExpectedSequence; +extern QIdentifierLiteral qBindExpectedRecord; +extern QIdentifierLiteral qBindExpectedText; +extern QIdentifierLiteral qBindExpectedBytes; +extern QIdentifierLiteral qBindExpectedInteger; +extern QIdentifierLiteral qBindExpectedDecimal; +extern QIdentifierLiteral qBindExpectedSmallerNumber; extern QIdentifierLiteral qBindExpectedPositiveInteger; -extern QIdentifierLiteral qBindExpectedBoolean ; -extern QIdentifierLiteral qBindExpectedConstant ; +extern QIdentifierLiteral qBindExpectedBoolean; +extern QIdentifierLiteral qBindExpectedConstant; -extern QIdentifierLiteral qBindIgnoredItem ; -extern QIdentifierLiteral qBindIgnoredItemName ; -extern QIdentifierLiteral qBindIgnoredCharacter ; -extern QIdentifierLiteral qBindIgnoredBytes ; +extern QIdentifierLiteral qBindIgnoredItem; +extern QIdentifierLiteral qBindIgnoredItemName; +extern QIdentifierLiteral qBindIgnoredCharacter; +extern QIdentifierLiteral qBindIgnoredBytes; // ////////////////////////////////////////////////////////////////////////// // Standard meta data names @@ -262,7 +263,7 @@ public: QValueStatus* operator ->() noexcept { return this; } QVal value() noexcept ; - QValueErrorHandler setErrorHandler(QValueErrorHandler newHandler = nullptr) { return Q_LIKELY(impl) ? impl->setErrorHandler(newHandler) : nullptr; } + QValueErrorHandler setErrorHandler(QValueErrorHandler newHandler = nullptr) { return Q_LIKELY(impl) ? impl->setErrorHandler(newHandler) : nullptr; } bool handleError(QIdentifierLiteral name, QString context = QString()) { return Q_LIKELY(impl) ? impl->handleError(name, context) : false; } bool handleError(const char* asciiName, QString context = QString()) { return handleError(QIdentifierLiteral(asciiName), context); } protected: @@ -557,7 +558,7 @@ struct QAbstractValueWriter : public QAbstractValue } return tryOut(); } - if (src.canConvert() ) { // TODO _meta({{qmColumns,"key,value"}}) trySequence() ... + if (src.canConvert()) { // TODO _meta(qmColumns,"key,value") trySequence() ... QAssociativeIterable ts = src.value(); quint32 size=quint32(ts.size()); if (!tryRecord(&size)) { @@ -730,16 +731,16 @@ struct QAbstractValueReader : public QAbstractValue ||(tryRecord () && tryOut())) { return true; } - bool b; // usually easier to check than types below - double d; // matches most used numbers more easily than types below - qint64 i; // matches most used integrals more easily than types below + bool b; // usually easier to check than types below + double d; // matches most used numbers more easily than types below + qint64 i; // matches most used integrals more easily than types below quint64 u; QVariant v; QByteArray bytes; QString s; // matches any type with usually less encoding work than QUtf8Data (which only captures efficiently utf-8 whereas QChar easily captures Latin1 in addition to ASCII) - tryBind(b) || tryBind(d) || tryBind(i) || tryBind(u) || tryBind(v) || tryBind(bytes) || tryNull(); + bool bound = tryBind(b) || tryBind(d) || tryBind(i) || tryBind(u) || tryBind(v) || tryBind(bytes) || tryNull(); setErrorHandler(suspended); - return true; + return bound || handleError(qBindExpectedValue); } QValueErrorHandler setErrorHandler(QValueErrorHandler newHandler = nullptr) { auto previousHandler = errorHandler; errorHandler = newHandler; return previousHandler; } @@ -1186,7 +1187,7 @@ struct QTransmogrifier { double d; if ((srcRes = src.bind( d))) { dst.bind( d); return srcRes; } //! \remark Double-precision floating point numeric types can only be handled if QAbstractValue refuses to lose leading digits or precision // TODO Other BindNative types we do not want to treat as text: QDateTime, QUuid src->setErrorHandler(suspended); - srcRes.handleError("ExpectedSequenceRecordNullTextBytesBooleanIntegerDecimal"); + srcRes.handleError(qBindExpectedValue); return srcRes; } else if (src->mode()==Write && dst->mode()==Read) { return zap(std::move(dst),std::move(src)); } // To return reader's QValueStatus instead of writer's QValueStatus since it should contain more information (mismatches, etc.) -- GitLab