Skip to content

Commit

Permalink
qtesttostring.h: standardize on unique_ptr<[]>
Browse files Browse the repository at this point in the history
... instead of QScopedArrayPointer.

Less Qt code (which we're supposed to test with this library) and more
consistent with the tuple implementation.

Also makes the header clean w.r.t. upcoming QT_NO_SCOPED_POINTER.

Pick-to: 6.9 6.8
Task-number: QTBUG-132213
Change-Id: I3705b8db89e909e3f1e37ad6a31aaba6f9af899a
Reviewed-by: Ahmad Samir <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
marcmutz committed Dec 20, 2024
1 parent 1fb86f1 commit f405925
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/testlib/qtesttostring.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QtCore/qvariant.h>

#include <cstdio>
#include <memory>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -321,7 +322,7 @@ struct QCborValueFormatter

static char *formatTag(QCborTag tag, const QCborValue &taggedValue)
{
QScopedArrayPointer<char> hold(format(taggedValue));
const std::unique_ptr<char[]> hold(format(taggedValue));
char *buf = new char[BufferLen];
std::snprintf(buf, BufferLen, "QCborValue(QCborTag(%llu), %s)",
qToUnderlying(tag), hold.get());
Expand All @@ -346,7 +347,7 @@ struct QCborValueFormatter

template<typename T> static char *format(QCborValue::Type type, const T &t)
{
QScopedArrayPointer<char> hold(QTest::toString(t));
const std::unique_ptr<char[]> hold(QTest::toString(t));
return innerFormat(type, hold.get());
}

Expand All @@ -360,9 +361,9 @@ struct QCborValueFormatter
case QCborValue::String:
return format(v.type(), v.toString());
case QCborValue::Array:
return innerFormat(v.type(), QScopedArrayPointer<char>(format(v.toArray())).get());
return innerFormat(v.type(), std::unique_ptr<char[]>(format(v.toArray())).get());
case QCborValue::Map:
return innerFormat(v.type(), QScopedArrayPointer<char>(format(v.toMap())).get());
return innerFormat(v.type(), std::unique_ptr<char[]>(format(v.toMap())).get());
case QCborValue::Tag:
return formatTag(v.tag(), v.taggedValue());
case QCborValue::SimpleType:
Expand Down Expand Up @@ -397,7 +398,7 @@ struct QCborValueFormatter
QByteArray out(1, '[');
const char *comma = "";
for (QCborValueConstRef v : a) {
QScopedArrayPointer<char> s(format(v));
const std::unique_ptr<char[]> s(format(v));
out += comma;
out += s.get();
comma = ", ";
Expand All @@ -411,8 +412,8 @@ struct QCborValueFormatter
QByteArray out(1, '{');
const char *comma = "";
for (auto pair : m) {
QScopedArrayPointer<char> key(format(pair.first));
QScopedArrayPointer<char> value(format(pair.second));
const std::unique_ptr<char[]> key(format(pair.first));
const std::unique_ptr<char[]> value(format(pair.second));
out += comma;
out += key.get();
out += ": ";
Expand Down Expand Up @@ -461,9 +462,9 @@ template <typename Rep, typename Period> char *toString(std::chrono::duration<Re
template <typename T1, typename T2>
inline char *toString(const std::pair<T1, T2> &pair)
{
const QScopedArrayPointer<char> first(toString(pair.first));
const QScopedArrayPointer<char> second(toString(pair.second));
return formatString("std::pair(", ")", 2, first.data(), second.data());
const std::unique_ptr<char[]> first(toString(pair.first));
const std::unique_ptr<char[]> second(toString(pair.second));
return formatString("std::pair(", ")", 2, first.get(), second.get());
}

template <typename Tuple, std::size_t... I>
Expand Down

0 comments on commit f405925

Please sign in to comment.