diff options
Diffstat (limited to 'tests/auto/corelib/text/qstring/tst_qstring.cpp')
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index c9fbff67c3..26d10244ae 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -594,6 +594,7 @@ private slots: void isValidUtf16_data(); void isValidUtf16(); void unicodeStrings(); + void vasprintfWithPrecision(); }; template <class T> const T &verifyZeroTermination(const T &t) { return t; } @@ -7088,6 +7089,35 @@ void tst_QString::isValidUtf16() QTEST(string.isValidUtf16(), "valid"); } +static QString doVasprintf(const char *msg, ...) { + va_list args; + va_start(args, msg); + const QString result = QString::vasprintf(msg, args); + va_end(args); + return result; +} + +void tst_QString::vasprintfWithPrecision() +{ + { + const char *msg = "Endpoint %.*s with"; + static const char arg0[3] = { 'a', 'b', 'c' }; + static const char arg1[4] = { 'a', 'b', 'c', '\0' }; + QCOMPARE(doVasprintf(msg, 3, arg0), QStringLiteral("Endpoint abc with")); + QCOMPARE(doVasprintf(msg, 9, arg1), QStringLiteral("Endpoint abc with")); + QCOMPARE(doVasprintf(msg, 0, nullptr), QStringLiteral("Endpoint with")); + } + + { + const char *msg = "Endpoint %.*ls with"; + static const ushort arg0[3] = { 'a', 'b', 'c' }; + static const ushort arg1[4] = { 'a', 'b', 'c', '\0' }; + QCOMPARE(doVasprintf(msg, 3, arg0), QStringLiteral("Endpoint abc with")); + QCOMPARE(doVasprintf(msg, 9, arg1), QStringLiteral("Endpoint abc with")); + QCOMPARE(doVasprintf(msg, 0, nullptr), QStringLiteral("Endpoint with")); + } +} + // QString's collation order is only supported during the lifetime as QCoreApplication QTEST_GUILESS_MAIN(tst_QString) |