/****************************************************************************** * 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 AnyAttributes { modulepar boolean AnyAttributes_verbose := false; #define verbose AnyAttributes_verbose #include "../macros.ttcnin" type component AA {} type record of universal charstring AttrList; type record AAProduct { AttrList info, // a record of universal charstring charstring name, integer price } with { variant (info) "anyAttributes from 'http://www.example.com/A', " "'http://www.example.com/B', unqualified" // 'absent' is used by ASN.1 } DECLARE_XER_ENCODERS(AAProduct, aap); DECLARE_EXER_ENCODERS(AAProduct, aap); const AAProduct aap := { info := { "http://www.example.com/A size=""small""", "http://www.example.com/B color=""red""", "http://www.example.com/B x=""spot""", "available=""yes"""}, name := "Trousers", price:= 20 } const AAProduct aap_trouble := { info := { "http://www.example.com/A size=""small""", // too many spaces "http://www.example.com/B color=""red"" ", // spaces after "http://www.example.com/B x=""spot"" ", // spaces before and after "available=""yes"""}, name := "Trousers", price:= 20 } const AAProduct aap_tabs := { info := { "http://www.example.com/A\t\t size=""small""", // too many spaces "http://www.example.com/B\tcolor=""red""\t\t", // spaces after "http://www.example.com/B\t\tx=""spot"" \t ", // spaces before and after "available=""yes"""}, name := "Trousers", price:= 20 } const AAProduct aap_jumbled := { info := { "http://www.example.com/B color=""red""", "http://www.example.com/A size=""small""", "available=""yes"""}, name := "Trousers", price:= 20 } /* _e is for EXER, _b is for BXER */ const universal charstring str_aap_e := "\n" & "\tTrousers\n" & "\t20\n" & "\n\n"; const universal charstring str_aap_e_jumbled := "\n" & "\tTrousers\n" & "\t20\n" & "\n\n"; const universal charstring str_aap_b := "\n" & "\t\n" & "\t\thttp://www.example.com/A size="small"\n" & "\t\thttp://www.example.com/B color="red"\n" & "\t\thttp://www.example.com/B x="spot"\n" & "\t\tavailable="yes"\n" & "\t\n" & "\tTrousers\n" & "\t20\n" & "\n\n"; testcase encode_aa() runs on AA { CHECK_METHOD(bxer_enc_aap, aap, str_aap_b); CHECK_METHOD(exer_enc_aap, aap, str_aap_e); CHECK_METHOD(exer_enc_aap, aap_trouble, str_aap_e); CHECK_METHOD(exer_enc_aap, aap_tabs , str_aap_e); } testcase decode_aa() runs on AA { CHECK_DECODE(bxer_dec_aap, str_aap_b, AAProduct, aap); CHECK_DECODE(exer_dec_aap, str_aap_e, AAProduct, aap); CHECK_DECODE(exer_dec_aap, str_aap_e_jumbled, AAProduct, aap_jumbled); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- type record ABProduct { AttrList info, // a record of universal charstring charstring name, integer price } with { variant (info) "anyAttributes except 'http://www.example.com/C', unqualified" } DECLARE_XER_ENCODERS(ABProduct, abp); DECLARE_EXER_ENCODERS(ABProduct, abp); const ABProduct abp := { info := { "http://www.example.com/A size=""small""", "http://www.example.com/B color=""red""", "http://www.example.com/B available=""yes"""}, name := "Trousers", price:= 20 } const universal charstring str_abp_e := //"\n" & // this one below is a workaround because the encoder doesn't recognize that namespace b1 has already been declared :( "\n" & "\tTrousers\n" & "\t20\n" & "\n\n"; const universal charstring str_abp_b := "\n" & "\t\n" & "\t\thttp://www.example.com/A size="small"\n" & "\t\thttp://www.example.com/B color="red"\n" & "\t\thttp://www.example.com/B available="yes"\n" & //originally: "\t\tavailable=\"yes\"\n" & "\t\n" & "\tTrousers\n" & "\t20\n" & "\n\n"; testcase encode_ab() runs on AA { CHECK_METHOD(bxer_enc_abp, abp, str_abp_b); CHECK_METHOD(exer_enc_abp, abp, str_abp_e); } testcase decode_ab() runs on AA { CHECK_DECODE(bxer_dec_abp, str_abp_b, ABProduct, abp); CHECK_DECODE(exer_dec_abp, str_abp_e, ABProduct, abp); } type record ouch { record of universal charstring embed, AttrList aa // a record of universal charstring } with { variant "embedValues" } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- // ANY-ATTRIBUTES and "normal" ATTRIBUTES type record AXProduct { charstring name, AttrList info, // a record of universal charstring boolean available, integer price } with { variant (info) "anyAttributes from 'http://www.example.com/X', unqualified"; variant (name) "attribute"; variant (available) "attribute" } DECLARE_XER_ENCODERS(AXProduct, axp); DECLARE_EXER_ENCODERS(AXProduct, axp); const AXProduct axp := { name := "Trousers", info := { "http://www.example.com/X size=""small""", "http://www.example.com/X color=""red""", "http://www.example.com/X available=""yes"""}, available := false, price:= 20 } const universal charstring estr_axp := //"\n" & // this one below is a workaround because the encoder doesn't recognize that namespace b1 has already been declared :( "\n" & "\t20\n" & "\n\n"; const universal charstring bstr_axp := "\n" & "\tTrousers\n" & "\t\n" & "\t\thttp://www.example.com/X size="small"\n" & "\t\thttp://www.example.com/X color="red"\n" & "\t\thttp://www.example.com/X available="yes"\n" & //originally: "\t\tavailable=\"yes\"\n" & "\t\n" & "\t\n" & "\t20\n" & "\n\n"; testcase encode_ax() runs on AA { CHECK_METHOD(bxer_enc_axp, axp, bstr_axp); CHECK_METHOD(exer_enc_axp, axp, estr_axp); } testcase decode_ax() runs on AA { CHECK_DECODE(bxer_dec_axp, bstr_axp, AXProduct, axp); //not quite right yet: CHECK_DECODE(exer_dec_axp, estr_axp, AXProduct, axp); } // Negative tests for namespace restrinctions in ANY-ATTRIBUTES // 1. anyAttributes from ... type record AAFProduct { AttrList info, // a record of universal charstring charstring name } with { variant (info) "anyAttributes from 'http://www.example.com/X', unqualified" } DECLARE_EXER_ENCODERS(AAFProduct, aaf); const AAFProduct aaf := { info := { "http://www.example.com/X size=""small""", "http://www.example.com/Y color=""red""", "available=""yes"""}, name := "Trousers" } const octetstring str_aaf := unichar2oct( "\n" & "\tTrousers\n" & "\n\n", "UTF-8"); template charstring error_aaf := pattern "*XML namespace \"http://www.example.com/Y\" is not in the allowed namespace list."; testcase encode_aaf() runs on AA { CHECK_METHOD_ERROR(exer_enc_aaf, aaf, octetstring, error_aaf); } testcase decode_aaf() runs on AA { CHECK_METHOD_ERROR(exer_dec_aaf, str_aaf, AAFProduct, error_aaf); } // 2. anyAttributes except ... type record AAEProduct { AttrList info, // a record of universal charstring charstring name } with { variant (info) "anyAttributes except 'http://www.example.com/X', unqualified" } DECLARE_EXER_ENCODERS(AAEProduct, aae); const AAEProduct aae1 := { info := { "http://www.example.com/X size=""small""", "http://www.example.com/Y color=""red""", "http://www.example.com/Z available=""yes"""}, name := "Trousers" } const AAEProduct aae2 := { info := { "http://www.example.com/Y size=""medium""", "http://www.example.com/Z color=""green""", "available=""no"""}, name := "Shirt" } const octetstring str_aae1 := unichar2oct( "\n" & "\tTrousers\n" & "\n\n", "UTF-8"); const octetstring str_aae2 := unichar2oct( "\n" & "\tShirt\n" & "\n\n", "UTF-8"); template charstring error_aae1 := pattern "*XML namespace \"http://www.example.com/X\" is in the excluded namespace list."; template charstring error_aae2 := pattern "*The unqualified XML namespace is in the excluded namespace list."; testcase encode_aae() runs on AA { CHECK_METHOD_ERROR(exer_enc_aae, aae1, octetstring, error_aae1); CHECK_METHOD_ERROR(exer_enc_aae, aae2, octetstring, error_aae2); } testcase decode_aae() runs on AA { CHECK_METHOD_ERROR(exer_dec_aae, str_aae1, AAEProduct, error_aae1); CHECK_METHOD_ERROR(exer_dec_aae, str_aae2, AAEProduct, error_aae2); } // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- control { execute(encode_aa()); execute(decode_aa()); execute(encode_ab()); execute(decode_ab()); execute(encode_ax()); execute(decode_ax()); execute(encode_aaf()); execute(decode_aaf()); execute(encode_aae()); execute(decode_aae()); } } with { encode "XML" }