From 90172c8726f948883c4a351f739dd8226c3752dc Mon Sep 17 00:00:00 2001 From: Peter O Date: Sun, 22 Jun 2014 16:20:05 -0400 Subject: [PATCH] Version 1.3.0 --- CBORDocs2/Program.cs | 1 - CBORDocs2/Properties/AssemblyInfo.cs | 5 +- CBORTest/BEncodingTest.cs | 1 - CBORTest/CBORExtraTest.cs | 1 - CBORTest/CBORObjectTest.cs | 82 ++++++++++++++++++- CBORTest/CBORSupplementTest.cs | 40 --------- CBORTest/CBORTest.cs | 16 ---- CBORTest/CBORTest.csproj | 2 +- CBORTest/TestCommon.cs | 1 - CBORTest/mstest2nunit.rb | 4 +- CBORTest/nunit2mstest.rb | 1 + Cbor/CBORObject.cs | 9 +- README.md | 10 ++- docs/PeterO.Cbor.CBORObject.md | 7 +- .../java/com/upokecenter/cbor/CBORObject.java | 11 ++- .../com/upokecenter/test/CBORObjectTest.java | 82 ++++++++++++++++++- .../upokecenter/test/CBORSupplementTest.java | 40 --------- .../java/com/upokecenter/test/CBORTest.java | 16 ---- .../java/com/upokecenter/test/TestCommon.java | 1 - 19 files changed, 183 insertions(+), 147 deletions(-) diff --git a/CBORDocs2/Program.cs b/CBORDocs2/Program.cs index a41566a4..a2e585fb 100644 --- a/CBORDocs2/Program.cs +++ b/CBORDocs2/Program.cs @@ -7,7 +7,6 @@ Any copyright is dedicated to the Public Domain. at: http://upokecenter.com/d/ */ using System; -using PeterO.DocGen; namespace CBORDocs { internal class Program { diff --git a/CBORDocs2/Properties/AssemblyInfo.cs b/CBORDocs2/Properties/AssemblyInfo.cs index 09820e1a..646a444d 100644 --- a/CBORDocs2/Properties/AssemblyInfo.cs +++ b/CBORDocs2/Properties/AssemblyInfo.cs @@ -1,7 +1,4 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("CBORDocs2")] diff --git a/CBORTest/BEncodingTest.cs b/CBORTest/BEncodingTest.cs index d0ca2fa1..4032ef2b 100644 --- a/CBORTest/BEncodingTest.cs +++ b/CBORTest/BEncodingTest.cs @@ -1,7 +1,6 @@ using System; using System.IO; using System.Text; - using Microsoft.VisualStudio.TestTools.UnitTesting; using PeterO; using PeterO.Cbor; diff --git a/CBORTest/CBORExtraTest.cs b/CBORTest/CBORExtraTest.cs index 4adc58c5..a273eb55 100644 --- a/CBORTest/CBORExtraTest.cs +++ b/CBORTest/CBORExtraTest.cs @@ -9,7 +9,6 @@ Any copyright is dedicated to the Public Domain. using System.Collections.Generic; using System.Globalization; using System.Linq; - using Microsoft.VisualStudio.TestTools.UnitTesting; using PeterO; using PeterO.Cbor; diff --git a/CBORTest/CBORObjectTest.cs b/CBORTest/CBORObjectTest.cs index a9b59f98..81616ade 100644 --- a/CBORTest/CBORObjectTest.cs +++ b/CBORTest/CBORObjectTest.cs @@ -168,7 +168,7 @@ public void TestAsByte() { CBORObject numberinfo = numbers[i]; CBORObject cbornumber = CBORObject.FromObject(ExtendedDecimal.FromString(numberinfo["number"].AsString())); if (numberinfo["byte"].AsBoolean()) { - Assert.AreEqual(BigInteger.fromString(numberinfo["integer"].AsString()).intValue(), ((int)cbornumber.AsByte()) &0xff); + Assert.AreEqual(BigInteger.fromString(numberinfo["integer"].AsString()).intValue(), ((int)cbornumber.AsByte()) & 0xff); } else { try { cbornumber.AsByte(); @@ -775,9 +775,61 @@ public void TestCount() { Assert.AreEqual(0, CBORObject.NewArray().Count); Assert.AreEqual(0, CBORObject.NewMap().Count); } + + // TODO: For 2.0 + public static void TestDecodeFromBytesVersion2Dot0() { + try { + CBORObject.DecodeFromBytes(new byte[] { }); + Assert.Fail("Should have failed"); + } catch (CBORException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + } + [TestMethod] public void TestDecodeFromBytes() { - // not implemented yet + try { + CBORObject.DecodeFromBytes(new byte[] { 0x1c }); + Assert.Fail("Should have failed"); + } catch (CBORException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + try { + CBORObject.DecodeFromBytes(null); + Assert.Fail("Should have failed"); + } catch (ArgumentNullException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { 0x1e }); + Assert.Fail("Should have failed"); + } catch (CBORException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { 0xfe }); + Assert.Fail("Should have failed"); + } catch (CBORException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { 0xff }); + Assert.Fail("Should have failed"); + } catch (CBORException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } } [TestMethod] public void TestDivide() { @@ -1193,7 +1245,9 @@ public void TestFromJSONString() { } [TestMethod] public void TestFromObject() { - CBORObject[] cborarray = { CBORObject.False, CBORObject.True}; + var cborarray = new CBORObject[2]; + cborarray[0] = CBORObject.False; + cborarray[1] = CBORObject.True; CBORObject cbor = CBORObject.FromObject(cborarray); Assert.AreEqual(2, cbor.Count); Assert.AreEqual(CBORObject.False, cbor[0]); @@ -1555,7 +1609,6 @@ public void TestSet() { } [TestMethod] public void TestSign() { - // TODO: Use number database try { int sign = CBORObject.True.Sign; Assert.Fail("Should have failed"); @@ -1588,6 +1641,27 @@ public void TestSign() { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } + CBORObject numbers = GetNumberData(); + for (int i = 0; i < numbers.Count; ++i) { + CBORObject numberinfo = numbers[i]; + CBORObject cbornumber = CBORObject.FromObject(ExtendedDecimal.FromString(numberinfo["number"].AsString())); + if (cbornumber.IsNaN()) { + try { + Assert.Fail(String.Empty + cbornumber.Sign); + Assert.Fail("Should have failed"); + } catch (InvalidOperationException) { + } catch (Exception ex) { + Assert.Fail(ex.ToString()); + throw new InvalidOperationException(String.Empty, ex); + } + } else if (numberinfo["number"].AsString().IndexOf('-') == 0) { + Assert.AreEqual(-1, cbornumber.Sign); + } else if (numberinfo["number"].AsString().Equals("0")) { + Assert.AreEqual(0, cbornumber.Sign); + } else { + Assert.AreEqual(1, cbornumber.Sign); + } + } } [TestMethod] public void TestSimpleValue() { diff --git a/CBORTest/CBORSupplementTest.cs b/CBORTest/CBORSupplementTest.cs index b6d2692a..07ecbc30 100644 --- a/CBORTest/CBORSupplementTest.cs +++ b/CBORTest/CBORSupplementTest.cs @@ -226,46 +226,6 @@ public void TestCBORObjectArgumentValidation() { Assert.AreEqual(CBORObject.True, CBORObject.FromObject(true)); Assert.AreEqual(CBORObject.False, CBORObject.FromObject(false)); Assert.AreEqual(CBORObject.FromObject(8), CBORObject.FromObject((byte)8)); - try { - CBORObject.DecodeFromBytes(null); - Assert.Fail("Should have failed"); - } catch (ArgumentNullException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0x1e }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0xfe }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0xff }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } try { CBORObject.AddConverter(null, new FakeConverter()); Assert.Fail("Should have failed"); diff --git a/CBORTest/CBORTest.cs b/CBORTest/CBORTest.cs index d66504bf..140216b4 100644 --- a/CBORTest/CBORTest.cs +++ b/CBORTest/CBORTest.cs @@ -948,22 +948,6 @@ public void TestCBORExceptions() { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } - try { - CBORObject.DecodeFromBytes(new byte[] { }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0x1c }); - Assert.Fail("Should have failed"); - } catch (CBORException) { - } catch (Exception ex) { - Assert.Fail(ex.ToString()); - throw new InvalidOperationException(String.Empty, ex); - } try { CBORObject.NewArray().Remove(null); Assert.Fail("Should have failed"); diff --git a/CBORTest/CBORTest.csproj b/CBORTest/CBORTest.csproj index a2796dea..1cf4c202 100644 --- a/CBORTest/CBORTest.csproj +++ b/CBORTest/CBORTest.csproj @@ -62,7 +62,7 @@ Test. - + diff --git a/CBORTest/TestCommon.cs b/CBORTest/TestCommon.cs index a2639560..c08c708c 100644 --- a/CBORTest/TestCommon.cs +++ b/CBORTest/TestCommon.cs @@ -7,7 +7,6 @@ Any copyright is dedicated to the Public Domain. */ using System; using System.Globalization; -// using System.Numerics; using Microsoft.VisualStudio.TestTools.UnitTesting; using PeterO; using PeterO.Cbor; diff --git a/CBORTest/mstest2nunit.rb b/CBORTest/mstest2nunit.rb index f2021241..0e3a586c 100644 --- a/CBORTest/mstest2nunit.rb +++ b/CBORTest/mstest2nunit.rb @@ -56,7 +56,7 @@ def utf8edit(file,createIfNotFound=false) end ################## - +Dir.chdir(File.dirname(__FILE__)) Dir.glob("*.cs"){|f| utf8edit(f){|data| data=data.gsub(/\[TestMethod\]/,"[Test]") @@ -75,4 +75,4 @@ def utf8edit(file,createIfNotFound=false) " ") next data } -} \ No newline at end of file +} diff --git a/CBORTest/nunit2mstest.rb b/CBORTest/nunit2mstest.rb index 79692155..78179c1b 100644 --- a/CBORTest/nunit2mstest.rb +++ b/CBORTest/nunit2mstest.rb @@ -57,6 +57,7 @@ def utf8edit(file,createIfNotFound=false) ################## +Dir.chdir(File.dirname(__FILE__)) Dir.glob("*.cs"){|f| utf8edit(f){|data| data=data.gsub(/\[Test\]/,"[TestMethod]") diff --git a/Cbor/CBORObject.cs b/Cbor/CBORObject.cs index 34f33349..2a5032eb 100644 --- a/Cbor/CBORObject.cs +++ b/Cbor/CBORObject.cs @@ -1278,11 +1278,12 @@ internal static CBORObject GetFixedLengthObject(int firstbyte, byte[] data) { /// Generates a CBOR object from an array of CBOR-encoded bytes. /// A byte array. /// A CBOR object corresponding to the data. - /// Data is null or empty. + /// Data is empty. Note: + /// In version 2.0, this method may change to throw CBORException instead + /// if the data is empty. /// There was an error in reading /// or parsing the data. This includes cases where not all of the byte array - /// represents a CBOR object, and cases where - /// is empty. + /// represents a CBOR object. /// The parameter /// is null. public static CBORObject DecodeFromBytes(byte[] data) { @@ -1290,7 +1291,7 @@ public static CBORObject DecodeFromBytes(byte[] data) { throw new ArgumentNullException("data"); } if (data.Length == 0) { - throw new CBORException("data is empty."); + throw new ArgumentException("data is empty."); } var firstbyte = (int)(data[0] & (int)0xff); int expectedLength = valueExpectedLengths[firstbyte]; diff --git a/README.md b/README.md index 98158601..e0b31e41 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ project, add the following to the `dependencies` section in your `pom.xml` file: com.upokecenter cbor - 1.2.0 + 1.3.0 ``` @@ -260,6 +260,14 @@ The following are some clarifications to RFC 7049. Release Notes ----------- +In version 1.3: + +- Added a CompareToIgnoreTags method to CBORObject +- The BigInteger constructor in the C# version is deprecated +- Fixed bugs in converting from CBOR float and double to integers in some corner cases +- Fixed a bug where CBORObject's OutermostTag returns 0 instead of the correct -1 for untagged objects +- Fixed a bug where BigInteger's bitLength return value can be wrong in some corner cases + In version 1.2: - The WriteJSON and WriteToJSON methods were added to CBORObject diff --git a/docs/PeterO.Cbor.CBORObject.md b/docs/PeterO.Cbor.CBORObject.md index c74ea59c..765a9c18 100644 --- a/docs/PeterO.Cbor.CBORObject.md +++ b/docs/PeterO.Cbor.CBORObject.md @@ -324,11 +324,10 @@ A CBOR object corresponding to the data. Exceptions: * System.ArgumentException: -Data is null or empty. +Data is empty. Note: In version 2.0, this method may change to throw CBORException instead if the data is empty. * PeterO.Cbor.CBORException: -There was an error in reading or parsing the data. This includes cases where not all of the byte array represents a CBOR object, and cases where data -is empty. +There was an error in reading or parsing the data. This includes cases where not all of the byte array represents a CBOR object. * System.ArgumentNullException: The parameter data @@ -1869,7 +1868,7 @@ A CBOR object where each key and value of the given map is converted to a CBOR o public static PeterO.Cbor.CBORObject FromObject( object obj); -Generates a CBORObject from an arbitrary object. The following types are specially handled by this method: `null` , primitive types, strings, `CBORObject` , `ExtendedDecimal` , `ExtendedFloat` , the custom `BigInteger` , lists, arrays, enumerations ( `Enum` objects), and maps. +Generates a CBORObject from an arbitrary object. The following types are specially handled by this method: `null` , primitive types, strings, `CBORObject` , `ExtendedDecimal` , `ExtendedFloat` , the custom `BigInteger` , lists, arrays, enumerations ( `Enum` objects), and maps. In the .NET version, if the object is a type not specially handled by this method, returns a CBOR map with the values of each of its read/write properties (or all properties in the case of an anonymous type). Properties are converted to their camel-case names (meaning if a name starts with A to Z, that letter is lower-cased). If the property name begins with the word "Is", that word is deleted from the name. Also, .NET `Enum` objects will be converted to their integer values, and a multidimensional array is converted to an array of arrays. The .NET value DBNull.Value is converted to CBORObject.Undefined. diff --git a/src/main/java/com/upokecenter/cbor/CBORObject.java b/src/main/java/com/upokecenter/cbor/CBORObject.java index de39669e..45818e2d 100644 --- a/src/main/java/com/upokecenter/cbor/CBORObject.java +++ b/src/main/java/com/upokecenter/cbor/CBORObject.java @@ -1229,10 +1229,12 @@ static CBORObject GetFixedLengthObject(int firstbyte, byte[] data) { * Generates a CBOR object from an array of CBOR-encoded bytes. * @param data A byte array. * @return A CBOR object corresponding to the data. - * @throws java.lang.IllegalArgumentException Data is null or empty. + * @throws java.lang.IllegalArgumentException Data is empty. Note: In version + * 2.0, this method may change to throw CBORException instead if the + * data is empty. * @throws CBORException There was an error in reading or parsing the * data. This includes cases where not all of the byte array represents - * a CBOR object, and cases where {@code data} is empty. + * a CBOR object. * @throws java.lang.NullPointerException The parameter {@code data} * is null. */ @@ -1241,7 +1243,7 @@ public static CBORObject DecodeFromBytes(byte[] data) { throw new NullPointerException("data"); } if (data.length == 0) { - throw new CBORException("data is empty."); + throw new IllegalArgumentException("data is empty."); } int firstbyte = (int)(data[0] & (int)0xff); int expectedLength = valueExpectedLengths[firstbyte]; @@ -1491,7 +1493,6 @@ public CBORObject get(int index) { /** * Sets the value of a CBOR object by integer index in this array. * @param index Zero-based index of the element. - * @return A CBORObject object. * @throws java.lang.IllegalStateException This object is not an * array. * @throws java.lang.NullPointerException The parameter "value" is @@ -1567,7 +1568,6 @@ public CBORObject get(CBORObject key) { * Sets the value of a CBOR object in this map, using a CBOR object as the * key. * @param key A CBORObject object. (2). - * @return A CBORObject object. * @throws java.lang.NullPointerException The key is null (as opposed * to CBORObject.Null); or the set method is called and the value is null. * @throws java.lang.IllegalStateException This object is not a map. @@ -1605,7 +1605,6 @@ public CBORObject get(String key) { /** * Sets the value of a CBOR object in this map, using a string as the key. * @param key A key that points to the desired value. - * @return A CBORObject object. * @throws java.lang.NullPointerException The key is null. * @throws java.lang.IllegalStateException This object is not a map. */ diff --git a/src/test/java/com/upokecenter/test/CBORObjectTest.java b/src/test/java/com/upokecenter/test/CBORObjectTest.java index 285c4f17..8439d1c1 100644 --- a/src/test/java/com/upokecenter/test/CBORObjectTest.java +++ b/src/test/java/com/upokecenter/test/CBORObjectTest.java @@ -168,7 +168,7 @@ public void TestAsByte() { CBORObject numberinfo = numbers.get(i); CBORObject cbornumber = CBORObject.FromObject(ExtendedDecimal.FromString(numberinfo.get("number").AsString())); if (numberinfo.get("byte").AsBoolean()) { - Assert.assertEquals(BigInteger.fromString(numberinfo.get("integer").AsString()).intValue(), ((int)cbornumber.AsByte()) &0xff); + Assert.assertEquals(BigInteger.fromString(numberinfo.get("integer").AsString()).intValue(), ((int)cbornumber.AsByte()) & 0xff); } else { try { cbornumber.AsByte(); @@ -775,9 +775,61 @@ public void TestCount() { Assert.assertEquals(0, CBORObject.NewArray().size()); Assert.assertEquals(0, CBORObject.NewMap().size()); } + + // TODO: For 2.0 + public static void TestDecodeFromBytesVersion2Dot0() { + try { + CBORObject.DecodeFromBytes(new byte[] { }); + Assert.fail("Should have failed"); + } catch (CBORException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + } + @Test public void TestDecodeFromBytes() { - // not implemented yet + try { + CBORObject.DecodeFromBytes(new byte[] { 0x1c }); + Assert.fail("Should have failed"); + } catch (CBORException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + try { + CBORObject.DecodeFromBytes(null); + Assert.fail("Should have failed"); + } catch (NullPointerException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { 0x1e }); + Assert.fail("Should have failed"); + } catch (CBORException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { (byte)0xfe }); + Assert.fail("Should have failed"); + } catch (CBORException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + try { + CBORObject.DecodeFromBytes(new byte[] { (byte)0xff }); + Assert.fail("Should have failed"); + } catch (CBORException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } } @Test public void TestDivide() { @@ -1193,7 +1245,9 @@ public void TestFromJSONString() { } @Test public void TestFromObject() { - CBORObject[] cborarray = { CBORObject.False, CBORObject.True}; + CBORObject[] cborarray = new CBORObject[2]; + cborarray[0] = CBORObject.False; + cborarray[1] = CBORObject.True; CBORObject cbor = CBORObject.FromObject(cborarray); Assert.assertEquals(2, cbor.size()); Assert.assertEquals(CBORObject.False, cbor.get(0)); @@ -1555,7 +1609,6 @@ public void TestSet() { } @Test public void TestSign() { - // TODO: Use number database try { int sign = CBORObject.True.signum(); Assert.fail("Should have failed"); @@ -1588,6 +1641,27 @@ public void TestSign() { Assert.fail(ex.toString()); throw new IllegalStateException("", ex); } + CBORObject numbers = GetNumberData(); + for (int i = 0; i < numbers.size(); ++i) { + CBORObject numberinfo = numbers.get(i); + CBORObject cbornumber = CBORObject.FromObject(ExtendedDecimal.FromString(numberinfo.get("number").AsString())); + if (cbornumber.IsNaN()) { + try { + Assert.fail("" + cbornumber.signum()); + Assert.fail("Should have failed"); + } catch (IllegalStateException ex) { + } catch (Exception ex) { + Assert.fail(ex.toString()); + throw new IllegalStateException("", ex); + } + } else if (numberinfo.get("number").AsString().indexOf('-') == 0) { + Assert.assertEquals(-1, cbornumber.signum()); + } else if (numberinfo.get("number").AsString().equals("0")) { + Assert.assertEquals(0, cbornumber.signum()); + } else { + Assert.assertEquals(1, cbornumber.signum()); + } + } } @Test public void TestSimpleValue() { diff --git a/src/test/java/com/upokecenter/test/CBORSupplementTest.java b/src/test/java/com/upokecenter/test/CBORSupplementTest.java index 5b5ca303..b9517e9f 100644 --- a/src/test/java/com/upokecenter/test/CBORSupplementTest.java +++ b/src/test/java/com/upokecenter/test/CBORSupplementTest.java @@ -226,46 +226,6 @@ public void TestCBORObjectArgumentValidation() { Assert.assertEquals(CBORObject.True, CBORObject.FromObject(true)); Assert.assertEquals(CBORObject.False, CBORObject.FromObject(false)); Assert.assertEquals(CBORObject.FromObject(8), CBORObject.FromObject((byte)8)); - try { - CBORObject.DecodeFromBytes(null); - Assert.fail("Should have failed"); - } catch (NullPointerException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0x1e }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { (byte)0xfe }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { (byte)0xff }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } try { CBORObject.AddConverter(null, new FakeConverter()); Assert.fail("Should have failed"); diff --git a/src/test/java/com/upokecenter/test/CBORTest.java b/src/test/java/com/upokecenter/test/CBORTest.java index f16cf04b..7d73f5d7 100644 --- a/src/test/java/com/upokecenter/test/CBORTest.java +++ b/src/test/java/com/upokecenter/test/CBORTest.java @@ -929,22 +929,6 @@ public void TestCBORExceptions() { Assert.fail(ex.toString()); throw new IllegalStateException("", ex); } - try { - CBORObject.DecodeFromBytes(new byte[] { }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } - try { - CBORObject.DecodeFromBytes(new byte[] { 0x1c }); - Assert.fail("Should have failed"); - } catch (CBORException ex) { - } catch (Exception ex) { - Assert.fail(ex.toString()); - throw new IllegalStateException("", ex); - } try { CBORObject.NewArray().Remove(null); Assert.fail("Should have failed"); diff --git a/src/test/java/com/upokecenter/test/TestCommon.java b/src/test/java/com/upokecenter/test/TestCommon.java index 5677dce2..00ee3731 100644 --- a/src/test/java/com/upokecenter/test/TestCommon.java +++ b/src/test/java/com/upokecenter/test/TestCommon.java @@ -7,7 +7,6 @@ at: http://upokecenter.com/d/ */ -// import java.math.*; import org.junit.Assert; import com.upokecenter.util.*;