diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | test/samples/uscxml/applications/3dviewer.scxml | 84 | ||||
-rw-r--r-- | test/samples/uscxml/arabica/test-arabica-events.xml | 10 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/CameraPos.proto | 9 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/DirectoryListingService.proto | 48 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/LinearAlgebra.proto | 18 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/ModelInfo.proto | 10 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/Pose.proto | 22 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/SceneSetup.proto | 8 | ||||
-rw-r--r-- | test/samples/uscxml/proto/3DViewer/SceneShotService.proto | 24 | ||||
-rw-r--r-- | test/samples/uscxml/scripts/test-simple-ecmascript.scxml | 12 | ||||
-rw-r--r-- | test/samples/uscxml/test-scenegraph.scxml | 45 | ||||
-rw-r--r-- | test/src/test-arabica-events.cpp | 61 |
13 files changed, 346 insertions, 10 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d47364e..39a4667 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,3 +48,8 @@ add_executable(test-completion src/test-completion.cpp) target_link_libraries(test-completion uscxml) add_test(test-completion ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-completion ${CMAKE_SOURCE_DIR}/test/samples/uscxml/test-donedata.scxml) set_target_properties(test-completion PROPERTIES FOLDER "Tests") + +add_executable(test-arabica-events src/test-arabica-events.cpp) +target_link_libraries(test-arabica-events uscxml) +add_test(test-arabica-events ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-arabica-events ${CMAKE_SOURCE_DIR}/test/samples/arabica/test-arabica-events.xml) +set_target_properties(test-arabica-events PROPERTIES FOLDER "Tests") diff --git a/test/samples/uscxml/applications/3dviewer.scxml b/test/samples/uscxml/applications/3dviewer.scxml new file mode 100644 index 0000000..90970d3 --- /dev/null +++ b/test/samples/uscxml/applications/3dviewer.scxml @@ -0,0 +1,84 @@ +<scxml + datamodel="ecmascript" + xmlns="http://www.w3.org/2005/07/scxml" + xmlns:scenegraph="http://uscxml.tk.informatik.tu-darmstadt.de/scenegraph.xsd"> + <datamodel> + <data id="localCam" /> + <data id="foo" /> + </datamodel> + <state id="start"> + <!-- setup all invokers --> + + <!-- 20ms heartbeat --> + <invoke type="heartbeat" id="heartbeat.20ms"> + <param name="interval" expr="'20ms'" /> + </invoke> + + <!-- receive files --> + <invoke type="umundo" id="umundo.files"> + <param name="domain" expr="''" /> + <param name="channel" expr="'umundo.files'" /> + <param name="types" expr="'../proto/3DViewer'" /> + </invoke> + + <!-- publish / subscribe to remote pose --> + <invoke type="umundo" id="umundo.pose"> + <param name="domain" expr="''" /> + <param name="channel" expr="'umundo.pose'" /> + <param name="types" expr="'../proto/3DViewer'" /> + </invoke> + + <!-- 3D viewer + This is only a template for nodes inserted per javascript + --> + <invoke type="scenegraph"> + <content> + <scenegraph:display id="localDisplay" width="50%" height="50%"> + <scenegraph:viewport> + <scenegraph:camera id="localCam"> + </scenegraph:camera> + <scenegraph:translation> + <scenegraph:rotation> + <scenegraph:scale> + <scenegraph:node /> + </scenegraph:scale> + </scenegraph:rotation> + </scenegraph:translation> + </scenegraph:viewport> + </scenegraph:display> + </content> + </invoke> + <state id="sendPose"> + <transition target="sendPose" event="heartbeat.20ms" /> + <onentry> + <script> + localCam = document.evaluate("//scenegraph:display[@id='localDisplay']").asNodeSet(); + print(localCam[0].getAttribute("pitch")); + </script> + <send target="#_umundo.pose" event="umundo.pose"> + <param name="type" expr="'SceneSetup'" /> + <content> +({ + 'camPose': { + 'euler': { + 'pitch': localCam.getAttribute("pitch"), + 'roll': localCam.getAttribute("roll"), + 'yaw': localCam.getAttribute("yaw"), + } + }, + 'modelPose': { + 'euler': { + 'pitch': localCam.getAttribute("pitch"), + 'roll': localCam.getAttribute("roll"), + 'yaw': localCam.getAttribute("yaw"), + } + }, + 'modelName': "foo", + 'bandName': "foo" +}) + </content> + </send> + </onentry> + </state> + </state> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/arabica/test-arabica-events.xml b/test/samples/uscxml/arabica/test-arabica-events.xml new file mode 100644 index 0000000..8998fd9 --- /dev/null +++ b/test/samples/uscxml/arabica/test-arabica-events.xml @@ -0,0 +1,10 @@ +<root> + <head> + <title></title> + </head> + <body> + <h1>This is Foo!</h1> + <p>This not supposed to be valid HTML</p> + <div id="container" /> + </body> +</root>
\ No newline at end of file diff --git a/test/samples/uscxml/proto/3DViewer/CameraPos.proto b/test/samples/uscxml/proto/3DViewer/CameraPos.proto new file mode 100644 index 0000000..6178ef4 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/CameraPos.proto @@ -0,0 +1,9 @@ +import "LinearAlgebra.proto"; + +message CameraPos { + required Vector3 center = 1; + required Quaternion rotation = 2; + required double distance = 3; + required double lastFrameTime = 4; + required bool thrown = 5 [default = false]; +}
\ No newline at end of file diff --git a/test/samples/uscxml/proto/3DViewer/DirectoryListingService.proto b/test/samples/uscxml/proto/3DViewer/DirectoryListingService.proto new file mode 100644 index 0000000..4a0e412 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/DirectoryListingService.proto @@ -0,0 +1,48 @@ +option java_package = "org.umundo.filesystem"; + +message DirectoryEntry { + enum Type { + NAMED_PIPE = 0; + CHAR_DEV = 1; + BLOCK_DEV = 2; + FILE = 3; + DIR = 4; + SYMLINK = 5; + SOCKET = 6; + UNKNOWN = 7; + } + required string name = 1; + required Type type = 2; + required string path = 3; + required int64 size = 4; + optional string extension = 5; + + repeated string segments = 6; + + optional int64 atime_ms = 11; + optional int64 ctime_ms = 12; + optional int64 mtime_ms = 13; + optional int64 btime_ms = 14; + + required string hostId = 15; + +} + +message DirectoryListingRequest { + required string pattern = 1; +} + +message DirectoryListingReply { + repeated DirectoryEntry entries = 1; +} + +message DirectoryEntryContent { + required bytes content = 1; + required string md5 = 2; +} + +service DirectoryListingService { + rpc list (DirectoryListingRequest) returns (DirectoryListingReply); + rpc get (DirectoryEntry) returns (DirectoryEntryContent); +} + diff --git a/test/samples/uscxml/proto/3DViewer/LinearAlgebra.proto b/test/samples/uscxml/proto/3DViewer/LinearAlgebra.proto new file mode 100644 index 0000000..135ed00 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/LinearAlgebra.proto @@ -0,0 +1,18 @@ +message Quaternion { + required double w = 1; + required double x = 2; + required double y = 3; + required double z = 4; +} + +message Vector3 { + required double x = 1 [default = 0]; + required double y = 2 [default = 0]; + required double z = 3 [default = 0]; +} + +message Matrix3 { + required Vector3 x = 1; + required Vector3 y = 2; + required Vector3 z = 3; +} diff --git a/test/samples/uscxml/proto/3DViewer/ModelInfo.proto b/test/samples/uscxml/proto/3DViewer/ModelInfo.proto new file mode 100644 index 0000000..3214a71 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/ModelInfo.proto @@ -0,0 +1,10 @@ +import "LinearAlgebra.proto"; + +message ModelInfo { + required string name = 1; + required string description = 2; +} + +message Annotation { + required Vector3 position = 1; +}
\ No newline at end of file diff --git a/test/samples/uscxml/proto/3DViewer/Pose.proto b/test/samples/uscxml/proto/3DViewer/Pose.proto new file mode 100644 index 0000000..c29d6ff --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/Pose.proto @@ -0,0 +1,22 @@ +import "LinearAlgebra.proto"; + +message EulerAngles { + required double pitch = 1 [default = 0]; + required double roll = 2 [default = 0]; + required double yaw = 3 [default = 0]; +} + +message Heading { + required Vector3 direction = 1; + optional double timestamp = 2; + optional double magneticHeading = 3; + optional double trueHeading = 4; +} + +message Pose { + optional Matrix3 orientation = 1; + optional EulerAngles euler = 2; + optional Vector3 position = 3; + optional Heading heading = 4; + optional double timestamp = 5; +} diff --git a/test/samples/uscxml/proto/3DViewer/SceneSetup.proto b/test/samples/uscxml/proto/3DViewer/SceneSetup.proto new file mode 100644 index 0000000..b3b7697 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/SceneSetup.proto @@ -0,0 +1,8 @@ +import "Pose.proto"; + +message SceneSetup { + optional Pose modelPose = 1; + optional Pose camPose = 2; + required string modelName = 3; + required string bandName = 4; +}
\ No newline at end of file diff --git a/test/samples/uscxml/proto/3DViewer/SceneShotService.proto b/test/samples/uscxml/proto/3DViewer/SceneShotService.proto new file mode 100644 index 0000000..c7412a3 --- /dev/null +++ b/test/samples/uscxml/proto/3DViewer/SceneShotService.proto @@ -0,0 +1,24 @@ +import "SceneSetup.proto"; + +message SceneShotReply { + optional bytes data = 1; + optional string base64 = 2; + optional string url = 3; + required uint32 width = 4; + required uint32 height = 5; +} + +message SceneShotRequest { + required uint32 width = 1 [default = 640]; + required uint32 height = 2 [default = 480]; + optional string format = 3 [default = "png"]; + optional string filename = 4; + optional SceneSetup sceneSetup = 5; + optional double pitch = 6; + optional double roll = 7; + optional double zoom = 8; +} + +service SceneShotService { + rpc sceneShot (SceneShotRequest) returns (SceneShotReply); +} diff --git a/test/samples/uscxml/scripts/test-simple-ecmascript.scxml b/test/samples/uscxml/scripts/test-simple-ecmascript.scxml new file mode 100644 index 0000000..10dee02 --- /dev/null +++ b/test/samples/uscxml/scripts/test-simple-ecmascript.scxml @@ -0,0 +1,12 @@ +<scxml datamodel="ecmascript"> + <state id="start"> + <onentry> + <script> + var nodeSet = document.evaluate("//state").asNodeSet(); + nodeSet[0].setAttribute("foo", "bar"); + </script> + <raise event="redo" /> + </onentry> + <transition target="start" event="redo" /> + </state> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/test-scenegraph.scxml b/test/samples/uscxml/test-scenegraph.scxml index 25e13ed..0efcd6d 100644 --- a/test/samples/uscxml/test-scenegraph.scxml +++ b/test/samples/uscxml/test-scenegraph.scxml @@ -1,5 +1,16 @@ -<scxml datamodel="ecmascript" initial="start" binding="late" xmlns:scenegraph="http://uscxml.tk.informatik.tu-darmstadt.de/scenegraph.xsd"> +<scxml datamodel="ecmascript" initial="start" binding="late" + xmlns="http://www.w3.org/2005/07/scxml" + xmlns:scenegraph="http://uscxml.tk.informatik.tu-darmstadt.de/scenegraph.xsd"> + <datamodel> + <data id="pitch">0</data> + <data id="yaw">0</data> + <data id="roll">0</data> + </datamodel> <state id="start"> + <invoke type="heartbeat"> + <param name="interval" expr="'10ms'" /> + <param name="eventname" expr="'heartbeat.20ms'" /> + </invoke> <invoke type="scenegraph"> <content> <scenegraph:display x="10%" y="10 %" width="50 % " height=" 50 % "> @@ -10,13 +21,8 @@ </scenegraph:translation> </scenegraph:scale> </scenegraph:viewport> - <scenegraph:viewport x="50%" y="0" width="50%" height="50%" id="scene2"> - <scenegraph:translation x="0" y="0" z="0"> - <scenegraph:node src="http://cs.iupui.edu/~aharris/mm/vrml4/house.wrl" /> - </scenegraph:translation> - </scenegraph:viewport> <scenegraph:viewport x="0" y="50%" width="50%" height="50%" id="scene3"> - <scenegraph:rotation pitch="100deg" roll="3.15149rad" yaw="10deg"> + <scenegraph:rotation id="treeRotation" pitch="100deg" roll="3.15149rad" yaw="10deg"> <scenegraph:node src="http://cs.iupui.edu/~aharris/webDesign/vrml/tree.wrl" /> </scenegraph:rotation> </scenegraph:viewport> @@ -25,17 +31,36 @@ <scenegraph:node src="scenegraph/HARD_MP_VAL_000.wrl" /> </scenegraph:translation> </scenegraph:viewport> + <scenegraph:viewport x="50%" y="0" width="50%" height="50%" id="scene2"> + <scenegraph:translation x="0" y="0" z="0"> + <scenegraph:node src="http://cs.iupui.edu/~aharris/mm/vrml4/house.wrl" /> + </scenegraph:translation> + </scenegraph:viewport> </scenegraph:display> - <!-- scenegraph:display x="20%" y="20 %" width="50 % " height=" 50 % "> - <scenegraph:viewport x="0" y="0" width="50%" height="50%" id="scene1"> + <scenegraph:display x="20%" y="20 %" width="50 % " height=" 50 % "> + <scenegraph:viewport x="0" y="0" width="100%" height="100%" id="scene1"> <scenegraph:translation x="0" y="0" z="0"> <scenegraph:node src="scenegraph/HARD_MP_VAL_000.wrl" /> </scenegraph:translation> </scenegraph:viewport> - </scenegraph:display --> + </scenegraph:display> </content> </invoke> + <state id="animate"> + <onentry> + <script> + var nodeSet = document.evaluate("//scenegraph:rotation[@id='treeRotation']").asNodeSet(); + nodeSet[0].setAttribute("pitch", "pitch" + pitch + "deg"); + nodeSet[0].setAttribute("roll", "roll" + roll + "deg"); + nodeSet[0].setAttribute("yaw", "yaw" + yaw + "deg"); + pitch += 0.5; + roll += 0.3; + yaw += 0.1; + </script> + </onentry> + <transition event="heartbeat.20ms" target="animate" /> + </state> </state> <final id="final"> <onentry> diff --git a/test/src/test-arabica-events.cpp b/test/src/test-arabica-events.cpp new file mode 100644 index 0000000..fcf4ea8 --- /dev/null +++ b/test/src/test-arabica-events.cpp @@ -0,0 +1,61 @@ +#include <XPath/XPath.hpp> +#include <DOM/Document.hpp> +#include <DOM/SAX2DOM/SAX2DOM.hpp> +#include <SAX/helpers/CatchErrorHandler.hpp> +#include <DOM/Events/EventTarget.hpp> +#include <DOM/Events/EventListener.hpp> + +using namespace Arabica::DOM; + +class CapturingEventListener : public Events::EventListener<std::string> { +public: + void handleEvent(Events::Event<std::string>& event) { + std::cout << "Handling captured event " << event.getType() << std::endl; + } +}; + +class BubblingEventListener : public Events::EventListener<std::string> { +public: + void handleEvent(Events::Event<std::string>& event) { + std::cout << "Handling bubbling event " << event.getType() << std::endl; + } +}; + +int main(int argc, char** argv) { + Arabica::SAX::InputSource<std::string> inputSource(argv[1]); + + Arabica::SAX2DOM::Parser<std::string> domParser; + Arabica::SAX::CatchErrorHandler<std::string> errorHandler; + domParser.setErrorHandler(errorHandler); + if(!domParser.parse(inputSource)) { + return -1; + } + Document<std::string> doc = domParser.getDocument(); + Element<std::string> elem = doc.getDocumentElement(); + + CapturingEventListener cel; + BubblingEventListener bel; + + Events::EventTarget<std::string> eventTarget(elem); + eventTarget.addEventListener("DOMNodeInserted", cel, true); + eventTarget.addEventListener("DOMNodeInserted", bel, false); + eventTarget.addEventListener("DOMNodeRemoved", cel, true); + eventTarget.addEventListener("DOMNodeRemoved", bel, false); + eventTarget.addEventListener("DOMAttrModified", cel, true); + eventTarget.addEventListener("DOMAttrModified", bel, false); + + Arabica::XPath::XPath<std::string> xpath; + Arabica::XPath::NodeSet<std::string> divs = xpath.evaluate("//div", doc).asNodeSet(); + + for (int i = 0; i < divs.size(); i++) { + Element<std::string> divElem = Element<std::string>(divs[i]); + divElem.setAttribute("foo", "true"); + divElem.setAttribute("foo", "false"); + + Element<std::string> fooElem = divElem.getOwnerDocument().createElement("foo"); + divElem.appendChild(fooElem); + divElem.removeChild(fooElem); + } + + +}
\ No newline at end of file |