Commit 568d8d7f authored by balaskoa's avatar balaskoa
Browse files

New test cases in regression_test/EncodeDecode/JSON/JsonBasicTest


Signed-off-by: default avatarbalaskoa <Jeno.Balasko@ericsson.com>
Change-Id: I21e5b0fb1dfe751c772b3378b7103ebbfc64d142
parent a532f4fd
/******************************************************************************
* Copyright (c) 2000-2020 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Balasko, Jeno
*
******************************************************************************/
* Copyright (c) 2000-2020 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Balasko, Jeno
*
******************************************************************************/
// The testcases check if the encode funcions run and check the result.
// The return value of encoding functions is bitstring
......@@ -23,6 +23,7 @@ import from JsonEncDecFunctions all;
type component CT {}
template charstring t_using_omit := pattern "*Dynamic test case error: Using the value of an optional field containing omit*"
function f_compare_bitstring(in bitstring pl_val, in bitstring pl_expected) {
if ( pl_val == pl_expected ){
setverdict(pass);
......@@ -45,7 +46,7 @@ testcase tc_jsonBasic_encdec_integer() runs on CT {
log("expected:",expected);
bs := f_json_enc_i2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_i2bs(y);
f_compare_bitstring(bs, expected);
......@@ -78,7 +79,7 @@ testcase tc_jsonBasic_encdec_integer_big() runs on CT {
log("expected:",expected);
bs := f_json_enc_i2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_i2bs(y);
f_compare_bitstring(bs, expected);
......@@ -103,6 +104,162 @@ testcase tc_jsonBasic_encdec_integer_big() runs on CT {
}
testcase tc_jsonBasic_encdec_integer_unbound() runs on CT {
var I_json y ; //intentionally unbound
var bitstring bs;
template charstring t_unbound := pattern "*Dynamic test case error:*Encoding an unbound integer value.*"
//encvalue
@try {
bs := f_json_enc_i2bs(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
//encvalue
@try {
bs := encvalue(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
//==== decode ====
var bitstring encoded; //intentionally unbound
template charstring t_unbound2 := pattern "*The argument of function bit2oct\(\) is an unbound bitstring value*"
@try {
var I_json z := f_json_dec_bs2i(encoded);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound2)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound2)); //TODO: got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
}
}
template charstring tl_unbound2 := pattern "*Dynamic test case error: The argument of function bit2oct\(\) is an unbound bitstring value*"
@try {
var I_json z ;
var integer r := decvalue(encoded, z);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,tl_unbound2)){
setverdict(pass)
} else {
setverdict(fail, match(e,tl_unbound2)); //got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
}
}
}
//The argument of the encode function is a field
testcase tc_jsonBasic_encdec_integer_field() runs on CT {
const R_json x := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var R_json y := { i:= 2, f:=2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
var bitstring expected := '00110010'B; //oct2bit(char2oct("2"));
log("expected:",expected);
bs := f_json_enc_i2bs(x.i);
f_compare_bitstring(bs, expected);
bs := f_json_enc_i2bs(y.i);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y.i);
f_compare_bitstring(bs, expected);
//decode test:
var I_json z := f_json_dec_bs2i(expected);
if ( y.i ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y.i==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
//The argument of the encode function is a field
testcase tc_jsonBasic_encdec_integer_field_optional() runs on CT {
const Ropt_json x := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var Ropt_json y := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
var bitstring expected := '00110010'B; //oct2bit(char2oct("2"));
log("expected:",expected);
bs := f_json_enc_i2bs(x.i);
f_compare_bitstring(bs, expected);
bs := f_json_enc_i2bs(y.i);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y.i);
f_compare_bitstring(bs, expected);
//decode test:
var I_json z := f_json_dec_bs2i(expected);
if ( y.i ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y.i==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_integer_field_optional_omit() runs on CT {
var Ropt_json y := { i:= omit, f:=2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
@try {
bs := f_json_enc_i2bs(y.i);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_using_omit)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_using_omit))
}
}
//encvalue
@try {
bs := encvalue(y.i);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_using_omit)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_using_omit))
}
}
}
testcase tc_jsonBasic_encdec_float1() runs on CT {
const F_json x := 2.0;
var F_json y := 2.0;
......@@ -111,7 +268,7 @@ testcase tc_jsonBasic_encdec_float1() runs on CT {
log("expected:",expected);
bs := f_json_enc_f2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
......@@ -145,7 +302,7 @@ testcase tc_jsonBasic_encdec_float2() runs on CT {
log("expected:",expected, " oct: ", char2oct("\"infinity\""));
bs := f_json_enc_f2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
......@@ -177,7 +334,7 @@ testcase tc_jsonBasic_encdec_float3() runs on CT {
log("expected:",expected, " oct: ", char2oct("\"-infinity\""));
bs := f_json_enc_f2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
......@@ -209,7 +366,7 @@ testcase tc_jsonBasic_encdec_float4() runs on CT {
log("expected:",expected, " oct: ", char2oct("\"not_a_number\""));
bs := f_json_enc_f2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
......@@ -232,6 +389,166 @@ testcase tc_jsonBasic_encdec_float4() runs on CT {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
var F_json y ; //intentionally unbound
var bitstring bs;
template charstring t_unbound := pattern "*Encoding an unbound float value.*"
//encvalue
@try {
bs := f_json_enc_f2bs(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
//encvalue
@try {
bs := encvalue(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
//==== decode ====
var bitstring encoded; //intentionally unbound
template charstring t_unbound2 := pattern "*The argument of function bit2oct\(\) is an unbound bitstring value.*"
@try {
var I_json z := f_json_dec_bs2i(encoded);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound2)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound2)); //TODO: got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
}
}
template charstring tl_unbound2 := pattern "*The argument of function bit2oct\(\) is an unbound bitstring value.*"
@try {
var I_json z ;
var integer r := decvalue(encoded, z);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound2)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound2)); //got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
}
}
}
//The argument of the encode function is a field
testcase tc_jsonBasic_encdec_float_field() runs on CT {
const R_json x := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var R_json y := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
var bitstring expected := oct2bit(char2oct("2.000000"));
log("expected:",expected);
bs := f_json_enc_f2bs(x.f);
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y.f);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y.f);
f_compare_bitstring(bs, expected);
//decode test:
var F_json z := f_json_dec_bs2f(expected);
if ( y.f ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y.f==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
//The argument of the encode function is a field
testcase tc_jsonBasic_encdec_float_field_optional() runs on CT {
const Ropt_json x := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var Ropt_json y := { i:= 2, f:= 2.0, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
var bitstring expected := oct2bit(char2oct("2.000000"));
log("expected:",expected, " oct: ", char2oct("2.000000"));
bs := f_json_enc_f2bs(x.f);
f_compare_bitstring(bs, expected);
log("bs:",bs, " oct: ", bit2oct(bs));
bs := f_json_enc_f2bs(y.f);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y.f);
f_compare_bitstring(bs, expected);
//decode test:
var F_json z := f_json_dec_bs2f(expected);
if ( y.f ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y.f==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_float_field_optional_omit() runs on CT {
var Ropt_json y := { i:= omit, f:= omit, bs := '1'B, cs :="1",hs:='1'H,os :='01'O,ucs:="1", e:= first }
var bitstring bs;
@try {
bs := f_json_enc_f2bs(y.f);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_using_omit)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_using_omit))
}
}
//encvalue
@try {
bs := encvalue(y.f);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_using_omit)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_using_omit))
}
}
}
//=====================================================
//======================== Enum =======================
//=====================================================
testcase tc_jsonBasic_encdec_enum() runs on CT {
const E_json x := second;
var E_json y := second;
......@@ -240,7 +557,7 @@ testcase tc_jsonBasic_encdec_enum() runs on CT {
log("expected:",expected);
bs := f_json_enc_e2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_e2bs(y);
if ( bs == expected ) {
setverdict(pass);
......@@ -277,7 +594,7 @@ testcase tc_jsonBasic_encdec_bool1() runs on CT {
log("expected:",expected);
bs := f_json_enc_b2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_b2bs(y);
if ( bs == expected ) {
setverdict(pass);
......@@ -314,7 +631,7 @@ testcase tc_jsonBasic_encdec_bool2() runs on CT {
log("expected:",expected);
bs := f_json_enc_b2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_b2bs(y);
if ( bs == expected ) {
setverdict(pass);
......@@ -351,7 +668,7 @@ testcase tc_jsonBasic_encdec_bitstring() runs on CT {
log("expected:",expected);
bs := f_json_enc_bs2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_bs2bs(y);
f_compare_bitstring(bs, expected);
......@@ -383,7 +700,7 @@ testcase tc_jsonBasic_encdec_charstring() runs on CT {
log("expected:",expected);
bs := f_json_enc_cs2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_cs2bs(y);
f_compare_bitstring(bs, expected);
......@@ -416,7 +733,7 @@ testcase tc_jsonBasic_encdec_hexstring() runs on CT {
log("expected:",expected);
bs := f_json_enc_hs2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_hs2bs(y);
f_compare_bitstring(bs, expected);
......@@ -448,7 +765,7 @@ testcase tc_jsonBasic_encdec_octetstring() runs on CT {
log("expected:",expected);
bs := f_json_enc_os2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_os2bs(y);
f_compare_bitstring(bs, expected);
......@@ -480,11 +797,11 @@ testcase tc_jsonBasic_encdec_ucharstring() runs on CT {
var bitstring expected := oct2bit(unichar2oct("\"" & char(0, 0, 0, 1) & "\"")); //ok
log("expected:",expected);
bs := f_json_enc_ucs2bs(x);
// log(bs);
// log(bit2oct(bs)); //'220122'O = "01"
// log(oct2char(bit2oct(bs))); // "\"" & char(0, 0, 0, 1) & "\""
// log(bs);
// log(bit2oct(bs)); //'220122'O = "01"
// log(oct2char(bit2oct(bs))); // "\"" & char(0, 0, 0, 1) & "\""
f_compare_bitstring(bs, expected);
bs := f_json_enc_ucs2bs(y);
f_compare_bitstring(bs, expected);
......@@ -519,13 +836,13 @@ testcase tc_jsonBasic_encdec_verdict() runs on CT {
log("expected:",expected, " oct: ", char2oct("\"pass\"") );
bs := f_json_enc_v2bs(x);
f_compare_bitstring(bs, expected);
bs := f_json_enc_v2bs(y);
f_compare_bitstring(bs, expected);
//encvalue is prohibited TODO: check this
// bs := encvalue(y);
// f_compare_bitstring(bs, expected);
//encvalue is prohibited TODO: check this
// bs := encvalue(y);
// f_compare_bitstring(bs, expected);
//decode test:
var V_json z := f_json_dec_bs2v(expected);
......@@ -535,13 +852,13 @@ testcase tc_jsonBasic_encdec_verdict() runs on CT {
setverdict(fail);
}
// decvalue is prohibited TODO: check this
// var integer r := decvalue(expected, z);
// if (r==0 and y==z){
// setverdict(pass);
// } else {
// setverdict(fail);
// }
// decvalue is prohibited TODO: check this
// var integer r := decvalue(expected, z);
// if (r==0 and y==z){
// setverdict(pass);
// } else {
// setverdict(fail);
// }
}
......@@ -554,6 +871,7 @@ testcase tc_jsonBasic_encdec_verdict() runs on CT {
testcase tc_jsonBasic_encdec_record() runs on CT {
const R_json x := {
i := 1,
f:=2.0,
bs := '1'B,
cs := "1",
hs :='1'H,
......@@ -563,6 +881,7 @@ testcase tc_jsonBasic_encdec_record() runs on CT {
};
var R_json y := {
i := 1,
f:=2.0,
bs := '1'B,
cs := "1",
hs :='1'H,
......@@ -571,14 +890,14 @@ testcase tc_jsonBasic_encdec_record() runs on CT {
e := first
};
var bitstring bs;
var bitstring expected := oct2bit(unichar2oct("{\"i\":1,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"" & char(0, 0, 0, 1) & "\",\"e\":\"first\"}"));// ???
var bitstring expected := oct2bit(unichar2oct("{\"i\":1,\"f\":2.000000,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"" & char(0, 0, 0, 1) & "\",\"e\":\"first\"}"));// ???
log("expected:",expected);
bs := f_json_enc_r2bs(x);
log(bs);
log(bit2oct(bs));
log(oct2char(bit2oct(bs)));
f_compare_bitstring(bs, expected);
bs := f_json_enc_r2bs(y);
log(bit2oct(bs));
if ( bs == expected ) {
......@@ -630,11 +949,11 @@ testcase tc_jsonBasic_encdec_set() runs on CT {
var bitstring expected := oct2bit(unichar2oct("{\"i\":1,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"" & char(0, 0, 0, 1) & "\",\"e\":\"first\"}"));// ???
log("expected:",expected);
bs := f_json_enc_s2bs(x);
// log(bs);
// log(bit2oct(bs));
// log(oct2char(bit2oct(bs)));
// log(bs);
// log(bit2oct(bs));
// log(oct2char(bit2oct(bs)));
f_compare_bitstring(bs, expected);
bs := f_json_enc_s2bs(y);
log(bit2oct(bs));
f_compare_bitstring(bs, expected);
......@@ -642,7 +961,7 @@ testcase tc_jsonBasic_encdec_set() runs on CT {
//encvalue
bs := encvalue(y);
f_compare_bitstring(bs, expected);
//decode test:
var S_json z := f_json_dec_bs2s(expected);
if ( y ==z ) {
......@@ -674,7 +993,7 @@ testcase tc_jsonBasic_encdec_AI3() runs on CT {
log(bit2oct(bs));
log(oct2char</