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