diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-09-28 14:26:37 +0200 |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-09-28 14:28:57 +0200 |
commit | 09d61361ff84b4f47f8a6fcda258957c93d552f9 (patch) | |
tree | 6537ffd17b9ccca99877443e3627c848493f607c /tests/auto | |
parent | e473c6b6c61ce1f10ddd26dfc0aba6b072b6256d (diff) | |
download | qt4-tools-09d61361ff84b4f47f8a6fcda258957c93d552f9.tar.gz |
add a test for custom QEventTransition
Test that the event has the right attributes.
Also improve the custom QSignalTransition test to cover all attributes.
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 1fae92b6e7..7244d72231 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1742,11 +1742,18 @@ class TestSignalTransition : public QSignalTransition { public: TestSignalTransition(QState *sourceState = 0) - : QSignalTransition(sourceState) {} + : QSignalTransition(sourceState), m_sender(0) + {} TestSignalTransition(QObject *sender, const char *signal, QAbstractState *target) - : QSignalTransition(sender, signal) + : QSignalTransition(sender, signal), m_sender(0) { setTargetState(target); } + QObject *senderReceived() const { + return m_sender; + } + int signalIndexReceived() const { + return m_signalIndex; + } QVariantList argumentsReceived() const { return m_args; } @@ -1755,10 +1762,14 @@ protected: if (!QSignalTransition::eventTest(e)) return false; QStateMachine::SignalEvent *se = static_cast<QStateMachine::SignalEvent*>(e); - const_cast<TestSignalTransition*>(this)->m_args = se->arguments(); + m_sender = se->sender(); + m_signalIndex = se->signalIndex(); + m_args = se->arguments(); return true; } private: + QObject *m_sender; + int m_signalIndex; QVariantList m_args; }; @@ -1870,6 +1881,8 @@ void tst_QStateMachine::signalTransitions() emitter.emitSignalWithIntArg(123); QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(trans->senderReceived(), (QObject*)&emitter); + QCOMPARE(trans->signalIndexReceived(), emitter.metaObject()->indexOfSignal("signalWithIntArg(int)")); QCOMPARE(trans->argumentsReceived().size(), 1); QCOMPARE(trans->argumentsReceived().at(0).toInt(), 123); } @@ -1890,6 +1903,8 @@ void tst_QStateMachine::signalTransitions() emitter.emitSignalWithStringArg(testString); QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(trans->senderReceived(), (QObject*)&emitter); + QCOMPARE(trans->signalIndexReceived(), emitter.metaObject()->indexOfSignal("signalWithStringArg(QString)")); QCOMPARE(trans->argumentsReceived().size(), 1); QCOMPARE(trans->argumentsReceived().at(0).toString(), testString); } @@ -2028,6 +2043,38 @@ void tst_QStateMachine::signalTransitions() } } +class TestEventTransition : public QEventTransition +{ +public: + TestEventTransition(QState *sourceState = 0) + : QEventTransition(sourceState), + m_eventSource(0), m_eventType(QEvent::None) + {} + TestEventTransition(QObject *object, QEvent::Type type, + QAbstractState *target) + : QEventTransition(object, type), + m_eventSource(0), m_eventType(QEvent::None) + { setTargetState(target); } + QObject *eventSourceReceived() const { + return m_eventSource; + } + QEvent::Type eventTypeReceived() const { + return m_eventType; + } +protected: + bool eventTest(QEvent *e) { + if (!QEventTransition::eventTest(e)) + return false; + QStateMachine::WrappedEvent *we = static_cast<QStateMachine::WrappedEvent*>(e); + m_eventSource = we->object(); + m_eventType = we->event()->type(); + return true; + } +private: + QObject *m_eventSource; + QEvent::Type m_eventType; +}; + void tst_QStateMachine::eventTransitions() { QPushButton button; @@ -2274,6 +2321,30 @@ void tst_QStateMachine::eventTransitions() QTest::ignoreMessage(QtWarningMsg, "QObject event transitions are not supported for custom types"); QTRY_COMPARE(startedSpy.count(), 1); } + // custom transition + { + QStateMachine machine; + QState *s0 = new QState(&machine); + QFinalState *s1 = new QFinalState(&machine); + + TestEventTransition *trans = new TestEventTransition(&button, QEvent::MouseButtonPress, s1); + s0->addTransition(trans); + QCOMPARE(trans->eventSourceReceived(), (QObject*)0); + QCOMPARE(trans->eventTypeReceived(), QEvent::None); + + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.setInitialState(s0); + machine.start(); + QCoreApplication::processEvents(); + + QTest::mousePress(&button, Qt::LeftButton); + QCoreApplication::processEvents(); + + QTRY_COMPARE(finishedSpy.count(), 1); + + QCOMPARE(trans->eventSourceReceived(), (QObject*)&button); + QCOMPARE(trans->eventTypeReceived(), QEvent::MouseButtonPress); + } } void tst_QStateMachine::historyStates() |