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