From b2173b54ef9ede85d88cb0fdf025b26e732ed44a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 5 Jan 2017 15:43:21 +0100 Subject: Long live QTest::addRow()! This new function does the same as newRow(), except that it has a less confusing name (in line with _add_Column()), and accepts printf-style arguments to avoid the need to newRow(qPrintable(QString::asprintf())), a common pattern in client code. It uses qvsnprintf() under the hoods, avoiding the need for the QString const char* round-trip. Port all in-tree users of newRow(qPrintable(QString::asnprintf())) to the new function. Change-Id: Icd5de9b7ea4f6759d98080ec30f5aecadb8bec39 Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp | 8 ++++---- tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 2 +- tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp | 8 ++++---- tests/auto/corelib/tools/qchar/tst_qchar.cpp | 2 +- tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp | 6 +++--- tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp index 7ffb5d0fd7..66fc578d5f 100644 --- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp +++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp @@ -112,13 +112,13 @@ void tst_QGetPutEnv::intValue_data() ROW(0xffffffff, 0, false); const int bases[] = {10, 8, 16}; for (size_t i = 0; i < sizeof bases / sizeof *bases; ++i) { - QTest::newRow(qPrintable(QString::asprintf("INT_MAX, base %d", bases[i]))) + QTest::addRow("INT_MAX, base %d", bases[i]) << QByteArray::number(INT_MAX) << INT_MAX << true; - QTest::newRow(qPrintable(QString::asprintf("INT_MAX+1, base %d", bases[i]))) + QTest::addRow("INT_MAX+1, base %d", bases[i]) << QByteArray::number(qlonglong(INT_MAX) + 1) << 0 << false; - QTest::newRow(qPrintable(QString::asprintf("INT_MIN, base %d", bases[i]))) + QTest::addRow("INT_MIN, base %d", bases[i]) << QByteArray::number(INT_MIN) << INT_MIN << true; - QTest::newRow(qPrintable(QString::asprintf("INT_MIN-1, base %d", bases[i]))) + QTest::addRow("INT_MIN-1, base %d", bases[i]) << QByteArray::number(qlonglong(INT_MIN) - 1) << 0 << false; }; } diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index bf778e9fd1..e6c3a0cfd7 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -143,7 +143,7 @@ void tst_QMutex::convertToMilliseconds_data() auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { const QScopedArrayPointer enumName(QTest::toString(unit)); - QTest::newRow(qPrintable(QString::asprintf("%s:%f:%lld", enumName.data(), d, i))) + QTest::addRow("%s:%f:%lld", enumName.data(), d, i) << unit << d << qint64(i) << expected; }; diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index c14e9fadf7..e13c2894af 100644 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -1076,22 +1076,22 @@ void tst_QAlgorithms::popCount_data_impl(size_t sizeof_T_Int) const uint bits = bitsSetInByte(byte); const quint64 value = static_cast(byte); const quint64 input = value << ((i % sizeof_T_Int) * 8U); - newRow(qPrintable(QString::asprintf("0x%016llx", input))) << input << bits; + QTest::addRow("0x%016llx", input) << input << bits; } // and some random ones: if (sizeof_T_Int >= 8) for (size_t i = 0; i < 1000; ++i) { const quint64 input = quint64(qrand()) << 32 | quint32(qrand()); - newRow(qPrintable(QString::asprintf("0x%016llx", input))) << input << bitsSetInInt64(input); + QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input); } else if (sizeof_T_Int >= 2) for (size_t i = 0; i < 1000 ; ++i) { const quint32 input = qrand(); if (sizeof_T_Int >= 4) - newRow(qPrintable(QString::asprintf("0x%08x", input))) << quint64(input) << bitsSetInInt(input); + QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input); else - newRow(qPrintable(QString::asprintf("0x%04x", quint16(input & 0xFFFF)))) << quint64(input & 0xFFFF) << bitsSetInShort(input & 0xFFFF); + QTest::addRow("0x%04x", quint16(input & 0xFFFF)) << quint64(input & 0xFFFF) << bitsSetInShort(input & 0xFFFF); } } diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index fb436b67d6..13898ace7b 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -108,7 +108,7 @@ void tst_QChar::operators_data() for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) - QTest::newRow(qPrintable(QString::asprintf("'\\%d' (op) '\\%d'", i, j))) + QTest::addRow("'\\%d' (op) '\\%d'", i, j) << QChar(ushort(i)) << QChar(ushort(j)); } } diff --git a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp index 06e2e1cc45..a68671d899 100644 --- a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp +++ b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp @@ -176,9 +176,9 @@ void tst_QLatin1String::relationalOperators_data() for (Data *lhs = data; lhs != data + sizeof data / sizeof *data; ++lhs) { for (Data *rhs = data; rhs != data + sizeof data / sizeof *data; ++rhs) { QLatin1StringContainer l = { lhs->l1 }, r = { rhs->l1 }; - QTest::newRow(qPrintable(QString::asprintf("\"%s\" <> \"%s\"", - lhs->l1.data() ? lhs->l1.data() : "nullptr", - rhs->l1.data() ? rhs->l1.data() : "nullptr"))) + QTest::addRow("\"%s\" <> \"%s\"", + lhs->l1.data() ? lhs->l1.data() : "nullptr", + rhs->l1.data() ? rhs->l1.data() : "nullptr") << l << lhs->order << r << rhs->order; } } diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp index 9e5fc55379..cd5aa03689 100644 --- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp +++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp @@ -151,10 +151,10 @@ static void makeRow(QSizePolicy sp, QSizePolicy::Policy hp, QSizePolicy::Policy int hst, int vst, QSizePolicy::ControlType ct, bool hfw, bool wfh, Qt::Orientations orients) { - QTest::newRow(qPrintable(QString::asprintf("%s-%s-%d-%d-%s-%s-%s", - PrettyPrint(hp).s(), PrettyPrint(vp).s(), hst, vst, - PrettyPrint(ct).s(), - hfw ? "true" : "false", wfh ? "true" : "false"))) + QTest::addRow("%s-%s-%d-%d-%s-%s-%s", + PrettyPrint(hp).s(), PrettyPrint(vp).s(), hst, vst, + PrettyPrint(ct).s(), + hfw ? "true" : "false", wfh ? "true" : "false") << sp << hp << vp << hst << vst << ct << hfw << wfh << orients; } -- cgit v1.2.3