From 707cc94fe52463870a9c6c8e2e66eaaa389e601d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Feb 2009 15:16:26 +0200 Subject: Start tracking XSD/e with git after version 3.0.0 --- .../parser/validation/built-in/string/driver.cxx | 613 +++++++++++++++++++++ 1 file changed, 613 insertions(+) create mode 100644 tests/cxx/parser/validation/built-in/string/driver.cxx (limited to 'tests/cxx/parser/validation/built-in/string/driver.cxx') diff --git a/tests/cxx/parser/validation/built-in/string/driver.cxx b/tests/cxx/parser/validation/built-in/string/driver.cxx new file mode 100644 index 0000000..06a4708 --- /dev/null +++ b/tests/cxx/parser/validation/built-in/string/driver.cxx @@ -0,0 +1,613 @@ +// file : tests/cxx/parser/validation/built-in/string/driver.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +// Test the built-in string & friends types validation. +// +#include +#include + +#include + +// Let the runtime header sort out which version (stl/no-stl) to +// include. +// +#include + +using namespace xsde::cxx; +using namespace xsde::cxx::parser; +using namespace xsde::cxx::parser::validating; + +bool +compare (const string_sequence* x, const string_sequence& y) +{ + bool r = *x == y; + delete x; + return r; +} + +int +main () +{ + // We are going to leak a bit of memory in the no-STL case. + // + using std::string; + + // Good. + // + + // string + // + { + context c (0); + string_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa "); + p._characters ("bbb"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_string () == string (" \n\t aaa bbb ")); + } + + // normalized_string + // + { + context c (0); + normalized_string_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa \n\t "); + p._characters (" bbb"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_normalized_string () == string (" aaa bbb ")); + } + + // token + // + { + context c (0); + token_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" aaa \n\t "); + p._characters (" bbb \n\t"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_token () == string ("aaa bbb")); + } + + // name + // + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a:b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string ("a:b-c_d123")); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" _12 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string ("_12")); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" :12 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_name () == string (":12")); + } + + // nmtoken + // + { + context c (0); + nmtoken_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" 123a:b-c_d123 "); + p._characters (" \n\t"); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_nmtoken () == string ("123a:b-c_d123")); + } + + // nmtokens + // + { + context c (0); + string_sequence s; +#ifdef XSDE_STL + s.push_back ("123"); + s.push_back ("abc"); +#else + s.push_back_copy ("123"); + s.push_back_copy ("abc"); +#endif + + nmtokens_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" 123 "); + p._characters (" \n\t abc "); + p._characters (" "); + p._post (); + assert (!c.error_type () && compare (p.post_nmtokens (), s)); + } + + // ncname + // + { + context c (0); + ncname_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_ncname () == string ("a.b-c_d123")); + } + + // id + // + { + context c (0); + id_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_id () == string ("a.b-c_d123")); + } + + // idref + // + { + context c (0); + idref_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a.b-c_d123 "); + p._characters (" "); + p._post (); + assert (!c.error_type () && + p.post_idref () == string ("a.b-c_d123")); + } + + // idrefs + // + { + context c (0); + string_sequence s; +#ifdef XSDE_STL + s.push_back ("a123"); + s.push_back ("abc"); +#else + s.push_back_copy ("a123"); + s.push_back_copy ("abc"); +#endif + + idrefs_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" \n\t"); + p._characters (" a123 "); + p._characters (" \n\t abc "); + p._characters (" "); + p._post (); + assert (!c.error_type () && compare (p.post_idrefs (), s)); + } + + // language + // + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" x "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("x")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" en "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("en")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (" en"); + p._characters ("-us "); + p._post (); + assert (!c.error_type () && p.post_language () == string ("en-us")); + } + + { + context c (0); + language_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("one-two-three-four44-seven77-eight888"); + p._post (); + assert (!c.error_type () && + p.post_language () == + string ("one-two-three-four44-seven77-eight888")); + } + + // Bad + // + + // name + // + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (""); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters (".a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("-a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("1a"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a,b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a b"); + p._post (); + assert (c.schema_error ()); + } + + { + context c (0); + name_pimpl p; + p.pre (); + p._pre_impl (c); + p._characters ("a