summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-07-22 11:06:27 +0200
committerMarc Mutz <[email protected]>2024-08-03 10:30:05 +0000
commita15ff49be73228bbbc72989736d32059322c414f (patch)
treeb0fbefbd1d879ba45438dadce0f0ef25f7dc51a1 /src/testlib/qtestcase.cpp
parentb2b0a5df25c32c3c36c731e2f5ca092edc2c8385 (diff)
QTest: simplify qPrintDataTags() string building
Use higher-level API (QByteArray::chopped()/operator+()) instead of new[] and qsnprintf(). methodSignature() already heavily depends on QByteArray concatenation, therefore trying to avoid using Qt code in QtTest is pointless, at least here. Drive-by indent lines so a follow-up port to std::fsprintf() will not have to re-indent these lines again. Amends b68bae1132b5dc5c8f55435c72cd48e24aa52ec9. Pick-to: 6.8 6.7 6.5 Change-Id: I94ec440d7e6d09196cf87cd3dbbfd765e0df69d0 Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 92358ab8c1c..2de43eb33cb 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -555,11 +555,8 @@ static void qPrintDataTags(FILE *stream)
// Retrieve local tags:
QStringList localTags;
QTestTable table;
- char *slot = qstrdup(tf.methodSignature().constData());
- slot[strlen(slot) - 2] = '\0';
- QByteArray member;
- member.resize(qstrlen(slot) + qstrlen("_data()") + 1);
- qsnprintf(member.data(), member.size(), "%s_data()", slot);
+ const QByteArray slot = tf.methodSignature().chopped(2);
+ const QByteArray member = slot + "_data()";
invokeTestMethodIfExists(member.constData());
const int dataCount = table.dataCount();
localTags.reserve(dataCount);
@@ -570,13 +567,15 @@ static void qPrintDataTags(FILE *stream)
if (gTable->dataCount() == 0) {
if (localTags.size() == 0) {
// No tags at all, so just print the test function:
- fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot);
+ fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot.data());
} else {
// Only local tags, so print each of them:
for (int k = 0; k < localTags.size(); ++k)
fprintf(
stream, "%s %s %s\n",
- currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
+ currTestMetaObj->className(),
+ slot.data(),
+ localTags.at(k).toLatin1().data());
}
} else {
for (int j = 0; j < gTable->dataCount(); ++j) {
@@ -584,19 +583,21 @@ static void qPrintDataTags(FILE *stream)
// Only global tags, so print the current one:
fprintf(
stream, "%s %s __global__ %s\n",
- currTestMetaObj->className(), slot, gTable->testData(j)->dataTag());
+ currTestMetaObj->className(),
+ slot.data(),
+ gTable->testData(j)->dataTag());
} else {
// Local and global tags, so print each of the local ones and
// the current global one:
for (int k = 0; k < localTags.size(); ++k)
fprintf(
- stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot,
+ stream, "%s %s %s __global__ %s\n",
+ currTestMetaObj->className(),
+ slot.data(),
localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
}
}
}
-
- delete[] slot;
}
}
}