From aa6a75298c95318c194ac53ac243de42ec411697 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 5 Sep 2019 17:21:06 +0300 Subject: [PATCH] error C2440: 'static_cast': cannot convert from 'double' to 'PassmarkLineType'. Conversions between enumeration and floating point values are no longer allowed. --HG-- branch : develop --- src/libs/vtest/abstracttest.cpp | 80 ++++++++++++++++++++++++++++++++- src/libs/vtest/abstracttest.h | 8 +++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/libs/vtest/abstracttest.cpp b/src/libs/vtest/abstracttest.cpp index 9e13d0286..15d1b343d 100644 --- a/src/libs/vtest/abstracttest.cpp +++ b/src/libs/vtest/abstracttest.cpp @@ -664,7 +664,7 @@ void AbstractTest::QPointFromJson(const QJsonObject &itemObject, QPointF &point) } //--------------------------------------------------------------------------------------------------------------------- -template +template::value>::type*> void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, const QString &defaultValue) { @@ -702,6 +702,84 @@ void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString } } +//--------------------------------------------------------------------------------------------------------------------- +template::value>::type*> +void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, + const QString &defaultValue) +{ + if (itemObject.contains(attribute)) + { + QJsonValue attributeValue = itemObject[attribute]; + if (attributeValue.isDouble()) + { + value = static_cast(static_cast(attributeValue.toDouble())); + } + else + { + const QString error = QStringLiteral("%1 is not double '%2'.").arg(attribute, attributeValue.toString()); + QFAIL(qUtf8Printable(error)); + } + } + else + { + if (not defaultValue.isEmpty()) + { + bool ok = false; + value = static_cast(defaultValue.toInt(&ok)); + + if (not ok) + { + const QString error = QStringLiteral("Cannot convert default value '%1' to int.").arg(defaultValue); + QFAIL(qUtf8Printable(error)); + } + } + else + { + const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute); + QFAIL(qUtf8Printable(error)); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +template::value>::type*> +void AbstractTest::ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, + const QString &defaultValue) +{ + if (itemObject.contains(attribute)) + { + QJsonValue attributeValue = itemObject[attribute]; + if (attributeValue.isDouble()) + { + value = static_cast(attributeValue.toDouble()); + } + else + { + const QString error = QStringLiteral("%1 is not double '%2'.").arg(attribute, attributeValue.toString()); + QFAIL(qUtf8Printable(error)); + } + } + else + { + if (not defaultValue.isEmpty()) + { + bool ok = false; + value = static_cast(defaultValue.toInt(&ok)); + + if (not ok) + { + const QString error = QStringLiteral("Cannot convert default value '%1' to int.").arg(defaultValue); + QFAIL(qUtf8Printable(error)); + } + } + else + { + const QString error = QStringLiteral("Json object does not contain attribute '%1'.").arg(attribute); + QFAIL(qUtf8Printable(error)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void AbstractTest::VPointFromJson(const QJsonObject &itemObject, VPointF &point) { diff --git a/src/libs/vtest/abstracttest.h b/src/libs/vtest/abstracttest.h index 127cad6da..ca9bb70c3 100644 --- a/src/libs/vtest/abstracttest.h +++ b/src/libs/vtest/abstracttest.h @@ -91,7 +91,13 @@ protected: void PrepareDocument(const QString &json, QByteArray &data) const; void TestRoot(const QJsonObject &root, const QString &attribute, const QString &file); - template + template ::value>::type* = nullptr> + void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, + const QString &defaultValue = QString()); + template ::value>::type* = nullptr> + void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, + const QString &defaultValue = QString()); + template ::value>::type* = nullptr> void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value, const QString &defaultValue = QString()); void ReadStringValue(const QJsonObject &itemObject, const QString &attribute, QString &value,