remove TARGET_JVM
[mono.git] / mcs / class / corlib / Test / System.IO / DirectoryInfoTest.cs
1 // DirectoryInfoTest.cs - NUnit Test Cases for System.IO.DirectoryInfo class
2 //
3 // Authors
4 //      Ville Palo (vi64pa@koti.soon.fi)
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 // 
7 // (C) 2003 Ville Palo
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // 
10
11 using NUnit.Framework;
12 using System;
13 using System.Collections;
14 using System.IO;
15
16 namespace MonoTests.System.IO
17 {
18         [TestFixture]
19         public class DirectoryInfoTest : Assertion
20         {
21                 string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
22
23                 static readonly char DSC = Path.DirectorySeparatorChar;
24                 string current;
25
26                 [SetUp]
27                 protected void SetUp ()
28                 {
29                         current = Directory.GetCurrentDirectory ();
30                         if (Directory.Exists (TempFolder))
31                                 Directory.Delete (TempFolder, true);
32                         Directory.CreateDirectory (TempFolder);
33                 }
34         
35                 [TearDown]
36                 protected void TearDown ()
37                 {
38                         if (Directory.Exists (TempFolder))
39                                 Directory.Delete (TempFolder, true);
40                         Directory.SetCurrentDirectory (current);
41                 }
42         
43                 [Test]
44                 public void Ctr ()
45                 {
46                         string path = TempFolder + DSC + "DIT.Ctr.Test";
47                         DeleteDir (path);
48                 
49                         FileInfo info = new FileInfo (path);
50                         AssertEquals ("test#01", true, info.DirectoryName.EndsWith (".Tests"));
51                         AssertEquals ("test#02", false, info.Exists);
52                         AssertEquals ("test#03", ".Test", info.Extension);
53                         AssertEquals ("test#05", "DIT.Ctr.Test", info.Name);            
54                 }
55
56                 [Test]
57                 [ExpectedException(typeof(ArgumentNullException))]
58                 public void CtorArgumentNullException ()
59                 {
60                         DirectoryInfo info = new DirectoryInfo (null);            
61                 }
62
63                 [Test]
64                 [ExpectedException(typeof(ArgumentException))]
65                 public void CtorArgumentException1 ()
66                 {
67                         DirectoryInfo info = new DirectoryInfo ("");            
68                 }
69
70                 [Test]
71                 [ExpectedException(typeof(ArgumentException))]
72                 public void CtorArgumentException2 ()
73                 {
74                         DirectoryInfo info = new DirectoryInfo ("   ");            
75                 }
76
77                 [Test]
78                 [ExpectedException(typeof(ArgumentException))]
79                 public void CtorArgumentException3 ()
80                 {
81                 string path = "";
82                 foreach (char c in Path.InvalidPathChars) {
83                         path += c;
84                 }
85                 DirectoryInfo info = new DirectoryInfo (path);
86                 }
87                                 
88                 [Test]
89                 public void Exists ()
90                 {
91                 string path = TempFolder + DSC + "DIT.Exists.Test";
92                 DeleteDir (path);
93             
94                 try {
95                         DirectoryInfo info = new DirectoryInfo (path);
96                         AssertEquals ("test#01", false, info.Exists);
97             
98                         Directory.CreateDirectory (path);
99                         AssertEquals ("test#02", false, info.Exists);
100                         info = new DirectoryInfo (path);
101                         AssertEquals ("test#03", true, info.Exists);            
102                 } finally {
103                         DeleteDir (path);
104                 }
105                 }
106                 
107                 [Test]
108                 public void Name ()
109                 {
110                         string path = TempFolder + DSC + "DIT.Name.Test";
111                         DeleteDir (path);
112                         
113                         try {
114                                 DirectoryInfo info = new DirectoryInfo (path);                          
115                                 AssertEquals ("test#01", "DIT.Name.Test", info.Name);
116                                 
117                                 info = Directory.CreateDirectory (path);
118                                 AssertEquals ("test#02", "DIT.Name.Test", info.Name);
119                                 
120                                 
121                         } finally {
122                                 DeleteDir (path);
123                         }                                  
124                 }
125                 
126                 [Test]
127                 public void Parent ()
128                 {
129                         string path = TempFolder + DSC + "DIT.Parent.Test";
130                         DeleteDir (path);
131                         
132                         try {
133                                 DirectoryInfo info = new DirectoryInfo (path);
134                                 AssertEquals ("test#01", "MonoTests.System.IO.Tests", info.Parent.Name);
135                                 
136                                 info = Directory.CreateDirectory (path);
137                                 AssertEquals ("test#02", "MonoTests.System.IO.Tests", info.Parent.Name);
138                                                                 
139                         } finally {
140                                 DeleteDir (path);
141                         }                                               
142                 }
143
144                 [Test]
145                 public void Create ()
146                 {
147                 string path = TempFolder + DSC + "DIT.Create.Test";
148                 DeleteDir (path);
149             
150                 try {
151                         DirectoryInfo info = new DirectoryInfo (path);
152                         AssertEquals ("test#01", false, info.Exists);
153                         info.Create ();                
154                         AssertEquals ("test#02", false, info.Exists);
155                         info = new DirectoryInfo (path);
156                         AssertEquals ("test#03", true, info.Exists);
157                 } finally {
158                         DeleteDir (path);
159                 }
160                 }
161
162                 [Test]
163                 public void CreateSubdirectory ()
164                 {
165                         string sub_path = Path.Combine ("test01", "test02");
166                         try {
167                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
168                                 info.CreateSubdirectory (sub_path);
169                                 Assert ("test#01", Directory.Exists (Path.Combine (TempFolder, sub_path)));
170                         } finally {
171                                 DeleteDir (Path.Combine (TempFolder, sub_path));
172                         }
173                                 
174                 }
175                 
176                 [Test]
177                 [ExpectedException(typeof(ArgumentException))]
178                 public void CreateSubdirectoryEmptyString ()
179                 {
180                         new DirectoryInfo (".").CreateSubdirectory ("");
181                 }
182
183                 [Test]
184                 public void Delete1 ()
185                 {
186                 string path = TempFolder + DSC + "DIT.Delete1.Test";
187                 DeleteDir (path);
188                         
189                         try {
190                                 Directory.CreateDirectory (path);
191                                 DirectoryInfo info = new DirectoryInfo (path);
192                                 AssertEquals ("test#01", true, info.Exists);
193                                 
194                                 info.Delete ();
195                                 AssertEquals ("test#02", true, info.Exists);
196                                 
197                                 info = new DirectoryInfo (path);
198                                 AssertEquals ("test#03", false, info.Exists);
199                         } finally {
200                                 DeleteDir (path);
201                         }
202                 }
203
204                 [Test]
205                 public void Delete2 ()
206                 {
207                 string path = TempFolder + DSC + "DIT.Delete2.Test";
208                 DeleteDir (path);
209                         
210                         try {
211                                 Directory.CreateDirectory (path);
212                                 File.Create (path + DSC + "test").Close ();
213                                 DirectoryInfo info = new DirectoryInfo (path);
214                                 AssertEquals ("test#01", true, info.Exists);
215                                 
216                                 info.Delete (true);
217                                 AssertEquals ("test#02", true, info.Exists);
218                                 
219                                 info = new DirectoryInfo (path);
220                                 AssertEquals ("test#03", false, info.Exists);
221                         } finally {
222                                 DeleteDir (path);
223                         }
224                 }
225                 
226                 [Test]
227                 [ExpectedException (typeof (IOException))]
228                 public void DeleteIOException1 ()
229                 {
230                 string path = TempFolder + DSC + "DIT.DeleteIOException1.Test";
231                 DeleteDir (path);                       
232                         
233                         try {
234                                 Directory.CreateDirectory (path);
235                                 File.Create (path + DSC + "test").Close ();
236                                 DirectoryInfo info = new DirectoryInfo (path);
237                                 info.Delete ();
238                         } finally {
239                                 DeleteDir (path);
240                         }
241                 }
242
243                 [Test]
244                 [ExpectedException (typeof (IOException))]
245                 public void DeleteIOException2 ()
246                 {
247                 string path = TempFolder + DSC + "DIT.DeleteIOException2.Test";
248                 DeleteDir (path);                       
249                         
250                         try {
251                                 Directory.CreateDirectory (path);
252                                 File.Create (path + DSC + "test").Close ();
253                                 DirectoryInfo info = new DirectoryInfo (path);
254                                 info.Delete (false);
255                         } finally {
256                                 DeleteDir (path);
257                         }
258                 }
259
260                 [Test]
261                 // from bug #75443
262                 public void FullName ()
263                 {
264                         DirectoryInfo di = new DirectoryInfo ("something");
265                         Assert ("Exists", !di.Exists);
266                         Assert ("FullName", di.FullName.EndsWith ("something"));
267
268                         di = new DirectoryInfo ("something" + Path.DirectorySeparatorChar);
269                         AssertEquals ("DirectorySeparatorChar", Path.DirectorySeparatorChar, di.FullName [di.FullName.Length - 1]);
270
271                         di = new DirectoryInfo ("something" + Path.AltDirectorySeparatorChar);
272                         AssertEquals ("AltDirectorySeparatorChar", Path.DirectorySeparatorChar, di.FullName [di.FullName.Length - 1]);
273                 }
274
275                 [Test]
276                 public void FullName_RootDirectory ()
277                 {
278                         DirectoryInfo di = new DirectoryInfo (String.Empty + Path.DirectorySeparatorChar);
279                         if (Path.DirectorySeparatorChar == '/') {
280                                 // can't be sure of the root drive under windows
281                                 AssertEquals ("FullName", "/", di.FullName);
282                         }
283                         AssertNull ("Parent", di.Parent);
284
285                         di = new DirectoryInfo (String.Empty + Path.AltDirectorySeparatorChar);
286                         if (Path.DirectorySeparatorChar == '/') {
287                                 // can't be sure of the root drive under windows
288                                 AssertEquals ("FullName-Alt", "/", di.FullName);
289                         }
290                         AssertNull ("Parent-Alt", di.Parent);
291                 }
292                 
293                 [Test]
294                 public void GetDirectories1 ()
295                 {
296                         string path = TempFolder + DSC + "DIT.GetDirectories1.Test";
297                         
298                         try {
299                                 DirectoryInfo info = Directory.CreateDirectory (path);
300                                 AssertEquals ("test#01", 0, info.GetDirectories ().Length);
301                                 
302                                 Directory.CreateDirectory (path + DSC + "1");
303                                 Directory.CreateDirectory (path + DSC + "2");                           
304                                 File.Create (path + DSC + "filetest").Close ();
305                                 AssertEquals ("test#02", 2, info.GetDirectories ().Length);
306                                 
307                                 Directory.Delete (path + DSC + 2);
308                                 AssertEquals ("test#02", 1, info.GetDirectories ().Length);                             
309                                 
310                         } finally {
311                                 DeleteDir (path);
312                         }
313                 }
314                 
315                 [Test]
316                 public void GetDirectories2 ()
317                 {
318                         string path = TempFolder + DSC + "DIT.GetDirectories2.Test";
319                         
320                         try {
321                                 DirectoryInfo info = Directory.CreateDirectory (path);
322                                 AssertEquals ("test#01", 0, info.GetDirectories ("*").Length);
323                                 
324                                 Directory.CreateDirectory (path + DSC + "test120");
325                                 Directory.CreateDirectory (path + DSC + "test210");
326                                 Directory.CreateDirectory (path + DSC + "atest330");
327                                 Directory.CreateDirectory (path + DSC + "test220");
328                                 Directory.CreateDirectory (path + DSC + "rest");
329                                 Directory.CreateDirectory (path + DSC + "rest" + DSC + "subdir");
330                                 File.Create (path + DSC + "filetest").Close ();
331                                 
332                                 AssertEquals ("test#02", 5, info.GetDirectories ("*").Length);
333                                 AssertEquals ("test#03", 3, info.GetDirectories ("test*").Length);
334                                 AssertEquals ("test#04", 2, info.GetDirectories ("test?20").Length);
335                                 AssertEquals ("test#05", 0, info.GetDirectories ("test?").Length);
336                                 AssertEquals ("test#06", 0, info.GetDirectories ("test[12]*").Length);
337                                 AssertEquals ("test#07", 2, info.GetDirectories ("test2*0").Length);
338                                 AssertEquals ("test#08", 4, info.GetDirectories ("*test*").Length);
339 #if NET_2_0
340                                 AssertEquals ("test#09", 6, info.GetDirectories ("*", SearchOption.AllDirectories).Length);
341 #endif
342                                 
343                         } finally {
344                                 DeleteDir (path);
345                         }
346                 }
347                 
348                 [Test]
349                 [ExpectedException (typeof (DirectoryNotFoundException))]               
350                 public void GetDirectoriesDirectoryNotFoundException1 ()
351                 {
352                 string path = TempFolder + DSC + "DIT.GetDirectoriesDirectoryNotFoundException1.Test";
353                 DeleteDir (path);
354                         
355                         try {
356                                 DirectoryInfo info = new DirectoryInfo (path);
357                                 info.GetDirectories ();
358                         } finally {
359                                 DeleteDir (path);
360                         }
361                 }
362
363                 [Test]
364                 [ExpectedException (typeof (DirectoryNotFoundException))]               
365                 public void GetDirectoriesDirectoryNotFoundException2 ()
366                 {
367                 string path = TempFolder + DSC + "DIT.GetDirectoriesDirectoryNotFoundException2.Test";
368                 DeleteDir (path);
369                         
370                         try {
371                                 DirectoryInfo info = new DirectoryInfo (path);
372                                 info.GetDirectories ("*");
373                         } finally {
374                                 DeleteDir (path);
375                         }
376                 }
377                 
378                 [Test]
379                 [ExpectedException (typeof (ArgumentNullException))]
380                 public void GetDirectoriesArgumentNullException ()
381                 {
382                 string path = TempFolder + DSC + "DIT.GetDirectoriesArgumentNullException.Test";
383                 DeleteDir (path);
384                         
385                         try {
386                                 DirectoryInfo info = new DirectoryInfo (path);
387                                 info.GetDirectories (null);
388                         } finally {
389                                 DeleteDir (path);
390                         }                       
391                 }
392
393                 [Test]
394                 public void GetFiles1 ()
395                 {
396                 string path = TempFolder + DSC + "DIT.GetFiles1.Test";
397                 DeleteDir (path);
398                         
399                         try {
400                                 DirectoryInfo info = Directory.CreateDirectory (path);
401                                 AssertEquals ("test#01", 0, info.GetFiles ().Length);
402                                 File.Create (path + DSC + "file1").Close ();
403                                 File.Create (path + DSC + "file2").Close ();
404                                 Directory.CreateDirectory (path + DSC + "directory1");
405                                 AssertEquals ("test#02", 2, info.GetFiles ().Length);
406                                                         
407                         } finally {
408                                 DeleteDir (path);
409                         }
410                 }
411                 
412                 [Test]
413                 public void GetFiles2()
414                 {
415                 string path = TempFolder + DSC + "DIT.GetFiles2.Test";
416                 DeleteDir (path);
417                         
418                         try {
419                                 DirectoryInfo info = Directory.CreateDirectory (path);
420                                 AssertEquals ("test#01", 0, info.GetFiles ("*").Length);
421                                 File.Create (path + DSC + "file120file").Close ();
422                                 File.Create (path + DSC + "file220file").Close ();
423                                 File.Create (path + DSC + "afile330file").Close ();
424                                 File.Create (path + DSC + "test.abc").Close ();
425                                 File.Create (path + DSC + "test.abcd").Close ();
426                                 File.Create (path + DSC + "test.abcdef").Close ();                              
427                                 Directory.CreateDirectory (path + DSC + "dir");
428                                 
429                                 AssertEquals ("test#02", 6, info.GetFiles ("*").Length);
430                                 AssertEquals ("test#03", 2, info.GetFiles ("file*file").Length);
431                                 AssertEquals ("test#04", 3, info.GetFiles ("*file*").Length);
432                                 AssertEquals ("test#05", 2, info.GetFiles ("file?20file").Length);
433                                 AssertEquals ("test#07", 1, info.GetFiles ("*.abcd").Length);
434                                 AssertEquals ("test#08", 2, info.GetFiles ("*.abcd*").Length);                                                  
435                         } finally {
436                                 DeleteDir (path);
437                         }
438                 }
439                 
440                 [Test]
441                 [ExpectedException (typeof (DirectoryNotFoundException))]
442                 public void GetFilesDirectoryNotFoundException1 ()
443                 {
444                         string path = TempFolder + DSC + "DIT.GetFilesDirectoryNotFoundException1.Test";
445                         DeleteDir (path);
446                         
447                         try {
448                                 DirectoryInfo info = new DirectoryInfo (path);
449                                 info.GetFiles ();
450                                 
451                         } finally {
452                                 DeleteDir (path);
453                         }
454                 }
455
456                 [Test]
457                 [ExpectedException (typeof (DirectoryNotFoundException))]
458                 public void GetFilesDirectoryNotFoundException2 ()
459                 {
460                         string path = TempFolder + DSC + "DIT.GetFilesDirectoryNotFoundException2.Test";
461                         DeleteDir (path);
462                         
463                         try {
464                                 DirectoryInfo info = new DirectoryInfo (path);
465                                 info.GetFiles ("*");
466                                 
467                         } finally {
468                                 DeleteDir (path);
469                         }
470                 }
471                 
472                 [Test]
473                 [ExpectedException (typeof (ArgumentNullException))]
474                 public void GetFilesArgumentNullException ()
475                 {
476                         string path = TempFolder + DSC + "DIT.GetFilesArgumentNullException.Test";
477                         DeleteDir (path);
478                         
479                         try {
480                                 DirectoryInfo info = new DirectoryInfo (path);
481                                 info.GetFiles (null);                           
482                         } finally {
483                                 DeleteDir (path);
484                         }
485                 }
486                 
487                 [Test]
488                 public void MoveTo ()
489                 {
490                         string path1 = TempFolder + DSC + "DIT.MoveTo.Soucre.Test";
491                         string path2 = TempFolder + DSC + "DIT.MoveTo.Dest.Test";
492                         DeleteDir (path1);
493                         DeleteDir (path2);
494                         
495                         try {
496                                 DirectoryInfo info1 = Directory.CreateDirectory (path1);
497                                 DirectoryInfo info2 = new DirectoryInfo (path2);
498                                 
499                                 AssertEquals ("test#01", true, info1.Exists);
500                                 AssertEquals ("test#02", false, info2.Exists);
501                                                                                                 
502                                 info1.MoveTo (path2);                           
503                                 AssertEquals ("test#03", true, info1.Exists);
504                                 AssertEquals ("test#04", false, info2.Exists);
505                                 
506                                 info1 = new DirectoryInfo (path1);
507                                 info2 = new DirectoryInfo (path2);
508                                 AssertEquals ("test#05", false, info1.Exists);
509                                 AssertEquals ("test#06", true, info2.Exists);
510                                 
511                         } finally {
512                                 DeleteDir (path1);
513                                 DeleteDir (path2);
514                         }
515                 }
516
517                 [Test]
518                 [ExpectedException (typeof (ArgumentNullException))]
519                 public void MoveToArgumentNullException ()
520                 {
521                         string path = TempFolder + DSC + "DIT.MoveToArgumentNullException.Test";
522                         DeleteDir (path);
523                         
524                         try {
525                                 DirectoryInfo info = Directory.CreateDirectory (path);
526                                 info.MoveTo (null);
527                         } finally {
528                                 DeleteDir (path);
529                         }
530                         
531                 }
532
533                 [Test]
534                 [ExpectedException (typeof (IOException))]
535                 public void MoveToIOException1 ()
536                 {
537                         string path = TempFolder + DSC + "DIT.MoveToIOException1.Test";
538                         DeleteDir (path);
539                         
540                         try {
541                                 DirectoryInfo info = Directory.CreateDirectory (path);
542                                 info.MoveTo (path);
543                         } finally {
544                                 DeleteDir (path);
545                         }                       
546                 }
547
548                 [Test]
549                 [ExpectedException (typeof (ArgumentException))]
550                 public void MoveToArgumentException1 ()
551                 {
552                         string path = TempFolder + DSC + "DIT.MoveToArgumentException1.Test";
553                         DeleteDir (path);
554                         
555                         try {
556                                 DirectoryInfo info = Directory.CreateDirectory (path);
557                                 info.MoveTo ("");
558                         } finally {
559                                 DeleteDir (path);
560                         }                       
561                 }
562
563                 [Test]
564                 [ExpectedException (typeof (ArgumentException))]
565                 public void MoveToArgumentException2 ()
566                 {
567                         string path = TempFolder + DSC + "DIT.MoveToArgumentException2.Test";
568                         DeleteDir (path);
569                         
570                         try {
571                                 DirectoryInfo info = Directory.CreateDirectory (path);
572                                 info.MoveTo ("    ");
573                         } finally {
574                                 DeleteDir (path);
575                         }                       
576                 }
577
578                 [Test]
579                 [ExpectedException (typeof (ArgumentException))]
580                 public void MoveToArgumentException3 ()
581                 {
582                         string path = TempFolder + DSC + "DIT.MoveToArgumentException3.Test";
583                         DeleteDir (path);
584                         
585                         try {
586                                 DirectoryInfo info = Directory.CreateDirectory (path);
587                                 info.MoveTo (Path.InvalidPathChars [0].ToString ());
588                         } finally {
589                                 DeleteDir (path);
590                         }                       
591                 }
592
593                 [Test]
594                 [ExpectedException (typeof (IOException))]
595                 public void MoveToIOException2 ()
596                 {
597                         string path = TempFolder + DSC + "DIT.MoveToIOException2.Test";
598                         DeleteDir (path);
599                         
600                         try {
601                                 DirectoryInfo info = new DirectoryInfo (path);
602                                 info.MoveTo (path);
603                         } finally {
604                                 DeleteDir (path);
605                         }                       
606                 }
607
608                 private void DeleteDir (string path)
609                 {
610                         if (Directory.Exists (path))
611                                 Directory.Delete (path, true);
612                 }
613  
614                 [Test]
615 #if TARGET_JVM
616         [Category("NotWorking")]
617 #endif
618                 public void DirectoryNameWithSpace ()
619                 {
620                         // check for Unix platforms - see FAQ for more details
621                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
622                         int platform = (int) Environment.OSVersion.Platform;
623                         if ((platform == 4) || (platform == 128)) {
624                                 DeleteDir ("this has a space at the end ");
625                                 string path = Path.Combine (TempFolder, "this has a space at the end ");
626                                 Directory.CreateDirectory (path);
627                                 DirectoryInfo i = new DirectoryInfo (path);
628                                 string dummy = null;
629                                 foreach (FileInfo f in i.GetFiles ()) // This used to throw
630                                         dummy = f.Name;
631                         }
632                 }
633
634                         [Test]
635                         public void LastWriteTime ()
636                         {
637                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
638                                 info.LastWriteTime = new DateTime (2003, 6, 4, 6, 4, 0);
639
640                                 DateTime time = Directory.GetLastWriteTime (TempFolder);
641                                 AssertEquals ("test#01", 2003, time.Year);
642                                 AssertEquals ("test#02", 6, time.Month);
643                                 AssertEquals ("test#03", 4, time.Day);
644                                 AssertEquals ("test#04", 6, time.Hour);
645                                 AssertEquals ("test#05", 4, time.Minute);
646                                 AssertEquals ("test#06", 0, time.Second);
647
648                                 time = TimeZone.CurrentTimeZone.ToLocalTime (
649                                         Directory.GetLastWriteTimeUtc (TempFolder));
650                                 AssertEquals ("test#07", 2003, time.Year);
651                                 AssertEquals ("test#08", 6, time.Month);
652                                 AssertEquals ("test#09", 4, time.Day);
653                                 AssertEquals ("test#10", 6, time.Hour);
654                                 AssertEquals ("test#11", 4, time.Minute);
655                                 AssertEquals ("test#12", 0, time.Second);
656                         }
657
658                         [Test]
659                         public void LastWriteTimeUtc ()
660                         {
661                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
662                                 info.LastWriteTimeUtc = new DateTime (2003, 6, 4, 6, 4, 0);
663
664                                 DateTime time = TimeZone.CurrentTimeZone.ToUniversalTime (
665                                         Directory.GetLastWriteTime (TempFolder));
666                                 AssertEquals ("test#1", 2003, time.Year);
667                                 AssertEquals ("test#2", 6, time.Month);
668                                 AssertEquals ("test#3", 4, time.Day);
669                                 AssertEquals ("test#4", 6, time.Hour);
670                                 AssertEquals ("test#5", 4, time.Minute);
671                                 AssertEquals ("test#6", 0, time.Second);
672
673                                 time = Directory.GetLastWriteTimeUtc (TempFolder);
674                                 AssertEquals ("test#7", 2003, time.Year);
675                                 AssertEquals ("test#8", 6, time.Month);
676                                 AssertEquals ("test#9", 4, time.Day);
677                                 AssertEquals ("test#10", 6, time.Hour);
678                                 AssertEquals ("test#11", 4, time.Minute);
679                                 AssertEquals ("test#12", 0, time.Second);
680                         }
681
682                         [Test]\r
683 #if TARGET_JVM\r
684             [Category("NotWorking")]\r
685 #endif
686                         public void LastAccessTime ()
687                         {
688                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
689                                 info.LastAccessTime = DateTime.Now;
690                         }
691
692                         [Test]\r
693 #if TARGET_JVM\r
694             [Category("NotWorking")]\r
695 #endif
696                         public void LastAccessTimeUtc ()
697                         {
698                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
699                                 info.LastAccessTimeUtc = DateTime.Now;
700                         }
701
702                         [Test]\r
703 #if TARGET_JVM\r
704             [Category("NotWorking")]\r
705 #endif
706                         public void CreationTime ()
707                         {
708                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
709                                 info.CreationTime = DateTime.Now;
710                         }
711
712                         [Test]\r
713 #if TARGET_JVM\r
714             [Category("NotWorking")]\r
715 #endif
716                         public void CreationTimeUtc ()
717                         {
718                                 DirectoryInfo info = new DirectoryInfo (TempFolder);
719                                 info.CreationTimeUtc = DateTime.Now;
720                         }
721
722
723                 private void CheckName (string name)
724                 {
725                         DirectoryInfo di = new DirectoryInfo (name);
726                         AssertEquals (name + ".Name", "share", di.Name);
727                         AssertEquals (name + ".Parent.Name", "usr", di.Parent.Name);
728                 }
729
730                 [Test]
731                 public void Name_Bug76903 ()
732                 {
733                         CheckName ("/usr/share");
734                         CheckName ("/usr/share/");
735                         CheckName ("/usr/share/.");
736                         CheckName ("/usr/share/./");
737                         CheckName ("/usr/share/blabla/../");
738                         CheckName ("/usr/lib/../share/.");
739                 }
740
741                 [Test]
742                 public void Hang_76191 ()
743                 {
744                         // from bug #76191 (hangs on Windows)
745                         DirectoryInfo di = new DirectoryInfo (Environment.CurrentDirectory);
746                         Stack s = new Stack ();
747                         s.Push (di);
748                         while (di.Parent != null) {
749                                 di = di.Parent;
750                                 s.Push (di);
751                         }
752                         while (s.Count > 0) {
753                                 di = (DirectoryInfo) s.Pop ();
754                                 Assert (di.Name, di.Exists);
755                         }
756                 }
757
758                 private void WindowsParentFullName (string name, string expected)
759                 {
760                         DirectoryInfo di = new DirectoryInfo (name);
761                         if (di.Parent == null)
762                                 AssertNull (name, expected);
763                         else
764                                 AssertEquals (name, expected, di.Parent.FullName);
765                 }
766
767                 [Test]
768                 public void WindowsSystem32_76191 ()
769                 {
770 #if !TARGET_JVM
771                         // check for Unix platforms - see FAQ for more details
772                         // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
773                         int platform = (int) Environment.OSVersion.Platform;
774                         if ((platform == 4) || (platform == 128))
775                                 return;
776 #endif
777
778                         Directory.SetCurrentDirectory (@"C:\WINDOWS\system32");
779                         WindowsParentFullName ("C:", "C:\\WINDOWS");
780                         WindowsParentFullName ("C:\\", null);
781                         WindowsParentFullName ("C:\\dir", "C:\\");
782                         WindowsParentFullName ("C:\\dir\\", "C:\\");
783                         WindowsParentFullName ("C:\\dir\\dir", "C:\\dir");
784                         WindowsParentFullName ("C:\\dir\\dir\\", "C:\\dir");
785                 }
786
787                 [Test]
788                 public void Parent_Bug77090 ()
789                 {
790                         DirectoryInfo di = new DirectoryInfo ("/home");
791                         if (Path.DirectorySeparatorChar == '\\') {
792                                 Assert ("/home parent (Windows path)", di.Parent.Name.EndsWith (":\\"));
793                         }
794                         else
795                                 AssertEquals ("/home parent", "/", di.Parent.Name);
796                         AssertNull ("/home parent parent", di.Parent.Parent);
797                 }
798         }
799 }