Commit 2e0b78ea authored by Botond Baranyi's avatar Botond Baranyi
Browse files

OER encoder now also uses type constraints that are not at the last referenced type (bug 541693)



Change-Id: I108adf8020c46fb2781ad59b01db60a5013ab9ca
Signed-off-by: Botond Baranyi's avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 9fb1c80f
......@@ -3050,12 +3050,16 @@ void Type::chk_oer() {
oerattrib = new OerAST();
}
Type* t = get_type_refd_last();
// sometimes (like with OPENTYPE fields) the relevant subtype information is
// at the last referenced type
SubType* relevant_sub_type = sub_type != NULL && sub_type->is_subtype_notempty() ?
sub_type : t->sub_type;
switch (t->typetype) {
case T_INT_A: {
if (t->is_constrained() && t->get_sub_type()->is_subtype_notempty()) {
if (relevant_sub_type != NULL && relevant_sub_type->is_subtype_notempty()) {
Location loc;
int_limit_t upper = t->get_sub_type()->get_int_limit(true, &loc);
int_limit_t lower = t->get_sub_type()->get_int_limit(false, &loc);
int_limit_t upper = relevant_sub_type->get_int_limit(true, &loc);
int_limit_t lower = relevant_sub_type->get_int_limit(false, &loc);
bool lower_inf = lower.get_type() != int_limit_t::NUMBER;
bool upper_inf = upper.get_type() != int_limit_t::NUMBER;
if (lower_inf || upper_inf) {
......@@ -3110,10 +3114,10 @@ void Type::chk_oer() {
case T_VIDEOTEXSTRING:
case T_GRAPHICSTRING:
case T_GENERALSTRING: {
if (t->is_constrained() && t->get_sub_type()->is_subtype_notempty()) {
if (relevant_sub_type != NULL && relevant_sub_type->is_subtype_notempty()) {
Location loc;
int_limit_t upper = t->get_sub_type()->get_int_limit(true, &loc);
int_limit_t lower = t->get_sub_type()->get_int_limit(false, &loc);
int_limit_t upper = relevant_sub_type->get_int_limit(true, &loc);
int_limit_t lower = relevant_sub_type->get_int_limit(false, &loc);
bool lower_inf = lower.get_type() != int_limit_t::NUMBER;
bool upper_inf = upper.get_type() != int_limit_t::NUMBER;
if (!lower_inf && !upper_inf) {
......
......@@ -3710,6 +3710,44 @@
}
setverdict(pass);
}
external function f_enc_int1(in Int1 x) return octetstring
with { extension "prototype(convert) encode(OER)" }
external function f_enc_int2(in Int2 x) return octetstring
with { extension "prototype(convert) encode(OER)" }
external function f_dec_int1(in octetstring x) return Int1
with { extension "prototype(convert) decode(OER)" }
external function f_dec_int2(in octetstring x) return Int2
with { extension "prototype(convert) decode(OER)" }
// Testing that type constraints are taken into account during encoding and decoding,
// even if they are not in the type at the end of the type reference chain.
testcase tc_541693() runs on EmptyCT {
// both types are constrained to one value (1), so there should be no length indicator in their encodings
var octetstring enc_exp := '01'O;
var octetstring enc := f_enc_int1(x1);
if (enc != enc_exp) {
setverdict(fail, "Got: ", enc, ", expected: ", enc_exp);
}
var Int1 dec1 := f_dec_int1(enc_exp);
if (dec1 != x1) {
setverdict(fail, "Got: ", dec1, ", expected: ", x1);
}
enc := f_enc_int2(x2);
if (enc != enc_exp) {
setverdict(fail, "Got: ", enc, ", expected: ", enc_exp);
}
var Int2 dec2 := f_dec_int2(enc_exp);
if (dec2 != x2) {
setverdict(fail, "Got: ", dec2, ", expected: ", x2);
}
setverdict(pass);
}
control {
execute(tc_boolean());
......@@ -3736,6 +3774,7 @@
execute(tc_533061());
execute(tc_default_dec());
execute(tc_default_enc());
execute(tc_541693());
}
}
......@@ -555,5 +555,12 @@ EmptyExtendableSequence ::= SEQUENCE {
SequenceOfInteger ::= SEQUENCE OF INTEGER
Int1 ::= INTEGER {v1(1)} (v1)
IntBase ::= INTEGER {v1(1)}
Int2 ::= IntBase (v1)
x1 Int1 ::= v1
x2 Int2 ::= v1
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