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 | * Baranyi, Botond | |
11 | * Raduly, Csaba | |
12 | * | |
970ed795 EL |
13 | ******************************************************************************/ |
14 | /* | |
15 | * Note: this file needs to be included *after* this bit: | |
16 | * | |
17 | * module whatever { | |
18 | * modulepar boolean verbose := false; | |
19 | */ | |
20 | ||
21 | /* The following macros output error/warning messages in the "GCC format", | |
22 | * which can be parsed by Eclipse. | |
23 | */ | |
24 | ||
25 | // A TODO in the output | |
26 | #define NOT_YET \ | |
27 | log(": warning: not implemented"); \ | |
28 | setverdict(inconc) | |
29 | ||
30 | // Output a failure or (optionally) success message in a format | |
31 | // that can be parsed by Eclipse (GCC format). | |
32 | // This requires a variable or module parameter called "verbose". | |
33 | #define COMPARE(actual,expected) if ( match(actual,expected) ) { \ | |
34 | if(verbose) { log( expected, "\t matches OK" ); } \ | |
35 | setverdict(pass); \ | |
36 | } else { \ | |
37 | log(": fail: G0T ", actual ); \ | |
38 | log(": fail: EXP ", expected); \ | |
39 | setverdict(fail, match(actual,expected)); \ | |
40 | } | |
41 | ||
42 | #ifndef NO_XER | |
43 | import from converter all; | |
44 | ||
45 | // Run an encode and compare the result | |
46 | #define CHECK_METHOD(method,input,expected) { \ | |
47 | var octetstring u8 := method(input); \ | |
48 | var universal charstring actual; \ | |
49 | var integer retval := o2u("UTF-8", u8, actual); \ | |
50 | if (retval!=0) { setverdict(fail, "Conversion failed: ", retval) } \ | |
51 | COMPARE(actual, expected); \ | |
52 | } | |
53 | ||
54 | // Run a decode and compare the result | |
55 | #define CHECK_DECODE(method,input,type,expected) { \ | |
56 | var octetstring bytes; \ | |
57 | var integer retval := u2o("UTF-8", input, bytes); \ | |
58 | if (retval!=0) { setverdict(fail, "Conversion failed: ", retval) } \ | |
59 | var type actual := method(bytes); \ | |
60 | COMPARE(actual, expected); \ | |
61 | } | |
62 | ||
63 | // Run an encode or decode expecting a DTE and compare the error message | |
64 | #define CHECK_METHOD_ERROR(method,input,type,expected_error) { \ | |
65 | @try { \ | |
66 | var type res := method(input); \ | |
67 | setverdict(fail, "Expected conversion error: ", expected_error); \ | |
68 | } @catch(err) { \ | |
69 | if (match(err, expected_error)) { setverdict(pass); } \ | |
70 | else { setverdict(fail, "Wrong error message! EXPECTED: ", expected_error, ", GOT: ", err); } \ | |
71 | } \ | |
72 | } | |
73 | ||
74 | // Run a decode and check that it failed | |
75 | #define CHECK_DECODE_FAIL(method,input,type) { \ | |
76 | var octetstring bytes; \ | |
77 | var integer retval := u2o("UTF-8", input, bytes); \ | |
78 | if (retval!=0) { setverdict(fail, "Conversion failed: ", retval) } \ | |
79 | var type actual; \ | |
80 | retval := method(bytes, actual); \ | |
81 | if (retval!=1) { log(": fail: Got ", retval, " instead of failure (1)"); \ | |
82 | setverdict(fail, "Expected failure (1), got: ", retval) } \ | |
83 | } | |
84 | ||
85 | // Run a decode and check that it failed, but compare the result of the decode | |
86 | #define CHECK_DECODE_FAIL_AND_COMPARE(method,input,type,expected) { \ | |
87 | var octetstring bytes; \ | |
88 | var integer retval := u2o("UTF-8", input, bytes); \ | |
89 | if (retval!=0) { setverdict(fail, "Conversion failed: ", retval) } \ | |
90 | var type actual; \ | |
91 | retval := method(bytes, actual); \ | |
92 | if (retval!=1) { log(": fail: Got ", retval, " instead of failure (1)"); \ | |
93 | setverdict(fail, "Expected failure (1), got: ", retval) } \ | |
94 | COMPARE(actual, expected); \ | |
95 | } | |
96 | ||
97 | /* | |
98 | Check both decodes. | |
99 | This has the disadvantage that the line number will be the same. | |
100 | Figuring out which decode failed may need some guesswork. | |
101 | But chances are, both will fail at the same time :) | |
102 | */ | |
103 | #define CHECK_DECODE2(typesuffix, input, type, expected) \ | |
104 | CHECK_DECODE(cxer_dec_ ## typesuffix, input, type, expected); \ | |
105 | CHECK_DECODE(bxer_dec_ ## typesuffix, input, type, expected) | |
106 | ||
107 | // Ease migration from CHECK_ENCODE :) | |
108 | #define CHECK_DECODE3(typesuffix, input, expected) \ | |
109 | CHECK_DECODE(cxer_dec_ ## typesuffix, input, Asn_ ## typesuffix, expected); \ | |
110 | CHECK_DECODE(bxer_dec_ ## typesuffix, input, Asn_ ## typesuffix, expected) | |
111 | ||
112 | ||
113 | #define DECLARE_XER_ENCODERS(Type, suffix) \ | |
114 | external function bxer_enc_ ## suffix(in Type par) return octetstring with { \ | |
115 | extension "prototype(convert) encode (XER:XER_BASIC) errorbehavior(ALL:ERROR)" } \ | |
116 | external function cxer_enc_ ## suffix(in Type par) return octetstring with { \ | |
117 | extension "prototype(convert) encode (XER:XER_CANONICAL) errorbehavior(ALL:ERROR)" } \ | |
118 | external function bxer_dec_ ## suffix(in octetstring par) return Type with { \ | |
119 | extension "prototype(convert) decode (XER:XER_BASIC) errorbehavior(ALL:ERROR)" } \ | |
120 | external function cxer_dec_ ## suffix(in octetstring par) return Type with { \ | |
121 | extension "prototype(convert) decode (XER:XER_CANONICAL) errorbehavior(ALL:ERROR)" } | |
122 | ||
123 | ||
124 | #define DECLARE_EXER_ENCODERS(Type, suffix) \ | |
125 | external function exer_enc_ ## suffix(in Type par) return octetstring with { \ | |
126 | extension "prototype(convert) encode (XER:XER_EXTENDED) errorbehavior(ALL:ERROR)" } \ | |
127 | external function exer_dec_ ## suffix(in octetstring par) return Type with { \ | |
128 | extension "prototype(convert) decode (XER:XER_EXTENDED) errorbehavior(ALL:ERROR)" } \ | |
129 | ||
130 | // Decoder which degrades all decoding errors to warnings to avoid DTE. | |
131 | // Using prototype(backtrack) to have a return value to check. | |
132 | #define DECLARE_EXER_WARNING_DECODER(Type, suffix) \ | |
133 | external function exer_decbt_ ## suffix(in octetstring par, out Type t) return integer with { \ | |
134 | extension "prototype(backtrack) decode (XER:XER_EXTENDED) errorbehavior(ALL:WARNING)" } \ | |
135 | ||
136 | // Note: errorbehavior(ALL:ERROR) ensures that all enc/dec errors are counted. | |
137 | // Encdec errors with error behavior of warning or ignore are not counted | |
138 | // in the final statistics. | |
139 | #endif | |
140 | ||
141 | ||
142 | // from isbound test | |
143 | #define MUST_BOUND(v) if ( isvalue(v) ) { \ | |
144 | if (verbose){ log( #v & "\t bound OK" ); } \ | |
145 | setverdict(pass); \ | |
146 | } else { \ | |
147 | log( ": fail: " & #v & "=", v, "\tshould be bound" ); \ | |
148 | setverdict(fail); \ | |
149 | } | |
150 | ||
151 | #define MUST_UNBOUND(v) if ( isvalue(v) ) { \ | |
152 | log( ": fail: " & #v & "=", v, "\tshould be unbound" ); \ | |
153 | setverdict(fail); \ | |
154 | } else { \ | |
155 | if (verbose){ log( #v & "\tunbound OK" ); } \ | |
156 | setverdict(pass); \ | |
157 | } | |
158 | ||
159 | /* A hack for two-element inline templates */ | |
160 | #define MUST_BOUND2(v,w) if ( isvalue(v,w) ) { \ | |
161 | if (verbose){ log( #v & #w & "\t bound OK" ); } \ | |
162 | setverdict(pass); \ | |
163 | } else { \ | |
164 | log( ": fail: " & #v & #w & "=", v,w, "\tshould be bound" ); \ | |
165 | setverdict(fail); \ | |
166 | } | |
167 | ||
168 | #define MUST_UNBOUND2(v,w) if ( isvalue(v,w) ) { \ | |
169 | log( ": fail: " & #v & #w & "=", v,w, "\tshould be unbound" ); \ | |
170 | setverdict(fail); \ | |
171 | } else { \ | |
172 | if (verbose){ log( #v & #w & "\tunbound OK" ); } \ | |
173 | setverdict(pass); \ | |
174 | } | |
175 |