summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine
Commit message (Collapse)AuthorAgeFilesLines
...
* statemachine: Make signal transition registration thread-safeKent Hansen2012-07-131-0/+50
| | | | | | | | Since Qt's connections are thread-safe, QStateMachine's plumbing around them should be thread-safe too. Change-Id: I8ae91c2edc2d32ca4ed4258b71e5da22de30ed91 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Fix signal transition handling in multi-threaded setupKent Hansen2012-07-131-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By default, QStateMachine lazily registers signal transitions (i.e., connects to the signal) when the transition's source state is entered. The connections are established in Qt::AutoConnection mode, which means that if the sender object lives in a different thread, the signal processing will be queued. But if a sender object's signal is used in an out-going transition of the target state of the queued transition, it's possible that a second signal emission on the sender object's thread will be "missed" by the state machine; before the machine gets around to processing the first queued emission (and registering the transitions of the new state), a sender object on the other thread could have emitted a new signal. The solution employed here is to eagerly register any signal transition whose sender object is on a different thread; that is, register it regardless of whether the transition's source state is active. Conversely, when a machine's transitions are unregistered (i.e., because the machine finished), signal transitions with sender objects on other threads should be left as-is, in case the machine will be run again. This doesn't solve the case where the sender object is moved to a different thread _after_ the transition has been initialized. Theoretically, we could catch that by installing an event filter on every sender object and handle the ThreadChange events, but that would be very expensive, and likely useless in most cases. So let's just say that that case isn't supported for now. Task-number: QTBUG-19789 Change-Id: Ibc87bfbf2ed83217ac61ae9401fe4f179ef26c24 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Fix dynamic transition registration edge casesKent Hansen2012-07-131-0/+86
| | | | | | | | | | | | Some of the transition constructors didn't call the maybeRegister() function, causing the transitions to be ignored if they were created when the state machine was running and the transition's source state was active. Added tests that cover all possible cases. Change-Id: If1b593b127bd719e3be4e5a2e6949a780c4e97c3 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Set correct signal index when signal is non-normalizedKent Hansen2012-07-131-22/+77
| | | | | | | | | | | | The originalSignalIndex member was not set if the signature had to be normalized. This caused the SignalEvent passed to onTransition() to report a signal index of -1. Improve the signal transition tests so they check both the event passed to eventTest() and onTransition(). Change-Id: I5331fd1944d53310b6d11eb2fd8713b80faa53a1 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Make it possible to connect to QAbstract{State,Transtion} private signals.Stephen Kelly2012-07-131-0/+121
| | | | | | | Use the same trick as used for private signals in the models. Change-Id: I4235788490cae0e3d554565621d145652dc5b0ca Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* statemachine: Fix state entry bug for parallel state groupsKent Hansen2012-07-121-0/+39
| | | | | | | | | | | | | | | | | | The SCXML spec had a bug that would cause the initial state of a compound state within a parallel state group to be entered even if the transition specified another (non-initial) state of the compound state as its target. This only happened if the transition had multiple target states. The bug has been fixed in recent revisions of the SCXML spec. This commit implements the fix, which is to walk the ancestors of the transition's target states only after all the target states themselves have been added, so that the default initial states are correctly overridden/ignored. Task-number: QTBUG-25958 Change-Id: Iac532047678c483a4a3996e24dacf30e00f6bbe0 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Support parallel root stateKent Hansen2012-07-111-4/+9
| | | | | | | | | | | QStateMachine inherits from QState, so it should be possible to set its childMode to ParallelStates, and it should behave as expected (the machine should emit the finished() signal when all its child states are in final states). Task-number: QTBUG-22931 Change-Id: Ic436351be0be69e3b01ae9984561132cd9839fa7 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Emit finished() signal when the initial state is finalKent Hansen2012-07-111-0/+12
| | | | | | | | | | It's legal to set a QFinalState as the initial state. The state machine should correctly emit the finished() signal upon entering such a state in the initial transition, and don't do any further processing. Change-Id: Ica8d3fadbbde604512ea1136624af54eb3b13b11 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Revamp property assignments implementationKent Hansen2012-07-111-0/+443
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the old implementation, property assignments (QState::assignProperty()) were "second-class citizens". Assignments were not really integrated into the state machine algorithm, but rather done as a separate step (QStateMachinePrivate::applyProperties()). While that was convenient for SCXML spec transcription purposes, it resulted in some pretty poor semantics on the user side: * Properties were not assigned until _after_ both the QAbstractState::onEntry() function had been called and the QState::entered() signal had been emitted. * Automatic property restoration (QStateMachine::RestoreProperties) did not play nice with nested states (and parallel states, in particular). The proper fix is to refactor the implementation to make property assignments first-class in the core state machine algorithm (QStateMachinePrivate::microstep()). In practice, this meant splitting some steps. Instead of calling exitStates() straight away, we now first only compute the states to exit (without actually exiting them), and use the resulting set to compute which properties are candidates for restoration. Similarly, instead of calling enterStates(), we first only compute the states to enter (without actually entering them), and use the resulting set to compute which properties are assigned by the entered states. With that in place, the rest was a matter of moving the various chunks of the old applyProperties() logic to the place where they belong in the per-state entry/exit. All existing autotests pass. Added several tests that verify the desired semantics in more detail. Task-number: QTBUG-20362 Change-Id: I7d8c7253b66cae87bb0d09aa504303218e230c65 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Don't assign properties for transitions with no targetsKent Hansen2012-07-101-0/+55
| | | | | | | | | | If the transition has no target states, that means the current state won't change; hence, property assignments should not be performed. In particular, properties should not be restored to the values they had before the state was entered. Change-Id: I237bbb541f939c272777e70c5f26c886ec457a17 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Purge restorable properties when they are restoredKent Hansen2012-07-101-0/+46
| | | | | | | | | | | | Previously, a registered restorable property would only be unregistered if the property was animated (see QStateMachinePrivate::_q_animationFinished()). But if a property is set directly, it should also be unregistered; otherwise, the state machine would use the previously saved (stale) value the next time that property should be restored. Change-Id: I5d246aa5355ddd0ba5f81b0186a9f0e4f3bbaa3f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Set compound state's initial state to 0 if it is removed/deletedKent Hansen2012-07-101-0/+13
| | | | | Change-Id: I45b7c15a9b3d5a1860cb9a7da8836f9eaaa0326d Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* statemachine: Don't crash if property assignment target is deletedKent Hansen2012-07-101-0/+52
| | | | | | | | Do like QPropertyAnimation and store the QObject in a QPointer. Purge the assignments list upon state entry and property restore. Change-Id: I54a56885a2905178ab6aa5cf292b3d25c86b7a97 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Make qstatemachine autotest build without widgetsKent Hansen2012-06-072-3/+16
| | | | | Change-Id: I3a58cb1cbe0c86aca6e533187e85c166bf0f8957 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* statemachine: Make delayed event posting work from secondary threadKent Hansen2012-06-061-0/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | postDelayedEvent() and cancelDelayedEvent() are marked as thread-safe in the documentation. Unfortunately, they didn't actually work when called from another thread; they just produced some warnings: QObject::startTimer: timers cannot be started from another thread QObject::killTimer: timers cannot be stopped from another thread As the warnings indicate, the issue was that postDelayedEvent() (cancelDelayedEvent()) unconditionally called QObject::startTimer() (stopTimer()), i.e. without considering which thread the function was called from. If the function is called from a different thread, the actual starting/stopping of the associated timer is now done from the correct thread, by asynchronously calling a private slot on the state machine. This also means that the raw timer id can no longer be used as the id of the delayed event, since a valid event id must be returned before the timer has started. The state machine now manages those ids itself (using a QFreeList, just like startTimer() and killTimer() do), and also keeps a mapping from timer id to event id once the timer has been started. This is inherently more complex than before, but at least the API should work as advertised/intended now. Task-number: QTBUG-17975 Change-Id: I3a866d01dca23174c8841112af50b87141df0943 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Write test to confirm QStateMachine calls connectNotify().Mitch Curtis2012-06-051-0/+35
| | | | | | | Task-number: QTBUG-16628 Change-Id: I77535fcb9a6ae306df8ccd670ee1bfc32721d66a Reviewed-by: Kent Hansen <kent.hansen@nokia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
* Enter initial state before QStateMachine::started() is emittedKent Hansen2012-06-041-0/+18
| | | | | | | | | | | | | | | The documentation says that started() "is emitted when the state machine has entered its initial state", but the implementation didn't adhere to that. The consequence is that if you e.g. emitted a signal from a slot connected to started(), and that signal was used by a transition from the initial state, the signal would effectively get ignored and the state machine would remain in the initial state. Task-number: QTBUG-24307 Change-Id: Ibbeb627d517eaff821d88e256a949eacf6aae350 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Fix typos in QState sorting functionsKent Hansen2012-06-041-2/+17
| | | | | | | | | | | | | | A QObject can't be a child of itself, so the comparison always returned false. In practice, this was causing the entry/exit order of parallel states to be random. QObject::children() is documented to contain the children in the order in which they were added, so this fix actually achieves deterministic behavior. Task-number: QTBUG-25959 Change-Id: Id3f12d6bfbc249f1d4fed0bafb7d0217093e458e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Improved stability of tst_qstatemachine, mark as parallel-safeRohan McGovern2012-05-312-1/+2
| | | | | | | | | | | | | | tst_QStateMachine::postEventFromOtherThread() assumed that 10,000 iterations of the event loop in a separate thread could always be completed successfully within the default QTRY_COMPARE timeout. This may be false if the CPU load is already high - such as when running other tests concurrently. Decrease the iteration count. Change-Id: I780523f73c0c16fa0b2ab3201b2b0affdebc198d Reviewed-by: Toby Tomkins <toby.tomkins@nokia.com> Reviewed-by: Kalle Lehtonen <kalle.ju.lehtonen@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-302-2/+2
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-232-2/+2
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-052-2/+2
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Cleanup corelib autotests.Jason McDonald2011-12-281-0/+79
| | | | | | | | | | | | | When using QSignalSpy, always verify that the signal spy is valid. This will cause the test to give a meaningful failure when spying on a non-existant signal. Without this change, tests that spy on a signal to ensure that it is not emitted (i.e. by comparing the spy count to zero) could pass erroneously if something went wrong when creating the signal spy, as an invalid QSignalSpy will always return a count of zero. Change-Id: I41f4a63d9f0de9190a86de237662dc96be802446 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove TESTED_CLASS/TESTED_FILES comments from tests.Jason McDonald2011-12-062-6/+0
| | | | | | | | | These comments were mostly empty or inaccurate. Appropriate naming of tests and appropriate placement of tests within the directory tree provide more reliable indicators of what is being tested. Change-Id: Ib6bf373d9e79917e4ab1417ee5c1264a2c2d7027 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Cleanup corelib autotestsJason McDonald2011-11-301-1/+1
| | | | | | | | Remove references to the old bug tracker. The data from the old bug tracker is no longer accessible, so these markers are meaningless. Change-Id: Ib9d029d52b70fd0a512b9532d65f03763eabfe57 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Cleanup corelib autotestsJason McDonald2011-11-291-2/+2
| | | | | | | | Don't name test functions using task identifiers from obsolete bug trackers. Change-Id: Iba6ae8ad3b39e365c5510ed5c86749a167572829 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove obsolete code from QStateMachine test.Jason McDonald2011-11-211-366/+0
| | | | | | | | | The removed code was already disabled because it tested API that never made it into an official Qt release -- see commit f7d69d75 in the Qt 4.x history. Change-Id: I4f7eb20f937bdabfcac92842c5804233dca26a23 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove obsolete code from QStateMachine test.Jason McDonald2011-11-211-245/+0
| | | | | | | | | The removed code was already disabled because it tested API that never made into an official Qt release -- see commit ad1441fc in the Qt 4.x history. Change-Id: I7dbfb83c82bdb79e8d3f7f6c7043d76913dea589 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Cleanup corelib autotestsJason McDonald2011-11-112-9/+4
| | | | | | | | | | | | | Tidy the autotest .pro files. Most autotest .pro files should look like this: CONFIG += testcase TARGET = tst_something QT = core testlib SOURCES = tst_something.cpp Change-Id: I877c2194e9fa9dd13478d117895e1e255a948ad7 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove redundant copies of QTRY_COMPARE.Jason McDonald2011-11-092-28/+0
| | | | | | | | QTRY_COMPARE is now part of qtestlib, so there's no need for copies of it. Change-Id: Ied4e7d3b30c1cf16ddcbf8655e4d976e74c2bd8a Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Cleanup corelib autotestsJason McDonald2011-11-072-28/+0
| | | | | | | Remove redundant empty constructors, destructors and test functions. Change-Id: Idb51368895e67ec3fc0345a9a5d33d77730c051b Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Remove obsolete code from qstate autotest.Jason McDonald2011-10-311-145/+0
| | | | | | | | This was originaly the only test function in this test, and should have been deleted when it was replaced by the other test functions. Change-Id: Idc71a5462fd4d19955f9b14389b877be16c62ab5 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* corelib: eliminated usage of qttest_p4.prfRohan McGovern2011-10-252-4/+6
| | | | | | | | | qttest_p4.prf was added as a convenience for Qt's own autotests in Qt4. It enables various crufty undocumented magic, of dubious value. Stop using it, and explicitly enable the things from it which we want. Change-Id: I7c1ffe9c8c294dbdc988e1582e580b1ed3f4593e Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
* Add missing Q_OBJECT macro to GoToStateTransitionKent Hansen2011-10-051-0/+19
| | | | | | | | | | | The missing macro caused qFindChild() to return any QAbstractTransition. Task-number: QTBUG-21813 Change-Id: I80507aa86c8c32d7fa59a1b5ae551043f5f90315 Reviewed-on: http://codereview.qt-project.org/6044 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
* Moving relevant tests to corelib/statemachineHolger Ihrig2011-09-015-0/+4871
Task-number: QTBUG-21066 Change-Id: I6dfff1c3b3ad2119a588dc52eb5a2e67255284c1 Reviewed-on: http://codereview.qt.nokia.com/3658 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>