From ebdda7cd44d9c2d8d81edb8775502425bcf2110d Mon Sep 17 00:00:00 2001 From: Peter O Date: Mon, 7 Dec 2020 16:46:48 -0500 Subject: [PATCH] Version 4.3.0 --- .github/workflows/Test.yml | 2 +- CBOR.nuspec | 14 +- CBOR/CBOR.csproj | 1 + CBOR/PeterO/Cbor/CBORDateConverter.cs | 12 +- CBOR/PeterO/Cbor/PropertyMap.cs | 2 +- CBOR20/Properties/AssemblyInfo.cs | 8 +- CBOR40/Properties/AssemblyInfo.cs | 8 +- CBORTest/CBORObjectTest.cs | 431 +++++++++++++------------- CBORTest/CBORPlistWriter.cs | 6 +- CBORTest/CBORTest.cs | 2 +- CBORTest/CBORTest.csproj | 2 +- 11 files changed, 254 insertions(+), 234 deletions(-) diff --git a/.github/workflows/Test.yml b/.github/workflows/Test.yml index d5dbc70c..8852100e 100644 --- a/.github/workflows/Test.yml +++ b/.github/workflows/Test.yml @@ -17,7 +17,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: '3.1.301' + dotnet-version: '2.2.402' - name: Test run: | dotnet add CBORTest package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything diff --git a/CBOR.nuspec b/CBOR.nuspec index 3b81d25d..ad5bf090 100644 --- a/CBOR.nuspec +++ b/CBOR.nuspec @@ -1,10 +1,8 @@ 4.2.0PeterO.CborfalseVersion 4.2: +>4.3.0PeterO.CborfalseVersion 4.3: -- Some arithmetic methods in CBORNumber do basic overflow checks. -- Add char array and byte array overloads to ParseJSONNumber -- Support implementations of IList in CBORObject deserialization -- Internally, the code avoids storing doubles (64-bit floating-point numbers) directly in CBORNumbers, uses sorted maps rather than hash tables in some CBOR objects, and can now store text strings as UTF-8 byte arrays. This could help avoid unnecessary string conversions in many case. -- Bug fixes and performance improvements -- Now uses Numbers library version 1.7.3CC0-1.0https://github.com/peteroupc/CBORPeter OccilA C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 7049.Peter OccilCBOR (Concise Binary Object Representation)cbor data serialization binary json +- Fixed bugs in DateTime support +- Added CompareTo overloads in CBORNumber class +- Add NewOrderedMap method based on a suggestion by a GitHub user +- Other bug fixesCC0-1.0https://github.com/peteroupc/CBORPeter OccilA C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.Peter OccilCBOR (Concise Binary Object Representation)cbor data serialization binary json \ No newline at end of file diff --git a/CBOR/CBOR.csproj b/CBOR/CBOR.csproj index daacaa29..d5c07fee 100644 --- a/CBOR/CBOR.csproj +++ b/CBOR/CBOR.csproj @@ -18,6 +18,7 @@ Version 4.3: - Fixed bugs in DateTime support - Added CompareTo overloads in CBORNumber class - Add NewOrderedMap method based on a suggestion by a GitHub user +- Other bug fixes cbor data serialization binary json diff --git a/CBOR/PeterO/Cbor/CBORDateConverter.cs b/CBOR/PeterO/Cbor/CBORDateConverter.cs index fd3df3f4..63ad3ff9 100644 --- a/CBOR/PeterO/Cbor/CBORDateConverter.cs +++ b/CBOR/PeterO/Cbor/CBORDateConverter.cs @@ -13,10 +13,14 @@ licensed under Creative Commons Zero (CC0): namespace PeterO.Cbor { internal class CBORDateConverter : ICBORToFromConverter { private static string DateTimeToString(DateTime bi) { - var lesserFields = new int[7]; - var year = new EInteger[1]; - PropertyMap.BreakDownDateTime(bi, year, lesserFields); - return CBORUtilities.ToAtomDateTimeString(year[0], lesserFields); + try { + var lesserFields = new int[7]; + var year = new EInteger[1]; + PropertyMap.BreakDownDateTime(bi, year, lesserFields); + return CBORUtilities.ToAtomDateTimeString(year[0], lesserFields); + } catch (ArgumentException ex) { + throw new CBORException(ex.Message, ex); + } } public DateTime FromCBORObject(CBORObject obj) { diff --git a/CBOR/PeterO/Cbor/PropertyMap.cs b/CBOR/PeterO/Cbor/PropertyMap.cs index ebcfd111..e740572a 100644 --- a/CBOR/PeterO/Cbor/PropertyMap.cs +++ b/CBOR/PeterO/Cbor/PropertyMap.cs @@ -149,11 +149,11 @@ public int GetHashCode(TKey a) { return ret; } } - */ private string CS(TKey k) { return String.Empty; } + */ [System.Diagnostics.Conditional("DEBUG")] private void CheckKeyExists(TKey key) { diff --git a/CBOR20/Properties/AssemblyInfo.cs b/CBOR20/Properties/AssemblyInfo.cs index b3aea676..f9df576b 100644 --- a/CBOR20/Properties/AssemblyInfo.cs +++ b/CBOR20/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ using System.Reflection; [assembly: System.CLSCompliant(true)] -[assembly: AssemblyInformationalVersion("4.2.0")] -[assembly: AssemblyVersion("4.2.0.0")] -[assembly: AssemblyFileVersion("4.2.0.0")] +[assembly: AssemblyInformationalVersion("4.3.0")] +[assembly: AssemblyVersion("4.3.0.0")] +[assembly: AssemblyFileVersion("4.3.0.0")] [assembly: AssemblyProduct("CBOR (Concise Binary Object Representati" + "on)")] [assembly: AssemblyTitle("CBOR (Concise Binary Object Representati" + @@ -10,6 +10,6 @@ [assembly: AssemblyDescription("A C# implementation of Concise Binary Ob" + "ject Representation (CBOR), a general-pu" + "rpose binary data format defined in RFC " + -"7049.")] +"8949.")] [assembly: AssemblyCompany("Peter Occil")] [assembly: AssemblyCopyright("CC0-1.0")] diff --git a/CBOR40/Properties/AssemblyInfo.cs b/CBOR40/Properties/AssemblyInfo.cs index b3aea676..f9df576b 100644 --- a/CBOR40/Properties/AssemblyInfo.cs +++ b/CBOR40/Properties/AssemblyInfo.cs @@ -1,8 +1,8 @@ using System.Reflection; [assembly: System.CLSCompliant(true)] -[assembly: AssemblyInformationalVersion("4.2.0")] -[assembly: AssemblyVersion("4.2.0.0")] -[assembly: AssemblyFileVersion("4.2.0.0")] +[assembly: AssemblyInformationalVersion("4.3.0")] +[assembly: AssemblyVersion("4.3.0.0")] +[assembly: AssemblyFileVersion("4.3.0.0")] [assembly: AssemblyProduct("CBOR (Concise Binary Object Representati" + "on)")] [assembly: AssemblyTitle("CBOR (Concise Binary Object Representati" + @@ -10,6 +10,6 @@ [assembly: AssemblyDescription("A C# implementation of Concise Binary Ob" + "ject Representation (CBOR), a general-pu" + "rpose binary data format defined in RFC " + -"7049.")] +"8949.")] [assembly: AssemblyCompany("Peter Occil")] [assembly: AssemblyCopyright("CC0-1.0")] diff --git a/CBORTest/CBORObjectTest.cs b/CBORTest/CBORObjectTest.cs index 55ea92d1..b6db079b 100644 --- a/CBORTest/CBORObjectTest.cs +++ b/CBORTest/CBORObjectTest.cs @@ -2041,15 +2041,15 @@ public void TestReadSequence() { public void TestEncodeToBytes() { // Test minimum data length int[] ranges = { - -24, 23, 1, - -256, -25, 2, - 24, 255, 2, - 256, 266, 3, - -266, -257, 3, - 65525, 65535, 3, - -65536, -65525, 3, - 65536, 65546, 5, - -65547, -65537, 5, + -24, 23, 1, + -256, -25, 2, + 24, 255, 2, + 256, 266, 3, + -266, -257, 3, + 65525, 65535, 3, + -65536, -65525, 3, + 65536, 65546, 5, + -65547, -65537, 5, }; string[] bigRanges = { "4294967285", "4294967295", @@ -4036,9 +4036,9 @@ public void TestReadJSON() { } } using (var ms = new MemoryStream(new byte[] { - 0xef, 0xbb, 0xbf, - 0x7b, 0x7d, - })) { + 0xef, 0xbb, 0xbf, + 0x7b, 0x7d, + })) { try { CBORObject.ReadJSON(ms); } catch (Exception ex) { @@ -4048,9 +4048,9 @@ public void TestReadJSON() { } // whitespace followed by BOM using (var ms2 = new MemoryStream(new byte[] { - 0x20, 0xef, 0xbb, - 0xbf, 0x7b, 0x7d, - })) { + 0x20, 0xef, 0xbb, + 0xbf, 0x7b, 0x7d, + })) { try { CBORObject.ReadJSON(ms2); Assert.Fail("Should have failed"); @@ -4085,9 +4085,9 @@ public void TestReadJSON() { } // two BOMs using (var ms3 = new MemoryStream(new byte[] { - 0xef, 0xbb, 0xbf, - 0xef, 0xbb, 0xbf, 0x7b, 0x7d, - })) { + 0xef, 0xbb, 0xbf, + 0xef, 0xbb, 0xbf, 0x7b, 0x7d, + })) { try { CBORObject.ReadJSON(ms3); Assert.Fail("Should have failed"); @@ -4099,82 +4099,82 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0xfe, 0xff, 0, - 0, - 0, - 0x74, 0, 0, 0, 0x72, 0, 0, 0, 0x75, 0, 0, 0, - 0x65, - })) { + 0, 0, 0xfe, 0xff, 0, + 0, + 0, + 0x74, 0, 0, 0, 0x72, 0, 0, 0, 0x75, 0, 0, 0, + 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0, 0x74, 0, 0, - 0, 0x72, 0, - 0, 0, 0x75, 0, 0, 0, 0x65, - })) { + 0, 0, 0, 0x74, 0, 0, + 0, 0x72, 0, + 0, 0, 0x75, 0, 0, 0, 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0, 0, - 0x74, 0, 0, 0, - 0x72, 0, 0, 0, 0x75, 0, 0, 0, 0x65, 0, 0, 0, - })) { + 0xff, 0xfe, 0, 0, + 0x74, 0, 0, 0, + 0x72, 0, 0, 0, 0x75, 0, 0, 0, 0x65, 0, 0, 0, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0x74, 0, 0, 0, 0x72, - 0, - 0, - 0, - 0x75, 0, 0, 0, 0x65, 0, 0, 0, - })) { + 0x74, 0, 0, 0, 0x72, + 0, + 0, + 0, + 0x75, 0, 0, 0, 0x65, 0, 0, 0, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0, 0x74, - 0, 0x72, 0, - 0x75, 0, 0x65, - })) { + 0xfe, 0xff, 0, 0x74, + 0, 0x72, 0, + 0x75, 0, 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0, 0x74, 0, 0x72, 0, - 0x75, 0, 0x65, - })) { + 0, 0x74, 0, 0x72, 0, + 0x75, 0, 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x74, 0, - 0x72, - 0, - 0x75, - 0, 0x65, 0, - })) { + 0xff, 0xfe, 0x74, 0, + 0x72, + 0, + 0x75, + 0, 0x65, 0, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0x74, 0, 0x72, 0, - 0x75, 0, 0x65, 0, - })) { + 0x74, 0, 0x72, 0, + 0x75, 0, 0x65, 0, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0xef, 0xbb, 0xbf, - 0x74, 0x72, 0x75, 0x65, - })) { + 0xef, 0xbb, 0xbf, + 0x74, 0x72, 0x75, 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0x74, 0x72, 0x75, - 0x65, - })) { + 0x74, 0x72, 0x75, + 0x65, + })) { Assert.AreEqual(CBORObject.True, CBORObject.ReadJSON(msjson)); } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0xfe, 0xff, 0, - 0, 0, 0x22, - 0, 1, 0, 0, 0, 0, 0, 0x22, - })) { + 0, 0, 0xfe, 0xff, 0, + 0, 0, 0x22, + 0, 1, 0, 0, 0, 0, 0, 0x22, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4183,10 +4183,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0, 0x22, 0, 1, - 0, 0, 0, 0, - 0, 0x22, - })) { + 0, 0, 0, 0x22, 0, 1, + 0, 0, 0, 0, + 0, 0x22, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4195,10 +4195,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0, 0, - 0x22, 0, 0, 0, - 0, 0, 1, 0, 0x22, 0, 0, 0, - })) { + 0xff, 0xfe, 0, 0, + 0x22, 0, 0, 0, + 0, 0, 1, 0, 0x22, 0, 0, 0, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4207,11 +4207,11 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0x22, 0, 0, 0, 0, 0, - 1, 0, 0x22, - 0, - 0, 0, - })) { + 0x22, 0, 0, 0, 0, 0, + 1, 0, 0x22, + 0, + 0, 0, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4220,11 +4220,11 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0, - 0x22, 0xd8, - 0, - 0xdc, 0, 0, 0x22, - })) { + 0xfe, 0xff, 0, + 0x22, 0xd8, + 0, + 0xdc, 0, 0, 0x22, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4233,9 +4233,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0x22, 0xd8, 0, - 0xdc, 0, 0, 0x22, - })) { + 0, 0x22, 0xd8, 0, + 0xdc, 0, 0, 0x22, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4244,10 +4244,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x22, 0, - 0, 0xd8, 0, - 0xdc, 0x22, 0, - })) { + 0xff, 0xfe, 0x22, 0, + 0, 0xd8, 0, + 0xdc, 0x22, 0, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4256,9 +4256,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0x22, 0, 0, 0xd8, 0, - 0xdc, 0x22, 0, - })) { + 0x22, 0, 0, 0xd8, 0, + 0xdc, 0x22, 0, + })) { { string stringTemp = CBORObject.ReadJSON(msjson).AsString(); Assert.AreEqual( @@ -4267,10 +4267,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0xfe, 0xff, 0, - 0, 0, 0x22, - 0, 0, 0xd8, 0, 0, 0, 0, 0x22, - })) { + 0, 0, 0xfe, 0xff, 0, + 0, 0, 0x22, + 0, 0, 0xd8, 0, 0, 0, 0, 0x22, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4282,11 +4282,11 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0, 0x22, 0, 0, - 0xd8, 0, 0, - 0, - 0, 0x22, - })) { + 0, 0, 0, 0x22, 0, 0, + 0xd8, 0, 0, + 0, + 0, 0x22, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4298,10 +4298,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0, 0, - 0x22, 0, 0, 0, - 0, 0xd8, 0, 0, 0x22, 0, 0, 0, - })) { + 0xff, 0xfe, 0, 0, + 0x22, 0, 0, 0, + 0, 0xd8, 0, 0, 0x22, 0, 0, 0, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4313,12 +4313,12 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0x22, 0, 0, 0, 0, - 0xd8, - 0, - 0, - 0x22, 0, 0, 0, - })) { + 0x22, 0, 0, 0, 0, + 0xd8, + 0, + 0, + 0x22, 0, 0, 0, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4330,10 +4330,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0, 0x22, - 0, 0xdc, 0, - 0xdc, 0, 0, 0x22, - })) { + 0xfe, 0xff, 0, 0x22, + 0, 0xdc, 0, + 0xdc, 0, 0, 0x22, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4345,10 +4345,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0, 0x22, 0, 0xdc, 0, - 0xdc, 0, 0, - 0x22, - })) { + 0, 0x22, 0, 0xdc, 0, + 0xdc, 0, 0, + 0x22, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4360,10 +4360,10 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x22, 0, - 0, 0xdc, 0, - 0xdc, 0x22, 0, - })) { + 0xff, 0xfe, 0x22, 0, + 0, 0xdc, 0, + 0xdc, 0x22, 0, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4375,9 +4375,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0x22, 0, 0, 0xdc, 0, - 0xdc, 0x22, 0, - })) { + 0x22, 0, 0, 0xdc, 0, + 0xdc, 0x22, 0, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4412,9 +4412,9 @@ public void TestReadJSON() { } // Illegal UTF-16 using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0x20, - 0x20, 0x20, - })) { + 0xfe, 0xff, 0x20, + 0x20, 0x20, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4426,9 +4426,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x20, - 0x20, 0x20, - })) { + 0xff, 0xfe, 0x20, + 0x20, 0x20, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4440,9 +4440,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xd8, - 0x00, - })) { + 0xfe, 0xff, 0xd8, + 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4454,9 +4454,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xdc, - 0x00, - })) { + 0xfe, 0xff, 0xdc, + 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4468,9 +4468,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xd8, - 0x00, 0x20, 0x00, - })) { + 0xfe, 0xff, 0xd8, + 0x00, 0x20, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4482,9 +4482,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xdc, - 0x00, 0x20, 0x00, - })) { + 0xfe, 0xff, 0xdc, + 0x00, 0x20, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4496,9 +4496,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xd8, - 0x00, 0xd8, 0x00, - })) { + 0xfe, 0xff, 0xd8, + 0x00, 0xd8, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4510,9 +4510,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xdc, - 0x00, 0xd8, 0x00, - })) { + 0xfe, 0xff, 0xdc, + 0x00, 0xd8, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4524,9 +4524,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xdc, - 0x00, 0xd8, 0x00, 0xdc, 0x00, - })) { + 0xfe, 0xff, 0xdc, + 0x00, 0xd8, 0x00, 0xdc, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4538,9 +4538,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xfe, 0xff, 0xdc, - 0x00, 0xdc, 0x00, - })) { + 0xfe, 0xff, 0xdc, + 0x00, 0xdc, 0x00, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4553,9 +4553,9 @@ public void TestReadJSON() { } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xd8, - })) { + 0xff, 0xfe, 0x00, + 0xd8, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4567,9 +4567,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xdc, - })) { + 0xff, 0xfe, 0x00, + 0xdc, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4581,9 +4581,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xd8, 0x00, 0x20, - })) { + 0xff, 0xfe, 0x00, + 0xd8, 0x00, 0x20, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4595,9 +4595,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xdc, 0x00, 0x20, - })) { + 0xff, 0xfe, 0x00, + 0xdc, 0x00, 0x20, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4609,9 +4609,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xd8, 0x00, 0xd8, - })) { + 0xff, 0xfe, 0x00, + 0xd8, 0x00, 0xd8, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4623,9 +4623,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xdc, 0x00, 0xd8, - })) { + 0xff, 0xfe, 0x00, + 0xdc, 0x00, 0xd8, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4637,9 +4637,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xdc, 0x00, 0xd8, 0x00, 0xdc, - })) { + 0xff, 0xfe, 0x00, + 0xdc, 0x00, 0xd8, 0x00, 0xdc, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4651,9 +4651,9 @@ public void TestReadJSON() { } } using (var msjson = new MemoryStream(new byte[] { - 0xff, 0xfe, 0x00, - 0xdc, 0x00, 0xdc, - })) { + 0xff, 0xfe, 0x00, + 0xdc, 0x00, 0xdc, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -4667,8 +4667,8 @@ public void TestReadJSON() { // Illegal UTF-32 using (var msjson = new MemoryStream(new byte[] { - 0, 0, 0, 0x20, 0, - })) { + 0, 0, 0, 0x20, 0, + })) { try { CBORObject.ReadJSON(msjson); Assert.Fail("Should have failed"); @@ -5027,8 +5027,12 @@ public void TestCalcEncodedSizeCircularRefs3bc() { throw new InvalidOperationException(String.Empty, ex); } cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - cbor.Add(CBORObject.NewOrderedMap().Add(cbor, "jkl").Add("mno", - 1),"test"); + { + object objectTemp = CBORObject.NewOrderedMap().Add(cbor, "jkl").Add("mno", + 1); + object objectTemp2 = "test"; + cbor.Add(objectTemp, objectTemp2); + } try { cbor.CalcEncodedSize(); Assert.Fail("Should have failed"); @@ -5039,8 +5043,12 @@ public void TestCalcEncodedSizeCircularRefs3bc() { throw new InvalidOperationException(String.Empty, ex); } cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - cbor.Add("test", CBORObject.NewOrderedMap().Add(cbor, - "jkl").Add("mno",1)); + { + object objectTemp = "test"; + object objectTemp2 = CBORObject.NewOrderedMap().Add(cbor, + "jkl").Add("mno", 1); + cbor.Add(objectTemp, objectTemp2); + } try { cbor.CalcEncodedSize(); Assert.Fail("Should have failed"); @@ -5051,8 +5059,12 @@ public void TestCalcEncodedSizeCircularRefs3bc() { throw new InvalidOperationException(String.Empty, ex); } cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - cbor.Add("test", CBORObject.NewOrderedMap().Add("mno", - 1).Add(cbor,"jkl")); + { + object objectTemp = "test"; + object objectTemp2 = CBORObject.NewOrderedMap().Add("mno", + 1).Add(cbor, "jkl"); + cbor.Add(objectTemp, objectTemp2); + } try { cbor.CalcEncodedSize(); Assert.Fail("Should have failed"); @@ -5063,8 +5075,12 @@ public void TestCalcEncodedSizeCircularRefs3bc() { throw new InvalidOperationException(String.Empty, ex); } cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - cbor.Add(CBORObject.NewOrderedMap().Add("mno", 1).Add(cbor, - "jkl"),"test"); + { + object objectTemp = CBORObject.NewOrderedMap().Add("mno", 1).Add(cbor, + "jkl"); + object objectTemp2 = "test"; + cbor.Add(objectTemp, objectTemp2); + } try { cbor.CalcEncodedSize(); Assert.Fail("Should have failed"); @@ -5085,45 +5101,44 @@ public void TestCalcEncodedSizeCircularRefs3bc() { cbor.Add("test", CBORObject.NewOrderedMap()); Assert.IsTrue(cbor.CalcEncodedSize() > 2); cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - { object objectTemp = CBORObject.NewOrderedMap().Add("jkl", - CBORObject.NewOrderedMap()); -object objectTemp2 = "test"; -cbor.Add(objectTemp, objectTemp2); -} + CBORObject.NewOrderedMap()); + object objectTemp2 = "test"; + cbor.Add(objectTemp, objectTemp2); + } Assert.IsTrue(cbor.CalcEncodedSize() > 2); cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); { object objectTemp = "test"; object objectTemp2 = CBORObject.NewOrderedMap().Add("jkl", - CBORObject.NewOrderedMap()); + CBORObject.NewOrderedMap()); cbor.Add(objectTemp, objectTemp2); -} + } Assert.IsTrue(cbor.CalcEncodedSize() > 2); cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); - { - object objectTemp = CBORObject.NewOrderedMap().Add(CBORObject.NewOrderedMap(), - "jkl"); -object objectTemp2 = "test"; -cbor.Add(objectTemp, objectTemp2); -} + object objectTemp = + CBORObject.NewOrderedMap().Add(CBORObject.NewOrderedMap(), + "jkl"); + object objectTemp2 = "test"; + cbor.Add(objectTemp, objectTemp2); + } Assert.IsTrue(cbor.CalcEncodedSize() > 2); cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); { object objectTemp = "test"; object objectTemp2 = CBORObject.NewOrderedMap() .Add(CBORObject.NewOrderedMap(), - "jkl"); + "jkl"); cbor.Add(objectTemp, objectTemp2); -} + } Assert.IsTrue(cbor.CalcEncodedSize() > 2); cbor = CBORObject.NewOrderedMap().Add("ghi", 2).Add("abc", 4); { CBORObject.NewOrderedMap().Add(CBORObject.NewOrderedMap(), - "jkl").Add("mno", - 1); + "jkl").Add("mno", + 1); object objectTemp2 = "test"; cbor.Add("test", objectTemp2); } @@ -5132,7 +5147,7 @@ public void TestCalcEncodedSizeCircularRefs3bc() { { object objectTemp2 = CBORObject.NewOrderedMap().Add(CBORObject.NewOrderedMap(), - "jkl").Add("mno", + "jkl").Add("mno", 1); cbor.Add("test", objectTemp2); } diff --git a/CBORTest/CBORPlistWriter.cs b/CBORTest/CBORPlistWriter.cs index 2d58e476..c000e39a 100644 --- a/CBORTest/CBORPlistWriter.cs +++ b/CBORTest/CBORPlistWriter.cs @@ -65,8 +65,10 @@ internal static void WritePlistStringUnquoted( internal static string ToPlistString(CBORObject obj) { var builder = new StringBuilder(); try { - WritePlistToInternal(obj, new StringOutput(builder), - JSONOptions.Default); + WritePlistToInternal( + obj, + new StringOutput(builder), + JSONOptions.Default); return builder.ToString(); } catch (IOException ex) { throw new CBORException(ex.Message, ex); diff --git a/CBORTest/CBORTest.cs b/CBORTest/CBORTest.cs index e68e4fc4..dbab92a1 100644 --- a/CBORTest/CBORTest.cs +++ b/CBORTest/CBORTest.cs @@ -2342,7 +2342,7 @@ public void TestRandomSlightlyModified() { for (var i = 0; i < 2000; ++i) { CBORObject originalObject = CBORTestCommon.RandomCBORObject(rand); byte[] array = originalObject.EncodeToBytes(); - Console.WriteLine("i=" + i + " obj=" + array.Length); + // Console.WriteLine("i=" + i + " obj=" + array.Length); TestRandomOne(SlightlyModify(array, rand)); } } diff --git a/CBORTest/CBORTest.csproj b/CBORTest/CBORTest.csproj index f417e1a6..ccf3cd87 100644 --- a/CBORTest/CBORTest.csproj +++ b/CBORTest/CBORTest.csproj @@ -1,6 +1,6 @@ - netcoreapp3.1 + netcoreapp2.2 false