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
--///////////////////////////////////////////////////////////////////////////// --/////////////////////////////////////////////////////////////////////////////
-- Copyright (c) 2000-2020 Ericsson Telecom AB -- Copyright (c) 2000-2020 Ericsson Telecom AB
-- All rights reserved. This program and the accompanying materials -- All rights reserved. This program and the accompanying materials
-- are made available under the terms of the Eclipse Public License v2.0 -- are made available under the terms of the Eclipse Public License v2.0
-- which accompanies this distribution, and is available at -- which accompanies this distribution, and is available at
-- https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html -- https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
-- --
-- Contributors: -- Contributors:
-- Balasko, Jeno -- Balasko, Jeno
-- Baranyi, Botond -- Baranyi, Botond
-- --
--///////////////////////////////////////////////////////////////////////////// --/////////////////////////////////////////////////////////////////////////////
JsonBasicASN1Types DEFINITIONS JsonBasicASN1Types DEFINITIONS
AUTOMATIC TAGS ::= AUTOMATIC TAGS ::=
BEGIN BEGIN
IMPORTS ; IMPORTS ;
Asn1-bs ::= BIT STRING Asn1-bs ::= BIT STRING
Asn1-bool ::= BOOLEAN Asn1-bool ::= BOOLEAN
Asn1-bmpstr ::= BMPString Asn1-bmpstr ::= BMPString
Asn1-Number ::= CHOICE { Asn1-Number ::= CHOICE {
decimal INTEGER, decimal INTEGER,
binary BIT STRING, binary BIT STRING,
hexadecimal OCTET STRING hexadecimal OCTET STRING
} }
Asn1-genstr ::= GeneralString --T-REC X.680-200811, Chapter 41
Asn1-graphstr ::= GraphicString --Definition of Restricted character string types
Asn1-ia5str ::= IA5String Asn1-genstr ::= GeneralString
Asn1-i ::= INTEGER Asn1-graphstr ::= GraphicString
Asn1-f ::= REAL Asn1-ia5str ::= IA5String
Asn1-null ::= NULL Asn1-ISO646String ::= ISO646String
Asn1-numstr ::= NumericString Asn1-numstr ::= NumericString
Asn1-oid ::= OBJECT IDENTIFIER Asn1-pstr ::= PrintableString
Asn1-os ::= OCTET STRING Asn1-teletexstr ::= TeletexString --T61String
Asn1-pstr ::= PrintableString Asn1-t61str ::= T61String
Asn1-seqofI ::= SEQUENCE OF INTEGER Asn1-univstr ::= UniversalString
Asn1-setofI ::= SET OF INTEGER Asn1-utf8str ::= UTF8String
Asn1-teletexstr ::= TeletexString Asn1-videotexstr ::= VideotexString
Asn1-utf8str ::= UTF8String Asn1-visiblestr ::= VisibleString
Asn1-videotexstr ::= VideotexString
Asn1-visiblestr ::= VisibleString
Asn1-i ::= INTEGER
END Asn1-f ::= REAL
Asn1-null ::= NULL
Asn1-oid ::= OBJECT IDENTIFIER
Asn1-os ::= OCTET STRING
Asn1-seqofI ::= SEQUENCE OF INTEGER
Asn1-setofI ::= SET OF INTEGER
END
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
* Balasko, Jeno * Balasko, Jeno
* *
******************************************************************************/ ******************************************************************************/
//cpp: 12 pass
//java:
module JsonBasicAttributeTest { module JsonBasicAttributeTest {
type component CT {} type component CT {}
...@@ -54,7 +56,7 @@ type record R3_json { ...@@ -54,7 +56,7 @@ type record R3_json {
} with { encode "JSON"; variant(i) "JSON: name as Integer"; variant(i) "JSON: omit as null";} } with { encode "JSON"; variant(i) "JSON: name as Integer"; variant(i) "JSON: omit as null";}
type record R4_json { type record R4_json {
integer i optional integer i
} with { encode "JSON"; variant "JSON: as value";} } with { encode "JSON"; variant "JSON: as value";}
//======= Record with more field ========= //======= Record with more field =========
...@@ -111,7 +113,7 @@ testcase tc_rec_attr_no_attr_omit() runs on CT { ...@@ -111,7 +113,7 @@ testcase tc_rec_attr_no_attr_omit() runs on CT {
var bitstring encoded := encvalue(x); var bitstring encoded := encvalue(x);
log(x); log(x);
log(bit2oct(encoded)); 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 { 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 { ...@@ -182,8 +184,8 @@ testcase tc_rec_attr_name_as_and_omit_as_null_intvalue() runs on CT {
//Attribute: as value & omit as null //Attribute: as value & omit as null
testcase tc_rec_attr_as_value_and_omit_as_null_omitvalue() runs on CT { testcase tc_rec_attr_as_value_and_omit_as_null_omitvalue() runs on CT {
var R4_json x := { i:= omit } var R4_json x := { i:= 1 }
var bitstring expected := oct2bit(char2oct("null")); var bitstring expected := oct2bit(char2oct("1"));
var bitstring encoded := encvalue(x); var bitstring encoded := encvalue(x);
log(bit2oct(encoded)); log(bit2oct(encoded));
f_compare_bitstring(expected,encoded); f_compare_bitstring(expected,encoded);
......
...@@ -892,12 +892,12 @@ testcase tc_jsonBasic_encdec_ucharstring() runs on CT { ...@@ -892,12 +892,12 @@ testcase tc_jsonBasic_encdec_ucharstring() runs on CT {
var UCS_json y := char(0,0,0,1); var UCS_json y := char(0,0,0,1);
var bitstring bs; var bitstring bs;
//var bitstring expected := '00100010 00000001 00100010'B; //"x01" ok, too //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); log("expected:",expected);
bs := f_json_enc_ucs2bs(x); bs := f_json_enc_ucs2bs(x);
// log(bs); log(bs);
// log(bit2oct(bs)); //'220122'O = "01" log(bit2oct(bs)); //'220122'O = "01"
// log(oct2char(bit2oct(bs))); // "\"" & char(0, 0, 0, 1) & "\"" log(oct2char(bit2oct(bs))); // "\"" & char(0, 0, 0, 1) & "\""
f_compare_bitstring(bs, expected); f_compare_bitstring(bs, expected);
bs := f_json_enc_ucs2bs(y); bs := f_json_enc_ucs2bs(y);
...@@ -988,7 +988,7 @@ testcase tc_jsonBasic_encdec_record() runs on CT { ...@@ -988,7 +988,7 @@ testcase tc_jsonBasic_encdec_record() runs on CT {
e := first e := first
}; };
var bitstring bs; 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); log("expected:",expected);
bs := f_json_enc_r2bs(x); bs := f_json_enc_r2bs(x);
log(bs); log(bs);
...@@ -1044,12 +1044,12 @@ testcase tc_jsonBasic_encdec_set() runs on CT { ...@@ -1044,12 +1044,12 @@ testcase tc_jsonBasic_encdec_set() runs on CT {
e := first e := first
}; };
var bitstring bs; 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); log("expected:",expected);
bs := f_json_enc_s2bs(x); bs := f_json_enc_s2bs(x);
// log(bs); log(bs);
// log(bit2oct(bs)); log(bit2oct(bs));
// log(oct2char(bit2oct(bs))); log(oct2char(bit2oct(bs)));
f_compare_bitstring(bs, expected); f_compare_bitstring(bs, expected);
bs := f_json_enc_s2bs(y); bs := f_json_enc_s2bs(y);
...@@ -1338,7 +1338,7 @@ testcase tc_jsonBasic_encdec_union() runs on CT { ...@@ -1338,7 +1338,7 @@ testcase tc_jsonBasic_encdec_union() runs on CT {
oct2bit(unichar2oct("{\"cs\":\"1\"}")), oct2bit(unichar2oct("{\"cs\":\"1\"}")),
oct2bit(unichar2oct("{\"hs\":\"1\"}")), oct2bit(unichar2oct("{\"hs\":\"1\"}")),
oct2bit(unichar2oct("{\"os\":\"01\"}")), oct2bit(unichar2oct("{\"os\":\"01\"}")),
oct2bit(unichar2oct("{\"ucs\":\"" & char(0, 0, 0, 1) & "\"}")), oct2bit(unichar2oct("{\"ucs\":\"\\u0001\"}")),
oct2bit(unichar2oct("{\"e\":\"first\"}")) oct2bit(unichar2oct("{\"e\":\"first\"}"))
} }
var bitstring bs; var bitstring bs;
...@@ -1419,13 +1419,13 @@ control { ...@@ -1419,13 +1419,13 @@ control {
execute( tc_jsonBasic_encdec_hexstring() ); execute( tc_jsonBasic_encdec_hexstring() );
execute( tc_jsonBasic_encdec_octetstring() ); execute( tc_jsonBasic_encdec_octetstring() );
execute( tc_jsonBasic_encdec_ucharstring() ); execute( tc_jsonBasic_encdec_ucharstring() );
execute( tc_jsonBasic_encdec_verdict()); // execute( tc_jsonBasic_encdec_verdict());
//JSON objects: //JSON objects:
execute( tc_jsonBasic_encdec_record() ); execute( tc_jsonBasic_encdec_record() );
execute( tc_jsonBasic_encdec_set() ); execute( tc_jsonBasic_encdec_set() );
execute( tc_jsonBasic_encdec_roi1() ); execute( tc_jsonBasic_encdec_roi1() );
execute( tc_jsonBasic_encdec_roi2() ); execute( tc_jsonBasic_encdec_roi2() );
execute( tc_jsonBasic_encdec_AI3()); // execute( tc_jsonBasic_encdec_AI3());
execute( tc_jsonBasic_encdec_soi1() ); execute( tc_jsonBasic_encdec_soi1() );
execute( tc_jsonBasic_encdec_soi2() ); execute( tc_jsonBasic_encdec_soi2() );
execute( tc_jsonBasic_encdec_soi3() ); execute( tc_jsonBasic_encdec_soi3() );
......
/****************************************************************************** /******************************************************************************
* Copyright (c) 2000-2020 Ericsson Telecom AB * Copyright (c) 2000-2020 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0 * are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
* *
* Contributors: * Contributors:
* Balasko, Jeno * Balasko, Jeno
* *
******************************************************************************/ ******************************************************************************/
// The testcases check if the encode and decode funcions run and check the result. // The testcases check if the encode and decode funcions run and check the result.
// The return value of the encoding functions is octetstring // The return value of the encoding functions is octetstring
// Anytype is out of scope // Anytype is out of scope
...@@ -44,7 +44,7 @@ testcase tc_jsonBasic_encdec_os_integer() runs on CT { ...@@ -44,7 +44,7 @@ testcase tc_jsonBasic_encdec_os_integer() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_i2os(x); os := f_json_enc_i2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_i2os(y); os := f_json_enc_i2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -55,17 +55,7 @@ testcase tc_jsonBasic_encdec_os_integer() runs on CT { ...@@ -55,17 +55,7 @@ testcase tc_jsonBasic_encdec_os_integer() 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_integer_big() runs on CT { testcase tc_jsonBasic_encdec_os_integer_big() runs on CT {
...@@ -76,7 +66,7 @@ testcase tc_jsonBasic_encdec_os_integer_big() runs on CT { ...@@ -76,7 +66,7 @@ testcase tc_jsonBasic_encdec_os_integer_big() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_i2os(x); os := f_json_enc_i2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_i2os(y); os := f_json_enc_i2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -89,6 +79,90 @@ 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 { 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;
...@@ -101,7 +175,7 @@ testcase tc_jsonBasic_encdec_os_float1() runs on CT { ...@@ -101,7 +175,7 @@ testcase tc_jsonBasic_encdec_os_float1() runs on CT {
os := f_json_enc_f2os(y); os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2f(expected); z := f_json_dec_os2f(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -144,7 +218,7 @@ testcase tc_jsonBasic_encdec_os_float1b() runs on CT { ...@@ -144,7 +218,7 @@ testcase tc_jsonBasic_encdec_os_float1b() runs on CT {
os := f_json_enc_f2os(y); os := f_json_enc_f2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
//decode test: //decode test:
z := f_json_dec_os2f(expected); z := f_json_dec_os2f(expected);
if ( y ==z ) { if ( y ==z ) {
...@@ -175,7 +249,7 @@ testcase tc_jsonBasic_encdec_os_float1c() runs on CT { ...@@ -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; const F_json x := infinity;
var F_json y := infinity, z; var F_json y := infinity, z;
var octetstring os; var octetstring os;
...@@ -196,7 +270,7 @@ testcase tc_jsonBasic_encdec_os_float2() runs on CT { ...@@ -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; const F_json x := -infinity;
var F_json y := -infinity, z; var F_json y := -infinity, z;
var octetstring os; var octetstring os;
...@@ -217,7 +291,7 @@ testcase tc_jsonBasic_encdec_os_float3() runs on CT { ...@@ -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; const F_json x := not_a_number;
var F_json y := not_a_number, z; var F_json y := not_a_number, z;
var octetstring os; var octetstring os;
...@@ -238,16 +312,17 @@ testcase tc_jsonBasic_encdec_os_float4() runs on CT { ...@@ -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 F_json y ; //intentionally unbound
var octetstring os; var octetstring os;
template charstring t_unbound := pattern "*Encoding an unbound float value.*" template charstring t_unbound := pattern "*Encoding an unbound float value.*"
//encvalue //encvalue
@try { @try {
os := f_json_enc_f2os(y); os := f_json_enc_f2os(y);
log(os)
setverdict(fail, "DTE expected") setverdict(fail, "DTE expected")
} @catch(e) { } @catch(e) {
log(e);
if( match(e,t_unbound)){ if( match(e,t_unbound)){
setverdict(pass) setverdict(pass)
} else { } else {
...@@ -295,6 +370,23 @@ testcase tc_jsonBasic_encdec_os_enum() runs on CT { ...@@ -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 ==== //=== Strings ====
//"A string is a sequence of zero or more Unicode characters" RFC 7159 //"A string is a sequence of zero or more Unicode characters" RFC 7159
...@@ -307,7 +399,7 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT { ...@@ -307,7 +399,7 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT {
log("expected:",expected); log("expected:",expected);
os := f_json_enc_bs2os(x); os := f_json_enc_bs2os(x);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
os := f_json_enc_bs2os(y); os := f_json_enc_bs2os(y);
f_compare_octetstring(os,expected); f_compare_octetstring(os,expected);
...@@ -320,6 +412,31 @@ testcase tc_jsonBasic_encdec_os_bitstring() runs on CT { ...@@ -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 ) {