From 2e6c3729334fea6cc0ab9dee4bdd51332dca4534 Mon Sep 17 00:00:00 2001 From: jez <> Date: Sat, 22 Dec 2007 22:21:26 +0000 Subject: [PATCH] hacked up a ncname test, although it's not working at the moment and I'm tired and can't think --- include/SAX/wrappers/saxlibxml2.hpp | 7 ++- include/XML/strings.hpp | 41 ++++++++++++++ include/XPath/impl/xpath_match_rewrite.hpp | 7 ++- include/XPath/impl/xpath_node_test.hpp | 30 +++++----- include/XPath/impl/xpath_parser.hpp | 2 +- .../XSLT/impl/xslt_processing_instruction.hpp | 4 ++ tests/Utils/test_xml_strings.hpp | 56 +++++++++++++++++++ tests/Utils/util_test_suite.hpp | 2 + tests/XSLT/main.cpp | 10 ++-- tests/XSLT/xslt_test.cpp | 6 +- 10 files changed, 136 insertions(+), 29 deletions(-) create mode 100755 include/XML/strings.hpp create mode 100755 tests/Utils/test_xml_strings.hpp diff --git a/include/SAX/wrappers/saxlibxml2.hpp b/include/SAX/wrappers/saxlibxml2.hpp index 2fcb95b7..9b61b04e 100644 --- a/include/SAX/wrappers/saxlibxml2.hpp +++ b/include/SAX/wrappers/saxlibxml2.hpp @@ -126,6 +126,7 @@ class libxml2_wrapper : public XMLReaderInterface, typedef SAX::DTDHandler dtdHandlerT; typedef SAX::ContentHandler contentHandlerT; typedef SAX::Attributes attributesT; + typedef SAX::AttributeType attributeTypeT; typedef SAX::DeclHandler declHandlerT; typedef SAX::LexicalHandler lexicalHandlerT; typedef SAX::InputSource inputSourceT; @@ -568,7 +569,7 @@ void libxml2_wrapper::SAXstartElement(const xmlChar* qName, attributes.addAttribute(emptyString_, emptyString_, attQName, - attributesT::Type::CDATA, + attributeTypeT::CDATA, value); } } // while @@ -585,7 +586,7 @@ void libxml2_wrapper::SAXstartElement(const xmlChar* qName, attributes.addAttribute(attName.URI, attName.localName, attName.rawName, - attributesT::Type::CDATA, + attributeTypeT::CDATA, value); } } // while ... @@ -611,7 +612,7 @@ void libxml2_wrapper::SAXstartElementNoNS(const xmlChar* qN attributes.addAttribute(emptyString_, emptyString_, attQName, - attributesT::Type::CDATA, + attributeTypeT::CDATA, value); } // while .. } // if ... diff --git a/include/XML/strings.hpp b/include/XML/strings.hpp new file mode 100755 index 00000000..e9296245 --- /dev/null +++ b/include/XML/strings.hpp @@ -0,0 +1,41 @@ +#ifndef ARABICA_XML_STRINGS_HPP +#define ARABICA_XML_STRINGS_HPP + +#include +#include + +namespace Arabica +{ +namespace XML +{ + + bool is_ncname(const std::string& str) + { + using namespace Arabica::text; + + std::string::const_iterator s = str.begin(); + if(!(is_letter(*s) || (*s == Unicode::LOW_LINE))) + return false; + + ++s; + for(std::string::const_iterator se; s != se; ++s) + { + wchar_t c = static_cast(*s); + if(!(is_letter(c) || + is_digit(c) || + (c == Unicode::FULL_STOP) || + (c == Unicode::HYPHEN_MINUS) || + (c == Unicode::LOW_LINE) || + (c == Unicode::COLON) || + is_combining_char(c) || + is_extender(c))) + return false; + } + return true; + } // is_ncname + +} // namespace XML +} // namespace Arabica + + +#endif diff --git a/include/XPath/impl/xpath_match_rewrite.hpp b/include/XPath/impl/xpath_match_rewrite.hpp index a523621b..d27ebe3e 100755 --- a/include/XPath/impl/xpath_match_rewrite.hpp +++ b/include/XPath/impl/xpath_match_rewrite.hpp @@ -51,7 +51,8 @@ namespace impl virtual void scan(const XPathExpression_impl* const expr) { - const FunctionHolder* const fn = dynamic_cast* const>(expr); + typedef FunctionHolder FH; + const FH* const fn = dynamic_cast(expr); if(fn == 0) return; @@ -98,7 +99,7 @@ MatchExpr::MatchExpr(XPathExpression_impl(match); // foreach step in the steplist StepList& steps = path->steps_; - for(StepList::const_iterator s = steps.begin(), se = steps.end(); s != se; ++s) + for(typename StepList::const_iterator s = steps.begin(), se = steps.end(); s != se; ++s) { // foreach predicate in the predicatelist Step* step = dynamic_cast(*s); @@ -106,7 +107,7 @@ MatchExpr::MatchExpr(XPathExpression_implpredicates_; - for(Predicates::iterator p = predicates.begin(), pe = predicates.end(); p != pe; ++p) + for(typename Predicates::iterator p = predicates.begin(), pe = predicates.end(); p != pe; ++p) { // should rewrite? Expression* pred = *p; diff --git a/include/XPath/impl/xpath_node_test.hpp b/include/XPath/impl/xpath_node_test.hpp index b9772703..06fcaa96 100644 --- a/include/XPath/impl/xpath_node_test.hpp +++ b/include/XPath/impl/xpath_node_test.hpp @@ -32,7 +32,7 @@ template class AnyNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new AnyNodeTest(); } + virtual NodeTest* clone() const { return new AnyNodeTest(); } virtual bool operator()(const DOM::Node& node) const { return true; @@ -43,7 +43,7 @@ template class NodeNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new NodeNodeTest(); } + virtual NodeTest* clone() const { return new NodeNodeTest(); } virtual bool operator()(const DOM::Node& node) const { int type = node.getNodeType(); @@ -59,7 +59,7 @@ class NameNodeTest : public NodeTest { public: NameNodeTest(const string_type& name) : name_(name) { } - virtual NodeTest* clone() const { return new NameNodeTest(name_); } + virtual NodeTest* clone() const { return new NameNodeTest(name_); } virtual bool operator()(const DOM::Node& node) const { @@ -78,7 +78,7 @@ class AttributeNameNodeTest : public NodeTest { public: AttributeNameNodeTest(const string_type& name) : name_(name) { } - virtual NodeTest* clone() const { return new AttributeNameNodeTest(name_); } + virtual NodeTest* clone() const { return new AttributeNameNodeTest(name_); } virtual bool operator()(const DOM::Node& node) const { @@ -97,7 +97,7 @@ class QNameNodeTest : public NodeTest public: QNameNodeTest(const string_type& namespace_uri, const string_type& name) : uri_(namespace_uri), name_(name) { } - virtual NodeTest* clone() const { return new QNameNodeTest(uri_, name_); } + virtual NodeTest* clone() const { return new QNameNodeTest(uri_, name_); } virtual bool operator()(const DOM::Node& node) const { @@ -118,7 +118,7 @@ class AttributeQNameNodeTest : public NodeTest public: AttributeQNameNodeTest(const string_type& namespace_uri, const string_type& name) : uri_(namespace_uri), name_(name) { } - virtual NodeTest* clone() const { return new AttributeQNameNodeTest(uri_, name_); } + virtual NodeTest* clone() const { return new AttributeQNameNodeTest(uri_, name_); } virtual bool operator()(const DOM::Node& node) const { @@ -136,7 +136,7 @@ template class StarNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new StarNodeTest(); } + virtual NodeTest* clone() const { return new StarNodeTest(); } virtual bool operator()(const DOM::Node& node) const { @@ -152,7 +152,7 @@ class QStarNodeTest : public StarNodeTest typedef StarNodeTest baseT; public: QStarNodeTest(const string_type& namespace_uri) : baseT(), uri_(namespace_uri) { } - virtual NodeTest* clone() const { return new QStarNodeTest(uri_); } + virtual NodeTest* clone() const { return new QStarNodeTest(uri_); } virtual bool operator()(const DOM::Node& node) const { @@ -168,7 +168,7 @@ template class TextNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new TextNodeTest(); } + virtual NodeTest* clone() const { return new TextNodeTest(); } virtual bool operator()(const DOM::Node& node) const { @@ -180,7 +180,7 @@ template class CommentNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new CommentNodeTest(); } + virtual NodeTest* clone() const { return new CommentNodeTest(); } virtual bool operator()(const DOM::Node& node) const { @@ -192,7 +192,7 @@ template class AttributeNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new AttributeNodeTest(); } + virtual NodeTest* clone() const { return new AttributeNodeTest(); } virtual bool operator()(const DOM::Node& node) const { @@ -206,7 +206,7 @@ class AttributeQStarNodeTest : public AttributeNodeTest baseT; public: AttributeQStarNodeTest(const string_type& namespace_uri) : baseT(), uri_(namespace_uri) { } - virtual NodeTest* clone() const { return new AttributeQStarNodeTest(uri_); } + virtual NodeTest* clone() const { return new AttributeQStarNodeTest(uri_); } virtual bool operator()(const DOM::Node& node) const { @@ -223,7 +223,7 @@ template class NotAttributeNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new NotAttributeNodeTest(); } + virtual NodeTest* clone() const { return new NotAttributeNodeTest(); } virtual bool operator()(const DOM::Node& node) const { @@ -237,7 +237,7 @@ class ProcessingInstructionNodeTest : public NodeTest* clone() const { return new ProcessingInstructionNodeTest(target_); } virtual bool operator()(const DOM::Node& node) const { @@ -258,7 +258,7 @@ template class RootNodeTest : public NodeTest { public: - virtual NodeTest* clone() const { return new RootNodeTest(); } + virtual NodeTest* clone() const { return new RootNodeTest(); } virtual bool operator()(const DOM::Node& node) const { diff --git a/include/XPath/impl/xpath_parser.hpp b/include/XPath/impl/xpath_parser.hpp index 295fe712..d0f30e1d 100644 --- a/include/XPath/impl/xpath_parser.hpp +++ b/include/XPath/impl/xpath_parser.hpp @@ -505,11 +505,11 @@ private: #include "xpath_relational.hpp" #include "xpath_logical.hpp" #include "xpath_step.hpp" -#include "xpath_match_rewrite.hpp" #include "xpath_compile_context.hpp" #include "xpath_variable.hpp" #include "xpath_function_holder.hpp" #include "xpath_union.hpp" +#include "xpath_match_rewrite.hpp" namespace Arabica { diff --git a/include/XSLT/impl/xslt_processing_instruction.hpp b/include/XSLT/impl/xslt_processing_instruction.hpp index 3965d1f7..5b07d08c 100755 --- a/include/XSLT/impl/xslt_processing_instruction.hpp +++ b/include/XSLT/impl/xslt_processing_instruction.hpp @@ -1,6 +1,7 @@ #ifndef ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP #define ARABICA_XSLT_PROCESSING_INSTRUCTION_HPP +#include #include #include "xslt_item.hpp" @@ -35,6 +36,9 @@ private: if(name.empty()) throw SAX::SAXException("xsl:processing-instruction : name attribute must evaluate to a valid name"); + if(!Arabica::XML::is_ncname(name)) + throw SAX::SAXException("xsl:processing-instruction : '" + name + "' is not valid as the name"); + if(name.length() != 3) return; diff --git a/tests/Utils/test_xml_strings.hpp b/tests/Utils/test_xml_strings.hpp new file mode 100755 index 00000000..9ecda0d2 --- /dev/null +++ b/tests/Utils/test_xml_strings.hpp @@ -0,0 +1,56 @@ +#ifndef UTILS_XML_STRINGS_HPP +#define UTILS_XML_STRINGS_HPP + +#include + +using namespace Arabica::XML; + +class XMLStringTest : public TestCase +{ +public: + XMLStringTest(std::string name) : + TestCase(name) + { + } // XMLStringTest + + void test1() + { + assertTrue(is_ncname("woo")); + } // test1 + + void test2() + { + assertTrue(is_ncname("WOO")); + } // test2 + + void test3() + { + assertFalse(is_ncname("???")); + } // test3 + + void test4() + { + assertTrue("a:b"); + } // test4 + + void test5() + { + assertFalse(":b"); + } // test5 + +}; // class XMLStringTest + +TestSuite* XMLStringTest_suite() +{ + TestSuite* suiteOfTests = new TestSuite(); + + suiteOfTests->addTest(new TestCaller("test1", &XMLStringTest::test1)); + suiteOfTests->addTest(new TestCaller("test2", &XMLStringTest::test2)); + suiteOfTests->addTest(new TestCaller("test3", &XMLStringTest::test3)); + suiteOfTests->addTest(new TestCaller("test4", &XMLStringTest::test4)); + suiteOfTests->addTest(new TestCaller("test5", &XMLStringTest::test5)); + + return suiteOfTests; +} // XMLStringTest_suite + +#endif diff --git a/tests/Utils/util_test_suite.hpp b/tests/Utils/util_test_suite.hpp index fb209643..1f03c211 100644 --- a/tests/Utils/util_test_suite.hpp +++ b/tests/Utils/util_test_suite.hpp @@ -8,6 +8,7 @@ #include "test_normalize_whitespace.hpp" #include "test_base64.hpp" #include "test_uri.hpp" +#include "test_xml_strings.hpp" template bool Util_test_suite(int argc, const char** argv) @@ -17,6 +18,7 @@ bool Util_test_suite(int argc, const char** argv) runner.addTest("NormalizeWhitespaceTest", NormalizeWhitespaceTest_suite()); runner.addTest("Base64Test", Base64Test_suite()); runner.addTest("URITest", URITest_suite()); + runner.addTest("XMLString", XMLStringTest_suite()); return runner.run(argc, argv); } // main diff --git a/tests/XSLT/main.cpp b/tests/XSLT/main.cpp index f69d56d7..5da9d7ae 100755 --- a/tests/XSLT/main.cpp +++ b/tests/XSLT/main.cpp @@ -15,11 +15,6 @@ // #include "scope_test.hpp" #include "xslt_test.hpp" -/* -typedef std::string string_type; -typedef Arabica::default_string_adaptor string_adaptor; -*/ - int main(int argc, const char* argv[]) { TestRunner runner; @@ -27,6 +22,7 @@ int main(int argc, const char* argv[]) // runner.addTest("ScopeTest", ScopeTest_suite()); // Xalan supplied test cases +/* //runner.addTest("attribset", XSLTTest_suite("attribset")); runner.addTest("attribvaltemplate", XSLTTest_suite("attribvaltemplate")); runner.addTest("axes", XSLTTest_suite("axes")); @@ -88,7 +84,9 @@ int main(int argc, const char* argv[]) //runner.addTest("Namespace_XPath", XSLTTest_suite("Namespace_XPath")); //runner.addTest("Number", XSLTTest_suite("Number")); //runner.addTest("Output", XSLTTest_suite("Output")); + */ runner.addTest("ProcessingInstruction", XSLTTest_suite("ProcessingInstruction")); +/* //runner.addTest("RTF", XSLTTest_suite("RTF")); runner.addTest("Sorting", XSLTTest_suite("Sorting")); //runner.addTest("Stylesheet", XSLTTest_suite("Stylesheet")); @@ -98,7 +96,7 @@ int main(int argc, const char* argv[]) //runner.addTest("Variables", XSLTTest_suite("Variables")); //runner.addTest("Whitespaces", XSLTTest_suite("Whitespaces")); //runner.addTest("XSLTFunctions", XSLTTest_suite("XSLTFunctions")); - + */ runner.addTest("ArabicaErrors", ArabicaTest_suite("errors")); runner.addTest("ArabicaInclude", ArabicaTest_suite("include")); runner.addTest("ArabicaProcessingInstruction", ArabicaTest_suite("processing-instruction")); diff --git a/tests/XSLT/xslt_test.cpp b/tests/XSLT/xslt_test.cpp index f4dfec0f..f470a1e9 100755 --- a/tests/XSLT/xslt_test.cpp +++ b/tests/XSLT/xslt_test.cpp @@ -531,8 +531,11 @@ protected: class Expected { public: - Expected() + Expected() { } + + void load() { + std::cout << "Loaded expected fails" << std::endl; Arabica::DOM::Document fail_doc = buildDOM(PATH_PREFIX + "arabica-expected-fails.xml"); Arabica::XPath::NodeSet failcases = selectNodes("/test-suite/test-case", fail_doc); for(int i = 0; i != failcases.size(); ++i) @@ -579,6 +582,7 @@ Arabica::DOM::Document loadCatalog(const std::string& catalog_filen c = buildDOM(PATH_PREFIX + catalog_filename); catalogs[catalog_filename] = c; std::cout << "Loaded " << catalog_filename << std::endl; + expected.load(); } // if(c == 0) return c;