Fixed the tests checking for PlatformID.
[mono.git] / mcs / class / corlib / Test / System.IO / FileNotFoundExceptionTest.cs
1 //
2 // FileNotFoundExceptionTest.cs - Unit tests for
3 //      System.IO.FileNotFoundException
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 using System.IO;
32
33 using NUnit.Framework;
34
35 namespace MonoTests.System.IO {
36         [TestFixture]
37         public class FileNotFoundExceptionTest {
38                 [Test]
39                 public void Constructor1 ()
40                 {
41                         FileNotFoundException fnf = new FileNotFoundException ();
42
43 #if NET_2_0
44                         Assert.IsNotNull (fnf.Data, "#1");
45 #endif
46                         Assert.IsNull (fnf.FileName, "#2");
47                         Assert.IsNull (fnf.InnerException, "#3");
48                         Assert.IsNotNull (fnf.Message, "#4"); // Unable to find the specified file
49                         Assert.IsNull (fnf.FusionLog, "#5");
50                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType().FullName), "#6");
51                 }
52
53                 [Test]
54                 public void Constructor2 ()
55                 {
56                         FileNotFoundException fnf = new FileNotFoundException ("message");
57
58 #if NET_2_0
59                         Assert.IsNotNull (fnf.Data, "#1");
60 #endif
61                         Assert.IsNull (fnf.FileName, "#2");
62                         Assert.IsNull (fnf.InnerException, "#3");
63                         Assert.IsNotNull (fnf.Message, "#4");
64                         Assert.AreEqual ("message", fnf.Message, "#5");
65                         Assert.IsNull (fnf.FusionLog, "#6");
66 #if TARGET_JVM
67             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"),"#7");
68 #else
69                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
70                                 fnf.ToString (), "#7");
71 #endif
72                 }
73
74                 [Test]
75                 public void Constructor2_Message_Empty ()
76                 {
77                         FileNotFoundException fnf = new FileNotFoundException (string.Empty);
78
79 #if NET_2_0
80                         Assert.IsNotNull (fnf.Data, "#1");
81 #endif
82                         Assert.IsNull (fnf.FileName, "#2");
83                         Assert.IsNull (fnf.InnerException, "#3");
84                         Assert.IsNotNull (fnf.Message, "#4");
85                         Assert.AreEqual (string.Empty, fnf.Message, "#5");
86                         Assert.IsNull (fnf.FusionLog, "#6");
87 #if TARGET_JVM
88             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#7");
89 #else
90                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
91                                 fnf.ToString (), "#7");
92 #endif
93                 }
94
95                 [Test]
96                 public void Constructor2_Message_Null ()
97                 {
98                         FileNotFoundException fnf = new FileNotFoundException ((string) null);
99
100 #if NET_2_0
101                         Assert.IsNotNull (fnf.Data, "#1");
102 #endif
103                         Assert.IsNull (fnf.FileName, "#2");
104                         Assert.IsNull (fnf.InnerException, "#3");
105 #if NET_2_0
106                         Assert.IsNull (fnf.Message, "#4");
107 #else
108                         Assert.IsNotNull (fnf.Message, "#4"); // File or assembly name (null), or ...
109 #endif
110                         Assert.IsNull (fnf.FusionLog, "#5");
111 #if NET_2_0 && !TARGET_JVM
112                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
113                                 fnf.ToString (), "#6");
114 #else
115                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#6");
116 #endif
117                 }
118
119                 [Test]
120                 public void Constructor3 ()
121                 {
122                         ArithmeticException ame = new ArithmeticException ("something");
123                         FileNotFoundException fnf = new FileNotFoundException ("message",
124                                 ame);
125
126 #if NET_2_0
127                         Assert.IsNotNull (fnf.Data, "#1");
128 #endif
129                         Assert.IsNull (fnf.FileName, "#2");
130                         Assert.IsNotNull (fnf.InnerException, "#3");
131                         Assert.AreSame (ame, fnf.InnerException, "#4");
132                         Assert.IsNotNull (fnf.Message, "#5");
133                         Assert.AreEqual ("message", fnf.Message, "#6");
134                         Assert.IsNull (fnf.FusionLog, "#7");
135 #if TARGET_JVM
136             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message ---> "
137                 + ame.GetType().FullName + ": something"), "#8");
138 #else
139                         Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
140                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
141 #endif
142                 }
143
144                 [Test]
145                 public void Constructor3_Message_Empty ()
146                 {
147                         ArithmeticException ame = new ArithmeticException ("something");
148                         FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
149
150 #if NET_2_0
151                         Assert.IsNotNull (fnf.Data, "#1");
152 #endif
153                         Assert.IsNull (fnf.FileName, "#2");
154                         Assert.IsNotNull (fnf.InnerException, "#3");
155                         Assert.AreSame (ame, fnf.InnerException, "#4");
156                         Assert.IsNotNull (fnf.Message, "#5");
157                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
158                         Assert.IsNull (fnf.FusionLog, "#7");
159 #if TARGET_JVM
160             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ":  ---> "
161                 + ame.GetType().FullName + ": something"), "#8");
162 #else
163                         Assert.AreEqual (fnf.GetType ().FullName + ":  ---> "
164                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
165 #endif
166                 }
167
168                 [Test]
169                 public void Constructor3_Message_Null ()
170                 {
171                         ArithmeticException ame = new ArithmeticException ("something");
172                         FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
173
174 #if NET_2_0
175                         Assert.IsNotNull (fnf.Data, "#1");
176 #endif
177                         Assert.IsNull (fnf.FileName, "#2");
178                         Assert.IsNotNull (fnf.InnerException, "#3");
179                         Assert.AreSame (ame, fnf.InnerException, "#4");
180 #if NET_2_0
181                         Assert.IsNull (fnf.Message, "#5");
182 #else
183                         Assert.IsNotNull (fnf.Message, "#5"); // File or assembly name (null), or ...
184 #endif
185                         Assert.IsNull (fnf.FusionLog, "#6");
186 #if NET_2_0
187 #if TARGET_JVM
188             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ":  ---> "
189                 + ame.GetType().FullName + ": something"), "#7");
190 #else
191                         Assert.AreEqual (fnf.GetType ().FullName + ":  ---> "
192                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
193 #endif
194 #else
195                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName), "#7");
196                         Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#9");
197 #endif
198                 }
199
200                 [Test]
201                 public void Constructor3_InnerException_Null ()
202                 {
203                         FileNotFoundException fnf = new FileNotFoundException ("message",
204                                 (Exception) null);
205
206 #if NET_2_0
207                         Assert.IsNotNull (fnf.Data, "#1");
208 #endif
209                         Assert.IsNull (fnf.FileName, "#2");
210                         Assert.IsNull (fnf.InnerException, "#3");
211                         Assert.IsNotNull (fnf.Message, "#4");
212                         Assert.AreEqual ("message", fnf.Message, "#5");
213                         Assert.IsNull (fnf.FusionLog, "#6");
214 #if TARGET_JVM
215             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#7");
216 #else
217                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
218                                 fnf.ToString (), "#7");
219 #endif
220                 }
221
222                 [Test]
223                 public void Constructor4 ()
224                 {
225                         FileNotFoundException fnf = new FileNotFoundException ("message",
226                                 "file.txt");
227
228 #if NET_2_0
229                         Assert.IsNotNull (fnf.Data, "#1");
230 #endif
231                         Assert.IsNotNull (fnf.FileName, "#2");
232                         Assert.AreEqual ("file.txt", fnf.FileName, "#3");
233                         Assert.IsNull (fnf.InnerException, "#4");
234                         Assert.IsNotNull (fnf.Message, "#5");
235                         Assert.AreEqual ("message", fnf.Message, "#6");
236                         Assert.IsNull (fnf.FusionLog, "#7");
237                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
238                                 + ": message" + Environment.NewLine), "#8");
239 #if NET_2_0
240                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
241                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
242 #else
243                         Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
244                         Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
245 #endif
246                 }
247
248                 [Test]
249                 public void Constructor4_FileName_Empty ()
250                 {
251                         FileNotFoundException fnf = new FileNotFoundException ("message",
252                                 string.Empty);
253
254 #if NET_2_0
255                         Assert.IsNotNull (fnf.Data, "#1");
256 #endif
257                         Assert.IsNotNull (fnf.FileName, "#2");
258                         Assert.AreEqual (string.Empty, fnf.FileName, "#3");
259                         Assert.IsNull (fnf.InnerException, "#4");
260                         Assert.IsNotNull (fnf.Message, "#5");
261                         Assert.AreEqual ("message", fnf.Message, "#6");
262                         Assert.IsNull (fnf.FusionLog, "#7");
263 #if TARGET_JVM
264             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#8");
265 #else
266                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
267                                 fnf.ToString (), "#8");
268 #endif
269                 }
270
271                 [Test]
272                 public void Constructor4_FileName_Null ()
273                 {
274                         FileNotFoundException fnf = new FileNotFoundException ("message",
275                                 (string) null);
276
277 #if NET_2_0
278                         Assert.IsNotNull (fnf.Data, "#A1");
279 #endif
280                         Assert.IsNull (fnf.FileName, "#A2");
281                         Assert.IsNull (fnf.InnerException, "#A3");
282                         Assert.IsNotNull (fnf.Message, "#A4");
283                         Assert.AreEqual ("message", fnf.Message, "#A5");
284                         Assert.IsNull (fnf.FusionLog, "#A6");
285 #if TARGET_JVM
286             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": message"), "#A7");
287 #else
288                 
289                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
290                                 fnf.ToString (), "#A7");
291 #endif
292
293                         fnf = new FileNotFoundException (string.Empty, (string) null);
294
295 #if NET_2_0
296                         Assert.IsNotNull (fnf.Data, "#B1");
297 #endif
298                         Assert.IsNull (fnf.FileName, "#B2");
299                         Assert.IsNull (fnf.InnerException, "#B3");
300                         Assert.IsNotNull (fnf.Message, "#B4");
301                         Assert.AreEqual (string.Empty, fnf.Message, "#B5");
302                         Assert.IsNull (fnf.FusionLog, "#B6");
303 #if TARGET_JVM
304             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#B7");
305 #else
306                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
307                                 fnf.ToString (), "#B7");
308 #endif
309                 }
310
311                 [Test]
312                 public void Constructor4_FileNameAndMessage_Empty ()
313                 {
314                         FileNotFoundException fnf = new FileNotFoundException (string.Empty,
315                                 string.Empty);
316
317 #if NET_2_0
318                         Assert.IsNotNull (fnf.Data, "#1");
319 #endif
320                         Assert.IsNotNull (fnf.FileName, "#2");
321                         Assert.AreEqual (string.Empty, fnf.FileName, "#3");
322                         Assert.IsNull (fnf.InnerException, "#4");
323                         Assert.IsNotNull (fnf.Message, "#5");
324                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
325                         Assert.IsNull (fnf.FusionLog, "#7");
326 #if TARGET_JVM
327             Assert.IsTrue(fnf.ToString().StartsWith(fnf.GetType().FullName + ": "), "#8");
328 #else
329                         Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
330 #endif
331                 }
332
333                 [Test]
334                 public void Constructor4_FileNameAndMessage_Null ()
335                 {
336                         FileNotFoundException fnf = new FileNotFoundException ((string) null,
337                                 (string) null);
338
339 #if NET_2_0
340                         Assert.IsNotNull (fnf.Data, "#1");
341 #endif
342                         Assert.IsNull (fnf.FileName, "#2");
343                         Assert.IsNull (fnf.InnerException, "#3");
344 #if NET_2_0
345                         Assert.IsNull (fnf.Message, "#4");
346 #else
347                         Assert.IsNotNull (fnf.Message, "#4");
348 #endif
349                         Assert.IsNull (fnf.FusionLog, "#5");
350                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
351                                 + ": "), "#6");
352 #if !TARGET_JVM
353                         Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
354 #endif
355                         Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
356                 }
357
358                 [Test]
359                 public void Constructor4_Message_Empty ()
360                 {
361                         FileNotFoundException fnf = null;
362                         
363                         fnf = new FileNotFoundException (string.Empty, "file.txt");
364
365 #if NET_2_0
366                         Assert.IsNotNull (fnf.Data, "#1");
367 #endif
368                         Assert.IsNotNull (fnf.FileName, "#2");
369                         Assert.AreEqual ("file.txt", fnf.FileName, "#3");
370                         Assert.IsNull (fnf.InnerException, "#4");
371                         Assert.IsNotNull (fnf.Message, "#5");
372                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
373                         Assert.IsNull (fnf.FusionLog, "#7");
374                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
375                                 + ": " + Environment.NewLine), "#8");
376 #if NET_2_0
377                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
378                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
379 #else
380                         Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
381                         Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
382 #endif
383                 }
384
385                 [Test]
386                 public void Constructor4_Message_Null ()
387                 {
388                         FileNotFoundException fnf = null;
389                         
390                         fnf = new FileNotFoundException ((string) null, "file.txt");
391
392 #if NET_2_0
393                         Assert.IsNotNull (fnf.Data, "#A1");
394 #endif
395                         Assert.IsNotNull (fnf.FileName, "#A2");
396                         Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
397                         Assert.IsNull (fnf.InnerException, "#A4");
398                         Assert.IsNotNull (fnf.Message, "#A5");
399                         Assert.IsNull (fnf.FusionLog, "#A6");
400                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
401                                 + ": "), "#A7");
402                         Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
403 #if NET_2_0
404                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
405                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
406 #else
407                         Assert.IsFalse (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
408                         Assert.IsTrue (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
409 #endif
410
411                         fnf = new FileNotFoundException ((string) null, string.Empty);
412
413 #if NET_2_0
414                         Assert.IsNotNull (fnf.Data, "#B1");
415 #endif
416                         Assert.IsNotNull (fnf.FileName, "#B2");
417                         Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
418                         Assert.IsNull (fnf.InnerException, "#B4");
419                         // .NET 1.1: File or assembly name , or one of its dependencies ...
420                         // .NET 2.0: Could not load file or assembly '' or one of its ...
421                         Assert.IsNotNull (fnf.Message, "#B5");
422                         Assert.IsNull (fnf.FusionLog, "#B6");
423                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
424                                 + ": "), "#B7");
425 #if !TARGET_JVM
426                         Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
427 #endif
428 #if NET_2_0
429                         Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
430 #else
431                         Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#B9");
432                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"\"") != -1, "#B10");
433 #endif
434                 }
435         }
436 }