From 5c4a0a5b2682fc38deb78995fb1c9a005098744d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 21 Oct 2024 14:31:52 +0200 Subject: [PATCH] tst_QDebug: add missing test for std::pair streaming tst_QPair also doesn't have it. Pick-to: 6.5 6.2 Change-Id: I7391203a9dcb2d937487ee2f3ba1b6ed21d700db Reviewed-by: Thiago Macieira (cherry picked from commit 9b0970ad820c084b0fe73bcbbc72b44f04cae3dd) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index efbb13e89ac..44532be2775 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -74,6 +74,7 @@ private slots: void qDebugQStringView() const; void qDebugQUtf8StringView() const; void qDebugQLatin1String() const; + void qDebugStdPair() const; void qDebugStdString() const; void qDebugStdStringView() const; void qDebugStdWString() const; @@ -678,6 +679,31 @@ void tst_QDebug::qDebugQLatin1String() const QCOMPARE(s_msg, QString("\"\\nSm\\u00F8rg\\u00E5sbord\\\\\"")); } +void tst_QDebug::qDebugStdPair() const +{ + QByteArray file, function; + int line = 0; + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << std::pair(42, u"foo"_s) << std::pair(u"barbaz"_s, 4.2); + d.nospace().noquote() << std::pair(u"baz"_s, -42); + } +#ifndef QT_NO_MESSAGELOGCONTEXT + file = __FILE__; line = __LINE__ - 5; function = Q_FUNC_INFO; +#endif + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, R"(std::pair(42,"foo") std::pair("barbaz",4.2) std::pair(baz,-42))"_L1); + QCOMPARE(s_file, file); + QCOMPARE(s_line, line); + QCOMPARE(s_function, function); + + /* simpler tests from now on */ + // nested: + qDebug() << std::pair(std::pair(std::pair(4.2, 42), ".42"), u"42"_s); + QCOMPARE(s_msg, R"(std::pair(std::pair(std::pair(4.2,42),.42),"42"))"_L1); +} + void tst_QDebug::qDebugStdString() const { QString file, function;