Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
d44e3c4f | 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
970ed795 EL |
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 | |
d44e3c4f | 7 | * |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Delic, Adam | |
11 | * Raduly, Csaba | |
12 | * | |
970ed795 EL |
13 | ******************************************************************************/ |
14 | module Marx { | |
15 | modulepar boolean Marx_verbose := false; | |
16 | #define verbose Marx_verbose | |
17 | #include "../macros.ttcnin" | |
18 | ||
19 | ||
20 | type record Silent {} | |
21 | ||
22 | ||
23 | //type enumerated Marxes { chico, groucho, harpo }; | |
24 | ||
25 | type record Brothers { | |
26 | record of enumerated { chico,groucho,harpo } order, | |
27 | integer chico, | |
28 | charstring groucho, | |
29 | Silent harpo | |
30 | } | |
31 | with { | |
32 | variant "useOrder"; | |
33 | } | |
34 | ||
35 | DECLARE_XER_ENCODERS(Brothers, marx); | |
36 | DECLARE_EXER_ENCODERS(Brothers, marx); | |
37 | ||
38 | type component MGM {} | |
39 | type component Paramount {} | |
40 | ||
41 | const universal charstring str_grimm_b := | |
42 | "<Brothers>\n" & | |
43 | "\t<order>\n" & | |
44 | "\t\t<chico/><groucho/><harpo/>\n" & | |
45 | "\t</order>\n" & | |
46 | "\t<chico>17</chico>\n" & | |
47 | "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" & | |
48 | "\t<harpo/>\n" & | |
49 | "</Brothers>\n" & | |
50 | "\n"; | |
51 | ||
52 | const universal charstring str_grimm_e := | |
53 | "<Brothers>\n" & | |
54 | "\t<chico>17</chico>\n" & | |
55 | "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" & | |
56 | "\t<harpo/>\n" & | |
57 | "</Brothers>\n" & | |
58 | "\n"; | |
59 | ||
60 | const universal charstring str_grimm_b2 := | |
61 | "<Brothers>\n" & | |
62 | "\t<order>\n" & | |
63 | "\t\t<groucho/><harpo/><chico/>\n" & | |
64 | "\t</order>\n" & | |
65 | "\t<chico>17</chico>\n" & | |
66 | "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" & | |
67 | "\t<harpo/>\n" & | |
68 | "</Brothers>\n" & | |
69 | "\n"; | |
70 | ||
71 | const universal charstring str_grimm_e2 := | |
72 | "<Brothers>\n" & | |
73 | "\t<groucho>Je suis Marxiste, tendance Groucho</groucho>\n" & | |
74 | "\t<harpo/>\n" & | |
75 | "\t<chico>17</chico>\n" & | |
76 | "</Brothers>\n" & | |
77 | "\n"; | |
78 | ||
79 | testcase duck_soup () runs on Paramount | |
80 | { | |
81 | var Brothers grimm := { | |
82 | { chico, groucho, harpo }, | |
83 | 17, "Je suis Marxiste, tendance Groucho", {} | |
84 | } | |
85 | CHECK_METHOD(bxer_enc_marx, grimm, str_grimm_b); | |
86 | CHECK_METHOD(exer_enc_marx, grimm, str_grimm_e); | |
87 | ||
88 | grimm.order := { groucho, harpo, chico }; | |
89 | ||
90 | CHECK_METHOD(bxer_enc_marx, grimm, str_grimm_b2); | |
91 | CHECK_METHOD(exer_enc_marx, grimm, str_grimm_e2); | |
92 | } | |
93 | ||
94 | testcase a_night_at_the_opera () runs on MGM | |
95 | { | |
96 | var Brothers grimm := { | |
97 | { chico, groucho, harpo }, | |
98 | 17, "Je suis Marxiste, tendance Groucho", {} | |
99 | } | |
100 | CHECK_DECODE(bxer_dec_marx, str_grimm_b, Brothers, grimm); | |
101 | CHECK_DECODE(exer_dec_marx, str_grimm_e, Brothers, grimm); | |
102 | } | |
103 | ||
104 | /* * * * * * * * * * * * * * */ | |
105 | ||
106 | type record Stooges { | |
107 | record of universal charstring emb, | |
108 | record of enumerated { curly, larry, moe } ord, | |
109 | integer curly, | |
110 | float larry, | |
111 | boolean moe | |
112 | } | |
113 | with { | |
114 | variant "useOrder"; | |
115 | variant "embedValues"; | |
116 | } | |
117 | ||
118 | DECLARE_XER_ENCODERS (Stooges, st3); | |
119 | DECLARE_EXER_ENCODERS(Stooges, st3); | |
120 | ||
121 | const universal charstring str_stg_b := | |
122 | "<Stooges>\n" & | |
123 | ||
124 | "\t<emb>\n" & | |
125 | "\t\t<UNIVERSAL_CHARSTRING/>\n" & | |
126 | "\t\t<UNIVERSAL_CHARSTRING>. is curly</UNIVERSAL_CHARSTRING>\n" & | |
127 | "\t\t<UNIVERSAL_CHARSTRING>.. is bald</UNIVERSAL_CHARSTRING>\n" & | |
128 | "\t\t<UNIVERSAL_CHARSTRING>...is tall</UNIVERSAL_CHARSTRING>\n" & | |
129 | "\t</emb>\n" & | |
130 | ||
131 | "\t<ord>\n" & | |
132 | "\t\t<larry/><curly/><moe/>\n" & | |
133 | "\t</ord>\n" & | |
134 | "\t<curly>13</curly>\n" & | |
135 | "\t<larry>1.414213</larry>\n" & | |
136 | "\t<moe><true/></moe>\n" & | |
137 | "</Stooges>\n" & | |
138 | "\n"; | |
139 | ||
140 | const universal charstring str_stg_e := | |
141 | "<Stooges>" & | |
142 | "" & // the first embedded string (empty in this case) | |
143 | "<larry>1.414213</larry>" & | |
144 | ". is curly" & // the embedded strings are not affected by USE-ORDER | |
145 | "<curly>13</curly>" & | |
146 | ".. is bald" & | |
147 | "<moe>true</moe>" & | |
148 | "...is tall" & | |
149 | "</Stooges>" & | |
150 | "\n"; | |
151 | ||
152 | ||
153 | const Stooges s3 := { | |
154 | emb := {"",". is curly",".. is bald","...is tall"}, | |
155 | ord := { larry, curly, moe }, | |
156 | curly := 13, | |
157 | larry := 1.414213, | |
158 | moe := true | |
159 | } | |
160 | ||
161 | testcase beer_and_pretzels() runs on MGM | |
162 | { | |
163 | CHECK_METHOD(bxer_enc_st3, s3, str_stg_b); | |
164 | CHECK_METHOD(exer_enc_st3, s3, str_stg_e); | |
165 | } | |
166 | ||
167 | testcase plane_nuts() runs on MGM | |
168 | { | |
169 | var Stooges expected := s3; | |
170 | CHECK_DECODE(bxer_dec_st3, str_stg_b, Stooges, expected); | |
171 | CHECK_DECODE(exer_dec_st3, str_stg_e, Stooges, expected); | |
172 | } | |
173 | ||
174 | control { | |
175 | execute(duck_soup()); // encoding use-order | |
176 | execute(a_night_at_the_opera()); // decode ===//=== | |
177 | execute(beer_and_pretzels()); // encoding use-order + embed-values | |
178 | execute(plane_nuts()); // decode ===//=== ===//=== | |
179 | } | |
180 | ||
181 | } | |
182 | with { | |
183 | encode "XML" | |
184 | } |