2005-12-05 Lluis Sanchez Gual <lluis@novell.com>
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlSerializerTestClasses.cs
1 //\r
2 // System.Xml.XmlSerializerTestClasses\r
3 //\r
4 // Author:\r
5 //   Erik LeBel <eriklebel@yahoo.ca>\r
6 //\r
7 // (C) 2003 Erik LeBel\r
8 //\r
9 // Classes to use in the testing of the XmlSerializer\r
10 //\r
11 \r
12 using System;\r
13 using System.ComponentModel;\r
14 using System.Collections;\r
15 using System.Xml.Serialization;\r
16 using System.Xml;\r
17 \r
18 namespace MonoTests.System.Xml.TestClasses\r
19 {\r
20         public enum SimpleEnumeration { FIRST, SECOND };\r
21 \r
22         [Flags]\r
23         public enum EnumDefaultValue { e1 = 1, e2 = 2, e3 = 3 }\r
24         public enum EnumDefaultValueNF { e1 = 1, e2 = 2, e3 = 3 }\r
25         \r
26         public class SimpleClass\r
27         {\r
28                 public string something = null;\r
29         }\r
30 \r
31         public class StringCollection : CollectionBase\r
32         {\r
33                 public void Add (String parameter) \r
34                 {\r
35                         List.Insert (Count, parameter);\r
36                 }\r
37                         \r
38                 public String this [int index]\r
39                 {\r
40                         get\r
41                         { \r
42                                 if (index < 0 || index > Count)\r
43                                         throw new ArgumentOutOfRangeException ();\r
44                                         \r
45                                 return (String) List [index]; \r
46                         }\r
47                         set { List [index] = value; }\r
48                 }\r
49         }\r
50         \r
51         public class StringCollectionContainer\r
52         {\r
53                 StringCollection messages = new StringCollection();\r
54                 \r
55                 public StringCollection Messages\r
56                 {\r
57                         get { return messages; }\r
58                 }\r
59         }\r
60 \r
61         public class ArrayContainer\r
62         {\r
63                 public object [] items = null;\r
64         }\r
65         \r
66         public class ClassArrayContainer\r
67         {\r
68                 public SimpleClass [] items = null;\r
69         }\r
70         \r
71         [XmlRoot("simple")]\r
72         public class SimpleClassWithXmlAttributes\r
73         {\r
74                 [XmlAttribute("member")]\r
75                 public string something = null;\r
76         }\r
77         \r
78         [XmlRoot("field")]\r
79         public class Field\r
80         {\r
81                 [XmlAttribute("modifiers")]\r
82                 public MapModifiers Modifiers;\r
83         }\r
84 \r
85         [Flags]\r
86         public enum MapModifiers\r
87         {\r
88                 [XmlEnum("public")]\r
89                 Public = 0,\r
90                 [XmlEnum("protected")]\r
91                 Protected = 1,\r
92         }\r
93         \r
94         public class MyList : ArrayList\r
95         {\r
96                 object container;\r
97                 \r
98                 // NOTE: MyList has no public constructor\r
99                 public MyList (object container) : base()\r
100                 {\r
101                         this.container = container;\r
102                 }\r
103         }\r
104         \r
105         public class Container\r
106         {\r
107                 public MyList Items;\r
108                 \r
109                 public Container () {\r
110                         Items = new MyList(this);\r
111                 }\r
112         }\r
113         \r
114         public class Container2\r
115         {\r
116                 public MyList Items;\r
117                 \r
118                 public Container2 () {\r
119                 }\r
120                 \r
121                 public Container2 (bool b) {\r
122                         Items = new MyList(this);\r
123                 }\r
124         }
125 \r
126         public class MyElem: XmlElement
127         {
128                 public MyElem (XmlDocument doc): base ("","myelem","", doc)
129                 {
130                         SetAttribute ("aa","1");
131                 }
132
133                 [XmlAttribute]
134                 public int kk=1;
135         }
136 \r
137         public class MyDocument: XmlDocument
138         {
139                 public MyDocument ()
140                 {
141                 }
142
143                 [XmlAttribute]
144                 public int kk=1;
145         }
146         
147         public class CDataContainer
148         {
149                 public XmlCDataSection cdata;
150         }
151         
152         public class NodeContainer
153         {
154                 public XmlNode node;
155         }\r
156         \r
157         public class Choices\r
158         {\r
159                 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]\r
160                 [XmlElementAttribute("ChoiceOne", typeof(string), IsNullable=false)]\r
161                 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]\r
162                 [XmlChoiceIdentifier("ItemType")]\r
163                 public string MyChoice;\r
164 \r
165                 [XmlIgnore]\r
166                 public ItemChoiceType ItemType;\r
167         }\r
168         \r
169         [XmlType(IncludeInSchema = false)]\r
170         public enum ItemChoiceType\r
171         {\r
172                 ChoiceZero,\r
173                 [XmlEnum ("ChoiceOne")]\r
174                 StrangeOne,\r
175                 ChoiceTwo,\r
176         }\r
177         \r
178         public class WrongChoices\r
179         {\r
180                 [XmlElementAttribute("ChoiceZero", typeof(string), IsNullable=false)]\r
181                 [XmlElementAttribute("StrangeOne", typeof(string), IsNullable=false)]\r
182                 [XmlElementAttribute("ChoiceTwo", typeof(string), IsNullable=false)]\r
183                 [XmlChoiceIdentifier("ItemType")]\r
184                 public string MyChoice;\r
185 \r
186                 [XmlIgnore]\r
187                 public ItemChoiceType ItemType;\r
188         }
189         
190         [XmlType ("Type with space")]
191         public class TestSpace
192         {
193            [XmlElement (ElementName = "Element with space")]
194            public int elem;
195             
196            [XmlAttribute (AttributeName = "Attribute with space")]
197            public int attr; 
198         }
199 \r
200         [Serializable]
201         public class ReadOnlyProperties {
202                 string[] strArr = new string[2] { "string1", "string2" };
203
204                 public string[] StrArr {
205                         get { return strArr; }
206                 }
207                 
208                 public string dat {
209                         get { return "fff"; }
210                 } 
211         }
212         
213         [XmlRoot("root")]
214         public class ListDefaults
215         {
216                 public ListDefaults ()
217                 {
218                         ed = new SimpleClass ();
219                         str = "hola";
220                 }
221                 
222             public ArrayList list2;
223             
224             public MyList list3;
225             
226             public string[] list4;
227             
228                 [XmlElement("e", typeof(SimpleClass))]
229             public ArrayList list5;
230             
231                 [DefaultValue (null)]
232             public SimpleClass ed;
233             
234                 [DefaultValue (null)]
235             public string str; 
236         }
237         
238         public class clsPerson
239         {
240                 public IList EmailAccounts;
241         }
242         
243         public class ArrayClass
244         {
245                 public object names = new object[] { "un","dos" };
246         }
247         
248         public class CompositeValueType
249         {
250                 public void Init ()
251                 {
252                         Items = new object[] { 1, 2 };
253                         ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.In, ItemsChoiceType.Es };
254                 }\r
255            \r
256                 [XmlElementAttribute("Es", typeof(int))]\r
257                 [XmlElementAttribute("In", typeof(int))]\r
258                 [XmlChoiceIdentifierAttribute("ItemsElementName")]\r
259                 public object[] Items;\r
260            \r
261                 [XmlElementAttribute("ItemsElementName")]\r
262                 [XmlIgnoreAttribute()]\r
263                 public ItemsChoiceType[] ItemsElementName;\r
264         }\r
265
266         public enum ItemsChoiceType {\r
267            In, Es\r
268         }
269         
270         public class ArrayAttributeWithType
271         {
272                 [XmlAttribute (DataType="anyURI")]
273                 public string[] at = new string [] { "a","b" };
274
275                 [XmlAttribute (DataType="base64Binary")]
276                 public byte[][] bin1 = new byte[][] { new byte[]{1,2},  new byte[]{1,2}};
277                 
278                 [XmlAttribute (DataType="base64Binary")]
279                 public byte[] bin2 = new byte[] { 1,2 };
280         }
281         
282         public class ArrayAttributeWithWrongType
283         {
284                 [XmlAttribute (DataType="int")]
285                 public string[] at = new string [] { "a","b" };
286         }
287         
288         [XmlType ("Container")]
289         public class EntityContainer
290         {
291                 EntityCollection collection1;
292                 EntityCollection collection2;
293                 EntityCollection collection3 = new EntityCollection ("root");
294                 EntityCollection collection4 = new EntityCollection ("root");
295                 
296                 [XmlArray (IsNullable=true)]
297                 public EntityCollection Collection1 {
298                         get { return collection1; }
299                         set { collection1 = value; collection1.Container = "assigned"; }
300                 }
301                 
302                 [XmlArray (IsNullable=false)]
303                 public EntityCollection Collection2 {
304                         get { return collection2; }
305                         set { collection2 = value; collection2.Container = "assigned"; }
306                 }
307                 
308                 [XmlArray (IsNullable=true)]
309                 public EntityCollection Collection3 {
310                         get { return collection3; }
311                         set { collection3 = value; collection3.Container = "assigned"; }
312                 }
313                 
314                 [XmlArray (IsNullable=false)]
315                 public EntityCollection Collection4 {
316                         get { return collection4; }
317                         set { collection4 = value; collection4.Container = "assigned"; }
318                 }
319         }
320         
321         [XmlType ("Container")]
322         public class ArrayEntityContainer
323         {
324                 Entity[] collection1;
325                 Entity[] collection2;
326                 Entity[] collection3 = new Entity [0];
327                 Entity[] collection4 = new Entity [0];
328                 
329                 [XmlArray (IsNullable=true)]
330                 public Entity[] Collection1 {
331                         get { return collection1; }
332                         set { collection1 = value; }
333                 }
334                 
335                 [XmlArray (IsNullable=false)]
336                 public Entity[] Collection2 {
337                         get { return collection2; }
338                         set { collection2 = value; }
339                 }
340                 
341                 [XmlArray (IsNullable=true)]
342                 public Entity[] Collection3 {
343                         get { return collection3; }
344                         set { collection3 = value; }
345                 }
346                 
347                 [XmlArray (IsNullable=false)]
348                 public Entity[] Collection4 {
349                         get { return collection4; }
350                         set { collection4 = value; }
351                 }
352         }
353         
354         public class Entity
355         {
356                 private string _name = string.Empty;
357                 private string _parent = null;
358
359                 [XmlAttribute]
360                 public string Name {
361                         get { return _name; }
362                         set { _name = value; }
363                 }
364
365                 [XmlIgnore] 
366                 public string Parent {
367                         get { return _parent; }
368                         set { _parent = value; }
369                 }
370         }
371
372         public class EntityCollection : ArrayList
373         {
374                 public string _container;
375
376                 public EntityCollection ()
377                 {
378                 }
379
380                 public EntityCollection (string c)
381                 {
382                         _container = c;
383                 }
384
385                 public string Container {
386                         get { return _container; }
387                         set { _container = value; }
388                 }
389
390                 public int Add (Entity value)
391                 {
392                         if(_container != null)
393                                 value.Parent = _container;
394
395                         return base.Add(value);
396                 }
397
398                 public new Entity this[int index]
399                 {
400                         get { return (Entity) base[index]; }
401                         set { base[index] = value; }
402                 }
403         }
404         
405         [XmlType ("Container")]
406         public class ObjectWithReadonlyCollection
407         {
408                 EntityCollection collection1 = new EntityCollection ("root");
409                 
410                 public EntityCollection Collection1 {
411                         get { return collection1; }
412                 }
413         }
414         
415         [XmlType ("Container")]
416         public class ObjectWithReadonlyNulCollection
417         {
418                 EntityCollection collection1;
419                 
420                 public EntityCollection Collection1 {
421                         get { return collection1; }
422                 }
423         }
424         
425         [XmlType ("Container")]
426         public class ObjectWithReadonlyArray
427         {
428                 Entity[] collection1 = new Entity [0];
429                 
430                 public Entity[] Collection1 {
431                         get { return collection1; }
432                 }
433         }
434 }\r
435