2010-01-04 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / appdomain1.cs
blob23361c90e974ca43807788220643838c684bd48b
1 using System;
2 using System.Security.Policy;
3 using System.Runtime.Remoting;
4 using System.Threading;
6 class Container {
8 class MBRTest : MarshalByRefObject
10 public int Int {
11 get {
12 return (int) AppDomain.CurrentDomain.GetData("test_integer");
16 public string Str {
17 get {
18 return (string) AppDomain.CurrentDomain.GetData("test_string");
22 public bool Bool {
23 get {
24 return (bool) AppDomain.CurrentDomain.GetData("test_bool");
28 public int [] Arr {
29 get {
30 return (int []) AppDomain.CurrentDomain.GetData("test_array");
35 static int Main ()
37 Console.WriteLine ("Friendly name: " + AppDomain.CurrentDomain.FriendlyName);
39 AppDomain newDomain = AppDomain.CreateDomain ("NewDomain");
41 if (!RemotingServices.IsTransparentProxy(newDomain))
42 return 1;
44 // First test that this domain get's the right data from the other domain
45 newDomain.SetData ("test_string", "a");
47 object t = newDomain.GetData("test_string");
48 if (t.GetType() != typeof(string))
49 return 2;
51 if ((string) newDomain.GetData ("test_string") != "a")
52 return 3;
54 newDomain.SetData ("test_integer", 1);
55 if ((int) newDomain.GetData ("test_integer") != 1)
56 return 4;
58 newDomain.SetData ("test_bool", true);
59 if ((bool)newDomain.GetData ("test_bool") != true)
60 return 5;
62 newDomain.SetData ("test_bool", false);
63 if ((bool)newDomain.GetData ("test_bool") != false)
64 return 6;
66 int [] ta = { 1, 2, 3 };
67 newDomain.SetData ("test_array", ta);
69 int [] ca = (int [])newDomain.GetData ("test_array");
71 if (ca [0] != 1 || ca [1] != 2 || ca [2] != 3)
72 return 7;
74 // Creata a MBR object to test that the other domain has the correct info
75 MBRTest test = (MBRTest) newDomain.CreateInstanceAndUnwrap (typeof(MBRTest).Assembly.FullName, typeof(MBRTest).FullName);
77 if (!RemotingServices.IsTransparentProxy(test))
78 return 8;
80 // Time to test that the newDomain also have the same info
81 if (test.Int != 1)
82 return 9;
84 if (test.Str != "a")
85 return 10;
87 if (test.Bool != false)
88 return 11;
90 ca = test.Arr;
92 if (ca [0] != 1 || ca [1] != 2 || ca [2] != 3)
93 return 12;
95 Console.WriteLine("test-ok");
97 return 0;