public static int Main() { MainApp a = new MainApp(); // simple delegate roundtrip { int x = CallSimpleDelegate(a.CreateSimpleCallback(false), 1); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return(1); } } Console.WriteLine("Simple delegate roundtrip passed"); // delegate roundtrip { double x = CallDelegate(a.CreateCallback(false), new MyValue(1)); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return(1); } } Console.WriteLine("Delegate roundtrip passed"); // simple delegate roundtrip - crossdomain { AppDomain app = AppDomain.CreateDomain("MyDomain"); MainApp remoteapp = (MainApp)app.CreateInstanceAndUnwrap("interoptest1", "MainApp"); MySimpleDelegate callback = remoteapp.CreateSimpleCallback(true); int x = CallSimpleDelegate(callback, 1); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return(1); } } Console.WriteLine("Simple delegate roundtrip crossdomain passed"); // delegate roundtrip - crossdomain { AppDomain app = AppDomain.CreateDomain("MyDomain"); MainApp remoteapp = (MainApp)app.CreateInstanceAndUnwrap("interoptest1", "MainApp"); MyDelegate callback = remoteapp.CreateCallback(true); double x = CallDelegate(callback, new MyValue(1)); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return(1); } } Console.WriteLine("Delegate roundtrip crossdomain passed"); // ffi roundtrip { double d = CallFFI(a, new MyValue(1)); if (d != 2) { Console.WriteLine("Unexpected value: " + d.ToString()); return(2); } } Console.WriteLine("FFI roundtrip passed"); // array marshaling { int[] rg = new int[4]; rg[0] = 12; rg[1] = 33; rg[2] = -21; rg[3] = 18; int sum = Sum(rg.Length, rg); if (sum != 42) { Console.WriteLine("Unexpected value: " + sum.ToString()); return(3); } } Console.WriteLine("Array marshalling passed"); // array marshaling ex { MyStruct[] rg = new MyStruct[7]; rg[0].value = new MyValue(2314); rg[1].value = new MyValue(3452); rg[2].value = new MyValue(3235); rg[3].value = new MyValue(3452); rg[4].value = new MyValue(6980); rg[5].value = new MyValue(3133); rg[6].value = new MyValue(3426); int sum = ObjectSum(rg.Length, rg); if (sum != 25992) { Console.WriteLine("Unexpected value: " + sum.ToString()); return(4); } } Console.WriteLine("Array marshalling ex passed"); // errorinfo roundtrip { bool thrown = false; try { ReallyBadError(new MyValue(0)); } catch (Exception e) { string s = e.ToString(); if (s.IndexOf("qwerty") == -1) { Console.WriteLine("Unexpected value: " + s); return(5); } thrown = true; } if (!thrown) { Console.WriteLine("Exception wasn't thrown"); return(5); } } Console.WriteLine("IErrorInfo roundtrip passed"); // delegate roundtrip { MySimpleDelegate d1 = a.CreateSimpleCallback(false); MySimpleDelegate d2 = DelegateMarshal(d1); if (d1 != d2) { Console.WriteLine("Delegate marshal failed"); return(8); } } Console.WriteLine("Delegate marshal passed"); Console.WriteLine("All test passed"); return(0); }
public static int Main() { MainApp a = new MainApp(); // simple delegate roundtrip { int x = CallSimpleDelegate(a.CreateSimpleCallback(false), 1); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return 1; } } Console.WriteLine("Simple delegate roundtrip passed"); // delegate roundtrip { double x = CallDelegate(a.CreateCallback(false), new MyValue(1)); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return 1; } } Console.WriteLine("Delegate roundtrip passed"); // simple delegate roundtrip - crossdomain { AppDomain app = AppDomain.CreateDomain("MyDomain"); MainApp remoteapp = (MainApp)app.CreateInstanceAndUnwrap ("interoptest1", "MainApp"); MySimpleDelegate callback = remoteapp.CreateSimpleCallback(true); int x = CallSimpleDelegate(callback, 1); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return 1; } } Console.WriteLine("Simple delegate roundtrip crossdomain passed"); // delegate roundtrip - crossdomain { AppDomain app = AppDomain.CreateDomain("MyDomain"); MainApp remoteapp = (MainApp)app.CreateInstanceAndUnwrap ("interoptest1", "MainApp"); MyDelegate callback = remoteapp.CreateCallback(true); double x = CallDelegate(callback, new MyValue(1)); if (x != 2) { Console.WriteLine("Unexpected value: " + x.ToString()); return 1; } } Console.WriteLine("Delegate roundtrip crossdomain passed"); // ffi roundtrip { double d = CallFFI(a, new MyValue(1)); if (d != 2) { Console.WriteLine("Unexpected value: " + d.ToString()); return 2; } } Console.WriteLine("FFI roundtrip passed"); // array marshaling { int[] rg = new int[4]; rg[0] = 12; rg[1] = 33; rg[2] = -21; rg[3] = 18; int sum = Sum(rg.Length, rg); if (sum != 42) { Console.WriteLine("Unexpected value: " + sum.ToString()); return 3; } } Console.WriteLine("Array marshalling passed"); // array marshaling ex { MyStruct[] rg = new MyStruct[7]; rg[0].value = new MyValue(2314); rg[1].value = new MyValue(3452); rg[2].value = new MyValue(3235); rg[3].value = new MyValue(3452); rg[4].value = new MyValue(6980); rg[5].value = new MyValue(3133); rg[6].value = new MyValue(3426); int sum = ObjectSum(rg.Length, rg); if (sum != 25992) { Console.WriteLine("Unexpected value: " + sum.ToString()); return 4; } } Console.WriteLine("Array marshalling ex passed"); // errorinfo roundtrip { bool thrown = false; try { ReallyBadError(new MyValue(0)); } catch (Exception e) { string s = e.ToString(); if (s.IndexOf("qwerty") == -1) { Console.WriteLine("Unexpected value: " + s); return 5; } thrown = true; } if (!thrown) { Console.WriteLine("Exception wasn't thrown"); return 5; } } Console.WriteLine("IErrorInfo roundtrip passed"); // delegate roundtrip { MySimpleDelegate d1 = a.CreateSimpleCallback(false); MySimpleDelegate d2 = DelegateMarshal(d1); if (d1 != d2) { Console.WriteLine("Delegate marshal failed"); return 8; } } Console.WriteLine("Delegate marshal passed"); Console.WriteLine("All test passed"); return 0; }