aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx/hybrid
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-10-07 08:52:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-10-07 08:52:20 +0200
commit56043225000df52cf530a85dc5f53ad06ba241cd (patch)
tree9bf6a0090522896c0fa96baff61a574defcc7165 /tests/cxx/hybrid
parentc1f810de13243f1b6b3a9e7c9313ceb936471e53 (diff)
Add support for STL-conforming iterators
The new XSDE_STL_ITERATOR configuration variable is used to conditionally turn this on.
Diffstat (limited to 'tests/cxx/hybrid')
-rw-r--r--tests/cxx/hybrid/iterator/driver.cxx62
-rw-r--r--tests/cxx/hybrid/iterator/makefile80
-rw-r--r--tests/cxx/hybrid/iterator/test.xsd24
-rw-r--r--tests/cxx/hybrid/makefile8
4 files changed, 173 insertions, 1 deletions
diff --git a/tests/cxx/hybrid/iterator/driver.cxx b/tests/cxx/hybrid/iterator/driver.cxx
new file mode 100644
index 0000000..cff3015
--- /dev/null
+++ b/tests/cxx/hybrid/iterator/driver.cxx
@@ -0,0 +1,62 @@
+// file : tests/cxx/hybrid/iterator/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 conformance to STL iterator requirements.
+//
+
+#include <cassert>
+#include <iostream>
+#include <algorithm>
+
+#include "test.hxx"
+
+using namespace std;
+using namespace test;
+
+struct fix_pred
+{
+ fix_pred (int v): v_ (v) {}
+ bool operator() (const fix& x) const {return x.a () == v_;}
+ int v_;
+};
+
+struct var_pred
+{
+ var_pred (const char* v): v_ (v) {}
+ bool operator() (const var& x) const {return x.a () == v_;}
+ const char* v_;
+};
+
+int
+main ()
+{
+ type::f_sequence fs;
+
+ fix f;
+ f.a (1);
+ fs.push_back (f);
+ f.a (2);
+ fs.push_back (f);
+ f.a (3);
+ fs.push_back (f);
+
+ assert (find_if (fs.begin (), fs.end (), fix_pred (2))->a () == 2);
+
+
+ type::v_sequence vs;
+
+ var* v;
+ v = new var;
+ v->a ("a");
+ vs.push_back (v);
+ v = new var;
+ v->a ("b");
+ vs.push_back (v);
+ v = new var;
+ v->a ("c");
+ vs.push_back (v);
+
+ assert (find_if (vs.begin (), vs.end (), var_pred ("b"))->a () == "b");
+}
diff --git a/tests/cxx/hybrid/iterator/makefile b/tests/cxx/hybrid/iterator/makefile
new file mode 100644
index 0000000..74e62c3
--- /dev/null
+++ b/tests/cxx/hybrid/iterator/makefile
@@ -0,0 +1,80 @@
+# file : tests/cxx/hybrid/iterator/makefile
+# author : Boris Kolpackov <boris@codesynthesis.com>
+# copyright : Copyright (c) 2006-2009 Code Synthesis Tools CC
+# license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make
+
+xsd := test.xsd
+cxx := driver.cxx
+
+obj := $(addprefix $(out_base)/,$(cxx:.cxx=.o) $(xsd:.xsd=.o))
+dep := $(obj:.o=.o.d)
+
+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)
+
+genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen): xsde_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)) \
+ $(addprefix $(out_base)/,$(xsd:.xsd=.cxx.xsd.clean))
+
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(gen): | $(out_base)/.gitignore
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+
+# How to.
+#
+$(call include,$(bld_root)/cxx/o-e.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(scf_root)/xsde/hybrid/xsd-cxx.make)
+
+
+# Dependencies.
+#
+$(call import,$(src_root)/xsde/makefile)
+$(call import,$(src_root)/libxsde/xsde/makefile)
diff --git a/tests/cxx/hybrid/iterator/test.xsd b/tests/cxx/hybrid/iterator/test.xsd
new file mode 100644
index 0000000..eb41ee1
--- /dev/null
+++ b/tests/cxx/hybrid/iterator/test.xsd
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="fix">
+ <sequence>
+ <element name="a" type="int"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="var">
+ <sequence>
+ <element name="a" type="string"/>
+ <element name="b" type="int" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="f" type="t:fix" maxOccurs="unbounded"/>
+ <element name="v" type="t:var" maxOccurs="unbounded"/>
+ </sequence>
+ </complexType>
+
+</schema>
diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile
index fe1bccf..a30ac41 100644
--- a/tests/cxx/hybrid/makefile
+++ b/tests/cxx/hybrid/makefile
@@ -11,6 +11,12 @@ ifeq ($(xsde_polymorphic),y)
tests += polymorphism
endif
+ifeq ($(xsde_stl),y)
+ifeq ($(xsde_stl_iterator),y)
+tests += iterator
+endif
+endif
+
ifeq ($(xsde_iostream),y)
tests += built-in default list recursive test-template union
@@ -26,7 +32,7 @@ ifeq ($(xsde_parser_validation),y)
tests += choice
endif
-endif
+endif # xsde_iostream
default := $(out_base)/
test := $(out_base)/.test