diff options
author | Erik Verbruggen <erik.verbruggen@me.com> | 2013-09-09 15:52:06 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-09 17:44:16 +0200 |
commit | 3dbc7a72c7e38b2a34df3a9ef496547c795420af (patch) | |
tree | c52a1b2d8c4926dcd5ae1cad8a5c085ed7710463 /tests/auto/qml/qqmllanguage | |
parent | 49fad77637be8fc2b0744fb33917dc806b701545 (diff) |
Fix return type checks in test.
When calling into JavaScript, the specific type of the return value can
differ if that return value is a number. This is not only the case for
non-integral numbers, or numbers that do not fit into the (signed)
integer range, but it also depends on which optimizations are run. to
check if the return value is of a number type, use this method instead
of checking against a specific userType.
Change-Id: I0464c062bd617c83b7a1e887f7853aa5cd8f43e4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qml/qqmllanguage')
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index b5c8edf5f3..3e2493effe 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -198,6 +198,18 @@ private: QStringList defaultImportPathList; void testType(const QString& qml, const QString& type, const QString& error, bool partialMatch = false); + + // When calling into JavaScript, the specific type of the return value can differ if that return + // value is a number. This is not only the case for non-integral numbers, or numbers that do not + // fit into the (signed) integer range, but it also depends on which optimizations are run. So, + // to check if the return value is of a number type, use this method instead of checking against + // a specific userType. + static bool isJSNumberType(int userType) + { + return userType == (int) QVariant::Int + || userType == (int) QVariant::UInt + || userType == (int) QVariant::Double; + } }; #define DETERMINE_ERRORS(errorfile,expected,actual)\ @@ -841,8 +853,8 @@ void tst_qqmllanguage::bindJSValueToVar() QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QCOMPARE(object->property("test1Bound").userType(), (int)QVariant::Int); - QCOMPARE(object->property("test20Bound").userType(), (int)QVariant::Double); + QVERIFY(isJSNumberType(object->property("test1Bound").userType())); + QVERIFY(isJSNumberType(object->property("test20Bound").userType())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); @@ -890,8 +902,8 @@ void tst_qqmllanguage::bindJSValueToVariant() QCOMPARE(object->property("test14").userType(), (int)QVariant::PointF); QCOMPARE(object->property("test15").userType(), (int)QVariant::SizeF); QCOMPARE(object->property("test16").userType(), (int)QVariant::Vector3D); - QCOMPARE(object->property("test1Bound").userType(), (int)QVariant::Int); - QCOMPARE(object->property("test20Bound").userType(), (int)QVariant::Double); + QVERIFY(isJSNumberType(object->property("test1Bound").userType())); + QVERIFY(isJSNumberType(object->property("test20Bound").userType())); QCOMPARE(object->property("test1"), QVariant(5)); QCOMPARE(object->property("test2"), QVariant((double)1.7)); |