Stop using QTest::qt_snprintf() in testlib.

After the previous commit, QTest::qt_snprintf() is equivalent to
qsnprintf(), so just use that instead.

Change-Id: I89ad6e3749ba5efb1926b0b618a904e8baca9f52
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2011-12-12 12:23:02 +10:00 committed by Qt by Nokia
parent e179afdbb6
commit 949aaf9a2a
7 changed files with 49 additions and 61 deletions

View File

@ -257,7 +257,7 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result)
const char *bmtag = QTest::benchmarkResult2String(); const char *bmtag = QTest::benchmarkResult2String();
char buf1[1024]; char buf1[1024];
QTest::qt_snprintf( qsnprintf(
buf1, sizeof(buf1), "%s: %s::%s", buf1, sizeof(buf1), "%s: %s::%s",
bmtag, bmtag,
QTestResult::currentTestObjectName(), QTestResult::currentTestObjectName(),
@ -267,16 +267,15 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result)
bufTag[0] = 0; bufTag[0] = 0;
QByteArray tag = result.context.tag.toAscii(); QByteArray tag = result.context.tag.toAscii();
if (tag.isEmpty() == false) { if (tag.isEmpty() == false) {
QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); qsnprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data());
} }
char fillFormat[8]; char fillFormat[8];
int fillLength = 5; int fillLength = 5;
QTest::qt_snprintf( qsnprintf(fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength);
fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength);
char fill[1024]; char fill[1024];
QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); qsnprintf(fill, sizeof(fill), fillFormat, "");
const char * unitText = QTest::benchmarkMetricUnit(result.metric); const char * unitText = QTest::benchmarkMetricUnit(result.metric);
@ -285,34 +284,24 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result)
QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value)); QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value));
char buf2[1024]; char buf2[1024];
QTest::qt_snprintf( qsnprintf(buf2, sizeof(buf2), "%s %s", resultBuffer, unitText);
buf2, sizeof(buf2), "%s %s",
resultBuffer,
unitText);
char buf2_[1024]; char buf2_[1024];
QByteArray iterationText = " per iteration"; QByteArray iterationText = " per iteration";
Q_ASSERT(result.iterations > 0); Q_ASSERT(result.iterations > 0);
QTest::qt_snprintf( qsnprintf(buf2_, sizeof(buf2_), "%s", iterationText.data());
buf2_,
sizeof(buf2_), "%s",
iterationText.data());
char buf3[1024]; char buf3[1024];
Q_ASSERT(result.iterations > 0); Q_ASSERT(result.iterations > 0);
QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value)); QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value));
QTest::qt_snprintf( qsnprintf(buf3, sizeof(buf3), " (total: %s, iterations: %d)", resultBuffer, result.iterations);
buf3, sizeof(buf3), " (total: %s, iterations: %d)",
resultBuffer,
result.iterations);
char buf[1024]; char buf[1024];
if (result.setByMacro) { if (result.setByMacro) {
QTest::qt_snprintf( qsnprintf(buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3);
buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3);
} else { } else {
QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); qsnprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2);
} }
memcpy(buf, bmtag, strlen(bmtag)); memcpy(buf, bmtag, strlen(bmtag));
@ -340,13 +329,12 @@ void QPlainTestLogger::startLogging()
char buf[1024]; char buf[1024];
if (QTestLog::verboseLevel() < 0) { if (QTestLog::verboseLevel() < 0) {
QTest::qt_snprintf(buf, sizeof(buf), "Testing %s\n", qsnprintf(buf, sizeof(buf), "Testing %s\n", QTestResult::currentTestObjectName());
QTestResult::currentTestObjectName());
} else { } else {
QTest::qt_snprintf(buf, sizeof(buf), qsnprintf(buf, sizeof(buf),
"********* Start testing of %s *********\n" "********* Start testing of %s *********\n"
"Config: Using QTest library " QTEST_VERSION_STR "Config: Using QTest library " QTEST_VERSION_STR
", Qt %s\n", QTestResult::currentTestObjectName(), qVersion()); ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion());
} }
outputMessage(buf); outputMessage(buf);
} }
@ -355,15 +343,15 @@ void QPlainTestLogger::stopLogging()
{ {
char buf[1024]; char buf[1024];
if (QTestLog::verboseLevel() < 0) { if (QTestLog::verboseLevel() < 0) {
QTest::qt_snprintf(buf, sizeof(buf), "Totals: %d passed, %d failed, %d skipped\n", qsnprintf(buf, sizeof(buf), "Totals: %d passed, %d failed, %d skipped\n",
QTestResult::passCount(), QTestResult::failCount(), QTestResult::passCount(), QTestResult::failCount(),
QTestResult::skipCount()); QTestResult::skipCount());
} else { } else {
QTest::qt_snprintf(buf, sizeof(buf), qsnprintf(buf, sizeof(buf),
"Totals: %d passed, %d failed, %d skipped\n" "Totals: %d passed, %d failed, %d skipped\n"
"********* Finished testing of %s *********\n", "********* Finished testing of %s *********\n",
QTestResult::passCount(), QTestResult::failCount(), QTestResult::passCount(), QTestResult::failCount(),
QTestResult::skipCount(), QTestResult::currentTestObjectName()); QTestResult::skipCount(), QTestResult::currentTestObjectName());
} }
outputMessage(buf); outputMessage(buf);

View File

@ -195,18 +195,18 @@ inline bool qCompare(QStringList const &t1, QStringList const &t2,
msg[0] = '\0'; msg[0] = '\0';
bool isOk = true; bool isOk = true;
if (t1.count() != t2.count()) { if (t1.count() != t2.count()) {
qt_snprintf(msg, 1024, "Compared QStringLists have different sizes.\n" qsnprintf(msg, 1024, "Compared QStringLists have different sizes.\n"
" Actual (%s) size : '%d'\n" " Actual (%s) size : '%d'\n"
" Expected (%s) size: '%d'", actual, t1.count(), expected, t2.count()); " Expected (%s) size: '%d'", actual, t1.count(), expected, t2.count());
isOk = false; isOk = false;
} }
const int min = qMin(t1.count(), t2.count()); const int min = qMin(t1.count(), t2.count());
for (int i = 0; isOk && i < min; ++i) { for (int i = 0; isOk && i < min; ++i) {
if (t1.at(i) != t2.at(i)) { if (t1.at(i) != t2.at(i)) {
qt_snprintf(msg, 1024, "Compared QStringLists differ at index %d.\n" qsnprintf(msg, 1024, "Compared QStringLists differ at index %d.\n"
" Actual (%s) : '%s'\n" " Actual (%s) : '%s'\n"
" Expected (%s) : '%s'", i, actual, t1.at(i).toLatin1().constData(), " Expected (%s) : '%s'", i, actual, t1.at(i).toLatin1().constData(),
expected, t2.at(i).toLatin1().constData()); expected, t2.at(i).toLatin1().constData());
isOk = false; isOk = false;
} }
} }

View File

@ -1106,7 +1106,7 @@ static void qPrintDataTags(FILE *stream)
slot[strlen(slot) - 2] = '\0'; slot[strlen(slot) - 2] = '\0';
QByteArray member; QByteArray member;
member.resize(qstrlen(slot) + qstrlen("_data()") + 1); member.resize(qstrlen(slot) + qstrlen("_data()") + 1);
QTest::qt_snprintf(member.data(), member.size(), "%s_data()", slot); qsnprintf(member.data(), member.size(), "%s_data()", slot);
invokeMethod(QTest::currentTestObject, member.constData()); invokeMethod(QTest::currentTestObject, member.constData());
for (int j = 0; j < table.dataCount(); ++j) for (int j = 0; j < table.dataCount(); ++j)
localTags << QLatin1String(table.testData(j)->dataTag()); localTags << QLatin1String(table.testData(j)->dataTag());
@ -1436,8 +1436,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
if (colon != -1) { if (colon != -1) {
data = qstrdup(argv[i]+colon+1); data = qstrdup(argv[i]+colon+1);
} }
QTest::qt_snprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf qsnprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf
QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" qsnprintf(buf + off, qMin(512 - off, 3), "()"); // append "()"
int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf);
if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) {
fprintf(stderr, "Unknown testfunction: '%s'\n", buf); fprintf(stderr, "Unknown testfunction: '%s'\n", buf);
@ -1589,7 +1589,7 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0)
if (curGlobalDataIndex == 0) { if (curGlobalDataIndex == 0) {
QTestResult::setCurrentTestLocation(QTestResult::DataFunc); QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
QTest::qt_snprintf(member, 512, "%s_data()", slot); qsnprintf(member, 512, "%s_data()", slot);
invokeMethod(QTest::currentTestObject, member); invokeMethod(QTest::currentTestObject, member);
} }
@ -2374,7 +2374,7 @@ Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2
template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \
{ \ { \
char *msg = new char[128]; \ char *msg = new char[128]; \
qt_snprintf(msg, 128, #FORMAT, t); \ qsnprintf(msg, 128, #FORMAT, t); \
return msg; \ return msg; \
} }
@ -2411,7 +2411,7 @@ char *QTest::toString(const char *str)
char *QTest::toString(const void *p) char *QTest::toString(const void *p)
{ {
char *msg = new char[128]; char *msg = new char[128];
qt_snprintf(msg, 128, "%p", p); qsnprintf(msg, 128, "%p", p);
return msg; return msg;
} }

View File

@ -291,7 +291,7 @@ void QTestLog::printUnhandledIgnoreMessages()
char msg[1024]; char msg[1024];
QTest::IgnoreResultList *list = QTest::ignoreResultList; QTest::IgnoreResultList *list = QTest::ignoreResultList;
while (list) { while (list) {
QTest::qt_snprintf(msg, 1024, "Did not receive message: \"%s\"", list->msg); qsnprintf(msg, 1024, "Did not receive message: \"%s\"", list->msg);
QTest::TestLoggers::addMessage(QAbstractTestLogger::Info, msg); QTest::TestLoggers::addMessage(QAbstractTestLogger::Info, msg);
list = list->next; list = list->next;

View File

@ -239,11 +239,11 @@ bool QTestResult::verify(bool statement, const char *statementStr,
char msg[1024]; char msg[1024];
if (QTestLog::verboseLevel() >= 2) { if (QTestLog::verboseLevel() >= 2) {
QTest::qt_snprintf(msg, 1024, "QVERIFY(%s)", statementStr); qsnprintf(msg, 1024, "QVERIFY(%s)", statementStr);
QTestLog::info(msg, file, line); QTestLog::info(msg, file, line);
} }
QTest::qt_snprintf(msg, 1024, "'%s' returned FALSE. (%s)", statementStr, description); qsnprintf(msg, 1024, "'%s' returned FALSE. (%s)", statementStr, description);
return checkStatement(statement, msg, file, line); return checkStatement(statement, msg, file, line);
} }
@ -267,9 +267,9 @@ bool QTestResult::compare(bool success, const char *msg, char *val1, char *val2,
return compare(success, msg, file, line); return compare(success, msg, file, line);
char buf[1024]; char buf[1024];
QTest::qt_snprintf(buf, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s", msg, qsnprintf(buf, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s", msg,
actual, val1 ? val1 : "<null>", actual, val1 ? val1 : "<null>",
expected, val2 ? val2 : "<null>"); expected, val2 ? val2 : "<null>");
delete [] val1; delete [] val1;
delete [] val2; delete [] val2;
return compare(success, buf, file, line); return compare(success, buf, file, line);

View File

@ -251,7 +251,7 @@ void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
QTest::benchmarkResultFormatString(), QTest::benchmarkResultFormatString(),
quotedMetric.constData(), quotedMetric.constData(),
quotedTag.constData(), quotedTag.constData(),
QByteArray::number(result.value).constData(), //no 64-bit qt_snprintf support QByteArray::number(result.value).constData(), //no 64-bit qsnprintf support
result.iterations); result.iterations);
outputString(buf.constData()); outputString(buf.constData());
} }

