diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-11-29 13:21:43 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-11-29 14:10:08 +0000 |
commit | 33c50e910c6f8ed68994e4968389603ddb8bc6f7 (patch) | |
tree | e0dd29a02b7c64c8b9041a8e8406b54e549aa8c4 /tests/auto/corelib/tools/qstring | |
parent | 7adbdddbb6b6977e8b86ea0bf6262721d0c6ef6e (diff) |
Fix tst_QString::sprintf()
Compare to QLatin1String and use reinterpret_cast to fix MSVC warning:
tst_qstring.cpp(1271): warning C4312: 'type cast': conversion from 'unsigned int' to 'void *' of greater size
Change-Id: I4f26d72f0fad59e09636fe609a2772309a688e5c
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/corelib/tools/qstring')
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index a0a872710c..414ba2d8cf 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1255,6 +1255,11 @@ void tst_QString::fill() QCOMPARE(f, QLatin1String("FFF")); } +static inline const void *ptrValue(quintptr v) +{ + return reinterpret_cast<const void *>(v); +} + void tst_QString::sprintf() { QString a; @@ -1266,21 +1271,21 @@ void tst_QString::sprintf() QCOMPARE(a.sprintf("X%9iY", 50000 ), QLatin1String("X 50000Y")); QCOMPARE(a.sprintf("X%-9sY","hello"), QLatin1String("Xhello Y")); QCOMPARE(a.sprintf("X%-9iY", 50000 ), QLatin1String("X50000 Y")); - QCOMPARE(a.sprintf("%lf", 1.23), QString("1.230000")); - QCOMPARE(a.sprintf("%lf", 1.23456789), QString("1.234568")); - QCOMPARE(a.sprintf("%p", (void *)0xbfffd350), QString("0xbfffd350")); - QCOMPARE(a.sprintf("%p", (void *)0), QString("0x0")); + QCOMPARE(a.sprintf("%lf", 1.23), QLatin1String("1.230000")); + QCOMPARE(a.sprintf("%lf", 1.23456789), QLatin1String("1.234568")); + QCOMPARE(a.sprintf("%p", ptrValue(0xbfffd350)), QLatin1String("0xbfffd350")); + QCOMPARE(a.sprintf("%p", ptrValue(0)), QLatin1String("0x0")); int i = 6; long l = -2; float f = 4.023f; QString S1; S1.sprintf("%d %ld %f",i,l,f); - QCOMPARE(S1,QString("6 -2 4.023000")); + QCOMPARE(S1, QLatin1String("6 -2 4.023000")); double d = -514.25683; S1.sprintf("%f",d); - QCOMPARE(S1, QString("-514.256830")); + QCOMPARE(S1, QLatin1String("-514.256830")); } void tst_QString::sprintfS() |