[runtime] Fix Empty generic enumerator equality
[mono.git] / mcs / class / corlib / Test / System / BadImageFormatExceptionTest.cs
1 //
2 // BadImageFormatExceptionTest.cs - Unit tests for
3 //      System.BadImageFormatException
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
7 //
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System
35 {
36         [TestFixture]
37         public class BadImageFormatExceptionTest
38         {
39                 [Test]
40                 public void Constructor1 ()
41                 {
42                         BadImageFormatException bif = new BadImageFormatException ();
43
44                         Assert.IsNotNull (bif.Data, "#1");
45                         Assert.IsNull (bif.FileName, "#2");
46                         Assert.IsNull (bif.InnerException, "#3");
47                         Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library (.dll) is invalid
48                         Assert.IsNull (bif.FusionLog, "#5");
49                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName), "#6");
50                 }
51
52                 [Test]
53                 public void Constructor2 ()
54                 {
55                         BadImageFormatException bif = new BadImageFormatException ("message");
56
57                         Assert.IsNotNull (bif.Data, "#1");
58                         Assert.IsNull (bif.FileName, "#2");
59                         Assert.IsNull (bif.InnerException, "#3");
60                         Assert.IsNotNull (bif.Message, "#4");
61                         Assert.AreEqual ("message", bif.Message, "#5");
62                         Assert.IsNull (bif.FusionLog, "#6");
63                         Assert.AreEqual (bif.GetType ().FullName + ": message",
64                                 bif.ToString (), "#7");
65                 }
66
67                 [Test]
68                 public void Constructor2_Message_Empty ()
69                 {
70                         BadImageFormatException bif = new BadImageFormatException (string.Empty);
71
72                         Assert.IsNotNull (bif.Data, "#1");
73                         Assert.IsNull (bif.FileName, "#2");
74                         Assert.IsNull (bif.InnerException, "#3");
75                         Assert.IsNotNull (bif.Message, "#4");
76                         Assert.AreEqual (string.Empty, bif.Message, "#5");
77                         Assert.IsNull (bif.FusionLog, "#6");
78                         Assert.AreEqual (bif.GetType ().FullName + ": ",
79                                 bif.ToString (), "#7");
80                 }
81
82                 [Test]
83                 public void Constructor2_Message_Null ()
84                 {
85                         BadImageFormatException bif = new BadImageFormatException ((string) null);
86
87                         Assert.IsNotNull (bif.Data, "#1");
88                         Assert.IsNull (bif.FileName, "#2");
89                         Assert.IsNull (bif.InnerException, "#3");
90                         Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
91                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
92                         Assert.IsNull (bif.FusionLog, "#5");
93                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#6");
94                         Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#7");
95                 }
96
97                 [Test]
98                 public void Constructor3 ()
99                 {
100                         ArithmeticException ame = new ArithmeticException ("something");
101                         BadImageFormatException bif = new BadImageFormatException ("message",
102                                 ame);
103
104                         Assert.IsNotNull (bif.Data, "#1");
105                         Assert.IsNull (bif.FileName, "#2");
106                         Assert.IsNotNull (bif.InnerException, "#3");
107                         Assert.AreSame (ame, bif.InnerException, "#4");
108                         Assert.IsNotNull (bif.Message, "#5");
109                         Assert.AreEqual ("message", bif.Message, "#6");
110                         Assert.IsNull (bif.FusionLog, "#7");
111                         Assert.AreEqual (bif.GetType ().FullName + ": message ---> "
112                                 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
113                 }
114
115                 [Test]
116                 public void Constructor3_Message_Empty ()
117                 {
118                         ArithmeticException ame = new ArithmeticException ("something");
119                         BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
120
121                         Assert.IsNotNull (bif.Data, "#1");
122                         Assert.IsNull (bif.FileName, "#2");
123                         Assert.IsNotNull (bif.InnerException, "#3");
124                         Assert.AreSame (ame, bif.InnerException, "#4");
125                         Assert.IsNotNull (bif.Message, "#5");
126                         Assert.AreEqual (string.Empty, bif.Message, "#6");
127                         Assert.IsNull (bif.FusionLog, "#7");
128                         Assert.AreEqual (bif.GetType ().FullName + ":  ---> "
129                                 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
130                 }
131
132                 [Test]
133                 public void Constructor3_Message_Null ()
134                 {
135                         ArithmeticException ame = new ArithmeticException ("something");
136                         BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
137
138                         Assert.IsNotNull (bif.Data, "#1");
139                         Assert.IsNull (bif.FileName, "#2");
140                         Assert.IsNotNull (bif.InnerException, "#3");
141                         Assert.AreSame (ame, bif.InnerException, "#4");
142                         Assert.IsNotNull (bif.Message, "#5"); // Could not load file or assembly '' ...
143                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#6");
144                         Assert.IsNull (bif.FusionLog, "#7");
145                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#8");
146                         Assert.IsTrue (bif.ToString ().IndexOf ("---> " + ame.GetType ().FullName) != -1, "#9");
147                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#10");
148                 }
149
150                 [Test]
151                 public void Constructor3_InnerException_Null ()
152                 {
153                         BadImageFormatException bif = new BadImageFormatException ("message",
154                                 (Exception) null);
155
156                         Assert.IsNotNull (bif.Data, "#1");
157                         Assert.IsNull (bif.FileName, "#2");
158                         Assert.IsNull (bif.InnerException, "#3");
159                         Assert.IsNotNull (bif.Message, "#4");
160                         Assert.AreEqual ("message", bif.Message, "#5");
161                         Assert.IsNull (bif.FusionLog, "#6");
162                         Assert.AreEqual (bif.GetType ().FullName + ": message",
163                                 bif.ToString (), "#7");
164                 }
165
166                 [Test]
167                 public void Constructor4 ()
168                 {
169                         BadImageFormatException bif = new BadImageFormatException ("message",
170                                 "file.txt");
171
172                         Assert.IsNotNull (bif.Data, "#1");
173                         Assert.IsNotNull (bif.FileName, "#2");
174                         Assert.AreEqual ("file.txt", bif.FileName, "#3");
175                         Assert.IsNull (bif.InnerException, "#4");
176                         Assert.IsNotNull (bif.Message, "#5");
177                         Assert.AreEqual ("message", bif.Message, "#6");
178                         Assert.IsNull (bif.FusionLog, "#7");
179                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
180                                 + ": message" + Environment.NewLine), "#8");
181                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
182                         Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
183                 }
184
185                 [Test]
186                 public void Constructor4_FileName_Empty ()
187                 {
188                         BadImageFormatException bif = new BadImageFormatException ("message",
189                                 string.Empty);
190
191                         Assert.IsNotNull (bif.Data, "#1");
192                         Assert.IsNotNull (bif.FileName, "#2");
193                         Assert.AreEqual (string.Empty, bif.FileName, "#3");
194                         Assert.IsNull (bif.InnerException, "#4");
195                         Assert.IsNotNull (bif.Message, "#5");
196                         Assert.AreEqual ("message", bif.Message, "#6");
197                         Assert.IsNull (bif.FusionLog, "#7");
198                         Assert.AreEqual (bif.GetType ().FullName + ": message",
199                                 bif.ToString (), "#8");
200                 }
201
202                 [Test]
203                 public void Constructor4_FileName_Null ()
204                 {
205                         BadImageFormatException bif = new BadImageFormatException ("message",
206                                 (string) null);
207
208                         Assert.IsNotNull (bif.Data, "#A1");
209                         Assert.IsNull (bif.FileName, "#A2");
210                         Assert.IsNull (bif.InnerException, "#A3");
211                         Assert.IsNotNull (bif.Message, "#A4");
212                         Assert.AreEqual ("message", bif.Message, "#A5");
213                         Assert.IsNull (bif.FusionLog, "#A6");
214                         Assert.AreEqual (bif.GetType ().FullName + ": message",
215                                 bif.ToString (), "#A7");
216
217                         bif = new BadImageFormatException (string.Empty, (string) null);
218
219                         Assert.IsNotNull (bif.Data, "#B1");
220                         Assert.IsNull (bif.FileName, "#B2");
221                         Assert.IsNull (bif.InnerException, "#B3");
222                         Assert.IsNotNull (bif.Message, "#B4");
223                         Assert.AreEqual (string.Empty, bif.Message, "#B5");
224                         Assert.IsNull (bif.FusionLog, "#B6");
225                         Assert.AreEqual (bif.GetType ().FullName + ": ",
226                                 bif.ToString (), "#B7");
227                 }
228
229                 [Test]
230                 public void Constructor4_FileNameAndMessage_Empty ()
231                 {
232                         BadImageFormatException bif = new BadImageFormatException (string.Empty,
233                                 string.Empty);
234
235                         Assert.IsNotNull (bif.Data, "#1");
236                         Assert.IsNotNull (bif.FileName, "#2");
237                         Assert.AreEqual (string.Empty, bif.FileName, "#3");
238                         Assert.IsNull (bif.InnerException, "#4");
239                         Assert.IsNotNull (bif.Message, "#5");
240                         Assert.AreEqual (string.Empty, bif.Message, "#6");
241                         Assert.IsNull (bif.FusionLog, "#7");
242                         Assert.AreEqual (bif.GetType ().FullName + ": ", bif.ToString (), "#8");
243                 }
244
245                 [Test]
246                 public void Constructor4_FileNameAndMessage_Null ()
247                 {
248                         BadImageFormatException bif = new BadImageFormatException ((string) null,
249                                 (string) null);
250
251                         Assert.IsNotNull (bif.Data, "#1");
252                         Assert.IsNull (bif.FileName, "#2");
253                         Assert.IsNull (bif.InnerException, "#3");
254                         Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
255                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
256                         Assert.IsNull (bif.FusionLog, "#5");
257                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
258                                 + ": "), "#6");
259                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
260                 }
261
262                 [Test]
263                 public void Constructor4_Message_Empty ()
264                 {
265                         BadImageFormatException bif = null;
266                         
267                         bif = new BadImageFormatException (string.Empty, "file.txt");
268
269                         Assert.IsNotNull (bif.Data, "#1");
270                         Assert.IsNotNull (bif.FileName, "#2");
271                         Assert.AreEqual ("file.txt", bif.FileName, "#3");
272                         Assert.IsNull (bif.InnerException, "#4");
273                         Assert.IsNotNull (bif.Message, "#5");
274                         Assert.AreEqual (string.Empty, bif.Message, "#6");
275                         Assert.IsNull (bif.FusionLog, "#7");
276                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
277                                 + ": " + Environment.NewLine), "#8");
278                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
279                         Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
280                 }
281
282                 [Test]
283                 public void Constructor4_Message_Null ()
284                 {
285                         BadImageFormatException bif = null;
286                         
287                         bif = new BadImageFormatException ((string) null, "file.txt");
288
289                         Assert.IsNotNull (bif.Data, "#A1");
290                         Assert.IsNotNull (bif.FileName, "#A2");
291                         Assert.AreEqual ("file.txt", bif.FileName, "#A3");
292                         Assert.IsNull (bif.InnerException, "#A4");
293                         Assert.IsNotNull (bif.Message, "#A5");
294                         Assert.IsNull (bif.FusionLog, "#A6");
295                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
296                                 + ": "), "#A7");
297                         Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
298                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
299
300                         bif = new BadImageFormatException ((string) null, string.Empty);
301
302                         Assert.IsNotNull (bif.Data, "#B1");
303                         Assert.IsNotNull (bif.FileName, "#B2");
304                         Assert.AreEqual (string.Empty, bif.FileName, "#B3");
305                         Assert.IsNull (bif.InnerException, "#B4");
306                         // .NET 1.1: The format of the file 'file.txt' is invalid
307                         // .NET 2.0: Could not load file or assembly 'file.txt' or one of its ...
308                         Assert.IsNotNull (bif.Message, "#B5");
309                         Assert.IsNull (bif.FusionLog, "#B6");
310                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
311                                 + ": "), "#B7");
312                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
313                         Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");
314                 }
315         }
316 }