2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / tests / appdomain1.cs
1 using System;
2 using System.Security.Policy;
3 using System.Runtime.Remoting;
4 using System.Threading;
5
6 class Container {
7
8         class MBRTest : MarshalByRefObject
9         {
10                 public int Int {
11                         get {
12                                 return (int) AppDomain.CurrentDomain.GetData("test_integer");
13                         }
14                 }
15
16                 public string Str {
17                         get {
18                                 return (string) AppDomain.CurrentDomain.GetData("test_string");
19                         }
20                 }
21
22                 public bool Bool {
23                         get {
24                                 return (bool) AppDomain.CurrentDomain.GetData("test_bool");
25                         }
26                 }
27
28                 public int [] Arr {
29                         get {
30                                 return (int []) AppDomain.CurrentDomain.GetData("test_array");
31                         }
32                 }
33         }
34
35         static int Main ()
36         {
37                 Console.WriteLine ("Friendly name: " + AppDomain.CurrentDomain.FriendlyName);
38                         
39                 AppDomain newDomain = AppDomain.CreateDomain ("NewDomain");
40
41                 if (!RemotingServices.IsTransparentProxy(newDomain))
42                         return 1;
43
44                 // First test that this domain get's the right data from the other domain
45                 newDomain.SetData ("test_string", "a");
46
47                 object t = newDomain.GetData("test_string");
48                 if (t.GetType() != typeof(string))
49                         return 2;
50
51                 if ((string) newDomain.GetData ("test_string") != "a")
52                         return 3;
53
54                 newDomain.SetData ("test_integer", 1);
55                 if ((int) newDomain.GetData ("test_integer") != 1)
56                         return 4;
57
58                 newDomain.SetData ("test_bool", true);
59                 if ((bool)newDomain.GetData ("test_bool") != true)
60                         return 5;
61
62                 newDomain.SetData ("test_bool", false);
63                 if ((bool)newDomain.GetData ("test_bool") != false)
64                         return 6;
65
66                 int [] ta = { 1, 2, 3 };
67                 newDomain.SetData ("test_array", ta);
68
69                 int [] ca = (int [])newDomain.GetData ("test_array");
70                 
71                 if (ca [0] != 1 || ca [1] != 2 || ca [2] != 3)
72                         return 7;
73
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);\r
76                 
77                 if (!RemotingServices.IsTransparentProxy(test))
78                         return 8;
79
80                 // Time to test that the newDomain also have the same info
81                 if (test.Int != 1)
82                         return 9;
83
84                 if (test.Str != "a")
85                         return 10;
86
87                 if (test.Bool != false)
88                         return 11;
89
90                 ca = test.Arr;
91                 
92                 if (ca [0] != 1 || ca [1] != 2 || ca [2] != 3)
93                         return 12;
94
95                 Console.WriteLine("test-ok");
96
97                 return 0;
98         }
99 }