1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
13 ******************************************************************************/
15 * Note: this file needs to be included *after* this bit:
18 * modulepar boolean verbose := false;
21 /* The following macros output error/warning messages in the "GCC format",
22 * which can be parsed by Eclipse.
25 // A TODO in the output
27 log(": warning: not implemented"); \
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" ); } \
37 log(": fail: G0T ", actual ); \
38 log(": fail: EXP ", expected); \
39 setverdict(fail, match(actual,expected)); \
43 import from converter all;
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); \
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); \
63 // Run an encode or decode expecting a DTE and compare the error message
64 #define CHECK_METHOD_ERROR(method,input,type,expected_error) { \
66 var type res := method(input); \
67 setverdict(fail, "Expected conversion error: ", expected_error); \
69 if (match(err, expected_error)) { setverdict(pass); } \
70 else { setverdict(fail, "Wrong error message! EXPECTED: ", expected_error, ", GOT: ", err); } \
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) } \
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) } \
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) } \
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); \
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 :)
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)
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)
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)" }
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)" } \
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)" } \
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.
143 #define MUST_BOUND(v) if ( isvalue(v) ) { \
144 if (verbose){ log( #v & "\t bound OK" ); } \
147 log( ": fail: " & #v & "=", v, "\tshould be bound" ); \
151 #define MUST_UNBOUND(v) if ( isvalue(v) ) { \
152 log( ": fail: " & #v & "=", v, "\tshould be unbound" ); \
155 if (verbose){ log( #v & "\tunbound OK" ); } \
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" ); } \
164 log( ": fail: " & #v & #w & "=", v,w, "\tshould be bound" ); \
168 #define MUST_UNBOUND2(v,w) if ( isvalue(v,w) ) { \
169 log( ": fail: " & #v & #w & "=", v,w, "\tshould be unbound" ); \
172 if (verbose){ log( #v & #w & "\tunbound OK" ); } \