public void StructRefParameter() { var csStruct = new StructWithMarshal(); NativeFunctions.SetAllElements(ref csStruct); Assert.Equal(10, csStruct.I[0]); Assert.Equal(10, csStruct.I[1]); Assert.Equal(10, csStruct.I[2]); }
public void NullableStructParameter() { Assert.Equal(0, NativeFunctions.FirstElementOrZero(null)); var csStruct = new StructWithMarshal(); csStruct.I[0] = 4; Assert.Equal(csStruct.I[0], NativeFunctions.FirstElementOrZero(csStruct)); }
public void StructMarshalling() { var defaultMarshalling = new StructWithMarshal(); defaultMarshalling.I[1] = 6; var staticMarshalling = new StructWithStaticMarshal(); staticMarshalling.I[1] = 10; NativeFunctions.StructMarshalling(defaultMarshalling, staticMarshalling, out var defaultOut, out var staticOut); Assert.Equal(defaultMarshalling.I[1], defaultOut.I[1]); Assert.Equal(staticMarshalling.I[1], staticOut.I[1]); }
public void StructWithMarshallingArrays() { int seed = 37; var rng = new Random(seed); StructWithMarshal[] array = new StructWithMarshal[5]; for (int i = 0; i < array.Length; i++) { for (int j = 0; j < array[i].I.Length; j++) { array[i].I[j] = rng.Next(); } } int result = NativeFunctions.SumStructWithMarshal(array); Assert.Equal(array.SelectMany(x => x.I).Aggregate((x, a) => x + a), result); }