public void TestStructWithNestedUnionLongerSourceArray() { using (var val = new StructWithNestedUnion()) { byte[] bytes = Encoding.ASCII.GetBytes("TestStructWithNestedUnionLongerSourceArray"); sbyte[] sbytes = Array.ConvertAll(bytes, q => Convert.ToSByte(q)); UnionNestedInsideStruct unionNestedInsideStruct; unionNestedInsideStruct.SzText = sbytes; Assert.Throws <InvalidOperationException>(() => val.NestedUnion = unionNestedInsideStruct); } }
public void TestStructWithNestedUnionTestMethod() { using (var val = new StructWithNestedUnion()) { byte[] bytes = Encoding.ASCII.GetBytes("TestUnions"); sbyte[] sbytes = Array.ConvertAll(bytes, q => Convert.ToSByte(q)); UnionNestedInsideStruct unionNestedInsideStruct; unionNestedInsideStruct.SzText = sbytes; Assert.AreEqual(sbytes.Length, unionNestedInsideStruct.SzText.Length); Assert.AreEqual("TestUnions", unionNestedInsideStruct.SzText); val.NestedUnion = unionNestedInsideStruct; Assert.AreEqual(10, val.NestedUnion.SzText.Length); Assert.AreEqual("TestUnions", val.NestedUnion.SzText); string ret = CLI.CLI.StructWithNestedUnionTestMethod(val); Assert.AreEqual("TestUnions", ret); } }