diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-11-02 23:29:08 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2020-11-07 09:35:11 +0100 |
commit | 7cad91a7df03d0683c81519ae6839c5f546cfceb (patch) | |
tree | 4a3e855fe8b3ee7407e7138b10305165254a1e67 /tests | |
parent | b8069f0a4783cd80c1b2c44053e054607b066d79 (diff) |
QDebug: add op<<(QByteArrayView)
[ChangeLog][QtCore][QDebug] Added streaming of QByteArrayViews.
Task-number: QTBUG-88029
Change-Id: I66f5cc45a0438dbaacb1754cb3c669b3717f528b
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 949882b578..d68cbc5e25 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -75,6 +75,7 @@ private slots: void qDebugQStringView() const; void qDebugQLatin1String() const; void qDebugQByteArray() const; + void qDebugQByteArrayView() const; void qDebugQFlags() const; void textStreamModifiers() const; void resetFormat() const; @@ -635,6 +636,48 @@ void tst_QDebug::qDebugQByteArray() const QCOMPARE(s_msg, QString("\"\\xFF\"\"FFFF\"")); } +void tst_QDebug::qDebugQByteArrayView() const +{ + QString file, function; + int line = 0; + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QByteArrayView("foo") << QByteArrayView("") << QByteArrayView("barbaz", 3); + d.nospace().noquote() << QByteArrayView("baz"); + } +#ifndef QT_NO_MESSAGELOGCONTEXT + file = __FILE__; line = __LINE__ - 5; function = Q_FUNC_INFO; +#endif + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" baz")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); + + /* simpler tests from now on */ + QByteArrayView ba = "\"Hello\""; + qDebug() << ba; + QCOMPARE(s_msg, QString("\"\\\"Hello\\\"\"")); + + qDebug().noquote().nospace() << ba; + QCOMPARE(s_msg, QString::fromLatin1(ba)); + + qDebug().noquote().nospace() << qSetFieldWidth(8) << ba; + QCOMPARE(s_msg, " " + QString::fromLatin1(ba)); + + ba = "\nSm\xC3\xB8rg\xC3\xA5sbord\\"; + qDebug().noquote().nospace() << ba; + QCOMPARE(s_msg, QString::fromUtf8(ba)); + + qDebug() << ba; + QCOMPARE(s_msg, QString("\"\\nSm\\xC3\\xB8rg\\xC3\\xA5sbord\\\\\"")); + + // ensure that it closes hex escape sequences correctly + qDebug() << QByteArrayView("\377FFFF"); + QCOMPARE(s_msg, QString("\"\\xFF\"\"FFFF\"")); +} + enum TestEnum { Flag1 = 0x1, Flag2 = 0x10 |