2002-12-31 Martin Baulig <martin@ximian.com>
[mono.git] / mono / tests / appdomain2.cs
1 using System;
2 using System.IO;
3 using System.Security.Policy;
4 using System.Threading;
5 using System.Runtime.Serialization;
6
7 class Container {
8
9         [Serializable]
10         public struct c2 : ISerializable {
11                 public int a;
12                 public string s1;
13
14                 private c2 (SerializationInfo info, StreamingContext context) {
15                         a = info.GetInt32("a");
16                         s1 = info.GetString("s1");
17                         Console.WriteLine ("SetObjectData called: " + info.AssemblyName + "," +
18                                            info.FullTypeName + " " + s1 + ", " + a);
19                 }
20
21                 public void GetObjectData (SerializationInfo info, StreamingContext context) {
22                         Console.WriteLine ("GetObjectData called: " + info.AssemblyName + "," +
23                                            info.FullTypeName + " " + s1 + ", " + a);
24                         info.AddValue ("a", a);
25                         if (s1 != null)
26                                 info.AddValue ("s1", s1);
27                         else
28                                 info.AddValue ("s1", "(null)");
29                 }
30         }
31         
32         [Serializable]
33         public class c1 {
34                 public c1 () {
35                         e1.a = 3;
36                         e1.s1 = "SS";
37                         sa [0].a = 5;
38                 }
39                 public int a = 1;
40                 public int b = 2;
41                 public string s1 = "TEST1";
42                 [NonSerialized] public string s2 = "TEST2";
43                 public c2 [] sa = new c2 [2];
44                 public c2 e1;
45         }
46         
47         static int Main ()
48         {
49                 AppDomainSetup setup = new AppDomainSetup ();
50                 setup.ApplicationBase = Directory.GetCurrentDirectory ();
51                 Console.WriteLine (AppDomain.CurrentDomain.FriendlyName);
52                         
53                 AppDomain newDomain = AppDomain.CreateDomain ("NewDomain", new Evidence (), setup);
54
55                 c1 a1 = new c1 ();
56
57                 
58                 newDomain.SetData ("TEST", a1);
59                 c1 r1 = (c1)newDomain.GetData ("TEST");
60                 if (r1.a != 1 || r1.b !=2)
61                         return 1;
62                 
63                 if (r1.s1 != "TEST1")
64                         return 2;
65                 
66                 if (r1.s2 != null)
67                         return 3;
68
69                 if (r1.e1.a != 3)
70                         return 4;
71
72                 if (r1.e1.s1 != "SS")
73                         return 4;
74                 
75                 if (r1.sa [0].a != 5)
76                         return 5;
77
78                 if (r1.sa [0].s1 != "(null)")
79                         return 6;
80                 
81
82                 return 0;
83         }
84 }