Commit 082c0a84 authored by Adam Knapp's avatar Adam Knapp
Browse files

Lengthto regression tests update for bit/octetstring (issue #419)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent b53197ab
......@@ -16,6 +16,12 @@ module Bug546231 {
external function dec_R2(in octetstring stream) return R2
with { extension "prototype(convert)" extension "decode(RAW)" }
external function dec_R2_Octet(in octetstring stream) return R2_Octet
with { extension "prototype(convert)" extension "decode(RAW)" }
external function dec_R2_Bit(in octetstring stream) return R2_Bit
with { extension "prototype(convert)" extension "decode(RAW)" }
type record R2 {
integer lengthfield,
record of integer listfield,
......@@ -25,6 +31,24 @@ type record R2 {
variant (lengthfield) "UNIT(elements)"
}
type record R2_Octet {
octetstring lengthfield length(1),
record of integer listfield,
integer last_field
} with {
variant (lengthfield) "LENGTHTO(listfield)"
variant (lengthfield) "UNIT(elements)"
}
type record R2_Bit {
bitstring lengthfield length(8),
record of integer listfield,
integer last_field
} with {
variant (lengthfield) "LENGTHTO(listfield)"
variant (lengthfield) "UNIT(elements)"
}
type component CT {};
testcase tc1() runs on CT {
......@@ -49,9 +73,57 @@ testcase tc2() runs on CT {
}
}
testcase tc1_Octet() runs on CT {
var R2_Octet res := dec_R2_Octet('0000'O);
var R2_Octet exp := { lengthfield := '00'O, listfield := { }, last_field := 0 };
if (res == exp) {
setverdict(pass);
}
else {
setverdict(fail, "Got: ", res, ", expected: ", exp);
}
}
testcase tc2_Octet() runs on CT {
var R2_Octet res := dec_R2_Octet('010102'O);
var R2_Octet exp := { lengthfield := '01'O, listfield := { 1 }, last_field := 2 };
if (res == exp) {
setverdict(pass);
}
else {
setverdict(fail, "Got: ", res, ", expected: ", exp);
}
}
testcase tc1_Bit() runs on CT {
var R2_Bit res := dec_R2_Bit('0000'O);
var R2_Bit exp := { lengthfield := '00000000'B, listfield := { }, last_field := 0 };
if (res == exp) {
setverdict(pass);
}
else {
setverdict(fail, "Got: ", res, ", expected: ", exp);
}
}
testcase tc2_Bit() runs on CT {
var R2_Bit res := dec_R2_Bit('010102'O);
var R2_Bit exp := { lengthfield := '00000001'B, listfield := { 1 }, last_field := 2 };
if (res == exp) {
setverdict(pass);
}
else {
setverdict(fail, "Got: ", res, ", expected: ", exp);
}
}
control {
execute(tc1());
execute(tc2());
execute(tc1_Octet());
execute(tc2_Octet());
execute(tc1_Bit());
execute(tc2_Bit());
}
} with {
......
......@@ -14,7 +14,7 @@ module Bug572603 {
type record UnknownIE {
integer ie_code,
integer ie_length,
octetstring ie_length length(1),
octetstring ie_data
} with {
variant (ie_length) "LENGTHTO(ie_data)"
......@@ -46,7 +46,7 @@ type record of IE2 IE2_list
type record IE3 {
integer ie_code,
integer ie_length,
bitstring ie_length length(8),
octetstring ie_data
} with {
variant "PRESENCE(ie_code = 3)"
......@@ -75,7 +75,7 @@ with { extension "prototype(convert)" extension "decode(RAW)" }
type component CT {}
testcase tc_bug572603() runs on CT {
var PDU v_pdu1 := { f_ie1 := { 1, 1, 'AA'O }, f_ie2_list := { { 2, 1, 'BB'O }, { 2, 1, 'BB'O } }, f_ie3 := { 3, 1, 'CC'O }, f_other := { { 4, 1, 'DD'O } } }
var PDU v_pdu1 := { f_ie1 := { 1, 1, 'AA'O }, f_ie2_list := { { 2, 1, 'BB'O }, { 2, 1, 'BB'O } }, f_ie3 := { 3, '00000001'B, 'CC'O }, f_other := { { 4, '01'O, 'DD'O } } }
var PDU v_pdu2
var octetstring v_oct := '0101AA0201BB0401DD0201BB0301CC'O;
v_pdu2 := dec_PDU(v_oct);
......
......@@ -42,6 +42,64 @@ testcase tc1() runs on CT {
setverdict(pass);
}
type record Rec1_Octet {
octetstring len,
octetstring data
}
with {
variant (len) "LENGTHTO(data) + 1";
variant (len) "FIELDLENGTH(1)"
}
testcase tc1_Octet() runs on CT {
var Rec1_Octet val := { '00'O, '12345678'O };
var bitstring enc_exp := oct2bit('0512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec1_Octet dec_exp := { int2oct(lengthof(val.data), 1), val.data };
var Rec1_Octet dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
type record Rec1_Bit {
bitstring len,
octetstring data
}
with {
variant (len) "LENGTHTO(data) + 1";
variant (len) "FIELDLENGTH(8)"
}
testcase tc1_Bit() runs on CT {
var Rec1_Bit val := { '00000000'B, '12345678'O };
var bitstring enc_exp := oct2bit('0512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec1_Bit dec_exp := { int2bit(lengthof(val.data), 8), val.data };
var Rec1_Bit dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
type record Rec2 {
integer len,
bitstring data1,
......@@ -72,6 +130,69 @@ testcase tc2() runs on CT {
setverdict(pass);
}
type record Rec2_Octet {
octetstring len,
bitstring data1,
octetstring data2
}
with {
variant (len) "LENGTHTO(data1, data2) - 2";
variant (len) "FIELDLENGTH(1)";
variant (data1) "FIELDLENGTH(8)";
}
testcase tc2_Octet() runs on CT {
var Rec2_Octet val := { '00'O, '10010101'B, '12345678'O };
var bitstring enc_exp := oct2bit('039512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec2_Octet dec_exp := { int2oct(lengthof(val.data1) / 8 + lengthof(val.data2), 1), val.data1, val.data2 };
var Rec2_Octet dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
type record Rec2_Bit {
bitstring len,
bitstring data1,
octetstring data2
}
with {
variant (len) "LENGTHTO(data1, data2) - 2";
variant (len) "FIELDLENGTH(8)";
variant (data1) "FIELDLENGTH(8)";
}
testcase tc2_Bit() runs on CT {
var Rec2_Bit val := { '00000000'B, '10010101'B, '12345678'O };
var bitstring enc_exp := oct2bit('039512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec2_Bit dec_exp := { int2bit(lengthof(val.data1) / 8 + lengthof(val.data2), 8), val.data1, val.data2 };
var Rec2_Bit dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
type record Rec3 {
union { integer i1, integer i2 } len,
bitstring data1,
......@@ -102,10 +223,86 @@ testcase tc3() runs on CT {
setverdict(pass);
}
type union length_octet { octetstring i1, octetstring i2 } with {
variant (i1) "FIELDLENGTH(1)";
variant (i2) "FIELDLENGTH(2)";
}
type record Rec3_Octet {
length_octet len,
bitstring data1,
octetstring data2
}
with {
variant (len) "LENGTHTO(data1, data2) + 10";
variant (data1) "FIELDLENGTH(8)";
}
testcase tc3_Octet() runs on CT {
var Rec3_Octet val := { { i1 := '00'O }, '10010101'B, '12345678'O };
var bitstring enc_exp := oct2bit('0F9512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec3_Octet dec_exp := { { i1 := int2oct(lengthof(val.data1) / 8 + lengthof(val.data2), 1) }, val.data1, val.data2 };
var Rec3_Octet dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
type union length_bit { bitstring i1, bitstring i2 } with {
variant (i1) "FIELDLENGTH(8)";
variant (i2) "FIELDLENGTH(12)";
}
type record Rec3_Bit {
length_bit len,
bitstring data1,
octetstring data2
}
with {
variant (len) "LENGTHTO(data1, data2) + 10";
variant (data1) "FIELDLENGTH(8)";
}
testcase tc3_Bit() runs on CT {
var Rec3_Bit val := { { i1 := '00000000'B }, '10010101'B, '12345678'O };
var bitstring enc_exp := oct2bit('0F9512345678'O);
var bitstring enc := encvalue(val);
if (enc_exp != enc) {
setverdict(fail, "Encoding failed. Expected: ", bit2oct(enc_exp), ", got: ", bit2oct(enc));
}
var Rec3_Bit dec_exp := { { i1 := int2bit(lengthof(val.data1) / 8 + lengthof(val.data2), 8) }, val.data1, val.data2 };
var Rec3_Bit dec;
var integer res := decvalue(enc_exp, dec);
if (res != 0) {
setverdict(fail, "Invalid decoding result: ", res);
}
else if (dec_exp != dec) {
setverdict(fail, "Decoding failed. Expected: ", dec_exp, ", got: ", dec);
}
setverdict(pass);
}
control {
execute(tc1());
execute(tc2());
execute(tc3());
execute(tc1_Octet());
execute(tc2_Octet());
execute(tc3_Octet());
execute(tc1_Bit());
execute(tc2_Bit());
execute(tc3_Bit());
}
}
......
......@@ -24,4 +24,5 @@ RAW_EncDec_4
RAW_EncDec_5
RAW_EncDec_6
RAW_EncDec_7
RAW_EncDec_8
\ No newline at end of file
RAW_EncDec_8
RAW_EncDec_Lengthto
......@@ -4819,7 +4819,7 @@ with {variant (paramLength) "LENGTHTO(octstr , bit7 , bit1 , hexstr , int )" }
type record Param2
{ ParamName paramName ,
integer paramLength ,
octetstring paramLength length(1),
OCT3_ octstr ,
BIT7_ bit7 ,
BIT1_ bit1 ,
......@@ -4829,7 +4829,7 @@ with {variant (paramLength) "LENGTHTO(octstr , bit7 , bit1 , hexstr , int )" }
type record Param3
{ ParamName paramName ,
integer paramLength ,
bitstring paramLength length(8),
OCT3_ octstr ,
BIT7_ bit7 ,
BIT1_ bit1 ,
......@@ -5017,7 +5017,7 @@ testcase TC_structured_types_10() runs on TempComp{
int := 1 } ,
param3 :=
{ paramName := name3 ,
paramLength := 6 ,
paramLength := '00000110'B ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......@@ -5025,7 +5025,7 @@ testcase TC_structured_types_10() runs on TempComp{
int := 1 } ,
param2 :=
{ paramName := name2 ,
paramLength := 6 ,
paramLength := '06'O ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......@@ -5105,7 +5105,7 @@ testcase TC_structured_types_12() runs on TempComp{
int := 1 } ,
param3 :=
{ paramName := name3 ,
paramLength := 6 ,
paramLength := '00000110'B ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......@@ -5151,7 +5151,7 @@ testcase TC_structured_types_13() runs on TempComp{
param4 := omit ,
param3 :=
{ paramName := name3 ,
paramLength := 6 ,
paramLength := '00000110'B ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......@@ -5432,7 +5432,7 @@ testcase TC_structured_types_14() runs on TempComp{
int := 1 } ,
param3 :=
{ paramName := name3 ,
paramLength := 6 ,
paramLength := '00000110'B ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......@@ -5482,7 +5482,7 @@ testcase TC_structured_types_15() runs on TempComp{
int := 1 } ,
param3 :=
{ paramName := name3 ,
paramLength := 6 ,
paramLength := '00000110'B ,
octstr := '123456'O ,
bit7 := '0000000'B ,
bit1 := '1'B ,
......
......@@ -23,8 +23,29 @@ module RAW_EncDec_8 {
extension "prototype(convert)"
extension "decode(RAW)"
}
type octetstring OCT2 length(2);
external function enc_U_Octet(in U_Octet pl_pdu) return octetstring
with {
extension "prototype(convert)"
extension "encode(RAW)"
};
external function dec_U_Octet(in octetstring pl_octetstring) return U_Octet
with {
extension "prototype(convert)"
extension "decode(RAW)"
}
external function enc_U_Bit(in U_Bit pl_pdu) return octetstring
with {
extension "prototype(convert)"
extension "encode(RAW)"
};
external function dec_U_Bit(in octetstring pl_octetstring) return U_Bit
with {
extension "prototype(convert)"
extension "decode(RAW)"
}
type record R1 {
integer f1,
......@@ -44,6 +65,43 @@ module RAW_EncDec_8 {
variant ""
}
type record R1_Octet {
octetstring f1,
octetstring f2,
integer f3
} with {
encode "RAW"
variant (f1) "FIELDLENGTH(8)"
variant (f1) "LENGTHTO(f2)"
}
type union U_Octet {
R1_Octet u1,
octetstring u2 length(8)
} with {
encode "RAW"
variant ""
}
type record R1_Bit {
bitstring f1,
octetstring f2,
integer f3
} with {
encode "RAW"
variant (f1) "FIELDLENGTH(64)"
variant (f1) "LENGTHTO(f2)"
}
type union U_Bit {
R1_Bit u1,
octetstring u2 length(8)
} with {
encode "RAW"
variant ""
}
testcase TC_01() runs on Test_CT{
var U pl_u, pl_u_result;
pl_u.u2 := 'FFFFFFFFFFFFFFFF'O;
......@@ -55,8 +113,32 @@ testcase TC_01() runs on Test_CT{
setverdict(pass);
}
testcase TC_01_Octet() runs on Test_CT{
var U_Octet pl_u, pl_u_result;
pl_u.u2 := 'FFFFFFFFFFFFFFFF'O;
var octetstring os := enc_U_Octet(pl_u);
pl_u_result := dec_U_Octet(os);
if (pl_u != pl_u_result) {
setverdict(fail);
}
setverdict(pass);
}
testcase TC_01_Bit() runs on Test_CT{
var U_Bit pl_u, pl_u_result;
pl_u.u2 := 'FFFFFFFFFFFFFFFF'O;
var octetstring os := enc_U_Bit(pl_u);
pl_u_result := dec_U_Bit(os);
if (pl_u != pl_u_result) {
setverdict(fail);
}
setverdict(pass);
}
control{
execute(TC_01());
execute(TC_01_Octet());
execute(TC_01_Bit());
}
}
......@@ -29,13 +29,22 @@ type record IE1{
type record IE2{
OCT1 ie_type,
integer len,
octetstring len length(1),
octetstring data
} with {
variant "PRESENCE(ie_type = '02'O)"
variant (len) "LENGTHTO(data)"
}
type record IE3{
OCT1 ie_type,
bitstring len length(8),
octetstring data
} with {
variant "PRESENCE(ie_type = '03'O)"
variant (len) "LENGTHTO(data)"
}
type record unknown_IE{
OCT1 ie_type,
integer len,
......@@ -49,6 +58,7 @@ type record of unknown_IE unknown_IE_list
type set PDU{
IE1 ie1_field,
IE2 ie2_field optional,
IE3 ie3_field optional,
unknown_IE_list unknown_ies optional
} with {
variant (unknown_ies) "REPEATABLE(yes)"
......@@ -59,14 +69,15 @@ with { extension "prototype(backtrack) decode(RAW)" }
// no spread record of
testcase tc_1() runs on CT {
var octetstring stream := '010100020100030100040100'O ; // IE1, IE2, unknown IE
var octetstring stream := '010100020100030100040100050100'O ; // IE1, IE2, IE3, unknown IE
var PDU pdu_decoded;
var PDU pdu_expected := {
ie1_field := { ie_type := '01'O, len:=1, data := '00'O },
ie2_field := { ie_type := '02'O, len:=1, data := '00'O },
ie2_field := { ie_type := '02'O, len:='01'O, data := '00'O },
ie3_field := { ie_type := '03'O, len:='00000001'B, data := '00'O },
unknown_ies := {
{ ie_type := '03'O, len:=1, data := '00'O},
{ ie_type := '04'O, len:=1, data := '00'O}
{ ie_type := '04'O, len:=1, data := '00'O},
{ ie_type := '05'O, len:=1, data := '00'O}
}
}