using System.IO;
using System.Globalization;
using System.Threading;
+using System.Runtime.InteropServices;
+
using NUnit.Framework;
}
}
+ [Test]
+ public void Delete_NonExisting_NoException ()
+ {
+ File.Delete (Path.Combine (Directory.GetDirectoryRoot (Directory.GetCurrentDirectory ()), "monononexistingfile.dat"));
+ }
+
[Test]
public void GetAttributes_Archive ()
{
Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
Assert.IsFalse (ex.Message.IndexOf (destFile) != -1, "#5");
-#else
- Assert.IsTrue (ex.Message.IndexOf (destFile) != -1, "#5");
-#endif
}
} finally {
DeleteFile (sourceFile);
string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetCreationTime (path);
DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
Assert.AreEqual (expectedTime.Year, time.Year, "#1");
Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
Assert.AreEqual (expectedTime.Second, time.Second, "#5");
Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
- try {
- File.GetCreationTime (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetCreationTimeUtc (path);
Assert.AreEqual (1601, time.Year, "#1");
Assert.AreEqual (1, time.Month, "#2");
Assert.AreEqual (0, time.Hour, "#4");
Assert.AreEqual (0, time.Second, "#5");
Assert.AreEqual (0, time.Millisecond, "#6");
-#else
- try {
- File.GetCreationTimeUtc (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetLastAccessTime (path);
DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
Assert.AreEqual (expectedTime.Year, time.Year, "#1");
Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
Assert.AreEqual (expectedTime.Second, time.Second, "#5");
Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
- try {
- File.GetLastAccessTime (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetLastAccessTimeUtc (path);
Assert.AreEqual (1601, time.Year, "#1");
Assert.AreEqual (1, time.Month, "#2");
Assert.AreEqual (0, time.Hour, "#4");
Assert.AreEqual (0, time.Second, "#5");
Assert.AreEqual (0, time.Millisecond, "#6");
-#else
- try {
- File.GetLastAccessTimeUtc (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetLastWriteTime (path);
DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
Assert.AreEqual (expectedTime.Year, time.Year, "#1");
Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
Assert.AreEqual (expectedTime.Second, time.Second, "#5");
Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
- try {
- File.GetLastWriteTime (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
DeleteFile (path);
-#if NET_2_0
DateTime time = File.GetLastWriteTimeUtc (path);
Assert.AreEqual (1601, time.Year, "#1");
Assert.AreEqual (1, time.Month, "#2");
Assert.AreEqual (0, time.Hour, "#4");
Assert.AreEqual (0, time.Second, "#5");
Assert.AreEqual (0, time.Millisecond, "#6");
-#else
- try {
- File.GetLastWriteTimeUtc (path);
- Assert.Fail ("#1");
- } catch (IOException ex) {
- // Could not find a part of the path "..."
- Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
- Assert.IsNull (ex.InnerException, "#3");
- Assert.IsNotNull (ex.Message, "#4");
- Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
- }
-#endif
}
[Test]
}
[Test]
+ [Category ("LargeFileSupport")]
public void Position_Large ()
{
// fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
}
[Test]
+ [Category ("LargeFileSupport")]
public void Seek_Large ()
{
// fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
}
[Test]
+ [Category ("LargeFileSupport")]
public void Lock_Large ()
{
// note: already worked without HAVE_LARGE_FILE_SUPPORT
LockUnlock ((long) Int32.MaxValue + 1);
}
-#if NET_2_0
[Test]
public void ReadWriteAllText ()
{
Assert.AreEqual ("replaceFile", txt, "#3");
}
}
-#endif
static bool RunningOnUnix {
get {
Directory.Delete (path, true);
}
-#if NET_2_0
void read_all (string s)
{
string f = Path.GetTempFileName ();
DeleteFile (f);
}
}
-#endif
void MoveTest (FileAccess acc, FileShare share, bool works)
{
MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
}
+
+
+ [DllImport ("libc", SetLastError=true)]
+ public static extern int symlink (string oldpath, string newpath);
+
+ [Test]
+ public void SymLinkLoop ()
+ {
+ if (!RunningOnUnix)
+ Assert.Ignore ("Symlink are hard on windows");
+
+ var name1 = Path.GetRandomFileName ();
+ var name2 = Path.GetRandomFileName ();
+
+ var path1 = Path.Combine (Path.GetTempPath (), name1);
+ var path2 = Path.Combine (Path.GetTempPath (), name2);
+
+ File.Delete (path1);
+ File.Delete (path2);
+
+ try {
+ if (symlink (path1, path2) != 0)
+ Assert.Fail ("symlink #1 failed with errno={0}", Marshal.GetLastWin32Error ());
+ if (symlink (path2, path1) != 0)
+ Assert.Fail ("symlink #2 failed with errno={0}", Marshal.GetLastWin32Error ());
+
+ Assert.IsTrue (File.Exists (path1), "File.Exists must return true for path1 symlink loop");
+ Assert.IsTrue (File.Exists (path2), "File.Exists must return true for path2 symlink loop");
+
+ try {
+ using (var f = File.Open (path1, FileMode.Open, FileAccess.Read)) {
+ Assert.Fail ("File.Open must throw for symlink loops");
+ }
+ } catch (IOException ex) {
+ Assert.AreEqual (0x80070781u, (uint)ex.HResult, "Ensure HRESULT is correct");
+ }
+
+ File.Delete (path1); //Delete must not throw and must work
+ Assert.IsFalse (File.Exists (path1), "File.Delete must delete symlink loops");
+
+ } finally {
+ try {
+ File.Delete (path1);
+ File.Delete (path2);
+ } catch (IOException) {
+ //Don't double fault any exception from the tests.
+ }
+
+ }
+ }
}
}