Commit | Line | Data |
---|---|---|
970ed795 | 1 | /****************************************************************************** |
3abe9331 | 2 | * Copyright (c) 2000-2015 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 | |
7 | ******************************************************************************/ | |
8 | module Txerint { | |
9 | ||
10 | modulepar boolean verbose := false; | |
11 | ||
12 | #include "../macros.ttcnin" | |
13 | ||
14 | import from AsnValues all; | |
15 | type component TINT {} | |
16 | ||
17 | external function flatten(inout universal charstring par) ; | |
18 | ||
19 | DECLARE_XER_ENCODERS(integer, int); | |
20 | DECLARE_EXER_ENCODERS(integer,int) | |
21 | DECLARE_XER_ENCODERS(r_int, r_int); | |
22 | DECLARE_EXER_ENCODERS(r_int,r_int) | |
23 | DECLARE_XER_ENCODERS(u_int, u_int); | |
24 | DECLARE_EXER_ENCODERS(u_int,u_int) | |
25 | ||
26 | type record r_int { | |
27 | integer i optional | |
28 | } | |
29 | ||
30 | type union u_int { | |
31 | integer i | |
32 | } | |
33 | ||
34 | testcase encode_int() runs on TINT | |
35 | { | |
36 | var integer plain := 42; | |
37 | var universal charstring expected := "<INTEGER>42</INTEGER>"; | |
38 | CHECK_METHOD(cxer_enc_int, plain, expected); | |
39 | CHECK_METHOD(bxer_enc_int, plain, expected & lf); | |
40 | CHECK_METHOD(exer_enc_int, plain, expected & lf); | |
41 | ||
42 | plain := -13; | |
43 | expected := "<INTEGER>-13</INTEGER>"; | |
44 | CHECK_METHOD(cxer_enc_int, plain, expected); | |
45 | CHECK_METHOD(bxer_enc_int, plain, expected & lf); | |
46 | CHECK_METHOD(exer_enc_int, plain, expected & lf); | |
47 | ||
48 | plain := 0; | |
49 | expected := "<INTEGER>0</INTEGER>"; | |
50 | CHECK_METHOD(cxer_enc_int, plain, expected); | |
51 | CHECK_METHOD(bxer_enc_int, plain, expected & lf); | |
52 | CHECK_METHOD(exer_enc_int, plain, expected & lf); | |
53 | ||
54 | plain := -0; | |
55 | expected := "<INTEGER>0</INTEGER>"; | |
56 | CHECK_METHOD(cxer_enc_int, plain, expected); | |
57 | CHECK_METHOD(bxer_enc_int, plain, expected & lf); | |
58 | CHECK_METHOD(exer_enc_int, plain, expected & lf); | |
59 | ||
60 | plain := 602214179000000000000000; | |
61 | expected := "<INTEGER>602214179000000000000000</INTEGER>"; | |
62 | CHECK_METHOD(cxer_enc_int, plain, expected); | |
63 | CHECK_METHOD(bxer_enc_int, plain, expected & lf); | |
64 | CHECK_METHOD(exer_enc_int, plain, expected & lf); | |
65 | } | |
66 | ||
67 | testcase decode_int() runs on TINT | |
68 | { | |
69 | var integer expected := 42; | |
70 | const charstring the_answer := "<INTEGER>42</INTEGER>"; | |
71 | CHECK_DECODE(cxer_dec_int, the_answer, integer, expected); | |
72 | CHECK_DECODE(bxer_dec_int, the_answer, integer, expected); | |
73 | ||
74 | // this is not a valid encoding of an integer: | |
75 | //const charstring deep_answer := "<INTEGER><deep>42</deep></INTEGER>" | |
76 | //CHECK_DECODE(cxer_dec_int, deep_answer, integer, expected); | |
77 | //CHECK_DECODE(bxer_dec_int, deep_answer, integer, expected); | |
78 | ||
79 | const charstring eris := "<INTEGER>-13</INTEGER>"; | |
80 | expected := -13; | |
81 | CHECK_DECODE(cxer_dec_int, eris, integer, expected); | |
82 | CHECK_DECODE(bxer_dec_int, eris, integer, expected); | |
83 | ||
84 | const charstring nought := "<INTEGER>0</INTEGER>"; | |
85 | expected := 0; | |
86 | CHECK_DECODE(cxer_dec_int, nought, integer, expected); | |
87 | CHECK_DECODE(bxer_dec_int, nought, integer, expected); | |
88 | ||
89 | const charstring minought := "<INTEGER>0</INTEGER>"; | |
90 | expected := -0; | |
91 | CHECK_DECODE(cxer_dec_int, minought, integer, expected); | |
92 | CHECK_DECODE(bxer_dec_int, minought, integer, expected); | |
93 | ||
94 | const charstring avogadros := "<INTEGER><!-- Hey look, Avogadro's constant -->602214179000000000000000</INTEGER>"; | |
95 | expected := 602214179000000000000000; | |
96 | CHECK_DECODE(cxer_dec_int, avogadros, integer, expected); | |
97 | CHECK_DECODE(bxer_dec_int, avogadros, integer, expected); | |
98 | ||
99 | // The following should cause a runtime error (and not a segfault!) | |
100 | // when the XmlReader creation fails. But we can't test that here. | |
101 | // CHECK_DECODE(bxer_dec_int, "", integer, 0); | |
102 | } | |
103 | ||
104 | testcase encode_integer_omit() runs on TINT | |
105 | { | |
106 | var r_int rec := { omit } | |
107 | var universal charstring expected := "<r_int/>\n"; | |
108 | CHECK_METHOD(cxer_enc_r_int, rec, expected); | |
109 | CHECK_METHOD(bxer_enc_r_int, rec, expected & lf); | |
110 | CHECK_METHOD(exer_enc_r_int, rec, expected & lf); | |
111 | ||
112 | rec.i := 33; | |
113 | expected := "<r_int>\n\t<i>33</i>\n</r_int>\n\n"; | |
114 | CHECK_METHOD(bxer_enc_r_int, rec, expected); | |
115 | CHECK_METHOD(exer_enc_r_int, rec, expected); | |
116 | flatten(expected); | |
117 | CHECK_METHOD(cxer_enc_r_int, rec, expected & lf); | |
118 | } | |
119 | ||
120 | testcase decode_integer_omit() runs on TINT | |
121 | { | |
122 | var r_int expected := { omit } | |
123 | const charstring omitted := "<r_int/>\n"; | |
124 | CHECK_DECODE(cxer_dec_r_int, omitted, r_int, expected); | |
125 | CHECK_DECODE(bxer_dec_r_int, omitted, r_int, expected); | |
126 | ||
127 | const charstring supplied := "<r_int><i>37</i></r_int>\n"; | |
128 | expected.i := 37; | |
129 | CHECK_DECODE(cxer_dec_r_int, supplied, r_int, expected); | |
130 | CHECK_DECODE(bxer_dec_r_int, supplied, r_int, expected); | |
131 | } | |
132 | ||
133 | testcase encode_integer_choice() runs on TINT | |
134 | { | |
135 | var u_int rec := { i := 17 } | |
136 | var universal charstring expected := "<u_int>\n\t<i>17</i>\n</u_int>\n\n"; | |
137 | CHECK_METHOD(bxer_enc_u_int, rec, expected); | |
138 | CHECK_METHOD(exer_enc_u_int, rec, expected); | |
139 | flatten(expected); | |
140 | CHECK_METHOD(cxer_enc_u_int, rec, expected & lf); | |
141 | } | |
142 | ||
143 | testcase decode_integer_choice() runs on TINT | |
144 | { | |
145 | var u_int expected := { i := 19 } | |
146 | const charstring omitted := "<u_int>\n\t<i>19</i>\n</u_int>\n"; | |
147 | CHECK_DECODE(cxer_dec_u_int, omitted, u_int, expected); | |
148 | CHECK_DECODE(bxer_dec_u_int, omitted, u_int, expected); | |
149 | } | |
150 | ||
151 | ||
152 | control { | |
153 | execute(encode_int()); | |
154 | execute(decode_int()); | |
155 | execute(encode_integer_omit()) | |
156 | execute(decode_integer_omit()) | |
157 | execute(encode_integer_choice()); | |
158 | execute(decode_integer_choice()); | |
159 | } | |
160 | ||
161 | } | |
162 | with { | |
163 | encode "XML"; | |
164 | extension "version R8J"; // I is forbidden | |
165 | } |