From 1ca6396a3dd284241de11bcaa210ad5836e8e5a8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 8 Dec 2009 16:18:01 +0200 Subject: Multiple object model character encodings support Also add support for ISO-8859-1. --- tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx | 76 ++++++++++++++++++++ tests/cxx/tree/encoding/char/iso-8859-1/makefile | 83 ++++++++++++++++++++++ tests/cxx/tree/encoding/char/iso-8859-1/test.std | 18 +++++ tests/cxx/tree/encoding/char/iso-8859-1/test.xml | 14 ++++ tests/cxx/tree/encoding/char/iso-8859-1/test.xsd | 31 ++++++++ tests/cxx/tree/encoding/char/lcp/driver.cxx | 2 +- tests/cxx/tree/encoding/char/lcp/makefile | 4 +- tests/cxx/tree/encoding/char/makefile | 2 +- tests/cxx/tree/encoding/char/utf-8/makefile | 2 +- 9 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx create mode 100644 tests/cxx/tree/encoding/char/iso-8859-1/makefile create mode 100644 tests/cxx/tree/encoding/char/iso-8859-1/test.std create mode 100644 tests/cxx/tree/encoding/char/iso-8859-1/test.xml create mode 100644 tests/cxx/tree/encoding/char/iso-8859-1/test.xsd (limited to 'tests/cxx/tree/encoding') diff --git a/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx b/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx new file mode 100644 index 0000000..9bd5725 --- /dev/null +++ b/tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx @@ -0,0 +1,76 @@ +// file : tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test ISO-8859-1 encoding. +// + +#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 + { + try + { + root (argv[1]); + return 1; + } + catch (xsd::cxx::xml::iso8859_1_unrepresentable const&) + { + } + + xsd::cxx::xml::char_transcoder::unrep_char ('?'); + auto_ptr r (root (argv[1])); + + { + type::a_sequence const& s (r->a ()); + + if (s[0] != "abc" || + s[1] != "\xE6" || + s[2] != "\xA2\xA3\xA4\xA5" || + s[3] != "???") + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + { + type::b_sequence const& s (r->b ()); + + if (s[0] != strenum::abc || + s[1] != strenum::a_c || + s[2] != strenum::cxx__bc) + { + cerr << "invalid encoding" << endl; + return 1; + } + } + + xml_schema::namespace_infomap map; + map["t"].name = "test"; + + root (std::cout, *r, map, "ISO-8859-1"); + } + catch (xml_schema::exception const& e) + { + cerr << "xml_schema::exception: " << e.what () << endl; + return 1; + } +} diff --git a/tests/cxx/tree/encoding/char/iso-8859-1/makefile b/tests/cxx/tree/encoding/char/iso-8859-1/makefile new file mode 100644 index 0000000..dd48fc1 --- /dev/null +++ b/tests/cxx/tree/encoding/char/iso-8859-1/makefile @@ -0,0 +1,83 @@ +# file : tests/cxx/tree/encoding/char/iso-8859-1/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) + + +# Build. +# +$(driver): $(obj) $(xerces_c.l) + +$(obj) $(dep): cpp_options := -I$(src_root)/libxsd +$(obj) $(dep): $(xerces_c.l.cpp-options) + +genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): xsd := $(out_root)/xsd/xsd +$(gen): xsd_options := --char-encoding iso8859-1 --generate-serialization \ +--generate-doxygen +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test.xml $(src_base)/test.std + $(call message,test $$1,$$1 $(src_base)/test.xml | diff -u $(src_base)/test.std -,$(driver)) + +# 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)/xsd/tree/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/tests/cxx/tree/encoding/char/iso-8859-1/test.std b/tests/cxx/tree/encoding/char/iso-8859-1/test.std new file mode 100644 index 0000000..ca6297f --- /dev/null +++ b/tests/cxx/tree/encoding/char/iso-8859-1/test.std @@ -0,0 +1,18 @@ + + + + abc + + æ + + ¢£¤¥ + + ??? + + abc + + aâc + + âòbc + + diff --git a/tests/cxx/tree/encoding/char/iso-8859-1/test.xml b/tests/cxx/tree/encoding/char/iso-8859-1/test.xml new file mode 100644 index 0000000..9c9e752 --- /dev/null +++ b/tests/cxx/tree/encoding/char/iso-8859-1/test.xml @@ -0,0 +1,14 @@ + + + abc + æ + ¢£¤¥ + Āꪪ򪪪 + + abc + aâc + âòbc + + diff --git a/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd b/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd new file mode 100644 index 0000000..31b8901 --- /dev/null +++ b/tests/cxx/tree/encoding/char/iso-8859-1/test.xsd @@ -0,0 +1,31 @@ + + + + + + + + Test enum. Valid values are: + abc + aâc + òbc + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cxx/tree/encoding/char/lcp/driver.cxx b/tests/cxx/tree/encoding/char/lcp/driver.cxx index 3d30aa9..7bc4a2d 100644 --- a/tests/cxx/tree/encoding/char/lcp/driver.cxx +++ b/tests/cxx/tree/encoding/char/lcp/driver.cxx @@ -3,7 +3,7 @@ // copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC // license : GNU GPL v2 + exceptions; see accompanying LICENSE file -// Test local code page encoding (XSD_USE_LCP defined). +// Test local code page encoding (--char-encoding lcp). // The test just makes sure it still compiles and works. // diff --git a/tests/cxx/tree/encoding/char/lcp/makefile b/tests/cxx/tree/encoding/char/lcp/makefile index 9520a42..324e331 100644 --- a/tests/cxx/tree/encoding/char/lcp/makefile +++ b/tests/cxx/tree/encoding/char/lcp/makefile @@ -27,14 +27,14 @@ $(call import,\ # $(driver): $(obj) $(xerces_c.l) -$(obj) $(dep): cpp_options := -I$(src_root)/libxsd -DXSD_USE_LCP +$(obj) $(dep): cpp_options := -I$(src_root)/libxsd $(obj) $(dep): $(xerces_c.l.cpp-options) genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.ixx) $(xsd:.xsd=.cxx) gen := $(addprefix $(out_base)/,$(genf)) $(gen): xsd := $(out_root)/xsd/xsd -$(gen): xsd_options := --generate-serialization +$(gen): xsd_options := --generate-serialization --char-encoding lcp $(gen): $(out_root)/xsd/xsd $(call include-dep,$(dep)) diff --git a/tests/cxx/tree/encoding/char/makefile b/tests/cxx/tree/encoding/char/makefile index 78b6e7a..ef25ad3 100644 --- a/tests/cxx/tree/encoding/char/makefile +++ b/tests/cxx/tree/encoding/char/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../build/bootstrap.make -tests := lcp utf-8 +tests := lcp utf-8 iso-8859-1 default := $(out_base)/ test := $(out_base)/.test diff --git a/tests/cxx/tree/encoding/char/utf-8/makefile b/tests/cxx/tree/encoding/char/utf-8/makefile index 9fbbc7c..da5d7b4 100644 --- a/tests/cxx/tree/encoding/char/utf-8/makefile +++ b/tests/cxx/tree/encoding/char/utf-8/makefile @@ -1,4 +1,4 @@ -# file : tests/cxx/tree/encoding/char/lcp/makefile +# file : tests/cxx/tree/encoding/char/utf-8/makefile # author : Boris Kolpackov # copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC # license : GNU GPL v2 + exceptions; see accompanying LICENSE file -- cgit v1.1