diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-12 11:57:08 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-12 11:57:08 (GMT) |
commit | ba050afaaad699e60ca657b311d5c34d038bb89c (patch) | |
tree | d4c79e30631c63e8557c6ec893a70dda46aa6cd5 /test/src | |
parent | 45ab2909e17f7e0348ccfe4179f23a897a2fd305 (diff) | |
download | uscxml-ba050afaaad699e60ca657b311d5c34d038bb89c.zip uscxml-ba050afaaad699e60ca657b311d5c34d038bb89c.tar.gz uscxml-ba050afaaad699e60ca657b311d5c34d038bb89c.tar.bz2 |
Refactoring for other datamodels
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-arabica-xpath.cpp | 196 |
1 files changed, 95 insertions, 101 deletions
diff --git a/test/src/test-arabica-xpath.cpp b/test/src/test-arabica-xpath.cpp index 2bcf605..2991dc0 100644 --- a/test/src/test-arabica-xpath.cpp +++ b/test/src/test-arabica-xpath.cpp @@ -9,28 +9,25 @@ typedef string_adaptor SA; -class NodeSetVariableResolver : public Arabica::XPath::VariableResolver<string_type, string_adaptor> -{ - //typedef string_adaptorstring_adaptor; +class NodeSetVariableResolver : public Arabica::XPath::VariableResolver<string_type, string_adaptor> { + //typedef string_adaptorstring_adaptor; public: - virtual Arabica::XPath::XPathValue<string_type, string_adaptor> resolveVariable(const string_type& /* namepace_uri */, - const string_type& name) const - { - using namespace Arabica::XPath; - typename VarMap::const_iterator n = map_.find(name); - if(n == map_.end()) - throw UnboundVariableException(string_adaptor::asStdString(name)); - return XPathValue<string_type, string_adaptor>(new NodeSetValue<string_type, string_adaptor>((*n).second)); - } // resolveVariable - - void setVariable(const string_type& name, const Arabica::XPath::NodeSet<string_type, string_adaptor>& value) - { - map_[name] = value; - } // setVariable - + virtual Arabica::XPath::XPathValue<string_type, string_adaptor> resolveVariable(const string_type& /* namepace_uri */, + const string_type& name) const { + using namespace Arabica::XPath; + typename VarMap::const_iterator n = map_.find(name); + if(n == map_.end()) + throw UnboundVariableException(string_adaptor::asStdString(name)); + return XPathValue<string_type, string_adaptor>(new NodeSetValue<string_type, string_adaptor>((*n).second)); + } // resolveVariable + + void setVariable(const string_type& name, const Arabica::XPath::NodeSet<string_type, string_adaptor>& value) { + map_[name] = value; + } // setVariable + private: - typedef std::map<string_type, Arabica::XPath::NodeSet<string_type, string_adaptor> > VarMap; - VarMap map_; + typedef std::map<string_type, Arabica::XPath::NodeSet<string_type, string_adaptor> > VarMap; + VarMap map_; }; // class NodeSetVariableResolver Arabica::XPath::XPath<string_type, string_adaptor> parser; @@ -50,49 +47,46 @@ Arabica::DOM::ProcessingInstruction<string_type, string_adaptor> processingInstr Arabica::DOM::Document<string_type, string_adaptor> chapters_; Arabica::DOM::Document<string_type, string_adaptor> numbers_; -class StringVariableResolver : public Arabica::XPath::VariableResolver<string_type, string_adaptor> -{ +class StringVariableResolver : public Arabica::XPath::VariableResolver<string_type, string_adaptor> { public: - virtual Arabica::XPath::XPathValue<string_type, string_adaptor> resolveVariable(const string_type& /* namespace_uri */, - const string_type& name) const - { - using namespace Arabica::XPath; - typename VarMap::const_iterator n = map_.find(name); - if(n == map_.end()) - throw UnboundVariableException(string_adaptor::asStdString(name)); - return XPathValue<string_type, string_adaptor>(new StringValue<string_type, string_adaptor>((*n).second)); - } // resolveVariable - - void setVariable(const string_type& name, const string_type& value) - { - map_[name] = value; - } // setVariable - + virtual Arabica::XPath::XPathValue<string_type, string_adaptor> resolveVariable(const string_type& /* namespace_uri */, + const string_type& name) const { + using namespace Arabica::XPath; + typename VarMap::const_iterator n = map_.find(name); + if(n == map_.end()) + throw UnboundVariableException(string_adaptor::asStdString(name)); + return XPathValue<string_type, string_adaptor>(new StringValue<string_type, string_adaptor>((*n).second)); + } // resolveVariable + + void setVariable(const string_type& name, const string_type& value) { + map_[name] = value; + } // setVariable + private: - typedef std::map<string_type, string_type> VarMap; - VarMap map_; + typedef std::map<string_type, string_type> VarMap; + VarMap map_; }; // StringVariableResolver int main(int argc, char** argv) { - + factory_ = Arabica::SimpleDOM::DOMImplementation<string_type, string_adaptor>::getDOMImplementation(); document_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); root_ = document_.createElement("root"); document_.appendChild(root_); assert(root_); - + element1_ = document_.createElement(SA::construct_from_utf8("child1")); element2_ = document_.createElement(SA::construct_from_utf8("child2")); element3_ = document_.createElement(SA::construct_from_utf8("child3")); - + element1_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1")); - + element2_.setAttribute(SA::construct_from_utf8("one"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("two"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("three"), SA::construct_from_utf8("1")); element2_.setAttribute(SA::construct_from_utf8("four"), SA::construct_from_utf8("1")); - + text_ = document_.createTextNode(SA::construct_from_utf8("data")); comment_ = document_.createComment(SA::construct_from_utf8("comment")); processingInstruction_ = document_.createProcessingInstruction(SA::construct_from_utf8("target"), SA::construct_from_utf8("data")); @@ -101,13 +95,13 @@ int main(int argc, char** argv) { element2_.appendChild(spinkle_); element2_.appendChild(comment_); element2_.appendChild(processingInstruction_); - + attr_ = element1_.getAttributeNode(SA::construct_from_utf8("one")); - + root_.appendChild(element1_); root_.appendChild(element2_); root_.appendChild(element3_); - + chapters_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); chapters_.appendChild(chapters_.createElement(SA::construct_from_utf8("document"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("one"))); @@ -115,7 +109,7 @@ int main(int argc, char** argv) { chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("three"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("four"))); chapters_.getFirstChild().appendChild(chapters_.createElement(SA::construct_from_utf8("chapter"))).appendChild(chapters_.createTextNode(SA::construct_from_utf8("five"))); - + numbers_ = factory_.createDocument(SA::construct_from_utf8(""), SA::construct_from_utf8(""), 0); numbers_.appendChild(numbers_.createElement(SA::construct_from_utf8("doc"))); numbers_.getFirstChild().appendChild(numbers_.createElement(SA::construct_from_utf8("number"))).appendChild(numbers_.createTextNode(SA::construct_from_utf8("1"))); @@ -131,68 +125,68 @@ int main(int argc, char** argv) { std::cout << numbers_ << std::endl; std::cout << chapters_ << std::endl; - + if (false) { - using namespace Arabica::XPath; - StringVariableResolver svr; - svr.setVariable(SA::construct_from_utf8("index"), SA::construct_from_utf8("1")); - - parser.setVariableResolver(svr); - XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("/root/*[@two = $index]"), document_); - assert(NODE_SET == result.type()); - assert(element2_ == result.asNodeSet()[0]); - - parser.resetVariableResolver(); - } // test18 + using namespace Arabica::XPath; + StringVariableResolver svr; + svr.setVariable(SA::construct_from_utf8("index"), SA::construct_from_utf8("1")); + + parser.setVariableResolver(svr); + XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("/root/*[@two = $index]"), document_); + assert(NODE_SET == result.type()); + assert(element2_ == result.asNodeSet()[0]); + + parser.resetVariableResolver(); + } // test18 if (false) { - using namespace Arabica::XPath; - XPathExpression<string_type, string_adaptor> xpath = parser.compile(SA::construct_from_utf8("root/*[position() = 2]")); - XPathValue<string_type, string_adaptor> result = xpath.evaluate(document_); - - assert(NODE_SET == result.type()); - assert(1 == result.asNodeSet().size()); - Arabica::DOM::Node<string_type, string_adaptor> n = result.asNodeSet()[0]; - assert(element2_ == n); - } // test19 + using namespace Arabica::XPath; + XPathExpression<string_type, string_adaptor> xpath = parser.compile(SA::construct_from_utf8("root/*[position() = 2]")); + XPathValue<string_type, string_adaptor> result = xpath.evaluate(document_); + + assert(NODE_SET == result.type()); + assert(1 == result.asNodeSet().size()); + Arabica::DOM::Node<string_type, string_adaptor> n = result.asNodeSet()[0]; + assert(element2_ == n); + } // test19 if (false) { - using namespace Arabica::XPath; - Arabica::DOM::DocumentFragment<string_type, string_adaptor> frag = document_.createDocumentFragment(); - frag.appendChild(document_.createElement(SA::construct_from_utf8("foo"))); - - NodeSetVariableResolver svr; - NodeSet<string_type, string_adaptor> ns; - ns.push_back(frag); - svr.setVariable(SA::construct_from_utf8("fruit"), ns); - parser.setVariableResolver(svr); - - XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("$fruit/foo|/root/child3"), document_); - assert(NODE_SET == result.type()); - assert(2 == result.asNodeSet().size()); - assert(element3_ == result.asNodeSet()[0]); - } // testUnion11 + using namespace Arabica::XPath; + Arabica::DOM::DocumentFragment<string_type, string_adaptor> frag = document_.createDocumentFragment(); + frag.appendChild(document_.createElement(SA::construct_from_utf8("foo"))); + + NodeSetVariableResolver svr; + NodeSet<string_type, string_adaptor> ns; + ns.push_back(frag); + svr.setVariable(SA::construct_from_utf8("fruit"), ns); + parser.setVariableResolver(svr); + + XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("$fruit/foo|/root/child3"), document_); + assert(NODE_SET == result.type()); + assert(2 == result.asNodeSet().size()); + assert(element3_ == result.asNodeSet()[0]); + } // testUnion11 if (false) { - using namespace Arabica::XPath; - XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("local-name(/root)"), document_); - assert(STRING == result.type()); - assert(SA::construct_from_utf8("root") == result.asString()); - } // testLocalNameFn1 + using namespace Arabica::XPath; + XPathValue<string_type, string_adaptor> result = parser.evaluate_expr(SA::construct_from_utf8("local-name(/root)"), document_); + assert(STRING == result.type()); + assert(SA::construct_from_utf8("root") == result.asString()); + } // testLocalNameFn1 { - using namespace Arabica::XPath; - Arabica::DOM::DocumentFragment<std::string> frag = document_.createDocumentFragment(); - frag.appendChild(document_.createElement("foo")); - - NodeSetVariableResolver svr; - NodeSet<string_type, string_adaptor> ns; - ns.push_back(frag); - svr.setVariable("fruit", ns); - parser.setVariableResolver(svr); - - XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("local-name($fruit/foo) = 'foo'"), document_); + using namespace Arabica::XPath; + Arabica::DOM::DocumentFragment<std::string> frag = document_.createDocumentFragment(); + frag.appendChild(document_.createElement("foo")); + + NodeSetVariableResolver svr; + NodeSet<string_type, string_adaptor> ns; + ns.push_back(frag); + svr.setVariable("fruit", ns); + parser.setVariableResolver(svr); + + XPathValue<string_type, string_adaptor> result = parser.evaluate(SA::construct_from_utf8("local-name($fruit/foo) = 'foo'"), document_); std::cout << result.asBool() << std::endl; - } + } }
\ No newline at end of file |