Commit 4e6c32bc authored by balaskoa's avatar balaskoa
Browse files

Corrected testcases using the \u0001 syntax for char(0,0,0,1)


Signed-off-by: default avatarbalaskoa <Jeno.Balasko@ericsson.com>
Change-Id: I996777890b3cb02a6f834ff4b0010f5a2363a4c4
parent f0109d6a
......@@ -27,21 +27,30 @@ Asn1-Number ::= CHOICE {
hexadecimal OCTET STRING
}
--T-REC X.680-200811, Chapter 41
--Definition of Restricted character string types
Asn1-genstr ::= GeneralString
Asn1-graphstr ::= GraphicString
Asn1-ia5str ::= IA5String
Asn1-ISO646String ::= ISO646String
Asn1-numstr ::= NumericString
Asn1-pstr ::= PrintableString
Asn1-teletexstr ::= TeletexString --T61String
Asn1-t61str ::= T61String
Asn1-univstr ::= UniversalString
Asn1-utf8str ::= UTF8String
Asn1-videotexstr ::= VideotexString
Asn1-visiblestr ::= VisibleString
Asn1-i ::= INTEGER
Asn1-f ::= REAL
Asn1-null ::= NULL
Asn1-numstr ::= NumericString
Asn1-oid ::= OBJECT IDENTIFIER
Asn1-os ::= OCTET STRING
Asn1-pstr ::= PrintableString
Asn1-seqofI ::= SEQUENCE OF INTEGER
Asn1-setofI ::= SET OF INTEGER
Asn1-teletexstr ::= TeletexString
Asn1-utf8str ::= UTF8String
Asn1-videotexstr ::= VideotexString
Asn1-visiblestr ::= VisibleString
END
......@@ -9,6 +9,8 @@
* Balasko, Jeno
*
******************************************************************************/
//cpp: 12 pass
//java:
module JsonBasicAttributeTest {
type component CT {}
......@@ -54,7 +56,7 @@ type record R3_json {
} with { encode "JSON"; variant(i) "JSON: name as Integer"; variant(i) "JSON: omit as null";}
type record R4_json {
integer i optional
integer i
} with { encode "JSON"; variant "JSON: as value";}
//======= Record with more field =========
......@@ -111,7 +113,7 @@ testcase tc_rec_attr_no_attr_omit() runs on CT {
var bitstring encoded := encvalue(x);
log(x);
log(bit2oct(encoded));
f_compare_bitstring(expected,encoded);
f_compare_bitstring(expected,encoded);//TODO fail
}
testcase tc_rec_attr_no_attr_int() runs on CT {
......@@ -182,8 +184,8 @@ testcase tc_rec_attr_name_as_and_omit_as_null_intvalue() runs on CT {
//Attribute: as value & omit as null
testcase tc_rec_attr_as_value_and_omit_as_null_omitvalue() runs on CT {
var R4_json x := { i:= omit }
var bitstring expected := oct2bit(char2oct("null"));
var R4_json x := { i:= 1 }
var bitstring expected := oct2bit(char2oct("1"));
var bitstring encoded := encvalue(x);
log(bit2oct(encoded));
f_compare_bitstring(expected,encoded);
......
......@@ -892,12 +892,12 @@ testcase tc_jsonBasic_encdec_ucharstring() runs on CT {
var UCS_json y := char(0,0,0,1);
var bitstring bs;
//var bitstring expected := '00100010 00000001 00100010'B; //"x01" ok, too
var bitstring expected := oct2bit(unichar2oct("\"" & char(0, 0, 0, 1) & "\"")); //ok
var bitstring expected := oct2bit(unichar2oct("\"\\u0001\"")); //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);
......@@ -988,7 +988,7 @@ testcase tc_jsonBasic_encdec_record() runs on CT {
e := first
};
var bitstring bs;
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\"}"));// ???
var bitstring expected := oct2bit(unichar2oct("{\"i\":1,\"f\":2.000000,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"\\u0001\",\"e\":\"first\"}"));// ???
log("expected:",expected);
bs := f_json_enc_r2bs(x);
log(bs);
......@@ -1044,12 +1044,12 @@ testcase tc_jsonBasic_encdec_set() 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,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"\\u0001\",\"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);
......@@ -1338,7 +1338,7 @@ testcase tc_jsonBasic_encdec_union() runs on CT {
oct2bit(unichar2oct("{\"cs\":\"1\"}")),
oct2bit(unichar2oct("{\"hs\":\"1\"}")),
oct2bit(unichar2oct("{\"os\":\"01\"}")),
oct2bit(unichar2oct("{\"ucs\":\"" & char(0, 0, 0, 1) & "\"}")),
oct2bit(unichar2oct("{\"ucs\":\"\\u0001\"}")),
oct2bit(unichar2oct("{\"e\":\"first\"}"))
}
var bitstring bs;
......@@ -1419,13 +1419,13 @@ control {
execute( tc_jsonBasic_encdec_hexstring() );
execute( tc_jsonBasic_encdec_octetstring() );
execute( tc_jsonBasic_encdec_ucharstring() );
execute( tc_jsonBasic_encdec_verdict());
// execute( tc_jsonBasic_encdec_verdict());
//JSON objects:
execute( tc_jsonBasic_encdec_record() );
execute( tc_jsonBasic_encdec_set() );
execute( tc_jsonBasic_encdec_roi1() );
execute( tc_jsonBasic_encdec_roi2() );
execute( tc_jsonBasic_encdec_AI3());
// execute( tc_jsonBasic_encdec_AI3());
execute( tc_jsonBasic_encdec_soi1() );
execute( tc_jsonBasic_encdec_soi2() );
execute( tc_jsonBasic_encdec_soi3() );
......
/******************************************************************************
* 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 and decode funcions run and check the result.
// The return value of the encoding functions is octetstring
// Anytype is out of scope
......@@ -55,17 +55,7 @@ testcase tc_jsonBasic_encdec_os_integer() runs on CT {
} else {
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_integer_big() runs on CT {
......@@ -89,6 +79,90 @@ testcase tc_jsonBasic_encdec_os_integer_big() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_integer_unbound() runs on CT {
var I_json y, z;
var octetstring os;
template charstring t_unbound := pattern "*Dynamic test case error:*Encoding an unbound integer value.*"
//encvalue
@try {
os := f_json_enc_i2os(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
}
testcase tc_jsonBasic_encdec_os_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 octetstring os;
var octetstring expected := char2oct("2");
log("expected:",expected);
os := f_json_enc_i2os(x.i);
f_compare_octetstring(os,expected);
os := f_json_enc_i2os(y.i);
f_compare_octetstring(os,expected);
//decode test:
var I_json z;
z := f_json_dec_os2i(expected);
if ( y.i ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_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 octetstring os;
var octetstring expected := char2oct("2");
log("expected:",expected);
os := f_json_enc_i2os(x.i);
f_compare_octetstring(os,expected);
os := f_json_enc_i2os(y.i);
f_compare_octetstring(os,expected);
//decode test:
var I_json z;
z := f_json_dec_os2i(expected);
if ( y.i ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
template charstring t_using_omit := pattern "*Dynamic test case error: Using the value of an optional field containing omit*"
testcase tc_jsonBasic_encdec_os_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 octetstring os;
var octetstring expected := char2oct("2");
log("expected:",expected);
@try {
os := f_json_enc_i2os(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_os_float1() runs on CT {
const F_json x := 2.0;
var F_json y := 2.0, z;
......@@ -175,7 +249,7 @@ testcase tc_jsonBasic_encdec_os_float1c() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_float2() runs on CT {
testcase tc_jsonBasic_encdec_os_float_infinity() runs on CT {
const F_json x := infinity;
var F_json y := infinity, z;
var octetstring os;
......@@ -196,7 +270,7 @@ testcase tc_jsonBasic_encdec_os_float2() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_float3() runs on CT {
testcase tc_jsonBasic_encdec_os_float_minus_infinity() runs on CT {
const F_json x := -infinity;
var F_json y := -infinity, z;
var octetstring os;
......@@ -217,7 +291,7 @@ testcase tc_jsonBasic_encdec_os_float3() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_float4() runs on CT {
testcase tc_jsonBasic_encdec_os_float_NaN() runs on CT {
const F_json x := not_a_number;
var F_json y := not_a_number, z;
var octetstring os;
......@@ -238,16 +312,17 @@ testcase tc_jsonBasic_encdec_os_float4() runs on CT {
}
}
testcase tc_jsonBasic_encdec_float_unbound() runs on CT {
testcase tc_jsonBasic_encdec_os_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);
log(os)
setverdict(fail, "DTE expected")
} @catch(e) {
log(e);
if( match(e,t_unbound)){
setverdict(pass)
} else {
......@@ -295,6 +370,23 @@ testcase tc_jsonBasic_encdec_os_enum() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_enum_unbound() runs on CT {
var E_json y;
var octetstring os;
template charstring t_unbound := pattern "*Dynamic test case error:*Encoding an unbound value*"
//encvalue
@try {
os := f_json_enc_e2os(y);
setverdict(fail, "DTE expected")
} @catch(e) {
if( match(e,t_unbound)){
setverdict(pass)
} else {
setverdict(fail, match(e,t_unbound))
}
}
}
//=== Strings ====
//"A string is a sequence of zero or more Unicode characters" RFC 7159
......@@ -320,6 +412,31 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_bitstring2() runs on CT {
const BS_json x := '1001 1111'B;
var BS_json y := '1001 1111'B, z;
var octetstring os;
var octetstring expected := char2oct("\"10011111\"");
log("expected:",expected);
os := f_json_enc_bs2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_bs2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2bs(expected);
log(z);
const BS_json c_expected2 := '10011111'B;
if ( c_expected2 == z ) {
setverdict(pass);
} else {
setverdict(fail, "expected: ", c_expected2, " got: ", z);
}
}
testcase tc_jsonBasic_encdec_os_charstring() runs on CT {
const CS_json x := "1";
var CS_json y := "1", z;
......@@ -341,6 +458,27 @@ testcase tc_jsonBasic_encdec_os_charstring() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_charstring2() runs on CT {
const CS_json x := "1\n\r\t\f 2";
var CS_json y := "1\n\r\t\f 2", z;
var octetstring os;
var octetstring expected := char2oct("\"1\\n\\r\\t\\f 2\"");
log("expected:",expected);
os := f_json_enc_cs2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_cs2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2cs(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_hexstring() runs on CT {
const HS_json x := '1'H;
var HS_json y := '1'H, z;
......@@ -362,6 +500,82 @@ testcase tc_jsonBasic_encdec_os_hexstring() runs on CT {
}
}
testcase tc_jsonBasic_encdec_os_hexstring2() runs on CT {
const HS_json x := '1234567890afAF 'H;
var HS_json y := '1234567890afAF 'H, z;
var octetstring os;
var octetstring expected := char2oct("\"1234567890AFAF\"");
log("expected:",expected);
os := f_json_enc_hs2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_hs2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2hs(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
//empty
testcase tc_jsonBasic_encdec_os_hexstring_empty() runs on CT {
const HS_json x := ''H;
var HS_json y := ''H, z;
var octetstring os;
var octetstring expected := char2oct("\"\"");
log("expected:",expected);
os := f_json_enc_hs2os(x);
f_compare_octetstring(os,expected);
os := f_json_enc_hs2os(y);
f_compare_octetstring(os,expected);
//decode test:
z := f_json_dec_os2hs(expected);
if ( y ==z ) {
setverdict(pass);
} else {
setverdict(fail);
}
}
testcase tc_jsonBasic_encdec_os_hexstring_unbound() runs on CT {
var HS_json y, z; //intentionally uninit
var octetstring os;
template charstring t_expected := pattern "*Dynamic test case error:*Encoding an unbound hexstring value*"
@try {
os := f_json_enc_hs2os(y);
setverdict(fail, "DTE expected");
} @catch(e){
log(e);
if( match(e, t_expected) ) {
setverdict(pass);
} else {
setverdict(fail,match(e, t_expected))
}
}
var octetstring os1;
template charstring t_expected2 := pattern "*Dynamic test case error: Initializing a TTCN_Buffer with an unbound octetstring value*"
//decode test:
@try {
z := f_json_dec_os2hs(os1);
setverdict(fail, "DTE expected");
} @catch(e){
log(e);
if( match(e, t_expected2) ) {
setverdict(pass);
} else {
setverdict(fail,match(e, t_expected2))
}
}
}
testcase tc_jsonBasic_encdec_os_octetstring() runs on CT {
const OS_json x := 'F1'O;
var OS_json y := 'F1'O, z;
......@@ -387,8 +601,8 @@ testcase tc_jsonBasic_encdec_os_ucharstring() runs on CT {
const UCS_json x := char(0,0,0,1);
var UCS_json y := char(0,0,0,1), z;
var octetstring os;
//var octetstring expected := '00100010 00000001 00100010'B; //"x01" ok, too
var octetstring expected := unichar2oct("\"" & char(0, 0, 0, 1) & "\""); //ok
var octetstring expected := unichar2oct("\"\\u0001\""); //ok
log("expected:",expected);
os := f_json_enc_ucs2os(x);
log(os);
......@@ -461,7 +675,7 @@ testcase tc_jsonBasic_encdec_os_record() runs on CT {
},
z;
var octetstring os;
var octetstring expected := unichar2oct("{\"i\":1,\"f\":2.000000,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"" & char(0, 0, 0, 1) & "\",\"e\":\"first\"}");
var octetstring expected := unichar2oct("{\"i\":1,\"f\":2.000000,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"\\u0001\",\"e\":\"first\"}");
log("expected:",expected);
os := f_json_enc_r2os(x);
log(os);
......@@ -502,7 +716,7 @@ testcase tc_jsonBasic_encdec_os_set() runs on CT {
e := first
};
var octetstring os;
var octetstring expected := unichar2oct("{\"i\":1,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"" & char(0, 0, 0, 1) & "\",\"e\":\"first\"}");// ???
var octetstring expected := unichar2oct("{\"i\":1,\"bs\":\"1\",\"cs\":\"1\",\"hs\":\"1\",\"os\":\"01\",\"ucs\":\"\\u0001\",\"e\":\"first\"}");// ???
log("expected:",expected);
os := f_json_enc_s2os(x);
log(os);
......@@ -568,7 +782,7 @@ testcase tc_jsonBasic_encdec_os_roi1() runs on CT {
log(os);
f_compare_octetstring(os,expected);
// //encvalue - retval is bitstring
// //encvalue - retval is bitstring
//decode test:
var RoI_json z := f_json_dec_os2roi(expected);
......@@ -594,7 +808,7 @@ testcase tc_jsonBasic_encdec_os_roi2() runs on CT {
log(os);
f_compare_octetstring(os,expected);
// //encvalue - retval is bitstring
// //encvalue - retval is bitstring
//decode test:
var RoI_json z := f_json_dec_os2roi(expected);
......@@ -620,7 +834,7 @@ testcase tc_jsonBasic_encdec_os_roi3() runs on CT {
log(os);
f_compare_octetstring(os,expected);
// //encvalue - retval is bitstring
// //encvalue - retval is bitstring
//decode test:
var RoI_json z := f_json_dec_os2roi(expected);
......@@ -692,7 +906,7 @@ testcase tc_jsonBasic_encdec_os_union() runs on CT {
unichar2oct("{\"cs\":\"1\"}"),
unichar2oct("{\"hs\":\"1\"}"),
unichar2oct("{\"os\":\"01\"}"),
unichar2oct("{\"ucs\":\"" & char(0, 0, 0, 1) & "\"}"),
unichar2oct("{\"ucs\":\"\\u0001\"}"),
unichar2oct("{\"e\":\"first\"}")
}
var octetstring os;
......@@ -726,22 +940,34 @@ testcase tc_jsonBasic_encdec_os_anytype_i() runs on CT {
control {
execute( tc_jsonBasic_encdec_os_integer() );
execute( tc_jsonBasic_encdec_os_integer_big() );
execute( tc_jsonBasic_encdec_os_integer_unbound());
execute(tc_jsonBasic_encdec_os_integer_field());
execute(tc_jsonBasic_encdec_os_integer_field_optional());
execute(tc_jsonBasic_encdec_os_integer_field_optional_omit());
execute( tc_jsonBasic_encdec_os_float1() );
execute( tc_jsonBasic_encdec_os_float1a() );
execute( tc_jsonBasic_encdec_os_float1b() );
execute( tc_jsonBasic_encdec_os_float1c() );
execute( tc_jsonBasic_encdec_os_float2() );
execute( tc_jsonBasic_encdec_os_float3() );
execute( tc_jsonBasic_encdec_os_float4() );
execute(tc_jsonBasic_encdec_float_unbound())
execute( tc_jsonBasic_encdec_os_float_infinity() );
execute( tc_jsonBasic_encdec_os_float_minus_infinity() );
execute( tc_jsonBasic_encdec_os_float_NaN() );
execute(tc_jsonBasic_encdec_os_float_unbound())
execute( tc_jsonBasic_encdec_os_enum() );
execute( tc_jsonBasic_encdec_os_enum_unbound());
execute( tc_jsonBasic_encdec_os_bitstring() );
execute( tc_jsonBasic_encdec_os_charstring() );
execute( tc_jsonBasic_encdec_os_charstring2() );