error C2440: 'static_cast': cannot convert from 'double' to 'PassmarkLineType'.
Conversions between enumeration and floating point values are no longer allowed. --HG-- branch : develop
This commit is contained in:
parent
d791649170
commit
aa6a75298c
|
@ -664,7 +664,7 @@ void AbstractTest::QPointFromJson(const QJsonObject &itemObject, QPointF &point)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
template<typename T, typename std::enable_if<std::is_floating_point<T>::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<typename T, typename std::enable_if<std::is_enum<T>::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<T>(static_cast<int>(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<T>(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<typename T, typename std::enable_if<std::is_integral<T>::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<T>(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<T>(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)
|
||||
{
|
||||
|
|
|
@ -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 <typename T>
|
||||
template <typename T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr>
|
||||
void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
||||
const QString &defaultValue = QString());
|
||||
template <typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
|
||||
void ReadDoubleValue(const QJsonObject &itemObject, const QString &attribute, T &value,
|
||||
const QString &defaultValue = QString());
|
||||
template <typename T, typename std::enable_if<std::is_integral<T>::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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user