aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-03-20 12:20:53 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-03-23 09:58:53 +0100
commitea775373c5905e577e6ff2209c4a0a37437dd569 (patch)
treec91a3754b9995b02b7bdb2b829f94123487ffaa0 /tests
parentbc30b5f3b403878fcc29dc56264a8137d7ae8ed5 (diff)
QQuickViewTestUtil: Don't leak on matchAgainst()
QTest::toString() returns a bare pointer to a heap-allocated character array. We need to delete it. Change-Id: I5a5cf1054e582af21e784595c00646d5b4fc0b7f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/shared/viewtestutil.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp
index 4089e5ddae..67b73f047c 100644
--- a/tests/auto/quick/shared/viewtestutil.cpp
+++ b/tests/auto/quick/shared/viewtestutil.cpp
@@ -282,14 +282,28 @@ void QQuickViewTestUtil::QaimModel::resetItems(const QList<QPair<QString, QStrin
endResetModel();
}
+class ScopedPrintable
+{
+ Q_DISABLE_COPY_MOVE(ScopedPrintable)
+
+public:
+ ScopedPrintable(const QString &string) : data(QTest::toString(string)) {}
+ ~ScopedPrintable() { delete[] data; }
+
+ operator const char*() const { return data; }
+
+private:
+ const char *data;
+};
+
void QQuickViewTestUtil::QaimModel::matchAgainst(const QList<QPair<QString, QString> > &other, const QString &error1, const QString &error2) {
for (int i=0; i<other.count(); i++) {
QVERIFY2(list.contains(other[i]),
- QTest::toString(other[i].first + QLatin1Char(' ') + other[i].second + QLatin1Char(' ') + error1));
+ ScopedPrintable(other[i].first + QLatin1Char(' ') + other[i].second + QLatin1Char(' ') + error1));
}
for (int i=0; i<list.count(); i++) {
QVERIFY2(other.contains(list[i]),
- QTest::toString(list[i].first + QLatin1Char(' ') + list[i].second + QLatin1Char(' ') + error2));
+ ScopedPrintable(list[i].first + QLatin1Char(' ') + list[i].second + QLatin1Char(' ') + error2));
}
}