Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Security;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;

namespace System.Diagnostics.Tests
Expand Down Expand Up @@ -73,45 +72,32 @@ void Cleanup(string username, string _)

[ConditionalTheory(typeof(ProcessStartInfoTests), nameof(IsAdmin_IsNotNano_RemoteExecutorIsSupported))]
[PlatformSpecific(TestPlatforms.Windows)]
[InlineData(ProcessWindowStyle.Normal, true)]
[InlineData(ProcessWindowStyle.Normal, false)]
[InlineData(ProcessWindowStyle.Hidden, true)]
[InlineData(ProcessWindowStyle.Hidden, false)]
[InlineData(ProcessWindowStyle.Minimized, true)]
[InlineData(ProcessWindowStyle.Minimized, false)]
[InlineData(ProcessWindowStyle.Maximized, true)]
[InlineData(ProcessWindowStyle.Maximized, false)]
public void TestWindowStyle(ProcessWindowStyle windowStyle, bool useShellExecute)
[InlineData(ProcessWindowStyle.Normal)]
[InlineData(ProcessWindowStyle.Hidden)]
[InlineData(ProcessWindowStyle.Minimized)]
[InlineData(ProcessWindowStyle.Maximized)]
public void TestWindowStyle(ProcessWindowStyle windowStyle)
{
if (useShellExecute && PlatformDetection.IsMonoRuntime)
(bool expectUsesShowWindow, int expectedWindowFlag) = windowStyle switch
{
// https://github.com/dotnet/runtime/issues/34360
throw new SkipTestException("ShellExecute tries to set STA COM apartment state which is not implemented by Mono.");
}

// "x y" where x is the expected dwFlags & 0x1 result and y is the wShowWindow value
(int expectedDwFlag, int expectedWindowFlag) = windowStyle switch
{
ProcessWindowStyle.Hidden => (1, 0),
ProcessWindowStyle.Minimized => (1, 2),
ProcessWindowStyle.Maximized => (1, 3),
// UseShellExecute always sets the flag but no shell does not for Normal.
_ => useShellExecute ? (1, 1) : (0, 0),
ProcessWindowStyle.Hidden => (true, 0), // SW_HIDE is 0
ProcessWindowStyle.Minimized => (true, 2), // SW_SHOWMINIMIZED is 2
ProcessWindowStyle.Maximized => (true, 3), // SW_SHOWMAXIMIZED is 3
_ => (false, 0),
};

using Process p = CreateProcess((string procArg) =>
{
Interop.GetStartupInfoW(out Interop.STARTUPINFO si);

string[] argSplit = procArg.Split(" ");
int expectedDwFlag = int.Parse(argSplit[0]);
bool expectUsesShowWindow = bool.Parse(argSplit[0]);
short expectedWindowFlag = short.Parse(argSplit[1]);

Assert.Equal(expectedDwFlag, si.dwFlags);
Assert.Equal(expectUsesShowWindow, (si.dwFlags & 0x1) != 0); // STARTF_USESHOWWINDOW is 0x1
Assert.Equal(expectedWindowFlag, si.wShowWindow);
return RemoteExecutor.SuccessExitCode;
}, $"{expectedDwFlag} {expectedWindowFlag}");
p.StartInfo.UseShellExecute = useShellExecute;
}, $"{expectUsesShowWindow} {expectedWindowFlag}");
p.StartInfo.WindowStyle = windowStyle;
p.Start();

Expand Down
Loading