From 0bce70a0e483294b83b8bf9d5468838a63405612 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Mar 2009 17:23:30 +0200 Subject: Add support for binary representations xsde/cxx/hybrid/insertion-*: insertion operators generator xsde/cxx/hybrid/extraction-*: extraction operators generator libxsde/xsde/cxx/hybrid/cdr/: CDR support code libxsde/xsde/cxx/hybrid/xdr/: XDR support code tests/cxx/hybrid/binary/: new tests examples/cxx/hybrid/binary/: new examples documentation/cxx/hybrid/guide/: new chapter --- tests/cxx/hybrid/binary/cdr/driver.cxx | 102 +++++++++++++++++++++ tests/cxx/hybrid/binary/cdr/makefile | 97 ++++++++++++++++++++ tests/cxx/hybrid/binary/cdr/output.xml | 2 + tests/cxx/hybrid/binary/cdr/test.xml | 93 +++++++++++++++++++ tests/cxx/hybrid/binary/cdr/test.xsd | 131 ++++++++++++++++++++++++++ tests/cxx/hybrid/binary/custom/driver.cxx | 102 +++++++++++++++++++++ tests/cxx/hybrid/binary/custom/makefile | 128 ++++++++++++++++++++++++++ tests/cxx/hybrid/binary/custom/output.xml | 2 + tests/cxx/hybrid/binary/custom/test.xml | 93 +++++++++++++++++++ tests/cxx/hybrid/binary/custom/test.xsd | 131 ++++++++++++++++++++++++++ tests/cxx/hybrid/binary/xdr/driver.cxx | 147 ++++++++++++++++++++++++++++++ tests/cxx/hybrid/binary/xdr/makefile | 98 ++++++++++++++++++++ tests/cxx/hybrid/binary/xdr/output.xml | 2 + tests/cxx/hybrid/binary/xdr/test.xml | 93 +++++++++++++++++++ tests/cxx/hybrid/binary/xdr/test.xsd | 131 ++++++++++++++++++++++++++ tests/cxx/hybrid/makefile | 8 ++ 16 files changed, 1360 insertions(+) create mode 100644 tests/cxx/hybrid/binary/cdr/driver.cxx create mode 100644 tests/cxx/hybrid/binary/cdr/makefile create mode 100644 tests/cxx/hybrid/binary/cdr/output.xml create mode 100644 tests/cxx/hybrid/binary/cdr/test.xml create mode 100644 tests/cxx/hybrid/binary/cdr/test.xsd create mode 100644 tests/cxx/hybrid/binary/custom/driver.cxx create mode 100644 tests/cxx/hybrid/binary/custom/makefile create mode 100644 tests/cxx/hybrid/binary/custom/output.xml create mode 100644 tests/cxx/hybrid/binary/custom/test.xml create mode 100644 tests/cxx/hybrid/binary/custom/test.xsd create mode 100644 tests/cxx/hybrid/binary/xdr/driver.cxx create mode 100644 tests/cxx/hybrid/binary/xdr/makefile create mode 100644 tests/cxx/hybrid/binary/xdr/output.xml create mode 100644 tests/cxx/hybrid/binary/xdr/test.xml create mode 100644 tests/cxx/hybrid/binary/xdr/test.xsd (limited to 'tests/cxx/hybrid') diff --git a/tests/cxx/hybrid/binary/cdr/driver.cxx b/tests/cxx/hybrid/binary/cdr/driver.cxx new file mode 100644 index 0000000..e7909cf --- /dev/null +++ b/tests/cxx/hybrid/binary/cdr/driver.cxx @@ -0,0 +1,102 @@ +// file : tests/cxx/hybrid/binary/cdr/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test CDR insertion and extraction. +// + +#include +#include + +#include + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using std::cerr; +using std::endl; + +using namespace test; + +int +main (int argc, char* argv[]) +{ + /* + try + { + */ + + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + std::auto_ptr r (root_p.post ()); + + // Save to a CDR stream. + // + ACE_OutputCDR ace_ocdr; + xml_schema::ocdrstream ocdr (ace_ocdr); + ocdr << *r; + + // Load from a CDR stream. + // + ACE_InputCDR ace_icdr (ace_ocdr); + xml_schema::icdrstream icdr (ace_icdr); + std::auto_ptr c (new type); + icdr >> *c; + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*c); + doc_s.serialize (std::cout); + root_s.post (); + + /* + } + catch (const xml_schema::xdr_exception&) + { + cerr << "XDR operation filed" << endl; + return 1; + } + catch (const xml_schema::parser_exception& e) + { + cerr << argv[0] << ":" << e.line () << ":" << e.column () << ": " + << e.text () << endl; + return 1; + } + catch (const xml_schema::serializer_exception& e) + { + cerr << "error: " << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << argv[0] << ": unable to open or read/write failure" << endl; + return 1; + } + */ +} diff --git a/tests/cxx/hybrid/binary/cdr/makefile b/tests/cxx/hybrid/binary/cdr/makefile new file mode 100644 index 0000000..a557d82 --- /dev/null +++ b/tests/cxx/hybrid/binary/cdr/makefile @@ -0,0 +1,97 @@ +# file : tests/cxx/hybrid/binary/cdr/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=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.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) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \ + $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \ + $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \ + $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \ + $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx) + +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate --generate-extraction CDR --generate-insertion CDR + +$(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)/test.xml $(src_base)/output.xml + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output.xml -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(gen): | $(out_base)/.gitignore +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# 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/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/binary/cdr/output.xml b/tests/cxx/hybrid/binary/cdr/output.xml new file mode 100644 index 0000000..a484661 --- /dev/null +++ b/tests/cxx/hybrid/binary/cdr/output.xml @@ -0,0 +1,2 @@ +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/binary/cdr/test.xml b/tests/cxx/hybrid/binary/cdr/test.xml new file mode 100644 index 0000000..acd75d2 --- /dev/null +++ b/tests/cxx/hybrid/binary/cdr/test.xml @@ -0,0 +1,93 @@ + + + 1 2 3 + + abc + + left + + + aaa + + + aaa + bbb + c + cc + ccc + + + + 123 + abcdef + 12.34false + + + 65 + 66 + -222 + 57005 + -57005 + 3735928559 + -2147483648 + 2147483647 + -2147483648 + -2147483648 + 2147483647 + 2147483647 + -2147483648 + + + + true + + + + 1234.1234 + 12345678.12345678 + 1234567812345678.1234567812345678 + + + + string + normalized string + one two three + name + name-token + name tokens + ncname + en-us + + + xsi:schemaLocation + + + + elements1 + elements2 + elements1 + elements1 elements2 + + + + http://www.codesynthesis.com + + + + YmFzZTY0IGJpbmFyeQ== + 6865782052696E617279 + + + + 2001-10-26+02:00 + 2001-10-26T21:32:52+02:00 + P1Y2M3DT5H20M30S + ---01+02:00 + --11+02:00 + --11-02+02:00 + 2001+02:00 + 2001-11+02:00 + + + + diff --git a/tests/cxx/hybrid/binary/cdr/test.xsd b/tests/cxx/hybrid/binary/cdr/test.xsd new file mode 100644 index 0000000..7a92c7e --- /dev/null +++ b/tests/cxx/hybrid/binary/cdr/test.xsd @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cxx/hybrid/binary/custom/driver.cxx b/tests/cxx/hybrid/binary/custom/driver.cxx new file mode 100644 index 0000000..400551a --- /dev/null +++ b/tests/cxx/hybrid/binary/custom/driver.cxx @@ -0,0 +1,102 @@ +// file : tests/cxx/hybrid/binary/custom/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test RAW insertion and extraction. +// + +#include +#include + +#include "orawstream.hxx" +#include "irawstream.hxx" + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using std::cerr; +using std::endl; + +using namespace test; + +int +main (int argc, char* argv[]) +{ + /* + try + { + */ + + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + std::auto_ptr r (root_p.post ()); + + // Save the object model to a RAW stream. + // + xml_schema::buffer buf; + orawstream oraw (buf); + oraw << *r; + + // Load the object model from a RAW stream. + // + irawstream iraw (buf); + std::auto_ptr c (new type); + iraw >> *c; + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*c); + doc_s.serialize (std::cout); + root_s.post (); + + /* + } + catch (const xml_schema::xdr_exception&) + { + cerr << "XDR operation filed" << endl; + return 1; + } + catch (const xml_schema::parser_exception& e) + { + cerr << argv[0] << ":" << e.line () << ":" << e.column () << ": " + << e.text () << endl; + return 1; + } + catch (const xml_schema::serializer_exception& e) + { + cerr << "error: " << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << argv[0] << ": unable to open or read/write failure" << endl; + return 1; + } + */ +} diff --git a/tests/cxx/hybrid/binary/custom/makefile b/tests/cxx/hybrid/binary/custom/makefile new file mode 100644 index 0000000..50fe420 --- /dev/null +++ b/tests/cxx/hybrid/binary/custom/makefile @@ -0,0 +1,128 @@ +# file : tests/cxx/hybrid/binary/custom/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2005-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 exceptions.cxx orawstream.cxx irawstream.cxx + +obj := $(addprefix $(out_base)/,\ +$(cxx:.cxx=.o) \ +$(xsd:.xsd=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.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 +dist := $(out_base)/.dist +dist-win := $(out_base)/.dist-win +clean := $(out_base)/.clean + +# Build. +# +$(driver): $(obj) $(xsde.l) + +$(obj) $(dep): $(xsde.l.cpp-options) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \ + $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \ + $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \ + $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \ + $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx) + +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate --extern-xml-schema xml-schema.xsd \ +--generate-insertion orawstream --hxx-prologue '\\\#include "orawstream.hxx"' \ +--generate-extraction irawstream --hxx-prologue '\\\#include "irawstream.hxx"' + +# Header files for XML Schema namespace. +# +$(out_base)/xml-schema%hxx \ +$(out_base)/xml-schema-pskel%hxx \ +$(out_base)/xml-schema-sskel%hxx: $(out_root)/xsde/xsde + $(call message,xsde $(src_base)/xml-schema.xsd,\ +$(out_root)/xsde/xsde cxx-hybrid --output-dir $(out_base) \ +--generate-xml-schema --generate-parser --generate-serializer xml-schema.xsd) + +genf += xml-schema.hxx xml-schema-pskel.hxx xml-schema-sskel.hxx + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(driver) + + +# Dist. +# +dist-common := $(out_base)/.dist-common + +.PHONY: $(dist) $(dist-win) $(dist-common) + +$(dist) $(dist-win) $(dist-common): path := $(subst $(src_root)/,,$(src_base)) + +$(dist-common): + $(call install-data,$(src_base)/driver.cxx,$(dist_prefix)/$(path)/driver.cxx) + $(call install-data,$(src_base)/library.xsd,$(dist_prefix)/$(path)/library.xsd) + $(call install-data,$(src_base)/library.xml,$(dist_prefix)/$(path)/library.xml) + +$(dist): $(dist-common) + $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README) + +$(dist-win): $(dist-common) + $(call install-data,$(src_base)/README,$(dist_prefix)/$(path)/README.txt) + $(call message,,unix2dos $(dist_prefix)/$(path)/README.txt) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + $(call message,rm $$1,rm -f $$1,$(out_base)/xml-schema.hxx) + $(call message,rm $$1,rm -f $$1,$(out_base)/xml-schema-pskel.hxx) + $(call message,rm $$1,rm -f $$1,$(out_base)/xml-schema-sskel.hxx) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(gen): | $(out_base)/.gitignore +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# 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,$(bld_root)/install.make) +$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/binary/custom/output.xml b/tests/cxx/hybrid/binary/custom/output.xml new file mode 100644 index 0000000..a484661 --- /dev/null +++ b/tests/cxx/hybrid/binary/custom/output.xml @@ -0,0 +1,2 @@ +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/binary/custom/test.xml b/tests/cxx/hybrid/binary/custom/test.xml new file mode 100644 index 0000000..acd75d2 --- /dev/null +++ b/tests/cxx/hybrid/binary/custom/test.xml @@ -0,0 +1,93 @@ + + + 1 2 3 + + abc + + left + + + aaa + + + aaa + bbb + c + cc + ccc + + + + 123 + abcdef + 12.34false + + + 65 + 66 + -222 + 57005 + -57005 + 3735928559 + -2147483648 + 2147483647 + -2147483648 + -2147483648 + 2147483647 + 2147483647 + -2147483648 + + + + true + + + + 1234.1234 + 12345678.12345678 + 1234567812345678.1234567812345678 + + + + string + normalized string + one two three + name + name-token + name tokens + ncname + en-us + + + xsi:schemaLocation + + + + elements1 + elements2 + elements1 + elements1 elements2 + + + + http://www.codesynthesis.com + + + + YmFzZTY0IGJpbmFyeQ== + 6865782052696E617279 + + + + 2001-10-26+02:00 + 2001-10-26T21:32:52+02:00 + P1Y2M3DT5H20M30S + ---01+02:00 + --11+02:00 + --11-02+02:00 + 2001+02:00 + 2001-11+02:00 + + + + diff --git a/tests/cxx/hybrid/binary/custom/test.xsd b/tests/cxx/hybrid/binary/custom/test.xsd new file mode 100644 index 0000000..7a92c7e --- /dev/null +++ b/tests/cxx/hybrid/binary/custom/test.xsd @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cxx/hybrid/binary/xdr/driver.cxx b/tests/cxx/hybrid/binary/xdr/driver.cxx new file mode 100644 index 0000000..2f87dd9 --- /dev/null +++ b/tests/cxx/hybrid/binary/xdr/driver.cxx @@ -0,0 +1,147 @@ +// file : tests/cxx/hybrid/binary/xdr/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test XDR insertion and extraction. +// + +#include // size_t +#include // memcpy +#include + +#include +#include + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +using std::cerr; +using std::endl; + +extern "C" int +overflow (char* p, char* buf, int n) +{ + xml_schema::buffer* dst (reinterpret_cast (p)); + + size_t size (dst->size ()); + dst->size (size + n); + memcpy (dst->data () + size, buf, n); + + return n; +} + +struct underflow_info +{ + xml_schema::buffer* buf; + std::size_t pos; +}; + +extern "C" int +underflow (char* p, char* buf, int n) +{ + underflow_info* ui (reinterpret_cast (p)); + + size_t size (ui->buf->size () - ui->pos); + n = size > n ? n : size; + + memcpy (buf, ui->buf->data () + ui->pos, n); + ui->pos += n; + + return n; +} + +using namespace test; + +int +main (int argc, char* argv[]) +{ + /* + try + { + */ + + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + // Parse. + // + root_paggr root_p; + + xml_schema::document_pimpl doc_p ( + root_p.root_parser (), + root_p.root_namespace (), + root_p.root_name ()); + + root_p.pre (); + doc_p.parse (argv[1]); + std::auto_ptr r (root_p.post ()); + + // Save to an XDR stream. + // + XDR xdr; + xml_schema::buffer buf; + xdrrec_create (&xdr, 0, 0, reinterpret_cast (&buf), 0, &overflow); + xdr.x_op = XDR_ENCODE; + xml_schema::oxdrstream oxdr (xdr); + oxdr << *r; + xdrrec_endofrecord (&xdr, true); // flush the data + xdr_destroy (&xdr); + + // Load from an XDR stream. + // + underflow_info ui; + ui.buf = &buf; + ui.pos = 0; + xdrrec_create (&xdr, 0, 0, reinterpret_cast (&ui), &underflow, 0); + xdr.x_op = XDR_DECODE; + xdrrec_skiprecord (&xdr); + xml_schema::ixdrstream ixdr (xdr); + std::auto_ptr c (new type); + ixdr >> *c; + xdr_destroy (&xdr); + + // Serialize. + // + root_saggr root_s; + + xml_schema::document_simpl doc_s ( + root_s.root_serializer (), + root_s.root_namespace (), + root_s.root_name ()); + + doc_s.add_prefix ("t", "test"); + + root_s.pre (*c); + doc_s.serialize (std::cout); + root_s.post (); + + /* + } + catch (const xml_schema::xdr_exception&) + { + cerr << "XDR operation filed" << endl; + return 1; + } + catch (const xml_schema::parser_exception& e) + { + cerr << argv[0] << ":" << e.line () << ":" << e.column () << ": " + << e.text () << endl; + return 1; + } + catch (const xml_schema::serializer_exception& e) + { + cerr << "error: " << e.text () << endl; + return 1; + } + catch (const std::ios_base::failure&) + { + cerr << argv[0] << ": unable to open or read/write failure" << endl; + return 1; + } + */ +} diff --git a/tests/cxx/hybrid/binary/xdr/makefile b/tests/cxx/hybrid/binary/xdr/makefile new file mode 100644 index 0000000..d15723f --- /dev/null +++ b/tests/cxx/hybrid/binary/xdr/makefile @@ -0,0 +1,98 @@ +# file : tests/cxx/hybrid/binary/xdr/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=.o) \ +$(xsd:.xsd=-pskel.o) \ +$(xsd:.xsd=-pimpl.o) \ +$(xsd:.xsd=-sskel.o) \ +$(xsd:.xsd=-simpl.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) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \ + $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \ + $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \ + $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \ + $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx) + +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(out_root)/xsde/xsde +$(gen): xsde := $(out_root)/xsde/xsde +$(gen): xsde_options += --generate-parser --generate-serializer \ +--generate-aggregate --generate-extraction XDR --generate-insertion XDR + +$(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)/test.xml $(src_base)/output.xml + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -ubB $(src_base)/output.xml -,$(driver)) + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(driver).o.clean \ + $(addsuffix .cxx.clean,$(obj)) \ + $(addsuffix .cxx.clean,$(dep)) \ + $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean)) + + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(gen): | $(out_base)/.gitignore +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + + +# 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/hybrid/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsde/makefile) +$(call import,$(src_root)/libxsde/xsde/makefile) diff --git a/tests/cxx/hybrid/binary/xdr/output.xml b/tests/cxx/hybrid/binary/xdr/output.xml new file mode 100644 index 0000000..a484661 --- /dev/null +++ b/tests/cxx/hybrid/binary/xdr/output.xml @@ -0,0 +1,2 @@ +1 2 3abcleftaaaaaabbbcccccc123abcdef12.34false6566-22257005-570053735928559-21474836482147483647-2147483648-214748364821474836472147483647-2147483648true1234.1212345678.12345681234567812345678stringnormalized stringone two threenamename-tokenname tokensncnameen-usxsi:schemaLocationelements1elements2elements1elements1 elements2http://www.codesynthesis.comYmFzZTY0IGJpbmFyeQ== +6865782052696E6172792001-10-26+02:002001-10-26T21:32:52+02:00P1Y2M3DT5H20M30S---01+02:00--11+02:00--02-11+02:002001+02:002001-11+02:00 \ No newline at end of file diff --git a/tests/cxx/hybrid/binary/xdr/test.xml b/tests/cxx/hybrid/binary/xdr/test.xml new file mode 100644 index 0000000..acd75d2 --- /dev/null +++ b/tests/cxx/hybrid/binary/xdr/test.xml @@ -0,0 +1,93 @@ + + + 1 2 3 + + abc + + left + + + aaa + + + aaa + bbb + c + cc + ccc + + + + 123 + abcdef + 12.34false + + + 65 + 66 + -222 + 57005 + -57005 + 3735928559 + -2147483648 + 2147483647 + -2147483648 + -2147483648 + 2147483647 + 2147483647 + -2147483648 + + + + true + + + + 1234.1234 + 12345678.12345678 + 1234567812345678.1234567812345678 + + + + string + normalized string + one two three + name + name-token + name tokens + ncname + en-us + + + xsi:schemaLocation + + + + elements1 + elements2 + elements1 + elements1 elements2 + + + + http://www.codesynthesis.com + + + + YmFzZTY0IGJpbmFyeQ== + 6865782052696E617279 + + + + 2001-10-26+02:00 + 2001-10-26T21:32:52+02:00 + P1Y2M3DT5H20M30S + ---01+02:00 + --11+02:00 + --11-02+02:00 + 2001+02:00 + 2001-11+02:00 + + + + diff --git a/tests/cxx/hybrid/binary/xdr/test.xsd b/tests/cxx/hybrid/binary/xdr/test.xsd new file mode 100644 index 0000000..7a92c7e --- /dev/null +++ b/tests/cxx/hybrid/binary/xdr/test.xsd @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile index 3351241..84fed4c 100644 --- a/tests/cxx/hybrid/makefile +++ b/tests/cxx/hybrid/makefile @@ -10,6 +10,14 @@ tests := sequences ifeq ($(xsde_iostream),y) tests += built-in list test-template union +ifeq ($(xsde_cdr),y) +tests += binary/cdr +endif + +ifeq ($(xsde_xdr),y) +tests += binary/xdr +endif + ifeq ($(xsde_parser_validation),y) tests += choice endif -- cgit v1.1