diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-06-20 16:45:12 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-06-20 16:45:12 +0200 |
commit | 6213b8145772d3dc584907a544f6c46b8cef74e2 (patch) | |
tree | 4c1902793bb78511e63c09cbe92f9eda6b3d7237 /tests/auto/corelib/kernel/qvariant | |
parent | 75e9c7d6bc662e62e9ce8b641588183992c1e8bf (diff) | |
parent | 25739bebba0343a8b35775a073c49f0fba080762 (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm
src/plugins/platforms/qnx/qqnxrasterbackingstore.cpp
tools/configure/configureapp.cpp
Change-Id: I3092bd3276af14304b7ab3ae1e1cc05d11cdede0
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index fff65a50a4..dab40db0ec 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -142,6 +142,9 @@ private slots: void toDouble_data(); void toDouble(); + void toFloat_data(); + void toFloat(); + void toPointF_data(); void toPointF(); @@ -459,6 +462,9 @@ void tst_QVariant::canConvert_data() var = QVariant::fromValue<signed char>(-1); QTest::newRow("SChar") << var << N << N << Y << N << Y << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; + var = QVariant::fromValue<QJsonValue>(QJsonValue(QStringLiteral("hello"))); + QTest::newRow("JsonValue") + << var << N << N << Y << N << N << N << N << N << N << Y << N << N << Y << N << N << N << Y << N << N << N << N << N << N << N << N << N << Y << N << N << Y << Y; #undef N #undef Y @@ -514,6 +520,7 @@ void tst_QVariant::toInt_data() bytearray[2] = '0'; bytearray[3] = '0'; QTest::newRow( "QByteArray2" ) << QVariant( bytearray ) << 4500 << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << 321 << true; } void tst_QVariant::toInt() @@ -560,6 +567,7 @@ void tst_QVariant::toUInt_data() bytearray[2] = '2'; bytearray[3] = '1'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (uint)4321 << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (uint)321 << true; } void tst_QVariant::toUInt() @@ -745,6 +753,8 @@ void tst_QVariant::toBool_data() QTest::newRow( "ulonglong1" ) << QVariant( (qulonglong)1 ) << true; QTest::newRow( "QChar" ) << QVariant(QChar('a')) << true; QTest::newRow( "Null_QChar" ) << QVariant(QChar(0)) << false; + QTest::newRow("QJsonValue(true)") << QVariant(QJsonValue(true)) << true; + QTest::newRow("QJsonValue(false)") << QVariant(QJsonValue(false)) << false; } void tst_QVariant::toBool() @@ -808,6 +818,7 @@ void tst_QVariant::toDouble_data() bytearray[2] = '.'; bytearray[3] = '1'; QTest::newRow( "bytearray" ) << QVariant( bytearray ) << 32.1 << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(32.1)) << 32.1 << true; } void tst_QVariant::toDouble() @@ -823,6 +834,34 @@ void tst_QVariant::toDouble() QVERIFY( ok == valueOK ); } +void tst_QVariant::toFloat_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<float>("result"); + QTest::addColumn<bool>("valueOK"); + + QByteArray bytearray(4, ' '); + bytearray[0] = '3'; + bytearray[1] = '2'; + bytearray[2] = '.'; + bytearray[3] = '1'; + QTest::newRow("QByteArray") << QVariant(bytearray) << float(32.1) << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(32.1)) << float(32.1) << true; +} + +void tst_QVariant::toFloat() +{ + QFETCH(QVariant, value ); + QFETCH(float, result); + QFETCH(bool, valueOK); + QVERIFY(value.isValid()); + QVERIFY(value.canConvert(QMetaType::Float)); + bool ok; + float d = value.toFloat(&ok); + QCOMPARE(d, result); + QVERIFY(ok == valueOK); +} + void tst_QVariant::toLongLong_data() { QTest::addColumn<QVariant>("value"); @@ -846,6 +885,7 @@ void tst_QVariant::toLongLong_data() bytearray[2] = '0'; bytearray[3] = '0'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qlonglong) 3200 << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qlonglong)321 << true; } void tst_QVariant::toLongLong() @@ -890,6 +930,7 @@ void tst_QVariant::toULongLong_data() bytearray[2] = '0'; bytearray[3] = '1'; QTest::newRow( "QByteArray" ) << QVariant( bytearray ) << (qulonglong) 3201 << true; + QTest::newRow("QJsonValue") << QVariant(QJsonValue(321)) << (qulonglong)321 << true; } void tst_QVariant::toULongLong() @@ -956,6 +997,7 @@ void tst_QVariant::toString_data() QTest::newRow( "qdatetime" ) << QVariant( QDateTime( QDate( 2002, 1, 1 ), QTime( 12, 34, 56 ) ) ) << QString( "2002-01-01T12:34:56.000" ); QTest::newRow( "llong" ) << QVariant( (qlonglong)Q_INT64_C(123456789012) ) << QString( "123456789012" ); + QTest::newRow("QJsonValue") << QVariant(QJsonValue(QString("hello"))) << QString("hello"); } void tst_QVariant::toString() |