aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/parser/validation/built-in/string
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-02-24 15:16:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-02-24 15:16:26 +0200
commit707cc94fe52463870a9c6c8e2e66eaaa389e601d (patch)
tree13e10ff28bf4455d915f9d59b401bdbb62a393cb /tests/cxx/parser/validation/built-in/string
Start tracking XSD/e with git after version 3.0.03.0.0
Diffstat (limited to 'tests/cxx/parser/validation/built-in/string')
-rw-r--r--tests/cxx/parser/validation/built-in/string/driver.cxx613
-rw-r--r--tests/cxx/parser/validation/built-in/string/makefile61
2 files changed, 674 insertions, 0 deletions
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 <boris@codesynthesis.com>
+// 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 <string>
+#include <cassert>
+
+#include <xsde/config.h>
+
+// Let the runtime header sort out which version (stl/no-stl) to
+// include.
+//
+#include <xsde/cxx/parser/validating/xml-schema-pimpl.hxx>
+
+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<b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ // nmtoken
+ //
+ {
+ context c (0);
+ nmtoken_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ nmtoken_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a,b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ nmtoken_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ nmtoken_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a<b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ // nmtokens
+ //
+ {
+ context c (0);
+ nmtokens_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters (" ");
+ p._characters (" \t\n ");
+ p._post_impl ();
+ assert (c.schema_error () == schema_error::invalid_nmtokens_value);
+ }
+
+ {
+ context c (0);
+ nmtokens_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("ab a,b");
+ p._post_impl ();
+ assert (c.schema_error () == schema_error::invalid_nmtoken_value);
+ }
+
+ // ncname
+ //
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters (".a");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("-a");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters (":a");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("1a");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a:b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a,b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ {
+ context c (0);
+ ncname_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a<b");
+ p._post ();
+ assert (c.schema_error ());
+ }
+
+ // id
+ //
+ {
+ context c (0);
+ id_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a b");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_id_value);
+ }
+
+ // idref
+ //
+ {
+ context c (0);
+ idref_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a b");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_idref_value);
+ }
+
+ // idrefs
+ //
+ {
+ context c (0);
+ idrefs_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters (" ");
+ p._characters (" \t\n ");
+ p._post_impl ();
+ assert (c.schema_error () == schema_error::invalid_idrefs_value);
+ }
+
+ {
+ context c (0);
+ idrefs_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("ab a<b");
+ p._post_impl ();
+ assert (c.schema_error () == schema_error::invalid_idref_value);
+ }
+
+ // language
+ //
+ {
+ context c (0);
+ language_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters (" ");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_language_value);
+ }
+
+ {
+ context c (0);
+ language_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("en-");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_language_value);
+ }
+
+ {
+ context c (0);
+ language_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("a1");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_language_value);
+ }
+
+ {
+ context c (0);
+ language_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("en+us");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_language_value);
+ }
+
+ {
+ context c (0);
+ language_pimpl p;
+ p.pre ();
+ p._pre_impl (c);
+ p._characters ("en-nine99999");
+ p._post ();
+ assert (c.schema_error () == schema_error::invalid_language_value);
+ }
+}
diff --git a/tests/cxx/parser/validation/built-in/string/makefile b/tests/cxx/parser/validation/built-in/string/makefile
new file mode 100644
index 0000000..27fc822
--- /dev/null
+++ b/tests/cxx/parser/validation/built-in/string/makefile
@@ -0,0 +1,61 @@
+# file : tests/cxx/parser/validation/built-in/string/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../../../build/bootstrap.make
+
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o))
+dep := $(obj:.o=.o.d)
+
+xsde.l := $(out_root)/libxsde/xsde/xsde.l
+xsde.l.cpp-options := $(out_root)/libxsde/xsde/xsde.l.cpp-options
+
+driver := $(out_base)/driver
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+
+# Build.
+#
+$(driver): $(obj) $(xsde.l)
+
+$(obj) $(dep): $(xsde.l.cpp-options)
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+.PHONY: $(out_base)/
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+.PHONY: $(test)
+
+$(test): driver := $(driver)
+$(test): $(driver)
+ $(call message,test $$1,$$1,$(driver))
+
+# Clean.
+#
+.PHONY: $(clean)
+
+$(clean): $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(obj)) \
+ $(addsuffix .cxx.clean,$(dep))
+
+
+# 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)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/libxsde/xsde/makefile)