| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include <QtTest/QtTest> |
| 30 | #include <QtCore/QCoreApplication> |
| 31 | #ifndef QT_NO_WIDGETS |
| 32 | #include <QtWidgets/QPushButton> |
| 33 | #include <QtWidgets/QGraphicsScene> |
| 34 | #include <QtWidgets/QGraphicsSceneEvent> |
| 35 | #include <QtWidgets/QGraphicsTextItem> |
| 36 | #endif |
| 37 | |
| 38 | #include "qstatemachine.h" |
| 39 | #include "qstate.h" |
| 40 | #include "qhistorystate.h" |
| 41 | #ifndef QT_NO_WIDGETS |
| 42 | #include "qkeyeventtransition.h" |
| 43 | #include "qmouseeventtransition.h" |
| 44 | #endif |
| 45 | #include "private/qstate_p.h" |
| 46 | #include "private/qstatemachine_p.h" |
| 47 | |
| 48 | static int globalTick; |
| 49 | |
| 50 | // Run exec for a maximum of TIMEOUT msecs |
| 51 | #define QCOREAPPLICATION_EXEC(TIMEOUT) \ |
| 52 | { \ |
| 53 | QTimer timer; \ |
| 54 | timer.setSingleShot(true); \ |
| 55 | timer.setInterval(TIMEOUT); \ |
| 56 | timer.start(); \ |
| 57 | connect(&timer, SIGNAL(timeout()), QCoreApplication::instance(), SLOT(quit())); \ |
| 58 | QCoreApplication::exec(); \ |
| 59 | } |
| 60 | |
| 61 | #define TEST_RUNNING_CHANGED(RUNNING) \ |
| 62 | { \ |
| 63 | QTRY_COMPARE(runningSpy.count(), 1); \ |
| 64 | QList<QVariant> runningArgs = runningSpy.takeFirst(); \ |
| 65 | QVERIFY(runningArgs.at(0).type() == QVariant::Bool); \ |
| 66 | QVERIFY(runningArgs.at(0).toBool() == RUNNING); \ |
| 67 | QCOMPARE(machine.isRunning(), runningArgs.at(0).toBool()); \ |
| 68 | } |
| 69 | |
| 70 | #define TEST_RUNNING_CHANGED_STARTED_STOPPED \ |
| 71 | { \ |
| 72 | QTRY_COMPARE(runningSpy.count(), 2); \ |
| 73 | QList<QVariant> runningArgs = runningSpy.takeFirst(); \ |
| 74 | QVERIFY(runningArgs.at(0).type() == QVariant::Bool); \ |
| 75 | QVERIFY(runningArgs.at(0).toBool() == true); \ |
| 76 | runningArgs = runningSpy.takeFirst(); \ |
| 77 | QVERIFY(runningArgs.at(0).type() == QVariant::Bool); \ |
| 78 | QVERIFY(runningArgs.at(0).toBool() == false); \ |
| 79 | QCOMPARE(machine.isRunning(), runningArgs.at(0).toBool()); \ |
| 80 | } |
| 81 | |
| 82 | #define DEFINE_ACTIVE_SPY(VAR) \ |
| 83 | QSignalSpy VAR##_activeSpy(VAR, &QState::activeChanged); \ |
| 84 | QVERIFY(VAR##_activeSpy.isValid()); |
| 85 | |
| 86 | #define TEST_ACTIVE_CHANGED(VAR, COUNT) \ |
| 87 | { \ |
| 88 | QTRY_COMPARE(VAR##_activeSpy.count(), COUNT); \ |
| 89 | bool |
|---|