未验证 提交 8b391f60 编写于 作者: A Adam Sitnik 提交者: GitHub

implement test for Long Paths support in ProcessModule.FileName (#46685)

上级 a78e7e46
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{3742D5F8-5C86-49FD-BAEA-050742CCEB7A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LongPath", "tests\LongPath\LongPath.csproj", "{C67553AE-F09B-407D-AD3E-D61950E06BE8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj", "{AA583AE2-BE26-4AA4-845F-916133916B7D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Win32.Registry", "..\Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj", "{E5AE4EB3-DB23-4F33-858B-63B68A60F7F1}"
......@@ -50,6 +52,7 @@ EndProject
Global
GlobalSection(NestedProjects) = preSolution
{3742D5F8-5C86-49FD-BAEA-050742CCEB7A} = {05C87914-711A-4589-9672-8169DB6A6BA4}
{C67553AE-F09B-407D-AD3E-D61950E06BE8} = {05C87914-711A-4589-9672-8169DB6A6BA4}
{ABA61FEF-EB06-441D-9D3D-F25FFC7CD83D} = {05C87914-711A-4589-9672-8169DB6A6BA4}
{AA583AE2-BE26-4AA4-845F-916133916B7D} = {9ABDFB23-5430-4410-81C3-3C0327996580}
{4792FFA1-1AD2-4230-8DE3-D2BCF1CF804F} = {9ABDFB23-5430-4410-81C3-3C0327996580}
......@@ -160,6 +163,10 @@ Global
{9C521ED1-5221-4C93-BBA0-86C13D4C23C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C521ED1-5221-4C93-BBA0-86C13D4C23C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C521ED1-5221-4C93-BBA0-86C13D4C23C7}.Release|Any CPU.Build.0 = Release|Any CPU
{C67553AE-F09B-407D-AD3E-D61950E06BE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C67553AE-F09B-407D-AD3E-D61950E06BE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C67553AE-F09B-407D-AD3E-D61950E06BE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C67553AE-F09B-407D-AD3E-D61950E06BE8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System
{
// this type is not used anywhere, but it exists so the containing `.dll` is not empty and
// can be copied to the output folder and be dynamically loaded during test execution
public class ClassDefinedInAssemblyWithAVeryLongPath
{
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="ClassDefinedInAssemblyWithAVeryLongPath.cs" />
</ItemGroup>
</Project>
// 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;
using System.Linq;
using System.Reflection;
using Microsoft.DotNet.RemoteExecutor;
using Xunit;
......@@ -89,5 +91,33 @@ public void ModulesAreDisposedWhenProcessIsDisposed()
process.Dispose();
Assert.Equal(expectedCount, disposedCount);
}
[ActiveIssue("https://github.com/dotnet/runtime/pull/335059")]
[ConditionalFact(typeof(PathFeatures), nameof(PathFeatures.AreAllLongPathsAvailable))]
[PlatformSpecific(TestPlatforms.Windows)]
public void LongModuleFileNamesAreSupported()
{
// To be able to test Long Path support for ProcessModule.FileName we need a .dll that has a path >= 260 chars.
// Since Long Paths support can be disabled (see the ConditionalFact attribute usage above),
// we just copy "LongName.dll" from bin to a temp directory with a long name and load it from there.
// Loading from new path is possible because the type exposed by the assembly is not referenced in any explicit way.
const string libraryName = "LongPath.dll";
string testBinPath = Path.GetDirectoryName(typeof(ProcessModuleTests).Assembly.Location);
string libraryToCopy = Path.Combine(testBinPath, libraryName);
Assert.True(File.Exists(libraryToCopy), $"{libraryName} was not present in bin folder '{testBinPath}'");
string directoryWithLongName = Path.Combine(TestDirectory, new string('a', Math.Max(1, 261 - TestDirectory.Length)));
Directory.CreateDirectory(directoryWithLongName);
string longNamePath = Path.Combine(directoryWithLongName, libraryName);
Assert.True(longNamePath.Length > 260);
File.Copy(libraryToCopy, longNamePath);
Assembly loaded = Assembly.LoadFile(longNamePath);
Assert.Contains(Process.GetCurrentProcess().Modules.Cast<ProcessModule>(), module => module.FileName == longNamePath);
}
}
}
......@@ -17,6 +17,8 @@
Link="Common\Microsoft\Win32\TempRegistryKey.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs"
Link="Common\System\IO\PathFeatures.cs" />
<Compile Include="DelegateSynchronizeInvoke.cs" />
<Compile Include="FileAssociations.cs" />
<Compile Include="Helpers.cs" />
......@@ -50,5 +52,6 @@
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.DirectoryServices\src\System.DirectoryServices.csproj" />
<ProjectReference Include="LongPath\LongPath.csproj" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册