Merge pull request #3528 from BrzVlad/fix-sgen-check-before-collections
[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                 static char ADSC = Path.AltDirectorySeparatorChar;
41
42                 [SetUp]
43                 public void SetUp ()
44                 {
45                         if ('/' == DSC) {
46                                 OS = OsType.Unix;
47                                 path1 = "/foo/test.txt";
48                                 path2 = "/etc";
49                                 path3 = "init.d";
50                         } else if ('\\' == DSC) {
51                                 OS = OsType.Windows;
52                                 path1 = "c:\\foo\\test.txt";
53                                 path2 = Environment.GetEnvironmentVariable ("SYSTEMROOT");
54                                 path3 = "system32";
55                         } else {
56                                 OS = OsType.Mac;
57                                 //FIXME: For Mac. figure this out when we need it
58                                 path1 = "foo:test.txt";
59                                 path2 = "foo";
60                                 path3 = "bar";
61                         }
62                 }
63
64                 bool Windows
65                 {
66                         get {
67                                 return OS == OsType.Windows;
68                         }
69                 }
70
71                 bool Unix
72                 {
73                         get {
74                                 return OS == OsType.Unix;
75                         }
76                 }
77
78                 bool Mac
79                 {
80                         get {
81                                 return OS == OsType.Mac;
82                         }
83                 }
84
85                 [Test]
86                 public void ChangeExtension ()
87                 {
88                         string [] files = new string [3];
89                         files [(int) OsType.Unix] = "/foo/test.doc";
90                         files [(int) OsType.Windows] = "c:\\foo\\test.doc";
91                         files [(int) OsType.Mac] = "foo:test.doc";
92
93                         string testPath = Path.ChangeExtension (path1, "doc");
94                         Assert.AreEqual (files [(int) OS], testPath, "ChangeExtension #01");
95
96                         testPath = Path.ChangeExtension (String.Empty, ".extension");
97                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #02");
98
99                         testPath = Path.ChangeExtension (null, ".extension");
100                         Assert.AreEqual (null, testPath, "ChangeExtension #03");
101
102                         testPath = Path.ChangeExtension ("path", null);
103                         Assert.AreEqual ("path", testPath, "ChangeExtension #04");
104
105                         testPath = Path.ChangeExtension ("path.ext", "doc");
106                         Assert.AreEqual ("path.doc", testPath, "ChangeExtension #05");
107
108                         testPath = Path.ChangeExtension ("path.ext1.ext2", "doc");
109                         Assert.AreEqual ("path.ext1.doc", testPath, "ChangeExtension #06");
110
111                         testPath = Path.ChangeExtension ("hogehoge.xml", ".xsl");
112                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #07");
113                         testPath = Path.ChangeExtension ("hogehoge", ".xsl");
114                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #08");
115                         testPath = Path.ChangeExtension ("hogehoge.xml", "xsl");
116                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #09");
117                         testPath = Path.ChangeExtension ("hogehoge", "xsl");
118                         Assert.AreEqual ("hogehoge.xsl", testPath, "ChangeExtension #10");
119                         testPath = Path.ChangeExtension ("hogehoge.xml", String.Empty);
120                         Assert.AreEqual ("hogehoge.", testPath, "ChangeExtension #11");
121                         testPath = Path.ChangeExtension ("hogehoge", String.Empty);
122                         Assert.AreEqual ("hogehoge.", testPath, "ChangeExtension #12");
123                         testPath = Path.ChangeExtension ("hogehoge.", null);
124                         Assert.AreEqual ("hogehoge", testPath, "ChangeExtension #13");
125                         testPath = Path.ChangeExtension ("hogehoge", null);
126                         Assert.AreEqual ("hogehoge", testPath, "ChangeExtension #14");
127                         testPath = Path.ChangeExtension (String.Empty, null);
128                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #15");
129                         testPath = Path.ChangeExtension (String.Empty, "bashrc");
130                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #16");
131                         testPath = Path.ChangeExtension (String.Empty, ".bashrc");
132                         Assert.AreEqual (String.Empty, testPath, "ChangeExtension #17");
133                         testPath = Path.ChangeExtension (null, null);
134                         Assert.IsNull (testPath, "ChangeExtension #18");
135                 }
136
137                 [Test]
138                 public void ChangeExtension_Extension_InvalidPathChars () 
139                 {
140                         string fn = Path.ChangeExtension ("file.ext", "<");
141                         Assert.AreEqual ("file.<", fn, "Invalid filename");
142                 }
143
144                 [Test]
145                 public void ChangeExtension_Path_InvalidPathChars ()
146                 {
147                         try {
148                                 Path.ChangeExtension ("fi\0le.ext", ".extension");
149                                 Assert.Fail ("#1");
150                         } catch (ArgumentException ex) {
151                                 // Illegal characters in path
152                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
153                                 Assert.IsNull (ex.InnerException, "#3");
154                                 Assert.IsNotNull (ex.Message, "#4");
155                                 Assert.IsNull (ex.ParamName, "#5");
156                         }
157                 }
158
159                 [Test]
160                 public void Combine ()
161                 {
162                         string [] files = new string [3];
163                         files [(int) OsType.Unix] = "/etc/init.d";
164                         files [(int) OsType.Windows] = Environment.GetEnvironmentVariable ("SYSTEMROOT") + @"\system32";
165                         files [(int) OsType.Mac] = "foo:bar";
166
167                         string testPath = Path.Combine (path2, path3);
168                         Assert.AreEqual (files [(int) OS], testPath, "Combine #01");
169
170                         testPath = Path.Combine ("one", String.Empty);
171                         Assert.AreEqual ("one", testPath, "Combine #02");
172
173                         testPath = Path.Combine (String.Empty, "one");
174                         Assert.AreEqual ("one", testPath, "Combine #03");
175
176                         string current = Directory.GetCurrentDirectory ();
177                         bool currentIsDSC = current.Length == 1 && current [0] == DSC;
178                         testPath = Path.Combine (current, "one");
179
180                         string expected = (currentIsDSC ? String.Empty : current) + DSC + "one";
181                         Assert.AreEqual (expected, testPath, "Combine #04");
182
183                         testPath = Path.Combine ("one", current);
184                         // LAMESPEC noted in Path.cs
185                         Assert.AreEqual (current, testPath, "Combine #05");
186
187                         testPath = Path.Combine (current, expected);
188                         Assert.AreEqual (expected, testPath, "Combine #06");
189
190                         testPath = DSC + "one";
191                         testPath = Path.Combine (testPath, "two" + DSC);
192                         expected = DSC + "one" + DSC + "two" + DSC;
193                         Assert.AreEqual (expected, testPath, "Combine #06");
194
195                         testPath = "one" + DSC;
196                         testPath = Path.Combine (testPath, DSC + "two");
197                         expected = DSC + "two";
198                         Assert.AreEqual (expected, testPath, "Combine #06");
199
200                         testPath = "one" + DSC;
201                         testPath = Path.Combine (testPath, "two" + DSC);
202                         expected = "one" + DSC + "two" + DSC;
203                         Assert.AreEqual (expected, testPath, "Combine #07");
204
205                         Assert.AreEqual ("a", Path.Combine (new [] { "a", "" }), "Combine #08");
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 GetDirectoryName_Replaces_AltDirectorySeparatorChar ()
365                 {
366                         Assert.AreEqual ($"foo{DSC}bar", Path.GetDirectoryName ($"foo{ADSC}bar{ADSC}dingus"), "#1");
367                 }
368
369                 [Test]
370                 public void GetExtension ()
371                 {
372                         string testExtn = Path.GetExtension (path1);
373
374                         Assert.AreEqual (".txt", testExtn, "GetExtension #01");
375
376                         testExtn = Path.GetExtension (path2);
377                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #02");
378
379                         testExtn = Path.GetExtension (String.Empty);
380                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #03");
381
382                         testExtn = Path.GetExtension (null);
383                         Assert.AreEqual (null, testExtn, "GetExtension #04");
384
385                         testExtn = Path.GetExtension (" ");
386                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #05");
387
388                         testExtn = Path.GetExtension (path1 + ".doc");
389                         Assert.AreEqual (".doc", testExtn, "GetExtension #06");
390
391                         testExtn = Path.GetExtension (path1 + ".doc" + DSC + "a.txt");
392                         Assert.AreEqual (".txt", testExtn, "GetExtension #07");
393
394                         testExtn = Path.GetExtension (".");
395                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #08");
396
397                         testExtn = Path.GetExtension ("end.");
398                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #09");
399
400                         testExtn = Path.GetExtension (".start");
401                         Assert.AreEqual (".start", testExtn, "GetExtension #10");
402
403                         testExtn = Path.GetExtension (".a");
404                         Assert.AreEqual (".a", testExtn, "GetExtension #11");
405
406                         testExtn = Path.GetExtension ("a.");
407                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #12");
408
409                         testExtn = Path.GetExtension ("a");
410                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #13");
411
412                         testExtn = Path.GetExtension ("makefile");
413                         Assert.AreEqual (String.Empty, testExtn, "GetExtension #14");
414                 }
415
416                 [Test]
417                 public void GetExtension_Path_InvalidPathChars ()
418                 {
419                         try {
420                                 Path.GetExtension ("hi\0world.txt");
421                                 Assert.Fail ("#1");
422                         } catch (ArgumentException ex) {
423                                 // Illegal characters in path.
424                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
425                                 Assert.IsNull (ex.InnerException, "#3");
426                                 Assert.IsNotNull (ex.Message, "#4");
427                                 Assert.IsNull (ex.ParamName, "#5");
428                         }
429                 }
430
431                 [Test]
432                 public void GetFileName ()
433                 {
434                         string testFileName = Path.GetFileName (path1);
435
436                         Assert.AreEqual ("test.txt", testFileName, "#1");
437                         testFileName = Path.GetFileName (null);
438                         Assert.AreEqual (null, testFileName, "#2");
439                         testFileName = Path.GetFileName (String.Empty);
440                         Assert.AreEqual (String.Empty, testFileName, "#3");
441                         testFileName = Path.GetFileName (" ");
442                         Assert.AreEqual (" ", testFileName, "#4");
443                 }
444
445                 [Test]
446                 public void GetFileName_Path_InvalidPathChars ()
447                 {
448                         try {
449                                 Path.GetFileName ("hi\0world");
450                                 Assert.Fail ("#1");
451                         } catch (ArgumentException ex) {
452                                 // Illegal characters in path
453                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
454                                 Assert.IsNull (ex.InnerException, "#3");
455                                 Assert.IsNotNull (ex.Message, "#4");
456                                 Assert.IsNull (ex.ParamName, "#5");
457                         }
458                 }
459
460                 [Test]
461                 public void GetFileNameWithoutExtension ()
462                 {
463                         string testFileName = Path.GetFileNameWithoutExtension (path1);
464
465                         Assert.AreEqual ("test", testFileName, "GetFileNameWithoutExtension #01");
466
467                         testFileName = Path.GetFileNameWithoutExtension (null);
468                         Assert.AreEqual (null, testFileName, "GetFileNameWithoutExtension #02");
469
470                         testFileName = Path.GetFileNameWithoutExtension (String.Empty);
471                         Assert.AreEqual (String.Empty, testFileName, "GetFileNameWithoutExtension #03");
472                 }
473
474                 [Test]
475                 public void GetFileNameWithoutExtension_Path_InvalidPathChars ()
476                 {
477                         try {
478                                 Path.GetFileNameWithoutExtension ("hi\0world");
479                                 Assert.Fail ("#1");
480                         } catch (ArgumentException ex) {
481                                 // Illegal characters in path
482                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
483                                 Assert.IsNull (ex.InnerException, "#3");
484                                 Assert.IsNotNull (ex.Message, "#4");
485                                 Assert.IsNull (ex.ParamName, "#5");
486                         }
487                 }
488
489                 [Test]
490                 public void GetFullPath ()
491                 {
492                         string current = Directory.GetCurrentDirectory ();
493                         bool currentIsDSC = current.Length == 1 && current [0] == DSC;
494                         string testFullPath = Path.GetFullPath ("foo.txt");
495                         string expected = (currentIsDSC ? String.Empty : current) + DSC + "foo.txt";
496                         Assert.AreEqual (expected, testFullPath, "GetFullPath #01");
497
498                         testFullPath = Path.GetFullPath ("a//./.././foo.txt");
499                         Assert.AreEqual (expected, testFullPath, "GetFullPath #02");
500
501                         if (!Windows){
502                                 Assert.AreEqual ("/bin/bash", Path.GetFullPath ("/../bin/bash"));
503                         }
504                                 
505                 }
506
507                 [Test]
508                 public void GetFullPath_Unix ()
509                 {
510                         if (Windows)
511                                 Assert.Ignore ("Running on Windows.");
512
513                         string root =  "/";
514                         string [,] test = new string [,] {
515                                 {"root////././././././../root/././../root", "root"},
516                                 {"root/", "root/"},
517                                 {"root/./", "root/"},
518                                 {"root/./", "root/"},
519                                 {"root/../", String.Empty},
520                                 {"root/../", String.Empty},
521                                 {"root/../..", String.Empty},
522                                 {"root/.hiddenfile", "root/.hiddenfile"},
523                                 {"root/. /", "root/. /"},
524                                 {"root/.. /", "root/.. /"},
525                                 {"root/..weirdname", "root/..weirdname"},
526                                 {"root/..", String.Empty},
527                                 {"root/../a/b/../../..", String.Empty},
528                                 {"root/./..", String.Empty},
529                                 {"..", String.Empty},
530                                 {".", String.Empty},
531                                 {"root//dir", "root/dir"},
532                                 {"root/.              /", "root/.              /"},
533                                 {"root/..             /", "root/..             /"},
534                                 {"root/      .              /", "root/      .              /"},
535                                 {"root/      ..             /", "root/      ..             /"},
536                                 {"root/./", "root/"},
537                                 //ERROR! Paths are trimmed
538                                 // I don't understand this comment^^.
539                                 // No trimming occurs but the paths are not equal. That's why the test fails. Commented out.
540                                 //{"root/..                      /", "root/..                   /"},
541                                 {".//", String.Empty}
542                         };
543
544                         for (int i = 0; i < test.GetUpperBound (0); i++) {
545                                 Assert.AreEqual (root + test [i, 1], Path.GetFullPath (root + test [i, 0]),
546                                                  String.Format ("GetFullPathUnix #{0}", i));
547                         }
548
549                         Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
550                         Assert.AreEqual ("/hey", Path.GetFullPath ("/hey"), "#02");
551                         Assert.AreEqual (Environment.CurrentDirectory, Path.GetFullPath ("."), "#03");
552                         Assert.AreEqual (Path.Combine (Environment.CurrentDirectory, "hey"),
553                                              Path.GetFullPath ("hey"), "#04");
554                         Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
555
556                         string curdir = Directory.GetCurrentDirectory ();
557                         try {
558                                 Directory.SetCurrentDirectory ("/");
559                                 Assert.AreEqual ("/test.txt", Path.GetFullPath ("test.txt"), "xambug #833");
560                         }
561                         finally {
562                                 Directory.SetCurrentDirectory (curdir);
563                         }
564                 }
565
566                 [Test]
567                 public void GetFullPath_Windows ()
568                 {
569                         if (!Windows)
570                                 Assert.Ignore ("Not running on Windows.");
571
572                         string root =  "C:\\";
573                         string [,] test = new string [,] {
574                                 {"root////././././././../root/././../root", "root"},
575                                 {"root/", "root\\"},
576                                 {"root/./", "root\\"},
577                                 {"root/./", "root\\"},
578                                 {"root/../", ""},
579                                 {"root/../", ""},
580                                 {"root/../..", ""},
581                                 {"root/.hiddenfile", "root\\.hiddenfile"},
582                                 {"root/. /", "root\\"},
583                                 {"root/.. /", ""},
584                                 {"root/..weirdname", "root\\..weirdname"},
585                                 {"root/..", ""},
586                                 {"root/../a/b/../../..", ""},
587                                 {"root/./..", ""},
588                                 {"..", ""},
589                                 {".", ""},
590                                 {"root//dir", "root\\dir"},
591                                 {"root/.              /", "root\\"},
592                                 {"root/..             /", ""},
593                                 {"root/./", "root\\"},
594                                 {"root/..                      /", ""},
595                                 {".//", ""}
596                         };
597
598                         for (int i = 0; i < test.GetUpperBound (0); i++) {
599                                 try {
600                                         Assert.AreEqual (root + test [i, 1], Path.GetFullPath (root + test [i, 0]),
601                                                          String.Format ("GetFullPathWindows #{0}", i));
602                                 } catch (Exception ex) { 
603                                         Assert.Fail (String.Format ("GetFullPathWindows #{0} (\"{1}\") failed: {2}", 
604                                                 i, root + test [i, 0], ex.GetType ()));
605                                 }
606                         }
607
608                         // UNC tests
609                         string root2 = @"\\server\share";
610                         root = @"\\server\share\";
611                         test = new string [,] {         
612                                 {"root////././././././../root/././../root", "root"},
613                                 {"root/", "root\\"},
614                                 {"root/./", "root\\"},
615                                 {"root/./", "root\\"},
616                                 {"root/../", ""},
617                                 {"root/../", ""},
618                                 {"root/../..", null},
619                                 {"root/.hiddenfile", "root\\.hiddenfile"},
620                                 {"root/. /", "root\\"},
621                                 {"root/.. /", ""},
622                                 {"root/..weirdname", "root\\..weirdname"},
623                                 {"root/..", null},
624                                 {"root/../a/b/../../..", null},
625                                 {"root/./..", null},
626                                 {"..", null},
627                                 {".", null},
628                                 {"root//dir", "root\\dir"},
629                                 {"root/.              /", "root\\"},
630                                 {"root/..             /", ""},
631                                 {"root/./", "root\\"},
632                                 {"root/..                      /", ""},
633                                 {".//", ""}
634                         };
635
636                         for (int i = 0; i < test.GetUpperBound (0); i++) {
637                                 // "null" means we have to compare against "root2"
638                                 string res = test [i, 1] != null
639                                         ? root + test [i, 1]
640                                         : root2;
641                                 try {
642                                         Assert.AreEqual (res, Path.GetFullPath (root + test [i, 0]),
643                                                          String.Format ("GetFullPathWindows UNC #{0}", i));
644                                 } catch (AssertionException) {
645                                         throw;
646                                 } catch (Exception ex) {
647                                         Assert.Fail (String.Format ("GetFullPathWindows UNC #{0} (\"{1}\") failed: {2}",
648                                                 i, root + test [i, 0], ex.GetType ()));
649                                 }
650                         }
651
652                         test = new string [,] {         
653                                 {"root////././././././../root/././../root", "root"},
654                                 {"root/", "root\\"},
655                                 {"root/./", "root\\"},
656                                 {"root/./", "root\\"},
657                                 {"root/../", ""},
658                                 {"root/../", ""},
659                                 {"root/../..", null},
660                                 {"root/.hiddenfile", "root\\.hiddenfile"},
661                                 {"root/. /", "root\\"},
662                                 {"root/.. /", ""},
663                                 {"root/..weirdname", "root\\..weirdname"},
664                                 {"root/..", null},
665                                 {"root/../a/b/../../..", null},
666                                 {"root/./..", null},
667                                 {"..", null},
668                                 {".", null},
669                                 {"root//dir", "root\\dir"},
670                                 {"root/.              /", "root\\"},
671                                 {"root/..             /", ""},
672                                 {"root/./", "root\\"},
673                                 {"root/..                      /", ""},
674                                 {".//", ""}
675                         };
676
677                         string root3 = @"//server/share";
678                         root = @"//server/share/";
679                         bool needSlashConvert = Path.DirectorySeparatorChar != '/';
680
681                         for (int i = 0; i < test.GetUpperBound (0); i++) {
682                                 // "null" means we have to compare against "root2"
683                                 string res = test [i, 1] != null
684                                         ? root + test [i, 1]
685                                         : root3;
686                                 if (needSlashConvert)
687                                         res = res.Replace ('/', Path.DirectorySeparatorChar);
688                                 try {
689                                         Assert.AreEqual (res, Path.GetFullPath (root + test [i, 0]),
690                                                          String.Format ("GetFullPathWindows UNC[2] #{0}", i));
691                                 } catch (AssertionException) {
692                                         throw;
693                                 } catch (Exception ex) {
694                                         Assert.Fail (String.Format ("GetFullPathWindows UNC[2] #{0} (\"{1}\") failed: {2}",
695                                                 i, root + test [i, 0], ex.GetType ()));
696                                 }
697                         }
698
699                         // These cases require that we don't pass a root to GetFullPath - it should return the proper drive root.
700                         string root4 = Path.GetPathRoot(Directory.GetCurrentDirectory());
701                         Assert.AreEqual(root4, Path.GetFullPath(@"\"));
702                         Assert.AreEqual(root4, Path.GetFullPath("/"));
703                 }
704
705                 [Test]
706                 public void GetFullPath_Path_Empty ()
707                 {
708                         try {
709                                 Path.GetFullPath (String.Empty);
710                                 Assert.Fail ("#1");
711                         } catch (ArgumentException ex) {
712                                 // The path is not of a legal form
713                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
714                                 Assert.IsNull (ex.InnerException, "#3");
715                                 Assert.IsNotNull (ex.Message, "#4");
716                                 Assert.IsNull (ex.ParamName, "#5");
717                         }
718                 }
719
720                 [Test]
721                 public void GetFullPath_Path_EndingSeparator ()
722                 {
723                         string fp = Path.GetFullPath ("something/");
724                         char end = fp [fp.Length - 1];
725                         Assert.IsTrue (end == Path.DirectorySeparatorChar);
726                 }
727
728                 [Test]
729                 public void GetFullPath_Path_InvalidPathChars ()
730                 {
731                         try {
732                                 Path.GetFullPath ("hi\0world");
733                                 Assert.Fail ("#1");
734                         } catch (ArgumentException ex) {
735                                 // Illegal characters in path
736                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
737                                 Assert.IsNull (ex.InnerException, "#3");
738                                 Assert.IsNotNull (ex.Message, "#4");
739                                 Assert.IsNull (ex.ParamName, "#5");
740                         }
741                 }
742
743                 [Test]
744                 public void GetFullPath_Path_Null ()
745                 {
746                         try {
747                                 Path.GetFullPath (null);
748                                 Assert.Fail ("#1");
749                         } catch (ArgumentNullException ex) {
750                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
751                                 Assert.IsNull (ex.InnerException, "#3");
752                                 Assert.IsNotNull (ex.Message, "#4");
753                                 Assert.AreEqual ("path", ex.ParamName, "#5");
754                         }
755                 }
756
757                 [Test]
758                 public void GetFullPath_Path_Whitespace ()
759                 {
760                         try {
761                                 Path.GetFullPath ("  ");
762                                 Assert.Fail ("#1");
763                         } catch (ArgumentException ex) {
764                                 // The path is not of a legal form
765                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
766                                 Assert.IsNull (ex.InnerException, "#3");
767                                 Assert.IsNotNull (ex.Message, "#4");
768                                 Assert.IsNull (ex.ParamName, "#5");
769                         }
770                 }
771
772                 [Test]
773                 public void GetFullPath2 ()
774                 {
775                         if (Windows) {
776                                 Assert.AreEqual (@"Z:\", Path.GetFullPath ("Z:"), "GetFullPath w#01");
777                                 Assert.AreEqual (@"c:\abc\def", Path.GetFullPath (@"c:\abc\def"), "GetFullPath w#02");
778                                 Assert.IsTrue (Path.GetFullPath (@"\").EndsWith (@"\"), "GetFullPath w#03");
779                                 // "\\\\" is not allowed
780                                 Assert.IsTrue (Path.GetFullPath ("/").EndsWith (@"\"), "GetFullPath w#05");
781                                 // "//" is not allowed
782                                 Assert.IsTrue (Path.GetFullPath ("readme.txt").EndsWith (@"\readme.txt"), "GetFullPath w#07");
783                                 Assert.IsTrue (Path.GetFullPath ("c").EndsWith (@"\c"), "GetFullPath w#08");
784                                 Assert.IsTrue (Path.GetFullPath (@"abc\def").EndsWith (@"abc\def"), "GetFullPath w#09");
785                                 Assert.IsTrue (Path.GetFullPath (@"\abc\def").EndsWith (@"\abc\def"), "GetFullPath w#10");
786                                 Assert.AreEqual (@"\\abc\def", Path.GetFullPath (@"\\abc\def"), "GetFullPath w#11");
787                                 Assert.AreEqual (Directory.GetCurrentDirectory () + @"\abc\def", Path.GetFullPath (@"abc//def"), "GetFullPath w#12");
788                                 Assert.AreEqual (Directory.GetCurrentDirectory ().Substring (0, 2) + @"\abc\def", Path.GetFullPath ("/abc/def"), "GetFullPath w#13");
789                                 Assert.AreEqual (@"\\abc\def", Path.GetFullPath ("//abc/def"), "GetFullPath w#14");
790                         } else {
791                                 Assert.AreEqual ("/", Path.GetFullPath ("/"), "#01");
792                                 Assert.AreEqual ("/hey", Path.GetFullPath ("/hey"), "#02");
793                                 Assert.AreEqual (Environment.CurrentDirectory, Path.GetFullPath ("."), "#03");
794                                 Assert.AreEqual (Path.Combine (Environment.CurrentDirectory, "hey"),
795                                                      Path.GetFullPath ("hey"), "#04");
796                         }
797                 }
798
799                 [Test]
800                 public void GetPathRoot ()
801                 {
802                         string current;
803                         string expected;
804                         if (!Windows){
805                                 current = Directory.GetCurrentDirectory ();
806                                 expected = current [0].ToString ();
807                         } else {
808                                 current = @"J:\Some\Strange Directory\Name";
809                                 expected = "J:\\";
810                         }
811
812                         string pathRoot = Path.GetPathRoot (current);
813                         Assert.AreEqual (expected, pathRoot, "GetPathRoot #01");
814                 }
815
816                 [Test]
817                 public void GetPathRoot2 ()
818                 {
819                         // note: this method doesn't call Directory.GetCurrentDirectory so it can be
820                         // reused for partial trust unit tests in PathCas.cs
821
822                         string pathRoot;
823                         
824                         pathRoot = Path.GetPathRoot ("hola");
825                         Assert.AreEqual (String.Empty, pathRoot, "#A1");
826                         pathRoot = Path.GetPathRoot (null);
827                         Assert.AreEqual (null, pathRoot, "#A2");
828
829                         if (Windows) {
830                                 Assert.AreEqual ("z:", Path.GetPathRoot ("z:"), "GetPathRoot w#01");
831                                 Assert.AreEqual ("c:\\", Path.GetPathRoot ("c:\\abc\\def"), "GetPathRoot w#02");
832                                 Assert.AreEqual ("\\", Path.GetPathRoot ("\\"), "GetPathRoot w#03");
833                                 Assert.AreEqual ("\\\\", Path.GetPathRoot ("\\\\"), "GetPathRoot w#04");
834                                 Assert.AreEqual ("\\", Path.GetPathRoot ("/"), "GetPathRoot w#05");
835                                 Assert.AreEqual ("\\\\", Path.GetPathRoot ("//"), "GetPathRoot w#06");
836                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("readme.txt"), "GetPathRoot w#07");
837                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("c"), "GetPathRoot w#08");
838                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("abc\\def"), "GetPathRoot w#09");
839                                 Assert.AreEqual ("\\", Path.GetPathRoot ("\\abc\\def"), "GetPathRoot w#10");
840                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def"), "GetPathRoot w#11");
841                                 Assert.AreEqual (String.Empty, Path.GetPathRoot ("abc//def"), "GetPathRoot w#12");
842                                 Assert.AreEqual ("\\", Path.GetPathRoot ("/abc/def"), "GetPathRoot w#13");
843                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("//abc/def"), "GetPathRoot w#14");
844                                 Assert.AreEqual (@"C:\", Path.GetPathRoot (@"C:\"), "GetPathRoot w#15");
845                                 Assert.AreEqual (@"C:\", Path.GetPathRoot (@"C:\\"), "GetPathRoot w#16");
846                                 Assert.AreEqual ("\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def\\ghi"), "GetPathRoot w#17");
847                         } else {
848                                 // TODO: Same tests for Unix.
849                         }
850                 }
851
852                 [Test]
853                 public void GetPathRoot_Path_Empty ()
854                 {
855                         try {
856                                 Path.GetPathRoot (String.Empty);
857                                 Assert.Fail ("#1");
858                         } catch (ArgumentException ex) {
859                                 // The path is not of a legal form
860                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
861                                 Assert.IsNull (ex.InnerException, "#3");
862                                 Assert.IsNotNull (ex.Message, "#4");
863                                 Assert.IsNull (ex.ParamName, "#5");
864                         }
865                 }
866
867                 [Test]
868                 public void GetPathRoot_Path_InvalidPathChars ()
869                 {
870                         try {
871                                 Path.GetPathRoot ("hi\0world");
872                                 Assert.Fail ("#1");
873                         } catch (ArgumentException ex) {
874                                 // Illegal characters in path
875                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
876                                 Assert.IsNull (ex.InnerException, "#3");
877                                 Assert.IsNotNull (ex.Message, "#4");
878                                 Assert.IsNull (ex.ParamName, "#5");
879                         }
880                 }
881
882                 [Test]
883                 public void GetPathRoot_Path_Whitespace ()
884                 {
885                         try {
886                                 Path.GetPathRoot ("  ");
887                                 Assert.Fail ("#1");
888                         } catch (ArgumentException ex) {
889                                 // The path is not of a legal form
890                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
891                                 Assert.IsNull (ex.InnerException, "#3");
892                                 Assert.IsNotNull (ex.Message, "#4");
893                                 Assert.IsNull (ex.ParamName, "#5");
894                         }
895                 }
896
897                 [Test]
898                 public void GetTempPath ()
899                 {
900                         string getTempPath = Path.GetTempPath ();
901                         Assert.IsTrue (getTempPath != String.Empty, "GetTempPath #01");
902                         Assert.IsTrue (Path.IsPathRooted (getTempPath), "GetTempPath #02");
903                         Assert.AreEqual (Path.DirectorySeparatorChar, getTempPath [getTempPath.Length - 1], "GetTempPath #03");
904                 }
905
906                 [Test]
907                 public void GetTempFileName ()
908                 {
909                         string getTempFileName = null;
910                         try {
911                                 getTempFileName = Path.GetTempFileName ();
912                                 Assert.IsTrue (getTempFileName != String.Empty, "GetTempFileName #01");
913                                 Assert.IsTrue (File.Exists (getTempFileName), "GetTempFileName #02");
914                         } finally {
915                                 if (getTempFileName != null && getTempFileName != String.Empty){
916                                         File.Delete (getTempFileName);
917                                 }
918                         }
919                 }
920
921                 [Test]
922                 public void HasExtension ()
923                 {
924                         Assert.AreEqual (true, Path.HasExtension ("foo.txt"), "HasExtension #01");
925                         Assert.AreEqual (false, Path.HasExtension ("foo"), "HasExtension #02");
926                         Assert.AreEqual (true, Path.HasExtension (path1), "HasExtension #03");
927                         Assert.AreEqual (false, Path.HasExtension (path2), "HasExtension #04");
928                         Assert.AreEqual (false, Path.HasExtension (null), "HasExtension #05");
929                         Assert.AreEqual (false, Path.HasExtension (String.Empty), "HasExtension #06");
930                         Assert.AreEqual (false, Path.HasExtension (" "), "HasExtension #07");
931                         Assert.AreEqual (false, Path.HasExtension ("."), "HasExtension #08");
932                         Assert.AreEqual (false, Path.HasExtension ("end."), "HasExtension #09");
933                         Assert.AreEqual (true, Path.HasExtension (".start"), "HasExtension #10");
934                         Assert.AreEqual (true, Path.HasExtension (".a"), "HasExtension #11");
935                         Assert.AreEqual (false, Path.HasExtension ("a."), "HasExtension #12");
936                         Assert.AreEqual (false, Path.HasExtension ("Makefile"), "HasExtension #13");
937                 }
938
939                 [Test]
940                 public void HasExtension_Path_InvalidPathChars ()
941                 {
942                         try {
943                                 Path.HasExtension ("hi\0world.txt");
944                                 Assert.Fail ("#1");
945                         } catch (ArgumentException ex) {
946                                 // Illegal characters in path
947                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
948                                 Assert.IsNull (ex.InnerException, "#3");
949                                 Assert.IsNotNull (ex.Message, "#4");
950                                 Assert.IsNull (ex.ParamName, "#5");
951                         }
952                 }
953
954                 [Test]
955                 public void IsPathRooted ()
956                 {
957                         Assert.IsTrue (Path.IsPathRooted (path2), "IsPathRooted #01");
958                         Assert.IsTrue (!Path.IsPathRooted (path3), "IsPathRooted #02");
959                         Assert.IsTrue (!Path.IsPathRooted (null), "IsPathRooted #03");
960                         Assert.IsTrue (!Path.IsPathRooted (String.Empty), "IsPathRooted #04");
961                         Assert.IsTrue (!Path.IsPathRooted (" "), "IsPathRooted #05");
962                         Assert.IsTrue (Path.IsPathRooted ("/"), "IsPathRooted #06");
963                         Assert.IsTrue (Path.IsPathRooted ("//"), "IsPathRooted #07");
964                         Assert.IsTrue (!Path.IsPathRooted (":"), "IsPathRooted #08");
965
966                         if (Windows) {
967                                 Assert.IsTrue (Path.IsPathRooted ("\\"), "IsPathRooted #09");
968                                 Assert.IsTrue (Path.IsPathRooted ("\\\\"), "IsPathRooted #10");
969                                 Assert.IsTrue (Path.IsPathRooted ("z:"), "IsPathRooted #11");
970                                 Assert.IsTrue (Path.IsPathRooted ("z:\\"), "IsPathRooted #12");
971                                 Assert.IsTrue (Path.IsPathRooted ("z:\\topdir"), "IsPathRooted #13");
972                                 // This looks MS BUG. It is treated as absolute path
973                                 Assert.IsTrue (Path.IsPathRooted ("z:curdir"), "IsPathRooted #14");
974                                 Assert.IsTrue (Path.IsPathRooted ("\\abc\\def"), "IsPathRooted #15");
975                         } else {
976                                 if (Environment.GetEnvironmentVariable ("MONO_IOMAP") == "all"){
977                                         Assert.IsTrue (Path.IsPathRooted ("\\"), "IsPathRooted #16");
978                                         Assert.IsTrue (Path.IsPathRooted ("\\\\"), "IsPathRooted #17");
979                                 } else {
980                                         Assert.IsTrue (!Path.IsPathRooted ("\\"), "IsPathRooted #09");
981                                         Assert.IsTrue (!Path.IsPathRooted ("\\\\"), "IsPathRooted #10");
982                                         Assert.IsTrue (!Path.IsPathRooted ("z:"), "IsPathRooted #11");
983                                 }
984                         }
985                 }
986
987                 [Test]
988                 public void IsPathRooted_Path_Empty ()
989                 {
990                         Assert.IsTrue (!Path.IsPathRooted (String.Empty));
991                 }
992
993                 [Test]
994                 public void IsPathRooted_Path_InvalidPathChars ()
995                 {
996                         try {
997                                 Path.IsPathRooted ("hi\0world");
998                                 Assert.Fail ("#1");
999                         } catch (ArgumentException ex) {
1000                                 // Illegal characters in path.
1001                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1002                                 Assert.IsNull (ex.InnerException, "#3");
1003                                 Assert.IsNotNull (ex.Message, "#4");
1004                                 Assert.IsNull (ex.ParamName, "#5");
1005                         }
1006                 }
1007
1008                 [Test]
1009                 public void IsPathRooted_Path_Null ()
1010                 {
1011                         Assert.IsTrue (!Path.IsPathRooted (null));
1012                 }
1013
1014                 [Test]
1015                 public void IsPathRooted_Path_Whitespace ()
1016                 {
1017                         Assert.IsTrue (!Path.IsPathRooted ("  "));
1018                 }
1019
1020                 [Test]
1021                 public void CanonicalizeDots ()
1022                 {
1023                         string current = Path.GetFullPath (".");
1024                         Assert.IsTrue (!current.EndsWith ("."), "TestCanonicalizeDotst #01");
1025                         string parent = Path.GetFullPath ("..");
1026                         Assert.IsTrue (!current.EndsWith (".."), "TestCanonicalizeDotst #02");
1027                 }
1028 #if !MOBILE
1029                 [Test]
1030                 public void WindowsSystem32_76191 ()
1031                 {
1032                         // check for Unix platforms - see FAQ for more details
1033                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1034                         int platform = (int) Environment.OSVersion.Platform;
1035                         if ((platform == 4) || (platform == 128) || (platform == 6))
1036                                 Assert.Ignore ("Running on Unix.");
1037
1038                         string curdir = Directory.GetCurrentDirectory ();
1039                         try {
1040                                 string system = Environment.SystemDirectory;
1041                                 Directory.SetCurrentDirectory (system);
1042                                 string drive = system.Substring (0, 2);
1043                                 Assert.AreEqual (system, Path.GetFullPath (drive), "current dir");
1044                         }
1045                         finally {
1046                                 Directory.SetCurrentDirectory (curdir);
1047                         }
1048                 }
1049
1050                 [Test]
1051                 public void WindowsSystem32_77007 ()
1052                 {
1053                         // check for Unix platforms - see FAQ for more details
1054                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1055                         int platform = (int) Environment.OSVersion.Platform;
1056                         if ((platform == 4) || (platform == 128) || (platform == 6))
1057                                 Assert.Ignore ("Running on Unix.");
1058
1059                         string curdir = Directory.GetCurrentDirectory ();
1060                         try {
1061                                 string system = Environment.SystemDirectory;
1062                                 Directory.SetCurrentDirectory (system);
1063                                 // e.g. C:dir (no backslash) will return CurrentDirectory + dir
1064                                 string dir = system.Substring (0, 2) + "dir";
1065                                 Assert.AreEqual (Path.Combine (system, "dir"), Path.GetFullPath (dir), "current dir");
1066                         }
1067                         finally {
1068                                 Directory.SetCurrentDirectory (curdir);
1069                         }
1070                 }
1071 #endif
1072                 [Test]
1073                 public void WindowsDriveC14N_77058 ()
1074                 {
1075                         // check for Unix platforms - see FAQ for more details
1076                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
1077                         int platform = (int) Environment.OSVersion.Platform;
1078                         if ((platform == 4) || (platform == 128) || (platform == 6))
1079                                 Assert.Ignore ("Running on Unix.");
1080
1081                         Assert.AreEqual (@"C:\Windows\dir", Path.GetFullPath (@"C:\Windows\System32\..\dir"), "1");
1082                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\dir"), "2");
1083                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\dir"), "3");
1084                         Assert.AreEqual (@"C:\dir", Path.GetFullPath (@"C:\Windows\System32\..\..\..\..\dir"), "4");
1085                         Assert.AreEqual (@"C:\dir\", Path.GetFullPath (@"C:\Windows\System32\..\.\..\.\..\dir\"), "5");
1086                 }
1087
1088                 [Test]
1089                 public void InvalidPathChars_Values ()
1090                 {
1091                         char[] invalid = Path.InvalidPathChars;
1092                         if (Windows) {
1093                                 Assert.AreEqual (36, invalid.Length, "Length");
1094
1095                                 foreach (char c in invalid) {
1096                                         int i = (int) c;
1097
1098                                         if (i < 32)
1099                                                 continue;
1100
1101                                         // in both 1.1 SP1 and 2.0
1102                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1103                                                 continue;
1104                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1105                                 }
1106                         } else {
1107                                 foreach (char c in invalid) {
1108                                         int i = (int) c;
1109                                         if (i == 0)
1110                                                 continue;
1111                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1112                                 }
1113                         }
1114                 }
1115
1116                 [Test]
1117                 public void InvalidPathChars_Modify ()
1118                 {
1119                         char[] expected = Path.InvalidPathChars;
1120                         char[] invalid = Path.InvalidPathChars;
1121                         char original = invalid[0];
1122                         try {
1123                                 invalid[0] = 'a';
1124                                 // kind of scary
1125                                 Assert.IsTrue (expected[0] == 'a', "expected");
1126                                 Assert.AreEqual (expected[0], Path.InvalidPathChars[0], "readonly");
1127                         } finally {
1128                                 invalid[0] = original;
1129                         }
1130                 }
1131
1132                 [Test]
1133                 public void GetInvalidFileNameChars_Values ()
1134                 {
1135                         char[] invalid = Path.GetInvalidFileNameChars ();
1136                         if (Windows) {
1137                                 Assert.AreEqual (41, invalid.Length);
1138                                 foreach (char c in invalid) {
1139                                         int i = (int) c;
1140                                         if (i < 32)
1141                                                 continue;
1142                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1143                                                 continue;
1144                                         // ':', '*', '?', '\', '/'
1145                                         if ((i == 58) || (i == 42) || (i == 63) || (i == 92) || (i == 47))
1146                                                 continue;
1147                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1148                                 }
1149                         } else {
1150                                 foreach (char c in invalid) {
1151                                         int i = (int) c;
1152                                         // null or '/'
1153                                         if ((i == 0) || (i == 47))
1154                                                 continue;
1155                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1156                                 }
1157                         }
1158                 }
1159
1160                 [Test]
1161                 public void GetInvalidFileNameChars_Modify ()
1162                 {
1163                         char[] expected = Path.GetInvalidFileNameChars ();
1164                         char[] invalid = Path.GetInvalidFileNameChars ();
1165                         invalid[0] = 'a';
1166                         Assert.IsTrue (expected[0] != 'a', "expected");
1167                         Assert.AreEqual (expected[0], Path.GetInvalidFileNameChars ()[0], "readonly");
1168                 }
1169
1170                 [Test]
1171                 public void GetInvalidPathChars_Values ()
1172                 {
1173                         char[] invalid = Path.GetInvalidPathChars ();
1174                         if (Windows) {
1175                                 Assert.AreEqual (36, invalid.Length);
1176                                 foreach (char c in invalid) {
1177                                         int i = (int) c;
1178                                         if (i < 32)
1179                                                 continue;
1180                                         if ((i == 34) || (i == 60) || (i == 62) || (i == 124))
1181                                                 continue;
1182                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1183                                 }
1184                         } else {
1185                                 foreach (char c in invalid) {
1186                                         int i = (int) c;
1187                                         if (i == 0)
1188                                                 continue;
1189                                         Assert.Fail (String.Format ("'{0}' (#{1}) is invalid", c, i));
1190                                 }
1191                         }
1192                 }
1193
1194                 [Test]
1195                 public void GetInvalidPathChars_Order ()
1196                 {
1197                         if (Windows) {
1198                                 char [] invalid = Path.GetInvalidPathChars ();
1199                                 char [] expected = new char [36] { '\x22', '\x3C', '\x3E', '\x7C', '\x00', '\x01', '\x02',
1200                                         '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D',
1201                                         '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18',
1202                                         '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F' };
1203                                 Assert.AreEqual (expected.Length, invalid.Length);
1204                                 for (int i = 0; i < expected.Length; i++ ) {
1205                                         Assert.AreEqual (expected [i], invalid [i], "Character at position " + i);
1206                                 }
1207                         }
1208                 }
1209
1210                 [Test]
1211                 public void GetInvalidPathChars_Modify ()
1212                 {
1213                         char[] expected = Path.GetInvalidPathChars ();
1214                         char[] invalid = Path.GetInvalidPathChars ();
1215                         invalid[0] = 'a';
1216                         Assert.IsTrue (expected[0] != 'a', "expected");
1217                         Assert.AreEqual (expected[0], Path.GetInvalidPathChars ()[0], "readonly");
1218                 }
1219
1220                 [Test]
1221                 public void GetRandomFileName ()
1222                 {
1223                         string s = Path.GetRandomFileName ();
1224                         Assert.AreEqual (12, s.Length, "Length");
1225                         char[] invalid = Path.GetInvalidFileNameChars ();
1226                         for (int i=0; i < s.Length; i++) {
1227                                 if (i == 8)
1228                                         Assert.AreEqual ('.', s[i], "8");
1229                                 else
1230                                         Assert.IsTrue (Array.IndexOf (invalid, s[i]) == -1, i.ToString ());
1231                         }
1232                 }
1233
1234                 [Test]
1235                 public void GetRandomFileNameIsAlphaNumerical ()
1236                 {
1237                         string [] names = new string [1000];
1238                         for (int i = 0; i < names.Length; i++)
1239                                 names [i] = Path.GetRandomFileName ();
1240
1241                         foreach (string name in names) {
1242                                 Assert.AreEqual (12, name.Length);
1243                                 Assert.AreEqual ('.', name [8]);
1244
1245                                 for (int i = 0; i < 12; i++) {
1246                                         if (i == 8)
1247                                                 continue;
1248
1249                                         char c = name [i];
1250                                         Assert.IsTrue (('a' <= c && c <= 'z') || ('0' <= c && c <= '9'));
1251                                 }
1252                         }
1253                 }
1254
1255                 string Concat (string sep, params string [] parms)
1256                 {
1257                         return String.Join (sep, parms);
1258                 }
1259
1260                 [Test]
1261                 public void Combine_3Params ()
1262                 {
1263                         string sep = Path.DirectorySeparatorChar.ToString ();
1264
1265                         try {
1266                                 Path.Combine (null, "two", "three");
1267                                 Assert.Fail ("#A1-1");
1268                         } catch {
1269                                 // success
1270                         }
1271
1272                         try {
1273                                 Path.Combine ("one", null, "three");
1274                                 Assert.Fail ("#A1-2");
1275                         } catch {
1276                                 // success
1277                         }
1278
1279                         try {
1280                                 Path.Combine ("one", "two", null);
1281                                 Assert.Fail ("#A1-3");
1282                         } catch {
1283                                 // success
1284                         }
1285                         
1286                         Assert.AreEqual (Concat (sep, "one", "two", "three"), Path.Combine ("one", "two", "three"), "#A2-1");
1287                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three"), Path.Combine (sep + "one", "two", "three"), "#A2-2");
1288                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three"), Path.Combine (sep + "one" + sep, "two", "three"), "#A2-3");
1289                         Assert.AreEqual (Concat (sep, sep + "two", "three"), Path.Combine (sep + "one" + sep, sep + "two", "three"), "#A2-4");
1290                         Assert.AreEqual (Concat (sep, sep + "three"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three"), "#A2-5");
1291
1292                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three"), Path.Combine (sep + "one" + sep + sep, "two", "three"), "#A3");
1293
1294                         Assert.AreEqual ("", Path.Combine ("", "", ""), "#A4");
1295                 }
1296
1297                 [Test]
1298                 public void Combine_4Params ()
1299                 {
1300                         string sep = Path.DirectorySeparatorChar.ToString ();
1301
1302                         try {
1303                                 Path.Combine (null, "two", "three", "four");
1304                                 Assert.Fail ("#A1-1");
1305                         } catch {
1306                                 // success
1307                         }
1308
1309                         try {
1310                                 Path.Combine ("one", null, "three", "four");
1311                                 Assert.Fail ("#A1-2");
1312                         } catch {
1313                                 // success
1314                         }
1315
1316                         try {
1317                                 Path.Combine ("one", "two", null, "four");
1318                                 Assert.Fail ("#A1-3");
1319                         } catch {
1320                                 // success
1321                         }
1322
1323                         try {
1324                                 Path.Combine ("one", "two", "three", null);
1325                                 Assert.Fail ("#A1-4");
1326                         } catch {
1327                                 // success
1328                         }
1329
1330                         Assert.AreEqual (Concat (sep, "one", "two", "three", "four"), Path.Combine ("one", "two", "three", "four"), "#A2-1");
1331                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four"), Path.Combine (sep + "one", "two", "three", "four"), "#A2-2");
1332                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four"), Path.Combine (sep + "one" + sep, "two", "three", "four"), "#A2-3");
1333                         Assert.AreEqual (Concat (sep, sep + "two", "three", "four"), Path.Combine (sep + "one" + sep, sep + "two", "three", "four"), "#A2-4");
1334                         Assert.AreEqual (Concat (sep, sep + "three", "four"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", "four"), "#A2-5");
1335                         Assert.AreEqual (Concat (sep, sep + "four"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four"), "#A2-6");
1336
1337                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three", "four"), Path.Combine (sep + "one" + sep + sep, "two", "three", "four"), "#A3");
1338
1339                         Assert.AreEqual ("", Path.Combine ("", "", "", ""), "#A4");
1340                 }
1341
1342                 [Test]
1343                 public void Combine_ManyParams ()
1344                 {
1345                         string sep = Path.DirectorySeparatorChar.ToString ();
1346
1347                         try {
1348                                 Path.Combine (null, "two", "three", "four", "five");
1349                                 Assert.Fail ("#A1-1");
1350                         } catch {
1351                                 // success
1352                         }
1353
1354                         try {
1355                                 Path.Combine ("one", null, "three", "four", "five");
1356                                 Assert.Fail ("#A1-2");
1357                         } catch {
1358                                 // success
1359                         }
1360
1361                         try {
1362                                 Path.Combine ("one", "two", null, "four", "five");
1363                                 Assert.Fail ("#A1-3");
1364                         } catch {
1365                                 // success
1366                         }
1367
1368                         try {
1369                                 Path.Combine ("one", "two", "three", null, "five");
1370                                 Assert.Fail ("#A1-4");
1371                         } catch {
1372                                 // success
1373                         }
1374
1375                         try {
1376                                 Path.Combine ("one", "two", "three", "four", null);
1377                                 Assert.Fail ("#A1-5");
1378                         } catch {
1379                                 // success
1380                         }
1381
1382                         Assert.AreEqual (Concat (sep, "one", "two", "three", "four", "five"), Path.Combine ("one", "two", "three", "four", "five"), "#A2-1");
1383                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four", "five"), Path.Combine (sep + "one", "two", "three", "four", "five"), "#A2-2");
1384                         Assert.AreEqual (Concat (sep, sep + "one", "two", "three", "four", "five"), Path.Combine (sep + "one" + sep, "two", "three", "four", "five"), "#A2-3");
1385                         Assert.AreEqual (Concat (sep, sep + "two", "three", "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", "three", "four", "five"), "#A2-4");
1386                         Assert.AreEqual (Concat (sep, sep + "three", "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", "four", "five"), "#A2-5");
1387                         Assert.AreEqual (Concat (sep, sep + "four", "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four", "five"), "#A2-6");
1388                         Assert.AreEqual (Concat (sep, sep + "five"), Path.Combine (sep + "one" + sep, sep + "two", sep + "three", sep + "four", sep + "five"), "#A2-6");
1389
1390                         Assert.AreEqual (Concat (sep, sep + "one" + sep, "two", "three", "four", "five"), Path.Combine (sep + "one" + sep + sep, "two", "three", "four", "five"), "#A3");
1391
1392                         Assert.AreEqual ("", Path.Combine ("", "", "", "", ""), "#A4");
1393                 }
1394         }
1395 }
1396