From b6c102b742e9a89ba471432e1cb89f9fcbe737d5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 24 Oct 2024 15:12:35 +0200 Subject: [PATCH] tst_QDebug: extend test with optionals of const or optional type Amends b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a. Change-Id: I420f11571629025a9d3b588d4ab124b34ee3811c Reviewed-by: David Faure (cherry picked from commit dd672edd15393378898b518091c3117a91c5bbfd) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 44532be2775..f4faa12d6dd 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -1263,6 +1263,23 @@ void tst_QDebug::qDebugStdOptional() const QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); + + /* simpler tests from now on */ + // const + qDebug() << std::optional(42) << std::optional(std::nullopt); + QCOMPARE(s_msg, R"(std::optional(42) nullopt)"_L1); + // nested + { + auto d = qDebug(); + // the constructors would do the wrong thing (convert payload types), so use emplace() + std::optional> opt; + d << opt; + opt.emplace(); + d << opt; + *opt = 42; + d << opt; + } + QCOMPARE(s_msg, R"(nullopt std::optional(nullopt) std::optional(std::optional(42)))"_L1); } void tst_QDebug::textStreamModifiers() const