From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- tests/cxx/tree/binary/cdr/driver.cxx | 137 +++++++++++++++++++++++++++++++++++ tests/cxx/tree/binary/cdr/makefile | 86 ++++++++++++++++++++++ tests/cxx/tree/binary/cdr/test.xml | 91 +++++++++++++++++++++++ tests/cxx/tree/binary/cdr/test.xsd | 120 ++++++++++++++++++++++++++++++ 4 files changed, 434 insertions(+) create mode 100644 tests/cxx/tree/binary/cdr/driver.cxx create mode 100644 tests/cxx/tree/binary/cdr/makefile create mode 100644 tests/cxx/tree/binary/cdr/test.xml create mode 100644 tests/cxx/tree/binary/cdr/test.xsd (limited to 'tests/cxx/tree/binary/cdr') diff --git a/tests/cxx/tree/binary/cdr/driver.cxx b/tests/cxx/tree/binary/cdr/driver.cxx new file mode 100644 index 0000000..40cb799 --- /dev/null +++ b/tests/cxx/tree/binary/cdr/driver.cxx @@ -0,0 +1,137 @@ +// file : tests/cxx/tree/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 non-polymorphic binary serialization to ACE CDR. +// + +#include // std::auto_ptr +#include +#include + +#include "test.hxx" + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " test.xml" << endl; + return 1; + } + + try + { + auto_ptr r (root (argv[1])); + + // Save to a CDR stream. + // + ACE_OutputCDR ace_ocdr; + xml_schema::ostream ocdr (ace_ocdr); + ocdr << *r; + + // Load from a CDR stream. + // + ACE_InputCDR ace_icdr (ace_ocdr); + xml_schema::istream icdr (ace_icdr); + auto_ptr c (new type (icdr)); + + // Compare the two. + // + assert (r->list () == c->list ()); + assert (r->union_ () == c->union_ ()); + assert (r->enumeration () == c->enumeration ()); + + type::complex_sequence rs (r->complex ()), cs (c->complex ()); + + for (type::complex_iterator ri (rs.begin ()), ci (cs.begin ()); + ri != rs.end () && ci != rs.end (); ++ri, ++ci) + { + assert (ri->a () == ci->a ()); + if (ri->b ()) + assert (ri->b () == ci->b ()); + assert (ri->c () == ci->c ()); + + assert (ri->x () == ci->x ()); + if (ri->y ()) + assert (ri->y () == ci->y ()); + } + + // integers + // + assert (r->byte () == c->byte ()); + assert (r->unsigned_byte () == c->unsigned_byte ()); + assert (r->short_ () == c->short_ ()); + assert (r->unsigned_short () == c->unsigned_short ()); + assert (r->int_ () == c->int_ ()); + assert (r->unsigned_int () == c->unsigned_int ()); + assert (r->long_ () == c->long_ ()); + assert (r->unsigned_long () == c->unsigned_long ()); + assert (r->integer () == c->integer ()); + assert (r->non_positive_integer () == c->non_positive_integer ()); + assert (r->non_negative_integer () == c->non_negative_integer ()); + assert (r->positive_integer () == c->positive_integer ()); + assert (r->negative_integer () == c->negative_integer ()); + + // boolean + // + assert (r->boolean () == c->boolean ()); + + // floats + // + assert (r->float_ () == c->float_ ()); + assert (r->double_ () == c->double_ ()); + assert (r->decimal () == c->decimal ()); + + // strings + // + assert (r->string () == c->string ()); + assert (r->normalized_string () == c->normalized_string ()); + assert (r->token () == c->token ()); + assert (r->name () == c->name ()); + assert (r->name_token () == c->name_token ()); + assert (r->name_tokens () == c->name_tokens ()); + assert (r->ncname () == c->ncname ()); + assert (r->language () == c->language ()); + + // qualified name + // + assert (r->qname () == c->qname ()); + + // ID/IDREF + // + assert (r->id () == c->id ()); + assert (r->id_ref () == c->id_ref ()); + assert (r->id_refs () == c->id_refs ()); + + // URI + // + assert (r->any_uri () == c->any_uri ()); + + // binary + // + assert (r->base64_binary () == c->base64_binary ()); + assert (r->hex_binary () == c->hex_binary ()); + + // date/time + // + assert (r->day () == c->day ()); + assert (r->month () == c->month ()); + assert (r->year () == c->year ()); + assert (r->month_day () == c->month_day ()); + assert (r->year_month () == c->year_month ()); + assert (r->date () == c->date ()); + assert (r->time () == c->time ()); + assert (r->date_time () == c->date_time ()); + assert (r->duration () == c->duration ()); + } + catch (xml_schema::exception const& e) + { + cerr << e << endl; + return 1; + } +} diff --git a/tests/cxx/tree/binary/cdr/makefile b/tests/cxx/tree/binary/cdr/makefile new file mode 100644 index 0000000..3298f18 --- /dev/null +++ b/tests/cxx/tree/binary/cdr/makefile @@ -0,0 +1,86 @@ +# file : tests/cxx/tree/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)) +dep := $(obj:.o=.o.d) + +driver := $(out_base)/driver +test := $(out_base)/.test +clean := $(out_base)/.clean + + +# Import. +# +$(call import,\ + $(scf_root)/import/libxerces-c/stub.make,\ + l: xerces_c.l,cpp-options: xerces_c.l.cpp-options) + +$(call import,\ + $(scf_root)/import/libace/stub.make,\ + l: ace.l,cpp-options: ace.l.cpp-options) + +# Build. +# +$(driver): $(obj) $(xerces_c.l) $(ace.l) + +$(obj) $(dep): cpp_options := -I$(src_root)/libxsd +$(obj) $(dep): $(xerces_c.l.cpp-options) $(ace.l.cpp-options) + +$(out_base)/$(xsd:.xsd=.hxx) \ +$(out_base)/$(xsd:.xsd=.ixx) \ +$(out_base)/$(xsd:.xsd=.cxx): xsd := $(out_root)/xsd/xsd + +$(out_base)/$(xsd:.xsd=.hxx) \ +$(out_base)/$(xsd:.xsd=.ixx) \ +$(out_base)/$(xsd:.xsd=.cxx): xsd_options := \ +--generate-insertion ACE_OutputCDR \ +--generate-extraction ACE_InputCDR + +$(out_base)/$(xsd:.xsd=.hxx) \ +$(out_base)/$(xsd:.xsd=.ixx) \ +$(out_base)/$(xsd:.xsd=.cxx): $(out_root)/xsd/xsd + +$(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 + $(call message,test $$1,$$1 $(src_base)/test.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)) + + +# 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)/xsd/tree/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/tests/cxx/tree/binary/cdr/test.xml b/tests/cxx/tree/binary/cdr/test.xml new file mode 100644 index 0000000..928b4cf --- /dev/null +++ b/tests/cxx/tree/binary/cdr/test.xml @@ -0,0 +1,91 @@ + + + 1 2 3 + + abc + + left + + + aaa + + + aaa + bbb + c + cc + ccc + + + + + 65 + 66 + -222 + 57005 + -57005 + 3735928559 + -3735928559 + 16045690984833335023 + -3735928559 + -3735928559 + 3735928559 + 3735928559 + -3735928559 + + + + 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/tree/binary/cdr/test.xsd b/tests/cxx/tree/binary/cdr/test.xsd new file mode 100644 index 0000000..e593f64 --- /dev/null +++ b/tests/cxx/tree/binary/cdr/test.xsd @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.1