From 7347a5f99df2da154acb1bdc538d4bc771cab066 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 18 Aug 2011 17:48:35 +0200 Subject: [PATCH 01/43] Make the DBus timeout configurable in QDBusAbstractInterface. Merge-request: 1253 Reviewed-by: Thiago Reviewed-by: Frederik Gladhorn (cherry picked from commit e58a402fbee2fc8af8cd651acafdc28525ed1314) Change-Id: I4246047b149193e510f2984a0b1a1fae655b9a51 Reviewed-on: http://codereview.qt.nokia.com/3580 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/dbus/qdbusabstractinterface.cpp | 31 ++++++- src/dbus/qdbusabstractinterface.h | 3 + src/dbus/qdbusabstractinterface_p.h | 1 + .../com.trolltech.QtDBus.Pinger.xml | 4 + .../auto/qdbusabstractinterface/interface.cpp | 14 +++ tests/auto/qdbusabstractinterface/interface.h | 1 + tests/auto/qdbusabstractinterface/pinger.h | 7 ++ .../tst_qdbusabstractinterface.cpp | 92 +++++++++++++++++++ 8 files changed, 149 insertions(+), 4 deletions(-) diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index 187ad67ddb4..9f683130407 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -88,6 +88,7 @@ QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv : connection(con), service(serv), path(p), interface(iface), lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() && connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))), + timeout(-1), isValid(!lastError.isValid()) { if (!isValid) @@ -144,7 +145,7 @@ void QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, QVariant & QLatin1String("Get")); QDBusMessagePrivate::setParametersValidated(msg, true); msg << interface << QString::fromUtf8(mp.name()); - QDBusMessage reply = connection.call(msg, QDBus::Block); + QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); if (reply.type() != QDBusMessage::ReplyMessage) { lastError = reply; @@ -210,7 +211,7 @@ bool QDBusAbstractInterfacePrivate::setProperty(const QMetaProperty &mp, const Q QLatin1String("Set")); QDBusMessagePrivate::setParametersValidated(msg, true); msg << interface << QString::fromUtf8(mp.name()) << QVariant::fromValue(QDBusVariant(value)); - QDBusMessage reply = connection.call(msg, QDBus::Block); + QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); if (reply.type() != QDBusMessage::ReplyMessage) { lastError = reply; @@ -383,6 +384,28 @@ QDBusError QDBusAbstractInterface::lastError() const return d_func()->lastError; } +/*! + Sets the timeout in seconds for all future DBus calls to \a timeout. + -1 means the default DBus timeout (usually 25 seconds). + + \since 4.8 +*/ +void QDBusAbstractInterface::setTimeout(int timeout) +{ + d_func()->timeout = timeout; +} + +/*! + Returns the current value of the timeout in seconds. + -1 means the default DBus timeout (usually 25 seconds). + + \since 4.8 +*/ +int QDBusAbstractInterface::timeout() const +{ + return d_func()->timeout; +} + /*! Places a call to the remote method specified by \a method on this interface, using \a args as arguments. This function returns the message that was received as a reply, which can be a normal @@ -442,7 +465,7 @@ QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode, QDBusMessagePrivate::setParametersValidated(msg, true); msg.setArguments(args); - QDBusMessage reply = d->connection.call(msg, mode); + QDBusMessage reply = d->connection.call(msg, mode, d->timeout); if (thread() == QThread::currentThread()) d->lastError = reply; // will clear if reply isn't an error @@ -475,7 +498,7 @@ QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); QDBusMessagePrivate::setParametersValidated(msg, true); msg.setArguments(args); - return d->connection.asyncCall(msg); + return d->connection.asyncCall(msg, d->timeout); } /*! diff --git a/src/dbus/qdbusabstractinterface.h b/src/dbus/qdbusabstractinterface.h index 72b922e499e..34ff4107f9f 100644 --- a/src/dbus/qdbusabstractinterface.h +++ b/src/dbus/qdbusabstractinterface.h @@ -95,6 +95,9 @@ public: QDBusError lastError() const; + void setTimeout(int timeout); + int timeout() const; + QDBusMessage call(const QString &method, const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), diff --git a/src/dbus/qdbusabstractinterface_p.h b/src/dbus/qdbusabstractinterface_p.h index a000dafa8bc..4f96165aa02 100644 --- a/src/dbus/qdbusabstractinterface_p.h +++ b/src/dbus/qdbusabstractinterface_p.h @@ -77,6 +77,7 @@ public: QString path; QString interface; mutable QDBusError lastError; + int timeout; // this is set during creation and never changed // it can't be const because QDBusInterfacePrivate has one more check diff --git a/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml index 16675917085..d945ec9b437 100644 --- a/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml +++ b/tests/auto/qdbusabstractinterface/com.trolltech.QtDBus.Pinger.xml @@ -15,6 +15,10 @@ + + + + diff --git a/tests/auto/qdbusabstractinterface/interface.cpp b/tests/auto/qdbusabstractinterface/interface.cpp index 0326177fc08..849db93084f 100644 --- a/tests/auto/qdbusabstractinterface/interface.cpp +++ b/tests/auto/qdbusabstractinterface/interface.cpp @@ -40,9 +40,23 @@ ****************************************************************************/ #include "interface.h" +#include Interface::Interface() { } +// Export the sleep function +// TODO QT5: remove this class, QThread::msleep is now public +class FriendlySleepyThread : public QThread { +public: + using QThread::msleep; +}; + +int Interface::sleepMethod(int msec) +{ + FriendlySleepyThread::msleep(msec); + return 42; +} + #include "moc_interface.cpp" diff --git a/tests/auto/qdbusabstractinterface/interface.h b/tests/auto/qdbusabstractinterface/interface.h index b840a38e8e7..0fb15fe6c50 100644 --- a/tests/auto/qdbusabstractinterface/interface.h +++ b/tests/auto/qdbusabstractinterface/interface.h @@ -101,6 +101,7 @@ public: public slots: Q_SCRIPTABLE void voidMethod() {} + Q_SCRIPTABLE int sleepMethod(int); Q_SCRIPTABLE QString stringMethod() { return "Hello, world"; } Q_SCRIPTABLE RegisteredType complexMethod() { return RegisteredType("Hello, world"); } Q_SCRIPTABLE QString multiOutMethod(int &value) { value = 42; return "Hello, world"; } diff --git a/tests/auto/qdbusabstractinterface/pinger.h b/tests/auto/qdbusabstractinterface/pinger.h index 6245a5a02f6..739a14229f3 100644 --- a/tests/auto/qdbusabstractinterface/pinger.h +++ b/tests/auto/qdbusabstractinterface/pinger.h @@ -117,6 +117,13 @@ public Q_SLOTS: // METHODS return reply; } + inline QDBusPendingReply sleepMethod(int in0) + { + QList argumentList; + argumentList << qVariantFromValue(in0); + return asyncCallWithArgumentList(QLatin1String("sleepMethod"), argumentList); + } + inline QDBusPendingReply stringMethod() { QList argumentList; diff --git a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp index 00e3a76d15d..994df058fa1 100644 --- a/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp +++ b/tests/auto/qdbusabstractinterface/tst_qdbusabstractinterface.cpp @@ -111,6 +111,8 @@ private slots: void makeAsyncComplexCallPeer(); void makeAsyncMultiOutCallPeer(); + void callWithTimeout(); + void stringPropRead(); void stringPropWrite(); void variantPropRead(); @@ -458,6 +460,96 @@ void tst_QDBusAbstractInterface::makeAsyncMultiOutCallPeer() QCoreApplication::instance()->processEvents(); } +static const char server_serviceName[] = "com.trolltech.autotests.dbusserver"; +static const char server_objectPath[] = "/com/trolltech/server"; +static const char server_interfaceName[] = "com.trolltech.QtDBus.Pinger"; + +class DBusServerThread : public QThread +{ +public: + DBusServerThread() { + start(); + m_ready.acquire(); + } + ~DBusServerThread() { + quit(); + wait(); + } + + void run() + { + QDBusConnection con = QDBusConnection::connectToBus(QDBusConnection::SessionBus, "ThreadConnection"); + if (!con.isConnected()) + qWarning("Error registering to DBus"); + if (!con.registerService(server_serviceName)) + qWarning("Error registering service name"); + Interface targetObj; + con.registerObject(server_objectPath, &targetObj, QDBusConnection::ExportScriptableContents); + m_ready.release(); + exec(); + + QDBusConnection::disconnectFromBus( con.name() ); + } +private: + QSemaphore m_ready; +}; + +void tst_QDBusAbstractInterface::callWithTimeout() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + QVERIFY2(con.isConnected(), "Not connected to D-Bus"); + + DBusServerThread serverThread; + + QDBusMessage msg = QDBusMessage::createMethodCall(server_serviceName, + server_objectPath, server_interfaceName, "sleepMethod"); + msg << 100; + + { + // Call with no timeout -> works + QDBusMessage reply = con.call(msg); + QCOMPARE((int)reply.type(), (int)QDBusMessage::ReplyMessage); + QCOMPARE(reply.arguments().at(0).toInt(), 42); + } + + { + // Call with 1 sec timeout -> fails + QDBusMessage reply = con.call(msg, QDBus::Block, 1); + QCOMPARE(reply.type(), QDBusMessage::ErrorMessage); + } + + // Now using QDBusInterface + + QDBusInterface iface(server_serviceName, server_objectPath, server_interfaceName, con); + { + // Call with no timeout + QDBusMessage reply = iface.call("sleepMethod", 100); + QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); + QCOMPARE(reply.arguments().at(0).toInt(), 42); + } + { + // Call with 1 sec timeout -> fails + iface.setTimeout(1); + QDBusMessage reply = iface.call("sleepMethod", 100); + QCOMPARE(reply.type(), QDBusMessage::ErrorMessage); + } + + // Now using generated code + com::trolltech::QtDBus::Pinger p(server_serviceName, server_objectPath, QDBusConnection::sessionBus()); + { + // Call with no timeout + QDBusReply reply = p.sleepMethod(100); + QVERIFY(reply.isValid()); + QCOMPARE(int(reply), 42); + } + { + // Call with 1 sec timeout -> fails + p.setTimeout(1); + QDBusReply reply = p.sleepMethod(100); + QVERIFY(!reply.isValid()); + } +} + void tst_QDBusAbstractInterface::stringPropRead() { Pinger p = getPinger(); From d4d883de469a87914748b41c69d80d9a890205e4 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 17 Aug 2011 13:14:57 +0200 Subject: [PATCH 02/43] Add a QApplication::queryKeyboardModifiers() method. QApplication::keyboardModifiers returns the keyboard modifiers from the last keypress event in this process, as documented. However there are use cases for querying keyboard modifiers as they currently are, see QTBUG-11243. Merge-request: 585 Reviewed-by: Frederik Gladhorn (cherry picked from commit 3b5354386225974ea6db78c12f32cb81e2d50104) Change-Id: I9b4e54ac79fc225e3ed8d2bcaba953a6eb59f0d2 Reviewed-on: http://codereview.qt.nokia.com/3581 Reviewed-by: Frederik Gladhorn --- src/gui/kernel/qapplication.cpp | 21 ++++++++++++++++++++- src/gui/kernel/qapplication.h | 1 + src/gui/kernel/qapplication_mac.mm | 5 +++++ src/gui/kernel/qapplication_qws.cpp | 5 +++++ src/gui/kernel/qapplication_s60.cpp | 8 ++++++++ src/gui/kernel/qapplication_win.cpp | 5 +++++ src/gui/kernel/qapplication_x11.cpp | 15 +++++++++++++++ src/gui/kernel/qdnd_x11.cpp | 17 +---------------- 8 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 9cd1b7bb092..593a3209a85 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -3319,7 +3319,7 @@ bool QApplication::desktopSettingsAware() one of the above events. If no keys are being held Qt::NoModifier is returned. - \sa mouseButtons() + \sa mouseButtons(), queryKeyboardModifiers() */ Qt::KeyboardModifiers QApplication::keyboardModifiers() @@ -3327,6 +3327,25 @@ Qt::KeyboardModifiers QApplication::keyboardModifiers() return QApplicationPrivate::modifier_buttons; } +/*! + \fn Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() + + Queries and returns the state of the modifier keys on the keyboard. + Unlike keyboardModifiers, this method returns the actual keys held + on the input device at the time of calling the method. + + It does not rely on the keypress events having been received by this + process, which makes it possible to check the modifiers while moving + a window, for instance. Note that in most cases, you should use + keyboardModifiers(), which is faster and more accurate since it contains + the state of the modifiers as they were when the currently processed + event was received. + + \sa keyboardModifiers() + + \since 4.8 +*/ + /*! Returns the current state of the buttons on the mouse. The current state is updated syncronously as the event queue is emptied of events that will diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index 01a246a0c67..15488490d19 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -198,6 +198,7 @@ public: static void alert(QWidget *widget, int duration = 0); static Qt::KeyboardModifiers keyboardModifiers(); + static Qt::KeyboardModifiers queryKeyboardModifiers(); static Qt::MouseButtons mouseButtons(); static void setDesktopSettingsAware(bool); diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index cb1f0cdbe45..e06756c86a8 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1395,6 +1395,11 @@ void QApplication::restoreOverrideCursor() } #endif // QT_NO_CURSOR +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return qt_mac_get_modifiers(GetCurrentEventKeyModifiers()); +} + QWidget *QApplication::topLevelAt(const QPoint &p) { #ifndef QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp index 14f779008c4..428f5580239 100644 --- a/src/gui/kernel/qapplication_qws.cpp +++ b/src/gui/kernel/qapplication_qws.cpp @@ -2707,6 +2707,11 @@ void QApplication::alert(QWidget *, int) { } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return keyboardModifiers(); // TODO proper implementation +} + int QApplication::qwsProcessEvent(QWSEvent* event) { Q_D(QApplication); diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index f0739cdd9f9..e277765effb 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -114,6 +114,8 @@ QWidget *qt_button_down = 0; // widget got last button-down QSymbianControl *QSymbianControl::lastFocusedControl = 0; +static Qt::KeyboardModifiers app_keyboardModifiers = Qt::NoModifier; + QS60Data* qGlobalS60Data() { return qt_s60Data(); @@ -712,6 +714,7 @@ void QSymbianControl::HandlePointerEvent(const TPointerEvent& pEvent) Qt::MouseButton button; mapS60MouseEventTypeToQt(&type, &button, &pEvent); Qt::KeyboardModifiers modifiers = mapToQtModifiers(pEvent.iModifiers); + app_keyboardModifiers = modifiers; QPoint widgetPos = translatePointForFixedNativeOrientation(pEvent.iPosition); TPoint controlScreenPos = PositionRelativeToScreen(); @@ -2541,6 +2544,11 @@ void QApplication::setEffectEnabled(Qt::UIEffect /* effect */, bool /* enable */ // TODO: Implement QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return app_keyboardModifiers; +} + TUint QApplicationPrivate::resolveS60ScanCode(TInt scanCode, TUint keysym) { if (!scanCode) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index c34e75ffccc..756cb56b582 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1319,6 +1319,11 @@ Qt::KeyboardModifiers qt_win_getKeyboardModifiers() return modifiers; } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return qt_win_getKeyboardModifiers(); +} + /***************************************************************************** Routines to find a Qt widget from a screen position *****************************************************************************/ diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 8d5a0b8a50b..311b147976d 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -3061,6 +3061,21 @@ void QApplicationPrivate::_q_alertTimeOut() } } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint keybstate; + for (int i = 0; i < ScreenCount(X11->display); ++i) { + if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child, + &root_x, &root_y, &win_x, &win_y, &keybstate)) + return X11->translateModifiers(keybstate & 0x00ff); + } + return 0; + +} + /***************************************************************************** Special lookup functions for windows that have been reparented recently *****************************************************************************/ diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 750ddf892e6..11e87e96f32 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -1112,21 +1112,6 @@ void qt_xdnd_send_leave() waiting_for_status = false; } -// TODO: remove and use QApplication::currentKeyboardModifiers() in Qt 4.8. -static Qt::KeyboardModifiers currentKeyboardModifiers() -{ - Window root; - Window child; - int root_x, root_y, win_x, win_y; - uint keybstate; - for (int i = 0; i < ScreenCount(X11->display); ++i) { - if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child, - &root_x, &root_y, &win_x, &win_y, &keybstate)) - return X11->translateModifiers(keybstate & 0x00ff); - } - return 0; -} - void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) { DEBUG("xdndHandleDrop"); @@ -1175,7 +1160,7 @@ void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) // Drop coming from another app? Update keyboard modifiers. if (!qt_xdnd_dragging) { - QApplicationPrivate::modifier_buttons = currentKeyboardModifiers(); + QApplicationPrivate::modifier_buttons = QApplication::queryKeyboardModifiers(); } QDropEvent de(qt_xdnd_current_position, possible_actions, dropData, From 64bd1737add51f52f8add7d8ee8d57597a702cb4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 25 Aug 2011 12:42:44 +0200 Subject: [PATCH 03/43] Mark QNetworkReply test as unstable QTBUG-21102 is currently blocking integration of several commits. Marking the test as unstable until the bug has been fixed. Change-Id: I9b630767fd1aa4369564f5e90c63e850808385e1 Reviewed-on: http://codereview.qt.nokia.com/3584 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Petersson --- tests/auto/qnetworkreply/test/test.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/qnetworkreply/test/test.pro b/tests/auto/qnetworkreply/test/test.pro index d415e04451c..dba1c69dbb6 100644 --- a/tests/auto/qnetworkreply/test/test.pro +++ b/tests/auto/qnetworkreply/test/test.pro @@ -3,6 +3,8 @@ QT -= gui SOURCES += ../tst_qnetworkreply.cpp TARGET = ../tst_qnetworkreply +qpa:contains(QT_CONFIG,xcb): CONFIG+=insignificant_test # unstable, QTBUG-21102 + win32 { CONFIG(debug, debug|release) { TARGET = ../../debug/tst_qnetworkreply From 56746e3dfab072f00a0ef1fa5276765ca8d8a9c0 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 25 Aug 2011 13:02:39 +1000 Subject: [PATCH 04/43] test: marked tst_qlistwidget as insignificant This test sometimes passes and sometimes fails. Task-number: QTBUG-21098 Change-Id: Ic56e93d12a7b3fa2e9c135e25610bf1119fa636e Reviewed-on: http://codereview.qt.nokia.com/3548 Reviewed-by: Qt Sanity Bot Reviewed-by: Michael Goddard --- tests/auto/qlistwidget/qlistwidget.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/qlistwidget/qlistwidget.pro b/tests/auto/qlistwidget/qlistwidget.pro index eb4c335b5bb..30305e1c8dc 100644 --- a/tests/auto/qlistwidget/qlistwidget.pro +++ b/tests/auto/qlistwidget/qlistwidget.pro @@ -2,4 +2,4 @@ load(qttest_p4) QT += core-private gui-private SOURCES += tst_qlistwidget.cpp - +qpa:contains(QT_CONFIG,xcb):CONFIG+=insignificant_test # QTBUG-21098, fails unstably From 8525cb69b12612d4588b20116ef7379ca322e6dd Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 25 Aug 2011 13:38:08 +1000 Subject: [PATCH 05/43] test: marked tst_qmenu as insignificant (for qpa, xcb) This autotest sometimes fails and sometimes passes. Task-number: QTBUG-21100 Change-Id: I5b3a1cb9713cc12ead130b4c64a876397d61fe17 Reviewed-on: http://codereview.qt.nokia.com/3549 Reviewed-by: Qt Sanity Bot Reviewed-by: Sergio Ahumada --- tests/auto/qmenu/qmenu.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/qmenu/qmenu.pro b/tests/auto/qmenu/qmenu.pro index 3a32920b140..63451a11b6e 100644 --- a/tests/auto/qmenu/qmenu.pro +++ b/tests/auto/qmenu/qmenu.pro @@ -1,2 +1,4 @@ load(qttest_p4) SOURCES += tst_qmenu.cpp + +qpa:contains(QT_CONFIG,xcb):CONFIG+=insignificant_test # QTBUG-21100, unstably fails From 37fc7b5fe6cec8ea211afec4f0b3b199f11bb87a Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 25 Aug 2011 18:04:23 +1000 Subject: [PATCH 06/43] test: marked tst_qfiledialog as insignificant for qpa, xcb This autotest sometimes passes and sometimes fails. Task-number: QTBUG-21109 Change-Id: I160b43a1abd0de7350029f2eb758f177e880d38d Reviewed-on: http://codereview.qt.nokia.com/3575 Reviewed-by: Qt Sanity Bot Reviewed-by: Sergio Ahumada --- tests/auto/qfiledialog/qfiledialog.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/auto/qfiledialog/qfiledialog.pro b/tests/auto/qfiledialog/qfiledialog.pro index 57828b1bd47..ec93f12a951 100644 --- a/tests/auto/qfiledialog/qfiledialog.pro +++ b/tests/auto/qfiledialog/qfiledialog.pro @@ -26,3 +26,5 @@ wince* { } else { DEFINES += SRCDIR=\\\"$$PWD/\\\" } + +qpa:contains(QT_CONFIG,xcb):CONFIG+=insignificant_test From 9a442b7b54883dbc2830486ca15802d15df46bad Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 14 Jul 2011 10:57:02 +0200 Subject: [PATCH 07/43] Add constants to QAccessible::Event enum. Reviewed-by: Gabi (cherry picked from commit 81036d4be6122dfcb55a4852bcc1037c7d8f7309) Change-Id: Id818d9c9e53ece0c93b89649db5aa31d59920426 Reviewed-on: http://codereview.qt.nokia.com/3031 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible.h | 68 ++++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index 16869bb926a..24a67446435 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -84,40 +84,40 @@ public: MenuCommand = 0x0018, // Values from IAccessible2 - ActionChanged = 0x0101, - ActiveDescendantChanged, - AttributeChanged, - DocumentContentChanged, - DocumentLoadComplete, - DocumentLoadStopped, - DocumentReload, - HyperlinkEndIndexChanged, - HyperlinkNumberOfAnchorsChanged, - HyperlinkSelectedLinkChanged, - HypertextLinkActivated, - HypertextLinkSelected, - HyperlinkStartIndexChanged, - HypertextChanged, - HypertextNLinksChanged, - ObjectAttributeChanged, - PageChanged, - SectionChanged, - TableCaptionChanged, - TableColumnDescriptionChanged, - TableColumnHeaderChanged, - TableModelChanged, - TableRowDescriptionChanged, - TableRowHeaderChanged, - TableSummaryChanged, - TextAttributeChanged, - TextCaretMoved, - // TextChanged, deprecated, use TextUpdated - TextColumnChanged = TextCaretMoved + 2, - TextInserted, - TextRemoved, - TextUpdated, - TextSelectionChanged, - VisibleDataChanged, + ActionChanged = 0x0101, + ActiveDescendantChanged = 0x0102, + AttributeChanged = 0x0103, + DocumentContentChanged = 0x0104, + DocumentLoadComplete = 0x0105, + DocumentLoadStopped = 0x0106, + DocumentReload = 0x0107, + HyperlinkEndIndexChanged = 0x0108, + HyperlinkNumberOfAnchorsChanged = 0x0109, + HyperlinkSelectedLinkChanged = 0x010A, + HypertextLinkActivated = 0x010B, + HypertextLinkSelected = 0x010C, + HyperlinkStartIndexChanged = 0x010D, + HypertextChanged = 0x010E, + HypertextNLinksChanged = 0x010F, + ObjectAttributeChanged = 0x0110, + PageChanged = 0x0111, + SectionChanged = 0x0112, + TableCaptionChanged = 0x0113, + TableColumnDescriptionChanged = 0x0114, + TableColumnHeaderChanged = 0x0115, + TableModelChanged = 0x0116, + TableRowDescriptionChanged = 0x0117, + TableRowHeaderChanged = 0x0118, + TableSummaryChanged = 0x0119, + TextAttributeChanged = 0x011A, + TextCaretMoved = 0x011B, + // TextChanged = 0x011C, is deprecated in IA2, use TextUpdated + TextColumnChanged = 0x011D, + TextInserted = 0x011E, + TextRemoved = 0x011F, + TextUpdated = 0x0120, + TextSelectionChanged = 0x0121, + VisibleDataChanged = 0x0122, ObjectCreated = 0x8000, ObjectDestroyed = 0x8001, From e6cecd9ce01b1fcdf7d8038fa79cd60b10ab43bf Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 24 Aug 2011 09:13:45 +0200 Subject: [PATCH 08/43] Fix justification of RTL text Since the trailing space is included in the QScriptLine, it may affect the positions of preceding script items when the text is RTL. The best solution for this would be to disregard the trailing space in the layout process, or somehow make it have an advance of 0 so it doesn't affect the layout. However, to minimize the impact of the change, and to be consistent with previous work arounds such as bf992df6434fc37715f728ca09601c5567dd83c9, we simply include the trailing (visually leading) space in the justification pass for now. Task-number: QTBUG-20920 Reviewed-by: Lars (cherry picked from commit 1a8a36eb6b6df9e2550b5eaa4606f2d411fd4294) Change-Id: I94972ebaea2e1bdb09950523c43844351b304abe Reviewed-on: http://codereview.qt.nokia.com/3462 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Qt Sanity Bot --- src/gui/text/qtextengine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index f7b7aa28a1e..53cd2baa013 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2093,7 +2093,8 @@ void QTextEngine::justify(const QScriptLine &line) } } - QFixed need = line.width - line.textWidth; + QFixed leading = leadingSpaceWidth(line); + QFixed need = line.width - line.textWidth - leading; if (need < 0) { // line overflows already! const_cast(line).justified = true; From c478ebc91445b3f7b42a594208aca4d8e9c71a70 Mon Sep 17 00:00:00 2001 From: Michael Goddard Date: Wed, 24 Aug 2011 12:28:50 +1000 Subject: [PATCH 09/43] Don't use the // operator, since some versions of Perl don't have it. Could use || but it's only used for an if test anyway. Change-Id: I97fe251ab4f27fb75981af12316aaf5da053d47a Reviewed-on: http://codereview.qt.nokia.com/3431 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- bin/qtmodule-configtests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/qtmodule-configtests b/bin/qtmodule-configtests index 0552f8e6146..ab03908c845 100755 --- a/bin/qtmodule-configtests +++ b/bin/qtmodule-configtests @@ -267,7 +267,7 @@ if (abs_path($out_basedir) ne abs_path($qtbasedir)) { while ((my $testName, my $testParameters) = each %configtests) { printf " % *s: ", $maxNameLength, $testName; # right aligned, yes/no lines up - my $fatalTest = $testParameters->{"fatal"} // 0; + my $fatalTest = $testParameters->{"fatal"}; my $message = $testParameters->{"message"}; my $testResult = executeTest($testName); From 3c48d26c5b297f851615f942b30a3346d8b0df5c Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 25 Aug 2011 16:21:36 +1000 Subject: [PATCH 10/43] Remove duplicated code from QTestBasicStreamer. Instead of using the file output functions inherited from QAbstractTestLogger, QTestLogger relied on QTestBasicStreamer having a copy of these functions. This commit removes the copied functions from QTestBasicStreamer and makes it and QTestLogger use the original functions from QAbstractTestLogger. Change-Id: Icac1ae9d85cd39efd4c67c79104404dd56766b17 Reviewed-on: http://codereview.qt.nokia.com/3565 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestbasicstreamer.cpp | 53 +----------------------------- src/testlib/qtestbasicstreamer.h | 3 -- src/testlib/qtestlogger.cpp | 5 +-- 3 files changed, 4 insertions(+), 57 deletions(-) diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp index 25e48ee4d52..50933b91cd1 100644 --- a/src/testlib/qtestbasicstreamer.cpp +++ b/src/testlib/qtestbasicstreamer.cpp @@ -43,8 +43,6 @@ #include "qtestlogger_p.h" #include "qtestelement.h" #include "qtestelementattribute.h" -#include "QtTest/private/qtestlog_p.h" -#include "qtestassert.h" #include #include @@ -55,11 +53,6 @@ QT_BEGIN_NAMESPACE -namespace QTest -{ - static FILE *stream = 0; -} - QTestBasicStreamer::QTestBasicStreamer() :testLogger(0) { @@ -158,51 +151,7 @@ void QTestBasicStreamer::outputElementAttributes(const QTestElement* element, QT void QTestBasicStreamer::outputString(const char *msg) const { - QTEST_ASSERT(QTest::stream); - - ::fputs(msg, QTest::stream); - ::fflush(QTest::stream); -} - -void QTestBasicStreamer::startStreaming() -{ - QTEST_ASSERT(!QTest::stream); - - const char *out = QTestLog::outputFileName(); - if (!out) { - QTest::stream = stdout; - return; - } - #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, out, "wt")) { - #else - QTest::stream = ::fopen(out, "wt"); - if (!QTest::stream) { - #endif - printf("Unable to open file for logging: %s", out); - ::exit(1); - } -} - -bool QTestBasicStreamer::isTtyOutput() -{ - QTEST_ASSERT(QTest::stream); - -#if defined(Q_OS_WIN) || defined(Q_OS_INTEGRITY) - return true; -#else - static bool ttyoutput = isatty(fileno(QTest::stream)); - return ttyoutput; -#endif -} - -void QTestBasicStreamer::stopStreaming() -{ - QTEST_ASSERT(QTest::stream); - if (QTest::stream != stdout) - fclose(QTest::stream); - - QTest::stream = 0; + testLogger->outputString(msg); } void QTestBasicStreamer::setLogger(const QTestLogger *tstLogger) diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h index 867c1f1d7de..371bb496eaf 100644 --- a/src/testlib/qtestbasicstreamer.h +++ b/src/testlib/qtestbasicstreamer.h @@ -64,9 +64,6 @@ class QTestBasicStreamer virtual void output(QTestElement *element) const; void outputString(const char *msg) const; - bool isTtyOutput(); - void startStreaming(); - void stopStreaming(); void setLogger(const QTestLogger *tstLogger); const QTestLogger *logger() const; diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 2c81a4bec7d..316e89fb551 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -80,6 +80,8 @@ QTestLogger::~QTestLogger() void QTestLogger::startLogging() { + QAbstractTestLogger::startLogging(); + switch(format){ case TLF_LightXml:{ logFormatter = new QTestLightXmlStreamer; @@ -99,7 +101,6 @@ void QTestLogger::startLogging() } logFormatter->setLogger(this); - logFormatter->startStreaming(); } void QTestLogger::stopLogging() @@ -161,7 +162,7 @@ void QTestLogger::stopLogging() logFormatter->output(iterator); } - logFormatter->stopStreaming(); + QAbstractTestLogger::stopLogging(); } void QTestLogger::enterTestFunction(const char *function) From c400a3433a15adac5ff58898c29900169458d2c1 Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 15 Jul 2011 04:30:33 +0400 Subject: [PATCH 11/43] don't build code related to CClass if QT_NO_REGEXP_CCLASS is defined Change-Id: If86835b1065eeb95e0774f1b42870dcd5225da58 Reviewed-on: http://codereview.qt.nokia.com/3671 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/corelib/tools/qregexp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 325320da121..a93767fc85a 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1252,7 +1252,9 @@ private: friend class Box; +#ifndef QT_NO_REGEXP_CCLASS void setupCategoriesRangeMap(); +#endif /* This is the lexical analyzer for regular expressions. @@ -1293,7 +1295,9 @@ private: int yyTok; // the last token read bool yyMayCapture; // set this to false to disable capturing +#ifndef QT_NO_REGEXP_CCLASS QHash > categoriesRangeMap; // fast lookup hash for xml schema extensions +#endif friend struct QRegExpMatchState; }; @@ -2735,6 +2739,7 @@ void QRegExpEngine::Box::addAnchorsToEngine(const Box &to) const } } +#ifndef QT_NO_REGEXP_CCLASS void QRegExpEngine::setupCategoriesRangeMap() { categoriesRangeMap.insert("IsBasicLatin", qMakePair(0x0000, 0x007F)); @@ -2880,6 +2885,7 @@ void QRegExpEngine::setupCategoriesRangeMap() categoriesRangeMap.insert("IsSupplementaryPrivateUseArea-A", qMakePair(0xF0000, 0xFFFFF)); categoriesRangeMap.insert("IsSupplementaryPrivateUseArea-B", qMakePair(0x100000, 0x10FFFF)); } +#endif int QRegExpEngine::getChar() { From 24667a905d17bb1c11b0673bba4284edf733c03a Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 15 Jul 2011 04:29:03 +0400 Subject: [PATCH 12/43] optimize parsing of templates like p{L}, p{Lu}, etc replacing the if-else trees with the switch statement gives a 2x-3x parsing performance boost on parsing these expressions. Change-Id: Ia0e76ae4e1ab6930dbecf1d4a5232a4cc7198654 Reviewed-on: http://codereview.qt.nokia.com/3672 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/corelib/tools/qregexp.cpp | 222 +++++++++++++++++++--------------- 1 file changed, 124 insertions(+), 98 deletions(-) diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index a93767fc85a..5932fb8aa82 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -3107,104 +3107,130 @@ int QRegExpEngine::getEscape() } yyCh = getChar(); // skip closing '}' - if (category == "M") { - yyCharClass->addCategories(FLAG(QChar::Mark_NonSpacing) | - FLAG(QChar::Mark_SpacingCombining) | - FLAG(QChar::Mark_Enclosing)); - } else if (category == "Mn") { - yyCharClass->addCategories(FLAG(QChar::Mark_NonSpacing)); - } else if (category == "Mc") { - yyCharClass->addCategories(FLAG(QChar::Mark_SpacingCombining)); - } else if (category == "Me") { - yyCharClass->addCategories(FLAG(QChar::Mark_Enclosing)); - } else if (category == "N") { - yyCharClass->addCategories(FLAG(QChar::Number_DecimalDigit) | - FLAG(QChar::Number_Letter) | - FLAG(QChar::Number_Other)); - } else if (category == "Nd") { - yyCharClass->addCategories(FLAG(QChar::Number_DecimalDigit)); - } else if (category == "Nl") { - yyCharClass->addCategories(FLAG(QChar::Number_Letter)); - } else if (category == "No") { - yyCharClass->addCategories(FLAG(QChar::Number_Other)); - } else if (category == "Z") { - yyCharClass->addCategories(FLAG(QChar::Separator_Space) | - FLAG(QChar::Separator_Line) | - FLAG(QChar::Separator_Paragraph)); - } else if (category == "Zs") { - yyCharClass->addCategories(FLAG(QChar::Separator_Space)); - } else if (category == "Zl") { - yyCharClass->addCategories(FLAG(QChar::Separator_Line)); - } else if (category == "Zp") { - yyCharClass->addCategories(FLAG(QChar::Separator_Paragraph)); - } else if (category == "C") { - yyCharClass->addCategories(FLAG(QChar::Other_Control) | - FLAG(QChar::Other_Format) | - FLAG(QChar::Other_Surrogate) | - FLAG(QChar::Other_PrivateUse) | - FLAG(QChar::Other_NotAssigned)); - } else if (category == "Cc") { - yyCharClass->addCategories(FLAG(QChar::Other_Control)); - } else if (category == "Cf") { - yyCharClass->addCategories(FLAG(QChar::Other_Format)); - } else if (category == "Cs") { - yyCharClass->addCategories(FLAG(QChar::Other_Surrogate)); - } else if (category == "Co") { - yyCharClass->addCategories(FLAG(QChar::Other_PrivateUse)); - } else if (category == "Cn") { - yyCharClass->addCategories(FLAG(QChar::Other_NotAssigned)); - } else if (category == "L") { - yyCharClass->addCategories(FLAG(QChar::Letter_Uppercase) | - FLAG(QChar::Letter_Lowercase) | - FLAG(QChar::Letter_Titlecase) | - FLAG(QChar::Letter_Modifier) | - FLAG(QChar::Letter_Other)); - } else if (category == "Lu") { - yyCharClass->addCategories(FLAG(QChar::Letter_Uppercase)); - } else if (category == "Ll") { - yyCharClass->addCategories(FLAG(QChar::Letter_Lowercase)); - } else if (category == "Lt") { - yyCharClass->addCategories(FLAG(QChar::Letter_Titlecase)); - } else if (category == "Lm") { - yyCharClass->addCategories(FLAG(QChar::Letter_Modifier)); - } else if (category == "Lo") { - yyCharClass->addCategories(FLAG(QChar::Letter_Other)); - } else if (category == "P") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Connector) | - FLAG(QChar::Punctuation_Dash) | - FLAG(QChar::Punctuation_Open) | - FLAG(QChar::Punctuation_Close) | - FLAG(QChar::Punctuation_InitialQuote) | - FLAG(QChar::Punctuation_FinalQuote) | - FLAG(QChar::Punctuation_Other)); - } else if (category == "Pc") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Connector)); - } else if (category == "Pd") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Dash)); - } else if (category == "Ps") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Open)); - } else if (category == "Pe") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Close)); - } else if (category == "Pi") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_InitialQuote)); - } else if (category == "Pf") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_FinalQuote)); - } else if (category == "Po") { - yyCharClass->addCategories(FLAG(QChar::Punctuation_Other)); - } else if (category == "S") { - yyCharClass->addCategories(FLAG(QChar::Symbol_Math) | - FLAG(QChar::Symbol_Currency) | - FLAG(QChar::Symbol_Modifier) | - FLAG(QChar::Symbol_Other)); - } else if (category == "Sm") { - yyCharClass->addCategories(FLAG(QChar::Symbol_Math)); - } else if (category == "Sc") { - yyCharClass->addCategories(FLAG(QChar::Symbol_Currency)); - } else if (category == "Sk") { - yyCharClass->addCategories(FLAG(QChar::Symbol_Modifier)); - } else if (category == "So") { - yyCharClass->addCategories(FLAG(QChar::Symbol_Other)); - } else if (category.startsWith("Is")) { + int catlen = category.length(); + if (catlen == 1 || catlen == 2) { + switch (category.at(0)) { + case 'M': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Mark_NonSpacing) | + FLAG(QChar::Mark_SpacingCombining) | + FLAG(QChar::Mark_Enclosing)); + } else { + switch (category.at(1)) { + case 'n': yyCharClass->addCategories(FLAG(QChar::Mark_NonSpacing)); break; // Mn + case 'c': yyCharClass->addCategories(FLAG(QChar::Mark_SpacingCombining)); break; // Mc + case 'e': yyCharClass->addCategories(FLAG(QChar::Mark_Enclosing)); break; // Me + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'N': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Number_DecimalDigit) | + FLAG(QChar::Number_Letter) | + FLAG(QChar::Number_Other)); + } else { + switch (category.at(1)) { + case 'd': yyCharClass->addCategories(FLAG(QChar::Number_DecimalDigit)); break; // Nd + case 'l': yyCharClass->addCategories(FLAG(QChar::Number_Letter)); break; // Hl + case 'o': yyCharClass->addCategories(FLAG(QChar::Number_Other)); break; // No + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'Z': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Separator_Space) | + FLAG(QChar::Separator_Line) | + FLAG(QChar::Separator_Paragraph)); + } else { + switch (category.at(1)) { + case 's': yyCharClass->addCategories(FLAG(QChar::Separator_Space)); break; // Zs + case 'l': yyCharClass->addCategories(FLAG(QChar::Separator_Line)); break; // Zl + case 'p': yyCharClass->addCategories(FLAG(QChar::Separator_Paragraph)); break; // Zp + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'C': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Other_Control) | + FLAG(QChar::Other_Format) | + FLAG(QChar::Other_Surrogate) | + FLAG(QChar::Other_PrivateUse) | + FLAG(QChar::Other_NotAssigned)); + } else { + switch (category.at(1)) { + case 'c': yyCharClass->addCategories(FLAG(QChar::Other_Control)); break; // Cc + case 'f': yyCharClass->addCategories(FLAG(QChar::Other_Format)); break; // Cf + case 's': yyCharClass->addCategories(FLAG(QChar::Other_Surrogate)); break; // Cs + case 'o': yyCharClass->addCategories(FLAG(QChar::Other_PrivateUse)); break; // Co + case 'n': yyCharClass->addCategories(FLAG(QChar::Other_NotAssigned)); break; // Cn + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'L': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Letter_Uppercase) | + FLAG(QChar::Letter_Lowercase) | + FLAG(QChar::Letter_Titlecase) | + FLAG(QChar::Letter_Modifier) | + FLAG(QChar::Letter_Other)); + } else { + switch (category.at(1)) { + case 'u': yyCharClass->addCategories(FLAG(QChar::Letter_Uppercase)); break; // Lu + case 'l': yyCharClass->addCategories(FLAG(QChar::Letter_Lowercase)); break; // Ll + case 't': yyCharClass->addCategories(FLAG(QChar::Letter_Titlecase)); break; // Lt + case 'm': yyCharClass->addCategories(FLAG(QChar::Letter_Modifier)); break; // Lm + case 'o': yyCharClass->addCategories(FLAG(QChar::Letter_Other)); break; // Lo + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'P': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Punctuation_Connector) | + FLAG(QChar::Punctuation_Dash) | + FLAG(QChar::Punctuation_Open) | + FLAG(QChar::Punctuation_Close) | + FLAG(QChar::Punctuation_InitialQuote) | + FLAG(QChar::Punctuation_FinalQuote) | + FLAG(QChar::Punctuation_Other)); + } else { + switch (category.at(1)) { + case 'c': yyCharClass->addCategories(FLAG(QChar::Punctuation_Connector)); break; // Pc + case 'd': yyCharClass->addCategories(FLAG(QChar::Punctuation_Dash)); break; // Pd + case 's': yyCharClass->addCategories(FLAG(QChar::Punctuation_Open)); break; // Ps + case 'e': yyCharClass->addCategories(FLAG(QChar::Punctuation_Close)); break; // Pe + case 'i': yyCharClass->addCategories(FLAG(QChar::Punctuation_InitialQuote)); break; // Pi + case 'f': yyCharClass->addCategories(FLAG(QChar::Punctuation_FinalQuote)); break; // Pf + case 'o': yyCharClass->addCategories(FLAG(QChar::Punctuation_Other)); break; // Po + default: error(RXERR_CATEGORY); break; + } + } + break; + case 'S': + if (catlen == 1) { + yyCharClass->addCategories(FLAG(QChar::Symbol_Math) | + FLAG(QChar::Symbol_Currency) | + FLAG(QChar::Symbol_Modifier) | + FLAG(QChar::Symbol_Other)); + } else { + switch (category.at(1)) { + case 'm': yyCharClass->addCategories(FLAG(QChar::Symbol_Math)); break; // Sm + case 'c': yyCharClass->addCategories(FLAG(QChar::Symbol_Currency)); break; // Sc + case 'k': yyCharClass->addCategories(FLAG(QChar::Symbol_Modifier)); break; // Sk + case 'o': yyCharClass->addCategories(FLAG(QChar::Symbol_Other)); break; // So + default: error(RXERR_CATEGORY); break; + } + } + break; + default: + error(RXERR_CATEGORY); + break; + } + } else if (catlen > 2 && category.at(0) == 'I' && category.at(1) == 's') { if (categoriesRangeMap.isEmpty()) setupCategoriesRangeMap(); From 580bd22dc6162f3da2b829093cb14e898f2f628f Mon Sep 17 00:00:00 2001 From: Ritt Konstantin Date: Fri, 15 Jul 2011 06:00:05 +0400 Subject: [PATCH 13/43] optimize parsing of templates like p{IsArabic}, etc use qBinaryFind() with a case-sensitive string comparison instead of QHash. This also improves startup time and reduces runtime memory consumption. Change-Id: I5c5f7cae5e42acb3fa727acac19fe39c53310329 Reviewed-on: http://codereview.qt.nokia.com/3673 Reviewed-by: Qt Sanity Bot Reviewed-by: Lars Knoll --- src/corelib/tools/qregexp.cpp | 321 +++++++++++++++++----------------- 1 file changed, 160 insertions(+), 161 deletions(-) diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 5932fb8aa82..5e2e56ea34a 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1252,10 +1252,6 @@ private: friend class Box; -#ifndef QT_NO_REGEXP_CCLASS - void setupCategoriesRangeMap(); -#endif - /* This is the lexical analyzer for regular expressions. */ @@ -1295,9 +1291,6 @@ private: int yyTok; // the last token read bool yyMayCapture; // set this to false to disable capturing -#ifndef QT_NO_REGEXP_CCLASS - QHash > categoriesRangeMap; // fast lookup hash for xml schema extensions -#endif friend struct QRegExpMatchState; }; @@ -2740,152 +2733,161 @@ void QRegExpEngine::Box::addAnchorsToEngine(const Box &to) const } #ifndef QT_NO_REGEXP_CCLASS -void QRegExpEngine::setupCategoriesRangeMap() -{ - categoriesRangeMap.insert("IsBasicLatin", qMakePair(0x0000, 0x007F)); - categoriesRangeMap.insert("IsLatin-1Supplement", qMakePair(0x0080, 0x00FF)); - categoriesRangeMap.insert("IsLatinExtended-A", qMakePair(0x0100, 0x017F)); - categoriesRangeMap.insert("IsLatinExtended-B", qMakePair(0x0180, 0x024F)); - categoriesRangeMap.insert("IsIPAExtensions", qMakePair(0x0250, 0x02AF)); - categoriesRangeMap.insert("IsSpacingModifierLetters", qMakePair(0x02B0, 0x02FF)); - categoriesRangeMap.insert("IsCombiningDiacriticalMarks", qMakePair(0x0300, 0x036F)); - categoriesRangeMap.insert("IsGreek", qMakePair(0x0370, 0x03FF)); - categoriesRangeMap.insert("IsCyrillic", qMakePair(0x0400, 0x04FF)); - categoriesRangeMap.insert("IsCyrillicSupplement", qMakePair(0x0500, 0x052F)); - categoriesRangeMap.insert("IsArmenian", qMakePair(0x0530, 0x058F)); - categoriesRangeMap.insert("IsHebrew", qMakePair(0x0590, 0x05FF)); - categoriesRangeMap.insert("IsArabic", qMakePair(0x0600, 0x06FF)); - categoriesRangeMap.insert("IsSyriac", qMakePair(0x0700, 0x074F)); - categoriesRangeMap.insert("IsArabicSupplement", qMakePair(0x0750, 0x077F)); - categoriesRangeMap.insert("IsThaana", qMakePair(0x0780, 0x07BF)); - categoriesRangeMap.insert("IsDevanagari", qMakePair(0x0900, 0x097F)); - categoriesRangeMap.insert("IsBengali", qMakePair(0x0980, 0x09FF)); - categoriesRangeMap.insert("IsGurmukhi", qMakePair(0x0A00, 0x0A7F)); - categoriesRangeMap.insert("IsGujarati", qMakePair(0x0A80, 0x0AFF)); - categoriesRangeMap.insert("IsOriya", qMakePair(0x0B00, 0x0B7F)); - categoriesRangeMap.insert("IsTamil", qMakePair(0x0B80, 0x0BFF)); - categoriesRangeMap.insert("IsTelugu", qMakePair(0x0C00, 0x0C7F)); - categoriesRangeMap.insert("IsKannada", qMakePair(0x0C80, 0x0CFF)); - categoriesRangeMap.insert("IsMalayalam", qMakePair(0x0D00, 0x0D7F)); - categoriesRangeMap.insert("IsSinhala", qMakePair(0x0D80, 0x0DFF)); - categoriesRangeMap.insert("IsThai", qMakePair(0x0E00, 0x0E7F)); - categoriesRangeMap.insert("IsLao", qMakePair(0x0E80, 0x0EFF)); - categoriesRangeMap.insert("IsTibetan", qMakePair(0x0F00, 0x0FFF)); - categoriesRangeMap.insert("IsMyanmar", qMakePair(0x1000, 0x109F)); - categoriesRangeMap.insert("IsGeorgian", qMakePair(0x10A0, 0x10FF)); - categoriesRangeMap.insert("IsHangulJamo", qMakePair(0x1100, 0x11FF)); - categoriesRangeMap.insert("IsEthiopic", qMakePair(0x1200, 0x137F)); - categoriesRangeMap.insert("IsEthiopicSupplement", qMakePair(0x1380, 0x139F)); - categoriesRangeMap.insert("IsCherokee", qMakePair(0x13A0, 0x13FF)); - categoriesRangeMap.insert("IsUnifiedCanadianAboriginalSyllabics", qMakePair(0x1400, 0x167F)); - categoriesRangeMap.insert("IsOgham", qMakePair(0x1680, 0x169F)); - categoriesRangeMap.insert("IsRunic", qMakePair(0x16A0, 0x16FF)); - categoriesRangeMap.insert("IsTagalog", qMakePair(0x1700, 0x171F)); - categoriesRangeMap.insert("IsHanunoo", qMakePair(0x1720, 0x173F)); - categoriesRangeMap.insert("IsBuhid", qMakePair(0x1740, 0x175F)); - categoriesRangeMap.insert("IsTagbanwa", qMakePair(0x1760, 0x177F)); - categoriesRangeMap.insert("IsKhmer", qMakePair(0x1780, 0x17FF)); - categoriesRangeMap.insert("IsMongolian", qMakePair(0x1800, 0x18AF)); - categoriesRangeMap.insert("IsLimbu", qMakePair(0x1900, 0x194F)); - categoriesRangeMap.insert("IsTaiLe", qMakePair(0x1950, 0x197F)); - categoriesRangeMap.insert("IsNewTaiLue", qMakePair(0x1980, 0x19DF)); - categoriesRangeMap.insert("IsKhmerSymbols", qMakePair(0x19E0, 0x19FF)); - categoriesRangeMap.insert("IsBuginese", qMakePair(0x1A00, 0x1A1F)); - categoriesRangeMap.insert("IsPhoneticExtensions", qMakePair(0x1D00, 0x1D7F)); - categoriesRangeMap.insert("IsPhoneticExtensionsSupplement", qMakePair(0x1D80, 0x1DBF)); - categoriesRangeMap.insert("IsCombiningDiacriticalMarksSupplement", qMakePair(0x1DC0, 0x1DFF)); - categoriesRangeMap.insert("IsLatinExtendedAdditional", qMakePair(0x1E00, 0x1EFF)); - categoriesRangeMap.insert("IsGreekExtended", qMakePair(0x1F00, 0x1FFF)); - categoriesRangeMap.insert("IsGeneralPunctuation", qMakePair(0x2000, 0x206F)); - categoriesRangeMap.insert("IsSuperscriptsandSubscripts", qMakePair(0x2070, 0x209F)); - categoriesRangeMap.insert("IsCurrencySymbols", qMakePair(0x20A0, 0x20CF)); - categoriesRangeMap.insert("IsCombiningMarksforSymbols", qMakePair(0x20D0, 0x20FF)); - categoriesRangeMap.insert("IsLetterlikeSymbols", qMakePair(0x2100, 0x214F)); - categoriesRangeMap.insert("IsNumberForms", qMakePair(0x2150, 0x218F)); - categoriesRangeMap.insert("IsArrows", qMakePair(0x2190, 0x21FF)); - categoriesRangeMap.insert("IsMathematicalOperators", qMakePair(0x2200, 0x22FF)); - categoriesRangeMap.insert("IsMiscellaneousTechnical", qMakePair(0x2300, 0x23FF)); - categoriesRangeMap.insert("IsControlPictures", qMakePair(0x2400, 0x243F)); - categoriesRangeMap.insert("IsOpticalCharacterRecognition", qMakePair(0x2440, 0x245F)); - categoriesRangeMap.insert("IsEnclosedAlphanumerics", qMakePair(0x2460, 0x24FF)); - categoriesRangeMap.insert("IsBoxDrawing", qMakePair(0x2500, 0x257F)); - categoriesRangeMap.insert("IsBlockElements", qMakePair(0x2580, 0x259F)); - categoriesRangeMap.insert("IsGeometricShapes", qMakePair(0x25A0, 0x25FF)); - categoriesRangeMap.insert("IsMiscellaneousSymbols", qMakePair(0x2600, 0x26FF)); - categoriesRangeMap.insert("IsDingbats", qMakePair(0x2700, 0x27BF)); - categoriesRangeMap.insert("IsMiscellaneousMathematicalSymbols-A", qMakePair(0x27C0, 0x27EF)); - categoriesRangeMap.insert("IsSupplementalArrows-A", qMakePair(0x27F0, 0x27FF)); - categoriesRangeMap.insert("IsBraillePatterns", qMakePair(0x2800, 0x28FF)); - categoriesRangeMap.insert("IsSupplementalArrows-B", qMakePair(0x2900, 0x297F)); - categoriesRangeMap.insert("IsMiscellaneousMathematicalSymbols-B", qMakePair(0x2980, 0x29FF)); - categoriesRangeMap.insert("IsSupplementalMathematicalOperators", qMakePair(0x2A00, 0x2AFF)); - categoriesRangeMap.insert("IsMiscellaneousSymbolsandArrows", qMakePair(0x2B00, 0x2BFF)); - categoriesRangeMap.insert("IsGlagolitic", qMakePair(0x2C00, 0x2C5F)); - categoriesRangeMap.insert("IsCoptic", qMakePair(0x2C80, 0x2CFF)); - categoriesRangeMap.insert("IsGeorgianSupplement", qMakePair(0x2D00, 0x2D2F)); - categoriesRangeMap.insert("IsTifinagh", qMakePair(0x2D30, 0x2D7F)); - categoriesRangeMap.insert("IsEthiopicExtended", qMakePair(0x2D80, 0x2DDF)); - categoriesRangeMap.insert("IsSupplementalPunctuation", qMakePair(0x2E00, 0x2E7F)); - categoriesRangeMap.insert("IsCJKRadicalsSupplement", qMakePair(0x2E80, 0x2EFF)); - categoriesRangeMap.insert("IsKangxiRadicals", qMakePair(0x2F00, 0x2FDF)); - categoriesRangeMap.insert("IsIdeographicDescriptionCharacters", qMakePair(0x2FF0, 0x2FFF)); - categoriesRangeMap.insert("IsCJKSymbolsandPunctuation", qMakePair(0x3000, 0x303F)); - categoriesRangeMap.insert("IsHiragana", qMakePair(0x3040, 0x309F)); - categoriesRangeMap.insert("IsKatakana", qMakePair(0x30A0, 0x30FF)); - categoriesRangeMap.insert("IsBopomofo", qMakePair(0x3100, 0x312F)); - categoriesRangeMap.insert("IsHangulCompatibilityJamo", qMakePair(0x3130, 0x318F)); - categoriesRangeMap.insert("IsKanbun", qMakePair(0x3190, 0x319F)); - categoriesRangeMap.insert("IsBopomofoExtended", qMakePair(0x31A0, 0x31BF)); - categoriesRangeMap.insert("IsCJKStrokes", qMakePair(0x31C0, 0x31EF)); - categoriesRangeMap.insert("IsKatakanaPhoneticExtensions", qMakePair(0x31F0, 0x31FF)); - categoriesRangeMap.insert("IsEnclosedCJKLettersandMonths", qMakePair(0x3200, 0x32FF)); - categoriesRangeMap.insert("IsCJKCompatibility", qMakePair(0x3300, 0x33FF)); - categoriesRangeMap.insert("IsCJKUnifiedIdeographsExtensionA", qMakePair(0x3400, 0x4DB5)); - categoriesRangeMap.insert("IsYijingHexagramSymbols", qMakePair(0x4DC0, 0x4DFF)); - categoriesRangeMap.insert("IsCJKUnifiedIdeographs", qMakePair(0x4E00, 0x9FFF)); - categoriesRangeMap.insert("IsYiSyllables", qMakePair(0xA000, 0xA48F)); - categoriesRangeMap.insert("IsYiRadicals", qMakePair(0xA490, 0xA4CF)); - categoriesRangeMap.insert("IsModifierToneLetters", qMakePair(0xA700, 0xA71F)); - categoriesRangeMap.insert("IsSylotiNagri", qMakePair(0xA800, 0xA82F)); - categoriesRangeMap.insert("IsHangulSyllables", qMakePair(0xAC00, 0xD7A3)); - categoriesRangeMap.insert("IsPrivateUse", qMakePair(0xE000, 0xF8FF)); - categoriesRangeMap.insert("IsCJKCompatibilityIdeographs", qMakePair(0xF900, 0xFAFF)); - categoriesRangeMap.insert("IsAlphabeticPresentationForms", qMakePair(0xFB00, 0xFB4F)); - categoriesRangeMap.insert("IsArabicPresentationForms-A", qMakePair(0xFB50, 0xFDFF)); - categoriesRangeMap.insert("IsVariationSelectors", qMakePair(0xFE00, 0xFE0F)); - categoriesRangeMap.insert("IsVerticalForms", qMakePair(0xFE10, 0xFE1F)); - categoriesRangeMap.insert("IsCombiningHalfMarks", qMakePair(0xFE20, 0xFE2F)); - categoriesRangeMap.insert("IsCJKCompatibilityForms", qMakePair(0xFE30, 0xFE4F)); - categoriesRangeMap.insert("IsSmallFormVariants", qMakePair(0xFE50, 0xFE6F)); - categoriesRangeMap.insert("IsArabicPresentationForms-B", qMakePair(0xFE70, 0xFEFF)); - categoriesRangeMap.insert("IsHalfwidthandFullwidthForms", qMakePair(0xFF00, 0xFFEF)); - categoriesRangeMap.insert("IsSpecials", qMakePair(0xFFF0, 0xFFFF)); - categoriesRangeMap.insert("IsLinearBSyllabary", qMakePair(0x10000, 0x1007F)); - categoriesRangeMap.insert("IsLinearBIdeograms", qMakePair(0x10080, 0x100FF)); - categoriesRangeMap.insert("IsAegeanNumbers", qMakePair(0x10100, 0x1013F)); - categoriesRangeMap.insert("IsAncientGreekNumbers", qMakePair(0x10140, 0x1018F)); - categoriesRangeMap.insert("IsOldItalic", qMakePair(0x10300, 0x1032F)); - categoriesRangeMap.insert("IsGothic", qMakePair(0x10330, 0x1034F)); - categoriesRangeMap.insert("IsUgaritic", qMakePair(0x10380, 0x1039F)); - categoriesRangeMap.insert("IsOldPersian", qMakePair(0x103A0, 0x103DF)); - categoriesRangeMap.insert("IsDeseret", qMakePair(0x10400, 0x1044F)); - categoriesRangeMap.insert("IsShavian", qMakePair(0x10450, 0x1047F)); - categoriesRangeMap.insert("IsOsmanya", qMakePair(0x10480, 0x104AF)); - categoriesRangeMap.insert("IsCypriotSyllabary", qMakePair(0x10800, 0x1083F)); - categoriesRangeMap.insert("IsKharoshthi", qMakePair(0x10A00, 0x10A5F)); - categoriesRangeMap.insert("IsByzantineMusicalSymbols", qMakePair(0x1D000, 0x1D0FF)); - categoriesRangeMap.insert("IsMusicalSymbols", qMakePair(0x1D100, 0x1D1FF)); - categoriesRangeMap.insert("IsAncientGreekMusicalNotation", qMakePair(0x1D200, 0x1D24F)); - categoriesRangeMap.insert("IsTaiXuanJingSymbols", qMakePair(0x1D300, 0x1D35F)); - categoriesRangeMap.insert("IsMathematicalAlphanumericSymbols", qMakePair(0x1D400, 0x1D7FF)); - categoriesRangeMap.insert("IsCJKUnifiedIdeographsExtensionB", qMakePair(0x20000, 0x2A6DF)); - categoriesRangeMap.insert("IsCJKCompatibilityIdeographsSupplement", qMakePair(0x2F800, 0x2FA1F)); - categoriesRangeMap.insert("IsTags", qMakePair(0xE0000, 0xE007F)); - categoriesRangeMap.insert("IsVariationSelectorsSupplement", qMakePair(0xE0100, 0xE01EF)); - categoriesRangeMap.insert("IsSupplementaryPrivateUseArea-A", qMakePair(0xF0000, 0xFFFFF)); - categoriesRangeMap.insert("IsSupplementaryPrivateUseArea-B", qMakePair(0x100000, 0x10FFFF)); -} -#endif +// fast lookup hash for xml schema extensions +// sorted by name for b-search +static const struct CategoriesRangeMapEntry { + const char name[40]; + uint first, second; +} categoriesRangeMap[] = { + { "AegeanNumbers", 0x10100, 0x1013F }, + { "AlphabeticPresentationForms", 0xFB00, 0xFB4F }, + { "AncientGreekMusicalNotation", 0x1D200, 0x1D24F }, + { "AncientGreekNumbers", 0x10140, 0x1018F }, + { "Arabic", 0x0600, 0x06FF }, + { "ArabicPresentationForms-A", 0xFB50, 0xFDFF }, + { "ArabicPresentationForms-B", 0xFE70, 0xFEFF }, + { "ArabicSupplement", 0x0750, 0x077F }, + { "Armenian", 0x0530, 0x058F }, + { "Arrows", 0x2190, 0x21FF }, + { "BasicLatin", 0x0000, 0x007F }, + { "Bengali", 0x0980, 0x09FF }, + { "BlockElements", 0x2580, 0x259F }, + { "Bopomofo", 0x3100, 0x312F }, + { "BopomofoExtended", 0x31A0, 0x31BF }, + { "BoxDrawing", 0x2500, 0x257F }, + { "BraillePatterns", 0x2800, 0x28FF }, + { "Buginese", 0x1A00, 0x1A1F }, + { "Buhid", 0x1740, 0x175F }, + { "ByzantineMusicalSymbols", 0x1D000, 0x1D0FF }, + { "CJKCompatibility", 0x3300, 0x33FF }, + { "CJKCompatibilityForms", 0xFE30, 0xFE4F }, + { "CJKCompatibilityIdeographs", 0xF900, 0xFAFF }, + { "CJKCompatibilityIdeographsSupplement", 0x2F800, 0x2FA1F }, + { "CJKRadicalsSupplement", 0x2E80, 0x2EFF }, + { "CJKStrokes", 0x31C0, 0x31EF }, + { "CJKSymbolsandPunctuation", 0x3000, 0x303F }, + { "CJKUnifiedIdeographs", 0x4E00, 0x9FFF }, + { "CJKUnifiedIdeographsExtensionA", 0x3400, 0x4DB5 }, + { "CJKUnifiedIdeographsExtensionB", 0x20000, 0x2A6DF }, + { "Cherokee", 0x13A0, 0x13FF }, + { "CombiningDiacriticalMarks", 0x0300, 0x036F }, + { "CombiningDiacriticalMarksSupplement", 0x1DC0, 0x1DFF }, + { "CombiningHalfMarks", 0xFE20, 0xFE2F }, + { "CombiningMarksforSymbols", 0x20D0, 0x20FF }, + { "ControlPictures", 0x2400, 0x243F }, + { "Coptic", 0x2C80, 0x2CFF }, + { "CurrencySymbols", 0x20A0, 0x20CF }, + { "CypriotSyllabary", 0x10800, 0x1083F }, + { "Cyrillic", 0x0400, 0x04FF }, + { "CyrillicSupplement", 0x0500, 0x052F }, + { "Deseret", 0x10400, 0x1044F }, + { "Devanagari", 0x0900, 0x097F }, + { "Dingbats", 0x2700, 0x27BF }, + { "EnclosedAlphanumerics", 0x2460, 0x24FF }, + { "EnclosedCJKLettersandMonths", 0x3200, 0x32FF }, + { "Ethiopic", 0x1200, 0x137F }, + { "EthiopicExtended", 0x2D80, 0x2DDF }, + { "EthiopicSupplement", 0x1380, 0x139F }, + { "GeneralPunctuation", 0x2000, 0x206F }, + { "GeometricShapes", 0x25A0, 0x25FF }, + { "Georgian", 0x10A0, 0x10FF }, + { "GeorgianSupplement", 0x2D00, 0x2D2F }, + { "Glagolitic", 0x2C00, 0x2C5F }, + { "Gothic", 0x10330, 0x1034F }, + { "Greek", 0x0370, 0x03FF }, + { "GreekExtended", 0x1F00, 0x1FFF }, + { "Gujarati", 0x0A80, 0x0AFF }, + { "Gurmukhi", 0x0A00, 0x0A7F }, + { "HalfwidthandFullwidthForms", 0xFF00, 0xFFEF }, + { "HangulCompatibilityJamo", 0x3130, 0x318F }, + { "HangulJamo", 0x1100, 0x11FF }, + { "HangulSyllables", 0xAC00, 0xD7A3 }, + { "Hanunoo", 0x1720, 0x173F }, + { "Hebrew", 0x0590, 0x05FF }, + { "Hiragana", 0x3040, 0x309F }, + { "IPAExtensions", 0x0250, 0x02AF }, + { "IdeographicDescriptionCharacters", 0x2FF0, 0x2FFF }, + { "Kanbun", 0x3190, 0x319F }, + { "KangxiRadicals", 0x2F00, 0x2FDF }, + { "Kannada", 0x0C80, 0x0CFF }, + { "Katakana", 0x30A0, 0x30FF }, + { "KatakanaPhoneticExtensions", 0x31F0, 0x31FF }, + { "Kharoshthi", 0x10A00, 0x10A5F }, + { "Khmer", 0x1780, 0x17FF }, + { "KhmerSymbols", 0x19E0, 0x19FF }, + { "Lao", 0x0E80, 0x0EFF }, + { "Latin-1Supplement", 0x0080, 0x00FF }, + { "LatinExtended-A", 0x0100, 0x017F }, + { "LatinExtended-B", 0x0180, 0x024F }, + { "LatinExtendedAdditional", 0x1E00, 0x1EFF }, + { "LetterlikeSymbols", 0x2100, 0x214F }, + { "Limbu", 0x1900, 0x194F }, + { "LinearBIdeograms", 0x10080, 0x100FF }, + { "LinearBSyllabary", 0x10000, 0x1007F }, + { "Malayalam", 0x0D00, 0x0D7F }, + { "MathematicalAlphanumericSymbols", 0x1D400, 0x1D7FF }, + { "MathematicalOperators", 0x2200, 0x22FF }, + { "MiscellaneousMathematicalSymbols-A", 0x27C0, 0x27EF }, + { "MiscellaneousMathematicalSymbols-B", 0x2980, 0x29FF }, + { "MiscellaneousSymbols", 0x2600, 0x26FF }, + { "MiscellaneousSymbolsandArrows", 0x2B00, 0x2BFF }, + { "MiscellaneousTechnical", 0x2300, 0x23FF }, + { "ModifierToneLetters", 0xA700, 0xA71F }, + { "Mongolian", 0x1800, 0x18AF }, + { "MusicalSymbols", 0x1D100, 0x1D1FF }, + { "Myanmar", 0x1000, 0x109F }, + { "NewTaiLue", 0x1980, 0x19DF }, + { "NumberForms", 0x2150, 0x218F }, + { "Ogham", 0x1680, 0x169F }, + { "OldItalic", 0x10300, 0x1032F }, + { "OldPersian", 0x103A0, 0x103DF }, + { "OpticalCharacterRecognition", 0x2440, 0x245F }, + { "Oriya", 0x0B00, 0x0B7F }, + { "Osmanya", 0x10480, 0x104AF }, + { "PhoneticExtensions", 0x1D00, 0x1D7F }, + { "PhoneticExtensionsSupplement", 0x1D80, 0x1DBF }, + { "PrivateUse", 0xE000, 0xF8FF }, + { "Runic", 0x16A0, 0x16FF }, + { "Shavian", 0x10450, 0x1047F }, + { "Sinhala", 0x0D80, 0x0DFF }, + { "SmallFormVariants", 0xFE50, 0xFE6F }, + { "SpacingModifierLetters", 0x02B0, 0x02FF }, + { "Specials", 0xFFF0, 0xFFFF }, + { "SuperscriptsandSubscripts", 0x2070, 0x209F }, + { "SupplementalArrows-A", 0x27F0, 0x27FF }, + { "SupplementalArrows-B", 0x2900, 0x297F }, + { "SupplementalMathematicalOperators", 0x2A00, 0x2AFF }, + { "SupplementalPunctuation", 0x2E00, 0x2E7F }, + { "SupplementaryPrivateUseArea-A", 0xF0000, 0xFFFFF }, + { "SupplementaryPrivateUseArea-B", 0x100000, 0x10FFFF }, + { "SylotiNagri", 0xA800, 0xA82F }, + { "Syriac", 0x0700, 0x074F }, + { "Tagalog", 0x1700, 0x171F }, + { "Tagbanwa", 0x1760, 0x177F }, + { "Tags", 0xE0000, 0xE007F }, + { "TaiLe", 0x1950, 0x197F }, + { "TaiXuanJingSymbols", 0x1D300, 0x1D35F }, + { "Tamil", 0x0B80, 0x0BFF }, + { "Telugu", 0x0C00, 0x0C7F }, + { "Thaana", 0x0780, 0x07BF }, + { "Thai", 0x0E00, 0x0E7F }, + { "Tibetan", 0x0F00, 0x0FFF }, + { "Tifinagh", 0x2D30, 0x2D7F }, + { "Ugaritic", 0x10380, 0x1039F }, + { "UnifiedCanadianAboriginalSyllabics", 0x1400, 0x167F }, + { "VariationSelectors", 0xFE00, 0xFE0F }, + { "VariationSelectorsSupplement", 0xE0100, 0xE01EF }, + { "VerticalForms", 0xFE10, 0xFE1F }, + { "YiRadicals", 0xA490, 0xA4CF }, + { "YiSyllables", 0xA000, 0xA48F }, + { "YijingHexagramSymbols", 0x4DC0, 0x4DFF } +}; + +inline bool operator<(const char *name, const CategoriesRangeMapEntry &entry) +{ return qstrcmp(name, entry.name) < 0; } +inline bool operator<(const CategoriesRangeMapEntry &entry, const char *name) +{ return qstrcmp(entry.name, name) < 0; } +#endif // QT_NO_REGEXP_CCLASS int QRegExpEngine::getChar() { @@ -3231,15 +3233,12 @@ int QRegExpEngine::getEscape() break; } } else if (catlen > 2 && category.at(0) == 'I' && category.at(1) == 's') { - if (categoriesRangeMap.isEmpty()) - setupCategoriesRangeMap(); - - if (categoriesRangeMap.contains(category)) { - const QPair range = categoriesRangeMap.value(category); - yyCharClass->addRange(range.first, range.second); - } else { + static const int N = sizeof(categoriesRangeMap) / sizeof(categoriesRangeMap[0]); + const CategoriesRangeMapEntry *r = qBinaryFind(categoriesRangeMap, categoriesRangeMap + N, category.constData() + 2); + if (r != categoriesRangeMap + N) + yyCharClass->addRange(r->first, r->second); + else error(RXERR_CATEGORY); - } } else { error(RXERR_CATEGORY); } From 22011ece4c48ddd7887d7527d558dfb95fd9ceb7 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 26 Aug 2011 08:07:20 +0200 Subject: [PATCH 14/43] Fix crash when fallback font is not #0 in multi font engine Easily reproducible by testing Chinese with the threaded renderer. The multi engine would then have a list of engines with a single item, but the glyphs might belong to e.g. engine 11. In that case, engine() would assert when it couldn't find the engine if the layout had been done in a different thread. We force the loading of the required engine if it's not already loaded. Note that this fix does not work on Mac, as loadEngine() will crash there, so the layout has to be done in the same thread as the rendering, since loading the engines is part of the layout process. Task-number: QTBUG-21112 Change-Id: I71cc396664e3b95fbb4815a90873457e1f89528e Reviewed-on: http://codereview.qt.nokia.com/3631 Reviewed-by: Qt Sanity Bot Reviewed-by: Jiang Jiang --- src/gui/text/qfontengine_p.h | 5 +++++ src/gui/text/qtextlayout.cpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/gui/text/qfontengine_p.h b/src/gui/text/qfontengine_p.h index 5f779e155a7..e9a8d6f6077 100644 --- a/src/gui/text/qfontengine_p.h +++ b/src/gui/text/qfontengine_p.h @@ -434,6 +434,11 @@ public: QFontEngine *engine(int at) const {Q_ASSERT(at < engines.size()); return engines.at(at); } + inline void ensureEngineAt(int at) + { + if (at >= engines.size() || engines.at(at) == 0) + loadEngine(at); + } protected: friend class QPSPrintEnginePrivate; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 8c5e63da54c..d253c02052f 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2305,6 +2305,7 @@ QList QTextLine::glyphRuns(int from, int length) const continue; QGlyphLayout subLayout = glyphLayout.mid(start, end - start); + multiFontEngine->ensureEngineAt(which); glyphRuns.append(glyphRunWithInfo(multiFontEngine->engine(which), subLayout, pos, flags, x, width)); for (int i = 0; i < subLayout.numGlyphs; i++) { @@ -2317,6 +2318,7 @@ QList QTextLine::glyphRuns(int from, int length) const } QGlyphLayout subLayout = glyphLayout.mid(start, end - start); + multiFontEngine->ensureEngineAt(which); QGlyphRun glyphRun = glyphRunWithInfo(multiFontEngine->engine(which), subLayout, pos, flags, x, width); if (!glyphRun.isEmpty()) From 8412020740e0d1669f32c9d66b500874d975a015 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Fri, 26 Aug 2011 10:33:20 +0200 Subject: [PATCH 15/43] Check if bridge plugin vector is still valid. Q_GLOBAL_STATIC may be destroyed and we still send ObjectDestroyed notifications. This only shows now that we actually send the Destroyed notifications. Change-Id: I3057556cdc897dab6adfc3274e4abc68473ffa7f Reviewed-on: http://codereview.qt.nokia.com/3657 Reviewed-by: Qt Sanity Bot Reviewed-by: Gabriel de Dietrich --- src/gui/accessible/qaccessible_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/accessible/qaccessible_unix.cpp b/src/gui/accessible/qaccessible_unix.cpp index 19fbe783011..1c1eb2ad058 100644 --- a/src/gui/accessible/qaccessible_unix.cpp +++ b/src/gui/accessible/qaccessible_unix.cpp @@ -96,7 +96,7 @@ void QAccessible::updateAccessibility(QObject *o, int who, Event reason) } initialize(); - if (bridges()->isEmpty()) + if (!bridges() || bridges()->isEmpty()) return; QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(o); From eeffba2e55707912599b1258c8fda1684c7ef53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Mon, 13 Jun 2011 00:31:38 +0200 Subject: [PATCH 16/43] Incorrect property name in QAccessibleAbstractSpinBox::setCurrentValue Merge-request: 1263 Reviewed-by: Frederik Gladhorn (cherry picked from commit 031958c130904c16a4bafa5617aaa197469efa9e) Change-Id: I0639f90271b80392e9bcf7f0e4ddaf0f3cd6b478 Reviewed-on: http://codereview.qt.nokia.com/3039 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/rangecontrols.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/rangecontrols.cpp b/src/plugins/accessible/widgets/rangecontrols.cpp index 8868d53dc7c..485983ef12a 100644 --- a/src/plugins/accessible/widgets/rangecontrols.cpp +++ b/src/plugins/accessible/widgets/rangecontrols.cpp @@ -212,7 +212,7 @@ QVariant QAccessibleAbstractSpinBox::currentValue() void QAccessibleAbstractSpinBox::setCurrentValue(const QVariant &value) { - abstractSpinBox()->setProperty("setValue", value); + abstractSpinBox()->setProperty("value", value); } QVariant QAccessibleAbstractSpinBox::maximumValue() From 420c4edb8aa8317afef864353a6fb5353d00ad60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Thu, 14 Jul 2011 14:25:57 +0200 Subject: [PATCH 17/43] Call QAccessible::updateAccessibility when setText is called on QLabel The method is called when the text of a label is changed and setAccessibleName has not been called on the label, as the text of the label acts as the accessible name of the label. Merge-request: 1301 Reviewed-by: Frederik Gladhorn (cherry picked from commit a1f2b68e97477440cf508e6d497eb5f5d9971971) Change-Id: Ic10f75e72ac3faa84777c444177b287b720a1dc2 Reviewed-on: http://codereview.qt.nokia.com/3040 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/gui/widgets/qlabel.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp index 7a94f421254..ab88f38bbb9 100644 --- a/src/gui/widgets/qlabel.cpp +++ b/src/gui/widgets/qlabel.cpp @@ -55,6 +55,10 @@ #include "private/qstylesheetstyle_p.h" #include +#ifndef QT_NO_ACCESSIBILITY +#include +#endif + QT_BEGIN_NAMESPACE /*! @@ -377,6 +381,11 @@ void QLabel::setText(const QString &text) #endif d->updateLabel(); + +#ifndef QT_NO_ACCESSIBILITY + if (accessibleName().isEmpty()) + QAccessible::updateAccessibility(this, 0, QAccessible::NameChanged); +#endif } QString QLabel::text() const From 5dd208b1f4e1780acf06e58291103adab0117f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Fri, 29 Jul 2011 10:35:54 -0700 Subject: [PATCH 18/43] Call QAccessible::updateAccessibility when a widget is deleted Merge-request: 1310 Reviewed-by: Frederik Gladhorn (cherry picked from commit df3f763920b1450733817596148e087d11c0c543) Change-Id: I74fb08104c5dc527f9e9ac88776e4aa2623a3385 Reviewed-on: http://codereview.qt.nokia.com/3041 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/gui/kernel/qwidget.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 231fc261d7a..8bfd078448b 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1680,6 +1680,10 @@ QWidget::~QWidget() if (!d->children.isEmpty()) d->deleteChildren(); +#ifndef QT_NOACCESSIBILITY + QAccessible::updateAccessibility(this, 0, QAccessible::ObjectDestroyed); +#endif + QApplication::removePostedEvents(this); QT_TRY { From 3cdc2ea183c68640b4883ddfa2bbea8e24c5106b Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Fri, 29 Jul 2011 14:43:01 -0700 Subject: [PATCH 19/43] Fix typo for ifdef QT_NO_ACCESSIBILITY Reviewed-by: TrustMe (cherry picked from commit eaf3b5ff76e4866ef3597110c6e565305c3298ad) Change-Id: I21df13a24fc5d339c5fcbf38f151c0339e1c87a9 Reviewed-on: http://codereview.qt.nokia.com/3042 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/gui/kernel/qwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 8bfd078448b..72ff5e9df2c 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -1680,7 +1680,7 @@ QWidget::~QWidget() if (!d->children.isEmpty()) d->deleteChildren(); -#ifndef QT_NOACCESSIBILITY +#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(this, 0, QAccessible::ObjectDestroyed); #endif From 14c2d4700cf62e8f0a58f206525ab651aad8464c Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 23 Aug 2011 15:56:33 +1000 Subject: [PATCH 20/43] Remove obsolete testlib files from .gitignore Change-Id: I8d0ff9cad1da7df3e5e0d18e8f19b17b468afc01 Reviewed-on: http://codereview.qt.nokia.com/3368 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 47bd28227dc..5199d726b9e 100644 --- a/.gitignore +++ b/.gitignore @@ -112,8 +112,6 @@ tests/auto/qprocess/fileWriterProcess.txt .com.apple.timemachine.supported tests/auto/qlibrary/libmylib.so* tests/auto/qresourceengine/runtime_resource.rcc -tools/qtestlib/chart/chart* -tools/qtestlib/updater/updater* tools/activeqt/testcon/testcon.tlb translations/*.qm translations/*_untranslated.ts From 865c27460e9779e7e4cafea84db843c3c5b26765 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 17:14:21 +1000 Subject: [PATCH 21/43] Remove circular dependency in testlib logging code Pass the output file name from the QTestLog to the test logger when commencing logging rather than having the logger call back into the QTestLog. Change-Id: Id484635f9fcfca08a66c92f3442887e9473b6f9b Reviewed-on: http://codereview.qt.nokia.com/3454 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qabstracttestlogger.cpp | 12 +++++------- src/testlib/qabstracttestlogger_p.h | 2 +- src/testlib/qplaintestlogger.cpp | 4 ++-- src/testlib/qplaintestlogger_p.h | 2 +- src/testlib/qtestlog.cpp | 4 ++-- src/testlib/qtestlogger.cpp | 4 ++-- src/testlib/qtestlogger_p.h | 2 +- src/testlib/qxmltestlogger.cpp | 4 ++-- src/testlib/qxmltestlogger_p.h | 2 +- 9 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index 735ad0122a5..1e95471e709 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "QtTest/private/qabstracttestlogger_p.h" -#include "QtTest/private/qtestlog_p.h" #include "QtTest/qtestassert.h" #include "QtCore/qbytearray.h" @@ -81,22 +80,21 @@ bool QAbstractTestLogger::isTtyOutput() } -void QAbstractTestLogger::startLogging() +void QAbstractTestLogger::startLogging(const char *filename) { QTEST_ASSERT(!QTest::stream); - const char *out = QTestLog::outputFileName(); - if (!out) { + if (!filename) { QTest::stream = stdout; return; } #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, out, "wt")) { + if (::fopen_s(&QTest::stream, filename, "wt")) { #else - QTest::stream = ::fopen(out, "wt"); + QTest::stream = ::fopen(filename, "wt"); if (!QTest::stream) { #endif - printf("Unable to open file for logging: %s", out); + printf("Unable to open file for logging: %s", filename); ::exit(1); } } diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 847c14453ac..20b212a3b83 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -82,7 +82,7 @@ public: QAbstractTestLogger() {} virtual ~QAbstractTestLogger() {} - virtual void startLogging(); + virtual void startLogging(const char *filename); virtual void stopLogging(); virtual void enterTestFunction(const char *function) = 0; diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 5656ac60c50..daa44052ee4 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -407,9 +407,9 @@ QPlainTestLogger::~QPlainTestLogger() #endif } -void QPlainTestLogger::startLogging() +void QPlainTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); char buf[1024]; if (QTestLog::verboseLevel() < 0) { diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index aa9df834eb2..1784e3be777 100644 --- a/src/testlib/qplaintestlogger_p.h +++ b/src/testlib/qplaintestlogger_p.h @@ -63,7 +63,7 @@ public: QPlainTestLogger(); ~QPlainTestLogger(); - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 8a2d5596f31..a438da2746b 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -296,7 +296,7 @@ void QTestLog::startLogging(unsigned int randomSeed) QTEST_ASSERT(!QTest::testLogger); QTest::initLogger(); QTest::testLogger->registerRandomSeed(randomSeed); - QTest::testLogger->startLogging(); + QTest::testLogger->startLogging(QTest::outFile); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } @@ -304,7 +304,7 @@ void QTestLog::startLogging() { QTEST_ASSERT(!QTest::testLogger); QTest::initLogger(); - QTest::testLogger->startLogging(); + QTest::testLogger->startLogging(QTest::outFile); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 316e89fb551..9cf43209516 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -78,9 +78,9 @@ QTestLogger::~QTestLogger() delete filelogger; } -void QTestLogger::startLogging() +void QTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); switch(format){ case TLF_LightXml:{ diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 1d27b63e212..5793537e788 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -74,7 +74,7 @@ class QTestLogger : public QAbstractTestLogger TLF_XunitXml = 2 }; - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index 2c8ba6c0a70..15b5c84fd5e 100644 --- a/src/testlib/qxmltestlogger.cpp +++ b/src/testlib/qxmltestlogger.cpp @@ -102,9 +102,9 @@ QXmlTestLogger::~QXmlTestLogger() { } -void QXmlTestLogger::startLogging() +void QXmlTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); QTestCharBuffer buf; if (xmlmode == QXmlTestLogger::Complete) { diff --git a/src/testlib/qxmltestlogger_p.h b/src/testlib/qxmltestlogger_p.h index dc2f4b8aa1b..ad510d5ce0e 100644 --- a/src/testlib/qxmltestlogger_p.h +++ b/src/testlib/qxmltestlogger_p.h @@ -66,7 +66,7 @@ public: QXmlTestLogger(XmlMode mode = Complete); ~QXmlTestLogger(); - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); From dc7b2b8d9ca1d394d8338ce1c1f51eafac187908 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 11:39:34 +1000 Subject: [PATCH 22/43] Remove color logging feature from qtestlib. This feature was undocumented and only worked if a secret environment variable was set, the test output was going to a real console, and plain text test results were being generated. Including code in testlib for fancy presentation of test results conflicts with testlib's stated goal of being a lightweight framework where every feature contributes to finding bugs, so this feature is being removed. If fancy presentation of test output is required, it should be achieved by post-processing the test output outside of the test framework. Change-Id: I872165c4d2c3d2498c3aa039070ecf319e237ca1 Reviewed-on: http://codereview.qt.nokia.com/3432 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qabstracttestlogger.cpp | 13 ------ src/testlib/qabstracttestlogger_p.h | 1 - src/testlib/qplaintestlogger.cpp | 72 +++++------------------------ 3 files changed, 12 insertions(+), 74 deletions(-) diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index 1e95471e709..25193c9aeda 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -67,19 +67,6 @@ void QAbstractTestLogger::outputString(const char *msg) ::fflush(QTest::stream); } -bool QAbstractTestLogger::isTtyOutput() -{ - QTEST_ASSERT(QTest::stream); - -#if defined(Q_OS_WIN) || defined(Q_OS_INTEGRITY) - return true; -#else - static bool ttyoutput = isatty(fileno(QTest::stream)); - return ttyoutput; -#endif -} - - void QAbstractTestLogger::startLogging(const char *filename) { QTEST_ASSERT(!QTest::stream); diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 20b212a3b83..beba7e7e0a1 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -98,7 +98,6 @@ public: virtual void registerRandomSeed(unsigned int seed) = 0; static void outputString(const char *msg); - static bool isTtyOutput(); }; struct QTestCharBuffer diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index daa44052ee4..efb90d798a9 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -71,85 +71,46 @@ QT_BEGIN_NAMESPACE namespace QTest { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - static CRITICAL_SECTION outputCriticalSection; - static HANDLE hConsole = INVALID_HANDLE_VALUE; - static WORD consoleAttributes = 0; - - static const char *qWinColoredMsg(int prefix, int color, const char *msg) - { - if (!hConsole) - return msg; - - WORD attr = consoleAttributes & ~(FOREGROUND_GREEN | FOREGROUND_BLUE - | FOREGROUND_RED | FOREGROUND_INTENSITY); - if (prefix) - attr |= FOREGROUND_INTENSITY; - if (color == 32) - attr |= FOREGROUND_GREEN; - if (color == 36) - attr |= FOREGROUND_BLUE | FOREGROUND_GREEN; - if (color == 31) - attr |= FOREGROUND_RED | FOREGROUND_INTENSITY; - if (color == 37) - attr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - if (color == 33) - attr |= FOREGROUND_RED | FOREGROUND_GREEN; - SetConsoleTextAttribute(hConsole, attr); - printf(msg); - SetConsoleTextAttribute(hConsole, consoleAttributes); - return ""; - } - -# define COLORED_MSG(prefix, color, msg) colored ? qWinColoredMsg(prefix, color, msg) : msg -#else -# define COLORED_MSG(prefix, color, msg) colored && QAbstractTestLogger::isTtyOutput() ? "\033["#prefix";"#color"m" msg "\033[0m" : msg #endif static const char *incidentType2String(QAbstractTestLogger::IncidentTypes type) { - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); switch (type) { case QAbstractTestLogger::Pass: - return COLORED_MSG(0, 32, "PASS "); //green + return "PASS "; case QAbstractTestLogger::XFail: - return COLORED_MSG(1, 32, "XFAIL "); //light green + return "XFAIL "; case QAbstractTestLogger::Fail: - return COLORED_MSG(0, 31, "FAIL! "); //red + return "FAIL! "; case QAbstractTestLogger::XPass: - return COLORED_MSG(0, 31, "XPASS "); //red, too + return "XPASS "; } return "??????"; } static const char *benchmarkResult2String() { - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); - return COLORED_MSG(0, 36, "RESULT "); // cyan + return "RESULT "; } static const char *messageType2String(QAbstractTestLogger::MessageTypes type) { -#ifdef Q_OS_WIN - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); -#else - static bool colored = ::getenv("QTEST_COLORED"); -#endif switch (type) { case QAbstractTestLogger::Skip: - return COLORED_MSG(0, 37, "SKIP "); //white + return "SKIP "; case QAbstractTestLogger::Warn: - return COLORED_MSG(0, 33, "WARNING"); // yellow + return "WARNING"; case QAbstractTestLogger::QWarning: - return COLORED_MSG(1, 33, "QWARN "); + return "QWARN "; case QAbstractTestLogger::QDebug: - return COLORED_MSG(1, 33, "QDEBUG "); + return "QDEBUG "; case QAbstractTestLogger::QSystem: - return COLORED_MSG(1, 33, "QSYSTEM"); + return "QSYSTEM"; case QAbstractTestLogger::QFatal: - return COLORED_MSG(0, 31, "QFATAL "); // red + return "QFATAL "; case QAbstractTestLogger::Info: - return "INFO "; // no coloring + return "INFO "; } return "??????"; } @@ -388,15 +349,6 @@ QPlainTestLogger::QPlainTestLogger() { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) InitializeCriticalSection(&QTest::outputCriticalSection); - QTest::hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - if (QTest::hConsole != INVALID_HANDLE_VALUE) { - CONSOLE_SCREEN_BUFFER_INFO info; - if (GetConsoleScreenBufferInfo(QTest::hConsole, &info)) { - QTest::consoleAttributes = info.wAttributes; - } else { - QTest::hConsole = INVALID_HANDLE_VALUE; - } - } #endif } From e8e9b62f725f2229ae9e6d0218bbcbf7d54425ee Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 25 Aug 2011 18:20:19 +1000 Subject: [PATCH 23/43] Enable multiple instances of QAbstractTestLogger. Previously QAbstractTestLogger used a global variable for the file pointer to which it was writing test output. This effectively meant that only one instance of this or its derived classes could exist at any time. This commit moves the file pointer inside the class, so that multiple loggers can exist at the same time. This means that the outputString() method can no longer be static, which in turn means that several functions used by QPlainTestLogger need to move from the QTest namespace into the class, and also that QTestBasicStreamer must hold a non-const pointer to its associated logger instead of a const pointer. Task-number: QTBUG-20615 Change-Id: If941f1f9399cf20fb93e3e87f3390bceeca1cbfc Reviewed-on: http://codereview.qt.nokia.com/3576 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qabstracttestlogger.cpp | 29 ++- src/testlib/qabstracttestlogger_p.h | 8 +- src/testlib/qplaintestlogger.cpp | 294 ++++++++++++++-------------- src/testlib/qplaintestlogger_p.h | 4 + src/testlib/qtestbasicstreamer.cpp | 4 +- src/testlib/qtestbasicstreamer.h | 6 +- 6 files changed, 174 insertions(+), 171 deletions(-) diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index 25193c9aeda..a5651317e7b 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -54,32 +54,27 @@ QT_BEGIN_NAMESPACE -namespace QTest -{ - static FILE *stream = 0; -} - void QAbstractTestLogger::outputString(const char *msg) { - QTEST_ASSERT(QTest::stream); + QTEST_ASSERT(stream); - ::fputs(msg, QTest::stream); - ::fflush(QTest::stream); + ::fputs(msg, stream); + ::fflush(stream); } void QAbstractTestLogger::startLogging(const char *filename) { - QTEST_ASSERT(!QTest::stream); + QTEST_ASSERT(!stream); if (!filename) { - QTest::stream = stdout; + stream = stdout; return; } #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, filename, "wt")) { + if (::fopen_s(&stream, filename, "wt")) { #else - QTest::stream = ::fopen(filename, "wt"); - if (!QTest::stream) { + stream = ::fopen(filename, "wt"); + if (!stream) { #endif printf("Unable to open file for logging: %s", filename); ::exit(1); @@ -88,9 +83,9 @@ void QAbstractTestLogger::startLogging(const char *filename) void QAbstractTestLogger::stopLogging() { - QTEST_ASSERT(QTest::stream); - if (QTest::stream != stdout) { - fclose(QTest::stream); + QTEST_ASSERT(stream); + if (stream != stdout) { + fclose(stream); } else { #ifdef Q_OS_SYMBIAN // Convenience sleep for Symbian and TRK. Without this sleep depending on the timing the @@ -99,7 +94,7 @@ void QAbstractTestLogger::stopLogging() User::AfterHighRes(2*1000*1000); #endif } - QTest::stream = 0; + stream = 0; } namespace QTest diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index beba7e7e0a1..e592249e718 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -54,6 +54,7 @@ // #include +#include QT_BEGIN_NAMESPACE @@ -79,7 +80,7 @@ public: Info }; - QAbstractTestLogger() {} + QAbstractTestLogger() : stream(0) {} virtual ~QAbstractTestLogger() {} virtual void startLogging(const char *filename); @@ -97,7 +98,10 @@ public: virtual void registerRandomSeed(unsigned int seed) = 0; - static void outputString(const char *msg); + void outputString(const char *msg); + +private: + FILE *stream; }; struct QTestCharBuffer diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index efb90d798a9..44ec7924003 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -115,81 +115,6 @@ namespace QTest { return "??????"; } - static void outputMessage(const char *str) - { -#if defined(Q_OS_WINCE) - QString strUtf16 = QString::fromLatin1(str); - const int maxOutputLength = 255; - do { - QString tmp = strUtf16.left(maxOutputLength); - OutputDebugString((wchar_t*)tmp.utf16()); - strUtf16.remove(0, maxOutputLength); - } while (!strUtf16.isEmpty()); - if (QTestLog::outputFileName()) -#elif defined(Q_OS_WIN) - EnterCriticalSection(&outputCriticalSection); - // OutputDebugString is not threadsafe - OutputDebugStringA(str); - LeaveCriticalSection(&outputCriticalSection); -#elif defined(Q_OS_SYMBIAN) - // RDebug::Print has a cap of 256 characters so break it up - TPtrC8 ptr(reinterpret_cast(str)); - _LIT(format, "[QTestLib] %S"); - const int maxBlockSize = 256 - ((const TDesC &)format).Length(); - HBufC* hbuffer = HBufC::New(maxBlockSize); - if(hbuffer) { - for (int i = 0; i < ptr.Length(); i += maxBlockSize) { - int size = Min(maxBlockSize, ptr.Length() - i); - hbuffer->Des().Copy(ptr.Mid(i, size)); - RDebug::Print(format, hbuffer); - } - delete hbuffer; - } - else { - // fast, no allocations, but truncates silently - RDebug::RawPrint(format); - TPtrC8 ptr(reinterpret_cast(str)); - RDebug::RawPrint(ptr); - RDebug::RawPrint(_L8("\n")); - } -#endif - QAbstractTestLogger::outputString(str); - } - - static void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0) - { - QTEST_ASSERT(type); - QTEST_ASSERT(msg); - - QTestCharBuffer buf; - - const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() - : "UnknownTestFunc"; - const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; - const char *gtag = QTestResult::currentGlobalDataTag() - ? QTestResult::currentGlobalDataTag() - : ""; - const char *filler = (tag[0] && gtag[0]) ? ":" : ""; - if (file) { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" -#ifdef Q_OS_WIN - "%s(%d) : failure location\n" -#else - " Loc: [%s(%d)]\n" -#endif - , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg, file, line); - } else { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", - type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg); - } - // In colored mode, printf above stripped our nonprintable control characters. - // Put them back. - memcpy(buf.data(), type, strlen(type)); - outputMessage(buf.data()); - } - template static int countSignificantDigits(T num) { @@ -274,74 +199,149 @@ namespace QTest { int size = result.count(); return size; } +} -// static void printBenchmarkResult(const char *bmtag, int value, int iterations) - static void printBenchmarkResult(const QBenchmarkResult &result) - { - const char *bmtag = QTest::benchmarkResult2String(); - - char buf1[1024]; - QTest::qt_snprintf( - buf1, sizeof(buf1), "%s: %s::%s", - bmtag, - QTestResult::currentTestObjectName(), - result.context.slotName.toAscii().data()); - - char bufTag[1024]; - bufTag[0] = 0; - QByteArray tag = result.context.tag.toAscii(); - if (tag.isEmpty() == false) { - QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); +void QPlainTestLogger::outputMessage(const char *str) +{ +#if defined(Q_OS_WINCE) + QString strUtf16 = QString::fromLatin1(str); + const int maxOutputLength = 255; + do { + QString tmp = strUtf16.left(maxOutputLength); + OutputDebugString((wchar_t*)tmp.utf16()); + strUtf16.remove(0, maxOutputLength); + } while (!strUtf16.isEmpty()); + if (QTestLog::outputFileName()) +#elif defined(Q_OS_WIN) + EnterCriticalSection(&QTest::outputCriticalSection); + // OutputDebugString is not threadsafe + OutputDebugStringA(str); + LeaveCriticalSection(&QTest::outputCriticalSection); +#elif defined(Q_OS_SYMBIAN) + // RDebug::Print has a cap of 256 characters so break it up + TPtrC8 ptr(reinterpret_cast(str)); + _LIT(format, "[QTestLib] %S"); + const int maxBlockSize = 256 - ((const TDesC &)format).Length(); + HBufC* hbuffer = HBufC::New(maxBlockSize); + if (hbuffer) { + for (int i = 0; i < ptr.Length(); i += maxBlockSize) { + int size = Min(maxBlockSize, ptr.Length() - i); + hbuffer->Des().Copy(ptr.Mid(i, size)); + RDebug::Print(format, hbuffer); } - - - char fillFormat[8]; - int fillLength = 5; - QTest::qt_snprintf( - fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); - char fill[1024]; - QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); - - const char * unitText = QTest::benchmarkMetricUnit(result.metric); - - qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); - char resultBuffer[100] = ""; - formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value)); - - char buf2[1024]; - QTest::qt_snprintf( - buf2, sizeof(buf2), "%s %s", - resultBuffer, - unitText); - - char buf2_[1024]; - QByteArray iterationText = " per iteration"; - Q_ASSERT(result.iterations > 0); - QTest::qt_snprintf( - buf2_, - sizeof(buf2_), "%s", - iterationText.data()); - - char buf3[1024]; - Q_ASSERT(result.iterations > 0); - formatResult(resultBuffer, 100, result.value, countSignificantDigits(result.value)); - QTest::qt_snprintf( - buf3, sizeof(buf3), " (total: %s, iterations: %d)", - resultBuffer, - result.iterations); - - char buf[1024]; - - if (result.setByMacro) { - QTest::qt_snprintf( - buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); - } else { - QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); - } - - memcpy(buf, bmtag, strlen(bmtag)); - outputMessage(buf); + delete hbuffer; } + else { + // fast, no allocations, but truncates silently + RDebug::RawPrint(format); + TPtrC8 ptr(reinterpret_cast(str)); + RDebug::RawPrint(ptr); + RDebug::RawPrint(_L8("\n")); + } +#endif + outputString(str); +} + +void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line) +{ + QTEST_ASSERT(type); + QTEST_ASSERT(msg); + + QTestCharBuffer buf; + + const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() + : "UnknownTestFunc"; + const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; + const char *gtag = QTestResult::currentGlobalDataTag() + ? QTestResult::currentGlobalDataTag() + : ""; + const char *filler = (tag[0] && gtag[0]) ? ":" : ""; + if (file) { + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" +#ifdef Q_OS_WIN + "%s(%d) : failure location\n" +#else + " Loc: [%s(%d)]\n" +#endif + , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, + msg[0] ? " " : "", msg, file, line); + } else { + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", + type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, + msg[0] ? " " : "", msg); + } + // In colored mode, printf above stripped our nonprintable control characters. + // Put them back. + memcpy(buf.data(), type, strlen(type)); + outputMessage(buf.data()); +} + +//void QPlainTestLogger::printBenchmarkResult(const char *bmtag, int value, int iterations) +void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) +{ + const char *bmtag = QTest::benchmarkResult2String(); + + char buf1[1024]; + QTest::qt_snprintf( + buf1, sizeof(buf1), "%s: %s::%s", + bmtag, + QTestResult::currentTestObjectName(), + result.context.slotName.toAscii().data()); + + char bufTag[1024]; + bufTag[0] = 0; + QByteArray tag = result.context.tag.toAscii(); + if (tag.isEmpty() == false) { + QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); + } + + + char fillFormat[8]; + int fillLength = 5; + QTest::qt_snprintf( + fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); + char fill[1024]; + QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); + + const char * unitText = QTest::benchmarkMetricUnit(result.metric); + + qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); + char resultBuffer[100] = ""; + QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value)); + + char buf2[1024]; + QTest::qt_snprintf( + buf2, sizeof(buf2), "%s %s", + resultBuffer, + unitText); + + char buf2_[1024]; + QByteArray iterationText = " per iteration"; + Q_ASSERT(result.iterations > 0); + QTest::qt_snprintf( + buf2_, + sizeof(buf2_), "%s", + iterationText.data()); + + char buf3[1024]; + Q_ASSERT(result.iterations > 0); + QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value)); + QTest::qt_snprintf( + buf3, sizeof(buf3), " (total: %s, iterations: %d)", + resultBuffer, + result.iterations); + + char buf[1024]; + + if (result.setByMacro) { + QTest::qt_snprintf( + buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); + } else { + QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); + } + + memcpy(buf, bmtag, strlen(bmtag)); + outputMessage(buf); } QPlainTestLogger::QPlainTestLogger() @@ -380,7 +380,7 @@ void QPlainTestLogger::startLogging(const char *filename) ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion()); } } - QTest::outputMessage(buf); + outputMessage(buf); } void QPlainTestLogger::stopLogging() @@ -397,7 +397,7 @@ void QPlainTestLogger::stopLogging() QTestResult::passCount(), QTestResult::failCount(), QTestResult::skipCount(), QTestResult::currentTestObjectName()); } - QTest::outputMessage(buf); + outputMessage(buf); QAbstractTestLogger::stopLogging(); } @@ -406,7 +406,7 @@ void QPlainTestLogger::stopLogging() void QPlainTestLogger::enterTestFunction(const char * /*function*/) { if (QTestLog::verboseLevel() >= 1) - QTest::printMessage(QTest::messageType2String(Info), "entering"); + printMessage(QTest::messageType2String(Info), "entering"); } void QPlainTestLogger::leaveTestFunction() @@ -420,13 +420,13 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, if (type == QAbstractTestLogger::Pass && QTestLog::verboseLevel() < 0) return; - QTest::printMessage(QTest::incidentType2String(type), description, file, line); + printMessage(QTest::incidentType2String(type), description, file, line); } void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { -// QTest::printBenchmarkResult(QTest::benchmarkResult2String(), value, iterations); - QTest::printBenchmarkResult(result); +// printBenchmarkResult(QTest::benchmarkResult2String(), value, iterations); + printBenchmarkResult(result); } void QPlainTestLogger::addMessage(MessageTypes type, const char *message, @@ -437,7 +437,7 @@ void QPlainTestLogger::addMessage(MessageTypes type, const char *message, && QTestLog::verboseLevel() < 0) return; - QTest::printMessage(QTest::messageType2String(type), message, file, line); + printMessage(QTest::messageType2String(type), message, file, line); } void QPlainTestLogger::registerRandomSeed(unsigned int seed) diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index 1784e3be777..5fa33e6b514 100644 --- a/src/testlib/qplaintestlogger_p.h +++ b/src/testlib/qplaintestlogger_p.h @@ -79,6 +79,10 @@ public: private: unsigned int randomSeed; bool hasRandomSeed; + + void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0); + void outputMessage(const char *str); + void printBenchmarkResult(const QBenchmarkResult &result); }; QT_END_NAMESPACE diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp index 50933b91cd1..70f51bfdaa5 100644 --- a/src/testlib/qtestbasicstreamer.cpp +++ b/src/testlib/qtestbasicstreamer.cpp @@ -154,12 +154,12 @@ void QTestBasicStreamer::outputString(const char *msg) const testLogger->outputString(msg); } -void QTestBasicStreamer::setLogger(const QTestLogger *tstLogger) +void QTestBasicStreamer::setLogger(QTestLogger *tstLogger) { testLogger = tstLogger; } -const QTestLogger *QTestBasicStreamer::logger() const +QTestLogger *QTestBasicStreamer::logger() const { return testLogger; } diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h index 371bb496eaf..af0bc060836 100644 --- a/src/testlib/qtestbasicstreamer.h +++ b/src/testlib/qtestbasicstreamer.h @@ -65,8 +65,8 @@ class QTestBasicStreamer void outputString(const char *msg) const; - void setLogger(const QTestLogger *tstLogger); - const QTestLogger *logger() const; + void setLogger(QTestLogger *tstLogger); + QTestLogger *logger() const; protected: virtual void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; @@ -78,7 +78,7 @@ class QTestBasicStreamer virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const; private: - const QTestLogger *testLogger; + QTestLogger *testLogger; }; QT_END_NAMESPACE From 36533edf7159547bdcf5b7def02870d1b04d09ac Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 11:44:17 +1000 Subject: [PATCH 24/43] Remove ability to change XML logger during a test. It doesn't make sense to change the logger associated with a streamer in the middle of a test run, so only allow the logger to be set when constructing a streamer. Change-Id: I02661de2b6071c74d10bc854cbe436581978d2d9 Reviewed-on: http://codereview.qt.nokia.com/3622 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestbasicstreamer.cpp | 11 ++++------- src/testlib/qtestbasicstreamer.h | 3 +-- src/testlib/qtestlightxmlstreamer.cpp | 4 ++-- src/testlib/qtestlightxmlstreamer.h | 2 +- src/testlib/qtestlogger.cpp | 8 +++----- src/testlib/qtestxmlstreamer.cpp | 4 ++-- src/testlib/qtestxmlstreamer.h | 2 +- src/testlib/qtestxunitstreamer.cpp | 4 ++-- src/testlib/qtestxunitstreamer.h | 2 +- 9 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp index 70f51bfdaa5..d371b4d08ee 100644 --- a/src/testlib/qtestbasicstreamer.cpp +++ b/src/testlib/qtestbasicstreamer.cpp @@ -43,6 +43,7 @@ #include "qtestlogger_p.h" #include "qtestelement.h" #include "qtestelementattribute.h" +#include "qtestassert.h" #include #include @@ -53,9 +54,10 @@ QT_BEGIN_NAMESPACE -QTestBasicStreamer::QTestBasicStreamer() - :testLogger(0) +QTestBasicStreamer::QTestBasicStreamer(QTestLogger *logger) + :testLogger(logger) { + QTEST_ASSERT(testLogger); } QTestBasicStreamer::~QTestBasicStreamer() @@ -154,11 +156,6 @@ void QTestBasicStreamer::outputString(const char *msg) const testLogger->outputString(msg); } -void QTestBasicStreamer::setLogger(QTestLogger *tstLogger) -{ - testLogger = tstLogger; -} - QTestLogger *QTestBasicStreamer::logger() const { return testLogger; diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h index af0bc060836..04bc40638ff 100644 --- a/src/testlib/qtestbasicstreamer.h +++ b/src/testlib/qtestbasicstreamer.h @@ -58,14 +58,13 @@ struct QTestCharBuffer; class QTestBasicStreamer { public: - QTestBasicStreamer(); + QTestBasicStreamer(QTestLogger *logger); virtual ~QTestBasicStreamer(); virtual void output(QTestElement *element) const; void outputString(const char *msg) const; - void setLogger(QTestLogger *tstLogger); QTestLogger *logger() const; protected: diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp index 5a8f96d0689..8ac4e03d771 100644 --- a/src/testlib/qtestlightxmlstreamer.cpp +++ b/src/testlib/qtestlightxmlstreamer.cpp @@ -52,8 +52,8 @@ QT_BEGIN_NAMESPACE -QTestLightXmlStreamer::QTestLightXmlStreamer() - :QTestBasicStreamer() +QTestLightXmlStreamer::QTestLightXmlStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) { } diff --git a/src/testlib/qtestlightxmlstreamer.h b/src/testlib/qtestlightxmlstreamer.h index c8ac68146d3..b3076c1623c 100644 --- a/src/testlib/qtestlightxmlstreamer.h +++ b/src/testlib/qtestlightxmlstreamer.h @@ -56,7 +56,7 @@ class QTestElementAttribute; class QTestLightXmlStreamer: public QTestBasicStreamer { public: - QTestLightXmlStreamer(); + QTestLightXmlStreamer(QTestLogger *logger); ~QTestLightXmlStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 9cf43209516..af069d76b20 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -84,23 +84,21 @@ void QTestLogger::startLogging(const char *filename) switch(format){ case TLF_LightXml:{ - logFormatter = new QTestLightXmlStreamer; + logFormatter = new QTestLightXmlStreamer(this); filelogger->init(); break; }case TLF_XML:{ - logFormatter = new QTestXmlStreamer; + logFormatter = new QTestXmlStreamer(this); filelogger->init(); break; }case TLF_XunitXml:{ - logFormatter = new QTestXunitStreamer; + logFormatter = new QTestXunitStreamer(this); delete errorLogElement; errorLogElement = new QTestElement(QTest::LET_SystemError); filelogger->init(); break; } } - - logFormatter->setLogger(this); } void QTestLogger::stopLogging() diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp index 6a7f9ae8f7d..7a4115262b0 100644 --- a/src/testlib/qtestxmlstreamer.cpp +++ b/src/testlib/qtestxmlstreamer.cpp @@ -53,8 +53,8 @@ QT_BEGIN_NAMESPACE -QTestXmlStreamer::QTestXmlStreamer() - :QTestBasicStreamer() +QTestXmlStreamer::QTestXmlStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) { } diff --git a/src/testlib/qtestxmlstreamer.h b/src/testlib/qtestxmlstreamer.h index 46318a9d18f..300940806c2 100644 --- a/src/testlib/qtestxmlstreamer.h +++ b/src/testlib/qtestxmlstreamer.h @@ -56,7 +56,7 @@ class QTestElementAttribute; class QTestXmlStreamer: public QTestBasicStreamer { public: - QTestXmlStreamer(); + QTestXmlStreamer(QTestLogger *logger); ~QTestXmlStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp index c4b3192c5a6..fb9699eef12 100644 --- a/src/testlib/qtestxunitstreamer.cpp +++ b/src/testlib/qtestxunitstreamer.cpp @@ -48,8 +48,8 @@ QT_BEGIN_NAMESPACE -QTestXunitStreamer::QTestXunitStreamer() - :QTestBasicStreamer() +QTestXunitStreamer::QTestXunitStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) {} QTestXunitStreamer::~QTestXunitStreamer() diff --git a/src/testlib/qtestxunitstreamer.h b/src/testlib/qtestxunitstreamer.h index f99e231f8d9..4d1cb2734a0 100644 --- a/src/testlib/qtestxunitstreamer.h +++ b/src/testlib/qtestxunitstreamer.h @@ -55,7 +55,7 @@ class QTestLogger; class QTestXunitStreamer: public QTestBasicStreamer { public: - QTestXunitStreamer(); + QTestXunitStreamer(QTestLogger *logger); ~QTestXunitStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; From 58f2ac3a2993423ab247c43b307513f054b65870 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 23 Aug 2011 18:35:27 +1000 Subject: [PATCH 25/43] Remove QTestFileLogger class. This class is not very useful -- it just creates a text file that records each occasion that an autotest enters a test function as a stop-gap solution for the fact that the newer XML logger produces no output if the autotest fails to terminate gracefully. Addressing QTBUG-20615 will provide a better solution by allowing the user to get a partial plain text test log in those circumstances. Change-Id: I179bb98dbd696d0734cd3f12046e5c567def30cc Reviewed-on: http://codereview.qt.nokia.com/3390 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestfilelogger.cpp | 114 -------------------------------- src/testlib/qtestfilelogger.h | 67 ------------------- src/testlib/qtestlogger.cpp | 18 ++--- src/testlib/qtestlogger_p.h | 2 - src/testlib/testlib.pro | 4 +- src/tools/uic/qclass_lib_map.h | 1 - 6 files changed, 5 insertions(+), 201 deletions(-) delete mode 100644 src/testlib/qtestfilelogger.cpp delete mode 100644 src/testlib/qtestfilelogger.h diff --git a/src/testlib/qtestfilelogger.cpp b/src/testlib/qtestfilelogger.cpp deleted file mode 100644 index 2349ca3cd59..00000000000 --- a/src/testlib/qtestfilelogger.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtestfilelogger.h" -#include "qtestassert.h" -#include "QtTest/private/qtestlog_p.h" -#include "QtTest/private/qtestresult_p.h" - -#include - -#include -#include - -QT_BEGIN_NAMESPACE - -namespace QTest -{ - static FILE *stream = 0; -} - -QTestFileLogger::QTestFileLogger() -{ -} - -QTestFileLogger::~QTestFileLogger() -{ - if(QTest::stream) - fclose(QTest::stream); - - QTest::stream = 0; -} - -void QTestFileLogger::init() -{ - char filename[100]; - int index = 0; -#if defined(Q_OS_SYMBIAN) - QByteArray ba(QDir::toNativeSeparators(QString(QDir::homePath()+QDir::separator())).toUtf8()); - index = ba.length(); - QTest::qt_snprintf(filename, sizeof(filename), "%s%s.log", - ba.constData(), QTestResult::currentTestObjectName()); -#else - QTest::qt_snprintf(filename, sizeof(filename), "%s.log", - QTestResult::currentTestObjectName()); -#endif - - // Keep filenames simple - for (uint i = index; i < sizeof(filename) && filename[i]; ++i) { - char& c = filename[i]; - if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') || c == '-' || c == '.')) { - c = '_'; - } - } - -#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, filename, "wt")) { -#else - QTest::stream = ::fopen(filename, "wt"); - if (!QTest::stream) { -#endif - printf("Unable to open file for simple logging: %s", filename); - ::exit(1); - } -} - -void QTestFileLogger::flush(const char *msg) -{ - QTEST_ASSERT(QTest::stream); - - ::fputs(msg, QTest::stream); - ::fflush(QTest::stream); -} - -QT_END_NAMESPACE - diff --git a/src/testlib/qtestfilelogger.h b/src/testlib/qtestfilelogger.h deleted file mode 100644 index 9b10a495390..00000000000 --- a/src/testlib/qtestfilelogger.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTESTFILELOGGER_H -#define QTESTFILELOGGER_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Test) - -class QTestFileLogger -{ - public: - QTestFileLogger(); - ~QTestFileLogger(); - - void init(); - void flush(const char *msg); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTESTFILELOGGER_H diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index af069d76b20..7e9332a4b6a 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -44,7 +44,6 @@ #include "qtestxunitstreamer.h" #include "qtestxmlstreamer.h" #include "qtestlightxmlstreamer.h" -#include "qtestfilelogger.h" #include "QtTest/qtestcase.h" #include "QtTest/private/qtestresult_p.h" @@ -56,7 +55,7 @@ QT_BEGIN_NAMESPACE QTestLogger::QTestLogger(int fm) :listOfTestcases(0), currentLogElement(0), errorLogElement(0), - logFormatter(0), format( (TestLoggerFormat)fm ), filelogger(new QTestFileLogger), + logFormatter(0), format( (TestLoggerFormat)fm ), testCounter(0), passCounter(0), failureCounter(0), errorCounter(0), warningCounter(0), skipCounter(0), @@ -75,7 +74,6 @@ QTestLogger::~QTestLogger() delete listOfTestcases; delete logFormatter; - delete filelogger; } void QTestLogger::startLogging(const char *filename) @@ -83,22 +81,18 @@ void QTestLogger::startLogging(const char *filename) QAbstractTestLogger::startLogging(filename); switch(format){ - case TLF_LightXml:{ + case TLF_LightXml: logFormatter = new QTestLightXmlStreamer(this); - filelogger->init(); break; - }case TLF_XML:{ + case TLF_XML: logFormatter = new QTestXmlStreamer(this); - filelogger->init(); break; - }case TLF_XunitXml:{ + case TLF_XunitXml: logFormatter = new QTestXunitStreamer(this); delete errorLogElement; errorLogElement = new QTestElement(QTest::LET_SystemError); - filelogger->init(); break; } - } } void QTestLogger::stopLogging() @@ -165,10 +159,6 @@ void QTestLogger::stopLogging() void QTestLogger::enterTestFunction(const char *function) { - char buf[1024]; - QTest::qt_snprintf(buf, sizeof(buf), "Entered test-function: %s\n", function); - filelogger->flush(buf); - currentLogElement = new QTestElement(QTest::LET_TestCase); currentLogElement->addAttribute(QTest::AI_Name, function); currentLogElement->addToList(&listOfTestcases); diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 5793537e788..c9b9da1ee8d 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -59,7 +59,6 @@ QT_BEGIN_NAMESPACE class QTestBasicStreamer; class QTestElement; -class QTestFileLogger; class QTestLogger : public QAbstractTestLogger { @@ -111,7 +110,6 @@ class QTestLogger : public QAbstractTestLogger QTestElement *errorLogElement; QTestBasicStreamer *logFormatter; TestLoggerFormat format; - QTestFileLogger *filelogger; int testCounter; int passCounter; diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index c3df1b4ec72..482c82cfd3b 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -27,7 +27,6 @@ HEADERS = qbenchmark.h \ qtestelement.h \ qtestevent.h \ qtesteventloop.h \ - qtestfilelogger.h \ qtest_global.h \ qtest_gui.h \ qtest.h \ @@ -60,8 +59,7 @@ SOURCES = qtestcase.cpp \ qtestxunitstreamer.cpp \ qtestxmlstreamer.cpp \ qtestlightxmlstreamer.cpp \ - qtestlogger.cpp \ - qtestfilelogger.cpp + qtestlogger.cpp DEFINES *= QT_NO_CAST_TO_ASCII \ QT_NO_CAST_FROM_ASCII \ QTESTLIB_MAKEDLL \ diff --git a/src/tools/uic/qclass_lib_map.h b/src/tools/uic/qclass_lib_map.h index 35b4f928ef0..f86f458d459 100644 --- a/src/tools/uic/qclass_lib_map.h +++ b/src/tools/uic/qclass_lib_map.h @@ -527,7 +527,6 @@ QT_CLASS_LIB(QTestMouseEvent, QtTest, qtestevent.h) QT_CLASS_LIB(QTestDelayEvent, QtTest, qtestevent.h) QT_CLASS_LIB(QTestEventList, QtTest, qtestevent.h) QT_CLASS_LIB(QTestEventLoop, QtTest, qtesteventloop.h) -QT_CLASS_LIB(QTestFileLogger, QtTest, qtestfilelogger.h) QT_CLASS_LIB(QTestLightXmlStreamer, QtTest, qtestlightxmlstreamer.h) QT_CLASS_LIB(QEventSizeOfChecker, QtTest, qtestspontaneevent.h) QT_CLASS_LIB(QEventSizeOfChecker, QtTest, qtestspontaneevent.h) From 4e85437d9b18ae8a8f4a867962cec71acb2009e8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 25 Aug 2011 15:06:26 +1000 Subject: [PATCH 26/43] Fix minor formatting issues. Change-Id: I66767e906c54988ca0d0e2823b1a396993ba06f2 Reviewed-on: http://codereview.qt.nokia.com/3624 Reviewed-by: Jason McDonald Reviewed-by: Rohan McGovern --- src/testlib/qtestlog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index a438da2746b..9e0ab786904 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -168,28 +168,28 @@ namespace QTest { } } -void initLogger() -{ - switch (QTest::logMode) { + void initLogger() + { + switch (QTest::logMode) { case QTestLog::Plain: QTest::testLogger = new QPlainTestLogger; break; - case QTestLog::XML:{ + case QTestLog::XML: if(QTest::flushMode == QTestLog::FLushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML); break; - }case QTestLog::LightXML:{ + case QTestLog::LightXML: if(QTest::flushMode == QTestLog::FLushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml); break; - }case QTestLog::XunitXML: + case QTestLog::XunitXML: QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml); } -} + } } From c542972f1e85b2a5199c035f4268de4569e4c6ff Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 15:23:07 +1000 Subject: [PATCH 27/43] Fix typo in enum name. Change-Id: I2eccbd3b9dd31aa5e869d622055f9235f90c0c03 Reviewed-on: http://codereview.qt.nokia.com/3445 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 4 ++-- src/testlib/qtestlog.cpp | 4 ++-- src/testlib/qtestlog_p.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 27a897c2634..c63d333261e 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1109,8 +1109,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTestLog::setLogMode(QTestLog::XML); } else if (strcmp(argv[i], "-lightxml") == 0) { QTestLog::setLogMode(QTestLog::LightXML); - }else if(strcmp(argv[i], "-flush") == 0){ - QTestLog::setFlushMode(QTestLog::FLushOn); + } else if (strcmp(argv[i], "-flush") == 0){ + QTestLog::setFlushMode(QTestLog::FlushOn); } else if (strcmp(argv[i], "-silent") == 0) { QTestLog::setVerboseLevel(-1); } else if (strcmp(argv[i], "-v1") == 0) { diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 9e0ab786904..674772f95b8 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -175,13 +175,13 @@ namespace QTest { QTest::testLogger = new QPlainTestLogger; break; case QTestLog::XML: - if(QTest::flushMode == QTestLog::FLushOn) + if (QTest::flushMode == QTestLog::FlushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML); break; case QTestLog::LightXML: - if(QTest::flushMode == QTestLog::FLushOn) + if (QTest::flushMode == QTestLog::FlushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml); diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index 20c731fee66..ee944047446 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -63,7 +63,7 @@ class Q_TESTLIB_EXPORT QTestLog { public: enum LogMode { Plain = 0, XML, LightXML, XunitXML }; - enum FlushMode { NoFlush = 0, FLushOn }; + enum FlushMode { NoFlush = 0, FlushOn }; static void enterTestFunction(const char* function); static void leaveTestFunction(); From 37054f82d826fb043cc813c176dddf390494289c Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 13:41:43 +1000 Subject: [PATCH 28/43] Fix broken header file guard. Change-Id: I6db5be5289b271be24a4a9d77c5f2a1e9f560d2d Reviewed-on: http://codereview.qt.nokia.com/3434 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestxmlstreamer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testlib/qtestxmlstreamer.h b/src/testlib/qtestxmlstreamer.h index 300940806c2..96e82467794 100644 --- a/src/testlib/qtestxmlstreamer.h +++ b/src/testlib/qtestxmlstreamer.h @@ -40,7 +40,7 @@ ****************************************************************************/ #ifndef QTESTXMLSTREAMER_H -#define QTESXMLSTREAMER_H +#define QTESTXMLSTREAMER_H #include From 058d4afe3d755d2e31e077c26aa338417fa31f72 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 25 Aug 2011 12:53:07 +1000 Subject: [PATCH 29/43] Remove mode parameter from QTestLog::addSkip(). The mode parameter is never used by the logging code, so there's little value in passing it there. Change-Id: Ibe2cbe5eaf457a7e3ffd3aea3a4be7c8278c91b6 Reviewed-on: http://codereview.qt.nokia.com/3547 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 2 +- src/testlib/qtestlog.cpp | 3 +-- src/testlib/qtestlog_p.h | 3 +-- src/testlib/qtestresult.cpp | 5 ++--- src/testlib/qtestresult_p.h | 3 +-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index c63d333261e..9c50257b44c 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1959,7 +1959,7 @@ bool QTest::qVerify(bool statement, const char *statementStr, const char *descri void QTest::qSkip(const char *message, QTest::SkipMode mode, const char *file, int line) { - QTestResult::addSkip(message, mode, file, line); + QTestResult::addSkip(message, file, line); if (mode == QTest::SkipAll) QTestResult::setSkipCurrentTest(true); } diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 674772f95b8..a13bcdc7f84 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -275,8 +275,7 @@ void QTestLog::addXPass(const char *msg, const char *file, int line) QTest::testLogger->addIncident(QAbstractTestLogger::XPass, msg, file, line); } -void QTestLog::addSkip(const char *msg, QTest::SkipMode /*mode*/, - const char *file, int line) +void QTestLog::addSkip(const char *msg, const char *file, int line) { QTEST_ASSERT(QTest::testLogger); QTEST_ASSERT(msg); diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index ee944047446..006b3ac12fa 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -72,8 +72,7 @@ public: static void addFail(const char *msg, const char *file, int line); static void addXFail(const char *msg, const char *file, int line); static void addXPass(const char *msg, const char *file, int line); - static void addSkip(const char *msg, QTest::SkipMode mode, - const char *file, int line); + static void addSkip(const char *msg, const char *file, int line); static void addBenchmarkResult(const QBenchmarkResult &result); static void addIgnoreMessage(QtMsgType type, const char *msg); static int unhandledIgnoreMessages(); diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 7fb0208bb3f..4a6764b115a 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -285,12 +285,11 @@ void QTestResult::addFailure(const char *message, const char *file, int line) ++QTest::fails; } -void QTestResult::addSkip(const char *message, QTest::SkipMode mode, - const char *file, int line) +void QTestResult::addSkip(const char *message, const char *file, int line) { clearExpectFail(); - QTestLog::addSkip(message, mode, file, line); + QTestLog::addSkip(message, file, line); ++QTest::skips; } diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h index a3e265ffac1..1ce81854b53 100644 --- a/src/testlib/qtestresult_p.h +++ b/src/testlib/qtestresult_p.h @@ -93,8 +93,7 @@ public: static void setCurrentTestFunction(const char *func); static void setCurrentTestLocation(TestLocation loc); static void setCurrentTestObject(const char *name); - static void addSkip(const char *message, QTest::SkipMode mode, - const char *file, int line); + static void addSkip(const char *message, const char *file, int line); static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line); static bool verify(bool statement, const char *statementStr, const char *extraInfo, From 603a5025d8b671185c6fcf8672970a4e2881d64d Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 18:03:56 +1000 Subject: [PATCH 30/43] Be more consistent when including private headers. Change-Id: I0fdc014391ff34ba3be9501c2e73bd5357df1f5e Reviewed-on: http://codereview.qt.nokia.com/3467 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlog.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index a13bcdc7f84..855f8fd69c3 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -45,6 +45,7 @@ #include "QtTest/private/qtestresult_p.h" #include "QtTest/private/qabstracttestlogger_p.h" #include "QtTest/private/qplaintestlogger_p.h" +#include "QtTest/private/qtestlogger_p.h" #include "QtTest/private/qxmltestlogger_p.h" #include #include @@ -53,9 +54,6 @@ #include #include - -#include "qtestlogger_p.h" - QT_BEGIN_NAMESPACE namespace QTest { From 39f9fd29526ae8f6803314d9fdc8dcf1cb9bd2bc Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 18:20:44 +1000 Subject: [PATCH 31/43] Add missing assertions. For both QTestLog::addFail() and QTestLog::addIgnoreMessage(), passing a null message does not make sense and is therefore an error that should be brought to the developer's attention. Change-Id: Ib09ad90b70d74f7432c08708db8a70dee008cce4 Reviewed-on: http://codereview.qt.nokia.com/3470 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlog.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 855f8fd69c3..9990bbdb463 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -251,6 +251,7 @@ void QTestLog::addPass(const char *msg) void QTestLog::addFail(const char *msg, const char *file, int line) { QTEST_ASSERT(QTest::testLogger); + QTEST_ASSERT(msg); QTest::testLogger->addIncident(QAbstractTestLogger::Fail, msg, file, line); } @@ -353,6 +354,8 @@ int QTestLog::verboseLevel() void QTestLog::addIgnoreMessage(QtMsgType type, const char *msg) { + QTEST_ASSERT(msg); + QTest::IgnoreResultList *item = new QTest::IgnoreResultList(type, msg); QTest::IgnoreResultList *list = QTest::ignoreResultList; From adcfd88764aab630290479c3b68651690f27f050 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 17:58:31 +1000 Subject: [PATCH 32/43] Remove QTestLog constructor/destructor definitions QTestLog is an entirely static class and its constructor and destructor are declared private to prevent accidental construction of an instance of the class. Therefore, the constructor and destructor do not need to be defined. Change-Id: I860f1344c5032091f5c641a20e1656bb52a6f07e Reviewed-on: http://codereview.qt.nokia.com/3466 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlog.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 9990bbdb463..36b69e1155b 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -191,14 +191,6 @@ namespace QTest { } -QTestLog::QTestLog() -{ -} - -QTestLog::~QTestLog() -{ -} - void QTestLog::enterTestFunction(const char* function) { QTEST_ASSERT(QTest::testLogger); From a541bd9662b07e53cc2173b12b71bb07f188ace8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 13:48:56 +1000 Subject: [PATCH 33/43] Remove unused methods from QTestLogger. The setLogFormat() and logFormat() methods are never called -- the log format is set in the call to the constructor and it would not make sense to change it during a test run. Change-Id: I59256f17f28bbc72d86cabfb2a961d2faf0e2d52 Reviewed-on: http://codereview.qt.nokia.com/3435 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlogger.cpp | 10 ---------- src/testlib/qtestlogger_p.h | 3 --- 2 files changed, 13 deletions(-) diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 7e9332a4b6a..4aa1738a996 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -358,16 +358,6 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char } } -void QTestLogger::setLogFormat(TestLoggerFormat fm) -{ - format = fm; -} - -QTestLogger::TestLoggerFormat QTestLogger::logFormat() -{ - return format; -} - int QTestLogger::passCount() const { return passCounter; diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index c9b9da1ee8d..b3fb1143da0 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -87,9 +87,6 @@ class QTestLogger : public QAbstractTestLogger void addMessage(MessageTypes type, const char *message, const char *file = 0, int line = 0); - void setLogFormat(TestLoggerFormat fm); - TestLoggerFormat logFormat(); - int passCount() const; int failureCount() const; int errorCount() const; From 043914bd97f2ad7afc474e13ebd97f2eadf60eae Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 24 Aug 2011 14:25:20 +1000 Subject: [PATCH 34/43] Remove unused members and methods from QTestLogger. QTestLogger was counting various test outputs, but was only using three of the counters internally and the rest were not used at all. This commit removes the unused counters and all of the getter methods. Change-Id: I447183dcaf3e6cc335bbf58656e25b1d32ba810a Reviewed-on: http://codereview.qt.nokia.com/3437 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlogger.cpp | 78 +++++-------------------------------- src/testlib/qtestlogger_p.h | 18 --------- 2 files changed, 10 insertions(+), 86 deletions(-) diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 4aa1738a996..ff1f60967de 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -54,15 +54,16 @@ QT_BEGIN_NAMESPACE QTestLogger::QTestLogger(int fm) - :listOfTestcases(0), currentLogElement(0), errorLogElement(0), - logFormatter(0), format( (TestLoggerFormat)fm ), - testCounter(0), passCounter(0), - failureCounter(0), errorCounter(0), - warningCounter(0), skipCounter(0), - systemCounter(0), qdebugCounter(0), - qwarnCounter(0), qfatalCounter(0), - infoCounter(0), randomSeed_(0), - hasRandomSeed_(false) + : listOfTestcases(0) + , currentLogElement(0) + , errorLogElement(0) + , logFormatter(0) + , format( (TestLoggerFormat)fm ) + , testCounter(0) + , failureCounter(0) + , errorCounter(0) + , randomSeed_(0) + , hasRandomSeed_(false) { } @@ -182,11 +183,9 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, typeBuf = "xpass"; break; case QAbstractTestLogger::Pass: - ++passCounter; typeBuf = "pass"; break; case QAbstractTestLogger::XFail: - ++passCounter; typeBuf = "xfail"; break; case QAbstractTestLogger::Fail: @@ -302,31 +301,24 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char switch (type) { case QAbstractTestLogger::Warn: - ++warningCounter; typeBuf = "warn"; break; case QAbstractTestLogger::QSystem: - ++systemCounter; typeBuf = "system"; break; case QAbstractTestLogger::QDebug: - ++qdebugCounter; typeBuf = "qdebug"; break; case QAbstractTestLogger::QWarning: - ++qwarnCounter; typeBuf = "qwarn"; break; case QAbstractTestLogger::QFatal: - ++qfatalCounter; typeBuf = "qfatal"; break; case QAbstractTestLogger::Skip: - ++skipCounter; typeBuf = "skip"; break; case QAbstractTestLogger::Info: - ++infoCounter; typeBuf = "info"; break; default: @@ -358,56 +350,6 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char } } -int QTestLogger::passCount() const -{ - return passCounter; -} - -int QTestLogger::failureCount() const -{ - return failureCounter; -} - -int QTestLogger::errorCount() const -{ - return errorCounter; -} - -int QTestLogger::warningCount() const -{ - return warningCounter; -} - -int QTestLogger::skipCount() const -{ - return skipCounter; -} - -int QTestLogger::systemCount() const -{ - return systemCounter; -} - -int QTestLogger::qdebugCount() const -{ - return qdebugCounter; -} - -int QTestLogger::qwarnCount() const -{ - return qwarnCounter; -} - -int QTestLogger::qfatalCount() const -{ - return qfatalCounter; -} - -int QTestLogger::infoCount() const -{ - return infoCounter; -} - void QTestLogger::registerRandomSeed(unsigned int seed) { randomSeed_ = seed; diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index b3fb1143da0..eef5b92d2b5 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -87,16 +87,6 @@ class QTestLogger : public QAbstractTestLogger void addMessage(MessageTypes type, const char *message, const char *file = 0, int line = 0); - int passCount() const; - int failureCount() const; - int errorCount() const; - int warningCount() const; - int skipCount() const; - int systemCount() const; - int qdebugCount() const; - int qwarnCount() const; - int qfatalCount() const; - int infoCount() const; void registerRandomSeed(unsigned int seed); unsigned int randomSeed() const; bool hasRandomSeed() const; @@ -109,16 +99,8 @@ class QTestLogger : public QAbstractTestLogger TestLoggerFormat format; int testCounter; - int passCounter; int failureCounter; int errorCounter; - int warningCounter; - int skipCounter; - int systemCounter; - int qdebugCounter; - int qwarnCounter; - int qfatalCounter; - int infoCounter; unsigned int randomSeed_; bool hasRandomSeed_; }; From 15400d94664f93dc22f71802eb72c34c52e371ac Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 17:36:55 +1000 Subject: [PATCH 35/43] Send error messages to stderr rather than stdout The commit changes printf's that output error and warning messages to send their text to the stderr stream. Non-error output, such as that produced by passing the -help option to a test, still goes to stdout. Change-Id: Iea4d62451e3e7e84c654859cb09ea7e717511d13 Reviewed-on: http://codereview.qt.nokia.com/3636 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qabstracttestlogger.cpp | 2 +- src/testlib/qtestcase.cpp | 66 ++++++++++++++--------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index a5651317e7b..d71addb655e 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -76,7 +76,7 @@ void QAbstractTestLogger::startLogging(const char *filename) stream = ::fopen(filename, "wt"); if (!stream) { #endif - printf("Unable to open file for logging: %s", filename); + fprintf(stderr, "Unable to open file for logging: %s", filename); ::exit(1); } } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 9c50257b44c..d71fb902548 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1018,12 +1018,12 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false; Q_TESTLIB_EXPORT QStringList testFunctions; Q_TESTLIB_EXPORT QStringList testTags; -static void qPrintTestSlots() +static void qPrintTestSlots(FILE *stream) { for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); if (isValidSlot(sl)) - printf("%s\n", sl.signature()); + fprintf(stream, "%s\n", sl.signature()); } } @@ -1032,7 +1032,7 @@ static int qToInt(char *str) char *pEnd; int l = (int)strtol(str, &pEnd, 10); if (*pEnd != 0) { - printf("Invalid numeric parameter: '%s'\n", str); + fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); exit(1); } return l; @@ -1100,7 +1100,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (qml) { QTest::printAvailableFunctions = true; } else { - qPrintTestSlots(); + qPrintTestSlots(stdout); exit(0); } } else if(strcmp(argv[i], "-xunitxml") == 0){ @@ -1121,35 +1121,35 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QSignalDumper::startDump(); } else if (strcmp(argv[i], "-o") == 0) { if (i + 1 >= argc) { - printf("-o needs an extra parameter specifying the filename\n"); + fprintf(stderr, "-o needs an extra parameter specifying the filename\n"); exit(1); } else { QTestLog::redirectOutput(argv[++i]); } } else if (strcmp(argv[i], "-eventdelay") == 0) { if (i + 1 >= argc) { - printf("-eventdelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::eventDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-keydelay") == 0) { if (i + 1 >= argc) { - printf("-keydelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::keyDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-mousedelay") == 0) { if (i + 1 >= argc) { - printf("-mousedelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::mouseDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-maxwarnings") == 0) { if (i + 1 >= argc) { - printf("-maxwarnings needs an extra parameter with the amount of warnings\n"); + fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); exit(1); } else { QTestLog::setMaxWarnings(qToInt(argv[++i])); @@ -1166,10 +1166,10 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (QFileInfo(QDir::currentPath()).isWritable()) { QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); } else { - printf("WARNING: Current directory not writable. Using the walltime measurer.\n"); + fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); } else { - printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " + fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " "Using the walltime measurer.\n"); } } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option @@ -1194,28 +1194,28 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::seed = longSeed; } if (!argumentOk) { - printf("-seed needs an extra positive integer parameter to specify the seed\n"); + fprintf(stderr, "-seed needs an extra positive integer parameter to specify the seed\n"); exit(1); } else { QTest::seedSet = true; } } else if (strcmp(argv[i], "-minimumvalue") == 0) { if (i + 1 >= argc) { - printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); + fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); exit(1); } else { QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-iterations") == 0) { if (i + 1 >= argc) { - printf("-iterations needs an extra parameter to indicate the number of iterations\n"); + fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-median") == 0) { if (i + 1 >= argc) { - printf("-median needs an extra parameter to indicate the number of median iterations\n"); + fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); @@ -1230,23 +1230,23 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } else if (strcmp(argv[i], "-graphicssystem") == 0) { // do nothing if (i + 1 >= argc) { - printf("-graphicssystem needs an extra parameter specifying the graphics system\n"); + fprintf(stderr, "-graphicssystem needs an extra parameter specifying the graphics system\n"); exit(1); } else { ++i; } } else if (argv[i][0] == '-') { - printf("Unknown option: '%s'\n\n%s", argv[i], testOptions); + fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); if (qml) { - printf ("\nqmltest related options:\n" - " -import : Specify an import directory.\n" - " -input : Specify the root directory for test cases.\n" - " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" - ); + fprintf(stderr, "\nqmltest related options:\n" + " -import : Specify an import directory.\n" + " -input : Specify the root directory for test cases.\n" + " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" + ); } - printf("\n" - " -help : This help\n"); + fprintf(stderr, "\n" + " -help : This help\n"); exit(1); } else if (qml) { // We can't check the availability of test functions until @@ -1295,9 +1295,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { - printf("Unknown testfunction: '%s'\n", buf); - printf("Available testfunctions:\n"); - qPrintTestSlots(); + fprintf(stderr, "Unknown testfunction: '%s'\n", buf); + fprintf(stderr, "Available testfunctions:\n"); + qPrintTestSlots(stderr); exit(1); } testFuncs[testFuncCount].set(idx, data); @@ -1307,7 +1307,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } if (QTest::seedSet && !QTest::randomOrder) { - printf("-seed requires -random\n"); + fprintf(stderr, "-seed requires -random\n"); exit(1); } } @@ -1466,8 +1466,8 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) if (!*data) data = 0; else { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Function has no testdata.\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Function has no testdata.\n"); return false; } } @@ -1492,10 +1492,10 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) } if (data && !foundFunction) { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Available testdata:\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Available testdata:\n"); for(int i = 0; i < table.dataCount(); ++i) - printf("%s\n", table.testData(i)->dataTag()); + fprintf(stderr, "%s\n", table.testData(i)->dataTag()); return false; } From d094f71b2238d9d83282c87817035e0159dc84a3 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 17:43:55 +1000 Subject: [PATCH 36/43] Remove obsolete autotest command-line flag. The charting functionality was removed in Qt 4.6, though the command-line option was retained to print a warning that the feature had been removed. Sufficient time has passed for this to be removed completely. Change-Id: I2adf2818c6a6e57e765104de97b28dbf6914e3fa Reviewed-on: http://codereview.qt.nokia.com/3638 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index d71fb902548..161c46e579b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1223,8 +1223,6 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } else if (strcmp(argv[i], "-vb") == 0) { QBenchmarkGlobalData::current->verboseOutput = true; - } else if (strcmp(argv[i], "-chart") == 0) { - fprintf(stderr, "Warning: `-chart' option is not available\n"); } else if (strcmp(argv[i], "-qws") == 0) { // do nothing } else if (strcmp(argv[i], "-graphicssystem") == 0) { From f310067ee0265be1f0488b886c988de02eac7975 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 17:49:56 +1000 Subject: [PATCH 37/43] Remove debugging printf. Change-Id: Ib5733e96d3a6cec956d2f4c326d7be42e813c440 Reviewed-on: http://codereview.qt.nokia.com/3639 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestlogger.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index ff1f60967de..d53a9687196 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -259,7 +259,6 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark); -// printf("element %i", benchmarkElement->elementType()); benchmarkElement->addAttribute( QTest::AI_Metric, From f4d721fccb29e5cb5f43cb0e3f8441f0cb159083 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 18:01:43 +1000 Subject: [PATCH 38/43] Remove obsolete ifdef. QTEST_EMBED is not defined in Qt itself, nor is it defined by any of the CI builds for Qt's supported platforms. Change-Id: I73a3979630130fc8f1ef99dcbc17b4d1875ba246 Reviewed-on: http://codereview.qt.nokia.com/3641 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtest_global.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/testlib/qtest_global.h b/src/testlib/qtest_global.h index 85b9d6e1c17..b7479a8102c 100644 --- a/src/testlib/qtest_global.h +++ b/src/testlib/qtest_global.h @@ -50,9 +50,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Test) -#ifdef QTEST_EMBED -# define Q_TESTLIB_EXPORT -#elif !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) +#if !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) # define Q_TESTLIB_EXPORT #else # ifdef QTESTLIB_MAKEDLL From cf058d482363ff4823f319e118dde913fd7d9c5d Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 18:10:08 +1000 Subject: [PATCH 39/43] Remove default params from QTestData constructor The constructor asserts if either parameter is null, so having defaults seems to be pointless. Change-Id: I8cec52e17e5f94458e8d8323855eaed6433686e7 Reviewed-on: http://codereview.qt.nokia.com/3644 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestdata.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testlib/qtestdata.h b/src/testlib/qtestdata.h index b964ec1dcce..02ee03ff7d5 100644 --- a/src/testlib/qtestdata.h +++ b/src/testlib/qtestdata.h @@ -69,7 +69,7 @@ public: private: friend class QTestTable; - QTestData(const char *tag = 0, QTestTable *parent = 0); + QTestData(const char *tag, QTestTable *parent); Q_DISABLE_COPY(QTestData) From c3dd4b834a7c51264ecb0f5659f9689cbb7384cb Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 18:32:16 +1000 Subject: [PATCH 40/43] Remove literal tabs Change-Id: I06064f68a0ca23968cec30ccb063dadf2e67571b Reviewed-on: http://codereview.qt.nokia.com/3645 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 161c46e579b..81d2af64fdd 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1273,9 +1273,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QString::fromLatin1(argv[i] + colon + 1); } } else { - if (!QTest::testFuncs) { - QTest::testFuncs = new QTest::TestFunction[512]; - } + if (!QTest::testFuncs) { + QTest::testFuncs = new QTest::TestFunction[512]; + } int colon = -1; char buf[512], *data=0; @@ -1299,8 +1299,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) exit(1); } testFuncs[testFuncCount].set(idx, data); - testFuncCount++; - QTEST_ASSERT(QTest::testFuncCount < 512); + testFuncCount++; + QTEST_ASSERT(QTest::testFuncCount < 512); } } From e99eb3c2c1c276ec70a73a0a8fa8b645301ac82b Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 18:36:59 +1000 Subject: [PATCH 41/43] Remove unused function Change-Id: I04eea17a3674beb59c84e3992f9bb2754f7b3525 Reviewed-on: http://codereview.qt.nokia.com/3646 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 81d2af64fdd..065bd5c3580 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -972,12 +972,6 @@ void seedRandom() } } -int qTestRandomSeed() -{ - Q_ASSERT(QTest::seedSet); - return QTest::seed; -} - template void swap(T * array, int pos, int otherPos) { From a2229efe741aa4b92be2bfb6c3c0310a29baee64 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 26 Aug 2011 18:42:34 +1000 Subject: [PATCH 42/43] Rename COMPARE_IMPL2 to TO_STRING_IMPL. Change-Id: Idbc8c78815f9259c5ecc36fbb053d64f6802c66b Reviewed-on: http://codereview.qt.nokia.com/3649 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 065bd5c3580..a9774599e8b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2187,7 +2187,7 @@ Q_TESTLIB_EXPORT bool QTest::qCompare(double const &t1, double const &t2 toString(t1), toString(t2), actual, expected, file, line); } -#define COMPARE_IMPL2(TYPE, FORMAT) \ +#define TO_STRING_IMPL(TYPE, FORMAT) \ template <> Q_TESTLIB_EXPORT char *QTest::toString(const TYPE &t) \ { \ char *msg = new char[128]; \ @@ -2195,23 +2195,23 @@ template <> Q_TESTLIB_EXPORT char *QTest::toString(const TYPE &t) \ return msg; \ } -COMPARE_IMPL2(short, %hd) -COMPARE_IMPL2(ushort, %hu) -COMPARE_IMPL2(int, %d) -COMPARE_IMPL2(uint, %u) -COMPARE_IMPL2(long, %ld) -COMPARE_IMPL2(ulong, %lu) +TO_STRING_IMPL(short, %hd) +TO_STRING_IMPL(ushort, %hu) +TO_STRING_IMPL(int, %d) +TO_STRING_IMPL(uint, %u) +TO_STRING_IMPL(long, %ld) +TO_STRING_IMPL(ulong, %lu) #if defined(Q_OS_WIN) -COMPARE_IMPL2(qint64, %I64d) -COMPARE_IMPL2(quint64, %I64u) +TO_STRING_IMPL(qint64, %I64d) +TO_STRING_IMPL(quint64, %I64u) #else -COMPARE_IMPL2(qint64, %lld) -COMPARE_IMPL2(quint64, %llu) +TO_STRING_IMPL(qint64, %lld) +TO_STRING_IMPL(quint64, %llu) #endif -COMPARE_IMPL2(bool, %d) -COMPARE_IMPL2(char, %c) -COMPARE_IMPL2(float, %g) -COMPARE_IMPL2(double, %lg) +TO_STRING_IMPL(bool, %d) +TO_STRING_IMPL(char, %c) +TO_STRING_IMPL(float, %g) +TO_STRING_IMPL(double, %lg) /*! \internal */ From d7305c10948f501450b6b3358d261217d13c6d6e Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 29 Aug 2011 11:47:57 +1000 Subject: [PATCH 43/43] Remove the QTEST_NOEXITCODE define. Tests that are expected to return a non-zero exitcode should be marked with "CONFIG+=insignificant_test" in their .pro file. Change-Id: Iebb9c7129c08833ed517115f569086d6fcfe827b Reviewed-on: http://codereview.qt.nokia.com/3689 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- src/testlib/qtestcase.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index a9774599e8b..b6aaa347569 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1891,10 +1891,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) } #endif -#if defined(QTEST_NOEXITCODE) - return 0; -#else - #ifdef QTESTLIB_USE_VALGRIND if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) return callgrindChildExitCode; @@ -1902,8 +1898,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) // make sure our exit code is never going above 127 // since that could wrap and indicate 0 test fails return qMin(QTestResult::failCount(), 127); - -#endif } /*!