-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathctor_options.Windows.cs
More file actions
59 lines (46 loc) · 2.25 KB
/
Copy pathctor_options.Windows.cs
File metadata and controls
59 lines (46 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.IO.Pipes;
using System.Threading.Tasks;
using Xunit;
namespace System.IO.Tests
{
public partial class FileStream_ctor_options
{
private unsafe long GetAllocatedSize(FileStream fileStream)
{
Interop.Kernel32.FILE_STANDARD_INFO info;
Assert.True(Interop.Kernel32.GetFileInformationByHandleEx(fileStream.SafeFileHandle, Interop.Kernel32.FileStandardInfo, &info, (uint)sizeof(Interop.Kernel32.FILE_STANDARD_INFO)));
return info.AllocationSize;
}
private static bool SupportsPreallocation => true;
private static bool IsGetAllocatedSizeImplemented => true;
[Theory]
[InlineData(@"\\?\")]
[InlineData(@"\??\")]
[InlineData("")]
public void ExtendedPathsAreSupported(string prefix)
{
const long preallocationSize = 123;
string filePath = prefix + Path.GetFullPath(GetTestFilePath());
using (var fs = CreateFileStream(filePath, FileMode.CreateNew, FileAccess.Write, FileShare.None, bufferSize: 4096, FileOptions.None, preallocationSize))
{
Assert.Equal(0, fs.Length);
Assert.True(GetAllocatedSize(fs) >= preallocationSize);
}
}
[ConditionalTheory(typeof(FileSystemTest), nameof(FileSystemTest.IsTempPathOnFat32))]
[InlineData(FileMode.Create)]
[InlineData(FileMode.CreateNew)]
public void WhenFileIsTooLargeTheErrorMessageContainsAllDetails(FileMode mode)
{
const long tooMuch = uint.MaxValue + 1L; // more than FAT32 max size
string filePath = GetTestFilePath();
Assert.StartsWith(Path.GetTempPath(), filePath); // this is what IsFat32 method relies on
IOException ex = Assert.Throws<IOException>(() => CreateFileStream(filePath, mode, FileAccess.Write, FileShare.None, bufferSize: 4096, FileOptions.None, tooMuch));
Assert.Contains(filePath, ex.Message);
Assert.Contains(tooMuch.ToString(), ex.Message);
Assert.False(File.Exists(filePath)); // ensure it was NOT created
}
}
}