tst_QString: add checks for sprintf's %ls

... at the cost of a bunch of warnings about
ushort*/wchar_t*.

It wasn't checked at all, which isn't really a solution,
either.

Split off the %s checks into a separate function, which
makes obvious the sorry state of sprintf non-%s, non-%d
testing that's left.

Change-Id: I6312f984bacfb568b609e34b5218b3ab9a9765c4
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-11-12 09:16:13 +01:00
parent e4e10fa2d5
commit ceb71d5b3f

View File

@ -480,6 +480,7 @@ private slots:
void indexOf3_data();
// void indexOf3();
void sprintf();
void sprintfS();
void fill();
void truncate();
void constructor();
@ -1252,7 +1253,11 @@ void tst_QString::sprintf()
double d = -514.25683;
S1.sprintf("%f",d);
QCOMPARE(S1, QString("-514.256830"));
}
void tst_QString::sprintfS()
{
QString a;
QCOMPARE(a.sprintf("%.3s", "Hello" ), QLatin1String("Hel"));
QCOMPARE(a.sprintf("%10.3s", "Hello" ), QLatin1String(" Hel"));
QCOMPARE(a.sprintf("%.10s", "Hello" ), QLatin1String("Hello"));
@ -1272,6 +1277,26 @@ void tst_QString::sprintf()
a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz");
QCOMPARE((int)n2, 6);
QCOMPARE(a, QString("foobarwhiz"));
{ // %ls
QCOMPARE(a.sprintf("%.3ls", QString("Hello").utf16() ), QLatin1String("Hel"));
QCOMPARE(a.sprintf("%10.3ls", QString("Hello").utf16() ), QLatin1String(" Hel"));
QCOMPARE(a.sprintf("%.10ls", QString("Hello").utf16() ), QLatin1String("Hello"));
QCOMPARE(a.sprintf("%10.10ls", QString("Hello").utf16() ), QLatin1String(" Hello"));
QCOMPARE(a.sprintf("%-10.10ls", QString("Hello").utf16() ), QLatin1String("Hello "));
QCOMPARE(a.sprintf("%-10.3ls", QString("Hello").utf16() ), QLatin1String("Hel "));
QCOMPARE(a.sprintf("%-5.5ls", QString("Hello").utf16() ), QLatin1String("Hello"));
// Check utf16 is preserved for %ls
QCOMPARE(a.sprintf("%ls",
QString::fromUtf8("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205").utf16()),
QLatin1String("\366\344\374\326\304\334\370\346\345\330\306\305"));
int n;
a.sprintf("%ls%n%s", QString("hello").utf16(), &n, "goodbye");
QCOMPARE(n, 5);
QCOMPARE(a, QLatin1String("hellogoodbye"));
}
}
/*