public void X() { var u = new TestUnion(3); var a = u.Map(i => i.ToString(), s => s); Assert.AreEqual("3", a); }
static void Main(string[] args) { //Console.WriteLine("Hello World!"); //ITest test = new TestAllCustomers(); //ITest test = new TestSelect(); //ITest test = new TestSingle(); //ITest test = new TestLast(); //ITest test = new TestTake(); //ITest test = new TestSkip(); //ITest test = new TestJoin(); //ITest test = new TestSelectMany(); //ITest test = new TestOrderBy(); //ITest test = new TestWhere(); //ITest test = new TestAny(); //ITest test = new TestContains(); //ITest test = new TestAll(); //ITest test = new TestDistinct();] //ITest test = new TestTarefa2(); //ITest test = new TestCountMaxMin(); //ITest test = new TestSumAverage(); //ITest test = new TestGroupBy(); ITest test = new TestUnion(); test.Test(); Console.ReadLine(); }
public void TestSimpleUnion() { TestUnion arg = new TestUnion(); short case0Val = 11; arg.Setval0(case0Val); TestUnion result = m_testService.EchoTestUnion(arg); Assert.AreEqual(case0Val, result.Getval0()); Assert.AreEqual(0, result.Discriminator); TestUnion arg2 = new TestUnion(); int case1Val = 12; arg2.Setval1(case1Val, 2); TestUnion result2 = m_testService.EchoTestUnion(arg2); Assert.AreEqual(case1Val, result2.Getval1()); Assert.AreEqual(2, result2.Discriminator); TestUnion arg3 = new TestUnion(); bool case2Val = true; arg3.Setval2(case2Val, 7); TestUnion result3 = m_testService.EchoTestUnion(arg3); Assert.AreEqual(case2Val, result3.Getval2()); Assert.AreEqual(7, result3.Discriminator); }
static void Main(string[] args) { ITest customersTest = new TestUnion(); customersTest.Test(); Console.Read(); }
public void UnionMarshalsCorrectly() { var obj = new TestUnion { Decimal = 2.0f }; Assert.Equal(obj.Integer, Functions.PassThrough(obj).Integer); }
//*********************** Сохранить float ***************************** public void WriteFloat(float fl) { TestUnion un = new TestUnion(); un.f = fl; fs.WriteByte(un.b1); fs.WriteByte(un.b2); fs.WriteByte(un.b3); fs.WriteByte(un.b4); }
//************************ Сохранить int ****************************** public void WriteInt(int num) { TestUnion un = new TestUnion(); un.i = num; fs.WriteByte(un.b1); fs.WriteByte(un.b2); fs.WriteByte(un.b3); fs.WriteByte(un.b4); }
//************************ Прочесть int ******************************* public int ReadInt() { TestUnion un = new TestUnion(); un.b1 = (byte)fs.ReadByte(); un.b2 = (byte)fs.ReadByte(); un.b3 = (byte)fs.ReadByte(); un.b4 = (byte)fs.ReadByte(); return(un.i); }
//*********************** Прочесть float ****************************** public float ReadFloat() { TestUnion un = new TestUnion(); un.b1 = (byte)fs.ReadByte(); un.b2 = (byte)fs.ReadByte(); un.b3 = (byte)fs.ReadByte(); un.b4 = (byte)fs.ReadByte(); return(un.f); }
public Form1() { InitializeComponent(); var x = new TestUnion { Number = 0xDEADBEEF }; MessageBox.Show(string.Format("{0:X} {1:X} {2:X}", x.Number, x.High, x.Low)); }
public static Offset <TestTableWithUnion> CreateTestTableWithUnion(FlatBufferBuilder builder, int IntProp = 0, TestUnion UnionProp_type = TestUnion.NONE, int UnionPropOffset = 0) { builder.StartObject(3); TestTableWithUnion.AddUnionProp(builder, UnionPropOffset); TestTableWithUnion.AddIntProp(builder, IntProp); TestTableWithUnion.AddUnionPropType(builder, UnionProp_type); return(TestTableWithUnion.EndTestTableWithUnion(builder)); }
public static void Main(string[] args) { var x = new TestUnion { Number = 0xABADF00D }; Console.WriteLine("{0:X} {1:X} {2:X}", x.Number, x.High, x.Low); x.Low = 0xFACE; Console.WriteLine("{0:X} {1:X} {2:X}", x.Number, x.High, x.Low); x.High = 0xDEAD; Console.WriteLine("{0:X} {1:X} {2:X}", x.Number, x.High, x.Low); }
public static int UnmanagedDLL(int which, ref TestUnion testUnion) { IntPtr buffer = Marshal.AllocHGlobal( Math.Max(Marshal.SizeOf(typeof(TestA)), Marshal.SizeOf(typeof(TestB))); int returnType = fnUnmanagedDLL(which, buffer); switch (returnType) { case 1: // What ever fnUnmanagedDLL returns for TestA testUnion.a = (TestA)Marshal.PtrToStructure(buffer, typeof(TestA)); break; case 2: // What ever fnUnmanagedDLL returns for TestB testUnion.a = (TestB)Marshal.PtrToStructure(buffer, typeof(TestB)); break; } Marhsal.FreeHGlobal(buffer); // Need to manually free the allocated buffer return returnType; }
public void TestPassingUnionsAsAny() { TestUnion arg = new TestUnion(); short case0Val = 11; arg.Setval0(case0Val); TestUnion result = (TestUnion)m_testService.EchoAny(arg); Assert.AreEqual(case0Val, result.Getval0()); Assert.AreEqual(0, result.Discriminator); TestUnionE arg2 = new TestUnionE(); TestEnumForU case1Val = TestEnumForU.A; arg2.SetvalE1(case1Val, TestEnumForU.B); TestUnionE result2 = (TestUnionE)m_testService.EchoAny(arg2); Assert.AreEqual(case1Val, result2.GetvalE1()); Assert.AreEqual(TestEnumForU.B, result2.Discriminator); }
public void Union_Test() { var t = new TestUnion { Data1 = new TestUnionData1() { Str = "" } }; Console.WriteLine(t.Data2.Index); var t2 = new TestUnion { Data2 = new TestUnionData2 { Index = -1 } }; Console.WriteLine(t2.Data1); }
public void SerializeAndParse_Full() { ValueStruct vs = new ValueStruct { A = 1, B = 2, C = 3, Inner = new InnerValueStruct { A = 3.14f } }; for (int i = 0; i < vs.D_Length; ++i) { vs.D(i) = (byte)i; } RefStruct rs = new() { A = 1, VS = vs, }; RootTable table = new() { refStruct = rs, union = new TestUnion(vs), valueStruct = vs, valueStructVector = Enumerable.Range(0, 10).Select(x => vs).ToList(), vectorOfUnion = Enumerable.Range(0, 10).Select(x => new TestUnion(vs)).ToList(), }; ISerializer <RootTable> serializer = RootTable.Serializer; int maxBytes = serializer.GetMaxSize(table); byte[] buffer = new byte[maxBytes]; int written = serializer.Write(buffer, table); RootTable parsed = serializer.Parse(buffer[..written]);
public void TestPassingUnionsAsAny() { TestUnion arg = new TestUnion(); short case0Val = 11; arg.Setval0(case0Val); TestUnion result = (TestUnion)m_testService.EchoAny(arg); Assertion.AssertEquals(case0Val, result.Getval0()); Assertion.AssertEquals(0, result.Discriminator); TestUnionE arg2 = new TestUnionE(); TestEnumForU case1Val = TestEnumForU.A; arg2.SetvalE1(case1Val, TestEnumForU.B); TestUnionE result2 = (TestUnionE)m_testService.EchoAny(arg2); Assertion.AssertEquals(case1Val, result2.GetvalE1()); Assertion.AssertEquals(TestEnumForU.B, result2.Discriminator); }
public TestUnion EchoUnion(TestUnion arg) { return(arg); }
public static extern void WriteUnionInt(int i, out TestUnion result);
public void TestUnionExceptions() { try { TestUnion arg = new TestUnion(); arg.Getval0(); Assert.Fail("exception not thrown for getting value from non-initalized union"); } catch (omg.org.CORBA.BAD_OPERATION) { } try { TestUnion arg = new TestUnion(); arg.Setval0(11); arg.Getval1(); Assert.Fail("exception not thrown for getting value from non-initalized union"); } catch (omg.org.CORBA.BAD_OPERATION) { } try { TestUnion arg1 = new TestUnion(); arg1.Setval1(11, 7); Assert.Fail("exception not thrown on wrong discriminator value."); } catch (omg.org.CORBA.BAD_PARAM) { } try { TestUnion arg2 = new TestUnion(); arg2.Setval2(false, 0); Assert.Fail("exception not thrown on wrong discriminator value."); } catch (omg.org.CORBA.BAD_PARAM) { } }
public void TestSimpleUnionNoExceptions() { TestUnion arg = new TestUnion(); short case0Val = 11; arg.Setval0(case0Val); TestUnion result = m_testService.EchoUnion(arg); Assert.AreEqual(case0Val, result.Getval0()); Assert.AreEqual(0, result.Discriminator); TestUnion arg2 = new TestUnion(); int case1Val = 12; arg2.Setval1(case1Val, 2); TestUnion result2 = m_testService.EchoUnion(arg2); Assert.AreEqual(case1Val, result2.Getval1()); Assert.AreEqual(2, result2.Discriminator); TestUnion arg3 = new TestUnion(); bool case2Val = true; arg3.Setval2(case2Val, 7); TestUnion result3 = m_testService.EchoUnion(arg3); Assert.AreEqual(case2Val, result3.Getval2()); Assert.AreEqual(7, result3.Discriminator); TestUnionULong arg4 = new TestUnionULong(); int case1Val2 = 13; arg4.Setval1(case1Val2); TestUnionULong result4 = m_testService.EchoUnionULong(arg4); Assert.AreEqual(case1Val2, result4.Getval1()); uint case1DiscrVal = 0x80000000; Assert.AreEqual((int)case1DiscrVal, result4.Discriminator); }
public void TestUnionNetSerializableOptimized() { // check, that the generated union is serializable also with other formatters optimized (not all fields, but only needed ones) TestUnion arg = new TestUnion(); int case1Val = 12; arg.Setval1(case1Val, 2); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.MemoryStream serialised = new System.IO.MemoryStream(); try { formatter.Serialize(serialised, arg); serialised.Seek(0, System.IO.SeekOrigin.Begin); formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); TestUnion deser = (TestUnion)formatter.Deserialize(serialised); Assert.AreEqual(2, deser.Discriminator); Assert.AreEqual(case1Val, deser.Getval1()); } finally { serialised.Close(); } }
public static Offset <TestTableWithUnionAndMoreFields> CreateTestTableWithUnionAndMoreFields(FlatBufferBuilder builder, int IntProp = 0, TestUnion UnionProp_type = TestUnion.NONE, int UnionPropOffset = 0, StringOffset StringPropOffset = default(StringOffset), float FloatProp = 0, double DoubleProp = 0) { builder.StartObject(6); TestTableWithUnionAndMoreFields.AddDoubleProp(builder, DoubleProp); TestTableWithUnionAndMoreFields.AddFloatProp(builder, FloatProp); TestTableWithUnionAndMoreFields.AddStringProp(builder, StringPropOffset); TestTableWithUnionAndMoreFields.AddUnionProp(builder, UnionPropOffset); TestTableWithUnionAndMoreFields.AddIntProp(builder, IntProp); TestTableWithUnionAndMoreFields.AddUnionPropType(builder, UnionProp_type); return(TestTableWithUnionAndMoreFields.EndTestTableWithUnionAndMoreFields(builder)); }
public TestUnion EchoUnion(TestUnion arg) { return arg; }
public static extern void WriteUnionFloat(float f, out TestUnion result);
protected override void WndProc(ref Message m) { if (m.Msg == WM_POINTERUPDATE) { IntPtr wp = m.WParam; var tu = new TestUnion { Number = (uint)wp }; int pid = tu.Low; IntPtr xy = m.LParam; int x = unchecked((short)(long)xy); int y = unchecked((short)((long)xy >> 16)); // convert into relative position x = (x - clientRect.Left); y = (y - clientRect.Top); // fix this with proper bit value... bool isInteracting = ((unchecked((short)((long)wp >> 16))) < 1024) || ((unchecked((short)((long)wp >> 16))) > 10240); OnPointerUpdate(pid, new Point(x, y), isInteracting); } else if (m.Msg == WM_POINTERDOWN) { IntPtr wp = m.WParam; var tu = new TestUnion { Number = (uint)wp }; int pid = tu.Low; IntPtr xy = m.LParam; int x = unchecked((short)(long)xy); int y = unchecked((short)((long)xy >> 16)); // convert into relative position x = (x - clientRect.Left); y = (y - clientRect.Top); OnPointerDown(pid, new Point(x, y)); } else if (m.Msg == WM_POINTERUP) { IntPtr wp = m.WParam; var tu = new TestUnion { Number = (uint)wp }; int pid = tu.Low; IntPtr xy = m.LParam; int x = unchecked((short)(long)xy); int y = unchecked((short)((long)xy >> 16)); // convert into relative position x = (x - clientRect.Left); y = (y - clientRect.Top); OnPointerUp(pid, new Point(x, y)); } // prevent window from being activated else if (m.Msg == WM_MOUSEACTIVATE) { m.Result = (IntPtr)MA_NOACTIVATE; return; } else if (m.Msg == WM_POINTERACTIVATE) { m.Result = (IntPtr)PA_NOACTIVATE; return; } else if (m.Msg == WM_SYSCOMMAND) { if (isAnalyserFound) { int command = m.WParam.ToInt32() & 0xfff0; if (command == SC_MOVE) return; } } else if (m.Msg == WM_GESTURE) { m.Result = (IntPtr)0; return; } base.WndProc(ref m); }
public void TestSimpleUnion() { TestUnion arg = new TestUnion(); short case0Val = 11; arg.Setval0(case0Val); TestUnion result = m_testService.EchoTestUnion(arg); Assertion.AssertEquals(case0Val, result.Getval0()); Assertion.AssertEquals(0, result.Discriminator); TestUnion arg2 = new TestUnion(); int case1Val = 12; arg2.Setval1(case1Val, 2); TestUnion result2 = m_testService.EchoTestUnion(arg2); Assertion.AssertEquals(case1Val, result2.Getval1()); Assertion.AssertEquals(2, result2.Discriminator); TestUnion arg3 = new TestUnion(); bool case2Val = true; arg3.Setval2(case2Val, 7); TestUnion result3 = m_testService.EchoTestUnion(arg3); Assertion.AssertEquals(case2Val, result3.Getval2()); Assertion.AssertEquals(7, result3.Discriminator); }
public static void AddUnionPropType(FlatBufferBuilder builder, TestUnion UnionPropType) { builder.AddByte(1, (byte)UnionPropType, 0); }