From 5f1b93713b811b56f37f83b62072ca0e2bb1b90e Mon Sep 17 00:00:00 2001 From: Botond Baranyi <botond.baranyi@ericsson.com> Date: Tue, 15 Aug 2017 15:49:21 +0200 Subject: [PATCH] Allowed field/element types to be encodable with the top-level object's codec in all cases Change-Id: I7780981fd32fc1ba2ed725c7dfdcd53f11e10e53 Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com> --- compiler2/Type.cc | 10 ++-------- .../multipleEncodings/Testcases.ttcn | 20 +++++++++++++++++++ .../multipleEncodings/TtcnTypes.ttcn | 5 +++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/compiler2/Type.cc b/compiler2/Type.cc index e466afb32..832c06029 100644 --- a/compiler2/Type.cc +++ b/compiler2/Type.cc @@ -3252,19 +3252,13 @@ namespace Common { case T_OPENTYPE: for (size_t i = 0; i < get_nof_comps(); ++i) { Type* field_type = get_comp_byIndex(i)->get_type(); - if (field_type->has_encoding(coding, NULL) || - field_type->get_type_w_coding_table() == NULL) { - field_type->get_type_refd_last()->set_gen_coder_functions(coding); - } + field_type->get_type_refd_last()->set_gen_coder_functions(coding); } break; case T_SEQOF: case T_SETOF: case T_ARRAY: - if (get_ofType()->has_encoding(coding, NULL) || - get_ofType()->get_type_w_coding_table() == NULL) { - get_ofType()->get_type_refd_last()->set_gen_coder_functions(coding); - } + get_ofType()->get_type_refd_last()->set_gen_coder_functions(coding); break; default: break; diff --git a/regression_test/multipleEncodings/Testcases.ttcn b/regression_test/multipleEncodings/Testcases.ttcn index a9fca73c7..260a7dc05 100644 --- a/regression_test/multipleEncodings/Testcases.ttcn +++ b/regression_test/multipleEncodings/Testcases.ttcn @@ -457,6 +457,25 @@ testcase tc_asn_setencode_negtest() runs on CT { } } +// Encoding and decoding a type, that has JSON encoding set on the top level, but its element type +// and the element type's fields don't have JSON encoding. The entire structure must be encodable +// with JSON. +testcase tc_ttcn_codec_switch() runs on CT { + var RecOf x := { { f1 := val1 }, { f1 := val2 } }; + var universal charstring exp := "[{\"f1\":\"val1\"},{\"f1\":\"val2\"}]"; + var universal charstring enc := encvalue_unichar(x, "UTF-8"); + if (exp != enc) { + setverdict(fail, "Encvalue_unichar test failed. Expected: ", exp, ", got: ", enc); + } + + var RecOf dec; + var integer res := decvalue_unichar(enc, dec); + if (x != dec) { + setverdict(fail, "Decvalue test failed. Expected: ", x, ", got: ", dec); + } + setverdict(pass); +} + control { execute(tc_ttcn_encvalue()); execute(tc_ttcn_encvalue_negtest()); @@ -475,6 +494,7 @@ control { execute(tc_asn_setencode_json()); execute(tc_asn_setencode_per()); execute(tc_asn_setencode_negtest()); + execute(tc_ttcn_codec_switch()); } } diff --git a/regression_test/multipleEncodings/TtcnTypes.ttcn b/regression_test/multipleEncodings/TtcnTypes.ttcn index 22560d217..cfee27c6c 100644 --- a/regression_test/multipleEncodings/TtcnTypes.ttcn +++ b/regression_test/multipleEncodings/TtcnTypes.ttcn @@ -51,6 +51,11 @@ with { variant "JSON: as value"; } +type record of R1 RecOf +with { + encode "JSON"; +} + type record Msg { bitstring data } -- GitLab