| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- // FileSystemInfoTest.cs - NUnit Test Cases for System.IO.FileSystemInfo class
- //
- // Ville Palo ([email protected])
- //
- // (C) 2003 Ville Palo
- //
- using NUnit.Framework;
- using System;
- using System.IO;
- using System.Globalization;
- using System.Threading;
- namespace MonoTests.System.IO
- {
- [TestFixture]
- public class FileSystemInfoTest : Assertion
- {
- string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
- static readonly char DSC = Path.DirectorySeparatorChar;
- [SetUp]
- protected void SetUp()
- {
- if (Directory.Exists (TempFolder))
- Directory.Delete (TempFolder, true);
- Directory.CreateDirectory (TempFolder);
- Thread.CurrentThread.CurrentCulture = new CultureInfo ("EN-us");
- }
- [TearDown]
- protected void TearDown() {
- 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)
- {
- if (File.Exists (path))
- File.Delete (path);
- }
- private void DeleteDir (string path)
- {
- if (Directory.Exists (path))
- Directory.Delete (path, true);
- }
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void CreationTimeFile ()
- {
- 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);
- info.CreationTime = new DateTime (1999, 12, 31, 11, 59, 59);
- DateTime time = info.CreationTime;
- AssertEquals ("test#01", 1999, time.Year);
- AssertEquals ("test#02", 12, time.Month);
- AssertEquals ("test#03", 31, time.Day);
- AssertEquals ("test#04", 11, time.Hour);
- AssertEquals ("test#05", 59, time.Minute);
- AssertEquals ("test#06", 59, time.Second);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (info.CreationTimeUtc);
- AssertEquals ("test#07", 1999, time.Year);
- AssertEquals ("test#08", 12, time.Month);
- AssertEquals ("test#09", 31, time.Day);
- AssertEquals ("test#10", 11, time.Hour);
- AssertEquals ("test#11", 59, time.Minute);
- AssertEquals ("test#12", 59, time.Second);
-
- info.CreationTimeUtc = new DateTime (1999, 12, 31, 11, 59, 59);
- time = TimeZone.CurrentTimeZone.ToUniversalTime (info.CreationTime);
- AssertEquals ("test#13", 1999, time.Year);
- AssertEquals ("test#14", 12, time.Month);
- AssertEquals ("test#15", 31, time.Day);
- AssertEquals ("test#16", 11, time.Hour);
- AssertEquals ("test#17", 59, time.Minute);
- AssertEquals ("test#18", 59, time.Second);
- time = info.CreationTimeUtc;
- AssertEquals ("test#19", 1999, time.Year);
- AssertEquals ("test#20", 12, time.Month);
- AssertEquals ("test#21", 31, time.Day);
- AssertEquals ("test#22", 11, time.Hour);
- AssertEquals ("test#23", 59, time.Minute);
- AssertEquals ("test#24", 59, time.Second);
- } finally {
- DeleteFile (path);
- }
- }
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void CreationTimeDirectory ()
- {
- string path = TempFolder + DSC + "FSIT.CreationTimeDirectory.Test";
- DeleteDir (path);
- if (Unix) { // Unix doesn't support CreationTimes
- return;
- }
-
- try {
- FileSystemInfo info = Directory.CreateDirectory (path);
- info.CreationTime = new DateTime (1999, 12, 31, 11, 59, 59);
- DateTime time = info.CreationTime;
-
- AssertEquals ("test#01", 1999, time.Year);
- AssertEquals ("test#02", 12, time.Month);
- AssertEquals ("test#03", 31, time.Day);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (info.CreationTimeUtc);
- AssertEquals ("test#07", 1999, time.Year);
- AssertEquals ("test#08", 12, time.Month);
- AssertEquals ("test#09", 31, time.Day);
- AssertEquals ("test#10", 11, time.Hour);
-
- info.CreationTimeUtc = new DateTime (1999, 12, 31, 11, 59, 59);
-
- time = TimeZone.CurrentTimeZone.ToUniversalTime (info.CreationTime);
- AssertEquals ("test#13", 1999, time.Year);
- AssertEquals ("test#14", 12, time.Month);
- AssertEquals ("test#15", 31, time.Day);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (info.CreationTimeUtc);
- AssertEquals ("test#19", 1999, time.Year);
- AssertEquals ("test#20", 12, time.Month);
- AssertEquals ("test#21", 31, time.Day);
-
- } finally {
- DeleteDir (path);
- }
- }
-
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void CreationTimeNoFileOrDirectory ()
- {
- string path = TempFolder + DSC + "FSIT.CreationTimeNoFile.Test";
- DeleteFile (path);
- DeleteDir (path);
-
- try {
- FileSystemInfo info = new FileInfo (path);
-
- 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", 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 = 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", 0, time.Hour);
- AssertEquals ("test#12", 0, time.Minute);
- AssertEquals ("test#13", 0, time.Second);
- AssertEquals ("test#14", 0, time.Millisecond);
- } finally {
- DeleteFile (path);
- DeleteDir (path);
- }
- }
-
- [Test]
- public void Extenssion ()
- {
- string path = TempFolder + DSC + "FSIT.Extenssion.Test";
- DeleteFile (path);
-
- try {
- FileSystemInfo info = new FileInfo (path);
- AssertEquals ("test#01", ".Test", info.Extension);
- } finally {
- DeleteFile (path);
- }
- }
-
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void DefaultLastAccessTime ()
- {
- string path = TempFolder + DSC + "FSIT.DefaultLastAccessTime.Test";
- DeleteFile (path);
-
- try {
-
- FileSystemInfo info = new FileInfo (path);
- 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", 0, time.Hour);
- AssertEquals ("test#05", 0, time.Minute);
- AssertEquals ("test#06", 0, time.Second);
- AssertEquals ("test#07", 0, time.Millisecond);
- } finally {
- DeleteFile (path);
- }
- }
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void LastAccessTime ()
- {
- string path = TempFolder + DSC + "FSIT.LastAccessTime.Test";
- DeleteFile (path);
- try {
- File.Create (path).Close ();
- FileSystemInfo info = new FileInfo (path);
- DateTime time;
- info = new FileInfo (path);
-
- info.LastAccessTime = new DateTime (2000, 1, 1, 1, 1, 1);
- time = info.LastAccessTime;
- AssertEquals ("test#01", 2000, time.Year);
- AssertEquals ("test#02", 1, time.Month);
- AssertEquals ("test#03", 1, time.Day);
- AssertEquals ("test#04", 1, time.Hour);
-
- time = TimeZone.CurrentTimeZone.ToLocalTime (info.LastAccessTimeUtc);
- 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.LastAccessTimeUtc = new DateTime (2000, 1, 1, 1, 1, 1);
- time = TimeZone.CurrentTimeZone.ToUniversalTime (info.LastAccessTime);
- 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.LastAccessTimeUtc;
- AssertEquals ("test#13", 2000, time.Year);
- AssertEquals ("test#14", 1, time.Month);
- AssertEquals ("test#15", 1, time.Day);
- AssertEquals ("test#16", 1, time.Hour);
-
- } finally {
- DeleteFile (path);
- }
- }
-
- [Test]
- #if TARGET_JVM
- [Category("NotWorking")]
- #endif
- public void DefaultLastWriteTime ()
- {
- string path = TempFolder + DSC + "FSIT.DefaultLastWriteTime.Test";
- DeleteDir (path);
- try {
- FileSystemInfo info = new DirectoryInfo (path);
- 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", 0, time.Hour);
- AssertEquals ("test#05", 0, time.Minute);
- AssertEquals ("test#06", 0, time.Second);
- AssertEquals ("test#07", 0, time.Millisecond);
- } finally {
- DeleteDir (path);
- }
- }
-
- [Test]
- public void LastWriteTime ()
- {
- string path = TempFolder + DSC + "FSIT.LastWriteTime.Test";
- DeleteDir (path);
-
- try {
- FileSystemInfo info = Directory.CreateDirectory (path);
-
- info.LastWriteTime = new DateTime (2000, 1, 1, 1, 1, 1);
- DateTime time = info.LastWriteTime;
-
- AssertEquals ("test#01", 2000, time.Year);
- AssertEquals ("test#02", 1, time.Month);
- AssertEquals ("test#03", 1, time.Day);
- AssertEquals ("test#04", 1, time.Hour);
-
- 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 = 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.LastWriteTime.ToUniversalTime ();
- AssertEquals ("test#13", 2000, time.Year);
- AssertEquals ("test#14", 1, time.Month);
- AssertEquals ("test#15", 1, time.Day);
- AssertEquals ("test#16", 1, time.Hour);
- } finally {
- DeleteDir (path);
- }
- }
- }
- }
|