View File

@ -86,13 +86,13 @@ void QXunitTestLogger::stopLogging()
currentLogElement = new QTestElement(QTest::LET_TestSuite); currentLogElement = new QTestElement(QTest::LET_TestSuite);
currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName()); currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName());
QTest::qt_snprintf(buf, sizeof(buf), "%i", testCounter); qsnprintf(buf, sizeof(buf), "%i", testCounter);
currentLogElement->addAttribute(QTest::AI_Tests, buf); currentLogElement->addAttribute(QTest::AI_Tests, buf);
QTest::qt_snprintf(buf, sizeof(buf), "%i", failureCounter); qsnprintf(buf, sizeof(buf), "%i", failureCounter);
currentLogElement->addAttribute(QTest::AI_Failures, buf); currentLogElement->addAttribute(QTest::AI_Failures, buf);
QTest::qt_snprintf(buf, sizeof(buf), "%i", errorCounter); qsnprintf(buf, sizeof(buf), "%i", errorCounter);
currentLogElement->addAttribute(QTest::AI_Errors, buf); currentLogElement->addAttribute(QTest::AI_Errors, buf);
QTestElement *property; QTestElement *property;
@ -173,7 +173,7 @@ void QXunitTestLogger::addIncident(IncidentTypes type, const char *description,
failureElement->addAttribute(QTest::AI_File, file); failureElement->addAttribute(QTest::AI_File, file);
else else
failureElement->addAttribute(QTest::AI_File, ""); failureElement->addAttribute(QTest::AI_File, "");
QTest::qt_snprintf(buf, sizeof(buf), "%i", line); qsnprintf(buf, sizeof(buf), "%i", line);
failureElement->addAttribute(QTest::AI_Line, buf); failureElement->addAttribute(QTest::AI_Line, buf);
failureElement->addAttribute(QTest::AI_Description, description); failureElement->addAttribute(QTest::AI_Description, description);
addTag(failureElement); addTag(failureElement);
@ -212,7 +212,7 @@ void QXunitTestLogger::addIncident(IncidentTypes type, const char *description,
else else
currentLogElement->addAttribute(QTest::AI_File, ""); currentLogElement->addAttribute(QTest::AI_File, "");
QTest::qt_snprintf(buf, sizeof(buf), "%i", line); qsnprintf(buf, sizeof(buf), "%i", line);
currentLogElement->addAttribute(QTest::AI_Line, buf); currentLogElement->addAttribute(QTest::AI_Line, buf);
/* /*
@ -235,7 +235,7 @@ void QXunitTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData()); benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(result.value).constData());
char buf[100]; char buf[100];
QTest::qt_snprintf(buf, sizeof(buf), "%i", result.iterations); qsnprintf(buf, sizeof(buf), "%i", result.iterations);
benchmarkElement->addAttribute(QTest::AI_Iterations, buf); benchmarkElement->addAttribute(QTest::AI_Iterations, buf);
currentLogElement->addLogElement(benchmarkElement); currentLogElement->addLogElement(benchmarkElement);
} }
@ -303,7 +303,7 @@ void QXunitTestLogger::addMessage(MessageTypes type, const char *message, const
errorElement->addAttribute(QTest::AI_File, ""); errorElement->addAttribute(QTest::AI_File, "");
char buf[100]; char buf[100];
QTest::qt_snprintf(buf, sizeof(buf), "%i", line); qsnprintf(buf, sizeof(buf), "%i", line);
errorElement->addAttribute(QTest::AI_Line, buf); errorElement->addAttribute(QTest::AI_Line, buf);
currentLogElement->addLogElement(errorElement); currentLogElement->addLogElement(errorElement);