From 76d23e639004517db8f9469d64ac1789f8449365 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Jan 2010 13:50:11 +0200 Subject: Add support for ISO-8859-1 as application encoding New runtime configuration parameter, XSDE_ENCODING. New option, --char-encoding. New test, tests/cxx/hybrid/iso8859-1. --- tests/cxx/hybrid/iso8859-1/driver.cxx | 95 ++++++++++++++++++++++++++++ tests/cxx/hybrid/iso8859-1/makefile | 108 ++++++++++++++++++++++++++++++++ tests/cxx/hybrid/iso8859-1/test-000.std | 1 + tests/cxx/hybrid/iso8859-1/test-000.xml | 15 +++++ tests/cxx/hybrid/iso8859-1/test.xsd | 23 +++++++ tests/cxx/hybrid/makefile | 6 +- 6 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 tests/cxx/hybrid/iso8859-1/driver.cxx create mode 100644 tests/cxx/hybrid/iso8859-1/makefile create mode 100644 tests/cxx/hybrid/iso8859-1/test-000.std create mode 100644 tests/cxx/hybrid/iso8859-1/test-000.xml create mode 100644 tests/cxx/hybrid/iso8859-1/test.xsd (limited to 'tests') diff --git a/tests/cxx/hybrid/iso8859-1/driver.cxx b/tests/cxx/hybrid/iso8859-1/driver.cxx new file mode 100644 index 0000000..ec68dbf --- /dev/null +++ b/tests/cxx/hybrid/iso8859-1/driver.cxx @@ -0,0 +1,95 @@ +// file : tests/cxx/hybrid/iso8859-1/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test support for the ISO-8859-1 encoding. +// + +#include + +#include +#include + +#include "test.hxx" +#include "test-pimpl.hxx" +#include "test-simpl.hxx" + +#include + +using namespace std; +using namespace test; + +int +main (int argc, char* argv[]) +{ + 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 ()); + +#ifdef XSDE_EXCEPTIONS + try + { + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + assert (false); + } + catch (const xml_schema::parser_exception& e) + { + // cerr << e.line () << ":" << e.column () << ": " << e.text () << endl; + } +#else + root_p.pre (); + doc_p.parse (argv[1]); + assert (doc_p._error ()); +#endif + + doc_p.reset (); + xml_schema::iso8859_1::unrep_char ('?'); + + root_p.pre (); + doc_p.parse (argv[1]); + type* r = root_p.post (); + + assert (r->a ()[0] == string ("abc")); + assert (r->a ()[1] == string ("\xE6")); + assert (r->a ()[2] == string ("\xA2\xA3\xA4\xA5")); + assert (r->a ()[3] == string ("???")); + assert (r->a ()[4] == string ("longlonglonglonglonglonglonglonglonglonglonglong\xE6longlonglonglong")); + + assert (r->b ()[0] == strenum::abc); + assert (r->b ()[1] == strenum::a_c); + assert (r->b ()[1].string () == string ("a\xE2""c")); + assert (r->b ()[2] == strenum::cxx__bc); + + assert (r->element_name_with_special_char__ () == string ("longlonglong\xA2\xA3\xA4\xA5longlong")); + + // 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 (*r); + doc_s.serialize (cout); + root_s.post (); + + delete r; +} diff --git a/tests/cxx/hybrid/iso8859-1/makefile b/tests/cxx/hybrid/iso8859-1/makefile new file mode 100644 index 0000000..2cc1f57 --- /dev/null +++ b/tests/cxx/hybrid/iso8859-1/makefile @@ -0,0 +1,108 @@ +# file : tests/cxx/hybrid/iso8859-1/makefile +# author : Boris Kolpackov +# copyright : Copyright (c) 2006-2010 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 +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) $(dist) $(dist-win): xsde_options += --generate-parser \ +--generate-serializer --generate-aggregate + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) $(src_base)/test-000.xml $(src_base)/test-000.std + $(call message,test $$1,$$1 $(src_base)/test-000.xml | diff -u $(src_base)/test-000.std -,$(driver)) + + +# Dist. +# +$(dist) $(dist-win): opt := -src $(src_base) -cmd cxx-hybrid -xsd "$(xsd)" \ +-cxx "$(cxx)" -gen "$(genf)" -opt "$(xsde_options)" -out $(dist_prefix) + +$(dist): + $(call message,install $(src_base),$(scf_root)/dist $(opt)) + +$(dist-win): + $(call message,install $(src_base),$(scf_root)/dist -win $(opt)) + + +# 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/iso8859-1/test-000.std b/tests/cxx/hybrid/iso8859-1/test-000.std new file mode 100644 index 0000000..2631b99 --- /dev/null +++ b/tests/cxx/hybrid/iso8859-1/test-000.std @@ -0,0 +1 @@ +abc梣¤¥???longlonglonglonglonglonglonglonglonglonglonglongælonglonglonglongabcaâcâòbclonglonglong¢£¤¥longlong \ No newline at end of file diff --git a/tests/cxx/hybrid/iso8859-1/test-000.xml b/tests/cxx/hybrid/iso8859-1/test-000.xml new file mode 100644 index 0000000..fd61446 --- /dev/null +++ b/tests/cxx/hybrid/iso8859-1/test-000.xml @@ -0,0 +1,15 @@ + + + abc + æ + ¢£¤¥ + Āꪪ򪪪 + longlonglonglonglonglonglonglonglonglonglonglongælonglonglonglong + + abc + aâc + âòbc + + longlonglong¢£¤¥longlong + + diff --git a/tests/cxx/hybrid/iso8859-1/test.xsd b/tests/cxx/hybrid/iso8859-1/test.xsd new file mode 100644 index 0000000..242b84a --- /dev/null +++ b/tests/cxx/hybrid/iso8859-1/test.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile index 60960c3..8fb3f3f 100644 --- a/tests/cxx/hybrid/makefile +++ b/tests/cxx/hybrid/makefile @@ -10,7 +10,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make # all_tests := sequences polymorphism iterator built-in default enumeration \ -list recursive test-template union binary/cdr binary/xdr choice +iso8859-1 list recursive test-template union binary/cdr binary/xdr choice build_tests := sequences @@ -27,6 +27,10 @@ endif ifeq ($(xsde_iostream),y) build_tests += built-in default enumeration list test-template union +ifeq ($(xsde_encoding),iso8859-1) +build_tests += iso8859-1 +endif + ifeq ($(xsde_cdr),y) build_tests += binary/cdr endif -- cgit v1.1