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