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