2 // BadImageFormatExceptionTest.cs - Unit tests for
3 // System.BadImageFormatException
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using NUnit.Framework;
34 namespace MonoTests.System
37 public class BadImageFormatExceptionTest
40 public void Constructor1 ()
42 BadImageFormatException bif = new BadImageFormatException ();
45 Assert.IsNotNull (bif.Data, "#1");
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");
55 public void Constructor2 ()
57 BadImageFormatException bif = new BadImageFormatException ("message");
60 Assert.IsNotNull (bif.Data, "#1");
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 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
68 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName + ": message"), "#7");
70 Assert.AreEqual (bif.GetType ().FullName + ": message",
71 bif.ToString (), "#7");
76 public void Constructor2_Message_Empty ()
78 BadImageFormatException bif = new BadImageFormatException (string.Empty);
81 Assert.IsNotNull (bif.Data, "#1");
83 Assert.IsNull (bif.FileName, "#2");
84 Assert.IsNull (bif.InnerException, "#3");
85 Assert.IsNotNull (bif.Message, "#4");
86 Assert.AreEqual (string.Empty, bif.Message, "#5");
87 Assert.IsNull (bif.FusionLog, "#6");
88 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
89 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#7");
91 Assert.AreEqual (bif.GetType ().FullName + ": ",
92 bif.ToString (), "#7");
97 public void Constructor2_Message_Null ()
99 BadImageFormatException bif = new BadImageFormatException ((string) null);
102 Assert.IsNotNull (bif.Data, "#1");
104 Assert.IsNull (bif.FileName, "#2");
105 Assert.IsNull (bif.InnerException, "#3");
107 Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
108 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
110 Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
111 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
113 Assert.IsNull (bif.FusionLog, "#5");
114 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#6");
116 Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#7");
118 Assert.IsFalse (bif.ToString ().IndexOf ("''") != -1, "#7");
123 public void Constructor3 ()
125 ArithmeticException ame = new ArithmeticException ("something");
126 BadImageFormatException bif = new BadImageFormatException ("message",
130 Assert.IsNotNull (bif.Data, "#1");
132 Assert.IsNull (bif.FileName, "#2");
133 Assert.IsNotNull (bif.InnerException, "#3");
134 Assert.AreSame (ame, bif.InnerException, "#4");
135 Assert.IsNotNull (bif.Message, "#5");
136 Assert.AreEqual ("message", bif.Message, "#6");
137 Assert.IsNull (bif.FusionLog, "#7");
138 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
139 Assert.IsTrue (bif.ToString ().IndexOf (ame.GetType ().FullName + ": something") != -1, "#8");
141 Assert.AreEqual (bif.GetType ().FullName + ": message ---> "
142 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
147 public void Constructor3_Message_Empty ()
149 ArithmeticException ame = new ArithmeticException ("something");
150 BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
153 Assert.IsNotNull (bif.Data, "#1");
155 Assert.IsNull (bif.FileName, "#2");
156 Assert.IsNotNull (bif.InnerException, "#3");
157 Assert.AreSame (ame, bif.InnerException, "#4");
158 Assert.IsNotNull (bif.Message, "#5");
159 Assert.AreEqual (string.Empty, bif.Message, "#6");
160 Assert.IsNull (bif.FusionLog, "#7");
161 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
162 Assert.IsTrue (bif.ToString ().IndexOf (ame.GetType ().FullName + ": something") != -1, "#8");
164 Assert.AreEqual (bif.GetType ().FullName + ": ---> "
165 + ame.GetType ().FullName + ": something", bif.ToString (), "#8");
170 public void Constructor3_Message_Null ()
172 ArithmeticException ame = new ArithmeticException ("something");
173 BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
176 Assert.IsNotNull (bif.Data, "#1");
178 Assert.IsNull (bif.FileName, "#2");
179 Assert.IsNotNull (bif.InnerException, "#3");
180 Assert.AreSame (ame, bif.InnerException, "#4");
182 Assert.IsNotNull (bif.Message, "#5"); // Could not load file or assembly '' ...
183 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#6");
185 Assert.IsNotNull (bif.Message, "#5"); // Format of the executable (.exe) or library ...
186 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#6");
188 Assert.IsNull (bif.FusionLog, "#7");
189 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#8");
190 Assert.IsTrue (bif.ToString ().IndexOf ("---> " + ame.GetType ().FullName) != -1, "#9");
191 #if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
192 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#10");
197 public void Constructor3_InnerException_Null ()
199 BadImageFormatException bif = new BadImageFormatException ("message",
203 Assert.IsNotNull (bif.Data, "#1");
205 Assert.IsNull (bif.FileName, "#2");
206 Assert.IsNull (bif.InnerException, "#3");
207 Assert.IsNotNull (bif.Message, "#4");
208 Assert.AreEqual ("message", bif.Message, "#5");
209 Assert.IsNull (bif.FusionLog, "#6");
210 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
211 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#7");
213 Assert.AreEqual (bif.GetType ().FullName + ": message",
214 bif.ToString (), "#7");
219 public void Constructor4 ()
221 BadImageFormatException bif = new BadImageFormatException ("message",
225 Assert.IsNotNull (bif.Data, "#1");
227 Assert.IsNotNull (bif.FileName, "#2");
228 Assert.AreEqual ("file.txt", bif.FileName, "#3");
229 Assert.IsNull (bif.InnerException, "#4");
230 Assert.IsNotNull (bif.Message, "#5");
231 Assert.AreEqual ("message", bif.Message, "#6");
232 Assert.IsNull (bif.FusionLog, "#7");
233 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
234 + ": message" + Environment.NewLine), "#8");
236 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
237 Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
239 Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
240 Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
245 public void Constructor4_FileName_Empty ()
247 BadImageFormatException bif = new BadImageFormatException ("message",
251 Assert.IsNotNull (bif.Data, "#1");
253 Assert.IsNotNull (bif.FileName, "#2");
254 Assert.AreEqual (string.Empty, bif.FileName, "#3");
255 Assert.IsNull (bif.InnerException, "#4");
256 Assert.IsNotNull (bif.Message, "#5");
257 Assert.AreEqual ("message", bif.Message, "#6");
258 Assert.IsNull (bif.FusionLog, "#7");
259 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
260 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#8");
262 Assert.AreEqual (bif.GetType ().FullName + ": message",
263 bif.ToString (), "#8");
268 public void Constructor4_FileName_Null ()
270 BadImageFormatException bif = new BadImageFormatException ("message",
274 Assert.IsNotNull (bif.Data, "#A1");
276 Assert.IsNull (bif.FileName, "#A2");
277 Assert.IsNull (bif.InnerException, "#A3");
278 Assert.IsNotNull (bif.Message, "#A4");
279 Assert.AreEqual ("message", bif.Message, "#A5");
280 Assert.IsNull (bif.FusionLog, "#A6");
281 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
282 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": message"), "#A7");
284 Assert.AreEqual (bif.GetType ().FullName + ": message",
285 bif.ToString (), "#A7");
288 bif = new BadImageFormatException (string.Empty, (string) null);
291 Assert.IsNotNull (bif.Data, "#B1");
293 Assert.IsNull (bif.FileName, "#B2");
294 Assert.IsNull (bif.InnerException, "#B3");
295 Assert.IsNotNull (bif.Message, "#B4");
296 Assert.AreEqual (string.Empty, bif.Message, "#B5");
297 Assert.IsNull (bif.FusionLog, "#B6");
298 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
299 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#B7");
301 Assert.AreEqual (bif.GetType ().FullName + ": ",
302 bif.ToString (), "#B7");
307 public void Constructor4_FileNameAndMessage_Empty ()
309 BadImageFormatException bif = new BadImageFormatException (string.Empty,
313 Assert.IsNotNull (bif.Data, "#1");
315 Assert.IsNotNull (bif.FileName, "#2");
316 Assert.AreEqual (string.Empty, bif.FileName, "#3");
317 Assert.IsNull (bif.InnerException, "#4");
318 Assert.IsNotNull (bif.Message, "#5");
319 Assert.AreEqual (string.Empty, bif.Message, "#6");
320 Assert.IsNull (bif.FusionLog, "#7");
321 #if TARGET_JVM // ToString always has a stack trace under TARGET_JVM
322 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType().FullName + ": "), "#8");
324 Assert.AreEqual (bif.GetType ().FullName + ": ", bif.ToString (), "#8");
329 public void Constructor4_FileNameAndMessage_Null ()
331 BadImageFormatException bif = new BadImageFormatException ((string) null,
335 Assert.IsNotNull (bif.Data, "#1");
337 Assert.IsNull (bif.FileName, "#2");
338 Assert.IsNull (bif.InnerException, "#3");
340 Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
341 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
343 Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
344 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
346 Assert.IsNull (bif.FusionLog, "#5");
347 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
349 #if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
350 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
355 public void Constructor4_Message_Empty ()
357 BadImageFormatException bif = null;
359 bif = new BadImageFormatException (string.Empty, "file.txt");
362 Assert.IsNotNull (bif.Data, "#1");
364 Assert.IsNotNull (bif.FileName, "#2");
365 Assert.AreEqual ("file.txt", bif.FileName, "#3");
366 Assert.IsNull (bif.InnerException, "#4");
367 Assert.IsNotNull (bif.Message, "#5");
368 Assert.AreEqual (string.Empty, bif.Message, "#6");
369 Assert.IsNull (bif.FusionLog, "#7");
370 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
371 + ": " + Environment.NewLine), "#8");
373 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
374 Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
376 Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
377 Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
382 public void Constructor4_Message_Null ()
384 BadImageFormatException bif = null;
386 bif = new BadImageFormatException ((string) null, "file.txt");
389 Assert.IsNotNull (bif.Data, "#A1");
391 Assert.IsNotNull (bif.FileName, "#A2");
392 Assert.AreEqual ("file.txt", bif.FileName, "#A3");
393 Assert.IsNull (bif.InnerException, "#A4");
394 Assert.IsNotNull (bif.Message, "#A5");
395 Assert.IsNull (bif.FusionLog, "#A6");
396 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
398 Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
399 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
401 bif = new BadImageFormatException ((string) null, string.Empty);
404 Assert.IsNotNull (bif.Data, "#B1");
406 Assert.IsNotNull (bif.FileName, "#B2");
407 Assert.AreEqual (string.Empty, bif.FileName, "#B3");
408 Assert.IsNull (bif.InnerException, "#B4");
409 // .NET 1.1: The format of the file 'file.txt' is invalid
410 // .NET 2.0: Could not load file or assembly 'file.txt' or one of its ...
411 Assert.IsNotNull (bif.Message, "#B5");
412 Assert.IsNull (bif.FusionLog, "#B6");
413 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
415 #if !TARGET_JVM // ToString always has a stack trace under TARGET_JVM
416 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
418 Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");