summaryrefslogtreecommitdiffstats
path: root/test/src/test-arabica-events.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-01-10 22:42:42 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-01-10 22:42:42 (GMT)
commit7aa7095d17a180d663cd9647c31d99d97c1dca4f (patch)
tree460bc3a67f0adc3199bec9f22ee15a102263eb4c /test/src/test-arabica-events.cpp
parentda1032ffbff229ce2ca9a83d47522ff45c90ba23 (diff)
downloaduscxml-7aa7095d17a180d663cd9647c31d99d97c1dca4f.zip
uscxml-7aa7095d17a180d663cd9647c31d99d97c1dca4f.tar.gz
uscxml-7aa7095d17a180d663cd9647c31d99d97c1dca4f.tar.bz2
Major changes - see details
- Dynamic SceneGraph ML - V8 DOM for ecmascript datamodel - New heartbeat invoker - Fixed various bugs
Diffstat (limited to 'test/src/test-arabica-events.cpp')
-rw-r--r--test/src/test-arabica-events.cpp61
1 files changed, 61 insertions, 0 deletions
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