| 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 |
| 7 | * |
| 8 | * Contributors: |
| 9 | * Balasko, Jeno |
| 10 | * Raduly, Csaba |
| 11 | * |
| 12 | ******************************************************************************/ |
| 13 | module AnyStuff { |
| 14 | |
| 15 | import from Flattener { function all } |
| 16 | |
| 17 | modulepar boolean AnyStuff_verbose := false; |
| 18 | #define verbose AnyStuff_verbose |
| 19 | #include "../macros.ttcnin" |
| 20 | |
| 21 | type component Anything {} |
| 22 | |
| 23 | type record AnyElem { |
| 24 | universal charstring Html, |
| 25 | integer num |
| 26 | } |
| 27 | with { |
| 28 | variant (Html) "anyElement" |
| 29 | } |
| 30 | |
| 31 | type record UnivAnyElem { |
| 32 | universal charstring Html, |
| 33 | integer num |
| 34 | } |
| 35 | with { |
| 36 | variant (Html) "anyElement" |
| 37 | } |
| 38 | |
| 39 | type record AnyElemList { |
| 40 | record of universal charstring elem_list |
| 41 | , integer f1 optional |
| 42 | , charstring f2 optional |
| 43 | } |
| 44 | with { |
| 45 | variant (elem_list) "anyElement" // perhaps this should now be variant (elem_list[-]) |
| 46 | } |
| 47 | |
| 48 | DECLARE_XER_ENCODERS(AnyElem, ae); |
| 49 | DECLARE_EXER_ENCODERS(AnyElem, ae); |
| 50 | |
| 51 | DECLARE_XER_ENCODERS(UnivAnyElem, uae); |
| 52 | DECLARE_EXER_ENCODERS(UnivAnyElem, uae); |
| 53 | |
| 54 | DECLARE_XER_ENCODERS(AnyElemList, anyt); |
| 55 | DECLARE_EXER_ENCODERS(AnyElemList, anyt); |
| 56 | |
| 57 | const AnyElem ae1 := { |
| 58 | "<html><head><title>Hello</title></head><body>nobody</body></html>", |
| 59 | 42 |
| 60 | } |
| 61 | |
| 62 | const UnivAnyElem uae1 := { |
| 63 | "<html><head><title>Hello</title></head><body>nobody</body></html>", |
| 64 | 42 |
| 65 | } |
| 66 | |
| 67 | const AnyElemList aybabtu := { |
| 68 | { "<all/>", "<your/>", "<base/>", "<are/>", "<belong to='us'/>" } |
| 69 | , omit, omit |
| 70 | } |
| 71 | |
| 72 | const AnyElemList aybabtu_expect := { |
| 73 | { "<all/>", "<your/>", "<base/>", "<are/>", "<belong to=\"us\"/>" } |
| 74 | , omit, omit |
| 75 | } |
| 76 | |
| 77 | const universal charstring ae1str := |
| 78 | "<AnyElem>\n" & |
| 79 | "\t<html><head><title>Hello</title></head><body>nobody</body></html>\n" & |
| 80 | "\t<num>42</num>\n" & |
| 81 | "</AnyElem>\n\n"; |
| 82 | |
| 83 | const universal charstring ae1strb := // for Basic XER |
| 84 | "<AnyElem>\n" & |
| 85 | "\t<Html><html><head><title>Hello</title></head><body>nobody</body></html></Html>\n" & |
| 86 | "\t<num>42</num>\n" & |
| 87 | "</AnyElem>\n\n"; |
| 88 | |
| 89 | const universal charstring uae1str := |
| 90 | "<UnivAnyElem>\n" & |
| 91 | "\t<html><head><title>Hello</title></head><body>nobody</body></html>\n" & |
| 92 | "\t<num>42</num>\n" & |
| 93 | "</UnivAnyElem>\n\n"; |
| 94 | |
| 95 | const universal charstring uae1strb := // for Basic XER |
| 96 | "<UnivAnyElem>\n" & |
| 97 | "\t<Html><html><head><title>Hello</title></head><body>nobody</body></html></Html>\n" & |
| 98 | "\t<num>42</num>\n" & |
| 99 | "</UnivAnyElem>\n\n"; |
| 100 | |
| 101 | const universal charstring aybabtustr := |
| 102 | "<AnyElemList>\n" & |
| 103 | "\t<all/>\n" & |
| 104 | "\t<your/>\n" & |
| 105 | "\t<base/>\n" & |
| 106 | "\t<are/>\n" & |
| 107 | "\t<belong to='us'/>\n" & |
| 108 | "</AnyElemList>\n\n"; |
| 109 | |
| 110 | const universal charstring aybabtustr_b := |
| 111 | "<AnyElemList>\n" & |
| 112 | "\t<elem_list>\n" & |
| 113 | "\t\t<UNIVERSAL_CHARSTRING><all/></UNIVERSAL_CHARSTRING>\n" & |
| 114 | "\t\t<UNIVERSAL_CHARSTRING><your/></UNIVERSAL_CHARSTRING>\n" & |
| 115 | "\t\t<UNIVERSAL_CHARSTRING><base/></UNIVERSAL_CHARSTRING>\n" & |
| 116 | "\t\t<UNIVERSAL_CHARSTRING><are/></UNIVERSAL_CHARSTRING>\n" & |
| 117 | "\t\t<UNIVERSAL_CHARSTRING><belong to='us'/></UNIVERSAL_CHARSTRING>\n" & |
| 118 | "\t</elem_list>\n" & |
| 119 | "</AnyElemList>\n\n"; |
| 120 | |
| 121 | |
| 122 | testcase enc_anyelement() runs on Anything |
| 123 | { |
| 124 | CHECK_METHOD(bxer_enc_ae, ae1, ae1strb); |
| 125 | CHECK_METHOD(exer_enc_ae, ae1, ae1str); |
| 126 | |
| 127 | CHECK_METHOD(bxer_enc_uae, uae1, uae1strb); |
| 128 | CHECK_METHOD(exer_enc_uae, uae1, uae1str); |
| 129 | |
| 130 | CHECK_METHOD(bxer_enc_anyt, aybabtu, aybabtustr_b); |
| 131 | CHECK_METHOD(exer_enc_anyt, aybabtu, aybabtustr); |
| 132 | } |
| 133 | |
| 134 | testcase dec_anyelement() runs on Anything |
| 135 | { |
| 136 | CHECK_DECODE(bxer_dec_ae, ae1strb, AnyElem, ae1); |
| 137 | CHECK_DECODE(exer_dec_ae, ae1str , AnyElem, ae1); |
| 138 | CHECK_DECODE(exer_dec_ae, flatten(ae1str), AnyElem, ae1); |
| 139 | |
| 140 | CHECK_DECODE(bxer_dec_uae, uae1strb, UnivAnyElem, uae1); |
| 141 | CHECK_DECODE(exer_dec_uae, uae1str , UnivAnyElem, uae1); |
| 142 | CHECK_DECODE(exer_dec_uae, flatten(uae1str), UnivAnyElem, uae1); |
| 143 | |
| 144 | var AnyElemList expected := aybabtu; |
| 145 | CHECK_DECODE(bxer_dec_anyt, aybabtustr_b, AnyElemList, expected); |
| 146 | //No, it should NOT do this: expected.elem_list := {} |
| 147 | //This is not an EMBED-VALUES! |
| 148 | expected := aybabtu_expect; |
| 149 | CHECK_DECODE(exer_dec_anyt, aybabtustr, AnyElemList, expected); |
| 150 | CHECK_DECODE(exer_dec_anyt, flatten(aybabtustr), AnyElemList, expected); |
| 151 | } |
| 152 | |
| 153 | control |
| 154 | { |
| 155 | execute(enc_anyelement()); |
| 156 | execute(dec_anyelement()); |
| 157 | } |
| 158 | |
| 159 | } |
| 160 | with { encode "XML" } |