diff options
Diffstat (limited to 'tests/auto/qstate')
-rw-r--r-- | tests/auto/qstate/tst_qstate.cpp | 111 |
1 files changed, 48 insertions, 63 deletions
diff --git a/tests/auto/qstate/tst_qstate.cpp b/tests/auto/qstate/tst_qstate.cpp index c4a0050..f28c3fa 100644 --- a/tests/auto/qstate/tst_qstate.cpp +++ b/tests/auto/qstate/tst_qstate.cpp @@ -42,15 +42,16 @@ private slots: #if 0 void test(); #endif - void setPropertyOnEntry(); - void setPropertyOnEntryTwice(); - void setPropertyOnExit(); - void setPropertyOnExitTwice(); + void assignProperty(); + void assignPropertyTwice(); void historyInitialState(); void addEntryAction(); + +private: + bool functionCalled; }; -tst_QState::tst_QState() +tst_QState::tst_QState() : functionCalled(false) { } @@ -200,20 +201,36 @@ void tst_QState::test() } #endif +class TestClass: public QObject +{ + Q_OBJECT +public: + TestClass() : called(false) {} + bool called; + +public slots: + void slot() { called = true; } + + +}; + void tst_QState::addEntryAction() { QStateMachine sm; + + TestClass testObject; + QState *s0 = new QState(sm.rootState()); - s0->addEntryAction(new QStateSetPropertyAction(this, "objectName", "commandTest")); + s0->addEntryAction(new QStateInvokeMethodAction(&testObject, "slot")); sm.setInitialState(s0); sm.start(); QCoreApplication::processEvents(); - QCOMPARE(this->objectName(), QString::fromLatin1("commandTest")); + QCOMPARE(testObject.called, true); } -void tst_QState::setPropertyOnEntry() +void tst_QState::assignProperty() { QStateMachine machine; @@ -221,7 +238,7 @@ void tst_QState::setPropertyOnEntry() object->setProperty("fooBar", 10); QState *s1 = new QState(machine.rootState()); - s1->setPropertyOnEntry(object, "fooBar", 20); + s1->assignProperty(object, "fooBar", 20); machine.setInitialState(s1); machine.start(); @@ -230,7 +247,7 @@ void tst_QState::setPropertyOnEntry() QCOMPARE(object->property("fooBar").toInt(), 20); } -void tst_QState::setPropertyOnEntryTwice() +void tst_QState::assignPropertyTwice() { QStateMachine machine; @@ -238,8 +255,8 @@ void tst_QState::setPropertyOnEntryTwice() object->setProperty("fooBar", 10); QState *s1 = new QState(machine.rootState()); - s1->setPropertyOnEntry(object, "fooBar", 20); - s1->setPropertyOnEntry(object, "fooBar", 30); + s1->assignProperty(object, "fooBar", 20); + s1->assignProperty(object, "fooBar", 30); machine.setInitialState(s1); machine.start(); @@ -248,56 +265,24 @@ void tst_QState::setPropertyOnEntryTwice() QCOMPARE(object->property("fooBar").toInt(), 30); } -void tst_QState::setPropertyOnExit() -{ - QStateMachine machine; - - QObject *object = new QObject(); - object->setProperty("fooBar", 10); - - QState *s1 = new QState(machine.rootState()); - s1->setPropertyOnExit(object, "fooBar", 20); - - QState *s2 = new QState(machine.rootState()); - s1->addTransition(new QTransition(QEvent::User), s2); - - machine.setInitialState(s1); - machine.start(); - QCoreApplication::processEvents(); - - QCOMPARE(object->property("fooBar").toInt(), 10); - - machine.postEvent(new QEvent(QEvent::User)); - QCoreApplication::processEvents(); - - QCOMPARE(object->property("fooBar").toInt(), 20); -} - -void tst_QState::setPropertyOnExitTwice() +class EventTestTransition: public QTransition { - QStateMachine machine; - - QObject *object = new QObject(); - object->setProperty("fooBar", 10); - - QState *s1 = new QState(machine.rootState()); - s1->setPropertyOnExit(object, "fooBar", 20); - s1->setPropertyOnExit(object, "fooBar", 30); - - QState *s2 = new QState(machine.rootState()); - s1->addTransition(new QTransition(QEvent::User), s2); +public: + EventTestTransition(QEvent::Type type, QState *targetState) + : QTransition(QList<QAbstractState*>() << targetState), m_type(type) + { + } + +protected: + bool eventTest(QEvent *e) const + { + return e->type() == m_type; + } + +private: + QEvent::Type m_type; - machine.setInitialState(s1); - machine.start(); - QCoreApplication::processEvents(); - - QCOMPARE(object->property("fooBar").toInt(), 10); - - machine.postEvent(new QEvent(QEvent::User)); - QCoreApplication::processEvents(); - - QCOMPARE(object->property("fooBar").toInt(), 30); -} +}; void tst_QState::historyInitialState() { @@ -315,9 +300,9 @@ void tst_QState::historyInitialState() QState *s4 = new QState(s2); - s1->addTransition(new QTransition(QEvent::User), s2); - s2->addTransition(new QTransition(QEvent::User), s1); - s3->addTransition(new QTransition(QEvent::Type(QEvent::User+1)), s4); + 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(); |