summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib.pro1
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp2
-rw-r--r--tests/auto/guiapplauncher/guiapplauncher.pro3
-rw-r--r--tests/auto/macnativeevents/macnativeevents.pro16
-rw-r--r--tests/auto/macnativeevents/qnativeinput.cpp378
-rw-r--r--tests/auto/macnativeevents/qnativeinput.h228
-rw-r--r--tests/auto/macnativeevents/qnativeinput_mac.cpp382
-rw-r--r--tests/auto/macnativeevents/qnativeplayer.cpp139
-rw-r--r--tests/auto/macnativeevents/qnativeplayer.h92
-rw-r--r--tests/auto/macnativeevents/tst_macnativeevents.cpp81
-rw-r--r--tests/auto/network.pro1
-rw-r--r--tests/auto/other.pro1
-rw-r--r--tests/auto/qdatetime/tst_qdatetime.cpp75
-rw-r--r--tests/auto/qdiriterator/tst_qdiriterator.cpp48
-rw-r--r--tests/auto/qelapsedtimer/qelapsedtimer.pro13
-rw-r--r--tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp157
-rw-r--r--tests/auto/qfile/tst_qfile.cpp47
-rw-r--r--tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp25
-rw-r--r--tests/auto/qglthreads/qglthreads.pro3
-rw-r--r--tests/auto/qkeysequence/tst_qkeysequence.cpp52
-rw-r--r--tests/auto/qlocale/tst_qlocale.cpp33
-rw-r--r--tests/auto/qnetworkaccessmanager/qnetworkaccessmanager.pro5
-rw-r--r--tests/auto/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp111
-rw-r--r--tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp8
-rw-r--r--tests/auto/qnetworksession/test/tst_qnetworksession.cpp265
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp19
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp87
-rw-r--r--tests/auto/qshortcut/tst_qshortcut.cpp2
-rw-r--r--tests/auto/qstate/tst_qstate.cpp33
-rw-r--r--tests/auto/qstring/tst_qstring.cpp5
-rw-r--r--tests/auto/qstringlist/tst_qstringlist.cpp10
-rw-r--r--tests/auto/qtextscriptengine/tst_qtextscriptengine.cpp75
-rw-r--r--tests/auto/qtranslator/qtranslator.pro2
-rw-r--r--tests/auto/qtranslator/qtranslator.qrc5
-rw-r--r--tests/auto/qtranslator/tst_qtranslator.cpp19
-rw-r--r--tests/auto/qwidget/qwidget.pro4
-rw-r--r--tests/auto/qwidget_window/qwidget_window.pro3
-rw-r--r--tests/auto/qwizard/tst_qwizard.cpp97
38 files changed, 2469 insertions, 58 deletions
diff --git a/tests/auto/corelib.pro b/tests/auto/corelib.pro
index c08e372..259be4c 100644
--- a/tests/auto/corelib.pro
+++ b/tests/auto/corelib.pro
@@ -24,6 +24,7 @@ SUBDIRS=\
qdebug \
qdiriterator \
qeasingcurve \
+ qelapsedtimer \
qevent \
qexplicitlyshareddatapointer \
qfileinfo \
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index e623df6..febcec3 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -677,7 +677,7 @@ void tst_qdeclarativetextinput::setHAlignClearCache()
view.show();
QApplication::setActiveWindow(&view);
QTest::qWaitForWindowShown(&view);
- QCOMPARE(input.nbPaint, 1);
+ QTRY_COMPARE(input.nbPaint, 1);
input.setHAlign(QDeclarativeTextInput::AlignRight);
QApplication::processEvents();
//Changing the alignment should trigger a repaint
diff --git a/tests/auto/guiapplauncher/guiapplauncher.pro b/tests/auto/guiapplauncher/guiapplauncher.pro
index 2f81061..30f5cf4 100644
--- a/tests/auto/guiapplauncher/guiapplauncher.pro
+++ b/tests/auto/guiapplauncher/guiapplauncher.pro
@@ -16,3 +16,6 @@ HEADERS += windowmanager.h
# process enumeration,etc.
win32:LIBS+=-luser32
+x11 {
+ LIBS += $$QMAKE_LIBS_X11
+}
diff --git a/tests/auto/macnativeevents/macnativeevents.pro b/tests/auto/macnativeevents/macnativeevents.pro
new file mode 100644
index 0000000..a0293d4
--- /dev/null
+++ b/tests/auto/macnativeevents/macnativeevents.pro
@@ -0,0 +1,16 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Wed Nov 29 22:24:47 2006
+######################################################################
+
+load(qttest_p4)
+TEMPLATE = app
+DEPENDPATH += .
+INCLUDEPATH += .
+LIBS += -framework Carbon
+
+HEADERS += qnativeinput.h qnativeplayer.h
+SOURCES += qnativeinput.cpp qnativeplayer.cpp qnativeinput_mac.cpp
+
+SOURCES += tst_macnativeevents.cpp
+
+requires(mac)
diff --git a/tests/auto/macnativeevents/qnativeinput.cpp b/tests/auto/macnativeevents/qnativeinput.cpp
new file mode 100644
index 0000000..c9462a6
--- /dev/null
+++ b/tests/auto/macnativeevents/qnativeinput.cpp
@@ -0,0 +1,378 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnativeinput.h"
+
+QNativeInput::QNativeInput(bool subscribe)
+{
+ if (subscribe)
+ subscribeForNativeEvents();
+}
+
+QNativeInput::~QNativeInput()
+{
+ unsubscribeForNativeEvents();
+}
+
+void QNativeInput::notify(QNativeEvent *event)
+{
+ nativeEvent(event);
+}
+
+void QNativeInput::nativeEvent(QNativeEvent *event)
+{
+ switch (event->id()){
+ case QNativeMouseButtonEvent::eventId:{
+ QNativeMouseButtonEvent *e = static_cast<QNativeMouseButtonEvent *>(event);
+ (e->clickCount > 0) ? nativeMousePressEvent(e) : nativeMouseReleaseEvent(e);
+ break; }
+ case QNativeMouseMoveEvent::eventId:
+ nativeMouseMoveEvent(static_cast<QNativeMouseMoveEvent *>(event));
+ break;
+ case QNativeMouseDragEvent::eventId:
+ nativeMouseDragEvent(static_cast<QNativeMouseDragEvent *>(event));
+ break;
+ case QNativeMouseWheelEvent::eventId:
+ nativeMouseWheelEvent(static_cast<QNativeMouseWheelEvent *>(event));
+ break;
+ case QNativeKeyEvent::eventId:{
+ QNativeKeyEvent *e = static_cast<QNativeKeyEvent *>(event);
+ e->press ? nativeKeyPressEvent(e) : nativeKeyReleaseEvent(e);
+ break; }
+ case QNativeModifierEvent::eventId:
+ nativeModifierEvent(static_cast<QNativeModifierEvent *>(event));
+ break;
+ default:
+ break;
+ }
+}
+
+Qt::Native::Status QNativeInput::sendNativeEvent(const QNativeEvent &event, int pid)
+{
+ switch (event.id()){
+ case QNativeMouseMoveEvent::eventId:
+ return sendNativeMouseMoveEvent(static_cast<const QNativeMouseMoveEvent &>(event));
+ case QNativeMouseButtonEvent::eventId:
+ return sendNativeMouseButtonEvent(static_cast<const QNativeMouseButtonEvent &>(event));
+ case QNativeMouseDragEvent::eventId:
+ return sendNativeMouseDragEvent(static_cast<const QNativeMouseDragEvent &>(event));
+ case QNativeMouseWheelEvent::eventId:
+ return sendNativeMouseWheelEvent(static_cast<const QNativeMouseWheelEvent &>(event));
+ case QNativeKeyEvent::eventId:
+ return sendNativeKeyEvent(static_cast<const QNativeKeyEvent &>(event), pid);
+ case QNativeModifierEvent::eventId:
+ return sendNativeModifierEvent(static_cast<const QNativeModifierEvent &>(event));
+ case QNativeEvent::eventId:
+ qWarning() << "Warning: Cannot send a pure native event. Use a sub class.";
+ default:
+ return Qt::Native::Failure;
+ }
+}
+
+QNativeEvent::QNativeEvent(Qt::KeyboardModifiers modifiers)
+ : modifiers(modifiers){}
+
+QNativeMouseEvent::QNativeMouseEvent(QPoint pos, Qt::KeyboardModifiers modifiers)
+ : QNativeEvent(modifiers), globalPos(pos){}
+
+QNativeMouseMoveEvent::QNativeMouseMoveEvent(QPoint pos, Qt::KeyboardModifiers modifiers)
+ : QNativeMouseEvent(pos, modifiers){}
+
+QNativeMouseButtonEvent::QNativeMouseButtonEvent(QPoint globalPos, Qt::MouseButton button, int clickCount, Qt::KeyboardModifiers modifiers)
+ : QNativeMouseEvent(globalPos, modifiers), button(button), clickCount(clickCount){}
+
+QNativeMouseDragEvent::QNativeMouseDragEvent(QPoint globalPos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers)
+ : QNativeMouseButtonEvent(globalPos, button, true, modifiers){}
+
+QNativeMouseWheelEvent::QNativeMouseWheelEvent(QPoint globalPos, int delta, Qt::KeyboardModifiers modifiers)
+ : QNativeMouseEvent(globalPos, modifiers), delta(delta){}
+
+QNativeKeyEvent::QNativeKeyEvent(int nativeKeyCode, bool press, Qt::KeyboardModifiers modifiers)
+ : QNativeEvent(modifiers), nativeKeyCode(nativeKeyCode), press(press), character(QChar()){}
+
+QNativeModifierEvent::QNativeModifierEvent(Qt::KeyboardModifiers modifiers, int nativeKeyCode)
+ : QNativeEvent(modifiers), nativeKeyCode(nativeKeyCode){}
+
+QNativeKeyEvent::QNativeKeyEvent(int nativeKeyCode, bool press, QChar character, Qt::KeyboardModifiers modifiers)
+ : QNativeEvent(modifiers), nativeKeyCode(nativeKeyCode), press(press), character(character){}
+
+static QString getButtonAsString(const QNativeMouseButtonEvent *e)
+{
+ switch (e->button){
+ case Qt::LeftButton:
+ return "button = LeftButton";
+ break;
+ case Qt::RightButton:
+ return "button = RightButton";
+ break;
+ case Qt::MidButton:
+ return "button = MidButton";
+ break;
+ default:
+ return "button = Other";
+ break;
+ }
+}
+
+static QString getModifiersAsString(const QNativeEvent *e)
+{
+ if (e->modifiers == 0)
+ return "modifiers = none";
+
+ QString tmp = "modifiers = ";
+ if (e->modifiers.testFlag(Qt::ShiftModifier))
+ tmp += "Shift";
+ if (e->modifiers.testFlag(Qt::ControlModifier))
+ tmp += "Control";
+ if (e->modifiers.testFlag(Qt::AltModifier))
+ tmp += "Alt";
+ if (e->modifiers.testFlag(Qt::MetaModifier))
+ tmp += "Meta";
+ return tmp;
+}
+
+static QString getPosAsString(QPoint pos)
+{
+ return QString("QPoint(%1, %2)").arg(pos.x()).arg(pos.y());
+}
+
+static QString getBoolAsString(bool b)
+{
+ return b ? QString("true") : QString("false");
+}
+
+QString QNativeMouseMoveEvent::toString() const
+{
+ return QString("QNativeMouseMoveEvent(globalPos = %1 %2)").arg(getPosAsString(globalPos))
+ .arg(getModifiersAsString(this));
+}
+
+QString QNativeMouseButtonEvent::toString() const
+{
+ return QString("QNativeMouseButtonEvent(globalPos = %1, %2, clickCount = %3, %4)").arg(getPosAsString(globalPos))
+ .arg(getButtonAsString(this)).arg(clickCount).arg(getModifiersAsString(this));
+}
+
+QString QNativeMouseDragEvent::toString() const
+{
+ return QString("QNativeMouseDragEvent(globalPos = %1, %2, clickCount = %3, %4)").arg(getPosAsString(globalPos))
+ .arg(getButtonAsString(this)).arg(clickCount).arg(getModifiersAsString(this));
+}
+
+QString QNativeMouseWheelEvent::toString() const
+{
+ return QString("QNativeMouseWheelEvent(globalPos = %1, delta = %2, %3)").arg(getPosAsString(globalPos))
+ .arg(delta).arg(getModifiersAsString(this));
+}
+
+QString QNativeKeyEvent::toString() const
+{
+ return QString("QNativeKeyEvent(press = %1, native key code = %2, character = %3, %4)").arg(getBoolAsString(press))
+ .arg(nativeKeyCode).arg(character.isPrint() ? character : QString("<no char>"))
+ .arg(getModifiersAsString(this));
+}
+
+QString QNativeModifierEvent::toString() const
+{
+ return QString("QNativeModifierEvent(%1, native key code = %2)").arg(getModifiersAsString(this))
+ .arg(nativeKeyCode);
+}
+
+QDebug operator<<(QDebug d, QNativeEvent *e)
+{
+ Q_UNUSED(e);
+ return d << e->toString();
+}
+
+QDebug operator<<(QDebug d, const QNativeEvent &e)
+{
+ Q_UNUSED(e);
+ return d << e.toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeEvent *e)
+{
+ return s << e->eventId << " " << e->modifiers << " QNativeEvent";
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeMouseEvent *e)
+{
+ return s << e->eventId << " " << e->globalPos.x() << " " << e->globalPos.y() << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeMouseMoveEvent *e)
+{
+ return s << e->eventId << " " << e->globalPos.x() << " " << e->globalPos.y() << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeMouseButtonEvent *e)
+{
+ return s << e->eventId << " " << e->globalPos.x() << " " << e->globalPos.y() << " " << e->button
+ << " " << e->clickCount << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeMouseDragEvent *e)
+{
+ return s << e->eventId << " " << e->globalPos.x() << " " << e->globalPos.y() << " " << e->button << " " << e->clickCount
+ << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeMouseWheelEvent *e)
+{
+ return s << e->eventId << " " << e->globalPos.x() << " " << e->globalPos.y() << " " << e->delta
+ << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeKeyEvent *e)
+{
+ return s << e->eventId << " " << e->press << " " << e->nativeKeyCode << " " << e->character
+ << " " << e->modifiers << " " << e->toString();
+}
+
+QTextStream &operator<<(QTextStream &s, QNativeModifierEvent *e)
+{
+ return s << e->eventId << " " << e->modifiers << " " << e->nativeKeyCode << " " << e->toString();
+}
+
+
+
+
+QTextStream &operator>>(QTextStream &s, QNativeMouseMoveEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int x, y, modifiers;
+ s >> x >> y >> modifiers >> humanReadable;
+ e->globalPos.setX(x);
+ e->globalPos.setY(y);
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ return s;
+}
+
+QTextStream &operator>>(QTextStream &s, QNativeMouseButtonEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int x, y, button, clickCount, modifiers;
+ s >> x >> y >> button >> clickCount >> modifiers >> humanReadable;
+ e->globalPos.setX(x);
+ e->globalPos.setY(y);
+ e->clickCount = clickCount;
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ switch (button){
+ case 1:
+ e->button = Qt::LeftButton;
+ break;
+ case 2:
+ e->button = Qt::RightButton;
+ break;
+ case 3:
+ e->button = Qt::MidButton;
+ break;
+ default:
+ e->button = Qt::NoButton;
+ break;
+ }
+ return s;
+}
+
+QTextStream &operator>>(QTextStream &s, QNativeMouseDragEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int x, y, button, clickCount, modifiers;
+ s >> x >> y >> button >> clickCount >> modifiers >> humanReadable;
+ e->globalPos.setX(x);
+ e->globalPos.setY(y);
+ e->clickCount = clickCount;
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ switch (button){
+ case 1:
+ e->button = Qt::LeftButton;
+ break;
+ case 2:
+ e->button = Qt::RightButton;
+ break;
+ case 3:
+ e->button = Qt::MidButton;
+ break;
+ default:
+ e->button = Qt::NoButton;
+ break;
+ }
+ return s;
+}
+
+QTextStream &operator>>(QTextStream &s, QNativeMouseWheelEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int x, y, modifiers;
+ s >> x >> y >> e->delta >> modifiers >> humanReadable;
+ e->globalPos.setX(x);
+ e->globalPos.setY(y);
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ return s;
+}
+
+QTextStream &operator>>(QTextStream &s, QNativeKeyEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int press, modifiers;
+ QString character;
+ s >> press >> e->nativeKeyCode >> character >> modifiers >> humanReadable;
+ e->press = bool(press);
+ e->character = character[0];
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ return s;
+}
+
+QTextStream &operator>>(QTextStream &s, QNativeModifierEvent *e)
+{
+ // Skip reading eventId.
+ QString humanReadable;
+ int modifiers;
+ s >> modifiers >> e->nativeKeyCode >> humanReadable;
+ e->modifiers = Qt::KeyboardModifiers(modifiers);
+ return s;
+}
+
diff --git a/tests/auto/macnativeevents/qnativeinput.h b/tests/auto/macnativeevents/qnativeinput.h
new file mode 100644
index 0000000..a98e4e4
--- /dev/null
+++ b/tests/auto/macnativeevents/qnativeinput.h
@@ -0,0 +1,228 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef Q_NATIVE_INPUT
+#define Q_NATIVE_INPUT
+
+#include <QtCore>
+
+namespace Qt {
+namespace Native {
+ enum Status {Success, Failure};
+}}
+
+// ----------------------------------------------------------------------------
+// Declare a set of native events that can be used to communicate with
+// client applications in an platform independent way
+// ----------------------------------------------------------------------------
+
+class QNativeEvent
+{
+public:
+ static const int eventId = 1;
+
+ QNativeEvent(Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const = 0;
+ Qt::KeyboardModifiers modifiers; // Yields for mouse events too.
+};
+
+class QNativeMouseEvent : public QNativeEvent {
+public:
+ static const int eventId = 2;
+
+ QNativeMouseEvent(){};
+ QNativeMouseEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeMouseEvent(){};
+ virtual int id() const { return eventId; };
+
+ QPoint globalPos;
+};
+
+class QNativeMouseMoveEvent : public QNativeMouseEvent {
+public:
+ static const int eventId = 4;
+
+ QNativeMouseMoveEvent(){};
+ QNativeMouseMoveEvent(QPoint globalPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeMouseMoveEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+};
+
+class QNativeMouseButtonEvent : public QNativeMouseEvent {
+public:
+ static const int eventId = 8;
+
+ QNativeMouseButtonEvent(){};
+ QNativeMouseButtonEvent(QPoint globalPos, Qt::MouseButton button, int clickCount, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeMouseButtonEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+
+ Qt::MouseButton button;
+ int clickCount;
+};
+
+class QNativeMouseDragEvent : public QNativeMouseButtonEvent {
+public:
+ static const int eventId = 16;
+
+ QNativeMouseDragEvent(){};
+ QNativeMouseDragEvent(QPoint globalPos, Qt::MouseButton button, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeMouseDragEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+};
+
+class QNativeMouseWheelEvent : public QNativeMouseEvent {
+public:
+ static const int eventId = 32;
+
+ QNativeMouseWheelEvent(){};
+ QNativeMouseWheelEvent(QPoint globalPos, int delta, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ virtual ~QNativeMouseWheelEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+
+ int delta;
+};
+
+class QNativeKeyEvent : public QNativeEvent {
+ public:
+ static const int eventId = 64;
+
+ QNativeKeyEvent(){};
+ QNativeKeyEvent(int nativeKeyCode, bool press, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
+ QNativeKeyEvent(int nativeKeyCode, bool press, QChar character, Qt::KeyboardModifiers modifiers);
+ virtual ~QNativeKeyEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+
+ int nativeKeyCode;
+ bool press;
+ QChar character;
+
+ // Some Qt to Native mappings:
+ static int Key_A;
+ static int Key_B;
+ static int Key_C;
+ static int Key_1;
+ static int Key_Backspace;
+ static int Key_Enter;
+ static int Key_Del;
+};
+
+class QNativeModifierEvent : public QNativeEvent {
+public:
+ static const int eventId = 128;
+
+ QNativeModifierEvent(Qt::KeyboardModifiers modifiers = Qt::NoModifier, int nativeKeyCode = 0);
+ virtual ~QNativeModifierEvent(){};
+ virtual int id() const { return eventId; };
+ virtual QString toString() const;
+
+ int nativeKeyCode;
+};
+
+// ----------------------------------------------------------------------------
+// Declare a set of related output / input functions for convenience:
+// ----------------------------------------------------------------------------
+
+QDebug operator<<(QDebug d, QNativeEvent *e);
+QDebug operator<<(QDebug d, const QNativeEvent &e);
+
+QTextStream &operator<<(QTextStream &s, QNativeEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeMouseEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeMouseMoveEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeMouseButtonEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeMouseDragEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeMouseWheelEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeKeyEvent *e);
+QTextStream &operator<<(QTextStream &s, QNativeModifierEvent *e);
+
+QTextStream &operator>>(QTextStream &s, QNativeMouseMoveEvent *e);
+QTextStream &operator>>(QTextStream &s, QNativeMouseButtonEvent *e);
+QTextStream &operator>>(QTextStream &s, QNativeMouseDragEvent *e);
+QTextStream &operator>>(QTextStream &s, QNativeMouseWheelEvent *e);
+QTextStream &operator>>(QTextStream &s, QNativeKeyEvent *e);
+QTextStream &operator>>(QTextStream &s, QNativeModifierEvent *e);
+
+// ----------------------------------------------------------------------------
+// Declare the main class that is supposed to be sub-classed by components
+// that are to receive native events
+// ----------------------------------------------------------------------------
+
+class QNativeInput
+{
+ public:
+ QNativeInput(bool subscribe = true);
+ virtual ~QNativeInput();
+
+ // Callback methods. Should be implemented by interested sub-classes:
+ void notify(QNativeEvent *event);
+ virtual void nativeEvent(QNativeEvent *event);
+ virtual void nativeMousePressEvent(QNativeMouseButtonEvent *){};
+ virtual void nativeMouseReleaseEvent(QNativeMouseButtonEvent *){};
+ virtual void nativeMouseMoveEvent(QNativeMouseMoveEvent *){};
+ virtual void nativeMouseDragEvent(QNativeMouseDragEvent *){};
+ virtual void nativeMouseWheelEvent(QNativeMouseWheelEvent *){};
+ virtual void nativeKeyPressEvent(QNativeKeyEvent *){};
+ virtual void nativeKeyReleaseEvent(QNativeKeyEvent *){};
+ virtual void nativeModifierEvent(QNativeModifierEvent *){};
+
+ // The following methods will differ in implementation from OS to OS:
+ static Qt::Native::Status sendNativeMouseButtonEvent(const QNativeMouseButtonEvent &event);
+ static Qt::Native::Status sendNativeMouseMoveEvent(const QNativeMouseMoveEvent &event);
+ static Qt::Native::Status sendNativeMouseDragEvent(const QNativeMouseDragEvent &event);
+ static Qt::Native::Status sendNativeMouseWheelEvent(const QNativeMouseWheelEvent &event);
+ static Qt::Native::Status sendNativeKeyEvent(const QNativeKeyEvent &event, int pid = 0);
+ static Qt::Native::Status sendNativeModifierEvent(const QNativeModifierEvent &event);
+ // sendNativeEvent will NOT differ from OS to OS.
+ static Qt::Native::Status sendNativeEvent(const QNativeEvent &event, int pid = 0);
+
+ // The following methods will differ in implementation from OS to OS:
+ Qt::Native::Status subscribeForNativeEvents();
+ Qt::Native::Status unsubscribeForNativeEvents();
+};
+
+#endif // Q_NATIVE_INPUT
diff --git a/tests/auto/macnativeevents/qnativeinput_mac.cpp b/tests/auto/macnativeevents/qnativeinput_mac.cpp
new file mode 100644
index 0000000..143a633
--- /dev/null
+++ b/tests/auto/macnativeevents/qnativeinput_mac.cpp
@@ -0,0 +1,382 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnativeinput.h"
+#include <Carbon/Carbon.h>
+#include <QtCore>
+
+// ************************************************************
+// Quartz
+// ************************************************************
+
+static Qt::KeyboardModifiers getModifiersFromQuartzEvent(CGEventRef inEvent)
+{
+ Qt::KeyboardModifiers m;
+ CGEventFlags flags = CGEventGetFlags(inEvent);
+ if (flags & kCGEventFlagMaskShift || flags & kCGEventFlagMaskAlphaShift)
+ m |= Qt::ShiftModifier;
+ if (flags & kCGEventFlagMaskControl)
+ m |= Qt::MetaModifier;
+ if (flags & kCGEventFlagMaskAlternate)
+ m |= Qt::AltModifier;
+ if (flags & kCGEventFlagMaskCommand)
+ m |= Qt::ControlModifier;
+ return m;
+}
+
+static void setModifiersFromQNativeEvent(CGEventRef inEvent, const QNativeEvent &event)
+{
+ CGEventFlags flags = 0;
+ if (event.modifiers.testFlag(Qt::ShiftModifier))
+ flags |= kCGEventFlagMaskShift;
+ if (event.modifiers.testFlag(Qt::MetaModifier))
+ flags |= kCGEventFlagMaskControl;
+ if (event.modifiers.testFlag(Qt::AltModifier))
+ flags |= kCGEventFlagMaskAlternate;
+ if (event.modifiers.testFlag(Qt::ControlModifier))
+ flags |= kCGEventFlagMaskCommand;
+ CGEventSetFlags(inEvent, flags);
+}
+
+static QPoint getMouseLocationFromQuartzEvent(CGEventRef inEvent)
+{
+ CGPoint pos = CGEventGetLocation(inEvent);
+ QPoint tmp;
+ tmp.setX(pos.x);
+ tmp.setY(pos.y);
+ return tmp;
+}
+
+static QChar getCharFromQuartzEvent(CGEventRef inEvent)
+{
+ UniCharCount count = 0;
+ UniChar c;
+ CGEventKeyboardGetUnicodeString(inEvent, 1, &count, &c);
+ return QChar(c);
+}
+
+static CGEventRef EventHandler_Quartz(CGEventTapProxy proxy, CGEventType type, CGEventRef inEvent, void *refCon)
+{
+ Q_UNUSED(proxy);
+ QNativeInput *nativeInput = static_cast<QNativeInput *>(refCon);
+ switch (type){
+ case kCGEventKeyDown:{
+ QNativeKeyEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.nativeKeyCode = CGEventGetIntegerValueField(inEvent, kCGKeyboardEventKeycode);
+ e.character = getCharFromQuartzEvent(inEvent);
+ e.press = true;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventKeyUp:{
+ QNativeKeyEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.nativeKeyCode = CGEventGetIntegerValueField(inEvent, kCGKeyboardEventKeycode);
+ e.character = getCharFromQuartzEvent(inEvent);
+ e.press = false;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventLeftMouseDown:{
+ QNativeMouseButtonEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ e.clickCount = CGEventGetIntegerValueField(inEvent, kCGMouseEventClickState);
+ e.button = Qt::LeftButton;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventLeftMouseUp:{
+ QNativeMouseButtonEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ e.clickCount = 0;
+ e.button = Qt::LeftButton;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventRightMouseDown:{
+ QNativeMouseButtonEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ e.clickCount = CGEventGetIntegerValueField(inEvent, kCGMouseEventClickState);
+ e.button = Qt::RightButton;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventRightMouseUp:{
+ QNativeMouseButtonEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ e.clickCount = 0;
+ e.button = Qt::RightButton;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventMouseMoved:{
+ QNativeMouseMoveEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventLeftMouseDragged:{
+ QNativeMouseDragEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ e.clickCount = CGEventGetIntegerValueField(inEvent, kCGMouseEventClickState);
+ e.button = Qt::LeftButton;
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventScrollWheel:{
+ QNativeMouseWheelEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.delta = CGEventGetIntegerValueField(inEvent, kCGScrollWheelEventDeltaAxis1);
+ e.globalPos = getMouseLocationFromQuartzEvent(inEvent);
+ nativeInput->notify(&e);
+ break;
+ }
+ case kCGEventFlagsChanged:{
+ QNativeModifierEvent e;
+ e.modifiers = getModifiersFromQuartzEvent(inEvent);
+ e.nativeKeyCode = CGEventGetIntegerValueField(inEvent, kCGKeyboardEventKeycode);
+ nativeInput->notify(&e);
+ break;
+ }
+
+ }
+
+ return inEvent;
+}
+
+Qt::Native::Status insertEventHandler_Quartz(QNativeInput *nativeInput, int pid = 0)
+{
+ uid_t uid = geteuid();
+ if (uid != 0)
+ qWarning("MacNativeEvents: You must be root to listen for key events!");
+
+ CFMachPortRef port;
+ if (!pid){
+ port = CGEventTapCreate(kCGHIDEventTap,
+ kCGHeadInsertEventTap, kCGEventTapOptionListenOnly,
+ kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput);
+ } else {
+ ProcessSerialNumber psn;
+ GetProcessForPID(pid, &psn);
+ port = CGEventTapCreateForPSN(&psn,
+ kCGHeadInsertEventTap, kCGEventTapOptionListenOnly,
+ kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput);
+ }
+
+ CFRunLoopSourceRef eventSrc = CFMachPortCreateRunLoopSource(NULL, port, 0);
+ CFRunLoopAddSource((CFRunLoopRef) GetCFRunLoopFromEventLoop(GetMainEventLoop()),
+ eventSrc, kCFRunLoopCommonModes);
+
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status removeEventHandler_Quartz()
+{
+ return Qt::Native::Success; // ToDo:
+}
+
+Qt::Native::Status sendNativeKeyEventToProcess_Quartz(const QNativeKeyEvent &event, int pid)
+{
+ ProcessSerialNumber psn;
+ GetProcessForPID(pid, &psn);
+
+ CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, event.press);
+ setModifiersFromQNativeEvent(e, event);
+ SetFrontProcess(&psn);
+ CGEventPostToPSN(&psn, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeKeyEvent_Quartz(const QNativeKeyEvent &event)
+{
+ CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, event.press);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeMouseMoveEvent_Quartz(const QNativeMouseMoveEvent &event)
+{
+ CGPoint pos;
+ pos.x = event.globalPos.x();
+ pos.y = event.globalPos.y();
+
+ CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeMouseButtonEvent_Quartz(const QNativeMouseButtonEvent &event)
+{
+ CGPoint pos;
+ pos.x = event.globalPos.x();
+ pos.y = event.globalPos.y();
+
+ CGEventType type = 0;
+ if (event.button == Qt::LeftButton)
+ type = (event.clickCount > 0) ? kCGEventLeftMouseDown : kCGEventLeftMouseUp;
+ else if (event.button == Qt::RightButton)
+ type = (event.clickCount > 0) ? kCGEventRightMouseDown : kCGEventRightMouseUp;
+ else
+ type = (event.clickCount > 0) ? kCGEventOtherMouseDown : kCGEventOtherMouseUp;
+
+ CGEventRef e = CGEventCreateMouseEvent(0, type, pos, event.button);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventSetIntegerValueField(e, kCGMouseEventClickState, event.clickCount);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeMouseDragEvent_Quartz(const QNativeMouseDragEvent &event)
+{
+ CGPoint pos;
+ pos.x = event.globalPos.x();
+ pos.y = event.globalPos.y();
+
+ CGEventType type = 0;
+ if (event.button == Qt::LeftButton)
+ type = kCGEventLeftMouseDragged;
+ else if (event.button == Qt::RightButton)
+ type = kCGEventRightMouseDragged;
+ else
+ type = kCGEventOtherMouseDragged;
+
+ CGEventRef e = CGEventCreateMouseEvent(0, type, pos, event.button);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeMouseWheelEvent_Quartz(const QNativeMouseWheelEvent &event)
+{
+ CGPoint pos;
+ pos.x = event.globalPos.x();
+ pos.y = event.globalPos.y();
+
+ CGEventRef e = CGEventCreateScrollWheelEvent(0, kCGScrollEventUnitPixel, 1, 0);
+ CGEventSetIntegerValueField(e, kCGScrollWheelEventDeltaAxis1, event.delta);
+ CGEventSetLocation(e, pos);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+
+ return Qt::Native::Success;
+}
+
+Qt::Native::Status sendNativeModifierEvent_Quartz(const QNativeModifierEvent &event)
+{
+ CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, 0);
+ CGEventSetType(e, kCGEventFlagsChanged);
+ setModifiersFromQNativeEvent(e, event);
+ CGEventPost(kCGHIDEventTap, e);
+ CFRelease(e);
+ return Qt::Native::Success;
+}
+
+// ************************************************************
+// QNativeInput methods:
+// ************************************************************
+
+Qt::Native::Status QNativeInput::sendNativeMouseButtonEvent(const QNativeMouseButtonEvent &event)
+{
+ return sendNativeMouseButtonEvent_Quartz(event);
+}
+
+Qt::Native::Status QNativeInput::sendNativeMouseMoveEvent(const QNativeMouseMoveEvent &event)
+{
+ return sendNativeMouseMoveEvent_Quartz(event);
+}
+
+Qt::Native::Status QNativeInput::sendNativeMouseDragEvent(const QNativeMouseDragEvent &event)
+{
+ return sendNativeMouseDragEvent_Quartz(event);
+}
+
+Qt::Native::Status QNativeInput::sendNativeMouseWheelEvent(const QNativeMouseWheelEvent &event)
+{
+ return sendNativeMouseWheelEvent_Quartz(event);
+}
+
+Qt::Native::Status QNativeInput::sendNativeKeyEvent(const QNativeKeyEvent &event, int pid)
+{
+ if (!pid)
+ return sendNativeKeyEvent_Quartz(event);
+ else
+ return sendNativeKeyEventToProcess_Quartz(event, pid);
+}
+
+Qt::Native::Status QNativeInput::sendNativeModifierEvent(const QNativeModifierEvent &event)
+{
+ return sendNativeModifierEvent_Quartz(event);
+}
+
+Qt::Native::Status QNativeInput::subscribeForNativeEvents()
+{
+ return insertEventHandler_Quartz(this);
+}
+
+Qt::Native::Status QNativeInput::unsubscribeForNativeEvents()
+{
+ return removeEventHandler_Quartz();
+}
+
+// Some Qt to Mac mappings:
+int QNativeKeyEvent::Key_A = 0;
+int QNativeKeyEvent::Key_B = 11;
+int QNativeKeyEvent::Key_C = 8;
+int QNativeKeyEvent::Key_1 = 18;
+int QNativeKeyEvent::Key_Backspace = 51;
+int QNativeKeyEvent::Key_Enter = 36;
+int QNativeKeyEvent::Key_Del = 117;
+
diff --git a/tests/auto/macnativeevents/qnativeplayer.cpp b/tests/auto/macnativeevents/qnativeplayer.cpp
new file mode 100644
index 0000000..92298ef
--- /dev/null
+++ b/tests/auto/macnativeevents/qnativeplayer.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnativeplayer.h"
+
+QNativePlayer::QNativePlayer()
+{
+ currIndex = -1;
+ playbackMultiplier = 1.0;
+ wait = false;
+}
+
+QNativePlayer::~QNativePlayer()
+{
+ for (int i=0; i<eventList.size(); i++)
+ delete eventList.takeAt(i).second;
+}
+
+void QNativePlayer::sendNextEvent()
+{
+ QNativeEvent *e = eventList.at(currIndex).second;
+ if (e)
+ QNativeInput::sendNativeEvent(*e);
+ waitNextEvent();
+}
+
+void QNativePlayer::waitNextEvent()
+{
+ if (++currIndex >= eventList.size()){
+ emit done();
+ stop();
+ return;
+ }
+
+ int interval = eventList.at(currIndex).first;
+ QTimer::singleShot(interval * playbackMultiplier, this, SLOT(sendNextEvent()));
+}
+
+void QNativePlayer::append(int waitMs, QNativeEvent *event)
+{
+ eventList.append(QPair<int, QNativeEvent *>(waitMs, event));
+}
+
+void QNativePlayer::play(Playback playback)
+{
+ waitNextEvent();
+
+ wait = (playback == WaitUntilFinished);
+ while (wait)
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+}
+
+void QNativePlayer::stop()
+{
+ wait = false;
+ QAbstractEventDispatcher::instance()->interrupt();
+}
+
+// ************************************************************************
+
+QEventOutputList::QEventOutputList()
+{
+ wait = true;
+}
+
+QEventOutputList::~QEventOutputList()
+{
+ qDeleteAll(*this);
+}
+
+bool QEventOutputList::waitUntilEmpty(int maxEventWaitTime)
+{
+ int currSize = size();
+ QTime time;
+ time.restart();
+ while (wait){
+ QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
+
+ if (isEmpty()){
+ return true;
+ }
+ else if (currSize == size()){
+ if (time.elapsed() > maxEventWaitTime){
+ return false;
+ }
+ }
+ else{
+ currSize = size();
+ time.restart();
+ }
+ }
+ return false;
+}
+
+void QEventOutputList::sleep(int sleepTime)
+{
+ QTime time;
+ time.restart();
+ while (time.elapsed() < sleepTime)
+ QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
+}
diff --git a/tests/auto/macnativeevents/qnativeplayer.h b/tests/auto/macnativeevents/qnativeplayer.h
new file mode 100644
index 0000000..61ee162
--- /dev/null
+++ b/tests/auto/macnativeevents/qnativeplayer.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef Q_NATIVE_PLAYBACK
+#define Q_NATIVE_PLAYBACK
+
+#include <QtCore>
+#include "qnativeinput.h"
+
+class QNativePlayer : public QObject
+{
+ Q_OBJECT;
+
+ public:
+ enum Playback {ReturnImmediately, WaitUntilFinished};
+
+ QNativePlayer();
+ ~QNativePlayer();
+
+ void append(int waitMs, QNativeEvent *event = 0);
+ void play(Playback playback = WaitUntilFinished);
+ void stop();
+ float playbackMultiplier;
+
+signals:
+ void done();
+
+private slots:
+ void sendNextEvent();
+
+ private:
+ void waitNextEvent();
+
+ QList<QPair<int, QNativeEvent *> > eventList;
+ int currIndex;
+ bool wait;
+};
+
+// ******************************************************************
+
+class QEventOutputList : public QList<QEvent *>
+{
+public:
+ QEventOutputList();
+ ~QEventOutputList();
+ bool waitUntilEmpty(int maxEventWaitTime = 1000);
+ bool wait;
+
+ // Useful method. Just sleep and process events:
+ static void sleep(int sleepTime);
+};
+
+
+#endif
diff --git a/tests/auto/macnativeevents/tst_macnativeevents.cpp b/tests/auto/macnativeevents/tst_macnativeevents.cpp
new file mode 100644
index 0000000..ccadd54
--- /dev/null
+++ b/tests/auto/macnativeevents/tst_macnativeevents.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QWidget>
+#include <QPushButton>
+#include <QtTest/QtTest>
+
+#include "qnativeinput.h"
+#include "qnativeplayer.h"
+
+#ifdef Q_OS_MAC
+
+QT_USE_NAMESPACE
+
+class tst_MacNativeEvents : public QObject
+{
+Q_OBJECT
+private slots:
+ void testLeftMousePressRelease();
+};
+
+void tst_MacNativeEvents::testLeftMousePressRelease()
+{
+ QPushButton w("click me");
+ w.show();
+ QPoint p = w.geometry().center();
+
+ QNativePlayer player;
+ player.append(50, new QNativeMouseButtonEvent(p, Qt::LeftButton, 1, Qt::NoModifier));
+ player.append(50, new QNativeMouseButtonEvent(p, Qt::LeftButton, 0, Qt::NoModifier));
+ player.play();
+}
+
+#include "tst_macnativeevents.moc"
+
+QTEST_MAIN(tst_MacNativeEvents)
+
+#else
+
+QTEST_NOOP_MAIN
+
+#endif
diff --git a/tests/auto/network.pro b/tests/auto/network.pro
index dbefa91..4f205fe 100644
--- a/tests/auto/network.pro
+++ b/tests/auto/network.pro
@@ -16,6 +16,7 @@ SUBDIRS=\
qhttpnetworkreply \
qhttpsocketengine \
qnativesocketengine \
+ qnetworkaccessmanager \
qnetworkaddressentry \
qnetworkconfiguration \
qnetworkconfigurationmanager \
diff --git a/tests/auto/other.pro b/tests/auto/other.pro
index e220d1a..3c8f856 100644
--- a/tests/auto/other.pro
+++ b/tests/auto/other.pro
@@ -37,6 +37,7 @@ SUBDIRS=\
contains(QT_CONFIG, OdfWriter):SUBDIRS += qzip qtextodfwriter
mac: {
SUBDIRS += macgui \
+ macnativeevents \
macplist \
qaccessibility_mac
}
diff --git a/tests/auto/qdatetime/tst_qdatetime.cpp b/tests/auto/qdatetime/tst_qdatetime.cpp
index 86a4c80..a6b9a5f 100644
--- a/tests/auto/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/qdatetime/tst_qdatetime.cpp
@@ -106,6 +106,8 @@ private slots:
void secsTo();
void operator_eqeq();
void currentDateTime();
+ void currentDateTimeUtc();
+ void currentDateTimeUtc2();
void fromStringTextDate_data();
void fromStringTextDate();
@@ -880,6 +882,79 @@ void tst_QDateTime::currentDateTime()
QVERIFY(dt3.timeSpec() == Qt::UTC);
}
+void tst_QDateTime::currentDateTimeUtc()
+{
+#if defined(Q_OS_WINCE)
+ __time64_t buf1, buf2;
+ ::_time64(&buf1);
+#else
+ time_t buf1, buf2;
+ ::time(&buf1);
+#endif
+ QDateTime lowerBound;
+ lowerBound.setTime_t(buf1);
+
+ QDateTime dt1 = QDateTime::currentDateTimeUtc();
+ QDateTime dt2 = QDateTime::currentDateTimeUtc().toLocalTime();
+ QDateTime dt3 = QDateTime::currentDateTimeUtc().toUTC();
+
+#if defined(Q_OS_WINCE)
+ ::_time64(&buf2);
+#else
+ ::time(&buf2);
+#endif
+ QDateTime upperBound;
+ upperBound.setTime_t(buf2);
+ upperBound = upperBound.addSecs(1);
+
+ QVERIFY(lowerBound < upperBound);
+
+ QVERIFY(lowerBound <= dt1);
+ QVERIFY(dt1 < upperBound);
+ QVERIFY(lowerBound <= dt2);
+ QVERIFY(dt2 < upperBound);
+ QVERIFY(lowerBound <= dt3);
+ QVERIFY(dt3 < upperBound);
+
+ QVERIFY(dt1.timeSpec() == Qt::UTC);
+ QVERIFY(dt2.timeSpec() == Qt::LocalTime);
+ QVERIFY(dt3.timeSpec() == Qt::UTC);
+}
+
+void tst_QDateTime::currentDateTimeUtc2()
+{
+ QDateTime local, utc;
+ qint64 msec;
+
+ // check that we got all down to the same milliseconds
+ int i = 2;
+ bool ok = false;
+ do {
+ local = QDateTime::currentDateTime();
+ utc = QDateTime::currentDateTimeUtc();
+ msec = QDateTime::currentMsecsSinceEpoch();
+ ok = local.time().msec() == utc.time().msec()
+ && utc.time().msec() == (msec % 1000);
+ } while (--i && !ok);
+
+ if (!i)
+ QSKIP("Failed to get the dates within 1 ms of each other", SkipAll);
+
+ // seconds and milliseconds should be the same:
+ QCOMPARE(utc.time().second(), local.time().second());
+ QCOMPARE(utc.time().msec(), local.time().msec());
+ QCOMPARE(msec % 1000, qint64(local.time().msec()));
+ QCOMPARE(msec / 1000 % 60, qint64(local.time().second()));
+
+ // the two dates should be equal, actually
+ QCOMPARE(local.toUTC(), utc);
+ QCOMPARE(utc.toLocalTime(), local);
+
+ // and finally, the time_t should equal our number
+ QCOMPARE(qint64(utc.toTime_t()), msec / 1000);
+ QCOMPARE(qint64(local.toTime_t()), msec / 1000);
+}
+
void tst_QDateTime::toTime_t_data()
{
QTest::addColumn<QString>("dateTimeStr");
diff --git a/tests/auto/qdiriterator/tst_qdiriterator.cpp b/tests/auto/qdiriterator/tst_qdiriterator.cpp
index f6fce32..c1db8f2 100644
--- a/tests/auto/qdiriterator/tst_qdiriterator.cpp
+++ b/tests/auto/qdiriterator/tst_qdiriterator.cpp
@@ -198,6 +198,54 @@ void tst_QDirIterator::iterateRelativeDirectory_data()
#endif
"entrylist/writable").split(',');
+ QTest::newRow("NoDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::AllEntries | QDir::NoDot) << QStringList("*")
+ << QString(
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+ "entrylist/..,"
+#endif
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
+ QTest::newRow("NoDotDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::AllEntries | QDir::NoDotDot) << QStringList("*")
+ << QString(
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
+ "entrylist/.,"
+#endif
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
+ QTest::newRow("NoDotAndDotDot")
+ << QString("entrylist") << QDirIterator::IteratorFlags(0)
+ << QDir::Filters(QDir::AllEntries | QDir::NoDotAndDotDot) << QStringList("*")
+ << QString(
+ "entrylist/file,"
+#ifndef Q_NO_SYMLINKS
+ "entrylist/linktofile.lnk,"
+#endif
+ "entrylist/directory,"
+#if !defined(Q_NO_SYMLINKS) && !defined(Q_NO_SYMLINKS_TO_DIRS)
+ "entrylist/linktodirectory.lnk,"
+#endif
+ "entrylist/writable").split(',');
+
QTest::newRow("QDir::Subdirectories | QDir::FollowSymlinks")
<< QString("entrylist") << QDirIterator::IteratorFlags(QDirIterator::Subdirectories | QDirIterator::FollowSymlinks)
<< QDir::Filters(QDir::NoFilter) << QStringList("*")
diff --git a/tests/auto/qelapsedtimer/qelapsedtimer.pro b/tests/auto/qelapsedtimer/qelapsedtimer.pro
new file mode 100644
index 0000000..ed75228
--- /dev/null
+++ b/tests/auto/qelapsedtimer/qelapsedtimer.pro
@@ -0,0 +1,13 @@
+load(qttest_p4)
+QT -= gui
+
+SOURCES += tst_qelapsedtimer.cpp
+wince* {
+ DEFINES += SRCDIR=\\\"\\\"
+} else:symbian {
+ # do not define SRCDIR at all
+ TARGET.EPOCHEAPSIZE = 0x100000 0x3000000
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD/\\\"
+}
+
diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp
new file mode 100644
index 0000000..9ea422c
--- /dev/null
+++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QString>
+#include <QtCore/QTime>
+#include <QtCore/QElapsedTimer>
+#include <QtTest/QtTest>
+
+static const int minResolution = 50; // the minimum resolution for the tests
+
+class tst_QElapsedTimer : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void statics();
+ void validity();
+ void basics();
+ void elapsed();
+};
+
+void tst_QElapsedTimer::statics()
+{
+ qDebug() << "Clock type is" << QElapsedTimer::clockType();
+ qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic");
+ QElapsedTimer t;
+ t.start();
+ qDebug() << "Current time is" << t.msecsSinceReference();
+}
+
+void tst_QElapsedTimer::validity()
+{
+ QElapsedTimer t;
+
+ t.invalidate();
+ QVERIFY(!t.isValid());
+
+ t.start();
+ QVERIFY(t.isValid());
+
+ t.invalidate();
+ QVERIFY(!t.isValid());
+}
+
+void tst_QElapsedTimer::basics()
+{
+ QElapsedTimer t1;
+ t1.start();
+
+ QVERIFY(t1.msecsSinceReference() != 0);
+
+ QCOMPARE(t1, t1);
+ QVERIFY(!(t1 != t1));
+ QVERIFY(!(t1 < t1));
+ QCOMPARE(t1.msecsTo(t1), qint64(0));
+ QCOMPARE(t1.secsTo(t1), qint64(0));
+// QCOMPARE(t1 + 0, t1);
+// QCOMPARE(t1 - 0, t1);
+
+#if 0
+ QElapsedTimer t2 = t1;
+ t2 += 1000; // so we can use secsTo
+
+ QVERIFY(t1 != t2);
+ QVERIFY(!(t1 == t2));
+ QVERIFY(t1 < t2);
+ QVERIFY(!(t2 < t1));
+ QCOMPARE(t1.msecsTo(t2), qint64(1000));
+ QCOMPARE(t1.secsTo(t2), qint64(1));
+// QCOMPARE(t2 - t1, qint64(1000));
+// QCOMPARE(t1 - t2, qint64(-1000));
+#endif
+
+ quint64 value1 = t1.msecsSinceReference();
+ qint64 elapsed = t1.restart();
+ QVERIFY(elapsed < minResolution);
+
+ quint64 value2 = t1.msecsSinceReference();
+ // in theory, elapsed == value2 - value1
+
+ // However, since QElapsedTimer keeps internally the full resolution,
+ // we have here a rounding error due to integer division
+ QVERIFY(qAbs(elapsed - qint64(value2 - value1)) < 1);
+}
+
+void tst_QElapsedTimer::elapsed()
+{
+ QElapsedTimer t1;
+ t1.start();
+
+ QTest::qSleep(4*minResolution);
+ QElapsedTimer t2;
+ t2.start();
+
+ QVERIFY(t1 != t2);
+ QVERIFY(!(t1 == t2));
+ QVERIFY(t1 < t2);
+ QVERIFY(t1.msecsTo(t2) > 0);
+ // don't check: t1.secsTo(t2)
+// QVERIFY(t1 - t2 < 0);
+
+ QVERIFY(t1.elapsed() > 0);
+ QVERIFY(t1.hasExpired(minResolution));
+ QVERIFY(!t1.hasExpired(8*minResolution));
+ QVERIFY(!t2.hasExpired(minResolution));
+
+ QVERIFY(!t1.hasExpired(-1));
+ QVERIFY(!t2.hasExpired(-1));
+
+ qint64 elapsed = t1.restart();
+ QVERIFY(elapsed > 3*minResolution);
+ QVERIFY(elapsed < 5*minResolution);
+ qint64 diff = t2.msecsTo(t1);
+ QVERIFY(diff < minResolution);
+}
+
+QTEST_MAIN(tst_QElapsedTimer);
+
+#include "tst_qelapsedtimer.moc"
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index f407b12..8722a86 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -196,6 +196,7 @@ private slots:
void miscWithUncPathAsCurrentDir();
void standarderror();
void handle();
+ void nativeHandleLeaks();
void readEof_data();
void readEof();
@@ -392,6 +393,7 @@ void tst_QFile::cleanupTestCase()
QFile::remove("resources");
QFile::remove("qfile_map_testfile");
QFile::remove("readAllBuffer.txt");
+ QFile::remove("qt_file.tmp");
}
//------------------------------------------
@@ -2538,6 +2540,51 @@ void tst_QFile::handle()
#endif
}
+void tst_QFile::nativeHandleLeaks()
+{
+ int fd1, fd2;
+
+#ifdef Q_OS_WIN
+ HANDLE handle1, handle2;
+#endif
+
+ {
+ QFile file("qt_file.tmp");
+ QVERIFY( file.open(QIODevice::ReadWrite) );
+
+ fd1 = file.handle();
+ QVERIFY( -1 != fd1 );
+ }
+
+#ifdef Q_OS_WIN
+ handle1 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ QVERIFY( INVALID_HANDLE_VALUE != handle1 );
+ QVERIFY( ::CloseHandle(handle1) );
+#endif
+
+ {
+ QFile file("qt_file.tmp");
+ QVERIFY( file.open(QIODevice::ReadOnly) );
+
+ fd2 = file.handle();
+ QVERIFY( -1 != fd2 );
+ }
+
+#ifdef Q_OS_WIN
+ handle2 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ QVERIFY( INVALID_HANDLE_VALUE != handle2 );
+ QVERIFY( ::CloseHandle(handle2) );
+#endif
+
+ QCOMPARE( fd2, fd1 );
+
+#ifdef Q_OS_WIN
+ QCOMPARE( handle2, handle1 );
+#endif
+}
+
void tst_QFile::readEof_data()
{
QTest::addColumn<QString>("filename");
diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index 7138905..a26e34d 100644
--- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -79,6 +79,8 @@ private slots:
void nonExistingFile();
+ void removeFileAndUnWatch();
+
void cleanup();
private:
QStringList do_force_engines;
@@ -532,5 +534,28 @@ void tst_QFileSystemWatcher::nonExistingFile()
QVERIFY(true);
}
+void tst_QFileSystemWatcher::removeFileAndUnWatch()
+{
+ static const char * const filename = "foo.txt";
+ QFileSystemWatcher watcher;
+
+ {
+ QFile testFile(filename);
+ testFile.open(QIODevice::WriteOnly);
+ testFile.close();
+ }
+ watcher.addPath(filename);
+
+ QFile::remove(filename);
+ watcher.removePath(filename);
+
+ {
+ QFile testFile(filename);
+ testFile.open(QIODevice::WriteOnly);
+ testFile.close();
+ }
+ watcher.addPath(filename);
+}
+
QTEST_MAIN(tst_QFileSystemWatcher)
#include "tst_qfilesystemwatcher.moc"
diff --git a/tests/auto/qglthreads/qglthreads.pro b/tests/auto/qglthreads/qglthreads.pro
index 4d20a19..73b75d4 100644
--- a/tests/auto/qglthreads/qglthreads.pro
+++ b/tests/auto/qglthreads/qglthreads.pro
@@ -5,3 +5,6 @@ QT += opengl
HEADERS += tst_qglthreads.h
SOURCES += tst_qglthreads.cpp
+x11 {
+ LIBS += $$QMAKE_LIBS_X11
+}
diff --git a/tests/auto/qkeysequence/tst_qkeysequence.cpp b/tests/auto/qkeysequence/tst_qkeysequence.cpp
index b1ef223..1faae6a 100644
--- a/tests/auto/qkeysequence/tst_qkeysequence.cpp
+++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp
@@ -134,6 +134,8 @@ private slots:
void keyBindings();
void translated_data();
void translated();
+ void i18nKeys_data();
+ void i18nKeys();
void initTestCase();
@@ -570,5 +572,55 @@ void tst_QKeySequence::translated()
}
+void tst_QKeySequence::i18nKeys_data()
+{
+ QTest::addColumn<int>("keycode");
+ QTest::addColumn<QString>("keystring");
+
+ // Japanese keyboard support
+ QTest::newRow("Kanji") << (int)Qt::Key_Kanji << QString("Kanji");
+ QTest::newRow("Muhenkan") << (int)Qt::Key_Muhenkan << QString("Muhenkan");
+ QTest::newRow("Henkan") << (int)Qt::Key_Henkan << QString("Henkan");
+ QTest::newRow("Romaji") << (int)Qt::Key_Romaji << QString("Romaji");
+ QTest::newRow("Hiragana") << (int)Qt::Key_Hiragana << QString("Hiragana");
+ QTest::newRow("Katakana") << (int)Qt::Key_Katakana << QString("Katakana");
+ QTest::newRow("Hiragana Katakana") << (int)Qt::Key_Hiragana_Katakana << QString("Hiragana Katakana");
+ QTest::newRow("Zenkaku") << (int)Qt::Key_Zenkaku << QString("Zenkaku");
+ QTest::newRow("Hankaku") << (int)Qt::Key_Hankaku << QString("Hankaku");
+ QTest::newRow("Zenkaku Hankaku") << (int)Qt::Key_Zenkaku_Hankaku << QString("Zenkaku Hankaku");
+ QTest::newRow("Touroku") << (int)Qt::Key_Touroku << QString("Touroku");
+ QTest::newRow("Massyo") << (int)Qt::Key_Massyo << QString("Massyo");
+ QTest::newRow("Kana Lock") << (int)Qt::Key_Kana_Lock << QString("Kana Lock");
+ QTest::newRow("Kana Shift") << (int)Qt::Key_Kana_Shift << QString("Kana Shift");
+ QTest::newRow("Eisu Shift") << (int)Qt::Key_Eisu_Shift << QString("Eisu Shift");
+ QTest::newRow("Eisu_toggle") << (int)Qt::Key_Eisu_toggle << QString("Eisu toggle");
+ QTest::newRow("Code input") << (int)Qt::Key_Codeinput << QString("Code input");
+ QTest::newRow("Multiple Candidate") << (int)Qt::Key_MultipleCandidate << QString("Multiple Candidate");
+ QTest::newRow("Previous Candidate") << (int)Qt::Key_PreviousCandidate << QString("Previous Candidate");
+
+ // Korean keyboard support
+ QTest::newRow("Hangul") << (int)Qt::Key_Hangul << QString("Hangul");
+ QTest::newRow("Hangul Start") << (int)Qt::Key_Hangul_Start << QString("Hangul Start");
+ QTest::newRow("Hangul End") << (int)Qt::Key_Hangul_End << QString("Hangul End");
+ QTest::newRow("Hangul Hanja") << (int)Qt::Key_Hangul_Hanja << QString("Hangul Hanja");
+ QTest::newRow("Hangul Jamo") << (int)Qt::Key_Hangul_Jamo << QString("Hangul Jamo");
+ QTest::newRow("Hangul Romaja") << (int)Qt::Key_Hangul_Romaja << QString("Hangul Romaja");
+ QTest::newRow("Hangul Jeonja") << (int)Qt::Key_Hangul_Jeonja << QString("Hangul Jeonja");
+ QTest::newRow("Hangul Banja") << (int)Qt::Key_Hangul_Banja << QString("Hangul Banja");
+ QTest::newRow("Hangul PreHanja") << (int)Qt::Key_Hangul_PreHanja << QString("Hangul PreHanja");
+ QTest::newRow("Hangul PostHanja") << (int)Qt::Key_Hangul_PostHanja << QString("Hangul PostHanja");
+ QTest::newRow("Hangul Special") << (int)Qt::Key_Hangul_Special << QString("Hangul Special");
+}
+
+void tst_QKeySequence::i18nKeys()
+{
+ QFETCH(int, keycode);
+ QFETCH(QString, keystring);
+ QKeySequence seq(keycode);
+
+ QCOMPARE(seq, QKeySequence(keystring));
+ QCOMPARE(seq.toString(), keystring);
+}
+
QTEST_MAIN(tst_QKeySequence)
#include "tst_qkeysequence.moc"
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp
index 5a87154..182f73b 100644
--- a/tests/auto/qlocale/tst_qlocale.cpp
+++ b/tests/auto/qlocale/tst_qlocale.cpp
@@ -176,6 +176,11 @@ void tst_QLocale::ctor()
QCOMPARE(l.language(), exp_lang); \
QCOMPARE(l.country(), exp_country); \
}
+ {
+ QLocale l(QLocale::C, QLocale::AnyCountry);
+ QCOMPARE(l.language(), QLocale::C);
+ QCOMPARE(l.country(), QLocale::AnyCountry);
+ }
TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
TEST_CTOR(Aymara, AnyCountry, default_lang, default_country)
TEST_CTOR(Aymara, France, default_lang, default_country)
@@ -1580,7 +1585,7 @@ void tst_QLocale::dayName_data()
QTest::newRow("ru_RU long") << QString("ru_RU") << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320\265\321\201\320\265\320\275\321\214\320\265") << 7 << QLocale::LongFormat;
QTest::newRow("ru_RU short") << QString("ru_RU") << QString::fromUtf8("\320\222\321\201") << 7 << QLocale::ShortFormat;
- QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("") << 7 << QLocale::NarrowFormat;
+ QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("\320\222") << 7 << QLocale::NarrowFormat;
}
void tst_QLocale::dayName()
@@ -1891,16 +1896,16 @@ void tst_QLocale::ampm()
QCOMPARE(c.pmText(), QLatin1String("PM"));
QLocale de("de_DE");
- QCOMPARE(de.amText(), QLatin1String("vorm."));
- QCOMPARE(de.pmText(), QLatin1String("nachm."));
+ QCOMPARE(de.amText(), QLatin1String("AM"));
+ QCOMPARE(de.pmText(), QLatin1String("PM"));
QLocale sv("sv_SE");
QCOMPARE(sv.amText(), QLatin1String("fm"));
QCOMPARE(sv.pmText(), QLatin1String("em"));
QLocale nn("nl_NL");
- QCOMPARE(nn.amText(), QLatin1String(""));
- QCOMPARE(nn.pmText(), QLatin1String(""));
+ QCOMPARE(nn.amText(), QLatin1String("AM"));
+ QCOMPARE(nn.pmText(), QLatin1String("PM"));
QLocale ua("uk_UA");
QCOMPARE(ua.amText(), QString::fromUtf8("\320\264\320\277"));
@@ -1916,7 +1921,7 @@ void tst_QLocale::dateFormat()
const QLocale no("no_NO");
QCOMPARE(no.dateFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yy"));
QCOMPARE(no.dateFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yy"));
- QCOMPARE(no.dateFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy"));
+ QCOMPARE(no.dateFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM y"));
}
void tst_QLocale::timeFormat()
@@ -1926,9 +1931,9 @@ void tst_QLocale::timeFormat()
QCOMPARE(c.timeFormat(QLocale::NarrowFormat), c.timeFormat(QLocale::ShortFormat));
const QLocale no("no_NO");
- QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH.mm"));
- QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm"));
- QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("'kl'. HH.mm.ss "));
+ QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH:mm"));
+ QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH:mm"));
+ QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("'kl'. HH:mm:ss tttt"));
}
void tst_QLocale::dateTimeFormat()
@@ -1938,9 +1943,9 @@ void tst_QLocale::dateTimeFormat()
QCOMPARE(c.dateTimeFormat(QLocale::NarrowFormat), c.dateTimeFormat(QLocale::ShortFormat));
const QLocale no("no_NO");
- QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yy HH.mm"));
- QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yy HH.mm"));
- QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy 'kl'. HH.mm.ss "));
+ QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yy HH:mm"));
+ QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yy HH:mm"));
+ QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM y 'kl'. HH:mm:ss tttt"));
}
void tst_QLocale::monthName()
@@ -1961,12 +1966,12 @@ void tst_QLocale::monthName()
QCOMPARE(de.monthName(12, QLocale::LongFormat), QLatin1String("Dezember"));
QCOMPARE(de.monthName(12, QLocale::ShortFormat), QLatin1String("Dez"));
// 'de' locale doesn't have narrow month name
- QCOMPARE(de.monthName(12, QLocale::NarrowFormat), QLatin1String(""));
+ QCOMPARE(de.monthName(12, QLocale::NarrowFormat), QLatin1String("D"));
QLocale ru("ru_RU");
QCOMPARE(ru.monthName(1, QLocale::LongFormat), QString::fromUtf8("\321\217\320\275\320\262\320\260\321\200\321\217"));
QCOMPARE(ru.monthName(1, QLocale::ShortFormat), QString::fromUtf8("\321\217\320\275\320\262\56"));
- QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("")); // empty in CLDR 1.6.1
+ QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257"));
}
void tst_QLocale::standaloneMonthName()
diff --git a/tests/auto/qnetworkaccessmanager/qnetworkaccessmanager.pro b/tests/auto/qnetworkaccessmanager/qnetworkaccessmanager.pro
new file mode 100644
index 0000000..e2889c1
--- /dev/null
+++ b/tests/auto/qnetworkaccessmanager/qnetworkaccessmanager.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+SOURCES += tst_qnetworkaccessmanager.cpp
+QT = core network
+
+
diff --git a/tests/auto/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp b/tests/auto/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp
new file mode 100644
index 0000000..375c839
--- /dev/null
+++ b/tests/auto/qnetworkaccessmanager/tst_qnetworkaccessmanager.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtNetwork/QNetworkAccessManager>
+#include <QtNetwork/QNetworkConfigurationManager>
+
+#include <QtCore/QDebug>
+
+Q_DECLARE_METATYPE(QNetworkAccessManager::NetworkAccessibility);
+
+class tst_QNetworkAccessManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QNetworkAccessManager();
+
+private slots:
+ void networkAccessible();
+};
+
+tst_QNetworkAccessManager::tst_QNetworkAccessManager()
+{
+}
+
+void tst_QNetworkAccessManager::networkAccessible()
+{
+ QNetworkAccessManager manager;
+
+ qRegisterMetaType<QNetworkAccessManager::NetworkAccessibility>("QNetworkAccessManager::NetworkAccessibility");
+
+ QSignalSpy spy(&manager,
+ SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)));
+
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
+
+ manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
+
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
+ QNetworkAccessManager::NotAccessible);
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
+
+ manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
+
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
+ QNetworkAccessManager::UnknownAccessibility);
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::UnknownAccessibility);
+
+ QNetworkConfigurationManager configManager;
+ QNetworkConfiguration defaultConfig = configManager.defaultConfiguration();
+ if (defaultConfig.isValid()) {
+ manager.setConfiguration(defaultConfig);
+
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.takeFirst().at(0).value<QNetworkAccessManager::NetworkAccessibility>(),
+ QNetworkAccessManager::Accessible);
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::Accessible);
+
+ manager.setNetworkAccessible(QNetworkAccessManager::NotAccessible);
+
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(QNetworkAccessManager::NetworkAccessibility(spy.takeFirst().at(0).toInt()),
+ QNetworkAccessManager::NotAccessible);
+ QCOMPARE(manager.networkAccessible(), QNetworkAccessManager::NotAccessible);
+ }
+}
+
+QTEST_MAIN(tst_QNetworkAccessManager)
+#include "tst_qnetworkaccessmanager.moc"
diff --git a/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp b/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
index 8b68006..30c5a74 100644
--- a/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
+++ b/tests/auto/qnetworkconfigurationmanager/tst_qnetworkconfigurationmanager.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -285,14 +285,12 @@ void tst_QNetworkConfigurationManager::defaultConfiguration()
QNetworkConfiguration defaultConfig = manager.defaultConfiguration();
bool confirm = configs.contains(defaultConfig);
- bool isUserChoice = (defaultConfig.type() == QNetworkConfiguration::UserChoice);
- //user choice config is not part of allConfigurations()
- QVERIFY(isUserChoice != confirm);
- if (!isUserChoice) {
+ if (defaultConfig.type() != QNetworkConfiguration::UserChoice) {
QVERIFY(confirm || !defaultConfig.isValid());
QVERIFY(!(confirm && !defaultConfig.isValid()));
} else {
+ QVERIFY(!confirm); // user choice config is not part of allConfigurations()
QVERIFY(defaultConfig.isValid());
QCOMPARE(defaultConfig.name(), QString("UserChoice"));
QCOMPARE(defaultConfig.children().count(), 0);
diff --git a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
index 4b56f77..58b0576 100644
--- a/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
+++ b/tests/auto/qnetworksession/test/tst_qnetworksession.cpp
@@ -42,6 +42,7 @@
#include <QtTest/QtTest>
#include <QLocalServer>
#include <QLocalSocket>
+#include <QTimer>
#include "../../qbearertestcommon.h"
#include <qnetworkconfigmanager.h>
#include <qnetworksession.h>
@@ -53,6 +54,9 @@
QT_USE_NAMESPACE
+// Can be used to configure tests that require manual attention (such as roaming)
+//#define QNETWORKSESSION_MANUAL_TESTS 1
+
Q_DECLARE_METATYPE(QNetworkConfiguration)
Q_DECLARE_METATYPE(QNetworkConfiguration::Type);
Q_DECLARE_METATYPE(QNetworkSession::State);
@@ -75,6 +79,9 @@ private slots:
void repeatedOpenClose();
void roamingErrorCodes();
+
+ void sessionStop_data();
+ void sessionStop();
void sessionProperties_data();
void sessionProperties();
@@ -106,6 +113,7 @@ private:
// Helper functions
bool openSession(QNetworkSession *session);
bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration = true);
+void updateConfigurations();
QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType);
void tst_QNetworkSession::initTestCase()
@@ -226,14 +234,13 @@ void tst_QNetworkSession::cleanupTestCase()
void tst_QNetworkSession::invalidSession()
{
- // Verify that session created with invalid configuration remains in invalid state
+ // 1. Verify that session created with invalid configuration remains in invalid state
QNetworkSession session(QNetworkConfiguration(), 0);
QVERIFY(!session.isOpen());
QVERIFY(session.state() == QNetworkSession::Invalid);
QVERIFY(session.error() == QNetworkSession::InvalidConfigurationError);
- // Verify that opening session with invalid configuration both 1) emits invalidconfigurationerror
- // and 2) sets session's state as invalid.
+ // 2. Verify that opening session with invalid configuration both 1) emits invalidconfigurationerror and 2) sets session's state as invalid.
QSignalSpy errorSpy(&session, SIGNAL(error(QNetworkSession::SessionError)));
session.open();
session.waitForOpened(1000); // Should bail out right away
@@ -244,24 +251,56 @@ void tst_QNetworkSession::invalidSession()
QVERIFY(session.error() == QNetworkSession::InvalidConfigurationError);
QVERIFY(session.state() == QNetworkSession::Invalid);
- // Check same thing with a config from platform (there are subtle differences
- // because emtpy configuration does not have private pointer). Test with config
- // in '(un)defined' state
- QList<QNetworkConfiguration> allConfigs = manager.allConfigurations();
- foreach(QNetworkConfiguration config, allConfigs) {
- if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) {
- QNetworkSession session2(config);
- QSignalSpy errorSpy2(&session2, SIGNAL(error(QNetworkSession::SessionError)));
- session2.open();
- session2.waitForOpened(1000); // Should bail out right away
- QVERIFY(errorSpy2.count() == 1);
- QNetworkSession::SessionError error2 =
- qvariant_cast<QNetworkSession::SessionError> (errorSpy2.first().at(0));
- QVERIFY(error2 == QNetworkSession::InvalidConfigurationError);
- QVERIFY(session2.state() == QNetworkSession::Invalid);
- break; // Once is enough
- }
+#ifdef QNETWORKSESSION_MANUAL_TESTS
+ QNetworkConfiguration definedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint);
+ if (definedConfig.isValid()) {
+ // 3. Verify that opening a session with defined configuration emits error and enters notavailable-state
+ // TODO these timer waits should be changed to waiting appropriate signals, now these wait excessively
+ qDebug() << "Shutdown WLAN IAP (waiting 60 seconds): " << definedConfig.name();
+ QTest::qWait(60000);
+ // Shutting down WLAN should bring back to defined -state.
+ QVERIFY((definedConfig.state() & QNetworkConfiguration::Defined) == QNetworkConfiguration::Defined);
+ QNetworkSession definedSession(definedConfig);
+ QSignalSpy errorSpy(&definedSession, SIGNAL(error(QNetworkSession::SessionError)));
+ QNetworkSession::SessionError sessionError;
+
+ definedSession.open();
+
+ QVERIFY(definedConfig.isValid()); // Session remains valid
+ QVERIFY(definedSession.state() == QNetworkSession::NotAvailable); // State is not available because WLAN is not in coverage
+ QVERIFY(!errorSpy.isEmpty()); // Session tells with error about invalidated configuration
+ sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0));
+ qDebug() << "Error code is: " << sessionError;
+ QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError);
+
+ qDebug() << "Turn the WLAN IAP back on (waiting 60 seconds): " << definedConfig.name();
+ QTest::qWait(60000);
+ updateConfigurations();
+
+ QVERIFY(definedConfig.state() == QNetworkConfiguration::Discovered);
}
+
+ QNetworkConfiguration invalidatedConfig = suitableConfiguration("WLAN",QNetworkConfiguration::InternetAccessPoint);
+ if (invalidatedConfig.isValid()) {
+ // 4. Verify that invalidating a session after its successfully configured works
+ QNetworkSession invalidatedSession(invalidatedConfig);
+ QSignalSpy errorSpy(&invalidatedSession, SIGNAL(error(QNetworkSession::SessionError)));
+ QNetworkSession::SessionError sessionError;
+
+ qDebug() << "Delete the WLAN IAP from phone now (waiting 60 seconds): " << invalidatedConfig.name();
+ QTest::qWait(60000);
+
+ invalidatedSession.open();
+ QVERIFY(!invalidatedConfig.isValid());
+ QVERIFY(invalidatedSession.state() == QNetworkSession::Invalid);
+ QVERIFY(!errorSpy.isEmpty());
+
+ sessionError = qvariant_cast<QNetworkSession::SessionError> (errorSpy.first().at(0));
+ QVERIFY(sessionError == QNetworkSession::InvalidConfigurationError);
+ qDebug() << "Add the WLAN IAP back (waiting 60 seconds): " << invalidatedConfig.name();
+ QTest::qWait(60000);
+ }
+#endif
}
void tst_QNetworkSession::sessionProperties_data()
@@ -316,11 +355,13 @@ void tst_QNetworkSession::sessionProperties()
// QNetworkSession::interface() should return an invalid interface unless
// session is in the connected state.
qDebug() << "Session state:" << session.state();
+#ifndef QT_NO_NETWORKINTERFACE
qDebug() << "Session iface:" << session.interface().isValid() << session.interface().name();
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QCOMPARE(session.state() == QNetworkSession::Connected, session.interface().isValid());
#endif
+#endif
if (!configuration.isValid()) {
QVERIFY(configuration.state() == QNetworkConfiguration::Undefined &&
@@ -382,7 +423,6 @@ void tst_QNetworkSession::repeatedOpenClose() {
}
void tst_QNetworkSession::roamingErrorCodes() {
-
#ifndef Q_OS_SYMBIAN
QSKIP("Roaming supported on Symbian.", SkipAll);
#else
@@ -410,8 +450,9 @@ void tst_QNetworkSession::roamingErrorCodes() {
QVERIFY(iapSession.state() == QNetworkSession::Disconnected);
QVERIFY(adminIapSession.state() == QNetworkSession::Disconnected);
#endif // Q_OS_SYMBIAN
- /*
- // Check for roaming error. Challenging to automate, therefore commented out.
+
+#ifdef QNETWORKSESSION_MANUAL_TESTS
+ // Check for roaming error.
// Case requires that you have controllable WLAN in Internet SNAP (only).
QNetworkConfiguration snapConfig = suitableConfiguration("bearer_not_relevant_with_snaps", QNetworkConfiguration::ServiceNetwork);
if (!snapConfig.isValid()) {
@@ -439,7 +480,144 @@ void tst_QNetworkSession::roamingErrorCodes() {
error = qvariant_cast<QNetworkSession::SessionError>(errorSpy2.first().at(0));
QVERIFY(error == QNetworkSession::SessionAbortedError);
QVERIFY(iapSession2.state() == QNetworkSession::Disconnected);
- */
+#endif
+}
+
+
+void tst_QNetworkSession::sessionStop_data() {
+ QTest::addColumn<QString>("bearerType");
+ QTest::addColumn<QNetworkConfiguration::Type>("configurationType");
+
+ QTest::newRow("SNAP") << "bearer_type_not_relevant_with_SNAPs" << QNetworkConfiguration::ServiceNetwork;
+ QTest::newRow("WLAN_IAP") << "WLAN" << QNetworkConfiguration::InternetAccessPoint;
+ QTest::newRow("Cellular_IAP") << "cellular" << QNetworkConfiguration::InternetAccessPoint;
+}
+
+void tst_QNetworkSession::sessionStop()
+{
+#ifndef Q_OS_SYMBIAN
+ QSKIP("Testcase contains mainly Symbian specific checks, because it is only platform to really support interface (IAP-level) Stop.", SkipAll);
+#endif
+ QFETCH(QString, bearerType);
+ QFETCH(QNetworkConfiguration::Type, configurationType);
+
+ int configWaitdelayInMs = 2000;
+
+ QNetworkConfiguration config = suitableConfiguration(bearerType, configurationType);
+ if (!config.isValid()) {
+ QSKIP("No suitable configurations, skipping this round of session stop test.", SkipSingle);
+ }
+ qDebug() << "Using following configuration to open and stop a session: " << config.name();
+
+ QNetworkSession openedSession(config);
+ QNetworkSession closedSession(config);
+ QNetworkSession innocentSession(config);
+ QNetworkConfigurationManager mgr;
+
+ QSignalSpy closedSessionOpenedSpy(&closedSession, SIGNAL(opened()));
+ QSignalSpy closedSessionClosedSpy(&closedSession, SIGNAL(closed()));
+ QSignalSpy closedSessionStateChangedSpy(&closedSession, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy closedErrorSpy(&closedSession, SIGNAL(error(QNetworkSession::SessionError)));
+
+ QSignalSpy innocentSessionClosedSpy(&innocentSession, SIGNAL(closed()));
+ QSignalSpy innocentSessionStateChangedSpy(&innocentSession, SIGNAL(stateChanged(QNetworkSession::State)));
+ QSignalSpy innocentErrorSpy(&innocentSession, SIGNAL(error(QNetworkSession::SessionError)));
+ QNetworkSession::SessionError sessionError;
+
+ // 1. Verify that stopping an opened session works (the simplest usecase).
+ qDebug("----------1. Verify that stopping an opened session works (the simplest usecase)");
+ QSignalSpy configChangeSpy(&mgr, SIGNAL(configurationChanged(QNetworkConfiguration)));
+ QVERIFY(openSession(&openedSession));
+ qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs);
+ // Clear signals caused by opening
+ closedSessionOpenedSpy.clear();
+ closedSessionClosedSpy.clear();
+ closedSessionStateChangedSpy.clear();
+ closedErrorSpy.clear();
+ openedSession.stop();
+
+ QVERIFY(openedSession.state() == QNetworkSession::Disconnected);
+ QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+ QVERIFY(config.state() != QNetworkConfiguration::Active);
+
+ // 2. Verify that stopping a session based on non-connected configuration does nothing
+ qDebug("----------2. Verify that stopping a session based on non-connected configuration does nothing");
+ QNetworkSession::State closedSessionOriginalState = closedSession.state();
+ // Clear all possible signals
+ configChangeSpy.clear();
+ closedSessionOpenedSpy.clear();
+ closedSessionClosedSpy.clear();
+ closedSessionStateChangedSpy.clear();
+ closedErrorSpy.clear();
+
+ closedSession.stop();
+ qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs);
+ QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+
+ QVERIFY(closedSessionOpenedSpy.isEmpty());
+ QVERIFY(closedSessionClosedSpy.isEmpty());
+ QVERIFY(closedSessionStateChangedSpy.isEmpty());
+ QVERIFY(closedErrorSpy.isEmpty());
+ QVERIFY(closedSession.state() == closedSessionOriginalState); // State remains
+
+ // 3. Check that stopping a opened session affects also other opened session based on the same configuration.
+ if (config.type() == QNetworkConfiguration::InternetAccessPoint) {
+ qDebug("----------3. Check that stopping a opened session affects also other opened session based on the same configuration.");
+ QVERIFY(openSession(&openedSession));
+ QVERIFY(openSession(&innocentSession));
+
+ configChangeSpy.clear();
+ innocentSessionClosedSpy.clear();
+ innocentSessionStateChangedSpy.clear();
+ innocentErrorSpy.clear();
+
+ openedSession.stop();
+ qDebug("Waiting for %d ms to get all configurationChange signals from platform.", configWaitdelayInMs);
+ QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+
+ QVERIFY(!innocentSessionClosedSpy.isEmpty());
+ QVERIFY(!innocentSessionStateChangedSpy.isEmpty());
+ QVERIFY(!innocentErrorSpy.isEmpty());
+ QVERIFY(innocentSession.state() == QNetworkSession::Disconnected);
+ QVERIFY(openedSession.state() == QNetworkSession::Disconnected);
+ sessionError = qvariant_cast<QNetworkSession::SessionError>(innocentErrorSpy.first().at(0));
+ QVERIFY(sessionError == QNetworkSession::SessionAbortedError);
+
+ innocentSessionClosedSpy.clear();
+ innocentSessionStateChangedSpy.clear();
+ innocentErrorSpy.clear();
+ } else {
+ qDebug("----------3. Skip for SNAP configuration.");
+ }
+ // 4. Check that stopping a non-opened session stops the other session based on the
+ // same configuration if configuration is IAP. Stopping closed SNAP session has no impact on other opened SNAP session.
+ if (config.type() == QNetworkConfiguration::ServiceNetwork) {
+ qDebug("----------4. Skip for SNAP configuration.");
+ } else if (config.type() == QNetworkConfiguration::InternetAccessPoint) {
+ qDebug("----------4. Check that stopping a non-opened session stops the other session based on the same configuration");
+ QVERIFY(openSession(&innocentSession));
+ qDebug("Waiting for %d ms after open to make sure all platform indications are propagated", configWaitdelayInMs);
+ QTest::qWait(configWaitdelayInMs);
+ closedSession.stop();
+ qDebug("Waiting for %d ms to get all configurationChange signals from platform..", configWaitdelayInMs);
+ QTest::qWait(configWaitdelayInMs); // Wait to get all relevant configurationChange() signals
+
+ QVERIFY(!innocentSessionClosedSpy.isEmpty());
+ QVERIFY(!innocentSessionStateChangedSpy.isEmpty());
+ QVERIFY(!innocentErrorSpy.isEmpty());
+ QVERIFY(innocentSession.state() == QNetworkSession::Disconnected);
+ QVERIFY(closedSession.state() == QNetworkSession::Disconnected);
+ sessionError = qvariant_cast<QNetworkSession::SessionError>(innocentErrorSpy.first().at(0));
+ QVERIFY(sessionError == QNetworkSession::SessionAbortedError);
+ QVERIFY(config.state() == QNetworkConfiguration::Discovered);
+ }
+
+ // 5. Sanity check that stopping invalid session does not crash
+ qDebug("----------5. Sanity check that stopping invalid session does not crash");
+ QNetworkSession invalidSession(QNetworkConfiguration(), 0);
+ QVERIFY(invalidSession.state() == QNetworkSession::Invalid);
+ invalidSession.stop();
+ QVERIFY(invalidSession.state() == QNetworkSession::Invalid);
}
void tst_QNetworkSession::userChoiceSession_data()
@@ -518,10 +696,12 @@ void tst_QNetworkSession::userChoiceSession()
QTRY_VERIFY(!stateChangedSpy.isEmpty());
QVERIFY(session.state() == QNetworkSession::Connected);
+#ifndef QT_NO_NETWORKINTERFACE
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QVERIFY(session.interface().isValid());
#endif
+#endif
const QString userChoiceIdentifier =
session.sessionProperty("UserChoiceConfiguration").toString();
@@ -663,10 +843,12 @@ void tst_QNetworkSession::sessionOpenCloseStop()
}
QVERIFY(session.state() == QNetworkSession::Connected);
+#ifndef QT_NO_NETWORKINTERFACE
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QVERIFY(session.interface().isValid());
#endif
+#endif
} else {
QFAIL("Timeout waiting for session to open.");
}
@@ -699,12 +881,14 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(session2.isOpen());
QVERIFY(session.state() == QNetworkSession::Connected);
QVERIFY(session2.state() == QNetworkSession::Connected);
+#ifndef QT_NO_NETWORKINTERFACE
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QVERIFY(session.interface().isValid());
#endif
QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
QCOMPARE(session.interface().index(), session2.interface().index());
+#endif
}
sessionOpenedSpy2.clear();
@@ -796,14 +980,13 @@ void tst_QNetworkSession::sessionOpenCloseStop()
state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(0).at(0));
if (state == QNetworkSession::Roaming) {
QTRY_VERIFY(!errorSpy.isEmpty() || stateChangedSpy.count() > 1);
- if (stateChangedSpy.count() > 1) {
- state = qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0));
- if (state == QNetworkSession::Connected) {
- roamedSuccessfully = true;
- QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
- }
+ if (stateChangedSpy.count() > 1 &&
+ qvariant_cast<QNetworkSession::State>(stateChangedSpy.at(1).at(0)) ==
+ QNetworkSession::Connected) {
+ roamedSuccessfully = true;
}
}
+
if (roamedSuccessfully) {
QString configId = session.sessionProperty("ActiveConfiguration").toString();
QNetworkConfiguration config = manager.configurationFromIdentifier(configId);
@@ -838,8 +1021,9 @@ void tst_QNetworkSession::sessionOpenCloseStop()
}
QTRY_VERIFY(!sessionClosedSpy.isEmpty());
- QVERIFY(session.state() == QNetworkSession::Disconnected);
- QVERIFY(session2.state() == QNetworkSession::Disconnected);
+
+ QTRY_VERIFY(session.state() == QNetworkSession::Disconnected);
+ QTRY_VERIFY(session2.state() == QNetworkSession::Disconnected);
}
QVERIFY(errorSpy2.isEmpty());
@@ -875,12 +1059,14 @@ void tst_QNetworkSession::sessionOpenCloseStop()
QVERIFY(!session2.isOpen());
QVERIFY(session.state() == QNetworkSession::Connected);
QVERIFY(session2.state() == QNetworkSession::Connected);
+#ifndef QT_NO_NETWORKINTERFACE
#if !(defined(Q_OS_SYMBIAN) && defined(__WINS__))
// On Symbian emulator, the support for data bearers is limited
QVERIFY(session.interface().isValid());
#endif
QCOMPARE(session.interface().hardwareAddress(), session2.interface().hardwareAddress());
QCOMPARE(session.interface().index(), session2.interface().index());
+#endif
}
sessionClosedSpy2.clear();
@@ -1059,6 +1245,7 @@ void tst_QNetworkSession::outOfProcessSession()
// Ignores configurations in other than 'discovered' -state. Returns invalid (QNetworkConfiguration())
// if none found.
QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfiguration::Type configType) {
+
// Refresh configurations and derive configurations matching given parameters.
QNetworkConfigurationManager mgr;
QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted()));
@@ -1099,6 +1286,15 @@ QNetworkConfiguration suitableConfiguration(QString bearerType, QNetworkConfigur
}
}
+// A convinience-function: updates configurations and waits that they are updated.
+void updateConfigurations()
+{
+ QNetworkConfigurationManager mgr;
+ QSignalSpy updateSpy(&mgr, SIGNAL(updateCompleted()));
+ mgr.updateConfigurations();
+ QTRY_NOOP(updateSpy.count() == 1);
+}
+
// A convinience function for test-cases: opens the given configuration and return
// true if it was done gracefully.
bool openSession(QNetworkSession *session) {
@@ -1198,8 +1394,8 @@ bool closeSession(QNetworkSession *session, bool lastSessionOnConfiguration) {
return false;
}
if (lastSessionOnConfiguration &&
- session->configuration().state() != QNetworkConfiguration::Discovered) {
- qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is not back in 'Discovered' -state.");
+ session->configuration().state() == QNetworkConfiguration::Active) {
+ qDebug("tst_QNetworkSession::closeSession() failure: session's configuration is still in active state.");
return false;
}
return true;
@@ -1270,4 +1466,3 @@ void tst_QNetworkSession::sessionAutoClose()
QTEST_MAIN(tst_QNetworkSession)
#include "tst_qnetworksession.moc"
-
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index e71d7c3..0615b63 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -121,6 +121,7 @@ private slots:
void castWithPrototypeChain();
void castWithMultipleInheritance();
void collectGarbage();
+ void reportAdditionalMemoryCost();
void gcWithNestedDataStructure();
void processEventsWhileRunning();
void throwErrorFromProcessEvents();
@@ -2369,6 +2370,24 @@ void tst_QScriptEngine::collectGarbage()
QVERIFY(ptr == 0);
}
+void tst_QScriptEngine::reportAdditionalMemoryCost()
+{
+ QScriptEngine eng;
+ for (int x = 0; x < 1000; ++x) {
+ eng.reportAdditionalMemoryCost(0);
+ eng.reportAdditionalMemoryCost(10);
+ eng.reportAdditionalMemoryCost(1000);
+ eng.reportAdditionalMemoryCost(10000);
+ eng.reportAdditionalMemoryCost(100000);
+ eng.reportAdditionalMemoryCost(1000000);
+ eng.reportAdditionalMemoryCost(10000000);
+ eng.reportAdditionalMemoryCost(-1);
+ eng.reportAdditionalMemoryCost(-1000);
+ QScriptValue obj = eng.newObject();
+ eng.collectGarbage();
+ }
+}
+
void tst_QScriptEngine::gcWithNestedDataStructure()
{
QScriptEngine eng;
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index b4ce561..c1496f7 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -533,6 +533,7 @@ private slots:
void objectDeleted();
void connectToDestroyedSignal();
void emitAfterReceiverDeleted();
+ void inheritedSlots();
private:
QScriptEngine *m_engine;
@@ -2658,6 +2659,21 @@ void tst_QScriptExtQObject::enumerate_data()
<< "mySignal()"
// slots
<< "mySlot()" << "myOtherSlot()");
+
+ QTest::newRow( "don't enumerate slots" )
+ << int(QScriptEngine::ExcludeSlots)
+ << (QStringList()
+ // meta-object-defined properties:
+ // inherited
+ << "objectName"
+ // non-inherited
+ << "p1" << "p2" << "p4" << "p6"
+ // dynamic properties
+ << "dp1" << "dp2" << "dp3"
+ // inherited signals
+ << "destroyed(QObject*)" << "destroyed()"
+ // signals
+ << "mySignal()");
}
void tst_QScriptExtQObject::enumerate()
@@ -2850,6 +2866,28 @@ void tst_QScriptExtQObject::wrapOptions()
QVERIFY(obj.property("intProperty").isValid());
QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
}
+ // exclude slots
+ {
+ QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSlots);
+ QVERIFY(!obj.property("deleteLater").isValid());
+ QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember));
+ QVERIFY(!obj.property("mySlot").isValid());
+ QVERIFY(!(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("myInvokable").isFunction());
+ QVERIFY(obj.propertyFlags("myInvokable") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("mySignal").isFunction());
+ QVERIFY(obj.propertyFlags("mySignal") & QScriptValue::QObjectMember);
+ QVERIFY(obj.property("destroyed").isFunction());
+ QVERIFY(obj.propertyFlags("destroyed") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("objectName").isValid());
+ QVERIFY(obj.propertyFlags("objectName") & QScriptValue::QObjectMember);
+ QVERIFY(obj.property("intProperty").isValid());
+ QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
+ }
// exclude all that we can
{
QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
@@ -2871,6 +2909,33 @@ void tst_QScriptExtQObject::wrapOptions()
QCOMPARE(obj.property("child")
.strictlyEquals(QScriptValue(m_engine, 123)), true);
}
+ // exclude absolutely all that we can
+ {
+ QScriptValue obj = m_engine->newQObject(m_myObject, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSuperClassMethods
+ | QScriptEngine::ExcludeSuperClassProperties
+ | QScriptEngine::ExcludeChildObjects
+ | QScriptEngine::ExcludeSlots);
+ QVERIFY(!obj.property("deleteLater").isValid());
+ QVERIFY(!(obj.propertyFlags("deleteLater") & QScriptValue::QObjectMember));
+
+ QVERIFY(!obj.property("mySlot").isValid());
+ QVERIFY(!(obj.propertyFlags("mySlot") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("mySignal").isFunction());
+ QVERIFY(obj.propertyFlags("mySignal") & QScriptValue::QObjectMember);
+
+ QVERIFY(obj.property("myInvokable").isFunction());
+ QVERIFY(obj.propertyFlags("myInvokable") & QScriptValue::QObjectMember);
+
+ QVERIFY(!obj.property("objectName").isValid());
+ QVERIFY(!(obj.propertyFlags("objectName") & QScriptValue::QObjectMember));
+
+ QVERIFY(obj.property("intProperty").isValid());
+ QVERIFY(obj.propertyFlags("intProperty") & QScriptValue::QObjectMember);
+
+ QVERIFY(!obj.property("child").isValid());
+ }
delete child;
}
@@ -3043,5 +3108,27 @@ void tst_QScriptExtQObject::emitAfterReceiverDeleted()
}
}
+void tst_QScriptExtQObject::inheritedSlots()
+{
+ QScriptEngine eng;
+
+ QPushButton prototypeButton;
+ QScriptValue scriptPrototypeButton = eng.newQObject(&prototypeButton);
+
+ QPushButton button;
+ QScriptValue scriptButton = eng.newQObject(&button, QScriptEngine::QtOwnership,
+ QScriptEngine::ExcludeSlots);
+ scriptButton.setPrototype(scriptPrototypeButton);
+
+ QVERIFY(scriptButton.property("click").isFunction());
+ QVERIFY(scriptButton.property("click").strictlyEquals(scriptPrototypeButton.property("click")));
+
+ QSignalSpy prototypeButtonClickedSpy(&prototypeButton, SIGNAL(clicked()));
+ QSignalSpy buttonClickedSpy(&button, SIGNAL(clicked()));
+ scriptButton.property("click").call(scriptButton);
+ QCOMPARE(buttonClickedSpy.count(), 1);
+ QCOMPARE(prototypeButtonClickedSpy.count(), 0);
+}
+
QTEST_MAIN(tst_QScriptExtQObject)
#include "tst_qscriptextqobject.moc"
diff --git a/tests/auto/qshortcut/tst_qshortcut.cpp b/tests/auto/qshortcut/tst_qshortcut.cpp
index 39518c5..6df4cc4 100644
--- a/tests/auto/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/qshortcut/tst_qshortcut.cpp
@@ -224,10 +224,10 @@ void tst_QShortcut::initTestCase()
mainW->setFixedSize( 100, 100 );
mainW->setCentralWidget( edit );
mainW->show();
- mainW->activateWindow();
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(mainW);
#endif
+ mainW->activateWindow();
QTest::qWait(100);
connect( mainW->statusBar(), SIGNAL(messageChanged(const QString&)),
this, SLOT(statusMessage(const QString&)) );
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
index b05aaa0..0d39c72 100644
--- a/tests/auto/qstate/tst_qstate.cpp
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -77,6 +77,7 @@ private slots:
void assignProperty();
void assignPropertyTwice();
void historyInitialState();
+ void transitions();
private:
bool functionCalled;
@@ -370,6 +371,38 @@ void tst_QState::historyInitialState()
QVERIFY(machine.configuration().contains(s4));
}
+void tst_QState::transitions()
+{
+ QState s1;
+ QState s2;
+
+ QVERIFY(s1.transitions().isEmpty());
+
+ QAbstractTransition *t1 = s1.addTransition(this, SIGNAL(destroyed()), &s2);
+ QVERIFY(t1 != 0);
+ QCOMPARE(s1.transitions().count(), 1);
+ QCOMPARE(s1.transitions().first(), t1);
+ QVERIFY(s2.transitions().isEmpty());
+
+ s1.removeTransition(t1);
+ QVERIFY(s1.transitions().isEmpty());
+
+ s1.addTransition(t1);
+ QCOMPARE(s1.transitions().count(), 1);
+ QCOMPARE(s1.transitions().first(), t1);
+
+ QAbstractTransition *t2 = new QEventTransition(&s1);
+ QCOMPARE(s1.transitions().count(), 2);
+ QVERIFY(s1.transitions().contains(t1));
+ QVERIFY(s1.transitions().contains(t2));
+
+ // Transitions from child states should not be reported.
+ QState *s21 = new QState(&s2);
+ QAbstractTransition *t3 = s21->addTransition(this, SIGNAL(destroyed()), &s2);
+ QVERIFY(s2.transitions().isEmpty());
+ QCOMPARE(s21->transitions().count(), 1);
+ QCOMPARE(s21->transitions().first(), t3);
+}
QTEST_MAIN(tst_QState)
#include "tst_qstate.moc"
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index d79ebb9..1bea4b7 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -938,6 +938,11 @@ void tst_QString::sprintf()
// Check utf8 conversion for %s
QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString("\366\344\374\326\304\334\370\346\345\330\306\305"));
+ // Check codecForCStrings is used to read non-modifier sequences in the format string
+ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
+ QCOMPARE(a.sprintf("\303\251\303\250\303\240 %s", "\303\251\303\250\303\240"), QString("\303\251\303\250\303\240 \303\251\303\250\303\240"));
+ QTextCodec::setCodecForCStrings(0);
+
int n1;
a.sprintf("%s%n%s", "hello", &n1, "goodbye");
QCOMPARE(n1, 5);
diff --git a/tests/auto/qstringlist/tst_qstringlist.cpp b/tests/auto/qstringlist/tst_qstringlist.cpp
index 8429303..210903c 100644
--- a/tests/auto/qstringlist/tst_qstringlist.cpp
+++ b/tests/auto/qstringlist/tst_qstringlist.cpp
@@ -77,6 +77,7 @@ private slots:
void streamingOperator();
void join() const;
void join_data() const;
+ void joinEmptiness() const;
};
extern const char email[];
@@ -311,5 +312,14 @@ void tst_QStringList::join_data() const
<< QString("a b c");
}
+void tst_QStringList::joinEmptiness() const
+{
+ QStringList list;
+ QString string = list.join(QString());
+
+ QVERIFY(string.isEmpty());
+ QVERIFY(string.isNull());
+}
+
QTEST_APPLESS_MAIN(tst_QStringList)
#include "tst_qstringlist.moc"
diff --git a/tests/auto/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/qtextscriptengine/tst_qtextscriptengine.cpp
index 6de3f59..841f5b9 100644
--- a/tests/auto/qtextscriptengine/tst_qtextscriptengine.cpp
+++ b/tests/auto/qtextscriptengine/tst_qtextscriptengine.cpp
@@ -99,6 +99,7 @@ private slots:
void kannada();
void malayalam();
void sinhala();
+ void greek();
void khmer();
void linearB();
@@ -998,6 +999,80 @@ void tst_QTextScriptEngine::linearB()
#endif
}
+#if defined(Q_WS_X11)
+static bool decomposedShaping( const QFont &f, const QChar &ch)
+{
+ QString str = QString().append(ch);
+ QTextLayout layout(str, f);
+ QTextEngine *e = layout.d;
+ e->itemize();
+ e->shape(0);
+
+ QTextLayout decomposed(str.normalized(QString::NormalizationForm_D), f);
+ QTextEngine *de = decomposed.d;
+ de->itemize();
+ de->shape(0);
+
+ if( e->layoutData->items[0].num_glyphs != de->layoutData->items[0].num_glyphs )
+ goto error;
+
+ for (int i = 0; i < e->layoutData->items[0].num_glyphs; ++i) {
+ if ((e->layoutData->glyphLayout.glyphs[i] & 0xffffff) != (de->layoutData->glyphLayout.glyphs[i] & 0xffffff))
+ goto error;
+ }
+ return true;
+ error:
+ qDebug("%s: decomposedShaping of char %4x failed, nglyphs=%d, decomposed nglyphs %d",
+ f.family().toLatin1().constData(),
+ ch.unicode(),
+ e->layoutData->items[0].num_glyphs,
+ de->layoutData->items[0].num_glyphs);
+
+ str = "";
+ int i = 0;
+ while (i < e->layoutData->items[0].num_glyphs) {
+ str += QString("%1 ").arg(e->layoutData->glyphLayout.glyphs[i], 4, 16);
+ ++i;
+ }
+ qDebug(" composed glyph result = %s", str.toLatin1().constData());
+ str = "";
+ i = 0;
+ while (i < de->layoutData->items[0].num_glyphs) {
+ str += QString("%1 ").arg(de->layoutData->glyphLayout.glyphs[i], 4, 16);
+ ++i;
+ }
+ qDebug(" decomposed glyph result = %s", str.toLatin1().constData());
+ return false;
+}
+#endif
+
+
+void tst_QTextScriptEngine::greek()
+{
+#if defined(Q_WS_X11)
+ {
+ if (QFontDatabase().families(QFontDatabase::Any).contains("DejaVu Sans")) {
+ QFont f("DejaVu Sans");
+ for (int uc = 0x1f00; uc <= 0x1fff; ++uc) {
+ QString str;
+ str.append(uc);
+ if (str.normalized(QString::NormalizationForm_D).normalized(QString::NormalizationForm_C) != str) {
+ //qDebug() << "skipping" << hex << uc;
+ continue;
+ }
+ if (uc == 0x1fc1 || uc == 0x1fed)
+ continue;
+ QVERIFY( decomposedShaping(f, QChar(uc)) );
+ }
+ } else {
+ QSKIP("couln't find DejaVu Sans", SkipAll);
+ }
+ }
+#else
+ QSKIP("X11 specific test", SkipAll);
+#endif
+}
+
QTEST_MAIN(tst_QTextScriptEngine)
#include "tst_qtextscriptengine.moc"
diff --git a/tests/auto/qtranslator/qtranslator.pro b/tests/auto/qtranslator/qtranslator.pro
index 30ffc1c..2b08b4a 100644
--- a/tests/auto/qtranslator/qtranslator.pro
+++ b/tests/auto/qtranslator/qtranslator.pro
@@ -1,6 +1,6 @@
load(qttest_p4)
SOURCES += tst_qtranslator.cpp
-
+RESOURCES += qtranslator.qrc
wince*|symbian*: {
addFiles.sources = hellotr_la.qm msgfmt_from_po.qm
diff --git a/tests/auto/qtranslator/qtranslator.qrc b/tests/auto/qtranslator/qtranslator.qrc
new file mode 100644
index 0000000..333dcfa
--- /dev/null
+++ b/tests/auto/qtranslator/qtranslator.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/tst_qtranslator">
+ <file>hellotr_la.qm</file>
+ </qresource>
+</RCC>
diff --git a/tests/auto/qtranslator/tst_qtranslator.cpp b/tests/auto/qtranslator/tst_qtranslator.cpp
index 44fc10c..f2bfbf0 100644
--- a/tests/auto/qtranslator/tst_qtranslator.cpp
+++ b/tests/auto/qtranslator/tst_qtranslator.cpp
@@ -70,6 +70,8 @@ private slots:
void testLanguageChange();
void plural();
void translate_qm_file_generated_with_msgfmt();
+ void loadFromResource();
+ void loadDirectory();
private:
int languageChangeEventCounter;
@@ -237,5 +239,22 @@ void tst_QTranslator::translate_qm_file_generated_with_msgfmt()
qApp->removeTranslator(&translator);
}
+void tst_QTranslator::loadFromResource()
+{
+ QTranslator tor;
+ tor.load(":/tst_qtranslator/hellotr_la.qm");
+ QVERIFY(!tor.isEmpty());
+ QCOMPARE(tor.translate("QPushButton", "Hello world!"), QString::fromLatin1("Hallo Welt!"));
+}
+
+void tst_QTranslator::loadDirectory()
+{
+ QVERIFY(QFileInfo("../qtranslator").isDir());
+
+ QTranslator tor;
+ tor.load("qtranslator", "..");
+ QVERIFY(tor.isEmpty());
+}
+
QTEST_MAIN(tst_QTranslator)
#include "tst_qtranslator.moc"
diff --git a/tests/auto/qwidget/qwidget.pro b/tests/auto/qwidget/qwidget.pro
index 61db2ee..e39431b 100644
--- a/tests/auto/qwidget/qwidget.pro
+++ b/tests/auto/qwidget/qwidget.pro
@@ -14,6 +14,10 @@ mac {
OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm
}
+x11 {
+ LIBS += $$QMAKE_LIBS_X11
+}
+
symbian {
INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE
LIBS += -leikcore -lcone -leikcoctl
diff --git a/tests/auto/qwidget_window/qwidget_window.pro b/tests/auto/qwidget_window/qwidget_window.pro
index e375fab..df7d687 100644
--- a/tests/auto/qwidget_window/qwidget_window.pro
+++ b/tests/auto/qwidget_window/qwidget_window.pro
@@ -1,4 +1,7 @@
load(qttest_p4)
SOURCES += tst_qwidget_window.cpp
+x11 {
+ LIBS += $$QMAKE_LIBS_X11
+}
diff --git a/tests/auto/qwizard/tst_qwizard.cpp b/tests/auto/qwizard/tst_qwizard.cpp
index 764cd3e..f797227 100644
--- a/tests/auto/qwizard/tst_qwizard.cpp
+++ b/tests/auto/qwizard/tst_qwizard.cpp
@@ -104,6 +104,7 @@ private slots:
void setCommitPage();
void setWizardStyle();
void removePage();
+ void sideWidget();
// task-specific tests below me:
void task161660_buttonSpacing();
@@ -569,12 +570,16 @@ void tst_QWizard::addPage()
QWizard wizard;
const int N = 100;
QWizardPage *pages[N];
+ QSignalSpy spy(&wizard, SIGNAL(pageAdded(int)));
for (int i = 0; i < N; ++i) {
pages[i] = new QWizardPage(parent);
QCOMPARE(wizard.addPage(pages[i]), i);
QCOMPARE(pages[i]->window(), (QWidget *)&wizard);
QCOMPARE(wizard.startId(), 0);
+ QCOMPARE(spy.count(), 1);
+ QList<QVariant> arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), i);
}
for (int i = 0; i < N; ++i) {
@@ -585,16 +590,29 @@ void tst_QWizard::addPage()
QVERIFY(!wizard.page(N + 1));
wizard.setPage(N + 50, new QWizardPage);
+ QCOMPARE(spy.count(), 1);
+ QList<QVariant> arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), N + 50);
wizard.setPage(-3000, new QWizardPage);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), -3000);
QWizardPage *pageX = new QWizardPage;
QCOMPARE(wizard.addPage(pageX), N + 51);
QCOMPARE(wizard.page(N + 51), pageX);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), N + 51);
QCOMPARE(wizard.addPage(new QWizardPage), N + 52);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), N + 52);
QTest::ignoreMessage(QtWarningMsg,"QWizard::setPage: Cannot insert null page");
wizard.addPage(0); // generates a warning
+ QCOMPARE(spy.count(), 0);
delete parent;
}
@@ -611,6 +629,7 @@ void tst_QWizard::setPage()
QWidget *parent = new QWidget;
QWizard wizard;
QWizardPage *page;
+ QSignalSpy spy(&wizard, SIGNAL(pageAdded(int)));
QCOMPARE(wizard.startId(), -1);
QCOMPARE(wizard.currentId(), -1);
@@ -620,6 +639,7 @@ void tst_QWizard::setPage()
page = new QWizardPage(parent);
QTest::ignoreMessage(QtWarningMsg,"QWizard::setPage: Cannot insert page with ID -1");
wizard.setPage(-1, page); // gives a warning and does nothing
+ QCOMPARE(spy.count(), 0);
QVERIFY(!wizard.page(-2));
QVERIFY(!wizard.page(-1));
QVERIFY(!wizard.page(0));
@@ -631,6 +651,9 @@ void tst_QWizard::setPage()
page = new QWizardPage(parent);
wizard.setPage(0, page);
+ QCOMPARE(spy.count(), 1);
+ QList<QVariant> arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 0);
QCOMPARE(page->window(), (QWidget *)&wizard);
QCOMPARE(wizard.page(0), page);
QCOMPARE(wizard.startId(), 0);
@@ -641,6 +664,9 @@ void tst_QWizard::setPage()
page = new QWizardPage(parent);
wizard.setPage(-2, page);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), -2);
QCOMPARE(page->window(), (QWidget *)&wizard);
QCOMPARE(wizard.page(-2), page);
QCOMPARE(wizard.startId(), -2);
@@ -659,6 +685,9 @@ void tst_QWizard::setPage()
page = new QWizardPage(parent);
wizard.setPage(2, page);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 2);
QCOMPARE(wizard.page(2), page);
QCOMPARE(wizard.startId(), -2);
QCOMPARE(wizard.currentId(), -2);
@@ -675,6 +704,9 @@ void tst_QWizard::setPage()
page = new QWizardPage(parent);
wizard.setPage(-3, page);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), -3);
QCOMPARE(wizard.page(-3), page);
QCOMPARE(wizard.startId(), -3);
QCOMPARE(wizard.currentId(), -2);
@@ -743,6 +775,7 @@ void tst_QWizard::setPage()
QCOMPARE(wizard.nextId(), -2);
CHECK_VISITED(wizard, QList<int>() << -3);
}
+ QCOMPARE(spy.count(), 0);
delete parent;
}
@@ -766,7 +799,17 @@ void tst_QWizard::setStartId()
wizard.setPage(INT_MAX, new QWizardPage);
QCOMPARE(wizard.startId(), INT_MIN);
- QTest::ignoreMessage(QtWarningMsg,"QWizard::setStartId: Invalid page ID -1");
+ QTest::ignoreMessage(QtWarningMsg,"QWizard::setStartId: Invalid page ID 123");
+ wizard.setStartId(123);
+ QCOMPARE(wizard.startId(), INT_MIN);
+
+ wizard.setStartId(-1);
+ QCOMPARE(wizard.startId(), INT_MIN);
+
+ wizard.setStartId(-2);
+ QCOMPARE(wizard.startId(), -2);
+ QCOMPARE(wizard.nextId(), -1);
+
wizard.setStartId(-1);
QCOMPARE(wizard.startId(), INT_MIN);
@@ -2209,6 +2252,7 @@ void tst_QWizard::removePage()
QWizardPage *page1 = new QWizardPage;
QWizardPage *page2 = new QWizardPage;
QWizardPage *page3 = new QWizardPage;
+ QSignalSpy spy(&wizard, SIGNAL(pageRemoved(int)));
wizard.setPage(0, page0);
wizard.setPage(1, page1);
@@ -2218,26 +2262,36 @@ void tst_QWizard::removePage()
wizard.restart();
QCOMPARE(wizard.pageIds().size(), 4);
QCOMPARE(wizard.visitedPages().size(), 1);
+ QCOMPARE(spy.count(), 0);
// Removing a non-existent page
wizard.removePage(4);
QCOMPARE(wizard.pageIds().size(), 4);
+ QCOMPARE(spy.count(), 0);
// Removing and then reinserting a page
QCOMPARE(wizard.pageIds().size(), 4);
QVERIFY(wizard.pageIds().contains(2));
wizard.removePage(2);
+ QCOMPARE(spy.count(), 1);
+ QList<QVariant> arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 2);
QCOMPARE(wizard.pageIds().size(), 3);
QVERIFY(!wizard.pageIds().contains(2));
wizard.setPage(2, page2);
+ QCOMPARE(spy.count(), 0);
QCOMPARE(wizard.pageIds().size(), 4);
QVERIFY(wizard.pageIds().contains(2));
// Removing the same page twice
wizard.removePage(2); // restore
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 2);
QCOMPARE(wizard.pageIds().size(), 3);
QVERIFY(!wizard.pageIds().contains(2));
wizard.removePage(2);
+ QCOMPARE(spy.count(), 0);
QCOMPARE(wizard.pageIds().size(), 3);
QVERIFY(!wizard.pageIds().contains(2));
@@ -2247,7 +2301,11 @@ void tst_QWizard::removePage()
wizard.next();
QCOMPARE(wizard.visitedPages().size(), 2);
QCOMPARE(wizard.currentPage(), page1);
+ QCOMPARE(spy.count(), 0);
wizard.removePage(2);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 2);
QCOMPARE(wizard.visitedPages().size(), 2);
QVERIFY(!wizard.pageIds().contains(2));
QCOMPARE(wizard.currentPage(), page1);
@@ -2256,9 +2314,13 @@ void tst_QWizard::removePage()
wizard.setPage(2, page2); // restore
wizard.restart();
wizard.next();
+ QCOMPARE(spy.count(), 0);
QCOMPARE(wizard.visitedPages().size(), 2);
QCOMPARE(wizard.currentPage(), page1);
wizard.removePage(0);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 0);
QCOMPARE(wizard.visitedPages().size(), 1);
QVERIFY(!wizard.visitedPages().contains(0));
QVERIFY(!wizard.pageIds().contains(0));
@@ -2268,9 +2330,13 @@ void tst_QWizard::removePage()
wizard.setPage(0, page0); // restore
wizard.restart();
wizard.next();
+ QCOMPARE(spy.count(), 0);
QCOMPARE(wizard.visitedPages().size(), 2);
QCOMPARE(wizard.currentPage(), page1);
wizard.removePage(1);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 1);
QCOMPARE(wizard.visitedPages().size(), 1);
QVERIFY(!wizard.visitedPages().contains(1));
QVERIFY(!wizard.pageIds().contains(1));
@@ -2278,6 +2344,9 @@ void tst_QWizard::removePage()
// Remove the current page which is the first (and only) one in the history
wizard.removePage(0);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 0);
QCOMPARE(wizard.visitedPages().size(), 1);
QVERIFY(!wizard.visitedPages().contains(0));
QCOMPARE(wizard.pageIds().size(), 2);
@@ -2285,6 +2354,9 @@ void tst_QWizard::removePage()
QCOMPARE(wizard.currentPage(), page2);
//
wizard.removePage(2);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 2);
QCOMPARE(wizard.visitedPages().size(), 1);
QVERIFY(!wizard.visitedPages().contains(2));
QCOMPARE(wizard.pageIds().size(), 1);
@@ -2292,11 +2364,34 @@ void tst_QWizard::removePage()
QCOMPARE(wizard.currentPage(), page3);
//
wizard.removePage(3);
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).toInt(), 3);
QVERIFY(wizard.visitedPages().empty());
QVERIFY(wizard.pageIds().empty());
QCOMPARE(wizard.currentPage(), static_cast<QWizardPage *>(0));
}
+void tst_QWizard::sideWidget()
+{
+ QWizard wizard;
+
+ wizard.setSideWidget(0);
+ QVERIFY(wizard.sideWidget() == 0);
+ QWidget *w1 = new QWidget(&wizard);
+ wizard.setSideWidget(w1);
+ QVERIFY(wizard.sideWidget() == w1);
+ QWidget *w2 = new QWidget(&wizard);
+ wizard.setSideWidget(w2);
+ QVERIFY(wizard.sideWidget() == w2);
+ QVERIFY(w1->parent() != 0);
+ QCOMPARE(w1->window(), static_cast<QWidget *>(&wizard));
+ QCOMPARE(w2->window(), static_cast<QWidget *>(&wizard));
+ w1->setParent(0);
+ wizard.setSideWidget(0);
+ QVERIFY(wizard.sideWidget() == 0);
+}
+
void tst_QWizard::task161660_buttonSpacing()
{
#ifndef QT_NO_STYLE_PLASTIQUE