summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2024-07-18 14:09:06 +0200
committerMarc Mutz <[email protected]>2024-08-03 12:30:05 +0200
commit7e2fa57faf230ef8cb505b95c2bc0e70867ac131 (patch)
tree45aa67dc6cfd95889e2e7497554669d1ec06c771
parentbd7d54249e3f2b6a9dd6b759c892d7c97d26c0aa (diff)
Make headers QT_NO_QSNPRINTF-clean
Before we roll out QT_NO_QSNPRINTF across Qt, we need to make sure at least the headers are clean, so downstream modules can port without being stabbed in the back by unported upstream headers. Pick-to: 6.8 Task-number: QTBUG-127110 Change-Id: I7411ff0036482ad68bd5867b624518f68f249228 Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/testlib/qpropertytesthelper_p.h2
-rw-r--r--src/testlib/qtest.h9
-rw-r--r--src/testlib/qtest_gui.h62
-rw-r--r--src/testlib/qtesttostring.h30
4 files changed, 55 insertions, 48 deletions
diff --git a/src/testlib/qpropertytesthelper_p.h b/src/testlib/qpropertytesthelper_p.h
index 67314ec1a08..54398278997 100644
--- a/src/testlib/qpropertytesthelper_p.h
+++ b/src/testlib/qpropertytesthelper_p.h
@@ -21,6 +21,8 @@
#include <QTest>
#include <private/qglobal_p.h>
+#include <cstdio>
+
QT_BEGIN_NAMESPACE
namespace QTestPrivate {
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index f3802d548b9..c749cbd492f 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -19,6 +19,7 @@
#include <QtCore/qcoreapplication.h>
#endif
+#include <cstdio>
#include <initializer_list>
#include <memory>
@@ -55,7 +56,7 @@ bool _q_compareSequence(ActualIterator actualIt, ActualIterator actualEnd,
bool isOk = actualSize == expectedSize;
if (!isOk) {
- qsnprintf(msg, sizeof(msg), "Compared lists have different sizes.\n"
+ std::snprintf(msg, sizeof(msg), "Compared lists have different sizes.\n"
" Actual (%s) size: %lld\n"
" Expected (%s) size: %lld",
actual, qlonglong(actualSize),
@@ -68,11 +69,11 @@ bool _q_compareSequence(ActualIterator actualIt, ActualIterator actualEnd,
char *val1 = toString(*actualIt);
char *val2 = toString(*expectedIt);
- qsnprintf(msg, sizeof(msg), "Compared lists differ at index %lld.\n"
- " Actual (%s): %s\n"
+ std::snprintf(msg, sizeof(msg), "Compared lists differ at index %lld.\n"
+ " Actual (%s): %s\n"
" Expected (%s): %s",
qlonglong(i), actual, val1 ? val1 : "<null>",
- expected, val2 ? val2 : "<null>");
+ expected, val2 ? val2 : "<null>");
isOk = false;
delete [] val1;
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h
index 667debb3c43..83511cb3804 100644
--- a/src/testlib/qtest_gui.h
+++ b/src/testlib/qtest_gui.h
@@ -32,6 +32,8 @@
#include <QtGui/qvector4d.h>
#include <QtGui/qicon.h>
+#include <cstdio>
+
#if 0
// inform syncqt
#pragma qt_no_master_include
@@ -130,34 +132,34 @@ inline bool qCompare(QImage const &t1, QImage const &t2,
const bool t1Null = t1.isNull();
const bool t2Null = t2.isNull();
if (t1Null != t2Null) {
- qsnprintf(msg, 1024, "Compared QImages differ.\n"
- " Actual (%s).isNull(): %d\n"
- " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
+ std::snprintf(msg, 1024, "Compared QImages differ.\n"
+ " Actual (%s).isNull(): %d\n"
+ " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
return compare_helper(false, msg, actual, expected, file, line);
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, actual, expected, file, line);
if (!qFuzzyCompare(t1.devicePixelRatio(), t2.devicePixelRatio())) {
- qsnprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n"
- " Actual (%s): %g\n"
- " Expected (%s): %g",
- actual, t1.devicePixelRatio(),
- expected, t2.devicePixelRatio());
+ std::snprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatio(),
+ expected, t2.devicePixelRatio());
return compare_helper(false, msg, actual, expected, file, line);
}
if (t1.width() != t2.width() || t1.height() != t2.height()) {
- qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
- " Actual (%s): %dx%d\n"
- " Expected (%s): %dx%d",
- actual, t1.width(), t1.height(),
- expected, t2.width(), t2.height());
+ std::snprintf(msg, 1024, "Compared QImages differ in size.\n"
+ " Actual (%s): %dx%d\n"
+ " Expected (%s): %dx%d",
+ actual, t1.width(), t1.height(),
+ expected, t2.width(), t2.height());
return compare_helper(false, msg, actual, expected, file, line);
}
if (t1.format() != t2.format()) {
- qsnprintf(msg, 1024, "Compared QImages differ in format.\n"
- " Actual (%s): %d\n"
- " Expected (%s): %d",
- actual, t1.format(), expected, t2.format());
+ std::snprintf(msg, 1024, "Compared QImages differ in format.\n"
+ " Actual (%s): %d\n"
+ " Expected (%s): %d",
+ actual, t1.format(), expected, t2.format());
return compare_helper(false, msg, actual, expected, file, line);
}
return compare_helper(t1 == t2, "Compared values are not the same",
@@ -172,27 +174,27 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c
const bool t1Null = t1.isNull();
const bool t2Null = t2.isNull();
if (t1Null != t2Null) {
- qsnprintf(msg, 1024, "Compared QPixmaps differ.\n"
- " Actual (%s).isNull(): %d\n"
- " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
+ std::snprintf(msg, 1024, "Compared QPixmaps differ.\n"
+ " Actual (%s).isNull(): %d\n"
+ " Expected (%s).isNull(): %d", actual, t1Null, expected, t2Null);
return compare_helper(false, msg, actual, expected, file, line);
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, actual, expected, file, line);
if (!qFuzzyCompare(t1.devicePixelRatio(), t2.devicePixelRatio())) {
- qsnprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n"
- " Actual (%s): %g\n"
- " Expected (%s): %g",
- actual, t1.devicePixelRatio(),
- expected, t2.devicePixelRatio());
+ std::snprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatio(),
+ expected, t2.devicePixelRatio());
return compare_helper(false, msg, actual, expected, file, line);
}
if (t1.width() != t2.width() || t1.height() != t2.height()) {
- qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
- " Actual (%s): %dx%d\n"
- " Expected (%s): %dx%d",
- actual, t1.width(), t1.height(),
- expected, t2.width(), t2.height());
+ std::snprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
+ " Actual (%s): %dx%d\n"
+ " Expected (%s): %dx%d",
+ actual, t1.width(), t1.height(),
+ expected, t2.width(), t2.height());
return compare_helper(false, msg, actual, expected, file, line);
}
return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);
diff --git a/src/testlib/qtesttostring.h b/src/testlib/qtesttostring.h
index 5fffa398132..551e40124a0 100644
--- a/src/testlib/qtesttostring.h
+++ b/src/testlib/qtesttostring.h
@@ -31,6 +31,8 @@
#include <QtCore/quuid.h>
#include <QtCore/qvariant.h>
+#include <cstdio>
+
QT_BEGIN_NAMESPACE
namespace QTest {
@@ -77,7 +79,7 @@ inline typename std::enable_if<!QtPrivate::IsQEnumHelper<F>::Value, char*>::type
{
const size_t space = 3 + 2 * sizeof(unsigned); // 2 for 0x, two hex digits per byte, 1 for '\0'
char *msg = new char[space];
- qsnprintf(msg, space, "0x%x", unsigned(f.toInt()));
+ std::snprintf(msg, space, "0x%x", unsigned(f.toInt()));
return msg;
}
@@ -196,7 +198,7 @@ template<> inline char *toString(const QChar &c)
const ushort uc = c.unicode();
if (uc < 128) {
char msg[32];
- qsnprintf(msg, sizeof(msg), "QChar: '%c' (0x%x)", char(uc), unsigned(uc));
+ std::snprintf(msg, sizeof(msg), "QChar: '%c' (0x%x)", char(uc), unsigned(uc));
return qstrdup(msg);
}
return qstrdup(qPrintable(QString::fromLatin1("QChar: '%1' (0x%2)").arg(c).arg(QString::number(static_cast<int>(c.unicode()), 16))));
@@ -206,7 +208,7 @@ template<> inline char *toString(const QChar &c)
template<> inline char *toString(const QModelIndex &idx)
{
char msg[128];
- qsnprintf(msg, sizeof(msg), "QModelIndex(%d,%d,%p,%p)",
+ std::snprintf(msg, sizeof(msg), "QModelIndex(%d,%d,%p,%p)",
idx.row(), idx.column(), idx.internalPointer(),
static_cast<const void*>(idx.model()));
return qstrdup(msg);
@@ -216,21 +218,21 @@ template<> inline char *toString(const QModelIndex &idx)
template<> inline char *toString(const QPoint &p)
{
char msg[128];
- qsnprintf(msg, sizeof(msg), "QPoint(%d,%d)", p.x(), p.y());
+ std::snprintf(msg, sizeof(msg), "QPoint(%d,%d)", p.x(), p.y());
return qstrdup(msg);
}
template<> inline char *toString(const QSize &s)
{
char msg[128];
- qsnprintf(msg, sizeof(msg), "QSize(%dx%d)", s.width(), s.height());
+ std::snprintf(msg, sizeof(msg), "QSize(%dx%d)", s.width(), s.height());
return qstrdup(msg);
}
template<> inline char *toString(const QRect &s)
{
char msg[256];
- qsnprintf(msg, sizeof(msg), "QRect(%d,%d %dx%d) (bottomright %d,%d)",
+ std::snprintf(msg, sizeof(msg), "QRect(%d,%d %dx%d) (bottomright %d,%d)",
s.left(), s.top(), s.width(), s.height(), s.right(), s.bottom());
return qstrdup(msg);
}
@@ -238,22 +240,22 @@ template<> inline char *toString(const QRect &s)
template<> inline char *toString(const QPointF &p)
{
char msg[64];
- qsnprintf(msg, sizeof(msg), "QPointF(%g,%g)", p.x(), p.y());
+ std::snprintf(msg, sizeof(msg), "QPointF(%g,%g)", p.x(), p.y());
return qstrdup(msg);
}
template<> inline char *toString(const QSizeF &s)
{
char msg[64];
- qsnprintf(msg, sizeof(msg), "QSizeF(%gx%g)", s.width(), s.height());
+ std::snprintf(msg, sizeof(msg), "QSizeF(%gx%g)", s.width(), s.height());
return qstrdup(msg);
}
template<> inline char *toString(const QRectF &s)
{
char msg[256];
- qsnprintf(msg, sizeof(msg), "QRectF(%g,%g %gx%g) (bottomright %g,%g)",
- s.left(), s.top(), s.width(), s.height(), s.right(), s.bottom());
+ std::snprintf(msg, sizeof(msg), "QRectF(%g,%g %gx%g) (bottomright %g,%g)",
+ s.left(), s.top(), s.width(), s.height(), s.right(), s.bottom());
return qstrdup(msg);
}
@@ -313,7 +315,7 @@ struct QCborValueFormatter
static char *formatSimpleType(QCborSimpleType st)
{
char *buf = new char[BufferLen];
- qsnprintf(buf, BufferLen, "QCborValue(QCborSimpleType(%d))", int(st));
+ std::snprintf(buf, BufferLen, "QCborValue(QCborSimpleType(%d))", int(st));
return buf;
}
@@ -321,7 +323,7 @@ struct QCborValueFormatter
{
QScopedArrayPointer<char> hold(format(taggedValue));
char *buf = new char[BufferLen];
- qsnprintf(buf, BufferLen, "QCborValue(QCborTag(%llu), %s)",
+ std::snprintf(buf, BufferLen, "QCborValue(QCborTag(%llu), %s)",
qToUnderlying(tag), hold.get());
return buf;
}
@@ -336,9 +338,9 @@ struct QCborValueFormatter
char *buf = new char[BufferLen];
const char *typeName = typeEnum.valueToKey(t);
if (typeName)
- qsnprintf(buf, BufferLen, "QCborValue(%s, %s)", typeName, str);
+ std::snprintf(buf, BufferLen, "QCborValue(%s, %s)", typeName, str);
else
- qsnprintf(buf, BufferLen, "QCborValue(<unknown type 0x%02x>)", t);
+ std::snprintf(buf, BufferLen, "QCborValue(<unknown type 0x%02x>)", t);
return buf;
}