Merge pull request #5714 from alexischr/update_bockbuild
[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                         Assert.IsNotNull (fnf.Data, "#1");
44                         Assert.IsNull (fnf.FileName, "#2");
45                         Assert.IsNull (fnf.InnerException, "#3");
46                         Assert.IsNotNull (fnf.Message, "#4"); // Unable to find the specified file
47                         Assert.IsNull (fnf.FusionLog, "#5");
48                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType().FullName), "#6");
49                 }
50
51                 [Test]
52                 public void Constructor2 ()
53                 {
54                         FileNotFoundException fnf = new FileNotFoundException ("message");
55
56                         Assert.IsNotNull (fnf.Data, "#1");
57                         Assert.IsNull (fnf.FileName, "#2");
58                         Assert.IsNull (fnf.InnerException, "#3");
59                         Assert.IsNotNull (fnf.Message, "#4");
60                         Assert.AreEqual ("message", fnf.Message, "#5");
61                         Assert.IsNull (fnf.FusionLog, "#6");
62                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
63                                 fnf.ToString (), "#7");
64                 }
65
66                 [Test]
67                 public void Constructor2_Message_Empty ()
68                 {
69                         FileNotFoundException fnf = new FileNotFoundException (string.Empty);
70
71                         Assert.IsNotNull (fnf.Data, "#1");
72                         Assert.IsNull (fnf.FileName, "#2");
73                         Assert.IsNull (fnf.InnerException, "#3");
74                         Assert.IsNotNull (fnf.Message, "#4");
75                         Assert.AreEqual (string.Empty, fnf.Message, "#5");
76                         Assert.IsNull (fnf.FusionLog, "#6");
77                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
78                                 fnf.ToString (), "#7");
79                 }
80
81                 [Test]
82                 public void Constructor2_Message_Null ()
83                 {
84                         FileNotFoundException fnf = new FileNotFoundException ((string) null);
85
86                         Assert.IsNotNull (fnf.Data, "#1");
87                         Assert.IsNull (fnf.FileName, "#2");
88                         Assert.IsNull (fnf.InnerException, "#3");
89                         Assert.IsNull (fnf.Message, "#4");
90                         Assert.IsNull (fnf.FusionLog, "#5");
91                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
92                                 fnf.ToString (), "#6");
93                 }
94
95                 [Test]
96                 public void Constructor3 ()
97                 {
98                         ArithmeticException ame = new ArithmeticException ("something");
99                         FileNotFoundException fnf = new FileNotFoundException ("message",
100                                 ame);
101
102                         Assert.IsNotNull (fnf.Data, "#1");
103                         Assert.IsNull (fnf.FileName, "#2");
104                         Assert.IsNotNull (fnf.InnerException, "#3");
105                         Assert.AreSame (ame, fnf.InnerException, "#4");
106                         Assert.IsNotNull (fnf.Message, "#5");
107                         Assert.AreEqual ("message", fnf.Message, "#6");
108                         Assert.IsNull (fnf.FusionLog, "#7");
109                         Assert.AreEqual (fnf.GetType ().FullName + ": message ---> "
110                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
111                 }
112
113                 [Test]
114                 public void Constructor3_Message_Empty ()
115                 {
116                         ArithmeticException ame = new ArithmeticException ("something");
117                         FileNotFoundException fnf = new FileNotFoundException (string.Empty, ame);
118
119                         Assert.IsNotNull (fnf.Data, "#1");
120                         Assert.IsNull (fnf.FileName, "#2");
121                         Assert.IsNotNull (fnf.InnerException, "#3");
122                         Assert.AreSame (ame, fnf.InnerException, "#4");
123                         Assert.IsNotNull (fnf.Message, "#5");
124                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
125                         Assert.IsNull (fnf.FusionLog, "#7");
126                         Assert.AreEqual (fnf.GetType ().FullName + ":  ---> "
127                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#8");
128                 }
129
130                 [Test]
131                 public void Constructor3_Message_Null ()
132                 {
133                         ArithmeticException ame = new ArithmeticException ("something");
134                         FileNotFoundException fnf = new FileNotFoundException ((string) null, ame);
135
136                         Assert.IsNotNull (fnf.Data, "#1");
137                         Assert.IsNull (fnf.FileName, "#2");
138                         Assert.IsNotNull (fnf.InnerException, "#3");
139                         Assert.AreSame (ame, fnf.InnerException, "#4");
140                         Assert.IsNull (fnf.Message, "#5");
141                         Assert.IsNull (fnf.FusionLog, "#6");
142                         Assert.AreEqual (fnf.GetType ().FullName + ":  ---> "
143                                 + ame.GetType ().FullName + ": something", fnf.ToString (), "#7");
144                 }
145
146                 [Test]
147                 public void Constructor3_InnerException_Null ()
148                 {
149                         FileNotFoundException fnf = new FileNotFoundException ("message",
150                                 (Exception) null);
151
152                         Assert.IsNotNull (fnf.Data, "#1");
153                         Assert.IsNull (fnf.FileName, "#2");
154                         Assert.IsNull (fnf.InnerException, "#3");
155                         Assert.IsNotNull (fnf.Message, "#4");
156                         Assert.AreEqual ("message", fnf.Message, "#5");
157                         Assert.IsNull (fnf.FusionLog, "#6");
158                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
159                                 fnf.ToString (), "#7");
160                 }
161
162                 [Test]
163                 public void Constructor4 ()
164                 {
165                         FileNotFoundException fnf = new FileNotFoundException ("message",
166                                 "file.txt");
167
168                         Assert.IsNotNull (fnf.Data, "#1");
169                         Assert.IsNotNull (fnf.FileName, "#2");
170                         Assert.AreEqual ("file.txt", fnf.FileName, "#3");
171                         Assert.IsNull (fnf.InnerException, "#4");
172                         Assert.IsNotNull (fnf.Message, "#5");
173                         Assert.AreEqual ("message", fnf.Message, "#6");
174                         Assert.IsNull (fnf.FusionLog, "#7");
175                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
176                                 + ": message" + Environment.NewLine), "#8");
177                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
178                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#9");
179                 }
180
181                 [Test]
182                 public void Constructor4_FileName_Empty ()
183                 {
184                         FileNotFoundException fnf = new FileNotFoundException ("message",
185                                 string.Empty);
186
187                         Assert.IsNotNull (fnf.Data, "#1");
188                         Assert.IsNotNull (fnf.FileName, "#2");
189                         Assert.AreEqual (string.Empty, fnf.FileName, "#3");
190                         Assert.IsNull (fnf.InnerException, "#4");
191                         Assert.IsNotNull (fnf.Message, "#5");
192                         Assert.AreEqual ("message", fnf.Message, "#6");
193                         Assert.IsNull (fnf.FusionLog, "#7");
194                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
195                                 fnf.ToString (), "#8");
196                 }
197
198                 [Test]
199                 public void Constructor4_FileName_Null ()
200                 {
201                         FileNotFoundException fnf = new FileNotFoundException ("message",
202                                 (string) null);
203
204                         Assert.IsNotNull (fnf.Data, "#A1");
205                         Assert.IsNull (fnf.FileName, "#A2");
206                         Assert.IsNull (fnf.InnerException, "#A3");
207                         Assert.IsNotNull (fnf.Message, "#A4");
208                         Assert.AreEqual ("message", fnf.Message, "#A5");
209                         Assert.IsNull (fnf.FusionLog, "#A6");
210                 
211                         Assert.AreEqual (fnf.GetType ().FullName + ": message",
212                                 fnf.ToString (), "#A7");
213
214                         fnf = new FileNotFoundException (string.Empty, (string) null);
215
216                         Assert.IsNotNull (fnf.Data, "#B1");
217                         Assert.IsNull (fnf.FileName, "#B2");
218                         Assert.IsNull (fnf.InnerException, "#B3");
219                         Assert.IsNotNull (fnf.Message, "#B4");
220                         Assert.AreEqual (string.Empty, fnf.Message, "#B5");
221                         Assert.IsNull (fnf.FusionLog, "#B6");
222                         Assert.AreEqual (fnf.GetType ().FullName + ": ",
223                                 fnf.ToString (), "#B7");
224                 }
225
226                 [Test]
227                 public void Constructor4_FileNameAndMessage_Empty ()
228                 {
229                         FileNotFoundException fnf = new FileNotFoundException (string.Empty,
230                                 string.Empty);
231
232                         Assert.IsNotNull (fnf.Data, "#1");
233                         Assert.IsNotNull (fnf.FileName, "#2");
234                         Assert.AreEqual (string.Empty, fnf.FileName, "#3");
235                         Assert.IsNull (fnf.InnerException, "#4");
236                         Assert.IsNotNull (fnf.Message, "#5");
237                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
238                         Assert.IsNull (fnf.FusionLog, "#7");
239                         Assert.AreEqual (fnf.GetType ().FullName + ": ", fnf.ToString (), "#8");
240                 }
241
242                 [Test]
243                 public void Constructor4_FileNameAndMessage_Null ()
244                 {
245                         FileNotFoundException fnf = new FileNotFoundException ((string) null,
246                                 (string) null);
247
248                         Assert.IsNotNull (fnf.Data, "#1");
249                         Assert.IsNull (fnf.FileName, "#2");
250                         Assert.IsNull (fnf.InnerException, "#3");
251                         Assert.IsNull (fnf.Message, "#4");
252                         Assert.IsNull (fnf.FusionLog, "#5");
253                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
254                                 + ": "), "#6");
255                         Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#7");
256                         Assert.IsFalse (fnf.ToString ().IndexOf ("''") != -1, "#8");
257                 }
258
259                 [Test]
260                 public void Constructor4_Message_Empty ()
261                 {
262                         FileNotFoundException fnf = null;
263                         
264                         fnf = new FileNotFoundException (string.Empty, "file.txt");
265
266                         Assert.IsNotNull (fnf.Data, "#1");
267                         Assert.IsNotNull (fnf.FileName, "#2");
268                         Assert.AreEqual ("file.txt", fnf.FileName, "#3");
269                         Assert.IsNull (fnf.InnerException, "#4");
270                         Assert.IsNotNull (fnf.Message, "#5");
271                         Assert.AreEqual (string.Empty, fnf.Message, "#6");
272                         Assert.IsNull (fnf.FusionLog, "#7");
273                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
274                                 + ": " + Environment.NewLine), "#8");
275                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#9");
276                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#10");
277                 }
278
279                 [Test]
280                 public void Constructor4_Message_Null ()
281                 {
282                         FileNotFoundException fnf = null;
283                         
284                         fnf = new FileNotFoundException ((string) null, "file.txt");
285
286                         Assert.IsNotNull (fnf.Data, "#A1");
287                         Assert.IsNotNull (fnf.FileName, "#A2");
288                         Assert.AreEqual ("file.txt", fnf.FileName, "#A3");
289                         Assert.IsNull (fnf.InnerException, "#A4");
290                         Assert.IsNotNull (fnf.Message, "#A5");
291                         Assert.IsNull (fnf.FusionLog, "#A6");
292                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
293                                 + ": "), "#A7");
294                         Assert.IsTrue (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#A8");
295                         Assert.IsTrue (fnf.ToString ().IndexOf ("'file.txt'") != -1, "#A9");
296                         Assert.IsFalse (fnf.ToString ().IndexOf ("\"file.txt\"") != -1, "#A10");
297
298                         fnf = new FileNotFoundException ((string) null, string.Empty);
299
300                         Assert.IsNotNull (fnf.Data, "#B1");
301                         Assert.IsNotNull (fnf.FileName, "#B2");
302                         Assert.AreEqual (string.Empty, fnf.FileName, "#B3");
303                         Assert.IsNull (fnf.InnerException, "#B4");
304                         // .NET 1.1: File or assembly name , or one of its dependencies ...
305                         // .NET 2.0: Could not load file or assembly '' or one of its ...
306                         Assert.IsNotNull (fnf.Message, "#B5");
307                         Assert.IsNull (fnf.FusionLog, "#B6");
308                         Assert.IsTrue (fnf.ToString ().StartsWith (fnf.GetType ().FullName
309                                 + ": "), "#B7");
310                         Assert.IsFalse (fnf.ToString ().IndexOf (Environment.NewLine) != -1, "#B8");
311                         Assert.IsTrue (fnf.ToString ().IndexOf ("''") != -1, "#B9");
312                 }
313         }
314 }