diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-20 09:58:20 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-20 09:59:44 (GMT) |
commit | 264eb347595cc92a444e3908831d89acef1f05b3 (patch) | |
tree | b00fe745eb671ff1a245e9714dcb3a169d0e13c0 /tests/auto | |
parent | dd5877fe48d647f1da20995c4d833d76ed43fd84 (diff) | |
download | Qt-264eb347595cc92a444e3908831d89acef1f05b3.zip Qt-264eb347595cc92a444e3908831d89acef1f05b3.tar.gz Qt-264eb347595cc92a444e3908831d89acef1f05b3.tar.bz2 |
Fix QVariant::toFloat() and QVariant::toReal
Reviewed-by: Thierry
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qvariant/tst_qvariant.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 9ad4482..709cba9 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -267,6 +267,8 @@ private slots: void convertByteArrayToBool_data() const; void toIntFromQString() const; void task256984_setValue(); + + void numericalConvert(); }; Q_DECLARE_METATYPE(QDate) @@ -3060,11 +3062,45 @@ void tst_QVariant::task256984_setValue() QVERIFY( !v2.isDetached() ); qVariantSetValue(v2, 3); //set an integer value - + QVERIFY( v1.isDetached() ); QVERIFY( v2.isDetached() ); } +void tst_QVariant::numericalConvert() +{ + QVariant vfloat(float(5.3)); + QVariant vdouble(double(5.3)); + QVariant vreal(qreal(5.3)); + QVariant vint(int(5)); + QVariant vuint(uint(5)); + QVariant vshort(short(5)); + QVariant vlonglong(quint64(5)); + QVariant vstringint(QString::fromLatin1("5")); + QVariant vstring(QString::fromLatin1("5.3")); + + QVector<QVariant *> vect; + vect << &vfloat << &vdouble << &vreal << &vint << &vuint << &vshort<< &vlonglong << &vstringint << &vstring; + + for(int i = 0; i < vect.size(); i++) { + double num = 5.3; + if (i >= 3 && i <= 7) + num = 5; + QVariant *v = vect.at(i); + QCOMPARE(v->toFloat() , float(num)); + QCOMPARE(float(v->toReal()) , float(num)); + QCOMPARE(float(v->toDouble()) , float(num)); + if(i != 8) { + QCOMPARE(v->toInt() , int(num)); + QCOMPARE(v->toUInt() , uint(num)); + QCOMPARE(v->toULongLong() , quint64(num)); + } + QCOMPARE(v->toString() , QString::number(num)); + } +} + + + QTEST_MAIN(tst_QVariant) #include "tst_qvariant.moc" |