diff options
| author | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 | 
|---|---|---|
| committer | Jörg Frings-Fürst <jff@merkur> | 2014-05-18 16:08:14 +0200 | 
| commit | a15cf65c44d5c224169c32ef5495b68c758134b7 (patch) | |
| tree | 3419f58fc8e1b315ba8171910ee044c5d467c162 /xsd/tests/cxx/parser/validation/built-in/integer | |
Imported Upstream version 3.3.0.2upstream/3.3.0.2
Diffstat (limited to 'xsd/tests/cxx/parser/validation/built-in/integer')
| -rw-r--r-- | xsd/tests/cxx/parser/validation/built-in/integer/driver.cxx | 305 | ||||
| -rw-r--r-- | xsd/tests/cxx/parser/validation/built-in/integer/makefile | 65 | 
2 files changed, 370 insertions, 0 deletions
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)  | 
