Commit 7fa00a37 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed OER encoding of records and decoding of enums (bug 529017)



Change-Id: I669edc2f8b4995ce6f355579b60a35e1ff9099a8
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 99dedd6d
......@@ -883,7 +883,6 @@ void defEnumClass(const enum_def *edef, output_struct *output)
" if (enum_value >= 0 && enum_value < 128) {\n"
" char c = enum_value;\n"
" p_buf.put_c(c);\n"
" p_buf.increase_pos(1);\n"
" } else {\n"
// This case is the same as encoding a not restricted integer except
// the first bit is set to 1 before decoding
......@@ -904,11 +903,12 @@ void defEnumClass(const enum_def *edef, output_struct *output)
"{\n"
" const unsigned char* uc = p_buf.get_read_data();\n"
" if (!(uc[0] & 0x80)) {\n"
" if (is_valid_enum(uc[0])) {"
" enum_value = static_cast<%s>(uc[0]);\n"
" if (is_valid_enum(uc[0])) {\n"
" enum_value = static_cast<%s>(uc[0]);\n"
" } else {\n"
" enum_value = %s;\n"
" }\n"
" p_buf.increase_pos(1);\n"
" } else {\n"
// This case is the same as decoding a not restricted integer except
// the first bit is set to 0
......
......@@ -4686,12 +4686,14 @@ void defRecordClass1(const struct_def *sdef, output_struct *output)
if (opt_elements != 0 || sdef->oerExtendable) {
src = mputstr(src,
" char c = 0;\n");
if (sdef->oerExtendable && sdef->oerNrOrRootcomps != sdef->nElements) {
if (sdef->oerExtendable) {
pos--;
src = mputprintf(src,
" if (has_extension) {\n"
" c += %i;\n"
" }\n", 1 << 7);
if (sdef->oerNrOrRootcomps != sdef->nElements) {
src = mputprintf(src,
" if (has_extension) {\n"
" c += %i;\n"
" }\n", 1 << 7);
}
}
}
......
......@@ -3522,6 +3522,28 @@
setverdict(pass);
}
external function enc_Rec529017(in Rec529017 pdu) return octetstring
with { extension "prototype (convert) encode(OER)" }
external function dec_Rec529017(in octetstring stream) return Rec529017
with { extension "prototype (convert) decode(OER)" }
// Testing the fixes to record encoding and enum decoding made for bug 529017
testcase tc_529017() runs on EmptyCT {
var Rec529017 x := { val0, 4 };
var octetstring enc := enc_Rec529017(x);
var octetstring enc_exp := '40000104'O;
if (enc != enc_exp) {
setverdict(fail, "Encoding failed. Got: ", enc, ", expected: ", enc_exp);
}
var Rec529017 dec := dec_Rec529017(enc_exp);
if (dec != x) {
setverdict(fail, "Decoding failed. Got: ", dec, ", expected: ", x);
}
setverdict(pass);
}
control {
execute(tc_boolean());
......@@ -3542,5 +3564,7 @@
execute(tc_external());
execute(tc_opentype());
execute(tc_example());
execute(tc_529017());
}
}
\ No newline at end of file
}
......@@ -520,8 +520,21 @@ ErrorReturn ::= SEQUENCE
}
-- Types for the test of bugfix 529017
Rec529017 ::= SEQUENCE
{
en Enum529017,
i INTEGER OPTIONAL,
...
}
Enum529017 ::= ENUMERATED
{
val0,
val1
}
END
\ No newline at end of file
END
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