diff options
Diffstat (limited to 'xsd/tests/cxx/parser/validation/built-in')
30 files changed, 4932 insertions, 0 deletions
| diff --git a/xsd/tests/cxx/parser/validation/built-in/any-type/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/any-type/driver.cxx new file mode 100644 index 0000000..46ccc96 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/any-type/driver.cxx @@ -0,0 +1,156 @@ +// file      : tests/cxx/parser/validation/built-in/any-type/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the anyType and anySimpleType validation. +// + +#include <string> +#include <fstream> +#include <iostream> + +#include "test-pskel.hxx" + +using namespace std; +using namespace test; +using xml_schema::ro_string; + +struct any_type_pimpl: xml_schema::any_type_pimpl +{ +  virtual void +  pre () +  { +    cout << "{" << endl; +  } + +  virtual void +  _start_any_element (ro_string const&,  +                      ro_string const& n, +		      ro_string const*) +  { +    cout << "  start any element '" << n << "'" << endl; +  } + +  virtual void +  _end_any_element (ro_string const&, ro_string const& n) +  { +    cout << "  end any element '" << n << "'" << endl; +  } + +  virtual void +  _any_attribute (ro_string const&, +                  ro_string const& n, +		  ro_string const& v) +  { +    cout << "  any attribute " << n << " = '" << v << "'" << endl; +  } + +  virtual void +  _any_characters (ro_string const& s) +  { +    cout << "  any text: '" << s << "'" << endl; +  } + +  virtual void +  post_any_type () +  { +    cout << "}" << endl +         << endl; +  } +}; + +struct any_simple_type_pimpl: xml_schema::any_simple_type_pimpl +{ +  virtual void +  pre () +  { +    cout << "{" << endl; +  } + +  virtual void +  _any_characters (ro_string const& s) +  { +    cout << "  any text: '" << s << "'" << endl; +  } + +  virtual void +  post_any_simple_type () +  { +    cout << "}" << endl +         << endl; +  } +}; + +struct any_extension_pimpl: virtual any_extension_pskel, +                            any_type_pimpl + +{ +  virtual void +  x (const string& v) +  { +    cout << "  x = " << v << endl; +  } +}; + +struct any_simple_extension_pimpl: virtual any_simple_extension_pskel, +                                   any_simple_type_pimpl +{ +  virtual void +  x (const string& v) +  { +    cout << "  x = " << v << endl; +  } +}; + +struct type_pimpl: type_pskel +{ +}; + +int +main (int argc, char* argv[]) +{ +  if (argc != 2) +  { +    cerr << "usage: " << argv[0] << " test.xml" << endl; +    return 1; +  } + +  try +  { +    xml_schema::string_pimpl string_p; + +    any_type_pimpl any_type_p; +    any_simple_type_pimpl any_simple_type_p; + +    any_extension_pimpl any_extension_p; +    any_simple_extension_pimpl any_simple_extension_p; + +    type_pimpl type_p; + +    any_extension_p.parsers (string_p); +    any_simple_extension_p.parsers (string_p); + +    type_p.parsers (any_type_p, +                    any_extension_p, +                    any_simple_extension_p, +                    any_simple_type_p); + +    xml_schema::document doc_p (type_p, "test", "root"); + +    ifstream ifs (argv[1]); +    type_p.pre (); +    doc_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate); +    type_p.post_type (); +  } +  catch (xml_schema::exception const& e) +  { +    cerr << e << endl; +    return 1; +  } +  catch (ios_base::failure const&) +  { +    cerr << "io failure" << endl; +    return 1; +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/any-type/makefile b/xsd/tests/cxx/parser/validation/built-in/any-type/makefile new file mode 100644 index 0000000..bf42aac --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/any-type/makefile @@ -0,0 +1,89 @@ +# file      : tests/cxx/parser/validation/built-in/any-type/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +tests := 000 + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=-pskel.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=-pskel.hxx) $(xsd:.xsd=-pskel.ixx) $(xsd:.xsd=-pskel.cxx) +gen  := $(addprefix $(out_base)/,$(genf)) + +$(gen): xsd := $(out_root)/xsd/xsd +$(gen): xsd_options := --generate-validation +$(gen): $(out_root)/xsd/xsd + +$(call include-dep,$(dep)) + + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +test_targets := $(addprefix $(out_base)/.test-,$(tests)) + +$(test): $(test_targets) +$(test_targets): driver := $(driver) + +.PHONY: $(out_base)/.test-% +$(out_base)/.test-%: $(driver) $(src_base)/test.xsd $(src_base)/test-%.xml $(src_base)/test-%.std +	$(call message,test $(out_base)/$*,$(driver) $(src_base)/test-$*.xml | diff -u $(src_base)/test-$*.std -) + + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep))                           \ +  $(addprefix $(out_base)/,$(xsd:.xsd=-pskel.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/parser/xsd-cxx.make) + + +# Dependencies. +# +$(call import,$(src_root)/xsd/makefile) diff --git a/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.std b/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.std new file mode 100644 index 0000000..84d7b3a --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.std @@ -0,0 +1,99 @@ +{ +  any text: '123abc' +} + +{ +  any text: ' +    ' +  start any element 'any' +  end any element 'any' +  any text: ' +  ' +} + +{ +  any text: ' +    ' +  start any element 'any' +  any attribute x = 'xxx' +  any text: 'aaa' +  start any element 'a' +  any text: 'bbb' +  end any element 'a' +  any text: 'ccc' +  end any element 'any' +  any text: ' +  ' +} + +{ +  any attribute x = 'x' +  any text: ' +    ' +  start any element 'a' +  any text: 'a' +  end any element 'a' +  any text: ' +    ' +  start any element 'any' +  any attribute x = 'xxx' +  any text: 'aaa' +  start any element 'a' +  any text: 'bbb' +  end any element 'a' +  any text: 'ccc' +  end any element 'any' +  any text: ' +  ' +} + +{ +  any text: ' +    ' +  start any element 'any' +  end any element 'any' +  any text: ' +  ' +} + +{ +  any text: ' +    ' +  start any element 'any' +  any attribute x = 'xxx' +  any text: 'aaa' +  start any element 'a' +  any text: 'bbb' +  end any element 'a' +  any text: 'ccc' +  end any element 'any' +  any text: ' +  ' +} + +{ +  x = x +  any text: ' +    ' +  start any element 'a' +  any text: 'a' +  end any element 'a' +  any text: ' +    ' +  start any element 'any' +  any attribute x = 'xxx' +  any text: 'aaa' +  start any element 'a' +  any text: 'bbb' +  end any element 'a' +  any text: 'ccc' +  end any element 'any' +  any text: ' +  ' +} + +{ +  x = x +  any text: 'abc123' +} + diff --git a/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.xml b/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.xml new file mode 100644 index 0000000..7875b7e --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/any-type/test-000.xml @@ -0,0 +1,41 @@ +<t:root xmlns:t="test" +        xmlns:o="other" +        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +        xsi:schemaLocation="test test.xsd" +        as="123abc"> + +  <!-- test dispatching of anyType nested elements and attributes --> + +  <a> +    <o:any/> +  </a> + +  <a> +    <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> +  </a> + +  <a x="x"> +    <a>a</a> +    <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> +  </a> + +  <!-- anyType extension --> + +  <a-extension> +    <o:any/> +  </a-extension> + +  <a-extension> +    <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> +  </a-extension> + +  <a-extension x="x"> +    <a>a</a> +    <o:any x="xxx">aaa<a>bbb</a>ccc</o:any> +  </a-extension> + +  <!-- anySimpleType extension --> + +  <as-extension x="x">abc123</as-extension> + +</t:root> diff --git a/xsd/tests/cxx/parser/validation/built-in/any-type/test.xsd b/xsd/tests/cxx/parser/validation/built-in/any-type/test.xsd new file mode 100644 index 0000000..86a4e13 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/any-type/test.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test"> + +  <complexType name="any-extension"> +    <complexContent mixed="true"> +      <extension base="anyType"> +	<attribute name="x" type="string"/> +      </extension> +    </complexContent> +  </complexType> + +  <complexType name="any-simple-extension"> +    <simpleContent> +      <extension base="anySimpleType"> +	<attribute name="x" type="string"/> +      </extension> +    </simpleContent> +  </complexType> + +  <complexType name="type"> +    <choice maxOccurs="unbounded"> +      <element name="a" type="anyType"/> +      <element name="a-extension" type="t:any-extension"/> +      <element name="as-extension" type="t:any-simple-extension"/> +    </choice> +    <attribute name="as" type="anySimpleType"/> +  </complexType> + +  <element name="root" type="t:type"/> + +</schema> diff --git a/xsd/tests/cxx/parser/validation/built-in/binary/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/binary/driver.cxx new file mode 100644 index 0000000..e75d55f --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/binary/driver.cxx @@ -0,0 +1,155 @@ +// file      : tests/cxx/parser/validation/built-in/binary/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in base64Binary and hexBinary types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  typedef xsd::cxx::parser::buffer buffer; + +  // Good. +  // + +  // hexBinary +  // +  { +    hex_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("  "); +    p._post (); +    assert (*p.post_hex_binary () == buffer ()); +  } + +  { +    hex_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n313"); +    p._characters ("23334356162636a6b  "); +    p._post (); +    assert (*p.post_hex_binary () == buffer ("12345abcjk", 10)); +  } + +  // base64Binary +  // +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("MTIzND  "); +    p._characters ("VhYmNqaw = = "); +    p._post (); +    assert (*p.post_base64_binary () == buffer ("12345abcjk", 10)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("YQ=="); +    p._post (); +    assert (*p.post_base64_binary () == buffer ("a", 1)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("YWI="); +    p._post (); +    assert (*p.post_base64_binary () == buffer ("ab", 2)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("YWJj"); +    p._post (); +    assert (*p.post_base64_binary () == buffer ("abc", 3)); +  } + +  // Bad +  // + +  // hexBinary +  // +  { +    hex_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("313"); +    assert (test_post_fail (p)); +  } + +  { +    hex_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("313233343X6162636a6b"); +    assert (test_post_fail (p)); +  } + +  // base64Binary +  // +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("YQ"); +    assert (test_post_fail (p)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("=="); +    assert (test_post_fail (p)); +  } + +  { +    base64_binary_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("MTIzNDVhYmNqaw=A"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/binary/makefile b/xsd/tests/cxx/parser/validation/built-in/binary/makefile new file mode 100644 index 0000000..b729cd0 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/binary/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/binary/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/boolean/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/boolean/driver.cxx new file mode 100644 index 0000000..85586a6 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/boolean/driver.cxx @@ -0,0 +1,147 @@ +// file      : tests/cxx/parser/validation/built-in/boolean/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in boolean type validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +bool +test_post_fail (boolean_pimpl<char>& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("true"); +    p._post (); +    assert (p.post_boolean ()); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1"); +    p._post (); +    assert (p.post_boolean ()); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("false"); +    p._post (); +    assert (!p.post_boolean ()); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (!p.post_boolean ()); +  } + + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("  true  "); +    p._post (); +    assert (p.post_boolean ()); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" "); +    p._characters (" \n  "); +    p._characters ("   fa"); +    p._characters ("l"); +    p._characters ("se   "); +    p._characters (" \n  "); +    p._characters (" "); +    p._post (); +    assert (!p.post_boolean ()); +  } + +  // Bad +  // +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    //p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("  "); +    assert (test_post_fail (p)); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("                        "); +    assert (test_post_fail (p)); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("fal"); +    p._characters ("s   "); +    p._characters ("e"); +    assert (test_post_fail (p)); +  } + +  { +    boolean_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("01"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/boolean/makefile b/xsd/tests/cxx/parser/validation/built-in/boolean/makefile new file mode 100644 index 0000000..39ca5e9 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/boolean/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/boolean/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/byte/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/byte/driver.cxx new file mode 100644 index 0000000..466f004 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/byte/driver.cxx @@ -0,0 +1,258 @@ +// file      : tests/cxx/parser/validation/built-in/byte/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in byte and unsigned byte types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("123"); +    p._post (); +    assert (p.post_byte () == 123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("\t +123 \n "); +    p._post (); +    assert (p.post_byte () == 123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-123"); +    p._post (); +    assert (p.post_byte () == -123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+123"); +    p._post (); +    assert (p.post_byte () == 123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0000000000000000123"); +    p._post (); +    assert (p.post_byte () == 123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+0000000000000000123"); +    p._post (); +    assert (p.post_byte () == 123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0000000000000000123"); +    p._post (); +    assert (p.post_byte () == -123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("\t \n"); +    p._characters (" -"); +    p._characters ("00000"); +    p._characters ("001"); +    p._characters ("23   \n\t"); +    p._post (); +    assert (p.post_byte () == -123); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-128"); +    p._post (); +    assert (p.post_byte () == -128); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("127"); +    p._post (); +    assert (p.post_byte () == 127); +  } + +  { +    unsigned_byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+123"); +    p._post (); +    assert (p.post_unsigned_byte () == 123); +  } + +  { +    unsigned_byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_unsigned_byte () == 0); +  } + +  { +    unsigned_byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("255"); +    p._post (); +    assert (p.post_unsigned_byte () == 255); +  } + +  // Bad +  // +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n \t "); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+"); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-"); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("++01"); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--01"); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-01"); +    p._characters ("    "); +    p._characters ("23    "); +    assert (test_post_fail (p)); +  } + +  { +    unsigned_byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-123"); +    assert (test_post_fail (p)); +  } + +  // Ranges +  // +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-129"); +    assert (test_post_fail (p)); +  } + +  { +    byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("128"); +    assert (test_post_fail (p)); +  } + +  { +    unsigned_byte_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("256"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/byte/makefile b/xsd/tests/cxx/parser/validation/built-in/byte/makefile new file mode 100644 index 0000000..32f4b91 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/byte/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/byte/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/date-time/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/date-time/driver.cxx new file mode 100644 index 0000000..6297912 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/date-time/driver.cxx @@ -0,0 +1,1535 @@ +// file      : tests/cxx/parser/validation/built-in/date-time/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in date and time types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  typedef xsd::cxx::parser::gday gday; +  typedef xsd::cxx::parser::gmonth gmonth; +  typedef xsd::cxx::parser::gyear gyear; +  typedef xsd::cxx::parser::gmonth_day gmonth_day; +  typedef xsd::cxx::parser::gyear_month gyear_month; +  typedef xsd::cxx::parser::date date; +  typedef xsd::cxx::parser::time time; +  typedef xsd::cxx::parser::date_time date_time; +  typedef xsd::cxx::parser::duration duration; + +  // Good. +  // + +  // gday & time zone parsing +  // +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("---1"); +    p._characters ("2+12:00"); +    p._post (); +    assert (p.post_gday () == gday (12, 12, 00)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---01"); +    p._post (); +    assert (p.post_gday () == gday (1)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---31"); +    p._post (); +    assert (p.post_gday () == gday (31)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---15Z"); +    p._post (); +    assert (p.post_gday () == gday (15, 0, 0)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---15-14:00"); +    p._post (); +    assert (p.post_gday () == gday (15, -14, 0)); +  } + +  // gmonth +  // +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("--1"); +    p._characters ("0+12:00"); +    p._post (); +    assert (p.post_gmonth () == gmonth (10, 12, 0)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--01"); +    p._post (); +    assert (p.post_gmonth () == gmonth (1)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12Z"); +    p._post (); +    assert (p.post_gmonth () == gmonth (12, 0, 0)); +  } + +  // gyear +  // +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("20"); +    p._characters ("07+12:00"); +    p._post (); +    assert (p.post_gyear () == gyear (2007, 12, 00)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0001"); +    p._post (); +    assert (p.post_gyear () == gyear (1)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-20000Z"); +    p._post (); +    assert (p.post_gyear () == gyear (-20000, 0, 0)); +  } + +  // gmonth_day +  // +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("--1"); +    p._characters ("0-28+12:00  "); +    p._post (); +    assert (p.post_gmonth_day () == gmonth_day (10, 28, 12, 00)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12-31"); +    p._post (); +    assert (p.post_gmonth_day () == gmonth_day (12, 31)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--01-01Z"); +    p._post (); +    assert (p.post_gmonth_day () == gmonth_day (1, 1, 0, 0)); +  } + +  // gyear_month +  // +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("200"); +    p._characters ("7-12+12:00  "); +    p._post (); +    assert (p.post_gyear_month () == gyear_month (2007, 12, 12, 00)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2007-10"); +    p._post (); +    assert (p.post_gyear_month () == gyear_month (-2007, 10)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20007-10Z"); +    p._post (); +    assert (p.post_gyear_month () == gyear_month (20007, 10, 0, 0)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-20007-01"); +    p._post (); +    assert (p.post_gyear_month () == gyear_month (-20007, 1)); +  } + +  // date +  // +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("200"); +    p._characters ("7-12-26+12:00  "); +    p._post (); +    assert (p.post_date () == date (2007, 12, 26, 12, 0)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2007-10-15"); +    p._post (); +    assert (p.post_date () == date (-2007, 10, 15)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20007-12-31Z"); +    p._post (); +    assert (p.post_date () == date (20007, 12, 31, 0, 0)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-20007-01-01"); +    p._post (); +    assert (p.post_date () == date (-20007, 1, 1)); +  } + +  // time +  // +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("12:"); +    p._characters ("46:23.456+12:00  "); +    p._post (); +    assert (p.post_time () == time (12, 46, 23.456, 12, 0)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("12:13:14"); +    p._post (); +    assert (p.post_time () == time (12, 13, 14.0)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("12:13:14Z"); +    p._post (); +    assert (p.post_time () == time (12, 13, 14.0, 0, 0)); +  } + +  // date_time +  // +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("200"); +    p._characters ("7-12-26T12:13:14.123+12:00  "); +    p._post (); +    assert (p.post_date_time () == +            date_time (2007, 12, 26, 12, 13, 14.123, 12, 0)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2007-10-15T12:13:14"); +    p._post (); +    assert (p.post_date_time () == date_time (-2007, 10, 15, 12, 13, 14.0)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20007-12-31T12:13:14Z"); +    p._post (); +    assert (p.post_date_time () == +            date_time (20007, 12, 31, 12, 13, 14.0, 0, 0)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-20007-01-01T12:13:14"); +    p._post (); +    assert (p.post_date_time () == date_time (-20007, 1, 1, 12, 13, 14.0)); +  } + +  // duration +  // +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \t\n "); +    p._characters ("-P200"); +    p._characters ("7Y13M32DT25H61M61.123S  "); +    p._post (); +    assert (p.post_duration () == +            duration (true, 2007, 13, 32, 25, 61, 61.123)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1Y"); +    p._post (); +    assert (p.post_duration () == duration (false, 1, 0, 0, 0, 0, 0.0)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1M"); +    p._post (); +    assert (p.post_duration () == duration (false, 0, 1, 0, 0, 0, 0.0)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1D"); +    p._post (); +    assert (p.post_duration () == duration (false, 0, 0, 1, 0, 0, 0.0)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT1H"); +    p._post (); +    assert (p.post_duration () == duration (false, 0, 0, 0, 1, 0, 0.0)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT1M"); +    p._post (); +    assert (p.post_duration () == duration (false, 0, 0, 0, 0, 1, 0.0)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT1.1S"); +    p._post (); +    assert (p.post_duration () == duration (false, 0, 0, 0, 0, 0, 1.1)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1YT1S"); +    p._post (); +    assert (p.post_duration () == duration (false, 1, 0, 0, 0, 0, 1.0)); +  } + +  // Bad +  // + +  // gday & time zone parsing +  // +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---1"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---00"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---32"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---2X"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12asd"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12X"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---1212:00"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12+2:00"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12+1200"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12+15:00"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12+12:60"); +    assert (test_post_fail (p)); +  } + +  { +    gday_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("---12+14:01"); +    assert (test_post_fail (p)); +  } + +  // gmonth +  // +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-12"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--00"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--13"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--1X"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--11+12:3o"); +    assert (test_post_fail (p)); +  } + +  // gyear +  // +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("207"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-207"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0000"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20X7"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007+12:3o"); +    assert (test_post_fail (p)); +  } + +  // gmonth_day +  // +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-12-12"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--1212"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12?12"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--00-12"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12-00"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--13-23"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12-32"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--1X-12"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--12-2X"); +    assert (test_post_fail (p)); +  } + +  { +    gmonth_day_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("--11-11+12:3o"); +    assert (test_post_fail (p)); +  } + +  // gyear_month +  // +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("207-01"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-207-01"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0000-01"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20X7-01"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007?12"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-0"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-00"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-13"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-1X"); +    assert (test_post_fail (p)); +  } + +  { +    gyear_month_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01+12:3o"); +    assert (test_post_fail (p)); +  } + +  // date +  // +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("207-01-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-207-01-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0000-01-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20X7-01-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007?01-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-0-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-00-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-13-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-1X-01"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10?12"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-0"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-00"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-32"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-2X"); +    assert (test_post_fail (p)); +  } + +  { +    date_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01+12:3o"); +    assert (test_post_fail (p)); +  } + +  // time +  // +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1:01:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2X:01:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23?01:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:0:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:60:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:4X:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10?12"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10:"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10:0"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10:01."); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10:60"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:10:2X"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("24:01:00"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("24:00:01"); +    assert (test_post_fail (p)); +  } + +  { +    time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:01:01+12:3o"); +    assert (test_post_fail (p)); +  } + +  // date_time +  // +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("207-01-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-207-01-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0000-01-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("20X7-01-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007?01-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-0-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-00-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-13-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-1X-01T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10?12T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-0T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-00T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-32T12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-10-2XT12:13:14"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T1:01:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T2X:01:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23?01:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:0:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:60:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:4X:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10?12"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10:"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10:0"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10:01."); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10:60"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T23:10:2X"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T24:01:00"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T24:00:01"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("23:01:01+12:3o"); +    assert (test_post_fail (p)); +  } + +  { +    date_time_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007-01-01T12:13:14+12:3o"); +    assert (test_post_fail (p)); +  } + +  // duration +  // +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    // p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2007Y"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2007Y"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P-2007Y"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P-1M"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P-1D"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT-1H"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT-1M"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT-1.1S"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1H1M1S"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1M1Y"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT1S1H"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("PT1H1Y"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1Ygarbage"); +    assert (test_post_fail (p)); +  } + +  { +    duration_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("P1YT"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/date-time/makefile b/xsd/tests/cxx/parser/validation/built-in/date-time/makefile new file mode 100644 index 0000000..d5e2edc --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/date-time/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/date-time/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/float/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/float/driver.cxx new file mode 100644 index 0000000..1f6f0bd --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/float/driver.cxx @@ -0,0 +1,287 @@ +// file      : tests/cxx/parser/validation/built-in/float/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in float, double, and decimal types validation. +// +#include <math.h> +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // + +  // float +  // +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" 0000123.456 "); +    p._post (); +    assert (p.post_float () == 123.456F); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-12.345E2"); +    p._post (); +    assert (p.post_float () == -12.345E2F); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_float () == 0.0F); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0"); +    p._post (); +    assert (p.post_float () == -0.0F); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("INF"); +    p._post (); +    assert (isinf (p.post_float ())); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-INF"); +    p._post (); +    assert (isinf (p.post_float ())); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("NaN"); +    p._post (); +    assert (isnan (p.post_float ())); +  } + +  // double +  // +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" 0000123.456789 "); +    p._post (); +    assert (p.post_double () == 123.456789); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-12.3456789E2"); +    p._post (); +    assert (p.post_double () == -12.3456789E2); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_double () == 0.0); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0"); +    p._post (); +    assert (p.post_double () == -0.0); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("INF"); +    p._post (); +    assert (isinf (p.post_double ())); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-INF"); +    p._post (); +    assert (isinf (p.post_double ())); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("NaN"); +    p._post (); +    assert (isnan (p.post_double ())); +  } + +  // decimal +  // +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" 0000123.456789 "); +    p._post (); +    assert (p.post_decimal () == 123.456789); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-123.45678912345"); +    p._post (); +    assert (p.post_decimal () == -123.45678912345); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_decimal () == 0.0); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0"); +    p._post (); +    assert (p.post_decimal () == -0.0); +  } + + +  // Bad +  // + +  // float +  // +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+INF"); +    assert (test_post_fail (p)); +  } + +  { +    float_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1.45 E2"); +    assert (test_post_fail (p)); +  } + +  // double +  // +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+INF"); +    assert (test_post_fail (p)); +  } + +  { +    double_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1.45 E2"); +    assert (test_post_fail (p)); +  } + +  // decimal +  // +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("INF"); +    assert (test_post_fail (p)); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+INF"); +    assert (test_post_fail (p)); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-INF"); +    assert (test_post_fail (p)); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("NaN"); +    assert (test_post_fail (p)); +  } + +  { +    decimal_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1.45 2"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/float/makefile b/xsd/tests/cxx/parser/validation/built-in/float/makefile new file mode 100644 index 0000000..8755f3a --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/float/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/float/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/int/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/int/driver.cxx new file mode 100644 index 0000000..00c5947 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/int/driver.cxx @@ -0,0 +1,118 @@ +// file      : tests/cxx/parser/validation/built-in/int/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in int and unsigned int types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // +  { +    int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2147483648"); +    p._post (); +    assert (p.post_int () == -2147483648); +  } + +  { +    int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_int () == 0); +  } + +  { +    int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2147483647"); +    p._post (); +    assert (p.post_int () == 2147483647); +  } + +  { +    unsigned_int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_unsigned_int () == 0); +  } + +  { +    unsigned_int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("4294967295"); +    p._post (); +    assert (p.post_unsigned_int () == 4294967295); +  } + +  // Bad +  // + +  { +    unsigned_int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-123"); +    assert (test_post_fail (p)); +  } + + +  // Ranges +  // +  { +    int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-2147483649"); +    assert (test_post_fail (p)); +  } + +  { +    int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("2147483648"); +    assert (test_post_fail (p)); +  } + +  { +    unsigned_int_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("4294967296"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/int/makefile b/xsd/tests/cxx/parser/validation/built-in/int/makefile new file mode 100644 index 0000000..4cebe64 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/int/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/int/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/integer/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/integer/driver.cxx new file mode 100644 index 0000000..fa8e4e0 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/integer/driver.cxx @@ -0,0 +1,305 @@ +// file      : tests/cxx/parser/validation/built-in/int/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in integer & friends types validation. +// +#include <limits.h> + +#include <string> +#include <sstream> +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace std; +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // + +  std::string min; +  std::string max; +  std::string umax; + +  { +    ostringstream ostr; +    ostr << LLONG_MIN; +    min = ostr.str (); +  } + +  { +    ostringstream ostr; +    ostr << LLONG_MAX; +    max = ostr.str (); +  } + +  { +    ostringstream ostr; +    ostr << ULLONG_MAX; +    umax = ostr.str (); +  } + +  // integer +  // +  { +    integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (min.c_str ()); +    p._post (); +    assert (p.post_integer () == LLONG_MIN); +  } + +  { +    integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_integer () == 0); +  } + +  { +    integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (max.c_str ()); +    p._post (); +    assert (p.post_integer () == LLONG_MAX); +  } + +  // negative_integer +  // +  { +    negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (min.c_str ()); +    p._post (); +    assert (p.post_negative_integer () == LLONG_MIN); +  } + +  { +    negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-1"); +    p._post (); +    assert (p.post_negative_integer () == -1); +  } + +  // non_positive_integer +  // +  { +    non_positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (min.c_str ()); +    p._post (); +    assert (p.post_non_positive_integer () == LLONG_MIN); +  } + +  { +    non_positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+0"); +    p._post (); +    assert (p.post_non_positive_integer () == 0); +  } + +  // positive_integer +  // +  { +    positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1"); +    p._post (); +    assert (p.post_positive_integer () == 1); +  } + +  { +    positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (umax.c_str ()); +    p._post (); +    assert (p.post_positive_integer () == ULLONG_MAX); +  } + +  // non_negative_integer +  // +  /* +  { +    non_negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0"); +    p._post (); +    assert (p.post_non_negative_integer () == 0); +  } +  */ + +  { +    non_negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_non_negative_integer () == 0); +  } + +  { +    non_negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (umax.c_str ()); +    p._post (); +    assert (p.post_non_negative_integer () == ULLONG_MAX); +  } + + +  // Bad +  // + +  std::string past_min (min); +  std::string past_max (max); +  std::string past_umax (umax); + +  assert (*past_min.rbegin () != '9'); +  assert (*past_max.rbegin () != '9'); +  assert (*past_umax.rbegin () != '9'); + +  (*past_min.rbegin ())++; +  (*past_max.rbegin ())++; +  (*past_umax.rbegin ())++; + +  // integer +  // +  { +    integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_min.c_str ()); +    assert (test_post_fail (p)); +  } + +  { +    integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_max.c_str ()); +    assert (test_post_fail (p)); +  } + +  // negative_integer +  // +  { +    negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_min.c_str ()); +    assert (test_post_fail (p)); +  } + +  { +    negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-0"); +    assert (test_post_fail (p)); +  } + +  { +    negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1"); +    assert (test_post_fail (p)); +  } + +  // non_positive_integer +  // +  { +    non_positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_min.c_str ()); +    assert (test_post_fail (p)); +  } + +  { +    non_positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1"); +    assert (test_post_fail (p)); +  } + +  // positive_integer +  // +  { +    positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-1"); +    assert (test_post_fail (p)); +  } + +  { +    positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("+0"); +    assert (test_post_fail (p)); +  } + +  { +    positive_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_umax.c_str ()); +    assert (test_post_fail (p)); +  } + +  // non_negative_integer +  // +  { +    non_negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-1"); +    assert (test_post_fail (p)); +  } + +  { +    non_negative_integer_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (past_umax.c_str ()); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/integer/makefile b/xsd/tests/cxx/parser/validation/built-in/integer/makefile new file mode 100644 index 0000000..6b9d816 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/integer/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/integer/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/long/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/long/driver.cxx new file mode 100644 index 0000000..c7a66c4 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/long/driver.cxx @@ -0,0 +1,118 @@ +// file      : tests/cxx/parser/validation/built-in/long/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in long and unsigned long types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // +  { +    long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-9223372036854775808"); +    p._post (); +    assert (p.post_long () == (-9223372036854775807LL - 1)); +  } + +  { +    long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_long () == 0); +  } + +  { +    long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("9223372036854775807"); +    p._post (); +    assert (p.post_long () == 9223372036854775807LL); +  } + +  { +    unsigned_long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_unsigned_long () == 0); +  } + +  { +    unsigned_long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("18446744073709551615"); +    p._post (); +    assert (p.post_unsigned_long () == 18446744073709551615ULL); +  } + +  // Bad +  // + +  { +    unsigned_long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-123"); +    assert (test_post_fail (p)); +  } + + +  // Ranges +  // +  { +    long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-9223372036854775809"); +    assert (test_post_fail (p)); +  } + +  { +    long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("9223372036854775808"); +    assert (test_post_fail (p)); +  } + +  { +    unsigned_long_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("18446744073709551616"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/long/makefile b/xsd/tests/cxx/parser/validation/built-in/long/makefile new file mode 100644 index 0000000..2ab6368 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/long/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/long/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/makefile b/xsd/tests/cxx/parser/validation/built-in/makefile new file mode 100644 index 0000000..34bea8f --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/makefile @@ -0,0 +1,19 @@ +# file      : tests/cxx/parser/validation/built-in/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +tests := any-type binary boolean byte date-time float int integer long \ +qname short string uri + +default   := $(out_base)/ +test      := $(out_base)/.test +clean     := $(out_base)/.clean + +$(default): $(addprefix $(out_base)/,$(addsuffix /,$(tests))) +$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(tests))) +$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(tests))) + +$(foreach t,$(tests),$(call import,$(src_base)/$t/makefile)) diff --git a/xsd/tests/cxx/parser/validation/built-in/qname/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/qname/driver.cxx new file mode 100644 index 0000000..3a4bc90 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/qname/driver.cxx @@ -0,0 +1,107 @@ +// file      : tests/cxx/parser/validation/built-in/qname/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in QName type validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +bool +test_post_fail (qname_pimpl<char>& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  typedef xsd::cxx::parser::qname<char> qname; + +  // Good. +  // +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" xsi"); +    p._characters (":"); +    p._characters ("schemaLocation"); +    p._post (); +    assert (p.post_qname () == qname ("xsi", "schemaLocation")); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("schemaLocation"); +    p._post (); +    assert (p.post_qname () == qname ("schemaLocation")); +  } + + +  // Bad +  // +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    //p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (":"); +    assert (test_post_fail (p)); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("xsi:"); +    assert (test_post_fail (p)); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (":schemaLocation"); +    assert (test_post_fail (p)); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("x?i:schemaLocation"); +    assert (test_post_fail (p)); +  } + +  { +    qname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("xsi:schema Location"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/qname/makefile b/xsd/tests/cxx/parser/validation/built-in/qname/makefile new file mode 100644 index 0000000..5f53fea --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/qname/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/qname/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/short/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/short/driver.cxx new file mode 100644 index 0000000..2bb95d2 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/short/driver.cxx @@ -0,0 +1,118 @@ +// file      : tests/cxx/parser/validation/built-in/short/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in short and unsigned short types validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post (); +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  // Good. +  // +  { +    short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-32768"); +    p._post (); +    assert (p.post_short () == -32768); +  } + +  { +    short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_short () == 0); +  } + +  { +    short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("32767"); +    p._post (); +    assert (p.post_short () == 32767); +  } + +  { +    unsigned_short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("0"); +    p._post (); +    assert (p.post_unsigned_short () == 0); +  } + +  { +    unsigned_short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("65535"); +    p._post (); +    assert (p.post_unsigned_short () == 65535); +  } + +  // Bad +  // + +  { +    unsigned_short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-1234"); +    assert (test_post_fail (p)); +  } + + +  // Ranges +  // +  { +    short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-32769"); +    assert (test_post_fail (p)); +  } + +  { +    short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("32768"); +    assert (test_post_fail (p)); +  } + +  { +    unsigned_short_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("65536"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/short/makefile b/xsd/tests/cxx/parser/validation/built-in/short/makefile new file mode 100644 index 0000000..eee8382 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/short/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/short/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/string/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/string/driver.cxx new file mode 100644 index 0000000..2419d59 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/string/driver.cxx @@ -0,0 +1,514 @@ +// file      : tests/cxx/parser/validation/built-in/string/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in string & friends types validation. +// +#include <string> +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +template <typename T> +bool +test_post_fail (T& p) +{ +  try +  { +    p._post_impl (); // List implementation needs this to be post_impl. +  } +  catch (invalid_value<char> const&) +  { +    return true; +  } + +  return false; +} + +int +main () +{ +  typedef xsd::cxx::parser::string_sequence<char> strings; + +  // Good. +  // + +  // string +  // +  { +    string_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" aaa "); +    p._characters ("bbb"); +    p._characters (" "); +    p._post (); +    assert (p.post_string () == " \n\t aaa bbb "); +  } + +  // normalized_string +  // +  { +    normalized_string_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" aaa \n\t "); +    p._characters (" bbb"); +    p._characters ("  "); +    p._post (); +    assert (p.post_normalized_string () == "    aaa     bbb  "); +  } + +  // token +  // +  { +    token_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" aaa \n\t "); +    p._characters (" bbb \n\t"); +    p._characters ("  "); +    p._post (); +    assert (p.post_token () == "aaa bbb"); +  } + +  // name +  // +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" a:b-c_d123 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_name () == "a:b-c_d123"); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" _12 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_name () == "_12"); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" :12 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_name () == ":12"); +  } + +  // nmtoken +  // +  { +    nmtoken_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" 123a:b-c_d123 "); +    p._characters (" \n\t"); +    p._characters ("  "); +    p._post (); +    assert (p.post_nmtoken () == "123a:b-c_d123"); +  } + +  // nmtokens +  // +  { +    strings s; +    s.push_back ("123"); +    s.push_back ("abc"); + +    nmtokens_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" 123 "); +    p._characters (" \n\t abc "); +    p._characters ("  "); +    p._post (); +    assert (p.post_nmtokens () == s); +  } + +  // ncname +  // +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" a.b-c_d123 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_ncname () == "a.b-c_d123"); +  } + +  // id +  // +  { +    id_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" a.b-c_d123 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_id () == "a.b-c_d123"); +  } + +  // idref +  // +  { +    idref_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" a.b-c_d123 "); +    p._characters ("  "); +    p._post (); +    assert (p.post_idref () == "a.b-c_d123"); +  } + +  // idrefs +  // +  { +    strings s; +    s.push_back ("a123"); +    s.push_back ("abc"); + +    idrefs_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" \n\t"); +    p._characters (" a123 "); +    p._characters (" \n\t abc "); +    p._characters ("  "); +    p._post (); +    assert (p.post_idrefs () == s); +  } + +  // language +  // +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" x "); +    p._post (); +    assert (p.post_language () == "x"); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" en "); +    p._post (); +    assert (p.post_language () == "en"); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" en"); +    p._characters ("-us "); +    p._post (); +    assert (p.post_language () == "en-us"); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("one-two-three-four44-seven77-eight888"); +    p._post (); +    assert (p.post_language () == "one-two-three-four44-seven77-eight888"); +  } + + +  // Bad +  // + +  // name +  // +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (".a"); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-a"); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1a"); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a,b"); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a b"); +    assert (test_post_fail (p)); +  } + +  { +    name_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a<b"); +    assert (test_post_fail (p)); +  } + +  // nmtoken +  // +  { +    nmtoken_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    nmtoken_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a,b"); +    assert (test_post_fail (p)); +  } + +  { +    nmtoken_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a b"); +    assert (test_post_fail (p)); +  } + +  { +    nmtoken_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a<b"); +    assert (test_post_fail (p)); +  } + +  // nmtokens +  // +  { +    nmtokens_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" "); +    p._characters (" \t\n  "); +    assert (test_post_fail (p)); +  } + +  { +    nmtokens_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("ab a,b"); +    assert (test_post_fail (p)); +  } + +  // ncname +  // +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (""); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (".a"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("-a"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (":a"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1a"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("1:a"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a,b"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a b"); +    assert (test_post_fail (p)); +  } + +  { +    ncname_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a<b"); +    assert (test_post_fail (p)); +  } + +  // id +  // +  { +    id_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a b"); +    assert (test_post_fail (p)); +  } + +  // idref +  // +  { +    idref_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a b"); +    assert (test_post_fail (p)); +  } + +  // idrefs +  // +  { +    idrefs_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("  "); +    p._characters (" \t\n "); +    assert (test_post_fail (p)); +  } + +  { +    idrefs_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("ab a<b"); +    assert (test_post_fail (p)); +  } + +  // language +  // +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters (" "); +    assert (test_post_fail (p)); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("en-"); +    assert (test_post_fail (p)); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("a1"); +    assert (test_post_fail (p)); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("en+us"); +    assert (test_post_fail (p)); +  } + +  { +    language_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("en-nine99999"); +    assert (test_post_fail (p)); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/string/makefile b/xsd/tests/cxx/parser/validation/built-in/string/makefile new file mode 100644 index 0000000..5be3c4c --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/string/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/string/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) diff --git a/xsd/tests/cxx/parser/validation/built-in/uri/driver.cxx b/xsd/tests/cxx/parser/validation/built-in/uri/driver.cxx new file mode 100644 index 0000000..f6de3c2 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/uri/driver.cxx @@ -0,0 +1,55 @@ +// file      : tests/cxx/parser/validation/built-in/uri/driver.cxx +// author    : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2006-2010 Code Synthesis Tools CC +// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in anyURI type validation. +// +#include <cassert> + +#include <xsd/cxx/parser/validating/exceptions.hxx> +#include <xsd/cxx/parser/validating/xml-schema-pimpl.hxx> + +using namespace xsd::cxx::parser::validating; + +int +main () +{ +  // Good. +  // +  { +    uri_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("  "); +    p._post (); +    assert (p.post_uri () == ""); +  } + +  { +    uri_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("relative"); +    p._post (); +    assert (p.post_uri () == "relative"); +  } + +  { +    uri_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("#id"); +    p._post (); +    assert (p.post_uri () == "#id"); +  } + +  { +    uri_pimpl<char> p; +    p.pre (); +    p._pre (); +    p._characters ("http://www.example.com/foo#bar"); +    p._post (); +    assert (p.post_uri () == "http://www.example.com/foo#bar"); +  } +} diff --git a/xsd/tests/cxx/parser/validation/built-in/uri/makefile b/xsd/tests/cxx/parser/validation/built-in/uri/makefile new file mode 100644 index 0000000..ad53e89 --- /dev/null +++ b/xsd/tests/cxx/parser/validation/built-in/uri/makefile @@ -0,0 +1,65 @@ +# file      : tests/cxx/parser/validation/built-in/uri/makefile +# author    : Boris Kolpackov <boris@codesynthesis.com> +# 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 + +cxx := driver.cxx + +obj := $(addprefix $(out_base)/,$(cxx:.cxx=.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) + +$(call include-dep,$(dep)) + +# Convenience alias for default target. +# +$(out_base)/: $(driver) + + +# Test. +# +$(test): driver := $(driver) +$(test): $(driver) +	$(call message,test $$1,$$1,$(driver)) + +# Clean. +# +$(clean): $(driver).o.clean                                \ +  $(addsuffix .cxx.clean,$(obj))                           \ +  $(addsuffix .cxx.clean,$(dep)) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver +$(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) | 
