aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmltest/statemachine
diff options
context:
space:
mode:
authorNobuaki Sukegawa <nsukeg@gmail.com>2014-12-14 19:31:25 +0900
committerNobuaki Sukegawa <nsukeg@gmail.com>2014-12-20 20:24:03 +0100
commiteff84a13afaf3e3ab1f3ef28d28e5d20b0145891 (patch)
treea218ceb40871a9dba1e660741d61d0d8da12902f /tests/auto/qmltest/statemachine
parente7b66a60584b3fcb1436a7dbe8396b71cb69fe1b (diff)
Resolve type names inside guard property of SignalTransition
SignalTransition's guard is evaluated against ad-hoc QQmlContext because it needs signal args added to its contextProperty. Since QQmlContext created this way does not have import type cache, we could not use type names inside guard. To avoid this problem, this patch makes guard's context inherit parent's type cahce. Change-Id: I4ddd559779681b53d4ee42f4820d05438addb5ac Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/qmltest/statemachine')
-rw-r--r--tests/auto/qmltest/statemachine/tst_enumguard.qml98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/auto/qmltest/statemachine/tst_enumguard.qml b/tests/auto/qmltest/statemachine/tst_enumguard.qml
new file mode 100644
index 0000000000..6e2a10782f
--- /dev/null
+++ b/tests/auto/qmltest/statemachine/tst_enumguard.qml
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Ford Motor Company
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtTest 1.1
+import QtQml.StateMachine 1.0
+
+TestCase {
+ id: testCase
+ StateMachine {
+ id: machine
+ initialState: startState
+ State {
+ id: startState
+ SignalTransition {
+ id: signalTrans
+ signal: testCase.mysignal
+ guard: alignment === QState.ParallelStates
+ targetState: finalState
+ }
+ }
+ FinalState {
+ id: finalState
+ }
+ }
+
+ SignalSpy {
+ id: finalStateActive
+ target: finalState
+ signalName: "activeChanged"
+ }
+
+ signal mysignal(int alignment)
+
+ name: "testEnumGuard"
+ function test_enumGuard()
+ {
+ // Start statemachine, should not have reached finalState yet.
+ machine.start()
+ tryCompare(finalStateActive, "count", 0)
+ tryCompare(machine, "running", true)
+
+ // Emit the signalTrans.signal which will evaluate the guard. The
+ // guard should return true, finalState be reached and the
+ // statemachine be stopped.
+ testCase.mysignal(QState.ParallelStates)
+ tryCompare(finalStateActive, "count", 1)
+ tryCompare(machine, "running", false)
+
+ // Restart machine.
+ machine.start()
+ tryCompare(machine, "running", true)
+ tryCompare(finalStateActive, "count", 2)
+
+ // Emit signal that makes the signalTrans.guard return false. The
+ // finalState should not have been triggered.
+ testCase.mysignal(QState.ExclusiveStates)
+ tryCompare(finalStateActive, "count", 2)
+ tryCompare(machine, "running", true)
+ }
+}