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.7 6.5 Change-Id: I94ec440d7e6d09196cf87cd3dbbfd765e0df69d0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit a15ff49be73228bbbc72989736d32059322c414f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
13ed410121
commit
2a72fb6d81
@ -555,11 +555,8 @@ static void qPrintDataTags(FILE *stream)
|
|||||||
// Retrieve local tags:
|
// Retrieve local tags:
|
||||||
QStringList localTags;
|
QStringList localTags;
|
||||||
QTestTable table;
|
QTestTable table;
|
||||||
char *slot = qstrdup(tf.methodSignature().constData());
|
const QByteArray slot = tf.methodSignature().chopped(2);
|
||||||
slot[strlen(slot) - 2] = '\0';
|
const QByteArray member = slot + "_data()";
|
||||||
QByteArray member;
|
|
||||||
member.resize(qstrlen(slot) + qstrlen("_data()") + 1);
|
|
||||||
qsnprintf(member.data(), member.size(), "%s_data()", slot);
|
|
||||||
invokeTestMethodIfExists(member.constData());
|
invokeTestMethodIfExists(member.constData());
|
||||||
const int dataCount = table.dataCount();
|
const int dataCount = table.dataCount();
|
||||||
localTags.reserve(dataCount);
|
localTags.reserve(dataCount);
|
||||||
@ -570,13 +567,15 @@ static void qPrintDataTags(FILE *stream)
|
|||||||
if (gTable->dataCount() == 0) {
|
if (gTable->dataCount() == 0) {
|
||||||
if (localTags.size() == 0) {
|
if (localTags.size() == 0) {
|
||||||
// No tags at all, so just print the test function:
|
// 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 {
|
} else {
|
||||||
// Only local tags, so print each of them:
|
// Only local tags, so print each of them:
|
||||||
for (int k = 0; k < localTags.size(); ++k)
|
for (int k = 0; k < localTags.size(); ++k)
|
||||||
fprintf(
|
fprintf(
|
||||||
stream, "%s %s %s\n",
|
stream, "%s %s %s\n",
|
||||||
currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
|
currTestMetaObj->className(),
|
||||||
|
slot.data(),
|
||||||
|
localTags.at(k).toLatin1().data());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int j = 0; j < gTable->dataCount(); ++j) {
|
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:
|
// Only global tags, so print the current one:
|
||||||
fprintf(
|
fprintf(
|
||||||
stream, "%s %s __global__ %s\n",
|
stream, "%s %s __global__ %s\n",
|
||||||
currTestMetaObj->className(), slot, gTable->testData(j)->dataTag());
|
currTestMetaObj->className(),
|
||||||
|
slot.data(),
|
||||||
|
gTable->testData(j)->dataTag());
|
||||||
} else {
|
} else {
|
||||||
// Local and global tags, so print each of the local ones and
|
// Local and global tags, so print each of the local ones and
|
||||||
// the current global one:
|
// the current global one:
|
||||||
for (int k = 0; k < localTags.size(); ++k)
|
for (int k = 0; k < localTags.size(); ++k)
|
||||||
fprintf(
|
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());
|
localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] slot;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user