qtesttostring.h: standardize on unique_ptr<[]>
... 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. Task-number: QTBUG-132213 Change-Id: I3705b8db89e909e3f1e37ad6a31aaba6f9af899a Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit f405925829ca37af47ecbb291bdb8a95a606e024) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 9cd2e3ffef75642b89c8dcfbc57b71612634677e)
This commit is contained in:
parent
4f60aa4b7c
commit
12b81f3cae
@ -32,6 +32,7 @@
|
|||||||
#include <QtCore/qvariant.h>
|
#include <QtCore/qvariant.h>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -321,7 +322,7 @@ struct QCborValueFormatter
|
|||||||
|
|
||||||
static char *formatTag(QCborTag tag, const QCborValue &taggedValue)
|
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];
|
char *buf = new char[BufferLen];
|
||||||
std::snprintf(buf, BufferLen, "QCborValue(QCborTag(%llu), %s)",
|
std::snprintf(buf, BufferLen, "QCborValue(QCborTag(%llu), %s)",
|
||||||
qToUnderlying(tag), hold.get());
|
qToUnderlying(tag), hold.get());
|
||||||
@ -346,7 +347,7 @@ struct QCborValueFormatter
|
|||||||
|
|
||||||
template<typename T> static char *format(QCborValue::Type type, const T &t)
|
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());
|
return innerFormat(type, hold.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,9 +361,9 @@ struct QCborValueFormatter
|
|||||||
case QCborValue::String:
|
case QCborValue::String:
|
||||||
return format(v.type(), v.toString());
|
return format(v.type(), v.toString());
|
||||||
case QCborValue::Array:
|
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:
|
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:
|
case QCborValue::Tag:
|
||||||
return formatTag(v.tag(), v.taggedValue());
|
return formatTag(v.tag(), v.taggedValue());
|
||||||
case QCborValue::SimpleType:
|
case QCborValue::SimpleType:
|
||||||
@ -397,7 +398,7 @@ struct QCborValueFormatter
|
|||||||
QByteArray out(1, '[');
|
QByteArray out(1, '[');
|
||||||
const char *comma = "";
|
const char *comma = "";
|
||||||
for (QCborValueConstRef v : a) {
|
for (QCborValueConstRef v : a) {
|
||||||
QScopedArrayPointer<char> s(format(v));
|
const std::unique_ptr<char[]> s(format(v));
|
||||||
out += comma;
|
out += comma;
|
||||||
out += s.get();
|
out += s.get();
|
||||||
comma = ", ";
|
comma = ", ";
|
||||||
@ -411,8 +412,8 @@ struct QCborValueFormatter
|
|||||||
QByteArray out(1, '{');
|
QByteArray out(1, '{');
|
||||||
const char *comma = "";
|
const char *comma = "";
|
||||||
for (auto pair : m) {
|
for (auto pair : m) {
|
||||||
QScopedArrayPointer<char> key(format(pair.first));
|
const std::unique_ptr<char[]> key(format(pair.first));
|
||||||
QScopedArrayPointer<char> value(format(pair.second));
|
const std::unique_ptr<char[]> value(format(pair.second));
|
||||||
out += comma;
|
out += comma;
|
||||||
out += key.get();
|
out += key.get();
|
||||||
out += ": ";
|
out += ": ";
|
||||||
@ -461,9 +462,9 @@ template <typename Rep, typename Period> char *toString(std::chrono::duration<Re
|
|||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
inline char *toString(const std::pair<T1, T2> &pair)
|
inline char *toString(const std::pair<T1, T2> &pair)
|
||||||
{
|
{
|
||||||
const QScopedArrayPointer<char> first(toString(pair.first));
|
const std::unique_ptr<char[]> first(toString(pair.first));
|
||||||
const QScopedArrayPointer<char> second(toString(pair.second));
|
const std::unique_ptr<char[]> second(toString(pair.second));
|
||||||
return formatString("std::pair(", ")", 2, first.data(), second.data());
|
return formatString("std::pair(", ")", 2, first.get(), second.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Tuple, std::size_t... I>
|
template <typename Tuple, std::size_t... I>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user