diff options
Diffstat (limited to 'sources/pyside6/tests/QtScxml')
-rw-r--r-- | sources/pyside6/tests/QtScxml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside6/tests/QtScxml/QtScxml.pyproject | 3 | ||||
-rw-r--r-- | sources/pyside6/tests/QtScxml/test_dynamic.py | 53 | ||||
-rw-r--r-- | sources/pyside6/tests/QtScxml/trafficlight.scxml | 64 |
4 files changed, 121 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtScxml/CMakeLists.txt b/sources/pyside6/tests/QtScxml/CMakeLists.txt new file mode 100644 index 000000000..dde186697 --- /dev/null +++ b/sources/pyside6/tests/QtScxml/CMakeLists.txt @@ -0,0 +1 @@ +PYSIDE_TEST(test_dynamic.py) diff --git a/sources/pyside6/tests/QtScxml/QtScxml.pyproject b/sources/pyside6/tests/QtScxml/QtScxml.pyproject new file mode 100644 index 000000000..21ee7c9ab --- /dev/null +++ b/sources/pyside6/tests/QtScxml/QtScxml.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["test_dynamic.py"] +} diff --git a/sources/pyside6/tests/QtScxml/test_dynamic.py b/sources/pyside6/tests/QtScxml/test_dynamic.py new file mode 100644 index 000000000..212d6f7c1 --- /dev/null +++ b/sources/pyside6/tests/QtScxml/test_dynamic.py @@ -0,0 +1,53 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from helper.timedqapplication import TimedQApplication +from PySide6.QtCore import QCoreApplication, QObject, Slot, SIGNAL, SLOT +from PySide6.QtScxml import QScxmlStateMachine, QScxmlEvent + + +class Receiver(QObject): + def __init__(self): + super().__init__() + self.eventReceived = False + self.reachedStable = False + + @Slot(QScxmlEvent) + def handleEvent(self, event): + self.eventReceived = True + + @Slot() + def slotReachedStable(self): + self.reachedStable = True + + +class testDynamicStateMachine(TimedQApplication): + def setUp(self): + super().setUp() + filePath = Path(__file__).parent / "trafficlight.scxml" + self.assertTrue(filePath.is_file()) + self._machine = QScxmlStateMachine.fromFile(os.fspath(filePath)) + self._receiver = Receiver() + self._machine.connectToEvent("*", self._receiver, + SLOT("handleEvent(QScxmlEvent)")) + self._machine.reachedStableState.connect(self._receiver.slotReachedStable) + self.assertTrue(not self._machine.parseErrors()) + self.assertTrue(self._machine) + + def test(self): + self._machine.start() + while not self._receiver.reachedStable and not self._receiver.eventReceived: + QCoreApplication.processEvents() + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtScxml/trafficlight.scxml b/sources/pyside6/tests/QtScxml/trafficlight.scxml new file mode 100644 index 000000000..699409e68 --- /dev/null +++ b/sources/pyside6/tests/QtScxml/trafficlight.scxml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +--> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + xmlns:qt="http://theqtcompany.com/scxml/2015/06/" + version="1.0" + name="TrafficLightStateMachine" + initial="working" +> + <state id="working" initial="yellow"> + <state id="red"> + <onentry> + <send event="startGoingGreen" delay="3s"/> + </onentry> + <transition event="startGoingGreen" target="redGoingGreen"/> + </state> + + <state id="yellow" initial="greenGoingRed"> + <state id="redGoingGreen"> + <onentry> + <send event="goGreen" delay="1s"/> + </onentry> + <transition event="goGreen" target="green"/> + </state> + + <state id="greenGoingRed"> + <onentry> + <send event="goRed" delay="1s"/> + </onentry> + <transition event="goRed" target="red"/> + </state> + </state> + + <state id="green"> + <onentry> + <send event="startGoingRed" delay="3s"/> + </onentry> + <transition event="startGoingRed" target="greenGoingRed"/> + </state> + + <transition event="smash" target="broken"/> + </state> + + <state id="broken" initial="blinking"> + <state id="blinking"> + <onentry> + <send event="unblink" delay="1s"/> + </onentry> + <transition event="unblink" target="unblinking"/> + </state> + + <state id="unblinking"> + <onentry> + <send event="blink" delay="1s"/> + </onentry> + <transition event="blink" target="blinking"/> + </state> + + <transition event="repair" target="working"/> + </state> +</scxml> |