Skip to content

Commit

Permalink
Add test for parameter passing
Browse files Browse the repository at this point in the history
Signed-off-by: Enrico Ghiorzi <[email protected]>
  • Loading branch information
EnricoGhiorzi committed May 21, 2024
1 parent 4121c29 commit f82541e
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scan_fmt_xml/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ fn send() -> anyhow::Result<()> {
test(PathBuf::from_str("./tests/test_send/model.xml")?)
}

#[test]
fn param() -> anyhow::Result<()> {
test(PathBuf::from_str("./tests/test_param/model.xml")?)
}

fn test(file: PathBuf) -> anyhow::Result<()> {
let parser = Parser::parse(file)?;
let mut model = Sc2CsVisitor::visit(parser)?;
Expand Down
23 changes: 23 additions & 0 deletions scan_fmt_xml/tests/test_param/fsm_1.scxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<scxml
version="1.0"
xmlns="http://www.w3.org/2005/07/scxml"
datamodel="ecmascript"
name="fsm_1"
initial="initial">

<datamodel>
<!-- TYPE p:int32 -->
<data id="p" expr="0"/>
</datamodel>

<state id="initial">
<transition target="finished" cond="p == 0">
<send event="message" target="fsm_2">
<!-- TYPE result:int32 -->
<param name="result" expr="p + 1"/>
</send>
</transition>
</state>

<state id="finished"/>
</scxml>
18 changes: 18 additions & 0 deletions scan_fmt_xml/tests/test_param/fsm_2.scxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<scxml
version="1.0"
xmlns="http://www.w3.org/2005/07/scxml"
datamodel="ecmascript"
name="fsm_2"
initial="idle">

<state id="idle">
<transition event="message" target="finished" cond="_event.data.result == 1"/>
<transition event="message" target="loop"/>
</state>

<state id="finished"/>

<state id="loop">
<transition target="loop"/>
</state>
</scxml>
16 changes: 16 additions & 0 deletions scan_fmt_xml/tests/test_param/model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<specification xmlns="..." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="...">

<model>

<types path="./types.xml" />

<processList>
<process id="fsm_1" moc="fsm" path="./fsm_1.scxml" />
<process id="fsm_2" moc="fsm" path="./fsm_2.scxml" />
</processList>

</model>

<properties path="./properties.xml"/>
</specification>
102 changes: 102 additions & 0 deletions scan_fmt_xml/tests/test_param/types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!-- Basic types from OMG IDL as utilized in ROS2 IDL
and mapping from OMG IDL datatypes to ECMAScript 2023
See: https://www.omg.org/spec/IDL/4.2/About-IDL/
https://design.ros2.org/articles/idl_interface_definition.html
https://wiki.ros.org/msg
https://262.ecma-international.org/14.0/#sec-ecmascript-data-types-and-values
void
ECMAScript: Null
int8
uint8
int16
uint16
int32
uint32
int64
uint64
ECMAScript: BigInt
float32
float64
ECMAScript: Number
char
wchar
ECMAScript: String
boolean
ECMAScript: Boolean
sequence<type_spec>
sequence<type_spec, N>
<type_spec> []
ECMAScript: Array (??)
string
wstring
ECMAScript: String
time
ECMAScript: BigInt
NOTE: alias for uint32
duration
ECMAScript: BigInt
NOTE: alias for int32
URI
ECMAScript: String
NOTE: alias for string
-->


<dataTypeList>

<!-- Here are some examples on how ROS2 data types can be encoded easily -->

<!-- From https://wiki.ros.org/msg#headerSect -->
<structure id="Header">
<field id="stamp" type="time"/>
<field id="frame_id" type="string"/>
</structure>

<!-- From geometry_msgs/msg/Point.msg -->
<structure id="Point">
<field id="x" type="float64"/>
<field id="y" type="float64"/>
<field id="z" type="float64"/>
</structure>

<!-- From geometry_msgs/msg/Point.msg -->
<structure id="Point32">
<field id="x" type="float32"/>
<field id="y" type="float32"/>
<field id="z" type="float32"/>
</structure>

<!-- From geometry_msgs/msg/PointStamped.msg -->
<structure id="PointStamped">
<field id="header" type="Header"/>
<field id="point" type="Point"/>
</structure>

<!-- From geometry_msgs/msg/Polygon.msg -->
<structure id="Polygon">
<field id="points" type="Point32[]"/>
</structure>

<!-- End of example section -->

<!-- This is the only non-native data type required in this example -->

<enumeration id="TickResponse">
<label id="RUNNING"/>
<label id="SUCCESS"/>
<label id="FAILURE"/>
</enumeration>

</dataTypeList>

0 comments on commit f82541e

Please sign in to comment.