Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Resources / ResXDataNodeTest.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
21 //
22 // ResXFileRefTest.cs: Unit Tests for ResXFileRef.
23 //
24 // Authors:
25 //      Andreia Gaita   (avidigal@novell.com)
26 //
27
28 #if NET_2_0
29
30 using System;
31 using System.Resources;
32 using System.Runtime.Serialization;
33 using System.Collections;
34
35 using NUnit.Framework;
36 namespace MonoTests.System.Resources
37 {
38         [TestFixture]
39         public class ResXDataNodeTest : MonoTests.System.Windows.Forms.TestHelper
40         {
41                 [Test]
42                 [ExpectedException (typeof (ArgumentNullException))]
43                 public void ConstructorEx1 ()
44                 {
45                         ResXDataNode d = new ResXDataNode (null, (object)null);
46                 }
47
48                 [Test]
49                 [ExpectedException (typeof (ArgumentNullException))]
50                 public void ConstructorEx2 ()
51                 {
52                         ResXDataNode d = new ResXDataNode (null, (ResXFileRef) null);
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (ArgumentException))]
57                 public void ConstructorEx3 ()
58                 {
59                         ResXDataNode d = new ResXDataNode ("", (object) null);
60                 }
61
62                 [Test]
63                 [ExpectedException (typeof (ArgumentNullException))]
64                 public void ConstructorEx4 ()
65                 {
66                         ResXDataNode d = new ResXDataNode ("", (ResXFileRef) null);
67                 }
68
69                 [Test]
70                 [ExpectedException (typeof (ArgumentException))]
71                 public void ConstructorEx5 ()
72                 {
73                         ResXDataNode d = new ResXDataNode ("", new ResXFileRef ("filename", "typename"));
74                 }
75
76                 [Test]
77                 [ExpectedException (typeof (InvalidOperationException))]
78                 public void ConstructorEx6 ()
79                 {
80                         ResXDataNode d = new ResXDataNode ("name", new notserializable ());
81                 }
82
83                 [Test]
84                 public void WriteRead1 ()
85                 {
86                         ResXResourceWriter rw = new ResXResourceWriter ("resx.resx");
87                         serializable ser = new serializable ("aaaaa", "bbbbb");
88                         ResXDataNode dn = new ResXDataNode ("test", ser);
89                         dn.Comment = "comment";
90                         rw.AddResource (dn);
91                         rw.Close ();
92
93                         bool found = false;
94                         ResXResourceReader rr = new ResXResourceReader ("resx.resx");
95                         IDictionaryEnumerator en = rr.GetEnumerator ();
96                         while (en.MoveNext ()) {
97                                 serializable o = ((DictionaryEntry) en.Current).Value as serializable;
98                                 if (o != null) {
99                                         found = true;
100                                         Assert.AreEqual (ser, o, "#A1");
101                                 }
102
103                         }
104                         rr.Close ();
105
106                         Assert.IsTrue (found, "#A2 - Serialized object not found on resx");
107                 }
108         }
109
110         class notserializable
111         {
112                 public object test;
113                 public notserializable ()
114                 {
115
116                 }
117         }
118
119         [SerializableAttribute]
120         public class serializable : ISerializable
121         {
122                 string name;
123                 string value;
124
125                 public serializable (string name, string value)
126                 {
127                         this.name = name;
128                         this.value = value;
129                 }
130
131                 public serializable (SerializationInfo info, StreamingContext ctxt)
132                 {
133                         name = (string) info.GetValue ("sername", typeof (string));
134                         value = (String) info.GetValue ("servalue", typeof (string));
135                 }
136
137                 public void GetObjectData (SerializationInfo info, StreamingContext ctxt)
138                 {
139                         info.AddValue ("sername", name);
140                         info.AddValue ("servalue", value);
141                 }
142
143                 public override string ToString ()
144                 {
145                         return String.Format ("name={0};value={1}", this.name, this.value);
146                 }
147
148                 public override bool Equals (object obj)
149                 {
150                         serializable o = obj as serializable;
151                         if (o == null)
152                                 return false;
153                         return this.name.Equals(o.name) && this.value.Equals(o.value);
154                 }
155         }
156 }
157 #endif
158