aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/tree/default
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cxx/tree/default')
-rw-r--r--tests/cxx/tree/default/driver.cxx48
-rw-r--r--tests/cxx/tree/default/makefile83
-rw-r--r--tests/cxx/tree/default/output26
-rw-r--r--tests/cxx/tree/default/test.xml11
-rw-r--r--tests/cxx/tree/default/test.xsd39
5 files changed, 207 insertions, 0 deletions
diff --git a/tests/cxx/tree/default/driver.cxx b/tests/cxx/tree/default/driver.cxx
new file mode 100644
index 0000000..3c71222
--- /dev/null
+++ b/tests/cxx/tree/default/driver.cxx
@@ -0,0 +1,48 @@
+// file : tests/cxx/tree/default/driver.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Test default attribute/element values.
+//
+
+#include <memory> // std::auto_ptr
+#include <iostream>
+
+#include "test.hxx"
+
+using namespace std;
+using namespace test;
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " test.xml" << endl;
+ return 1;
+ }
+
+ try
+ {
+ auto_ptr<type> r (root (argv[1], xml_schema::flags::dont_validate));
+
+ cout << *r << endl
+ << "default x: " << derived::x_default_value () << endl
+ << "default y: " << derived::y_default_value () << endl
+ << "fixed p: " << derived::p_default_value () << endl
+ << "fixed q1: " << derived::q1_default_value () << endl
+ << "fixed q2: " << derived::q2_default_value () << endl;
+
+ // Serialize.
+ //
+ xml_schema::namespace_infomap map;
+ map["t"].name = "test";
+ root (cout, *r, map);
+ }
+ catch (xml_schema::exception const& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+}
diff --git a/tests/cxx/tree/default/makefile b/tests/cxx/tree/default/makefile
new file mode 100644
index 0000000..209c283
--- /dev/null
+++ b/tests/cxx/tree/default/makefile
@@ -0,0 +1,83 @@
+# file : tests/cxx/tree/default/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
+
+xsd := test.xsd
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.o))
+dep := $(obj:.o=.o.d)
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/libxerces-c/stub.make,\
+ l: xerces_c.l,cpp-options: xerces_c.l.cpp-options)
+
+
+# Build.
+#
+$(driver): $(obj) $(xerces_c.l)
+
+$(obj) $(dep): cpp_options := -I$(src_root)/libxsd
+$(obj) $(dep): $(xerces_c.l.cpp-options)
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd := $(out_root)/xsd/xsd
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): xsd_options := --generate-ostream \
+--generate-serialization --generate-default-ctor --generate-from-base-ctor \
+--omit-default-attributes
+
+$(out_base)/$(xsd:.xsd=.hxx) \
+$(out_base)/$(xsd:.xsd=.ixx) \
+$(out_base)/$(xsd:.xsd=.cxx): $(out_root)/xsd/xsd
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+.PHONY: $(test)
+
+$(test): driver := $(driver)
+$(test): $(driver) $(src_base)/test.xml $(src_base)/output
+ $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/output -,$(driver))
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
+
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(scf_root)/xsd/tree/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsd/makefile)
diff --git a/tests/cxx/tree/default/output b/tests/cxx/tree/default/output
new file mode 100644
index 0000000..1259952
--- /dev/null
+++ b/tests/cxx/tree/default/output
@@ -0,0 +1,26 @@
+
+derived:
+a: a
+x: foo
+q1: 1
+y: -20
+p: bar
+q2: 2
+qname:
+x: x
+y: y
+default x: foo
+default y: -20
+fixed p: bar
+fixed q1: 1
+fixed q2: 2
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<t:root xmlns:t="test">
+
+ <derived q1="1" q2="2">
+ <a>a</a>
+ </derived>
+
+ <qname x="x" y="y"/>
+
+</t:root>
diff --git a/tests/cxx/tree/default/test.xml b/tests/cxx/tree/default/test.xml
new file mode 100644
index 0000000..d568ac9
--- /dev/null
+++ b/tests/cxx/tree/default/test.xml
@@ -0,0 +1,11 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <derived q1="1" q2="2">
+ <a>a</a>
+ </derived>
+
+ <qname y="y"><!--a></a--></qname>
+
+</t:root>
diff --git a/tests/cxx/tree/default/test.xsd b/tests/cxx/tree/default/test.xsd
new file mode 100644
index 0000000..aa9ac66
--- /dev/null
+++ b/tests/cxx/tree/default/test.xsd
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="base">
+ <sequence>
+ <element name="a" type="string"/>
+ </sequence>
+ <attribute name="x" type="string" default="foo"/>
+ <attribute name="q1" type="int" fixed="1" use="required"/>
+ </complexType>
+
+ <complexType name="derived">
+ <complexContent>
+ <extension base="t:base">
+ <attribute name="y" type="int" default="-20"/>
+ <attribute name="p" type="string" fixed="bar"/>
+ <attribute name="q2" type="int" fixed="2" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="qname">
+ <sequence>
+ <!--element name="a" type="QName" default="a"/-->
+ </sequence>
+ <attribute name="x" type="QName" default="x"/>
+ <attribute name="y" type="QName" fixed="y" use="required"/>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="derived" type="t:derived"/>
+ <element name="qname" type="t:qname"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>