Commit 4b09fee3 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed JSON decoding of similar records/sets inside an 'as value' union (bug 568645)


Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
Change-Id: Ic386b5ab6cd050bb77c565e47d35aed0b6f19baf
parent 87315038
......@@ -3512,6 +3512,9 @@ char* generate_json_decoder(char* src, const struct_def* sdef)
src = mputprintf(src,
"{\n"
// invalid field name
" if (p_silent) {\n"
" return JSON_ERROR_INVALID_TOKEN;\n"
" }\n"
" JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, %sJSON_DEC_INVALID_NAME_ERROR, (int)name_len, fld_name);\n"
// if this is set to a warning, skip the value of the field
" dec_len += p_tok.get_next_token(&j_token, NULL, NULL);\n"
......
......@@ -844,6 +844,34 @@ testcase tc_bug_522660() runs on MTC {
}
}
testcase tc_bug_568645() runs on MTC {
var universal charstring stream := "{ \"i1\":123}";
var Uni568645 pdu_decoded;
var Uni568645 pdu_expected := { field1 := { i1 := 123 } };
var integer result := decvalue_unichar(stream, pdu_decoded);
if (result != 0 or pdu_decoded != pdu_expected) {
setverdict(fail, "Test #1 failed. Result: ", result, ". Decoded value: ",
pdu_decoded, ", expected: ", pdu_expected);
}
stream := "{ \"i1\":123, \"i2\":456}";
pdu_expected := { field2 := { i1 := 123, i2 := 456 } };
result := decvalue_unichar(stream, pdu_decoded);
if (result != 0 or pdu_decoded != pdu_expected) {
setverdict(fail, "Test #2 failed. Result: ", result, ". Decoded value: ",
pdu_decoded, ", expected: ", pdu_expected);
}
stream := "{ \"i1\":123, \"i2\":[1,2,3]}";
pdu_expected := { field3 := { i1 := 123, i2 := { 1, 2, 3 } } };
result := decvalue_unichar(stream, pdu_decoded);
if (result != 0 or pdu_decoded != pdu_expected) {
setverdict(fail, "Test #3 failed. Result: ", result, ". Decoded value: ",
pdu_decoded, ", expected: ", pdu_expected);
}
setverdict(pass);
}
//=========================================================================
// Control
//=========================================================================
......@@ -935,6 +963,7 @@ control {
execute(tc_multi_level_recordof());
execute(tc_bug_522660());
execute(tc_bug_568645());
}
......
......@@ -395,6 +395,29 @@ with {
type record of EnumNumber EnumNumberList;
type union Uni568645 {
Set568645a field1,
Set568645b field2,
Set568645c field3
}
with {
variant "JSON: as value"
}
type set Set568645a {
integer i1
}
type set Set568645b {
integer i1,
integer i2
}
type set Set568645c {
integer i1,
record of integer i2
}
} with {
encode "JSON";
extension "anytype integer, charstring, R, RoI, Thing";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment