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