@@ -130,6 +130,21 @@ public static void TestJsonUtf8One(byte[] bytes) {
130130 }
131131 }
132132
133+ public void JsonTestSuiteTest (String fn , byte [] jsonBytes ) {
134+ CBORObject json = null ;
135+ try {
136+ json = CBORObject .ReadJSONBytes (jsonBytes , new
137+ JSONOptions ("allowduplicatekeys=1" ));
138+ } catch (CBORException ex ) {
139+ json = null ;
140+ }
141+ if (fn .startsWith ("y_" ) && json == null ) {
142+ Assert .fail ("should have succeeded: " + fn );
143+ } else if (fn .startsWith ("n_" ) && json != null ) {
144+ Assert .fail ("should have failed: " + fn );
145+ }
146+ }
147+
133148 @ Test (timeout = 30000 )
134149 public void TestCorrectUtf8 () {
135150 RandomGenerator rg = new RandomGenerator ();
@@ -1024,29 +1039,34 @@ public static boolean TestEquivJSONOne(byte[] bytes) {
10241039 Assert .fail ();
10251040 }
10261041 if (!cbo .equals (cbo2 )) {
1027- System .out .print ("jsonstring" );
1028- System .out .print (TestCommon .ToByteArrayString (bytes ));
1029- System .out .print (com .upokecenter .util .DataUtilities .GetUtf8String (bytes , true ));
1030- System .out .print ("old " + TestCommon .ToByteArrayString (cbo .ToJSONBytes ()));
1031- System .out .print (cbo .ToJSONString ());
1032- System .out .print ("new " +
1042+ if (bytes .length < 16 ) {
1043+ System .out .println ("jsonstring" );
1044+ System .out .println (TestCommon .ToByteArrayString (bytes ));
1045+ System .out .println (com .upokecenter .util .DataUtilities .GetUtf8String (bytes , true ));
1046+ System .out .println ("old " +
1047+ TestCommon .ToByteArrayString (cbo .ToJSONBytes ()));
1048+ System .out .println (cbo .ToJSONString ());
1049+ System .out .println ("new " +
10331050 TestCommon .ToByteArrayString (cbo2 .ToJSONBytes ()));
1034- System .out .print (cbo2 .ToJSONString ());
1051+ System .out .println (cbo2 .ToJSONString ());
1052+ }
10351053 Assert .assertEquals (cbo , cbo2 );
10361054 }
10371055 cbo2 = CBORObject .FromJSONBytes (cbo .ToJSONBytes ());
10381056 if (!(cbo2 != null )) {
10391057 Assert .fail ();
10401058 }
10411059 if (!cbo .equals (cbo2 )) {
1042- System .out .print ("jsonbytes" );
1043- System .out .print (TestCommon .ToByteArrayString (bytes ));
1044- System .out .print (com .upokecenter .util .DataUtilities .GetUtf8String (bytes , true ));
1045- System .out .print ("old " + TestCommon .ToByteArrayString (cbo .ToJSONBytes ()));
1046- System .out .print (cbo .ToJSONString ());
1047- System .out .print ("new " +
1060+ if (bytes .length < 16 ) {
1061+ System .out .println ("jsonbytes" );
1062+ System .out .println (TestCommon .ToByteArrayString (bytes ));
1063+ System .out .println (com .upokecenter .util .DataUtilities .GetUtf8String (bytes , true ));
1064+ System .out .println ("old " + TestCommon .ToByteArrayString (cbo .ToJSONBytes ()));
1065+ System .out .println (cbo .ToJSONString ());
1066+ System .out .println ("new " +
10481067 TestCommon .ToByteArrayString (cbo2 .ToJSONBytes ()));
1049- System .out .print (cbo2 .ToJSONString ());
1068+ System .out .println (cbo2 .ToJSONString ());
1069+ }
10501070 Assert .assertEquals (cbo , cbo2 );
10511071 }
10521072 return true ;
0 commit comments