* DirectoryInfoTest.cs: Added tests for bug #75285.
[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 //
11 // (c) Marcin Szczepanski 
12 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
13 // (c) 2003 Ben Maurer
14 // (c) 2003 Gilles Freart
15 //
16
17 using NUnit.Framework;
18 using System.IO;
19 using System;
20 using System.Text;
21
22 namespace MonoTests.System.IO
23 {
24
25         enum OsType {
26                 Windows,
27                 Unix,
28                 Mac
29         }
30
31         [TestFixture]
32         public class PathTest : Assertion
33         {
34                 static string path1;
35                 static string path2;
36                 static string path3;
37                 static OsType OS;
38                 static char DSC = Path.DirectorySeparatorChar;
39              
40                 [SetUp]
41                 public void SetUp ()
42                 {
43                         if ('/' == DSC) {
44                                 OS = OsType.Unix;
45                                 path1 = "/foo/test.txt";
46                                 path2 = "/etc";
47                                 path3 = "init.d";
48                         } else if ('\\' == DSC) {
49                                 OS = OsType.Windows;
50                                 path1 = "c:\\foo\\test.txt";
51                                 path2 = Environment.GetEnvironmentVariable ("SYSTEMROOT");
52                                 path3 = "system32";
53                         } else {
54                                 OS = OsType.Mac;
55                                 //FIXME: For Mac. figure this out when we need it
56                                 path1 = "foo:test.txt";
57                                 path2 = "foo";
58                                 path3 = "bar";
59                         }
60                 }
61
62                 bool Windows
63                 {
64                         get {
65                                 return OS == OsType.Windows;
66                         }
67                 }
68
69                 bool Unix
70                 {
71                         get {
72                                 return OS == OsType.Unix;
73                         }
74                 }
75
76                 bool Mac
77                 {
78                         get {
79                                 return OS == OsType.Mac;
80                         }
81                 }
82
83                 public void TestChangeExtension ()
84                 {
85                         string [] files = new string [3];
86                         files [(int) OsType.Unix] = "/foo/test.doc";
87                         files [(int) OsType.Windows] = "c:\\foo\\test.doc";
88                         files [(int) OsType.Mac] = "foo:test.doc";
89
90                         string testPath = Path.ChangeExtension (path1, "doc");
91                         AssertEquals ("ChangeExtension #01", files [(int) OS], testPath);
92
93                         testPath = Path.ChangeExtension ("", ".extension");
94                         AssertEquals ("ChangeExtension #02", String.Empty, testPath);
95
96                         testPath = Path.ChangeExtension (null, ".extension");
97                         AssertEquals ("ChangeExtension #03", null, testPath);
98
99                         testPath = Path.ChangeExtension ("path", null);
100                         AssertEquals ("ChangeExtension #04", "path", testPath);
101
102                         testPath = Path.ChangeExtension ("path.ext", "doc");
103                         AssertEquals ("ChangeExtension #05", "path.doc", testPath);
104
105                         testPath = Path.ChangeExtension ("path.ext1.ext2", "doc");
106                         AssertEquals ("ChangeExtension #06", "path.ext1.doc", testPath);
107
108                         testPath = Path.ChangeExtension ("hogehoge.xml", ".xsl");
109                         AssertEquals ("ChangeExtension #07", "hogehoge.xsl", testPath);
110                         testPath = Path.ChangeExtension ("hogehoge", ".xsl");
111                         AssertEquals ("ChangeExtension #08", "hogehoge.xsl", testPath);
112                         testPath = Path.ChangeExtension ("hogehoge.xml", "xsl");
113                         AssertEquals ("ChangeExtension #09", "hogehoge.xsl", testPath);
114                         testPath = Path.ChangeExtension ("hogehoge", "xsl");
115                         AssertEquals ("ChangeExtension #10", "hogehoge.xsl", testPath);
116                         testPath = Path.ChangeExtension ("hogehoge.xml", String.Empty);
117                         AssertEquals ("ChangeExtension #11", "hogehoge.", testPath);
118                         testPath = Path.ChangeExtension ("hogehoge", String.Empty);
119                         AssertEquals ("ChangeExtension #12", "hogehoge.", testPath);
120                         testPath = Path.ChangeExtension ("hogehoge.", null);
121                         AssertEquals ("ChangeExtension #13", "hogehoge", testPath);
122                         testPath = Path.ChangeExtension ("hogehoge", null);
123                         AssertEquals ("ChangeExtension #14", "hogehoge", testPath);
124                         testPath = Path.ChangeExtension (String.Empty, null);
125                         AssertEquals ("ChangeExtension #15", String.Empty, testPath);
126                         testPath = Path.ChangeExtension (String.Empty, "bashrc");
127                         AssertEquals ("ChangeExtension #16", String.Empty, testPath);
128                         testPath = Path.ChangeExtension (String.Empty, ".bashrc");
129                         AssertEquals ("ChangeExtension #17", String.Empty, testPath);
130                         testPath = Path.ChangeExtension (null, null);
131                         AssertNull ("ChangeExtension #18", testPath);
132                 }
133
134                 [Test]
135                 [ExpectedException (typeof (ArgumentException))]
136                 public void ChangeExtension_BadPath () 
137                 {
138                         if (!Windows) throw new ArgumentException ("Test Only On Windows");
139                         Path.ChangeExtension ("<", ".extension");
140                 }
141
142                 [Test]
143                 public void ChangeExtension_BadExtension () 
144                 {
145                         if (Windows) {
146                                 string fn = Path.ChangeExtension ("file.ext", "<");
147                                 AssertEquals ("Invalid filename", "file.<", fn);
148                         }
149                 }
150
151                 public void TestCombine ()
152                 {
153                         string [] files = new string [3];
154                         files [(int) OsType.Unix] = "/etc/init.d";
155                         files [(int) OsType.Windows] = Environment.GetEnvironmentVariable ("SYSTEMROOT") + @"\system32";
156                         files [(int) OsType.Mac] = "foo:bar";
157
158                         string testPath = Path.Combine (path2, path3);
159                         AssertEquals ("Combine #01", files [(int) OS], testPath);
160
161                         testPath = Path.Combine ("one", "");
162                         AssertEquals ("Combine #02", "one", testPath);
163
164                         testPath = Path.Combine ("", "one");
165                         AssertEquals ("Combine #03", "one", testPath);
166
167                         string current = Directory.GetCurrentDirectory ();
168                         testPath = Path.Combine (current, "one");
169
170                         string expected = current + DSC + "one";
171                         AssertEquals ("Combine #04", expected, testPath);
172
173                         testPath = Path.Combine ("one", current);
174                         // LAMESPEC noted in Path.cs
175                         AssertEquals ("Combine #05", current, testPath);
176
177                         testPath = Path.Combine (current, expected);
178                         AssertEquals ("Combine #06", expected, testPath);
179
180                         testPath = DSC + "one";
181                         testPath = Path.Combine (testPath, "two" + DSC);
182                         expected = DSC + "one" + DSC + "two" + DSC;
183                         AssertEquals ("Combine #06", expected, testPath);
184
185                         testPath = "one" + DSC;
186                         testPath = Path.Combine (testPath, DSC + "two");
187                         expected = DSC + "two";
188                         AssertEquals ("Combine #06", expected, testPath);
189
190                         testPath = "one" + DSC;
191                         testPath = Path.Combine (testPath, "two" + DSC);
192                         expected = "one" + DSC + "two" + DSC;
193                         AssertEquals ("Combine #07", expected, testPath);
194
195                         //TODO: Tests for UNC names
196                         try {
197                                 testPath = Path.Combine ("one", null);
198                                 Fail ("Combine Fail #01");
199                         } catch (Exception e) {
200                                 AssertEquals ("Combine Exc. #01", typeof (ArgumentNullException), e.GetType ());
201                         }
202
203                         try {
204                                 testPath = Path.Combine (null, "one");
205                                 Fail ("Combine Fail #02");
206                         } catch (Exception e) {
207                                 AssertEquals ("Combine Exc. #02", typeof (ArgumentNullException), e.GetType ());
208                         }
209
210                         if (Windows) {
211                                 try {
212                                         testPath = Path.Combine ("a>", "one");
213                                         Fail ("Combine Fail #03");
214                                 } catch (Exception e) {
215                                         AssertEquals ("Combine Exc. #03", typeof (ArgumentException), e.GetType ());
216                                 }
217
218                                 try {
219                                         testPath = Path.Combine ("one", "aaa<");
220                                         Fail ("Combine Fail #04");
221                                 } catch (Exception e) {
222                                         AssertEquals ("Combine Exc. #04", typeof (ArgumentException), e.GetType ());
223                                 }
224                         }
225                 }
226
227                 [Test]
228                 [ExpectedException (typeof(ArgumentException))]
229                 public void EmptyDirectoryName ()
230                 {
231                         string testDirName = Path.GetDirectoryName ("");
232                 }
233
234                 public void TestDirectoryName ()
235                 {
236                         string [] files = new string [3];
237                         files [(int) OsType.Unix] = "/foo";
238                         files [(int) OsType.Windows] = "c:\\foo";
239                         files [(int) OsType.Mac] = "foo";
240
241                         AssertEquals ("GetDirectoryName #01", null, Path.GetDirectoryName (null));
242                         string testDirName = Path.GetDirectoryName (path1);
243                         AssertEquals ("GetDirectoryName #02", files [(int) OS], testDirName);
244                         testDirName = Path.GetDirectoryName (files [(int) OS] + DSC);
245                         AssertEquals ("GetDirectoryName #03", files [(int) OS], testDirName);
246
247                         if (Windows) {
248                                 try {
249                                         testDirName = Path.GetDirectoryName ("aaa>");
250                                         Fail ("GetDirectoryName Fail #02");
251                                 } catch (Exception e) {
252                                         AssertEquals ("GetDirectoryName Exc. #02", typeof (ArgumentException), e.GetType ());
253                                 }
254                         }
255
256                         try {
257                                 testDirName = Path.GetDirectoryName ("   ");
258                                 Fail ("GetDirectoryName Fail #03");
259                         } catch (Exception e) {
260                                 AssertEquals ("GetDirectoryName Exc. #03", typeof (ArgumentException), e.GetType ());
261                         }
262                 }
263
264                 public void TestGetExtension ()
265                 {
266                         string testExtn = Path.GetExtension (path1);
267
268                         AssertEquals ("GetExtension #01",  ".txt", testExtn);
269
270                         testExtn = Path.GetExtension (path2);
271                         AssertEquals ("GetExtension #02", String.Empty, testExtn);
272
273                         testExtn = Path.GetExtension (String.Empty);
274                         AssertEquals ("GetExtension #03", String.Empty, testExtn);
275
276                         testExtn = Path.GetExtension (null);
277                         AssertEquals ("GetExtension #04", null, testExtn);
278
279                         testExtn = Path.GetExtension (" ");
280                         AssertEquals ("GetExtension #05", String.Empty, testExtn);
281
282                         testExtn = Path.GetExtension (path1 + ".doc");
283                         AssertEquals ("GetExtension #06", ".doc", testExtn);
284
285                         testExtn = Path.GetExtension (path1 + ".doc" + DSC + "a.txt");
286                         AssertEquals ("GetExtension #07", ".txt", testExtn);
287
288                         testExtn = Path.GetExtension (".");
289                         AssertEquals ("GetExtension #08", String.Empty, testExtn);
290
291                         testExtn = Path.GetExtension ("end.");
292                         AssertEquals ("GetExtension #09", String.Empty, testExtn);
293
294                         testExtn = Path.GetExtension (".start");
295                         AssertEquals ("GetExtension #10", ".start", testExtn);
296
297                         testExtn = Path.GetExtension (".a");
298                         AssertEquals ("GetExtension #11", ".a", testExtn);
299
300                         testExtn = Path.GetExtension ("a.");
301                         AssertEquals ("GetExtension #12", String.Empty, testExtn);
302
303                         testExtn = Path.GetExtension ("a");
304                         AssertEquals ("GetExtension #13", String.Empty, testExtn);
305
306                         testExtn = Path.GetExtension ("makefile");
307                         AssertEquals ("GetExtension #14", String.Empty, testExtn);
308
309                         if (Windows) {
310                                 try {
311                                         testExtn = Path.GetExtension ("hi<there.txt");
312                                         Fail ("GetExtension Fail #01");
313                                 } catch (Exception e) {
314                                         AssertEquals ("GetExtension Exc. #01", typeof (ArgumentException), e.GetType ());
315                                 }
316                         }
317                 }
318
319                 public void TestGetFileName ()
320                 {
321                         string testFileName = Path.GetFileName (path1);
322
323                         AssertEquals ("GetFileName #01", "test.txt", testFileName);
324                         testFileName = Path.GetFileName (null);
325                         AssertEquals ("GetFileName #02", null, testFileName);
326                         testFileName = Path.GetFileName (String.Empty);
327                         AssertEquals ("GetFileName #03", String.Empty, testFileName);
328                         testFileName = Path.GetFileName (" ");
329                         AssertEquals ("GetFileName #04", " ", testFileName);
330
331                         if (Windows) {
332                                 try {
333                                         testFileName = Path.GetFileName ("hi<");
334                                         Fail ("GetFileName Fail #01");
335                                 } catch (Exception e) {
336                                         AssertEquals ("GetFileName Exc. #01", typeof (ArgumentException), e.GetType ());
337                                 }
338                         }
339                 }
340
341                 public void TestGetFileNameWithoutExtension ()
342                 {
343                         string testFileName = Path.GetFileNameWithoutExtension (path1);
344
345                         AssertEquals ("GetFileNameWithoutExtension #01", "test", testFileName);
346
347                         testFileName = Path.GetFileNameWithoutExtension (null);
348                         AssertEquals ("GetFileNameWithoutExtension #02", null, testFileName);
349
350                         testFileName = Path.GetFileNameWithoutExtension (String.Empty);
351                         AssertEquals ("GetFileNameWithoutExtension #03", String.Empty, testFileName);
352                 }
353
354                 [Ignore("This does not work under windows. See ERROR comments below.")]
355                 public void TestGetFullPath ()
356                 {
357                         string current = Directory.GetCurrentDirectory ();
358
359                         string testFullPath = Path.GetFullPath ("foo.txt");
360                         string expected = current + DSC + "foo.txt";
361                         AssertEquals ("GetFullPath #01", expected, testFullPath);
362
363                         testFullPath = Path.GetFullPath ("a//./.././foo.txt");
364                         AssertEquals ("GetFullPath #02", expected, testFullPath);
365                         string root = Windows ? "C:\\" : "/";
366                         string [,] test = new string [,] {              
367                                 {"root////././././././../root/././../root", "root"},
368                                 {"root/", "root/"},
369                                 {"root/./", "root/"},
370                                 {"root/./", "root/"},
371                                 {"root/../", ""},
372                                 {"root/../", ""},
373                                 {"root/../..", ""},
374                                 {"root/.hiddenfile", "root/.hiddenfile"},
375                                 {"root/. /", "root/. /"},
376                                 {"root/.. /", "root/.. /"},
377                                 {"root/..weirdname", "root/..weirdname"},
378                                 {"root/..", ""},
379                                 {"root/../a/b/../../..", ""},
380                                 {"root/./..", ""},
381                                 {"..", ""},
382                                 {".", ""},
383                                 {"root//dir", "root/dir"},
384                                 {"root/.              /", "root/.              /"},
385                                 {"root/..             /", "root/..             /"},
386                                 {"root/      .              /", "root/      .              /"},
387                                 {"root/      ..             /", "root/      ..             /"},
388                                 {"root/./", "root/"},
389                                 //ERROR! Paths are trimmed
390                                 {"root/..                      /", "root/..                   /"},
391                                 {".//", ""}
392                         };
393
394                         //ERROR! GetUpperBound (1) returns 1. GetUpperBound (0) == 23
395                         //... so only the first test was being done.
396                         for (int i = 0; i < test.GetUpperBound (1); i++) {
397                                 AssertEquals (String.Format ("GetFullPath #{0}", i), root + test [i, 1], Path.GetFullPath (root + test [i, 0]));
398                         }
399                         
400                         if (Windows) {
401                                 string uncroot = @"\\server\share\";
402                                 string [,] testunc = new string [,] {           
403                                         {"root////././././././../root/././../root", "root"},
404                                         {"root/", "root/"},
405                                         {"root/./", "root/"},
406                                         {"root/./", "root/"},
407                                         {"root/../", ""},
408                                         {"root/../", ""},
409                                         {"root/../..", ""},
410                                         {"root/.hiddenfile", "root/.hiddenfile"},
411                                         {"root/. /", "root/. /"},
412                                         {"root/.. /", "root/.. /"},
413                                         {"root/..weirdname", "root/..weirdname"},
414                                         {"root/..", ""},
415                                         {"root/../a/b/../../..", ""},
416                                         {"root/./..", ""},
417                                         {"..", ""},
418                                         {".", ""},
419                                         {"root//dir", "root/dir"},
420                                         {"root/.              /", "root/.              /"},
421                                         {"root/..             /", "root/..             /"},
422                                         {"root/      .              /", "root/      .              /"},
423                                         {"root/      ..             /", "root/      ..             /"},
424                                         {"root/./", "root/"},
425                                         {"root/..                      /", "root/..                   /"},
426                                         {".//", ""}
427                                 };
428                                 for (int i = 0; i < test.GetUpperBound (1); i++) {
429                                         AssertEquals (String.Format ("GetFullPath UNC #{0}", i), uncroot + test [i, 1], Path.GetFullPath (uncroot + test [i, 0]));
430                                 }       
431                         }
432                         
433                         try {
434                                 testFullPath = Path.GetFullPath (null);
435                                 Fail ("GetFullPath Fail #01");
436                         } catch (Exception e) {
437                                 AssertEquals ("GetFullPath Exc. #01", typeof (ArgumentNullException), e.GetType ());
438                         }
439
440                         try {
441                                 testFullPath = Path.GetFullPath (String.Empty);
442                                 Fail ("GetFullPath Fail #02");
443                         } catch (Exception e) {
444                                 AssertEquals ("GetFullPath Exc. #02", typeof (ArgumentException), e.GetType ());
445                         }
446                 }
447
448                 public void TestGetFullPath2 ()
449                 {
450                         if (Windows) {
451                                 AssertEquals ("GetFullPath w#01", @"Z:\", Path.GetFullPath ("Z:"));
452                                 AssertEquals ("GetFullPath w#02", @"c:\abc\def", Path.GetFullPath (@"c:\abc\def"));
453                                 Assert ("GetFullPath w#03", Path.GetFullPath (@"\").EndsWith (@"\"));
454                                 // "\\\\" is not allowed
455                                 Assert ("GetFullPath w#05", Path.GetFullPath ("/").EndsWith (@"\"));
456                                 // "//" is not allowed
457                                 Assert ("GetFullPath w#07", Path.GetFullPath ("readme.txt").EndsWith (@"\readme.txt"));
458                                 Assert ("GetFullPath w#08", Path.GetFullPath ("c").EndsWith (@"\c"));
459                                 Assert ("GetFullPath w#09", Path.GetFullPath (@"abc\def").EndsWith (@"abc\def"));
460                                 Assert ("GetFullPath w#10", Path.GetFullPath (@"\abc\def").EndsWith (@"\abc\def"));
461                                 AssertEquals ("GetFullPath w#11", @"\\abc\def", Path.GetFullPath (@"\\abc\def"));
462                                 AssertEquals ("GetFullPath w#12", Directory.GetCurrentDirectory () + @"\abc\def", Path.GetFullPath (@"abc//def"));
463                                 AssertEquals ("GetFullPath w#13", Directory.GetCurrentDirectory ().Substring (0,2) + @"\abc\def", Path.GetFullPath ("/abc/def"));
464                                 AssertEquals ("GetFullPath w#14", @"\\abc\def", Path.GetFullPath ("//abc/def"));
465                         }
466                 }
467
468                 public void TestGetPathRoot ()
469                 {
470                         string current;
471                         string expected;
472                         if (!Windows){
473                                 current = Directory.GetCurrentDirectory ();
474                                 expected = current [0].ToString ();
475                         } else {
476                                 current = @"J:\Some\Strange Directory\Name";
477                                 expected = "J:\\";
478                         }
479
480                         string pathRoot = Path.GetPathRoot (current);
481                         AssertEquals ("GetPathRoot #01", expected, pathRoot);
482                 }
483
484                 [Test]
485                 public void TestGetPathRoot2 ()
486                 {
487                         // note: this method doesn't call Directory.GetCurrentDirectory so it can be
488                         // reused for partial trust unit tests in PathCas.cs
489
490                         string pathRoot = Path.GetPathRoot ("hola");
491                         AssertEquals ("GetPathRoot #02", String.Empty, pathRoot);
492
493                         pathRoot = Path.GetPathRoot (null);
494                         AssertEquals ("GetPathRoot #03", null, pathRoot);
495
496                         if (Windows) {
497                                 AssertEquals ("GetPathRoot w#01", "z:", Path.GetPathRoot ("z:"));
498                                 AssertEquals ("GetPathRoot w#02", "c:\\", Path.GetPathRoot ("c:\\abc\\def"));
499                                 AssertEquals ("GetPathRoot w#03", "\\", Path.GetPathRoot ("\\"));
500                                 AssertEquals ("GetPathRoot w#04", "\\\\", Path.GetPathRoot ("\\\\"));
501                                 AssertEquals ("GetPathRoot w#05", "\\", Path.GetPathRoot ("/"));
502                                 AssertEquals ("GetPathRoot w#06", "\\\\", Path.GetPathRoot ("//"));
503                                 AssertEquals ("GetPathRoot w#07", String.Empty, Path.GetPathRoot ("readme.txt"));
504                                 AssertEquals ("GetPathRoot w#08", String.Empty, Path.GetPathRoot ("c"));
505                                 AssertEquals ("GetPathRoot w#09", String.Empty, Path.GetPathRoot ("abc\\def"));
506                                 AssertEquals ("GetPathRoot w#10", "\\", Path.GetPathRoot ("\\abc\\def"));
507                                 AssertEquals ("GetPathRoot w#11", "\\\\abc\\def", Path.GetPathRoot ("\\\\abc\\def"));
508                                 AssertEquals ("GetPathRoot w#12", String.Empty, Path.GetPathRoot ("abc//def"));
509                                 AssertEquals ("GetPathRoot w#13", "\\", Path.GetPathRoot ("/abc/def"));
510                                 AssertEquals ("GetPathRoot w#14", "\\\\abc\\def", Path.GetPathRoot ("//abc/def"));
511                         } else {
512                                 // TODO: Same tests for Unix.
513                         }
514                 }
515
516                 public void TestGetTempPath ()
517                 {
518                         string getTempPath = Path.GetTempPath ();
519                         Assert ("GetTempPath #01",  getTempPath != String.Empty);
520                         Assert ("GetTempPath #02",  Path.IsPathRooted (getTempPath));
521                         AssertEquals ("GetTempPath #03", Path.DirectorySeparatorChar, getTempPath [getTempPath.Length - 1]);
522                 }
523
524                 public void TestGetTempFileName ()
525                 {
526                         string getTempFileName = null;
527                         try {
528                                 getTempFileName = Path.GetTempFileName ();
529                                 Assert ("GetTempFileName #01", getTempFileName != String.Empty);
530                                 Assert ("GetTempFileName #02", File.Exists (getTempFileName));
531                         } finally {
532                                 if (getTempFileName != null && getTempFileName != String.Empty){
533                                         File.Delete (getTempFileName);
534                                 }
535                         }
536                 }
537
538                 public void TestHasExtension ()
539                 {
540                         AssertEquals ("HasExtension #01",  true, Path.HasExtension ("foo.txt"));
541                         AssertEquals ("HasExtension #02",  false, Path.HasExtension ("foo"));
542                         AssertEquals ("HasExtension #03",  true, Path.HasExtension (path1));
543                         AssertEquals ("HasExtension #04",  false, Path.HasExtension (path2));
544                         AssertEquals ("HasExtension #05",  false, Path.HasExtension (null));
545                         AssertEquals ("HasExtension #06",  false, Path.HasExtension (String.Empty));
546                         AssertEquals ("HasExtension #07",  false, Path.HasExtension (" "));
547                         AssertEquals ("HasExtension #08",  false, Path.HasExtension ("."));
548                         AssertEquals ("HasExtension #09",  false, Path.HasExtension ("end."));
549                         AssertEquals ("HasExtension #10",  true, Path.HasExtension (".start"));
550                         AssertEquals ("HasExtension #11",  true, Path.HasExtension (".a"));
551                         AssertEquals ("HasExtension #12",  false, Path.HasExtension ("a."));
552                         AssertEquals ("HasExtension #13",  false, Path.HasExtension ("Makefile"));
553                 }
554
555                 public void TestRooted ()
556                 {
557                         Assert ("IsPathRooted #01", Path.IsPathRooted (path2));
558                         Assert ("IsPathRooted #02", !Path.IsPathRooted (path3));
559                         Assert ("IsPathRooted #03", !Path.IsPathRooted (null));
560                         Assert ("IsPathRooted #04", !Path.IsPathRooted (String.Empty));
561                         Assert ("IsPathRooted #05", !Path.IsPathRooted (" "));
562                         Assert ("IsPathRooted #06", Path.IsPathRooted ("/"));
563                         if (Windows)
564                                 Assert ("IsPathRooted #07", Path.IsPathRooted ("\\"));
565                         else
566                                 Assert ("IsPathRooted #07", !Path.IsPathRooted ("\\"));
567                         Assert ("IsPathRooted #08", Path.IsPathRooted ("//"));
568                         if (Windows)
569                                 Assert ("IsPathRooted #09", Path.IsPathRooted ("\\\\"));
570                         else
571                                 Assert ("IsPathRooted #09", !Path.IsPathRooted ("\\\\"));
572                         Assert ("IsPathRooted #10", !Path.IsPathRooted (":"));
573                         if (Windows)
574                                 Assert ("IsPathRooted #11", Path.IsPathRooted ("z:"));
575                         else
576                                 Assert ("IsPathRooted #11", !Path.IsPathRooted ("z:"));
577
578                         if (Windows) {
579                                 Assert ("IsPathRooted #12", Path.IsPathRooted ("z:\\"));
580                                 Assert ("IsPathRooted #13", Path.IsPathRooted ("z:\\topdir"));
581                                 // This looks MS BUG. It is treated as absolute path
582                                 Assert ("IsPathRooted #14", Path.IsPathRooted ("z:curdir"));
583                                 Assert ("IsPathRooted #15", Path.IsPathRooted ("\\abc\\def"));
584                         }
585                 }
586
587                 public void TestCanonicalizeDots ()
588                 {
589                         string current = Path.GetFullPath (".");
590                         Assert ("TestCanonicalizeDotst #01", !current.EndsWith ("."));
591                         string parent = Path.GetFullPath ("..");
592                         Assert ("TestCanonicalizeDotst #02", !current.EndsWith (".."));
593                 }
594
595                 public void TestDirectoryNameBugs ()
596                 {
597                         if (Windows) {
598                                 AssertEquals ("Win #01", "C:\\foo", Path.GetDirectoryName ("C:\\foo\\foo.txt"));
599                         } else {
600                                 AssertEquals ("No win #01", "/etc", Path.GetDirectoryName ("/etc/hostname"));
601                         }
602                 }
603
604                 public void TestGetFullPathUnix ()
605                 {
606                         if (Windows)
607                                 return;
608
609                         AssertEquals ("#01", "/", Path.GetFullPath ("/"));
610                         AssertEquals ("#02", "/hey", Path.GetFullPath ("/hey"));
611                         AssertEquals ("#03", Environment.CurrentDirectory, Path.GetFullPath ("."));
612                         AssertEquals ("#04", Path.Combine (Environment.CurrentDirectory, "hey"),
613                                              Path.GetFullPath ("hey"));
614                 }
615         }
616 }
617