summaryrefslogtreecommitdiffstats
path: root/test/uscxml/promela/test-complete.scxml
blob: a96152b26911d9d33bb75b66fe26dcbdf5ffce88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<scxml datamodel="promela">

  <datamodel>
    <data id="foreachArray1" type="int[3]">[1,2,3]</data>
    <data id="parallelVar1" type="int" expr="0"/>
    <data id="ifVar1">{ foo: 1, bar: 'baz' }</data>
    <data id="counter">{ itemSum: 0, indexSum: 0 }</data>
    <data id="sendVar1" type="int" expr="4"/>
    <data id="histVar1" type="int">0</data>
    <data id="finalizeVar1" type="int">0</data>
  </datamodel>

  <state id="s0">
    <history id="s0.h0" type="deep" />
    <parallel id="p0">
      <state id="p0.s0">
        <state id="p0.s0.s0">
          <onentry>
            <if cond="ifVar1.foo == 3">
              <log label="if choosen" />
              <log label="ifVar1.bar is" expr="ifVar1.bar" />
              <foreach array="foreachArray1" 
                       item="foreachItem1" 
                       index="foreachIndex1">
                <script>
                  counter.indexSum = counter.indexSum + foreachIndex1;
                  counter.itemSum = counter.itemSum + foreachItem1;
                </script>
                <log label="foreach counter.indexSum is" 
                     expr="counter.indexSum" />
                <log label="foreach counter.itemSum is" 
                     expr="counter.itemSum" />
              </foreach>
              <raise event="if.choosen" />
            <elseif cond="ifVar1.bar == 'baz'" />
              <log label="elseif choosen" />
              <log label="ifVar1.bar is" expr="ifVar1.bar" />
              <assign location="ifVar1.foo" expr="3" />
              <send event="elseif.choosen" namelist="sendVar1">
                <param name="foo" expr="sendVar1 + 16" />
                <param name="bar" expr="'a string literal'" />
              </send>
            <else />
              <log label="else choosen" />
              <log label="ifVar1.foo is" expr="ifVar1.foo" />
              <log label="ifVar1.bar is" expr="ifVar1.bar" />
              <raise event="else.choosen" />
            </if>
            <script>parallelVar1++</script>
          </onentry>
          <transition event="else.choosen" target="p0">
            <assign location="ifVar1.bar" expr="'baz'" />
          </transition>
          <transition event="elseif.choosen" target="p0"
                      cond="_event.data.foo == 20 &amp;&amp; 
                            _event.data.sendVar1 == 4 &amp;&amp; 
                            _event.data.bar == 'a string literal'" 
          />
        </state>
        <state id="p0.s0.s1">
          <onentry>
            <if cond="_x.states['p0'] &amp;&amp; histVar1 == 1">
              <raise event="to.s2" />
            <else />
              <raise event="to.s1" />
            </if>
          </onentry>
          <transition event="to.s2" target="s2" />
          <transition event="to.s1" target="s1" />
        </state>
      </state>
      <state id="p0.s1">
        <onexit>
          <script>parallelVar1++</script>
        </onexit>
      </state>
      <transition event="if.choosen" 
                  cond="counter.itemSum == 6 &amp;&amp; 
                        counter.indexSum == 3" 
                  target="p0.s0.s1" />
    </parallel>
  </state>
  
  <state id="s1">
    <invoke type="scxml" autoforward="true">
      <content>
        <scxml datamodel="promela">
          <state id="waitForEvent">
            <transition event="trigger.child">
              <send target="#_parent" event="back.to.history" />
            </transition>
          </state>
        </scxml>
      </content>
      <finalize>
        <script>finalizeVar1++;</script>
      </finalize>
    </invoke>
    <onentry>
      <send event="trigger.child" delay="1000" />
    </onentry>
    <transition event="back.to.history" 
                cond="finalizeVar1 == 1" 
                target="s0.h0">
      <assign location="histVar1" expr="4-3" />
    </transition>
  </state>
  
  <state id="s2" initial="s2.s0">
    <onentry>
      <send event="cancel.delayed" delay="3000" sendid="cancel.delayed" />
      <cancel sendid="cancel.delayed" />
    </onentry>
    <transition event="done.state.s2" 
                cond="_event.data.Var1 == 'foo'" 
                target="s3.h0">
      <assign location="histVar1" expr="8" />
    </transition>
    <transition event="done.state.s2" target="fail" />
    <transition event="cancel.delayed" target="fail" />
    <transition target="pass" cond="histVar1 == 8" />
    <state id="s2.s0">
      <transition target="s2.s1"/>
    </state>
    <final id="s2.s1">
      <donedata>
        <param name="Var1" expr="'foo'"/>
      </donedata>
    </final>
  </state>
  
  <state id="s3">
    <history id="s3.h0" type="shallow">
      <transition target="s3.s1">
        <log label="history transition" />
        <assign location="histVar1" expr="4" />
      </transition>
    </history>
    <state id="s3.s1">
      <transition target="s2" />
    </state>
  </state>
  
  <final id="pass">
    <onentry>
      <log label="Outcome" expr="'pass'"/>
    </onentry>
  </final>
  <final id="fail">
    <onentry>
      <log label="Outcome" expr="'fail'"/>
    </onentry>
  </final>
</scxml>