summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qdebug/tst_qdebug.cpp')
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp161
1 files changed, 155 insertions, 6 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 99c4ee7edc..764c928d76 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -56,11 +56,16 @@ private slots:
void criticalWithoutDebug() const;
void debugWithBool() const;
void debugSpaceHandling() const;
+ void debugNoQuotes() const;
void stateSaver() const;
void veryLongWarningMessage() const;
+ void qDebugQChar() const;
void qDebugQStringRef() const;
void qDebugQLatin1String() const;
+ void qDebugQByteArray() const;
+ void qDebugQFlags() const;
void textStreamModifiers() const;
+ void resetFormat() const;
void defaultMessagehandler() const;
void threadSafety() const;
};
@@ -167,7 +172,8 @@ public:
QDebug operator<< (QDebug s, const MyPoint& point)
{
const QDebugStateSaver saver(s);
- return s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")";
+ s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")";
+ return s;
}
class MyLine
@@ -203,10 +209,45 @@ void tst_QDebug::debugSpaceHandling() const
d << 1 << 2;
MyLine line(MyPoint(10, 11), MyPoint (12, 13));
d << line;
+ d << "bar";
// With the old implementation of MyPoint doing dbg.nospace() << ...; dbg.space() we ended up with
// MyLine(MyPoint(10, 11) , MyPoint(12, 13) )
}
- QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13))"));
+ QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13)) bar"));
+
+ QVERIFY(qDebug().autoInsertSpaces());
+ qDebug() << QPoint(21, 22) << QRect(23, 24, 25, 26) << QLine(27, 28, 29, 30);
+ QCOMPARE(s_msg, QString::fromLatin1("QPoint(21,22) QRect(23,24 25x26) QLine(QPoint(27,28),QPoint(29,30))"));
+ qDebug() << QPointF(21, 22) << QRectF(23, 24, 25, 26) << QLineF(27, 28, 29, 30);
+ QCOMPARE(s_msg, QString::fromLatin1("QPointF(21,22) QRectF(23,24 25x26) QLineF(QPointF(27,28),QPointF(29,30))"));
+ qDebug() << QMimeType() << QMimeDatabase().mimeTypeForName("application/pdf") << "foo";
+ QCOMPARE(s_msg, QString::fromLatin1("QMimeType(invalid) QMimeType(\"application/pdf\") foo"));
+}
+
+void tst_QDebug::debugNoQuotes() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ d << QStringLiteral("Hello");
+ d.noquote();
+ d << QStringLiteral("Hello");
+ d.quote();
+ d << QStringLiteral("Hello");
+ }
+ QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\""));
+
+ {
+ QDebug d = qDebug();
+ d << QChar('H');
+ d << QLatin1String("Hello");
+ d << QByteArray("Hello");
+ d.noquote();
+ d << QChar('H');
+ d << QLatin1String("Hello");
+ d << QByteArray("Hello");
+ }
+ QCOMPARE(s_msg, QString::fromLatin1("'H' \"Hello\" \"Hello\" H Hello Hello"));
}
void tst_QDebug::stateSaver() const
@@ -214,13 +255,46 @@ void tst_QDebug::stateSaver() const
MessageHandlerSetter mhs(myMessageHandler);
{
QDebug d = qDebug();
+ d << 42;
+ {
+ QDebugStateSaver saver(d);
+ d << 43;
+ }
+ d << 44;
+ }
+ QCOMPARE(s_msg, QString::fromLatin1("42 43 44"));
+
+ {
+ QDebug d = qDebug();
{
QDebugStateSaver saver(d);
d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42;
}
- d.space() << 42;
+ d << 42;
}
QCOMPARE(s_msg, QString::fromLatin1("02a 42"));
+
+ {
+ QDebug d = qDebug();
+ {
+ QDebugStateSaver saver(d);
+ d.nospace().noquote() << QStringLiteral("Hello");
+ }
+ d << QStringLiteral("World");
+ }
+ QCOMPARE(s_msg, QString::fromLatin1("Hello \"World\""));
+
+ {
+ QDebug d = qDebug();
+ d.noquote().nospace() << QStringLiteral("Hello") << hex << 42;
+ {
+ QDebugStateSaver saver(d);
+ d.resetFormat();
+ d << QStringLiteral("World") << 42;
+ }
+ d << QStringLiteral("!") << 42;
+ }
+ QCOMPARE(s_msg, QString::fromLatin1("Hello2a\"World\" 42!2a"));
}
void tst_QDebug::veryLongWarningMessage() const
@@ -241,6 +315,23 @@ void tst_QDebug::veryLongWarningMessage() const
QCOMPARE(QString::fromLatin1(s_function), function);
}
+void tst_QDebug::qDebugQChar() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ d << QChar('f');
+ d.nospace().noquote() << QChar('o') << QChar('o');
+ }
+ QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO;
+ QCOMPARE(s_msgType, QtDebugMsg);
+ QCOMPARE(s_msg, QString::fromLatin1("'f' oo"));
+ QCOMPARE(QString::fromLatin1(s_file), file);
+ QCOMPARE(s_line, line);
+ QCOMPARE(QString::fromLatin1(s_function), function);
+
+}
+
void tst_QDebug::qDebugQStringRef() const
{
/* Use a basic string. */
@@ -276,13 +367,55 @@ void tst_QDebug::qDebugQStringRef() const
void tst_QDebug::qDebugQLatin1String() const
{
MessageHandlerSetter mhs(myMessageHandler);
- { qDebug() << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); }
+ {
+ QDebug d = qDebug();
+ d << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3);
+ d.nospace().noquote() << QLatin1String("baz");
+ }
+ QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO;
+ 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);
+}
+
+void tst_QDebug::qDebugQByteArray() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ d << QByteArrayLiteral("foo") << QByteArrayLiteral("") << QByteArray("barbaz", 3);
+ d.nospace().noquote() << QByteArrayLiteral("baz");
+ }
+ QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO;
+ 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);
+}
+
+enum TestEnum {
+ Flag1 = 0x1,
+ Flag2 = 0x10
+};
+
+Q_DECLARE_FLAGS(TestFlags, TestEnum)
+
+void tst_QDebug::qDebugQFlags() const
+{
+ QFlags<TestEnum> flags(Flag1 | Flag2);
+
+ MessageHandlerSetter mhs(myMessageHandler);
+ { qDebug() << flags; }
QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO;
QCOMPARE(s_msgType, QtDebugMsg);
- QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\""));
+ QCOMPARE(s_msg, QString::fromLatin1("QFlags(0x1|0x10)"));
QCOMPARE(QString::fromLatin1(s_file), file);
QCOMPARE(s_line, line);
QCOMPARE(QString::fromLatin1(s_function), function);
+
}
void tst_QDebug::textStreamModifiers() const
@@ -297,6 +430,22 @@ void tst_QDebug::textStreamModifiers() const
QCOMPARE(QString::fromLatin1(s_function), function);
}
+void tst_QDebug::resetFormat() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ d.nospace().noquote() << hex << int(0xf);
+ d.resetFormat() << int(0xf) << QStringLiteral("foo");
+ }
+ QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO;
+ QCOMPARE(s_msgType, QtDebugMsg);
+ QCOMPARE(s_msg, QString::fromLatin1("f15 \"foo\""));
+ QCOMPARE(QString::fromLatin1(s_file), file);
+ QCOMPARE(s_line, line);
+ QCOMPARE(QString::fromLatin1(s_function), function);
+}
+
void tst_QDebug::defaultMessagehandler() const
{
MessageHandlerSetter mhs(0); // set 0, should set default handler