summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp38
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"