Commit dad2eee2 authored by balaskoa's avatar balaskoa
Browse files

JsonBasicTest: new tests


Signed-off-by: default avatarbalaskoa <Jeno.Balasko@ericsson.com>
Change-Id: I9958835422b3f215a64497f85a33c62e5b2e0601
parent 568d8d7f
...@@ -292,6 +292,104 @@ testcase tc_jsonBasic_encdec_float1() runs on CT { ...@@ -292,6 +292,104 @@ testcase tc_jsonBasic_encdec_float1() runs on CT {
} }
} }
testcase tc_jsonBasic_encdec_float1a() runs on CT {
const F_json x := 2.0e5;
var F_json y := 2.0e5;
var bitstring bs;
var bitstring expected := oct2bit(char2oct("200000.000000"));
log("expected:",expected);
bs := f_json_enc_f2bs(x);
log(bit2oct(bs));
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y);
f_compare_bitstring(bs, expected);
//decode test:
var F_json z := f_json_dec_bs2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_float1b() runs on CT {
const F_json x := 2.0e9;
var F_json y := 2.0e9;
var bitstring bs;
var bitstring expected := oct2bit(char2oct("2000000000.000000"));
log("expected:",expected);
bs := f_json_enc_f2bs(x);
log(bit2oct(bs));
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y);
f_compare_bitstring(bs, expected);
//decode test:
var F_json z := f_json_dec_bs2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_float1c() runs on CT {
const F_json x := 2.0e10;
var F_json y := 2.0e10;
var bitstring bs;
var bitstring expected := oct2bit(char2oct("2.000000e+10"));
log("expected:",expected);
bs := f_json_enc_f2bs(x);
log(bit2oct(bs));
f_compare_bitstring(bs, expected);
bs := f_json_enc_f2bs(y);
f_compare_bitstring(bs, expected);
//encvalue
bs := encvalue(y);
f_compare_bitstring(bs, expected);
//decode test:
var F_json z := f_json_dec_bs2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
var integer r := decvalue(expected, z);
if (r==0 and y==z){
setverdict(pass);
} else {
setverdict(fail);
}
}
//Reference Guide: "The special float values //Reference Guide: "The special float values
//infinity, -infinity and not_a_number are encoded as JSON strings." //infinity, -infinity and not_a_number are encoded as JSON strings."
testcase tc_jsonBasic_encdec_float2() runs on CT { testcase tc_jsonBasic_encdec_float2() runs on CT {
...@@ -400,7 +498,7 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT { ...@@ -400,7 +498,7 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
setverdict(fail, "DTE expected") setverdict(fail, "DTE expected")
} @catch(e) { } @catch(e) {
if( match(e,t_unbound)){ if( match(e,t_unbound)){
setverdict(pass) setverdict(pass)
} else { } else {
setverdict(fail, match(e,t_unbound)) setverdict(fail, match(e,t_unbound))
...@@ -413,7 +511,7 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT { ...@@ -413,7 +511,7 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
setverdict(fail, "DTE expected") setverdict(fail, "DTE expected")
} @catch(e) { } @catch(e) {
if( match(e,t_unbound)){ if( match(e,t_unbound)){
setverdict(pass) setverdict(pass)
} else { } else {
setverdict(fail, match(e,t_unbound)) setverdict(fail, match(e,t_unbound))
...@@ -423,10 +521,10 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT { ...@@ -423,10 +521,10 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
var bitstring encoded; //intentionally unbound var bitstring encoded; //intentionally unbound
template charstring t_unbound2 := pattern "*The argument of function bit2oct\(\) is an unbound bitstring value.*" template charstring t_unbound2 := pattern "*The argument of function bit2oct\(\) is an unbound bitstring value.*"
@try { @try {
var I_json z := f_json_dec_bs2i(encoded); var F_json z := f_json_dec_bs2f(encoded);
setverdict(fail, "DTE expected") setverdict(fail, "DTE expected")
} @catch(e) { } @catch(e) {
if( match(e,t_unbound2)){ if( match(e,t_unbound2)){
setverdict(pass) setverdict(pass)
} else { } else {
setverdict(fail, match(e,t_unbound2)); //TODO: got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value setverdict(fail, match(e,t_unbound2)); //TODO: got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
...@@ -435,11 +533,11 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT { ...@@ -435,11 +533,11 @@ testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
template charstring tl_unbound2 := pattern "*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 { @try {
var I_json z ; var F_json z ;
var integer r := decvalue(encoded, z); var integer r := decvalue(encoded, z);
setverdict(fail, "DTE expected") setverdict(fail, "DTE expected")
} @catch(e) { } @catch(e) {
if( match(e,t_unbound2)){ if( match(e,t_unbound2)){
setverdict(pass) setverdict(pass)
} else { } else {
setverdict(fail, match(e,t_unbound2)); //got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value setverdict(fail, match(e,t_unbound2)); //got: Dynamic test case error: The argument of function bit2oct() is an unbound bitstring value
...@@ -1303,6 +1401,9 @@ control { ...@@ -1303,6 +1401,9 @@ control {
execute(tc_jsonBasic_encdec_integer_field_optional()); execute(tc_jsonBasic_encdec_integer_field_optional());
execute(tc_jsonBasic_encdec_integer_field_optional_omit()); execute(tc_jsonBasic_encdec_integer_field_optional_omit());
execute( tc_jsonBasic_encdec_float1() ); execute( tc_jsonBasic_encdec_float1() );
execute( tc_jsonBasic_encdec_float1a() );
execute( tc_jsonBasic_encdec_float1b() );
execute( tc_jsonBasic_encdec_float1c() );
execute( tc_jsonBasic_encdec_float2() ); execute( tc_jsonBasic_encdec_float2() );
execute( tc_jsonBasic_encdec_float3() ); execute( tc_jsonBasic_encdec_float3() );
execute( tc_jsonBasic_encdec_float4() ); execute( tc_jsonBasic_encdec_float4() );
......
...@@ -87,20 +87,9 @@ testcase tc_jsonBasic_encdec_os_integer_big() runs on CT { ...@@ -87,20 +87,9 @@ testcase tc_jsonBasic_encdec_os_integer_big() runs on CT {
} else { } else {
setverdict(fail); setverdict(fail);
} }
// //Whitespace test
// expected := char2oct(" 2 3 4 ");
// log(expected);
//
// //decode test:
// z := f_json_dec_os2i(expected);
// if ( y ==z ) {
// setverdict(pass);
// } else {
// setverdict(fail);
// }
} }
testcase tc_jsonBasic_encdec_os_float() runs on CT { testcase tc_jsonBasic_encdec_os_float1() runs on CT {
const F_json x := 2.0; const F_json x := 2.0;
var F_json y := 2.0, z; var F_json y := 2.0, z;
var octetstring os; var octetstring os;
...@@ -109,7 +98,50 @@ testcase tc_jsonBasic_encdec_os_float() runs on CT { ...@@ -109,7 +98,50 @@ testcase tc_jsonBasic_encdec_os_float() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_f2os(x); os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_float1a() runs on CT {
const F_json x := 2.0e5;
var F_json y := 2.0e5, z;
var octetstring os;
//var octetstring expected := '00110010'B;
var octetstring expected := char2oct("200000.000000");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_float1b() runs on CT {
const F_json x := 2.0e9;
var F_json y := 2.0e9, z;
var octetstring os;
var octetstring expected := char2oct("2000000000.000000");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y); os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -120,9 +152,126 @@ testcase tc_jsonBasic_encdec_os_float() runs on CT { ...@@ -120,9 +152,126 @@ testcase tc_jsonBasic_encdec_os_float() runs on CT {
} else { } else {
setverdict(fail); setverdict(fail);
} }
}
testcase tc_jsonBasic_encdec_os_float1c() runs on CT {
const F_json x := 2.0e10;
var F_json y := 2.0e10, z;
var octetstring os;
var octetstring expected := char2oct("2.000000e+10");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_float2() runs on CT {
const F_json x := infinity;
var F_json y := infinity, z;
var octetstring os;
var octetstring expected := char2oct("\"infinity\"");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_float3() runs on CT {
const F_json x := -infinity;
var F_json y := -infinity, z;
var octetstring os;
var octetstring expected := char2oct("\"-infinity\"");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_float4() runs on CT {
const F_json x := not_a_number;
var F_json y := not_a_number, z;
var octetstring os;
var octetstring expected := char2oct("\"not_a_number\"");
log("expected:",expected);
os := f_json_enc_f2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2f(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
} }
testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
var F_json y ; //intentionally unbound
var octetstring os;
template charstring t_unbound := pattern "*Encoding an unbound float value.*"
//encvalue
@try {
os := f_json_enc_f2os(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
//==== decode ====
var octetstring encoded; //intentionally unbound
template charstring t_unbound2 := pattern "*Dynamic test case error: Initializing a TTCN_Buffer with an unbound octetstring value.*"
@try {
var F_json z := f_json_dec_os2f(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
}
}
}
//====== Enum ======
testcase tc_jsonBasic_encdec_os_enum() runs on CT { testcase tc_jsonBasic_encdec_os_enum() runs on CT {
const E_json x := first; const E_json x := first;
var E_json y := first, z; var E_json y := first, z;
...@@ -133,7 +282,7 @@ testcase tc_jsonBasic_encdec_os_enum() runs on CT { ...@@ -133,7 +282,7 @@ testcase tc_jsonBasic_encdec_os_enum() runs on CT {
os := f_json_enc_e2os(x); os := f_json_enc_e2os(x);
log("os:",os); log("os:",os);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_e2os(y); os := f_json_enc_e2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -162,7 +311,6 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT { ...@@ -162,7 +311,6 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT {
os := f_json_enc_bs2os(y); os := f_json_enc_bs2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2bs(expected); z := f_json_dec_os2bs(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -180,10 +328,10 @@ testcase tc_jsonBasic_encdec_os_charstring() runs on CT { ...@@ -180,10 +328,10 @@ testcase tc_jsonBasic_encdec_os_charstring() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_cs2os(x); os := f_json_enc_cs2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_cs2os(y); os := f_json_enc_cs2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2cs(expected); z := f_json_dec_os2cs(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -201,10 +349,10 @@ testcase tc_jsonBasic_encdec_os_hexstring() runs on CT { ...@@ -201,10 +349,10 @@ testcase tc_jsonBasic_encdec_os_hexstring() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_hs2os(x); os := f_json_enc_hs2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_hs2os(y); os := f_json_enc_hs2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2hs(expected); z := f_json_dec_os2hs(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -222,10 +370,10 @@ testcase tc_jsonBasic_encdec_os_octetstring() runs on CT { ...@@ -222,10 +370,10 @@ testcase tc_jsonBasic_encdec_os_octetstring() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_os2os(x); os := f_json_enc_os2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_os2os(y); os := f_json_enc_os2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2os(expected); z := f_json_dec_os2os(expected);
if ( y==z ) { if ( y==z ) {
...@@ -235,8 +383,6 @@ testcase tc_jsonBasic_encdec_os_octetstring() runs on CT { ...@@ -235,8 +383,6 @@ testcase tc_jsonBasic_encdec_os_octetstring() runs on CT {
} }
} }
testcase tc_jsonBasic_encdec_os_ucharstring() runs on CT { testcase tc_jsonBasic_encdec_os_ucharstring() runs on CT {
const UCS_json x := char(0,0,0,1); const UCS_json x := char(0,0,0,1);
var UCS_json y := char(0,0,0,1), z; var UCS_json y := char(0,0,0,1), z;
...@@ -248,10 +394,10 @@ testcase tc_jsonBasic_encdec_os_ucharstring() runs on CT { ...@@ -248,10 +394,10 @@ testcase tc_jsonBasic_encdec_os_ucharstring() runs on CT {
log(os); log(os);
log(oct2char(os)); // "\"" & char(0, 0, 0, 1) & "\"" log(oct2char(os)); // "\"" & char(0, 0, 0, 1) & "\""
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_ucs2os(y); os := f_json_enc_ucs2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2ucs(expected); z := f_json_dec_os2ucs(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -272,7 +418,7 @@ testcase tc_jsonBasic_encdec_os_verdict() runs on CT { ...@@ -272,7 +418,7 @@ testcase tc_jsonBasic_encdec_os_verdict() runs on CT {
log("expected:",expected ); log("expected:",expected );
bs := f_json_enc_v2os(x); bs := f_json_enc_v2os(x);
f_compare_octetstring(bs, expected); f_compare_octetstring(bs, expected);
bs := f_json_enc_v2os(y); bs := f_json_enc_v2os(y);
f_compare_octetstring(bs, expected); f_compare_octetstring(bs, expected);
...@@ -321,7 +467,7 @@ testcase tc_jsonBasic_encdec_os_record() runs on CT { ...@@ -321,7 +467,7 @@ testcase tc_jsonBasic_encdec_os_record() runs on CT {
log(os); log(os);
log(oct2char(os)); log(oct2char(os));
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_r2os(y); os := f_json_enc_r2os(y);
log(oct2unichar(os)); log(oct2unichar(os));
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -361,7 +507,7 @@ testcase tc_jsonBasic_encdec_os_set() runs on CT { ...@@ -361,7 +507,7 @@ testcase tc_jsonBasic_encdec_os_set() runs on CT {
os := f_json_enc_s2os(x); os := f_json_enc_s2os(x);
log(os); log(os);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_s2os(y); os := f_json_enc_s2os(y);
log(os); log(os);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -417,7 +563,7 @@ testcase tc_jsonBasic_encdec_os_roi1() runs on CT { ...@@ -417,7 +563,7 @@ testcase tc_jsonBasic_encdec_os_roi1() runs on CT {
log(os); log(os);
log( (os)); log( (os));
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_roi2os(y); os := f_json_enc_roi2os(y);
log(os); log(os);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -469,7 +615,7 @@ testcase tc_jsonBasic_encdec_os_roi3() runs on CT { ...@@ -469,7 +615,7 @@ testcase tc_jsonBasic_encdec_os_roi3() runs on CT {
log(os); log(os);
log( (os)); log( (os));
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_roi2os(y); os := f_json_enc_roi2os(y);