Author: jbeard Date: Tue Aug 10 14:19:42 2010 New Revision: 984032 URL: http://svn.apache.org/viewvc?rev=984032&view=rev Log: Made changes so that history states and initial states inside of parallel states are handled correctly. Intermediat commit, some unit tests are still broken.
Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/ commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml (with props) commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/ commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js (with props) Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.js commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/ir-compiler/normalizeInitialStates.xsl commons/sandbox/gsoc/2010/scxml-js/trunk/test/in_predicate/TestInPredicate.xml commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink.xml commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_dataModule.xml commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_executableContent.xml commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_performance.xml Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/build.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/build.js?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/build.js (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/build.js Tue Aug 10 14:19:42 2010 @@ -73,14 +73,17 @@ require.def("build", //paths to all of the SCXML files we want to compile var scxmlTests = { - KitchenSink_dataModule :"test/kitchen_sink/KitchenSink_dataModule.xml", KitchenSink :"test/kitchen_sink/KitchenSink.xml", + KitchenSink_dataModule :"test/kitchen_sink/KitchenSink_dataModule.xml", + /* KitchenSink_performance :"test/kitchen_sink/KitchenSink_performance.xml", KitchenSink_executableContent :"test/kitchen_sink/KitchenSink_executableContent.xml", ConditionalTransition :"test/conditional_transition/TestConditionalTransition.xml", InPredicate :"test/in_predicate/TestInPredicate.xml", EventSystemProperties :"test/event_system_properties/TestEventSystemProperties.xml", - PrefixEvents:"test/prefix_events/TestPrefixEvents.xml" + PrefixEvents:"test/prefix_events/TestPrefixEvents.xml", + */ + Parallel:"test/parallel/TestParallel.xml" } //FIXME: this violates Don't Repeat Yourself; these paths are written here and in the module @@ -107,13 +110,16 @@ require.def("build", var unitTestScripts = [ - "test/kitchen_sink/scripts/unitTest_dataModel", - "test/kitchen_sink/scripts/unitTest", - "test/kitchen_sink/scripts/unitTest_executableContent", - "test/conditional_transition/scripts/unitTest", - "test/in_predicate/scripts/unitTest", - "test/event_system_properties/scripts/unitTest", - "test/prefix_events/scripts/unitTest" + "test/kitchen_sink/scripts/unitTest", + "test/kitchen_sink/scripts/unitTest_dataModel", + /* + "test/kitchen_sink/scripts/unitTest_executableContent", + "test/conditional_transition/scripts/unitTest", + "test/in_predicate/scripts/unitTest", + "test/event_system_properties/scripts/unitTest", + "test/prefix_events/scripts/unitTest" + */ + "test/parallel/scripts/unitTest" ] //gets populated at run-time Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/backends/js/AbstractStatechartGenerator.xsl Tue Aug 10 14:19:42 2010 @@ -643,6 +643,8 @@ <param name="t"/> <variable name="isDeep" select="$s/@type = 'deep'"/> + <variable name="isChildOfParallel" select="local-name($s/..) = 'parallel'"/> + <variable name="historyStateReference"> <call-template name="genHistoryTriggerDispatcherHistoryStateReference"> <with-param name="s" select="$s"/> @@ -677,9 +679,26 @@ var newConfiguration = []; </if> + <if test="$isChildOfParallel"> + <variable name="siblingStates" select="$s/../s:state | $s/../s:parallel"/> + + var siblingStates = [ + <for-each select="$siblingStates"> + + <value-of select="@id"/> + + <if test="not(position()=last())"> + , + </if> + </for-each> + ]; + + </if> + <value-of select="$historyStateReference"/>.lastConfiguration.forEach(function(state){ <call-template name="genHistoryTriggerDispatcherInnerForEach"> <with-param name="isDeep" select="$isDeep"/> + <with-param name="isChildOfParallel" select="$isChildOfParallel"/> </call-template> }); @@ -702,11 +721,20 @@ <template name="genHistoryTriggerDispatcherInnerForEach"> <param name="isDeep"/> + <param name="isChildOfParallel"/> var statesEntered = [<value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>]; for(var parent = <value-of select="$genHistoryTriggerDispatcherInnerForEachStateReference"/>.parent; - parent != historyState.parent && parent != null; + parent != null && + <choose> + <when test="$isChildOfParallel"> + siblingStates.indexOf(parent) == -1 + </when> + <otherwise> + parent != historyState.parent + </otherwise> + </choose>; parent = parent.parent){ statesEntered.push(parent); } Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/ir-compiler/normalizeInitialStates.xsl URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/ir-compiler/normalizeInitialStates.xsl?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/ir-compiler/normalizeInitialStates.xsl (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/ir-compiler/normalizeInitialStates.xsl Tue Aug 10 14:19:42 2010 @@ -23,5 +23,34 @@ </xsl:copy> </xsl:template> + + <xsl:template match="s:parallel"> + <!-- parallel states do not have use "initial" tag or attribute to specify initial states; instead it's implied. + we add initial tag here as it makes transformations easier, but I should probably move it to a different + namespace, as this makes the IR invalid SCXML --> + <xsl:copy> + <xsl:apply-templates select="@*"/> + + <initial id="{concat(@id,'_initial')}"> + <xsl:choose> + <xsl:when test="s:history"> + <transition target="{s:history/@id}"/> + </xsl:when> + <xsl:otherwise> + <transition> + <!-- make a space-separate list of targets. this will get broken up by later transitions --> + <xsl:attribute name="target"> + <xsl:for-each select="s:state"> + <xsl:value-of select="@id"/><xsl:text> </xsl:text> + </xsl:for-each> + </xsl:attribute> + </transition> + </xsl:otherwise> + </xsl:choose> + </initial> + <xsl:apply-templates select="node()"/> + + </xsl:copy> + </xsl:template> </xsl:stylesheet> Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/in_predicate/TestInPredicate.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/in_predicate/TestInPredicate.xml?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/in_predicate/TestInPredicate.xml (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/in_predicate/TestInPredicate.xml Tue Aug 10 14:19:42 2010 @@ -27,7 +27,7 @@ This is to test the use of the In() pred <transition target="p1"/> </initial> - <parallel id="p1" initial="r1 r2"> + <parallel id="p1"> <state id="r1" initial="a1"> <!-- sanity tests --> Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink.xml?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink.xml (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink.xml Tue Aug 10 14:19:42 2010 @@ -59,10 +59,6 @@ <parallel id="Parallel1"> - <initial> - <transition target="DeepHistory"/> - </initial> - <history id="DeepHistory" type="deep"> <transition target="ParallelRegion1 ParallelRegion2"/> </history> Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_dataModule.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_dataModule.xml?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_dataModule.xml (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_dataModule.xml Tue Aug 10 14:19:42 2010 @@ -85,10 +85,6 @@ <log label="y" expr="y"/> </onexit> - <initial> - <transition target="DeepHistory"/> - </initial> - <history id="DeepHistory" type="deep"> <transition target="ParallelRegion1 ParallelRegion2"/> </history> Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_executableContent.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_executableContent.xml?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_executableContent.xml (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_executableContent.xml Tue Aug 10 14:19:42 2010 @@ -96,10 +96,6 @@ <log label="y" expr="self.y"/> </onexit> - <initial> - <transition target="DeepHistory"/> - </initial> - <history id="DeepHistory" type="deep"> <transition target="ParallelRegion1 ParallelRegion2"/> </history> Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_performance.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_performance.xml?rev=984032&r1=984031&r2=984032&view=diff ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_performance.xml (original) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/kitchen_sink/KitchenSink_performance.xml Tue Aug 10 14:19:42 2010 @@ -56,10 +56,6 @@ <parallel id="Parallel1"> - <initial> - <transition target="DeepHistory"/> - </initial> - <history id="DeepHistory" type="deep"> <transition target="ParallelRegion1 ParallelRegion2"/> </history> Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml?rev=984032&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml (added) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml Tue Aug 10 14:19:42 2010 @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +--> +<!-- +This is to test the use of the In() predicate. +--> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + profile="ecmascript"> + + <initial> + <transition target="p1"/> + </initial> + + <parallel id="p1"> + <state id="r1" initial="a"> + <state id="a"> + <transition target="b" event="t1"/> + </state> + <state id="b"> + </state> + </state> + + <state id="r2" initial="c"> + <state id="c"> + <transition target="d" event="t2"/> + </state> + <state id="d"> + </state> + </state> + + <transition target="p2" event="t3"/> + </parallel> + + <parallel id="p2"> + <history type="shallow" id="shallow_history"> + <transition target="e g"/> + </history> + + <state id="r3" initial="f"> + <state id="e"> + <transition target="f" event="t4"/> + </state> + <state id="f"> + </state> + </state> + + <state id="r4" initial="h"> + <state id="g"> + <transition target="h" event="t5"/> + </state> + <state id="h"> + </state> + </state> + + <transition target="p3" event="t6_10"/> + </parallel> + + <parallel id="p3"> + <history type="deep" id="deep_history"> + <transition target="c1 c2"/> + </history> + + <state id="r5"> + <state id="c1" initial="i"> + <state id="i"> + <transition target="j" event="t7"/> + </state> + <state id="j"> + </state> + </state> + </state> + + <state id="r6"> + <state id="c2" initial="k"> + <state id="k"> + <transition target="l" event="t8"/> + </state> + <state id="l"> + </state> + </state> + </state> + + <transition target="p2" event="t9"/> + </parallel> +</scxml> + + + Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/TestParallel.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js?rev=984032&view=auto ============================================================================== --- commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js (added) +++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js Tue Aug 10 14:19:42 2010 @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +require.def( "test/parallel/scripts/unitTest", +{ + + scxmlTest : "test/parallel/TestParallel.xml", + + register:function(scConstructor){ + + //TODO: can load this using RequireJS, so we don't need to use the dojo module system? + dojo.require("doh.runner"); + var sc; + doh.register("testParallel",[ + { + name:"testAll", + //timeout:5000, + setUp:function(){ + sc = new scConstructor() + sc.initialize(); + }, + runTest:function(){ + var $ = function(conf){return conf.map(function(s){return s.toString()})}; + + var conf0 = sc.getCurrentConfiguration(); + console.log($(conf0)); + doh.assertTrue(setwiseEqual([sc._states.a,sc._states.c],conf0)); + + console.info("sending event t1") + sc.t1() + var conf1 = sc.getCurrentConfiguration(); + console.log($(conf1)); + doh.assertTrue(setwiseEqual([sc._states.b,sc._states.c],conf1)); + + + console.info("sending event t2") + sc.t2() + var conf2 = sc.getCurrentConfiguration(); + console.log($(conf2)); + doh.assertTrue(setwiseEqual([sc._states.b,sc._states.d],conf2)); + + console.info("sending event t3") + sc.t3() + var conf3 = sc.getCurrentConfiguration(); + console.log($(conf3)); + doh.assertTrue(setwiseEqual([sc._states.e,sc._states.g],conf3)); + + console.info("sending event t4") + sc.t4() + var conf4 = sc.getCurrentConfiguration(); + console.log($(conf4)); + doh.assertTrue(setwiseEqual([sc._states.f,sc._states.g],conf4)); + + console.info("sending event t5") + sc.t5() + var conf5 = sc.getCurrentConfiguration(); + console.log($(conf5)); + doh.assertTrue(setwiseEqual([sc._states.f,sc._states.h],conf5)); + + console.info("sending event t6_10") + sc.t6_10() + var conf6 = sc.getCurrentConfiguration(); + console.log($(conf6)); + doh.assertTrue(setwiseEqual([sc._states.i,sc._states.k],conf6)); + + console.info("sending event t7") + sc.t7() + var conf7 = sc.getCurrentConfiguration(); + console.log($(conf7)); + doh.assertTrue(setwiseEqual([sc._states.j,sc._states.k],conf7)); + + console.info("sending event t8") + sc.t8() + var conf8 = sc.getCurrentConfiguration(); + console.log($(conf8)); + doh.assertTrue(setwiseEqual([sc._states.j,sc._states.l],conf8)); + + console.info("sending event t9") + sc.t9() + var conf9 = sc.getCurrentConfiguration(); + console.log($(conf9)); + doh.assertTrue(setwiseEqual([sc._states.f,sc._states.h],conf9)); + + console.info("sending event t6_10") + sc.t6_10() + var conf10 = sc.getCurrentConfiguration(); + console.log($(conf10)); + doh.assertTrue(setwiseEqual([sc._states.j,sc._states.l],conf10)); + }, + tearDown:function(){ + sc.destroy(); + } + } + ]); + } +}) + + Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/parallel/scripts/unitTest.js ------------------------------------------------------------------------------ svn:eol-style = native