[mapguide-commits] r9784 - in sandbox/jng/vanilla_swig/Bindings: . src/Test/DotNet/src/TestMapGuideApi src/Test/DotNet/src/TestMapGuideApi/ExternalTests src/Test/DotNet/src/TestMisc src/Test/DotNet/src/TestRunner
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Sat Nov 14 06:13:44 PST 2020
Author: jng
Date: 2020-11-14 06:13:44 -0800 (Sat, 14 Nov 2020)
New Revision: 9784
Added:
sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/ExternalTests/ByteReaderReadByChunksTest.cs
Modified:
sandbox/jng/vanilla_swig/Bindings/TODO.txt
sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/TestMapGuideApi.csproj
sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMisc/
sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestRunner/
Log:
Add byte reader piecemeal test
Modified: sandbox/jng/vanilla_swig/Bindings/TODO.txt
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/TODO.txt 2020-11-14 13:37:21 UTC (rev 9783)
+++ sandbox/jng/vanilla_swig/Bindings/TODO.txt 2020-11-14 14:13:44 UTC (rev 9784)
@@ -5,6 +5,7 @@
- [ ] Fix up inconsistent stack direction in C# exceptions (C++ call stack are printed downwards, C# call stack is printed upwards)
- [x] Check in test case admin tool
- [x] Consolidate Tools.sln into Bindings.sln
+ - [ ] Relocate/remove existing test code
- Split .net binding into the Foundation/Geometry/PlatformBase/MapGuideCommon/Web layout (https://github.com/jumpinjackie/mapguide-api-bindings/issues/18)
- [ ] Add CentOS 6 Dockerfile that
- Install SWIG and common libs tarball (from docker build system)
@@ -12,7 +13,7 @@
- Generate and build the .net/Java SWIG glue libraries
- Copy the compiled libs out of the docker container and into the same native library staging area for Java/.net
- [x] Refactor current .net test suite to reference these nuget packages
- - [ ] Verify test suite still passes (Windows)
+ - [x] Verify test suite still passes (Windows)
- [ ] Verify test suite still passes (Linux)
- Automatic class id generation (https://github.com/jumpinjackie/mapguide-api-bindings/issues/34)
- [ ] Add SWIG preprocessor that controls whether the class id header should be included
Added: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/ExternalTests/ByteReaderReadByChunksTest.cs
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/ExternalTests/ByteReaderReadByChunksTest.cs (rev 0)
+++ sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/ExternalTests/ByteReaderReadByChunksTest.cs 2020-11-14 14:13:44 UTC (rev 9784)
@@ -0,0 +1,92 @@
+using OSGeo.MapGuide;
+using OSGeo.MapGuide.Test.Common;
+using System;
+using System.Buffers;
+
+namespace TestMapGuideApi.ExternalTests
+{
+ public class ByteReaderReadByChunksTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ string testString = "abcd1234";
+ (int testLength, int expectedIterations, int expectedLastRead)[] testLengths = new[]
+ {
+ // 2 read size, 4 expected iterations, 2 bytes expected to be read on last iteration
+ (2, 4, 2),
+ (3, 3, 2),
+ (4, 2, 4),
+ };
+ foreach (var (testLength, expectedIterations, expectedLastRead) in testLengths)
+ {
+ var bytes = System.Text.Encoding.UTF8.GetBytes(testString);
+ var bs = new MgByteSource(bytes, bytes.Length);
+ var content = "";
+ var br = bs.GetReader();
+ byte[] buffer = new byte[testLength];
+ int read = br.Read(buffer, testLength);
+ int iterations = 0;
+ while (read > 0)
+ {
+ var sbuf = System.Text.Encoding.UTF8.GetString(buffer);
+ var expectedSubStr = testString.Substring(content.Length, read);
+ //Console.WriteLine("Buffer: " + sbuf);
+ Assert.Equals(expectedSubStr, sbuf);
+ content += sbuf;
+ read = br.Read(buffer, testLength);
+ iterations++;
+ if (iterations == expectedIterations) //Is last iteration?
+ {
+ Assert.Equals(expectedLastRead, read);
+ }
+ }
+
+ Assert.Equals(expectedIterations, iterations);
+ }
+ }
+ }
+
+ // This test is same as above, but uses an ArrayPool instead of allocating a byte[] array
+ public class ByteReaderReadByChunksNoAllocTest : IExternalTest
+ {
+ public void Execute(IPlatformFactory factory, ITestLogger logger)
+ {
+ string testString = "abcd1234";
+ (int testLength, int expectedIterations, int expectedLastRead)[] testLengths = new[]
+ {
+ // 2 read size, 4 expected iterations, 2 bytes expected to be read on last iteration
+ (2, 4, 2),
+ (3, 3, 2),
+ (4, 2, 4),
+ };
+ foreach (var (testLength, expectedIterations, expectedLastRead) in testLengths)
+ {
+ var bytes = System.Text.Encoding.UTF8.GetBytes(testString);
+ var bs = new MgByteSource(bytes, bytes.Length);
+ var content = "";
+ var br = bs.GetReader();
+ var pool = ArrayPool<byte>.Shared;
+ var buffer = pool.Rent(testLength);
+ int read = br.Read(buffer, testLength);
+ int iterations = 0;
+ while (read > 0)
+ {
+ var sbuf = System.Text.Encoding.UTF8.GetString(buffer, 0, testLength);
+ var expectedSubStr = testString.Substring(content.Length, read);
+ //Console.WriteLine("Buffer: " + sbuf);
+ Assert.Equals(expectedSubStr, sbuf);
+ content += sbuf;
+ read = br.Read(buffer, testLength);
+ iterations++;
+ if (iterations == expectedIterations) //Is last iteration?
+ {
+ Assert.Equals(expectedLastRead, read);
+ }
+ }
+
+ Assert.Equals(expectedIterations, iterations);
+ pool.Return(buffer);
+ }
+ }
+ }
+}
Modified: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/TestMapGuideApi.csproj
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/TestMapGuideApi.csproj 2020-11-14 13:37:21 UTC (rev 9783)
+++ sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMapGuideApi/TestMapGuideApi.csproj 2020-11-14 14:13:44 UTC (rev 9784)
@@ -21,5 +21,6 @@
<PackageReference Include="OSGeo.MapGuide.Geometry" Version="4.0.0" />
<PackageReference Include="OSGeo.MapGuide.MapGuideCommon" Version="4.0.0" />
<PackageReference Include="OSGeo.MapGuide.Web" Version="4.0.0" />
+ <PackageReference Include="System.Buffers" Version="4.5.1" />
</ItemGroup>
</Project>
\ No newline at end of file
Index: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMisc
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMisc 2020-11-14 13:37:21 UTC (rev 9783)
+++ sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMisc 2020-11-14 14:13:44 UTC (rev 9784)
Property changes on: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestMisc
___________________________________________________________________
Modified: svn:ignore
## -1,2 +1,3 ##
obj
bin
+Resources
Index: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestRunner
===================================================================
--- sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestRunner 2020-11-14 13:37:21 UTC (rev 9783)
+++ sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestRunner 2020-11-14 14:13:44 UTC (rev 9784)
Property changes on: sandbox/jng/vanilla_swig/Bindings/src/Test/DotNet/src/TestRunner
___________________________________________________________________
Modified: svn:ignore
## -1,2 +1,3 ##
bin
obj
+Resources
More information about the mapguide-commits
mailing list