1 // file      : tests/cxx/parser/validation/built-in/any-type/driver.cxx
2 // copyright : Copyright (c) 2006-2017 Code Synthesis Tools CC
3 // license   : GNU GPL v2 + exceptions; see accompanying LICENSE file
4 
5 // Test the anyType and anySimpleType validation.
6 //
7 
8 #include <string>
9 #include <fstream>
10 #include <iostream>
11 
12 #include "test-pskel.hxx"
13 
14 using namespace std;
15 using namespace test;
16 using xml_schema::ro_string;
17 
18 struct any_type_pimpl: xml_schema::any_type_pimpl
19 {
20   virtual void
preany_type_pimpl21   pre ()
22   {
23     cout << "{" << endl;
24   }
25 
26   virtual void
_start_any_elementany_type_pimpl27   _start_any_element (ro_string const&,
28                       ro_string const& n,
29 		      ro_string const*)
30   {
31     cout << "  start any element '" << n << "'" << endl;
32   }
33 
34   virtual void
_end_any_elementany_type_pimpl35   _end_any_element (ro_string const&, ro_string const& n)
36   {
37     cout << "  end any element '" << n << "'" << endl;
38   }
39 
40   virtual void
_any_attributeany_type_pimpl41   _any_attribute (ro_string const&,
42                   ro_string const& n,
43 		  ro_string const& v)
44   {
45     cout << "  any attribute " << n << " = '" << v << "'" << endl;
46   }
47 
48   virtual void
_any_charactersany_type_pimpl49   _any_characters (ro_string const& s)
50   {
51     cout << "  any text: '" << s << "'" << endl;
52   }
53 
54   virtual void
post_any_typeany_type_pimpl55   post_any_type ()
56   {
57     cout << "}" << endl
58          << endl;
59   }
60 };
61 
62 struct any_simple_type_pimpl: xml_schema::any_simple_type_pimpl
63 {
64   virtual void
preany_simple_type_pimpl65   pre ()
66   {
67     cout << "{" << endl;
68   }
69 
70   virtual void
_any_charactersany_simple_type_pimpl71   _any_characters (ro_string const& s)
72   {
73     cout << "  any text: '" << s << "'" << endl;
74   }
75 
76   virtual void
post_any_simple_typeany_simple_type_pimpl77   post_any_simple_type ()
78   {
79     cout << "}" << endl
80          << endl;
81   }
82 };
83 
84 struct any_extension_pimpl: virtual any_extension_pskel,
85                             any_type_pimpl
86 
87 {
88   virtual void
xany_extension_pimpl89   x (const string& v)
90   {
91     cout << "  x = " << v << endl;
92   }
93 };
94 
95 struct any_simple_extension_pimpl: virtual any_simple_extension_pskel,
96                                    any_simple_type_pimpl
97 {
98   virtual void
xany_simple_extension_pimpl99   x (const string& v)
100   {
101     cout << "  x = " << v << endl;
102   }
103 };
104 
105 struct type_pimpl: type_pskel
106 {
107 };
108 
109 int
main(int argc,char * argv[])110 main (int argc, char* argv[])
111 {
112   if (argc != 2)
113   {
114     cerr << "usage: " << argv[0] << " test.xml" << endl;
115     return 1;
116   }
117 
118   try
119   {
120     xml_schema::string_pimpl string_p;
121 
122     any_type_pimpl any_type_p;
123     any_simple_type_pimpl any_simple_type_p;
124 
125     any_extension_pimpl any_extension_p;
126     any_simple_extension_pimpl any_simple_extension_p;
127 
128     type_pimpl type_p;
129 
130     any_extension_p.parsers (string_p);
131     any_simple_extension_p.parsers (string_p);
132 
133     type_p.parsers (any_type_p,
134                     any_extension_p,
135                     any_simple_extension_p,
136                     any_simple_type_p);
137 
138     xml_schema::document doc_p (type_p, "test", "root");
139 
140     ifstream ifs (argv[1]);
141     type_p.pre ();
142     doc_p.parse (ifs, argv[1], "", xml_schema::flags::dont_validate);
143     type_p.post_type ();
144   }
145   catch (xml_schema::exception const& e)
146   {
147     cerr << e << endl;
148     return 1;
149   }
150   catch (ios_base::failure const&)
151   {
152     cerr << "io failure" << endl;
153     return 1;
154   }
155 }
156