Skip to content

Commit

Permalink
Merge pull request #38 from jp-embedded/test375
Browse files Browse the repository at this point in the history
Test375
  • Loading branch information
jp-embedded committed Jul 7, 2017
2 parents 1d96bfd + 6b14566 commit 4c241c8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/scxml_parser.cpp
Expand Up @@ -24,6 +24,11 @@
using namespace boost::property_tree;
using namespace std;

// allow appending vector to vector
template <typename T> void operator+=(std::vector<T> &v1, const std::vector<T> &v2) {
v1.insert(v1.end(), v2.begin(), v2.end());
}

void scxml_parser::parse_scxml(const ptree &pt)
{
try {
Expand Down Expand Up @@ -85,8 +90,8 @@ void scxml_parser::parse_parallel(const ptree &pt, const boost::shared_ptr<state
else if (it->first == "history") parse_state(it->second, st);
else if (it->first == "parallel") parse_parallel(it->second, st);
else if (it->first == "transition") st->transitions.push_back(parse_transition(it->second));
else if (it->first == "onentry") st->entry_actions = parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions = parse_entry(it->second);
else if (it->first == "onentry") st->entry_actions += parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions += parse_entry(it->second);
else if (it->first == "initial") st->initial = parse_initial(it->second);
else cerr << "warning: unknown item '" << it->first << "' in <parallel>" << endl;
}
Expand Down Expand Up @@ -191,8 +196,8 @@ void scxml_parser::parse_state(const ptree &pt, const boost::shared_ptr<state> &
else if (it->first == "final") parse_final(it->second, st);
else if (it->first == "parallel") parse_parallel(it->second, st);
else if (it->first == "transition") st->transitions.push_back(parse_transition(it->second));
else if (it->first == "onentry") st->entry_actions = parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions = parse_entry(it->second);
else if (it->first == "onentry") st->entry_actions += parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions += parse_entry(it->second);
else if (it->first == "initial") st->initial = parse_initial(it->second);
else if (it->first == "datamodel") { scxml_parser::data_list m = parse_datamodel(it->second); m_scxml.datamodel.insert(m_scxml.datamodel.end(), m.begin(), m.end()); }
else cerr << "warning: unknown item '" << it->first << "' in <state>" << endl;
Expand Down Expand Up @@ -227,8 +232,8 @@ void scxml_parser::parse_final(const ptree &pt, const boost::shared_ptr<state> &
for (ptree::const_iterator it = pt.begin(); it != pt.end(); ++it) {
if (it->first == "<xmlcomment>") ; // ignore comments
else if (it->first == "<xmlattr>") ; // ignore, parsed above
else if (it->first == "onentry") st->entry_actions = parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions = parse_entry(it->second);
else if (it->first == "onentry") st->entry_actions += parse_entry(it->second);
else if (it->first == "onexit") st->exit_actions += parse_entry(it->second);
else cerr << "warning: unknown item '" << it->first << "' in <state>" << endl;
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/test.cpp
Expand Up @@ -8,6 +8,7 @@
#include "test506.h"
#include "test533.h"
#include "test570.h"
#include "test375.h"
#include "test576.h"
#include "event_list.h"
#include "event_tokens.h"
Expand Down Expand Up @@ -52,6 +53,14 @@ TEST(w3c, 372)
EXPECT_EQ(typeid(sc_test372::state_pass), typeid(*sc.cur_state));
}

// test that onentry handlers are executed in document order. event1 should be raised before event2
TEST(w3c, 375)
{
sc_test375 sc;
sc.init();
EXPECT_EQ(typeid(sc_test375::state_pass), typeid(*sc.cur_state));
}

// test that executable content in the <initial> transition executes after the onentry handler on the state
// and before the onentry handler of the child states. Event1, event2, and event3 should occur in that order.
TEST(w3c, 412)
Expand Down
30 changes: 30 additions & 0 deletions src/test/test375.txml
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!-- test that onentry handlers are executed in document order. event1 should be raised before event2 -->


<scxml conf:datamodel="" version="1.0" xmlns="http://www.w3.org/2005/07/scxml" xmlns:conf="http://www.w3.org/2005/scxml-conformance">



<state id="s0">
<onentry>
<raise event="event1"/>
</onentry>
<onentry>
<raise event="event2"/>
</onentry>

<transition event="event1" target="s1"/>
<transition event="*" conf:targetfail=""/>

</state>

<state id="s1">
<transition event="event2" conf:targetpass=""/>
<transition event="*" conf:targetfail=""/>
</state>


<conf:pass/>
<conf:fail/>
</scxml>
13 changes: 13 additions & 0 deletions src/vc2013/test/test.vcxproj
Expand Up @@ -161,6 +161,19 @@ $(OutDir)scxmlcc.exe %(RelativeDir)%(Filename).scxml</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">msxsl %(RelativeDir)%(Filename)%(Extension) %(RelativeDir)cpp.xsl -o %(RelativeDir)%(Filename).scxml
$(OutDir)scxmlcc.exe %(RelativeDir)%(Filename).scxml</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">msxsl %(RelativeDir)%(Filename)%(Extension) %(RelativeDir)cpp.xsl -o %(RelativeDir)%(Filename).scxml
$(OutDir)scxmlcc.exe %(RelativeDir)%(Filename).scxml</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(RelativeDir)%(Filename).h</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(RelativeDir)%(Filename).h</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">msxsl/scxmlcc %(FullPath)</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">msxsl/scxmlcc %(FullPath)</Message>
</CustomBuild>
<CustomBuild Include="..\..\test\test375.txml">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">msxsl %(RelativeDir)%(Filename)%(Extension) %(RelativeDir)cpp.xsl -o %(RelativeDir)%(Filename).scxml
$(OutDir)scxmlcc.exe %(RelativeDir)%(Filename).scxml</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">msxsl %(RelativeDir)%(Filename)%(Extension) %(RelativeDir)cpp.xsl -o %(RelativeDir)%(Filename).scxml
$(OutDir)scxmlcc.exe %(RelativeDir)%(Filename).scxml</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(RelativeDir)%(Filename).h</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
Expand Down
3 changes: 3 additions & 0 deletions src/vc2013/test/test.vcxproj.filters
Expand Up @@ -62,5 +62,8 @@
<CustomBuild Include="..\..\test\test570.txml">
<Filter>Source Files</Filter>
</CustomBuild>
<CustomBuild Include="..\..\test\test375.txml">
<Filter>Source Files</Filter>
</CustomBuild>
</ItemGroup>
</Project>

0 comments on commit 4c241c8

Please sign in to comment.