summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-03-14 15:13:53 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-03-16 02:26:56 +0000
commite74e27e67eab8b714ddc2f3f7fc2175fd6dcbe5a (patch)
tree1ba58f5f39efe5b91f74046990db8ecacab96ad4 /tests/auto/corelib/kernel
parent78891e53905591eb6736a69296b31e12c3195a55 (diff)
QObject: give some TLC to dumpRecursive()
In no particular order: - use the variable field width feature of QString::asprintf() to generate the indentation implicitly, instead of fill()ing a QByteArray with the desired number of spaces - just default-construct 'flags', don't assign an empty string - use qUtf16Printable() to avoid funneling UTF-16 data through 8-bit encodings - use a C++11 ranged for instead of a counted loop - remove a pointless isEmpty() guard (the loop won't execute when the children().isEmpty()) - avoid copying object->children() (returns by cref, so it's also ok to stuff it directly into the ranged for loop). Add a test. Pick-to: 6.3 Change-Id: Ie7314713cb48de7e890cdee0760c0361dd24fd18 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index bf30282822..af4b35fb46 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -108,6 +108,7 @@ private slots:
void deleteSelfInSlot();
void disconnectSelfInSlotAndDeleteAfterEmit();
void dumpObjectInfo();
+ void dumpObjectTree();
void connectToSender();
void qobjectConstCast();
void uniqConnection();
@@ -3413,6 +3414,32 @@ void tst_QObject::dumpObjectInfo()
a.dumpObjectInfo(); // should not crash
}
+void tst_QObject::dumpObjectTree()
+{
+ QObject a;
+ Q_SET_OBJECT_NAME(a);
+
+ QTimer b(&a);
+ Q_SET_OBJECT_NAME(b);
+
+ QObject c(&b);
+ Q_SET_OBJECT_NAME(c);
+
+ QFile f(&a);
+ Q_SET_OBJECT_NAME(f);
+
+ const char * const output[] = {
+ "QObject::a ",
+ " QTimer::b ",
+ " QObject::c ",
+ " QFile::f ",
+ };
+ for (const char *line : output)
+ QTest::ignoreMessage(QtDebugMsg, line);
+
+ a.dumpObjectTree();
+}
+
class ConnectToSender : public QObject
{ Q_OBJECT
public slots: