summaryrefslogtreecommitdiff
path: root/libxsd/tests/cxx/tree/basic
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-12-18 18:48:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2021-01-13 22:32:43 +0300
commit2615896faa646e5830abf2c269150e1165c66515 (patch)
tree7d95978ec0a83094c9462ed4e1f59d42f4ff8ddb /libxsd/tests/cxx/tree/basic
parent7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff)
Switch to build2
Diffstat (limited to 'libxsd/tests/cxx/tree/basic')
-rw-r--r--libxsd/tests/cxx/tree/basic/buildfile6
-rw-r--r--libxsd/tests/cxx/tree/basic/driver.cxx61
-rw-r--r--libxsd/tests/cxx/tree/basic/testscript73
3 files changed, 140 insertions, 0 deletions
diff --git a/libxsd/tests/cxx/tree/basic/buildfile b/libxsd/tests/cxx/tree/basic/buildfile
new file mode 100644
index 0000000..7ab3a95
--- /dev/null
+++ b/libxsd/tests/cxx/tree/basic/buildfile
@@ -0,0 +1,6 @@
+# file : tests/cxx/tree/basic/buildfile
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+import libs = libxsd%lib{xsd}
+
+exe{driver}: {hxx cxx}{*} $libs testscript
diff --git a/libxsd/tests/cxx/tree/basic/driver.cxx b/libxsd/tests/cxx/tree/basic/driver.cxx
new file mode 100644
index 0000000..9ec6fd6
--- /dev/null
+++ b/libxsd/tests/cxx/tree/basic/driver.cxx
@@ -0,0 +1,61 @@
+// file : tests/cxx/tree/basic/driver.cxx
+// copyright : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+//#include <memory> // std::auto_ptr/unique_ptr
+#include <cassert>
+#include <iostream>
+
+#include <xercesc/dom/DOMText.hpp>
+#include <xercesc/dom/DOMElement.hpp>
+#include <xercesc/dom/DOMDocument.hpp>
+
+// Define XSD_CXX11 since we include libxsd headers directly.
+//
+#ifdef _MSC_VER
+# if _MSC_VER >= 1600 // VC++10 and later have C++11 always enabled.
+# define XSD_CXX11
+# endif
+#else
+# if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
+# define XSD_CXX11
+# endif
+#endif
+
+#include <libxsd/cxx/xml/qualified-name.hxx>
+
+#include <libxsd/cxx/xml/dom/auto-ptr.hxx> // XSD_DOM_AUTO_PTR
+#include <libxsd/cxx/xml/dom/elements.hxx> // name()
+#include <libxsd/cxx/xml/dom/parsing-source.hxx> // parser, parse()
+
+#include <libxsd/cxx/tree/text.hxx> // text_content()
+#include <libxsd/cxx/tree/parsing.hxx>
+#include <libxsd/cxx/tree/elements.hxx> // auto_initializer, properties
+#include <libxsd/cxx/tree/exceptions.hxx> // parsing
+#include <libxsd/cxx/tree/error-handler.hxx>
+
+using namespace std;
+using namespace xsd::cxx;
+
+int
+main (int argc, char* argv[])
+{
+ assert (argc == 2);
+
+ xml::auto_initializer ai;
+
+ tree::error_handler<char> h;
+ tree::properties<char> ps;
+
+ XSD_DOM_AUTO_PTR<xercesc::DOMDocument> d (
+ xml::dom::parse<char> (argv[1], h, ps, 0 /* flags */));
+
+ h.throw_if_failed<tree::parsing<char>> (); // Abort on error.
+
+ xml::dom::parser<char> p (*d->getDocumentElement (), true, false, false);
+ for (; p.more_content (); p.next_content (false /* text */))
+ {
+ const xercesc::DOMElement& i (p.cur_element ());
+ const xml::qualified_name<char> n (xml::dom::name<char> (i));
+ cout << n.name () << ' ' << tree::text_content<char> (i) << endl;
+ }
+}
diff --git a/libxsd/tests/cxx/tree/basic/testscript b/libxsd/tests/cxx/tree/basic/testscript
new file mode 100644
index 0000000..e903f1c
--- /dev/null
+++ b/libxsd/tests/cxx/tree/basic/testscript
@@ -0,0 +1,73 @@
+# file : tests/cxx/tree/basic/testscript
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+: basic
+:
+{
+ cat <<EOI >=hello.xsd;
+ <?xml version="1.0"?>
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:complexType name="hello_t">
+
+ <xsd:annotation>
+ <xsd:documentation>
+ The hello_t type consists of a greeting phrase and a
+ collection of names to which this greeting applies.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:sequence>
+
+ <xsd:element name="greeting" type="xsd:string">
+ <xsd:annotation>
+ <xsd:documentation>
+ The greeting element contains the greeting phrase
+ for this hello object.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+ <xsd:element name="name" type="xsd:string" maxOccurs="unbounded">
+ <xsd:annotation>
+ <xsd:documentation>
+ The name elements contains names to be greeted.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:element name="hello" type="hello_t">
+ <xsd:annotation>
+ <xsd:documentation>
+ The hello element is a root of the Hello XML vocabulary.
+ Every conforming document should start with this element.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ </xsd:schema>
+ EOI
+
+ cat <<EOI >=hello.xml;
+ <?xml version="1.0"?>
+ <hello xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="hello.xsd">
+
+ <greeting>Hello</greeting>
+
+ <name>sun</name>
+ <name>moon</name>
+ <name>world</name>
+
+ </hello>
+ EOI
+
+ $* hello.xml >>EOO
+ greeting Hello
+ name sun
+ name moon
+ name world
+ EOO
+}