/****************************************************************************** * Copyright (c) 2000-2015 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 ******************************************************************************/ module Order { // USE-ORDER tests straight out of the whitepaper modulepar boolean Order_verbose := false; #define verbose Order_verbose #include "../macros.ttcnin" type component Ord {} // Example 1: "Plain" USE-ORDER type record UOProductO { record of enumerated { id, name, price, color } order, charstring available, // this is not in the whitepaper integer id, charstring name, float price, charstring color } with { variant "element"; variant "useOrder"; variant "namespace as 'http://www.example.com' prefix 'exm'"; variant (available) "attribute"; } DECLARE_XER_ENCODERS(UOProductO, prodO); DECLARE_EXER_ENCODERS(UOProductO, prodO); const UOProductO uoprod := { order := { id, color, price, name }, available := "", id := 100, name := "shirt", price := 12.23, color := "red" } const universal charstring str_prod_e := "\n" & "\t100\n" & "\tred\n" & "\t12.230000\n" & "\tshirt\n" & "\n" & "\n"; const universal charstring str_prod_b := "\n" & "\t\n" & "\t\t\n" & "\t\n" & "\t<true/>\n" & "\t100\n" & "\tshirt\n" & "\t12.230000\n" & "\tred\n" & "\n" & "\n"; testcase enc_uo() runs on Ord { CHECK_METHOD(bxer_enc_prodO, uoprod, str_prod_b); CHECK_METHOD(exer_enc_prodO, uoprod, str_prod_e); } testcase dec_uo() runs on Ord { CHECK_DECODE(bxer_dec_prodO, str_prod_b, UOProductO, uoprod); CHECK_DECODE(exer_dec_prodO, str_prod_e, UOProductO, uoprod); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // Example 2: USE-ORDER and EMBED-VALUES type record UOProductEmb { record length(5) of universal charstring embed, record of enumerated { id, name, price, color } order, integer id, charstring name, float price, charstring color } with { variant "element"; variant "useOrder"; variant "embedValues"; variant "namespace as 'http://www.example.com' prefix 'exm'"; } DECLARE_XER_ENCODERS(UOProductEmb, prod5); DECLARE_EXER_ENCODERS(UOProductEmb, prod5); const UOProductEmb prod5 := { embed := {"Order Id ", "", "", "US Dollars", "" }, order := { id, color, price, name }, id := 100, name := "shirt", price := 12.23, color := "red" } const universal charstring str_prod5_e := "Order Id " & "100red12.230000US Dollarsshirt" & "\n"; const universal charstring str_prod5_b := "\n" & "\t\n" & "\t\tOrder Id \n" & "\t\t\n" & "\t\t\n" & "\t\tUS Dollars\n" & "\t\t\n" & "\t\n" & "\t\n" & "\t\t\n" & "\t\n" & "\t100\n" & "\tshirt\n" & "\t12.230000\n" & "\tred\n" & "\n" & "\n"; testcase enc_uo_emb() runs on Ord { CHECK_METHOD(bxer_enc_prod5, prod5, str_prod5_b); CHECK_METHOD(exer_enc_prod5, prod5, str_prod5_e); } testcase dec_uo_emb() runs on Ord { var UOProductEmb expected := prod5; CHECK_DECODE(bxer_dec_prod5, str_prod5_b, UOProductEmb, expected); CHECK_DECODE(exer_dec_prod5, str_prod5_e, UOProductEmb, expected); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // Example 3: USE-ORDER and USE-NIL type record UOProductNil { record of enumerated { id, name, price, color } order, boolean available, // not in the whitepaper UOProductInfo info optional } with { variant "element"; variant "useOrder"; variant "useNil"; variant (available) "attribute"; variant "namespace as 'http://www.example.com' prefix 'exm'"; } type record UOProductInfo { integer id, charstring name, float price, charstring color } DECLARE_XER_ENCODERS(UOProductNil, prod0); DECLARE_EXER_ENCODERS(UOProductNil, prod0); // ... ... present ... ... const UOProductNil prod0 := { order := { id, color, price, name }, available := true, info := { id := 100, name := "shirt", price := 12.23, color := "red" } } const universal charstring str_prod0_e := "\n" & "\t100\n" & "\tred\n" & "\t12.230000\n" & "\tshirt\n" & "\n" & "\n"; // 'nil' attribute present but says 'no' const universal charstring str_prod0nonil_e := "\n" & "\t100\n" & "\tred\n" & "\t12.230000\n" & "\tshirt\n" & "\n" & "\n"; const universal charstring str_prod0_b := "\n" & "\t\n" & "\t\t\n" & "\t\n" & "\t\n" & "\t\n" & "\t\t100\n" & "\t\tshirt\n" & "\t\t12.230000\n" & "\t\tred\n" & "\t\n" & "\n" & "\n"; testcase enc_uo_nil_present() runs on Ord { CHECK_METHOD(bxer_enc_prod0, prod0, str_prod0_b); CHECK_METHOD(exer_enc_prod0, prod0, str_prod0_e); } testcase dec_uo_nil_present() runs on Ord { CHECK_DECODE(bxer_dec_prod0, str_prod0_b, UOProductNil, prod0); CHECK_DECODE(exer_dec_prod0, str_prod0_e, UOProductNil, prod0); CHECK_DECODE(exer_dec_prod0, str_prod0nonil_e, UOProductNil, prod0); } // Example 4: ... ... absent ... ... const UOProductNil prod0nil := { order := { }, available := false, info := omit } const universal charstring str_prod0nil_e := "\n" & "\n"; const universal charstring str_prod0nil_b := "\n" & "\t\n" & "\t\n" & "\n" & "\n"; testcase enc_uo_nil_absent() runs on Ord { CHECK_METHOD(bxer_enc_prod0, prod0nil, str_prod0nil_b); CHECK_METHOD(exer_enc_prod0, prod0nil, str_prod0nil_e); } testcase dec_uo_nil_absent() runs on Ord { CHECK_DECODE(bxer_dec_prod0, str_prod0nil_b, UOProductNil, prod0nil); CHECK_DECODE(exer_dec_prod0, str_prod0nil_e, UOProductNil, prod0nil); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // Example 5: USE-ORDER and ANY-ELEMENT type record UORecordAny { record of enumerated { id, anyElem, bytes, anyElem2 } order, integer id, universal charstring anyElem, octetstring bytes, universal charstring anyElem2 } with { variant "useOrder"; variant (anyElem) "anyElement"; variant (anyElem2) "anyElement"; } DECLARE_EXER_ENCODERS(UORecordAny, uo_any); const UORecordAny any0 := { order := { bytes, anyElem, anyElem2, id }, id := 2, anyElem := "", bytes := 'A1'O, anyElem2 := "123" }; const universal charstring str_any0 := "\n" & "\tA1\n" & "\t\n" & "\t123\n" & "\t2\n" & "\n\n"; testcase enc_uo_any() runs on Ord { CHECK_METHOD(exer_enc_uo_any, any0, str_any0); } testcase dec_uo_any() runs on Ord { CHECK_DECODE(exer_dec_uo_any, str_any0, UORecordAny, any0); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // Example 6: USE-ORDER with only one element that is optional type record UORecordOneOpt { record of enumerated { id } order, integer id optional } with { variant "useOrder"; } DECLARE_EXER_ENCODERS(UORecordOneOpt, uo_one_opt); const UORecordOneOpt one_opt := { order := { id }, id := 2 }; const universal charstring str_one_opt_e := "\n" & "\t2\n" & "\n\n"; testcase enc_uo_one_opt() runs on Ord { CHECK_METHOD(exer_enc_uo_one_opt, one_opt, str_one_opt_e); } testcase dec_uo_one_opt() runs on Ord { CHECK_DECODE(exer_dec_uo_one_opt, str_one_opt_e, UORecordOneOpt, one_opt); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // Example 7: USE-ORDER with only one record element that is optional type record UORecordOneOpt2 { record of enumerated { id } order, RecordOneOpt id optional } with { variant "useOrder"; } type record RecordOneOpt { integer identity } DECLARE_EXER_ENCODERS(UORecordOneOpt2, uo_one_opt2); const UORecordOneOpt2 one_opt2 := { order := { id }, id := { identity := 2 } }; const universal charstring str_one_opt2_e := "\n" & "\t\n" & "\t\t2\n" & "\t\n" & "\n\n"; testcase enc_uo_one_opt2() runs on Ord { CHECK_METHOD(exer_enc_uo_one_opt2, one_opt2, str_one_opt2_e); } testcase dec_uo_one_opt2() runs on Ord { CHECK_DECODE(exer_dec_uo_one_opt2, str_one_opt2_e, UORecordOneOpt2, one_opt2); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- control { execute(enc_uo()); execute(dec_uo()); execute(enc_uo_emb()); execute(dec_uo_emb()); execute(enc_uo_nil_present()); execute(enc_uo_nil_absent()); execute(dec_uo_nil_present()); execute(dec_uo_nil_absent()); execute(enc_uo_any()); execute(dec_uo_any()); execute(enc_uo_one_opt()); execute(dec_uo_one_opt()); execute(enc_uo_one_opt2()); execute(dec_uo_one_opt2()); } } with { encode "XML" variant "controlNamespace 'http://www.w3.org/2001/XMLSchema-instance' prefix 'xsi'" /* A "namespace" attribute here would have the equivalent effect of NAMESPACE ALL AS ... rather than NAMESPACE ALL, ALL IN ALL AS ... because (at least for a record or set type) unqualified attributes stop there and are not propagated to the component. */ }