summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qdebug
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2023-11-20 20:46:23 +0100
committerDavid Faure <david.faure@kdab.com>2023-11-22 05:56:25 +0100
commitb7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a (patch)
tree4909c75ee34a05c5c1559406d13dc4db8e915f79 /tests/auto/corelib/io/qdebug
parentdc7eb46352374f811841fda87c58c7dc1d52d787 (diff)
qDebug: add support for std::optional and std::nullopt_t
[ChangeLog][QtCore][QDebug] Added support for std::optional and std::nullopt_t Change-Id: I1e6196adb408401cae8776cd0c60af294a39a83f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qdebug')
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 6c976e4a63..2137604457 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -89,6 +89,7 @@ private slots:
void qDebugQFlags() const;
void qDebugStdChrono_data() const;
void qDebugStdChrono() const;
+ void qDebugStdOptional() const;
void textStreamModifiers() const;
void resetFormat() const;
void defaultMessagehandler() const;
@@ -1215,6 +1216,28 @@ void tst_QDebug::qDebugStdChrono() const
QCOMPARE(fn(), expected);
}
+void tst_QDebug::qDebugStdOptional() const
+{
+ QString file, function;
+ int line = 0;
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ std::optional<QByteArray> notSet = std::nullopt;
+ std::optional<QByteArray> set("foo");
+ auto no = std::nullopt;
+ QDebug d = qDebug();
+ d << notSet << set << no;
+ }
+#ifndef QT_NO_MESSAGELOGCONTEXT
+ file = __FILE__; line = __LINE__ - 4; function = Q_FUNC_INFO;
+#endif
+ QCOMPARE(s_msgType, QtDebugMsg);
+ QCOMPARE(s_msg, QString::fromLatin1("nullopt std::optional(\"foo\") nullopt"));
+ QCOMPARE(QString::fromLatin1(s_file), file);
+ QCOMPARE(s_line, line);
+ QCOMPARE(QString::fromLatin1(s_function), function);
+}
+
void tst_QDebug::textStreamModifiers() const
{
QString file, function;