aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/parser/reset
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cxx/parser/reset')
-rw-r--r--tests/cxx/parser/reset/driver.cxx300
-rw-r--r--tests/cxx/parser/reset/fail-schema.xml8
-rw-r--r--tests/cxx/parser/reset/fail-xml.xml7
-rw-r--r--tests/cxx/parser/reset/makefile75
-rw-r--r--tests/cxx/parser/reset/output8
-rw-r--r--tests/cxx/parser/reset/pass.xml7
-rw-r--r--tests/cxx/parser/reset/test.xsd27
7 files changed, 432 insertions, 0 deletions
diff --git a/tests/cxx/parser/reset/driver.cxx b/tests/cxx/parser/reset/driver.cxx
new file mode 100644
index 0000000..5701df5
--- /dev/null
+++ b/tests/cxx/parser/reset/driver.cxx
@@ -0,0 +1,300 @@
+// file : tests/cxx/parser/reset/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 parser resetting.
+//
+
+#include <assert.h>
+
+#include <string>
+#include <iostream>
+
+#include "test-pskel.hxx"
+
+using namespace std;
+using namespace test;
+
+bool fail = true;
+
+struct error {};
+
+#ifdef XSDE_REUSE_STYLE_MIXIN
+struct base_pimpl: virtual base_pskel
+#else
+struct base_pimpl: base_pskel
+#endif
+{
+ base_pimpl (unsigned long i)
+ : i_ (i)
+ {
+ }
+
+ virtual void
+ pre ()
+ {
+#ifndef XSDE_EXCEPTIONS
+ assert (!_error ());
+#endif
+
+ if (fail && i_ == 3)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+private:
+ unsigned long i_;
+};
+
+#ifdef XSDE_REUSE_STYLE_MIXIN
+struct inner_pimpl: inner_pskel, base_pimpl
+#else
+struct inner_pimpl: inner_pskel
+#endif
+{
+ inner_pimpl (unsigned long i)
+#ifdef XSDE_REUSE_STYLE_MIXIN
+ : base_pimpl (i), i_ (i)
+#else
+ : inner_pskel (&base_impl_), base_impl_ (i), i_ (i)
+#endif
+ {
+ }
+
+ virtual void
+ b (int v)
+ {
+ if (fail && i_ == 4)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+
+ if (!fail)
+ cout << i_ << ": " << v << endl;
+ }
+
+ virtual void
+ post_inner ()
+ {
+ if (fail && i_ == 5)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+private:
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ base_pimpl base_impl_;
+#endif
+ unsigned long i_;
+};
+
+struct type_pimpl: type_pskel
+{
+ type_pimpl (unsigned long i)
+ : i_ (i)
+ {
+ }
+
+ virtual void
+ pre ()
+ {
+ if (fail && i_ == 0)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+ virtual void
+ a ()
+ {
+ if (fail && i_ == 1)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+ virtual void
+ post_type ()
+ {
+ if (fail && i_ == 2)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+private:
+ unsigned long i_;
+};
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 4)
+ {
+ cerr << "usage: " << argv[0] << " pass.xml fail-xml.xml fail-schema.xml"
+ << endl;
+ return 1;
+ }
+
+ const char* pass = argv[1];
+ const char* fail_xml = argv[2];
+ const char* fail_schema = argv[3];
+
+ try
+ {
+ for (unsigned long i (0); i < 8; ++i)
+ {
+#ifndef XSDE_PARSER_VALIDATION
+ if (i == 7)
+ {
+ cout << "7: 1" << endl;
+ continue;
+ }
+#endif
+
+ xml_schema::int_pimpl int_p;
+ inner_pimpl inner_p (i);
+ type_pimpl type_p (i);
+
+ inner_p.parsers (int_p);
+ type_p.parsers (inner_p);
+
+ xml_schema::document_pimpl doc_p (type_p, "test", "root");
+
+#ifdef XSDE_EXCEPTIONS
+ try
+ {
+ fail = true;
+
+ type_p.pre ();
+
+ switch (i)
+ {
+ case 6:
+ {
+ doc_p.parse (fail_xml);
+ break;
+ }
+ case 7:
+ {
+ doc_p.parse (fail_schema);
+ break;
+ }
+ default:
+ {
+ doc_p.parse (pass);
+ break;
+ }
+ }
+
+ type_p.post_type ();
+ assert (false);
+ }
+ catch (error const&)
+ {
+ }
+ catch (xml_schema::parser_exception const&)
+ {
+ }
+
+ fail = false;
+ doc_p.reset ();
+
+ type_p.pre ();
+ doc_p.parse (pass);
+ type_p.post_type ();
+#else
+ do
+ {
+ fail = true;
+
+ type_p.pre ();
+
+ if (type_p._error ())
+ break;
+
+ switch (i)
+ {
+ case 6:
+ {
+ doc_p.parse (fail_xml);
+ break;
+ }
+ case 7:
+ {
+ doc_p.parse (fail_schema);
+ break;
+ }
+ default:
+ {
+ doc_p.parse (pass);
+ break;
+ }
+ }
+
+ if (doc_p._error ())
+ break;
+
+ type_p.post_type ();
+
+ if (type_p._error ())
+ break;
+
+ assert (false);
+ }
+ while (false);
+
+ fail = false;
+ doc_p.reset ();
+
+ type_p.pre ();
+ assert (!type_p._error ());
+
+ doc_p.parse (pass);
+ assert (!doc_p._error ());
+
+ type_p.post_type ();
+ assert (!type_p._error ());
+#endif
+ }
+ }
+#ifdef XSDE_EXCEPTIONS
+ catch (xml_schema::parser_exception const& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+#endif
+ catch (std::ios_base::failure const&)
+ {
+ cerr << "io failure" << endl;
+ return 1;
+ }
+}
diff --git a/tests/cxx/parser/reset/fail-schema.xml b/tests/cxx/parser/reset/fail-schema.xml
new file mode 100644
index 0000000..92c6c8b
--- /dev/null
+++ b/tests/cxx/parser/reset/fail-schema.xml
@@ -0,0 +1,8 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <a><b>1</b></a>
+ <a><b>1</b></a>
+
+</t:root>
diff --git a/tests/cxx/parser/reset/fail-xml.xml b/tests/cxx/parser/reset/fail-xml.xml
new file mode 100644
index 0000000..b2aacb2
--- /dev/null
+++ b/tests/cxx/parser/reset/fail-xml.xml
@@ -0,0 +1,7 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <a></b>1</b></a>
+
+</t:root>
diff --git a/tests/cxx/parser/reset/makefile b/tests/cxx/parser/reset/makefile
new file mode 100644
index 0000000..31dd3b4
--- /dev/null
+++ b/tests/cxx/parser/reset/makefile
@@ -0,0 +1,75 @@
+# file : tests/cxx/parser/reset/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=-pskel.o))
+dep := $(obj:.o=.o.d)
+
+xsde.l := $(out_root)/libxsde/xsde/xsde.l
+xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+
+# Build.
+#
+$(driver): $(obj) $(xsde.l)
+
+$(obj) $(dep): $(xsde.l.cpp-options)
+
+skel := $(out_base)/$(xsd:.xsd=-pskel.hxx) \
+ $(out_base)/$(xsd:.xsd=-pskel.ixx) \
+ $(out_base)/$(xsd:.xsd=-pskel.cxx)
+
+$(skel): xsde := $(out_root)/xsde/xsde
+$(skel): $(out_root)/xsde/xsde
+
+$(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)/pass.xml $(src_base)/fail-xml.xml \
+ $(src_base)/fail-schema.xml $(src_base)/output
+ $(call message,test $$1,$$1 $(src_base)/pass.xml \
+$(src_base)/fail-xml.xml $(src_base)/fail-schema.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=-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)/xsde/parser/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)
diff --git a/tests/cxx/parser/reset/output b/tests/cxx/parser/reset/output
new file mode 100644
index 0000000..0e6cb1e
--- /dev/null
+++ b/tests/cxx/parser/reset/output
@@ -0,0 +1,8 @@
+0: 1
+1: 1
+2: 1
+3: 1
+4: 1
+5: 1
+6: 1
+7: 1
diff --git a/tests/cxx/parser/reset/pass.xml b/tests/cxx/parser/reset/pass.xml
new file mode 100644
index 0000000..956ec2a
--- /dev/null
+++ b/tests/cxx/parser/reset/pass.xml
@@ -0,0 +1,7 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <a><b>1</b></a>
+
+</t:root>
diff --git a/tests/cxx/parser/reset/test.xsd b/tests/cxx/parser/reset/test.xsd
new file mode 100644
index 0000000..56ee5a4
--- /dev/null
+++ b/tests/cxx/parser/reset/test.xsd
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="base">
+ <sequence>
+ </sequence>
+ </complexType>
+
+ <complexType name="inner">
+ <complexContent>
+ <extension base="t:base">
+ <sequence>
+ <element name="b" type="int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="a" type="t:inner"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>