summaryrefslogtreecommitdiff
path: root/tests/cxx/tree
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-12-08 16:18:01 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-12-08 16:18:01 +0200
commit1ca6396a3dd284241de11bcaa210ad5836e8e5a8 (patch)
tree465c19f0d668a91bb556d748911847acfb80cb09 /tests/cxx/tree
parentd71611d5fb575078bdf573c35257bb86bb7054e0 (diff)
Multiple object model character encodings support
Also add support for ISO-8859-1.
Diffstat (limited to 'tests/cxx/tree')
-rw-r--r--tests/cxx/tree/encoding/char/iso-8859-1/driver.cxx76
-rw-r--r--tests/cxx/tree/encoding/char/iso-8859-1/makefile83
-rw-r--r--tests/cxx/tree/encoding/char/iso-8859-1/test.std18
-rw-r--r--tests/cxx/tree/encoding/char/iso-8859-1/test.xml14
-rw-r--r--tests/cxx/tree/encoding/char/iso-8859-1/test.xsd31
-rw-r--r--tests/cxx/tree/encoding/char/lcp/driver.cxx2
-rw-r--r--tests/cxx/tree/encoding/char/lcp/makefile4
-rw-r--r--tests/cxx/tree/encoding/char/makefile2
-rw-r--r--tests/cxx/tree/encoding/char/utf-8/makefile2
9 files changed, 227 insertions, 5 deletions
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 <boris@codesynthesis.com>
+// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+// Test ISO-8859-1 encoding.
+//
+
+#include <memory> // std::auto_ptr
+#include <fstream>
+#include <iostream>
+
+#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<type> 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 <boris@codesynthesis.com>
+# 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 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
+<t:root xmlns:t="test">
+
+ <a>abc</a>
+
+ <a>æ</a>
+
+ <a>¢£¤¥</a>
+
+ <a>???</a>
+
+ <b>abc</b>
+
+ <b>aâc</b>
+
+ <b>âòbc</b>
+
+</t:root>
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 @@
+<t:root xmlns:t="test"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="test test.xsd">
+
+ <a>abc</a>
+ <a>&#xE6;</a>
+ <a>&#xA2;&#xA3;&#xA4;&#xA5;</a>
+ <a>&#x100;&#xAAAA;&#xAAAAA;</a>
+
+ <b>abc</b>
+ <b>a&#xE2;c</b>
+ <b>&#xE2;&#xF2;bc</b>
+
+</t:root>
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 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <simpleType name="strenum">
+
+ <annotation>
+ <documentation>
+ Test enum. Valid values are:
+ abc
+ a&#xE2;c
+ &#xF2;bc
+ </documentation>
+ </annotation>
+
+ <restriction base="string">
+ <enumeration value="abc"/>
+ <enumeration value="a&#xE2;c"/>
+ <enumeration value="&#xE2;&#xF2;bc"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="a" type="string" maxOccurs="unbounded"/>
+ <element name="b" type="t:strenum" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>
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 <boris@codesynthesis.com>
# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
# license : GNU GPL v2 + exceptions; see accompanying LICENSE file