/****************************************************************************** * Copyright (c) 2000-2014 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 AnyElementOptional { modulepar boolean AnyElement_verbose := false; #define verbose AnyElement_verbose #include "../macros.ttcnin" type component AE {} type record AEProduct { charstring name, integer price, universal charstring info optional } with { variant (info) "anyElement from 'http://www.example.com/A', " "'http://www.example.com/B', unqualified" } DECLARE_XER_ENCODERS(AEProduct, ae); DECLARE_EXER_ENCODERS(AEProduct, ae); const AEProduct aep := { name := "Trousers", price := 20, info := "red" } const universal charstring str_ae_e := "\n" & "\tTrousers\n" & "\t20\n" & "\tred\n" & "\n\n"; const universal charstring str_ae_b := "\n" & "\tTrousers\n" & "\t20\n" & "\t<xyz:color xmlns:xyz="http://www.example.com/A" available="true">red</xyz:color>\n" & "\n\n"; testcase encode_aeopt() runs on AE { CHECK_METHOD(bxer_enc_ae, aep, str_ae_b); CHECK_METHOD(exer_enc_ae, aep, str_ae_e); } testcase decode_aeopt() runs on AE { CHECK_DECODE(bxer_dec_ae, str_ae_b, AEProduct, aep); CHECK_DECODE(exer_dec_ae, str_ae_e, AEProduct, aep); } // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --. // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. - type record AFProduct { charstring name, integer price, universal charstring info optional } with { variant (info) "anyElement except 'http://www.example.com/A', 'http://www.example.com/B', unqualified" } DECLARE_XER_ENCODERS(AFProduct, af); DECLARE_EXER_ENCODERS(AFProduct, af); const AFProduct afp := { name := "Trousers", price := 20, info := "red" } const universal charstring str_af_e := "\n" & "\tTrousers\n" & "\t20\n" & "\tred\n" & "\n\n"; const universal charstring str_af_b := "\n" & "\tTrousers\n" & "\t20\n" & "\t<xyz:color xmlns:xyz="http://www.example.com/C" available="true">red</xyz:color>\n" & "\n\n"; testcase encode_afopt() runs on AE { CHECK_METHOD(bxer_enc_af, afp, str_af_b); CHECK_METHOD(exer_enc_af, afp, str_af_e); } testcase decode_afopt() runs on AE { CHECK_DECODE(bxer_dec_af, str_af_b, AFProduct, afp); CHECK_DECODE(exer_dec_af, str_af_e, AFProduct, afp); } // .- -. -.. / -. --- .-- / ..-. --- .-. / ... --- -- . - .... .. -. --. // -.-. --- -- .--. .-.. . - . .-.. -.-- / -.. .. ..-. ..-. . .-. . -. - // ANY-ELEMENT as the only member of a record is a corner case type record anys_and_only_anys { record of universal charstring elements optional } with { variant (elements) "anyElement" } DECLARE_XER_ENCODERS(anys_and_only_anys, aaoa); DECLARE_EXER_ENCODERS(anys_and_only_anys, aaoa); const anys_and_only_anys noanys := { elements := {} } const universal charstring bstr_noanys := "\n" & "\t\n" & "\n\n"; const universal charstring estr_noanys := "\n\n"; const anys_and_only_anys marx := { elements := {"", "", ""} } const universal charstring estr_marx := "\n" & "\t\n" & "\t\n" & "\t\n" & "\n\n"; const universal charstring bstr_marx := "\n" & "\t\n" & "\t\t<chico/>\n" & "\t\t<groucho/>\n" & "\t\t<karl></karl>\n" & "\t\n" & "\n\n"; // When decoding EXER, karl becomes an empty element too (?) const anys_and_only_anys marx_dec := { elements := {"", "", ""} } testcase encode_only_opt() runs on AE { CHECK_METHOD(bxer_enc_aaoa, noanys, bstr_noanys); CHECK_METHOD(exer_enc_aaoa, noanys, estr_noanys); CHECK_METHOD(bxer_enc_aaoa, marx, bstr_marx); CHECK_METHOD(exer_enc_aaoa, marx, estr_marx); } testcase decode_only_opt() runs on AE { CHECK_DECODE(bxer_dec_aaoa, bstr_noanys, anys_and_only_anys, noanys); CHECK_DECODE(exer_dec_aaoa, estr_noanys, anys_and_only_anys, noanys); CHECK_DECODE(bxer_dec_aaoa, bstr_marx, anys_and_only_anys, marx); CHECK_DECODE(exer_dec_aaoa, estr_marx, anys_and_only_anys, marx_dec); } control { execute(encode_aeopt()) execute(decode_aeopt()) execute(encode_afopt()) execute(decode_afopt()) // execute(encode_anys()) // execute(decode_anys()) // execute(encode_utanys()) // execute(decode_utanys()) execute(encode_only_opt()) execute(decode_only_opt()) } } with { encode "XML" }