diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2014-01-09 05:46:14 +0400 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2014-01-09 05:47:01 +0400 |
commit | 4b0111dac91f63701175e4f6e09ebc9fd5aa4106 (patch) | |
tree | 5c703a827103de2de2d694f93ddd7ecc92f1b40d /mcs/class | |
parent | e66015a55e7d83d0077a482d13631d20a2bdd03d (diff) |
[corlib] Add an exhaustive regression test for file sharing and File.Move.
Diffstat (limited to 'mcs/class')
-rw-r--r-- | mcs/class/corlib/Test/System.IO/FileTest.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/mcs/class/corlib/Test/System.IO/FileTest.cs b/mcs/class/corlib/Test/System.IO/FileTest.cs index 6267439aed2..112978ae8b7 100644 --- a/mcs/class/corlib/Test/System.IO/FileTest.cs +++ b/mcs/class/corlib/Test/System.IO/FileTest.cs @@ -2760,5 +2760,53 @@ namespace MonoTests.System.IO } } #endif + + void MoveTest (FileAccess acc, FileShare share, bool works) + { + var file = "kk597rfdnllh89"; + + File.Delete (file + ".old"); + using (var v = File.Create (file)) { } + + using (var stream = new FileStream(file, FileMode.Open, acc, share, 4096, FileOptions.SequentialScan)) { + try { + File.Move(file, file + ".old"); + if (!works) + Assert.Fail ("Move with ({0}) and ({1}) did not fail", acc, share); + } catch (IOException) { + if (works) + Assert.Fail ("Move with ({0}) and ({1}) did fail", acc, share); + } + } + } + + [Test] + public void MoveTest () + { + MoveTest (FileAccess.Read, FileShare.None, false); + MoveTest (FileAccess.Read, FileShare.Read, false); + MoveTest (FileAccess.Read, FileShare.Write, false); + MoveTest (FileAccess.Read, FileShare.ReadWrite, false); + MoveTest (FileAccess.Read, FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.None, false); + MoveTest (FileAccess.Write, FileShare.Read, false); + MoveTest (FileAccess.Write, FileShare.Write, false); + MoveTest (FileAccess.Write, FileShare.ReadWrite, false); + MoveTest (FileAccess.Write, FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.Write, FileShare.ReadWrite | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.None, false); + MoveTest (FileAccess.ReadWrite, FileShare.Read, false); + MoveTest (FileAccess.ReadWrite, FileShare.Write, false); + MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite, false); + MoveTest (FileAccess.ReadWrite, FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.Read | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true); + MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true); + } } } |