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 ();
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");
53 public void Constructor2 ()
55 BadImageFormatException bif = new BadImageFormatException ("message");
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");
68 public void Constructor2_Message_Empty ()
70 BadImageFormatException bif = new BadImageFormatException (string.Empty);
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");
83 public void Constructor2_Message_Null ()
85 BadImageFormatException bif = new BadImageFormatException ((string) null);
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");
98 public void Constructor3 ()
100 ArithmeticException ame = new ArithmeticException ("something");
101 BadImageFormatException bif = new BadImageFormatException ("message",
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");
116 public void Constructor3_Message_Empty ()
118 ArithmeticException ame = new ArithmeticException ("something");
119 BadImageFormatException bif = new BadImageFormatException (string.Empty, ame);
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");
133 public void Constructor3_Message_Null ()
135 ArithmeticException ame = new ArithmeticException ("something");
136 BadImageFormatException bif = new BadImageFormatException ((string) null, ame);
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");
151 public void Constructor3_InnerException_Null ()
153 BadImageFormatException bif = new BadImageFormatException ("message",
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");
167 public void Constructor4 ()
169 BadImageFormatException bif = new BadImageFormatException ("message",
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");
186 public void Constructor4_FileName_Empty ()
188 BadImageFormatException bif = new BadImageFormatException ("message",
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");
203 public void Constructor4_FileName_Null ()
205 BadImageFormatException bif = new BadImageFormatException ("message",
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");
217 bif = new BadImageFormatException (string.Empty, (string) null);
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");
230 public void Constructor4_FileNameAndMessage_Empty ()
232 BadImageFormatException bif = new BadImageFormatException (string.Empty,
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");
246 public void Constructor4_FileNameAndMessage_Null ()
248 BadImageFormatException bif = new BadImageFormatException ((string) null,
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
259 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
263 public void Constructor4_Message_Empty ()
265 BadImageFormatException bif = null;
267 bif = new BadImageFormatException (string.Empty, "file.txt");
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");
283 public void Constructor4_Message_Null ()
285 BadImageFormatException bif = null;
287 bif = new BadImageFormatException ((string) null, "file.txt");
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
297 Assert.IsTrue (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
298 Assert.IsTrue (bif.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
300 bif = new BadImageFormatException ((string) null, string.Empty);
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
312 Assert.IsFalse (bif.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
313 Assert.IsTrue (bif.ToString ().IndexOf ("''") != -1, "#B9");