Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Hays <ianha@microsoft.com>2017-03-30 00:04:55 +0300
committerGitHub <noreply@github.com>2017-03-30 00:04:55 +0300
commitc1342249c245e5baea0c3ca12dbaebea58a0ba52 (patch)
tree6f2ec4288bbd4c383c5f26dea505fceb6c284719
parent8d9afda9f3d9400a34fa165cb67551ec6fe4577b (diff)
parent5baf19041063f6c8bd4adcde67c04e7f7dd31271 (diff)
Merge pull request #17625 from ianhays/MMF_Unauthorized
Fix some MMF tests to work on netfx
-rw-r--r--src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs b/src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs
index 78695a19fb..2c63bcbe7d 100644
--- a/src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs
+++ b/src/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs
@@ -640,6 +640,7 @@ namespace System.IO.MemoryMappedFiles.Tests
[Theory]
[InlineData(MemoryMappedFileAccess.ReadExecute)]
[InlineData(MemoryMappedFileAccess.ReadWriteExecute)]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "CreateFromFile in desktop uses FileStream's ctor that takes a FileSystemRights in order to specify execute privileges.")]
public void FileNotOpenedForExecute(MemoryMappedFileAccess access)
{
using (TempFile file = new TempFile(GetTestFilePath(), 4096))
@@ -660,11 +661,7 @@ namespace System.IO.MemoryMappedFiles.Tests
/// If the test is being run under the superuser, however, modification of a ReadOnly
/// file is allowed.
/// </summary>
- [Theory]
- [InlineData(MemoryMappedFileAccess.Read)]
- [InlineData(MemoryMappedFileAccess.ReadWrite)]
- [InlineData(MemoryMappedFileAccess.CopyOnWrite)]
- public void WriteToReadOnlyFile(MemoryMappedFileAccess access)
+ public void WriteToReadOnlyFile(MemoryMappedFileAccess access, bool succeeds)
{
const int Capacity = 4096;
using (TempFile file = new TempFile(GetTestFilePath(), Capacity))
@@ -673,7 +670,7 @@ namespace System.IO.MemoryMappedFiles.Tests
File.SetAttributes(file.Path, FileAttributes.ReadOnly);
try
{
- if (access == MemoryMappedFileAccess.Read || (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0))
+ if (succeeds)
using (MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, null, Capacity, access))
ValidateMemoryMappedFile(mmf, Capacity, MemoryMappedFileAccess.Read);
else
@@ -684,7 +681,29 @@ namespace System.IO.MemoryMappedFiles.Tests
File.SetAttributes(file.Path, original);
}
}
+ }
+
+ [Theory]
+ [InlineData(MemoryMappedFileAccess.Read)]
+ [InlineData(MemoryMappedFileAccess.ReadWrite)]
+ public void WriteToReadOnlyFile_ReadWrite(MemoryMappedFileAccess access)
+ {
+ WriteToReadOnlyFile(access, access == MemoryMappedFileAccess.Read ||
+ (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0));
+ }
+
+ [Fact]
+ [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "CreateFromFile in desktop uses FileStream's ctor that takes a FileSystemRights in order to specify execute privileges.")]
+ public void WriteToReadOnlyFile_CopyOnWrite()
+ {
+ WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && geteuid() == 0));
+ }
+ [Fact]
+ [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "CreateFromFile in desktop uses FileStream's ctor that takes a FileSystemRights in order to specify execute privileges.")]
+ public void WriteToReadOnlyFile_CopyOnWrite_netfx()
+ {
+ WriteToReadOnlyFile(MemoryMappedFileAccess.CopyOnWrite, succeeds: true);
}
[DllImport("libc", SetLastError = true)]