aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/serializer/reset
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cxx/serializer/reset')
-rw-r--r--tests/cxx/serializer/reset/driver.cxx281
-rw-r--r--tests/cxx/serializer/reset/makefile72
-rw-r--r--tests/cxx/serializer/reset/output7
-rw-r--r--tests/cxx/serializer/reset/test.xsd27
4 files changed, 387 insertions, 0 deletions
diff --git a/tests/cxx/serializer/reset/driver.cxx b/tests/cxx/serializer/reset/driver.cxx
new file mode 100644
index 0000000..49e5d32
--- /dev/null
+++ b/tests/cxx/serializer/reset/driver.cxx
@@ -0,0 +1,281 @@
+// file : tests/cxx/serializer/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 serializer resetting.
+//
+
+#include <assert.h>
+
+#include <string>
+#include <sstream>
+#include <iostream>
+
+#include "test-sskel.hxx"
+
+using namespace std;
+using namespace test;
+
+bool fail = true;
+
+struct error {};
+
+#ifdef XSDE_REUSE_STYLE_MIXIN
+struct base_simpl: virtual base_sskel
+#else
+struct base_simpl: base_sskel
+#endif
+{
+ base_simpl (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_simpl: inner_sskel, base_simpl
+#else
+struct inner_simpl: inner_sskel
+#endif
+{
+ inner_simpl (unsigned long i)
+#ifdef XSDE_REUSE_STYLE_MIXIN
+ : base_simpl (i), i_ (i)
+#else
+ : inner_sskel (&base_impl_), base_impl_ (i), i_ (i)
+#endif
+ {
+ }
+
+ virtual void
+ _pre ()
+ {
+ n_ = 0;
+ }
+
+ virtual bool
+ b_next ()
+ {
+ if (fail && i_ == 6)
+ {
+#ifdef XSDE_SERIALIZER_VALIDATION
+ return false;
+#else
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ return true;
+#endif
+ }
+
+ return n_++ == 0;
+ }
+
+ virtual int
+ b ()
+ {
+ if (fail && i_ == 4)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+
+ return 1;
+ }
+
+ virtual void
+ post ()
+ {
+ if (fail && i_ == 5)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+private:
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ base_simpl base_impl_;
+#endif
+ unsigned long i_;
+ unsigned long n_;
+};
+
+struct type_simpl: type_sskel
+{
+ type_simpl (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 ()
+ {
+ if (fail && i_ == 2)
+ {
+#ifdef XSDE_EXCEPTIONS
+ throw error ();
+#else
+ _app_error (1);
+#endif
+ }
+ }
+
+private:
+ unsigned long i_;
+};
+
+int
+main ()
+{
+ try
+ {
+ for (unsigned long i (0); i < 7; ++i)
+ {
+ xml_schema::int_simpl int_s;
+ inner_simpl inner_s (i);
+ type_simpl type_s (i);
+
+ inner_s.serializers (int_s);
+ type_s.serializers (inner_s);
+
+ xml_schema::document_simpl doc_s (type_s, "test", "root");
+
+ doc_s.add_prefix ("t", "test");
+ doc_s.add_schema ("test", "test.xsd");
+
+ ostringstream ostr;
+
+ cout << i << ": ";
+
+#ifdef XSDE_EXCEPTIONS
+ try
+ {
+ fail = true;
+
+ type_s.pre ();
+ doc_s.serialize (ostr);
+ type_s.post ();
+ assert (false);
+ }
+ catch (error const&)
+ {
+ }
+ catch (xml_schema::serializer_exception const&)
+ {
+ }
+
+ fail = false;
+ doc_s.reset ();
+
+ type_s.pre ();
+ doc_s.serialize (cout);
+ type_s.post ();
+#else
+ do
+ {
+ fail = true;
+
+ type_s.pre ();
+
+ if (type_s._error ())
+ break;
+
+ doc_s.serialize (ostr);
+
+ if (doc_s._error ())
+ break;
+
+ type_s.post ();
+
+ if (type_s._error ())
+ break;
+
+ assert (false);
+ }
+ while (false);
+
+ fail = false;
+ doc_s.reset ();
+
+ type_s.pre ();
+ assert (!type_s._error ());
+
+ doc_s.serialize (cout);
+ assert (!doc_s._error ());
+
+ type_s.post ();
+ assert (!type_s._error ());
+#endif
+
+ cout << endl;
+ }
+ }
+#ifdef XSDE_EXCEPTIONS
+ catch (xml_schema::serializer_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/serializer/reset/makefile b/tests/cxx/serializer/reset/makefile
new file mode 100644
index 0000000..2d87e58
--- /dev/null
+++ b/tests/cxx/serializer/reset/makefile
@@ -0,0 +1,72 @@
+# file : tests/cxx/serializer/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=-sskel.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=-sskel.hxx) \
+ $(out_base)/$(xsd:.xsd=-sskel.ixx) \
+ $(out_base)/$(xsd:.xsd=-sskel.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)/output
+ $(call message,test $$1,$$1 | 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=-sskel.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/serializer/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)
diff --git a/tests/cxx/serializer/reset/output b/tests/cxx/serializer/reset/output
new file mode 100644
index 0000000..8e0b569
--- /dev/null
+++ b/tests/cxx/serializer/reset/output
@@ -0,0 +1,7 @@
+0: <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>
+1: <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>
+2: <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>
+3: <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>
+4: <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>
+5: <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>
+6: <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/serializer/reset/test.xsd b/tests/cxx/serializer/reset/test.xsd
new file mode 100644
index 0000000..f368fa0
--- /dev/null
+++ b/tests/cxx/serializer/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" maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="a" type="t:inner"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>