remove TARGET_JVM
[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 #if NET_2_0
45                         Assert.IsNotNull (bif.Data, "#1");
46 #endif
47                         Assert.IsNull (bif.FileName, "#2");
48                         Assert.IsNull (bif.InnerException, "#3");
49                         Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library (.dll) is invalid
50                         Assert.IsNull (bif.FusionLog, "#5");
51                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName), "#6");
52                 }
53
54                 [Test]
55                 public void Constructor2 ()
56                 {
57                         BadImageFormatException bif = new BadImageFormatException ("message");
58
59 #if NET_2_0
60                         Assert.IsNotNull (bif.Data, "#1");
61 #endif
62                         Assert.IsNull (bif.FileName, "#2");
63                         Assert.IsNull (bif.InnerException, "#3");
64                         Assert.IsNotNull (bif.Message, "#4");
65                         Assert.AreEqual ("message", bif.Message, "#5");
66                         Assert.IsNull (bif.FusionLog, "#6");
67                         Assert.AreEqual (bif.GetType ().FullName + ": message",
68                                 bif.ToString (), "#7");
69                 }
70
71                 [Test]
72                 public void Constructor2_Message_Empty ()
73                 {
74                         BadImageFormatException bif = new BadImageFormatException (string.Empty);
75
76 #if NET_2_0
77                         Assert.IsNotNull (bif.Data, "#1");
78 #endif
79                         Assert.IsNull (bif.FileName, "#2");
80                         Assert.IsNull (bif.InnerException, "#3");
81                         Assert.IsNotNull (bif.Message, "#4");
82                         Assert.AreEqual (string.Empty, bif.Message, "#5");
83                         Assert.IsNull (bif.FusionLog, "#6");
84                         Assert.AreEqual (bif.GetType ().FullName + ": ",
85                                 bif.ToString (), "#7");
86                 }
87
88                 [Test]
89                 public void Constructor2_Message_Null ()
90                 {
91                         BadImageFormatException bif = new BadImageFormatException ((string) null);
92
93 #if NET_2_0
94                         Assert.IsNotNull (bif.Data, "#1");
95 #endif
96                         Assert.IsNull (bif.FileName, "#2");
97                         Assert.IsNull (bif.InnerException, "#3");
98 #if NET_2_0
99                         Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
100                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
101 #else
102                         Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
103                         Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
104 #endif
105                         Assert.IsNull (bif.FusionLog, "#5");
106                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#6");
107 #if NET_2_0
108                         Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#7");
109 #else
110                         Assert.IsFalse (bif.ToString ().IndexOf ("''") != -1, "#7");
111 #endif
112                 }
113
114                 [Test]
115                 public void Constructor3 ()
116                 {
117                         ArithmeticException ame = new ArithmeticException ("something");
118                         BadImageFormatException bif = new BadImageFormatException ("message",
119                                 ame);
120
121 #if NET_2_0
122                         Assert.IsNotNull (bif.Data, "#1");
123 #endif
124                         Assert.IsNull (bif.FileName, "#2");
125                         Assert.IsNotNull (bif.InnerException, "#3");
126                         Assert.AreSame (ame, bif.InnerException, "#4");
127                         Assert.IsNotNull (bif.Message, "#5");
128                         Assert.AreEqual ("message", bif.Message, "#6");
129                         Assert.IsNull (bif.FusionLog, "#7");
130                         Assert.AreEqual (bif.GetType ().FullName + ": message ---> "
131                                 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
132                 }
133
134                 [Test]
135                 public void Constructor3_Message_Empty ()
136                 {
137                         ArithmeticException ame = new ArithmeticException ("something");
138                         BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
139
140 #if NET_2_0
141                         Assert.IsNotNull (bif.Data, "#1");
142 #endif
143                         Assert.IsNull (bif.FileName, "#2");
144                         Assert.IsNotNull (bif.InnerException, "#3");
145                         Assert.AreSame (ame, bif.InnerException, "#4");
146                         Assert.IsNotNull (bif.Message, "#5");
147                         Assert.AreEqual (string.Empty, bif.Message, "#6");
148                         Assert.IsNull (bif.FusionLog, "#7");
149                         Assert.AreEqual (bif.GetType ().FullName + ":  ---> "
150                                 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
151                 }
152
153                 [Test]
154                 public void Constructor3_Message_Null ()
155                 {
156                         ArithmeticException ame = new ArithmeticException ("something");
157                         BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
158
159 #if NET_2_0
160                         Assert.IsNotNull (bif.Data, "#1");
161 #endif
162                         Assert.IsNull (bif.FileName, "#2");
163                         Assert.IsNotNull (bif.InnerException, "#3");
164                         Assert.AreSame (ame, bif.InnerException, "#4");
165 #if NET_2_0
166                         Assert.IsNotNull (bif.Message, "#5"); // Could not load file or assembly '' ...
167                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#6");
168 #else
169                         Assert.IsNotNull (bif.Message, "#5"); // Format of the executable (.exe) or library ...
170                         Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#6");
171 #endif
172                         Assert.IsNull (bif.FusionLog, "#7");
173                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#8");
174                         Assert.IsTrue (bif.ToString ().IndexOf ("---> " + ame.GetType ().FullName) != -1, "#9");
175                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#10");
176                 }
177
178                 [Test]
179                 public void Constructor3_InnerException_Null ()
180                 {
181                         BadImageFormatException bif = new BadImageFormatException ("message",
182                                 (Exception) null);
183
184 #if NET_2_0
185                         Assert.IsNotNull (bif.Data, "#1");
186 #endif
187                         Assert.IsNull (bif.FileName, "#2");
188                         Assert.IsNull (bif.InnerException, "#3");
189                         Assert.IsNotNull (bif.Message, "#4");
190                         Assert.AreEqual ("message", bif.Message, "#5");
191                         Assert.IsNull (bif.FusionLog, "#6");
192                         Assert.AreEqual (bif.GetType ().FullName + ": message",
193                                 bif.ToString (), "#7");
194                 }
195
196                 [Test]
197                 public void Constructor4 ()
198                 {
199                         BadImageFormatException bif = new BadImageFormatException ("message",
200                                 "file.txt");
201
202 #if NET_2_0
203                         Assert.IsNotNull (bif.Data, "#1");
204 #endif
205                         Assert.IsNotNull (bif.FileName, "#2");
206                         Assert.AreEqual ("file.txt", bif.FileName, "#3");
207                         Assert.IsNull (bif.InnerException, "#4");
208                         Assert.IsNotNull (bif.Message, "#5");
209                         Assert.AreEqual ("message", bif.Message, "#6");
210                         Assert.IsNull (bif.FusionLog, "#7");
211                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
212                                 + ": message" + Environment.NewLine), "#8");
213 #if NET_2_0
214                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
215                         Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
216 #else
217                         Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
218                         Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
219 #endif
220                 }
221
222                 [Test]
223                 public void Constructor4_FileName_Empty ()
224                 {
225                         BadImageFormatException bif = new BadImageFormatException ("message",
226                                 string.Empty);
227
228 #if NET_2_0
229                         Assert.IsNotNull (bif.Data, "#1");
230 #endif
231                         Assert.IsNotNull (bif.FileName, "#2");
232                         Assert.AreEqual (string.Empty, bif.FileName, "#3");
233                         Assert.IsNull (bif.InnerException, "#4");
234                         Assert.IsNotNull (bif.Message, "#5");
235                         Assert.AreEqual ("message", bif.Message, "#6");
236                         Assert.IsNull (bif.FusionLog, "#7");
237                         Assert.AreEqual (bif.GetType ().FullName + ": message",
238                                 bif.ToString (), "#8");
239                 }
240
241                 [Test]
242                 public void Constructor4_FileName_Null ()
243                 {
244                         BadImageFormatException bif = new BadImageFormatException ("message",
245                                 (string) null);
246
247 #if NET_2_0
248                         Assert.IsNotNull (bif.Data, "#A1");
249 #endif
250                         Assert.IsNull (bif.FileName, "#A2");
251                         Assert.IsNull (bif.InnerException, "#A3");
252                         Assert.IsNotNull (bif.Message, "#A4");
253                         Assert.AreEqual ("message", bif.Message, "#A5");
254                         Assert.IsNull (bif.FusionLog, "#A6");
255                         Assert.AreEqual (bif.GetType ().FullName + ": message",
256                                 bif.ToString (), "#A7");
257
258                         bif = new BadImageFormatException (string.Empty, (string) null);
259
260 #if NET_2_0
261                         Assert.IsNotNull (bif.Data, "#B1");
262 #endif
263                         Assert.IsNull (bif.FileName, "#B2");
264                         Assert.IsNull (bif.InnerException, "#B3");
265                         Assert.IsNotNull (bif.Message, "#B4");
266                         Assert.AreEqual (string.Empty, bif.Message, "#B5");
267                         Assert.IsNull (bif.FusionLog, "#B6");
268                         Assert.AreEqual (bif.GetType ().FullName + ": ",
269                                 bif.ToString (), "#B7");
270                 }
271
272                 [Test]
273                 public void Constructor4_FileNameAndMessage_Empty ()
274                 {
275                         BadImageFormatException bif = new BadImageFormatException (string.Empty,
276                                 string.Empty);
277
278 #if NET_2_0
279                         Assert.IsNotNull (bif.Data, "#1");
280 #endif
281                         Assert.IsNotNull (bif.FileName, "#2");
282                         Assert.AreEqual (string.Empty, bif.FileName, "#3");
283                         Assert.IsNull (bif.InnerException, "#4");
284                         Assert.IsNotNull (bif.Message, "#5");
285                         Assert.AreEqual (string.Empty, bif.Message, "#6");
286                         Assert.IsNull (bif.FusionLog, "#7");
287                         Assert.AreEqual (bif.GetType ().FullName + ": ", bif.ToString (), "#8");
288                 }
289
290                 [Test]
291                 public void Constructor4_FileNameAndMessage_Null ()
292                 {
293                         BadImageFormatException bif = new BadImageFormatException ((string) null,
294                                 (string) null);
295
296 #if NET_2_0
297                         Assert.IsNotNull (bif.Data, "#1");
298 #endif
299                         Assert.IsNull (bif.FileName, "#2");
300                         Assert.IsNull (bif.InnerException, "#3");
301 #if NET_2_0
302                         Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
303                         Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
304 #else
305                         Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
306                         Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
307 #endif
308                         Assert.IsNull (bif.FusionLog, "#5");
309                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
310                                 + ": "), "#6");
311                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
312                 }
313
314                 [Test]
315                 public void Constructor4_Message_Empty ()
316                 {
317                         BadImageFormatException bif = null;
318                         
319                         bif = new BadImageFormatException (string.Empty, "file.txt");
320
321 #if NET_2_0
322                         Assert.IsNotNull (bif.Data, "#1");
323 #endif
324                         Assert.IsNotNull (bif.FileName, "#2");
325                         Assert.AreEqual ("file.txt", bif.FileName, "#3");
326                         Assert.IsNull (bif.InnerException, "#4");
327                         Assert.IsNotNull (bif.Message, "#5");
328                         Assert.AreEqual (string.Empty, bif.Message, "#6");
329                         Assert.IsNull (bif.FusionLog, "#7");
330                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
331                                 + ": " + Environment.NewLine), "#8");
332 #if NET_2_0
333                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
334                         Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
335 #else
336                         Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
337                         Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
338 #endif
339                 }
340
341                 [Test]
342                 public void Constructor4_Message_Null ()
343                 {
344                         BadImageFormatException bif = null;
345                         
346                         bif = new BadImageFormatException ((string) null, "file.txt");
347
348 #if NET_2_0
349                         Assert.IsNotNull (bif.Data, "#A1");
350 #endif
351                         Assert.IsNotNull (bif.FileName, "#A2");
352                         Assert.AreEqual ("file.txt", bif.FileName, "#A3");
353                         Assert.IsNull (bif.InnerException, "#A4");
354                         Assert.IsNotNull (bif.Message, "#A5");
355                         Assert.IsNull (bif.FusionLog, "#A6");
356                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
357                                 + ": "), "#A7");
358                         Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
359                         Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
360
361                         bif = new BadImageFormatException ((string) null, string.Empty);
362
363 #if NET_2_0
364                         Assert.IsNotNull (bif.Data, "#B1");
365 #endif
366                         Assert.IsNotNull (bif.FileName, "#B2");
367                         Assert.AreEqual (string.Empty, bif.FileName, "#B3");
368                         Assert.IsNull (bif.InnerException, "#B4");
369                         // .NET 1.1: The format of the file 'file.txt' is invalid
370                         // .NET 2.0: Could not load file or assembly 'file.txt' or one of its ...
371                         Assert.IsNotNull (bif.Message, "#B5");
372                         Assert.IsNull (bif.FusionLog, "#B6");
373                         Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
374                                 + ": "), "#B7");
375                         Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
376                         Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");
377                 }
378         }
379 }