Sync with 5.4.0
[deliverable/titan.core.git] / regression_test / XML / EXER-whitepaper / UseType.ttcnpp
1 /******************************************************************************
2 * Copyright (c) 2000-2015 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 ******************************************************************************/
8 module UseType{
9 modulepar boolean UseType_verbose := false;
10 #define verbose UseType_verbose
11 #include "../macros.ttcnin"
12
13 type component Shop {}
14
15 type record Shirt {
16 charstring color,
17 charstring make,
18 integer size
19 }
20
21 type record Trousers {
22 boolean available,
23 charstring color,
24 charstring make
25 }
26 with {
27 variant (available) "attribute"
28 }
29
30 type record Shoes {
31 boolean available,
32 charstring color,
33 integer size
34 }
35 with {
36 variant (available) "attribute"
37 }
38
39 type union ProductUT {
40 Shirt shirt,
41 Trousers trousers,
42 Shoes shoes
43 }
44 with {
45 variant "element";
46 variant "useType";
47 variant "namespace as 'http://www.example.com' prefix 'exm'"
48 }
49
50 DECLARE_XER_ENCODERS(ProductUT, prodUT);
51 DECLARE_EXER_ENCODERS(ProductUT, prodUT);
52
53 const ProductUT shoo := { shoes := { available := false, color := "brown", size := 42 } }
54
55 const universal charstring str_shoo_e :=
56 "<exm:ProductUT xmlns:exm=\'http://www.example.com\' " &
57 "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type=\'shoes\' available='false'>\n" &
58 "\t<color>brown</color>\n" &
59 "\t<size>42</size>\n" &
60 "</exm:ProductUT>\n" &
61 "\n";
62
63 const universal charstring str_shoo_b :=
64 "<ProductUT>\n" &
65 "\t<shoes>\n" &
66 "\t\t<available><false/></available>\n" &
67 "\t\t<color>brown</color>\n" &
68 "\t\t<size>42</size>\n" &
69 "\t</shoes>\n" &
70 "</ProductUT>\n" &
71 "\n";
72
73 testcase enc_ut() runs on Shop {
74 CHECK_METHOD(bxer_enc_prodUT, shoo, str_shoo_b);
75 CHECK_METHOD(exer_enc_prodUT, shoo, str_shoo_e);
76 }
77
78 testcase dec_ut() runs on Shop
79 {
80 CHECK_DECODE(bxer_dec_prodUT, str_shoo_b, ProductUT, shoo);
81 CHECK_DECODE(exer_dec_prodUT, str_shoo_e, ProductUT, shoo);
82 }
83
84 /* * * An escapee from Name * * */
85
86 type union U {
87 boolean first,
88 integer second
89 }
90 with {
91 variant "useType";
92 variant (first) "name as 'One'";
93 variant (second) "name as 'Two'";
94 }
95
96 DECLARE_XER_ENCODERS(U, u);
97 DECLARE_EXER_ENCODERS(U, u);
98
99 const U v := { second := 123 }
100
101 const universal charstring str_12_e :=
102 "<U xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsi:type=\'Two\'>123</U>\n\n";
103
104 const universal charstring str_12_b :=
105 "<U>\n" &
106 "\t<second>123</second>\n" &
107 "</U>\n\n";
108
109
110
111 testcase encode_12() runs on Shop
112 {
113 CHECK_METHOD(bxer_enc_u, v, str_12_b);
114 CHECK_METHOD(exer_enc_u, v, str_12_e);
115 }
116
117 testcase decode_12() runs on Shop
118 {
119 CHECK_DECODE(bxer_dec_u, str_12_b, U, v);
120 CHECK_DECODE(exer_dec_u, str_12_e, U, v);
121 }
122
123 control {
124 execute(enc_ut());
125 execute(dec_ut());
126
127 execute(encode_12());
128 execute(decode_12());
129 }
130
131 }
132 with {
133 encode "XML"
134 variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'"
135 }
136
This page took 0.04856 seconds and 6 git commands to generate.