New test.
[mono.git] / mcs / class / corlib / Test / System.IO / FileSystemInfoTest.cs
index 22eabc2da6fd3fb1217fb5af71384dab64f545da..2c664ad6b9b454c3ebb418e51776ce7780d6b369 100644 (file)
@@ -18,6 +18,7 @@ namespace MonoTests.System.IO
         public class FileSystemInfoTest : Assertion
        {
                string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
+               static readonly char DSC = Path.DirectorySeparatorChar;
 
                [SetUp]
                protected void SetUp() 
@@ -33,6 +34,27 @@ namespace MonoTests.System.IO
                        if (Directory.Exists (TempFolder))
                                Directory.Delete (TempFolder, true);
                }
+               
+               bool Windows
+               {
+                       get {
+                               return Path.DirectorySeparatorChar == '\\';
+                       }
+               }
+
+               bool Unix
+               {
+                       get {
+                               return Path.DirectorySeparatorChar == '/';
+                       }
+               }
+
+               bool Mac
+               {
+                       get {
+                               return Path.DirectorySeparatorChar == ':';
+                       }
+               }
 
                private void DeleteFile (string path)
                {
@@ -49,9 +71,11 @@ namespace MonoTests.System.IO
                [Test]
                public void CreationTimeFile ()
                {
-                       string path = TempFolder + "/FSIT.CreationTime.Test";
+                       string path = TempFolder + DSC + "FSIT.CreationTime.Test";
                        DeleteFile (path);
-
+                       if (Unix) {  // Unix doesn't support CreationTimes
+                         return;
+                       }
                        try {
                                File.Create (path).Close ();
                                FileSystemInfo info = new FileInfo (path);
@@ -99,8 +123,11 @@ namespace MonoTests.System.IO
                [Test]
                public void CreationTimeDirectory ()
                {
-                       string path = TempFolder + "/FSIT.CreationTimeDirectory.Test";
+                       string path = TempFolder + DSC + "FSIT.CreationTimeDirectory.Test";
                        DeleteDir (path);
+                       if (Unix) {  // Unix doesn't support CreationTimes
+                         return;
+                       }
                        
                        try {                           
                                FileSystemInfo info = Directory.CreateDirectory (path);
@@ -137,29 +164,29 @@ namespace MonoTests.System.IO
                [Test]
                public void CreationTimeNoFileOrDirectory ()
                {
-                       string path = TempFolder + "/FSIT.CreationTimeNoFile.Test";
+                       string path = TempFolder + DSC + "FSIT.CreationTimeNoFile.Test";
                        DeleteFile (path);
                        DeleteDir (path);
                        
                        try {
                                FileSystemInfo info = new FileInfo (path);
                                
-                               DateTime time = info.CreationTime;
+                               DateTime time = TimeZone.CurrentTimeZone.ToUniversalTime(info.CreationTime);
                                AssertEquals ("test#01", 1601, time.Year);
                                AssertEquals ("test#02", 1, time.Month);
                                AssertEquals ("test#03", 1, time.Day);
-                               AssertEquals ("test#04", 2, time.Hour);
+                               AssertEquals ("test#04", 0, time.Hour);
                                AssertEquals ("test#05", 0, time.Minute);
                                AssertEquals ("test#06", 0, time.Second);
                                AssertEquals ("test#07", 0, time.Millisecond);
                                
                                info = new DirectoryInfo (path);
                                
-                               time = info.CreationTime;
+                               time = TimeZone.CurrentTimeZone.ToUniversalTime(info.CreationTime);
                                AssertEquals ("test#08", 1601, time.Year);
                                AssertEquals ("test#09", 1, time.Month);
                                AssertEquals ("test#10", 1, time.Day);
-                               AssertEquals ("test#11", 2, time.Hour);
+                               AssertEquals ("test#11", 0, time.Hour);
                                AssertEquals ("test#12", 0, time.Minute);
                                AssertEquals ("test#13", 0, time.Second);
                                AssertEquals ("test#14", 0, time.Millisecond);
@@ -172,7 +199,7 @@ namespace MonoTests.System.IO
                [Test]
                public void Extenssion ()
                {
-                       string path = TempFolder + "/FSIT.Extenssion.Test";
+                       string path = TempFolder + DSC + "FSIT.Extenssion.Test";
                        DeleteFile (path);
                        
                        try {
@@ -186,18 +213,18 @@ namespace MonoTests.System.IO
                [Test]
                public void DefaultLastAccessTime ()
                {
-                       string path = TempFolder + "/FSIT.DefaultLastAccessTime.Test";
+                       string path = TempFolder + DSC + "FSIT.DefaultLastAccessTime.Test";
                        DeleteFile (path);
                        
                        try {
                                
                                FileSystemInfo info = new FileInfo (path);
-                               DateTime time = info.LastAccessTime;
+                               DateTime time = TimeZone.CurrentTimeZone.ToUniversalTime(info.LastAccessTime);
 
                                AssertEquals ("test#01", 1601, time.Year);
                                AssertEquals ("test#02", 1, time.Month);
                                AssertEquals ("test#03", 1, time.Day);
-                               AssertEquals ("test#04", 2, time.Hour);
+                               AssertEquals ("test#04", 0, time.Hour);
                                AssertEquals ("test#05", 0, time.Minute);
                                AssertEquals ("test#06", 0, time.Second);
                                AssertEquals ("test#07", 0, time.Millisecond);
@@ -209,7 +236,7 @@ namespace MonoTests.System.IO
                [Test]
                public void LastAccessTime ()
                {
-                       string path = TempFolder + "/FSIT.LastAccessTime.Test";
+                       string path = TempFolder + DSC + "FSIT.LastAccessTime.Test";
                        DeleteFile (path);
 
                        try {
@@ -252,18 +279,18 @@ namespace MonoTests.System.IO
                [Test]
                public void DefaultLastWriteTime ()
                {
-                       string path = TempFolder + "/FSIT.DefaultLastWriteTime.Test";
+                       string path = TempFolder + DSC + "FSIT.DefaultLastWriteTime.Test";
                        DeleteDir (path);
 
                        try {
 
                                FileSystemInfo info = new DirectoryInfo (path);
-                               DateTime time = info.LastAccessTime;
+                               DateTime time = TimeZone.CurrentTimeZone.ToUniversalTime(info.LastWriteTime);
                                
                                AssertEquals ("test#01", 1601, time.Year);
                                AssertEquals ("test#02", 1, time.Month);
                                AssertEquals ("test#03", 1, time.Day);
-                               AssertEquals ("test#04", 2, time.Hour);
+                               AssertEquals ("test#04", 0, time.Hour);
                                AssertEquals ("test#05", 0, time.Minute);
                                AssertEquals ("test#06", 0, time.Second);
                                AssertEquals ("test#07", 0, time.Millisecond);
@@ -275,7 +302,7 @@ namespace MonoTests.System.IO
                [Test]
                public void LastWriteTime ()
                {
-                       string path = TempFolder + "/FSIT.LastWriteTime.Test";
+                       string path = TempFolder + DSC + "FSIT.LastWriteTime.Test";
                        DeleteDir (path);
                        
                        try {
@@ -289,20 +316,20 @@ namespace MonoTests.System.IO
                                AssertEquals ("test#03", 1, time.Day);
                                AssertEquals ("test#04", 1, time.Hour);
                                
-                               time = TimeZone.CurrentTimeZone.ToLocalTime (info.LastWriteTimeUtc);
+                               time = info.LastWriteTimeUtc.ToLocalTime ();
                                AssertEquals ("test#05", 2000, time.Year);
                                AssertEquals ("test#06", 1, time.Month);
                                AssertEquals ("test#07", 1, time.Day);
                                AssertEquals ("test#08", 1, time.Hour);
-                               
+
                                info.LastWriteTimeUtc = new DateTime (2000, 1, 1, 1, 1, 1);
-                               time = TimeZone.CurrentTimeZone.ToUniversalTime (info.LastWriteTime);
+                               time = info.LastWriteTimeUtc;
                                AssertEquals ("test#09", 2000, time.Year);
                                AssertEquals ("test#10", 1, time.Month);
                                AssertEquals ("test#11", 1, time.Day);
                                AssertEquals ("test#12", 1, time.Hour);
 
-                               time = info.LastWriteTimeUtc;
+                               time = info.LastWriteTime.ToUniversalTime ();
                                AssertEquals ("test#13", 2000, time.Year);
                                AssertEquals ("test#14", 1, time.Month);
                                AssertEquals ("test#15", 1, time.Day);