diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-02-24 15:16:26 +0200 |
commit | 707cc94fe52463870a9c6c8e2e66eaaa389e601d (patch) | |
tree | 13e10ff28bf4455d915f9d59b401bdbb62a393cb /tests/cxx/serializer/error-handling/codes |
Start tracking XSD/e with git after version 3.0.03.0.0
Diffstat (limited to 'tests/cxx/serializer/error-handling/codes')
-rw-r--r-- | tests/cxx/serializer/error-handling/codes/driver.cxx | 327 | ||||
-rw-r--r-- | tests/cxx/serializer/error-handling/codes/makefile | 72 | ||||
-rw-r--r-- | tests/cxx/serializer/error-handling/codes/output | 20 | ||||
-rw-r--r-- | tests/cxx/serializer/error-handling/codes/test.xsd | 22 |
4 files changed, 441 insertions, 0 deletions
diff --git a/tests/cxx/serializer/error-handling/codes/driver.cxx b/tests/cxx/serializer/error-handling/codes/driver.cxx new file mode 100644 index 0000000..ba1f6cd --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/driver.cxx @@ -0,0 +1,327 @@ +// file : tests/cxx/serializer/error-handling/codes/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 error reporting with error codes. +// + +#include <cassert> +#include <sstream> +#include <iostream> + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +// bool fail = true; + +struct test_simpl: virtual test_sskel +{ + test_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 6) + _app_error (case_); + + n_ = 0; + } + + virtual void + _pre () + { + if (case_ == 7) + _app_error (case_); + + if (case_ == 19) + _end_element (); + } + + // Attributes. + // + virtual bool + x_present () + { + if (case_ == 8) + { + _app_error (case_); + return false; + } + + return true; + } + + virtual int + x () + { + if (case_ == 9) + _app_error (case_); + + return -1; + } + + virtual int + y () + { + if (case_ == 10) + _app_error (case_); + + return -2; + } + + // Elements. + // + virtual int + a () + { + if (case_ == 11) + _app_error (case_); + + return 1; + } + + virtual bool + b_present () + { + if (case_ == 12) + { + _app_error (case_); + return false; + } + + return true; + } + + virtual int + b () + { + if (case_ == 13) + _app_error (case_); + + return 2; + } + + virtual bool + c_next () + { + if (case_ == 14) + { + _app_error (case_); + return false; + } + + return n_++ < 3; + } + + virtual int + c () + { + if (case_ == 15) + _app_error (case_); + + return 2 + n_; + } + + virtual void + _post () + { + if (case_ == 16) + _app_error (case_); + } + + virtual void + post () + { + if (case_ == 17) + _app_error (case_); + } + +private: + int case_; + int n_; +}; + +struct root_simpl: root_sskel +{ + root_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 1) + _app_error (case_); + } + + virtual void + _pre () + { + if (case_ == 2) + _app_error (case_); + } + + virtual void + test () + { + if (case_ == 3) + _app_error (case_); + } + + virtual void + _post () + { + if (case_ == 4) + _app_error (case_); + } + + virtual void + post () + { + if (case_ == 5) + _app_error (case_); + } + +private: + int case_; +}; + +struct writer: xml_schema::writer +{ + virtual bool + write (const char*, size_t) + { + return false; + } + + virtual bool + flush () + { + return false; + } +}; + + +void +print (xml_schema::serializer_error e) +{ + typedef xml_schema::serializer_error error; + + switch (e.type ()) + { + case error::sys: + { + cout << "sys: " << e.sys_code () << ": " << e.sys_text () << endl; + break; + } + case error::xml: + { + cout << "xml: " << e.xml_code () << ": " << e.xml_text () << endl; + break; + } +#ifdef XSDE_SERIALIZER_VALIDATION + case error::schema: + { + cout << "schema: " << e.schema_code () << ": " << e.schema_text () + << endl; + break; + } +#endif + case error::app: + { + cout << "app: " << e.app_code () << endl; + break; + } + default: + { + cout << "no error" << endl; + } + } +} + +int +main () +{ + typedef xml_schema::serializer_error error; + + /* + string output ("<g1:root xmlns:g1=\"test\"><test x=\"-1\" y=\"-2\">" + "<a>1</a><b>2</b><c>3</c><c>4</c><c>5</c></test></g1:root>"); + */ + + // 1-5 : app errors in the root element serializer + // 6-17: app errors in the sub element serializer + // 18 : xml error in document serializer + // 19 : xml error in sub element serializer + // 20 : sys error + // + for (int i (1); i <= 20; ++i) + { + xml_schema::int_simpl int_s; + test_simpl test_s (i); + root_simpl root_s (i); + + test_s.serializers (int_s, int_s, int_s, int_s, int_s); + root_s.serializers (test_s); + + xml_schema::document_simpl doc_s ( + root_s, + "test", + (i == 18 ? "bad name" : "root")); + + root_s.pre (); + + if (error e = root_s._error ()) + print (e); + else + { + ostringstream os; + + if (i == 20) + { + writer w; + doc_s.serialize (w); + } + else + doc_s.serialize (os); + + if (error e = doc_s._error ()) + print (e); + else + { + root_s.post (); + + if (error e = root_s._error ()) + print (e); + } + } + + /* + { + fail = false; + + ostringstream os; + + root_s.pre (); + assert (!root_s.error ()); + + doc_s.serialize (os); + assert (!doc_s._error ()); + + root_s.post (); + assert (!root_s.error ()); + + assert (os.str () == output); + + fail = true; + } + */ + } +} diff --git a/tests/cxx/serializer/error-handling/codes/makefile b/tests/cxx/serializer/error-handling/codes/makefile new file mode 100644 index 0000000..bdaca6c --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/error-handling/codes/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/error-handling/codes/output b/tests/cxx/serializer/error-handling/codes/output new file mode 100644 index 0000000..c01aab9 --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/output @@ -0,0 +1,20 @@ +app: 1 +app: 2 +app: 3 +app: 4 +app: 5 +app: 6 +app: 7 +app: 8 +app: 9 +app: 10 +app: 11 +app: 12 +app: 13 +app: 14 +app: 15 +app: 16 +app: 17 +xml: 3: illegal name +xml: 8: call out of sequence +sys: 4: write failed diff --git a/tests/cxx/serializer/error-handling/codes/test.xsd b/tests/cxx/serializer/error-handling/codes/test.xsd new file mode 100644 index 0000000..530118c --- /dev/null +++ b/tests/cxx/serializer/error-handling/codes/test.xsd @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + + <complexType name="test"> + <sequence> + <element name="a" type="int"/> + <element name="b" type="int" minOccurs="0"/> + <element name="c" type="int" maxOccurs="unbounded"/> + </sequence> + <attribute name="x" type="int"/> + <attribute name="y" type="int" use="required"/> + </complexType> + + <complexType name="root"> + <sequence> + <element name="test" type="t:test"/> + </sequence> + </complexType> + + <element name="root" type="t:root"/> + +</schema> |