New tests.
[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
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                         Assert.AreEqual (files [(int) OS], testPath, "ChangeExtension #01");
94
95                         testPath = Path.ChangeExtension (String.Empty, ".extension");
96                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #02");
97
98                         testPath = Path.ChangeExtension (null, ".extension");
99                         Assert.AreEqual (null, testPath, "ChangeExtension #03");
100
101                         testPath = Path.ChangeExtension ("path", null);
102                         Assert.AreEqual ("path", testPath, "ChangeExtension #04");
103
104                         testPath = Path.ChangeExtension ("path.ext", "doc");
105                         Assert.AreEqual ("path.doc", testPath, "ChangeExtension #05");
106
107                         testPath = Path.ChangeExtension ("path.ext1.ext2", "doc");
108                         Assert.AreEqual ("path.ext1.doc", testPath, "ChangeExtension #06");
109
110                         testPath = Path.ChangeExtension ("hogehoge.xml", ".xsl");
111                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #07");
112                         testPath = Path.ChangeExtension ("hogehoge", ".xsl");
113                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #08");
114                         testPath = Path.ChangeExtension ("hogehoge.xml", "xsl");
115                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #09");
116                         testPath = Path.ChangeExtension ("hogehoge", "xsl");
117                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #10");
118                         testPath = Path.ChangeExtension ("hogehoge.xml", String.Empty);
119                         Assert.AreEqual ("hogehoge.", testPath, "ChangeExtension #11");
120                         testPath = Path.ChangeExtension ("hogehoge", String.Empty);
121                         Assert.AreEqual ("hogehoge.", testPath, "ChangeExtension #12");
122                         testPath = Path.ChangeExtension ("hogehoge.", null);
123                         Assert.AreEqual ("hogehoge", testPath, "ChangeExtension #13");
124                         testPath = Path.ChangeExtension ("hogehoge", null);
125                         Assert.AreEqual ("hogehoge", testPath, "ChangeExtension #14");
126                         testPath = Path.ChangeExtension (String.Empty, null);
127                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #15");
128                         testPath = Path.ChangeExtension (String.Empty, "bashrc");
129                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #16");
130                         testPath = Path.ChangeExtension (String.Empty, ".bashrc");
131                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #17");
132                         testPath = Path.ChangeExtension (null, null);
133                         Assert.IsNull (testPath, "ChangeExtension #18");
134                 }
135
136                 [Test]
137                 public void ChangeExtension_Extension_InvalidPathChars () 
138                 {
139                         string fn = Path.ChangeExtension ("file.ext", "<");
140                         Assert.AreEqual ("file.<", fn, "Invalid filename");
141                 }
142
143                 [Test]
144                 public void ChangeExtension_Path_InvalidPathChars ()
145                 {
146                         try {
147                                 Path.ChangeExtension ("fi\0le.ext", ".extension");
148                                 Assert.Fail ("#1");
149                         } catch (ArgumentException ex) {
150                                 // Illegal characters in path
151                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
152                                 Assert.IsNull (ex.InnerException, "#3");
153                                 Assert.IsNotNull (ex.Message, "#4");
154                                 Assert.IsNull (ex.ParamName, "#5");
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                         Assert.AreEqual (files [(int) OS], testPath, "Combine #01");
168
169                         testPath = Path.Combine ("one", String.Empty);
170                         Assert.AreEqual ("one", testPath, "Combine #02");
171
172                         testPath = Path.Combine (String.Empty, "one");
173                         Assert.AreEqual ("one", testPath, "Combine #03");
174
175                         string current = Directory.GetCurrentDirectory ();
176                         testPath = Path.Combine (current, "one");
177
178                         string expected = current + DSC + "one";
179                         Assert.AreEqual (expected, testPath, "Combine #04");
180
181                         testPath = Path.Combine ("one", current);
182                         // LAMESPEC noted in Path.cs
183                         Assert.AreEqual (current, testPath, "Combine #05");
184
185                         testPath = Path.Combine (current, expected);
186                         Assert.AreEqual (expected, testPath, "Combine #06");
187
188                         testPath = DSC + "one";
189                         testPath = Path.Combine (testPath, "two" + DSC);
190                         expected = DSC + "one" + DSC + "two" + DSC;
191                         Assert.AreEqual (expected, testPath, "Combine #06");
192
193                         testPath = "one" + DSC;
194                         testPath = Path.Combine (testPath, DSC + "two");
195                         expected = DSC + "two";
196                         Assert.AreEqual (expected, testPath, "Combine #06");
197
198                         testPath = "one" + DSC;
199                         testPath = Path.Combine (testPath, "two" + DSC);
200                         expected = "one" + DSC + "two" + DSC;
201                         Assert.AreEqual (expected, testPath, "Combine #07");
202                 }
203
204                 [Test]
205                 public void Combine_Path1_InvalidPathChars ()
206                 {
207                         try {
208                                 Path.Combine ("a\0", "one");
209                                 Assert.Fail ("#1");
210                         } catch (ArgumentException ex) {
211                                 // Illegal characters in path
212                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
213                                 Assert.IsNull (ex.InnerException, "#3");
214                                 Assert.IsNotNull (ex.Message, "#4");
215                                 Assert.IsNull (ex.ParamName, "#5");
216                         }
217                 }
218
219                 [Test]
220                 public void Combine_Path1_Null ()
221                 {
222                         try {
223                                 Path.Combine (null, "one");
224                                 Assert.Fail ("#1");
225                         } catch (ArgumentNullException ex) {
226                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
227                                 Assert.IsNull (ex.InnerException, "#3");
228                                 Assert.IsNotNull (ex.Message, "#4");
229                                 Assert.AreEqual ("path1", ex.ParamName, "#5");
230                         }
231                 }
232
233                 [Test]
234                 public void Combine_Path2_InvalidPathChars ()
235                 {
236                         try {
237                                 Path.Combine ("one", "a\0");
238                                 Assert.Fail ("#1");
239                         } catch (ArgumentException ex) {
240                                 // Illegal characters in path
241                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
242                                 Assert.IsNull (ex.InnerException, "#3");
243                                 Assert.IsNotNull (ex.Message, "#4");
244                                 Assert.IsNull (ex.ParamName, "#5");
245                         }
246                 }
247
248                 [Test]
249                 public void Combine_Path2_Null ()
250                 {
251                         try {
252                                 Path.Combine ("one", null);
253                                 Assert.Fail ("#1");
254                         } catch (ArgumentNullException ex) {
255                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
256                                 Assert.IsNull (ex.InnerException, "#3");
257                                 Assert.IsNotNull (ex.Message, "#4");
258                                 Assert.AreEqual ("path2", ex.ParamName, "#5");
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                         Assert.AreEqual (files [(int) OS], testDirName, "#A1");
272                         testDirName = Path.GetDirectoryName (files [(int) OS] + DSC);
273                         Assert.AreEqual (files [(int) OS], testDirName, "#A2");
274
275                         if (Windows) {
276                                 Assert.AreEqual ("C:\\foo", Path.GetDirectoryName ("C:\\foo\\foo.txt"), "#B1");
277                                 Assert.AreEqual (null, Path.GetDirectoryName ("C:"), "#B2");
278                                 Assert.AreEqual (null, Path.GetDirectoryName (@"C:\"), "#B3");
279                                 Assert.AreEqual (@"C:\", Path.GetDirectoryName (@"C:\dir"), "#B4");
280                                 Assert.AreEqual (@"C:\dir", Path.GetDirectoryName (@"C:\dir\"), "#B5");
281                                 Assert.AreEqual (@"C:\dir", Path.GetDirectoryName (@"C:\dir\dir"), "#B6");
282                                 Assert.AreEqual (@"C:\dir\dir", Path.GetDirectoryName (@"C:\dir\dir\"), "#B7");
283
284                                 Assert.AreEqual ("\\foo\\bar", Path.GetDirectoryName ("/foo//bar/dingus"), "#C1");
285                                 Assert.AreEqual ("foo\\bar", Path.GetDirectoryName ("foo/bar/"), "#C2");
286                                 Assert.AreEqual ("foo\\bar", Path.GetDirectoryName ("foo/bar\\xxx"), "#C3");
287                                 Assert.AreEqual ("\\\\host\\dir\\dir2", Path.GetDirectoryName ("\\\\host\\dir\\\\dir2\\path"), "#C4");
288
289                                 // UNC tests
290                                 Assert.AreEqual (null, Path.GetDirectoryName (@"\\"), "#D1");
291                                 Assert.AreEqual (null, Path.GetDirectoryName (@"\\server"), "#D2");
292                                 Assert.AreEqual (null, Path.GetDirectoryName (@"\\server\share"), "#D3");
293                                 Assert.AreEqual (@"\\server\share", Path.GetDirectoryName (@"\\server\share\"), "#D4");
294                                 Assert.AreEqual (@"\\server\share", Path.GetDirectoryName (@"\\server\share\dir"), "#D5");
295                                 Assert.AreEqual (@"\\server\share\dir", Path.GetDirectoryName (@"\\server\share\dir\subdir"), "#D6");
296                         } else {
297                                 Assert.AreEqual ("/etc", Path.GetDirectoryName ("/etc/hostname"), "#B1");
298                                 Assert.AreEqual ("/foo/bar", Path.GetDirectoryName ("/foo//bar/dingus"), "#B2");
299                                 Assert.AreEqual ("foo/bar", Path.GetDirectoryName ("foo/bar/"), "#B3");
300                                 Assert.AreEqual ("/", Path.GetDirectoryName ("/tmp"), "#B4");
301                                 Assert.IsNull (Path.GetDirectoryName ("/"), "#B5");
302                                 Assert.AreEqual ("a", Path.GetDirectoryName ("a//b"), "#B6");
303                         }
304                 }
305
306                 [Test]
307                 public void GetDirectoryName_Path_Empty ()
308                 {
309                         try {
310                                 Path.GetDirectoryName (String.Empty);
311                                 Assert.Fail ("#1");
312                         } catch (ArgumentException ex) {
313                                 // The path is not of a legal form
314                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
315                                 Assert.IsNull (ex.InnerException, "#3");
316                                 Assert.IsNotNull (ex.Message, "#4");
317                                 Assert.IsNull (ex.ParamName, "#5");
318                         }
319                 }
320
321                 [Test]
322                 public void GetDirectoryName_Path_InvalidPathChars ()
323                 {
324                         try {
325                                 Path.GetDirectoryName ("hi\0world");
326                                 Assert.Fail ("#1");
327                         } catch (ArgumentException ex) {
328                                 // Illegal characters in path
329                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
330                                 Assert.IsNull (ex.InnerException, "#3");
331                                 Assert.IsNotNull (ex.Message, "#4");
332                                 Assert.IsNull (ex.ParamName, "#5");
333                         }
334                 }
335
336                 [Test]
337                 public void GetDirectoryName_Path_Null ()
338                 {
339                         Assert.IsNull (Path.GetDirectoryName (null));
340                 }
341
342                 [Test]
343                 public void GetDirectoryName_Path_Whitespace ()
344                 {
345                         try {
346                                 Path.GetDirectoryName ("   ");
347                                 Assert.Fail ("#1");
348                         } catch (ArgumentException ex) {
349                                 // The path is not of a legal form
350                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
351                                 Assert.IsNull (ex.InnerException, "#3");
352                                 Assert.IsNotNull (ex.Message, "#4");
353                                 Assert.IsNull (ex.ParamName, "#5");
354                         }
355                 }
356
357                 [Test]
358                 public void GetExtension ()
359                 {
360                         string testExtn = Path.GetExtension (path1);
361
362                         Assert.AreEqual (".txt", testExtn, "GetExtension #01");
363
364                         testExtn = Path.GetExtension (path2);
365                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #02");
366
367                         testExtn = Path.GetExtension (String.Empty);
368                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #03");
369
370                         testExtn = Path.GetExtension (null);
371                         Assert.AreEqual (null, testExtn, "GetExtension #04");
372
373                         testExtn = Path.GetExtension (" ");
374                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #05");
375
376                         testExtn = Path.GetExtension (path1 + ".doc");
377                         Assert.AreEqual (".doc", testExtn, "GetExtension #06");
378
379                         testExtn = Path.GetExtension (path1 + ".doc" + DSC + "a.txt");
380                         Assert.AreEqual (".txt", testExtn, "GetExtension #07");
381
382                         testExtn = Path.GetExtension (".");
383                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #08");
384
385                         testExtn = Path.GetExtension ("end.");
386                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #09");
387
388                         testExtn = Path.GetExtension (".start");
389                         Assert.AreEqual (".start", testExtn, "GetExtension #10");
390
391                         testExtn = Path.GetExtension (".a");
392                         Assert.AreEqual (".a", testExtn, "GetExtension #11");
393
394                         testExtn = Path.GetExtension ("a.");
395                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #12");
396
397                         testExtn = Path.GetExtension ("a");
398                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #13");
399
400                         testExtn = Path.GetExtension ("makefile");
401                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #14");
402                 }
403
404                 [Test]
405                 public void GetExtension_Path_InvalidPathChars ()
406                 {
407                         try {
408                                 Path.GetExtension ("hi\0world.txt");
409                                 Assert.Fail ("#1");
410                         } catch (ArgumentException ex) {
411                                 // Illegal characters in path.
412                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
413                                 Assert.IsNull (ex.InnerException, "#3");
414                                 Assert.IsNotNull (ex.Message, "#4");
415                                 Assert.IsNull (ex.ParamName, "#5");
416                         }
417                 }
418
419                 [Test]
420                 public void GetFileName ()
421                 {
422                         string testFileName = Path.GetFileName (path1);
423
424                         Assert.AreEqual ("test.txt", testFileName, "#1");
425                         testFileName = Path.GetFileName (null);
426                         Assert.AreEqual (null, testFileName, "#2");
427                         testFileName = Path.GetFileName (String.Empty);
428                         Assert.AreEqual (String.Empty, testFileName, "#3");
429                         testFileName = Path.GetFileName (" ");
430                         Assert.AreEqual (" ", testFileName, "#4");
431                 }
432
433                 [Test]
434                 public void GetFileName_Path_InvalidPathChars ()
435                 {
436                         try {
437                                 Path.GetFileName ("hi\0world");
438                                 Assert.Fail ("#1");
439                         } catch (ArgumentException ex) {
440                                 // Illegal characters in path
441                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
442                                 Assert.IsNull (ex.InnerException, "#3");
443                                 Assert.IsNotNull (ex.Message, "#4");
444                                 Assert.IsNull (ex.ParamName, "#5");
445                         }
446                 }
447
448                 [Test]
449                 public void GetFileNameWithoutExtension ()
450                 {
451                         string testFileName = Path.GetFileNameWithoutExtension (path1);
452
453                         Assert.AreEqual ("test", testFileName, "GetFileNameWithoutExtension #01");
454
455                         testFileName = Path.GetFileNameWithoutExtension (null);
456                         Assert.AreEqual (null, testFileName, "GetFileNameWithoutExtension #02");
457
458                         testFileName = Path.GetFileNameWithoutExtension (String.Empty);
459                         Assert.AreEqual (String.Empty, testFileName, "GetFileNameWithoutExtension #03");
460                 }
461
462                 [Test]
463                 public void GetFileNameWithoutExtension_Path_InvalidPathChars ()
464                 {
465                         try {
466                                 Path.GetFileNameWithoutExtension ("hi\0world");
467                                 Assert.Fail ("#1");
468                         } catch (ArgumentException ex) {
469                                 // Illegal characters in path
470                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
471                                 Assert.IsNull (ex.InnerException, "#3");
472                                 Assert.IsNotNull (ex.Message, "#4");
473                                 Assert.IsNull (ex.ParamName, "#5");
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                         Assert.AreEqual (expected, testFullPath, "GetFullPath #01");
485
486                         testFullPath = Path.GetFullPath ("a//./.././foo.txt");
487                         Assert.AreEqual (expected, testFullPath, "GetFullPath #02");
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                                 Assert.AreEqual (root + test [i, 1], Path.GetFullPath (root + test [i, 0]),
529                                                  String.Format ("GetFullPathUnix #{0}", i));
530                         }
531
532                         Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
533                         Assert.AreEqual ("/hey", Path.GetFullPath ("/hey"), "#02");
534                         Assert.AreEqual (Environment.CurrentDirectory, Path.GetFullPath ("."), "#03");
535                         Assert.AreEqual (Path.Combine (Environment.CurrentDirectory, "hey"),
536                                              Path.GetFullPath ("hey"), "#04");
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 #if !NET_2_0
567                                 {"root/      .              /", "root\\"},
568                                 {"root/      ..             /", ""},
569 #endif
570                                 {"root/./", "root\\"},
571                                 {"root/..                      /", ""},
572                                 {".//", ""}
573                         };
574
575                         for (int i = 0; i < test.GetUpperBound (0); i++) {
576                                 try {
577                                         Assert.AreEqual (root + test [i, 1], Path.GetFullPath (root + test [i, 0]),
578                                                          String.Format ("GetFullPathWindows #{0}", i));
579                                 } catch (Exception ex) { 
580                                         Assert.Fail (String.Format ("GetFullPathWindows #{0} (\"{1}\") failed: {2}", 
581                                                 i, root + test [i, 0], ex.GetType ()));
582                                 }
583                         }
584
585                         // UNC tests
586                         string root2 = @"\\server\share";
587                         root = @"\\server\share\";
588                         test = new string [,] {         
589                                 {"root////././././././../root/././../root", "root"},
590                                 {"root/", "root\\"},
591                                 {"root/./", "root\\"},
592                                 {"root/./", "root\\"},
593                                 {"root/../", ""},
594                                 {"root/../", ""},
595                                 {"root/../..", null},
596                                 {"root/.hiddenfile", "root\\.hiddenfile"},
597                                 {"root/. /", "root\\"},
598                                 {"root/.. /", ""},
599                                 {"root/..weirdname", "root\\..weirdname"},
600                                 {"root/..", null},
601                                 {"root/../a/b/../../..", null},
602                                 {"root/./..", null},
603                                 {"..", null},
604                                 {".", null},
605                                 {"root//dir", "root\\dir"},
606                                 {"root/.              /", "root\\"},
607                                 {"root/..             /", ""},
608 #if !NET_2_0
609                                 {"root/      .              /", "root\\"},
610                                 {"root/      ..             /", ""},
611 #endif
612                                 {"root/./", "root\\"},
613                                 {"root/..                      /", ""},
614                                 {".//", ""}
615                         };
616
617                         for (int i = 0; i < test.GetUpperBound (0); i++) {
618                                 // "null" means we have to compare against "root2"
619                                 string res = test [i, 1] != null
620                                         ? root + test [i, 1]
621                                         : root2;
622                                 try {
623                                         Assert.AreEqual (res, Path.GetFullPath (root + test [i, 0]),
624                                                          String.Format ("GetFullPathWindows UNC #{0}", i));
625                                 } catch (AssertionException) {
626                                         throw;
627                                 } catch (Exception ex) {
628                                         Assert.Fail (String.Format ("GetFullPathWindows UNC #{0} (\"{1}\") failed: {2}",
629                                                 i, root + test [i, 0], ex.GetType ()));
630                                 }
631                         }
632
633                         test = new string [,] {         
634                                 {"root////././././././../root/././../root", "root"},
635                                 {"root/", "root\\"},
636                                 {"root/./", "root\\"},
637                                 {"root/./", "root\\"},
638                                 {"root/../", ""},
639                                 {"root/../", ""},
640                                 {"root/../..", null},
641                                 {"root/.hiddenfile", "root\\.hiddenfile"},
642                                 {"root/. /", "root\\"},
643                                 {"root/.. /", ""},
644                                 {"root/..weirdname", "root\\..weirdname"},
645                                 {"root/..", null},
646                                 {"root/../a/b/../../..", null},
647                                 {"root/./..", null},
648                                 {"..", null},
649                                 {".", null},
650                                 {"root//dir", "root\\dir"},
651                                 {"root/.              /", "root\\"},
652                                 {"root/..             /", ""},
653 #if !NET_2_0
654                                 {"root/      .              /", "root\\"},
655                                 {"root/      ..             /", ""},
656 #endif
657                                 {"root/./", "root\\"},
658                                 {"root/..                      /", ""},
659                                 {".//", ""}
660                         };
661
662                         string root3 = @"//server/share";
663                         root = @"//server/share/";
664                         bool needSlashConvert = Path.DirectorySeparatorChar != '/';
665
666                         for (int i = 0; i < test.GetUpperBound (0); i++) {
667                                 // "null" means we have to compare against "root2"
668                                 string res = test [i, 1] != null
669                                         ? root + test [i, 1]
670                                         : root3;
671                                 if (needSlashConvert)
672                                         res = res.Replace ('/', Path.DirectorySeparatorChar);
673                                 try {
674                                         Assert.AreEqual (res, Path.GetFullPath (root + test [i, 0]),
675                                                          String.Format ("GetFullPathWindows UNC[2] #{0}", i));
676                                 } catch (AssertionException) {
677                                         throw;
678                                 } catch (Exception ex) {
679                                         Assert.Fail (String.Format ("GetFullPathWindows UNC[2] #{0} (\"{1}\") failed: {2}",
680                                                 i, root + test [i, 0], ex.GetType ()));
681                                 }
682                         }
683                 }
684
685                 [Test]
686                 public void GetFullPath_Path_Empty ()
687                 {
688                         try {
689                                 Path.GetFullPath (String.Empty);
690                                 Assert.Fail ("#1");
691                         } catch (ArgumentException ex) {
692                                 // The path is not of a legal form
693                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
694                                 Assert.IsNull (ex.InnerException, "#3");
695                                 Assert.IsNotNull (ex.Message, "#4");
696                                 Assert.IsNull (ex.ParamName, "#5");
697                         }
698                 }
699
700                 [Test]
701                 public void GetFullPath_Path_EndingSeparator ()
702                 {
703                         string fp = Path.GetFullPath ("something/");
704                         char end = fp [fp.Length - 1];
705                         Assert.IsTrue (end == Path.DirectorySeparatorChar);
706                 }
707
708                 [Test]
709                 public void GetFullPath_Path_InvalidPathChars ()
710                 {
711                         try {
712                                 Path.GetFullPath ("hi\0world");
713                                 Assert.Fail ("#1");
714                         } catch (ArgumentException ex) {
715                                 // Illegal characters in path
716                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
717                                 Assert.IsNull (ex.InnerException, "#3");
718                                 Assert.IsNotNull (ex.Message, "#4");
719                                 Assert.IsNull (ex.ParamName, "#5");
720                         }
721                 }
722
723                 [Test]
724                 public void GetFullPath_Path_Null ()
725                 {
726                         try {
727                                 Path.GetFullPath (null);
728                                 Assert.Fail ("#1");
729                         } catch (ArgumentNullException ex) {
730                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
731                                 Assert.IsNull (ex.InnerException, "#3");
732                                 Assert.IsNotNull (ex.Message, "#4");
733                                 Assert.AreEqual ("path", ex.ParamName, "#5");
734                         }
735                 }
736
737                 [Test]
738                 public void GetFullPath_Path_Whitespace ()
739                 {
740                         try {
741                                 Path.GetFullPath ("  ");
742                                 Assert.Fail ("#1");
743                         } catch (ArgumentException ex) {
744                                 // The path is not of a legal form
745                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
746                                 Assert.IsNull (ex.InnerException, "#3");
747                                 Assert.IsNotNull (ex.Message, "#4");
748                                 Assert.IsNull (ex.ParamName, "#5");
749                         }
750                 }
751
752                 [Test]
753                 public void GetFullPath2 ()
754                 {
755                         if (Windows) {
756                                 Assert.AreEqual (@"Z:\", Path.GetFullPath ("Z:"), "GetFullPath w#01");
757 #if !TARGET_JVM // Java full (canonical) path always starts with caps drive letter
758                                 Assert.AreEqual (@"c:\abc\def", Path.GetFullPath (@"c:\abc\def"), "GetFullPath w#02");
759 #endif
760                                 Assert.IsTrue (Path.GetFullPath (@"\").EndsWith (@"\"), "GetFullPath w#03");
761                                 // "\\\\" is not allowed
762                                 Assert.IsTrue (Path.GetFullPath ("/").EndsWith (@"\"), "GetFullPath w#05");
763                                 // "//" is not allowed
764                                 Assert.IsTrue (Path.GetFullPath ("readme.txt").EndsWith (@"\readme.txt"), "GetFullPath w#07");
765                                 Assert.IsTrue (Path.GetFullPath ("c").EndsWith (@"\c"), "GetFullPath w#08");
766                                 Assert.IsTrue (Path.GetFullPath (@"abc\def").EndsWith (@"abc\def"), "GetFullPath w#09");
767                                 Assert.IsTrue (Path.GetFullPath (@"\abc\def").EndsWith (@"\abc\def"), "GetFullPath w#10");
768                                 Assert.AreEqual (@"\\abc\def", Path.GetFullPath (@"\\abc\def"), "GetFullPath w#11");
769                                 Assert.AreEqual (Directory.GetCurrentDirectory () + @"\abc\def", Path.GetFullPath (@"abc//def"), "GetFullPath w#12");
770                                 Assert.AreEqual (Directory.GetCurrentDirectory ().Substring (0, 2) + @"\abc\def", Path.GetFullPath ("/abc/def"), "GetFullPath w#13");
771                                 Assert.AreEqual (@"\\abc\def", Path.GetFullPath ("//abc/def"), "GetFullPath w#14");
772                         } else {
773                                 Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
774                                 Assert.AreEqual ("/hey", Path.GetFullPath ("/hey"), "#02");
775                                 Assert.AreEqual (Environment.CurrentDirectory, Path.GetFullPath ("."), "#03");
776                                 Assert.AreEqual (Path.Combine (Environment.CurrentDirectory, "hey"),
777                                                      Path.GetFullPath ("hey"), "#04");
778                         }
779                 }
780
781                 [Test]
782                 public void GetPathRoot ()
783                 {
784                         string current;
785                         string expected;
786                         if (!Windows){
787                                 current = Directory.GetCurrentDirectory ();
788                                 expected = current [0].ToString ();
789                         } else {
790                                 current = @"J:\Some\Strange Directory\Name";
791                                 expected = "J:\\";
792                         }
793
794                         string pathRoot = Path.GetPathRoot (current);
795                         Assert.AreEqual (expected, pathRoot, "GetPathRoot #01");
796                 }
797
798                 [Test]
799                 public void GetPathRoot2 ()
800                 {
801                         // note: this method doesn't call Directory.GetCurrentDirectory so it can be
802                         // reused for partial trust unit tests in PathCas.cs
803
804                         string pathRoot;
805                         
806                         pathRoot = Path.GetPathRoot ("hola");
807                         Assert.AreEqual (String.Empty, pathRoot, "#A1");
808                         pathRoot = Path.GetPathRoot (null);
809                         Assert.AreEqual (null, pathRoot, "#A2");
810
811                         if (Windows) {
812                                 Assert.AreEqual ("z:", Path.GetPathRoot ("z:"), "GetPathRoot w#01");
813                                 Assert.AreEqual ("c:\\", Path.GetPathRoot ("c:\\abc\\def"), "GetPathRoot w#02");
814                                 Assert.AreEqual ("\\", Path.GetPathRoot ("\\"), "GetPathRoot w#03");
815                                 Assert.AreEqual ("\\\\", Path.GetPathRoot ("\\\\"), "GetPathRoot w#04");
816                                 Assert.AreEqual ("\\", Path.GetPathRoot ("/"), "GetPathRoot w#05");
817                                 Assert.AreEqual ("\\\\", Path.GetPathRoot ("//"), "GetPathRoot w#06");
818                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("readme.txt"), "GetPathRoot w#07");
819                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("c"), "GetPathRoot w#08");
820                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("abc\\def"), "GetPathRoot w#09");
821                                 Assert.AreEqual ("\\", Path.GetPathRoot ("\\abc\\def"), "GetPathRoot w#10");
822                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def"), "GetPathRoot w#11");
823                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("abc//def"), "GetPathRoot w#12");
824                                 Assert.AreEqual ("\\", Path.GetPathRoot ("/abc/def"), "GetPathRoot w#13");
825                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("//abc/def"), "GetPathRoot w#14");
826                                 Assert.AreEqual (@"C:\", Path.GetPathRoot (@"C:\"), "GetPathRoot w#15");
827                                 Assert.AreEqual (@"C:\", Path.GetPathRoot (@"C:\\"), "GetPathRoot w#16");
828                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def\\ghi"), "GetPathRoot w#17");
829                         } else {
830                                 // TODO: Same tests for Unix.
831                         }
832                 }
833
834                 [Test]
835                 public void GetPathRoot_Path_Empty ()
836                 {
837                         try {
838                                 Path.GetPathRoot (String.Empty);
839                                 Assert.Fail ("#1");
840                         } catch (ArgumentException ex) {
841                                 // The path is not of a legal form
842                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
843                                 Assert.IsNull (ex.InnerException, "#3");
844                                 Assert.IsNotNull (ex.Message, "#4");
845                                 Assert.IsNull (ex.ParamName, "#5");
846                         }
847                 }
848
849                 [Test]
850 #if ONLY_1_1
851                 [Category ("NotWorking")] // we also throw ArgumentException on 1.0 profile
852 #endif
853                 public void GetPathRoot_Path_InvalidPathChars ()
854                 {
855 #if NET_2_0
856                         try {
857                                 Path.GetPathRoot ("hi\0world");
858                                 Assert.Fail ("#1");
859                         } catch (ArgumentException ex) {
860                                 // Illegal characters in path
861                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
862                                 Assert.IsNull (ex.InnerException, "#3");
863                                 Assert.IsNotNull (ex.Message, "#4");
864                                 Assert.IsNull (ex.ParamName, "#5");
865                         }
866 #else
867                         Assert.AreEqual (String.Empty, Path.GetPathRoot ("hi\0world"));
868 #endif
869                 }
870
871                 [Test]
872                 public void GetPathRoot_Path_Whitespace ()
873                 {
874                         try {
875                                 Path.GetPathRoot ("  ");
876                                 Assert.Fail ("#1");
877                         } catch (ArgumentException ex) {
878                                 // The path is not of a legal form
879                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
880                                 Assert.IsNull (ex.InnerException, "#3");
881                                 Assert.IsNotNull (ex.Message, "#4");
882                                 Assert.IsNull (ex.ParamName, "#5");
883                         }
884                 }
885
886                 [Test]
887                 public void GetTempPath ()
888                 {
889                         string getTempPath = Path.GetTempPath ();
890                         Assert.IsTrue (getTempPath != String.Empty, "GetTempPath #01");
891                         Assert.IsTrue (Path.IsPathRooted (getTempPath), "GetTempPath #02");
892                         Assert.AreEqual (Path.DirectorySeparatorChar, getTempPath [getTempPath.Length - 1], "GetTempPath #03");
893                 }
894
895                 [Test]
896                 public void GetTempFileName ()
897                 {
898                         string getTempFileName = null;
899                         try {
900                                 getTempFileName = Path.GetTempFileName ();
901                                 Assert.IsTrue (getTempFileName != String.Empty, "GetTempFileName #01");
902                                 Assert.IsTrue (File.Exists (getTempFileName), "GetTempFileName #02");
903                         } finally {
904                                 if (getTempFileName != null && getTempFileName != String.Empty){
905                                         File.Delete (getTempFileName);
906                                 }
907                         }
908                 }
909
910                 [Test]
911                 public void HasExtension ()
912                 {
913                         Assert.AreEqual (true, Path.HasExtension ("foo.txt"), "HasExtension #01");
914                         Assert.AreEqual (false, Path.HasExtension ("foo"), "HasExtension #02");
915                         Assert.AreEqual (true, Path.HasExtension (path1), "HasExtension #03");
916                         Assert.AreEqual (false, Path.HasExtension (path2), "HasExtension #04");
917                         Assert.AreEqual (false, Path.HasExtension (null), "HasExtension #05");
918                         Assert.AreEqual (false, Path.HasExtension (String.Empty), "HasExtension #06");
919                         Assert.AreEqual (false, Path.HasExtension (" "), "HasExtension #07");
920                         Assert.AreEqual (false, Path.HasExtension ("."), "HasExtension #08");
921                         Assert.AreEqual (false, Path.HasExtension ("end."), "HasExtension #09");
922                         Assert.AreEqual (true, Path.HasExtension (".start"), "HasExtension #10");
923                         Assert.AreEqual (true, Path.HasExtension (".a"), "HasExtension #11");
924                         Assert.AreEqual (false, Path.HasExtension ("a."), "HasExtension #12");
925                         Assert.AreEqual (false, Path.HasExtension ("Makefile"), "HasExtension #13");
926                 }
927
928                 [Test]
929                 public void HasExtension_Path_InvalidPathChars ()
930                 {
931                         try {
932                                 Path.HasExtension ("hi\0world.txt");
933                                 Assert.Fail ("#1");
934                         } catch (ArgumentException ex) {
935                                 // Illegal characters in path
936                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
937                                 Assert.IsNull (ex.InnerException, "#3");
938                                 Assert.IsNotNull (ex.Message, "#4");
939                                 Assert.IsNull (ex.ParamName, "#5");
940                         }
941                 }
942
943                 [Test]
944                 public void IsPathRooted ()
945                 {
946                         Assert.IsTrue (Path.IsPathRooted (path2), "IsPathRooted #01");
947                         Assert.IsTrue (!Path.IsPathRooted (path3), "IsPathRooted #02");
948                         Assert.IsTrue (!Path.IsPathRooted (null), "IsPathRooted #03");
949                         Assert.IsTrue (!Path.IsPathRooted (String.Empty), "IsPathRooted #04");
950                         Assert.IsTrue (!Path.IsPathRooted (" "), "IsPathRooted #05");
951                         Assert.IsTrue (Path.IsPathRooted ("/"), "IsPathRooted #06");
952                         Assert.IsTrue (Path.IsPathRooted ("//"), "IsPathRooted #07");
953                         Assert.IsTrue (!Path.IsPathRooted (":"), "IsPathRooted #08");
954
955                         if (Windows) {
956                                 Assert.IsTrue (Path.IsPathRooted ("\\"), "IsPathRooted #09");
957                                 Assert.IsTrue (Path.IsPathRooted ("\\\\"), "IsPathRooted #10");
958                                 Assert.IsTrue (Path.IsPathRooted ("z:"), "IsPathRooted #11");
959                                 Assert.IsTrue (Path.IsPathRooted ("z:\\"), "IsPathRooted #12");
960                                 Assert.IsTrue (Path.IsPathRooted ("z:\\topdir"), "IsPathRooted #13");
961                                 // This looks MS BUG. It is treated as absolute path
962                                 Assert.IsTrue (Path.IsPathRooted ("z:curdir"), "IsPathRooted #14");
963                                 Assert.IsTrue (Path.IsPathRooted ("\\abc\\def"), "IsPathRooted #15");
964                         } else {
965                                 Assert.IsTrue (!Path.IsPathRooted ("\\"), "IsPathRooted #09");
966                                 Assert.IsTrue (!Path.IsPathRooted ("\\\\"), "IsPathRooted #10");
967                                 Assert.IsTrue (!Path.IsPathRooted ("z:"), "IsPathRooted #11");
968                         }
969                 }
970
971                 [Test]
972                 public void IsPathRooted_Path_Empty ()
973                 {
974                         Assert.IsTrue (!Path.IsPathRooted (String.Empty));
975                 }
976
977                 [Test]
978                 public void IsPathRooted_Path_InvalidPathChars ()
979                 {
980                         try {
981                                 Path.IsPathRooted ("hi\0world");
982                                 Assert.Fail ("#1");
983                         } catch (ArgumentException ex) {
984                                 // Illegal characters in path.
985                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
986                                 Assert.IsNull (ex.InnerException, "#3");
987                                 Assert.IsNotNull (ex.Message, "#4");
988                                 Assert.IsNull (ex.ParamName, "#5");
989                         }
990                 }
991
992                 [Test]
993                 public void IsPathRooted_Path_Null ()
994                 {
995                         Assert.IsTrue (!Path.IsPathRooted (null));
996                 }
997
998                 [Test]
999                 public void IsPathRooted_Path_Whitespace ()
1000                 {
1001                         Assert.IsTrue (!Path.IsPathRooted ("  "));
1002                 }
1003
1004                 [Test]
1005                 public void CanonicalizeDots ()
1006                 {
1007                         string current = Path.GetFullPath (".");
1008                         Assert.IsTrue (!current.EndsWith ("."), "TestCanonicalizeDotst #01");
1009                         string parent = Path.GetFullPath ("..");
1010                         Assert.IsTrue (!current.EndsWith (".."), "TestCanonicalizeDotst #02");
1011                 }
1012
1013                 [Test]
1014                 public void WindowsSystem32_76191 ()
1015                 {
1016                         // check for Unix platforms - see FAQ for more details
1017                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1018                         int platform = (int) Environment.OSVersion.Platform;
1019                         if ((platform == 4) || (platform == 128) || (platform == 6))
1020                                 return;
1021
1022                         string curdir = Directory.GetCurrentDirectory ();
1023                         try {
1024 #if TARGET_JVM
1025                                 string system = "C:\\WINDOWS\\system32\\";
1026 #else
1027                                 string system = Environment.SystemDirectory;
1028 #endif
1029                                 Directory.SetCurrentDirectory (system);
1030                                 string drive = system.Substring (0, 2);
1031                                 Assert.AreEqual (system, Path.GetFullPath (drive), "current dir");
1032                         }
1033                         finally {
1034                                 Directory.SetCurrentDirectory (curdir);
1035                         }
1036                 }
1037
1038                 [Test]
1039                 public void WindowsSystem32_77007 ()
1040                 {
1041                         // check for Unix platforms - see FAQ for more details
1042                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1043                         int platform = (int) Environment.OSVersion.Platform;
1044                         if ((platform == 4) || (platform == 128) || (platform == 6))
1045                                 return;
1046
1047                         string curdir = Directory.GetCurrentDirectory ();
1048                         try {
1049 #if TARGET_JVM
1050                                 string system = "C:\\WINDOWS\\system32\\";
1051 #else
1052                                 string system = Environment.SystemDirectory;
1053 #endif
1054                                 Directory.SetCurrentDirectory (system);
1055                                 // e.g. C:dir (no backslash) will return CurrentDirectory + dir
1056                                 string dir = system.Substring (0, 2) + "dir";
1057                                 Assert.AreEqual (Path.Combine (system, "dir"), Path.GetFullPath (dir), "current dir");
1058                         }
1059                         finally {
1060                                 Directory.SetCurrentDirectory (curdir);
1061                         }
1062                 }
1063
1064                 [Test]
1065 #if TARGET_JVM
1066                 [Ignore("Java full (canonical) path always returns windows dir in caps")]
1067 #endif
1068                 public void WindowsDriveC14N_77058 ()
1069                 {
1070                         // check for Unix platforms - see FAQ for more details
1071                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1072                         int platform = (int) Environment.OSVersion.Platform;
1073                         if ((platform == 4) || (platform == 128) || (platform == 6))
1074                                 return;
1075
1076                         Assert.AreEqual (@"C:\Windows\dir", Path.GetFullPath (@"C:\Windows\System32\..\dir"), "1");
1077                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\dir"), "2");
1078                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\dir"), "3");
1079                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\..\dir"), "4");
1080                         Assert.AreEqual (@"C:\dir\", Path.GetFullPath (@"C:\Windows\System32\..\.\..\.\..\dir\"), "5");
1081                 }
1082
1083                 [Test]
1084                 public void InvalidPathChars_Values ()
1085                 {
1086                         char[] invalid = Path.InvalidPathChars;
1087                         if (Windows) {
1088 #if NET_2_0
1089                                 Assert.AreEqual (36, invalid.Length, "Length");
1090 #else
1091                                 Assert.AreEqual (15, invalid.Length, "Length");
1092 #endif
1093                                 foreach (char c in invalid) {
1094                                         int i = (int) c;
1095 #if NET_2_0
1096                                         if (i < 32)
1097                                                 continue;
1098 #else
1099                                         if ((i == 0) || (i == 8) || ((i > 15) && (i < 19)) || ((i > 19) && (i < 26)))
1100                                                 continue;
1101 #endif
1102                                         // in both 1.1 SP1 and 2.0
1103                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1104                                                 continue;
1105                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1106                                 }
1107                         } else {
1108                                 foreach (char c in invalid) {
1109                                         int i = (int) c;
1110                                         if (i == 0)
1111                                                 continue;
1112                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1113                                 }
1114                         }
1115                 }
1116
1117                 [Test]
1118                 public void InvalidPathChars_Modify ()
1119                 {
1120                         char[] expected = Path.InvalidPathChars;
1121                         char[] invalid = Path.InvalidPathChars;
1122                         char original = invalid[0];
1123                         try {
1124                                 invalid[0] = 'a';
1125                                 // kind of scary
1126                                 Assert.IsTrue (expected[0] == 'a', "expected");
1127                                 Assert.AreEqual (expected[0], Path.InvalidPathChars[0], "readonly");
1128                         } finally {
1129                                 invalid[0] = original;
1130                         }
1131                 }
1132
1133 #if NET_2_0
1134                 [Test]
1135                 public void GetInvalidFileNameChars_Values ()
1136                 {
1137                         char[] invalid = Path.GetInvalidFileNameChars ();
1138                         if (Windows) {
1139                                 Assert.AreEqual (41, invalid.Length);
1140                                 foreach (char c in invalid) {
1141                                         int i = (int) c;
1142                                         if (i < 32)
1143                                                 continue;
1144                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1145                                                 continue;
1146                                         // ':', '*', '?', '\', '/'
1147                                         if ((i == 58) || (i == 42) || (i == 63) || (i == 92) || (i == 47))
1148                                                 continue;
1149                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1150                                 }
1151                         } else {
1152                                 foreach (char c in invalid) {
1153                                         int i = (int) c;
1154                                         // null or '/'
1155                                         if ((i == 0) || (i == 47))
1156                                                 continue;
1157                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1158                                 }
1159                         }
1160                 }
1161
1162                 [Test]
1163                 public void GetInvalidFileNameChars_Modify ()
1164                 {
1165                         char[] expected = Path.GetInvalidFileNameChars ();
1166                         char[] invalid = Path.GetInvalidFileNameChars ();
1167                         invalid[0] = 'a';
1168                         Assert.IsTrue (expected[0] != 'a', "expected");
1169                         Assert.AreEqual (expected[0], Path.GetInvalidFileNameChars ()[0], "readonly");
1170                 }
1171
1172                 [Test]
1173                 public void GetInvalidPathChars_Values ()
1174                 {
1175                         char[] invalid = Path.GetInvalidPathChars ();
1176                         if (Windows) {
1177                                 Assert.AreEqual (36, invalid.Length);
1178                                 foreach (char c in invalid) {
1179                                         int i = (int) c;
1180                                         if (i < 32)
1181                                                 continue;
1182                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1183                                                 continue;
1184                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1185                                 }
1186                         } else {
1187                                 foreach (char c in invalid) {
1188                                         int i = (int) c;
1189                                         if (i == 0)
1190                                                 continue;
1191                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1192                                 }
1193                         }
1194                 }
1195
1196                 [Test]
1197                 public void GetInvalidPathChars_Order ()
1198                 {
1199                         if (Windows) {
1200                                 char [] invalid = Path.GetInvalidPathChars ();
1201                                 char [] expected = new char [36] { '\x22', '\x3C', '\x3E', '\x7C', '\x00', '\x01', '\x02',
1202                                         '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D',
1203                                         '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18',
1204                                         '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F' };
1205                                 Assert.AreEqual (expected.Length, invalid.Length);
1206                                 for (int i = 0; i < expected.Length; i++ ) {
1207                                         Assert.AreEqual (expected [i], invalid [i], "Character at position " + i);
1208                                 }
1209                         }
1210                 }
1211
1212                 [Test]
1213                 public void GetInvalidPathChars_Modify ()
1214                 {
1215                         char[] expected = Path.GetInvalidPathChars ();
1216                         char[] invalid = Path.GetInvalidPathChars ();
1217                         invalid[0] = 'a';
1218                         Assert.IsTrue (expected[0] != 'a', "expected");
1219                         Assert.AreEqual (expected[0], Path.GetInvalidPathChars ()[0], "readonly");
1220                 }
1221
1222                 [Test]
1223                 public void GetRandomFileName ()
1224                 {
1225                         string s = Path.GetRandomFileName ();
1226                         Assert.AreEqual (12, s.Length, "Length");
1227                         char[] invalid = Path.GetInvalidFileNameChars ();
1228                         for (int i=0; i < s.Length; i++) {
1229                                 if (i == 8)
1230                                         Assert.AreEqual ('.', s[i], "8");
1231                                 else
1232                                         Assert.IsTrue (Array.IndexOf (invalid, s[i]) == -1, i.ToString ());
1233                         }
1234                 }
1235
1236                 [Test]
1237                 public void GetRandomFileNameIsAlphaNumerical ()
1238                 {
1239                         string [] names = new string [1000];
1240                         for (int i = 0; i < names.Length; i++)
1241                                 names [i] = Path.GetRandomFileName ();
1242
1243                         foreach (string name in names) {
1244                                 Assert.AreEqual (12, name.Length);
1245                                 Assert.AreEqual ('.', name [8]);
1246
1247                                 for (int i = 0; i < 12; i++) {
1248                                         if (i == 8)
1249                                                 continue;
1250
1251                                         char c = name [i];
1252                                         Assert.IsTrue (('a' <= c && c <= 'z') || ('0' <= c && c <= '9'));
1253                                 }
1254                         }
1255                 }
1256 #endif
1257 #if NET_4_0
1258                 string Concat (string sep, params string [] parms)
1259                 {
1260                         return String.Join (sep, parms);
1261                 }
1262
1263                 [Test]
1264                 public void Combine_3Params ()
1265                 {
1266                         string sep = Path.DirectorySeparatorChar.ToString ();
1267
1268                         try {
1269                                 Path.Combine (null, "two", "three");
1270                                 Assert.Fail ("#A1-1");
1271                         } catch {
1272                                 // success
1273                         }
1274
1275                         try {
1276                                 Path.Combine ("one", null, "three");
1277                                 Assert.Fail ("#A1-2");
1278                         } catch {
1279                                 // success
1280                         }
1281
1282                         try {
1283                                 Path.Combine ("one", "two", null);
1284                                 Assert.Fail ("#A1-3");
1285                         } catch {
1286                                 // success
1287                         }
1288                         
1289                         Assert.AreEqual (Concat (sep, "one", "two", "three"), Path.Combine ("one", "two", "three"), "#A2-1");
1290                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three"), Path.Combine (sep + "one", "two", "three"), "#A2-2");
1291                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three"), Path.Combine (sep + "one" + sep, "two", "three"), "#A2-3");
1292                         Assert.AreEqual (Concat (sep, sep + "two", "three"), Path.Combine (sep + "one" + sep, sep + "two", "three"), "#A2-4");
1293                         Assert.AreEqual (Concat (sep, sep + "three"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three"), "#A2-5");
1294
1295                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three"), Path.Combine (sep + "one" + sep + sep, "two", "three"), "#A3");
1296
1297                         Assert.AreEqual ("", Path.Combine ("", "", ""), "#A4");
1298                 }
1299
1300                 [Test]
1301                 public void Combine_4Params ()
1302                 {
1303                         string sep = Path.DirectorySeparatorChar.ToString ();
1304
1305                         try {
1306                                 Path.Combine (null, "two", "three", "four");
1307                                 Assert.Fail ("#A1-1");
1308                         } catch {
1309                                 // success
1310                         }
1311
1312                         try {
1313                                 Path.Combine ("one", null, "three", "four");
1314                                 Assert.Fail ("#A1-2");
1315                         } catch {
1316                                 // success
1317                         }
1318
1319                         try {
1320                                 Path.Combine ("one", "two", null, "four");
1321                                 Assert.Fail ("#A1-3");
1322                         } catch {
1323                                 // success
1324                         }
1325
1326                         try {
1327                                 Path.Combine ("one", "two", "three", null);
1328                                 Assert.Fail ("#A1-4");
1329                         } catch {
1330                                 // success
1331                         }
1332
1333                         Assert.AreEqual (Concat (sep, "one", "two", "three", "four"), Path.Combine ("one", "two", "three", "four"), "#A2-1");
1334                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four"), Path.Combine (sep + "one", "two", "three", "four"), "#A2-2");
1335                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four"), Path.Combine (sep + "one" + sep, "two", "three", "four"), "#A2-3");
1336                         Assert.AreEqual (Concat (sep, sep + "two", "three", "four"), Path.Combine (sep + "one" + sep, sep + "two", "three", "four"), "#A2-4");
1337                         Assert.AreEqual (Concat (sep, sep + "three", "four"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", "four"), "#A2-5");
1338                         Assert.AreEqual (Concat (sep, sep + "four"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four"), "#A2-6");
1339
1340                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three", "four"), Path.Combine (sep + "one" + sep + sep, "two", "three", "four"), "#A3");
1341
1342                         Assert.AreEqual ("", Path.Combine ("", "", "", ""), "#A4");
1343                 }
1344
1345                 [Test]
1346                 public void Combine_ManyParams ()
1347                 {
1348                         string sep = Path.DirectorySeparatorChar.ToString ();
1349
1350                         try {
1351                                 Path.Combine (null, "two", "three", "four", "five");
1352                                 Assert.Fail ("#A1-1");
1353                         } catch {
1354                                 // success
1355                         }
1356
1357                         try {
1358                                 Path.Combine ("one", null, "three", "four", "five");
1359                                 Assert.Fail ("#A1-2");
1360                         } catch {
1361                                 // success
1362                         }
1363
1364                         try {
1365                                 Path.Combine ("one", "two", null, "four", "five");
1366                                 Assert.Fail ("#A1-3");
1367                         } catch {
1368                                 // success
1369                         }
1370
1371                         try {
1372                                 Path.Combine ("one", "two", "three", null, "five");
1373                                 Assert.Fail ("#A1-4");
1374                         } catch {
1375                                 // success
1376                         }
1377
1378                         try {
1379                                 Path.Combine ("one", "two", "three", "four", null);
1380                                 Assert.Fail ("#A1-5");
1381                         } catch {
1382                                 // success
1383                         }
1384
1385                         Assert.AreEqual (Concat (sep, "one", "two", "three", "four", "five"), Path.Combine ("one", "two", "three", "four", "five"), "#A2-1");
1386                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four", "five"), Path.Combine (sep + "one", "two", "three", "four", "five"), "#A2-2");
1387                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four", "five"), Path.Combine (sep + "one" + sep, "two", "three", "four", "five"), "#A2-3");
1388                         Assert.AreEqual (Concat (sep, sep + "two", "three", "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", "three", "four", "five"), "#A2-4");
1389                         Assert.AreEqual (Concat (sep, sep + "three", "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", "four", "five"), "#A2-5");
1390                         Assert.AreEqual (Concat (sep, sep + "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four", "five"), "#A2-6");
1391                         Assert.AreEqual (Concat (sep, sep + "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four", sep + "five"), "#A2-6");
1392
1393                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three", "four", "five"), Path.Combine (sep + "one" + sep + sep, "two", "three", "four", "five"), "#A3");
1394
1395                         Assert.AreEqual ("", Path.Combine ("", "", "", "", ""), "#A4");
1396                 }
1397 #endif
1398         }
1399 }
1400