aboutsummaryrefslogtreecommitdiff
path: root/tests/cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cxx')
-rw-r--r--tests/cxx/hybrid/clone/driver.cxx79
-rw-r--r--tests/cxx/hybrid/clone/makefile109
-rw-r--r--tests/cxx/hybrid/clone/test-000.std71
-rw-r--r--tests/cxx/hybrid/clone/test-000.xml79
-rw-r--r--tests/cxx/hybrid/clone/test.xsd148
-rw-r--r--tests/cxx/hybrid/makefile5
6 files changed, 489 insertions, 2 deletions
diff --git a/tests/cxx/hybrid/clone/driver.cxx b/tests/cxx/hybrid/clone/driver.cxx
new file mode 100644
index 0000000..5d044ca
--- /dev/null
+++ b/tests/cxx/hybrid/clone/driver.cxx
@@ -0,0 +1,79 @@
+// file : tests/cxx/hybrid/clone/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 _clone() functionality.
+//
+
+#include <assert.h>
+#include <iostream>
+
+#include "test.hxx"
+#include "test-pimpl.hxx"
+#include "test-simpl.hxx"
+
+using namespace std;
+using namespace test;
+
+void
+data_destructor (void* p, size_t)
+{
+ delete static_cast<int*> (p);
+}
+
+void*
+data_clone (void* p, size_t)
+{
+ return new int (*static_cast<int*> (p));
+}
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " test.xml" << endl;
+ return 1;
+ }
+
+ // Parse.
+ //
+ root_paggr root_p;
+
+ xml_schema::document_pimpl doc_p (
+ root_p.root_parser (),
+ root_p.root_namespace (),
+ root_p.root_name ());
+
+ root_p.pre ();
+ doc_p.parse (argv[1]);
+ type* r = root_p.post ();
+
+ r->complex ().custom_data ().destructor (&data_destructor);
+ r->complex ().custom_data ().clone (&data_clone);
+ r->complex ().custom_data ().push_back (new int (123));
+
+ type* c = r->_clone ();
+ delete r;
+
+ assert (c->complex ().custom_data ().size () == 1);
+ assert (*static_cast<int*> (c->complex ().custom_data ()[0]) == 123);
+
+ // Serialize.
+ //
+ root_saggr root_s;
+
+ xml_schema::document_simpl doc_s (
+ root_s.root_serializer (),
+ root_s.root_namespace (),
+ root_s.root_name ());
+
+ doc_s.add_prefix ("t", "test");
+
+ root_s.pre (*c);
+ doc_s.serialize (cout, xml_schema::document_simpl::pretty_print);
+ root_s.post ();
+
+ delete c;
+}
diff --git a/tests/cxx/hybrid/clone/makefile b/tests/cxx/hybrid/clone/makefile
new file mode 100644
index 0000000..7138869
--- /dev/null
+++ b/tests/cxx/hybrid/clone/makefile
@@ -0,0 +1,109 @@
+# file : tests/cxx/hybrid/clone/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
+
+obj := $(addprefix $(out_base)/,\
+$(cxx:.cxx=.o) \
+$(xsd:.xsd=.o) \
+$(xsd:.xsd=-pskel.o) \
+$(xsd:.xsd=-pimpl.o) \
+$(xsd:.xsd=-sskel.o) \
+$(xsd:.xsd=-simpl.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
+dist := $(out_base)/.dist
+dist-win := $(out_base)/.dist-win
+clean := $(out_base)/.clean
+
+
+# Build.
+#
+$(driver): $(obj) $(xsde.l)
+
+$(obj) $(dep): $(xsde.l.cpp-options)
+
+genf := $(xsd:.xsd=.hxx) $(xsd:.xsd=.cxx) \
+ $(xsd:.xsd=-pskel.hxx) $(xsd:.xsd=-pskel.cxx) \
+ $(xsd:.xsd=-pimpl.hxx) $(xsd:.xsd=-pimpl.cxx) \
+ $(xsd:.xsd=-sskel.hxx) $(xsd:.xsd=-sskel.cxx) \
+ $(xsd:.xsd=-simpl.hxx) $(xsd:.xsd=-simpl.cxx)
+
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(out_root)/xsde/xsde
+$(gen): xsde := $(out_root)/xsde/xsde
+$(gen) $(dist) $(dist-win): xsde_options += --generate-parser \
+--generate-serializer --generate-aggregate --generate-clone \
+--custom-data complex
+
+$(call include-dep,$(dep))
+
+# Convenience alias for default target.
+#
+$(out_base)/: $(driver)
+
+
+# Test.
+#
+$(test): driver := $(driver)
+$(test): $(driver) $(src_base)/test-000.xml $(src_base)/test-000.std
+ $(call message,test $$1,$$1 $(src_base)/test-000.xml | diff -u $(src_base)/test-000.std -,$(driver))
+
+
+# Dist.
+#
+$(dist) $(dist-win): opt := -src $(src_base) -cmd cxx-hybrid -xsd "$(xsd)" \
+-cxx "$(cxx)" -gen "$(genf)" -opt "$(xsde_options)" -out $(dist_prefix)
+
+$(dist):
+ $(call message,install $(src_base),$(scf_root)/dist $(opt))
+
+$(dist-win):
+ $(call message,install $(src_base),$(scf_root)/dist -win $(opt))
+
+
+# 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/clone/test-000.std b/tests/cxx/hybrid/clone/test-000.std
new file mode 100644
index 0000000..f50ea2f
--- /dev/null
+++ b/tests/cxx/hybrid/clone/test-000.std
@@ -0,0 +1,71 @@
+<t:root xmlns:t="test">
+ <complex af="123" afixed="abc" av="abc def">
+ <f>123</f>
+ <v>abc def ghq</v>
+ <of>123</of>
+ <ov>abc def ghq</ov>
+ <pod>1</pod>
+ <pod>2</pod>
+ <pod>3</pod>
+ <fix>
+ <x>1</x>
+ <y>1</y>
+ </fix>
+ <fix>
+ <x>2</x>
+ <y>2</y>
+ </fix>
+ <fix>
+ <x>3</x>
+ <y>3</y>
+ </fix>
+ <var>a1 b1 c1</var>
+ <var>a2 b2 c2</var>
+ <var>a3 b3 c3</var>
+ <str>aaa</str>
+ <str>bbb</str>
+ <str>ccc</str>
+ <cv>abc def ghq</cv>
+ </complex>
+ <all>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <of>123</of>
+ <ov>abc def ghq</ov>
+ </all>
+ <sequence>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <c1v>abc def ghq</c1v>
+ <c2f>123</c2f>
+ </sequence>
+ <choice>
+ <cf>123</cf>
+ </choice>
+ <choice>
+ <cv>abc def ghq</cv>
+ </choice>
+ <choice>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <f>123</f>
+ <v>abc def ghq</v>
+ </choice>
+ <fixder>
+ <x>1</x>
+ <y>1</y>
+ <v>abc def ghq</v>
+ </fixder>
+ <varder>
+ <x>1</x>
+ <y>abc def ghq</y>
+ <f>123</f>
+ </varder>
+ <strder v="abc def ghq">str str</strder>
+ <list>abc def ghq</list>
+ <union>abc</union>
+ <enum>c</enum>
+ <enumder>b</enumder>
+</t:root> \ No newline at end of file
diff --git a/tests/cxx/hybrid/clone/test-000.xml b/tests/cxx/hybrid/clone/test-000.xml
new file mode 100644
index 0000000..c10c1b7
--- /dev/null
+++ b/tests/cxx/hybrid/clone/test-000.xml
@@ -0,0 +1,79 @@
+<t:root xmlns:t="test">
+ <complex af="123" av="abc def">
+ <f>123</f>
+ <v>abc def ghq</v>
+ <of>123</of>
+ <ov>abc def ghq</ov>
+
+ <pod>1</pod>
+ <pod>2</pod>
+ <pod>3</pod>
+
+ <fix><x>1</x><y>1</y></fix>
+ <fix><x>2</x><y>2</y></fix>
+ <fix><x>3</x><y>3</y></fix>
+
+ <var>a1 b1 c1</var>
+ <var>a2 b2 c2</var>
+ <var>a3 b3 c3</var>
+
+ <str>aaa</str>
+ <str>bbb</str>
+ <str>ccc</str>
+
+ <cv>abc def ghq</cv>
+ </complex>
+
+ <all>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <of>123</of>
+ <ov>abc def ghq</ov>
+ </all>
+
+ <sequence>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <f>123</f>
+ <v>abc def ghq</v>
+
+ <c1v>abc def ghq</c1v>
+
+ <c2f>123</c2f>
+ </sequence>
+
+ <choice>
+ <cf>123</cf>
+ </choice>
+
+ <choice>
+ <cv>abc def ghq</cv>
+ </choice>
+
+ <choice>
+ <f>123</f>
+ <v>abc def ghq</v>
+ <f>123</f>
+ <v>abc def ghq</v>
+ </choice>
+
+ <fixder>
+ <x>1</x>
+ <y>1</y>
+ <v>abc def ghq</v>
+ </fixder>
+
+ <varder>
+ <x>1</x>
+ <y>abc def ghq</y>
+ <f>123</f>
+ </varder>
+
+ <strder v="abc def ghq">str str</strder>
+
+ <list>abc def ghq</list>
+ <union>abc</union>
+ <enum>c</enum>
+ <enumder>b</enumder>
+
+</t:root>
diff --git a/tests/cxx/hybrid/clone/test.xsd b/tests/cxx/hybrid/clone/test.xsd
new file mode 100644
index 0000000..cc4bc12
--- /dev/null
+++ b/tests/cxx/hybrid/clone/test.xsd
@@ -0,0 +1,148 @@
+<?xml version="1.0"?>
+<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:t="test" targetNamespace="test">
+
+ <complexType name="fix">
+ <sequence>
+ <element name="x" type="int"/>
+ <element name="y" type="int"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="var">
+ <sequence>
+ <element name="x" type="int"/>
+ <element name="y" type="NMTOKENS"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="all">
+ <all minOccurs="0">
+ <element name="f" type="int"/>
+ <element name="v" type="NMTOKENS"/>
+ <element name="of" type="int" minOccurs="0"/>
+ <element name="ov" type="NMTOKENS" minOccurs="0"/>
+ </all>
+ </complexType>
+
+ <complexType name="sequence">
+ <sequence>
+ <sequence maxOccurs="unbounded">
+ <element name="f" type="int"/>
+ <element name="v" type="NMTOKENS"/>
+ </sequence>
+ <choice>
+ <element name="c1f" type="int"/>
+ <element name="c1v" type="NMTOKENS"/>
+ </choice>
+ <choice minOccurs="0">
+ <element name="c2f" type="int"/>
+ <element name="c2v" type="NMTOKENS"/>
+ </choice>
+ </sequence>
+ </complexType>
+
+ <complexType name="choice">
+ <choice>
+ <choice>
+ <element name="cf" type="int"/>
+ <element name="cv" type="NMTOKENS"/>
+ </choice>
+ <sequence maxOccurs="unbounded">
+ <element name="f" type="int"/>
+ <element name="v" type="NMTOKENS"/>
+ </sequence>
+ </choice>
+ </complexType>
+
+ <complexType name="complex">
+ <sequence>
+ <element name="f" type="int"/>
+ <element name="v" type="NMTOKENS"/>
+ <element name="of" type="int" minOccurs="0"/>
+ <element name="ov" type="NMTOKENS" minOccurs="0"/>
+ <element name="pod" type="int" maxOccurs="unbounded"/>
+ <element name="fix" type="t:var" maxOccurs="unbounded"/>
+ <element name="var" type="NMTOKENS" maxOccurs="unbounded"/>
+ <element name="str" type="string" maxOccurs="unbounded"/>
+ <choice>
+ <element name="cf" type="int"/>
+ <element name="cv" type="NMTOKENS"/>
+ </choice>
+ </sequence>
+ <attribute name="af" type="int" use="required"/>
+ <attribute name="av" type="NMTOKENS" default="abc"/>
+ <attribute name="afixed" type="NMTOKENS" default="abc"/>
+ </complexType>
+
+ <complexType name="fixder">
+ <complexContent>
+ <extension base="t:fix">
+ <sequence>
+ <element name="v" type="NMTOKENS"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="varder">
+ <complexContent>
+ <extension base="t:var">
+ <sequence>
+ <element name="f" type="int"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="strder">
+ <simpleContent>
+ <extension base="string">
+ <attribute name="v" type="NMTOKENS"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+
+ <simpleType name="list">
+ <list itemType="string"/>
+ </simpleType>
+
+ <simpleType name="union">
+ <union memberTypes="int string"/>
+ </simpleType>
+
+ <simpleType name="enum">
+ <restriction base="string">
+ <enumeration value="a"/>
+ <enumeration value="b"/>
+ <enumeration value="c"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="enumder">
+ <restriction base="t:enum">
+ <enumeration value="a"/>
+ <enumeration value="b"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="type">
+ <sequence>
+ <element name="complex" type="t:complex"/>
+ <element name="all" type="t:all"/>
+ <element name="sequence" type="t:sequence"/>
+ <element name="choice" type="t:choice" maxOccurs="unbounded"/>
+
+ <element name="fixder" type="t:fixder"/>
+ <element name="varder" type="t:varder"/>
+ <element name="strder" type="t:strder"/>
+
+ <element name="list" type="t:list"/>
+ <element name="union" type="t:union"/>
+ <element name="enum" type="t:enum"/>
+ <element name="enumder" type="t:enumder"/>
+ </sequence>
+ </complexType>
+
+ <element name="root" type="t:type"/>
+
+</schema>
diff --git a/tests/cxx/hybrid/makefile b/tests/cxx/hybrid/makefile
index 8fb3f3f..88d89a2 100644
--- a/tests/cxx/hybrid/makefile
+++ b/tests/cxx/hybrid/makefile
@@ -10,7 +10,8 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
#
all_tests := sequences polymorphism iterator built-in default enumeration \
-iso8859-1 list recursive test-template union binary/cdr binary/xdr choice
+iso8859-1 list recursive test-template union binary/cdr binary/xdr choice \
+clone
build_tests := sequences
@@ -40,7 +41,7 @@ build_tests += binary/xdr
endif
ifeq ($(xsde_parser_validation),y)
-build_tests += choice recursive
+build_tests += choice recursive clone
endif
endif # xsde_iostream