* Makefile.am: Build `docs` after `runtime`, so that it can depend
[mono.git] / mcs / class / corlib / Test / System.IO / PathTest.cs
1 //
2 // System.IO.Path Test Cases
3 //
4 // Authors:
5 //      Marcin Szczepanski (marcins@zipworld.com.au)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //      Ben Maurer (bmaurer@users.sf.net)
8 //      Gilles Freart (gfr@skynet.be)
9 //      Atsushi Enomoto (atsushi@ximian.com)
10 //      Sebastien Pouliot  <sebastien@ximian.com>
11 //
12 // (c) Marcin Szczepanski 
13 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
14 // (c) 2003 Ben Maurer
15 // (c) 2003 Gilles Freart
16 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
17 //
18
19 using NUnit.Framework;
20 using System.IO;
21 using System;
22 using System.Text;
23
24 namespace MonoTests.System.IO
25 {
26         enum OsType {
27                 Windows,
28                 Unix,
29                 Mac
30         }
31
32         [TestFixture]
33         public class PathTest : Assertion
34         {
35                 static string path1;
36                 static string path2;
37                 static string path3;
38                 static OsType OS;
39                 static char DSC = Path.DirectorySeparatorChar;
40
41                 [SetUp]
42                 public void SetUp ()
43                 {
44                         if ('/' == DSC) {
45                                 OS = OsType.Unix;
46                                 path1 = "/foo/test.txt";
47                                 path2 = "/etc";
48                                 path3 = "init.d";
49                         } else if ('\\' == DSC) {
50                                 OS = OsType.Windows;
51                                 path1 = "c:\\foo\\test.txt";
52                                 path2 = Environment.GetEnvironmentVariable ("SYSTEMROOT");
53                                 path3 = "system32";
54                         } else {
55                                 OS = OsType.Mac;
56                                 //FIXME: For Mac. figure this out when we need it
57                                 path1 = "foo:test.txt";
58                                 path2 = "foo";
59                                 path3 = "bar";
60                         }
61                 }
62
63                 bool Windows
64                 {
65                         get {
66                                 return OS == OsType.Windows;
67                         }
68                 }
69
70                 bool Unix
71                 {
72                         get {
73                                 return OS == OsType.Unix;
74                         }
75                 }
76
77                 bool Mac
78                 {
79                         get {
80                                 return OS == OsType.Mac;
81                         }
82                 }
83
84                 [Test]
85                 public void ChangeExtension ()
86                 {
87                         string [] files = new string [3];
88                         files [(int) OsType.Unix] = "/foo/test.doc";
89                         files [(int) OsType.Windows] = "c:\\foo\\test.doc";
90                         files [(int) OsType.Mac] = "foo:test.doc";
91
92                         string testPath = Path.ChangeExtension (path1, "doc");
93                         AssertEquals ("ChangeExtension #01", files [(int) OS], testPath);
94
95                         testPath = Path.ChangeExtension (String.Empty, ".extension");
96                         AssertEquals ("ChangeExtension #02", String.Empty, testPath);
97
98                         testPath = Path.ChangeExtension (null, ".extension");
99                         AssertEquals ("ChangeExtension #03", null, testPath);
100
101                         testPath = Path.ChangeExtension ("path", null);
102                         AssertEquals ("ChangeExtension #04", "path", testPath);
103
104                         testPath = Path.ChangeExtension ("path.ext", "doc");
105                         AssertEquals ("ChangeExtension #05", "path.doc", testPath);
106
107                         testPath = Path.ChangeExtension ("path.ext1.ext2", "doc");
108                         AssertEquals ("ChangeExtension #06", "path.ext1.doc", testPath);
109
110                         testPath = Path.ChangeExtension ("hogehoge.xml", ".xsl");
111                         AssertEquals ("ChangeExtension #07", "hogehoge.xsl", testPath);
112                         testPath = Path.ChangeExtension ("hogehoge", ".xsl");
113                         AssertEquals ("ChangeExtension #08", "hogehoge.xsl", testPath);
114                         testPath = Path.ChangeExtension ("hogehoge.xml", "xsl");
115                         AssertEquals ("ChangeExtension #09", "hogehoge.xsl", testPath);
116                         testPath = Path.ChangeExtension ("hogehoge", "xsl");
117                         AssertEquals ("ChangeExtension #10", "hogehoge.xsl", testPath);
118                         testPath = Path.ChangeExtension ("hogehoge.xml", String.Empty);
119                         AssertEquals ("ChangeExtension #11", "hogehoge.", testPath);
120                         testPath = Path.ChangeExtension ("hogehoge", String.Empty);
121                         AssertEquals ("ChangeExtension #12", "hogehoge.", testPath);
122                         testPath = Path.ChangeExtension ("hogehoge.", null);
123                         AssertEquals ("ChangeExtension #13", "hogehoge", testPath);
124                         testPath = Path.ChangeExtension ("hogehoge", null);
125                         AssertEquals ("ChangeExtension #14", "hogehoge", testPath);
126                         testPath = Path.ChangeExtension (String.Empty, null);
127                         AssertEquals ("ChangeExtension #15", String.Empty, testPath);
128                         testPath = Path.ChangeExtension (String.Empty, "bashrc");
129                         AssertEquals ("ChangeExtension #16", String.Empty, testPath);
130                         testPath = Path.ChangeExtension (String.Empty, ".bashrc");
131                         AssertEquals ("ChangeExtension #17", String.Empty, testPath);
132                         testPath = Path.ChangeExtension (null, null);
133                         AssertNull ("ChangeExtension #18", testPath);
134                 }
135
136                 [Test]
137                 public void ChangeExtension_Extension_InvalidPathChars () 
138                 {
139                         string fn = Path.ChangeExtension ("file.ext", "<");
140                         AssertEquals ("Invalid filename", "file.<", fn);
141                 }
142
143                 [Test]
144                 public void ChangeExtension_Path_InvalidPathChars ()
145                 {
146                         try {
147                                 Path.ChangeExtension ("fi\0le.ext", ".extension");
148                                 Fail ("#1");
149                         } catch (ArgumentException ex) {
150                                 // Illegal characters in path
151                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
152                                 AssertNull ("#3", ex.InnerException);
153                                 AssertNotNull ("#4", ex.Message);
154                                 AssertNull ("#5", ex.ParamName);
155                         }
156                 }
157
158                 [Test]
159                 public void Combine ()
160                 {
161                         string [] files = new string [3];
162                         files [(int) OsType.Unix] = "/etc/init.d";
163                         files [(int) OsType.Windows] = Environment.GetEnvironmentVariable ("SYSTEMROOT") + @"\system32";
164                         files [(int) OsType.Mac] = "foo:bar";
165
166                         string testPath = Path.Combine (path2, path3);
167                         AssertEquals ("Combine #01", files [(int) OS], testPath);
168
169                         testPath = Path.Combine ("one", String.Empty);
170                         AssertEquals ("Combine #02", "one", testPath);
171
172                         testPath = Path.Combine (String.Empty, "one");
173                         AssertEquals ("Combine #03", "one", testPath);
174
175                         string current = Directory.GetCurrentDirectory ();
176                         testPath = Path.Combine (current, "one");
177
178                         string expected = current + DSC + "one";
179                         AssertEquals ("Combine #04", expected, testPath);
180
181                         testPath = Path.Combine ("one", current);
182                         // LAMESPEC noted in Path.cs
183                         AssertEquals ("Combine #05", current, testPath);
184
185                         testPath = Path.Combine (current, expected);
186                         AssertEquals ("Combine #06", expected, testPath);
187
188                         testPath = DSC + "one";
189                         testPath = Path.Combine (testPath, "two" + DSC);
190                         expected = DSC + "one" + DSC + "two" + DSC;
191                         AssertEquals ("Combine #06", expected, testPath);
192
193                         testPath = "one" + DSC;
194                         testPath = Path.Combine (testPath, DSC + "two");
195                         expected = DSC + "two";
196                         AssertEquals ("Combine #06", expected, testPath);
197
198                         testPath = "one" + DSC;
199                         testPath = Path.Combine (testPath, "two" + DSC);
200                         expected = "one" + DSC + "two" + DSC;
201                         AssertEquals ("Combine #07", expected, testPath);
202                 }
203
204                 [Test]
205                 public void Combine_Path1_InvalidPathChars ()
206                 {
207                         try {
208                                 Path.Combine ("a\0", "one");
209                                 Fail ("#1");
210                         } catch (ArgumentException ex) {
211                                 // Illegal characters in path
212                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
213                                 AssertNull ("#3", ex.InnerException);
214                                 AssertNotNull ("#4", ex.Message);
215                                 AssertNull ("#5", ex.ParamName);
216                         }
217                 }
218
219                 [Test]
220                 public void Combine_Path1_Null ()
221                 {
222                         try {
223                                 Path.Combine (null, "one");
224                                 Fail ("#1");
225                         } catch (ArgumentNullException ex) {
226                                 AssertEquals ("#2", typeof (ArgumentNullException), ex.GetType ());
227                                 AssertNull ("#3", ex.InnerException);
228                                 AssertNotNull ("#4", ex.Message);
229                                 AssertEquals ("#5", "path1", ex.ParamName);
230                         }
231                 }
232
233                 [Test]
234                 public void Combine_Path2_InvalidPathChars ()
235                 {
236                         try {
237                                 Path.Combine ("one", "a\0");
238                                 Fail ("#1");
239                         } catch (ArgumentException ex) {
240                                 // Illegal characters in path
241                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
242                                 AssertNull ("#3", ex.InnerException);
243                                 AssertNotNull ("#4", ex.Message);
244                                 AssertNull ("#5", ex.ParamName);
245                         }
246                 }
247
248                 [Test]
249                 public void Combine_Path2_Null ()
250                 {
251                         try {
252                                 Path.Combine ("one", null);
253                                 Fail ("#1");
254                         } catch (ArgumentNullException ex) {
255                                 AssertEquals ("#2", typeof (ArgumentNullException), ex.GetType ());
256                                 AssertNull ("#3", ex.InnerException);
257                                 AssertNotNull ("#4", ex.Message);
258                                 AssertEquals ("#5", "path2", ex.ParamName);
259                         }
260                 }
261
262                 [Test]
263                 public void GetDirectoryName ()
264                 {
265                         string [] files = new string [3];
266                         files [(int) OsType.Unix] = "/foo";
267                         files [(int) OsType.Windows] = "c:\\foo";
268                         files [(int) OsType.Mac] = "foo";
269
270                         string testDirName = Path.GetDirectoryName (path1);
271                         AssertEquals ("#A1", files [(int) OS], testDirName);
272                         testDirName = Path.GetDirectoryName (files [(int) OS] + DSC);
273                         AssertEquals ("#A2", files [(int) OS], testDirName);
274
275                         if (Windows) {
276                                 AssertEquals ("#B1", "C:\\foo", Path.GetDirectoryName ("C:\\foo\\foo.txt"));
277                                 AssertEquals ("#B2", null, Path.GetDirectoryName ("C:"));
278                                 AssertEquals ("#B3", null, Path.GetDirectoryName (@"C:\"));
279                                 AssertEquals ("#B4", @"C:\", Path.GetDirectoryName (@"C:\dir"));
280                                 AssertEquals ("#B5", @"C:\dir", Path.GetDirectoryName (@"C:\dir\"));
281                                 AssertEquals ("#B6", @"C:\dir", Path.GetDirectoryName (@"C:\dir\dir"));
282                                 AssertEquals ("#B7", @"C:\dir\dir", Path.GetDirectoryName (@"C:\dir\dir\"));
283
284                                 AssertEquals ("#C1", "\\foo\\bar", Path.GetDirectoryName ("/foo//bar/dingus"));
285                                 AssertEquals ("#C2", "foo\\bar", Path.GetDirectoryName ("foo/bar/"));
286                                 AssertEquals ("#C3", "foo\\bar", Path.GetDirectoryName ("foo/bar\\xxx"));
287                                 AssertEquals ("#C4", "\\\\host\\dir\\dir2", Path.GetDirectoryName ("\\\\host\\dir\\\\dir2\\path"));
288
289                                 // UNC tests
290                                 AssertEquals ("#D1", null, Path.GetDirectoryName (@"\\"));
291                                 AssertEquals ("#D2", null, Path.GetDirectoryName (@"\\server"));
292                                 AssertEquals ("#D3", null, Path.GetDirectoryName (@"\\server\share"));
293                                 AssertEquals ("#D4", @"\\server\share", Path.GetDirectoryName (@"\\server\share\"));
294                                 AssertEquals ("#D5", @"\\server\share", Path.GetDirectoryName (@"\\server\share\dir"));
295                                 AssertEquals ("#D6", @"\\server\share\dir", Path.GetDirectoryName (@"\\server\share\dir\subdir"));
296                         } else {
297                                 AssertEquals ("#B1", "/etc", Path.GetDirectoryName ("/etc/hostname"));
298                                 AssertEquals ("#B2", "/foo/bar", Path.GetDirectoryName ("/foo//bar/dingus"));
299                                 AssertEquals ("#B3", "foo/bar", Path.GetDirectoryName ("foo/bar/"));
300                                 AssertEquals ("#B4", "/", Path.GetDirectoryName ("/tmp"));
301                                 AssertNull ("#B5", Path.GetDirectoryName ("/"));
302                                 AssertEquals ("#B6", "a", Path.GetDirectoryName ("a//b"));
303                         }
304                 }
305
306                 [Test]
307                 public void GetDirectoryName_Path_Empty ()
308                 {
309                         try {
310                                 Path.GetDirectoryName (String.Empty);
311                                 Fail ("#1");
312                         } catch (ArgumentException ex) {
313                                 // The path is not of a legal form
314                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
315                                 AssertNull ("#3", ex.InnerException);
316                                 AssertNotNull ("#4", ex.Message);
317                                 AssertNull ("#5", ex.ParamName);
318                         }
319                 }
320
321                 [Test]
322                 public void GetDirectoryName_Path_InvalidPathChars ()
323                 {
324                         try {
325                                 Path.GetDirectoryName ("hi\0world");
326                                 Fail ("#1");
327                         } catch (ArgumentException ex) {
328                                 // Illegal characters in path
329                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
330                                 AssertNull ("#3", ex.InnerException);
331                                 AssertNotNull ("#4", ex.Message);
332                                 AssertNull ("#5", ex.ParamName);
333                         }
334                 }
335
336                 [Test]
337                 public void GetDirectoryName_Path_Null ()
338                 {
339                         AssertNull (Path.GetDirectoryName (null));
340                 }
341
342                 [Test]
343                 public void GetDirectoryName_Path_Whitespace ()
344                 {
345                         try {
346                                 Path.GetDirectoryName ("   ");
347                                 Fail ("#1");
348                         } catch (ArgumentException ex) {
349                                 // The path is not of a legal form
350                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
351                                 AssertNull ("#3", ex.InnerException);
352                                 AssertNotNull ("#4", ex.Message);
353                                 AssertNull ("#5", ex.ParamName);
354                         }
355                 }
356
357                 [Test]
358                 public void GetExtension ()
359                 {
360                         string testExtn = Path.GetExtension (path1);
361
362                         AssertEquals ("GetExtension #01",  ".txt", testExtn);
363
364                         testExtn = Path.GetExtension (path2);
365                         AssertEquals ("GetExtension #02", String.Empty, testExtn);
366
367                         testExtn = Path.GetExtension (String.Empty);
368                         AssertEquals ("GetExtension #03", String.Empty, testExtn);
369
370                         testExtn = Path.GetExtension (null);
371                         AssertEquals ("GetExtension #04", null, testExtn);
372
373                         testExtn = Path.GetExtension (" ");
374                         AssertEquals ("GetExtension #05", String.Empty, testExtn);
375
376                         testExtn = Path.GetExtension (path1 + ".doc");
377                         AssertEquals ("GetExtension #06", ".doc", testExtn);
378
379                         testExtn = Path.GetExtension (path1 + ".doc" + DSC + "a.txt");
380                         AssertEquals ("GetExtension #07", ".txt", testExtn);
381
382                         testExtn = Path.GetExtension (".");
383                         AssertEquals ("GetExtension #08", String.Empty, testExtn);
384
385                         testExtn = Path.GetExtension ("end.");
386                         AssertEquals ("GetExtension #09", String.Empty, testExtn);
387
388                         testExtn = Path.GetExtension (".start");
389                         AssertEquals ("GetExtension #10", ".start", testExtn);
390
391                         testExtn = Path.GetExtension (".a");
392                         AssertEquals ("GetExtension #11", ".a", testExtn);
393
394                         testExtn = Path.GetExtension ("a.");
395                         AssertEquals ("GetExtension #12", String.Empty, testExtn);
396
397                         testExtn = Path.GetExtension ("a");
398                         AssertEquals ("GetExtension #13", String.Empty, testExtn);
399
400                         testExtn = Path.GetExtension ("makefile");
401                         AssertEquals ("GetExtension #14", String.Empty, testExtn);
402                 }
403
404                 [Test]
405                 public void GetExtension_Path_InvalidPathChars ()
406                 {
407                         try {
408                                 Path.GetExtension ("hi\0world.txt");
409                                 Fail ("#1");
410                         } catch (ArgumentException ex) {
411                                 // Illegal characters in path.
412                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
413                                 AssertNull ("#3", ex.InnerException);
414                                 AssertNotNull ("#4", ex.Message);
415                                 AssertNull ("#5", ex.ParamName);
416                         }
417                 }
418
419                 [Test]
420                 public void GetFileName ()
421                 {
422                         string testFileName = Path.GetFileName (path1);
423
424                         AssertEquals ("#1", "test.txt", testFileName);
425                         testFileName = Path.GetFileName (null);
426                         AssertEquals ("#2", null, testFileName);
427                         testFileName = Path.GetFileName (String.Empty);
428                         AssertEquals ("#3", String.Empty, testFileName);
429                         testFileName = Path.GetFileName (" ");
430                         AssertEquals ("#4", " ", testFileName);
431                 }
432
433                 [Test]
434                 public void GetFileName_Path_InvalidPathChars ()
435                 {
436                         try {
437                                 Path.GetFileName ("hi\0world");
438                                 Fail ("#1");
439                         } catch (ArgumentException ex) {
440                                 // Illegal characters in path
441                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
442                                 AssertNull ("#3", ex.InnerException);
443                                 AssertNotNull ("#4", ex.Message);
444                                 AssertNull ("#5", ex.ParamName);
445                         }
446                 }
447
448                 [Test]
449                 public void GetFileNameWithoutExtension ()
450                 {
451                         string testFileName = Path.GetFileNameWithoutExtension (path1);
452
453                         AssertEquals ("GetFileNameWithoutExtension #01", "test", testFileName);
454
455                         testFileName = Path.GetFileNameWithoutExtension (null);
456                         AssertEquals ("GetFileNameWithoutExtension #02", null, testFileName);
457
458                         testFileName = Path.GetFileNameWithoutExtension (String.Empty);
459                         AssertEquals ("GetFileNameWithoutExtension #03", String.Empty, testFileName);
460                 }
461
462                 [Test]
463                 public void GetFileNameWithoutExtension_Path_InvalidPathChars ()
464                 {
465                         try {
466                                 Path.GetFileNameWithoutExtension ("hi\0world");
467                                 Fail ("#1");
468                         } catch (ArgumentException ex) {
469                                 // Illegal characters in path
470                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
471                                 AssertNull ("#3", ex.InnerException);
472                                 AssertNotNull ("#4", ex.Message);
473                                 AssertNull ("#5", ex.ParamName);
474                         }
475                 }
476
477                 [Test]
478                 public void GetFullPath ()
479                 {
480                         string current = Directory.GetCurrentDirectory ();
481
482                         string testFullPath = Path.GetFullPath ("foo.txt");
483                         string expected = current + DSC + "foo.txt";
484                         AssertEquals ("GetFullPath #01", expected, testFullPath);
485
486                         testFullPath = Path.GetFullPath ("a//./.././foo.txt");
487                         AssertEquals ("GetFullPath #02", expected, testFullPath);
488                 }
489
490                 [Test]
491                 public void GetFullPath_Unix ()
492                 {
493                         if (Windows)
494                                 return;
495
496                         string root =  "/";
497                         string [,] test = new string [,] {
498                                 {"root////././././././../root/././../root", "root"},
499                                 {"root/", "root/"},
500                                 {"root/./", "root/"},
501                                 {"root/./", "root/"},
502                                 {"root/../", String.Empty},
503                                 {"root/../", String.Empty},
504                                 {"root/../..", String.Empty},
505                                 {"root/.hiddenfile", "root/.hiddenfile"},
506                                 {"root/. /", "root/. /"},
507                                 {"root/.. /", "root/.. /"},
508                                 {"root/..weirdname", "root/..weirdname"},
509                                 {"root/..", String.Empty},
510                                 {"root/../a/b/../../..", String.Empty},
511                                 {"root/./..", String.Empty},
512                                 {"..", String.Empty},
513                                 {".", String.Empty},
514                                 {"root//dir", "root/dir"},
515                                 {"root/.              /", "root/.              /"},
516                                 {"root/..             /", "root/..             /"},
517                                 {"root/      .              /", "root/      .              /"},
518                                 {"root/      ..             /", "root/      ..             /"},
519                                 {"root/./", "root/"},
520                                 //ERROR! Paths are trimmed
521                                 // I don't understand this comment^^.
522                                 // No trimming occurs but the paths are not equal. That's why the test fails. Commented out.
523                                 //{"root/..                      /", "root/..                   /"},
524                                 {".//", String.Empty}
525                         };
526
527                         for (int i = 0; i < test.GetUpperBound (0); i++) {
528                                 AssertEquals (String.Format ("GetFullPathUnix #{0}", i),
529                                         root + test [i, 1], Path.GetFullPath (root + test [i, 0]));
530                         }
531
532                         AssertEquals ("#01", "/", Path.GetFullPath ("/"));
533                         AssertEquals ("#02", "/hey", Path.GetFullPath ("/hey"));
534                         AssertEquals ("#03", Environment.CurrentDirectory, Path.GetFullPath ("."));
535                         AssertEquals ("#04", Path.Combine (Environment.CurrentDirectory, "hey"),
536                                              Path.GetFullPath ("hey"));
537                 }
538
539                 [Test]
540                 public void GetFullPath_Windows ()
541                 {
542                         if (!Windows)
543                                 return;
544
545                         string root =  "C:\\";
546                         string [,] test = new string [,] {
547                                 {"root////././././././../root/././../root", "root"},
548                                 {"root/", "root\\"},
549                                 {"root/./", "root\\"},
550                                 {"root/./", "root\\"},
551                                 {"root/../", ""},
552                                 {"root/../", ""},
553                                 {"root/../..", ""},
554                                 {"root/.hiddenfile", "root\\.hiddenfile"},
555                                 {"root/. /", "root\\"},
556                                 {"root/.. /", ""},
557                                 {"root/..weirdname", "root\\..weirdname"},
558                                 {"root/..", ""},
559                                 {"root/../a/b/../../..", ""},
560                                 {"root/./..", ""},
561                                 {"..", ""},
562                                 {".", ""},
563                                 {"root//dir", "root\\dir"},
564                                 {"root/.              /", "root\\"},
565                                 {"root/..             /", ""},
566                                 {"root/      .              /", "root\\"},
567                                 {"root/      ..             /", ""},
568                                 {"root/./", "root\\"},
569                                 {"root/..                      /", ""},
570                                 {".//", ""}
571                         };
572
573                         for (int i = 0; i < test.GetUpperBound (0); i++) {
574                                 AssertEquals (String.Format ("GetFullPathWindows #{0}", i),
575                                         root + test [i, 1], Path.GetFullPath (root + test [i, 0]));
576                         }
577
578                         // UNC tests
579                         string root2 = @"\\server\share";
580                         root = @"\\server\share\";
581                         test = new string [,] {         
582                                 {"root////././././././../root/././../root", "root"},
583                                 {"root/", "root\\"},
584                                 {"root/./", "root\\"},
585                                 {"root/./", "root\\"},
586                                 {"root/../", ""},
587                                 {"root/../", ""},
588                                 {"root/../..", null},
589                                 {"root/.hiddenfile", "root\\.hiddenfile"},
590                                 {"root/. /", "root\\"},
591                                 {"root/.. /", ""},
592                                 {"root/..weirdname", "root\\..weirdname"},
593                                 {"root/..", null},
594                                 {"root/../a/b/../../..", null},
595                                 {"root/./..", null},
596                                 {"..", null},
597                                 {".", null},
598                                 {"root//dir", "root\\dir"},
599                                 {"root/.              /", "root\\"},
600                                 {"root/..             /", ""},
601                                 {"root/      .              /", "root\\"},
602                                 {"root/      ..             /", ""},
603                                 {"root/./", "root\\"},
604                                 {"root/..                      /", ""},
605                                 {".//", ""}
606                         };
607
608                         for (int i = 0; i < test.GetUpperBound (0); i++) {
609                                 // "null" means we have to compare against "root2"
610                                 string res = test [i, 1] != null
611                                         ? root + test [i, 1]
612                                         : root2;
613                                 AssertEquals (String.Format ("GetFullPathWindows UNC #{0}", i),
614                                         res, Path.GetFullPath (root + test [i, 0]));
615                         }
616                 }
617
618                 [Test]
619                 public void GetFullPath_Path_Empty ()
620                 {
621                         try {
622                                 Path.GetFullPath (String.Empty);
623                                 Fail ("#1");
624                         } catch (ArgumentException ex) {
625                                 // The path is not of a legal form
626                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
627                                 AssertNull ("#3", ex.InnerException);
628                                 AssertNotNull ("#4", ex.Message);
629                                 AssertNull ("#5", ex.ParamName);
630                         }
631                 }
632
633                 [Test]
634                 public void GetFullPath_Path_EndingSeparator ()
635                 {
636                         string fp = Path.GetFullPath ("something/");
637                         char end = fp [fp.Length - 1];
638                         Assert (end == Path.DirectorySeparatorChar);
639                 }
640
641                 [Test]
642                 public void GetFullPath_Path_InvalidPathChars ()
643                 {
644                         try {
645                                 Path.GetFullPath ("hi\0world");
646                                 Fail ("#1");
647                         } catch (ArgumentException ex) {
648                                 // Illegal characters in path
649                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
650                                 AssertNull ("#3", ex.InnerException);
651                                 AssertNotNull ("#4", ex.Message);
652                                 AssertNull ("#5", ex.ParamName);
653                         }
654                 }
655
656                 [Test]
657                 public void GetFullPath_Path_Null ()
658                 {
659                         try {
660                                 Path.GetFullPath (null);
661                                 Fail ("#1");
662                         } catch (ArgumentNullException ex) {
663                                 AssertEquals ("#2", typeof (ArgumentNullException), ex.GetType ());
664                                 AssertNull ("#3", ex.InnerException);
665                                 AssertNotNull ("#4", ex.Message);
666                                 AssertEquals ("#5", "path", ex.ParamName);
667                         }
668                 }
669
670                 [Test]
671                 public void GetFullPath_Path_Whitespace ()
672                 {
673                         try {
674                                 Path.GetFullPath ("  ");
675                                 Fail ("#1");
676                         } catch (ArgumentException ex) {
677                                 // The path is not of a legal form
678                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
679                                 AssertNull ("#3", ex.InnerException);
680                                 AssertNotNull ("#4", ex.Message);
681                                 AssertNull ("#5", ex.ParamName);
682                         }
683                 }
684
685                 [Test]
686                 public void GetFullPath2 ()
687                 {
688                         if (Windows) {
689                                 AssertEquals ("GetFullPath w#01", @"Z:\", Path.GetFullPath ("Z:"));
690 #if !TARGET_JVM // Java full (canonical) path always starts with caps drive letter
691                                 AssertEquals ("GetFullPath w#02", @"c:\abc\def", Path.GetFullPath (@"c:\abc\def"));
692 #endif
693                                 Assert ("GetFullPath w#03", Path.GetFullPath (@"\").EndsWith (@"\"));
694                                 // "\\\\" is not allowed
695                                 Assert ("GetFullPath w#05", Path.GetFullPath ("/").EndsWith (@"\"));
696                                 // "//" is not allowed
697                                 Assert ("GetFullPath w#07", Path.GetFullPath ("readme.txt").EndsWith (@"\readme.txt"));
698                                 Assert ("GetFullPath w#08", Path.GetFullPath ("c").EndsWith (@"\c"));
699                                 Assert ("GetFullPath w#09", Path.GetFullPath (@"abc\def").EndsWith (@"abc\def"));
700                                 Assert ("GetFullPath w#10", Path.GetFullPath (@"\abc\def").EndsWith (@"\abc\def"));
701                                 AssertEquals ("GetFullPath w#11", @"\\abc\def", Path.GetFullPath (@"\\abc\def"));
702                                 AssertEquals ("GetFullPath w#12", Directory.GetCurrentDirectory () + @"\abc\def", Path.GetFullPath (@"abc//def"));
703                                 AssertEquals ("GetFullPath w#13", Directory.GetCurrentDirectory ().Substring (0, 2) + @"\abc\def", Path.GetFullPath ("/abc/def"));
704                                 AssertEquals ("GetFullPath w#14", @"\\abc\def", Path.GetFullPath ("//abc/def"));
705                         } else {
706                                 AssertEquals ("#01", "/", Path.GetFullPath ("/"));
707                                 AssertEquals ("#02", "/hey", Path.GetFullPath ("/hey"));
708                                 AssertEquals ("#03", Environment.CurrentDirectory, Path.GetFullPath ("."));
709                                 AssertEquals ("#04", Path.Combine (Environment.CurrentDirectory, "hey"),
710                                                      Path.GetFullPath ("hey"));
711                         }
712                 }
713
714                 [Test]
715                 public void GetPathRoot ()
716                 {
717                         string current;
718                         string expected;
719                         if (!Windows){
720                                 current = Directory.GetCurrentDirectory ();
721                                 expected = current [0].ToString ();
722                         } else {
723                                 current = @"J:\Some\Strange Directory\Name";
724                                 expected = "J:\\";
725                         }
726
727                         string pathRoot = Path.GetPathRoot (current);
728                         AssertEquals ("GetPathRoot #01", expected, pathRoot);
729                 }
730
731                 [Test]
732                 public void GetPathRoot2 ()
733                 {
734                         // note: this method doesn't call Directory.GetCurrentDirectory so it can be
735                         // reused for partial trust unit tests in PathCas.cs
736
737                         string pathRoot;
738                         
739                         pathRoot = Path.GetPathRoot ("hola");
740                         AssertEquals ("#A1", String.Empty, pathRoot);
741                         pathRoot = Path.GetPathRoot (null);
742                         AssertEquals ("#A2", null, pathRoot);
743
744                         if (Windows) {
745                                 AssertEquals ("GetPathRoot w#01", "z:", Path.GetPathRoot ("z:"));
746                                 AssertEquals ("GetPathRoot w#02", "c:\\", Path.GetPathRoot ("c:\\abc\\def"));
747                                 AssertEquals ("GetPathRoot w#03", "\\", Path.GetPathRoot ("\\"));
748                                 AssertEquals ("GetPathRoot w#04", "\\\\", Path.GetPathRoot ("\\\\"));
749                                 AssertEquals ("GetPathRoot w#05", "\\", Path.GetPathRoot ("/"));
750                                 AssertEquals ("GetPathRoot w#06", "\\\\", Path.GetPathRoot ("//"));
751                                 AssertEquals ("GetPathRoot w#07", String.Empty, Path.GetPathRoot ("readme.txt"));
752                                 AssertEquals ("GetPathRoot w#08", String.Empty, Path.GetPathRoot ("c"));
753                                 AssertEquals ("GetPathRoot w#09", String.Empty, Path.GetPathRoot ("abc\\def"));
754                                 AssertEquals ("GetPathRoot w#10", "\\", Path.GetPathRoot ("\\abc\\def"));
755                                 AssertEquals ("GetPathRoot w#11", "\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def"));
756                                 AssertEquals ("GetPathRoot w#12", String.Empty, Path.GetPathRoot ("abc//def"));
757                                 AssertEquals ("GetPathRoot w#13", "\\", Path.GetPathRoot ("/abc/def"));
758                                 AssertEquals ("GetPathRoot w#14", "\\\\abc\\def", Path.GetPathRoot ("//abc/def"));
759                                 AssertEquals ("GetPathRoot w#15", @"C:\", Path.GetPathRoot (@"C:\"));
760                                 AssertEquals ("GetPathRoot w#16", @"C:\", Path.GetPathRoot (@"C:\\"));
761                                 AssertEquals ("GetPathRoot w#17", "\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def\\ghi"));
762                         } else {
763                                 // TODO: Same tests for Unix.
764                         }
765                 }
766
767                 [Test]
768                 public void GetPathRoot_Path_Empty ()
769                 {
770                         try {
771                                 Path.GetPathRoot (String.Empty);
772                                 Fail ("#1");
773                         } catch (ArgumentException ex) {
774                                 // The path is not of a legal form
775                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
776                                 AssertNull ("#3", ex.InnerException);
777                                 AssertNotNull ("#4", ex.Message);
778                                 AssertNull ("#5", ex.ParamName);
779                         }
780                 }
781
782                 [Test]
783 #if ONLY_1_1
784                 [Category ("NotWorking")] // we also throw ArgumentException on 1.0 profile
785 #endif
786                 public void GetPathRoot_Path_InvalidPathChars ()
787                 {
788 #if NET_2_0
789                         try {
790                                 Path.GetPathRoot ("hi\0world");
791                                 Fail ("#1");
792                         } catch (ArgumentException ex) {
793                                 // Illegal characters in path
794                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
795                                 AssertNull ("#3", ex.InnerException);
796                                 AssertNotNull ("#4", ex.Message);
797                                 AssertNull ("#5", ex.ParamName);
798                         }
799 #else
800                         AssertEquals (String.Empty, Path.GetPathRoot ("hi\0world"));
801 #endif
802                 }
803
804                 [Test]
805                 public void GetPathRoot_Path_Whitespace ()
806                 {
807                         try {
808                                 Path.GetPathRoot ("  ");
809                                 Fail ("#1");
810                         } catch (ArgumentException ex) {
811                                 // The path is not of a legal form
812                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
813                                 AssertNull ("#3", ex.InnerException);
814                                 AssertNotNull ("#4", ex.Message);
815                                 AssertNull ("#5", ex.ParamName);
816                         }
817                 }
818
819                 [Test]
820                 public void GetTempPath ()
821                 {
822                         string getTempPath = Path.GetTempPath ();
823                         Assert ("GetTempPath #01",  getTempPath != String.Empty);
824                         Assert ("GetTempPath #02",  Path.IsPathRooted (getTempPath));
825                         AssertEquals ("GetTempPath #03", Path.DirectorySeparatorChar, getTempPath [getTempPath.Length - 1]);
826                 }
827
828                 [Test]
829                 public void GetTempFileName ()
830                 {
831                         string getTempFileName = null;
832                         try {
833                                 getTempFileName = Path.GetTempFileName ();
834                                 Assert ("GetTempFileName #01", getTempFileName != String.Empty);
835                                 Assert ("GetTempFileName #02", File.Exists (getTempFileName));
836                         } finally {
837                                 if (getTempFileName != null && getTempFileName != String.Empty){
838                                         File.Delete (getTempFileName);
839                                 }
840                         }
841                 }
842
843                 [Test]
844                 public void HasExtension ()
845                 {
846                         AssertEquals ("HasExtension #01",  true, Path.HasExtension ("foo.txt"));
847                         AssertEquals ("HasExtension #02",  false, Path.HasExtension ("foo"));
848                         AssertEquals ("HasExtension #03",  true, Path.HasExtension (path1));
849                         AssertEquals ("HasExtension #04",  false, Path.HasExtension (path2));
850                         AssertEquals ("HasExtension #05",  false, Path.HasExtension (null));
851                         AssertEquals ("HasExtension #06",  false, Path.HasExtension (String.Empty));
852                         AssertEquals ("HasExtension #07",  false, Path.HasExtension (" "));
853                         AssertEquals ("HasExtension #08",  false, Path.HasExtension ("."));
854                         AssertEquals ("HasExtension #09",  false, Path.HasExtension ("end."));
855                         AssertEquals ("HasExtension #10",  true, Path.HasExtension (".start"));
856                         AssertEquals ("HasExtension #11",  true, Path.HasExtension (".a"));
857                         AssertEquals ("HasExtension #12",  false, Path.HasExtension ("a."));
858                         AssertEquals ("HasExtension #13",  false, Path.HasExtension ("Makefile"));
859                 }
860
861                 [Test]
862                 public void HasExtension_Path_InvalidPathChars ()
863                 {
864                         try {
865                                 Path.HasExtension ("hi\0world.txt");
866                                 Fail ("#1");
867                         } catch (ArgumentException ex) {
868                                 // Illegal characters in path
869                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
870                                 AssertNull ("#3", ex.InnerException);
871                                 AssertNotNull ("#4", ex.Message);
872                                 AssertNull ("#5", ex.ParamName);
873                         }
874                 }
875
876                 [Test]
877                 public void IsPathRooted ()
878                 {
879                         Assert ("IsPathRooted #01", Path.IsPathRooted (path2));
880                         Assert ("IsPathRooted #02", !Path.IsPathRooted (path3));
881                         Assert ("IsPathRooted #03", !Path.IsPathRooted (null));
882                         Assert ("IsPathRooted #04", !Path.IsPathRooted (String.Empty));
883                         Assert ("IsPathRooted #05", !Path.IsPathRooted (" "));
884                         Assert ("IsPathRooted #06", Path.IsPathRooted ("/"));
885                         Assert ("IsPathRooted #07", Path.IsPathRooted ("//"));
886                         Assert ("IsPathRooted #08", !Path.IsPathRooted (":"));
887
888                         if (Windows) {
889                                 Assert ("IsPathRooted #09", Path.IsPathRooted ("\\"));
890                                 Assert ("IsPathRooted #10", Path.IsPathRooted ("\\\\"));
891                                 Assert ("IsPathRooted #11", Path.IsPathRooted ("z:"));
892                                 Assert ("IsPathRooted #12", Path.IsPathRooted ("z:\\"));
893                                 Assert ("IsPathRooted #13", Path.IsPathRooted ("z:\\topdir"));
894                                 // This looks MS BUG. It is treated as absolute path
895                                 Assert ("IsPathRooted #14", Path.IsPathRooted ("z:curdir"));
896                                 Assert ("IsPathRooted #15", Path.IsPathRooted ("\\abc\\def"));
897                         } else {
898                                 Assert ("IsPathRooted #09", !Path.IsPathRooted ("\\"));
899                                 Assert ("IsPathRooted #10", !Path.IsPathRooted ("\\\\"));
900                                 Assert ("IsPathRooted #11", !Path.IsPathRooted ("z:"));
901                         }
902                 }
903
904                 [Test]
905                 public void IsPathRooted_Path_Empty ()
906                 {
907                         Assert (!Path.IsPathRooted (String.Empty));
908                 }
909
910                 [Test]
911                 public void IsPathRooted_Path_InvalidPathChars ()
912                 {
913                         try {
914                                 Path.IsPathRooted ("hi\0world");
915                                 Fail ("#1");
916                         } catch (ArgumentException ex) {
917                                 // Illegal characters in path.
918                                 AssertEquals ("#2", typeof (ArgumentException), ex.GetType ());
919                                 AssertNull ("#3", ex.InnerException);
920                                 AssertNotNull ("#4", ex.Message);
921                                 AssertNull ("#5", ex.ParamName);
922                         }
923                 }
924
925                 [Test]
926                 public void IsPathRooted_Path_Null ()
927                 {
928                         Assert (!Path.IsPathRooted (null));
929                 }
930
931                 [Test]
932                 public void IsPathRooted_Path_Whitespace ()
933                 {
934                         Assert (!Path.IsPathRooted ("  "));
935                 }
936
937                 [Test]
938                 public void CanonicalizeDots ()
939                 {
940                         string current = Path.GetFullPath (".");
941                         Assert ("TestCanonicalizeDotst #01", !current.EndsWith ("."));
942                         string parent = Path.GetFullPath ("..");
943                         Assert ("TestCanonicalizeDotst #02", !current.EndsWith (".."));
944                 }
945
946                 [Test]
947                 public void WindowsSystem32_76191 ()
948                 {
949                         // check for Unix platforms - see FAQ for more details
950                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
951                         int platform = (int) Environment.OSVersion.Platform;
952                         if ((platform == 4) || (platform == 128))
953                                 return;
954
955                         string curdir = Directory.GetCurrentDirectory ();
956                         try {
957 #if TARGET_JVM
958                                 string system = "C:\\WINDOWS\\system32\\";
959 #else
960                                 string system = Environment.SystemDirectory;
961 #endif
962                                 Directory.SetCurrentDirectory (system);
963                                 string drive = system.Substring (0, 2);
964                                 AssertEquals ("current dir", system, Path.GetFullPath (drive));
965                         }
966                         finally {
967                                 Directory.SetCurrentDirectory (curdir);
968                         }
969                 }
970
971                 [Test]
972                 public void WindowsSystem32_77007 ()
973                 {
974                         // check for Unix platforms - see FAQ for more details
975                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
976                         int platform = (int) Environment.OSVersion.Platform;
977                         if ((platform == 4) || (platform == 128))
978                                 return;
979
980                         string curdir = Directory.GetCurrentDirectory ();
981                         try {
982 #if TARGET_JVM
983                                 string system = "C:\\WINDOWS\\system32\\";
984 #else
985                                 string system = Environment.SystemDirectory;
986 #endif
987                                 Directory.SetCurrentDirectory (system);
988                                 // e.g. C:dir (no backslash) will return CurrentDirectory + dir
989                                 string dir = system.Substring (0, 2) + "dir";
990                                 AssertEquals ("current dir", Path.Combine (system, "dir"), Path.GetFullPath (dir));
991                         }
992                         finally {
993                                 Directory.SetCurrentDirectory (curdir);
994                         }
995                 }
996
997                 [Test]
998 #if TARGET_JVM
999                 [Ignore("Java full (canonical) path always returns windows dir in caps")]
1000 #endif
1001                 public void WindowsDriveC14N_77058 ()
1002                 {
1003                         // check for Unix platforms - see FAQ for more details
1004                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1005                         int platform = (int) Environment.OSVersion.Platform;
1006                         if ((platform == 4) || (platform == 128))
1007                                 return;
1008
1009                         AssertEquals ("1", @"C:\Windows\dir", Path.GetFullPath (@"C:\Windows\System32\..\dir"));
1010                         AssertEquals ("2", @"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\dir"));
1011                         AssertEquals ("3", @"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\dir"));
1012                         AssertEquals ("4", @"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\..\dir"));
1013                         AssertEquals ("5", @"C:\dir\", Path.GetFullPath (@"C:\Windows\System32\..\.\..\.\..\dir\"));
1014                 }
1015
1016                 [Test]
1017                 public void InvalidPathChars_Values ()
1018                 {
1019                         char[] invalid = Path.InvalidPathChars;
1020                         if (Windows) {
1021 #if NET_2_0
1022                                 AssertEquals ("Length", 36, invalid.Length);
1023 #else
1024                                 AssertEquals ("Length", 15, invalid.Length);
1025 #endif
1026                                 foreach (char c in invalid) {
1027                                         int i = (int) c;
1028 #if NET_2_0
1029                                         if (i < 32)
1030                                                 continue;
1031 #else
1032                                         if ((i == 0) || (i == 8) || ((i > 15) && (i < 19)) || ((i > 19) && (i < 26)))
1033                                                 continue;
1034 #endif
1035                                         // in both 1.1 SP1 and 2.0
1036                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1037                                                 continue;
1038                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1039                                 }
1040                         } else {
1041                                 foreach (char c in invalid) {
1042                                         int i = (int) c;
1043                                         if (i == 0)
1044                                                 continue;
1045                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1046                                 }
1047                         }
1048                 }
1049
1050                 [Test]
1051                 public void InvalidPathChars_Modify ()
1052                 {
1053                         char[] expected = Path.InvalidPathChars;
1054                         char[] invalid = Path.InvalidPathChars;
1055                         char original = invalid[0];
1056                         try {
1057                                 invalid[0] = 'a';
1058                                 // kind of scary
1059                                 Assert ("expected", expected[0] == 'a');
1060                                 AssertEquals ("readonly", expected[0], Path.InvalidPathChars[0]);
1061                         } finally {
1062                                 invalid[0] = original;
1063                         }
1064                 }
1065
1066 #if NET_2_0
1067                 [Test]
1068                 public void GetInvalidFileNameChars_Values ()
1069                 {
1070                         char[] invalid = Path.GetInvalidFileNameChars ();
1071                         if (Windows) {
1072                                 AssertEquals (41, invalid.Length);
1073                                 foreach (char c in invalid) {
1074                                         int i = (int) c;
1075                                         if (i < 32)
1076                                                 continue;
1077                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1078                                                 continue;
1079                                         // ':', '*', '?', '\', '/'
1080                                         if ((i == 58) || (i == 42) || (i == 63) || (i == 92) || (i == 47))
1081                                                 continue;
1082                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1083                                 }
1084                         } else {
1085                                 foreach (char c in invalid) {
1086                                         int i = (int) c;
1087                                         // null or '/'
1088                                         if ((i == 0) || (i == 47))
1089                                                 continue;
1090                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1091                                 }
1092                         }
1093                 }
1094
1095                 [Test]
1096                 public void GetInvalidFileNameChars_Modify ()
1097                 {
1098                         char[] expected = Path.GetInvalidFileNameChars ();
1099                         char[] invalid = Path.GetInvalidFileNameChars ();
1100                         invalid[0] = 'a';
1101                         Assert ("expected", expected[0] != 'a');
1102                         AssertEquals ("readonly", expected[0], Path.GetInvalidFileNameChars ()[0]);
1103                 }
1104
1105                 [Test]
1106                 public void GetInvalidPathChars_Values ()
1107                 {
1108                         char[] invalid = Path.GetInvalidPathChars ();
1109                         if (Windows) {
1110                                 AssertEquals (36, invalid.Length);
1111                                 foreach (char c in invalid) {
1112                                         int i = (int) c;
1113                                         if (i < 32)
1114                                                 continue;
1115                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1116                                                 continue;
1117                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1118                                 }
1119                         } else {
1120                                 foreach (char c in invalid) {
1121                                         int i = (int) c;
1122                                         if (i == 0)
1123                                                 continue;
1124                                         Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1125                                 }
1126                         }
1127                 }
1128
1129                 [Test]
1130                 public void GetInvalidPathChars_Order ()
1131                 {
1132                         if (Windows) {
1133                                 char [] invalid = Path.GetInvalidPathChars ();
1134                                 char [] expected = new char [36] { '\x22', '\x3C', '\x3E', '\x7C', '\x00', '\x01', '\x02',
1135                                         '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D',
1136                                         '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18',
1137                                         '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F' };
1138                                 AssertEquals (expected.Length, invalid.Length);
1139                                 for (int i = 0; i < expected.Length; i++ ) {
1140                                         AssertEquals( "Character at position " + i,expected [i], invalid [i]);
1141                                 }
1142                         }
1143                 }
1144
1145                 [Test]
1146                 public void GetInvalidPathChars_Modify ()
1147                 {
1148                         char[] expected = Path.GetInvalidPathChars ();
1149                         char[] invalid = Path.GetInvalidPathChars ();
1150                         invalid[0] = 'a';
1151                         Assert ("expected", expected[0] != 'a');
1152                         AssertEquals ("readonly", expected[0], Path.GetInvalidPathChars ()[0]);
1153                 }
1154
1155                 [Test]
1156                 public void GetRandomFileName ()
1157                 {
1158                         string s = Path.GetRandomFileName ();
1159                         AssertEquals ("Length", 12, s.Length);
1160                         char[] invalid = Path.GetInvalidFileNameChars ();
1161                         for (int i=0; i < s.Length; i++) {
1162                                 if (i == 8)
1163                                         AssertEquals ("8", '.', s[i]);
1164                                 else
1165                                         Assert (i.ToString (), Array.IndexOf (invalid, s[i]) == -1);
1166                         }
1167                 }
1168
1169                 [Test]
1170                 public void GetRandomFileNameIsAlphaNumerical ()
1171                 {
1172                         string [] names = new string [1000];
1173                         for (int i = 0; i < names.Length; i++)
1174                                 names [i] = Path.GetRandomFileName ();
1175
1176                         foreach (string name in names) {
1177                                 AssertEquals (12, name.Length);
1178                                 AssertEquals ('.', name [8]);
1179
1180                                 for (int i = 0; i < 12; i++) {
1181                                         if (i == 8)
1182                                                 continue;
1183
1184                                         char c = name [i];
1185                                         Assert (('a' <= c && c <= 'z') || ('0' <= c && c <= '9'));
1186                                 }
1187                         }
1188                 }
1189 #endif
1190         }
1191 }
1192