From 707cc94fe52463870a9c6c8e2e66eaaa389e601d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2009 15:16:26 +0200 Subject: Start tracking XSD/e with git after version 3.0.0 --- .../error-handling/exceptions/driver.cxx | 285 +++++++++++++++++++++ .../serializer/error-handling/exceptions/makefile | 72 ++++++ .../serializer/error-handling/exceptions/output | 20 ++ .../serializer/error-handling/exceptions/test.xsd | 22 ++ 4 files changed, 399 insertions(+) create mode 100644 tests/cxx/serializer/error-handling/exceptions/driver.cxx create mode 100644 tests/cxx/serializer/error-handling/exceptions/makefile create mode 100644 tests/cxx/serializer/error-handling/exceptions/output create mode 100644 tests/cxx/serializer/error-handling/exceptions/test.xsd (limited to 'tests/cxx/serializer/error-handling/exceptions') diff --git a/tests/cxx/serializer/error-handling/exceptions/driver.cxx b/tests/cxx/serializer/error-handling/exceptions/driver.cxx new file mode 100644 index 0000000..3a7437b --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/driver.cxx @@ -0,0 +1,285 @@ +// file : tests/cxx/serializer/error-handling/exceptions/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test error reporting with exceptions. +// + +#include +#include +#include + +#include "test-sskel.hxx" + +using namespace std; +using namespace test; + +struct app +{ + app (int code) + : code_ (code) + { + } + + int + code () const + { + return code_; + } + +private: + int code_; +}; + +struct test_simpl: virtual test_sskel +{ + test_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 6) + throw app (case_); + + n_ = 0; + } + + virtual void + _pre () + { + if (case_ == 7) + throw app (case_); + + if (case_ == 19) + _end_element (); + } + + // Attributes. + // + virtual bool + x_present () + { + if (case_ == 8) + { + throw app (case_); + return false; + } + + return true; + } + + virtual int + x () + { + if (case_ == 9) + throw app (case_); + + return -1; + } + + virtual int + y () + { + if (case_ == 10) + throw app (case_); + + return -2; + } + + // Elements. + // + virtual int + a () + { + if (case_ == 11) + throw app (case_); + + return 1; + } + + virtual bool + b_present () + { + if (case_ == 12) + { + throw app (case_); + return false; + } + + return true; + } + + virtual int + b () + { + if (case_ == 13) + throw app (case_); + + return 2; + } + + virtual bool + c_next () + { + if (case_ == 14) + { + throw app (case_); + return false; + } + + return n_++ < 3; + } + + virtual int + c () + { + if (case_ == 15) + throw app (case_); + + return 2 + n_; + } + + virtual void + _post () + { + if (case_ == 16) + throw app (case_); + } + + virtual void + post () + { + if (case_ == 17) + throw app (case_); + } + +private: + int case_; + int n_; +}; + +struct root_simpl: root_sskel +{ + root_simpl (int c) + : case_ (c) + { + } + + virtual void + pre () + { + if (case_ == 1) + throw app (case_); + } + + virtual void + _pre () + { + if (case_ == 2) + throw app (case_); + } + + virtual void + test () + { + if (case_ == 3) + throw app (case_); + } + + virtual void + _post () + { + if (case_ == 4) + throw app (case_); + } + + virtual void + post () + { + if (case_ == 5) + throw app (case_); + } + +private: + int case_; +}; + +struct writer: xml_schema::writer +{ + virtual void + write (const char*, size_t) + { + throw ios_base::failure ("write failed"); + } + + virtual void + flush () + { + throw ios_base::failure ("write failed"); + } +}; + +int +main () +{ + + // 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) + { + try + { + 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 (); + + ostringstream os; + + if (i == 20) + { + writer w; + doc_s.serialize (w); + } + else + doc_s.serialize (os); + + root_s.post (); + } + catch (ios_base::failure const&) + { + cout << "sys: write failed" << endl; + } + catch (xml_schema::serializer_xml const& e) + { + cout << "xml: " << e.text () << endl; + } +#ifdef XSDE_SERIALIZER_VALIDATION + catch (xml_schema::serializer_schema const& e) + { + cout << "schema: " << e.text () << endl; + } +#endif + catch (app const& e) + { + cout << "app: " << e.code () << endl; + } + } +} diff --git a/tests/cxx/serializer/error-handling/exceptions/makefile b/tests/cxx/serializer/error-handling/exceptions/makefile new file mode 100644 index 0000000..19027cc --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/makefile @@ -0,0 +1,72 @@ +# file : tests/cxx/serializer/error-handling/exceptions/makefile +# author : Boris Kolpackov +# 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/exceptions/output b/tests/cxx/serializer/error-handling/exceptions/output new file mode 100644 index 0000000..e640bd6 --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/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: illegal name +xml: call out of sequence +sys: write failed diff --git a/tests/cxx/serializer/error-handling/exceptions/test.xsd b/tests/cxx/serializer/error-handling/exceptions/test.xsd new file mode 100644 index 0000000..530118c --- /dev/null +++ b/tests/cxx/serializer/error-handling/exceptions/test.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1