tst_qvariant: fix comparison ambiguity for QMetaEnum value
Under certain circumstances, VS2015 reported ambiguous options in using the operator>(Enum,int) operator. This change adds a static_cast<qint64> to remove any ambiguity. In the process of testing this change, a gap in the existing logic was identified: the handling (just in the test code) of large negative enum values. Consequently, and additional test case was added, and additional if-conditions were added to account for that case. Change-Id: Ife2c471ba4caa4b9a0107722042114e58145c4d0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
36f8816555
commit
e5d303cb9f
|
|
@ -80,7 +80,7 @@ public:
|
|||
enum MetaEnumTest_Enum1 { MetaEnumTest_Enum1_value = 42, MetaEnumTest_Enum1_bigValue = (Q_INT64_C(1) << 33) + 50 };
|
||||
Q_ENUM(MetaEnumTest_Enum1)
|
||||
|
||||
enum MetaEnumTest_Enum3 ENUM_SIZE(qint64) { MetaEnumTest_Enum3_value = -47, MetaEnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5 };
|
||||
enum MetaEnumTest_Enum3 ENUM_SIZE(qint64) { MetaEnumTest_Enum3_value = -47, MetaEnumTest_Enum3_bigValue = (Q_INT64_C(1) << 56) + 5, MetaEnumTest_Enum3_bigNegValue = -(Q_INT64_C(1) << 56) - 3 };
|
||||
Q_ENUM(MetaEnumTest_Enum3)
|
||||
enum MetaEnumTest_Enum4 ENUM_SIZE(quint64) { MetaEnumTest_Enum4_value = 47, MetaEnumTest_Enum4_bigValue = (Q_INT64_C(1) << 52) + 45 };
|
||||
Q_ENUM(MetaEnumTest_Enum4)
|
||||
|
|
@ -4671,7 +4671,7 @@ template<typename Enum> void testVariant(Enum value, bool *ok)
|
|||
QVERIFY(var2.convert(QMetaType::Int));
|
||||
QCOMPARE(var2.value<int>(), static_cast<int>(value));
|
||||
|
||||
if (static_cast<qint64>(value) <= INT_MAX) {
|
||||
if ((static_cast<qint64>(value) <= INT_MAX) && (static_cast<qint64>(value) >= INT_MIN)) {
|
||||
int intValue = static_cast<int>(value);
|
||||
QVariant intVar = intValue;
|
||||
QVERIFY(intVar.canConvert<Enum>());
|
||||
|
|
@ -4732,7 +4732,7 @@ template<typename Enum> void testVariantMeta(Enum value, bool *ok, const char *s
|
|||
|
||||
QVariant strVar = QString::fromLatin1(string);
|
||||
QVERIFY(strVar.canConvert<Enum>());
|
||||
if (value > INT_MAX) {
|
||||
if ((static_cast<qint64>(value) > INT_MAX) || (static_cast<qint64>(value) < INT_MIN)) {
|
||||
QEXPECT_FAIL("", "QMetaEnum api uses 'int' as return type QTBUG-27451", Abort);
|
||||
*ok = true;
|
||||
}
|
||||
|
|
@ -4754,6 +4754,7 @@ void tst_QVariant::metaEnums()
|
|||
METAENUMS_TEST(MetaEnumTest_Enum1_bigValue);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum3_value);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum3_bigValue);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum3_bigNegValue);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum4_value);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum4_bigValue);
|
||||
METAENUMS_TEST(MetaEnumTest_Enum5_value);
|
||||
|
|
|
|||
Loading…
Reference in New Issue