mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 17:22:21 +00:00
Fix verification for C# unions (#7970)
* Fix verification for unions * Run scripts\generate_code.py --------- Co-authored-by: Michael Le <michael.le647@gmail.com>
This commit is contained in:
@@ -99,6 +99,26 @@ namespace Google.FlatBuffers.Test
|
||||
}
|
||||
}
|
||||
|
||||
public static void ArrayEqual<T>(ArraySegment<T> expected, T[] actual)
|
||||
{
|
||||
#if NETCOREAPP
|
||||
ArrayEqual(expected.ToArray(), actual);
|
||||
#else
|
||||
if (expected.Count != actual.Length)
|
||||
{
|
||||
throw new AssertFailedException(expected, actual);
|
||||
}
|
||||
|
||||
for (var i = 0; i < expected.Count; ++i)
|
||||
{
|
||||
if (!expected.Array[expected.Offset + i].Equals(actual[i]))
|
||||
{
|
||||
throw new AssertArrayFailedException(i, expected, actual);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void IsTrue(bool value)
|
||||
{
|
||||
if (!value)
|
||||
|
||||
@@ -422,7 +422,7 @@ namespace Google.FlatBuffers.Test
|
||||
|
||||
// Get the full array back out and ensure they are equivalent
|
||||
var bbArray = uut.ToArray<T>(nOffset, data.Count);
|
||||
Assert.ArrayEqual(data.ToArray(), bbArray);
|
||||
Assert.ArrayEqual(data, bbArray);
|
||||
}
|
||||
|
||||
public unsafe void ByteBuffer_Put_IntPtr_Helper<T>(T[] data, int typeSize)
|
||||
@@ -643,7 +643,7 @@ namespace Google.FlatBuffers.Test
|
||||
float[] data = null;
|
||||
Assert.Throws<ArgumentNullException>(() => uut.Put(1024, data));
|
||||
|
||||
ArraySegment<float> dataArraySegment = default;
|
||||
ArraySegment<float> dataArraySegment = default(ArraySegment<float>);
|
||||
Assert.Throws<ArgumentNullException>(() => uut.Put(1024, dataArraySegment));
|
||||
|
||||
IntPtr dataPtr = IntPtr.Zero;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Google.FlatBuffers.Test
|
||||
{
|
||||
@@ -586,12 +587,14 @@ namespace Google.FlatBuffers.Test
|
||||
[FlatBuffersTestMethod]
|
||||
public void FlatBufferBuilder_Add_ArraySegment_Default_Throws()
|
||||
{
|
||||
var fbb = CreateBuffer(false);
|
||||
#if NETCOREAPP
|
||||
var fbb = CreateBuffer(false);
|
||||
|
||||
// Construct the data array
|
||||
ArraySegment<float> data = default;
|
||||
ArraySegment<float> data = default(ArraySegment<float>);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => fbb.Add(data));
|
||||
#endif
|
||||
}
|
||||
|
||||
[FlatBuffersTestMethod]
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<Compile Include="..\..\net\FlatBuffers\FlatBufferConstants.cs">
|
||||
<Link>FlatBuffers\FlatBufferConstants.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\FlatBufferVerify.cs">
|
||||
<Link>FlatBuffers\FlatBufferVerify.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\net\FlatBuffers\Struct.cs">
|
||||
<Link>FlatBuffers\Struct.cs</Link>
|
||||
</Compile>
|
||||
@@ -120,6 +123,9 @@
|
||||
<Compile Include="..\MyGame\Example\ArrayStruct.cs">
|
||||
<Link>MyGame\Example\ArrayStruct.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\LongEnum.cs">
|
||||
<Link>MyGame\Example\LongEnum.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MyGame\Example\NestedStruct.cs">
|
||||
<Link>MyGame\Example\NestedStruct.cs</Link>
|
||||
</Compile>
|
||||
@@ -220,4 +226,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user