summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-06-04 18:44:12 (GMT)
committerTobias Koenig <tokoe@kde.org>2009-06-04 18:44:12 (GMT)
commit5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd (patch)
treea1fc7824b38c3b712893794cfe55fa285cd3c760 /tests
parentf7741b78c90abcb272345810d55e446a7f390032 (diff)
parentb1b09172aee658e085423ddf6abfea291a072c74 (diff)
downloadQt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.zip
Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.gz
Qt-5d87f2542bbcb0877f4a9a9b5be4df80cd6aa4cd.tar.bz2
Merge commit 'qt-mainline/master'
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/_networkselftest/_networkselftest.pro6
-rw-r--r--tests/auto/_networkselftest/tst_networkselftest.cpp592
-rw-r--r--tests/auto/auto.pro11
-rw-r--r--tests/auto/macgui/tst_gui.cpp7
-rw-r--r--tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp154
-rw-r--r--tests/auto/network-settings.h9
-rw-r--r--tests/auto/q3socketdevice/tst_q3socketdevice.cpp7
-rw-r--r--tests/auto/qanimationgroup/qanimationgroup.pro5
-rw-r--r--tests/auto/qanimationgroup/tst_qanimationgroup.cpp413
-rw-r--r--tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp53
-rw-r--r--tests/auto/qcolor/tst_qcolor.cpp21
-rw-r--r--tests/auto/qcombobox/tst_qcombobox.cpp32
-rw-r--r--tests/auto/qcontiguouscache/qcontiguouscache.pro8
-rw-r--r--tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp479
-rw-r--r--tests/auto/qcssparser/tst_cssparser.cpp13
-rw-r--r--tests/auto/qdatastream/tst_qdatastream.cpp8
-rw-r--r--tests/auto/qdate/tst_qdate.cpp26
-rw-r--r--tests/auto/qeasingcurve/qeasingcurve.pro3
-rw-r--r--tests/auto/qeasingcurve/tst_qeasingcurve.cpp493
-rw-r--r--tests/auto/qfile/copy-fallback.qrc5
-rw-r--r--tests/auto/qfile/test/test.pro2
-rw-r--r--tests/auto/qfile/tst_qfile.cpp37
-rw-r--r--tests/auto/qfiledialog/tst_qfiledialog.cpp33
-rw-r--r--tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp65
-rw-r--r--tests/auto/qfuture/tst_qfuture.cpp2
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp285
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp4
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp26
-rw-r--r--tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp200
-rw-r--r--tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp9
-rw-r--r--tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp25
-rw-r--r--tests/auto/qicon/tst_qicon.cpp43
-rw-r--r--tests/auto/qimage/images/image.tifbin0 -> 2242 bytes
-rw-r--r--tests/auto/qimage/tst_qimage.cpp37
-rw-r--r--tests/auto/qimagereader/images/image_100dpi.tifbin0 -> 2242 bytes
-rw-r--r--tests/auto/qimagereader/qimagereader.pro2
-rw-r--r--tests/auto/qimagereader/qimagereader.qrc1
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp421
-rw-r--r--tests/auto/qimagewriter/tst_qimagewriter.cpp44
-rw-r--r--tests/auto/qiodevice/tst_qiodevice.cpp4
-rw-r--r--tests/auto/qitemdelegate/tst_qitemdelegate.cpp78
-rw-r--r--tests/auto/qitemmodel/tst_qitemmodel.cpp2
-rw-r--r--tests/auto/qitemview/tst_qitemview.cpp2
-rw-r--r--tests/auto/qmake/testcompiler.cpp6
-rw-r--r--tests/auto/qmake/testdata/bundle-spaces/some-file6
-rw-r--r--tests/auto/qmake/tst_qmake.cpp16
-rw-r--r--tests/auto/qmap/tst_qmap.cpp17
-rw-r--r--tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp16
-rw-r--r--tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp3
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp639
-rw-r--r--tests/auto/qobject/tst_qobject.cpp81
-rw-r--r--tests/auto/qobjectrace/tst_qobjectrace.cpp113
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp24
-rw-r--r--tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro5
-rw-r--r--tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp834
-rw-r--r--tests/auto/qpixmapcache/tst_qpixmapcache.cpp266
-rw-r--r--tests/auto/qprinter/tst_qprinter.cpp5
-rw-r--r--tests/auto/qpropertyanimation/qpropertyanimation.pro5
-rw-r--r--tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp958
-rw-r--r--tests/auto/qringbuffer/qringbuffer.pro6
-rw-r--r--tests/auto/qringbuffer/tst_qringbuffer.cpp200
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp14
-rw-r--r--tests/auto/qscriptqobject/tst_qscriptqobject.cpp66
-rw-r--r--tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro5
-rw-r--r--tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp1649
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp137
-rw-r--r--tests/auto/qsidebar/tst_qsidebar.cpp9
-rw-r--r--tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp46
-rw-r--r--tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp10
-rw-r--r--tests/auto/qspinbox/tst_qspinbox.cpp6
-rw-r--r--tests/auto/qsplitter/tst_qsplitter.cpp5
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp22
-rw-r--r--tests/auto/qsslsocket/qsslsocket.pro6
-rw-r--r--tests/auto/qsslsocket/tst_qsslsocket.cpp69
-rw-r--r--tests/auto/qstate/qstate.pro5
-rw-r--r--tests/auto/qstate/tst_qstate.cpp340
-rw-r--r--tests/auto/qstatemachine/qstatemachine.pro4
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp3758
-rw-r--r--tests/auto/qtcpserver/tst_qtcpserver.cpp2
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp38
-rw-r--r--tests/auto/qtessellator/testtessellator.cpp2
-rw-r--r--tests/auto/qtessellator/tst_tessellator.cpp8
-rw-r--r--tests/auto/qtessellator/utils.cpp2
-rw-r--r--tests/auto/qthreadonce/tst_qthreadonce.cpp2
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp30
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp36
-rw-r--r--tests/auto/selftests/expected_xunit.txt13
-rw-r--r--tests/auto/selftests/xunit/tst_xunit.cpp29
-rwxr-xr-xtests/auto/test.pl2
-rw-r--r--tests/auto/uic/baseline/languagesdialog.ui.h12
-rw-r--r--tests/auto/utf8/tst_utf8.cpp2
-rw-r--r--tests/benchmarks/benchmarks.pro2
-rw-r--r--tests/benchmarks/qanimation/dummyanimation.cpp20
-rw-r--r--tests/benchmarks/qanimation/dummyanimation.h19
-rw-r--r--tests/benchmarks/qanimation/dummyobject.cpp25
-rw-r--r--tests/benchmarks/qanimation/dummyobject.h23
-rw-r--r--tests/benchmarks/qanimation/main.cpp150
-rw-r--r--tests/benchmarks/qanimation/qanimation.pro18
-rw-r--r--tests/benchmarks/qanimation/rectanimation.cpp58
-rw-r--r--tests/benchmarks/qanimation/rectanimation.h30
-rw-r--r--tests/benchmarks/qgraphicsitem/qgraphicsitem.pro6
-rw-r--r--tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp170
-rw-r--r--tests/benchmarks/qgraphicsview/images/wine-big.jpegbin0 -> 12249 bytes
-rw-r--r--tests/benchmarks/qgraphicsview/qgraphicsview.qrc1
-rw-r--r--tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp103
-rw-r--r--tests/benchmarks/qmatrix4x4/qmatrix4x4.pro6
-rw-r--r--tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp261
-rw-r--r--tests/benchmarks/qpixmapcache/qpixmapcache.pro6
-rw-r--r--tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp226
-rw-r--r--tests/benchmarks/qstring/main.cpp123
-rw-r--r--tests/benchmarks/qstring/qstring.pro4
-rw-r--r--tests/benchmarks/qstringbuilder/main.cpp374
-rw-r--r--tests/benchmarks/qstringbuilder/qstringbuilder.pro12
-rw-r--r--tests/benchmarks/qvariant/qvariant.pro1
-rw-r--r--tests/benchmarks/qvariant/tst_qvariant.cpp115
115 files changed, 14458 insertions, 491 deletions
diff --git a/tests/auto/_networkselftest/_networkselftest.pro b/tests/auto/_networkselftest/_networkselftest.pro
new file mode 100644
index 0000000..9e2ad0e
--- /dev/null
+++ b/tests/auto/_networkselftest/_networkselftest.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+
+SOURCES += tst_networkselftest.cpp
+QT = core network
+DEFINES += SRCDIR=\\\"$$PWD\\\"
+
diff --git a/tests/auto/_networkselftest/tst_networkselftest.cpp b/tests/auto/_networkselftest/tst_networkselftest.cpp
new file mode 100644
index 0000000..dab4433
--- /dev/null
+++ b/tests/auto/_networkselftest/tst_networkselftest.cpp
@@ -0,0 +1,592 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtNetwork/QtNetwork>
+#include "../network-settings.h"
+
+class tst_NetworkSelfTest: public QObject
+{
+ Q_OBJECT
+private slots:
+ void hostTest();
+ void dnsResolution_data();
+ void dnsResolution();
+ void serverReachability();
+ void remotePortsOpen_data();
+ void remotePortsOpen();
+
+ // specific protocol tests
+ void ftpServer();
+ void imapServer();
+ void httpServer();
+ void httpsServer();
+ void httpProxy();
+ void httpProxyBasicAuth();
+ void httpProxyNtlmAuth();
+ void socks5Proxy();
+ void socks5ProxyAuth();
+};
+
+class Chat
+{
+public:
+ enum Type {
+ Reconnect,
+ Send,
+ Expect,
+ SkipBytes,
+ DiscardUntil,
+ DiscardUntilDisconnect,
+ Disconnect,
+ RemoteDisconnect,
+ StartEncryption
+ };
+ Chat(Type t, const QByteArray &d)
+ : data(d), type(t)
+ {
+ }
+ Chat(Type t, int val = 0)
+ : value(val), type(t)
+ {
+ }
+
+ static inline Chat send(const QByteArray &data)
+ { return Chat(Send, data); }
+ static inline Chat expect(const QByteArray &data)
+ { return Chat(Expect, data); }
+ static inline Chat discardUntil(const QByteArray &data)
+ { return Chat(DiscardUntil, data); }
+ static inline Chat skipBytes(int count)
+ { return Chat(SkipBytes, count); }
+
+ QByteArray data;
+ int value;
+ Type type;
+};
+
+static QString prettyByteArray(const QByteArray &array)
+{
+ // any control chars?
+ QString result;
+ result.reserve(array.length() + array.length() / 3);
+ for (int i = 0; i < array.length(); ++i) {
+ char c = array.at(i);
+ switch (c) {
+ case '\n':
+ result += "\\n";
+ continue;
+ case '\r':
+ result += "\\r";
+ continue;
+ case '\t':
+ result += "\\t";
+ continue;
+ case '"':
+ result += "\\\"";
+ continue;
+ default:
+ break;
+ }
+
+ if (c < 0x20 || uchar(c) >= 0x7f) {
+ result += '\\';
+ result += QString::number(uchar(c), 8);
+ } else {
+ result += c;
+ }
+ }
+ return result;
+}
+
+static bool doSocketRead(QTcpSocket *socket, int minBytesAvailable, int timeout = 2000)
+{
+ QTime timer;
+ timer.start();
+ forever {
+ if (socket->bytesAvailable() >= minBytesAvailable)
+ return true;
+ if (socket->state() == QAbstractSocket::UnconnectedState
+ || timer.elapsed() >= timeout)
+ return false;
+ if (!socket->waitForReadyRead(timeout - timer.elapsed()))
+ return false;
+ }
+}
+
+static bool doSocketFlush(QTcpSocket *socket, int timeout = 2000)
+{
+#ifndef QT_NO_OPENSSL
+ QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
+#endif
+ QTime timer;
+ timer.start();
+ forever {
+ if (socket->bytesToWrite() == 0
+#ifndef QT_NO_OPENSSL
+ && sslSocket->encryptedBytesToWrite() == 0
+#endif
+ )
+ return true;
+ if (socket->state() == QAbstractSocket::UnconnectedState
+ || timer.elapsed() >= timeout)
+ return false;
+ if (!socket->waitForBytesWritten(timeout - timer.elapsed()))
+ return false;
+ }
+}
+
+static void netChat(int port, const QList<Chat> &chat)
+{
+#ifndef QT_NO_OPENSSL
+ QSslSocket socket;
+#else
+ QTcpSocket socket;
+#endif
+
+ socket.connectToHost(QtNetworkSettings::serverName(), port);
+ qDebug() << 0 << "Connecting to server on port" << port;
+ QVERIFY2(socket.waitForConnected(10000),
+ QString("Failed to connect to server in step 0: %1").arg(socket.errorString()).toLocal8Bit());
+
+ // now start the chat
+ QList<Chat>::ConstIterator it = chat.constBegin();
+ for (int i = 1; it != chat.constEnd(); ++it, ++i) {
+ if (it->type != Chat::Reconnect
+ && socket.state() != QAbstractSocket::ConnectedState
+ && socket.state() != QAbstractSocket::ClosingState)
+ QFAIL(QString("Internal error: socket is in invalid state %1 in step %2")
+ .arg(socket.state()).arg(i).toLocal8Bit());
+
+ switch (it->type) {
+ case Chat::Expect: {
+ qDebug() << i << "Expecting" << prettyByteArray(it->data);
+ if (!doSocketRead(&socket, it->data.length()))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ // pop that many bytes off the socket
+ QByteArray received = socket.read(it->data.length());
+
+ // is it what we expected?
+ QVERIFY2(received == it->data,
+ QString("Did not receive expected data in step %1: data received was:\n%2")
+ .arg(i).arg(prettyByteArray(received)).toLocal8Bit());
+
+ break;
+ }
+
+ case Chat::DiscardUntil:
+ qDebug() << i << "Discarding until" << prettyByteArray(it->data);
+ while (true) {
+ // scan the buffer until we have our string
+ if (!doSocketRead(&socket, it->data.length()))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ QByteArray buffer;
+ buffer.resize(socket.bytesAvailable());
+ socket.peek(buffer.data(), socket.bytesAvailable());
+
+ int pos = buffer.indexOf(it->data);
+ if (pos == -1) {
+ // data not found, keep trying
+ continue;
+ }
+
+ buffer = socket.read(pos + it->data.length());
+ qDebug() << i << "Discarded" << prettyByteArray(buffer);
+ break;
+ }
+ break;
+
+ case Chat::SkipBytes: {
+ qDebug() << i << "Skipping" << it->value << "bytes";
+ if (!doSocketRead(&socket, it->value))
+ QFAIL(QString("Failed to receive data in step %1: timeout").arg(i).toLocal8Bit());
+
+ // now discard the bytes
+ QByteArray buffer = socket.read(it->value);
+ qDebug() << i << "Skipped" << prettyByteArray(buffer);
+ break;
+ }
+
+ case Chat::Send: {
+ qDebug() << i << "Sending" << prettyByteArray(it->data);
+ socket.write(it->data);
+ if (!doSocketFlush(&socket)) {
+ QVERIFY2(socket.state() == QAbstractSocket::ConnectedState,
+ QString("Socket disconnected while sending data in step %1").arg(i).toLocal8Bit());
+ QFAIL(QString("Failed to send data in step %1: timeout").arg(i).toLocal8Bit());
+ }
+ break;
+ }
+
+ case Chat::Disconnect:
+ qDebug() << i << "Disconnecting from host";
+ socket.disconnectFromHost();
+
+ // is this the last command?
+ if (it + 1 != chat.constEnd())
+ break;
+
+ // fall through:
+ case Chat::RemoteDisconnect:
+ case Chat::DiscardUntilDisconnect:
+ qDebug() << i << "Waiting for remote disconnect";
+ if (socket.state() != QAbstractSocket::UnconnectedState)
+ socket.waitForDisconnected(10000);
+ QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState,
+ QString("Socket did not disconnect as expected in step %1").arg(i).toLocal8Bit());
+
+ // any data left?
+ if (it->type == Chat::DiscardUntilDisconnect) {
+ QByteArray buffer = socket.readAll();
+ qDebug() << i << "Discarded in the process:" << prettyByteArray(buffer);
+ }
+
+ if (socket.bytesAvailable() != 0)
+ QFAIL(QString("Unexpected bytes still on buffer when disconnecting in step %1:\n%2")
+ .arg(i).arg(prettyByteArray(socket.readAll())).toLocal8Bit());
+ break;
+
+ case Chat::Reconnect:
+ qDebug() << i << "Reconnecting to server on port" << port;
+ socket.connectToHost(QtNetworkSettings::serverName(), port);
+ QVERIFY2(socket.waitForConnected(10000),
+ QString("Failed to reconnect to server in step %1: %2").arg(i).arg(socket.errorString()).toLocal8Bit());
+ break;
+
+ case Chat::StartEncryption:
+#ifdef QT_NO_OPENSSL
+ QFAIL("Internal error: SSL required for this test");
+#else
+ qDebug() << i << "Starting client encryption";
+ socket.ignoreSslErrors();
+ socket.startClientEncryption();
+ QVERIFY2(socket.waitForEncrypted(5000),
+ QString("Failed to start client encryption in step %1: %2").arg(i)
+ .arg(socket.errorString()).toLocal8Bit());
+ break;
+#endif
+ }
+ }
+}
+
+void tst_NetworkSelfTest::hostTest()
+{
+ // this is a localhost self-test
+ QHostInfo localhost = QHostInfo::fromName("localhost");
+ QCOMPARE(localhost.error(), QHostInfo::NoError);
+ QVERIFY(!localhost.addresses().isEmpty());
+
+ QTcpServer server;
+ QVERIFY(server.listen());
+
+ QTcpSocket socket;
+ socket.connectToHost("127.0.0.1", server.serverPort());
+ QVERIFY(socket.waitForConnected(10000));
+}
+
+void tst_NetworkSelfTest::dnsResolution_data()
+{
+ QTest::addColumn<QString>("hostName");
+ QTest::newRow("local-name") << QtNetworkSettings::serverLocalName();
+ QTest::newRow("fqdn") << QtNetworkSettings::serverName();
+}
+
+void tst_NetworkSelfTest::dnsResolution()
+{
+ QFETCH(QString, hostName);
+ QHostInfo resolved = QHostInfo::fromName(hostName);
+ QVERIFY2(resolved.error() == QHostInfo::NoError,
+ QString("Failed to resolve hostname %1: %2").arg(hostName, resolved.errorString()).toLocal8Bit());
+}
+
+void tst_NetworkSelfTest::serverReachability()
+{
+ // check that we get a proper error connecting to port 1
+ QTcpSocket socket;
+ socket.connectToHost(QtNetworkSettings::serverName(), 1);
+ socket.waitForConnected(10000);
+ QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!");
+ QVERIFY2(socket.error() == QAbstractSocket::ConnectionRefusedError,
+ QString("Could not reach server: %1").arg(socket.errorString()).toLocal8Bit());
+}
+
+void tst_NetworkSelfTest::remotePortsOpen_data()
+{
+ QTest::addColumn<int>("portNumber");
+ QTest::newRow("ftp") << 21;
+ QTest::newRow("ssh") << 22;
+ QTest::newRow("imap") << 143;
+ QTest::newRow("http") << 80;
+ QTest::newRow("https") << 443;
+ QTest::newRow("http-proxy") << 3128;
+ QTest::newRow("http-proxy-auth-basic") << 3129;
+ QTest::newRow("http-proxy-auth-ntlm") << 3130;
+ QTest::newRow("socks5-proxy") << 1080;
+ QTest::newRow("socks5-proxy-auth") << 1081;
+}
+
+void tst_NetworkSelfTest::remotePortsOpen()
+{
+ QFETCH(int, portNumber);
+ QTcpSocket socket;
+ socket.connectToHost(QtNetworkSettings::serverName(), portNumber);
+
+ if (!socket.waitForConnected(10000)) {
+ if (socket.error() == QAbstractSocket::SocketTimeoutError)
+ QFAIL(QString("Network timeout connecting to the server on port %1").arg(portNumber).toLocal8Bit());
+ else
+ QFAIL(QString("Error connecting to server on port %1: %2").arg(portNumber).arg(socket.errorString()).toLocal8Bit());
+ }
+ QVERIFY(socket.state() == QAbstractSocket::ConnectedState);
+}
+
+static QList<Chat> ftpChat()
+{
+ return QList<Chat>() << Chat::expect("220")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("USER anonymous\r\n")
+ << Chat::expect("331")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("PASS user@hostname\r\n")
+ << Chat::expect("230")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("QUIT\r\n")
+ << Chat::expect("221")
+ << Chat::discardUntil("\r\n")
+ << Chat::RemoteDisconnect;
+}
+
+void tst_NetworkSelfTest::ftpServer()
+{
+ netChat(21, ftpChat());
+}
+
+void tst_NetworkSelfTest::imapServer()
+{
+ netChat(143, QList<Chat>()
+ << Chat::expect("* OK ")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("1 CAPABILITY\r\n")
+ << Chat::expect("* CAPABILITY ")
+ << Chat::discardUntil("1 OK")
+ << Chat::discardUntil("\r\n")
+ << Chat::send("2 LOGOUT\r\n")
+ << Chat::discardUntil("2 OK")
+ << Chat::discardUntil("\r\n")
+ << Chat::RemoteDisconnect);
+}
+
+void tst_NetworkSelfTest::httpServer()
+{
+ netChat(80, QList<Chat>()
+ // HTTP/0.9 chat:
+ << Chat::send("GET /\r\n")
+ << Chat::DiscardUntilDisconnect
+
+ // HTTP/1.0 chat:
+ << Chat::Reconnect
+ << Chat::send("GET / HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+
+ // HTTP/1.0 POST:
+ << Chat::Reconnect
+ << Chat::send("POST / HTTP/1.0\r\n"
+ "Content-Length: 5\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ "Hello")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+ );
+}
+
+void tst_NetworkSelfTest::httpsServer()
+{
+#ifndef QT_NO_OPENSSL
+ netChat(443, QList<Chat>()
+ << Chat::StartEncryption
+ << Chat::send("GET / HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect);
+#else
+ QSKIP("SSL not enabled, cannot test");
+#endif
+}
+
+void tst_NetworkSelfTest::httpProxy()
+{
+ netChat(3128, QList<Chat>()
+ // proxy GET
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect
+
+ // proxy CONNECT
+ << Chat::Reconnect
+ << Chat::send("CONNECT " + QtNetworkSettings::serverName().toLatin1() + ":21 HTTP/1.0\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::discardUntil("\r\n\r\n")
+ << ftpChat());
+}
+
+void tst_NetworkSelfTest::httpProxyBasicAuth()
+{
+ netChat(3129, QList<Chat>()
+ // test auth required response
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("407 ")
+ << Chat::discardUntil("\r\nProxy-Authenticate: Basic realm=\"")
+ << Chat::DiscardUntilDisconnect
+
+ // now try sending our credentials
+ << Chat::Reconnect
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: close\r\n"
+ "Proxy-Authorization: Basic cXNvY2tzdGVzdDpwYXNzd29yZA==\r\n"
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("200 ")
+ << Chat::DiscardUntilDisconnect);
+}
+
+void tst_NetworkSelfTest::httpProxyNtlmAuth()
+{
+ netChat(3130, QList<Chat>()
+ // test auth required response
+ << Chat::send("GET http://" + QtNetworkSettings::serverName().toLatin1() + "/ HTTP/1.0\r\n"
+ "Host: " + QtNetworkSettings::serverName().toLatin1() + "\r\n"
+ "Proxy-connection: keep-alive\r\n" // NTLM auth will disconnect
+ "\r\n")
+ << Chat::expect("HTTP/1.")
+ << Chat::discardUntil(" ")
+ << Chat::expect("407 ")
+ << Chat::discardUntil("\r\nProxy-Authenticate: NTLM\r\n")
+ << Chat::DiscardUntilDisconnect
+ );
+}
+
+// SOCKSv5 is a binary protocol
+static const char handshakeNoAuth[] = "\5\1\0";
+static const char handshakeOkNoAuth[] = "\5\0";
+static const char handshakeAuthPassword[] = "\5\1\2\1\12qsockstest\10password";
+static const char handshakeOkPasswdAuth[] = "\5\2\1\0";
+static const char handshakeAuthNotOk[] = "\5\377";
+static const char connect1[] = "\5\1\0\1\177\0\0\1\0\25"; // Connect IPv4 127.0.0.1 port 21
+static const char connect2[] = "\5\1\0\3\11localhost\0\25"; // Connect hostname localhost 21
+static const char connected[] = "\5\0\0";
+
+void tst_NetworkSelfTest::socks5Proxy()
+{
+ netChat(1080, QList<Chat>()
+ // IP address connection
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+
+ // hostname connection
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeOkNoAuth, -1 + sizeof handshakeOkNoAuth))
+ << Chat::send(QByteArray(connect2, -1 + sizeof connect2))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+ );
+}
+
+void tst_NetworkSelfTest::socks5ProxyAuth()
+{
+ netChat(1081, QList<Chat>()
+ // unauthenticated connect -- will get error
+ << Chat::send(QByteArray(handshakeNoAuth, -1 + sizeof handshakeNoAuth))
+ << Chat::expect(QByteArray(handshakeAuthNotOk, -1 + sizeof handshakeAuthNotOk))
+ << Chat::RemoteDisconnect
+
+ // now try to connect with authentication
+ << Chat::Reconnect
+ << Chat::send(QByteArray(handshakeAuthPassword, -1 + sizeof handshakeAuthPassword))
+ << Chat::expect(QByteArray(handshakeOkPasswdAuth, -1 + sizeof handshakeOkPasswdAuth))
+ << Chat::send(QByteArray(connect1, -1 + sizeof connect1))
+ << Chat::expect(QByteArray(connected, -1 + sizeof connected))
+ << Chat::expect("\1") // IPv4 address following
+ << Chat::skipBytes(6) // the server's local address and port
+ << ftpChat()
+ );
+}
+
+QTEST_MAIN(tst_NetworkSelfTest)
+#include "tst_networkselftest.moc"
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index e8eea71..ab09817 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -4,7 +4,8 @@ TEMPLATE = subdirs
!wince*:SUBDIRS += \
headers
-SUBDIRS += bic \
+SUBDIRS += _networkselftest \
+ bic \
collections \
compile \
compilerwarnings \
@@ -75,6 +76,7 @@ SUBDIRS += bic \
qaction \
qactiongroup \
qalgorithms \
+ qanimationgroup \
qapplication \
qatomicint \
qatomicpointer \
@@ -209,10 +211,12 @@ SUBDIRS += bic \
qnumeric \
qobject \
qobjectrace \
+ qcontiguouscache \
qpaintengine \
qpainter \
qpainterpath \
qpalette \
+ qparallelanimationgroup \
qpathclipper \
qpen \
qpicture \
@@ -228,6 +232,7 @@ SUBDIRS += bic \
qprocess \
qprogressbar \
qprogressdialog \
+ qpropertyanimation \
qpushbutton \
qqueue \
qradiobutton \
@@ -238,6 +243,7 @@ SUBDIRS += bic \
qregexpvalidator \
qregion \
qresourceengine \
+ qringbuffer \
qscriptable \
qscriptclass \
qscriptcontext \
@@ -254,6 +260,7 @@ SUBDIRS += bic \
qscrollarea \
qsemaphore \
qsharedpointer \
+ qsequentialanimationgroup \
qset \
qsettings \
qshortcut \
@@ -287,6 +294,8 @@ SUBDIRS += bic \
qstackedwidget \
qstandarditem \
qstandarditemmodel \
+ qstate \
+ qstatemachine \
qstatusbar \
qstl \
qstring \
diff --git a/tests/auto/macgui/tst_gui.cpp b/tests/auto/macgui/tst_gui.cpp
index b302f8b..641e596 100644
--- a/tests/auto/macgui/tst_gui.cpp
+++ b/tests/auto/macgui/tst_gui.cpp
@@ -69,8 +69,7 @@ private slots:
QPixmap grabWindowContents(QWidget * widget)
{
- const int titleBarHeight = widget->frameGeometry().height() - widget->height();
- return QPixmap::grabWindow(widget->winId(), 0, titleBarHeight, -1, widget->height());
+ return QPixmap::grabWindow(widget->winId());
}
/*
@@ -79,10 +78,6 @@ QPixmap grabWindowContents(QWidget * widget)
*/
void tst_gui::scrollbarPainting()
{
-#if defined (Q_WS_MAC) && defined (__i386__)
- QSKIP("This test fails on scruffy when run by the autotest system (but not when you run it manually).", SkipAll);
-#endif
-
ColorWidget colorWidget;
colorWidget.resize(400, 400);
diff --git a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
index bb510fc..4d51e89 100644
--- a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
+++ b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
@@ -167,6 +167,9 @@ private slots:
void fill();
+ void mapRect_data();
+ void mapRect();
+
private:
static void setMatrix(QMatrix2x2& m, const qreal *values);
static void setMatrixFixed(QMatrix2x2& m, const qreal *values);
@@ -1975,6 +1978,14 @@ void tst_QMatrix::scale4x4_data()
0.0f, 0.0f, 0.0f, 1.0f};
QTest::newRow("complex")
<< (qreal)2.0f << (qreal)11.0f << (qreal)-6.5f << (void *)complexScale;
+
+ static const qreal complexScale2D[] =
+ {2.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, -11.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f};
+ QTest::newRow("complex2D")
+ << (qreal)2.0f << (qreal)-11.0f << (qreal)1.0f << (void *)complexScale2D;
}
void tst_QMatrix::scale4x4()
{
@@ -1993,6 +2004,12 @@ void tst_QMatrix::scale4x4()
m2.scale(x, y, z);
QVERIFY(isSame(m2, (const qreal *)resultValues));
+ if (z == 1.0f) {
+ QMatrix4x4 m2b;
+ m2b.scale(x, y);
+ QVERIFY(m2b == m2);
+ }
+
QVector3D v1(2.0f, 3.0f, -4.0f);
QVector3D v2 = m1 * v1;
QCOMPARE(v2.x(), (qreal)(2.0f * x));
@@ -2046,6 +2063,12 @@ void tst_QMatrix::scale4x4()
QVERIFY(isSame(m5, (const qreal *)resultValues));
}
+ if (z == 1.0f) {
+ QMatrix4x4 m4b(m3);
+ m4b.scale(x, y);
+ QVERIFY(m4b == m4);
+ }
+
// Test coverage when the special matrix type is unknown.
QMatrix4x4 m6;
@@ -2101,6 +2124,14 @@ void tst_QMatrix::translate4x4_data()
0.0f, 0.0f, 0.0f, 1.0f};
QTest::newRow("complex")
<< (qreal)2.0f << (qreal)11.0f << (qreal)-6.5f << (void *)complexTranslate;
+
+ static const qreal complexTranslate2D[] =
+ {1.0f, 0.0f, 0.0f, 2.0f,
+ 0.0f, 1.0f, 0.0f, -11.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f};
+ QTest::newRow("complex2D")
+ << (qreal)2.0f << (qreal)-11.0f << (qreal)0.0f << (void *)complexTranslate2D;
}
void tst_QMatrix::translate4x4()
{
@@ -2119,6 +2150,12 @@ void tst_QMatrix::translate4x4()
m2.translate(x, y, z);
QVERIFY(isSame(m2, (const qreal *)resultValues));
+ if (z == 0.0f) {
+ QMatrix4x4 m2b;
+ m2b.translate(x, y);
+ QVERIFY(m2b == m2);
+ }
+
QVector3D v1(2.0f, 3.0f, -4.0f);
QVector3D v2 = m1 * v1;
QCOMPARE(v2.x(), (qreal)(2.0f + x));
@@ -2153,6 +2190,12 @@ void tst_QMatrix::translate4x4()
QMatrix4x4 m4(m3);
m4.translate(x, y, z);
QVERIFY(m4 == m3 * m1);
+
+ if (z == 0.0f) {
+ QMatrix4x4 m4b(m3);
+ m4b.translate(x, y);
+ QVERIFY(m4b == m4);
+ }
}
// Test the generation and use of 4x4 rotation matrices.
@@ -3180,6 +3223,117 @@ void tst_QMatrix::fill()
QVERIFY(isSame(m2, fillValues4x3));
}
+// Test the mapRect() function for QRect and QRectF.
+void tst_QMatrix::mapRect_data()
+{
+ QTest::addColumn<qreal>("x");
+ QTest::addColumn<qreal>("y");
+ QTest::addColumn<qreal>("width");
+ QTest::addColumn<qreal>("height");
+
+ QTest::newRow("null")
+ << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f;
+ QTest::newRow("rect")
+ << (qreal)1.0f << (qreal)-20.5f << (qreal)100.0f << (qreal)63.75f;
+}
+void tst_QMatrix::mapRect()
+{
+ QFETCH(qreal, x);
+ QFETCH(qreal, y);
+ QFETCH(qreal, width);
+ QFETCH(qreal, height);
+
+ QRectF rect(x, y, width, height);
+ QRect recti(qRound(x), qRound(y), qRound(width), qRound(height));
+
+ QMatrix4x4 m1;
+ QVERIFY(m1.mapRect(rect) == rect);
+ QVERIFY(m1.mapRect(recti) == recti);
+
+ QMatrix4x4 m2;
+ m2.translate(-100.5f, 64.0f);
+ QRectF translated = rect.translated(-100.5f, 64.0f);
+ QRect translatedi = QRect(qRound(recti.x() - 100.5f), recti.y() + 64,
+ recti.width(), recti.height());
+ QVERIFY(m2.mapRect(rect) == translated);
+ QVERIFY(m2.mapRect(recti) == translatedi);
+
+ QMatrix4x4 m3;
+ m3.scale(-100.5f, 64.0f);
+ qreal scalex = x * -100.5f;
+ qreal scaley = y * 64.0f;
+ qreal scalewid = width * -100.5f;
+ qreal scaleht = height * 64.0f;
+ if (scalewid < 0.0f) {
+ scalewid = -scalewid;
+ scalex -= scalewid;
+ }
+ if (scaleht < 0.0f) {
+ scaleht = -scaleht;
+ scaley -= scaleht;
+ }
+ QRectF scaled(scalex, scaley, scalewid, scaleht);
+ QVERIFY(m3.mapRect(rect) == scaled);
+ scalex = recti.x() * -100.5f;
+ scaley = recti.y() * 64.0f;
+ scalewid = recti.width() * -100.5f;
+ scaleht = recti.height() * 64.0f;
+ if (scalewid < 0.0f) {
+ scalewid = -scalewid;
+ scalex -= scalewid;
+ }
+ if (scaleht < 0.0f) {
+ scaleht = -scaleht;
+ scaley -= scaleht;
+ }
+ QRect scaledi(qRound(scalex), qRound(scaley),
+ qRound(scalewid), qRound(scaleht));
+ QVERIFY(m3.mapRect(recti) == scaledi);
+
+ QMatrix4x4 m4;
+ m4.translate(-100.5f, 64.0f);
+ m4.scale(-2.5f, 4.0f);
+ qreal transx1 = x * -2.5f - 100.5f;
+ qreal transy1 = y * 4.0f + 64.0f;
+ qreal transx2 = (x + width) * -2.5f - 100.5f;
+ qreal transy2 = (y + height) * 4.0f + 64.0f;
+ if (transx1 > transx2)
+ qSwap(transx1, transx2);
+ if (transy1 > transy2)
+ qSwap(transy1, transy2);
+ QRectF trans(transx1, transy1, transx2 - transx1, transy2 - transy1);
+ QVERIFY(m4.mapRect(rect) == trans);
+ transx1 = recti.x() * -2.5f - 100.5f;
+ transy1 = recti.y() * 4.0f + 64.0f;
+ transx2 = (recti.x() + recti.width()) * -2.5f - 100.5f;
+ transy2 = (recti.y() + recti.height()) * 4.0f + 64.0f;
+ if (transx1 > transx2)
+ qSwap(transx1, transx2);
+ if (transy1 > transy2)
+ qSwap(transy1, transy2);
+ QRect transi(qRound(transx1), qRound(transy1),
+ qRound(transx2) - qRound(transx1),
+ qRound(transy2) - qRound(transy1));
+ QVERIFY(m4.mapRect(recti) == transi);
+
+ m4.rotate(45.0f, 0.0f, 0.0f, 1.0f);
+
+ QTransform t4;
+ t4.translate(-100.5f, 64.0f);
+ t4.scale(-2.5f, 4.0f);
+ t4.rotate(45.0f);
+ QRectF mr = m4.mapRect(rect);
+ QRectF tr = t4.mapRect(rect);
+ QVERIFY(fuzzyCompare(mr.x(), tr.x()));
+ QVERIFY(fuzzyCompare(mr.y(), tr.y()));
+ QVERIFY(fuzzyCompare(mr.width(), tr.width()));
+ QVERIFY(fuzzyCompare(mr.height(), tr.height()));
+
+ QRect mri = m4.mapRect(recti);
+ QRect tri = t4.mapRect(recti);
+ QVERIFY(mri == tri);
+}
+
QTEST_APPLESS_MAIN(tst_QMatrix)
#include "tst_qmatrixnxn.moc"
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h
index b2a449a..5a2f9c3 100644
--- a/tests/auto/network-settings.h
+++ b/tests/auto/network-settings.h
@@ -39,6 +39,7 @@
**
****************************************************************************/
#include <QString>
+#include <QtNetwork/QHostInfo>
class QtNetworkSettings
{
@@ -63,4 +64,12 @@ public:
{
return "qt-test-server.wildcard.dev." + serverDomainName();
}
+
+#ifdef QT_NETWORK_LIB
+ static QHostAddress serverIP()
+ {
+ return QHostInfo::fromName(serverName()).addresses().first();
+ }
+#endif
+
};
diff --git a/tests/auto/q3socketdevice/tst_q3socketdevice.cpp b/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
index 2b0c606..6255aee 100644
--- a/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
+++ b/tests/auto/q3socketdevice/tst_q3socketdevice.cpp
@@ -45,6 +45,8 @@
#include <q3socketdevice.h>
+#include "../network-settings.h"
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -97,8 +99,7 @@ void tst_Q3SocketDevice::readNull()
int attempts = 10;
while (attempts--) {
- // connect to imap.troll.no
- if (device.connect(QHostAddress("62.70.27.18"), 143))
+ if (device.connect(QtNetworkSettings::serverIP(), 143))
break;
}
@@ -117,7 +118,7 @@ void tst_Q3SocketDevice::readNull()
#endif
QCOMPARE(device.peerPort(), quint16(143));
QCOMPARE(device.peerAddress().toString(),
- QHostAddress("62.70.27.18").toString());
+ QtNetworkSettings::serverIP().toString());
QCOMPARE(device.error(), Q3SocketDevice::NoError);
// write a logout notice
diff --git a/tests/auto/qanimationgroup/qanimationgroup.pro b/tests/auto/qanimationgroup/qanimationgroup.pro
new file mode 100644
index 0000000..97d33dd
--- /dev/null
+++ b/tests/auto/qanimationgroup/qanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qanimationgroup.cpp
+
+
diff --git a/tests/auto/qanimationgroup/tst_qanimationgroup.cpp b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
new file mode 100644
index 0000000..2952a39
--- /dev/null
+++ b/tests/auto/qanimationgroup/tst_qanimationgroup.cpp
@@ -0,0 +1,413 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qanimationgroup.h>
+#include <QtCore/qsequentialanimationgroup.h>
+#include <QtCore/qparallelanimationgroup.h>
+
+//TESTED_CLASS=QAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+class tst_QAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QAnimationGroup();
+ virtual ~tst_QAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void emptyGroup();
+ void setCurrentTime();
+ void statesAndSignals();
+ void setParentAutoAdd();
+ void beginNestedGroup();
+ void addChildTwice();
+ void loopWithoutStartValue();
+};
+
+tst_QAnimationGroup::tst_QAnimationGroup()
+{
+}
+
+tst_QAnimationGroup::~tst_QAnimationGroup()
+{
+}
+
+void tst_QAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+}
+
+void tst_QAnimationGroup::cleanup()
+{
+}
+
+void tst_QAnimationGroup::construction()
+{
+ QSequentialAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent), id(0)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ if (event->timerId() == id)
+ stop();
+ }
+
+ void updateRunning(bool running)
+ {
+ if (running) {
+ id = startTimer(500);
+ } else {
+ killTimer(id);
+ id = 0;
+ }
+ }
+
+private:
+ int id;
+};
+
+void tst_QAnimationGroup::emptyGroup()
+{
+ QSequentialAnimationGroup group;
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ group.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 2);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractAnimation::pause: Cannot pause a stopped animation");
+ group.pause();
+
+ QCOMPARE(groupStateChangedSpy.count(), 2);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ group.start();
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+
+ group.stop();
+
+ QCOMPARE(groupStateChangedSpy.count(), 4);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QAnimationGroup::setCurrentTime()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+ AnimationObject p_o1;
+ AnimationObject p_o2;
+ AnimationObject p_o3;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // sequence operating on same object/property
+ QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ // parallel operating on different object/properties
+ QAnimationGroup *parallel = new QParallelAnimationGroup();
+ QVariantAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
+ QVariantAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
+ QVariantAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
+ a1_p_o2->setLoopCount(3);
+ parallel->addAnimation(a1_p_o1);
+ parallel->addAnimation(a1_p_o2);
+ parallel->addAnimation(a1_p_o3);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QParallelAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+ group.addAnimation(parallel);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 1);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+ QCOMPARE(a1_p_o1->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 1);
+ QCOMPARE(notTimeDriven->currentTime(), 1);
+ QCOMPARE(loopsForever->currentTime(), 1);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 0);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(loopsForever->currentLoop(), 1);
+ QCOMPARE(sequence->currentAnimation(), a2_s_o1);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(sequence->currentTime(), 251);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 251);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 1);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 251);
+ QCOMPARE(loopsForever->currentTime(), 1);
+ QCOMPARE(sequence->currentAnimation(), a2_s_o1);
+}
+
+void tst_QAnimationGroup::statesAndSignals()
+{
+}
+
+void tst_QAnimationGroup::setParentAutoAdd()
+{
+ QParallelAnimationGroup group;
+ QVariantAnimation *animation = new QPropertyAnimation(&group);
+ QCOMPARE(animation->group(), &group);
+}
+
+void tst_QAnimationGroup::beginNestedGroup()
+{
+ QAnimationGroup *subGroup;
+ QAnimationGroup *parent = new QParallelAnimationGroup();
+
+ for (int i = 0; i < 10; ++i) {
+ if (i & 1)
+ subGroup = new QParallelAnimationGroup(parent);
+ else
+ subGroup = new QSequentialAnimationGroup(parent);
+
+ QCOMPARE(parent->animationCount(), 1);
+ QAnimationGroup *child = static_cast<QAnimationGroup *>(parent->animationAt(0));
+
+ QCOMPARE(child->parent(), static_cast<QObject *>(parent));
+ if (i & 1)
+ QVERIFY(qobject_cast<QParallelAnimationGroup *> (child));
+ else
+ QVERIFY(qobject_cast<QSequentialAnimationGroup *> (child));
+
+ parent = child;
+ }
+}
+
+void tst_QAnimationGroup::addChildTwice()
+{
+ QPropertyAnimation *subGroup;
+ QPropertyAnimation *subGroup2;
+ QAnimationGroup *parent = new QSequentialAnimationGroup();
+
+ subGroup = new QPropertyAnimation();
+ subGroup->setParent(parent);
+ parent->addAnimation(subGroup);
+ QCOMPARE(parent->animationCount(), 1);
+
+ parent->clearAnimations();
+
+ QCOMPARE(parent->animationCount(), 0);
+
+ // adding the same item twice to a group will remove the item from its current position
+ // and append it to the end
+ subGroup = new QPropertyAnimation(parent);
+ subGroup2 = new QPropertyAnimation(parent);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup);
+ QCOMPARE(parent->animationAt(1), subGroup2);
+
+ parent->addAnimation(subGroup);
+
+ QCOMPARE(parent->animationCount(), 2);
+ QCOMPARE(parent->animationAt(0), subGroup2);
+ QCOMPARE(parent->animationAt(1), subGroup);
+
+ delete parent;
+}
+
+void tst_QAnimationGroup::loopWithoutStartValue()
+{
+ QAnimationGroup *parent = new QSequentialAnimationGroup();
+ QObject o;
+ o.setProperty("ole", 0);
+ QCOMPARE(o.property("ole").toInt(), 0);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(-50);
+ anim1.setDuration(100);
+
+ QPropertyAnimation anim2(&o, "ole");
+ anim2.setEndValue(50);
+ anim2.setDuration(100);
+
+ parent->addAnimation(&anim1);
+ parent->addAnimation(&anim2);
+
+ parent->setLoopCount(-1);
+ parent->start();
+
+ QVERIFY(anim1.startValue().isNull());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(parent->currentLoop(), 0);
+
+ parent->setCurrentTime(200);
+ QCOMPARE(parent->currentLoop(), 1);
+ QCOMPARE(anim1.currentValue().toInt(), 50);
+ parent->stop();
+}
+
+QTEST_MAIN(tst_QAnimationGroup)
+#include "tst_qanimationgroup.moc"
diff --git a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp
index 67a822f..617832b 100644
--- a/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp
+++ b/tests/auto/qcalendarwidget/tst_qcalendarwidget.cpp
@@ -47,6 +47,8 @@
#include <qspinbox.h>
#include <qmenu.h>
#include <qdebug.h>
+#include <qdatetime.h>
+#include <qtextformat.h>
//TESTED_CLASS=
@@ -68,6 +70,11 @@ public slots:
private slots:
void getSetCheck();
void buttonClickCheck();
+
+ void setTextFormat();
+ void resetTextFormat();
+
+ void setWeekdayFormat();
};
// Testing get/set functions
@@ -215,6 +222,52 @@ void tst_QCalendarWidget::buttonClickCheck()
}
+void tst_QCalendarWidget::setTextFormat()
+{
+ QCalendarWidget calendar;
+ QTextCharFormat format;
+ format.setFontItalic(true);
+ format.setForeground(Qt::green);
+
+ const QDate date(1984, 10, 20);
+ calendar.setDateTextFormat(date, format);
+ QCOMPARE(calendar.dateTextFormat(date), format);
+}
+
+void tst_QCalendarWidget::resetTextFormat()
+{
+ QCalendarWidget calendar;
+ QTextCharFormat format;
+ format.setFontItalic(true);
+ format.setForeground(Qt::green);
+
+ const QDate date(1984, 10, 20);
+ calendar.setDateTextFormat(date, format);
+
+ calendar.setDateTextFormat(QDate(), QTextCharFormat());
+ QCOMPARE(calendar.dateTextFormat(date), QTextCharFormat());
+}
+
+void tst_QCalendarWidget::setWeekdayFormat()
+{
+ QCalendarWidget calendar;
+
+ QTextCharFormat format;
+ format.setFontItalic(true);
+ format.setForeground(Qt::green);
+
+ calendar.setWeekdayTextFormat(Qt::Wednesday, format);
+
+ // check the format of the a given month
+ for (int i = 1; i <= 31; ++i) {
+ const QDate date(1984, 10, i);
+ const Qt::DayOfWeek dayOfWeek = static_cast<Qt::DayOfWeek>(date.dayOfWeek());
+ if (dayOfWeek == Qt::Wednesday)
+ QCOMPARE(calendar.weekdayTextFormat(dayOfWeek), format);
+ else
+ QVERIFY(calendar.weekdayTextFormat(dayOfWeek) != format);
+ }
+}
tst_QCalendarWidget::tst_QCalendarWidget()
{
diff --git a/tests/auto/qcolor/tst_qcolor.cpp b/tests/auto/qcolor/tst_qcolor.cpp
index 7608a15..684d5b5 100644
--- a/tests/auto/qcolor/tst_qcolor.cpp
+++ b/tests/auto/qcolor/tst_qcolor.cpp
@@ -111,12 +111,15 @@ private slots:
void toRgb_data();
void toRgb();
+ void toRgbNonDestructive();
void toHsv_data();
void toHsv();
+ void toHsvNonDestructive();
void toCmyk_data();
void toCmyk();
+ void toCmykNonDestructive();
void convertTo();
@@ -1124,6 +1127,12 @@ void tst_QColor::toHsv_data()
<< QColor::fromCmykF(0., 1., 1., 0.);
}
+void tst_QColor::toRgbNonDestructive()
+{
+ QColor aColor = QColor::fromRgbF(0.11, 0.22, 0.33, 0.44);
+ QCOMPARE(aColor, aColor.toRgb());
+}
+
void tst_QColor::toHsv()
{
// invalid should remain invalid
@@ -1136,6 +1145,12 @@ void tst_QColor::toHsv()
QCOMPARE(cmykColor.toHsv(), expectedColor);
}
+void tst_QColor::toHsvNonDestructive()
+{
+ QColor aColor = QColor::fromHsvF(0.11, 0.22, 0.33, 0.44);
+ QCOMPARE(aColor, aColor.toHsv());
+}
+
void tst_QColor::toCmyk_data()
{
QTest::addColumn<QColor>("expectedColor");
@@ -1165,6 +1180,12 @@ void tst_QColor::toCmyk()
QCOMPARE(hsvColor.toCmyk(), expectedColor);
}
+void tst_QColor::toCmykNonDestructive()
+{
+ QColor aColor = QColor::fromCmykF(0.11, 0.22, 0.33, 0.44);
+ QCOMPARE(aColor, aColor.toCmyk());
+}
+
void tst_QColor::convertTo()
{
QColor color(Qt::black);
diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp
index 6a87e3c..816b2e8 100644
--- a/tests/auto/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/qcombobox/tst_qcombobox.cpp
@@ -76,6 +76,7 @@
#endif
#include <qabstractitemview.h>
#include "../../shared/util.h"
+#include <qstyleditemdelegate.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -141,6 +142,8 @@ private slots:
void setModelColumn();
void noScrollbar_data();
void noScrollbar();
+ void setItemDelegate();
+ void task253944_itemDelegateIsReset();
protected slots:
void onEditTextChanged( const QString &newString );
@@ -2168,7 +2171,7 @@ void tst_QComboBox::noScrollbar_data()
QTest::newRow("everything and more") << QString::fromLatin1("QAbstractItemView { border: 1px 3px 5px 1px solid blue; "
" padding: 2px 5px 3px 1px; margin: 2px 5px 3px 1px; } "
" QAbstractItemView::item { border: 2px solid green; "
- " padding: 1px 1px 2px 2px margin: 1px; } " );
+ " padding: 1px 1px 2px 2px; margin: 1px; } " );
}
void tst_QComboBox::noScrollbar()
@@ -2176,10 +2179,11 @@ void tst_QComboBox::noScrollbar()
QStringList initialContent;
initialContent << "foo" << "bar" << "foobar" << "moo";
QFETCH(QString, stylesheet);
+ QString oldCss = qApp->styleSheet();
+ qApp->setStyleSheet(stylesheet);
{
QComboBox comboBox;
- comboBox.setStyleSheet(stylesheet);
comboBox.addItems(initialContent);
comboBox.show();
comboBox.resize(200, comboBox.height());
@@ -2193,7 +2197,6 @@ void tst_QComboBox::noScrollbar()
{
QTableWidget *table = new QTableWidget(2,2);
QComboBox comboBox;
- comboBox.setStyleSheet(stylesheet);
comboBox.setView(table);
comboBox.setModel(table->model());
comboBox.show();
@@ -2204,6 +2207,29 @@ void tst_QComboBox::noScrollbar()
QVERIFY(!comboBox.view()->horizontalScrollBar()->isVisible());
QVERIFY(!comboBox.view()->verticalScrollBar()->isVisible());
}
+
+ qApp->setStyleSheet(oldCss);
+}
+
+void tst_QComboBox::setItemDelegate()
+{
+ QComboBox comboBox;
+ QStyledItemDelegate *itemDelegate = new QStyledItemDelegate;
+ comboBox.setItemDelegate(itemDelegate);
+ QCOMPARE(comboBox.itemDelegate(), itemDelegate);
+}
+
+void tst_QComboBox::task253944_itemDelegateIsReset()
+{
+ QComboBox comboBox;
+ QStyledItemDelegate *itemDelegate = new QStyledItemDelegate;
+ comboBox.setItemDelegate(itemDelegate);
+
+ comboBox.setEditable(true);
+ QCOMPARE(comboBox.itemDelegate(), itemDelegate);
+
+ comboBox.setStyleSheet("QComboBox { border: 1px solid gray; }");
+ QCOMPARE(comboBox.itemDelegate(), itemDelegate);
}
QTEST_MAIN(tst_QComboBox)
diff --git a/tests/auto/qcontiguouscache/qcontiguouscache.pro b/tests/auto/qcontiguouscache/qcontiguouscache.pro
new file mode 100644
index 0000000..618efed
--- /dev/null
+++ b/tests/auto/qcontiguouscache/qcontiguouscache.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+
+QT = core
+
+SOURCES += tst_qcontiguouscache.cpp
+
+
+
diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp
new file mode 100644
index 0000000..6d59390
--- /dev/null
+++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp
@@ -0,0 +1,479 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QObject>
+#include <QTest>
+#include <QCache>
+#include <QContiguousCache>
+
+#include <QDebug>
+#include <stdio.h>
+
+class tst_QContiguousCache : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QContiguousCache() {}
+ virtual ~tst_QContiguousCache() {}
+private slots:
+ void empty();
+ void append_data();
+ void append();
+
+ void prepend_data();
+ void prepend();
+
+ void asScrollingList();
+
+ void complexType();
+
+ void operatorAt();
+
+ void cacheBenchmark();
+ void contiguousCacheBenchmark();
+
+ void setCapacity();
+};
+
+QTEST_MAIN(tst_QContiguousCache)
+
+void tst_QContiguousCache::empty()
+{
+ QContiguousCache<int> c(10);
+ QCOMPARE(c.capacity(), 10);
+ QCOMPARE(c.count(), 0);
+ QVERIFY(c.isEmpty());
+ c.append(1);
+ QCOMPARE(c.count(), 1);
+ QVERIFY(!c.isEmpty());
+ c.clear();
+ QCOMPARE(c.capacity(), 10);
+ QCOMPARE(c.count(), 0);
+ QVERIFY(c.isEmpty());
+ c.prepend(1);
+ QCOMPARE(c.count(), 1);
+ QVERIFY(!c.isEmpty());
+ c.clear();
+ QCOMPARE(c.count(), 0);
+ QVERIFY(c.isEmpty());
+ QCOMPARE(c.capacity(), 10);
+}
+
+void tst_QContiguousCache::append_data()
+{
+ QTest::addColumn<int>("start");
+ QTest::addColumn<int>("count");
+ QTest::addColumn<int>("cacheSize");
+ QTest::addColumn<bool>("invalidIndexes");
+
+ QTest::newRow("0+30[10]") << 0 << 30 << 10 << false;
+ QTest::newRow("300+30[10]") << 300 << 30 << 10 << false;
+ QTest::newRow("MAX-10+30[10]") << INT_MAX-10 << 30 << 10 << true;
+}
+
+void tst_QContiguousCache::append()
+{
+ QFETCH(int, start);
+ QFETCH(int, count);
+ QFETCH(int, cacheSize);
+ QFETCH(bool, invalidIndexes);
+
+ int i, j;
+ QContiguousCache<int> c(cacheSize);
+
+ i = 1;
+ QCOMPARE(c.available(), cacheSize);
+ if (start == 0)
+ c.append(i++);
+ else
+ c.insert(start, i++);
+ while (i < count) {
+ c.append(i);
+ QCOMPARE(c.available(), qMax(0, cacheSize - i));
+ QCOMPARE(c.first(), qMax(1, i-cacheSize+1));
+ QCOMPARE(c.last(), i);
+ QCOMPARE(c.count(), qMin(i, cacheSize));
+ QCOMPARE(c.isFull(), i >= cacheSize);
+ i++;
+ }
+
+ QCOMPARE(c.areIndexesValid(), !invalidIndexes);
+ if (invalidIndexes)
+ c.normalizeIndexes();
+ QVERIFY(c.areIndexesValid());
+
+ // test taking from end until empty.
+ for (j = 0; j < cacheSize; j++, i--) {
+ QCOMPARE(c.takeLast(), i-1);
+ QCOMPARE(c.count(), cacheSize-j-1);
+ QCOMPARE(c.available(), j+1);
+ QVERIFY(!c.isFull());
+ QCOMPARE(c.isEmpty(), j==cacheSize-1);
+ }
+
+}
+
+void tst_QContiguousCache::prepend_data()
+{
+ QTest::addColumn<int>("start");
+ QTest::addColumn<int>("count");
+ QTest::addColumn<int>("cacheSize");
+ QTest::addColumn<bool>("invalidIndexes");
+
+ QTest::newRow("30-30[10]") << 30 << 30 << 10 << false;
+ QTest::newRow("300-30[10]") << 300 << 30 << 10 << false;
+ QTest::newRow("10-30[10]") << 10 << 30 << 10 << true;
+}
+
+void tst_QContiguousCache::prepend()
+{
+ QFETCH(int, start);
+ QFETCH(int, count);
+ QFETCH(int, cacheSize);
+ QFETCH(bool, invalidIndexes);
+
+ int i, j;
+ QContiguousCache<int> c(cacheSize);
+
+ i = 1;
+ QCOMPARE(c.available(), cacheSize);
+ c.insert(start, i++);
+ while(i < count) {
+ c.prepend(i);
+ QCOMPARE(c.available(), qMax(0, cacheSize - i));
+ QCOMPARE(c.last(), qMax(1, i-cacheSize+1));
+ QCOMPARE(c.first(), i);
+ QCOMPARE(c.count(), qMin(i, cacheSize));
+ QCOMPARE(c.isFull(), i >= cacheSize);
+ i++;
+ }
+
+ QCOMPARE(c.areIndexesValid(), !invalidIndexes);
+ if (invalidIndexes)
+ c.normalizeIndexes();
+ QVERIFY(c.areIndexesValid());
+
+ // test taking from start until empty.
+ for (j = 0; j < cacheSize; j++, i--) {
+ QCOMPARE(c.takeFirst(), i-1);
+ QCOMPARE(c.count(), cacheSize-j-1);
+ QCOMPARE(c.available(), j+1);
+ QVERIFY(!c.isFull());
+ QCOMPARE(c.isEmpty(), j==cacheSize-1);
+ }
+}
+
+void tst_QContiguousCache::asScrollingList()
+{
+ int i;
+ QContiguousCache<int> c(10);
+
+ // Once allocated QContiguousCache should not
+ // allocate any additional memory for non
+ // complex data types.
+ QBENCHMARK {
+ // simulate scrolling in a list of items;
+ for(i = 0; i < 10; ++i) {
+ QCOMPARE(c.available(), 10-i);
+ c.append(i);
+ }
+
+ QCOMPARE(c.firstIndex(), 0);
+ QCOMPARE(c.lastIndex(), 9);
+ QCOMPARE(c.first(), 0);
+ QCOMPARE(c.last(), 9);
+ QVERIFY(!c.containsIndex(-1));
+ QVERIFY(!c.containsIndex(10));
+ QCOMPARE(c.available(), 0);
+
+ for (i = 0; i < 10; ++i) {
+ QVERIFY(c.containsIndex(i));
+ QCOMPARE(c.at(i), i);
+ QCOMPARE(c[i], i);
+ QCOMPARE(((const QContiguousCache<int>)c)[i], i);
+ }
+
+ for (i = 10; i < 30; ++i)
+ c.append(i);
+
+ QCOMPARE(c.firstIndex(), 20);
+ QCOMPARE(c.lastIndex(), 29);
+ QCOMPARE(c.first(), 20);
+ QCOMPARE(c.last(), 29);
+ QVERIFY(!c.containsIndex(19));
+ QVERIFY(!c.containsIndex(30));
+ QCOMPARE(c.available(), 0);
+
+ for (i = 20; i < 30; ++i) {
+ QVERIFY(c.containsIndex(i));
+ QCOMPARE(c.at(i), i);
+ QCOMPARE(c[i], i);
+ QCOMPARE(((const QContiguousCache<int> )c)[i], i);
+ }
+
+ for (i = 19; i >= 10; --i)
+ c.prepend(i);
+
+ QCOMPARE(c.firstIndex(), 10);
+ QCOMPARE(c.lastIndex(), 19);
+ QCOMPARE(c.first(), 10);
+ QCOMPARE(c.last(), 19);
+ QVERIFY(!c.containsIndex(9));
+ QVERIFY(!c.containsIndex(20));
+ QCOMPARE(c.available(), 0);
+
+ for (i = 10; i < 20; ++i) {
+ QVERIFY(c.containsIndex(i));
+ QCOMPARE(c.at(i), i);
+ QCOMPARE(c[i], i);
+ QCOMPARE(((const QContiguousCache<int> )c)[i], i);
+ }
+
+ for (i = 200; i < 220; ++i)
+ c.insert(i, i);
+
+ QCOMPARE(c.firstIndex(), 210);
+ QCOMPARE(c.lastIndex(), 219);
+ QCOMPARE(c.first(), 210);
+ QCOMPARE(c.last(), 219);
+ QVERIFY(!c.containsIndex(209));
+ QVERIFY(!c.containsIndex(300));
+ QCOMPARE(c.available(), 0);
+
+ for (i = 210; i < 220; ++i) {
+ QVERIFY(c.containsIndex(i));
+ QCOMPARE(c.at(i), i);
+ QCOMPARE(c[i], i);
+ QCOMPARE(((const QContiguousCache<int> )c)[i], i);
+ }
+ c.clear(); // needed to reset benchmark
+ }
+
+ // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed.
+ // bug was that item at 150 would instead be item that should have been inserted at 250
+ c.setCapacity(200);
+ for(i = 100; i < 300; ++i)
+ c.insert(i, i);
+ for (i = 250; i <= 306; ++i)
+ c.insert(i, 1000+i);
+ for (i = 107; i <= 306; ++i) {
+ QVERIFY(c.containsIndex(i));
+ QCOMPARE(c.at(i), i < 250 ? i : 1000+i);
+ }
+}
+
+struct RefCountingClassData
+{
+ QBasicAtomicInt ref;
+ static RefCountingClassData shared_null;
+};
+
+RefCountingClassData RefCountingClassData::shared_null = {
+ Q_BASIC_ATOMIC_INITIALIZER(1)
+};
+
+class RefCountingClass
+{
+public:
+ RefCountingClass() : d(&RefCountingClassData::shared_null) { d->ref.ref(); }
+
+ RefCountingClass(const RefCountingClass &other)
+ {
+ d = other.d;
+ d->ref.ref();
+ }
+
+ ~RefCountingClass()
+ {
+ if (!d->ref.deref())
+ delete d;
+ }
+
+ RefCountingClass &operator=(const RefCountingClass &other)
+ {
+ if (!d->ref.deref())
+ delete d;
+ d = other.d;
+ d->ref.ref();
+ return *this;
+ }
+
+ int refCount() const { return d->ref; }
+private:
+ RefCountingClassData *d;
+};
+
+void tst_QContiguousCache::complexType()
+{
+ RefCountingClass original;
+
+ QContiguousCache<RefCountingClass> contiguousCache(10);
+ contiguousCache.append(original);
+ QCOMPARE(original.refCount(), 3);
+ contiguousCache.removeFirst();
+ QCOMPARE(original.refCount(), 2); // shared null, 'original'.
+ contiguousCache.append(original);
+ QCOMPARE(original.refCount(), 3);
+ contiguousCache.clear();
+ QCOMPARE(original.refCount(), 2);
+
+ for(int i = 0; i < 100; ++i)
+ contiguousCache.insert(i, original);
+
+ QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache.
+
+ contiguousCache.clear();
+ QCOMPARE(original.refCount(), 2);
+ for (int i = 0; i < 100; i++)
+ contiguousCache.append(original);
+
+ QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache.
+ contiguousCache.clear();
+ QCOMPARE(original.refCount(), 2);
+
+ for (int i = 0; i < 100; i++)
+ contiguousCache.prepend(original);
+
+ QCOMPARE(original.refCount(), 12); // shared null, 'original', + 10 in contiguousCache.
+ contiguousCache.clear();
+ QCOMPARE(original.refCount(), 2);
+
+ for (int i = 0; i < 100; i++)
+ contiguousCache.append(original);
+
+ contiguousCache.takeLast();
+ QCOMPARE(original.refCount(), 11);
+
+ contiguousCache.takeFirst();
+ QCOMPARE(original.refCount(), 10);
+}
+
+void tst_QContiguousCache::operatorAt()
+{
+ RefCountingClass original;
+ QContiguousCache<RefCountingClass> contiguousCache(10);
+
+ for (int i = 25; i < 35; ++i)
+ contiguousCache[i] = original;
+
+ QCOMPARE(original.refCount(), 12); // shared null, orig, items in cache
+
+ // verify const access does not copy items.
+ const QContiguousCache<RefCountingClass> copy(contiguousCache);
+ for (int i = 25; i < 35; ++i)
+ QCOMPARE(copy[i].refCount(), 12);
+
+ // verify modifying the original increments ref count (e.g. does a detach)
+ contiguousCache[25] = original;
+ QCOMPARE(original.refCount(), 22);
+}
+
+/*
+ Benchmarks must be near identical in tasks to be fair.
+ QCache uses pointers to ints as its a requirement of QCache,
+ whereas QContiguousCache doesn't support pointers (won't free them).
+ Given the ability to use simple data types is a benefit, its
+ fair. Although this obviously must take into account we are
+ testing QContiguousCache use cases here, QCache has its own
+ areas where it is the more sensible class to use.
+*/
+void tst_QContiguousCache::cacheBenchmark()
+{
+ QBENCHMARK {
+ QCache<int, int> cache;
+ cache.setMaxCost(100);
+
+ for (int i = 0; i < 1000; i++)
+ cache.insert(i, new int(i));
+ }
+}
+
+void tst_QContiguousCache::contiguousCacheBenchmark()
+{
+ QBENCHMARK {
+ QContiguousCache<int> contiguousCache(100);
+ for (int i = 0; i < 1000; i++)
+ contiguousCache.insert(i, i);
+ }
+}
+
+void tst_QContiguousCache::setCapacity()
+{
+ int i;
+ QContiguousCache<int> contiguousCache(100);
+ for (i = 280; i < 310; ++i)
+ contiguousCache.insert(i, i);
+ QCOMPARE(contiguousCache.capacity(), 100);
+ QCOMPARE(contiguousCache.count(), 30);
+ QCOMPARE(contiguousCache.firstIndex(), 280);
+ QCOMPARE(contiguousCache.lastIndex(), 309);
+
+ for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) {
+ QVERIFY(contiguousCache.containsIndex(i));
+ QCOMPARE(contiguousCache.at(i), i);
+ }
+
+ contiguousCache.setCapacity(150);
+
+ QCOMPARE(contiguousCache.capacity(), 150);
+ QCOMPARE(contiguousCache.count(), 30);
+ QCOMPARE(contiguousCache.firstIndex(), 280);
+ QCOMPARE(contiguousCache.lastIndex(), 309);
+
+ for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) {
+ QVERIFY(contiguousCache.containsIndex(i));
+ QCOMPARE(contiguousCache.at(i), i);
+ }
+
+ contiguousCache.setCapacity(20);
+
+ QCOMPARE(contiguousCache.capacity(), 20);
+ QCOMPARE(contiguousCache.count(), 20);
+ QCOMPARE(contiguousCache.firstIndex(), 290);
+ QCOMPARE(contiguousCache.lastIndex(), 309);
+
+ for (i = contiguousCache.firstIndex(); i <= contiguousCache.lastIndex(); ++i) {
+ QVERIFY(contiguousCache.containsIndex(i));
+ QCOMPARE(contiguousCache.at(i), i);
+ }
+}
+
+#include "tst_qcontiguouscache.moc"
diff --git a/tests/auto/qcssparser/tst_cssparser.cpp b/tests/auto/qcssparser/tst_cssparser.cpp
index ab6bad6..b41a745 100644
--- a/tests/auto/qcssparser/tst_cssparser.cpp
+++ b/tests/auto/qcssparser/tst_cssparser.cpp
@@ -123,7 +123,7 @@ static void debug(const QVector<QCss::Symbol> &symbols, int index = -1)
qDebug() << "failure at index" << index;
}
-static void debug(const QCss::Parser &p) { debug(p.symbols); }
+//static void debug(const QCss::Parser &p) { debug(p.symbols); }
void tst_CssParser::scanner()
{
@@ -1473,7 +1473,12 @@ void tst_CssParser::extractFontFamily_data()
QTest::newRow("quoted-family-name") << "font-family: 'Times New Roman'" << QString("Times New Roman");
QTest::newRow("unquoted-family-name") << "font-family: Times New Roman" << QString("Times New Roman");
QTest::newRow("unquoted-family-name2") << "font-family: Times New Roman" << QString("Times New Roman");
- QTest::newRow("multiple") << "font-family: Times New Roman , foobar, 'baz'" << QString("Times New Roman");
+ QTest::newRow("multiple") << "font-family: Times New Roman , foobar, 'baz'" << QString("Times New Roman");
+ QTest::newRow("multiple2") << "font-family: invalid, Times New Roman " << QString("Times New Roman");
+ QTest::newRow("invalid") << "font-family: invalid" << QFontInfo(QFont("invalid font")).family();
+ QTest::newRow("shorthand") << "font: 12pt Times New Roman" << QString("Times New Roman");
+ QTest::newRow("shorthand multiple quote") << "font: 12pt invalid, \"Times New Roman\" " << QString("Times New Roman");
+ QTest::newRow("shorthand multiple") << "font: 12pt invalid, Times New Roman " << QString("Times New Roman");
}
void tst_CssParser::extractFontFamily()
@@ -1497,8 +1502,8 @@ void tst_CssParser::extractFontFamily()
int adjustment = 0;
QFont fnt;
extractor.extractFont(&fnt, &adjustment);
-
- QTEST(fnt.family(), "expectedFamily");
+ QFontInfo info(fnt);
+ QTEST(info.family(), "expectedFamily");
}
void tst_CssParser::extractBorder_data()
diff --git a/tests/auto/qdatastream/tst_qdatastream.cpp b/tests/auto/qdatastream/tst_qdatastream.cpp
index d7ca7bc..6a69fcc 100644
--- a/tests/auto/qdatastream/tst_qdatastream.cpp
+++ b/tests/auto/qdatastream/tst_qdatastream.cpp
@@ -462,7 +462,7 @@ void tst_QDataStream::writeQString(QDataStream* s)
{
QString test(QStringData(dataIndex(QTest::currentDataTag())));
*s << test;
- *s << QString("Faen her spyr man");
+ *s << QString("Her er det noe tekst");
*s << test;
*s << QString();
*s << test;
@@ -480,7 +480,7 @@ void tst_QDataStream::readQString(QDataStream *s)
*s >> S;
QCOMPARE(S, test);
*s >> S;
- QCOMPARE(S, QString("Faen her spyr man"));
+ QCOMPARE(S, QString("Her er det noe tekst"));
*s >> S;
QCOMPARE(S, test);
*s >> S;
@@ -533,7 +533,7 @@ void tst_QDataStream::writeQRegExp(QDataStream* s)
{
QRegExp test(QRegExpData(dataIndex(QTest::currentDataTag())));
*s << test;
- *s << QString("Faen her spyr man");
+ *s << QString("Her er det noe tekst");
*s << test;
*s << QString("nonempty");
*s << test;
@@ -550,7 +550,7 @@ void tst_QDataStream::readQRegExp(QDataStream *s)
*s >> R;
QCOMPARE(R, test);
*s >> S;
- QCOMPARE(S, QString("Faen her spyr man"));
+ QCOMPARE(S, QString("Her er det noe tekst"));
*s >> R;
QCOMPARE(R, test);
*s >> S;
diff --git a/tests/auto/qdate/tst_qdate.cpp b/tests/auto/qdate/tst_qdate.cpp
index d4273d0..4d6c80c 100644
--- a/tests/auto/qdate/tst_qdate.cpp
+++ b/tests/auto/qdate/tst_qdate.cpp
@@ -82,6 +82,8 @@ private slots:
void operator_gt_eq();
void fromString_data();
void fromString();
+ void fromString_format_data();
+ void fromString_format();
void toString_format_data();
void toString_format();
void isLeapYear();
@@ -618,6 +620,30 @@ void tst_QDate::fromString()
QCOMPARE( QDate::fromString( str2, Qt::ISODate ), d1 );
}
+void tst_QDate::fromString_format_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("format");
+ QTest::addColumn<QDate>("date");
+
+ //year with yy is always 19xx for compatibility
+ QTest::newRow( "data0" ) << QString("21052006") << QString("ddMMyyyy") << QDate(2006,5,21);
+ QTest::newRow( "data1" ) << QString("210506") << QString("ddMMyy") << QDate(1906,5,21);
+ QTest::newRow( "data2" ) << QString("21/5/2006") << QString("d/M/yyyy") << QDate(2006,5,21);
+ QTest::newRow( "data3" ) << QString("21/5/06") << QString("d/M/yy") << QDate(1906,5,21);
+ QTest::newRow( "data4" ) << QString("20060521") << QString("yyyyMMdd") << QDate(2006,5,21);
+ QTest::newRow( "data5" ) << QString("060521") << QString("yyMMdd") << QDate(1906,5,21);
+}
+
+void tst_QDate::fromString_format()
+{
+ QFETCH( QString, string );
+ QFETCH( QString, format );
+ QFETCH( QDate, date );
+
+ QCOMPARE( QDate::fromString( string, format ), date );
+}
+
void tst_QDate::toString_format_data()
{
QTest::addColumn<QDate>("t");
diff --git a/tests/auto/qeasingcurve/qeasingcurve.pro b/tests/auto/qeasingcurve/qeasingcurve.pro
new file mode 100644
index 0000000..2b66081
--- /dev/null
+++ b/tests/auto/qeasingcurve/qeasingcurve.pro
@@ -0,0 +1,3 @@
+load(qttest_p4)
+QT = core
+SOURCES += tst_qeasingcurve.cpp
diff --git a/tests/auto/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp
new file mode 100644
index 0000000..b25cdc7
--- /dev/null
+++ b/tests/auto/qeasingcurve/tst_qeasingcurve.cpp
@@ -0,0 +1,493 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#if QT_VERSION < 0x040200
+QTEST_NOOP_MAIN
+#else
+
+#include <qeasingcurve.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QEasingCurve : public QObject {
+ Q_OBJECT
+
+public:
+ tst_QEasingCurve();
+ virtual ~tst_QEasingCurve();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void type();
+ void propertyDefaults();
+ void valueForProgress_data();
+ void valueForProgress();
+ void setCustomType();
+ void operators();
+
+protected:
+};
+
+tst_QEasingCurve::tst_QEasingCurve()
+{
+}
+
+tst_QEasingCurve::~tst_QEasingCurve()
+{
+}
+
+void tst_QEasingCurve::init()
+{
+}
+
+void tst_QEasingCurve::cleanup()
+{
+}
+#include <qdebug.h>
+
+void tst_QEasingCurve::type()
+{
+ {
+ QEasingCurve curve(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+
+ curve.setPeriod(5);
+ curve.setAmplitude(3);
+ QCOMPARE(curve.period(), 5.0);
+ QCOMPARE(curve.amplitude(), 3.0);
+
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 5.0);
+ QCOMPARE(curve.amplitude(), 3.0);
+ }
+
+ {
+ QEasingCurve curve(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ curve.setAmplitude(2);
+ QCOMPARE(curve.type(), QEasingCurve::InElastic);
+ curve.setType(QEasingCurve::Linear);
+ }
+
+ {
+ // check bounaries
+ QEasingCurve curve(QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type 9999");
+ curve.setType((QEasingCurve::Type)9999);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, "QEasingCurve: Invalid curve type -9999");
+ curve.setType((QEasingCurve::Type)-9999);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(QEasingCurve::NCurveTypes).toLatin1().constData());
+ curve.setType(QEasingCurve::NCurveTypes);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(QEasingCurve::Custom).toLatin1().constData());
+ curve.setType(QEasingCurve::Custom);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
+ .arg(-1).toLatin1().constData());
+ curve.setType((QEasingCurve::Type)-1);
+ QCOMPARE(curve.type(), QEasingCurve::InCubic);
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.type(), QEasingCurve::Linear);
+ curve.setType(QEasingCurve::CosineCurve);
+ QCOMPARE(curve.type(), QEasingCurve::CosineCurve);
+ }
+}
+
+void tst_QEasingCurve::propertyDefaults()
+{
+ {
+ // checks if the defaults are correct, but also demonstrates a weakness with the API.
+ QEasingCurve curve(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::InBounce);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.3);
+ QCOMPARE(curve.amplitude(), 1.0);
+ QCOMPARE(curve.overshoot(), qreal(1.70158f));
+ curve.setPeriod(0.4);
+ curve.setAmplitude(0.6);
+ curve.setOvershoot(1.0);
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.period(), 0.4);
+ QCOMPARE(curve.amplitude(), 0.6);
+ QCOMPARE(curve.overshoot(), 1.0);
+ curve.setType(QEasingCurve::InElastic);
+ QCOMPARE(curve.period(), 0.4);
+ QCOMPARE(curve.amplitude(), 0.6);
+ QCOMPARE(curve.overshoot(), 1.0);
+ }
+}
+
+typedef QList<int> IntList;
+typedef QList<qreal> RealList;
+Q_DECLARE_METATYPE(IntList)
+Q_DECLARE_METATYPE(RealList)
+
+void tst_QEasingCurve::valueForProgress_data()
+{
+ QTest::addColumn<int>("type");
+ QTest::addColumn<IntList>("at");
+ QTest::addColumn<RealList>("expected");
+ // automatically generated.
+ // note that values are scaled from range [0,1] to range [0, 100] in order to store them as
+ // integer values and avoid fp inaccuracies
+ QTest::newRow("Linear") << int(QEasingCurve::Linear)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.4 << 0.5 << 0.6 << 0.7 << 0.8 << 0.9 << 1);
+
+ QTest::newRow("InQuad") << int(QEasingCurve::InQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01 << 0.04 << 0.09 << 0.16 << 0.25 << 0.36 << 0.49 << 0.64 << 0.81 << 1);
+
+ QTest::newRow("OutQuad") << int(QEasingCurve::OutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.19 << 0.36 << 0.51 << 0.64 << 0.75 << 0.84 << 0.91 << 0.96 << 0.99 << 1);
+
+ QTest::newRow("InOutQuad") << int(QEasingCurve::InOutQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02 << 0.08 << 0.18 << 0.32 << 0.5 << 0.68 << 0.82 << 0.92 << 0.98 << 1);
+
+ QTest::newRow("OutInQuad") << int(QEasingCurve::OutInQuad)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.18 << 0.32 << 0.42 << 0.48 << 0.5 << 0.52 << 0.58 << 0.68 << 0.82 << 1);
+
+ QTest::newRow("InCubic") << int(QEasingCurve::InCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001 << 0.008 << 0.027 << 0.064 << 0.125 << 0.216 << 0.343 << 0.512 << 0.729 << 1);
+
+ QTest::newRow("OutCubic") << int(QEasingCurve::OutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.271 << 0.488 << 0.657 << 0.784 << 0.875 << 0.936 << 0.973 << 0.992 << 0.999 << 1);
+
+ QTest::newRow("InOutCubic") << int(QEasingCurve::InOutCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.004 << 0.032 << 0.108 << 0.256 << 0.5 << 0.744 << 0.892 << 0.968 << 0.996 << 1);
+
+ QTest::newRow("OutInCubic") << int(QEasingCurve::OutInCubic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.244 << 0.392 << 0.468 << 0.496 << 0.5 << 0.504 << 0.532 << 0.608 << 0.756 << 1);
+
+ QTest::newRow("InQuart") << int(QEasingCurve::InQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0001 << 0.0016 << 0.0081 << 0.0256 << 0.0625 << 0.1296 << 0.2401 << 0.4096 << 0.6561 << 1);
+
+ QTest::newRow("OutQuart") << int(QEasingCurve::OutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3439 << 0.5904 << 0.7599 << 0.8704 << 0.9375 << 0.9744 << 0.9919 << 0.9984 << 0.9999 << 1);
+
+ QTest::newRow("InOutQuart") << int(QEasingCurve::InOutQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0008 << 0.0128 << 0.0648 << 0.2048 << 0.5 << 0.7952 << 0.9352 << 0.9872 << 0.9992 << 1);
+
+ QTest::newRow("OutInQuart") << int(QEasingCurve::OutInQuart)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.2952 << 0.4352 << 0.4872 << 0.4992 << 0.5 << 0.5008 << 0.5128 << 0.5648 << 0.7048 << 1);
+
+ QTest::newRow("InQuint") << int(QEasingCurve::InQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 1e-05 << 0.00032 << 0.00243 << 0.01024 << 0.03125 << 0.07776 << 0.1681 << 0.3277 << 0.5905 << 1);
+
+ QTest::newRow("OutQuint") << int(QEasingCurve::OutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4095 << 0.6723 << 0.8319 << 0.9222 << 0.9688 << 0.9898 << 0.9976 << 0.9997 << 1 << 1);
+
+ QTest::newRow("InOutQuint") << int(QEasingCurve::InOutQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.00016 << 0.00512 << 0.03888 << 0.1638 << 0.5 << 0.8362 << 0.9611 << 0.9949 << 0.9998 << 1);
+
+ QTest::newRow("OutInQuint") << int(QEasingCurve::OutInQuint)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3362 << 0.4611 << 0.4949 << 0.4998 << 0.5 << 0.5002 << 0.5051 << 0.5389 << 0.6638 << 1);
+
+ QTest::newRow("InSine") << int(QEasingCurve::InSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01231 << 0.04894 << 0.109 << 0.191 << 0.2929 << 0.4122 << 0.546 << 0.691 << 0.8436 << 1);
+
+ QTest::newRow("OutSine") << int(QEasingCurve::OutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1564 << 0.309 << 0.454 << 0.5878 << 0.7071 << 0.809 << 0.891 << 0.9511 << 0.9877 << 1);
+
+ QTest::newRow("InOutSine") << int(QEasingCurve::InOutSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02447 << 0.09549 << 0.2061 << 0.3455 << 0.5 << 0.6545 << 0.7939 << 0.9045 << 0.9755 << 1);
+
+ QTest::newRow("OutInSine") << int(QEasingCurve::OutInSine)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1545 << 0.2939 << 0.4045 << 0.4755 << 0.5 << 0.5245 << 0.5955 << 0.7061 << 0.8455 << 1);
+
+ QTest::newRow("InExpo") << int(QEasingCurve::InExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0009531 << 0.002906 << 0.006812 << 0.01462 << 0.03025 << 0.0615 << 0.124 << 0.249 << 0.499 << 1);
+
+ QTest::newRow("OutExpo") << int(QEasingCurve::OutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.5005 << 0.7507 << 0.8759 << 0.9384 << 0.9697 << 0.9854 << 0.9932 << 0.9971 << 0.999 << 1);
+
+ QTest::newRow("InOutExpo") << int(QEasingCurve::InOutExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001453 << 0.007312 << 0.03075 << 0.1245 << 0.5002 << 0.8754 << 0.9692 << 0.9927 << 0.9985 << 1);
+
+ QTest::newRow("OutInExpo") << int(QEasingCurve::OutInExpo)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3754 << 0.4692 << 0.4927 << 0.4985 << 0.5 << 0.5015 << 0.5073 << 0.5308 << 0.6245 << 1);
+
+ QTest::newRow("InCirc") << int(QEasingCurve::InCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.005013 << 0.0202 << 0.04606 << 0.08348 << 0.134 << 0.2 << 0.2859 << 0.4 << 0.5641 << 1);
+
+ QTest::newRow("OutCirc") << int(QEasingCurve::OutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4359 << 0.6 << 0.7141 << 0.8 << 0.866 << 0.9165 << 0.9539 << 0.9798 << 0.995 << 1);
+
+ QTest::newRow("InOutCirc") << int(QEasingCurve::InOutCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.0101 << 0.04174 << 0.1 << 0.2 << 0.5 << 0.8 << 0.9 << 0.9583 << 0.9899 << 1);
+
+ QTest::newRow("OutInCirc") << int(QEasingCurve::OutInCirc)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3 << 0.4 << 0.4583 << 0.4899 << 0.5 << 0.5101 << 0.5417 << 0.6 << 0.7 << 1);
+
+ QTest::newRow("InElastic") << int(QEasingCurve::InElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.001953 << -0.001953 << -0.003906 << 0.01562 << -0.01562 << -0.03125 << 0.125 << -0.125 << -0.25 << 1);
+
+ QTest::newRow("OutElastic") << int(QEasingCurve::OutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 1.25 << 1.125 << 0.875 << 1.031 << 1.016 << 0.9844 << 1.004 << 1.002 << 0.998 << 1);
+
+ QTest::newRow("InOutElastic") << int(QEasingCurve::InOutElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.0009766 << 0.007812 << -0.01563 << -0.0625 << 0.5 << 1.062 << 1.016 << 0.9922 << 1.001 << 1);
+
+ QTest::newRow("OutInElastic") << int(QEasingCurve::OutInElastic)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.375 << 0.5625 << 0.4922 << 0.498 << 0.5 << 0.4961 << 0.5078 << 0.5313 << 0.25 << 1);
+
+ QTest::newRow("InBack") << int(QEasingCurve::InBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.01431 << -0.04645 << -0.0802 << -0.09935 << -0.0877 << -0.02903 << 0.09287 << 0.2942 << 0.5912 << 1);
+
+ QTest::newRow("OutBack") << int(QEasingCurve::OutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.4088 << 0.7058 << 0.9071 << 1.029 << 1.088 << 1.099 << 1.08 << 1.046 << 1.014 << 1);
+
+ QTest::newRow("InOutBack") << int(QEasingCurve::InOutBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << -0.03752 << -0.09256 << -0.07883 << 0.08993 << 0.5 << 0.9101 << 1.079 << 1.093 << 1.038 << 1);
+
+ QTest::newRow("OutInBack") << int(QEasingCurve::OutInBack)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.3529 << 0.5145 << 0.5497 << 0.5232 << 0.5 << 0.4768 << 0.4503 << 0.4855 << 0.6471 << 1);
+
+ QTest::newRow("InBounce") << int(QEasingCurve::InBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.01188 << 0.06 << 0.06937 << 0.2275 << 0.2344 << 0.09 << 0.3194 << 0.6975 << 0.9244 << 1);
+
+ QTest::newRow("OutBounce") << int(QEasingCurve::OutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.07563 << 0.3025 << 0.6806 << 0.91 << 0.7656 << 0.7725 << 0.9306 << 0.94 << 0.9881 << 1);
+
+ QTest::newRow("InOutBounce") << int(QEasingCurve::InOutBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.03 << 0.1138 << 0.045 << 0.3488 << 0.5 << 0.6512 << 0.955 << 0.8862 << 0.97 << 1);
+
+ QTest::newRow("OutInBounce") << int(QEasingCurve::OutInBounce)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1513 << 0.41 << 0.2725 << 0.44 << 0.5 << 0.56 << 0.7275 << 0.59 << 0.8488 << 1);
+
+ QTest::newRow("InCurve") << int(QEasingCurve::InCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.02447 << 0.1059 << 0.2343 << 0.3727 << 0.5 << 0.6055 << 0.7 << 0.8 << 0.9 << 1);
+
+ QTest::newRow("OutCurve") << int(QEasingCurve::OutCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.1 << 0.2 << 0.3 << 0.3945 << 0.5 << 0.6273 << 0.7657 << 0.8941 << 0.9755 << 1);
+
+ QTest::newRow("SineCurve") << int(QEasingCurve::SineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0 << 0.09549 << 0.3455 << 0.6545 << 0.9045 << 1 << 0.9045 << 0.6545 << 0.3455 << 0.09549 << 0);
+
+ QTest::newRow("CosineCurve") << int(QEasingCurve::CosineCurve)
+ << (IntList() << 0 << 10 << 20 << 30 << 40 << 50 << 60 << 70 << 80 << 90 << 100)
+ << (RealList() << 0.5 << 0.7939 << 0.9755 << 0.9755 << 0.7939 << 0.5 << 0.2061 << 0.02447 << 0.02447 << 0.2061 << 0.5);
+
+}
+
+
+void tst_QEasingCurve::valueForProgress()
+{
+#if 0
+ // used to generate data tables...
+ QFile out;
+ out.open(stdout, QIODevice::WriteOnly);
+ for (int c = QEasingCurve::Linear; c < QEasingCurve::NCurveTypes - 1; ++c) {
+ QEasingCurve curve((QEasingCurve::Type)c);
+ QMetaObject mo = QEasingCurve::staticMetaObject;
+ QString strCurve = QLatin1String(mo.enumerator(mo.indexOfEnumerator("Type")).key(c));
+ QString strInputs;
+ QString strOutputs;
+
+ for (int t = 0; t <= 100; t+= 10) {
+ qreal ease = curve.valueForProgress(t/qreal(100));
+ strInputs += QString::fromAscii(" << %1").arg(t);
+ strOutputs += " << " + QString().setNum(ease, 'g', 4);
+ }
+ QString str = QString::fromAscii(" QTest::newRow(\"%1\") << int(QEasingCurve::%2)\n"
+ " << (IntList() %3)\n"
+ " << (RealList()%4);\n\n")
+ .arg(strCurve)
+ .arg(strCurve)
+ .arg(strInputs)
+ .arg(strOutputs);
+ out.write(str.toLatin1().constData());
+ }
+ out.close();
+ exit(1);
+#else
+ QFETCH(int, type);
+ QFETCH(IntList, at);
+ QFETCH(RealList, expected);
+
+ QEasingCurve curve((QEasingCurve::Type)type);
+ for (int i = 0; i < at.count(); ++i) {
+ qreal ease = curve.valueForProgress(at.at(i)/qreal(100));
+ // converting ease to 4 precision qreal to match the generated samples
+ qreal easeConv = qreal(QString().setNum(ease, 'g', 4).toDouble());
+ qreal ex = expected.at(i);
+
+ // the least significant digit it is still subject to rounding errors
+ qreal error = easeConv - ex;
+ // accept the potential rounding error in the least significant digit
+ QVERIFY(error <= 0.00001 );
+ }
+#endif
+}
+
+static qreal discreteEase(qreal progress)
+{
+ return qFloor(progress * 10) / qreal(10.0);
+}
+
+void tst_QEasingCurve::setCustomType()
+{
+ QEasingCurve curve;
+ curve.setCustomType(&discreteEase);
+ QCOMPARE(curve.type(), QEasingCurve::Custom);
+ QCOMPARE(curve.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve.valueForProgress(0.05), 0.0);
+ QCOMPARE(curve.valueForProgress(0.10), 0.1);
+ QCOMPARE(curve.valueForProgress(0.15), 0.1);
+ QCOMPARE(curve.valueForProgress(0.20), 0.2);
+ QCOMPARE(curve.valueForProgress(0.25), 0.2);
+ QCOMPARE(curve.valueForProgress(0.30), 0.3);
+ QCOMPARE(curve.valueForProgress(0.35), 0.3);
+ QCOMPARE(curve.valueForProgress(0.999999), 0.9);
+
+ curve.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.type(), QEasingCurve::Linear);
+ QCOMPARE(curve.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve.valueForProgress(0.1), 0.1);
+ QCOMPARE(curve.valueForProgress(0.5), 0.5);
+ QCOMPARE(curve.valueForProgress(0.99), 0.99);
+}
+
+void tst_QEasingCurve::operators()
+{
+ // operator=
+ QEasingCurve curve;
+ QEasingCurve curve2;
+ curve.setCustomType(&discreteEase);
+ curve2 = curve;
+ QCOMPARE(curve2.type(), QEasingCurve::Custom);
+ QCOMPARE(curve2.valueForProgress(0.0), 0.0);
+ QCOMPARE(curve2.valueForProgress(0.05), 0.0);
+ QCOMPARE(curve2.valueForProgress(0.15), 0.1);
+ QCOMPARE(curve2.valueForProgress(0.25), 0.2);
+ QCOMPARE(curve2.valueForProgress(0.35), 0.3);
+ QCOMPARE(curve2.valueForProgress(0.999999), 0.9);
+
+ // operator==
+ curve.setType(QEasingCurve::InBack);
+ curve2 = curve;
+ curve2.setOvershoot(qreal(1.70158f));
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 == curve);
+
+ curve.setOvershoot(3.0);
+ QVERIFY(curve2 != curve);
+ curve2.setOvershoot(3.0);
+ QVERIFY(curve2 == curve);
+
+ curve2.setType(QEasingCurve::Linear);
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 != curve);
+ curve2.setType(QEasingCurve::InBack);
+ QCOMPARE(curve.overshoot(), curve2.overshoot());
+ QVERIFY(curve2 == curve);
+}
+
+
+QTEST_MAIN(tst_QEasingCurve)
+#include "tst_qeasingcurve.moc"
+
+#endif //QT_VERSION
diff --git a/tests/auto/qfile/copy-fallback.qrc b/tests/auto/qfile/copy-fallback.qrc
new file mode 100644
index 0000000..864491f
--- /dev/null
+++ b/tests/auto/qfile/copy-fallback.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>copy-fallback.qrc</file>
+</qresource>
+</RCC>
diff --git a/tests/auto/qfile/test/test.pro b/tests/auto/qfile/test/test.pro
index 68f4c05..8d26f5e 100644
--- a/tests/auto/qfile/test/test.pro
+++ b/tests/auto/qfile/test/test.pro
@@ -17,7 +17,7 @@ QT = core network
DEFINES += SRCDIR=\\\"$$PWD/../\\\"
}
-RESOURCES += ../qfile.qrc ../rename-fallback.qrc
+RESOURCES += ../qfile.qrc ../rename-fallback.qrc ../copy-fallback.qrc
TARGET = ../tst_qfile
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index cb8091b..d650b0d 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -126,6 +126,7 @@ private slots:
void copyAfterFail();
void copyRemovesTemporaryFile() const;
void copyShouldntOverwrite();
+ void copyFallback();
void link();
void linkToDir();
void absolutePathLinkToRelativePath();
@@ -214,6 +215,13 @@ void tst_QFile::cleanup()
// TODO: Add cleanup code here.
// This will be executed immediately after each test is run.
+ // for copyFallback()
+ if (QFile::exists("file-copy-destination.txt")) {
+ QFile::setPermissions("file-copy-destination.txt",
+ QFile::ReadOwner | QFile::WriteOwner);
+ QFile::remove("file-copy-destination.txt");
+ }
+
// for renameFallback()
QFile::remove("file-rename-destination.txt");
@@ -948,6 +956,34 @@ void tst_QFile::copyShouldntOverwrite()
QFile::remove("tst_qfile.cpy");
}
+void tst_QFile::copyFallback()
+{
+ // Using a resource file to trigger QFile::copy's fallback handling
+ QFile file(":/copy-fallback.qrc");
+ QFile::remove("file-copy-destination.txt");
+
+ QVERIFY2(file.exists(), "test precondition");
+ QVERIFY2(!QFile::exists("file-copy-destination.txt"), "test precondition");
+
+ // Fallback copy of closed file.
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ // Need to reset permissions on Windows to be able to delete
+ QVERIFY(QFile::setPermissions("file-copy-destination.txt",
+ QFile::ReadOwner | QFile::WriteOwner));
+ QVERIFY(QFile::remove("file-copy-destination.txt"));
+
+ // Fallback copy of open file.
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QVERIFY(file.copy("file-copy-destination.txt"));
+ QVERIFY(QFile::exists("file-copy-destination.txt"));
+ QVERIFY(!file.isOpen());
+
+ QFile::remove("file-copy-destination.txt");
+}
+
#ifdef Q_OS_WIN
#include <objbase.h>
#include <shlobj.h>
@@ -2122,6 +2158,7 @@ void tst_QFile::renameFallback()
QVERIFY(!file.rename("file-rename-destination.txt"));
QVERIFY(!QFile::exists("file-rename-destination.txt"));
+ QVERIFY(!file.isOpen());
}
void tst_QFile::renameMultiple()
diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp
index 689f73d..16c84d8 100644
--- a/tests/auto/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp
@@ -159,6 +159,7 @@ private slots:
void task218353_relativePaths();
void task251321_sideBarHiddenEntries();
void task251341_sideBarRemoveEntries();
+ void task254490_selectFileMultipleTimes();
private:
QByteArray userSettings;
@@ -1981,5 +1982,37 @@ void tst_QFiledialog::task251341_sideBarRemoveEntries()
current.rmdir("testDir");
}
+void tst_QFiledialog::task254490_selectFileMultipleTimes()
+{
+ QString tempPath = QDir::tempPath();
+ QTemporaryFile *t;
+ t = new QTemporaryFile;
+ t->open();
+ QNonNativeFileDialog fd(0, "TestFileDialog");
+
+ fd.setDirectory(tempPath);
+ fd.setViewMode(QFileDialog::List);
+ fd.setAcceptMode(QFileDialog::AcceptSave);
+ fd.setFileMode(QFileDialog::AnyFile);
+
+ //This should select the file in the QFileDialog
+ fd.selectFile(t->fileName());
+
+ //This should clear the selection and write it into the filename line edit
+ fd.selectFile("new_file.txt");
+
+ fd.show();
+ QTest::qWait(250);
+
+ QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit");
+ QVERIFY(lineEdit);
+ QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt"));
+ QListView *list = qFindChild<QListView*>(&fd, "listView");
+ QVERIFY(list);
+ QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0);
+
+ t->deleteLater();
+}
+
QTEST_MAIN(tst_QFiledialog)
#include "tst_qfiledialog.moc"
diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 59d57ce..b109d4b 100644
--- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -43,6 +43,7 @@
#include <QtTest/QtTest>
#include "../../../src/gui/dialogs/qfilesystemmodel_p.h"
#include <QFileIconProvider>
+#include <QTreeView>
#include "../../shared/util.h"
#include <QTime>
#include <QStyle>
@@ -102,6 +103,7 @@ private slots:
void setData_data();
void setData();
+ void sort_data();
void sort();
void mkdir();
@@ -452,8 +454,12 @@ void tst_QFileSystemModel::rowsInserted()
} else {
QCOMPARE(model->index(model->rowCount(root) - 1, 0, root).data().toString(), QString("b"));
}
- if (spy0.count() > 0)
- if (count == 0) QCOMPARE(spy0.count(), 0); else QVERIFY(spy0.count() >= 1);
+ if (spy0.count() > 0) {
+ if (count == 0)
+ QCOMPARE(spy0.count(), 0);
+ else
+ QVERIFY(spy0.count() >= 1);
+ }
if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1);
QVERIFY(createFiles(tmp, QStringList(".hidden_file"), 5 + count));
@@ -722,6 +728,19 @@ void tst_QFileSystemModel::setData()
QTRY_COMPARE(model->rowCount(root), files.count());
}
+class MyFriendFileSystemModel : public QFileSystemModel
+{
+ friend class tst_QFileSystemModel;
+ Q_DECLARE_PRIVATE(QFileSystemModel)
+};
+
+void tst_QFileSystemModel::sort_data()
+{
+ QTest::addColumn<bool>("fileDialogMode");
+ QTest::newRow("standard usage") << false;
+ QTest::newRow("QFileDialog usage") << true;
+}
+
void tst_QFileSystemModel::sort()
{
QTemporaryFile file;
@@ -733,8 +752,48 @@ void tst_QFileSystemModel::sort()
model->sort(0, Qt::AscendingOrder);
model->sort(0, Qt::DescendingOrder);
QVERIFY(idx.column() != 0);
-}
+ QFETCH(bool, fileDialogMode);
+
+ MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel();
+ QTreeView *tree = new QTreeView();
+
+ if (fileDialogMode)
+ myModel->d_func()->disableRecursiveSort = true;
+
+ const QString dirPath = QString("%1/sortTemp").arg(QDir::tempPath());
+ QDir dir(dirPath);
+ dir.mkpath(dirPath);
+ QVERIFY(dir.exists());
+ dir.mkdir("a");
+ dir.mkdir("b");
+ dir.mkdir("c");
+ dir.mkdir("d");
+ dir.mkdir("e");
+ dir.mkdir("f");
+ dir.mkdir("g");
+ QTemporaryFile tempFile(dirPath + "/rXXXXXX");
+ tempFile.open();
+ myModel->setRootPath(QDir::rootPath());
+ tree->setModel(myModel);
+ tree->show();
+ QTest::qWait(500);
+ tree->expand(myModel->index(dir.absolutePath(), 0));
+ while (dir.cdUp())
+ {
+ tree->expand(myModel->index(dir.absolutePath(), 0));
+ }
+ QTest::qWait(250);
+ //File dialog Mode means sub trees are not sorted, only the current root
+ if (fileDialogMode)
+ QVERIFY(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString() != dirPath + QLatin1String("/a"));
+ else
+ QCOMPARE(myModel->index(0, 1, myModel->index(dirPath, 0)).data(QFileSystemModel::FilePathRole).toString(), dirPath + QLatin1String("/a"));
+
+ delete tree;
+ delete myModel;
+
+}
void tst_QFileSystemModel::mkdir()
{
diff --git a/tests/auto/qfuture/tst_qfuture.cpp b/tests/auto/qfuture/tst_qfuture.cpp
index 43fd614..383ecba 100644
--- a/tests/auto/qfuture/tst_qfuture.cpp
+++ b/tests/auto/qfuture/tst_qfuture.cpp
@@ -45,7 +45,7 @@
#include <QtTest/QtTest>
#include <qfuture.h>
-#include <versioncheck.h>
+#include "versioncheck.h"
#include <qfuturewatcher.h>
#include <qtconcurrentresultstore.h>
#include <qtconcurrentexception.h>
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 3b9895d..8afdeb4 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -217,6 +217,10 @@ private slots:
void tabChangesFocus_data();
void cacheMode();
void updateCachedItemAfterMove();
+ void deviceTransform_data();
+ void deviceTransform();
+ void setTransformProperties_data();
+ void setTransformProperties();
// task specific tests below me
void task141694_textItemEnsureVisible();
@@ -226,6 +230,7 @@ private slots:
void task240400_clickOnTextItem_data();
void task240400_clickOnTextItem();
void task243707_addChildBeforeParent();
+ void task197802_childrenVisibility();
};
void tst_QGraphicsItem::init()
@@ -245,50 +250,59 @@ void tst_QGraphicsItem::construction()
QCOMPARE(int(item->type()), int(QGraphicsEllipseItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), (QGraphicsEllipseItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 1:
item = new QGraphicsLineItem;
QCOMPARE(int(item->type()), int(QGraphicsLineItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 2:
item = new QGraphicsPathItem;
QCOMPARE(int(item->type()), int(QGraphicsPathItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), (QGraphicsPathItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 3:
item = new QGraphicsPixmapItem;
QCOMPARE(int(item->type()), int(QGraphicsPixmapItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), (QGraphicsPixmapItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 4:
item = new QGraphicsPolygonItem;
QCOMPARE(int(item->type()), int(QGraphicsPolygonItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), (QGraphicsPolygonItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 5:
item = new QGraphicsRectItem;
QCOMPARE(int(item->type()), int(QGraphicsRectItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)0);
+ QCOMPARE(item->flags(), 0);
break;
case 6:
- default:
item = new QGraphicsTextItem;
QCOMPARE(int(item->type()), int(QGraphicsTextItem::Type));
QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), (QGraphicsTextItem *)item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)0);
+ // This is the only item that uses an extended style option.
+ QCOMPARE(item->flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption));
+ break;
+ default:
+ qFatal("You broke the logic, please fix!");
break;
}
QCOMPARE(item->scene(), (QGraphicsScene *)0);
QCOMPARE(item->parentItem(), (QGraphicsItem *)0);
QVERIFY(item->children().isEmpty());
- QCOMPARE(item->flags(), 0);
QVERIFY(item->isVisible());
QVERIFY(item->isEnabled());
QVERIFY(!item->isSelected());
@@ -5424,6 +5438,41 @@ void tst_QGraphicsItem::task243707_addChildBeforeParent()
QVERIFY(!widget2->commonAncestorItem(widget));
}
+void tst_QGraphicsItem::task197802_childrenVisibility()
+{
+ QGraphicsScene scene;
+ QGraphicsRectItem item(QRectF(0,0,20,20));
+
+ QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(0,0,10,10), &item);
+ scene.addItem(&item);
+
+ //freshly created: both visible
+ QVERIFY(item.isVisible());
+ QVERIFY(item2->isVisible());
+
+ //hide child: parent visible, child not
+ item2->hide();
+ QVERIFY(item.isVisible());
+ QVERIFY(!item2->isVisible());
+
+ //hide parent: parent and child invisible
+ item.hide();
+ QVERIFY(!item.isVisible());
+ QVERIFY(!item2->isVisible());
+
+ //ask to show the child: parent and child invisible anyways
+ item2->show();
+ QVERIFY(!item.isVisible());
+ QVERIFY(!item2->isVisible());
+
+ //show the parent: both parent and child visible
+ item.show();
+ QVERIFY(item.isVisible());
+ QVERIFY(item2->isVisible());
+
+ delete item2;
+}
+
void tst_QGraphicsItem::boundingRegion_data()
{
QTest::addColumn<QLineF>("line");
@@ -6271,5 +6320,237 @@ void tst_QGraphicsItem::updateCachedItemAfterMove()
QCOMPARE(tester->repaints, 1);
}
+class Track : public QGraphicsRectItem
+{
+public:
+ Track(const QRectF &rect)
+ : QGraphicsRectItem(rect)
+ {
+ setAcceptHoverEvents(true);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ {
+ QGraphicsRectItem::paint(painter, option, widget);
+ painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1x%2\n%3x%4").arg(p.x()).arg(p.y()).arg(sp.x()).arg(sp.y()));
+ }
+
+protected:
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+ {
+ p = event->pos();
+ sp = event->widget()->mapFromGlobal(event->screenPos());
+ update();
+ }
+private:
+ QPointF p;
+ QPoint sp;
+};
+
+void tst_QGraphicsItem::deviceTransform_data()
+{
+ QTest::addColumn<bool>("untransformable1");
+ QTest::addColumn<bool>("untransformable2");
+ QTest::addColumn<bool>("untransformable3");
+ QTest::addColumn<qreal>("rotation1");
+ QTest::addColumn<qreal>("rotation2");
+ QTest::addColumn<qreal>("rotation3");
+ QTest::addColumn<QTransform>("deviceX");
+ QTest::addColumn<QPointF>("mapResult1");
+ QTest::addColumn<QPointF>("mapResult2");
+ QTest::addColumn<QPointF>("mapResult3");
+
+ QTest::newRow("nil") << false << false << false
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform()
+ << QPointF(150, 150) << QPointF(250, 250) << QPointF(350, 350);
+ QTest::newRow("deviceX rot 90") << false << false << false
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-350, 350);
+ QTest::newRow("deviceX rot 90 100") << true << false << false
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350);
+ QTest::newRow("deviceX rot 90 010") << false << true << false
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-150, 150) << QPointF(-150, 250) << QPointF(-50, 350);
+ QTest::newRow("deviceX rot 90 001") << false << false << true
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-150, 150) << QPointF(-250, 250) << QPointF(-250, 350);
+ QTest::newRow("deviceX rot 90 111") << true << true << true
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350);
+ QTest::newRow("deviceX rot 90 101") << true << false << true
+ << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << QTransform().rotate(90)
+ << QPointF(-50, 150) << QPointF(50, 250) << QPointF(150, 350);
+}
+
+void tst_QGraphicsItem::deviceTransform()
+{
+ QFETCH(bool, untransformable1);
+ QFETCH(bool, untransformable2);
+ QFETCH(bool, untransformable3);
+ QFETCH(qreal, rotation1);
+ QFETCH(qreal, rotation2);
+ QFETCH(qreal, rotation3);
+ QFETCH(QTransform, deviceX);
+ QFETCH(QPointF, mapResult1);
+ QFETCH(QPointF, mapResult2);
+ QFETCH(QPointF, mapResult3);
+
+ QGraphicsScene scene;
+ Track *rect1 = new Track(QRectF(0, 0, 100, 100));
+ Track *rect2 = new Track(QRectF(0, 0, 100, 100));
+ Track *rect3 = new Track(QRectF(0, 0, 100, 100));
+ rect2->setParentItem(rect1);
+ rect3->setParentItem(rect2);
+ rect1->setPos(100, 100);
+ rect2->setPos(100, 100);
+ rect3->setPos(100, 100);
+ rect1->rotate(rotation1);
+ rect2->rotate(rotation2);
+ rect3->rotate(rotation3);
+ rect1->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable1);
+ rect2->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable2);
+ rect3->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable3);
+ rect1->setBrush(Qt::red);
+ rect2->setBrush(Qt::green);
+ rect3->setBrush(Qt::blue);
+ scene.addItem(rect1);
+
+ QCOMPARE(rect1->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult1);
+ QCOMPARE(rect2->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult2);
+ QCOMPARE(rect3->deviceTransform(deviceX).map(QPointF(50, 50)), mapResult3);
+}
+
+void tst_QGraphicsItem::setTransformProperties_data()
+{
+ QTest::addColumn<QPointF>("origin");
+ QTest::addColumn<qreal>("rotationX");
+ QTest::addColumn<qreal>("rotationY");
+ QTest::addColumn<qreal>("rotationZ");
+ QTest::addColumn<qreal>("scaleX");
+ QTest::addColumn<qreal>("scaleY");
+ QTest::addColumn<qreal>("shearX");
+ QTest::addColumn<qreal>("shearY");
+
+ QTest::newRow("nothing") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationZ") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(42.2)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXY") << QPointF() << qreal(12.5) << qreal(53.6) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXYZ") << QPointF() << qreal(-25) << qreal(12) << qreal(556)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("rotationXYZ dicentred") << QPointF(-53, 25.2)
+ << qreal(-2578.2) << qreal(4565.2) << qreal(56)
+ << qreal(1) << qreal(1) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("Scale") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(6) << qreal(0.5) << qreal(0.0) << qreal(0.0);
+
+ QTest::newRow("Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(1) << qreal(1) << qreal(2.2) << qreal(0.5);
+
+ QTest::newRow("Scale and Shear") << QPointF() << qreal(0.0) << qreal(0.0) << qreal(0.0)
+ << qreal(5.2) << qreal(2.1) << qreal(5.2) << qreal(5.5);
+
+ QTest::newRow("Everything") << QPointF() << qreal(41) << qreal(-23) << qreal(0.56)
+ << qreal(8.2) << qreal(-0.2) << qreal(-12) << qreal(-0.8);
+
+ QTest::newRow("Everything dicentred") << QPointF(qreal(22.3), qreal(-56.2)) << qreal(-175) << qreal(196) << qreal(-1260)
+ << qreal(4) << qreal(2) << qreal(2.56) << qreal(0.8);
+}
+
+void tst_QGraphicsItem::setTransformProperties()
+{
+ QFETCH(QPointF,origin);
+ QFETCH(qreal,rotationX);
+ QFETCH(qreal,rotationY);
+ QFETCH(qreal,rotationZ);
+ QFETCH(qreal,scaleX);
+ QFETCH(qreal,scaleY);
+ QFETCH(qreal,shearX);
+ QFETCH(qreal,shearY);
+
+ QTransform result;
+ result.translate(origin.x(), origin.y());
+ result.rotate(rotationX, Qt::XAxis);
+ result.rotate(rotationY, Qt::YAxis);
+ result.rotate(rotationZ, Qt::ZAxis);
+ result.shear(shearX, shearY);
+ result.scale(scaleX, scaleY);
+ result.translate(-origin.x(), -origin.y());
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100));
+ scene.addItem(item);
+ item->setPos(100, 100);
+
+ item->setRotation(rotationX, rotationY, rotationZ);
+ item->setScale(scaleX, scaleY);
+ item->setShear(shearX, shearY);
+ item->setTransformOrigin(origin);
+
+ QCOMPARE(item->xRotation(), rotationX);
+ QCOMPARE(item->yRotation(), rotationY);
+ QCOMPARE(item->zRotation(), rotationZ);
+ QCOMPARE(item->xScale(), scaleX);
+ QCOMPARE(item->yScale(), scaleY);
+ QCOMPARE(item->horizontalShear(), shearX);
+ QCOMPARE(item->verticalShear(), shearY);
+ QCOMPARE(item->transformOrigin(), origin);
+
+ QCOMPARE(result, item->transform());
+
+ //-----------------------------------------------------------------
+ //Change the rotation Z
+ item->setZRotation(45);
+ QTransform result2;
+ result2.translate(origin.x(), origin.y());
+ result2.rotate(rotationX, Qt::XAxis);
+ result2.rotate(rotationY, Qt::YAxis);
+ result2.rotate(45, Qt::ZAxis);
+ result2.shear(shearX, shearY);
+ result2.scale(scaleX, scaleY);
+ result2.translate(-origin.x(), -origin.y());
+
+ QCOMPARE(item->xRotation(), rotationX);
+ QCOMPARE(item->yRotation(), rotationY);
+ QCOMPARE(item->zRotation(), 45.0);
+ QCOMPARE(item->xScale(), scaleX);
+ QCOMPARE(item->yScale(), scaleY);
+ QCOMPARE(item->horizontalShear(), shearX);
+ QCOMPARE(item->verticalShear(), shearY);
+ QCOMPARE(item->transformOrigin(), origin);
+
+ QCOMPARE(result2, item->transform());
+
+ //-----------------------------------------------------------------
+ // calling setTransform() should reset the properties to their default
+ item->setTransform(result);
+
+ QCOMPARE(item->xRotation(), 0.0);
+ QCOMPARE(item->yRotation(), 0.0);
+ QCOMPARE(item->zRotation(), 0.0);
+ QCOMPARE(item->xScale(), 1.0);
+ QCOMPARE(item->yScale(), 1.0);
+ QCOMPARE(item->horizontalShear(), 0.0);
+ QCOMPARE(item->verticalShear(), 0.0);
+ QCOMPARE(item->transformOrigin(), QPointF(0,0));
+
+ QCOMPARE(result, item->transform());
+}
+
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index da99c30..0c5ebf6 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -47,6 +47,7 @@
#include <QtGui>
#include <math.h>
+#include "../../shared/util.h"
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
#include <windows.h>
@@ -3537,8 +3538,7 @@ void tst_QGraphicsScene::changedSignal()
scene.addItem(rect);
QCOMPARE(cl.changes.size(), 0);
- qApp->processEvents();
- QCOMPARE(cl.changes.size(), 1);
+ QTRY_COMPARE(cl.changes.size(), 1);
QCOMPARE(cl.changes.at(0).size(), 1);
QCOMPARE(cl.changes.at(0).first(), QRectF(0, 0, 10, 10));
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index bb61f90..8e490ad 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -204,6 +204,7 @@ private slots:
void task239729_noViewUpdate();
void task239047_fitInViewSmallViewport();
void task245469_itemsAtPointWithClip();
+ void task253415_reconnectUpdateSceneOnSceneChanged();
};
void tst_QGraphicsView::initTestCase()
@@ -2370,7 +2371,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *viewport)
{
- lastLod = option->levelOfDetail;
+ lastLod = option->levelOfDetailFromTransform(painter->worldTransform());
QGraphicsRectItem::paint(painter, option, viewport);
}
@@ -3200,5 +3201,28 @@ void tst_QGraphicsView::mouseTracking2()
QCOMPARE(spy.count(), 1);
}
+void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged()
+{
+ QGraphicsView view;
+ QGraphicsView dummyView;
+ view.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint);
+ view.resize(200, 200);
+
+ QGraphicsScene scene1;
+ QObject::connect(&scene1, SIGNAL(changed(QList<QRectF>)), &dummyView, SLOT(updateScene(QList<QRectF>)));
+ view.setScene(&scene1);
+
+ QTest::qWait(125);
+
+ QGraphicsScene scene2;
+ QObject::connect(&scene2, SIGNAL(changed(QList<QRectF>)), &dummyView, SLOT(updateScene(QList<QRectF>)));
+ view.setScene(&scene2);
+
+ QTest::qWait(125);
+
+ bool wasConnected2 = QObject::disconnect(&scene2, SIGNAL(changed(QList<QRectF>)), &view, 0);
+ QVERIFY(wasConnected2);
+}
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"
diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
index 56737c3..56d42c3 100644
--- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -50,6 +50,8 @@
#include <qcleanlooksstyle.h>
#include <qlineedit.h>
#include <qboxlayout.h>
+#include <qaction.h>
+#include <qwidgetaction.h>
#include "../../shared/util.h"
@@ -148,13 +150,16 @@ private slots:
void defaultSize();
void explicitMouseGrabber();
void implicitMouseGrabber();
+ void doubleClickAfterExplicitMouseGrab();
void popupMouseGrabber();
void windowFlags_data();
void windowFlags();
+ void shortcutsDeletion();
// Task fixes
void task236127_bspTreeIndexFails();
void task243004_setStyleCrash();
+ void task250119_shortcutContext();
};
@@ -1996,6 +2001,104 @@ void tst_QGraphicsWidget::implicitMouseGrabber()
QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0);
}
+class GrabOnPressItem : public QGraphicsRectItem
+{
+public:
+ GrabOnPressItem(const QRectF &rect)
+ : QGraphicsRectItem(rect),
+ npress(0), nrelease(0), ndoubleClick(0),
+ ngrab(0), nungrab(0)
+ {
+ }
+ int npress;
+ int nrelease;
+ int ndoubleClick;
+ int ngrab;
+ int nungrab;
+protected:
+ bool sceneEvent(QEvent *event)
+ {
+ switch (event->type()) {
+ case QEvent::GrabMouse:
+ ++ngrab;
+ break;
+ case QEvent::UngrabMouse:
+ ++nungrab;
+ break;
+ default:
+ break;
+ }
+ return QGraphicsRectItem::sceneEvent(event);
+ }
+
+ void mousePressEvent(QGraphicsSceneMouseEvent *)
+ {
+ grabMouse();
+ ++npress;
+ }
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ {
+ ungrabMouse();
+ ++nrelease;
+ }
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *)
+ {
+ ++ndoubleClick;
+ }
+};
+
+void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab()
+{
+ QGraphicsScene scene;
+ GrabOnPressItem *item = new GrabOnPressItem(QRectF(0, 0, 100, 100));
+ scene.addItem(item);
+
+ {
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
+ event.setButton(Qt::LeftButton);
+ event.setButtons(Qt::LeftButton);
+ event.ignore();
+ event.setScenePos(QPointF(50, 50));
+ qApp->sendEvent(&scene, &event);
+ }
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(item->npress, 1);
+ QCOMPARE(item->ngrab, 1);
+ {
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
+ event.setButton(Qt::LeftButton);
+ event.setButtons(0);
+ event.ignore();
+ event.setScenePos(QPointF(50, 50));
+ qApp->sendEvent(&scene, &event);
+ }
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0);
+ QCOMPARE(item->nrelease, 1);
+ QCOMPARE(item->nungrab, 1);
+ {
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseDoubleClick);
+ event.setButton(Qt::LeftButton);
+ event.setButtons(Qt::LeftButton);
+ event.ignore();
+ event.setScenePos(QPointF(50, 50));
+ qApp->sendEvent(&scene, &event);
+ }
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(item->ndoubleClick, 1);
+ QCOMPARE(item->ngrab, 2);
+ {
+ QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
+ event.setButton(Qt::LeftButton);
+ event.setButtons(0);
+ event.ignore();
+ event.setScenePos(QPointF(50, 50));
+ qApp->sendEvent(&scene, &event);
+ }
+ QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)0);
+ QCOMPARE(item->nrelease, 2);
+ QCOMPARE(item->nungrab, 2);
+}
+
void tst_QGraphicsWidget::popupMouseGrabber()
{
QGraphicsScene scene;
@@ -2165,6 +2268,20 @@ void tst_QGraphicsWidget::windowFlags()
QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags));
}
+void tst_QGraphicsWidget::shortcutsDeletion()
+{
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsWidget *widget2 = new QGraphicsWidget;
+ widget->setMinimumSize(40, 40);
+ QWidgetAction *del = new QWidgetAction(widget);
+ del->setIcon(QIcon("edit-delete"));
+ del->setShortcut(Qt::Key_Delete);
+ del->setShortcutContext(Qt::WidgetShortcut);
+ widget2->addAction(del);
+ widget2->addAction(del);
+ delete widget;
+}
+
class ProxyStyle : public QCommonStyle
{
public:
@@ -2212,6 +2329,89 @@ void tst_QGraphicsWidget::task243004_setStyleCrash()
delete item2;
}
+class GraphicsWidget_task250119 : public QGraphicsWidget
+{
+public:
+ GraphicsWidget_task250119()
+ : shortcutEvents(0)
+ {
+ setFocusPolicy(Qt::StrongFocus);
+ resize(100, 100);
+ }
+
+ int shortcutEvents;
+
+private:
+ bool event(QEvent *event)
+ {
+ if (event->type() == QEvent::Shortcut)
+ shortcutEvents++;
+ return QGraphicsWidget::event(event);
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ {
+ if (hasFocus()) {
+ painter->setPen(QPen(Qt::black, 0, Qt::DashLine));
+ painter->drawRect(rect());
+ }
+ painter->setPen(QPen(Qt::black, 0, Qt::SolidLine));
+ painter->fillRect(rect().adjusted(2, 2, -2, -2), Qt::yellow);
+ painter->drawRect(rect().adjusted(2, 2, -2, -2));
+ }
+};
+
+void tst_QGraphicsWidget::task250119_shortcutContext()
+{
+ QGraphicsScene scene;
+ QGraphicsView view;
+ view.setScene(&scene);
+ view.show();
+ QTest::qWait(100);
+
+
+ // *** Event: ***
+
+ GraphicsWidget_task250119 w_event;
+ scene.addItem(&w_event);
+
+ const int id = w_event.grabShortcut(Qt::Key_A, Qt::WidgetWithChildrenShortcut);
+ w_event.setShortcutEnabled(id, true);
+
+ w_event.setFocus();
+ QTest::keyPress(&view, Qt::Key_A);
+ QCOMPARE(w_event.shortcutEvents, 1);
+
+ w_event.clearFocus();
+ QTest::keyPress(&view, Qt::Key_A);
+ QCOMPARE(w_event.shortcutEvents, 1);
+
+ scene.removeItem(&w_event);
+
+
+ // *** Signal: ***
+
+ GraphicsWidget_task250119 w_signal;
+ scene.addItem(&w_signal);
+
+ QAction action(0);
+ action.setShortcut(Qt::Key_B);
+ action.setShortcutContext(Qt::WidgetWithChildrenShortcut);
+ QSignalSpy spy(&action, SIGNAL(triggered()));
+
+ w_signal.addAction(&action);
+
+ w_signal.setFocus();
+ QTest::keyPress(&view, Qt::Key_B);
+ QCOMPARE(spy.count(), 1);
+
+ w_signal.clearFocus();
+ QTest::keyPress(&view, Qt::Key_B);
+ QCOMPARE(spy.count(), 1);
+
+ scene.removeItem(&w_signal);
+}
+
QTEST_MAIN(tst_QGraphicsWidget)
#include "tst_qgraphicswidget.moc"
diff --git a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
index b22397f..eb30147 100644
--- a/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
+++ b/tests/auto/qhttpnetworkconnection/tst_qhttpnetworkconnection.cpp
@@ -42,6 +42,7 @@
#include <QtTest/QtTest>
#include "private/qhttpnetworkconnection_p.h"
+#include "private/qnoncontiguousbytedevice_p.h"
#include <QAuthenticator>
#include "../network-settings.h"
@@ -303,8 +304,8 @@ void tst_QHttpNetworkConnection::put()
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Put);
QByteArray array = data.toLatin1();
- QBuffer buffer(&array);
- request.setData(&buffer);
+ QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array);
+ request.setUploadByteDevice(bd);
finishedCalled = false;
finishedWithErrorCalled = false;
@@ -393,8 +394,8 @@ void tst_QHttpNetworkConnection::post()
QHttpNetworkRequest request(protocol + host + path, QHttpNetworkRequest::Post);
QByteArray array = data.toLatin1();
- QBuffer buffer(&array);
- request.setData(&buffer);
+ QNonContiguousByteDevice *bd = QNonContiguousByteDeviceFactory::create(&array);
+ request.setUploadByteDevice(bd);
QHttpNetworkReply *reply = connection.sendRequest(request);
diff --git a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
index 9ef8f9a..7eaf7c7 100644
--- a/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
+++ b/tests/auto/qhttpsocketengine/tst_qhttpsocketengine.cpp
@@ -137,8 +137,6 @@ public slots:
}
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QHttpSocketEngine::tst_QHttpSocketEngine()
{
}
@@ -307,12 +305,11 @@ void tst_QHttpSocketEngine::simpleConnectToIMAP()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
QVERIFY(!socketDevice.localAddress().isNull());
QVERIFY(socketDevice.localPort() > 0);
@@ -328,7 +325,7 @@ void tst_QHttpSocketEngine::simpleConnectToIMAP()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -369,7 +366,6 @@ void tst_QHttpSocketEngine::simpleErrorsAndStates()
QVERIFY(!socketDevice.connectToHost(QHostAddress(QtNetworkSettings::serverName()), 8088));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
if (socketDevice.waitForWrite(15000)) {
- qDebug() << socketDevice.state();
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState ||
socketDevice.state() == QAbstractSocket::UnconnectedState);
} else {
@@ -451,14 +447,14 @@ void tst_QHttpSocketEngine::tcpSocketBlockingTest()
QTcpSocket socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected());
QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
// Read greeting
QVERIFY(socket.waitForReadyRead(5000));
QString s = socket.readLine();
- QCOMPARE(s.toLatin1().constData(), "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ QCOMPARE(s.toLatin1().constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write NOOP
QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8);
@@ -508,7 +504,7 @@ void tst_QHttpSocketEngine::tcpSocketNonBlockingTest()
tcpSocketNonBlocking_socket = &socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QCOMPARE(socket.state(), QTcpSocket::HostLookupState);
QTestEventLoop::instance().enterLoop(30);
@@ -533,7 +529,7 @@ void tst_QHttpSocketEngine::tcpSocketNonBlockingTest()
// Read greeting
QVERIFY(!tcpSocketNonBlocking_data.isEmpty());
QCOMPARE(tcpSocketNonBlocking_data.at(0).toLatin1().constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
tcpSocketNonBlocking_data.clear();
tcpSocketNonBlocking_totalWritten = 0;
@@ -696,12 +692,11 @@ void tst_QHttpSocketEngine::passwordAuth()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, QtNetworkSettings::serverName(), 3128, "qsockstest", "password"));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -715,7 +710,7 @@ void tst_QHttpSocketEngine::passwordAuth()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp
index 4e9a880..1dd223f 100644
--- a/tests/auto/qicon/tst_qicon.cpp
+++ b/tests/auto/qicon/tst_qicon.cpp
@@ -72,6 +72,8 @@ private slots:
void svg();
void addFile();
void availableSizes();
+ void streamAvailableSizes_data();
+ void streamAvailableSizes();
void task184901_badCache();
void task223279_inconsistentAddFile();
@@ -540,6 +542,47 @@ void tst_QIcon::availableSizes()
}
}
+void tst_QIcon::streamAvailableSizes_data()
+{
+ QTest::addColumn<QIcon>("icon");
+
+ QIcon icon;
+ icon.addFile(":/image.png", QSize(32,32));
+ QTest::newRow( "32x32" ) << icon;
+ icon.addFile(":/image.png", QSize(64,64));
+ QTest::newRow( "64x64" ) << icon;
+ icon.addFile(":/image.png", QSize(128,128));
+ QTest::newRow( "128x128" ) << icon;
+ icon.addFile(":/image.png", QSize(256,256));
+ QTest::newRow( "256x256" ) << icon;
+}
+
+void tst_QIcon::streamAvailableSizes()
+{
+ QFETCH(QIcon, icon);
+
+ QByteArray ba;
+ // write to QByteArray
+ {
+ QBuffer buffer(&ba);
+ buffer.open(QIODevice::WriteOnly);
+ QDataStream stream(&buffer);
+ stream << icon;
+ }
+
+ // read from QByteArray
+ {
+ QBuffer buffer(&ba);
+ buffer.open(QIODevice::ReadOnly);
+ QDataStream stream(&buffer);
+ QIcon i;
+ stream >> i;
+ QCOMPARE(i.isNull(), icon.isNull());
+ QCOMPARE(i.availableSizes(), icon.availableSizes());
+ }
+}
+
+
static inline bool operator<(const QSize &lhs, const QSize &rhs)
{
if (lhs.width() < rhs.width())
diff --git a/tests/auto/qimage/images/image.tif b/tests/auto/qimage/images/image.tif
new file mode 100644
index 0000000..ee0637c
--- /dev/null
+++ b/tests/auto/qimage/images/image.tif
Binary files differ
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp
index ee4ece2..b7199f3 100644
--- a/tests/auto/qimage/tst_qimage.cpp
+++ b/tests/auto/qimage/tst_qimage.cpp
@@ -131,6 +131,8 @@ private slots:
void nullSize();
void premultipliedAlphaConsistency();
+
+ void compareIndexed();
};
tst_QImage::tst_QImage()
@@ -274,6 +276,9 @@ void tst_QImage::formatHandlersInput_data()
QTest::newRow("PPM") << "PPM" << prefix + "image.ppm";
QTest::newRow("XBM") << "XBM" << prefix + "image.xbm";
QTest::newRow("XPM") << "XPM" << prefix + "image.xpm";
+#if defined QTEST_HAVE_TIFF
+ QTest::newRow("TIFF") << "TIFF" << prefix + "image.tif";
+#endif
}
void tst_QImage::formatHandlersInput()
@@ -1454,9 +1459,9 @@ void tst_QImage::smoothScale3()
QRgb cb = b.pixel(x, y);
// tolerate a little bit of rounding errors
- QVERIFY(compare(qRed(ca), qRed(cb), 2));
- QVERIFY(compare(qGreen(ca), qGreen(cb), 2));
- QVERIFY(compare(qBlue(ca), qBlue(cb), 2));
+ QVERIFY(compare(qRed(ca), qRed(cb), 3));
+ QVERIFY(compare(qGreen(ca), qGreen(cb), 3));
+ QVERIFY(compare(qBlue(ca), qBlue(cb), 3));
}
}
}
@@ -1759,5 +1764,31 @@ void tst_QImage::premultipliedAlphaConsistency()
}
}
+void tst_QImage::compareIndexed()
+{
+ QImage img(256, 1, QImage::Format_Indexed8);
+
+ QVector<QRgb> colorTable(256);
+ for (int i = 0; i < 256; ++i)
+ colorTable[i] = qRgb(i, i, i);
+ img.setColorTable(colorTable);
+
+ for (int i = 0; i < 256; ++i) {
+ img.setPixel(i, 0, i);
+ }
+
+ QImage imgInverted(256, 1, QImage::Format_Indexed8);
+ QVector<QRgb> invertedColorTable(256);
+ for (int i = 0; i < 256; ++i)
+ invertedColorTable[255-i] = qRgb(i, i, i);
+ imgInverted.setColorTable(invertedColorTable);
+
+ for (int i = 0; i < 256; ++i) {
+ imgInverted.setPixel(i, 0, (255-i));
+ }
+
+ QCOMPARE(img, imgInverted);
+}
+
QTEST_MAIN(tst_QImage)
#include "tst_qimage.moc"
diff --git a/tests/auto/qimagereader/images/image_100dpi.tif b/tests/auto/qimagereader/images/image_100dpi.tif
new file mode 100644
index 0000000..fcf3cd8
--- /dev/null
+++ b/tests/auto/qimagereader/images/image_100dpi.tif
Binary files differ
diff --git a/tests/auto/qimagereader/qimagereader.pro b/tests/auto/qimagereader/qimagereader.pro
index b178823..2c9510e 100644
--- a/tests/auto/qimagereader/qimagereader.pro
+++ b/tests/auto/qimagereader/qimagereader.pro
@@ -3,6 +3,7 @@ SOURCES += tst_qimagereader.cpp
MOC_DIR=tmp
QT += network
RESOURCES += qimagereader.qrc
+DEFINES += SRCDIR=\\\"$$PWD\\\"
!contains(QT_CONFIG, no-gif):DEFINES += QTEST_HAVE_GIF
!contains(QT_CONFIG, no-jpeg):DEFINES += QTEST_HAVE_JPEG
@@ -22,5 +23,6 @@ wince*: {
imagePlugins.path = imageformats
DEPLOYMENT += images imagePlugins
+ DEFINES += SRCDIR=\\\".\\\"
}
diff --git a/tests/auto/qimagereader/qimagereader.qrc b/tests/auto/qimagereader/qimagereader.qrc
index 13ce582..3c674ad 100644
--- a/tests/auto/qimagereader/qimagereader.qrc
+++ b/tests/auto/qimagereader/qimagereader.qrc
@@ -30,6 +30,7 @@
<file>images/image.pgm</file>
<file>images/image.png</file>
<file>images/image.ppm</file>
+ <file>images/image.tif</file>
<file>images/kollada.png</file>
<file>images/marble.xpm</file>
<file>images/namedcolors.xpm</file>
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp
index 8f7094c..f5313eb 100644
--- a/tests/auto/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/qimagereader/tst_qimagereader.cpp
@@ -158,6 +158,8 @@ private slots:
void pixelCompareWithBaseline();
};
+static const QLatin1String prefix(SRCDIR "/images/");
+
// Testing get/set functions
void tst_QImageReader::getSetCheck()
{
@@ -232,7 +234,7 @@ void tst_QImageReader::readImage()
QFETCH(QByteArray, format);
for (int i = 0; i < 2; ++i) {
- QImageReader io("images/" + fileName, i ? QByteArray() : format);
+ QImageReader io(prefix + fileName, i ? QByteArray() : format);
if (success) {
if (!io.supportsAnimation())
QVERIFY(io.imageCount() > 0);
@@ -248,16 +250,16 @@ void tst_QImageReader::readImage()
QVERIFY2(!image.isNull(), io.errorString().toLatin1().constData());
// No format
- QImageReader io2("images/" + fileName);
+ QImageReader io2(prefix + fileName);
QVERIFY2(!io2.read().isNull(), io.errorString().toLatin1().constData());
// No extension, no format
- QImageReader io3("images/" + fileName.left(fileName.lastIndexOf(QLatin1Char('.'))));
+ QImageReader io3(prefix + fileName.left(fileName.lastIndexOf(QLatin1Char('.'))));
QVERIFY2(!io3.read().isNull(), io.errorString().toLatin1().constData());
// Read into \a image2
QImage image2;
- QImageReader image2Reader("images/" + fileName, i ? QByteArray() : format);
+ QImageReader image2Reader(prefix + fileName, i ? QByteArray() : format);
QCOMPARE(image2Reader.format(), format);
QVERIFY(image2Reader.read(&image2));
if (image2Reader.canRead()) {
@@ -281,8 +283,8 @@ void tst_QImageReader::readImage()
void tst_QImageReader::jpegRgbCmyk()
{
- QImage image1(QLatin1String("images/YCbCr_cmyk.jpg"));
- QImage image2(QLatin1String("images/YCbCr_cmyk.png"));
+ QImage image1(prefix + QLatin1String("YCbCr_cmyk.jpg"));
+ QImage image2(prefix + QLatin1String("YCbCr_cmyk.png"));
QCOMPARE(image1, image2);
}
@@ -293,24 +295,24 @@ void tst_QImageReader::setScaledSize_data()
QTest::addColumn<QSize>("newSize");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("BMP: colorful") << "images/colorful" << QSize(200, 200) << QByteArray("bmp");
- QTest::newRow("BMP: font") << "images/font" << QSize(200, 200) << QByteArray("bmp");
- QTest::newRow("XPM: marble") << "images/marble" << QSize(200, 200) << QByteArray("xpm");
- QTest::newRow("PNG: kollada") << "images/kollada" << QSize(200, 200) << QByteArray("png");
- QTest::newRow("PPM: teapot") << "images/teapot" << QSize(200, 200) << QByteArray("ppm");
- QTest::newRow("PPM: runners") << "images/runners.ppm" << QSize(400, 400) << QByteArray("ppm");
- QTest::newRow("PPM: test") << "images/test.ppm" << QSize(10, 10) << QByteArray("ppm");
- QTest::newRow("XBM: gnus") << "images/gnus" << QSize(200, 200) << QByteArray("xbm");
+ QTest::newRow("BMP: colorful") << "colorful" << QSize(200, 200) << QByteArray("bmp");
+ QTest::newRow("BMP: font") << "font" << QSize(200, 200) << QByteArray("bmp");
+ QTest::newRow("XPM: marble") << "marble" << QSize(200, 200) << QByteArray("xpm");
+ QTest::newRow("PNG: kollada") << "kollada" << QSize(200, 200) << QByteArray("png");
+ QTest::newRow("PPM: teapot") << "teapot" << QSize(200, 200) << QByteArray("ppm");
+ QTest::newRow("PPM: runners") << "runners.ppm" << QSize(400, 400) << QByteArray("ppm");
+ QTest::newRow("PPM: test") << "test.ppm" << QSize(10, 10) << QByteArray("ppm");
+ QTest::newRow("XBM: gnus") << "gnus" << QSize(200, 200) << QByteArray("xbm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("JPEG: beavis") << "images/beavis" << QSize(200, 200) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis") << "beavis" << QSize(200, 200) << QByteArray("jpeg");
#endif // QTEST_HAVE_JPEG
#ifdef QTEST_HAVE_GIF
- QTest::newRow("GIF: earth") << "images/earth" << QSize(200, 200) << QByteArray("gif");
- QTest::newRow("GIF: trolltech") << "images/trolltech" << QSize(200, 200) << QByteArray("gif");
+ QTest::newRow("GIF: earth") << "earth" << QSize(200, 200) << QByteArray("gif");
+ QTest::newRow("GIF: trolltech") << "trolltech" << QSize(200, 200) << QByteArray("gif");
#endif // QTEST_HAVE_GIF
#ifdef QTEST_HAVE_MNG
- QTest::newRow("MNG: ball") << "images/ball" << QSize(200, 200) << QByteArray("mng");
- QTest::newRow("MNG: fire") << "images/fire" << QSize(200, 200) << QByteArray("mng");
+ QTest::newRow("MNG: ball") << "ball" << QSize(200, 200) << QByteArray("mng");
+ QTest::newRow("MNG: fire") << "fire" << QSize(200, 200) << QByteArray("mng");
#endif // QTEST_HAVE_MNG
}
@@ -323,7 +325,7 @@ void tst_QImageReader::setScaledSize()
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format))
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle);
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
reader.setScaledSize(newSize);
QImage image = reader.read();
QVERIFY(!image.isNull());
@@ -336,25 +338,25 @@ void tst_QImageReader::setClipRect_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<QRect>("newRect");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("BMP: colorful") << "images/colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: font") << "images/font" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: 4bpp uncompressed") << "images/tst7.bmp" << QRect(0, 0, 31, 31) << QByteArray("bmp");
- QTest::newRow("XPM: marble") << "images/marble" << QRect(0, 0, 50, 50) << QByteArray("xpm");
- QTest::newRow("PNG: kollada") << "images/kollada" << QRect(0, 0, 50, 50) << QByteArray("png");
- QTest::newRow("PPM: teapot") << "images/teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: runners") << "images/runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: test") << "images/test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("XBM: gnus") << "images/gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm");
+ QTest::newRow("BMP: colorful") << "colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: font") << "font" << QRect(0, 0, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: 4bpp uncompressed") << "tst7.bmp" << QRect(0, 0, 31, 31) << QByteArray("bmp");
+ QTest::newRow("XPM: marble") << "marble" << QRect(0, 0, 50, 50) << QByteArray("xpm");
+ QTest::newRow("PNG: kollada") << "kollada" << QRect(0, 0, 50, 50) << QByteArray("png");
+ QTest::newRow("PPM: teapot") << "teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: runners") << "runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: test") << "test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("XBM: gnus") << "gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("JPEG: beavis") << "images/beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis") << "beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg");
#endif // QTEST_HAVE_JPEG
#ifdef QTEST_HAVE_GIF
- QTest::newRow("GIF: earth") << "images/earth" << QRect(0, 0, 50, 50) << QByteArray("gif");
- QTest::newRow("GIF: trolltech") << "images/trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: earth") << "earth" << QRect(0, 0, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: trolltech") << "trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif");
#endif // QTEST_HAVE_GIF
#ifdef QTEST_HAVE_MNG
- QTest::newRow("MNG: ball") << "images/ball" << QRect(0, 0, 50, 50) << QByteArray("mng");
- QTest::newRow("MNG: fire") << "images/fire" << QRect(0, 0, 50, 50) << QByteArray("mng");
+ QTest::newRow("MNG: ball") << "ball" << QRect(0, 0, 50, 50) << QByteArray("mng");
+ QTest::newRow("MNG: fire") << "fire" << QRect(0, 0, 50, 50) << QByteArray("mng");
#endif // QTEST_HAVE_MNG
}
@@ -367,13 +369,13 @@ void tst_QImageReader::setClipRect()
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format))
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle);
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
reader.setClipRect(newRect);
QImage image = reader.read();
QVERIFY(!image.isNull());
QCOMPARE(image.rect(), newRect);
- QImageReader originalReader(fileName);
+ QImageReader originalReader(prefix + fileName);
QImage originalImage = originalReader.read();
QCOMPARE(originalImage.copy(newRect), image);
}
@@ -384,24 +386,24 @@ void tst_QImageReader::setScaledClipRect_data()
QTest::addColumn<QRect>("newRect");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("BMP: colorful") << "images/colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("BMP: font") << "images/font" << QRect(0, 0, 50, 50) << QByteArray("bmp");
- QTest::newRow("XPM: marble") << "images/marble" << QRect(0, 0, 50, 50) << QByteArray("xpm");
- QTest::newRow("PNG: kollada") << "images/kollada" << QRect(0, 0, 50, 50) << QByteArray("png");
- QTest::newRow("PPM: teapot") << "images/teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: runners") << "images/runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("PPM: test") << "images/test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
- QTest::newRow("XBM: gnus") << "images/gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm");
+ QTest::newRow("BMP: colorful") << "colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp");
+ QTest::newRow("BMP: font") << "font" << QRect(0, 0, 50, 50) << QByteArray("bmp");
+ QTest::newRow("XPM: marble") << "marble" << QRect(0, 0, 50, 50) << QByteArray("xpm");
+ QTest::newRow("PNG: kollada") << "kollada" << QRect(0, 0, 50, 50) << QByteArray("png");
+ QTest::newRow("PPM: teapot") << "teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: runners") << "runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("PPM: test") << "test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm");
+ QTest::newRow("XBM: gnus") << "gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("JPEG: beavis") << "images/beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg");
+ QTest::newRow("JPEG: beavis") << "beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg");
#endif // QTEST_HAVE_JPEG
#ifdef QTEST_HAVE_GIF
- QTest::newRow("GIF: earth") << "images/earth" << QRect(0, 0, 50, 50) << QByteArray("gif");
- QTest::newRow("GIF: trolltech") << "images/trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: earth") << "earth" << QRect(0, 0, 50, 50) << QByteArray("gif");
+ QTest::newRow("GIF: trolltech") << "trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif");
#endif // QTEST_HAVE_GIF
#ifdef QTEST_HAVE_MNG
- QTest::newRow("MNG: ball") << "images/ball" << QRect(0, 0, 50, 50) << QByteArray("mng");
- QTest::newRow("MNG: fire") << "images/fire" << QRect(0, 0, 50, 50) << QByteArray("mng");
+ QTest::newRow("MNG: ball") << "ball" << QRect(0, 0, 50, 50) << QByteArray("mng");
+ QTest::newRow("MNG: fire") << "fire" << QRect(0, 0, 50, 50) << QByteArray("mng");
#endif // QTEST_HAVE_MNG
}
@@ -414,14 +416,14 @@ void tst_QImageReader::setScaledClipRect()
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format))
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle);
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
reader.setScaledSize(QSize(300, 300));
reader.setScaledClipRect(newRect);
QImage image = reader.read();
QVERIFY(!image.isNull());
QCOMPARE(image.rect(), newRect);
- QImageReader originalReader(fileName);
+ QImageReader originalReader(prefix + fileName);
originalReader.setScaledSize(QSize(300, 300));
QImage originalImage = originalReader.read();
QCOMPARE(originalImage.copy(newRect), image);
@@ -433,29 +435,29 @@ void tst_QImageReader::imageFormat_data()
QTest::addColumn<QByteArray>("format");
QTest::addColumn<QImage::Format>("imageFormat");
- QTest::newRow("pbm") << QString("images/image.pbm") << QByteArray("pbm") << QImage::Format_Mono;
- QTest::newRow("pgm") << QString("images/image.pgm") << QByteArray("pgm") << QImage::Format_Indexed8;
- QTest::newRow("ppm-1") << QString("images/image.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
- QTest::newRow("ppm-2") << QString("images/teapot.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
- QTest::newRow("ppm-3") << QString("images/runners.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
- QTest::newRow("ppm-4") << QString("images/test.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
+ QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm") << QImage::Format_Mono;
+ QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm") << QImage::Format_Indexed8;
+ QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
+ QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
+ QTest::newRow("ppm-3") << QString("runners.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
+ QTest::newRow("ppm-4") << QString("test.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("jpeg-1") << QString("images/beavis.jpg") << QByteArray("jpeg") << QImage::Format_Indexed8;
- QTest::newRow("jpeg-2") << QString("images/YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
- QTest::newRow("jpeg-3") << QString("images/YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
+ QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Indexed8;
+ QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
+ QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
#endif
#if defined QTEST_HAVE_GIF
- QTest::newRow("gif-1") << QString("images/earth.gif") << QByteArray("gif") << QImage::Format_Invalid;
- QTest::newRow("gif-2") << QString("images/trolltech.gif") << QByteArray("gif") << QImage::Format_Invalid;
+ QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif") << QImage::Format_Invalid;
+ QTest::newRow("gif-2") << QString("trolltech.gif") << QByteArray("gif") << QImage::Format_Invalid;
#endif
- QTest::newRow("xbm") << QString("images/gnus.xbm") << QByteArray("xbm") << QImage::Format_MonoLSB;
- QTest::newRow("xpm") << QString("images/marble.xpm") << QByteArray("xpm") << QImage::Format_Indexed8;
- QTest::newRow("bmp-1") << QString("images/colorful.bmp") << QByteArray("bmp") << QImage::Format_Indexed8;
- QTest::newRow("bmp-2") << QString("images/font.bmp") << QByteArray("bmp") << QImage::Format_Indexed8;
- QTest::newRow("png") << QString("images/kollada.png") << QByteArray("png") << QImage::Format_ARGB32;
- QTest::newRow("png-2") << QString("images/YCbCr_cmyk.png") << QByteArray("png") << QImage::Format_RGB32;
- QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng") << QImage::Format_Invalid;
- QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng") << QImage::Format_Invalid;
+ QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm") << QImage::Format_MonoLSB;
+ QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm") << QImage::Format_Indexed8;
+ QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp") << QImage::Format_Indexed8;
+ QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp") << QImage::Format_Indexed8;
+ QTest::newRow("png") << QString("kollada.png") << QByteArray("png") << QImage::Format_ARGB32;
+ QTest::newRow("png-2") << QString("YCbCr_cmyk.png") << QByteArray("png") << QImage::Format_RGB32;
+ QTest::newRow("mng-1") << QString("ball.mng") << QByteArray("mng") << QImage::Format_Invalid;
+ QTest::newRow("mng-2") << QString("fire.mng") << QByteArray("mng") << QImage::Format_Invalid;
}
void tst_QImageReader::imageFormat()
@@ -463,7 +465,8 @@ void tst_QImageReader::imageFormat()
QFETCH(QString, fileName);
QFETCH(QByteArray, format);
QFETCH(QImage::Format, imageFormat);
- if (QImageReader::imageFormat(fileName).isEmpty()) {
+
+ if (QImageReader::imageFormat(prefix + fileName).isEmpty()) {
if (QByteArray("jpeg") == format)
#ifndef QTEST_HAVE_JPEG
return;
@@ -478,31 +481,31 @@ void tst_QImageReader::imageFormat()
#endif // !QTEST_HAVE_MNG
QSKIP(("Qt does not support the " + format + " format.").constData(), SkipSingle);
} else {
- QCOMPARE(QImageReader::imageFormat(fileName), format);
+ QCOMPARE(QImageReader::imageFormat(prefix + fileName), format);
}
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
QCOMPARE(reader.imageFormat(), imageFormat);
}
void tst_QImageReader::blackXPM()
{
- QImage image(QLatin1String("images/black.xpm"));
- QImage image2(QLatin1String("images/black.png"));
+ QImage image(prefix + QLatin1String("black.xpm"));
+ QImage image2(prefix + QLatin1String("black.png"));
QCOMPARE(image.pixel(25, 25), qRgb(190, 190, 190));
QCOMPARE(image.pixel(25, 25), image2.pixel(25, 25));
}
void tst_QImageReader::transparentXPM()
{
- QImage image(QLatin1String("images/nontransparent.xpm"));
- QImage image2(QLatin1String("images/transparent.xpm"));
+ QImage image(prefix + QLatin1String("nontransparent.xpm"));
+ QImage image2(prefix + QLatin1String("transparent.xpm"));
QCOMPARE(image.format(), QImage::Format_RGB32);
QCOMPARE(image2.format(), QImage::Format_ARGB32);
}
void tst_QImageReader::multiWordNamedColorXPM()
{
- QImage image(QLatin1String("images/namedcolors.xpm"));
+ QImage image(prefix + QLatin1String("namedcolors.xpm"));
QCOMPARE(image.pixel(0, 0), qRgb(102, 139, 139)); // pale turquoise 4
QCOMPARE(image.pixel(0, 1), qRgb(250, 250, 210)); // light golden rod yellow
QCOMPARE(image.pixel(0, 2), qRgb(255, 250, 205)); // lemon chiffon
@@ -593,7 +596,7 @@ void tst_QImageReader::supportsAnimation()
{
QFETCH(QString, fileName);
QFETCH(bool, success);
- QImageReader io("images/" + fileName);
+ QImageReader io(prefix + fileName);
QCOMPARE(io.supportsAnimation(), success);
}
@@ -606,7 +609,7 @@ void tst_QImageReader::sizeBeforeRead()
{
QFETCH(QString, fileName);
QFETCH(QByteArray, format);
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
QVERIFY(reader.canRead());
if (format == "mng") {
QCOMPARE(reader.size(), QSize());
@@ -644,7 +647,7 @@ void tst_QImageReader::imageFormatBeforeRead()
void tst_QImageReader::gifHandlerBugs()
{
{
- QImageReader io("images/trolltech.gif");
+ QImageReader io(prefix + "trolltech.gif");
QVERIFY(io.loopCount() != 1);
int count=0;
for (; io.canRead(); io.read(), ++count) ;
@@ -653,8 +656,8 @@ void tst_QImageReader::gifHandlerBugs()
// Task 95166
{
- QImageReader io1("images/bat1.gif");
- QImageReader io2("images/bat2.gif");
+ QImageReader io1(prefix + "bat1.gif");
+ QImageReader io2(prefix + "bat2.gif");
QVERIFY(io1.canRead());
QVERIFY(io2.canRead());
QImage im1 = io1.read();
@@ -666,8 +669,8 @@ void tst_QImageReader::gifHandlerBugs()
// Task 9994
{
- QImageReader io1("images/noclearcode.gif");
- QImageReader io2("images/noclearcode.bmp");
+ QImageReader io1(prefix + "noclearcode.gif");
+ QImageReader io2(prefix + "noclearcode.bmp");
QVERIFY(io1.canRead()); QVERIFY(io2.canRead());
QImage im1 = io1.read(); QImage im2 = io2.read();
QVERIFY(!im1.isNull()); QVERIFY(!im2.isNull());
@@ -731,29 +734,29 @@ void tst_QImageReader::readFromDevice_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("pbm") << QString("images/image.pbm") << QByteArray("pbm");
- QTest::newRow("pgm") << QString("images/image.pgm") << QByteArray("pgm");
- QTest::newRow("ppm-1") << QString("images/image.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-2") << QString("images/teapot.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-3") << QString("images/teapot.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-4") << QString("images/runners.ppm") << QByteArray("ppm");
+ QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm");
+ QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm");
+ QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-3") << QString("teapot.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-4") << QString("runners.ppm") << QByteArray("ppm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("jpeg-1") << QString("images/beavis.jpg") << QByteArray("jpeg");
- QTest::newRow("jpeg-2") << QString("images/YCbCr_cmyk.jpg") << QByteArray("jpeg");
- QTest::newRow("jpeg-3") << QString("images/YCbCr_rgb.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg");
#endif // QTEST_HAVE_JPEG
#ifdef QTEST_HAVE_GIF
- QTest::newRow("gif-1") << QString("images/earth.gif") << QByteArray("gif");
- QTest::newRow("gif-2") << QString("images/trolltech.gif") << QByteArray("gif");
+ QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif");
+ QTest::newRow("gif-2") << QString("trolltech.gif") << QByteArray("gif");
#endif // QTEST_HAVE_GIF
- QTest::newRow("xbm") << QString("images/gnus.xbm") << QByteArray("xbm");
- QTest::newRow("xpm") << QString("images/marble.xpm") << QByteArray("xpm");
- QTest::newRow("bmp-1") << QString("images/colorful.bmp") << QByteArray("bmp");
- QTest::newRow("bmp-2") << QString("images/font.bmp") << QByteArray("bmp");
- QTest::newRow("png") << QString("images/kollada.png") << QByteArray("png");
+ QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm");
+ QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm");
+ QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp");
+ QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp");
+ QTest::newRow("png") << QString("kollada.png") << QByteArray("png");
#ifdef QTEST_HAVE_MNG
- QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng");
- QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng");
+ QTest::newRow("mng-1") << QString("ball.mng") << QByteArray("mng");
+ QTest::newRow("mng-2") << QString("fire.mng") << QByteArray("mng");
#endif // QTEST_HAVE_MNG
}
@@ -762,9 +765,9 @@ void tst_QImageReader::readFromDevice()
QFETCH(QString, fileName);
QFETCH(QByteArray, format);
- QImage expectedImage(fileName, format);
+ QImage expectedImage(prefix + fileName, format);
- QFile file(fileName);
+ QFile file(prefix + fileName);
QVERIFY(file.open(QFile::ReadOnly));
QByteArray imageData = file.readAll();
QVERIFY(!imageData.isEmpty());
@@ -813,26 +816,26 @@ void tst_QImageReader::readFromFileAfterJunk_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<QByteArray>("format");
- QTest::newRow("pbm") << QString("images/image.pbm") << QByteArray("pbm");
- QTest::newRow("pgm") << QString("images/image.pgm") << QByteArray("pgm");
- QTest::newRow("ppm-1") << QString("images/image.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-2") << QString("images/teapot.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-3") << QString("images/teapot.ppm") << QByteArray("ppm");
- QTest::newRow("ppm-4") << QString("images/runners.ppm") << QByteArray("ppm");
+ QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm");
+ QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm");
+ QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-3") << QString("teapot.ppm") << QByteArray("ppm");
+ QTest::newRow("ppm-4") << QString("runners.ppm") << QByteArray("ppm");
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("jpeg-1") << QString("images/beavis.jpg") << QByteArray("jpeg");
- QTest::newRow("jpeg-2") << QString("images/YCbCr_cmyk.jpg") << QByteArray("jpeg");
- QTest::newRow("jpeg-3") << QString("images/YCbCr_rgb.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg");
+ QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg");
#endif
#if defined QTEST_HAVE_GIF
// QTest::newRow("gif-1") << QString("images/earth.gif") << QByteArray("gif");
// QTest::newRow("gif-2") << QString("images/trolltech.gif") << QByteArray("gif");
#endif
- QTest::newRow("xbm") << QString("images/gnus.xbm") << QByteArray("xbm");
- QTest::newRow("xpm") << QString("images/marble.xpm") << QByteArray("xpm");
- QTest::newRow("bmp-1") << QString("images/colorful.bmp") << QByteArray("bmp");
- QTest::newRow("bmp-2") << QString("images/font.bmp") << QByteArray("bmp");
- QTest::newRow("png") << QString("images/kollada.png") << QByteArray("png");
+ QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm");
+ QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm");
+ QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp");
+ QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp");
+ QTest::newRow("png") << QString("kollada.png") << QByteArray("png");
// QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng");
// QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng");
}
@@ -851,7 +854,7 @@ void tst_QImageReader::readFromFileAfterJunk()
QFile junkFile("junk");
QVERIFY(junkFile.open(QFile::WriteOnly));
- QFile imageFile(fileName);
+ QFile imageFile(prefix + fileName);
QVERIFY(imageFile.open(QFile::ReadOnly));
QByteArray imageData = imageFile.readAll();
QVERIFY(!imageData.isNull());
@@ -869,7 +872,7 @@ void tst_QImageReader::readFromFileAfterJunk()
for (int i = 0; i < iterations; ++i) {
QImageWriter writer(&junkFile, format);
junkFile.write("deadbeef", 9);
- QVERIFY(writer.write(QImage(fileName)));
+ QVERIFY(writer.write(QImage(prefix + fileName)));
}
}
junkFile.close();
@@ -903,8 +906,8 @@ void tst_QImageReader::description_data()
willem["Software"] = "Created on a NeXTstation color using \"pnmtopng\".";
willem["Disclaimer"] = "Freeware.";
- QTest::newRow("PNG") << QString("images/pngwithtext.png") << willem;
- QTest::newRow("PNG Compressed") << QString("images/pngwithcompressedtext.png") << willem;
+ QTest::newRow("PNG") << QString("pngwithtext.png") << willem;
+ QTest::newRow("PNG Compressed") << QString("pngwithcompressedtext.png") << willem;
}
void tst_QImageReader::description()
@@ -913,9 +916,9 @@ void tst_QImageReader::description()
QFETCH(QStringMap, description);
// Sanity check
- QVERIFY(!QImage(fileName).isNull());
+ QVERIFY(!QImage(prefix + fileName).isNull());
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
foreach (QString key, description.keys())
QCOMPARE(reader.text(key), description.value(key));
@@ -940,143 +943,143 @@ void tst_QImageReader::readFromResources_data()
QTest::addColumn<QSize>("size");
QTest::addColumn<QString>("message");
- QTest::newRow("images/corrupt.bmp") << QString("images/corrupt.bmp")
+ QTest::newRow("corrupt.bmp") << QString("corrupt.bmp")
<< QByteArray("bmp") << QSize(0, 0)
<< QString("");
- QTest::newRow("images/negativeheight.bmp") << QString("images/negativeheight.bmp")
+ QTest::newRow("negativeheight.bmp") << QString("negativeheight.bmp")
<< QByteArray("bmp") << QSize(127, 64)
<< QString("");
- QTest::newRow("images/font.bmp") << QString("images/font.bmp")
+ QTest::newRow("font.bmp") << QString("font.bmp")
<< QByteArray("bmp") << QSize(240, 8)
<< QString("");
- QTest::newRow("images/noclearcode.bmp") << QString("images/noclearcode.bmp")
+ QTest::newRow("noclearcode.bmp") << QString("noclearcode.bmp")
<< QByteArray("bmp") << QSize(29, 18)
<< QString("");
- QTest::newRow("images/colorful.bmp") << QString("images/colorful.bmp")
+ QTest::newRow("colorful.bmp") << QString("colorful.bmp")
<< QByteArray("bmp") << QSize(320, 200)
<< QString("");
- QTest::newRow("images/16bpp.bmp") << QString("images/16bpp.bmp")
+ QTest::newRow("16bpp.bmp") << QString("16bpp.bmp")
<< QByteArray("bmp") << QSize(320, 240)
<< QString("");
- QTest::newRow("images/crash-signed-char.bmp") << QString("images/crash-signed-char.bmp")
+ QTest::newRow("crash-signed-char.bmp") << QString("crash-signed-char.bmp")
<< QByteArray("bmp") << QSize(360, 280)
<< QString("");
- QTest::newRow("images/4bpp-rle.bmp") << QString("images/4bpp-rle.bmp")
+ QTest::newRow("4bpp-rle.bmp") << QString("4bpp-rle.bmp")
<< QByteArray("bmp") << QSize(640, 480)
<< QString("");
#ifdef QTEST_HAVE_GIF
- QTest::newRow("images/corrupt.gif") << QString("images/corrupt.gif")
+ QTest::newRow("corrupt.gif") << QString("corrupt.gif")
<< QByteArray("gif") << QSize(0, 0)
<< QString("");
- QTest::newRow("images/trolltech.gif") << QString("images/trolltech.gif")
+ QTest::newRow("trolltech.gif") << QString("trolltech.gif")
<< QByteArray("gif") << QSize(128, 64)
<< QString("");
- QTest::newRow("images/noclearcode.gif") << QString("images/noclearcode.gif")
+ QTest::newRow("noclearcode.gif") << QString("noclearcode.gif")
<< QByteArray("gif") << QSize(29, 18)
<< QString("");
- QTest::newRow("images/earth.gif") << QString("images/earth.gif")
+ QTest::newRow("earth.gif") << QString("earth.gif")
<< QByteArray("gif") << QSize(320, 200)
<< QString("");
- QTest::newRow("images/bat1.gif") << QString("images/bat1.gif")
+ QTest::newRow("bat1.gif") << QString("bat1.gif")
<< QByteArray("gif") << QSize(32, 32)
<< QString("");
- QTest::newRow("images/bat2.gif") << QString("images/bat2.gif")
+ QTest::newRow("bat2.gif") << QString("bat2.gif")
<< QByteArray("gif") << QSize(32, 32)
<< QString("");
#endif
#ifdef QTEST_HAVE_JPEG
- QTest::newRow("images/corrupt.jpg") << QString("images/corrupt.jpg")
+ QTest::newRow("corrupt.jpg") << QString("corrupt.jpg")
<< QByteArray("jpg") << QSize(0, 0)
<< QString("JPEG datastream contains no image");
- QTest::newRow("images/beavis.jpg") << QString("images/beavis.jpg")
+ QTest::newRow("beavis.jpg") << QString("beavis.jpg")
<< QByteArray("jpg") << QSize(350, 350)
<< QString("");
- QTest::newRow("images/YCbCr_cmyk.jpg") << QString("images/YCbCr_cmyk.jpg")
+ QTest::newRow("YCbCr_cmyk.jpg") << QString("YCbCr_cmyk.jpg")
<< QByteArray("jpg") << QSize(75, 50)
<< QString("");
- QTest::newRow("images/YCbCr_rgb.jpg") << QString("images/YCbCr_rgb.jpg")
+ QTest::newRow("YCbCr_rgb.jpg") << QString("YCbCr_rgb.jpg")
<< QByteArray("jpg") << QSize(75, 50)
<< QString("");
#endif
#ifdef QTEST_HAVE_MNG
- QTest::newRow("images/corrupt.mng") << QString("images/corrupt.mng")
+ QTest::newRow("corrupt.mng") << QString("corrupt.mng")
<< QByteArray("mng") << QSize(0, 0)
<< QString("MNG error 901: Application signalled I/O error; chunk IHDR; subcode 0:0");
- QTest::newRow("images/fire.mng") << QString("images/fire.mng")
+ QTest::newRow("fire.mng") << QString("fire.mng")
<< QByteArray("mng") << QSize(30, 60)
<< QString("");
- QTest::newRow("images/ball.mng") << QString("images/ball.mng")
+ QTest::newRow("ball.mng") << QString("ball.mng")
<< QByteArray("mng") << QSize(32, 32)
<< QString("");
#endif
- QTest::newRow("images/image.pbm") << QString("images/image.pbm")
+ QTest::newRow("image.pbm") << QString("image.pbm")
<< QByteArray("pbm") << QSize(16, 6)
<< QString("");
- QTest::newRow("images/image.pgm") << QString("images/image.pgm")
+ QTest::newRow("image.pgm") << QString("image.pgm")
<< QByteArray("pgm") << QSize(24, 7)
<< QString("");
- QTest::newRow("images/corrupt.png") << QString("images/corrupt.png")
+ QTest::newRow("corrupt.png") << QString("corrupt.png")
<< QByteArray("png") << QSize(0, 0)
<< QString("");
- QTest::newRow("images/away.png") << QString("images/away.png")
+ QTest::newRow("away.png") << QString("away.png")
<< QByteArray("png") << QSize(16, 16)
<< QString("");
- QTest::newRow("images/image.png") << QString("images/image.png")
+ QTest::newRow("image.png") << QString("image.png")
<< QByteArray("png") << QSize(22, 22)
<< QString("");
- QTest::newRow("images/pngwithcompressedtext.png") << QString("images/pngwithcompressedtext.png")
+ QTest::newRow("pngwithcompressedtext.png") << QString("pngwithcompressedtext.png")
<< QByteArray("png") << QSize(32, 32)
<< QString("");
- QTest::newRow("images/pngwithtext.png") << QString("images/pngwithtext.png")
+ QTest::newRow("pngwithtext.png") << QString("pngwithtext.png")
<< QByteArray("png") << QSize(32, 32)
<< QString("");
- QTest::newRow("images/kollada.png") << QString("images/kollada.png")
+ QTest::newRow("kollada.png") << QString("kollada.png")
<< QByteArray("png") << QSize(436, 160)
<< QString("");
- QTest::newRow("images/black.png") << QString("images/black.png")
+ QTest::newRow("black.png") << QString("black.png")
<< QByteArray("png") << QSize(48, 48)
<< QString("");
- QTest::newRow("images/YCbCr_cmyk.png") << QString("images/YCbCr_cmyk.png")
+ QTest::newRow("YCbCr_cmyk.png") << QString("YCbCr_cmyk.png")
<< QByteArray("png") << QSize(75, 50)
<< QString("");
- QTest::newRow("images/teapot.ppm") << QString("images/teapot.ppm")
+ QTest::newRow("teapot.ppm") << QString("teapot.ppm")
<< QByteArray("ppm") << QSize(256, 256)
<< QString("");
- QTest::newRow("images/image.ppm") << QString("images/image.ppm")
+ QTest::newRow("image.ppm") << QString("image.ppm")
<< QByteArray("ppm") << QSize(4, 4)
<< QString("");
- QTest::newRow("images/runners.ppm") << QString("images/runners.ppm")
+ QTest::newRow("runners.ppm") << QString("runners.ppm")
<< QByteArray("ppm") << QSize(400, 400)
<< QString("");
- QTest::newRow("images/test.ppm") << QString("images/test.ppm")
+ QTest::newRow("test.ppm") << QString("test.ppm")
<< QByteArray("ppm") << QSize(10, 10)
<< QString("");
-// QTest::newRow("images/corrupt.xbm") << QString("images/corrupt.xbm") << QByteArray("xbm") << QSize(0, 0);
- QTest::newRow("images/gnus.xbm") << QString("images/gnus.xbm")
+// QTest::newRow("corrupt.xbm") << QString("corrupt.xbm") << QByteArray("xbm") << QSize(0, 0);
+ QTest::newRow("gnus.xbm") << QString("gnus.xbm")
<< QByteArray("xbm") << QSize(271, 273)
<< QString("");
- QTest::newRow("images/corrupt-colors.xpm") << QString("images/corrupt-colors.xpm")
+ QTest::newRow("corrupt-colors.xpm") << QString("corrupt-colors.xpm")
<< QByteArray("xpm") << QSize(0, 0)
<< QString("QImage: XPM color specification is missing: bla9an.n#x");
- QTest::newRow("images/corrupt-pixels.xpm") << QString("images/corrupt-pixels.xpm")
+ QTest::newRow("corrupt-pixels.xpm") << QString("corrupt-pixels.xpm")
<< QByteArray("xpm") << QSize(0, 0)
<< QString("QImage: XPM pixels missing on image line 3");
- QTest::newRow("images/marble.xpm") << QString("images/marble.xpm")
+ QTest::newRow("marble.xpm") << QString("marble.xpm")
<< QByteArray("xpm") << QSize(240, 240)
<< QString("");
- QTest::newRow("images/test.xpm") << QString("images/test.xpm")
+ QTest::newRow("test.xpm") << QString("test.xpm")
<< QByteArray("xpm") << QSize(256, 256)
<< QString("");
- QTest::newRow("images/black.xpm") << QString("images/black.xpm")
+ QTest::newRow("black.xpm") << QString("black.xpm")
<< QByteArray("xpm") << QSize(48, 48)
<< QString("");
- QTest::newRow("images/namedcolors.xpm") << QString("images/namedcolors.xpm")
+ QTest::newRow("namedcolors.xpm") << QString("namedcolors.xpm")
<< QByteArray("xpm") << QSize(8, 8)
<< QString("");
- QTest::newRow("images/nontransparent.xpm") << QString("images/nontransparent.xpm")
+ QTest::newRow("nontransparent.xpm") << QString("nontransparent.xpm")
<< QByteArray("xpm") << QSize(8, 8)
<< QString("");
- QTest::newRow("images/transparent.xpm") << QString("images/transparent.xpm")
+ QTest::newRow("transparent.xpm") << QString("transparent.xpm")
<< QByteArray("xpm") << QSize(8, 8)
<< QString("");
}
@@ -1087,9 +1090,8 @@ void tst_QImageReader::readFromResources()
QFETCH(QByteArray, format);
QFETCH(QSize, size);
QFETCH(QString, message);
-
for (int i = 0; i < 2; ++i) {
- QString file = i ? (":/" + fileName) : fileName;
+ QString file = i ? (":/images/" + fileName) : (prefix + fileName);
{
// suppress warnings if we expect them
if (!message.isEmpty()) {
@@ -1153,7 +1155,7 @@ void tst_QImageReader::readFromResources()
QTest::ignoreMessage(QtWarningMsg, message.toLatin1());
QTest::ignoreMessage(QtWarningMsg, message.toLatin1());
}
- QCOMPARE(QImageReader(fileName).read(), QImageReader(":/" + fileName).read());
+ QCOMPARE(QImageReader(prefix + fileName).read(), QImageReader(":/images/" + fileName).read());
}
void tst_QImageReader::readCorruptImage_data()
@@ -1162,25 +1164,25 @@ void tst_QImageReader::readCorruptImage_data()
QTest::addColumn<bool>("shouldFail");
QTest::addColumn<QString>("message");
#if defined QTEST_HAVE_JPEG
- QTest::newRow("corrupt jpeg") << QString("images/corrupt.jpg") << true
+ QTest::newRow("corrupt jpeg") << QString("corrupt.jpg") << true
<< QString("JPEG datastream contains no image");
#endif
#if defined QTEST_HAVE_GIF
- QTest::newRow("corrupt gif") << QString("images/corrupt.gif") << true << QString("");
+ QTest::newRow("corrupt gif") << QString("corrupt.gif") << true << QString("");
#endif
#ifdef QTEST_HAVE_MNG
- QTest::newRow("corrupt mng") << QString("images/corrupt.mng") << true
+ QTest::newRow("corrupt mng") << QString("corrupt.mng") << true
<< QString("MNG error 901: Application signalled I/O error; chunk IHDR; subcode 0:0");
#endif
- QTest::newRow("corrupt png") << QString("images/corrupt.png") << true << QString("");
- QTest::newRow("corrupt bmp") << QString("images/corrupt.bmp") << true << QString("");
- QTest::newRow("corrupt xpm (colors)") << QString("images/corrupt-colors.xpm") << true
+ QTest::newRow("corrupt png") << QString("corrupt.png") << true << QString("");
+ QTest::newRow("corrupt bmp") << QString("corrupt.bmp") << true << QString("");
+ QTest::newRow("corrupt xpm (colors)") << QString("corrupt-colors.xpm") << true
<< QString("QImage: XPM color specification is missing: bla9an.n#x");
- QTest::newRow("corrupt xpm (pixels)") << QString("images/corrupt-pixels.xpm") << true
+ QTest::newRow("corrupt xpm (pixels)") << QString("corrupt-pixels.xpm") << true
<< QString("QImage: XPM pixels missing on image line 3");
- QTest::newRow("corrupt xbm") << QString("images/corrupt.xbm") << false << QString("");
+ QTest::newRow("corrupt xbm") << QString("corrupt.xbm") << false << QString("");
#if defined QTEST_HAVE_TIFF
- QTest::newRow("corrupt tiff") << QString("images/corrupt-data.tif") << true << QString("");
+ QTest::newRow("corrupt tiff") << QString("corrupt-data.tif") << true << QString("");
#endif
}
@@ -1189,16 +1191,17 @@ void tst_QImageReader::readCorruptImage()
QFETCH(QString, fileName);
QFETCH(bool, shouldFail);
QFETCH(QString, message);
+
if (!message.isEmpty())
QTest::ignoreMessage(QtWarningMsg, message.toLatin1());
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
QVERIFY(reader.canRead());
QCOMPARE(reader.read().isNull(), shouldFail);
}
void tst_QImageReader::readCorruptBmp()
{
- QCOMPARE(QImage("images/tst7.bmp").convertToFormat(QImage::Format_ARGB32_Premultiplied), QImage("images/tst7.png").convertToFormat(QImage::Format_ARGB32_Premultiplied));
+ QCOMPARE(QImage("tst7.bmp").convertToFormat(QImage::Format_ARGB32_Premultiplied), QImage("images/tst7.png").convertToFormat(QImage::Format_ARGB32_Premultiplied));
}
void tst_QImageReader::supportsOption_data()
@@ -1206,7 +1209,7 @@ void tst_QImageReader::supportsOption_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<QIntList>("options");
- QTest::newRow("png") << QString("images/black.png")
+ QTest::newRow("png") << QString("black.png")
<< (QIntList() << QImageIOHandler::Gamma
<< QImageIOHandler::Description
<< QImageIOHandler::Quality
@@ -1234,7 +1237,7 @@ void tst_QImageReader::supportsOption()
<< QImageIOHandler::Animation
<< QImageIOHandler::BackgroundColor;
- QImageReader reader(fileName);
+ QImageReader reader(prefix + fileName);
for (int i = 0; i < options.size(); ++i) {
QVERIFY(reader.supportsOption(QImageIOHandler::ImageOption(options.at(i))));
allOptions.remove(QImageIOHandler::ImageOption(options.at(i)));
@@ -1250,14 +1253,14 @@ void tst_QImageReader::tiffCompression_data()
QTest::addColumn<QString>("uncompressedFile");
QTest::addColumn<QString>("compressedFile");
- QTest::newRow("TIFF: adobedeflate") << "images/rgba_nocompression_littleendian.tif"
- << "images/rgba_adobedeflate_littleendian.tif";
- QTest::newRow("TIFF: lzw") << "images/rgba_nocompression_littleendian.tif"
- << "images/rgba_lzw_littleendian.tif";
- QTest::newRow("TIFF: packbits") << "images/rgba_nocompression_littleendian.tif"
- << "images/rgba_packbits_littleendian.tif";
- QTest::newRow("TIFF: zipdeflate") << "images/rgba_nocompression_littleendian.tif"
- << "images/rgba_zipdeflate_littleendian.tif";
+ QTest::newRow("TIFF: adobedeflate") << "rgba_nocompression_littleendian.tif"
+ << "rgba_adobedeflate_littleendian.tif";
+ QTest::newRow("TIFF: lzw") << "rgba_nocompression_littleendian.tif"
+ << "rgba_lzw_littleendian.tif";
+ QTest::newRow("TIFF: packbits") << "rgba_nocompression_littleendian.tif"
+ << "rgba_packbits_littleendian.tif";
+ QTest::newRow("TIFF: zipdeflate") << "rgba_nocompression_littleendian.tif"
+ << "rgba_zipdeflate_littleendian.tif";
}
void tst_QImageReader::tiffCompression()
@@ -1265,16 +1268,16 @@ void tst_QImageReader::tiffCompression()
QFETCH(QString, uncompressedFile);
QFETCH(QString, compressedFile);
- QImage uncompressedImage(uncompressedFile);
- QImage compressedImage(compressedFile);
+ QImage uncompressedImage(prefix + uncompressedFile);
+ QImage compressedImage(prefix + compressedFile);
QCOMPARE(uncompressedImage, compressedImage);
}
void tst_QImageReader::tiffEndianness()
{
- QImage littleEndian("images/rgba_nocompression_littleendian.tif");
- QImage bigEndian("images/rgba_nocompression_bigendian.tif");
+ QImage littleEndian(prefix + "rgba_nocompression_littleendian.tif");
+ QImage bigEndian(prefix + "rgba_nocompression_bigendian.tif");
QCOMPARE(littleEndian, bigEndian);
}
@@ -1286,8 +1289,10 @@ void tst_QImageReader::dotsPerMeter_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<int>("expectedDotsPerMeterX");
QTest::addColumn<int>("expectedDotsPerMeterY");
-
- QTest::newRow("TIFF: 72 dpi") << "images/rgba_nocompression_littleendian.tif" << qRound(72 * (100 / 2.54)) << qRound(72 * (100 / 2.54));
+#if defined QTEST_HAVE_TIFF
+ QTest::newRow("TIFF: 72 dpi") << ("rgba_nocompression_littleendian.tif") << qRound(72 * (100 / 2.54)) << qRound(72 * (100 / 2.54));
+ QTest::newRow("TIFF: 100 dpi") << ("image_100dpi.tif") << qRound(100 * (100 / 2.54)) << qRound(100 * (100 / 2.54));
+#endif
}
void tst_QImageReader::dotsPerMeter()
@@ -1296,7 +1301,7 @@ void tst_QImageReader::dotsPerMeter()
QFETCH(int, expectedDotsPerMeterX);
QFETCH(int, expectedDotsPerMeterY);
- QImage image(fileName);
+ QImage image(prefix + fileName);
QCOMPARE(image.dotsPerMeterX(), expectedDotsPerMeterX);
QCOMPARE(image.dotsPerMeterY(), expectedDotsPerMeterY);
@@ -1307,8 +1312,10 @@ void tst_QImageReader::physicalDpi_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<int>("expectedPhysicalDpiX");
QTest::addColumn<int>("expectedPhysicalDpiY");
-
- QTest::newRow("TIFF: 72 dpi") << "images/rgba_nocompression_littleendian.tif" << 72 << 72;
+#if defined QTEST_HAVE_TIFF
+ QTest::newRow("TIFF: 72 dpi") << "rgba_nocompression_littleendian.tif" << 72 << 72;
+ QTest::newRow("TIFF: 100 dpi") << "image_100dpi.tif" << 100 << 100;
+#endif
}
void tst_QImageReader::physicalDpi()
@@ -1317,7 +1324,7 @@ void tst_QImageReader::physicalDpi()
QFETCH(int, expectedPhysicalDpiX);
QFETCH(int, expectedPhysicalDpiY);
- QImage image(fileName);
+ QImage image(prefix + fileName);
QCOMPARE(image.physicalDpiX(), expectedPhysicalDpiX);
QCOMPARE(image.physicalDpiY(), expectedPhysicalDpiY);
@@ -1328,7 +1335,7 @@ void tst_QImageReader::autoDetectImageFormat()
// Assume PNG is supported :-)
{
// Disables file name extension probing
- QImageReader reader("images/kollada");
+ QImageReader reader(prefix + "kollada");
reader.setAutoDetectImageFormat(false);
QVERIFY(!reader.canRead());
QVERIFY(reader.read().isNull());
@@ -1338,7 +1345,7 @@ void tst_QImageReader::autoDetectImageFormat()
}
{
// Disables detection based on suffix
- QImageReader reader("images/kollada.png");
+ QImageReader reader(prefix + "kollada.png");
reader.setAutoDetectImageFormat(false);
QVERIFY(!reader.canRead());
QVERIFY(reader.read().isNull());
@@ -1348,7 +1355,7 @@ void tst_QImageReader::autoDetectImageFormat()
}
{
// Disables detection based on content
- QImageReader reader("images/kollada-noext");
+ QImageReader reader(prefix + "kollada-noext");
reader.setAutoDetectImageFormat(false);
QVERIFY(!reader.canRead());
QVERIFY(reader.read().isNull());
diff --git a/tests/auto/qimagewriter/tst_qimagewriter.cpp b/tests/auto/qimagewriter/tst_qimagewriter.cpp
index 878d398..349afa5 100644
--- a/tests/auto/qimagewriter/tst_qimagewriter.cpp
+++ b/tests/auto/qimagewriter/tst_qimagewriter.cpp
@@ -97,6 +97,9 @@ private slots:
void saveWithNoFormat_data();
void saveWithNoFormat();
+ void resolution_data();
+ void resolution();
+
void saveToTemporaryFile();
};
@@ -162,7 +165,7 @@ tst_QImageWriter::tst_QImageWriter()
tst_QImageWriter::~tst_QImageWriter()
{
- QDir dir("images");
+ QDir dir(prefix);
QStringList filesToDelete = dir.entryList(QStringList() << "gen-*" , QDir::NoDotAndDotDot | QDir::Files);
foreach( QString file, filesToDelete) {
QFile::remove(dir.absoluteFilePath(file));
@@ -442,13 +445,13 @@ void tst_QImageWriter::supportsOption_data()
QTest::addColumn<QString>("fileName");
QTest::addColumn<QIntList>("options");
- QTest::newRow("png") << QString(prefix + "gen-black.png")
+ QTest::newRow("png") << QString("gen-black.png")
<< (QIntList() << QImageIOHandler::Gamma
<< QImageIOHandler::Description
<< QImageIOHandler::Quality
<< QImageIOHandler::Size);
#if defined QTEST_HAVE_TIFF
- QTest::newRow("tiff") << QString("images/gen-black.tiff")
+ QTest::newRow("tiff") << QString("gen-black.tiff")
<< (QIntList() << QImageIOHandler::Size
<< QImageIOHandler::CompressionRatio);
#endif
@@ -475,7 +478,7 @@ void tst_QImageWriter::supportsOption()
<< QImageIOHandler::Animation
<< QImageIOHandler::BackgroundColor;
- QImageWriter writer(fileName);
+ QImageWriter writer(prefix + fileName);
for (int i = 0; i < options.size(); ++i) {
QVERIFY(writer.supportsOption(QImageIOHandler::ImageOption(options.at(i))));
allOptions.remove(QImageIOHandler::ImageOption(options.at(i)));
@@ -530,6 +533,39 @@ void tst_QImageWriter::saveWithNoFormat()
QVERIFY2(!outImage.isNull(), qPrintable(reader.errorString()));
}
+void tst_QImageWriter::resolution_data()
+{
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<int>("expectedDotsPerMeterX");
+ QTest::addColumn<int>("expectedDotsPerMeterY");
+#if defined QTEST_HAVE_TIFF
+ QTest::newRow("TIFF: 100 dpi") << ("image_100dpi.tif") << qRound(100 * (100 / 2.54)) << qRound(100 * (100 / 2.54));
+ QTest::newRow("TIFF: 50 dpi") << ("image_50dpi.tif") << qRound(50 * (100 / 2.54)) << qRound(50 * (100 / 2.54));
+ QTest::newRow("TIFF: 300 dot per meter") << ("image_300dpm.tif") << 300 << 300;
+#endif
+}
+
+void tst_QImageWriter::resolution()
+{
+ QFETCH(QString, filename);
+ QFETCH(int, expectedDotsPerMeterX);
+ QFETCH(int, expectedDotsPerMeterY);
+
+ QImage image(prefix + QLatin1String("colorful.bmp"));
+ image.setDotsPerMeterX(expectedDotsPerMeterX);
+ image.setDotsPerMeterY(expectedDotsPerMeterY);
+ const QString generatedFilepath = prefix + "gen-" + filename;
+ {
+ QImageWriter writer(generatedFilepath);
+ QVERIFY(writer.write(image));
+ }
+ QImageReader reader(generatedFilepath);
+ const QImage generatedImage = reader.read();
+
+ QCOMPARE(expectedDotsPerMeterX, generatedImage.dotsPerMeterX());
+ QCOMPARE(expectedDotsPerMeterY, generatedImage.dotsPerMeterY());
+}
+
void tst_QImageWriter::saveToTemporaryFile()
{
QImage image(prefix + "kollada.png");
diff --git a/tests/auto/qiodevice/tst_qiodevice.cpp b/tests/auto/qiodevice/tst_qiodevice.cpp
index 03a0665..367a2e0 100644
--- a/tests/auto/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/qiodevice/tst_qiodevice.cpp
@@ -120,7 +120,7 @@ void tst_QIODevice::constructing_QTcpSocket()
QVERIFY(!device->isOpen());
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected(5000));
QVERIFY(device->isOpen());
@@ -134,7 +134,7 @@ void tst_QIODevice::constructing_QTcpSocket()
QCOMPARE(socket.pos(), qlonglong(0));
socket.close();
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected(5000));
while (!device->canReadLine())
diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
index 27741e0..615ac01 100644
--- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
+++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp
@@ -59,6 +59,8 @@
#include <QItemDelegate>
#include <QAbstractItemDelegate>
+#include <QTextEdit>
+#include <QPlainTextEdit>
Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint)
@@ -226,6 +228,8 @@ private slots:
void decoration();
void editorEvent_data();
void editorEvent();
+ void enterKey_data();
+ void enterKey();
};
@@ -1048,6 +1052,80 @@ void tst_QItemDelegate::editorEvent()
QCOMPARE(index.data(Qt::CheckStateRole).toInt(), expectedCheckState);
}
+void tst_QItemDelegate::enterKey_data()
+{
+ QTest::addColumn<int>("widget");
+ QTest::addColumn<int>("key");
+ QTest::addColumn<bool>("expectedFocus");
+
+ QTest::newRow("lineedit enter") << 1 << int(Qt::Key_Enter) << false;
+ QTest::newRow("textedit enter") << 2 << int(Qt::Key_Enter) << true;
+ QTest::newRow("plaintextedit enter") << 3 << int(Qt::Key_Enter) << true;
+ QTest::newRow("plaintextedit return") << 3 << int(Qt::Key_Return) << true;
+ QTest::newRow("plaintextedit tab") << 3 << int(Qt::Key_Tab) << false;
+ QTest::newRow("lineedit tab") << 1 << int(Qt::Key_Tab) << false;
+}
+
+void tst_QItemDelegate::enterKey()
+{
+ QFETCH(int, widget);
+ QFETCH(int, key);
+ QFETCH(bool, expectedFocus);
+
+ QStandardItemModel model;
+ model.appendRow(new QStandardItem());
+
+ QListView view;
+ view.setModel(&model);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ view.setFocus();
+ QTest::qWait(30);
+
+ struct TestDelegate : public QItemDelegate
+ {
+ int widgetType;
+ virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/) const
+ {
+ QWidget *editor = 0;
+ switch(widgetType) {
+ case 1:
+ editor = new QLineEdit(parent);
+ break;
+ case 2:
+ editor = new QTextEdit(parent);
+ break;
+ case 3:
+ editor = new QPlainTextEdit(parent);
+ break;
+ }
+ editor->setObjectName(QString::fromLatin1("TheEditor"));
+ return editor;
+ }
+ } delegate;
+
+ delegate.widgetType = widget;
+
+ view.setItemDelegate(&delegate);
+ QModelIndex index = model.index(0, 0);
+ view.setCurrentIndex(index); // the editor will only selectAll on the current index
+ view.edit(index);
+ QTest::qWait(30);
+
+ QList<QWidget*> lineEditors = qFindChildren<QWidget *>(view.viewport(), QString::fromLatin1("TheEditor"));
+ QCOMPARE(lineEditors.count(), 1);
+
+ QWidget *editor = lineEditors.at(0);
+ QCOMPARE(editor->hasFocus(), true);
+
+ QTest::keyClick(editor, Qt::Key(key));
+ QApplication::processEvents();
+
+ QCOMPARE(editor->hasFocus(), expectedFocus);
+}
+
+
+
// ### _not_ covered:
// editing with a custom editor factory
diff --git a/tests/auto/qitemmodel/tst_qitemmodel.cpp b/tests/auto/qitemmodel/tst_qitemmodel.cpp
index ea1972e..d29a3e3 100644
--- a/tests/auto/qitemmodel/tst_qitemmodel.cpp
+++ b/tests/auto/qitemmodel/tst_qitemmodel.cpp
@@ -54,7 +54,7 @@
#include <QtTest/QtTest>
#include <QtCore>
#include <qdebug.h>
-#include <modelstotest.cpp>
+#include "modelstotest.cpp"
#include <QMetaType>
Q_DECLARE_METATYPE(QModelIndex)
diff --git a/tests/auto/qitemview/tst_qitemview.cpp b/tests/auto/qitemview/tst_qitemview.cpp
index 748bd50..3317c1d 100644
--- a/tests/auto/qitemview/tst_qitemview.cpp
+++ b/tests/auto/qitemview/tst_qitemview.cpp
@@ -42,7 +42,7 @@
#include <QtTest/QtTest>
#include <QtCore/QtCore>
-#include <viewstotest.cpp>
+#include "viewstotest.cpp"
#include <stdlib.h>
#if defined(Q_OS_WIN)
diff --git a/tests/auto/qmake/testcompiler.cpp b/tests/auto/qmake/testcompiler.cpp
index 122a2b8..7255d93 100644
--- a/tests/auto/qmake/testcompiler.cpp
+++ b/tests/auto/qmake/testcompiler.cpp
@@ -56,10 +56,8 @@ static QString targetName( BuildType buildMode, const QString& target, const QSt
targetName.append(".exe");
break;
case Dll: // dll
- if (version != "") {
- QStringList ver = QStringList::split(".", version);
- targetName.append(ver.first());
- }
+ if (!version.empty())
+ targetName.append(version.section(".", 0, 0));
targetName.append(".dll");
break;
case Lib: // lib
diff --git a/tests/auto/qmake/testdata/bundle-spaces/some-file b/tests/auto/qmake/testdata/bundle-spaces/some-file
index e69de29..9975dba 100644
--- a/tests/auto/qmake/testdata/bundle-spaces/some-file
+++ b/tests/auto/qmake/testdata/bundle-spaces/some-file
@@ -0,0 +1,6 @@
+all:
+ C:\git\qt-kinetic-animations\bin\qmake qdir.pro -o Makefile -spec win32-msvc2008
+ nmake -f Makefile
+first: all
+qmake:
+ C:\git\qt-kinetic-animations\bin\qmake qdir.pro -o Makefile -spec win32-msvc2008
diff --git a/tests/auto/qmake/tst_qmake.cpp b/tests/auto/qmake/tst_qmake.cpp
index 70f1f3c..1178c81 100644
--- a/tests/auto/qmake/tst_qmake.cpp
+++ b/tests/auto/qmake/tst_qmake.cpp
@@ -63,6 +63,7 @@ public slots:
private slots:
void simple_app();
+ void simple_app_shadowbuild();
void simple_lib();
void simple_dll();
void subdirs();
@@ -143,6 +144,21 @@ void tst_qmake::simple_app()
QVERIFY( test_compiler.removeMakefile( workDir ) );
}
+void tst_qmake::simple_app_shadowbuild()
+{
+ QString workDir = base_path + "/testdata/simple_app";
+ QString buildDir = base_path + "/testdata/simple_app_build";
+
+ QVERIFY( test_compiler.qmake( workDir, "simple_app", buildDir ));
+ QVERIFY( test_compiler.make( buildDir ));
+ QVERIFY( test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" ));
+ QVERIFY( test_compiler.makeClean( buildDir ));
+ QVERIFY( test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" )); // Should still exist after a make clean
+ QVERIFY( test_compiler.makeDistClean( buildDir ));
+ QVERIFY( !test_compiler.exists( buildDir, "simple_app", Exe, "1.0.0" )); // Should not exist after a make distclean
+ QVERIFY( test_compiler.removeMakefile( buildDir ) );
+}
+
void tst_qmake::simple_dll()
{
QString workDir = base_path + "/testdata/simple_dll";
diff --git a/tests/auto/qmap/tst_qmap.cpp b/tests/auto/qmap/tst_qmap.cpp
index 99efc80..68ac8d6 100644
--- a/tests/auto/qmap/tst_qmap.cpp
+++ b/tests/auto/qmap/tst_qmap.cpp
@@ -39,6 +39,7 @@
**
****************************************************************************/
+#define QT_STRICT_ITERATORS
#include <QtTest/QtTest>
#include <QDebug>
@@ -400,7 +401,7 @@ void tst_QMap::operator_eq()
QVERIFY(a == b);
QVERIFY(!(a != b));
-
+
a.insert(1,1);
b.insert(1,1);
QVERIFY(a == b);
@@ -422,7 +423,7 @@ void tst_QMap::operator_eq()
b.insert(-1, -1);
QVERIFY(a != b);
- QVERIFY(!(a == b));
+ QVERIFY(!(a == b));
}
{
@@ -468,7 +469,7 @@ void tst_QMap::operator_eq()
b.insert("willy", 1);
QVERIFY(a != b);
QVERIFY(!(a == b));
- }
+ }
}
void tst_QMap::empty()
@@ -523,9 +524,9 @@ void tst_QMap::find()
map1.insertMulti(4, compareString);
}
- QMap<int, QString>::const_iterator it=map1.find(4);
+ QMap<int, QString>::const_iterator it=map1.constFind(4);
- for(i = 9; i > 2 && it != map1.end() && it.key() == 4; --i) {
+ for(i = 9; i > 2 && it != map1.constEnd() && it.key() == 4; --i) {
compareString = testString.arg(i);
QVERIFY(it.value() == compareString);
++it;
@@ -546,9 +547,9 @@ void tst_QMap::constFind()
map1.insert(1,"Mensch");
map1.insert(1,"Mayer");
map1.insert(2,"Hej");
-
+
QVERIFY(map1.constFind(4) == map1.constEnd());
-
+
QVERIFY(map1.constFind(1).value() == "Mayer");
QVERIFY(map1.constFind(2).value() == "Hej");
@@ -677,7 +678,7 @@ void tst_QMap::iterators()
cstlIt--;
QVERIFY(cstlIt.value() == "Teststring 3");
- for(cstlIt = map.begin(), i = 1; cstlIt != map.constEnd(), i < 100; ++cstlIt, ++i)
+ for(cstlIt = map.constBegin(), i = 1; cstlIt != map.constEnd(), i < 100; ++cstlIt, ++i)
QVERIFY(cstlIt.value() == testString.arg(i));
//Java-Style iterators
diff --git a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
index 68ec414..90276f2 100644
--- a/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
+++ b/tests/auto/qnativesocketengine/tst_qnativesocketengine.cpp
@@ -100,8 +100,6 @@ private slots:
void receiveUrgentData();
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QNativeSocketEngine::tst_QNativeSocketEngine()
{
}
@@ -155,15 +153,14 @@ void tst_QNativeSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
QVERIFY(socketDevice.state() == QAbstractSocket::UnconnectedState);
- // Connect to imap.trolltech.com's IP
- bool connected = socketDevice.connectToHost(QHostAddress(IMAP_IP), 143);
- if (!connected) {
+ const bool isConnected = socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143);
+ if (!isConnected) {
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
}
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -176,7 +173,7 @@ void tst_QNativeSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
// Check that the greeting is what we expect it to be
- QCOMPARE(array.constData(), "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ QCOMPARE(array.constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "ZZZ LOGOUT\r\n";
@@ -580,9 +577,8 @@ void tst_QNativeSocketEngine::networkError()
QVERIFY(client.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
- // Connect to imap.trolltech.com's IP
- bool connected = client.connectToHost(QHostAddress(IMAP_IP), 143);
- if (!connected) {
+ const bool isConnected = client.connectToHost(QHostAddress(QtNetworkSettings::serverIP()), 143);
+ if (!isConnected) {
QVERIFY(client.state() == QAbstractSocket::ConnectingState);
QVERIFY(client.waitForWrite());
QVERIFY(client.state() == QAbstractSocket::ConnectedState);
diff --git a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
index fc15437..2383767 100644
--- a/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
+++ b/tests/auto/qnetworkdiskcache/tst_qnetworkdiskcache.cpp
@@ -389,7 +389,8 @@ void tst_QNetworkDiskCache::expire()
qint64 max = cache.maximumCacheSize();
QCOMPARE(max, limit);
for (int i = 0; i < 10; ++i) {
- QTest::qWait(2000);
+ if (i % 3 == 0)
+ QTest::qWait(2000);
QNetworkCacheMetaData m;
m.setUrl(QUrl("http://www.foo.com/" + QString::number(i)));
QIODevice *d = cache.prepare(m);
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 104b788..b76a4e6 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -52,6 +52,7 @@
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QLocalSocket>
#include <QtNetwork/QLocalServer>
+#include <QtNetwork/QHostInfo>
#include <QtNetwork/QFtp>
#include <QtNetwork/qauthenticator.h>
#include <QtNetwork/qnetworkaccessmanager.h>
@@ -91,6 +92,15 @@ class tst_QNetworkReply: public QObject
{
Q_OBJECT
+ struct ProxyData {
+ ProxyData(const QNetworkProxy &p, const QByteArray &t, bool auth)
+ : tag(t), proxy(p), requiresAuthentication(auth)
+ { }
+ QByteArray tag;
+ QNetworkProxy proxy;
+ bool requiresAuthentication;
+ };
+
QEventLoop *loop;
enum RunSimpleRequestReturn { Timeout = 0, Success, Failure };
int returnCode;
@@ -99,6 +109,7 @@ class tst_QNetworkReply: public QObject
QString wronlyFileName;
#endif
QString uniqueExtension;
+ QList<ProxyData> proxies;
QNetworkAccessManager manager;
MyCookieJar *cookieJar;
#ifndef QT_NO_OPENSSL
@@ -172,6 +183,8 @@ private Q_SLOTS:
void ioGetFromHttpsWithIgnoreSslErrors();
void ioGetFromHttpsWithSslHandshakeError();
#endif
+ void ioGetFromHttpBrokenServer_data();
+ void ioGetFromHttpBrokenServer();
void ioGetWithManyProxies_data();
void ioGetWithManyProxies();
@@ -190,11 +203,20 @@ private Q_SLOTS:
void ioPutToHttpFromFile();
void ioPostToHttpFromFile_data();
void ioPostToHttpFromFile();
+ void ioPostToHttpFromSocket_data();
+ void ioPostToHttpFromSocket();
+ void ioPostToHttpFromMiddleOfFileToEnd();
+ void ioPostToHttpFromMiddleOfFileFiveBytes();
+ void ioPostToHttpFromMiddleOfQBufferFiveBytes();
+ void ioPostToHttpNoBufferFlag();
+ void ioPostToHttpUploadProgress();
+ void ioPostToHttpEmtpyUploadProgress();
void rateControl_data();
void rateControl();
void downloadPerformance();
void uploadPerformance();
+ void httpUploadPerformance();
void performanceControlRate();
void downloadProgress_data();
@@ -215,6 +237,8 @@ private Q_SLOTS:
void httpProxyCommands_data();
void httpProxyCommands();
void proxyChange();
+ void authorizationError_data();
+ void authorizationError();
};
QT_BEGIN_NAMESPACE
@@ -364,6 +388,63 @@ public slots:
}
};
+class FixedSizeDataGenerator : public QIODevice
+{
+ Q_OBJECT
+ enum { Idle, Started, Stopped } state;
+public:
+ FixedSizeDataGenerator(qint64 size) : state(Idle)
+ { open(ReadOnly | Unbuffered);
+ toBeGeneratedTotalCount = toBeGeneratedCount = size;
+ }
+
+ virtual qint64 bytesAvailable() const
+ {
+ return state == Started ? toBeGeneratedCount + QIODevice::bytesAvailable() : 0;
+ }
+
+ virtual bool isSequential() const{
+ return false;
+ }
+
+ virtual bool reset() const{
+ return false;
+ }
+
+ qint64 size() const {
+ return toBeGeneratedTotalCount;
+ }
+
+public slots:
+ void start() { state = Started; emit readyRead(); }
+
+protected:
+ virtual qint64 readData(char *data, qint64 maxlen)
+ {
+ memset(data, '@', maxlen);
+
+ if (toBeGeneratedCount <= 0) {
+ return -1;
+ }
+
+ qint64 n = qMin(maxlen, toBeGeneratedCount);
+ toBeGeneratedCount -= n;
+
+ if (toBeGeneratedCount <= 0) {
+ // make sure this is a queued connection!
+ emit readChannelFinished();
+ }
+
+ return n;
+ }
+ virtual qint64 writeData(const char *, qint64)
+ { return -1; }
+
+ qint64 toBeGeneratedCount;
+ qint64 toBeGeneratedTotalCount;
+};
+
+
class DataGenerator: public QIODevice
{
Q_OBJECT
@@ -384,6 +465,7 @@ protected:
{
if (state == Stopped)
return -1; // EOF
+
// return as many bytes as are wanted
memset(data, '@', maxlen);
return maxlen;
@@ -392,6 +474,8 @@ protected:
{ return -1; }
};
+
+
class SocketPair: public QObject
{
Q_OBJECT
@@ -629,7 +713,7 @@ protected:
return;
transferRate = totalBytes * 1000 / timer.elapsed();
- qDebug() << "receive rate:" << (transferRate / 1024) << "kB/s in"
+ qDebug() << "TimedSender::run" << "receive rate:" << (transferRate / 1024) << "kB/s in"
<< timer.elapsed() << "ms";
}
@@ -643,12 +727,13 @@ protected:
class ThreadedDataReader: public QThread
{
Q_OBJECT
+ // used to make the constructor only return after the tcp server started listening
QSemaphore ready;
QTcpSocket *client;
int timeout;
int port;
public:
- int transferRate;
+ qint64 transferRate;
ThreadedDataReader()
: port(-1), transferRate(-1)
{
@@ -676,12 +761,65 @@ protected:
QTime timer;
timer.start();
eventLoop.exec();
+ qint64 elapsed = timer.elapsed();
- transferRate = reader.totalBytes * 1000 / timer.elapsed();
- qDebug() << "send rate:" << (transferRate / 1024) << "kB/s";
+ transferRate = reader.totalBytes * 1000 / elapsed;
+ qDebug() << "ThreadedDataReader::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec";
}
};
+class ThreadedDataReaderHttpServer: public QThread
+{
+ Q_OBJECT
+ // used to make the constructor only return after the tcp server started listening
+ QSemaphore ready;
+ QTcpSocket *client;
+ int timeout;
+ int port;
+public:
+ qint64 transferRate;
+ ThreadedDataReaderHttpServer()
+ : port(-1), transferRate(-1)
+ {
+ start();
+ ready.acquire();
+ }
+
+ inline int serverPort() const { return port; }
+
+protected:
+ void run()
+ {
+ QTcpServer server;
+ server.listen();
+ port = server.serverPort();
+ ready.release();
+
+ server.waitForNewConnection(-1);
+ client = server.nextPendingConnection();
+ client->write("HTTP/1.0 200 OK\r\n");
+ client->write("Content-length: 0\r\n");
+ client->write("\r\n");
+ client->flush();
+
+ QCoreApplication::processEvents();
+
+ QEventLoop eventLoop;
+ DataReader reader(client, false);
+ QObject::connect(client, SIGNAL(disconnected()), &eventLoop, SLOT(quit()));
+
+ QTime timer;
+ timer.start();
+ eventLoop.exec();
+ qint64 elapsed = timer.elapsed();
+
+ transferRate = reader.totalBytes * 1000 / elapsed;
+ qDebug() << "ThreadedDataReaderHttpServer::run" << "send rate:" << (transferRate / 1024) << "kB/s in" << elapsed << "msec";
+ }
+};
+
+
+
tst_QNetworkReply::tst_QNetworkReply()
{
testFileName = QDir::currentPath() + "/testfile";
@@ -692,8 +830,28 @@ tst_QNetworkReply::tst_QNetworkReply()
#endif
cookieJar = new MyCookieJar;
manager.setCookieJar(cookieJar);
+
+ QHostInfo hostInfo = QHostInfo::fromName(QtNetworkSettings::serverName());
+
+ proxies << ProxyData(QNetworkProxy::NoProxy, "", false);
+
+ if (hostInfo.error() == QHostInfo::NoError && !hostInfo.addresses().isEmpty()) {
+ QString proxyserver = hostInfo.addresses().first().toString();
+ proxies << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3128), "+proxy", false)
+ << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3129), "+proxyauth", true)
+ // currently unsupported
+ // << ProxyData(QNetworkProxy(QNetworkProxy::HttpProxy, proxyserver, 3130), "+proxyauth-ntlm", true);
+ << ProxyData(QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1080), "+socks", false)
+ << ProxyData(QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyserver, 1081), "+socksauth", true);
+ } else {
+ printf("==================================================================\n");
+ printf("Proxy could not be looked up. No proxy will be used while testing!\n");
+ printf("==================================================================\n");
+ }
}
+
+
void tst_QNetworkReply::authenticationRequired(QNetworkReply*, QAuthenticator* auth)
{
auth->setUser("httptest");
@@ -1887,6 +2045,53 @@ void tst_QNetworkReply::ioGetFromHttpsWithSslHandshakeError()
}
#endif
+void tst_QNetworkReply::ioGetFromHttpBrokenServer_data()
+{
+ QTest::addColumn<QByteArray>("dataToSend");
+ QTest::addColumn<bool>("doDisconnect");
+
+ QTest::newRow("no-newline") << QByteArray("Hello World") << false;
+ QTest::newRow("just-newline") << QByteArray("\r\n") << false;
+ QTest::newRow("just-2newline") << QByteArray("\r\n\r\n") << false;
+ QTest::newRow("with-newlines") << QByteArray("Long first line\r\nLong second line") << false;
+ QTest::newRow("with-newlines2") << QByteArray("\r\nSecond line") << false;
+ QTest::newRow("with-newlines3") << QByteArray("ICY\r\nSecond line") << false;
+ QTest::newRow("invalid-version") << QByteArray("HTTP/123 200 \r\n") << false;
+ QTest::newRow("invalid-version2") << QByteArray("HTTP/a.\033 200 \r\n") << false;
+ QTest::newRow("invalid-reply-code") << QByteArray("HTTP/1.0 fuu \r\n") << false;
+
+ QTest::newRow("empty+disconnect") << QByteArray() << true;
+
+ QTest::newRow("no-newline+disconnect") << QByteArray("Hello World") << true;
+ QTest::newRow("just-newline+disconnect") << QByteArray("\r\n") << true;
+ QTest::newRow("just-2newline+disconnect") << QByteArray("\r\n\r\n") << true;
+ QTest::newRow("with-newlines+disconnect") << QByteArray("Long first line\r\nLong second line") << true;
+ QTest::newRow("with-newlines2+disconnect") << QByteArray("\r\nSecond line") << true;
+ QTest::newRow("with-newlines3+disconnect") << QByteArray("ICY\r\nSecond line") << true;
+
+ QTest::newRow("invalid-version+disconnect") << QByteArray("HTTP/123 200 ") << true;
+ QTest::newRow("invalid-version2+disconnect") << QByteArray("HTTP/a.\033 200 ") << true;
+ QTest::newRow("invalid-reply-code+disconnect") << QByteArray("HTTP/1.0 fuu ") << true;
+}
+
+void tst_QNetworkReply::ioGetFromHttpBrokenServer()
+{
+ QFETCH(QByteArray, dataToSend);
+ QFETCH(bool, doDisconnect);
+ MiniHttpServer server(dataToSend);
+ server.doClose = doDisconnect;
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply = manager.get(request);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QCOMPARE(reply->url(), request.url());
+ QVERIFY(reply->error() != QNetworkReply::NoError);
+}
+
void tst_QNetworkReply::ioGetWithManyProxies_data()
{
QTest::addColumn<QList<QNetworkProxy> >("proxyList");
@@ -2452,6 +2657,320 @@ void tst_QNetworkReply::ioPostToHttpFromFile()
QCOMPARE(reply->readAll().trimmed(), md5sum(sourceFile.readAll()).toHex());
}
+void tst_QNetworkReply::ioPostToHttpFromSocket_data()
+{
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<QByteArray>("md5sum");
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QNetworkProxy>("proxy");
+ QTest::addColumn<int>("authenticationRequiredCount");
+ QTest::addColumn<int>("proxyAuthenticationRequiredCount");
+
+ for (int i = 0; i < proxies.count(); ++i)
+ for (int auth = 0; auth < 2; ++auth) {
+ QUrl url;
+ if (auth)
+ url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
+ else
+ url = "http://" + QtNetworkSettings::serverName() + "/qtest/cgi-bin/md5sum.cgi";
+
+ QNetworkProxy proxy = proxies.at(i).proxy;
+ QByteArray testsuffix = QByteArray(auth ? "+auth" : "") + proxies.at(i).tag;
+ int proxyauthcount = proxies.at(i).requiresAuthentication;
+
+ QByteArray data;
+ data = "";
+ QTest::newRow("empty" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+
+ data = "This is a normal message.";
+ QTest::newRow("generic" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+
+ data = "This is a message to show that Qt rocks!\r\n\n";
+ QTest::newRow("small" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+
+ data = QByteArray("abcd\0\1\2\abcd",12);
+ QTest::newRow("with-nul" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+
+ data = QByteArray(4097, '\4');
+ QTest::newRow("4k+1" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+
+ data = QByteArray(128*1024+1, '\177');
+ QTest::newRow("128k+1" + testsuffix) << data << md5sum(data) << url << proxy << auth << proxyauthcount;
+ }
+}
+
+void tst_QNetworkReply::ioPostToHttpFromSocket()
+{
+ qRegisterMetaType<QNetworkProxy>(); // for QSignalSpy
+ qRegisterMetaType<QAuthenticator *>();
+ qRegisterMetaType<QNetworkReply *>();
+
+ QFETCH(QByteArray, data);
+ QFETCH(QUrl, url);
+ QFETCH(QNetworkProxy, proxy);
+ SocketPair socketpair;
+ socketpair.create();
+ QVERIFY(socketpair.endPoints[0] && socketpair.endPoints[1]);
+
+ socketpair.endPoints[0]->write(data);
+
+ QNetworkRequest request(url);
+ manager.setProxy(proxy);
+ QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), socketpair.endPoints[1]);
+ socketpair.endPoints[0]->close();
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
+ SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ QSignalSpy authenticationRequiredSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ QSignalSpy proxyAuthenticationRequiredSpy(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
+
+ QTestEventLoop::instance().enterLoop(1);
+
+ disconnect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
+ this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
+ disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QCOMPARE(reply->url(), url);
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ // verify that the HTTP status code is 200 Ok
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+
+ QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex());
+
+ QTEST(authenticationRequiredSpy.count(), "authenticationRequiredCount");
+ QTEST(proxyAuthenticationRequiredSpy.count(), "proxyAuthenticationRequiredCount");
+ }
+
+// this tests checks if rewinding the POST-data to some place in the middle
+// worked.
+void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileToEnd()
+{
+ QFile sourceFile(SRCDIR "/rfc3252.txt");
+ QVERIFY(sourceFile.open(QIODevice::ReadOnly));
+ // seeking to the middle
+ sourceFile.seek(sourceFile.size() / 2);
+
+ QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.post(QNetworkRequest(url), &sourceFile);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ QTestEventLoop::instance().enterLoop(2);
+ disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ // compare half data
+ sourceFile.seek(sourceFile.size() / 2);
+ QByteArray data = sourceFile.readAll();
+ QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex());
+}
+
+void tst_QNetworkReply::ioPostToHttpFromMiddleOfFileFiveBytes()
+{
+ QFile sourceFile(SRCDIR "/rfc3252.txt");
+ QVERIFY(sourceFile.open(QIODevice::ReadOnly));
+ // seeking to the middle
+ sourceFile.seek(sourceFile.size() / 2);
+
+ QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
+ QNetworkRequest request(url);
+ // only send 5 bytes
+ request.setHeader(QNetworkRequest::ContentLengthHeader, 5);
+ QVERIFY(request.header(QNetworkRequest::ContentLengthHeader).isValid());
+ QNetworkReplyPtr reply = manager.post(request, &sourceFile);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ QTestEventLoop::instance().enterLoop(2);
+ disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ // compare half data
+ sourceFile.seek(sourceFile.size() / 2);
+ QByteArray data = sourceFile.read(5);
+ QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex());
+}
+
+void tst_QNetworkReply::ioPostToHttpFromMiddleOfQBufferFiveBytes()
+{
+ // test needed since a QBuffer goes with a different codepath than the QFile
+ // tested in ioPostToHttpFromMiddleOfFileFiveBytes
+ QBuffer uploadBuffer;
+ uploadBuffer.open(QIODevice::ReadWrite);
+ uploadBuffer.write("1234567890");
+ uploadBuffer.seek(5);
+
+ QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.post(request, &uploadBuffer);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ QTestEventLoop::instance().enterLoop(2);
+ disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ // compare half data
+ uploadBuffer.seek(5);
+ QByteArray data = uploadBuffer.read(5);
+ QCOMPARE(reply->readAll().trimmed(), md5sum(data).toHex());
+}
+
+
+void tst_QNetworkReply::ioPostToHttpNoBufferFlag()
+{
+ QByteArray data = QByteArray("daaaaaaataaaaaaa");
+ // create a sequential QIODevice by feeding the data into a local TCP server
+ SocketPair socketpair;
+ socketpair.create();
+ QVERIFY(socketpair.endPoints[0] && socketpair.endPoints[1]);
+ socketpair.endPoints[0]->write(data);
+
+ QUrl url = "http://" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi";
+ QNetworkRequest request(url);
+ // disallow buffering
+ request.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, true);
+ request.setHeader(QNetworkRequest::ContentLengthHeader, data.size());
+ QNetworkReplyPtr reply = manager.post(request, socketpair.endPoints[1]);
+ socketpair.endPoints[0]->close();
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ QTestEventLoop::instance().enterLoop(2);
+ disconnect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+
+ // verify: error code is QNetworkReply::ContentReSendError
+ QCOMPARE(reply->error(), QNetworkReply::ContentReSendError);
+}
+
+
+void tst_QNetworkReply::ioPostToHttpUploadProgress()
+{
+ QFile sourceFile(SRCDIR "/bigfile");
+ QVERIFY(sourceFile.open(QIODevice::ReadOnly));
+
+ // emulate a minimal http server
+ QTcpServer server;
+ server.listen(QHostAddress(QHostAddress::LocalHost), 0);
+
+ // create the request
+ QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort()));
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.post(request, &sourceFile);
+ QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64)));
+ connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ // get the request started and the incoming socket connected
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QTcpSocket *incomingSocket = server.nextPendingConnection();
+ QVERIFY(incomingSocket);
+ disconnect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ incomingSocket->setReadBufferSize(1*1024);
+ QTestEventLoop::instance().enterLoop(2);
+ // some progress should have been made
+ QList<QVariant> args = spy.last();
+ QVERIFY(!args.isEmpty());
+ QVERIFY(args.at(0).toLongLong() > 0);
+
+ incomingSocket->setReadBufferSize(32*1024);
+ incomingSocket->read(16*1024);
+ QTestEventLoop::instance().enterLoop(2);
+ // some more progress than before
+ QList<QVariant> args2 = spy.last();
+ QVERIFY(!args2.isEmpty());
+ QVERIFY(args2.at(0).toLongLong() > args.at(0).toLongLong());
+
+ // set the read buffer to unlimited
+ incomingSocket->setReadBufferSize(0);
+ QTestEventLoop::instance().enterLoop(10);
+ // progress should be finished
+ QList<QVariant> args3 = spy.last();
+ QVERIFY(!args3.isEmpty());
+ QVERIFY(args3.at(0).toLongLong() > args2.at(0).toLongLong());
+ QCOMPARE(args3.at(0).toLongLong(), args3.at(1).toLongLong());
+ QCOMPARE(args3.at(0).toLongLong(), sourceFile.size());
+
+ // after sending this, the QNAM should emit finished()
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ incomingSocket->write("HTTP/1.0 200 OK\r\n");
+ incomingSocket->write("Content-Length: 0\r\n");
+ incomingSocket->write("\r\n");
+ QTestEventLoop::instance().enterLoop(10);
+ // not timeouted -> finished() was emitted
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ incomingSocket->close();
+ server.close();
+}
+
+void tst_QNetworkReply::ioPostToHttpEmtpyUploadProgress()
+{
+ QByteArray ba;
+ ba.resize(0);
+ QBuffer buffer(&ba,0);
+ QVERIFY(buffer.open(QIODevice::ReadOnly));
+
+ // emulate a minimal http server
+ QTcpServer server;
+ server.listen(QHostAddress(QHostAddress::LocalHost), 0);
+
+ // create the request
+ QUrl url = QUrl(QString("http://127.0.0.1:%1/").arg(server.serverPort()));
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.post(request, &buffer);
+ QSignalSpy spy(reply, SIGNAL(uploadProgress(qint64,qint64)));
+ connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+
+ // get the request started and the incoming socket connected
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QTcpSocket *incomingSocket = server.nextPendingConnection();
+ QVERIFY(incomingSocket);
+
+ // after sending this, the QNAM should emit finished()
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ incomingSocket->write("HTTP/1.0 200 OK\r\n");
+ incomingSocket->write("Content-Length: 0\r\n");
+ incomingSocket->write("\r\n");
+ incomingSocket->flush();
+ QTestEventLoop::instance().enterLoop(10);
+ // not timeouted -> finished() was emitted
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ // final check: only 1 uploadProgress has been emitted
+ QVERIFY(spy.length() == 1);
+ QList<QVariant> args = spy.last();
+ QVERIFY(!args.isEmpty());
+ QCOMPARE(args.at(0).toLongLong(), buffer.size());
+ QCOMPARE(args.at(0).toLongLong(), buffer.size());
+
+ incomingSocket->close();
+ server.close();
+}
+
+
void tst_QNetworkReply::rateControl_data()
{
QTest::addColumn<int>("rate");
@@ -2488,8 +3007,8 @@ void tst_QNetworkReply::rateControl()
QTestEventLoop::instance().enterLoop(40);
int elapsedTime = loopTime.elapsed();
- qDebug() << "send rate:" << sender.transferRate;
- qDebug() << "receive rate:" << reader.totalBytesRead * 1000 / elapsedTime
+ qDebug() << "tst_QNetworkReply::rateControl" << "send rate:" << sender.transferRate;
+ qDebug() << "tst_QNetworkReply::rateControl" << "receive rate:" << reader.totalBytesRead * 1000 / elapsedTime
<< "(it received" << reader.totalBytesRead << "bytes in" << elapsedTime << "ms)";
sender.wait();
@@ -2523,23 +3042,54 @@ void tst_QNetworkReply::downloadPerformance()
sender.wait();
qint64 receivedBytes = reader.totalBytes;
- qDebug() << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and"
+ qDebug() << "tst_QNetworkReply::downloadPerformance" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and"
<< elapsedTime << "ms";
}
void tst_QNetworkReply::uploadPerformance()
{
- ThreadedDataReader reader;
- DataGenerator generator;
- QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1");
- QNetworkReplyPtr reply = manager.put(request, &generator);
+ ThreadedDataReader reader;
+ DataGenerator generator;
- connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTimer::singleShot(5000, &generator, SLOT(stop()));
- generator.start();
- QTestEventLoop::instance().enterLoop(40);
+
+ QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1");
+ QNetworkReplyPtr reply = manager.put(request, &generator);
+ generator.start();
+ connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTimer::singleShot(5000, &generator, SLOT(stop()));
+
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+}
+
+void tst_QNetworkReply::httpUploadPerformance()
+{
+ enum {UploadSize = 1000*1024*1024}; // 1000 MB
+ ThreadedDataReaderHttpServer reader;
+ FixedSizeDataGenerator generator(UploadSize);
+
+ QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"));
+ request.setHeader(QNetworkRequest::ContentLengthHeader,UploadSize);
+
+ QNetworkReplyPtr reply = manager.put(request, &generator);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+
+ QTime time;
+ generator.start();
+ time.start();
+ QTestEventLoop::instance().enterLoop(40);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ qint64 elapsed = time.elapsed();
+ qWarning() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, "
+ << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec";
+
+ reader.exit();
+ reader.wait(3000);
}
+
void tst_QNetworkReply::performanceControlRate()
{
// this is a control comparison for the other two above
@@ -2560,7 +3110,7 @@ void tst_QNetworkReply::performanceControlRate()
sender.wait();
qint64 receivedBytes = reader.totalBytes;
- qDebug() << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and"
+ qDebug() << "tst_QNetworkReply::performanceControlRate" << "receive rate:" << (receivedBytes * 1000 / elapsedTime / 1024) << "kB/s and"
<< elapsedTime << "ms";
}
@@ -2586,12 +3136,14 @@ void tst_QNetworkReply::downloadProgress()
QVERIFY(spy.isValid());
QCoreApplication::instance()->processEvents();
- server.waitForNewConnection(0); // ignore result, since processEvents may have got it
+ if (!server.hasPendingConnections())
+ server.waitForNewConnection(1000);
QVERIFY(server.hasPendingConnections());
QCOMPARE(spy.count(), 0);
QByteArray data(128, 'a');
QTcpSocket *sender = server.nextPendingConnection();
+ QVERIFY(sender);
QFETCH(int, loopCount);
for (int i = 1; i <= loopCount; ++i) {
@@ -2640,7 +3192,8 @@ void tst_QNetworkReply::uploadProgress()
QVERIFY(finished.isValid());
QCoreApplication::instance()->processEvents();
- server.waitForNewConnection(0); // ignore result, since processEvents may have got it
+ if (!server.hasPendingConnections())
+ server.waitForNewConnection(1000);
QVERIFY(server.hasPendingConnections());
QTcpSocket *receiver = server.nextPendingConnection();
@@ -2963,5 +3516,55 @@ void tst_QNetworkReply::proxyChange()
QVERIFY(int(reply3->error()) > 0);
}
+void tst_QNetworkReply::authorizationError_data()
+{
+
+ QTest::addColumn<QString>("url");
+ QTest::addColumn<int>("errorSignalCount");
+ QTest::addColumn<int>("finishedSignalCount");
+ QTest::addColumn<int>("error");
+ QTest::addColumn<int>("httpStatusCode");
+ QTest::addColumn<QString>("httpBody");
+
+ QTest::newRow("unknown-authorization-method") << "http://" + QtNetworkSettings::serverName() +
+ "/cgi-bin/http-unknown-authentication-method.cgi?401-authorization-required" << 1 << 1
+ << int(QNetworkReply::AuthenticationRequiredError) << 401 << "authorization required";
+ QTest::newRow("unknown-proxy-authorization-method") << "http://" + QtNetworkSettings::serverName() +
+ "/cgi-bin/http-unknown-authentication-method.cgi?407-proxy-authorization-required" << 1 << 1
+ << int(QNetworkReply::ProxyAuthenticationRequiredError) << 407
+ << "authorization required";
+}
+
+void tst_QNetworkReply::authorizationError()
+{
+ QFETCH(QString, url);
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply = manager.get(request);
+
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+
+ qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
+ QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError)));
+ QSignalSpy finishedSpy(reply, SIGNAL(finished()));
+ // now run the request:
+ connect(reply, SIGNAL(finished()),
+ &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+
+ QFETCH(int, errorSignalCount);
+ QCOMPARE(errorSpy.count(), errorSignalCount);
+ QFETCH(int, finishedSignalCount);
+ QCOMPARE(finishedSpy.count(), finishedSignalCount);
+ QFETCH(int, error);
+ QCOMPARE(reply->error(), QNetworkReply::NetworkError(error));
+
+ QFETCH(int, httpStatusCode);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), httpStatusCode);
+
+ QFETCH(QString, httpBody);
+ QCOMPARE(QString(reply->readAll()), httpBody);
+}
+
QTEST_MAIN(tst_QNetworkReply)
#include "tst_qnetworkreply.moc"
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index fb46073..399d021 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -116,6 +116,7 @@ private slots:
void dumpObjectInfo();
void connectToSender();
void qobjectConstCast();
+ void uniqConnection();
protected:
};
@@ -204,12 +205,20 @@ public:
sequence_slot3 = 0;
sequence_slot2 = 0;
sequence_slot1 = 0;
+ count_slot1 = 0;
+ count_slot2 = 0;
+ count_slot3 = 0;
+ count_slot4 = 0;
}
int sequence_slot1;
int sequence_slot2;
int sequence_slot3;
int sequence_slot4;
+ int count_slot1;
+ int count_slot2;
+ int count_slot3;
+ int count_slot4;
bool called(int slot) {
switch (slot) {
@@ -224,10 +233,10 @@ public:
static int sequence;
public slots:
- void slot1() { sequence_slot1 = ++sequence; }
- void slot2() { sequence_slot2 = ++sequence; }
- void slot3() { sequence_slot3 = ++sequence; }
- void slot4() { sequence_slot4 = ++sequence; }
+ void slot1() { sequence_slot1 = ++sequence; count_slot1++; }
+ void slot2() { sequence_slot2 = ++sequence; count_slot2++; }
+ void slot3() { sequence_slot3 = ++sequence; count_slot3++; }
+ void slot4() { sequence_slot4 = ++sequence; count_slot4++; }
};
@@ -2783,5 +2792,69 @@ void tst_QObject::qobjectConstCast()
QVERIFY(qobject_cast<const FooObject *>(cptr));
}
+void tst_QObject::uniqConnection()
+{
+ SenderObject *s = new SenderObject;
+ ReceiverObject *r1 = new ReceiverObject;
+ ReceiverObject *r2 = new ReceiverObject;
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot1() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot1() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal3() ), r1, SLOT( slot3() ) , Qt::UniqueConnection) );
+
+ s->emitSignal1();
+ s->emitSignal2();
+ s->emitSignal3();
+ s->emitSignal4();
+
+ QCOMPARE( r1->count_slot1, 1 );
+ QCOMPARE( r1->count_slot2, 0 );
+ QCOMPARE( r1->count_slot3, 2 );
+ QCOMPARE( r1->count_slot4, 0 );
+ QCOMPARE( r2->count_slot1, 1 );
+ QCOMPARE( r2->count_slot2, 0 );
+ QCOMPARE( r2->count_slot3, 0 );
+ QCOMPARE( r2->count_slot4, 0 );
+ QCOMPARE( r1->sequence_slot1, 1 );
+ QCOMPARE( r2->sequence_slot1, 2 );
+ QCOMPARE( r1->sequence_slot3, 4 );
+
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ QVERIFY( connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY(!connect( s, SIGNAL( signal4() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY( connect( s, SIGNAL( signal1() ), r2, SLOT( slot4() ) , Qt::UniqueConnection) );
+ QVERIFY(!connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) , Qt::UniqueConnection) );
+
+ s->emitSignal4();
+ QCOMPARE( r1->count_slot4, 1 );
+ QCOMPARE( r2->count_slot4, 1 );
+ QCOMPARE( r1->sequence_slot4, 1 );
+ QCOMPARE( r2->sequence_slot4, 2 );
+
+ r1->reset();
+ r2->reset();
+ ReceiverObject::sequence = 0;
+
+ connect( s, SIGNAL( signal4() ), r1, SLOT( slot4() ) );
+
+ s->emitSignal4();
+ QCOMPARE( r1->count_slot4, 2 );
+ QCOMPARE( r2->count_slot4, 1 );
+ QCOMPARE( r1->sequence_slot4, 3 );
+ QCOMPARE( r2->sequence_slot4, 2 );
+
+ delete s;
+ delete r1;
+ delete r2;
+}
+
QTEST_MAIN(tst_QObject)
#include "tst_qobject.moc"
diff --git a/tests/auto/qobjectrace/tst_qobjectrace.cpp b/tests/auto/qobjectrace/tst_qobjectrace.cpp
index 0c88f29..aa80534 100644
--- a/tests/auto/qobjectrace/tst_qobjectrace.cpp
+++ b/tests/auto/qobjectrace/tst_qobjectrace.cpp
@@ -43,6 +43,7 @@
#include <QtCore>
#include <QtTest/QtTest>
+
enum { OneMinute = 60 * 1000, TwoMinutes = OneMinute * 2 };
class tst_QObjectRace: public QObject
@@ -50,6 +51,7 @@ class tst_QObjectRace: public QObject
Q_OBJECT
private slots:
void moveToThreadRace();
+ void destroyRace();
};
class RaceObject : public QObject
@@ -69,12 +71,18 @@ public:
public slots:
void theSlot()
{
- enum { step = 1000 };
+ enum { step = 35 };
if ((++count % step) == 0) {
QThread *nextThread = threads.at((count / step) % threads.size());
moveToThread(nextThread);
}
}
+
+ void destroSlot() {
+ emit theSignal();
+ }
+signals:
+ void theSignal();
};
class RaceThread : public QThread
@@ -119,6 +127,10 @@ private slots:
if (stopWatch.elapsed() >= OneMinute / 2)
#endif
quit();
+
+ QObject o;
+ connect(&o, SIGNAL(destroyed()) , object, SLOT(destroSlot()));
+ connect(object, SIGNAL(destroyed()) , &o, SLOT(deleteLater()));
}
};
@@ -137,15 +149,110 @@ void tst_QObjectRace::moveToThreadRace()
for (int i = 0; i < ThreadCount; ++i)
threads[i]->start();
- QVERIFY(threads[0]->wait(TwoMinutes));
+
+ while(!threads[0]->isFinished()) {
+ QPointer<RaceObject> foo (object);
+ QObject o;
+ connect(&o, SIGNAL(destroyed()) , object, SLOT(destroSlot()));
+ connect(object, SIGNAL(destroyed()) , &o, SLOT(deleteLater()));
+ QTest::qWait(10);
+ }
// the other threads should finish pretty quickly now
for (int i = 1; i < ThreadCount; ++i)
- QVERIFY(threads[i]->wait(30000));
+ QVERIFY(threads[i]->wait(300));
for (int i = 0; i < ThreadCount; ++i)
delete threads[i];
delete object;
}
+
+class MyObject : public QObject
+{ Q_OBJECT
+ public slots:
+ void slot1() { emit signal1(); }
+ void slot2() { emit signal2(); }
+ void slot3() { emit signal3(); }
+ void slot4() { emit signal4(); }
+ void slot5() { emit signal5(); }
+ void slot6() { emit signal6(); }
+ void slot7() { emit signal7(); }
+ signals:
+ void signal1();
+ void signal2();
+ void signal3();
+ void signal4();
+ void signal5();
+ void signal6();
+ void signal7();
+};
+
+
+
+class DestroyThread : public QThread
+{
+ Q_OBJECT
+ QObject **objects;
+ int number;
+
+public:
+ void setObjects(QObject **o, int n)
+ {
+ objects = o;
+ number = n;
+ for(int i = 0; i < number; i++)
+ objects[i]->moveToThread(this);
+ }
+
+ void run() {
+ for(int i = 0; i < number; i++)
+ delete objects[i];
+ }
+};
+
+void tst_QObjectRace::destroyRace()
+{
+ enum { ThreadCount = 10, ObjectCountPerThread = 733,
+ ObjectCount = ThreadCount * ObjectCountPerThread };
+
+ const char *_slots[] = { SLOT(slot1()) , SLOT(slot2()) , SLOT(slot3()),
+ SLOT(slot4()) , SLOT(slot5()) , SLOT(slot6()),
+ SLOT(slot7()) };
+
+ const char *_signals[] = { SIGNAL(signal1()), SIGNAL(signal2()), SIGNAL(signal3()),
+ SIGNAL(signal4()), SIGNAL(signal5()), SIGNAL(signal6()),
+ SIGNAL(signal7()) };
+
+ QObject *objects[ObjectCount];
+ for (int i = 0; i < ObjectCount; ++i)
+ objects[i] = new MyObject;
+
+
+ for (int i = 0; i < ObjectCount * 11; ++i) {
+ connect(objects[(i*13) % ObjectCount], _signals[(2*i)%7],
+ objects[((i+2)*17) % ObjectCount], _slots[(3*i+2)%7] );
+ connect(objects[((i+6)*23) % ObjectCount], _signals[(5*i+4)%7],
+ objects[((i+8)*41) % ObjectCount], _slots[(i+6)%7] );
+ }
+
+ DestroyThread *threads[ThreadCount];
+ for (int i = 0; i < ThreadCount; ++i) {
+ threads[i] = new DestroyThread;
+ threads[i]->setObjects(objects + i*ObjectCountPerThread, ObjectCountPerThread);
+ }
+
+ for (int i = 0; i < ThreadCount; ++i)
+ threads[i]->start();
+
+ QVERIFY(threads[0]->wait(TwoMinutes));
+ // the other threads should finish pretty quickly now
+ for (int i = 1; i < ThreadCount; ++i)
+ QVERIFY(threads[i]->wait(3000));
+
+ for (int i = 0; i < ThreadCount; ++i)
+ delete threads[i];
+}
+
+
QTEST_MAIN(tst_QObjectRace)
#include "tst_qobjectrace.moc"
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index 87f9c13..af0f6cf 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -226,6 +226,7 @@ private slots:
void extendedBlendModes();
void zeroOpacity();
+ void clippingBug();
private:
void fillData();
@@ -4168,5 +4169,28 @@ void tst_QPainter::zeroOpacity()
QCOMPARE(target.pixel(0, 0), 0xff000000);
}
+void tst_QPainter::clippingBug()
+{
+ QImage img(32, 32, QImage::Format_ARGB32_Premultiplied);
+ img.fill(0);
+
+ QImage expected = img;
+ QPainter p(&expected);
+ p.fillRect(1, 1, 30, 30, Qt::red);
+ p.end();
+
+ QPainterPath path;
+ path.addRect(1, 1, 30, 30);
+ path.addRect(1, 1, 30, 30);
+ path.addRect(1, 1, 30, 30);
+
+ p.begin(&img);
+ p.setClipPath(path);
+ p.fillRect(0, 0, 32, 32, Qt::red);
+ p.end();
+
+ QCOMPARE(img, expected);
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"
diff --git a/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro b/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro
new file mode 100644
index 0000000..f2cacd3
--- /dev/null
+++ b/tests/auto/qparallelanimationgroup/qparallelanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qparallelanimationgroup.cpp
+
+
diff --git a/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
new file mode 100644
index 0000000..f2ab57a
--- /dev/null
+++ b/tests/auto/qparallelanimationgroup/tst_qparallelanimationgroup.cpp
@@ -0,0 +1,834 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qparallelanimationgroup.h>
+
+//TESTED_CLASS=QParallelAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+class tst_QParallelAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QParallelAnimationGroup();
+ virtual ~tst_QParallelAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime();
+ void clearGroup();
+ void propagateGroupUpdateToChildren();
+ void updateChildrenWithRunningGroup();
+ void deleteChildrenWithRunningGroup();
+ void startChildrenWithStoppedGroup();
+ void stopGroupWithRunningChild();
+ void startGroupWithRunningChild();
+ void zeroDurationAnimation();
+ void stopUncontrolledAnimations();
+ void loopCount_data();
+ void loopCount();
+ void autoAdd();
+};
+
+tst_QParallelAnimationGroup::tst_QParallelAnimationGroup()
+{
+}
+
+tst_QParallelAnimationGroup::~tst_QParallelAnimationGroup()
+{
+}
+
+void tst_QParallelAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+}
+
+void tst_QParallelAnimationGroup::cleanup()
+{
+}
+
+void tst_QParallelAnimationGroup::construction()
+{
+ QParallelAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class TestAnimation2 : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ TestAnimation2(QAbstractAnimation *animation) : QVariantAnimation(animation) {}
+ TestAnimation2(int duration, QAbstractAnimation *animation) : QVariantAnimation(animation), m_duration(duration) {}
+
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+
+ virtual int duration() const {
+ return m_duration;
+ }
+private:
+ int m_duration;
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent), id(0)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void timerEvent(QTimerEvent *event)
+ {
+ if (event->timerId() == id)
+ stop();
+ }
+
+ void updateRunning(bool running)
+ {
+ if (running) {
+ id = startTimer(500);
+ } else {
+ killTimer(id);
+ id = 0;
+ }
+ }
+
+private:
+ int id;
+};
+
+void tst_QParallelAnimationGroup::setCurrentTime()
+{
+ AnimationObject p_o1;
+ AnimationObject p_o2;
+ AnimationObject p_o3;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // parallel operating on different object/properties
+ QAnimationGroup *parallel = new QParallelAnimationGroup();
+ QVariantAnimation *a1_p_o1 = new QPropertyAnimation(&p_o1, "value");
+ QVariantAnimation *a1_p_o2 = new QPropertyAnimation(&p_o2, "value");
+ QVariantAnimation *a1_p_o3 = new QPropertyAnimation(&p_o3, "value");
+ a1_p_o2->setLoopCount(3);
+ parallel->addAnimation(a1_p_o1);
+ parallel->addAnimation(a1_p_o2);
+ parallel->addAnimation(a1_p_o3);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QParallelAnimationGroup group;
+ group.addAnimation(parallel);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(parallel->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_p_o3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(a1_p_o1->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 1);
+ QCOMPARE(notTimeDriven->currentTime(), 1);
+ QCOMPARE(loopsForever->currentTime(), 1);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 0);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(loopsForever->currentLoop(), 1);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(a1_p_o1->currentTime(), 250);
+ QCOMPARE(a1_p_o2->currentTime(), 1);
+ QCOMPARE(a1_p_o2->currentLoop(), 1);
+ QCOMPARE(a1_p_o3->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 251);
+ QCOMPARE(loopsForever->currentTime(), 1);
+}
+
+void tst_QParallelAnimationGroup::clearGroup()
+{
+ QParallelAnimationGroup group;
+
+ for (int i = 0; i < 10; ++i) {
+ new QParallelAnimationGroup(&group);
+ }
+
+ QCOMPARE(group.animationCount(), 10);
+
+ int count = group.animationCount();
+ QPointer<QAbstractAnimation> *children = new QPointer<QAbstractAnimation>[count];
+ for (int i = 0; i < count; ++i) {
+ QVERIFY(group.animationAt(i) != 0);
+ children[i] = group.animationAt(i);
+ }
+
+ group.clearAnimations();
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ for (int i = 0; i < count; ++i)
+ QCOMPARE(children[i], QPointer<QAbstractAnimation>());
+
+ delete[] children;
+}
+
+void tst_QParallelAnimationGroup::propagateGroupUpdateToChildren()
+{
+ // this test verifies if group state changes are updating its children correctly
+ QParallelAnimationGroup group;
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(43);
+ anim1.setDuration(100);
+ QVERIFY(!anim1.currentValue().isValid());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QVERIFY(anim2.currentValue().isValid());
+ QCOMPARE(anim2.currentValue().toInt(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim1.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::updateChildrenWithRunningGroup()
+{
+ // assert that its possible to modify a child's state directly while their group is running
+ QParallelAnimationGroup group;
+
+ TestAnimation anim;
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.setDuration(200);
+
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy childStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(groupStateChangedSpy.count(), 0);
+ QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(childStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+
+ // starting directly a running child will not have any effect
+ anim.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ anim.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Paused);
+
+ // in the animation stops directly, the group will still be running
+ anim.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::deleteChildrenWithRunningGroup()
+{
+ // test if children can be activated when their group is stopped
+ QParallelAnimationGroup group;
+
+ QVariantAnimation *anim1 = new TestAnimation;
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+ group.addAnimation(anim1);
+
+ QCOMPARE(group.duration(), anim1->duration());
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+
+ QTest::qWait(50);
+ QVERIFY(group.currentTime() > 0);
+
+ delete anim1;
+ QVERIFY(group.animationCount() == 0);
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), 0); //that's the invariant
+}
+
+void tst_QParallelAnimationGroup::startChildrenWithStoppedGroup()
+{
+ // test if children can be activated when their group is stopped
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+}
+
+void tst_QParallelAnimationGroup::stopGroupWithRunningChild()
+{
+ // children that started independently will not be affected by a group stop
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ anim1.stop();
+ anim2.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QParallelAnimationGroup::startGroupWithRunningChild()
+{
+ // as the group has precedence over its children, starting a group will restart all the children
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(1).at(1)),
+ QAnimationGroup::Paused);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.start();
+
+ QCOMPARE(stateChangedSpy1.count(), 3);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(2).at(1)),
+ QAnimationGroup::Running);
+
+ QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(3).at(1)),
+ QAnimationGroup::Running);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+}
+
+void tst_QParallelAnimationGroup::zeroDurationAnimation()
+{
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(0);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(100);
+
+ QSignalSpy stateChangedSpy1(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy1(&anim1, SIGNAL(finished()));
+
+ QSignalSpy stateChangedSpy2(&anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy2(&anim2, SIGNAL(finished()));
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ group.start();
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(finishedSpy1.count(), 1);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ QCOMPARE(finishedSpy2.count(), 0);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy1.at(0).at(1)),
+ QAnimationGroup::Running);
+
+
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Running);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+
+ group.stop();
+ group.setLoopCount(4);
+ stateChangedSpy1.clear();
+ stateChangedSpy2.clear();
+
+ group.start();
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ group.setCurrentTime(50);
+ QCOMPARE(stateChangedSpy1.count(), 2);
+ QCOMPARE(stateChangedSpy2.count(), 1);
+ group.setCurrentTime(150);
+ QCOMPARE(stateChangedSpy1.count(), 4);
+ QCOMPARE(stateChangedSpy2.count(), 3);
+ group.setCurrentTime(50);
+ QCOMPARE(stateChangedSpy1.count(), 6);
+ QCOMPARE(stateChangedSpy2.count(), 5);
+
+}
+
+void tst_QParallelAnimationGroup::stopUncontrolledAnimations()
+{
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(0);
+
+ AnimationObject o1;
+ UncontrolledAnimation notTimeDriven(&o1, "value");
+ QCOMPARE(notTimeDriven.totalDuration(), -1);
+
+ TestAnimation loopsForever;
+ loopsForever.setStartValue(0);
+ loopsForever.setEndValue(100);
+ loopsForever.setDuration(100);
+ loopsForever.setLoopCount(-1);
+
+ QSignalSpy stateChangedSpy(&anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&notTimeDriven);
+ group.addAnimation(&loopsForever);
+
+ group.start();
+
+ QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+
+ notTimeDriven.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+
+ loopsForever.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+}
+
+struct AnimState {
+ AnimState(int time = -1) : time(time), state(-1) {}
+ AnimState(int time, int state) : time(time), state(state) {}
+ int time;
+ int state;
+};
+
+#define Running QAbstractAnimation::Running
+#define Stopped QAbstractAnimation::Stopped
+
+Q_DECLARE_METATYPE(AnimState)
+void tst_QParallelAnimationGroup::loopCount_data()
+{
+ QTest::addColumn<bool>("directionBackward");
+ QTest::addColumn<int>("setLoopCount");
+ QTest::addColumn<int>("initialGroupTime");
+ QTest::addColumn<int>("currentGroupTime");
+ QTest::addColumn<AnimState>("expected1");
+ QTest::addColumn<AnimState>("expected2");
+ QTest::addColumn<AnimState>("expected3");
+
+ // D U R A T I O N
+ // 100 60*2 0
+ // direction = Forward
+ QTest::newRow("50") << false << 3 << 0 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("100") << false << 3 << 0 << 100 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("110") << false << 3 << 0 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120") << false << 3 << 0 << 120 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+
+ QTest::newRow("170") << false << 3 << 0 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("220") << false << 3 << 0 << 220 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("230") << false << 3 << 0 << 230 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("240") << false << 3 << 0 << 240 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+
+ QTest::newRow("290") << false << 3 << 0 << 290 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("340") << false << 3 << 0 << 340 << AnimState(100 ) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("350") << false << 3 << 0 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("360") << false << 3 << 0 << 360 << AnimState(100, Stopped) << AnimState( 60 ) << AnimState( 0, Stopped);
+
+ QTest::newRow("410") << false << 3 << 0 << 410 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("460") << false << 3 << 0 << 460 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("470") << false << 3 << 0 << 470 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("480") << false << 3 << 0 << 480 << AnimState(100, Stopped) << AnimState( 60, Stopped) << AnimState( 0, Stopped);
+
+ // direction = Forward, rewind
+ QTest::newRow("120-110") << false << 3 << 120 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120-50") << false << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("120-0") << false << 3 << 120 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-110") << false << 3 << 300 << 110 << AnimState( 0, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-50") << false << 3 << 300 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("300-0") << false << 3 << 300 << 0 << AnimState( 0, Running) << AnimState( 0, Running) << AnimState( 0, Stopped);
+ QTest::newRow("115-105") << false << 3 << 115 << 105 << AnimState( 42, Stopped) << AnimState( 45, Running) << AnimState( 0, Stopped);
+
+ // direction = Backward
+ QTest::newRow("b120-120") << true << 3 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-110") << true << 3 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-100") << true << 3 << 120 << 100 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-50") << true << 3 << 120 << 50 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b120-0") << true << 3 << 120 << 0 << AnimState( 0, Stopped) << AnimState( 0, Stopped) << AnimState( 0, Stopped);
+ QTest::newRow("b360-170") << true << 3 << 360 << 170 << AnimState( 50, Running) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-220") << true << 3 << 360 << 220 << AnimState(100, Running) << AnimState( 40, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-210") << true << 3 << 360 << 210 << AnimState( 90, Running) << AnimState( 30, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b360-120") << true << 3 << 360 << 120 << AnimState( 0, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+
+ // rewind, direction = Backward
+ QTest::newRow("b50-110") << true << 3 << 50 << 110 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-120") << true << 3 << 50 << 120 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-140") << true << 3 << 50 << 140 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-240") << true << 3 << 50 << 240 << AnimState(100, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-260") << true << 3 << 50 << 260 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b50-350") << true << 3 << 50 << 350 << AnimState(100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+
+ // infinite looping
+ QTest::newRow("inf1220") << false << -1 << 0 << 1220 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("inf1310") << false << -1 << 0 << 1310 << AnimState( 100, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+ // infinite looping, direction = Backward (will only loop once)
+ QTest::newRow("b.inf120-120") << true << -1 << 120 << 120 << AnimState( 42, Stopped) << AnimState( 60, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b.inf120-20") << true << -1 << 120 << 20 << AnimState( 20, Running) << AnimState( 20, Running) << AnimState( 0, Stopped);
+ QTest::newRow("b.inf120-110") << true << -1 << 120 << 110 << AnimState( 42, Stopped) << AnimState( 50, Running) << AnimState( 0, Stopped);
+
+
+}
+
+void tst_QParallelAnimationGroup::loopCount()
+{
+ QFETCH(bool, directionBackward);
+ QFETCH(int, setLoopCount);
+ QFETCH(int, initialGroupTime);
+ QFETCH(int, currentGroupTime);
+ QFETCH(AnimState, expected1);
+ QFETCH(AnimState, expected2);
+ QFETCH(AnimState, expected3);
+
+ QParallelAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(100);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(60); //total 120
+ anim2.setLoopCount(2);
+
+ TestAnimation anim3;
+ anim3.setStartValue(0);
+ anim3.setEndValue(100);
+ anim3.setDuration(0);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+ group.addAnimation(&anim3);
+
+ group.setLoopCount(setLoopCount);
+ if (initialGroupTime >= 0)
+ group.setCurrentTime(initialGroupTime);
+ if (directionBackward)
+ group.setDirection(QAbstractAnimation::Backward);
+
+ group.start();
+ if (initialGroupTime >= 0)
+ group.setCurrentTime(initialGroupTime);
+
+ anim1.setCurrentTime(42); // 42 is "untouched"
+ anim2.setCurrentTime(42);
+
+ group.setCurrentTime(currentGroupTime);
+
+ QCOMPARE(anim1.currentTime(), expected1.time);
+ QCOMPARE(anim2.currentTime(), expected2.time);
+ QCOMPARE(anim3.currentTime(), expected3.time);
+
+ if (expected1.state >=0)
+ QCOMPARE(int(anim1.state()), expected1.state);
+ if (expected2.state >=0)
+ QCOMPARE(int(anim2.state()), expected2.state);
+ if (expected3.state >=0)
+ QCOMPARE(int(anim3.state()), expected3.state);
+
+}
+
+void tst_QParallelAnimationGroup::autoAdd()
+{
+ QParallelAnimationGroup group;
+ QCOMPARE(group.duration(), 0);
+ TestAnimation2 *test = new TestAnimation2(250, &group); // 0, duration = 250;
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(test->duration(), 250);
+ QCOMPARE(group.duration(), 250);
+
+ test = new TestAnimation2(750, &group); // 1
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(group.duration(), 750);
+ test = new TestAnimation2(500, &group); // 2
+ QCOMPARE(test->group(), &group);
+ QCOMPARE(group.duration(), 750);
+
+ delete group.animationAt(1); // remove the one with duration = 750
+ QCOMPARE(group.duration(), 500);
+
+ delete group.animationAt(1); // remove the one with duration = 500
+ QCOMPARE(group.duration(), 250);
+
+ test = static_cast<TestAnimation2*>(group.animationAt(0));
+ test->setParent(0); // remove the last one (with duration = 250)
+ QCOMPARE(test->group(), static_cast<QAnimationGroup*>(0));
+ QCOMPARE(group.duration(), 0);
+}
+
+QTEST_MAIN(tst_QParallelAnimationGroup)
+#include "tst_qparallelanimationgroup.moc"
diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
index 1f515ff..fb5998a 100644
--- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
@@ -44,9 +44,7 @@
#include <qpixmapcache.h>
-
-
-
+#include "../../../src/gui/image/qpixmapcache_p.h"
//TESTED_CLASS=
@@ -68,10 +66,21 @@ private slots:
void setCacheLimit();
void find();
void insert();
+ void replace();
void remove();
void clear();
+ void pixmapKey();
};
+static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
+{
+ return (*reinterpret_cast<QPixmapCache::KeyData**>(&key));
+}
+
+static QPixmapCache::KeyData** getPrivateRef(QPixmapCache::Key &key)
+{
+ return (reinterpret_cast<QPixmapCache::KeyData**>(&key));
+}
static int originalCacheLimit;
@@ -119,6 +128,72 @@ void tst_QPixmapCache::setCacheLimit()
QVERIFY(QPixmapCache::find("P1") != 0);
delete p1;
+
+ //The int part of the API
+ p1 = new QPixmap(2, 3);
+ QPixmapCache::Key key = QPixmapCache::insert(*p1);
+ QVERIFY(QPixmapCache::find(key, p1) != 0);
+ delete p1;
+
+ QPixmapCache::setCacheLimit(0);
+ QVERIFY(QPixmapCache::find(key, p1) == 0);
+
+ p1 = new QPixmap(2, 3);
+ QPixmapCache::setCacheLimit(1000);
+ QPixmapCache::replace(key, *p1);
+ QVERIFY(QPixmapCache::find(key, p1) == 0);
+
+ delete p1;
+
+ //Let check if keys are released when the pixmap cache is
+ //full or has been flushed.
+ QPixmapCache::clear();
+ p1 = new QPixmap(2, 3);
+ key = QPixmapCache::insert(*p1);
+ QVERIFY(QPixmapCache::find(key, p1) != 0);
+ QPixmapCache::setCacheLimit(0);
+ QVERIFY(QPixmapCache::find(key, p1) == 0);
+ QPixmapCache::setCacheLimit(1000);
+ key = QPixmapCache::insert(*p1);
+ QCOMPARE(getPrivate(key)->isValid, true);
+ QCOMPARE(getPrivate(key)->key, 1);
+
+ delete p1;
+
+ //Let check if removing old entries doesn't let you get
+ // wrong pixmaps
+ QPixmapCache::clear();
+ QPixmap p2;
+ p1 = new QPixmap(2, 3);
+ key = QPixmapCache::insert(*p1);
+ QVERIFY(QPixmapCache::find(key, &p2) != 0);
+ //we flush the cache
+ QPixmapCache::setCacheLimit(0);
+ QPixmapCache::setCacheLimit(1000);
+ QPixmapCache::Key key2 = QPixmapCache::insert(*p1);
+ QCOMPARE(getPrivate(key2)->key, 2);
+ QVERIFY(QPixmapCache::find(key, &p2) == 0);
+ QVERIFY(QPixmapCache::find(key2, &p2) != 0);
+ QCOMPARE(p2, *p1);
+
+ delete p1;
+
+ //Here we simulate the flushing when the app is idle
+ /*QPixmapCache::clear();
+ QPixmapCache::setCacheLimit(originalCacheLimit);
+ p1 = new QPixmap(300, 300);
+ key = QPixmapCache::insert(*p1);
+ QCOMPARE(getPrivate(key)->key, 1);
+ key2 = QPixmapCache::insert(*p1);
+ key2 = QPixmapCache::insert(*p1);
+ QPixmapCache::Key key3 = QPixmapCache::insert(*p1);
+ QTest::qWait(32000);
+ key2 = QPixmapCache::insert(*p1);
+ QCOMPARE(getPrivate(key2)->key, 1);
+ //This old key is not valid anymore after the flush
+ QCOMPARE(getPrivate(key)->isValid, false);
+ QVERIFY(QPixmapCache::find(key, &p2) == 0);
+ delete p1;*/
}
void tst_QPixmapCache::find()
@@ -137,6 +212,28 @@ void tst_QPixmapCache::find()
QPixmap *p3 = QPixmapCache::find("P1");
QVERIFY(p3);
QCOMPARE(p1, *p3);
+
+ //The int part of the API
+ QPixmapCache::Key key = QPixmapCache::insert(p1);
+
+ QVERIFY(QPixmapCache::find(key, &p2));
+ QCOMPARE(p2.width(), 10);
+ QCOMPARE(p2.height(), 10);
+ QCOMPARE(p1, p2);
+
+ QPixmapCache::clear();
+
+ key = QPixmapCache::insert(p1);
+
+ //The int part of the API
+ // make sure it doesn't explode
+ QList<QPixmapCache::Key> keys;
+ for (int i = 0; i < 40000; ++i)
+ QPixmapCache::insert(p1);
+
+ //at that time the first key has been erase because no more place in the cache
+ QVERIFY(QPixmapCache::find(key, &p1) == 0);
+ QCOMPARE(getPrivate(key)->isValid, false);
}
void tst_QPixmapCache::insert()
@@ -152,18 +249,22 @@ void tst_QPixmapCache::insert()
QPixmapCache::insert("0", p1);
// ditto
- for (int j = 0; j < 20000; ++j)
+ for (int j = 0; j < 40000; ++j)
QPixmapCache::insert(QString::number(j), p1);
int num = 0;
- for (int k = 0; k < 20000; ++k) {
+ for (int k = 0; k < 40000; ++k) {
if (QPixmapCache::find(QString::number(k)))
++num;
}
+ if (QPixmapCache::find("0"))
+ ++num;
+
int estimatedNum = (1024 * QPixmapCache::cacheLimit())
/ ((p1.width() * p1.height() * p1.depth()) / 8);
- QVERIFY(estimatedNum - 1 <= num <= estimatedNum + 1);
+
+ QVERIFY(num <= estimatedNum);
QPixmap p3;
QPixmapCache::insert("null", p3);
@@ -176,6 +277,50 @@ void tst_QPixmapCache::insert()
QPixmapCache::insert("custom", c2);
//We have deleted the old pixmap in the cache for the same key
QVERIFY(c1.isDetached());
+
+ //The int part of the API
+ // make sure it doesn't explode
+ QList<QPixmapCache::Key> keys;
+ for (int i = 0; i < 40000; ++i)
+ keys.append(QPixmapCache::insert(p1));
+
+ num = 0;
+ for (int k = 0; k < 40000; ++k) {
+ if (QPixmapCache::find(keys.at(k), &p2))
+ ++num;
+ }
+
+ estimatedNum = (1024 * QPixmapCache::cacheLimit())
+ / ((p1.width() * p1.height() * p1.depth()) / 8);
+ QVERIFY(num <= estimatedNum);
+ QPixmapCache::insert(p3);
+
+}
+
+void tst_QPixmapCache::replace()
+{
+ //The int part of the API
+ QPixmap p1(10, 10);
+ p1.fill(Qt::red);
+
+ QPixmap p2(10, 10);
+ p2.fill(Qt::yellow);
+
+ QPixmapCache::Key key = QPixmapCache::insert(p1);
+
+ QPixmap p3;
+ QVERIFY(QPixmapCache::find(key, &p3) == 1);
+
+ QPixmapCache::replace(key,p2);
+
+ QVERIFY(QPixmapCache::find(key, &p3) == 1);
+
+ QCOMPARE(p3.width(), 10);
+ QCOMPARE(p3.height(), 10);
+ QCOMPARE(p3, p2);
+
+ //Broken keys
+ QCOMPARE(QPixmapCache::replace(QPixmapCache::Key(), p2), false);
}
void tst_QPixmapCache::remove()
@@ -198,6 +343,48 @@ void tst_QPixmapCache::remove()
QPixmapCache::remove("green");
QVERIFY(QPixmapCache::find("green") == 0);
+
+ //The int part of the API
+ QPixmapCache::clear();
+ p1.fill(Qt::red);
+ QPixmapCache::Key key = QPixmapCache::insert(p1);
+ p1.fill(Qt::yellow);
+
+ QVERIFY(QPixmapCache::find(key, &p2));
+ QVERIFY(p1.toImage() != p2.toImage());
+ QVERIFY(p1.toImage() == p1.toImage()); // sanity check
+
+ QPixmapCache::remove(key);
+ QVERIFY(QPixmapCache::find(key, &p1) == 0);
+
+ //Broken key
+ QPixmapCache::remove(QPixmapCache::Key());
+ QVERIFY(QPixmapCache::find(QPixmapCache::Key(), &p1) == 0);
+
+ //Test if keys are release
+ QPixmapCache::clear();
+ key = QPixmapCache::insert(p1);
+ QCOMPARE(getPrivate(key)->key, 1);
+ QPixmapCache::remove(key);
+ key = QPixmapCache::insert(p1);
+ QCOMPARE(getPrivate(key)->key, 1);
+
+ //Test if pixmaps are correctly deleted
+ QPixmapCache::clear();
+ key = QPixmapCache::insert(p1);
+ QCOMPARE(getPrivate(key)->key, 1);
+ QVERIFY(QPixmapCache::find(key, &p1) != 0);
+ QPixmapCache::remove(key);
+ QCOMPARE(p1.isDetached(), true);
+
+ //We mix both part of the API
+ QPixmapCache::clear();
+ p1.fill(Qt::red);
+ QPixmapCache::insert("red", p1);
+ key = QPixmapCache::insert(p1);
+ QPixmapCache::remove(key);
+ QVERIFY(QPixmapCache::find(key, &p1) == 0);
+ QVERIFY(QPixmapCache::find("red") != 0);
}
void tst_QPixmapCache::clear()
@@ -205,12 +392,11 @@ void tst_QPixmapCache::clear()
QPixmap p1(10, 10);
p1.fill(Qt::red);
- for (int i = 0; i < 20000; ++i) {
+ for (int i = 0; i < 20000; ++i)
QVERIFY(QPixmapCache::find("x" + QString::number(i)) == 0);
- }
- for (int j = 0; j < 20000; ++j) {
+
+ for (int j = 0; j < 20000; ++j)
QPixmapCache::insert(QString::number(j), p1);
- }
int num = 0;
for (int k = 0; k < 20000; ++k) {
@@ -221,10 +407,68 @@ void tst_QPixmapCache::clear()
QPixmapCache::clear();
- for (int k = 0; k < 20000; ++k) {
+ for (int k = 0; k < 20000; ++k)
QVERIFY(QPixmapCache::find(QString::number(k)) == 0);
+
+ //The int part of the API
+ QPixmap p2(10, 10);
+ p2.fill(Qt::red);
+
+ QList<QPixmapCache::Key> keys;
+ for (int k = 0; k < 20000; ++k)
+ keys.append(QPixmapCache::insert(p2));
+
+ QPixmapCache::clear();
+
+ for (int k = 0; k < 20000; ++k) {
+ QVERIFY(QPixmapCache::find(keys.at(k), &p1) == 0);
+ QCOMPARE(getPrivate(keys[k])->isValid, false);
}
}
+void tst_QPixmapCache::pixmapKey()
+{
+ QPixmapCache::Key key;
+ //Default constructed keys have no d pointer unless
+ //we use them
+ QVERIFY(!getPrivate(key));
+ //Let's put a d pointer
+ QPixmapCache::KeyData** keyd = getPrivateRef(key);
+ *keyd = new QPixmapCache::KeyData;
+ QCOMPARE(getPrivate(key)->ref, 1);
+ QPixmapCache::Key key2;
+ //Let's put a d pointer
+ QPixmapCache::KeyData** key2d = getPrivateRef(key2);
+ *key2d = new QPixmapCache::KeyData;
+ QCOMPARE(getPrivate(key2)->ref, 1);
+ key = key2;
+ QCOMPARE(getPrivate(key2)->ref, 2);
+ QCOMPARE(getPrivate(key)->ref, 2);
+ QPixmapCache::Key key3;
+ //Let's put a d pointer
+ QPixmapCache::KeyData** key3d = getPrivateRef(key3);
+ *key3d = new QPixmapCache::KeyData;
+ QPixmapCache::Key key4 = key3;
+ QCOMPARE(getPrivate(key3)->ref, 2);
+ QCOMPARE(getPrivate(key4)->ref, 2);
+ key4 = key;
+ QCOMPARE(getPrivate(key4)->ref, 3);
+ QCOMPARE(getPrivate(key3)->ref, 1);
+ QPixmapCache::Key key5(key3);
+ QCOMPARE(getPrivate(key3)->ref, 2);
+ QCOMPARE(getPrivate(key5)->ref, 2);
+
+ //let test default constructed keys
+ QPixmapCache::Key key6;
+ QVERIFY(!getPrivate(key6));
+ QPixmapCache::Key key7;
+ QVERIFY(!getPrivate(key7));
+ key6 = key7;
+ QVERIFY(!getPrivate(key6));
+ QVERIFY(!getPrivate(key7));
+ QPixmapCache::Key key8(key7);
+ QVERIFY(!getPrivate(key8));
+}
+
QTEST_MAIN(tst_QPixmapCache)
#include "tst_qpixmapcache.moc"
diff --git a/tests/auto/qprinter/tst_qprinter.cpp b/tests/auto/qprinter/tst_qprinter.cpp
index cde4ae5..221e3b0 100644
--- a/tests/auto/qprinter/tst_qprinter.cpp
+++ b/tests/auto/qprinter/tst_qprinter.cpp
@@ -953,8 +953,9 @@ void tst_QPrinter::printDialogCompleter()
QTest::qWait(100);
- QTest::keyClick(0, Qt::Key_Tab);
- QTest::keyClick(0, 'P');
+ QTest::keyClick(&dialog, Qt::Key_Tab);
+ QTest::keyClick(&dialog, 'P');
+ // The test passes if it doesn't crash.
#endif
}
diff --git a/tests/auto/qpropertyanimation/qpropertyanimation.pro b/tests/auto/qpropertyanimation/qpropertyanimation.pro
new file mode 100644
index 0000000..6d6ddbf
--- /dev/null
+++ b/tests/auto/qpropertyanimation/qpropertyanimation.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qpropertyanimation.cpp
+
+
diff --git a/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
new file mode 100644
index 0000000..0aeac91
--- /dev/null
+++ b/tests/auto/qpropertyanimation/tst_qpropertyanimation.cpp
@@ -0,0 +1,958 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <QtCore/qpropertyanimation.h>
+#include <QtCore/qvariantanimation.h>
+#include <QtGui/qwidget.h>
+
+//TESTED_CLASS=QPropertyAnimation
+//TESTED_FILES=
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void updateCurrentTime(int msecs)
+ {
+ QPropertyAnimation::updateCurrentTime(msecs);
+ if (msecs >= QPropertyAnimation::duration())
+ stop();
+ }
+};
+
+class MyObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal x READ x WRITE setX)
+public:
+ MyObject() : m_x(0) { }
+ qreal x() const { return m_x; }
+ void setX(qreal x) { m_x = x; }
+private:
+ qreal m_x;
+};
+
+class tst_QPropertyAnimation : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QPropertyAnimation();
+ virtual ~tst_QPropertyAnimation();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime_data();
+ void setCurrentTime();
+ void statesAndSignals_data();
+ void statesAndSignals();
+ void deletion1();
+ void deletion2();
+ void deletion3();
+ void duration0();
+ void noStartValue();
+ void noStartValueWithLoop();
+ void startWhenAnotherIsRunning();
+ void easingcurve_data();
+ void easingcurve();
+ void startWithoutStartValue();
+ void playForwardBackward();
+ void interpolated();
+ void setStartEndValues_data();
+ void setStartEndValues();
+ void zeroDurationStart();
+ void operationsInStates_data();
+ void operationsInStates();
+ void oneKeyValue();
+ void updateOnSetKeyValues();
+};
+
+tst_QPropertyAnimation::tst_QPropertyAnimation()
+{
+}
+
+tst_QPropertyAnimation::~tst_QPropertyAnimation()
+{
+}
+
+void tst_QPropertyAnimation::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+ qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy");
+}
+
+void tst_QPropertyAnimation::cleanup()
+{
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+ Q_PROPERTY(qreal realValue READ realValue WRITE setRealValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ qreal realValue() const { return rv; }
+ void setRealValue(qreal value) { rv = value; }
+
+ int v;
+ qreal rv;
+};
+
+
+void tst_QPropertyAnimation::construction()
+{
+ QPropertyAnimation panimation;
+}
+
+void tst_QPropertyAnimation::setCurrentTime_data()
+{
+ QTest::addColumn<int>("duration");
+ QTest::addColumn<int>("loopCount");
+ QTest::addColumn<int>("currentTime");
+ QTest::addColumn<int>("testCurrentTime");
+ QTest::addColumn<int>("testCurrentLoop");
+
+ QTest::newRow("-1") << -1 << 1 << 0 << 0 << 0;
+ QTest::newRow("0") << 0 << 1 << 0 << 0 << 0;
+ QTest::newRow("1") << 0 << 1 << 1 << 0 << 0;
+ QTest::newRow("2") << 0 << 2 << 1 << 0 << 0;
+ QTest::newRow("3") << 1 << 1 << 0 << 0 << 0;
+ QTest::newRow("4") << 1 << 1 << 1 << 1 << 0;
+ QTest::newRow("5") << 1 << 2 << 1 << 0 << 1;
+ QTest::newRow("6") << 1 << 2 << 2 << 1 << 1;
+ QTest::newRow("7") << 1 << 2 << 3 << 1 << 1;
+ QTest::newRow("8") << 1 << 3 << 2 << 0 << 2;
+ QTest::newRow("9") << 1 << 3 << 3 << 1 << 2;
+ QTest::newRow("a") << 10 << 1 << 0 << 0 << 0;
+ QTest::newRow("b") << 10 << 1 << 1 << 1 << 0;
+ QTest::newRow("c") << 10 << 1 << 10 << 10 << 0;
+ QTest::newRow("d") << 10 << 2 << 10 << 0 << 1;
+ QTest::newRow("e") << 10 << 2 << 11 << 1 << 1;
+ QTest::newRow("f") << 10 << 2 << 20 << 10 << 1;
+ QTest::newRow("g") << 10 << 2 << 21 << 10 << 1;
+ QTest::newRow("negloop 0") << 10 << -1 << 0 << 0 << 0;
+ QTest::newRow("negloop 1") << 10 << -1 << 10 << 0 << 1;
+ QTest::newRow("negloop 2") << 10 << -1 << 15 << 5 << 1;
+ QTest::newRow("negloop 3") << 10 << -1 << 20 << 0 << 2;
+ QTest::newRow("negloop 4") << 10 << -1 << 30 << 0 << 3;
+}
+
+void tst_QPropertyAnimation::setCurrentTime()
+{
+ QFETCH(int, duration);
+ QFETCH(int, loopCount);
+ QFETCH(int, currentTime);
+ QFETCH(int, testCurrentTime);
+ QFETCH(int, testCurrentLoop);
+
+ QPropertyAnimation animation;
+ if (duration < 0)
+ QTest::ignoreMessage(QtWarningMsg, "QVariantAnimation::setDuration: cannot set a negative duration");
+ animation.setDuration(duration);
+ animation.setLoopCount(loopCount);
+ animation.setCurrentTime(currentTime);
+
+ QCOMPARE(animation.currentTime(), testCurrentTime);
+ QCOMPARE(animation.currentLoop(), testCurrentLoop);
+}
+
+void tst_QPropertyAnimation::statesAndSignals_data()
+{
+ QTest::addColumn<bool>("uncontrolled");
+ QTest::newRow("normal animation") << false;
+ QTest::newRow("animation with undefined duration") << true;
+}
+
+void tst_QPropertyAnimation::statesAndSignals()
+{
+ QFETCH(bool, uncontrolled);
+ QPropertyAnimation *anim = uncontrolled ? new UncontrolledAnimation : new QPropertyAnimation;
+ anim->setDuration(100);
+
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy currentLoopSpy(anim, SIGNAL(currentLoopChanged(int)));
+
+ anim->setCurrentTime(1);
+ anim->setCurrentTime(100);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(runningSpy.count(), 0);
+ QCOMPARE(currentLoopSpy.count(), 0);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+
+ anim->setLoopCount(3);
+ anim->setCurrentTime(101);
+
+ if (uncontrolled)
+ QSKIP("Uncontrolled animations don't handle looping", SkipSingle);
+
+ QCOMPARE(currentLoopSpy.count(), 1);
+ QCOMPARE(anim->currentLoop(), 1);
+
+ anim->setCurrentTime(0);
+ QCOMPARE(currentLoopSpy.count(), 2);
+ QCOMPARE(anim->currentLoop(), 0);
+
+ anim->start();
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(runningSpy.count(), 1); //anim must have started
+ QCOMPARE(anim->currentLoop(), 0);
+ runningSpy.clear();
+
+ anim->stop();
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 1); //anim must have stopped
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(anim->currentTime(), 0);
+ QCOMPARE(anim->currentLoop(), 0);
+ QCOMPARE(currentLoopSpy.count(), 2);
+ runningSpy.clear();
+
+ anim->start();
+ QTest::qWait(1000);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 2); //started and stopped again
+ runningSpy.clear();
+ QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(anim->currentTime(), 100);
+ QCOMPARE(anim->currentLoop(), 2);
+ QCOMPARE(currentLoopSpy.count(), 4);
+
+ anim->start(); // auto-rewinds
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(anim->currentTime(), 0);
+ QCOMPARE(anim->currentLoop(), 0);
+ QCOMPARE(currentLoopSpy.count(), 5);
+ QCOMPARE(runningSpy.count(), 1); // anim has started
+ QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(anim->currentLoop(), 0);
+ runningSpy.clear();
+
+ QTest::qWait(1000);
+
+ QCOMPARE(currentLoopSpy.count(), 7);
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim->currentLoop(), 2);
+ QCOMPARE(runningSpy.count(), 1); // anim has stopped
+ QCOMPARE(finishedSpy.count(), 2);
+ QCOMPARE(anim->currentTime(), 100);
+
+ delete anim;
+}
+
+void tst_QPropertyAnimation::deletion1()
+{
+ QObject *object = new QWidget;
+ QPointer<QPropertyAnimation> anim = new QPropertyAnimation(object, "minimumWidth");
+
+ //test that the animation is deleted correctly depending of the deletion flag passed in start()
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+ anim->start();
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(100);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(150);
+ QVERIFY(anim); //The animation should not have been deleted
+ QCOMPARE(anim->state(), QAnimationGroup::Stopped);
+ QCOMPARE(runningSpy.count(), 2);
+ QCOMPARE(finishedSpy.count(), 1);
+
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(100);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QTest::qWait(150);
+ QVERIFY(!anim); //The animation must have been deleted
+ QCOMPARE(runningSpy.count(), 4);
+ QCOMPARE(finishedSpy.count(), 2);
+ delete object;
+}
+
+void tst_QPropertyAnimation::deletion2()
+{
+ //test that the animation get deleted if the object is deleted
+ QObject *object = new QWidget;
+ QPointer<QPropertyAnimation> anim = new QPropertyAnimation(object,"minimumWidth");
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+ anim->start();
+
+ QTest::qWait(50);
+ QVERIFY(anim);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ //we can't call deletaLater directly because the delete would only happen in the next loop of _this_ event loop
+ QTimer::singleShot(0, object, SLOT(deleteLater()));
+ QTest::qWait(50);
+
+ QVERIFY(anim->targetObject() == 0);
+}
+
+void tst_QPropertyAnimation::deletion3()
+{
+ //test that the stopped signal is emit when the animation is destroyed
+ QObject *object = new QWidget;
+ QPropertyAnimation *anim = new QPropertyAnimation(object,"minimumWidth");
+ anim->setStartValue(10);
+ anim->setEndValue(20);
+ anim->setDuration(200);
+
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy finishedSpy(anim, SIGNAL(finished()));
+ anim->start();
+
+ QTest::qWait(50);
+ QCOMPARE(anim->state(), QAnimationGroup::Running);
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+ delete anim;
+ QCOMPARE(runningSpy.count(), 2);
+ QCOMPARE(finishedSpy.count(), 0);
+}
+
+void tst_QPropertyAnimation::duration0()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setEndValue(43);
+ QVERIFY(!animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+ animation.setDuration(0);
+ animation.start();
+ QCOMPARE(animation.state(), QAnimationGroup::Stopped);
+ QCOMPARE(animation.currentTime(), 0);
+ QCOMPARE(o.property("ole").toInt(), 43);
+}
+
+class StartValueTester : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int ole READ ole WRITE setOle)
+public:
+ StartValueTester() : o(0) { }
+ int ole() const { return o; }
+ void setOle(int v) { o = v; values << v; }
+
+ int o;
+ QList<int> values;
+};
+
+void tst_QPropertyAnimation::noStartValue()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ QPropertyAnimation a(&o, "ole");
+ a.setEndValue(420);
+ a.setDuration(250);
+ a.start();
+
+ QTest::qWait(300);
+
+ QCOMPARE(o.values.first(), 42);
+ QCOMPARE(o.values.last(), 420);
+}
+
+void tst_QPropertyAnimation::noStartValueWithLoop()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ QPropertyAnimation a(&o, "ole");
+ a.setEndValue(420);
+ a.setDuration(250);
+ a.setLoopCount(2);
+ a.start();
+
+ a.setCurrentTime(250);
+ QCOMPARE(o.values.first(), 42);
+ QCOMPARE(a.currentValue().toInt(), 42);
+ QCOMPARE(o.values.last(), 42);
+
+ a.setCurrentTime(500);
+ QCOMPARE(a.currentValue().toInt(), 420);
+}
+
+void tst_QPropertyAnimation::startWhenAnotherIsRunning()
+{
+ StartValueTester o;
+ o.setProperty("ole", 42);
+ o.values.clear();
+
+ {
+ //normal case: the animation finishes and is deleted
+ QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole");
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QTest::qWait(anim->duration() + 50);
+ QCOMPARE(runningSpy.count(), 2); //started and then stopped
+ QVERIFY(!anim);
+ }
+
+ {
+ QPointer<QVariantAnimation> anim = new QPropertyAnimation(&o, "ole");
+ QSignalSpy runningSpy(anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim->start(QVariantAnimation::DeleteWhenStopped);
+ QTest::qWait(anim->duration()/2);
+ QPointer<QVariantAnimation> anim2 = new QPropertyAnimation(&o, "ole");
+ QCOMPARE(runningSpy.count(), 1);
+ QCOMPARE(anim->state(), QVariantAnimation::Running);
+
+ //anim2 will interrupt anim1
+ QMetaObject::invokeMethod(anim2, "start", Qt::QueuedConnection, Q_ARG(QAbstractAnimation::DeletionPolicy, QVariantAnimation::DeleteWhenStopped));
+ QTest::qWait(50);
+ QVERIFY(!anim); //anim should have been deleted
+ QVERIFY(anim2);
+ QTest::qWait(anim2->duration());
+ QVERIFY(!anim2); //anim2 is finished: it should have been deleted by now
+ QVERIFY(!anim);
+ }
+
+}
+
+// copy from easing.cpp in case that function changes definition
+static qreal easeInOutBack(qreal t)
+{
+ qreal s = 1.70158;
+ qreal t_adj = 2.0f * (qreal)t;
+ if (t_adj < 1) {
+ s *= 1.525f;
+ return 1.0/2*(t_adj*t_adj*((s+1)*t_adj - s));
+ } else {
+ t_adj -= 2;
+ s *= 1.525f;
+ return 1.0/2*(t_adj*t_adj*((s+1)*t_adj + s) + 2);
+ }
+}
+
+void tst_QPropertyAnimation::easingcurve_data()
+{
+ QTest::addColumn<int>("currentTime");
+ QTest::addColumn<int>("expectedvalue");
+
+ QTest::newRow("interpolation1") << 0 << 0;
+ QTest::newRow("interpolation2") << 1000 << 1000;
+ QTest::newRow("extrapolationbelow") << 250 << -99;
+ QTest::newRow("extrapolationabove") << 750 << 1099;
+}
+
+void tst_QPropertyAnimation::easingcurve()
+{
+ QFETCH(int, currentTime);
+ QFETCH(int, expectedvalue);
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation pAnimation(&o, "ole");
+ pAnimation.setStartValue(0);
+ pAnimation.setEndValue(1000);
+ pAnimation.setDuration(1000);
+
+ // this easingcurve assumes that we extrapolate before startValue and after endValue
+ QEasingCurve easingCurve;
+ easingCurve.setCustomType(easeInOutBack);
+ pAnimation.setEasingCurve(easingCurve);
+ pAnimation.start();
+ pAnimation.pause();
+ pAnimation.setCurrentTime(currentTime);
+ QCOMPARE(o.property("ole").toInt(), expectedvalue);
+}
+
+void tst_QPropertyAnimation::startWithoutStartValue()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim(&o, "ole");
+ anim.setEndValue(100);
+
+ anim.start();
+
+ QTest::qWait(100);
+ int current = anim.currentValue().toInt();
+ //it is somewhere in the animation
+ QVERIFY(current > 42);
+ QVERIFY(current < 100);
+
+ QTest::qWait(200);
+ QCOMPARE(anim.state(), QVariantAnimation::Stopped);
+
+ anim.setEndValue(110);
+ anim.start();
+ current = anim.currentValue().toInt();
+ // the default start value will reevaluate the current property
+ // and set it to the end value of the last iteration
+ QCOMPARE(current, 100);
+ QTest::qWait(100);
+ current = anim.currentValue().toInt();
+ //it is somewhere in the animation
+ QVERIFY(current >= 100);
+ QVERIFY(current <= 110);
+}
+
+void tst_QPropertyAnimation::playForwardBackward()
+{
+ QObject o;
+ o.setProperty("ole", 0);
+ QCOMPARE(o.property("ole").toInt(), 0);
+
+ QPropertyAnimation anim(&o, "ole");
+ anim.setEndValue(100);
+ anim.start();
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), anim.duration());
+
+ //the animation is at the end
+ anim.setDirection(QVariantAnimation::Backward);
+ anim.start();
+ QCOMPARE(anim.state(), QAbstractAnimation::Running);
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), 0);
+
+ //the direction is backward
+ //restarting should jump to the end
+ anim.start();
+ QCOMPARE(anim.state(), QAbstractAnimation::Running);
+ QCOMPARE(anim.currentTime(), anim.duration());
+ QTest::qWait(anim.duration() + 50);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(anim.currentTime(), 0);
+}
+
+struct Number
+{
+ Number() {}
+ Number(int n)
+ : n(n) {}
+
+ Number(const Number &other)
+ : n(other.n){}
+
+ Number &operator=(const Number &other) {
+ n = other.n;
+ return *this;
+ }
+ bool operator==(const Number &other) const {
+ return n == other.n;
+ }
+
+ int n;
+};
+
+Q_DECLARE_METATYPE(Number)
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+
+QVariant numberInterpolator(const Number &f, const Number &t, qreal progress)
+{
+ return qVariantFromValue<Number>(Number(f.n + (t.n - f.n)*progress));
+}
+
+QVariant xaxisQPointInterpolator(const QPointF &f, const QPointF &t, qreal progress)
+{
+ return QPointF(f.x() + (t.x() - f.x())*progress, f.y());
+}
+
+void tst_QPropertyAnimation::interpolated()
+{
+ QObject o;
+ o.setProperty("point", QPointF()); //this will avoid warnings
+ o.setProperty("number", qVariantFromValue<Number>(Number(42)));
+ QCOMPARE(qVariantValue<Number>(o.property("number")), Number(42));
+ {
+ qRegisterAnimationInterpolator<Number>(numberInterpolator);
+ QPropertyAnimation anim(&o, "number");
+ anim.setStartValue(qVariantFromValue<Number>(Number(0)));
+ anim.setEndValue(qVariantFromValue<Number>(Number(100)));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ Number t(qVariantValue<Number>(o.property("number")));
+ QCOMPARE(t, Number(10));
+ anim.setCurrentTime(500);
+ QCOMPARE(qVariantValue<Number>(o.property("number")), Number(50));
+ }
+ {
+ qRegisterAnimationInterpolator<QPointF>(xaxisQPointInterpolator);
+ QPropertyAnimation anim(&o, "point");
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(100, 100));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ QCOMPARE(o.property("point"), QVariant(QPointF(10, 0)));
+ anim.setCurrentTime(500);
+ QCOMPARE(o.property("point"), QVariant(QPointF(50, 0)));
+ }
+ {
+ // unregister it and see if we get back the default behaviour
+ qRegisterAnimationInterpolator<QPointF>(0);
+ QPropertyAnimation anim(&o, "point");
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(100, 100));
+ anim.setDuration(1000);
+ anim.start();
+ anim.pause();
+ anim.setCurrentTime(100);
+ QCOMPARE(o.property("point").toPointF(), QPointF(10, 10));
+ anim.setCurrentTime(500);
+ QCOMPARE(o.property("point").toPointF(), QPointF(50, 50));
+ }
+
+ {
+ // Interpolate a qreal property with a int interpolator
+ AnimationObject o1;
+ o1.setRealValue(42.42);
+ QPropertyAnimation anim(&o1, "realValue");
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.start();
+ QCOMPARE(o1.realValue(), qreal(0));
+ anim.setCurrentTime(250);
+ QCOMPARE(o1.realValue(), qreal(100));
+ }
+}
+
+Q_DECLARE_METATYPE(QVariant)
+
+void tst_QPropertyAnimation::setStartEndValues_data()
+{
+ QTest::addColumn<QByteArray>("propertyName");
+ QTest::addColumn<QVariant>("initialValue");
+ QTest::addColumn<QVariant>("startValue");
+ QTest::addColumn<QVariant>("endValue");
+
+ QTest::newRow("dynamic property") << QByteArray("ole") << QVariant(42) << QVariant(0) << QVariant(10);
+ QTest::newRow("real property, with unmatching types") << QByteArray("x") << QVariant(42.) << QVariant(0) << QVariant(10.);
+}
+
+void tst_QPropertyAnimation::setStartEndValues()
+{
+ MyObject object;
+ QFETCH(QByteArray, propertyName);
+ QFETCH(QVariant, initialValue);
+ QFETCH(QVariant, startValue);
+ QFETCH(QVariant, endValue);
+
+ //this tests the start value, end value and default start value
+ object.setProperty(propertyName, initialValue);
+ QPropertyAnimation anim(&object, propertyName);
+ QVariantAnimation::KeyValues values;
+ QCOMPARE(anim.keyValues(), values);
+
+ //let's add a start value
+ anim.setStartValue(startValue);
+ values << QVariantAnimation::KeyValue(0, startValue);
+ QCOMPARE(anim.keyValues(), values);
+
+ anim.setEndValue(endValue);
+ values << QVariantAnimation::KeyValue(1, endValue);
+ QCOMPARE(anim.keyValues(), values);
+
+ //now we can play with objects
+ QCOMPARE(object.property(propertyName).toDouble(), initialValue.toDouble());
+ anim.start();
+ QVERIFY(anim.startValue().isValid());
+ QCOMPARE(object.property(propertyName), anim.startValue());
+ anim.setCurrentTime(anim.duration()/2);
+ QCOMPARE(object.property(propertyName).toDouble(), (startValue.toDouble() + endValue.toDouble())/2 ); //just in the middle of the animation
+ anim.setCurrentTime(anim.duration()); //we go to the end of the animation
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped); //it should have stopped
+ QVERIFY(anim.endValue().isValid());
+ QCOMPARE(object.property(propertyName), anim.endValue()); //end of the animations
+
+ //now we remove the explicit start value and test the implicit one
+ anim.stop();
+ object.setProperty(propertyName, initialValue);
+
+ //let's reset the start value
+ values.remove(0);
+ anim.setStartValue(QVariant());
+ QCOMPARE(anim.keyValues(), values);
+ QVERIFY(!anim.startValue().isValid());
+
+ anim.start();
+ QCOMPARE(object.property(propertyName), initialValue);
+ anim.setCurrentTime(anim.duration()/2);
+ QCOMPARE(object.property(propertyName).toDouble(), (initialValue.toDouble() + endValue.toDouble())/2 ); //just in the middle of the animation
+ anim.setCurrentTime(anim.duration()); //we go to the end of the animation
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped); //it should have stopped
+ QVERIFY(anim.endValue().isValid());
+ QCOMPARE(object.property(propertyName), anim.endValue()); //end of the animations
+
+ //now we set back the startValue
+ anim.setStartValue(startValue);
+ QVERIFY(anim.startValue().isValid());
+ anim.start();
+ QCOMPARE(object.property(propertyName), startValue);
+}
+
+void tst_QPropertyAnimation::zeroDurationStart()
+{
+ QPropertyAnimation anim;
+ QSignalSpy spy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ anim.setDuration(0);
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ anim.start();
+ //the animation stops immediately
+ QCOMPARE(anim.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(spy.count(), 2);
+
+ //let's check the first state change
+ const QVariantList firstChange = spy.first();
+ //old state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.first()), QAbstractAnimation::Stopped);
+ //new state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(firstChange.last()), QAbstractAnimation::Running);
+
+ //let's check the first state change
+ const QVariantList secondChange = spy.last();
+ //old state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.first()), QAbstractAnimation::Running);
+ //new state
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(secondChange.last()), QAbstractAnimation::Stopped);
+}
+
+#define Pause 1
+#define Start 2
+#define Resume 3
+#define Stop 4
+
+void tst_QPropertyAnimation::operationsInStates_data()
+{
+ QTest::addColumn<QAbstractAnimation::State>("originState");
+ QTest::addColumn<int>("operation");
+ QTest::addColumn<QString>("expectedWarning");
+ QTest::addColumn<QAbstractAnimation::State>("expectedState");
+
+ QString pauseWarn(QLatin1String("QAbstractAnimation::pause: Cannot pause a stopped animation"));
+ QString resumeWarn(QLatin1String("QAbstractAnimation::resume: Cannot resume an animation that is not paused"));
+
+ QTest::newRow("S-pause") << QAbstractAnimation::Stopped << Pause << pauseWarn << QAbstractAnimation::Stopped;
+ QTest::newRow("S-start") << QAbstractAnimation::Stopped << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("S-resume") << QAbstractAnimation::Stopped << Resume << resumeWarn << QAbstractAnimation::Stopped;
+ QTest::newRow("S-stop") << QAbstractAnimation::Stopped << Stop << QString() << QAbstractAnimation::Stopped;
+
+ QTest::newRow("P-pause") << QAbstractAnimation::Paused << Pause << QString() << QAbstractAnimation::Paused;
+ QTest::newRow("P-start") << QAbstractAnimation::Paused << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("P-resume") << QAbstractAnimation::Paused << Resume << QString() << QAbstractAnimation::Running;
+ QTest::newRow("P-stop") << QAbstractAnimation::Paused << Stop << QString() << QAbstractAnimation::Stopped;
+
+ QTest::newRow("R-pause") << QAbstractAnimation::Running << Pause << QString() << QAbstractAnimation::Paused;
+ QTest::newRow("R-start") << QAbstractAnimation::Running << Start << QString() << QAbstractAnimation::Running;
+ QTest::newRow("R-resume") << QAbstractAnimation::Running << Resume << resumeWarn << QAbstractAnimation::Running;
+ QTest::newRow("R-stop") << QAbstractAnimation::Running << Stop << QString() << QAbstractAnimation::Stopped;
+}
+
+void tst_QPropertyAnimation::operationsInStates()
+{
+/**
+ * | pause() |start() |resume() |stop()
+ * ----------+------------+-----------+-----------+-------------------+
+ * Stopped | Stopped |Running |Stopped |Stopped |
+ * _| qWarning |restart |qWarning | |
+ * Paused | Paused |Running |Running |Stopped |
+ * _| | | | |
+ * Running | Paused |Running |Running |Stopped |
+ * | |restart |qWarning | |
+ * ----------+------------+-----------+-----------+-------------------+
+**/
+
+ QFETCH(QAbstractAnimation::State, originState);
+ QFETCH(int, operation);
+ QFETCH(QString, expectedWarning);
+ QFETCH(QAbstractAnimation::State, expectedState);
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QPropertyAnimation anim(&o, "ole");
+ QSignalSpy spy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ anim.stop();
+ switch (originState) {
+ case QAbstractAnimation::Stopped:
+ break;
+ case QAbstractAnimation::Paused:
+ anim.start();
+ anim.pause();
+ break;
+ case QAbstractAnimation::Running:
+ anim.start();
+ break;
+ }
+ if (!expectedWarning.isEmpty()) {
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(expectedWarning));
+ }
+ QCOMPARE(anim.state(), originState);
+ switch (operation) {
+ case Pause:
+ anim.pause();
+ break;
+ case Start:
+ anim.start();
+ break;
+ case Resume:
+ anim.resume();
+ break;
+ case Stop:
+ anim.stop();
+ break;
+ }
+
+ QCOMPARE(anim.state(), expectedState);
+}
+#undef Pause
+#undef Start
+#undef Resume
+#undef Stop
+
+void tst_QPropertyAnimation::oneKeyValue()
+{
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setStartValue(43);
+ animation.setEndValue(44);
+ animation.setDuration(100);
+
+ animation.setCurrentTime(0);
+
+ QVERIFY(animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 43);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ // remove the last key value
+ animation.setKeyValueAt(1.0, QVariant());
+
+ // we will neither interpolate, nor update the current value
+ // since there is only one 1 key value defined
+ animation.setCurrentTime(100);
+
+ // the animation should not have been modified
+ QVERIFY(animation.currentValue().isValid());
+ QCOMPARE(animation.currentValue().toInt(), 43);
+ QCOMPARE(o.property("ole").toInt(), 42);
+}
+
+void tst_QPropertyAnimation::updateOnSetKeyValues()
+{
+ QObject o;
+ o.setProperty("ole", 100);
+ QCOMPARE(o.property("ole").toInt(), 100);
+
+ QPropertyAnimation animation(&o, "ole");
+ animation.setStartValue(100);
+ animation.setEndValue(200);
+ animation.setDuration(100);
+
+ animation.setCurrentTime(50);
+ QCOMPARE(animation.currentValue().toInt(), 150);
+ animation.setKeyValueAt(0.0, 300);
+ QCOMPARE(animation.currentValue().toInt(), 250);
+
+ o.setProperty("ole", 100);
+ QPropertyAnimation animation2(&o, "ole");
+ QVariantAnimation::KeyValues kValues;
+ kValues << QVariantAnimation::KeyValue(0.0, 100) << QVariantAnimation::KeyValue(1.0, 200);
+ animation2.setKeyValues(kValues);
+ animation2.setDuration(100);
+ animation2.setCurrentTime(50);
+ QCOMPARE(animation2.currentValue().toInt(), 150);
+
+ kValues.clear();
+ kValues << QVariantAnimation::KeyValue(0.0, 300) << QVariantAnimation::KeyValue(1.0, 200);
+ animation2.setKeyValues(kValues);
+
+ QCOMPARE(animation2.currentValue().toInt(), animation.currentValue().toInt());
+}
+
+QTEST_MAIN(tst_QPropertyAnimation)
+#include "tst_qpropertyanimation.moc"
diff --git a/tests/auto/qringbuffer/qringbuffer.pro b/tests/auto/qringbuffer/qringbuffer.pro
new file mode 100644
index 0000000..91fb0a0
--- /dev/null
+++ b/tests/auto/qringbuffer/qringbuffer.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+SOURCES += tst_qringbuffer.cpp
+
+QT = core
+
+
diff --git a/tests/auto/qringbuffer/tst_qringbuffer.cpp b/tests/auto/qringbuffer/tst_qringbuffer.cpp
new file mode 100644
index 0000000..c741c2e
--- /dev/null
+++ b/tests/auto/qringbuffer/tst_qringbuffer.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include <private/qringbuffer_p.h>
+
+class tst_QRingBuffer : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QRingBuffer();
+ virtual ~tst_QRingBuffer();
+public slots:
+ void initTestCase();
+ void cleanupTestCase();
+private slots:
+ void readPointerAtPositionWriteRead();
+ void readPointerAtPositionEmptyRead();
+ void readPointerAtPositionWithHead();
+ void readPointerAtPositionReadTooMuch();
+ void sizeWhenEmpty();
+ void sizeWhenReservedAndChopped();
+ void sizeWhenReserved();
+};
+
+tst_QRingBuffer::tst_QRingBuffer()
+{
+}
+
+tst_QRingBuffer::~tst_QRingBuffer()
+{
+}
+
+void tst_QRingBuffer::initTestCase()
+{
+}
+
+void tst_QRingBuffer::cleanupTestCase()
+{
+}
+
+void tst_QRingBuffer::sizeWhenReserved()
+{
+ QRingBuffer ringBuffer;
+ ringBuffer.reserve(5);
+
+ QCOMPARE(ringBuffer.size(), 5);
+}
+
+void tst_QRingBuffer::sizeWhenReservedAndChopped()
+{
+ QRingBuffer ringBuffer;
+ ringBuffer.reserve(31337);
+ ringBuffer.chop(31337);
+
+ QCOMPARE(ringBuffer.size(), 0);
+}
+
+void tst_QRingBuffer::sizeWhenEmpty()
+{
+ QRingBuffer ringBuffer;
+
+ QCOMPARE(ringBuffer.size(), 0);
+}
+
+void tst_QRingBuffer::readPointerAtPositionReadTooMuch()
+{
+ QRingBuffer ringBuffer;
+
+ qint64 length;
+ const char *buf = ringBuffer.readPointerAtPosition(42, length);
+ QVERIFY(buf == 0);
+ QVERIFY(length == 0);
+}
+
+void tst_QRingBuffer::readPointerAtPositionWithHead()
+{
+ QRingBuffer ringBuffer;
+ char *buf = ringBuffer.reserve(4);
+ memcpy (buf, "0123", 4);
+ ringBuffer.free(2);
+
+ // ringBuffer should have stayed the same except
+ // its head it had moved to position 2
+ qint64 length;
+ const char* buf2 = ringBuffer.readPointerAtPosition(0, length);
+
+ QCOMPARE(length, qint64(2));
+ QVERIFY(*buf2 == '2');
+ QVERIFY(*(buf2+1) == '3');
+
+ // advance 2 more, ringBuffer should be empty then
+ ringBuffer.free(2);
+ buf2 = ringBuffer.readPointerAtPosition(0, length);
+ QCOMPARE(length, qint64(0));
+ QVERIFY(buf2 == 0);
+}
+
+void tst_QRingBuffer::readPointerAtPositionEmptyRead()
+{
+ QRingBuffer ringBuffer;
+
+ qint64 length;
+ const char *buf = ringBuffer.readPointerAtPosition(0, length);
+ QVERIFY(buf == 0);
+ QVERIFY(length == 0);
+}
+
+void tst_QRingBuffer::readPointerAtPositionWriteRead()
+{
+ //create some data
+ QBuffer inData;
+ inData.open(QIODevice::ReadWrite);
+ inData.putChar(0x42);
+ inData.putChar(0x23);
+ inData.write("Qt rocks!");
+ for (int i = 0; i < 5000; i++)
+ inData.write(QString("Number %1").arg(i).toUtf8());
+ inData.reset();
+ QVERIFY(inData.size() > 0);
+
+ //put the inData in the QRingBuffer
+ QRingBuffer ringBuffer;
+ qint64 remaining = inData.size();
+ while (remaining > 0) {
+ // write in chunks of 50 bytes
+ // this ensures there will be multiple QByteArrays inside the QRingBuffer
+ // since QRingBuffer is then only using individual arrays of around 4000 bytes
+ qint64 thisWrite = qMin(remaining, qint64(50));
+ char *pos = ringBuffer.reserve(thisWrite);
+ inData.read(pos, thisWrite);
+ remaining -= thisWrite;
+ }
+ // was data put into it?
+ QVERIFY(ringBuffer.size() > 0);
+ QCOMPARE(qint64(ringBuffer.size()), inData.size());
+
+ //read from the QRingBuffer in loop, put back into another QBuffer
+ QBuffer outData;
+ outData.open(QIODevice::ReadWrite);
+ remaining = ringBuffer.size();
+ while (remaining > 0) {
+ qint64 thisRead;
+ // always try to read as much as possible
+ const char *buf = ringBuffer.readPointerAtPosition(ringBuffer.size() - remaining, thisRead);
+ outData.write(buf, thisRead);
+ remaining -= thisRead;
+ }
+ outData.reset();
+
+ QVERIFY(outData.size() > 0);
+
+ // was the data read from the QRingBuffer the same as the one written into it?
+ QCOMPARE(outData.size(), inData.size());
+ QVERIFY(outData.buffer().startsWith(inData.buffer()));
+}
+
+
+QTEST_APPLESS_MAIN(tst_QRingBuffer)
+#include "tst_qringbuffer.moc"
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 5339fb4..fe60cd0 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -636,9 +636,21 @@ void tst_QScriptEngine::newQObject()
QScriptValue val = ret.property("objectName");
QVERIFY(val.isString());
}
+ // "promote" variant object to QObject
+ {
+ QScriptValue obj = eng.newVariant(123);
+ QVERIFY(obj.isVariant());
+ QScriptValue originalProto = obj.prototype();
+ QScriptValue ret = eng.newQObject(obj, this);
+ QVERIFY(ret.isQObject());
+ QVERIFY(ret.strictlyEquals(obj));
+ QVERIFY(obj.isQObject());
+ QCOMPARE(ret.toQObject(), (QObject *)this);
+ QVERIFY(ret.prototype().strictlyEquals(originalProto));
+ }
// replace QObject* of existing object
{
- QScriptValue object = eng.newQObject(this);
+ QScriptValue object = eng.newVariant(123);
QScriptValue originalProto = object.prototype();
QObject otherQObject;
QScriptValue ret = eng.newQObject(object, &otherQObject);
diff --git a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
index 9b9dd16..1025d2a 100644
--- a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
+++ b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
@@ -107,6 +107,7 @@ class MyQObject : public QObject
Q_PROPERTY(int readOnlyProperty READ readOnlyProperty)
Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
Q_PROPERTY(CustomType propWithCustomType READ propWithCustomType WRITE setPropWithCustomType)
+ Q_PROPERTY(Policy enumProperty READ enumProperty WRITE setEnumProperty)
Q_ENUMS(Policy Strategy)
Q_FLAGS(Ability)
@@ -144,6 +145,7 @@ public:
m_hiddenValue(456.0),
m_writeOnlyValue(789),
m_readOnlyValue(987),
+ m_enumValue(BarPolicy),
m_qtFunctionInvoked(-1)
{ }
@@ -205,6 +207,11 @@ public:
void setPropWithCustomType(const CustomType &c)
{ m_customType = c; }
+ Policy enumProperty() const
+ { return m_enumValue; }
+ void setEnumProperty(Policy policy)
+ { m_enumValue = policy; }
+
int qtFunctionInvoked() const
{ return m_qtFunctionInvoked; }
@@ -255,8 +262,8 @@ public:
{ m_qtFunctionInvoked = 36; m_actuals << policy; }
Q_INVOKABLE Policy myInvokableReturningEnum()
{ m_qtFunctionInvoked = 37; return BazPolicy; }
- Q_INVOKABLE MyQObject::Policy myInvokableReturningQualifiedEnum()
- { m_qtFunctionInvoked = 38; return BazPolicy; }
+ Q_INVOKABLE MyQObject::Strategy myInvokableReturningQualifiedEnum()
+ { m_qtFunctionInvoked = 38; return BazStrategy; }
Q_INVOKABLE QVector<int> myInvokableReturningVectorOfInt()
{ m_qtFunctionInvoked = 11; return QVector<int>(); }
Q_INVOKABLE void myInvokableWithVectorOfIntArg(const QVector<int> &)
@@ -410,6 +417,7 @@ protected:
int m_readOnlyValue;
QKeySequence m_shortcut;
CustomType m_customType;
+ Policy m_enumValue;
int m_qtFunctionInvoked;
QVariantList m_actuals;
QByteArray m_connectedSignal;
@@ -417,6 +425,7 @@ protected:
};
Q_DECLARE_METATYPE(MyQObject*)
+Q_DECLARE_METATYPE(MyQObject::Policy)
class MyOtherQObject : public MyQObject
{
@@ -530,6 +539,24 @@ static QScriptValue getSetProperty(QScriptContext *ctx, QScriptEngine *)
return ctx->callee().property("value");
}
+static QScriptValue policyToScriptValue(QScriptEngine *engine, const MyQObject::Policy &policy)
+{
+ return qScriptValueFromValue(engine, policy);
+}
+
+static void policyFromScriptValue(const QScriptValue &value, MyQObject::Policy &policy)
+{
+ QString str = value.toString();
+ if (str == QLatin1String("red"))
+ policy = MyQObject::FooPolicy;
+ else if (str == QLatin1String("green"))
+ policy = MyQObject::BarPolicy;
+ else if (str == QLatin1String("blue"))
+ policy = MyQObject::BazPolicy;
+ else
+ policy = (MyQObject::Policy)-1;
+}
+
void tst_QScriptExtQObject::getSetStaticProperty()
{
QCOMPARE(m_engine->evaluate("myObject.noSuchProperty").isUndefined(), true);
@@ -751,6 +778,31 @@ void tst_QScriptExtQObject::getSetStaticProperty()
QScriptValue::ReadOnly);
}
+ // enum property
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy);
+ {
+ QScriptValue val = m_engine->evaluate("myObject.enumProperty");
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), (int)MyQObject::BarPolicy);
+ }
+ m_engine->evaluate("myObject.enumProperty = 2");
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy);
+ m_engine->evaluate("myObject.enumProperty = 'BarPolicy'");
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy);
+ m_engine->evaluate("myObject.enumProperty = 'ScoobyDoo'");
+ // ### ouch! Shouldn't QMetaProperty::write() rather not change the value...?
+ QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1);
+ // enum property with custom conversion
+ qScriptRegisterMetaType<MyQObject::Policy>(m_engine, policyToScriptValue, policyFromScriptValue);
+ m_engine->evaluate("myObject.enumProperty = 'red'");
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::FooPolicy);
+ m_engine->evaluate("myObject.enumProperty = 'green'");
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy);
+ m_engine->evaluate("myObject.enumProperty = 'blue'");
+ QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy);
+ m_engine->evaluate("myObject.enumProperty = 'nada'");
+ QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1);
+
// auto-dereferencing of pointers
{
QBrush b = QColor(0xCA, 0xFE, 0xBA, 0xBE);
@@ -1879,6 +1931,16 @@ void tst_QScriptExtQObject::classEnums()
QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BazPolicy));
m_myObject->resetQtFunctionInvoked();
+ QCOMPARE(m_engine->evaluate("myObject.myInvokableWithEnumArg('BarPolicy')").isUndefined(), true);
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 10);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QCOMPARE(m_myObject->qtFunctionActuals().at(0).toInt(), int(MyQObject::BarPolicy));
+
+ m_myObject->resetQtFunctionInvoked();
+ QVERIFY(m_engine->evaluate("myObject.myInvokableWithEnumArg('NoSuchPolicy')").isError());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), -1);
+
+ m_myObject->resetQtFunctionInvoked();
QCOMPARE(m_engine->evaluate("myObject.myInvokableWithQualifiedEnumArg(MyQObject.BazPolicy)").isUndefined(), true);
QCOMPARE(m_myObject->qtFunctionInvoked(), 36);
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
diff --git a/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro b/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro
new file mode 100644
index 0000000..ad861c3
--- /dev/null
+++ b/tests/auto/qsequentialanimationgroup/qsequentialanimationgroup.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qsequentialanimationgroup.cpp
+
+
diff --git a/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
new file mode 100644
index 0000000..0631343
--- /dev/null
+++ b/tests/auto/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
@@ -0,0 +1,1649 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include "../../shared/util.h"
+
+#include <QtCore/qanimationgroup.h>
+#include <QtCore/qsequentialanimationgroup.h>
+
+//TESTED_CLASS=QSequentialAnimationGroup
+//TESTED_FILES=
+
+Q_DECLARE_METATYPE(QAbstractAnimation::State)
+Q_DECLARE_METATYPE(QAbstractAnimation*)
+
+class tst_QSequentialAnimationGroup : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QSequentialAnimationGroup();
+ virtual ~tst_QSequentialAnimationGroup();
+
+public Q_SLOTS:
+ void init();
+ void cleanup();
+
+private slots:
+ void construction();
+ void setCurrentTime();
+ void setCurrentTimeWithUncontrolledAnimation();
+ void seekingForwards();
+ void seekingBackwards();
+ void pauseAndResume();
+ void restart();
+ void looping();
+ void startDelay();
+ void clearGroup();
+ void groupWithZeroDurationAnimations();
+ void propagateGroupUpdateToChildren();
+ void updateChildrenWithRunningGroup();
+ void deleteChildrenWithRunningGroup();
+ void startChildrenWithStoppedGroup();
+ void stopGroupWithRunningChild();
+ void startGroupWithRunningChild();
+ void zeroDurationAnimation();
+ void stopUncontrolledAnimations();
+ void finishWithUncontrolledAnimation();
+ void addRemoveAnimation();
+ void currentAnimation();
+ void currentAnimationWithZeroDuration();
+ void insertAnimation();
+ void clearAnimations();
+};
+
+tst_QSequentialAnimationGroup::tst_QSequentialAnimationGroup()
+{
+}
+
+tst_QSequentialAnimationGroup::~tst_QSequentialAnimationGroup()
+{
+}
+
+void tst_QSequentialAnimationGroup::init()
+{
+ qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
+ qRegisterMetaType<QAbstractAnimation*>("QAbstractAnimation*");
+}
+
+void tst_QSequentialAnimationGroup::cleanup()
+{
+}
+
+void tst_QSequentialAnimationGroup::construction()
+{
+ QSequentialAnimationGroup animationgroup;
+}
+
+class AnimationObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int value READ value WRITE setValue)
+public:
+ AnimationObject(int startValue = 0)
+ : v(startValue)
+ { }
+
+ int value() const { return v; }
+ void setValue(int value) { v = value; }
+
+ int v;
+};
+
+class TestAnimation : public QVariantAnimation
+{
+ Q_OBJECT
+public:
+ virtual void updateCurrentValue(const QVariant &value) { Q_UNUSED(value)};
+ virtual void updateState(QAbstractAnimation::State oldState,
+ QAbstractAnimation::State newState)
+ {
+ Q_UNUSED(oldState)
+ Q_UNUSED(newState)
+ };
+};
+
+class UncontrolledAnimation : public QPropertyAnimation
+{
+ Q_OBJECT
+public:
+ UncontrolledAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = 0)
+ : QPropertyAnimation(target, propertyName, parent)
+ {
+ setDuration(250);
+ }
+
+ int duration() const { return -1; /* not time driven */ }
+
+protected:
+ void updateCurrentTime(int msecs)
+ {
+ QPropertyAnimation::updateCurrentTime(msecs);
+ if (msecs >= QPropertyAnimation::duration())
+ stop();
+ }
+};
+
+void tst_QSequentialAnimationGroup::setCurrentTime()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 251
+ group.setCurrentTime(251);
+ QCOMPARE(group.currentTime(), 251);
+ QCOMPARE(sequence->currentTime(), 251);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 750
+ group.setCurrentTime(750);
+ QCOMPARE(group.currentTime(), 750);
+ QCOMPARE(sequence->currentTime(), 750);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1000
+ group.setCurrentTime(1000);
+ QCOMPARE(group.currentTime(), 1000);
+ QCOMPARE(sequence->currentTime(), 1000);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1010
+ group.setCurrentTime(1010);
+ QCOMPARE(group.currentTime(), 1010);
+ QCOMPARE(sequence->currentTime(), 1010);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 10);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1250
+ group.setCurrentTime(1250);
+ QCOMPARE(group.currentTime(), 1250);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1500
+ group.setCurrentTime(1500);
+ QCOMPARE(group.currentTime(), 1500);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+
+ // Current time = 2000
+ group.setCurrentTime(2000);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::setCurrentTimeWithUncontrolledAnimation()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject t_o1;
+ AnimationObject t_o2;
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a1_s_o2);
+
+ UncontrolledAnimation *notTimeDriven = new UncontrolledAnimation(&t_o1, "value");
+ QCOMPARE(notTimeDriven->totalDuration(), -1);
+
+ QVariantAnimation *loopsForever = new QPropertyAnimation(&t_o2, "value");
+ loopsForever->setLoopCount(-1);
+ QCOMPARE(loopsForever->totalDuration(), -1);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(notTimeDriven);
+ group.addAnimation(loopsForever);
+ group.start();
+ group.pause(); // this allows the group to listen for the finish signal of its children
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+
+ // Current time = 250
+ group.setCurrentTime(250);
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(sequence->currentTime(), 250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+
+ // Current time = 500
+ group.setCurrentTime(500);
+ QCOMPARE(group.currentTime(), 500);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 0);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), notTimeDriven);
+
+ // Current time = 505
+ group.setCurrentTime(505);
+ QCOMPARE(group.currentTime(), 505);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 5);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), notTimeDriven);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Paused);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+
+ // Current time = 750 (end of notTimeDriven animation)
+ group.setCurrentTime(750);
+ QCOMPARE(group.currentTime(), 750);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), loopsForever);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Paused);
+
+ // Current time = 800 (as notTimeDriven was finished at 750, loopsforever should still run)
+ group.setCurrentTime(800);
+ QCOMPARE(group.currentTime(), 800);
+ QCOMPARE(group.currentAnimation(), loopsForever);
+ QCOMPARE(sequence->currentTime(), 500);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(notTimeDriven->currentTime(), 250);
+ QCOMPARE(loopsForever->currentTime(), 50);
+
+ loopsForever->stop(); // this should stop the group
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven->state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::seekingForwards()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ // Current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // Current time = 1500
+ group.setCurrentTime(1500);
+ QCOMPARE(group.currentTime(), 1500);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 250);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ // this will restart the group
+ group.start();
+ group.pause();
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::seekingBackwards()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(3);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+
+ // sequence operating on different object/properties
+ QAnimationGroup *sequence2 = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o2 = new QPropertyAnimation(&s_o2, "value");
+ QVariantAnimation *a1_s_o3 = new QPropertyAnimation(&s_o3, "value");
+ sequence2->addAnimation(a1_s_o2);
+ sequence2->addAnimation(a1_s_o3);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+ group.addAnimation(sequence2);
+
+ group.start();
+
+ // Current time = 1600
+ group.setCurrentTime(1600);
+ QCOMPARE(group.currentTime(), 1600);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 350);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 100);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Running);
+
+ // Seeking backwards, current time = 1
+ group.setCurrentTime(1);
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a2_s_o1->currentTime(), 0);
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a2_s_o1->currentLoop(), 0);
+ QEXPECT_FAIL("", "rewinding in nested groups is considered as a restart from the children,"
+ "hence they don't reset from their current animation", Continue);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence2->currentTime(), 0);
+ QCOMPARE(a1_s_o2->currentTime(), 0);
+ QCOMPARE(a1_s_o3->currentTime(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Running);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+
+ // Current time = 2000
+ group.setCurrentTime(2000);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 1250);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 2);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+ QCOMPARE(sequence2->currentTime(), 500);
+ QCOMPARE(a1_s_o2->currentTime(), 250);
+ QCOMPARE(a1_s_o3->currentTime(), 250);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(sequence2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a1_s_o3->state(), QAnimationGroup::Stopped);
+}
+
+typedef QList<QAbstractAnimation::State> StateList;
+
+static bool compareStates(const QSignalSpy& spy, const StateList &expectedStates)
+{
+ bool equals = true;
+ for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
+ if (i >= spy.count() || i >= expectedStates.count()) {
+ equals = false;
+ break;
+ }
+ QList<QVariant> args = spy.at(i);
+ QAbstractAnimation::State st = expectedStates.at(i);
+ QAbstractAnimation::State actual = qVariantValue<QAbstractAnimation::State>(args.value(1));
+ if (equals && actual != st) {
+ equals = false;
+ break;
+ }
+ }
+ if (!equals) {
+ const char *stateStrings[] = {"Stopped", "Paused", "Running"};
+ QString e,a;
+ for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) {
+ if (i < expectedStates.count()) {
+ int exp = int(expectedStates.at(i));
+ if (!e.isEmpty())
+ e += QLatin1String(", ");
+ e += QLatin1String(stateStrings[exp]);
+ }
+ if (i < spy.count()) {
+ QList<QVariant> args = spy.at(i);
+ QAbstractAnimation::State actual = qVariantValue<QAbstractAnimation::State>(args.value(1));
+ if (!a.isEmpty())
+ a += QLatin1String(", ");
+ if (int(actual) >= 0 && int(actual) <= 2) {
+ a += QLatin1String(stateStrings[int(actual)]);
+ } else {
+ a += QLatin1String("NaN");
+ }
+ }
+
+ }
+ qDebug("\n"
+ "expected (count == %d): %s\n"
+ "actual (count == %d): %s\n", expectedStates.count(), qPrintable(e), spy.count(), qPrintable(a));
+ }
+ return equals;
+}
+
+void tst_QSequentialAnimationGroup::pauseAndResume()
+{
+ AnimationObject s_o1;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ a2_s_o1->setLoopCount(2);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+ sequence->setLoopCount(2);
+
+ QSignalSpy a1StateChangedSpy(a1_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy seqStateChangedSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+
+ group.start();
+ group.pause();
+
+ // Current time = 1751
+ group.setCurrentTime(1751);
+ QCOMPARE(group.currentTime(), 1751);
+ QCOMPARE(sequence->currentTime(), 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 1);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QCOMPARE(a1StateChangedSpy.count(), 5); // Running,Paused,Stopped,Running,Stopped
+ QCOMPARE(seqStateChangedSpy.count(), 2); // Running,Paused
+
+ QVERIFY(compareStates(a1StateChangedSpy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped)));
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Paused);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(a1StateChangedSpy.at(4).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Paused);
+
+ group.resume();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(sequence->state(), QAnimationGroup::Running);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Running);
+
+ QVERIFY(group.currentTime() >= 1751);
+ QVERIFY(sequence->currentTime() >= 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QVERIFY(a3_s_o1->currentTime() >= 1);
+
+ QCOMPARE(seqStateChangedSpy.count(), 3); // Running,Paused,Running
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(2).at(1)),
+ QAnimationGroup::Running);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QVERIFY(group.currentTime() >= 1751);
+ QVERIFY(sequence->currentTime() >= 751);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QVERIFY(a3_s_o1->currentTime() >= 1);
+
+ QCOMPARE(seqStateChangedSpy.count(), 4); // Running,Paused,Running,Paused
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(3).at(1)),
+ QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(seqStateChangedSpy.count(), 5); // Running,Paused,Running,Paused,Stopped
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(4).at(1)),
+ QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::restart()
+{
+ AnimationObject s_o1;
+
+ // sequence operating on same object/property
+ QAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QSignalSpy seqCurrentAnimChangedSpy(sequence, SIGNAL(currentAnimationChanged(QAbstractAnimation*)));
+ QSignalSpy seqStateChangedSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QVariantAnimation *anims[3];
+ QSignalSpy *animsStateChanged[3];
+
+ for (int i = 0; i < 3; i++) {
+ anims[i] = new QPropertyAnimation(&s_o1, "value");
+ anims[i]->setDuration(100);
+ animsStateChanged[i] = new QSignalSpy(anims[i], SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ }
+
+ anims[1]->setLoopCount(2);
+ sequence->addAnimation(anims[0]);
+ sequence->addAnimation(anims[1]);
+ sequence->addAnimation(anims[2]);
+ sequence->setLoopCount(2);
+
+ QSequentialAnimationGroup group;
+ group.addAnimation(sequence);
+
+ group.start();
+
+ QTest::qWait(500);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+ QTest::qWait(300);
+ QTRY_COMPARE(group.state(), QAnimationGroup::Stopped);
+
+ for (int i = 0; i < 3; i++) {
+ QCOMPARE(animsStateChanged[i]->count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(1).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(2).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(animsStateChanged[i]->at(3).at(1)),
+ QAnimationGroup::Stopped);
+ }
+
+ QCOMPARE(seqStateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(seqStateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(seqCurrentAnimChangedSpy.count(), 6);
+ for(int i=0; i<seqCurrentAnimChangedSpy.count(); i++)
+ QCOMPARE(anims[i%3], qVariantValue<QAbstractAnimation*>(seqCurrentAnimChangedSpy.at(i).at(0)));
+
+ group.start();
+
+ QCOMPARE(animsStateChanged[0]->count(), 5);
+ QCOMPARE(animsStateChanged[1]->count(), 4);
+ QCOMPARE(animsStateChanged[2]->count(), 4);
+ QCOMPARE(seqStateChangedSpy.count(), 3);
+}
+
+void tst_QSequentialAnimationGroup::looping()
+{
+ AnimationObject s_o1;
+ AnimationObject s_o2;
+ AnimationObject s_o3;
+
+ // sequence operating on same object/property
+ QSequentialAnimationGroup *sequence = new QSequentialAnimationGroup();
+ QVariantAnimation *a1_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a2_s_o1 = new QPropertyAnimation(&s_o1, "value");
+ QVariantAnimation *a3_s_o1 = new QPropertyAnimation(&s_o1, "value");
+
+ QSignalSpy a1Spy(a1_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy a2Spy(a2_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy a3Spy(a3_s_o1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy seqSpy(sequence, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ a2_s_o1->setLoopCount(2);
+ sequence->addAnimation(a1_s_o1);
+ sequence->addAnimation(a2_s_o1);
+ sequence->addAnimation(a3_s_o1);
+ sequence->setLoopCount(2);
+
+ QSequentialAnimationGroup group;
+ QSignalSpy groupSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(sequence);
+ group.setLoopCount(2);
+
+ group.start();
+ group.pause();
+
+ // Current time = 1750
+ group.setCurrentTime(1750);
+ QCOMPARE(group.currentTime(), 1750);
+ QCOMPARE(sequence->currentTime(), 750);
+ QCOMPARE(sequence->currentLoop(), 1);
+ QCOMPARE(a1_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ // this animation is at the beginning because it is the current one inside sequence
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 0);
+ QCOMPARE(sequence->currentAnimation(), a3_s_o1);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Paused);
+
+ QCOMPARE(a1Spy.count(), 5); // Running,Paused,Stopped,Running,Stopped
+ QVERIFY(compareStates(a1Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped)));
+
+ QCOMPARE(a2Spy.count(), 4); // Running,Stopped,Running,Stopped
+ QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(seqSpy.count(), 2); // Running,Paused
+ QCOMPARE(groupSpy.count(), 2); // Running,Paused
+
+ // Looping, current time = duration + 1
+ group.setCurrentTime(group.duration() + 1);
+ QCOMPARE(group.currentTime(), 1);
+ QCOMPARE(group.currentLoop(), 1);
+ QCOMPARE(sequence->currentTime(), 1);
+ QCOMPARE(sequence->currentLoop(), 0);
+ QCOMPARE(a1_s_o1->currentTime(), 1);
+ QCOMPARE(a2_s_o1->currentTime(), 250);
+ QCOMPARE(a2_s_o1->currentLoop(), 1);
+ // this animation is at the end because it was run on the previous loop
+ QCOMPARE(a3_s_o1->currentLoop(), 0);
+ QCOMPARE(a3_s_o1->currentTime(), 250);
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(sequence->state(), QAnimationGroup::Paused);
+ QCOMPARE(a1_s_o1->state(), QAnimationGroup::Paused);
+ QCOMPARE(a2_s_o1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3_s_o1->state(), QAnimationGroup::Stopped);
+
+ QCOMPARE(a1Spy.count(), 7); // Running,Paused,Stopped,Running,Stopped,Running,Stopped
+ QCOMPARE(a2Spy.count(), 4); // Running, Stopped, Running, Stopped
+ QVERIFY(compareStates(a3Spy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped)));
+ QVERIFY(compareStates(seqSpy, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+ QCOMPARE(groupSpy.count(), 2);
+}
+
+void tst_QSequentialAnimationGroup::startDelay()
+{
+ QSequentialAnimationGroup group;
+ group.addPause(250);
+ group.addPause(125);
+ QCOMPARE(group.totalDuration(), 375);
+
+ QEventLoop loop;
+ QObject::connect(&group, SIGNAL(finished()), &loop, SLOT(quit()));
+
+ QTime time;
+ time.start();
+ group.start();
+ loop.exec();
+
+ QVERIFY(time.elapsed() >= 375);
+ QVERIFY(time.elapsed() < 1000);
+}
+
+void tst_QSequentialAnimationGroup::clearGroup()
+{
+ QSequentialAnimationGroup group;
+
+ for (int i = 0; i < 10; ++i) {
+ QSequentialAnimationGroup *subGroup = new QSequentialAnimationGroup(&group);
+ group.addPause(100);
+ subGroup->addPause(10);
+ }
+
+ QCOMPARE(group.animationCount(), 20);
+
+ int count = group.animationCount();
+ QPointer<QAbstractAnimation> *children = new QPointer<QAbstractAnimation>[count];
+ for (int i = 0; i < count; ++i) {
+ QVERIFY(group.animationAt(i) != 0);
+ children[i] = group.animationAt(i);
+ }
+
+ group.clearAnimations();
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ for (int i = 0; i < count; ++i)
+ QCOMPARE(children[i], QPointer<QAbstractAnimation>());
+
+ delete[] children;
+}
+
+void tst_QSequentialAnimationGroup::groupWithZeroDurationAnimations()
+{
+ QObject o;
+ QObject o2;
+
+ o.setProperty("myProperty", 42);
+ o.setProperty("myOtherProperty", 13);
+ o2.setProperty("myProperty", 42);
+ o2.setProperty("myOtherProperty", 13);
+
+ QSequentialAnimationGroup group;
+
+ QVariantAnimation *a1 = new QPropertyAnimation(&o, "myProperty");
+ a1->setDuration(0);
+ a1->setEndValue(43);
+ group.addAnimation(a1);
+
+ //this should just run fine and change nothing
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), a1);
+
+ QVariantAnimation *a2 = new QPropertyAnimation(&o2, "myOtherProperty");
+ a2->setDuration(500);
+ a2->setEndValue(31);
+ group.addAnimation(a2);
+
+ QVariantAnimation *a3 = new QPropertyAnimation(&o, "myProperty");
+ a3->setDuration(0);
+ a3->setEndValue(44);
+ group.addAnimation(a3);
+
+ QVariantAnimation *a4 = new QPropertyAnimation(&o, "myOtherProperty");
+ a4->setDuration(250);
+ a4->setEndValue(75);
+ group.addAnimation(a4);
+
+ QVariantAnimation *a5 = new QPropertyAnimation(&o2, "myProperty");
+ a5->setDuration(0);
+ a5->setEndValue(12);
+ group.addAnimation(a5);
+
+ QCOMPARE(o.property("myProperty").toInt(), 42);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 13);
+
+
+ group.start();
+
+ QCOMPARE(o.property("myProperty").toInt(), 43);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 13);
+
+ QTest::qWait(50);
+
+ int o2val = o2.property("myOtherProperty").toInt();
+ QVERIFY(o2val > 13);
+ QVERIFY(o2val < 31);
+ QCOMPARE(o.property("myProperty").toInt(), 43);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 13);
+
+ QTest::qWait(500);
+
+ QCOMPARE(o.property("myProperty").toInt(), 44);
+ QCOMPARE(o2.property("myProperty").toInt(), 42);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 31);
+ QCOMPARE(a1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a4->state(), QAnimationGroup::Running);
+ QCOMPARE(a5->state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QTest::qWait(500);
+
+ QTRY_COMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(o.property("myProperty").toInt(), 44);
+ QCOMPARE(o.property("myOtherProperty").toInt(), 75);
+ QCOMPARE(o2.property("myProperty").toInt(), 12);
+ QCOMPARE(o2.property("myOtherProperty").toInt(), 31);
+ QCOMPARE(a1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a2->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a4->state(), QAnimationGroup::Stopped);
+ QCOMPARE(a5->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::propagateGroupUpdateToChildren()
+{
+ // this test verifies if group state changes are updating its children correctly
+ QSequentialAnimationGroup group;
+
+ QObject o;
+ o.setProperty("ole", 42);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ QPropertyAnimation anim1(&o, "ole");
+ anim1.setEndValue(43);
+ anim1.setDuration(100);
+ QVERIFY(!anim1.currentValue().isValid());
+ QCOMPARE(anim1.currentValue().toInt(), 0);
+ QCOMPARE(o.property("ole").toInt(), 42);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QVERIFY(anim2.currentValue().isValid());
+ QCOMPARE(anim2.currentValue().toInt(), 0);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim1.state(), QAnimationGroup::Paused);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::updateChildrenWithRunningGroup()
+{
+ // assert that its possible to modify a child's state directly while their group is running
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim;
+ anim.setStartValue(0);
+ anim.setEndValue(100);
+ anim.setDuration(200);
+
+ QSignalSpy groupStateChangedSpy(&group, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy childStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(groupStateChangedSpy.count(), 0);
+ QCOMPARE(childStateChangedSpy.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(groupStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(childStateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+
+ // starting directly a running child will not have any effect
+ anim.start();
+
+ QCOMPARE(groupStateChangedSpy.count(), 1);
+ QCOMPARE(childStateChangedSpy.count(), 1);
+
+ anim.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Paused);
+
+ // in the animation stops directly, the group will still be running
+ anim.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::deleteChildrenWithRunningGroup()
+{
+ // test if children can be activated when their group is stopped
+ QSequentialAnimationGroup group;
+
+ QVariantAnimation *anim1 = new TestAnimation;
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+ group.addAnimation(anim1);
+
+ QCOMPARE(group.duration(), anim1->duration());
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+
+ QTest::qWait(50);
+ QVERIFY(group.currentTime() > 0);
+
+ delete anim1;
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), 0); //that's the invariant
+}
+
+void tst_QSequentialAnimationGroup::startChildrenWithStoppedGroup()
+{
+ // test if children can be activated when their group is stopped
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+}
+
+void tst_QSequentialAnimationGroup::stopGroupWithRunningChild()
+{
+ // children that started independently will not be affected by a group stop
+ QSequentialAnimationGroup group;
+
+ TestAnimation anim1;
+ anim1.setStartValue(0);
+ anim1.setEndValue(100);
+ anim1.setDuration(200);
+
+ TestAnimation anim2;
+ anim2.setStartValue(0);
+ anim2.setEndValue(100);
+ anim2.setDuration(200);
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(&anim1);
+ group.addAnimation(&anim2);
+
+ anim1.start();
+ anim2.start();
+ anim2.pause();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Running);
+ QCOMPARE(anim2.state(), QAnimationGroup::Paused);
+
+ anim1.stop();
+ anim2.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::startGroupWithRunningChild()
+{
+ // as the group has precedence over its children, starting a group will restart all the children
+ QSequentialAnimationGroup group;
+
+ TestAnimation *anim1 = new TestAnimation();
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(200);
+
+ TestAnimation *anim2 = new TestAnimation();
+ anim2->setStartValue(0);
+ anim2->setEndValue(100);
+ anim2->setDuration(200);
+
+ QSignalSpy stateChangedSpy1(anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+ QSignalSpy stateChangedSpy2(anim2, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ QCOMPARE(stateChangedSpy1.count(), 0);
+ QCOMPARE(stateChangedSpy2.count(), 0);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Stopped);
+
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+
+ anim1->start();
+ anim2->start();
+ anim2->pause();
+
+ QVERIFY(compareStates(stateChangedSpy1, (StateList() << QAbstractAnimation::Running)));
+
+ QVERIFY(compareStates(stateChangedSpy2, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+ QCOMPARE(anim2->state(), QAnimationGroup::Paused);
+
+ group.start();
+
+ QVERIFY(compareStates(stateChangedSpy1, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Stopped
+ << QAbstractAnimation::Running)));
+ QVERIFY(compareStates(stateChangedSpy2, (StateList() << QAbstractAnimation::Running
+ << QAbstractAnimation::Paused)));
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Running);
+ QCOMPARE(anim2->state(), QAnimationGroup::Paused);
+
+ QTest::qWait(300);
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+
+ QCOMPARE(stateChangedSpy2.count(), 4);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(2).at(1)),
+ QAnimationGroup::Stopped);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy2.at(3).at(1)),
+ QAnimationGroup::Running);
+
+ group.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::zeroDurationAnimation()
+{
+ QSequentialAnimationGroup group;
+
+ TestAnimation *anim1 = new TestAnimation();
+ anim1->setStartValue(0);
+ anim1->setEndValue(100);
+ anim1->setDuration(0);
+
+ TestAnimation *anim2 = new TestAnimation();
+ anim2->setStartValue(0);
+ anim2->setEndValue(100);
+ anim2->setDuration(100);
+
+ AnimationObject o1;
+ QPropertyAnimation *anim3 = new QPropertyAnimation(&o1, "value");
+ anim3->setEndValue(100);
+ anim3->setDuration(0);
+
+ QSignalSpy stateChangedSpy(anim1, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.addAnimation(anim1);
+ group.addAnimation(anim2);
+ group.addAnimation(anim3);
+ group.setLoopCount(2);
+ group.start();
+
+ QCOMPARE(stateChangedSpy.count(), 2);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(0).at(1)),
+ QAnimationGroup::Running);
+ QCOMPARE(qVariantValue<QAbstractAnimation::State>(stateChangedSpy.at(1).at(1)),
+ QAnimationGroup::Stopped);
+
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+
+ //now let's try to seek to the next loop
+ group.setCurrentTime(group.duration() + 1);
+ QCOMPARE(anim1->state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim2->state(), QAnimationGroup::Running);
+ QCOMPARE(anim3->state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(o1.value(), 100); //anim3 should have been run
+}
+
+void tst_QSequentialAnimationGroup::stopUncontrolledAnimations()
+{
+ QSequentialAnimationGroup group;
+
+ AnimationObject o1;
+ UncontrolledAnimation notTimeDriven(&o1, "value");
+ QCOMPARE(notTimeDriven.totalDuration(), -1);
+
+ TestAnimation loopsForever;
+ loopsForever.setStartValue(0);
+ loopsForever.setEndValue(100);
+ loopsForever.setDuration(100);
+ loopsForever.setLoopCount(-1);
+
+ group.addAnimation(&notTimeDriven);
+ group.addAnimation(&loopsForever);
+
+ group.start();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+
+ notTimeDriven.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Running);
+
+ loopsForever.stop();
+
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(loopsForever.state(), QAnimationGroup::Stopped);
+}
+
+void tst_QSequentialAnimationGroup::finishWithUncontrolledAnimation()
+{
+ AnimationObject o1;
+
+ //1st case:
+ //first we test a group with one uncontrolled animation
+ QSequentialAnimationGroup group;
+ UncontrolledAnimation notTimeDriven(&o1, "value", &group);
+ QSignalSpy spy(&group, SIGNAL(finished()));
+
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(notTimeDriven.currentTime(), 0);
+
+ QTest::qWait(300); //wait for the end of notTimeDriven
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ const int actualDuration = notTimeDriven.currentTime();
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.currentTime(), actualDuration);
+ QCOMPARE(spy.count(), 1);
+
+ //2nd case:
+ // lets make sure the seeking will work again
+ spy.clear();
+ QPropertyAnimation anim(&group);
+ QSignalSpy animStateChangedSpy(&anim, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)));
+
+ group.setCurrentTime(300);
+ QCOMPARE(group.state(), QAnimationGroup::Stopped);
+ QCOMPARE(notTimeDriven.currentTime(), actualDuration);
+ QCOMPARE(group.currentAnimation(), &anim);
+
+ //3rd case:
+ //now let's add a perfectly defined animation at the end
+ QCOMPARE(animStateChangedSpy.count(), 0);
+ group.start();
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(notTimeDriven.currentTime(), 0);
+
+ QCOMPARE(animStateChangedSpy.count(), 0);
+
+ QTest::qWait(300); //wait for the end of notTimeDriven
+ QCOMPARE(notTimeDriven.state(), QAnimationGroup::Stopped);
+ QCOMPARE(group.state(), QAnimationGroup::Running);
+ QCOMPARE(anim.state(), QAnimationGroup::Running);
+ QCOMPARE(group.currentAnimation(), &anim);
+ QCOMPARE(animStateChangedSpy.count(), 1);
+ QTest::qWait(300); //wait for the end of anim
+
+ QCOMPARE(anim.state(), QAnimationGroup::Stopped);
+ QCOMPARE(anim.currentTime(), anim.duration());
+
+ //we should simply be at the end
+ QCOMPARE(spy.count(), 1);
+ QCOMPARE(animStateChangedSpy.count(), 2);
+ QCOMPARE(group.currentTime(), notTimeDriven.currentTime() + anim.currentTime());
+}
+
+void tst_QSequentialAnimationGroup::addRemoveAnimation()
+{
+ //this test is specific to the sequential animation group
+ QSequentialAnimationGroup group;
+
+ QCOMPARE(group.duration(), 0);
+ QCOMPARE(group.currentTime(), 0);
+ QVariantAnimation *anim1 = new QPropertyAnimation;
+ group.addAnimation(anim1);
+ QCOMPARE(group.duration(), 250);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim1);
+
+ //let's append an animation
+ QVariantAnimation *anim2 = new QPropertyAnimation;
+ group.addAnimation(anim2);
+ QCOMPARE(group.duration(), 500);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim1);
+
+ //let's prepend an animation
+ QVariantAnimation *anim0 = new QPropertyAnimation;
+ group.insertAnimationAt(0, anim0);
+ QCOMPARE(group.duration(), 750);
+ QCOMPARE(group.currentTime(), 0);
+ QCOMPARE(group.currentAnimation(), anim0); //anim0 has become the new currentAnimation
+
+ group.setCurrentTime(300); //anim0 | anim1 | anim2
+ QCOMPARE(group.currentTime(), 300);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.removeAnimation(anim0); //anim1 | anim2
+ QCOMPARE(group.currentTime(), 50);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.setCurrentTime(0);
+ group.insertAnimationAt(0, anim0); //anim0 | anim1 | anim2
+ group.setCurrentTime(300);
+ QCOMPARE(group.currentTime(), 300);
+ QCOMPARE(group.currentAnimation(), anim1);
+ QCOMPARE(anim1->currentTime(), 50);
+
+ group.removeAnimation(anim1); //anim0 | anim2
+ QCOMPARE(group.currentTime(), 250);
+ QCOMPARE(group.currentAnimation(), anim2);
+ QCOMPARE(anim0->currentTime(), 250);
+}
+
+void tst_QSequentialAnimationGroup::currentAnimation()
+{
+ QSequentialAnimationGroup group;
+ QVERIFY(group.currentAnimation() == 0);
+
+ QPropertyAnimation anim;
+ anim.setDuration(0);
+ group.addAnimation(&anim);
+ QCOMPARE(group.currentAnimation(), &anim);
+}
+
+void tst_QSequentialAnimationGroup::currentAnimationWithZeroDuration()
+{
+ QSequentialAnimationGroup group;
+ QVERIFY(group.currentAnimation() == 0);
+
+ QPropertyAnimation zero1;
+ zero1.setDuration(0);
+ QPropertyAnimation zero2;
+ zero2.setDuration(0);
+
+ QPropertyAnimation anim;
+
+ QPropertyAnimation zero3;
+ zero3.setDuration(0);
+ QPropertyAnimation zero4;
+ zero4.setDuration(0);
+
+
+ group.addAnimation(&zero1);
+ group.addAnimation(&zero2);
+ group.addAnimation(&anim);
+ group.addAnimation(&zero3);
+ group.addAnimation(&zero4);
+
+ QCOMPARE(group.currentAnimation(), &zero1);
+
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), &anim);
+
+ group.setCurrentTime(group.duration());
+ QCOMPARE(group.currentAnimation(), &zero4);
+
+ group.setDirection(QAbstractAnimation::Backward);
+
+ group.setCurrentTime(0);
+ QCOMPARE(group.currentAnimation(), &zero1);
+
+ group.setCurrentTime(group.duration());
+ QCOMPARE(group.currentAnimation(), &anim);
+}
+
+void tst_QSequentialAnimationGroup::insertAnimation()
+{
+ QSequentialAnimationGroup group;
+ group.setLoopCount(2);
+ QPropertyAnimation *anim = new QPropertyAnimation(&group);
+ QCOMPARE(group.duration(), anim->duration());
+ group.setCurrentTime(300);
+ QCOMPARE(group.currentLoop(), 1);
+
+ //this will crash if the sequential group calls duration on the created animation
+ new QPropertyAnimation(&group);
+}
+
+
+class SequentialAnimationGroup : public QSequentialAnimationGroup
+{
+ Q_OBJECT
+public slots:
+ void clearAnimations()
+ {
+ QSequentialAnimationGroup::clearAnimations();
+ }
+
+ void refill()
+ {
+ stop();
+ clearAnimations();
+ new QPropertyAnimation(this);
+ start();
+ }
+
+};
+
+
+void tst_QSequentialAnimationGroup::clearAnimations()
+{
+ SequentialAnimationGroup group;
+ QPointer<QAbstractAnimation> anim1 = new QPropertyAnimation(&group);
+ group.connect(anim1, SIGNAL(finished()), SLOT(clearAnimations()));
+ new QPropertyAnimation(&group);
+ QCOMPARE(group.animationCount(), 2);
+
+ group.start();
+ QTest::qWait(anim1->duration() + 100);
+ QCOMPARE(group.animationCount(), 0);
+ QCOMPARE(group.state(), QAbstractAnimation::Stopped);
+ QCOMPARE(group.currentTime(), 0);
+
+ anim1 = new QPropertyAnimation(&group);
+ group.connect(anim1, SIGNAL(finished()), SLOT(refill()));
+ group.start();
+ QTest::qWait(anim1->duration() + 100);
+ QVERIFY(anim1 == 0); //anim1 should have been deleted
+ QCOMPARE(group.state(), QAbstractAnimation::Running);
+}
+
+QTEST_MAIN(tst_QSequentialAnimationGroup)
+#include "tst_qsequentialanimationgroup.moc"
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index 64439fb..a52bb3e 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -57,8 +57,11 @@ private slots:
void downCast();
void upCast();
void differentPointers();
+ void virtualBaseDifferentPointers();
#ifndef QTEST_NO_RTTI
void dynamicCast();
+ void dynamicCastDifferentPointers();
+ void dynamicCastVirtualBase();
void dynamicCastFailure();
#endif
void customDeleter();
@@ -321,6 +324,10 @@ class DiffPtrDerivedData: public Stuffing, public Data
{
};
+class VirtualDerived: virtual public Data
+{
+};
+
void tst_QSharedPointer::downCast()
{
{
@@ -439,7 +446,7 @@ void tst_QSharedPointer::differentPointers()
DiffPtrDerivedData *aData = new DiffPtrDerivedData;
Data *aBase = aData;
Q_ASSERT(aData == aBase);
- Q_ASSERT(quintptr(&aData) != quintptr(&aBase));
+ Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData);
QSharedPointer<DiffPtrDerivedData> ptr = qSharedPointerCast<DiffPtrDerivedData>(baseptr);
@@ -453,7 +460,7 @@ void tst_QSharedPointer::differentPointers()
DiffPtrDerivedData *aData = new DiffPtrDerivedData;
Data *aBase = aData;
Q_ASSERT(aData == aBase);
- Q_ASSERT(quintptr(&aData) != quintptr(&aBase));
+ Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<DiffPtrDerivedData> ptr = QSharedPointer<DiffPtrDerivedData>(aData);
QSharedPointer<Data> baseptr = ptr;
@@ -464,23 +471,53 @@ void tst_QSharedPointer::differentPointers()
QVERIFY(baseptr == aData);
QVERIFY(baseptr == aBase);
}
+}
+
+void tst_QSharedPointer::virtualBaseDifferentPointers()
+{
+ {
+ VirtualDerived *aData = new VirtualDerived;
+ Data *aBase = aData;
+ Q_ASSERT(aData == aBase);
+ Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
+
+ QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData);
+ QSharedPointer<Data> baseptr = qSharedPointerCast<Data>(ptr);
+ QVERIFY(ptr == baseptr);
+ QVERIFY(ptr.data() == baseptr.data());
+ QVERIFY(ptr == aBase);
+ QVERIFY(ptr == aData);
+ QVERIFY(baseptr == aData);
+ QVERIFY(baseptr == aBase);
+ }
+
+ {
+ VirtualDerived *aData = new VirtualDerived;
+ Data *aBase = aData;
+ Q_ASSERT(aData == aBase);
+ Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
- // there is no possibility for different pointers in
- // internal reference counting right now
- //
- // to do that, it's necessary to first implement the ability to
- // call (virtual) functions, so that the two differing bases have
- // the same reference counter
+ QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData);
+ QSharedPointer<Data> baseptr = ptr;
+ QVERIFY(ptr == baseptr);
+ QVERIFY(ptr.data() == baseptr.data());
+ QVERIFY(ptr == aBase);
+ QVERIFY(ptr == aData);
+ QVERIFY(baseptr == aData);
+ QVERIFY(baseptr == aBase);
+ }
}
#ifndef QTEST_NO_RTTI
void tst_QSharedPointer::dynamicCast()
{
- QSharedPointer<Data> baseptr = QSharedPointer<Data>(new DerivedData);
+ DerivedData *aData = new DerivedData;
+ QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData);
{
QSharedPointer<DerivedData> derivedptr = qSharedPointerDynamicCast<DerivedData>(baseptr);
QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
QCOMPARE(int(baseptr.d->weakref), 1);
@@ -490,6 +527,7 @@ void tst_QSharedPointer::dynamicCast()
QWeakPointer<Data> weakptr = baseptr;
QSharedPointer<DerivedData> derivedptr = qSharedPointerDynamicCast<DerivedData>(weakptr);
QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
QCOMPARE(int(baseptr.d->weakref), 1);
@@ -498,6 +536,87 @@ void tst_QSharedPointer::dynamicCast()
{
QSharedPointer<DerivedData> derivedptr = baseptr.dynamicCast<DerivedData>();
QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+}
+
+void tst_QSharedPointer::dynamicCastDifferentPointers()
+{
+ // DiffPtrDerivedData derives from both Data and Stuffing
+ DiffPtrDerivedData *aData = new DiffPtrDerivedData;
+ QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData);
+
+ {
+ QSharedPointer<DiffPtrDerivedData> derivedptr = qSharedPointerDynamicCast<DiffPtrDerivedData>(baseptr);
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+
+ {
+ QWeakPointer<Data> weakptr = baseptr;
+ QSharedPointer<DiffPtrDerivedData> derivedptr = qSharedPointerDynamicCast<DiffPtrDerivedData>(weakptr);
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+
+ {
+ QSharedPointer<DiffPtrDerivedData> derivedptr = baseptr.dynamicCast<DiffPtrDerivedData>();
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+
+ {
+ Stuffing *nakedptr = dynamic_cast<Stuffing *>(baseptr.data());
+ QVERIFY(nakedptr);
+
+ QSharedPointer<Stuffing> otherbaseptr = qSharedPointerDynamicCast<Stuffing>(baseptr);
+ QVERIFY(!otherbaseptr.isNull());
+ QVERIFY(otherbaseptr == nakedptr);
+ QCOMPARE(otherbaseptr.data(), nakedptr);
+ QCOMPARE(static_cast<DiffPtrDerivedData*>(otherbaseptr.data()), aData);
+ }
+}
+
+void tst_QSharedPointer::dynamicCastVirtualBase()
+{
+ VirtualDerived *aData = new VirtualDerived;
+ QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData);
+
+ {
+ QSharedPointer<VirtualDerived> derivedptr = qSharedPointerDynamicCast<VirtualDerived>(baseptr);
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+
+ {
+ QWeakPointer<Data> weakptr = baseptr;
+ QSharedPointer<VirtualDerived> derivedptr = qSharedPointerDynamicCast<VirtualDerived>(weakptr);
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
+ QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
+ }
+ QCOMPARE(int(baseptr.d->weakref), 1);
+ QCOMPARE(int(baseptr.d->strongref), 1);
+
+ {
+ QSharedPointer<VirtualDerived> derivedptr = baseptr.dynamicCast<VirtualDerived>();
+ QVERIFY(baseptr == derivedptr);
+ QCOMPARE(derivedptr.data(), aData);
QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data());
}
QCOMPARE(int(baseptr.d->weakref), 1);
diff --git a/tests/auto/qsidebar/tst_qsidebar.cpp b/tests/auto/qsidebar/tst_qsidebar.cpp
index 705e222..1384391 100644
--- a/tests/auto/qsidebar/tst_qsidebar.cpp
+++ b/tests/auto/qsidebar/tst_qsidebar.cpp
@@ -185,6 +185,13 @@ void tst_QSidebar::addUrls()
qsidebar.addUrls(doubleUrls, 1);
QCOMPARE(qsidebar.urls().size(), 1);
+ // Two paths that are effectively pointing to the same location
+ doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath());
+ doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath() + "/.");
+ qsidebar.setUrls(emptyUrls);
+ qsidebar.addUrls(doubleUrls, 1);
+ QCOMPARE(qsidebar.urls().size(), 1);
+
#if defined(Q_OS_WIN)
//Windows is case insensitive so no duplicate entries in that case
doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath());
@@ -200,8 +207,6 @@ void tst_QSidebar::addUrls()
qsidebar.addUrls(doubleUrls, 1);
QCOMPARE(qsidebar.urls().size(), 2);
#endif
-
-
}
void tst_QSidebar::goToUrl()
diff --git a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
index 86333e0..5ab5064 100644
--- a/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
+++ b/tests/auto/qsocks5socketengine/tst_qsocks5socketengine.cpp
@@ -145,8 +145,6 @@ private slots:
}
};
-static const char *IMAP_IP = "62.70.27.18";
-
tst_QSocks5SocketEngine::tst_QSocks5SocketEngine()
{
}
@@ -321,12 +319,11 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -340,7 +337,7 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -589,14 +586,14 @@ void tst_QSocks5SocketEngine::tcpSocketBlockingTest()
QTcpSocket socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(socket.waitForConnected());
QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
// Read greeting
QVERIFY(socket.waitForReadyRead(5000));
QString s = socket.readLine();
- QCOMPARE(s.toLatin1().constData(), "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ QCOMPARE(s.toLatin1().constData(), "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write NOOP
QCOMPARE((int) socket.write("1 NOOP\r\n", 8), 8);
@@ -646,7 +643,7 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest()
tcpSocketNonBlocking_socket = &socket;
// Connect
- socket.connectToHost("imap.troll.no", 143);
+ socket.connectToHost(QtNetworkSettings::serverName(), 143);
QCOMPARE(socket.state(), QTcpSocket::HostLookupState);
QTestEventLoop::instance().enterLoop(30);
@@ -671,7 +668,7 @@ void tst_QSocks5SocketEngine::tcpSocketNonBlockingTest()
// Read greeting
QVERIFY(!tcpSocketNonBlocking_data.isEmpty());
QCOMPARE(tcpSocketNonBlocking_data.at(0).toLatin1().constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
tcpSocketNonBlocking_data.clear();
tcpSocketNonBlocking_totalWritten = 0;
@@ -798,14 +795,14 @@ void tst_QSocks5SocketEngine::downloadBigFile()
if (QTestEventLoop::instance().timeout())
QFAIL("Network operation timed out");
- QCOMPARE(bytesAvailable, qint64(10000309));
+ QCOMPARE(bytesAvailable, qint64(10000000));
QVERIFY(tmpSocket->state() == QAbstractSocket::ConnectedState);
- qDebug("\t\t%.1fMB/%.1fs: %.1fMB/s",
+ /*qDebug("\t\t%.1fMB/%.1fs: %.1fMB/s",
bytesAvailable / (1024.0 * 1024.0),
stopWatch.elapsed() / 1024.0,
- (bytesAvailable / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));
+ (bytesAvailable / (stopWatch.elapsed() / 1000.0)) / (1024 * 1024));*/
delete tmpSocket;
tmpSocket = 0;
@@ -819,7 +816,10 @@ void tst_QSocks5SocketEngine::exitLoopSlot()
void tst_QSocks5SocketEngine::downloadBigFileSlot()
{
- bytesAvailable += tmpSocket->readAll().size();
+ QByteArray tmp=tmpSocket->readAll();
+ int correction=tmp.indexOf((char)0,0); //skip header
+ if (correction==-1) correction=0;
+ bytesAvailable += (tmp.size()-correction);
if (bytesAvailable >= 10000000)
QTestEventLoop::instance().exitLoop();
}
@@ -834,15 +834,14 @@ void tst_QSocks5SocketEngine::passwordAuth()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1080, "qsockstest", "password"));
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
- if (!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143)) {
+ if (!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143)) {
qDebug("%d, %s", socketDevice.error(), socketDevice.errorString().toLatin1().constData());
}
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -856,7 +855,7 @@ void tst_QSocks5SocketEngine::passwordAuth()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
@@ -902,17 +901,16 @@ void tst_QSocks5SocketEngine::passwordAuth2()
socketDevice.setProxy(QNetworkProxy(QNetworkProxy::Socks5Proxy, QtNetworkSettings::serverName(), 1081));
socketDevice.setReceiver(this);
- // Connect to imap.trolltech.com's IP
- QVERIFY(!socketDevice.connectToHost(QHostAddress(IMAP_IP), 143));
+ QVERIFY(!socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143));
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectingState);
while (socketDevice.state() == QAbstractSocket::ConnectingState) {
QVERIFY(socketDevice.waitForWrite());
- socketDevice.connectToHost(QHostAddress(IMAP_IP), 143);
+ socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143);
}
if (socketDevice.state() != QAbstractSocket::ConnectedState)
qDebug("%d, %s", socketDevice.error(), socketDevice.errorString().toLatin1().constData());
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState);
- QVERIFY(socketDevice.peerAddress() == QHostAddress(IMAP_IP));
+ QVERIFY(socketDevice.peerAddress() == QtNetworkSettings::serverIP());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -926,7 +924,7 @@ void tst_QSocks5SocketEngine::passwordAuth2()
// Check that the greeting is what we expect it to be
QCOMPARE(array.constData(),
- "* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n");
+ "* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID STARTTLS LOGINDISABLED] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n");
// Write a logout message
QByteArray array2 = "XXXX LOGOUT\r\n";
diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index f414d3a..d7c231f 100644
--- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -2585,6 +2585,16 @@ void tst_QSortFilterProxyModel::task248868_dynamicSorting()
QModelIndex index = proxy1.index(row, 0, QModelIndex());
QCOMPARE(proxy1.data(index, Qt::DisplayRole).toString(), expected.at(row));
}
+
+ //set up the sorting before seting the model up
+ QSortFilterProxyModel proxy2;
+ proxy2.setDynamicSortFilter(true);
+ proxy2.sort(0);
+ proxy2.setSourceModel(&model2);
+ for (int row = 0; row < proxy2.rowCount(QModelIndex()); ++row) {
+ QModelIndex index = proxy2.index(row, 0, QModelIndex());
+ QCOMPARE(proxy2.data(index, Qt::DisplayRole).toString(), expected.at(row));
+ }
}
class QtTestModel: public QAbstractItemModel
diff --git a/tests/auto/qspinbox/tst_qspinbox.cpp b/tests/auto/qspinbox/tst_qspinbox.cpp
index 1867356..575f261 100644
--- a/tests/auto/qspinbox/tst_qspinbox.cpp
+++ b/tests/auto/qspinbox/tst_qspinbox.cpp
@@ -241,6 +241,12 @@ void tst_QSpinBox::getSetCheck()
QCOMPARE(0.0, obj2.value());
obj2.setValue(1.0);
QCOMPARE(1.0, obj2.value());
+
+ // Make sure we update line edit geometry when updating
+ // buttons - see task 235747
+ QRect oldEditGeometry = obj1.childrenRect();
+ obj1.setButtonSymbols(QAbstractSpinBox::NoButtons);
+ QVERIFY(obj1.childrenRect() != oldEditGeometry);
}
tst_QSpinBox::tst_QSpinBox()
diff --git a/tests/auto/qsplitter/tst_qsplitter.cpp b/tests/auto/qsplitter/tst_qsplitter.cpp
index 33404e4..5fa0286 100644
--- a/tests/auto/qsplitter/tst_qsplitter.cpp
+++ b/tests/auto/qsplitter/tst_qsplitter.cpp
@@ -55,6 +55,7 @@
#include <qtreeview.h>
#include <qlabel.h>
#include <qdebug.h> // for file error messages
+#include "../../shared/util.h"
//TESTED_CLASS=
//TESTED_FILES=
@@ -1341,9 +1342,7 @@ void tst_QSplitter::task187373_addAbstractScrollAreas()
if (addOutsideConstructor)
splitter->addWidget(w);
- qApp->processEvents();
-
- QVERIFY(w->isVisible());
+ QTRY_VERIFY(w->isVisible());
QVERIFY(!w->isHidden());
QVERIFY(w->viewport()->isVisible());
QVERIFY(!w->viewport()->isHidden());
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index 074f16f..7f97972 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -178,9 +178,11 @@ private slots:
void task_217003_data() { generic_data(); }
void task_217003();
#endif
-
void task_250026_data() { generic_data("QODBC"); }
void task_250026();
+ void task_205701_data() { generic_data("QMYSQL"); }
+ void task_205701();
+
private:
@@ -297,7 +299,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
#ifdef NOT_READY_YET
tablenames << qTableName( "Planet" );
#endif
- tablenames << qTableName( "task_250026" );
+ tablenames << qTableName( "task_250026" );
tst_Databases::safeDropTables( db, tablenames );
}
@@ -2711,5 +2713,21 @@ void tst_QSqlQuery::task_250026()
QCOMPARE( q.value( 0 ).toString().length(), data1026.length() );
}
+void tst_QSqlQuery::task_205701()
+{
+ QSqlDatabase qsdb = QSqlDatabase::addDatabase("QMYSQL", "atest");
+ qsdb.setHostName("test");
+ qsdb.setDatabaseName("test");
+ qsdb.setUserName("test");
+ qsdb.setPassword("test");
+ qsdb.open();
+
+// {
+ QSqlQuery query(qsdb);
+// }
+ QSqlDatabase::removeDatabase("atest");
+}
+
+
QTEST_MAIN( tst_QSqlQuery )
#include "tst_qsqlquery.moc"
diff --git a/tests/auto/qsslsocket/qsslsocket.pro b/tests/auto/qsslsocket/qsslsocket.pro
index 147b40d..c29fc68 100644
--- a/tests/auto/qsslsocket/qsslsocket.pro
+++ b/tests/auto/qsslsocket/qsslsocket.pro
@@ -7,6 +7,12 @@ QT -= gui
TARGET = tst_qsslsocket
+!wince* {
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+} else {
+DEFINES += SRCDIR=\\\"./\\\"
+}
+
win32 {
CONFIG(debug, debug|release) {
DESTDIR = debug
diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp
index 432092a..40840bd 100644
--- a/tests/auto/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp
@@ -416,7 +416,7 @@ void tst_QSslSocket::simpleConnect()
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(exitLoop()));
// Start connecting
- socket.connectToHost("imap.troll.no", 993);
+ socket.connectToHost(QtNetworkSettings::serverName(), 993);
QCOMPARE(socket.state(), QAbstractSocket::HostLookupState);
enterLoop(10);
@@ -471,7 +471,7 @@ void tst_QSslSocket::simpleConnectWithIgnore()
connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(exitLoop()));
// Start connecting
- socket.connectToHost("imap.troll.no", 993);
+ socket.connectToHost(QtNetworkSettings::serverName(), 993);
QCOMPARE(socket.state(), QAbstractSocket::HostLookupState);
enterLoop(10);
@@ -490,7 +490,7 @@ void tst_QSslSocket::simpleConnectWithIgnore()
if (!socket.canReadLine())
enterLoop(10);
- QCOMPARE(socket.readAll(), QByteArray("* OK esparsett Cyrus IMAP4 v2.2.8 server ready\r\n"));
+ QCOMPARE(socket.readAll(), QByteArray("* OK [CAPABILITY IMAP4 IMAP4rev1 LITERAL+ ID AUTH=PLAIN SASL-IR] qt-test-server.qt-test-net Cyrus IMAP4 v2.3.11-Mandriva-RPM-2.3.11-6mdv2008.1 server ready\r\n"));
socket.disconnectFromHost();
}
@@ -499,36 +499,39 @@ void tst_QSslSocket::sslErrors_data()
{
QTest::addColumn<QString>("host");
QTest::addColumn<int>("port");
- QTest::addColumn<SslErrorList>("errors");
-
- QTest::newRow("imap.troll.no") << "imap.troll.no" << 993
- << (SslErrorList()
- << QSslError::HostNameMismatch
- << QSslError::SelfSignedCertificateInChain);
- QTest::newRow("imap.trolltech.com") << "imap.trolltech.com" << 993
- << (SslErrorList()
- << QSslError::SelfSignedCertificateInChain);
+ QTest::addColumn<SslErrorList>("expected");
+
+ QTest::newRow(qPrintable(QtNetworkSettings::serverLocalName()))
+ << QtNetworkSettings::serverLocalName()
+ << 993
+ << (SslErrorList() << QSslError::HostNameMismatch
+ << QSslError::SelfSignedCertificate);
+
+ QTest::newRow("imap.trolltech.com")
+ << "imap.trolltech.com"
+ << 993
+ << (SslErrorList() << QSslError::SelfSignedCertificateInChain);
}
void tst_QSslSocket::sslErrors()
{
QFETCH(QString, host);
QFETCH(int, port);
- QFETCH(SslErrorList, errors);
+ QFETCH(SslErrorList, expected);
QSslSocketPtr socket = newSocket();
socket->connectToHostEncrypted(host, port);
socket->waitForEncrypted(5000);
- SslErrorList list;
+ SslErrorList output;
foreach (QSslError error, socket->sslErrors())
- list << error.error();
+ output << error.error();
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
- if (list.last() == QSslError::CertificateUntrusted)
- list.takeLast();
+ if (output.last() == QSslError::CertificateUntrusted)
+ output.takeLast();
#endif
- QCOMPARE(list, errors);
+ QCOMPARE(output, expected);
}
void tst_QSslSocket::addCaCertificate()
@@ -575,7 +578,7 @@ void tst_QSslSocket::connectToHostEncrypted()
QSslSocketPtr socket = newSocket();
this->socket = socket;
- socket->addCaCertificates(QLatin1String("certs/qt-test-server-cacert.pem"));
+ QVERIFY(socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem")));
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(&socket, SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@@ -672,7 +675,7 @@ void tst_QSslSocket::peerCertificateChain()
QSslSocketPtr socket = newSocket();
this->socket = socket;
- QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(QLatin1String("certs/qt-test-server-cacert.pem"));
+ QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"));
QVERIFY(caCertificates.count() == 1);
socket->addCaCertificates(caCertificates);
@@ -733,7 +736,7 @@ void tst_QSslSocket::protocol()
QSslSocketPtr socket = newSocket();
this->socket = socket;
- QList<QSslCertificate> certs = QSslCertificate::fromPath("certs/qt-test-server-cacert.pem");
+ QList<QSslCertificate> certs = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem");
// qDebug() << "certs:" << certs.at(0).issuerInfo(QSslCertificate::CommonName);
socket->setCaCertificates(certs);
@@ -816,7 +819,7 @@ void tst_QSslSocket::setCaCertificates()
QSslSocket socket;
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates());
- socket.setCaCertificates(QSslCertificate::fromPath("certs/qt-test-server-cacert.pem"));
+ socket.setCaCertificates(QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem"));
QCOMPARE(socket.caCertificates().size(), 1);
socket.setCaCertificates(socket.defaultCaCertificates());
QCOMPARE(socket.caCertificates(), QSslSocket::defaultCaCertificates());
@@ -847,13 +850,13 @@ protected:
socket = new QSslSocket(this);
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot()));
- QFile file("certs/fluke.key");
+ QFile file(SRCDIR "certs/fluke.key");
QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull());
socket->setPrivateKey(key);
- QList<QSslCertificate> localCert = QSslCertificate::fromPath("certs/fluke.cert");
+ QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert");
QVERIFY(!localCert.isEmpty());
QVERIFY(localCert.first().handle());
socket->setLocalCertificate(localCert.first());
@@ -954,7 +957,7 @@ void tst_QSslSocket::addDefaultCaCertificate()
// Reset the global CA chain
QSslSocket::setDefaultCaCertificates(QSslSocket::systemCaCertificates());
- QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath("certs/qt-test-server-cacert.pem");
+ QList<QSslCertificate> flukeCerts = QSslCertificate::fromPath(SRCDIR "certs/qt-test-server-cacert.pem");
QCOMPARE(flukeCerts.size(), 1);
QList<QSslCertificate> globalCerts = QSslSocket::defaultCaCertificates();
QVERIFY(!globalCerts.contains(flukeCerts.first()));
@@ -1038,7 +1041,7 @@ void tst_QSslSocket::wildcard()
// responds with the wildcard, and QSslSocket should accept that as a
// valid connection. This was broken in 4.3.0.
QSslSocketPtr socket = newSocket();
- socket->addCaCertificates(QLatin1String("certs/qt-test-server-cacert.pem"));
+ socket->addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"));
this->socket = socket;
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
@@ -1064,7 +1067,7 @@ protected:
socket->ignoreSslErrors();
// Only set the certificate
- QList<QSslCertificate> localCert = QSslCertificate::fromPath("certs/fluke.cert");
+ QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert");
QVERIFY(!localCert.isEmpty());
QVERIFY(localCert.first().handle());
socket->setLocalCertificate(localCert.first());
@@ -1223,13 +1226,13 @@ protected:
socket = new QSslSocket(this);
connect(socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(ignoreErrorSlot()));
- QFile file("certs/fluke.key");
+ QFile file(SRCDIR "certs/fluke.key");
QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull());
socket->setPrivateKey(key);
- QList<QSslCertificate> localCert = QSslCertificate::fromPath("certs/fluke.cert");
+ QList<QSslCertificate> localCert = QSslCertificate::fromPath(SRCDIR "certs/fluke.cert");
QVERIFY(!localCert.isEmpty());
QVERIFY(localCert.first().handle());
socket->setLocalCertificate(localCert.first());
@@ -1389,8 +1392,8 @@ protected:
{
socket = new QSslSocket(this);
- socket->setPrivateKey("certs/fluke.key");
- socket->setLocalCertificate("certs/fluke.cert");
+ socket->setPrivateKey(SRCDIR "certs/fluke.key");
+ socket->setLocalCertificate(SRCDIR "certs/fluke.cert");
socket->setSocketDescriptor(socketDescriptor);
socket->startServerEncryption();
}
@@ -1513,7 +1516,7 @@ void tst_QSslSocket::resetProxy()
// make sure the connection works, and then set a nonsense proxy, and then
// make sure it does not work anymore
QSslSocket socket;
- socket.addCaCertificates(QLatin1String("certs/qt-test-server-cacert.pem"));
+ socket.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"));
socket.setProxy(goodProxy);
socket.connectToHostEncrypted(QtNetworkSettings::serverName(), 443);
QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString()));
@@ -1526,7 +1529,7 @@ void tst_QSslSocket::resetProxy()
// set the nonsense proxy and make sure the connection does not work,
// and then set the right proxy and make sure it works
QSslSocket socket2;
- socket2.addCaCertificates(QLatin1String("certs/qt-test-server-cacert.pem"));
+ socket2.addCaCertificates(QLatin1String(SRCDIR "certs/qt-test-server-cacert.pem"));
socket2.setProxy(badProxy);
socket2.connectToHostEncrypted(QtNetworkSettings::serverName(), 443);
QVERIFY(! socket2.waitForConnected(10000));
diff --git a/tests/auto/qstate/qstate.pro b/tests/auto/qstate/qstate.pro
new file mode 100644
index 0000000..9131fa8
--- /dev/null
+++ b/tests/auto/qstate/qstate.pro
@@ -0,0 +1,5 @@
+load(qttest_p4)
+QT = core
+SOURCES += tst_qstate.cpp
+
+
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp
new file mode 100644
index 0000000..75b1905
--- /dev/null
+++ b/tests/auto/qstate/tst_qstate.cpp
@@ -0,0 +1,340 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+#include "qstate.h"
+#include "qstatemachine.h"
+#include "qsignaltransition.h"
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+ } while(0)
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QState : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QState();
+ virtual ~tst_QState();
+
+private slots:
+#if 0
+ void test();
+#endif
+ void assignProperty();
+ void assignPropertyTwice();
+ void historyInitialState();
+
+private:
+ bool functionCalled;
+};
+
+tst_QState::tst_QState() : functionCalled(false)
+{
+}
+
+tst_QState::~tst_QState()
+{
+}
+
+#if 0
+void tst_QState::test()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+
+ QCOMPARE(s1->machine(), &machine);
+ QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QVERIFY(s1->childStates().isEmpty());
+ QVERIFY(s1->transitions().isEmpty());
+
+ QCOMPARE(s1->isFinal(), false);
+ s1->setFinal(true);
+ QCOMPARE(s1->isFinal(), true);
+ s1->setFinal(false);
+ QCOMPARE(s1->isFinal(), false);
+
+ QCOMPARE(s1->isParallel(), false);
+ s1->setParallel(true);
+ QCOMPARE(s1->isParallel(), true);
+ s1->setParallel(false);
+ QCOMPARE(s1->isParallel(), false);
+
+ QCOMPARE(s1->isAtomic(), true);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), false);
+
+ QState *s11 = new QState(s1);
+ QCOMPARE(s11->parentState(), s1);
+ QCOMPARE(s11->isAtomic(), true);
+ QCOMPARE(s11->isCompound(), false);
+ QCOMPARE(s11->isComplex(), false);
+ QCOMPARE(s11->machine(), s1->machine());
+ QVERIFY(s11->isDescendantOf(s1));
+
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QCOMPARE(s1->childStates().size(), 1);
+ QCOMPARE(s1->childStates().at(0), s11);
+
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), true);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setParallel(true);
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), true);
+
+ QState *s12 = new QState(s1);
+ QCOMPARE(s12->parentState(), s1);
+ QCOMPARE(s12->isAtomic(), true);
+ QCOMPARE(s12->isCompound(), false);
+ QCOMPARE(s12->isComplex(), false);
+ QCOMPARE(s12->machine(), s1->machine());
+ QVERIFY(s12->isDescendantOf(s1));
+ QVERIFY(!s12->isDescendantOf(s11));
+
+ QCOMPARE(s1->initialState(), (QState*)0);
+ QCOMPARE(s1->childStates().size(), 2);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), false);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setParallel(false);
+ QCOMPARE(s1->isAtomic(), false);
+ QCOMPARE(s1->isCompound(), true);
+ QCOMPARE(s1->isComplex(), true);
+
+ s1->setInitialState(s11);
+ QCOMPARE(s1->initialState(), s11);
+
+ s1->setInitialState(0);
+ QCOMPARE(s1->initialState(), (QState*)0);
+
+ s1->setInitialState(s12);
+ QCOMPARE(s1->initialState(), s12);
+
+ QState *s13 = new QState();
+ s1->setInitialState(s13);
+ QCOMPARE(s13->parentState(), s1);
+ QCOMPARE(s1->childStates().size(), 3);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+ QCOMPARE(s1->childStates().at(2), s13);
+ QVERIFY(s13->isDescendantOf(s1));
+
+ QVERIFY(s12->childStates().isEmpty());
+
+ QState *s121 = new QState(s12);
+ QCOMPARE(s121->parentState(), s12);
+ QCOMPARE(s121->isAtomic(), true);
+ QCOMPARE(s121->isCompound(), false);
+ QCOMPARE(s121->isComplex(), false);
+ QCOMPARE(s121->machine(), s12->machine());
+ QVERIFY(s121->isDescendantOf(s12));
+ QVERIFY(s121->isDescendantOf(s1));
+ QVERIFY(!s121->isDescendantOf(s11));
+
+ QCOMPARE(s12->childStates().size(), 1);
+ QCOMPARE(s12->childStates().at(0), (QState*)s121);
+
+ QCOMPARE(s1->childStates().size(), 3);
+ QCOMPARE(s1->childStates().at(0), s11);
+ QCOMPARE(s1->childStates().at(1), s12);
+ QCOMPARE(s1->childStates().at(2), s13);
+
+ s11->addTransition(s12);
+ QCOMPARE(s11->transitions().size(), 1);
+ QCOMPARE(s11->transitions().at(0)->sourceState(), s11);
+ QCOMPARE(s11->transitions().at(0)->targetStates().size(), 1);
+ QCOMPARE(s11->transitions().at(0)->targetStates().at(0), s12);
+ QCOMPARE(s11->transitions().at(0)->eventType(), QEvent::None);
+
+ QState *s14 = new QState();
+ s12->addTransition(QList<QState*>() << s13 << s14);
+ QCOMPARE(s12->transitions().size(), 1);
+ QCOMPARE(s12->transitions().at(0)->sourceState(), s12);
+ QCOMPARE(s12->transitions().at(0)->targetStates().size(), 2);
+ QCOMPARE(s12->transitions().at(0)->targetStates().at(0), s13);
+ QCOMPARE(s12->transitions().at(0)->targetStates().at(1), s14);
+ QCOMPARE(s12->transitions().at(0)->eventType(), QEvent::None);
+
+ s13->addTransition(this, SIGNAL(destroyed()), s14);
+ QCOMPARE(s13->transitions().size(), 1);
+ QCOMPARE(s13->transitions().at(0)->sourceState(), s13);
+ QCOMPARE(s13->transitions().at(0)->targetStates().size(), 1);
+ QCOMPARE(s13->transitions().at(0)->targetStates().at(0), s14);
+ QCOMPARE(s13->transitions().at(0)->eventType(), QEvent::Signal);
+ QVERIFY(qobject_cast<QSignalTransition*>(s13->transitions().at(0)) != 0);
+
+ delete s13->transitions().at(0);
+ QCOMPARE(s13->transitions().size(), 0);
+
+ s12->addTransition(this, SIGNAL(destroyed()), s11);
+ QCOMPARE(s12->transitions().size(), 2);
+}
+#endif
+
+class TestClass: public QObject
+{
+ Q_OBJECT
+public:
+ TestClass() : called(false) {}
+ bool called;
+
+public slots:
+ void slot() { called = true; }
+
+
+};
+
+void tst_QState::assignProperty()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 10);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(object, "fooBar", 20);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("fooBar").toInt(), 20);
+}
+
+void tst_QState::assignPropertyTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("fooBar", 10);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(object, "fooBar", 20);
+ s1->assignProperty(object, "fooBar", 30);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("fooBar").toInt(), 30);
+}
+
+class EventTestTransition: public QAbstractTransition
+{
+public:
+ EventTestTransition(QEvent::Type type, QState *targetState)
+ : QAbstractTransition(QList<QAbstractState*>() << targetState), m_type(type)
+ {
+ }
+
+protected:
+ bool eventTest(QEvent *e)
+ {
+ return e->type() == m_type;
+ }
+
+ void onTransition(QEvent *) {}
+
+private:
+ QEvent::Type m_type;
+
+};
+
+void tst_QState::historyInitialState()
+{
+ QStateMachine machine;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ QHistoryState *h1 = new QHistoryState(s2);
+
+ s2->setInitialState(h1);
+
+ QState *s3 = new QState(s2);
+ h1->setDefaultState(s3);
+
+ QState *s4 = new QState(s2);
+
+ s1->addTransition(new EventTestTransition(QEvent::User, s2));
+ s2->addTransition(new EventTestTransition(QEvent::User, s1));
+ s3->addTransition(new EventTestTransition(QEvent::Type(QEvent::User+1), s4));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s3));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s3));
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User+1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s4));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s4));
+}
+
+
+QTEST_MAIN(tst_QState)
+#include "tst_qstate.moc"
diff --git a/tests/auto/qstatemachine/qstatemachine.pro b/tests/auto/qstatemachine/qstatemachine.pro
new file mode 100644
index 0000000..e5b32b5
--- /dev/null
+++ b/tests/auto/qstatemachine/qstatemachine.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+QT = core gui
+SOURCES += tst_qstatemachine.cpp
+
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
new file mode 100644
index 0000000..66e50ba
--- /dev/null
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -0,0 +1,3758 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtCore/QCoreApplication>
+#include <QtGui/QPushButton>
+
+#include "qstatemachine.h"
+#include "qstate.h"
+#include "qhistorystate.h"
+#include "qkeyeventtransition.h"
+#include "qmouseeventtransition.h"
+#include "private/qstate_p.h"
+#include "private/qstatemachine_p.h"
+
+// Will try to wait for the condition while allowing event processing
+#define QTRY_COMPARE(__expr, __expected) \
+ do { \
+ const int __step = 50; \
+ const int __timeout = 5000; \
+ if ((__expr) != (__expected)) { \
+ QTest::qWait(0); \
+ } \
+ for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \
+ QTest::qWait(__step); \
+ } \
+ QCOMPARE(__expr, __expected); \
+ } while(0)
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+static int globalTick;
+
+// Run exec for a maximum of TIMEOUT msecs
+#define QCOREAPPLICATION_EXEC(TIMEOUT) \
+{ \
+ QTimer timer; \
+ timer.setSingleShot(true); \
+ timer.setInterval(TIMEOUT); \
+ timer.start(); \
+ connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); \
+ QCoreApplication::exec(); \
+}
+
+class SignalEmitter : public QObject
+{
+Q_OBJECT
+ public:
+ SignalEmitter(QObject *parent = 0)
+ : QObject(parent) {}
+ void emitSignalWithNoArg()
+ { emit signalWithNoArg(); }
+ void emitSignalWithIntArg(int arg)
+ { emit signalWithIntArg(arg); }
+ void emitSignalWithStringArg(const QString &arg)
+ { emit signalWithStringArg(arg); }
+Q_SIGNALS:
+ void signalWithNoArg();
+ void signalWithIntArg(int);
+ void signalWithStringArg(const QString &);
+};
+
+class tst_QStateMachine : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QStateMachine();
+ virtual ~tst_QStateMachine();
+
+private slots:
+ void init();
+ void cleanup();
+
+ void rootState();
+ void addAndRemoveState();
+ void stateEntryAndExit();
+ void assignProperty();
+ void assignPropertyWithAnimation();
+ void postEvent();
+ void stateFinished();
+ void parallelStates();
+ void allSourceToTargetConfigurations();
+ void signalTransitions();
+ void eventTransitions();
+ void historyStates();
+ void startAndStop();
+ void targetStateWithNoParent();
+ void targetStateDeleted();
+ void transitionToRootState();
+ void transitionEntersParent();
+
+ void defaultErrorState();
+ void customGlobalErrorState();
+ void customLocalErrorStateInBrokenState();
+ void customLocalErrorStateInOtherState();
+ void customLocalErrorStateInParentOfBrokenState();
+ void customLocalErrorStateOverridesParent();
+ void errorStateHasChildren();
+ void errorStateHasErrors();
+ void errorStateIsRootState();
+ void errorStateEntersParentFirst();
+ void customErrorStateIsNull();
+ void clearError();
+ void historyStateHasNowhereToGo();
+ void historyStateAsInitialState();
+ void brokenStateIsNeverEntered();
+ void customErrorStateNotInGraph();
+ void transitionToStateNotInGraph();
+ void restoreProperties();
+
+ void defaultGlobalRestorePolicy();
+ void globalRestorePolicySetToRestore();
+ void globalRestorePolicySetToDoNotRestore();
+
+ //void restorePolicyNotInherited();
+ //void mixedRestoreProperties();
+ //void setRestorePolicyToDoNotRestore();
+ //void setGlobalRestorePolicyToGlobalRestore();
+ //void restorePolicyOnChildState();
+
+ void transitionWithParent();
+ void transitionsFromParallelStateWithNoChildren();
+ void parallelStateTransition();
+ void parallelStateAssignmentsDone();
+ void nestedRestoreProperties();
+ void nestedRestoreProperties2();
+
+ void simpleAnimation();
+ void twoAnimations();
+ void twoAnimatedTransitions();
+ void playAnimationTwice();
+ void nestedTargetStateForAnimation();
+ void animatedGlobalRestoreProperty();
+ void specificTargetValueOfAnimation();
+
+ void addDefaultAnimation();
+ void addDefaultAnimationWithUnusedAnimation();
+ void removeDefaultAnimation();
+ void overrideDefaultAnimationWithSpecific();
+
+// void addDefaultAnimationForSource();
+// void addDefaultAnimationForTarget();
+// void removeDefaultAnimationForSource();
+// void removeDefaultAnimationForTarget();
+// void overrideDefaultAnimationWithSource();
+// void overrideDefaultAnimationWithTarget();
+// void overrideDefaultSourceAnimationWithSpecific();
+// void overrideDefaultTargetAnimationWithSpecific();
+// void overrideDefaultTargetAnimationWithSource();
+};
+
+tst_QStateMachine::tst_QStateMachine()
+{
+}
+
+tst_QStateMachine::~tst_QStateMachine()
+{
+}
+
+class TestState : public QState
+{
+public:
+ enum Event {
+ Entry,
+ Exit
+ };
+ TestState(QState *parent)
+ : QState(parent) {}
+ QList<QPair<int, Event> > events;
+protected:
+ virtual void onEntry(QEvent *) {
+ events.append(qMakePair(globalTick++, Entry));
+ }
+ virtual void onExit(QEvent *) {
+ events.append(qMakePair(globalTick++, Exit));
+ }
+};
+
+class TestTransition : public QAbstractTransition
+{
+public:
+ TestTransition(QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target) {}
+ QList<int> triggers;
+protected:
+ virtual bool eventTest(QEvent *) {
+ return true;
+ }
+ virtual void onTransition(QEvent *) {
+ triggers.append(globalTick++);
+ }
+};
+
+void tst_QStateMachine::init()
+{
+}
+
+void tst_QStateMachine::cleanup()
+{
+}
+
+class EventTransition : public QAbstractTransition
+{
+public:
+ EventTransition(QEvent::Type type, QAbstractState *target, QState *parent = 0)
+ : QAbstractTransition(QList<QAbstractState*>() << target, parent), m_type(type) {}
+protected:
+ virtual bool eventTest(QEvent *e) {
+ return (e->type() == m_type);
+ }
+ virtual void onTransition(QEvent *) {}
+private:
+ QEvent::Type m_type;
+};
+
+void tst_QStateMachine::transitionToRootState()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState();
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::setTargetStates: root state cannot be target of transition");
+ initialState->addTransition(new EventTransition(QEvent::User, machine.rootState()));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+}
+
+void tst_QStateMachine::transitionEntersParent()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setObjectName("entryController");
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("stateEntered", false);
+
+ QState *greatGrandParent = new QState();
+ greatGrandParent->setObjectName("grandParent");
+ greatGrandParent->assignProperty(entryController, "greatGrandParentEntered", true);
+ machine.addState(greatGrandParent);
+ machine.setInitialState(greatGrandParent);
+
+ QState *grandParent = new QState(greatGrandParent);
+ grandParent->setObjectName("grandParent");
+ grandParent->assignProperty(entryController, "grandParentEntered", true);
+
+ QState *parent = new QState(grandParent);
+ parent->setObjectName("parent");
+ parent->assignProperty(entryController, "parentEntered", true);
+
+ QState *state = new QState(parent);
+ state->setObjectName("state");
+ state->assignProperty(entryController, "stateEntered", true);
+
+ QState *initialStateOfGreatGrandParent = new QState(greatGrandParent);
+ initialStateOfGreatGrandParent->setObjectName("initialStateOfGreatGrandParent");
+ greatGrandParent->setInitialState(initialStateOfGreatGrandParent);
+
+ initialStateOfGreatGrandParent->addTransition(new EventTransition(QEvent::User, state));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("parentEntered").toBool(), false);
+ QCOMPARE(entryController->property("stateEntered").toBool(), false);
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(initialStateOfGreatGrandParent));
+
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("stateEntered", false);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("parentEntered").toBool(), true);
+ QCOMPARE(entryController->property("stateEntered").toBool(), true);
+ QCOMPARE(machine.configuration().count(), 4);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(grandParent));
+ QVERIFY(machine.configuration().contains(parent));
+ QVERIFY(machine.configuration().contains(state));
+}
+
+void tst_QStateMachine::defaultErrorState()
+{
+ QStateMachine machine;
+ QVERIFY(machine.errorState() != 0);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("MyInitialState");
+
+ machine.addState(brokenState);
+ machine.setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'MyInitialState'");
+
+ // initialState has no initial state
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'MyInitialState'"));
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+class CustomErrorState: public QState
+{
+public:
+ CustomErrorState(QStateMachine *machine, QState *parent = 0)
+ : QState(parent), error(QStateMachine::NoError), m_machine(machine)
+ {
+ }
+
+ void onEntry(QEvent *)
+ {
+ error = m_machine->error();
+ errorString = m_machine->errorString();
+ }
+
+ QStateMachine::Error error;
+ QString errorString;
+
+private:
+ QStateMachine *m_machine;
+};
+
+void tst_QStateMachine::customGlobalErrorState()
+{
+ QStateMachine machine;
+
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+ machine.setErrorState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.errorState(), customErrorState);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(initialState));
+
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QCOMPARE(customErrorState->error, QStateMachine::NoInitialStateError);
+ QCOMPARE(customErrorState->errorString, QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+}
+
+void tst_QStateMachine::customLocalErrorStateInBrokenState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+ brokenState->setErrorState(customErrorState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QCOMPARE(customErrorState->error, QStateMachine::NoInitialStateError);
+}
+
+void tst_QStateMachine::customLocalErrorStateInOtherState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ QTest::ignoreMessage(QtWarningMsg, "QState::setErrorState: error state cannot belong to a different state machine");
+ initialState->setErrorState(customErrorState);
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'brokenState'");
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::customLocalErrorStateInParentOfBrokenState()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ machine.addState(customErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *parentOfBrokenState = new QState();
+ machine.addState(parentOfBrokenState);
+ parentOfBrokenState->setObjectName("parentOfBrokenState");
+ parentOfBrokenState->setErrorState(customErrorState);
+
+ QState *brokenState = new QState(parentOfBrokenState);
+ brokenState->setObjectName("brokenState");
+ parentOfBrokenState->setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorState));
+}
+
+void tst_QStateMachine::customLocalErrorStateOverridesParent()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorStateForParent = new CustomErrorState(&machine);
+ machine.addState(customErrorStateForParent);
+
+ CustomErrorState *customErrorStateForBrokenState = new CustomErrorState(&machine);
+ machine.addState(customErrorStateForBrokenState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *parentOfBrokenState = new QState();
+ machine.addState(parentOfBrokenState);
+ parentOfBrokenState->setObjectName("parentOfBrokenState");
+ parentOfBrokenState->setErrorState(customErrorStateForParent);
+
+ QState *brokenState = new QState(parentOfBrokenState);
+ brokenState->setObjectName("brokenState");
+ brokenState->setErrorState(customErrorStateForBrokenState);
+ parentOfBrokenState->setInitialState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(customErrorStateForBrokenState));
+ QCOMPARE(customErrorStateForBrokenState->error, QStateMachine::NoInitialStateError);
+ QCOMPARE(customErrorStateForParent->error, QStateMachine::NoError);
+}
+
+void tst_QStateMachine::errorStateHasChildren()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+
+ machine.setErrorState(customErrorState);
+
+ QState *childOfErrorState = new QState(customErrorState);
+ childOfErrorState->setObjectName("childOfErrorState");
+ customErrorState->setInitialState(childOfErrorState);
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(customErrorState));
+ QVERIFY(machine.configuration().contains(childOfErrorState));
+}
+
+
+void tst_QStateMachine::errorStateHasErrors()
+{
+ QStateMachine machine;
+ CustomErrorState *customErrorState = new CustomErrorState(&machine);
+ customErrorState->setObjectName("customErrorState");
+ machine.addState(customErrorState);
+
+ QAbstractState *oldErrorState = machine.errorState();
+ machine.setErrorState(customErrorState);
+
+ QState *childOfErrorState = new QState(customErrorState);
+ childOfErrorState->setObjectName("childOfErrorState");
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'customErrorState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(oldErrorState)); // Fall back to default
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'customErrorState'"));
+}
+
+void tst_QStateMachine::errorStateIsRootState()
+{
+ QStateMachine machine;
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::setErrorState: root state cannot be error state");
+ machine.setErrorState(machine.rootState());
+
+ QState *initialState = new QState();
+ initialState->setObjectName("initialState");
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ brokenState->setObjectName("brokenState");
+ machine.addState(brokenState);
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialState->addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 1)));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'brokenState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::errorStateEntersParentFirst()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setObjectName("entryController");
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ QState *greatGrandParent = new QState();
+ greatGrandParent->setObjectName("greatGrandParent");
+ greatGrandParent->assignProperty(entryController, "greatGrandParentEntered", true);
+ machine.addState(greatGrandParent);
+ machine.setInitialState(greatGrandParent);
+
+ QState *grandParent = new QState(greatGrandParent);
+ grandParent->setObjectName("grandParent");
+ grandParent->assignProperty(entryController, "grandParentEntered", true);
+
+ QState *parent = new QState(grandParent);
+ parent->setObjectName("parent");
+ parent->assignProperty(entryController, "parentEntered", true);
+
+ QState *errorState = new QState(parent);
+ errorState->setObjectName("errorState");
+ errorState->assignProperty(entryController, "errorStateEntered", true);
+ machine.setErrorState(errorState);
+
+ QState *initialStateOfGreatGrandParent = new QState(greatGrandParent);
+ initialStateOfGreatGrandParent->setObjectName("initialStateOfGreatGrandParent");
+ greatGrandParent->setInitialState(initialStateOfGreatGrandParent);
+
+ QState *brokenState = new QState(greatGrandParent);
+ brokenState->setObjectName("brokenState");
+
+ QState *childState = new QState(brokenState);
+ childState->setObjectName("childState");
+
+ initialStateOfGreatGrandParent->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("parentEntered").toBool(), false);
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), false);
+ QCOMPARE(machine.configuration().count(), 2);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(initialStateOfGreatGrandParent));
+
+ entryController->setProperty("greatGrandParentEntered", false);
+ entryController->setProperty("grandParentEntered", false);
+ entryController->setProperty("parentEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("greatGrandParentEntered").toBool(), false);
+ QCOMPARE(entryController->property("grandParentEntered").toBool(), true);
+ QCOMPARE(entryController->property("parentEntered").toBool(), true);
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), true);
+ QCOMPARE(machine.configuration().count(), 4);
+ QVERIFY(machine.configuration().contains(greatGrandParent));
+ QVERIFY(machine.configuration().contains(grandParent));
+ QVERIFY(machine.configuration().contains(parent));
+ QVERIFY(machine.configuration().contains(errorState));
+}
+
+void tst_QStateMachine::customErrorStateIsNull()
+{
+ QStateMachine machine;
+ QAbstractState *oldErrorState = machine.errorState();
+ machine.rootState()->setErrorState(0);
+
+ QState *initialState = new QState();
+ machine.addState(initialState);
+ machine.setInitialState(initialState);
+
+ QState *brokenState = new QState();
+ machine.addState(brokenState);
+
+ new QState(brokenState);
+ initialState->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state ''");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.errorState(), reinterpret_cast<void *>(0));
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(oldErrorState));
+}
+
+void tst_QStateMachine::clearError()
+{
+ QStateMachine machine;
+ machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->setObjectName("brokenState");
+ machine.setInitialState(brokenState);
+ new QState(brokenState);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.error(), QStateMachine::NoInitialStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing initial state in compound state 'brokenState'"));
+
+ machine.clearError();
+
+ QCOMPARE(machine.error(), QStateMachine::NoError);
+ QVERIFY(machine.errorString().isEmpty());
+}
+
+void tst_QStateMachine::historyStateAsInitialState()
+{
+ QStateMachine machine;
+
+ QHistoryState *hs = new QHistoryState(machine.rootState());
+ machine.setInitialState(hs);
+
+ QState *s1 = new QState(machine.rootState());
+ hs->setDefaultState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+
+ QHistoryState *s2h = new QHistoryState(s2);
+ s2->setInitialState(s2h);
+
+ QState *s21 = new QState(s2);
+ s2h->setDefaultState(s21);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+}
+
+void tst_QStateMachine::historyStateHasNowhereToGo()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState(machine.rootState());
+ machine.setInitialState(initialState);
+ machine.setErrorState(new QState(machine.rootState())); // avoid warnings
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->setObjectName("brokenState");
+ brokenState->setInitialState(new QState(brokenState));
+
+ QHistoryState *historyState = new QHistoryState(brokenState);
+ historyState->setObjectName("historyState");
+ initialState->addTransition(new EventTransition(QEvent::User, historyState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+ QCOMPARE(machine.error(), QStateMachine::NoDefaultStateInHistoryStateError);
+ QCOMPARE(machine.errorString(), QString::fromLatin1("Missing default state in history state 'historyState'"));
+}
+
+void tst_QStateMachine::brokenStateIsNeverEntered()
+{
+ QStateMachine machine;
+
+ QObject *entryController = new QObject(&machine);
+ entryController->setProperty("brokenStateEntered", false);
+ entryController->setProperty("childStateEntered", false);
+ entryController->setProperty("errorStateEntered", false);
+
+ QState *initialState = new QState(machine.rootState());
+ machine.setInitialState(initialState);
+
+ QState *errorState = new QState(machine.rootState());
+ errorState->assignProperty(entryController, "errorStateEntered", true);
+ machine.setErrorState(errorState);
+
+ QState *brokenState = new QState(machine.rootState());
+ brokenState->assignProperty(entryController, "brokenStateEntered", true);
+ brokenState->setObjectName("brokenState");
+
+ QState *childState = new QState(brokenState);
+ childState->assignProperty(entryController, "childStateEntered", true);
+
+ initialState->addTransition(new EventTransition(QEvent::User, brokenState));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(entryController->property("errorStateEntered").toBool(), true);
+ QCOMPARE(entryController->property("brokenStateEntered").toBool(), false);
+ QCOMPARE(entryController->property("childStateEntered").toBool(), false);
+}
+
+void tst_QStateMachine::transitionToStateNotInGraph()
+{
+ QStateMachine machine;
+
+ QState *initialState = new QState(machine.rootState());
+ initialState->setObjectName("initialState");
+ machine.setInitialState(initialState);
+
+ QState independentState;
+ independentState.setObjectName("independentState");
+ initialState->addTransition(&independentState);
+
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initialState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(qobject_cast<QState*>(machine.rootState())->errorState()));
+}
+
+void tst_QStateMachine::customErrorStateNotInGraph()
+{
+ QStateMachine machine;
+
+ QState errorState;
+ errorState.setObjectName("errorState");
+ QTest::ignoreMessage(QtWarningMsg, "QState::setErrorState: error state cannot belong to a different state machine");
+ machine.setErrorState(&errorState);
+ QVERIFY(&errorState != machine.errorState());
+
+ QState *initialBrokenState = new QState(machine.rootState());
+ initialBrokenState->setObjectName("initialBrokenState");
+ machine.setInitialState(initialBrokenState);
+ new QState(initialBrokenState);
+
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: Missing initial state in compound state 'initialBrokenState'");
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+}
+
+void tst_QStateMachine::restoreProperties()
+{
+ QStateMachine machine;
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("a", 1);
+ object->setProperty("b", 2);
+
+ QState *S1 = new QState();
+ S1->setObjectName("S1");
+ S1->assignProperty(object, "a", 3);
+ machine.addState(S1);
+
+ QState *S2 = new QState();
+ S2->setObjectName("S2");
+ S2->assignProperty(object, "b", 5);
+ machine.addState(S2);
+
+ QState *S3 = new QState();
+ S3->setObjectName("S3");
+ machine.addState(S3);
+
+ QFinalState *S4 = new QFinalState();
+ machine.addState(S4);
+
+ S1->addTransition(new EventTransition(QEvent::User, S2));
+ S2->addTransition(new EventTransition(QEvent::User, S3));
+ S3->addTransition(S4);
+
+ machine.setInitialState(S1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 1);
+ QCOMPARE(object->property("b").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 1);
+ QCOMPARE(object->property("b").toInt(), 2);
+}
+
+void tst_QStateMachine::rootState()
+{
+ QStateMachine machine;
+ QVERIFY(machine.rootState() != 0);
+ QVERIFY(qobject_cast<QState*>(machine.rootState()) != 0);
+ QCOMPARE(qobject_cast<QState*>(machine.rootState())->parentState(), (QState*)0);
+ QCOMPARE(machine.rootState()->parent(), (QObject*)&machine);
+ QCOMPARE(machine.rootState()->machine(), &machine);
+
+ QState *s1 = new QState(machine.rootState());
+ QCOMPARE(s1->parentState(), machine.rootState());
+
+ QState *s2 = new QState();
+ s2->setParent(&machine);
+ QCOMPARE(s2->parentState(), machine.rootState());
+}
+
+void tst_QStateMachine::addAndRemoveState()
+{
+ QStateMachine machine;
+ QStatePrivate *root_d = QStatePrivate::get(machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 1); // the error state
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: cannot add null state");
+ machine.addState(0);
+
+ QState *s1 = new QState();
+ QCOMPARE(s1->parentState(), (QState*)0);
+ QCOMPARE(s1->machine(), (QStateMachine*)0);
+ machine.addState(s1);
+ QCOMPARE(s1->machine(), &machine);
+ QCOMPARE(s1->parentState(), machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 2);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s1);
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: state has already been added to this machine");
+ machine.addState(s1);
+
+ QState *s2 = new QState();
+ QCOMPARE(s2->parentState(), (QState*)0);
+ machine.addState(s2);
+ QCOMPARE(s2->parentState(), machine.rootState());
+ QCOMPARE(root_d->childStates().size(), 3);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s1);
+ QCOMPARE(root_d->childStates().at(2), (QAbstractState*)s2);
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::addState: state has already been added to this machine");
+ machine.addState(s2);
+
+ machine.removeState(s1);
+ QCOMPARE(s1->parentState(), (QState*)0);
+ QCOMPARE(root_d->childStates().size(), 2);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+ QCOMPARE(root_d->childStates().at(1), (QAbstractState*)s2);
+
+ machine.removeState(s2);
+ QCOMPARE(s2->parentState(), (QState*)0);
+ QCOMPARE(root_d->childStates().size(), 1);
+ QCOMPARE(root_d->childStates().at(0), (QAbstractState*)machine.errorState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::removeState: cannot remove null state");
+ machine.removeState(0);
+
+ {
+ QStateMachine machine2;
+ {
+ char warning[256];
+ sprintf(warning, "QStateMachine::removeState: state %p's machine (%p) is different from this machine (%p)",
+ machine2.rootState(), &machine2, &machine);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ machine.removeState(machine2.rootState());
+ }
+ // ### check this behavior
+ machine.addState(machine2.rootState());
+ QCOMPARE(machine2.rootState()->parent(), (QObject*)machine.rootState());
+ }
+
+ delete s1;
+ delete s2;
+ // ### how to deal with this?
+ // machine.removeState(machine.errorState());
+}
+
+void tst_QStateMachine::stateEntryAndExit()
+{
+ // Two top-level states
+ {
+ QStateMachine machine;
+
+ TestState *s1 = new TestState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
+ s1->addTransition((QAbstractState*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add null transition");
+ s1->addTransition((QAbstractTransition*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QState::removeTransition: cannot remove null transition");
+ s1->removeTransition((QAbstractTransition*)0);
+
+ TestState *s2 = new TestState(machine.rootState());
+ QFinalState *s3 = new QFinalState(machine.rootState());
+
+ TestTransition *t = new TestTransition(s2);
+ QCOMPARE(t->machine(), (QStateMachine*)0);
+ QCOMPARE(t->sourceState(), (QState*)0);
+ QCOMPARE(t->targetState(), s2);
+ QCOMPARE(t->targetStates().size(), 1);
+ QCOMPARE(t->targetStates().at(0), s2);
+ t->setTargetState(0);
+ QCOMPARE(t->targetState(), (QState*)0);
+ QVERIFY(t->targetStates().isEmpty());
+ t->setTargetState(s2);
+ QCOMPARE(t->targetState(), s2);
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::setTargetStates: target state(s) cannot be null");
+ t->setTargetStates(QList<QAbstractState*>() << 0);
+ QCOMPARE(t->targetState(), s2);
+ t->setTargetStates(QList<QAbstractState*>() << s2);
+ QCOMPARE(t->targetState(), s2);
+ QCOMPARE(t->targetStates().size(), 1);
+ QCOMPARE(t->targetStates().at(0), s2);
+ QCOMPARE(s1->addTransition(t), (QAbstractTransition*)t);
+ QCOMPARE(t->sourceState(), s1);
+ QCOMPARE(t->machine(), &machine);
+
+ {
+ QAbstractTransition *trans = s2->addTransition(s3);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)s2);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s3);
+ {
+ char warning[256];
+ sprintf(warning, "QState::removeTransition: transition %p's source state (%p) is different from this state (%p)", trans, s2, s1);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s1->removeTransition(trans);
+ }
+ s2->removeTransition(trans);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s3);
+ QCOMPARE(s2->addTransition(trans), trans);
+ QCOMPARE(trans->sourceState(), (QAbstractState*)s2);
+ }
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s1);
+ QCOMPARE(machine.initialState(), (QAbstractState*)s1);
+ {
+ char warning[256];
+ sprintf(warning, "QState::setInitialState: state %p is not a child of this state (%p)", machine.rootState(), machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ machine.setInitialState(machine.rootState());
+ QCOMPARE(machine.initialState(), (QAbstractState*)s1);
+ }
+ QVERIFY(machine.configuration().isEmpty());
+ globalTick = 0;
+ QVERIFY(!machine.isRunning());
+ machine.start();
+
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QTRY_COMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+
+ // s1 is entered
+ QCOMPARE(s1->events.count(), 2);
+ QCOMPARE(s1->events.at(0).first, 0);
+ QCOMPARE(s1->events.at(0).second, TestState::Entry);
+ // s1 is exited
+ QCOMPARE(s1->events.at(1).first, 1);
+ QCOMPARE(s1->events.at(1).second, TestState::Exit);
+ // t is triggered
+ QCOMPARE(t->triggers.count(), 1);
+ QCOMPARE(t->triggers.at(0), 2);
+ // s2 is entered
+ QCOMPARE(s2->events.count(), 2);
+ QCOMPARE(s2->events.at(0).first, 3);
+ QCOMPARE(s2->events.at(0).second, TestState::Entry);
+ // s2 is exited
+ QCOMPARE(s2->events.at(1).first, 4);
+ QCOMPARE(s2->events.at(1).second, TestState::Exit);
+ }
+ // Two top-level states, one has two child states
+ {
+ QStateMachine machine;
+
+ TestState *s1 = new TestState(machine.rootState());
+ TestState *s11 = new TestState(s1);
+ TestState *s12 = new TestState(s1);
+ TestState *s2 = new TestState(machine.rootState());
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s1->setInitialState(s11);
+ TestTransition *t1 = new TestTransition(s12);
+ s11->addTransition(t1);
+ TestTransition *t2 = new TestTransition(s2);
+ s12->addTransition(t2);
+ s2->addTransition(s3);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s1);
+ globalTick = 0;
+ machine.start();
+
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+
+ // s1 is entered
+ QCOMPARE(s1->events.count(), 2);
+ QCOMPARE(s1->events.at(0).first, 0);
+ QCOMPARE(s1->events.at(0).second, TestState::Entry);
+ // s11 is entered
+ QCOMPARE(s11->events.count(), 2);
+ QCOMPARE(s11->events.at(0).first, 1);
+ QCOMPARE(s11->events.at(0).second, TestState::Entry);
+ // s11 is exited
+ QCOMPARE(s11->events.at(1).first, 2);
+ QCOMPARE(s11->events.at(1).second, TestState::Exit);
+ // t1 is triggered
+ QCOMPARE(t1->triggers.count(), 1);
+ QCOMPARE(t1->triggers.at(0), 3);
+ // s12 is entered
+ QCOMPARE(s12->events.count(), 2);
+ QCOMPARE(s12->events.at(0).first, 4);
+ QCOMPARE(s12->events.at(0).second, TestState::Entry);
+ // s12 is exited
+ QCOMPARE(s12->events.at(1).first, 5);
+ QCOMPARE(s12->events.at(1).second, TestState::Exit);
+ // s1 is exited
+ QCOMPARE(s1->events.at(1).first, 6);
+ QCOMPARE(s1->events.at(1).second, TestState::Exit);
+ // t2 is triggered
+ QCOMPARE(t2->triggers.count(), 1);
+ QCOMPARE(t2->triggers.at(0), 7);
+ // s2 is entered
+ QCOMPARE(s2->events.count(), 2);
+ QCOMPARE(s2->events.at(0).first, 8);
+ QCOMPARE(s2->events.at(0).second, TestState::Entry);
+ // s2 is exited
+ QCOMPARE(s2->events.at(1).first, 9);
+ QCOMPARE(s2->events.at(1).second, TestState::Exit);
+ }
+}
+
+void tst_QStateMachine::assignProperty()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+
+ QTest::ignoreMessage(QtWarningMsg, "QState::assignProperty: cannot assign property 'foo' of null object");
+ s1->assignProperty(0, "foo", QVariant());
+
+ s1->assignProperty(s1, "objectName", "s1");
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s1->addTransition(s2);
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("s1"));
+
+ s1->assignProperty(s1, "objectName", "foo");
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("foo"));
+
+ s1->assignProperty(s1, "noSuchProperty", 123);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(s1->objectName(), QString::fromLatin1("foo"));
+ QCOMPARE(s1->dynamicPropertyNames().size(), 1);
+ QCOMPARE(s1->dynamicPropertyNames().at(0), QByteArray("noSuchProperty"));
+
+ QSignalSpy polishedSpy(s1, SIGNAL(polished()));
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(polishedSpy.count(), 1);
+}
+
+void tst_QStateMachine::assignPropertyWithAnimation()
+{
+ // Single animation
+ {
+ QStateMachine machine;
+ QVERIFY(machine.animationsEnabled());
+ machine.setAnimationsEnabled(false);
+ QVERIFY(!machine.animationsEnabled());
+ machine.setAnimationsEnabled(true);
+ QVERIFY(machine.animationsEnabled());
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QVERIFY(trans->animations().isEmpty());
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::addAnimation: cannot add null animation");
+ trans->addAnimation(0);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(250);
+ trans->addAnimation(&anim);
+ QCOMPARE(trans->animations().size(), 1);
+ QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim);
+ QCOMPARE(anim.parent(), (QObject*)0);
+ QTest::ignoreMessage(QtWarningMsg, "QAbstractTransition::removeAnimation: cannot remove null animation");
+ trans->removeAnimation(0);
+ trans->removeAnimation(&anim);
+ QVERIFY(trans->animations().isEmpty());
+ trans->addAnimation(&anim);
+ QCOMPARE(trans->animations().size(), 1);
+ QCOMPARE(trans->animations().at(0), (QAbstractAnimation*)&anim);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Two animations
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(150);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(150);
+ trans->addAnimation(&anim2);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Animation group
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(&obj, "foo", 123);
+ s1->assignProperty(&obj, "bar", 321);
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 654);
+ s2->assignProperty(&obj, "baz", 789);
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QSequentialAnimationGroup group;
+ group.addAnimation(new QPropertyAnimation(&obj, "foo"));
+ group.addAnimation(new QPropertyAnimation(&obj, "bar"));
+ trans->addAnimation(&group);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 456);
+ QCOMPARE(obj.property("bar").toInt(), 654);
+ QCOMPARE(obj.property("baz").toInt(), 789);
+ }
+ // Nested states
+ {
+ QStateMachine machine;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *s1 = new QState(machine.rootState());
+ QCOMPARE(s1->childMode(), QState::ExclusiveStates);
+ s1->setChildMode(QState::ParallelStates);
+ QCOMPARE(s1->childMode(), QState::ParallelStates);
+ s1->setChildMode(QState::ExclusiveStates);
+ QCOMPARE(s1->childMode(), QState::ExclusiveStates);
+ QCOMPARE(s1->initialState(), (QAbstractState*)0);
+ s1->setObjectName("s1");
+ s1->assignProperty(&obj, "foo", 123);
+ s1->assignProperty(&obj, "bar", 456);
+ QState *s2 = new QState(machine.rootState());
+ s2->setObjectName("s2");
+ s2->assignProperty(&obj, "foo", 321);
+ QState *s21 = new QState(s2);
+ s21->setObjectName("s21");
+ s21->assignProperty(&obj, "bar", 654);
+ QState *s22 = new QState(s2);
+ s22->setObjectName("s22");
+ s22->assignProperty(&obj, "bar", 789);
+ s2->setInitialState(s21);
+ QCOMPARE(s2->initialState(), (QAbstractState*)s21);
+
+ QAbstractTransition *trans = s1->addTransition(s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(500);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(250);
+ trans->addAnimation(&anim2);
+
+ s21->addTransition(s21, SIGNAL(polished()), s22);
+
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s22->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(obj.property("foo").toInt(), 321);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+ // Aborted animation
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QObject obj;
+ obj.setProperty("foo", 321);
+ obj.setProperty("bar", 654);
+ QState *group = new QState(machine.rootState());
+ QState *s1 = new QState(group);
+ group->setInitialState(s1);
+ s1->assignProperty(&obj, "foo", 123);
+ QState *s2 = new QState(group);
+ s2->assignProperty(&obj, "foo", 456);
+ s2->assignProperty(&obj, "bar", 789);
+ QAbstractTransition *trans = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
+ QPropertyAnimation anim(&obj, "foo");
+ anim.setDuration(8000);
+ trans->addAnimation(&anim);
+ QPropertyAnimation anim2(&obj, "bar");
+ anim2.setDuration(8000);
+ trans->addAnimation(&anim2);
+ QState *s3 = new QState(group);
+ s3->assignProperty(&obj, "foo", 911);
+ s2->addTransition(&emitter, SIGNAL(signalWithNoArg()), s3);
+
+ machine.setInitialState(group);
+ machine.start();
+ QTRY_COMPARE(machine.configuration().contains(s1), true);
+ QSignalSpy polishedSpy(s2, SIGNAL(polished()));
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(machine.configuration().contains(s2), true);
+ QVERIFY(polishedSpy.isEmpty());
+ emitter.emitSignalWithNoArg(); // will cause animations from s1-->s2 to abort
+ QTRY_COMPARE(machine.configuration().contains(s3), true);
+ QVERIFY(polishedSpy.isEmpty());
+ QCOMPARE(obj.property("foo").toInt(), 911);
+ QCOMPARE(obj.property("bar").toInt(), 789);
+ }
+}
+
+struct StringEvent : public QEvent
+{
+public:
+ StringEvent(const QString &val)
+ : QEvent(QEvent::Type(QEvent::User+2)),
+ value(val) {}
+
+ QString value;
+};
+
+class StringTransition : public QAbstractTransition
+{
+public:
+ StringTransition(const QString &value, QAbstractState *target)
+ : QAbstractTransition(QList<QAbstractState*>() << target), m_value(value) {}
+
+protected:
+ virtual bool eventTest(QEvent *e)
+ {
+ if (e->type() != QEvent::Type(QEvent::User+2))
+ return false;
+ StringEvent *se = static_cast<StringEvent*>(e);
+ return (m_value == se->value) && (!m_cond.isValid() || (m_cond.indexIn(m_value) != -1));
+ }
+ virtual void onTransition(QEvent *) {}
+
+private:
+ QString m_value;
+ QRegExp m_cond;
+};
+
+class StringEventPoster : public QState
+{
+public:
+ StringEventPoster(QStateMachine *machine, const QString &value, QState *parent = 0)
+ : QState(parent), m_machine(machine), m_value(value), m_delay(0) {}
+
+ void setString(const QString &value)
+ { m_value = value; }
+ void setDelay(int delay)
+ { m_delay = delay; }
+
+protected:
+ virtual void onEntry(QEvent *)
+ {
+ m_machine->postEvent(new StringEvent(m_value), m_delay);
+ }
+ virtual void onExit(QEvent *) {}
+
+private:
+ QStateMachine *m_machine;
+ QString m_value;
+ int m_delay;
+};
+
+void tst_QStateMachine::postEvent()
+{
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ {
+ QEvent e(QEvent::None);
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::postEvent: cannot post event when the state machine is not running");
+ machine.postEvent(&e);
+ }
+ StringEventPoster *s1 = new StringEventPoster(&machine, "a");
+ if (x == 1)
+ s1->setDelay(100);
+ QFinalState *s2 = new QFinalState;
+ s1->addTransition(new StringTransition("a", s2));
+ machine.addState(s1);
+ machine.addState(s2);
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ s1->setString("b");
+ QFinalState *s3 = new QFinalState();
+ machine.addState(s3);
+ s1->addTransition(new StringTransition("b", s3));
+ finishedSpy.clear();
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+ }
+}
+
+void tst_QStateMachine::stateFinished()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ QState *s1_1 = new QState(s1);
+ QFinalState *s1_2 = new QFinalState(s1);
+ s1_1->addTransition(s1_2);
+ s1->setInitialState(s1_1);
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s1->addTransition(s1, SIGNAL(finished()), s2);
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+}
+
+void tst_QStateMachine::parallelStates()
+{
+ QStateMachine machine;
+
+ QState *s1 = new QState(QState::ParallelStates);
+ QCOMPARE(s1->childMode(), QState::ParallelStates);
+ QState *s1_1 = new QState(s1);
+ QState *s1_1_1 = new QState(s1_1);
+ QFinalState *s1_1_f = new QFinalState(s1_1);
+ s1_1_1->addTransition(s1_1_f);
+ s1_1->setInitialState(s1_1_1);
+ QState *s1_2 = new QState(s1);
+ QState *s1_2_1 = new QState(s1_2);
+ QFinalState *s1_2_f = new QFinalState(s1_2);
+ s1_2_1->addTransition(s1_2_f);
+ s1_2->setInitialState(s1_2_1);
+ {
+ char warning[256];
+ sprintf(warning, "QState::setInitialState: ignoring attempt to set initial state of parallel state group %p", s1);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s1->setInitialState(0);
+ }
+ machine.addState(s1);
+
+ QFinalState *s2 = new QFinalState();
+ machine.addState(s2);
+
+ s1->addTransition(s1, SIGNAL(finished()), s2);
+
+ machine.setInitialState(s1);
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+}
+
+void tst_QStateMachine::allSourceToTargetConfigurations()
+{
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ s0->setObjectName("s0");
+ QState *s1 = new QState(s0);
+ s1->setObjectName("s1");
+ QState *s11 = new QState(s1);
+ s11->setObjectName("s11");
+ QState *s2 = new QState(s0);
+ s2->setObjectName("s2");
+ QState *s21 = new QState(s2);
+ s21->setObjectName("s21");
+ QState *s211 = new QState(s21);
+ s211->setObjectName("s211");
+ QFinalState *f = new QFinalState(machine.rootState());
+ f->setObjectName("f");
+
+ s0->setInitialState(s1);
+ s1->setInitialState(s11);
+ s2->setInitialState(s21);
+ s21->setInitialState(s211);
+
+ s11->addTransition(new StringTransition("g", s211));
+ s1->addTransition(new StringTransition("a", s1));
+ s1->addTransition(new StringTransition("b", s11));
+ s1->addTransition(new StringTransition("c", s2));
+ s1->addTransition(new StringTransition("d", s0));
+ s1->addTransition(new StringTransition("f", s211));
+ s211->addTransition(new StringTransition("d", s21));
+ s211->addTransition(new StringTransition("g", s0));
+ s211->addTransition(new StringTransition("h", f));
+ s21->addTransition(new StringTransition("b", s211));
+ s2->addTransition(new StringTransition("c", s1));
+ s2->addTransition(new StringTransition("f", s11));
+ s0->addTransition(new StringTransition("e", s211));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new StringEvent("a"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("b"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("c"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("d"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("e"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("f"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("g"));
+ QCoreApplication::processEvents();
+ machine.postEvent(new StringEvent("h"));
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+}
+
+class TestSignalTransition : public QSignalTransition
+{
+public:
+ TestSignalTransition(QState *sourceState = 0)
+ : QSignalTransition(sourceState) {}
+ TestSignalTransition(QObject *sender, const char *signal,
+ QAbstractState *target)
+ : QSignalTransition(sender, signal, QList<QAbstractState*>() << target) {}
+ QVariantList argumentsReceived() const {
+ return m_args;
+ }
+protected:
+ bool eventTest(QEvent *e) {
+ if (!QSignalTransition::eventTest(e))
+ return false;
+ QSignalEvent *se = static_cast<QSignalEvent*>(e);
+ const_cast<TestSignalTransition*>(this)->m_args = se->arguments();
+ return true;
+ }
+private:
+ QVariantList m_args;
+};
+
+void tst_QStateMachine::signalTransitions()
+{
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: sender cannot be null");
+ QCOMPARE(s0->addTransition(0, SIGNAL(noSuchSignal()), 0), (QObject*)0);
+
+ SignalEmitter emitter;
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: signal cannot be null");
+ QCOMPARE(s0->addTransition(&emitter, 0, 0), (QObject*)0);
+
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: cannot add transition to null state");
+ QCOMPARE(s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), 0), (QObject*)0);
+
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: no such signal SignalEmitter::noSuchSignal()");
+ QCOMPARE(s0->addTransition(&emitter, SIGNAL(noSuchSignal()), s1), (QObject*)0);
+
+ QSignalTransition *trans = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), s0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ emitter.emitSignalWithNoArg();
+
+ trans->setSignal(SIGNAL(signalWithIntArg(int)));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithIntArg(int))));
+ machine.start();
+ QCoreApplication::processEvents();
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setSignal(SIGNAL(signalWithNoArg()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 3);
+
+ SignalEmitter emitter2;
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setSenderObject(&emitter2);
+ emitter2.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 4);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ QTest::ignoreMessage(QtWarningMsg, "QSignalTransition: no such signal: SignalEmitter::noSuchSignal()");
+ trans->setSignal(SIGNAL(noSuchSignal()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(noSuchSignal())));
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
+ QSignalTransition *trans = s0->addTransition(&emitter, "signalWithNoArg()", s1);
+ QVERIFY(trans != 0);
+ QCOMPARE(trans->sourceState(), s0);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ QCOMPARE(trans->signal(), QByteArray("signalWithNoArg()"));
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ trans->setSignal("signalWithIntArg(int)");
+ QCOMPARE(trans->signal(), QByteArray("signalWithIntArg(int)"));
+ machine.start();
+ QCoreApplication::processEvents();
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
+ TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithIntArg(123);
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(trans->argumentsReceived().size(), 1);
+ QCOMPARE(trans->argumentsReceived().at(0).toInt(), 123);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ SignalEmitter emitter;
+ TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QString testString = QString::fromLatin1("hello");
+ emitter.emitSignalWithStringArg(testString);
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(trans->argumentsReceived().size(), 1);
+ QCOMPARE(trans->argumentsReceived().at(0).toString(), testString);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ TestSignalTransition *trans = new TestSignalTransition();
+ QCOMPARE(trans->senderObject(), (QObject*)0);
+ QCOMPARE(trans->signal(), QByteArray());
+
+ SignalEmitter emitter;
+ trans->setSenderObject(&emitter);
+ QCOMPARE(trans->senderObject(), (QObject*)&emitter);
+ trans->setSignal(SIGNAL(signalWithNoArg()));
+ QCOMPARE(trans->signal(), QByteArray(SIGNAL(signalWithNoArg())));
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ // Multiple transitions for same (object,signal)
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QState *s1 = new QState(machine.rootState());
+ QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QSignalTransition *t1 = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s0);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ s0->removeTransition(t0);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s1->removeTransition(t1);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s0->addTransition(t0);
+ s1->addTransition(t1);
+ emitter.emitSignalWithNoArg();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ }
+ // multiple signal transitions from same source
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithIntArg(int)), s2);
+ QFinalState *s3 = new QFinalState(machine.rootState());
+ s0->addTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s3);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ emitter.emitSignalWithNoArg();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ emitter.emitSignalWithIntArg(123);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 3);
+ emitter.emitSignalWithStringArg("hello");
+ QTRY_COMPARE(finishedSpy.count(), 3);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s3));
+ }
+}
+
+void tst_QStateMachine::eventTransitions()
+{
+ QPushButton button;
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QMouseEventTransition *trans;
+ if (x == 0) {
+ trans = new QMouseEventTransition(&button, QEvent::MouseButtonPress, Qt::LeftButton);
+ QCOMPARE(trans->targetState(), (QAbstractState*)0);
+ trans->setTargetState(s1);
+ } else {
+ trans = new QMouseEventTransition(&button, QEvent::MouseButtonPress,
+ Qt::LeftButton, QList<QAbstractState*>() << s1);
+ }
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonPress);
+ QCOMPARE(trans->button(), Qt::LeftButton);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ QTest::mousePress(&button, Qt::LeftButton);
+
+ trans->setEventType(QEvent::MouseButtonRelease);
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonRelease);
+ machine.start();
+ QCoreApplication::processEvents();
+ QTest::mouseRelease(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setEventType(QEvent::MouseButtonPress);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 3);
+
+ QPushButton button2;
+ machine.start();
+ QCoreApplication::processEvents();
+ trans->setEventObject(&button2);
+ QTest::mousePress(&button2, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 4);
+ }
+ for (int x = 0; x < 3; ++x) {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QEventTransition *trans;
+ if (x == 0) {
+ trans = new QEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::MouseButtonPress);
+ trans->setTargetState(s1);
+ } else if (x == 1) {
+ trans = new QEventTransition(&button, QEvent::MouseButtonPress);
+ trans->setTargetState(s1);
+ } else {
+ trans = new QEventTransition(&button, QEvent::MouseButtonPress,
+ QList<QAbstractState*>() << s1);
+ }
+ QCOMPARE(trans->eventObject(), (QObject*)&button);
+ QCOMPARE(trans->eventType(), QEvent::MouseButtonPress);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QMouseEventTransition *trans = new QMouseEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ QCOMPARE(trans->button(), Qt::NoButton);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::MouseButtonPress);
+ trans->setButton(Qt::LeftButton);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QKeyEventTransition *trans = new QKeyEventTransition(&button, QEvent::KeyPress, Qt::Key_A);
+ QCOMPARE(trans->eventType(), QEvent::KeyPress);
+ QCOMPARE(trans->key(), (int)Qt::Key_A);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::keyPress(&button, Qt::Key_A);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QKeyEventTransition *trans = new QKeyEventTransition();
+ QCOMPARE(trans->eventObject(), (QObject*)0);
+ QCOMPARE(trans->eventType(), QEvent::None);
+ QCOMPARE(trans->key(), 0);
+ trans->setEventObject(&button);
+ trans->setEventType(QEvent::KeyPress);
+ trans->setKey(Qt::Key_A);
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QTest::keyPress(&button, Qt::Key_A);
+ QCoreApplication::processEvents();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+ // Multiple transitions for same (object,event)
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QState *s1 = new QState(machine.rootState());
+ QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t0->setTargetState(s1);
+ s0->addTransition(t0);
+ QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t1->setTargetState(s0);
+ s1->addTransition(t1);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ s0->removeTransition(t0);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s1->removeTransition(t1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s0));
+
+ s0->addTransition(t0);
+ s1->addTransition(t1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ }
+ // multiple event transitions from same source
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QFinalState *s2 = new QFinalState(machine.rootState());
+ QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress);
+ t0->setTargetState(s1);
+ s0->addTransition(t0);
+ QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonRelease);
+ t1->setTargetState(s2);
+ s0->addTransition(t1);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QTest::mousePress(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ QTest::mouseRelease(&button, Qt::LeftButton);
+ QTRY_COMPARE(finishedSpy.count(), 2);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+ }
+ // custom event
+ {
+ QStateMachine machine;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+
+ QEventTransition *trans = new QEventTransition(&button, QEvent::Type(QEvent::User+1));
+ trans->setTargetState(s1);
+ s0->addTransition(trans);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ machine.setInitialState(s0);
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "QObject event transitions are not supported for custom types");
+ QTRY_COMPARE(startedSpy.count(), 1);
+ }
+}
+
+void tst_QStateMachine::historyStates()
+{
+ for (int x = 0; x < 2; ++x) {
+ QStateMachine machine;
+ QState *root = machine.rootState();
+ QState *s0 = new QState(root);
+ QState *s00 = new QState(s0);
+ QState *s01 = new QState(s0);
+ QHistoryState *s0h;
+ if (x == 0) {
+ s0h = new QHistoryState(s0);
+ QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory);
+ s0h->setHistoryType(QHistoryState::DeepHistory);
+ } else {
+ s0h = new QHistoryState(QHistoryState::DeepHistory, s0);
+ }
+ QCOMPARE(s0h->historyType(), QHistoryState::DeepHistory);
+ s0h->setHistoryType(QHistoryState::ShallowHistory);
+ QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory);
+ QCOMPARE(s0h->defaultState(), (QAbstractState*)0);
+ s0h->setDefaultState(s00);
+ QCOMPARE(s0h->defaultState(), (QAbstractState*)s00);
+ char warning[256];
+ sprintf(warning, "QHistoryState::setDefaultState: state %p does not belong to this history state's group (%p)", s0, s0);
+ QTest::ignoreMessage(QtWarningMsg, warning);
+ s0h->setDefaultState(s0);
+ QState *s1 = new QState(root);
+ QFinalState *s2 = new QFinalState(root);
+
+ s00->addTransition(new StringTransition("a", s01));
+ s0->addTransition(new StringTransition("b", s1));
+ s1->addTransition(new StringTransition("c", s0h));
+ s0->addTransition(new StringTransition("d", s2));
+
+ root->setInitialState(s0);
+ s0->setInitialState(s00);
+
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s00));
+
+ machine.postEvent(new StringEvent("a"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s01));
+
+ machine.postEvent(new StringEvent("b"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.postEvent(new StringEvent("c"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s0));
+ QVERIFY(machine.configuration().contains(s01));
+
+ machine.postEvent(new StringEvent("d"));
+ QCoreApplication::processEvents();
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s2));
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
+}
+
+void tst_QStateMachine::startAndStop()
+{
+ QStateMachine machine;
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ QVERIFY(!machine.isRunning());
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start: No initial state set for machine. Refusing to start.");
+ machine.start();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QVERIFY(!machine.isRunning());
+ machine.stop();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+ machine.start();
+ QTRY_COMPARE(machine.isRunning(), true);
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start(): already running");
+ machine.start();
+
+ machine.stop();
+ QTRY_COMPARE(machine.isRunning(), false);
+ QTRY_COMPARE(stoppedSpy.count(), 1);
+ QCOMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.start();
+ machine.stop();
+ QTRY_COMPARE(startedSpy.count(), 2);
+ QCOMPARE(stoppedSpy.count(), 2);
+}
+
+void tst_QStateMachine::targetStateWithNoParent()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ s1->setObjectName("s1");
+ QState s2;
+ s1->addTransition(&s2);
+ machine.setInitialState(s1);
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 's1'");
+ QTRY_COMPARE(machine.isRunning(), true);
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(machine.errorState()));
+ QCOMPARE(machine.error(), QStateMachine::NoCommonAncestorForTransitionError);
+}
+
+void tst_QStateMachine::targetStateDeleted()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ s1->setObjectName("s1");
+ QState *s2 = new QState(machine.rootState());
+ QAbstractTransition *trans = s1->addTransition(s2);
+ delete s2;
+ QCOMPARE(trans->targetState(), (QAbstractState*)0);
+ QVERIFY(trans->targetStates().isEmpty());
+}
+
+void tst_QStateMachine::defaultGlobalRestorePolicy()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+}
+
+/*
+void tst_QStateMachine::restorePolicyNotInherited()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *parentState = new QState(machine.rootState());
+ parentState->setObjectName("parentState");
+ parentState->setRestorePolicy(QState::RestoreProperties);
+
+ QState *s1 = new QState(parentState);
+ s1->setObjectName("s1");
+ s1->assignProperty(propertyHolder, "a", 3);
+ parentState->setInitialState(s1);
+
+ QState *s2 = new QState(parentState);
+ s2->setObjectName("s2");
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(parentState);
+ s3->setObjectName("s3");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(parentState);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+}*/
+
+void tst_QStateMachine::globalRestorePolicySetToDoNotRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::DoNotRestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+}
+
+/*
+void tst_QStateMachine::setRestorePolicyToDoNotRestore()
+{
+ QObject *object = new QObject();
+ object->setProperty("a", 1);
+ object->setProperty("b", 2);
+
+ QStateMachine machine;
+
+ QState *S1 = new QState();
+ S1->setObjectName("S1");
+ S1->assignProperty(object, "a", 3);
+ S1->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S1);
+
+ QState *S2 = new QState();
+ S2->setObjectName("S2");
+ S2->assignProperty(object, "b", 5);
+ S2->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S2);
+
+ QState *S3 = new QState();
+ S3->setObjectName("S3");
+ S3->setRestorePolicy(QState::DoNotRestoreProperties);
+ machine.addState(S3);
+
+ QFinalState *S4 = new QFinalState();
+ machine.addState(S4);
+
+ S1->addTransition(new EventTransition(QEvent::User, S2));
+ S2->addTransition(new EventTransition(QEvent::User, S3));
+ S3->addTransition(S4);
+
+ machine.setInitialState(S1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(object->property("a").toInt(), 3);
+ QCOMPARE(object->property("b").toInt(), 5);
+}
+
+void tst_QStateMachine::setGlobalRestorePolicyToGlobalRestore()
+{
+ s_countWarnings = false;
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
+
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties);
+ QCOMPARE(s_msgType, QtWarningMsg);
+
+ s_msgType = QtDebugMsg;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ machine.setGlobalRestorePolicy(QStateMachine::GlobalRestorePolicy);
+
+ QCOMPARE(machine.globalRestorePolicy(), QStateMachine::RestoreProperties);
+ QCOMPARE(s_msgType, QtWarningMsg);
+}
+
+
+void tst_QStateMachine::restorePolicyOnChildState()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *parentState = new QState(machine.rootState());
+ parentState->setObjectName("parentState");
+
+ QState *s1 = new QState(parentState);
+ s1->setRestorePolicy(QState::RestoreProperties);
+ s1->setObjectName("s1");
+ s1->assignProperty(propertyHolder, "a", 3);
+ parentState->setInitialState(s1);
+
+ QState *s2 = new QState(parentState);
+ s2->setRestorePolicy(QState::RestoreProperties);
+ s2->setObjectName("s2");
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(parentState);
+ s3->setRestorePolicy(QState::RestoreProperties);
+ s3->setObjectName("s3");
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(parentState);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+}
+*/
+
+void tst_QStateMachine::globalRestorePolicySetToRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("a", 1);
+ propertyHolder->setProperty("b", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "b", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("a").toInt(), 1);
+ QCOMPARE(propertyHolder->property("b").toInt(), 2);
+}
+
+/*
+void tst_QStateMachine::mixedRestoreProperties()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject();
+ propertyHolder->setProperty("a", 1);
+
+ QState *s1 = new QState(machine.rootState());
+ s1->setRestorePolicy(QState::RestoreProperties);
+ s1->assignProperty(propertyHolder, "a", 3);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "a", 4);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(propertyHolder, "a", 5);
+
+ QState *s5 = new QState(machine.rootState());
+ s5->setRestorePolicy(QState::RestoreProperties);
+ s5->assignProperty(propertyHolder, "a", 6);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+ s3->addTransition(new EventTransition(QEvent::User, s4));
+ s4->addTransition(new EventTransition(QEvent::User, s5));
+ s5->addTransition(new EventTransition(QEvent::User, s3));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ // Enter s1, save current
+ QCOMPARE(propertyHolder->property("a").toInt(), 3);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s2, restorePolicy == DoNotRestore, so restore all properties
+ QCOMPARE(propertyHolder->property("a").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s3
+ QCOMPARE(propertyHolder->property("a").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s4
+ QCOMPARE(propertyHolder->property("a").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s5, save current
+ QCOMPARE(propertyHolder->property("a").toInt(), 6);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ // Enter s3, restore
+ QCOMPARE(propertyHolder->property("a").toInt(), 5);
+}
+*/
+
+void tst_QStateMachine::transitionWithParent()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ EventTransition *trans = new EventTransition(QEvent::User, s2, s1);
+ QCOMPARE(trans->sourceState(), s1);
+ QCOMPARE(trans->targetState(), (QAbstractState*)s2);
+ QCOMPARE(trans->targetStates().size(), 1);
+ QCOMPARE(trans->targetStates().at(0), (QAbstractState*)s2);
+}
+
+void tst_QStateMachine::simpleAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("fooBar", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "fooBar", 2.0);
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "fooBar", s2);
+ et->addAnimation(animation);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(animation, SIGNAL(finished()), s3);
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("fooBar").toDouble(), 2.0);
+}
+
+class SlotCalledCounter: public QObject
+{
+ Q_OBJECT
+public:
+ SlotCalledCounter() : counter(0) {}
+
+ int counter;
+
+public slots:
+ void slot() { counter++; }
+};
+
+void tst_QStateMachine::twoAnimations()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+ s2->assignProperty(object, "bar", 10.0);
+
+ QPropertyAnimation *animationFoo = new QPropertyAnimation(object, "foo", s2);
+ QPropertyAnimation *animationBar = new QPropertyAnimation(object, "bar", s2);
+ animationBar->setDuration(900);
+
+ SlotCalledCounter counter;
+ connect(animationFoo, SIGNAL(finished()), &counter, SLOT(slot()));
+ connect(animationBar, SIGNAL(finished()), &counter, SLOT(slot()));
+
+ EventTransition *et = new EventTransition(QEvent::User, s2);
+ et->addAnimation(animationFoo);
+ et->addAnimation(animationBar);
+ s1->addTransition(et);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(s2, SIGNAL(polished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::twoAnimatedTransitions()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation2);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::playAnimationTwice()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 5.0);
+ QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(fooAnimation);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
+
+ QState *s4 = new QState(machine.rootState());
+ s4->assignProperty(object, "foo", 2.0);
+ s3->addTransition(new EventTransition(QEvent::User, s4))->addAnimation(fooAnimation);
+
+ QState *s5 = new QState(machine.rootState());
+ QObject::connect(s5, SIGNAL(entered()), QApplication::instance(), SLOT(quit()));
+ s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 5.0);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s5));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::nestedTargetStateForAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 3.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s2Child = new QState(s2);
+ s2Child->assignProperty(object, "bar", 10.0);
+ s2->setInitialState(s2Child);
+
+ QState *s2Child2 = new QState(s2);
+ s2Child2->assignProperty(object, "bar", 11.0);
+ QAbstractTransition *at = s2Child->addTransition(new EventTransition(QEvent::User, s2Child2));
+
+ QPropertyAnimation *animation = new QPropertyAnimation(object, "bar", s2);
+ animation->setDuration(2000);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ animation = new QPropertyAnimation(object, "foo", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ animation = new QPropertyAnimation(object, "bar", s2);
+ connect(animation, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(animation);
+
+ QState *s3 = new QState(machine.rootState());
+ s2->addTransition(s2Child, SIGNAL(polished()), s3);
+
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(object->property("bar").toDouble(), 10.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::animatedGlobalRestoreProperty()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+
+ QState *s4 = new QState(machine.rootState());
+ QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", s2);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s2->addTransition(pa, SIGNAL(finished()), s3);
+ pa = new QPropertyAnimation(object, "foo", s3);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ at = s3->addTransition(pa, SIGNAL(finished()), s4);
+ pa = new QPropertyAnimation(object, "foo", s4);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ at->addAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s4));
+ QCOMPARE(object->property("foo").toDouble(), 1.0);
+ QCOMPARE(counter.counter, 2);
+}
+
+void tst_QStateMachine::specificTargetValueOfAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
+ anim->setEndValue(10.0);
+ s1->addTransition(new EventTransition(QEvent::User, s2))->addAnimation(anim);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+ s2->addTransition(anim, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(anim->endValue().toDouble(), 10.0);
+}
+
+void tst_QStateMachine::addDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+ object->setProperty("bar", 2.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ pa = new QPropertyAnimation(object, "bar", &machine);
+ connect(pa, SIGNAL(finished()), &counter, SLOT(slot()));
+ machine.addDefaultAnimation(pa);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+ QCOMPARE(counter.counter, 1);
+}
+
+void tst_QStateMachine::removeDefaultAnimation()
+{
+ QStateMachine machine;
+
+ QObject propertyHolder;
+ propertyHolder.setProperty("foo", 0);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(&propertyHolder, "foo");
+
+ machine.addDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+
+ machine.addDefaultAnimation(anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(&propertyHolder, "foo");
+ machine.addDefaultAnimation(anim2);
+
+ QCOMPARE(machine.defaultAnimations().size(), 2);
+ QVERIFY(machine.defaultAnimations().contains(anim));
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 1);
+ QVERIFY(machine.defaultAnimations().contains(anim2));
+
+ machine.removeDefaultAnimation(anim2);
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+/*
+void tst_QStateMachine::addDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForSourceState(s1, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::addDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ QState *s1 = new QState(machine.rootState());
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *pa = new QPropertyAnimation(object, "foo", &machine);
+ machine.addDefaultAnimationForTargetState(s2, pa);
+ s2->addTransition(pa, SIGNAL(finished()), s3);
+
+ machine.setInitialState(s1);
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("foo").toDouble(), 2.0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForSource()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForSourceState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForSourceState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::removeDefaultAnimationForTarget()
+{
+ QStateMachine machine;
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ QPropertyAnimation *anim = new QPropertyAnimation(this, "foo");
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForSourceState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimations().size(), 0);
+ QCOMPARE(machine.defaultAnimationsForSourceState(machine.rootState()).size(), 0);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(this, "foo");
+ machine.addDefaultAnimationForTargetState(machine.rootState(), anim2);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 2);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim));
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim);
+
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 1);
+ QVERIFY(machine.defaultAnimationsForTargetState(machine.rootState()).contains(anim2));
+
+ machine.removeDefaultAnimationForTargetState(machine.rootState(), anim2);
+ QCOMPARE(machine.defaultAnimationsForTargetState(machine.rootState()).size(), 0);
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultAnimationWithTarget()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimation(defaultAnimation);
+ machine.addDefaultAnimationForTargetState(s2, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+
+}
+
+void tst_QStateMachine::overrideDefaultSourceAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForSourceState(s1, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSpecific()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ QAbstractTransition *at = s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ at->addAnimation(moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+void tst_QStateMachine::overrideDefaultTargetAnimationWithSource()
+{
+ QStateMachine machine;
+
+ QObject *object = new QObject();
+ object->setProperty("foo", 1.0);
+
+ SlotCalledCounter counter;
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(object, "foo", 2.0);
+
+ QState *s3 = new QState(machine.rootState());
+ QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QPropertyAnimation *defaultAnimation = new QPropertyAnimation(object, "foo");
+ connect(defaultAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ QPropertyAnimation *moreSpecificAnimation = new QPropertyAnimation(object, "foo");
+ s2->addTransition(moreSpecificAnimation, SIGNAL(finished()), s3);
+ connect(moreSpecificAnimation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), &counter, SLOT(slot()));
+
+ machine.addDefaultAnimationForTargetState(s2, defaultAnimation);
+ machine.addDefaultAnimationForSourceState(s1, moreSpecificAnimation);
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCOREAPPLICATION_EXEC(5000);
+
+ QVERIFY(machine.configuration().contains(s3));
+ QCOMPARE(counter.counter, 2); // specific animation started and stopped
+}
+
+*/
+
+void tst_QStateMachine::parallelStateAssignmentsDone()
+{
+ QStateMachine machine;
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 123);
+ propertyHolder->setProperty("bar", 456);
+ propertyHolder->setProperty("zoot", 789);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ parallelState->assignProperty(propertyHolder, "foo", 321);
+
+ QState *s2 = new QState(parallelState);
+ s2->assignProperty(propertyHolder, "bar", 654);
+
+ QState *s3 = new QState(parallelState);
+ s3->assignProperty(propertyHolder, "zoot", 987);
+
+ s1->addTransition(new EventTransition(QEvent::User, parallelState));
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("foo").toInt(), 123);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 456);
+ QCOMPARE(propertyHolder->property("zoot").toInt(), 789);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(propertyHolder->property("foo").toInt(), 321);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 654);
+ QCOMPARE(propertyHolder->property("zoot").toInt(), 987);
+}
+
+void tst_QStateMachine::transitionsFromParallelStateWithNoChildren()
+{
+ QStateMachine machine;
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ machine.setInitialState(parallelState);
+
+ QState *s1 = new QState(machine.rootState());
+ parallelState->addTransition(new EventTransition(QEvent::User, s1));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(1, machine.configuration().size());
+ QVERIFY(machine.configuration().contains(parallelState));
+
+ machine.postEvent(new QEvent(QEvent::User));
+
+ QCoreApplication::processEvents();
+
+ QCOMPARE(1, machine.configuration().size());
+ QVERIFY(machine.configuration().contains(s1));
+}
+
+void tst_QStateMachine::parallelStateTransition()
+{
+ QStateMachine machine;
+
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
+ machine.setInitialState(parallelState);
+
+ QState *s1 = new QState(parallelState);
+ QState *s2 = new QState(parallelState);
+
+ QState *s1InitialChild = new QState(s1);
+ s1->setInitialState(s1InitialChild);
+
+ QState *s2InitialChild = new QState(s2);
+ s2->setInitialState(s2InitialChild);
+
+ QState *s1OtherChild = new QState(s1);
+
+ s1->addTransition(new EventTransition(QEvent::User, s1OtherChild));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+ QVERIFY(machine.configuration().contains(s1));
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1InitialChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QVERIFY(machine.configuration().contains(parallelState));
+
+ QVERIFY(machine.configuration().contains(s1));
+
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s1OtherChild));
+ QVERIFY(machine.configuration().contains(s2InitialChild));
+ QCOMPARE(machine.configuration().size(), 5);
+
+}
+
+void tst_QStateMachine::nestedRestoreProperties()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 1);
+ propertyHolder->setProperty("bar", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "foo", 3);
+
+ QState *s21 = new QState(s2);
+ s21->assignProperty(propertyHolder, "bar", 4);
+ s2->setInitialState(s21);
+
+ QState *s22 = new QState(s2);
+ s22->assignProperty(propertyHolder, "bar", 5);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s21->addTransition(new EventTransition(QEvent::User, s22));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 1);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s22));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 5);
+}
+
+void tst_QStateMachine::nestedRestoreProperties2()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 1);
+ propertyHolder->setProperty("bar", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "foo", 3);
+
+ QState *s21 = new QState(s2);
+ s21->assignProperty(propertyHolder, "bar", 4);
+ s2->setInitialState(s21);
+
+ QState *s22 = new QState(s2);
+ s22->assignProperty(propertyHolder, "foo", 6);
+ s22->assignProperty(propertyHolder, "bar", 5);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s21->addTransition(new EventTransition(QEvent::User, s22));
+ s22->addTransition(new EventTransition(QEvent::User, s21));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 1);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s22));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 6);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 5);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+}
+
+
+QTEST_MAIN(tst_QStateMachine)
+#include "tst_qstatemachine.moc"
diff --git a/tests/auto/qtcpserver/tst_qtcpserver.cpp b/tests/auto/qtcpserver/tst_qtcpserver.cpp
index 50b293d..4fd1827 100644
--- a/tests/auto/qtcpserver/tst_qtcpserver.cpp
+++ b/tests/auto/qtcpserver/tst_qtcpserver.cpp
@@ -364,7 +364,7 @@ void tst_QTcpServer::ipv6LoopbackPerformanceTest()
void tst_QTcpServer::ipv4PerformanceTest()
{
QTcpSocket probeSocket;
- probeSocket.connectToHost("imap.troll.no", 143);
+ probeSocket.connectToHost(QtNetworkSettings::serverName(), 143);
QVERIFY(probeSocket.waitForConnected(5000));
QTcpServer server;
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index 2daa0f6..26f5f40 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -77,6 +77,7 @@ private slots:
void fileTemplate_data();
void getSetCheck();
void fileName();
+ void fileNameIsEmpty();
void autoRemove();
void write();
void openCloseOpenClose();
@@ -86,6 +87,8 @@ private slots:
void stressTest();
void rename();
void renameFdLeak();
+ void reOpenThroughQFile();
+
public:
};
@@ -189,6 +192,27 @@ void tst_QTemporaryFile::fileName()
QCOMPARE(absoluteFilePath, absoluteTempPath);
}
+void tst_QTemporaryFile::fileNameIsEmpty()
+{
+ QString filename;
+ {
+ QTemporaryFile file;
+ QVERIFY(file.fileName().isEmpty());
+
+ QVERIFY(file.open());
+ QVERIFY(!file.fileName().isEmpty());
+
+ filename = file.fileName();
+ QVERIFY(QFile::exists(filename));
+
+ file.close();
+ QVERIFY(!file.isOpen());
+ QVERIFY(QFile::exists(filename));
+ QVERIFY(!file.fileName().isEmpty());
+ }
+ QVERIFY(!QFile::exists(filename));
+}
+
void tst_QTemporaryFile::autoRemove()
{
// Test auto remove
@@ -358,6 +382,7 @@ void tst_QTemporaryFile::rename()
QVERIFY(file.rename("temporary-file.txt"));
QVERIFY(!dir.exists(tempname));
QVERIFY(dir.exists("temporary-file.txt"));
+ QCOMPARE(file.fileName(), QString("temporary-file.txt"));
}
QVERIFY(!dir.exists(tempname));
@@ -401,5 +426,18 @@ void tst_QTemporaryFile::renameFdLeak()
#endif
}
+void tst_QTemporaryFile::reOpenThroughQFile()
+{
+ QByteArray data("abcdefghij");
+
+ QTemporaryFile file;
+ QVERIFY(((QFile &)file).open(QIODevice::WriteOnly));
+ QCOMPARE(file.write(data), (qint64)data.size());
+
+ file.close();
+ QVERIFY(file.open());
+ QCOMPARE(file.readAll(), data);
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"
diff --git a/tests/auto/qtessellator/testtessellator.cpp b/tests/auto/qtessellator/testtessellator.cpp
index bd2795c..423c1e8 100644
--- a/tests/auto/qtessellator/testtessellator.cpp
+++ b/tests/auto/qtessellator/testtessellator.cpp
@@ -38,7 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include <testtessellator.h>
+#include "testtessellator.h"
#include <private/qtessellator_p.h>
#include "math.h"
diff --git a/tests/auto/qtessellator/tst_tessellator.cpp b/tests/auto/qtessellator/tst_tessellator.cpp
index 8958ac3..8899285 100644
--- a/tests/auto/qtessellator/tst_tessellator.cpp
+++ b/tests/auto/qtessellator/tst_tessellator.cpp
@@ -218,8 +218,8 @@ void tst_QTessellator::testArc()
const int stop = 1000;
#endif
for (int i = 0; i < stop; ++i) {
- mat.rotate(.01);
- mat.scale(.99, .99);
+ mat.rotate(qreal(.01));
+ mat.scale(qreal(.99), qreal(.99));
QPolygonF poly = arc.at(0);
QPolygonF vec = poly * mat;
QVERIFY(test_arc(vec, true));
@@ -361,11 +361,11 @@ void tst_QTessellator::testRects()
QVector<QPointF> v(5);
for (int i = 0; i < 5; ++i)
v[i] = vec[5 * rect + i];
- if (!test(v.data(), v.size(), false, test_tessellate_polygon_rect, 0.05)) {
+ if (!test(v.data(), v.size(), false, test_tessellate_polygon_rect, qreal(0.05))) {
simplifyTestFailure(v, false);
++failures;
}
- if (!test(v.data(), v.size(), true, test_tessellate_polygon_rect, 0.05)) {
+ if (!test(v.data(), v.size(), true, test_tessellate_polygon_rect, qreal(0.05))) {
simplifyTestFailure(v, true);
++failures;
}
diff --git a/tests/auto/qtessellator/utils.cpp b/tests/auto/qtessellator/utils.cpp
index 8a9dc1e..d408193 100644
--- a/tests/auto/qtessellator/utils.cpp
+++ b/tests/auto/qtessellator/utils.cpp
@@ -43,7 +43,7 @@
#include <assert.h>
#include <qglobal.h>
-#include <qnum.h>
+#include "qnum.h"
#define FloatToXFixed(i) (int)((i) * 65536)
#define IntToXFixed(i) ((i) << 16)
diff --git a/tests/auto/qthreadonce/tst_qthreadonce.cpp b/tests/auto/qthreadonce/tst_qthreadonce.cpp
index 7e67dc3..f20788a 100644
--- a/tests/auto/qthreadonce/tst_qthreadonce.cpp
+++ b/tests/auto/qthreadonce/tst_qthreadonce.cpp
@@ -46,7 +46,7 @@
#include <qmutex.h>
#include <qthread.h>
#include <qwaitcondition.h>
-#include <qthreadonce.h>
+#include "qthreadonce.h"
//TESTED_CLASS=
//TESTED_FILES=corelib/thread/qthreadonce.h corelib/thread/qthreadonce.cpp
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index c4517d6..2ef76a4 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -227,6 +227,7 @@ private slots:
void task246536_scrollbarsNotWorking();
void task250683_wrongSectionSize();
void task239271_addRowsWithFirstColumnHidden();
+ void task254234_proxySort();
};
class QtTestModel: public QAbstractItemModel
@@ -2498,7 +2499,6 @@ void tst_QTreeView::sortByColumn()
QCOMPARE(view.header()->sortIndicatorSection(), 0);
QCOMPARE(view.model()->data(view.model()->index(0,0)).toString(), QString::fromLatin1("a"));
QCOMPARE(view.model()->data(view.model()->index(1,0)).toString(), QString::fromLatin1("b"));
-
}
/*
@@ -3346,7 +3346,6 @@ void tst_QTreeView::task246536_scrollbarsNotWorking()
QVERIFY(o.count > 0);
}
-
void tst_QTreeView::task250683_wrongSectionSize()
{
QDirModel model;
@@ -3400,5 +3399,32 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden()
QVERIFY(delegate.paintedIndexes.contains(sub11.index()));
}
+void tst_QTreeView::task254234_proxySort()
+{
+ //based on tst_QTreeView::sortByColumn
+ // it used not to work when setting the source of a proxy after enabling sorting
+ QTreeView view;
+ QStandardItemModel model(4,2);
+ model.setItem(0,0,new QStandardItem("b"));
+ model.setItem(1,0,new QStandardItem("d"));
+ model.setItem(2,0,new QStandardItem("c"));
+ model.setItem(3,0,new QStandardItem("a"));
+ model.setItem(0,1,new QStandardItem("e"));
+ model.setItem(1,1,new QStandardItem("g"));
+ model.setItem(2,1,new QStandardItem("h"));
+ model.setItem(3,1,new QStandardItem("f"));
+
+ view.sortByColumn(1);
+ view.setSortingEnabled(true);
+
+ QSortFilterProxyModel proxy;
+ proxy.setDynamicSortFilter(true);
+ view.setModel(&proxy);
+ proxy.setSourceModel(&model);
+ QCOMPARE(view.header()->sortIndicatorSection(), 1);
+ QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h"));
+ QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g"));
+}
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index efdaaec..3fad366 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -350,6 +350,9 @@ private slots:
void updateOnDestroyedSignal();
void toplevelLineEditFocus();
+ void focusWidget_task254563();
+ void focusWidget_mixed_widget_hierarchy();
+
private:
bool ensureScreenSize(int width, int height);
QWidget *testWidget;
@@ -8412,6 +8415,7 @@ void tst_QWidget::translucentWidget()
ColorRedWidget label;
label.setFixedSize(16,16);
label.setAttribute(Qt::WA_TranslucentBackground);
+ label.move(qApp->desktop()->availableGeometry().topLeft());
label.show();
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&label);
@@ -8976,5 +8980,37 @@ void tst_QWidget::toplevelLineEditFocus()
QCOMPARE(QApplication::focusWidget(), &w);
}
+void tst_QWidget::focusWidget_task254563()
+{
+ //having different visibility for widget is important
+ QWidget top;
+ top.show();
+ QWidget container(&top);
+ QWidget *widget = new QWidget(&container);
+ widget->show();
+
+ widget->setFocus(); //set focus (will set the focus widget up to the toplevel to be 'widget')
+ container.setFocus();
+ delete widget; // will call clearFocus but that doesn't help
+ QVERIFY(top.focusWidget() != widget); //dangling pointer
+}
+
+void tst_QWidget::focusWidget_mixed_widget_hierarchy()
+{
+ QWidget top;
+ top.show();
+ QWidget notvisible(&top);
+ QWidget *visible = new QWidget(&notvisible);
+ visible->show();
+
+ visible->setFocus();
+ notvisible.setFocus();
+ notvisible.show();
+ QCOMPARE(top.focusWidget(), visible);
+ QCOMPARE(notvisible.focusWidget(), visible);
+ QCOMPARE(visible->focusWidget(), visible);
+}
+
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"
diff --git a/tests/auto/selftests/expected_xunit.txt b/tests/auto/selftests/expected_xunit.txt
index 875dda6..cb74491 100644
--- a/tests/auto/selftests/expected_xunit.txt
+++ b/tests/auto/selftests/expected_xunit.txt
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<testsuite errors="3" failures="2" tests="6" name="tst_Xunit">
+<testsuite errors="5" failures="3" tests="9" name="tst_Xunit">
<properties>
<property value="4.6.0" name="QTestVersion"/>
<property value="4.6.0" name="QtVersion"/>
@@ -20,10 +20,21 @@
<testcase result="fail" name="testFunc4">
<failure message="a forced failure!" result="fail"/>
</testcase>
+ <testcase result="xfail" name="testFunc5">
+ <!-- message="this failure is expected" type="info" -->
+ </testcase>
+ <testcase result="xfail" name="testFunc6">
+ <!-- message="this failure is also expected" type="info" -->
+ </testcase>
+ <testcase result="xpass" name="testFunc7">
+ <failure message="&apos;true&apos; returned FALSE. ()" result="xpass"/>
+ </testcase>
<testcase result="pass" name="cleanupTestCase"/>
<system-err>
<![CDATA[just a QWARN() !]]>
<![CDATA[a qDebug() call with comment-ending stuff -->]]>
<![CDATA[skipping this function!]]>
+<![CDATA[this failure is expected]]>
+<![CDATA[this failure is also expected]]>
</system-err>
</testsuite>
diff --git a/tests/auto/selftests/xunit/tst_xunit.cpp b/tests/auto/selftests/xunit/tst_xunit.cpp
index dbe9fec..c3c90ab 100644
--- a/tests/auto/selftests/xunit/tst_xunit.cpp
+++ b/tests/auto/selftests/xunit/tst_xunit.cpp
@@ -53,6 +53,9 @@ private slots:
void testFunc2();
void testFunc3();
void testFunc4();
+ void testFunc5();
+ void testFunc6();
+ void testFunc7();
};
tst_Xunit::tst_Xunit()
@@ -81,6 +84,32 @@ void tst_Xunit::testFunc4()
QFAIL("a forced failure!");
}
+/*
+ Note there are two testfunctions which give expected failures.
+ This is so we can test that expected failures don't add to failure
+ counts and unexpected passes do. If we had one xfail and one xpass
+ testfunction, we couldn't test which one of them adds to the failure
+ count.
+*/
+
+void tst_Xunit::testFunc5()
+{
+ QEXPECT_FAIL("", "this failure is expected", Abort);
+ QVERIFY(false);
+}
+
+void tst_Xunit::testFunc6()
+{
+ QEXPECT_FAIL("", "this failure is also expected", Abort);
+ QVERIFY(false);
+}
+
+void tst_Xunit::testFunc7()
+{
+ QEXPECT_FAIL("", "this pass is unexpected", Abort);
+ QVERIFY(true);
+}
+
QTEST_APPLESS_MAIN(tst_Xunit)
#include "tst_xunit.moc"
diff --git a/tests/auto/test.pl b/tests/auto/test.pl
index f2a1fe4..9fd5c9d 100755
--- a/tests/auto/test.pl
+++ b/tests/auto/test.pl
@@ -179,7 +179,7 @@ print " Tests started: $totalStarted \n";
print " Tests executed: $totalExecuted \n";
print " Tests timed out: $totalTimedOut \n";
-# This procedure takes care of handling death children on due time
+# This procedure takes care of handling dead children on due time
sub handleDeath {
$buryChildren = 1;
}
diff --git a/tests/auto/uic/baseline/languagesdialog.ui.h b/tests/auto/uic/baseline/languagesdialog.ui.h
index a0b9cae..fbe57ca 100644
--- a/tests/auto/uic/baseline/languagesdialog.ui.h
+++ b/tests/auto/uic/baseline/languagesdialog.ui.h
@@ -1,8 +1,8 @@
/********************************************************************************
** Form generated from reading ui file 'languagesdialog.ui'
**
-** Created: Mon Jun 16 17:57:32 2008
-** by: Qt User Interface Compiler version 4.5.0
+** Created: Fri May 15 16:58:03 2009
+** by: Qt User Interface Compiler version 4.5.2
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
@@ -57,7 +57,7 @@ public:
upButton->setObjectName(QString::fromUtf8("upButton"));
upButton->setEnabled(false);
QIcon icon;
- icon.addPixmap(QPixmap(QString::fromUtf8(":/images/up.png")), QIcon::Normal, QIcon::Off);
+ icon.addFile(QString::fromUtf8(":/images/up.png"), QSize(), QIcon::Normal, QIcon::Off);
upButton->setIcon(icon);
hboxLayout->addWidget(upButton);
@@ -66,7 +66,7 @@ public:
downButton->setObjectName(QString::fromUtf8("downButton"));
downButton->setEnabled(false);
QIcon icon1;
- icon1.addPixmap(QPixmap(QString::fromUtf8(":/images/down.png")), QIcon::Normal, QIcon::Off);
+ icon1.addFile(QString::fromUtf8(":/images/down.png"), QSize(), QIcon::Normal, QIcon::Off);
downButton->setIcon(icon1);
hboxLayout->addWidget(downButton);
@@ -75,7 +75,7 @@ public:
removeButton->setObjectName(QString::fromUtf8("removeButton"));
removeButton->setEnabled(false);
QIcon icon2;
- icon2.addPixmap(QPixmap(QString::fromUtf8(":/images/editdelete.png")), QIcon::Normal, QIcon::Off);
+ icon2.addFile(QString::fromUtf8(":/images/editdelete.png"), QSize(), QIcon::Normal, QIcon::Off);
removeButton->setIcon(icon2);
hboxLayout->addWidget(removeButton);
@@ -84,7 +84,7 @@ public:
openFileButton->setObjectName(QString::fromUtf8("openFileButton"));
openFileButton->setEnabled(true);
QIcon icon3;
- icon3.addPixmap(QPixmap(QString::fromUtf8(":/images/mac/fileopen.png")), QIcon::Normal, QIcon::Off);
+ icon3.addFile(QString::fromUtf8(":/images/mac/fileopen.png"), QSize(), QIcon::Normal, QIcon::Off);
openFileButton->setIcon(icon3);
hboxLayout->addWidget(openFileButton);
diff --git a/tests/auto/utf8/tst_utf8.cpp b/tests/auto/utf8/tst_utf8.cpp
index 3aef69f..e21e5a3 100644
--- a/tests/auto/utf8/tst_utf8.cpp
+++ b/tests/auto/utf8/tst_utf8.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index 8e2c243..bc41125 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = containers-associative \
containers-sequential \
+ qanimation \
qbytearray \
qpainter \
qtestlib-simple events \
@@ -8,6 +9,7 @@ SUBDIRS = containers-associative \
qpixmap \
blendbench \
qstringlist \
+ qmatrix4x4 \
qobject \
qrect \
qregexp \
diff --git a/tests/benchmarks/qanimation/dummyanimation.cpp b/tests/benchmarks/qanimation/dummyanimation.cpp
new file mode 100644
index 0000000..6fb1d0a
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyanimation.cpp
@@ -0,0 +1,20 @@
+#include "dummyanimation.h"
+#include "dummyobject.h"
+
+
+DummyAnimation::DummyAnimation(DummyObject *d) : m_dummy(d)
+{
+}
+
+void DummyAnimation::updateCurrentValue(const QVariant &value)
+{
+ if (state() == Stopped)
+ return;
+ if (m_dummy)
+ m_dummy->setRect(value.toRect());
+}
+
+void DummyAnimation::updateState(State state)
+{
+ Q_UNUSED(state);
+}
diff --git a/tests/benchmarks/qanimation/dummyanimation.h b/tests/benchmarks/qanimation/dummyanimation.h
new file mode 100644
index 0000000..fe6592b
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyanimation.h
@@ -0,0 +1,19 @@
+#include <QtGui>
+
+#ifndef _DUMMYANIMATION_H__
+
+class DummyObject;
+
+class DummyAnimation : public QVariantAnimation
+{
+public:
+ DummyAnimation(DummyObject *d);
+
+ void updateCurrentValue(const QVariant &value);
+ void updateState(State state);
+
+private:
+ DummyObject *m_dummy;
+};
+
+#endif \ No newline at end of file
diff --git a/tests/benchmarks/qanimation/dummyobject.cpp b/tests/benchmarks/qanimation/dummyobject.cpp
new file mode 100644
index 0000000..bd76388
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyobject.cpp
@@ -0,0 +1,25 @@
+#include "dummyobject.h"
+
+DummyObject::DummyObject()
+{
+}
+
+QRect DummyObject::rect() const
+{
+ return m_rect;
+}
+
+void DummyObject::setRect(const QRect &r)
+{
+ m_rect = r;
+}
+
+float DummyObject::opacity() const
+{
+ return m_opacity;
+}
+
+void DummyObject::setOpacity(float o)
+{
+ m_opacity = o;
+}
diff --git a/tests/benchmarks/qanimation/dummyobject.h b/tests/benchmarks/qanimation/dummyobject.h
new file mode 100644
index 0000000..c989662
--- /dev/null
+++ b/tests/benchmarks/qanimation/dummyobject.h
@@ -0,0 +1,23 @@
+#include <QtGui>
+
+#ifndef _DUMMYOBJECT_H__
+
+class DummyObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QRect rect READ rect WRITE setRect)
+ Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
+public:
+ DummyObject();
+ QRect rect() const;
+ void setRect(const QRect &r);
+ float opacity() const;
+ void setOpacity(float);
+
+private:
+ QRect m_rect;
+ float m_opacity;
+};
+
+
+#endif \ No newline at end of file
diff --git a/tests/benchmarks/qanimation/main.cpp b/tests/benchmarks/qanimation/main.cpp
new file mode 100644
index 0000000..7bb770f
--- /dev/null
+++ b/tests/benchmarks/qanimation/main.cpp
@@ -0,0 +1,150 @@
+#include <QtGui>
+#include <qtest.h>
+
+#include "dummyobject.h"
+#include "dummyanimation.h"
+#include "rectanimation.h"
+
+#define ITERATION_COUNT 10e3
+
+class tst_qanimation : public QObject
+{
+ Q_OBJECT
+private slots:
+ void itemPropertyAnimation();
+ void itemPropertyAnimation_data() { data();}
+ void dummyAnimation();
+ void dummyAnimation_data() { data();}
+ void dummyPropertyAnimation();
+ void dummyPropertyAnimation_data() { data();}
+ void rectAnimation();
+ void rectAnimation_data() { data();}
+
+ void floatAnimation_data() { data(); }
+ void floatAnimation();
+
+private:
+ void data();
+};
+
+
+void tst_qanimation::data()
+{
+ QTest::addColumn<bool>("started");
+ QTest::newRow("NotRunning") << false;
+ QTest::newRow("Running") << true;
+}
+
+void tst_qanimation::itemPropertyAnimation()
+{
+ QFETCH(bool, started);
+ QGraphicsWidget item;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&item, "pos");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QPointF(0,0));
+ anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+
+}
+
+void tst_qanimation::dummyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //first the dummy animation
+ {
+ DummyAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < anim.duration(); ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::dummyPropertyAnimation()
+{
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "rect");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::rectAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ RectAnimation anim(&dummy);
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(QRect(0, 0, 0, 0));
+ anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT));
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+void tst_qanimation::floatAnimation()
+{
+ //this is the simplest animation you can do
+ QFETCH(bool, started);
+ DummyObject dummy;
+
+ //then the property animation
+ {
+ QPropertyAnimation anim(&dummy, "opacity");
+ anim.setDuration(ITERATION_COUNT);
+ anim.setStartValue(0.f);
+ anim.setEndValue(1.f);
+ if (started)
+ anim.start();
+ QBENCHMARK {
+ for(int i = 0; i < ITERATION_COUNT; ++i) {
+ anim.setCurrentTime(i);
+ }
+ }
+ }
+}
+
+
+
+QTEST_MAIN(tst_qanimation)
+
+#include "main.moc"
diff --git a/tests/benchmarks/qanimation/qanimation.pro b/tests/benchmarks/qanimation/qanimation.pro
new file mode 100644
index 0000000..55cd75e
--- /dev/null
+++ b/tests/benchmarks/qanimation/qanimation.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qanimation
+DEPENDPATH += .
+INCLUDEPATH += .
+
+CONFIG += release
+#CONFIG += debug
+
+
+SOURCES += main.cpp \
+ dummyobject.cpp \
+ dummyanimation.cpp \
+ rectanimation.cpp
+
+HEADERS += dummyobject.h \
+ dummyanimation.h \
+ rectanimation.h
diff --git a/tests/benchmarks/qanimation/rectanimation.cpp b/tests/benchmarks/qanimation/rectanimation.cpp
new file mode 100644
index 0000000..d60a943
--- /dev/null
+++ b/tests/benchmarks/qanimation/rectanimation.cpp
@@ -0,0 +1,58 @@
+#include "rectanimation.h"
+#include "dummyobject.h"
+
+static inline int interpolateInteger(int from, int to, qreal progress)
+{
+ return from + (to - from) * progress;
+}
+
+
+RectAnimation::RectAnimation(DummyObject *obj) : m_object(obj), m_dura(250)
+{
+}
+
+void RectAnimation::setEndValue(const QRect &rect)
+{
+ m_end = rect;
+}
+
+void RectAnimation::setStartValue(const QRect &rect)
+{
+ m_start = rect;
+}
+
+void RectAnimation::setDuration(int d)
+{
+ m_dura = d;
+}
+
+int RectAnimation::duration() const
+{
+ return m_dura;
+}
+
+
+void RectAnimation::updateCurrentTime(int msecs)
+{
+ qreal progress = m_easing.valueForProgress( qreal(msecs) / qreal(m_dura) );
+ QRect now;
+ now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress),
+ interpolateInteger(m_start.top(), m_end.top(), progress),
+ interpolateInteger(m_start.right(), m_end.right(), progress),
+ interpolateInteger(m_start.bottom(), m_end.bottom(), progress));
+
+ bool changed = (now != m_current);
+ if (changed)
+ m_current = now;
+
+ if (state() == Stopped)
+ return;
+
+ if (m_object)
+ m_object->setRect(m_current);
+}
+
+void RectAnimation::updateState(QAbstractAnimation::State state)
+{
+ Q_UNUSED(state);
+}
diff --git a/tests/benchmarks/qanimation/rectanimation.h b/tests/benchmarks/qanimation/rectanimation.h
new file mode 100644
index 0000000..99b82b4
--- /dev/null
+++ b/tests/benchmarks/qanimation/rectanimation.h
@@ -0,0 +1,30 @@
+#include <QtGui>
+
+#ifndef _RECTANIMATION_H__
+
+class DummyObject;
+
+//this class is even simpler than the dummy
+//and uses no QVariant at all
+class RectAnimation : public QAbstractAnimation
+{
+public:
+ RectAnimation(DummyObject *obj);
+
+ void setEndValue(const QRect &rect);
+ void setStartValue(const QRect &rect);
+
+ void setDuration(int d);
+ int duration() const;
+
+ virtual void updateCurrentTime(int msecs);
+ virtual void updateState(QAbstractAnimation::State state);
+
+private:
+ DummyObject *m_object;
+ QEasingCurve m_easing;
+ QRect m_start, m_end, m_current;
+ int m_dura;
+};
+
+#endif
diff --git a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro
new file mode 100644
index 0000000..c8fc07b
--- /dev/null
+++ b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qgraphicsitem
+
+SOURCES += tst_qgraphicsitem.cpp
+
diff --git a/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp
new file mode 100644
index 0000000..68e3aa1
--- /dev/null
+++ b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QGraphicsItem>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+
+//TESTED_FILES=
+
+class tst_QGraphicsItem : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGraphicsItem();
+ virtual ~tst_QGraphicsItem();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void setPos_data();
+ void setPos();
+ void setTransform_data();
+ void setTransform();
+ void rotate();
+ void scale();
+ void shear();
+ void translate();
+ void setRotation();
+ void setRotationXYZ();
+};
+
+tst_QGraphicsItem::tst_QGraphicsItem()
+{
+}
+
+tst_QGraphicsItem::~tst_QGraphicsItem()
+{
+}
+
+void tst_QGraphicsItem::init()
+{
+}
+
+void tst_QGraphicsItem::cleanup()
+{
+}
+
+void tst_QGraphicsItem::setPos_data()
+{
+ QTest::addColumn<QPointF>("pos");
+
+ QTest::newRow("0, 0") << QPointF(0, 0);
+ QTest::newRow("10, 10") << QPointF(10, 10);
+ QTest::newRow("-10, -10") << QPointF(-10, -10);
+}
+
+void tst_QGraphicsItem::setPos()
+{
+ QFETCH(QPointF, pos);
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ rect->setPos(10, 10);
+ rect->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setTransform_data()
+{
+ QTest::addColumn<QTransform>("transform");
+
+ QTest::newRow("id") << QTransform();
+ QTest::newRow("rotate 45z") << QTransform().rotate(45);
+ QTest::newRow("scale 2x2") << QTransform().scale(2, 2);
+ QTest::newRow("translate 100, 100") << QTransform().translate(100, 100);
+ QTest::newRow("rotate 45x 45y 45z") << QTransform().rotate(45, Qt::XAxis)
+ .rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis);
+}
+
+void tst_QGraphicsItem::setTransform()
+{
+ QFETCH(QTransform, transform);
+
+ QGraphicsScene scene;
+ QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setTransform(transform);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::rotate()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->rotate(45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::scale()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->scale(2, 2);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::shear()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->shear(1.5, 1.5);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::translate()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->translate(100, 100);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setRotation()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setXRotation(45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+void tst_QGraphicsItem::setRotationXYZ()
+{
+ QGraphicsScene scene;
+ QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100));
+
+ QBENCHMARK {
+ item->setRotation(45, 45, 45);
+ item->transform(); // prevent lazy optimizing
+ }
+}
+
+QTEST_MAIN(tst_QGraphicsItem)
+#include "tst_qgraphicsitem.moc"
diff --git a/tests/benchmarks/qgraphicsview/images/wine-big.jpeg b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg
new file mode 100644
index 0000000..9900a50
--- /dev/null
+++ b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg
Binary files differ
diff --git a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
index 5e80029..3681648 100644
--- a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
+++ b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc
@@ -2,6 +2,7 @@
<qresource>
<file>images/designer.png</file>
<file>images/wine.jpeg</file>
+ <file>images/wine-big.jpeg</file>
<file>random.data</file>
</qresource>
</RCC>
diff --git a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
index a293de4..570f744 100644
--- a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp
@@ -124,6 +124,8 @@ private slots:
void textRiver();
void moveItemCache_data();
void moveItemCache();
+ void paintItemCache_data();
+ void paintItemCache();
};
tst_QGraphicsView::tst_QGraphicsView()
@@ -705,7 +707,6 @@ public:
QGraphicsPixmapItem::paint(painter,option,widget);
//We just want to wait, and we don't want to process the event loop with qWait
QTest::qSleep(3);
-
}
protected:
void advance(int i)
@@ -797,5 +798,105 @@ void tst_QGraphicsView::moveItemCache()
}
}
+class UpdatedPixmapCacheItem : public QGraphicsPixmapItem
+{
+public:
+ UpdatedPixmapCacheItem(bool partial, QGraphicsItem *parent = 0)
+ : QGraphicsPixmapItem(parent), partial(partial)
+ {
+ }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ {
+ QGraphicsPixmapItem::paint(painter,option,widget);
+ }
+protected:
+ void advance(int i)
+ {
+ if (partial)
+ update(QRectF(boundingRect().center().x(), boundingRect().center().x(), 30, 30));
+ else
+ update();
+ }
+
+private:
+ bool partial;
+};
+
+void tst_QGraphicsView::paintItemCache_data()
+{
+ QTest::addColumn<bool>("updatePartial");
+ QTest::addColumn<bool>("rotation");
+ QTest::addColumn<int>("cacheMode");
+ QTest::newRow("Partial Update : ItemCoordinate Cache") << true << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Partial Update : DeviceCoordinate Cache") << true << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Partial Update : No Cache") << true << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Full Update : ItemCoordinate Cache") << false << false << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Full Update : DeviceCoordinate Cache") << false << false << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Full Update : No Cache") << false << false << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Partial Update : ItemCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Partial Update : DeviceCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Partial Update : No Cache item rotated") << true << true << (int)QGraphicsItem::NoCache;
+ QTest::newRow("Full Update : ItemCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::ItemCoordinateCache;
+ QTest::newRow("Full Update : DeviceCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::DeviceCoordinateCache;
+ QTest::newRow("Full Update : No Cache item rotated") << false << true <<(int)QGraphicsItem::NoCache;
+}
+
+void tst_QGraphicsView::paintItemCache()
+{
+ QFETCH(bool, updatePartial);
+ QFETCH(bool, rotation);
+ QFETCH(int, cacheMode);
+
+ QGraphicsScene scene(0, 0, 300, 300);
+
+ CountPaintEventView view(&scene);
+ view.resize(600, 600);
+ view.setFrameStyle(0);
+ view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ view.show();
+
+ QPixmap pix(":/images/wine.jpeg");
+ QVERIFY(!pix.isNull());
+
+ QList<QGraphicsItem *> items;
+ QFile file(":/random.data");
+ QVERIFY(file.open(QIODevice::ReadOnly));
+ QDataStream str(&file);
+ UpdatedPixmapCacheItem *item = new UpdatedPixmapCacheItem(updatePartial);
+ item->setPixmap(pix);
+ item->setCacheMode((QGraphicsItem::CacheMode)cacheMode);
+ if (rotation)
+ item->setTransform(QTransform().rotate(45));
+ item->setPos(-100, -100);
+ scene.addItem(item);
+
+ QPixmap pix2(":/images/wine-big.jpeg");
+ item = new UpdatedPixmapCacheItem(updatePartial);
+ item->setPixmap(pix2);
+ item->setCacheMode((QGraphicsItem::CacheMode)cacheMode);
+ if (rotation)
+ item->setTransform(QTransform().rotate(45));
+ item->setPos(0, 0);
+ scene.addItem(item);
+
+ view.count = 0;
+
+ QBENCHMARK {
+#ifdef CALLGRIND_DEBUG
+ CALLGRIND_START_INSTRUMENTATION
+#endif
+ for (int i = 0; i < 50; ++i) {
+ scene.advance();
+ while (view.count < (i+1))
+ qApp->processEvents();
+ }
+#ifdef CALLGRIND_DEBUG
+ CALLGRIND_STOP_INSTRUMENTATION
+#endif
+ }
+}
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"
diff --git a/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro
new file mode 100644
index 0000000..e82d9de
--- /dev/null
+++ b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qmatrix4x4
+
+SOURCES += tst_qmatrix4x4.cpp
+
diff --git a/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp
new file mode 100644
index 0000000..5046b17
--- /dev/null
+++ b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module 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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtGui/qmatrix4x4.h>
+
+class tst_QMatrix4x4 : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QMatrix4x4() {}
+ ~tst_QMatrix4x4() {}
+
+private slots:
+ void multiply_data();
+ void multiply();
+
+ void multiplyInPlace_data();
+ void multiplyInPlace();
+
+ void multiplyDirect_data();
+ void multiplyDirect();
+
+ void mapVector3D_data();
+ void mapVector3D();
+
+ void mapVector2D_data();
+ void mapVector2D();
+
+ void mapVectorDirect_data();
+ void mapVectorDirect();
+};
+
+static qreal const generalValues[16] =
+ {1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f};
+
+void tst_QMatrix4x4::multiply_data()
+{
+ QTest::addColumn<QMatrix4x4>("m1");
+ QTest::addColumn<QMatrix4x4>("m2");
+
+ QTest::newRow("identity * identity")
+ << QMatrix4x4() << QMatrix4x4();
+ QTest::newRow("identity * general")
+ << QMatrix4x4() << QMatrix4x4(generalValues);
+ QTest::newRow("general * identity")
+ << QMatrix4x4(generalValues) << QMatrix4x4();
+ QTest::newRow("general * general")
+ << QMatrix4x4(generalValues) << QMatrix4x4(generalValues);
+}
+
+QMatrix4x4 mresult;
+
+void tst_QMatrix4x4::multiply()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ QBENCHMARK {
+ m3 = m1 * m2;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ mresult = m3;
+}
+
+void tst_QMatrix4x4::multiplyInPlace_data()
+{
+ multiply_data();
+}
+
+void tst_QMatrix4x4::multiplyInPlace()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ QBENCHMARK {
+ m3 = m1;
+ m3 *= m2;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ mresult = m3;
+}
+
+// Use a direct naive multiplication algorithm. This is used
+// to compare against the optimized routines to see if they are
+// actually faster than the naive implementation.
+void tst_QMatrix4x4::multiplyDirect_data()
+{
+ multiply_data();
+}
+void tst_QMatrix4x4::multiplyDirect()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ const float *m1data = m1.constData();
+ const float *m2data = m2.constData();
+ float *m3data = m3.data();
+
+ QBENCHMARK {
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ m3data[col * 4 + row] = 0.0f;
+ for (int j = 0; j < 4; ++j) {
+ m3data[col * 4 + row] +=
+ m1data[j * 4 + row] * m2data[col * 4 + j];
+ }
+ }
+ }
+ }
+}
+
+QVector3D vresult;
+
+void tst_QMatrix4x4::mapVector3D_data()
+{
+ QTest::addColumn<QMatrix4x4>("m1");
+
+ QTest::newRow("identity") << QMatrix4x4();
+ QTest::newRow("general") << QMatrix4x4(generalValues);
+
+ QMatrix4x4 t1;
+ t1.translate(-100.5f, 64.0f, 75.25f);
+ QTest::newRow("translate3D") << t1;
+
+ QMatrix4x4 t2;
+ t2.translate(-100.5f, 64.0f);
+ QTest::newRow("translate2D") << t2;
+
+ QMatrix4x4 s1;
+ s1.scale(-100.5f, 64.0f, 75.25f);
+ QTest::newRow("scale3D") << s1;
+
+ QMatrix4x4 s2;
+ s2.scale(-100.5f, 64.0f);
+ QTest::newRow("scale2D") << s2;
+}
+void tst_QMatrix4x4::mapVector3D()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ QVector3D v(10.5f, -2.0f, 3.0f);
+ QVector3D result;
+
+ m1.inferSpecialType();
+
+ QBENCHMARK {
+ result = m1 * v;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ vresult = result;
+}
+
+QPointF vresult2;
+
+void tst_QMatrix4x4::mapVector2D_data()
+{
+ mapVector3D_data();
+}
+void tst_QMatrix4x4::mapVector2D()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ QPointF v(10.5f, -2.0f);
+ QPointF result;
+
+ m1.inferSpecialType();
+
+ QBENCHMARK {
+ result = m1 * v;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ vresult2 = result;
+}
+
+// Use a direct naive multiplication algorithm. This is used
+// to compare against the optimized routines to see if they are
+// actually faster than the naive implementation.
+void tst_QMatrix4x4::mapVectorDirect_data()
+{
+ mapVector3D_data();
+}
+void tst_QMatrix4x4::mapVectorDirect()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ const float *m1data = m1.constData();
+ float v[4] = {10.5f, -2.0f, 3.0f, 1.0f};
+ float result[4];
+
+ QBENCHMARK {
+ for (int row = 0; row < 4; ++row) {
+ result[row] = 0.0f;
+ for (int col = 0; col < 4; ++col) {
+ result[row] += m1data[col * 4 + row] * v[col];
+ }
+ }
+ result[0] /= result[3];
+ result[1] /= result[3];
+ result[2] /= result[3];
+ }
+}
+
+QTEST_MAIN(tst_QMatrix4x4)
+
+#include "tst_qmatrix4x4.moc"
diff --git a/tests/benchmarks/qpixmapcache/qpixmapcache.pro b/tests/benchmarks/qpixmapcache/qpixmapcache.pro
new file mode 100644
index 0000000..e0d7543
--- /dev/null
+++ b/tests/benchmarks/qpixmapcache/qpixmapcache.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qpixmapcache
+TEMPLATE = app
+# Input
+SOURCES += tst_qpixmapcache.cpp
diff --git a/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp
new file mode 100644
index 0000000..f3c1134
--- /dev/null
+++ b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QPixmapCache>
+//TESTED_FILES=
+
+class tst_QPixmapCache : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QPixmapCache();
+ virtual ~tst_QPixmapCache();
+
+public slots:
+ void init();
+ void cleanup();
+
+private slots:
+ void insert_data();
+ void insert();
+ void find_data();
+ void find();
+ void styleUseCaseComplexKey();
+ void styleUseCaseComplexKey_data();
+};
+
+tst_QPixmapCache::tst_QPixmapCache()
+{
+}
+
+tst_QPixmapCache::~tst_QPixmapCache()
+{
+}
+
+void tst_QPixmapCache::init()
+{
+}
+
+void tst_QPixmapCache::cleanup()
+{
+}
+
+void tst_QPixmapCache::insert_data()
+{
+ QTest::addColumn<bool>("cacheType");
+ QTest::newRow("QPixmapCache") << true;
+ QTest::newRow("QPixmapCache (int API)") << false;
+}
+
+QList<QPixmapCache::Key> keys;
+
+void tst_QPixmapCache::insert()
+{
+ QFETCH(bool, cacheType);
+ QPixmap p;
+ if (cacheType) {
+ QBENCHMARK {
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ QString tmp;
+ tmp.sprintf("my-key-%d", i);
+ QPixmapCache::insert(tmp, p);
+ }
+ }
+ } else {
+ QBENCHMARK {
+ for (int i = 0 ; i <= 10000 ; i++)
+ keys.append(QPixmapCache::insert(p));
+ }
+ }
+}
+
+void tst_QPixmapCache::find_data()
+{
+ QTest::addColumn<bool>("cacheType");
+ QTest::newRow("QPixmapCache") << true;
+ QTest::newRow("QPixmapCache (int API)") << false;
+}
+
+void tst_QPixmapCache::find()
+{
+ QFETCH(bool, cacheType);
+ QPixmap p;
+ if (cacheType) {
+ QBENCHMARK {
+ QString tmp;
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ tmp.sprintf("my-key-%d", i);
+ QPixmapCache::find(tmp, p);
+ }
+ }
+ } else {
+ QBENCHMARK {
+ for (int i = 0 ; i <= 10000 ; i++)
+ QPixmapCache::find(keys.at(i), &p);
+ }
+ }
+
+}
+
+void tst_QPixmapCache::styleUseCaseComplexKey_data()
+{
+ QTest::addColumn<bool>("cacheType");
+ QTest::newRow("QPixmapCache") << true;
+ QTest::newRow("QPixmapCache (int API)") << false;
+}
+
+struct styleStruct {
+ QString key;
+ uint state;
+ uint direction;
+ uint complex;
+ uint palette;
+ int width;
+ int height;
+ bool operator==(const styleStruct &str) const
+ {
+ return str.key == key && str.state == state && str.direction == direction
+ && str.complex == complex && str.palette == palette && str.width == width
+ && str.height == height;
+ }
+};
+
+uint qHash(const styleStruct &myStruct)
+{
+ return qHash(myStruct.state);
+}
+
+void tst_QPixmapCache::styleUseCaseComplexKey()
+{
+ QFETCH(bool, cacheType);
+ QPixmap p;
+ if (cacheType) {
+ QBENCHMARK {
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ QString tmp;
+ tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200);
+ QPixmapCache::insert(tmp, p);
+ }
+
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ QString tmp;
+ tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200);
+ QPixmapCache::find(tmp, p);
+ }
+ }
+ } else {
+ QHash<styleStruct, QPixmapCache::Key> hash;
+ QBENCHMARK {
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ styleStruct myStruct;
+ myStruct.key = QString("my-progressbar-%1").arg(i);
+ myStruct.key = 5;
+ myStruct.key = 4;
+ myStruct.key = 3;
+ myStruct.palette = 358;
+ myStruct.width = 100;
+ myStruct.key = 200;
+ QPixmapCache::Key key = QPixmapCache::insert(p);
+ hash.insert(myStruct, key);
+ }
+ for (int i = 0 ; i <= 10000 ; i++)
+ {
+ styleStruct myStruct;
+ myStruct.key = QString("my-progressbar-%1").arg(i);
+ myStruct.key = 5;
+ myStruct.key = 4;
+ myStruct.key = 3;
+ myStruct.palette = 358;
+ myStruct.width = 100;
+ myStruct.key = 200;
+ QPixmapCache::Key key = hash.value(myStruct);
+ QPixmapCache::find(key, &p);
+ }
+ }
+ }
+
+}
+
+
+QTEST_MAIN(tst_QPixmapCache)
+#include "tst_qpixmapcache.moc"
diff --git a/tests/benchmarks/qstring/main.cpp b/tests/benchmarks/qstring/main.cpp
new file mode 100644
index 0000000..cbbf0a1
--- /dev/null
+++ b/tests/benchmarks/qstring/main.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QStringList>
+#include <qtest.h>
+
+class tst_QString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void equals() const;
+ void equals_data() const;
+};
+
+void tst_QString::equals() const
+{
+ QFETCH(QString, a);
+ QFETCH(QString, b);
+
+ QBENCHMARK {
+ a == b;
+ }
+}
+
+void tst_QString::equals_data() const
+{
+ static const struct {
+ ushort data[80];
+ int dummy; // just to ensure 4-byte alignment
+ } data = {
+ {
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 16
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 32
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 48
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 64
+ 64, 64, 64, 64, 96, 96, 96, 96,
+ 64, 64, 96, 96, 96, 96, 96, 96 // 80
+ }, 0
+ };
+ const QChar *ptr = reinterpret_cast<const QChar *>(data.data);
+
+ QTest::addColumn<QString>("a");
+ QTest::addColumn<QString>("b");
+ QString base = QString::fromRawData(ptr, 64);
+
+ QTest::newRow("different-length") << base << QString::fromRawData(ptr, 4);
+ QTest::newRow("same-string") << base << base;
+ QTest::newRow("same-data") << base << QString::fromRawData(ptr, 64);
+
+ // try to avoid crossing a cache line (that is, at ptr[64])
+ QTest::newRow("aligned-aligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 2, 60);
+ QTest::newRow("aligned-unaligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 1, 60);
+ QTest::newRow("unaligned-unaligned-4n")
+ << QString::fromRawData(ptr + 1, 60) << QString::fromRawData(ptr + 3, 60);
+
+ QTest::newRow("aligned-aligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 2, 61);
+ QTest::newRow("aligned-unaligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 1, 61);
+ QTest::newRow("unaligned-unaligned-4n+1")
+ << QString::fromRawData(ptr + 1, 61) << QString::fromRawData(ptr + 3, 61);
+
+ QTest::newRow("aligned-aligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 2, 59);
+ QTest::newRow("aligned-unaligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 1, 59);
+ QTest::newRow("unaligned-unaligned-4n-1")
+ << QString::fromRawData(ptr + 1, 59) << QString::fromRawData(ptr + 3, 59);
+
+ QTest::newRow("aligned-aligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 2, 58);
+ QTest::newRow("aligned-unaligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 1, 58);
+ QTest::newRow("unaligned-unaligned-2n")
+ << QString::fromRawData(ptr + 1, 58) << QString::fromRawData(ptr + 3, 58);
+}
+
+QTEST_MAIN(tst_QString)
+
+#include "main.moc"
diff --git a/tests/benchmarks/qstring/qstring.pro b/tests/benchmarks/qstring/qstring.pro
new file mode 100644
index 0000000..74423e7
--- /dev/null
+++ b/tests/benchmarks/qstring/qstring.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+TARGET = tst_qstring
+QT -= gui
+SOURCES += main.cpp
diff --git a/tests/benchmarks/qstringbuilder/main.cpp b/tests/benchmarks/qstringbuilder/main.cpp
new file mode 100644
index 0000000..d4e2fa0
--- /dev/null
+++ b/tests/benchmarks/qstringbuilder/main.cpp
@@ -0,0 +1,374 @@
+
+// Select one of the scenarios below
+#define SCENARIO 3
+
+#if SCENARIO == 1
+// this is the "no harm done" version. Only operator% is active,
+// with NO_CAST * defined
+#define P %
+#undef QT_USE_FAST_OPERATOR_PLUS
+#undef QT_USE_FAST_CONCATENATION
+#define QT_NO_CAST_FROM_ASCII
+#define QT_NO_CAST_TO_ASCII
+#endif
+
+
+#if SCENARIO == 2
+// this is the "full" version. Operator+ is replaced by a QStringBuilder
+// based version
+// with NO_CAST * defined
+#define P %
+#define QT_USE_FAST_OPERATOR_PLUS
+#define QT_USE_FAST_CONCATENATION
+#define QT_NO_CAST_FROM_ASCII
+#define QT_NO_CAST_TO_ASCII
+#endif
+
+#if SCENARIO == 3
+// this is the "no harm done" version. Only operator% is active,
+// with NO_CAST * _not_ defined
+#define P %
+#undef QT_USE_FAST_OPERATOR_PLUS
+#undef QT_USE_FAST_CONCATENATION
+#undef QT_NO_CAST_FROM_ASCII
+#undef QT_NO_CAST_TO_ASCII
+#endif
+
+#if SCENARIO == 4
+// this is the "full" version. Operator+ is replaced by a QStringBuilder
+// based version
+// with NO_CAST * _not_ defined
+#define P %
+#define QT_USE_FAST_OPERATOR_PLUS
+#define QT_USE_FAST_CONCATENATION
+#undef QT_NO_CAST_FROM_ASCII
+#undef QT_NO_CAST_TO_ASCII
+#endif
+
+
+#include <qbytearray.h>
+#include <qdebug.h>
+#include <qstring.h>
+#include <qstringbuilder.h>
+
+#include <qtest.h>
+
+#define COMPARE(a, b) QCOMPARE(a, b)
+//#define COMPARE(a, b)
+
+#define SEP(s) qDebug() << "\n\n-------- " s " ---------";
+
+#define LITERAL "some string literal"
+
+class tst_qstringbuilder : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_qstringbuilder()
+ : l1literal(LITERAL),
+ l1string(LITERAL),
+ ba(LITERAL),
+ string(l1string),
+ stringref(&string, 2, 10),
+ achar('c'),
+ r2(QLatin1String(LITERAL LITERAL)),
+ r3(QLatin1String(LITERAL LITERAL LITERAL)),
+ r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)),
+ r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL))
+ {}
+
+
+public:
+ enum { N = 10000 };
+
+ int run_traditional()
+ {
+ int s = 0;
+ for (int i = 0; i < N; ++i) {
+#if 0
+ s += QString(l1string + l1string).size();
+ s += QString(l1string + l1string + l1string).size();
+ s += QString(l1string + l1string + l1string + l1string).size();
+ s += QString(l1string + l1string + l1string + l1string + l1string).size();
+#endif
+ s += QString(achar + l1string + achar).size();
+ }
+ return s;
+ }
+
+ int run_builder()
+ {
+ int s = 0;
+ for (int i = 0; i < N; ++i) {
+#if 0
+ s += QString(l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size();
+#endif
+ s += QString(achar % l1literal % achar).size();
+ }
+ return s;
+ }
+
+private slots:
+
+ void separator_0() {
+ qDebug() << "\nIn each block the QStringBuilder based result appear first, "
+ "QStringBased second.\n";
+ }
+
+ void separator_1() { SEP("literal + literal (builder first)"); }
+
+ void b_2_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal; }
+ COMPARE(r, r2);
+ }
+ #ifndef QT_NO_CAST_FROM_ASCII
+ void b_l1literal_LITERAL() {
+ QBENCHMARK { r = l1literal P LITERAL; }
+ COMPARE(r, r2);
+ }
+ #endif
+ void s_2_l1string() {
+ QBENCHMARK { r = l1string + l1string; }
+ COMPARE(r, r2);
+ }
+
+
+ void separator_2() { SEP("2 strings"); }
+
+ void b_2_string() {
+ QBENCHMARK { r = string P string; }
+ COMPARE(r, r2);
+ }
+ void s_2_string() {
+ QBENCHMARK { r = string + string; }
+ COMPARE(r, r2);
+ }
+
+
+ void separator_2c() { SEP("2 string refs"); }
+
+ void b_2_stringref() {
+ QBENCHMARK { r = stringref % stringref; }
+ COMPARE(r, QString(stringref.toString() + stringref.toString()));
+ }
+ void s_2_stringref() {
+ QBENCHMARK { r = stringref.toString() + stringref.toString(); }
+ COMPARE(r, QString(stringref % stringref));
+ }
+
+
+ void separator_2b() { SEP("3 strings"); }
+
+ void b_3_string() {
+ QBENCHMARK { r = string P string P string; }
+ COMPARE(r, r3);
+ }
+ void s_3_string() {
+ QBENCHMARK { r = string + string + string; }
+ COMPARE(r, r3);
+ }
+
+
+ void separator_2a() { SEP("string + literal (builder first)"); }
+
+ void b_string_l1literal() {
+ QBENCHMARK { r = string % l1literal; }
+ COMPARE(r, r2);
+ }
+ #ifndef QT_NO_CAST_FROM_ASCII
+ void b_string_LITERAL() {
+ QBENCHMARK { r = string P LITERAL; }
+ COMPARE(r, r2);
+ }
+ void b_LITERAL_string() {
+ QBENCHMARK { r = LITERAL P string; }
+ COMPARE(r, r2);
+ }
+ #endif
+ void b_string_l1string() {
+ QBENCHMARK { r = string P l1string; }
+ COMPARE(r, r2);
+ }
+ void s_string_l1literal() {
+ QBENCHMARK { r = string + l1string; }
+ COMPARE(r, r2);
+ }
+ void s_string_l1string() {
+ QBENCHMARK { r = string + l1string; }
+ COMPARE(r, r2);
+ }
+
+
+ void separator_3() { SEP("3 literals"); }
+
+ void b_3_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal; }
+ COMPARE(r, r3);
+ }
+ void s_3_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string; }
+ COMPARE(r, r3);
+ }
+
+
+ void separator_4() { SEP("4 literals"); }
+
+ void b_4_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r4);
+ }
+ void s_4_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string + l1string; }
+ COMPARE(r, r4);
+ }
+
+
+ void separator_5() { SEP("5 literals"); }
+
+ void b_5_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r5);
+ }
+
+ void s_5_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; }
+ COMPARE(r, r5);
+ }
+
+
+ void separator_6() { SEP("4 chars"); }
+
+ void b_string_4_char() {
+ QBENCHMARK { r = string + achar + achar + achar + achar; }
+ COMPARE(r, QString(string P achar P achar P achar P achar));
+ }
+
+ void s_string_4_char() {
+ QBENCHMARK { r = string + achar + achar + achar + achar; }
+ COMPARE(r, QString(string P achar P achar P achar P achar));
+ }
+
+
+ void separator_7() { SEP("char + string + char"); }
+
+ void b_char_string_char() {
+ QBENCHMARK { r = achar + string + achar; }
+ COMPARE(r, QString(achar P string P achar));
+ }
+
+ void s_char_string_char() {
+ QBENCHMARK { r = achar + string + achar; }
+ COMPARE(r, QString(achar P string P achar));
+ }
+
+ void separator_8() { SEP("string.arg"); }
+
+ void b_string_arg() {
+ const QString pattern = l1string + QString::fromLatin1("%1") + l1string;
+ QBENCHMARK { r = l1literal P string P l1literal; }
+ COMPARE(r, r3);
+ }
+
+ void s_string_arg() {
+ const QString pattern = l1string + QLatin1String("%1") + l1string;
+ QBENCHMARK { r = pattern.arg(string); }
+ COMPARE(r, r3);
+ }
+
+ void s_bytearray_arg() {
+ QByteArray result;
+ QBENCHMARK { result = ba + ba + ba; }
+ }
+
+
+ void separator_9() { SEP("QString::reserve()"); }
+
+ void b_reserve() {
+ QBENCHMARK {
+ r.clear();
+ r = string P string P string P string;
+ }
+ COMPARE(r, r4);
+ }
+ void b_reserve_lit() {
+ QBENCHMARK {
+ r.clear();
+ r = string P l1literal P string P string;
+ }
+ COMPARE(r, r4);
+ }
+ void s_reserve() {
+ QBENCHMARK {
+ r.clear();
+ r.reserve(string.size() + string.size() + string.size() + string.size());
+ r += string;
+ r += string;
+ r += string;
+ r += string;
+ }
+ COMPARE(r, r4);
+ }
+ void s_reserve_lit() {
+ QBENCHMARK {
+ r.clear();
+ //r.reserve(string.size() + qstrlen(l1string.latin1())
+ // + string.size() + string.size());
+ r.reserve(1024);
+ r += string;
+ r += l1string;
+ r += string;
+ r += string;
+ }
+ COMPARE(r, r4);
+ }
+
+private:
+ const QLatin1Literal l1literal;
+ const QLatin1String l1string;
+ const QByteArray ba;
+ const QString string;
+ const QStringRef stringref;
+ const QLatin1Char achar;
+ const QString r2, r3, r4, r5;
+
+ QString r;
+};
+
+
+//void operator%(QString, int) {}
+
+int main(int argc, char *argv[])
+{
+ //qDebug() << (QString("xx") * QLatin1String("y")).toString();
+ //42 % 3; // Sanity test, should always work.
+ //QString("x") % 2; // Sanity test, should only compile when the
+ // operator%(QString, int) is visible.
+
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-builder")
+ || QLatin1String(argv[1]) == QLatin1String("-b"))) {
+ tst_qstringbuilder test;
+ return test.run_builder();
+ }
+
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-traditional")
+ || QLatin1String(argv[1]) == QLatin1String("-t"))) {
+ tst_qstringbuilder test;
+ return test.run_traditional();
+ }
+
+ if (argc == 1) {
+ QCoreApplication app(argc, argv);
+ QStringList args = app.arguments();
+ tst_qstringbuilder test;
+ return QTest::qExec(&test, argc, argv);
+ }
+
+ qDebug() << "Usage: " << argv[0] << " [--run-builder|-r|--run-traditional|-t]";
+}
+
+
+#include "main.moc"
diff --git a/tests/benchmarks/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
new file mode 100644
index 0000000..79171b4
--- /dev/null
+++ b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qstringbuilder
+
+QMAKE_CXXFLAGS += -g
+QMAKE_CFLAGS += -g
+
+QT -= gui
+
+CONFIG += release
+
+SOURCES += main.cpp
diff --git a/tests/benchmarks/qvariant/qvariant.pro b/tests/benchmarks/qvariant/qvariant.pro
index 68b4a97..63b5442 100644
--- a/tests/benchmarks/qvariant/qvariant.pro
+++ b/tests/benchmarks/qvariant/qvariant.pro
@@ -3,7 +3,6 @@ TEMPLATE = app
TARGET = tst_qvariant
DEPENDPATH += .
INCLUDEPATH += .
-QT -= gui
CONFIG += release
#CONFIG += debug
diff --git a/tests/benchmarks/qvariant/tst_qvariant.cpp b/tests/benchmarks/qvariant/tst_qvariant.cpp
index 4a7ad02..0eb1ae2 100644
--- a/tests/benchmarks/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/qvariant/tst_qvariant.cpp
@@ -38,7 +38,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include <QtCore>
+#include <QtGui/QPixmap>
#include <qtest.h>
#define ITERATION_COUNT 1e5
@@ -47,64 +49,73 @@ class tst_qvariant : public QObject
{
Q_OBJECT
private slots:
+ void testBound();
+
void doubleVariantCreation();
void floatVariantCreation();
void rectVariantCreation();
void stringVariantCreation();
+ void pixmapVariantCreation();
+
void doubleVariantSetValue();
void floatVariantSetValue();
void rectVariantSetValue();
void stringVariantSetValue();
+
void doubleVariantAssignment();
void floatVariantAssignment();
void rectVariantAssignment();
void stringVariantAssignment();
};
-
-void tst_qvariant::doubleVariantCreation()
+void tst_qvariant::testBound()
{
- double d = 0;
+ qreal d = qreal(.5);
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(d);
+ d = qBound<qreal>(0, d, 1);
}
}
}
-void tst_qvariant::floatVariantCreation()
+template <typename T>
+static void variantCreation(T val)
{
- float f = 0;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(f);
+ QVariant v(val);
}
}
}
+void tst_qvariant::doubleVariantCreation()
+{
+ variantCreation<double>(0.0);
+}
+
+void tst_qvariant::floatVariantCreation()
+{
+ variantCreation<float>(0.0f);
+}
+
void tst_qvariant::rectVariantCreation()
{
- QRect r(1,2,3,4);
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(r);
- }
- }
+ variantCreation<QRect>(QRect(1, 2, 3, 4));
}
void tst_qvariant::stringVariantCreation()
{
- QString s;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(s);
- }
- }
+ variantCreation<QString>(QString());
}
-void tst_qvariant::doubleVariantSetValue()
+void tst_qvariant::pixmapVariantCreation()
+{
+ variantCreation<QPixmap>(QPixmap());
+}
+
+template <typename T>
+static void variantSetValue(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -113,42 +124,29 @@ void tst_qvariant::doubleVariantSetValue()
}
}
+void tst_qvariant::doubleVariantSetValue()
+{
+ variantSetValue<double>(0.0);
+}
+
void tst_qvariant::floatVariantSetValue()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, f);
- }
- }
+ variantSetValue<float>(0.0f);
}
void tst_qvariant::rectVariantSetValue()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, r);
- }
- }
+ variantSetValue<QRect>(QRect());
}
void tst_qvariant::stringVariantSetValue()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, s);
- }
- }
+ variantSetValue<QString>(QString());
}
-void tst_qvariant::doubleVariantAssignment()
+template <typename T>
+static void variantAssignment(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -157,37 +155,24 @@ void tst_qvariant::doubleVariantAssignment()
}
}
+void tst_qvariant::doubleVariantAssignment()
+{
+ variantAssignment<double>(0.0);
+}
+
void tst_qvariant::floatVariantAssignment()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = f;
- }
- }
+ variantAssignment<float>(0.0f);
}
void tst_qvariant::rectVariantAssignment()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = r;
- }
- }
+ variantAssignment<QRect>(QRect());
}
void tst_qvariant::stringVariantAssignment()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = s;
- }
- }
+ variantAssignment<QString>(QString());
}
QTEST_MAIN(tst_qvariant)