summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-05-07 15:18:51 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-05-07 15:18:51 (GMT)
commit00f04527d3d28ab1aa5b90b9a05366012ff5d1e5 (patch)
treed44b989946d9248755a3e708caeca44ee1368c25
parentb39781b214e2502e0884bce88aa3ac324f2d0b12 (diff)
downloadQt-00f04527d3d28ab1aa5b90b9a05366012ff5d1e5.zip
Qt-00f04527d3d28ab1aa5b90b9a05366012ff5d1e5.tar.gz
Qt-00f04527d3d28ab1aa5b90b9a05366012ff5d1e5.tar.bz2
don't add signal transition if target is null or signal doesn't exist
-rw-r--r--src/corelib/statemachine/qstate.cpp9
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp23
2 files changed, 30 insertions, 2 deletions
diff --git a/src/corelib/statemachine/qstate.cpp b/src/corelib/statemachine/qstate.cpp
index acee27d..4d12219 100644
--- a/src/corelib/statemachine/qstate.cpp
+++ b/src/corelib/statemachine/qstate.cpp
@@ -346,6 +346,15 @@ QSignalTransition *QState::addTransition(QObject *sender, const char *signal,
qWarning("QState::addTransition: signal cannot be null");
return 0;
}
+ if (!target) {
+ qWarning("QState::addTransition: cannot add transition to null state");
+ return 0;
+ }
+ if (*signal && sender->metaObject()->indexOfSignal(signal+1) == -1) {
+ qWarning("QState::addTransition: no such signal %s::%s",
+ sender->metaObject()->className(), signal+1);
+ return 0;
+ }
QSignalTransition *trans = new QSignalTransition(sender, signal, QList<QAbstractState*>() << target);
addTransition(trans);
return trans;
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 9b7bff3..f7fce94 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -1579,9 +1579,28 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
QState *s0 = new QState(machine.rootState());
- QFinalState *s1 = new QFinalState(machine.rootState());
+ QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: sender cannot be null");
+ QCOMPARE(s0->addTransition(0, SIGNAL(noSuchSignal()), 0), (QObject*)0);
+
SignalEmitter emitter;
- s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
+ 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);