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 Assert.AreEqual (bif.GetType ().FullName + ": message",
68 bif.ToString (), "#7");
72 public void Constructor2_Message_Empty ()
74 BadImageFormatException bif = new BadImageFormatException (string.Empty);
77 Assert.IsNotNull (bif.Data, "#1");
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");
89 public void Constructor2_Message_Null ()
91 BadImageFormatException bif = new BadImageFormatException ((string) null);
94 Assert.IsNotNull (bif.Data, "#1");
96 Assert.IsNull (bif.FileName, "#2");
97 Assert.IsNull (bif.InnerException, "#3");
99 Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
100 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
102 Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
103 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
105 Assert.IsNull (bif.FusionLog, "#5");
106 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName), "#6");
108 Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#7");
110 Assert.IsFalse (bif.ToString ().IndexOf ("''") != -1, "#7");
115 public void Constructor3 ()
117 ArithmeticException ame = new ArithmeticException ("something");
118 BadImageFormatException bif = new BadImageFormatException ("message",
122 Assert.IsNotNull (bif.Data, "#1");
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");
135 public void Constructor3_Message_Empty ()
137 ArithmeticException ame = new ArithmeticException ("something");
138 BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
141 Assert.IsNotNull (bif.Data, "#1");
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");
154 public void Constructor3_Message_Null ()
156 ArithmeticException ame = new ArithmeticException ("something");
157 BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
160 Assert.IsNotNull (bif.Data, "#1");
162 Assert.IsNull (bif.FileName, "#2");
163 Assert.IsNotNull (bif.InnerException, "#3");
164 Assert.AreSame (ame, bif.InnerException, "#4");
166 Assert.IsNotNull (bif.Message, "#5"); // Could not load file or assembly '' ...
167 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#6");
169 Assert.IsNotNull (bif.Message, "#5"); // Format of the executable (.exe) or library ...
170 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#6");
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");
179 public void Constructor3_InnerException_Null ()
181 BadImageFormatException bif = new BadImageFormatException ("message",
185 Assert.IsNotNull (bif.Data, "#1");
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");
197 public void Constructor4 ()
199 BadImageFormatException bif = new BadImageFormatException ("message",
203 Assert.IsNotNull (bif.Data, "#1");
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");
214 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
215 Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
217 Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
218 Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
223 public void Constructor4_FileName_Empty ()
225 BadImageFormatException bif = new BadImageFormatException ("message",
229 Assert.IsNotNull (bif.Data, "#1");
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");
242 public void Constructor4_FileName_Null ()
244 BadImageFormatException bif = new BadImageFormatException ("message",
248 Assert.IsNotNull (bif.Data, "#A1");
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");
258 bif = new BadImageFormatException (string.Empty, (string) null);
261 Assert.IsNotNull (bif.Data, "#B1");
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");
273 public void Constructor4_FileNameAndMessage_Empty ()
275 BadImageFormatException bif = new BadImageFormatException (string.Empty,
279 Assert.IsNotNull (bif.Data, "#1");
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");
291 public void Constructor4_FileNameAndMessage_Null ()
293 BadImageFormatException bif = new BadImageFormatException ((string) null,
297 Assert.IsNotNull (bif.Data, "#1");
299 Assert.IsNull (bif.FileName, "#2");
300 Assert.IsNull (bif.InnerException, "#3");
302 Assert.IsNotNull (bif.Message, "#4"); // Could not load file or assembly '' ...
303 Assert.IsTrue (bif.Message.IndexOf ("''") != -1, "#5");
305 Assert.IsNotNull (bif.Message, "#4"); // Format of the executable (.exe) or library ...
306 Assert.IsFalse (bif.Message.IndexOf ("''") != -1, "#5");
308 Assert.IsNull (bif.FusionLog, "#5");
309 Assert.IsTrue (bif.ToString ().StartsWith (bif.GetType ().FullName
311 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
315 public void Constructor4_Message_Empty ()
317 BadImageFormatException bif = null;
319 bif = new BadImageFormatException (string.Empty, "file.txt");
322 Assert.IsNotNull (bif.Data, "#1");
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");
333 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
334 Assert.IsFalse (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
336 Assert.IsFalse (bif.ToString ().IndexOf ("'file.txt'") != -1, "#9");
337 Assert.IsTrue (bif.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
342 public void Constructor4_Message_Null ()
344 BadImageFormatException bif = null;
346 bif = new BadImageFormatException ((string) null, "file.txt");
349 Assert.IsNotNull (bif.Data, "#A1");
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
358 Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
359 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
361 bif = new BadImageFormatException ((string) null, string.Empty);
364 Assert.IsNotNull (bif.Data, "#B1");
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
375 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
376 Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");