summaryrefslogtreecommitdiff
path: root/tests/cxx/parser/validation/restriction
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-09-17 07:15:29 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-09-17 07:15:29 +0200
commitf0510d2f90467de8e8f260b47d79a9baaf9bef17 (patch)
tree0b9929946f06a9cbe9b9e8f2a7600dae4e048f79 /tests/cxx/parser/validation/restriction
Start tracking XSD with git
Diffstat (limited to 'tests/cxx/parser/validation/restriction')
-rw-r--r--tests/cxx/parser/validation/restriction/driver.cxx109
-rw-r--r--tests/cxx/parser/validation/restriction/makefile85
-rw-r--r--tests/cxx/parser/validation/restriction/test-000.std0
-rw-r--r--tests/cxx/parser/validation/restriction/test-000.xml31
-rw-r--r--tests/cxx/parser/validation/restriction/test-001.std1
-rw-r--r--tests/cxx/parser/validation/restriction/test-001.xml11
-rw-r--r--tests/cxx/parser/validation/restriction/test-002.std1
-rw-r--r--tests/cxx/parser/validation/restriction/test-002.xml12
-rw-r--r--tests/cxx/parser/validation/restriction/test-003.std1
-rw-r--r--tests/cxx/parser/validation/restriction/test-003.xml16
-rw-r--r--tests/cxx/parser/validation/restriction/test-004.std1
-rw-r--r--tests/cxx/parser/validation/restriction/test-004.xml10
-rw-r--r--tests/cxx/parser/validation/restriction/test-005.std1
-rw-r--r--tests/cxx/parser/validation/restriction/test-005.xml11
-rw-r--r--tests/cxx/parser/validation/restriction/test.xsd82
15 files changed, 372 insertions, 0 deletions
diff --git a/tests/cxx/parser/validation/restriction/driver.cxx b/tests/cxx/parser/validation/restriction/driver.cxx
new file mode 100644
index 0000000..34db4d2
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/driver.cxx
@@ -0,0 +1,109 @@
+// file : tests/cxx/parser/validation/restriction/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 the restriction compositor validation.
+//
+
+#include <string>
+#include <fstream>
+#include <iostream>
+
+#include "test-pskel.hxx"
+
+using namespace std;
+using namespace test;
+
+struct base_a_pimpl: base_a_pskel
+{
+};
+
+struct restriction_a_pimpl: restriction_a_pskel
+{
+};
+
+struct extension_b_pimpl: extension_b_pskel
+{
+};
+
+struct restriction_b_pimpl: restriction_b_pskel
+{
+};
+
+struct type_b_pimpl: type_b_pskel
+{
+};
+
+struct type_r_pimpl: type_r_pskel
+{
+};
+
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " test.xml" << endl;
+ return 1;
+ }
+
+ try
+ {
+ xml_schema::string_pimpl string_p;
+ base_a_pimpl base_a_p;
+ restriction_a_pimpl restriction_a_p;
+ extension_b_pimpl extension_b_p;
+ restriction_b_pimpl restriction_b_p;
+ type_b_pimpl type_b_p;
+ type_r_pimpl type_r_p;
+
+ base_a_p.parsers (string_p, string_p, string_p,
+ string_p, string_p, string_p);
+
+ restriction_a_p.parsers (string_p, string_p, string_p,
+ string_p, string_p, string_p);
+
+ extension_b_p.parsers (string_p, string_p, string_p,
+ string_p, string_p);
+
+ restriction_b_p.parsers (string_p, string_p, string_p,
+ string_p, string_p);
+
+ type_b_p.parsers (base_a_p, extension_b_p);
+ type_r_p.parsers (restriction_a_p, restriction_b_p);
+
+ xml_schema::document doc_b_p (type_b_p, "test", "root");
+ xml_schema::document doc_r_p (type_r_p, "test", "root");
+
+ {
+ ifstream ifs (argv[1]);
+ type_b_p.pre ();
+ doc_b_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate);
+ type_b_p.post_type_b ();
+ }
+
+ try
+ {
+ ifstream ifs (argv[1]);
+ type_r_p.pre ();
+ doc_r_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate);
+ type_r_p.post_type_r ();
+ }
+ catch (xml_schema::exception const& e)
+ {
+ cout << e << endl;
+ }
+ }
+ catch (xml_schema::exception const& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+ catch (ios_base::failure const&)
+ {
+ cerr << "io failure" << endl;
+ return 1;
+ }
+}
diff --git a/tests/cxx/parser/validation/restriction/makefile b/tests/cxx/parser/validation/restriction/makefile
new file mode 100644
index 0000000..bb78c5e
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/makefile
@@ -0,0 +1,85 @@
+# file : tests/cxx/parser/validation/restriction/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
+
+tests := 000 001 002 003 004 005
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.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)
+
+skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \
+ $(out_base)/$(xsd:.xsd=-pskel.ixx) \
+ $(out_base)/$(xsd:.xsd=-pskel.cxx)
+
+$(skel): xsd := $(out_root)/xsd/xsd
+$(skel): xsd_options := --generate-validation
+$(skel): $(out_root)/xsd/xsd
+
+$(call include-dep,$(dep))
+
+
+# Convenience alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+test_targets := $(addprefix $(out_base)/.test-,$(tests))
+
+.PHONY: $(test)
+$(test): $(test_targets)
+
+
+$(test_targets): driver := $(driver)
+
+.PHONY: $(out_base)/.test-%
+$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std
+ $(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -)
+
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.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/parser/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsd/makefile)
diff --git a/tests/cxx/parser/validation/restriction/test-000.std b/tests/cxx/parser/validation/restriction/test-000.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-000.std
diff --git a/tests/cxx/parser/validation/restriction/test-000.xml b/tests/cxx/parser/validation/restriction/test-000.xml
new file mode 100644
index 0000000..21402b4
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-000.xml
@@ -0,0 +1,31 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <restriction-a z="z">
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+ </restriction-a>
+
+ <restriction-a x="x" y="y" z="z">
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+ </restriction-a>
+
+ <restriction-b y="y">
+ <a>a</a>
+ <b>b</b>
+ </restriction-b>
+
+ <restriction-b y="y">
+ <a>a</a>
+ <c>c</c>
+ </restriction-b>
+
+ <restriction-b x="x" y="y">
+ <a>a</a>
+ </restriction-b>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test-001.std b/tests/cxx/parser/validation/restriction/test-001.std
new file mode 100644
index 0000000..5077837
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-001.std
@@ -0,0 +1 @@
+:7:8 error: expected element 'a' instead of 'b'
diff --git a/tests/cxx/parser/validation/restriction/test-001.xml b/tests/cxx/parser/validation/restriction/test-001.xml
new file mode 100644
index 0000000..4015302
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-001.xml
@@ -0,0 +1,11 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <!-- valid base but not restriction: a element -->
+ <restriction-a z="z">
+ <b>b</b>
+ <c>c</c>
+ </restriction-a>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test-002.std b/tests/cxx/parser/validation/restriction/test-002.std
new file mode 100644
index 0000000..f12c342
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-002.std
@@ -0,0 +1 @@
+:10:19 error: expected attribute 'z'
diff --git a/tests/cxx/parser/validation/restriction/test-002.xml b/tests/cxx/parser/validation/restriction/test-002.xml
new file mode 100644
index 0000000..eb7684c
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-002.xml
@@ -0,0 +1,12 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <!-- valid base but not restriction: z attribute -->
+ <restriction-a>
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+ </restriction-a>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test-003.std b/tests/cxx/parser/validation/restriction/test-003.std
new file mode 100644
index 0000000..0c65175
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-003.std
@@ -0,0 +1 @@
+:11:8 error: unexpected element 'a'
diff --git a/tests/cxx/parser/validation/restriction/test-003.xml b/tests/cxx/parser/validation/restriction/test-003.xml
new file mode 100644
index 0000000..49f18c7
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-003.xml
@@ -0,0 +1,16 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <!-- valid base but not restriction: sequence maxOccurs="1" -->
+ <restriction-a z="z">
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+
+ <a>a</a>
+ <b>b</b>
+ <c>c</c>
+ </restriction-a>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test-004.std b/tests/cxx/parser/validation/restriction/test-004.std
new file mode 100644
index 0000000..5077837
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-004.std
@@ -0,0 +1 @@
+:7:8 error: expected element 'a' instead of 'b'
diff --git a/tests/cxx/parser/validation/restriction/test-004.xml b/tests/cxx/parser/validation/restriction/test-004.xml
new file mode 100644
index 0000000..115cd38
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-004.xml
@@ -0,0 +1,10 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <!-- valid extension but not restriction: a element -->
+ <restriction-b y="y">
+ <b>b</b>
+ </restriction-b>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test-005.std b/tests/cxx/parser/validation/restriction/test-005.std
new file mode 100644
index 0000000..e92de14
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-005.std
@@ -0,0 +1 @@
+:9:19 error: expected attribute 'y'
diff --git a/tests/cxx/parser/validation/restriction/test-005.xml b/tests/cxx/parser/validation/restriction/test-005.xml
new file mode 100644
index 0000000..e9ab7d9
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test-005.xml
@@ -0,0 +1,11 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <!-- valid extension but not restriction: y attribute -->
+ <restriction-b>
+ <a>a</a>
+ <b>b</b>
+ </restriction-b>
+
+</t:root>
diff --git a/tests/cxx/parser/validation/restriction/test.xsd b/tests/cxx/parser/validation/restriction/test.xsd
new file mode 100644
index 0000000..158ded5
--- /dev/null
+++ b/tests/cxx/parser/validation/restriction/test.xsd
@@ -0,0 +1,82 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <!-- simple case -->
+ <complexType name="base-a">
+ <sequence minOccurs="1" maxOccurs="2">
+ <element name="a" type="string" minOccurs="0"/>
+ <element name="b" type="string"/>
+ <element name="c" type="string"/>
+ </sequence>
+ <attribute name="x" type="string"/>
+ <attribute name="y" type="string"/>
+ <attribute name="z" type="string"/>
+ </complexType>
+
+ <complexType name="restriction-a">
+ <complexContent>
+ <restriction base="t:base-a">
+ <sequence minOccurs="1" maxOccurs="1">
+ <element name="a" type="string" minOccurs="1"/>
+ <element name="b" type="string"/>
+ <element name="c" type="string"/>
+ </sequence>
+ <!-- Can be ommited if not changed, e.g., 'x'. -->
+ <attribute name="y" type="string"/> <!-- But can also be repeated without change. -->
+ <attribute name="z" type="string" use="required"/>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+ <!-- restriction of an extension -->
+ <complexType name="base-b">
+ <sequence>
+ <element name="a" type="string" minOccurs="0"/>
+ </sequence>
+ <attribute name="x" type="string"/>
+ </complexType>
+
+ <complexType name="extension-b">
+ <complexContent>
+ <extension base="t:base-b">
+ <choice>
+ <element name="b" type="string" minOccurs="0"/>
+ <element name="c" type="string"/>
+ </choice>
+ <attribute name="y" type="string"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="restriction-b">
+ <complexContent>
+ <restriction base="t:extension-b">
+ <sequence>
+ <sequence>
+ <element name="a" type="string" minOccurs="1"/>
+ </sequence>
+ <choice>
+ <element name="b" type="string" minOccurs="0"/>
+ <element name="c" type="string"/>
+ </choice>
+ </sequence>
+ <attribute name="y" type="string" use="required"/>
+ </restriction>
+ </complexContent>
+ </complexType>
+
+ <complexType name="type-b">
+ <choice maxOccurs="unbounded">
+ <element name="restriction-a" type="t:base-a"/>
+ <element name="restriction-b" type="t:extension-b"/>
+ </choice>
+ </complexType>
+
+ <complexType name="type-r">
+ <choice maxOccurs="unbounded">
+ <element name="restriction-a" type="t:restriction-a"/>
+ <element name="restriction-b" type="t:restriction-b"/>
+ </choice>
+ </complexType>
+
+</schema>