diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ParkingWindowTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ParkingWindowTests.cs index 693c51d360e..7688e3242cd 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ParkingWindowTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/Application.ParkingWindowTests.cs @@ -1,17 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Microsoft.DotNet.RemoteExecutor; using static System.Windows.Forms.Application; namespace System.Windows.Forms.Tests; public class ParkingWindowTests { - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public void ParkingWindow_DoesNotThrowOnGarbageCollecting() { - using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() => + Task.Run(() => { Control.CheckForIllegalCrossThreadCalls = true; @@ -28,10 +27,7 @@ public void ParkingWindow_DoesNotThrowOnGarbageCollecting() { Assert.True(ex is null, $"Expected no exception, but got: {ex.Message}"); // Actually need to check whether GC.Collect() does not throw exception. } - }); - - // verify the remote process succeeded - Assert.Equal(RemoteExecutor.SuccessExitCode, invokerHandle.ExitCode); + }).Wait(); } private Form InitFormWithControlToGarbageCollect() diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs index 63d88c318f6..206a8c47b83 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ApplicationTests.cs @@ -72,32 +72,36 @@ public void Application_CurrentCulture_SetNull_ThrowsArgumentNullException() Assert.Throws("value", () => Application.CurrentCulture = null); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public void Application_EnableVisualStyles_InvokeBeforeGettingRenderWithVisualStyles_Success() { - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - Assert.True(Application.UseVisualStyles); - Assert.True(Application.RenderWithVisualStyles); - }).Dispose(); + try + { + Application.EnableVisualStyles(); + Assert.True(Application.UseVisualStyles); + Assert.True(Application.RenderWithVisualStyles); + } + finally + { + Application.VisualStyleState = VisualStyleState.NoneEnabled; + } + }).Wait(); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public void Application_EnableVisualStyles_InvokeAfterGettingRenderWithVisualStyles_Success() { // This is not a recommended scenario per // https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.enablevisualstyles // EnableVisualStyles should be executed before any control-related code is. - RemoteExecutor.Invoke(() => - { - Assert.False(Application.UseVisualStyles); - Assert.False(Application.RenderWithVisualStyles); + Assert.False(Application.UseVisualStyles); + Assert.False(Application.RenderWithVisualStyles); - Application.EnableVisualStyles(); - Assert.True(Application.UseVisualStyles, "New Visual Styles will not be applied on WinForms app. This is a high priority bug and must be looked into"); - Assert.True(Application.RenderWithVisualStyles); - }).Dispose(); + Application.EnableVisualStyles(); + Assert.True(Application.UseVisualStyles, "New Visual Styles will not be applied on WinForms app. This is a high priority bug and must be looked into"); + Assert.True(Application.RenderWithVisualStyles); } [WinFormsFact] @@ -115,27 +119,26 @@ public void Application_VisualStyleState_Get_ReturnsExpected() Assert.Equal(state, Application.VisualStyleState); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [EnumData] [InvalidEnumData] public void Application_VisualStyleState_Set_ReturnsExpected(VisualStyleState valueParam) { // This needs to be in RemoteExecutor.Invoke because changing Application.VisualStyleState // sends WM_THEMECHANGED to all controls, which can cause a deadlock if another test fails. - RemoteExecutor.Invoke((valueString) => + Task.Run(() => { - VisualStyleState value = Enum.Parse(valueString); VisualStyleState state = Application.VisualStyleState; try { - Application.VisualStyleState = value; - Assert.Equal(value, Application.VisualStyleState); + Application.VisualStyleState = valueParam; + Assert.Equal(valueParam, Application.VisualStyleState); } finally { Application.VisualStyleState = state; } - }, valueParam.ToString()); + }).Wait(); } [Fact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CommonDialogTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CommonDialogTests.cs index d1af4adeccb..dc47416c7c7 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CommonDialogTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/CommonDialogTests.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using System.Reflection; -using Microsoft.DotNet.RemoteExecutor; using Moq; namespace System.Windows.Forms.Tests; @@ -116,29 +115,32 @@ public void ShowDialog_NonControlOwner_ReturnsExpected(bool runDialogResult, Dia Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object)); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [InlineData(true, DialogResult.OK)] [InlineData(false, DialogResult.Cancel)] public void ShowDialog_NonControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam) { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) => + Task.Run(() => { - bool runDialogResult = bool.Parse(runDialogResultString); - DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString); - - Application.EnableVisualStyles(); - - using SubCommonDialog dialog = new() + try { - RunDialogResult = runDialogResult - }; - var owner = new Mock(MockBehavior.Strict); - owner - .Setup(o => o.Handle) - .Returns(IntPtr.Zero); - Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner.Object)); - }, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose(); + Application.EnableVisualStyles(); + + using SubCommonDialog dialog = new() + { + RunDialogResult = runDialogResultParam + }; + var owner = new Mock(MockBehavior.Strict); + owner + .Setup(o => o.Handle) + .Returns(IntPtr.Zero); + Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner.Object)); + } + finally + { + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsTheory] @@ -154,26 +156,29 @@ public void ShowDialog_ControlOwner_ReturnsExpected(bool runDialogResult, Dialog Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner)); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [InlineData(true, DialogResult.OK)] [InlineData(false, DialogResult.Cancel)] public void ShowDialog_ControlOwnerWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam) { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) => + Task.Run(() => { - bool runDialogResult = bool.Parse(runDialogResultString); - DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString); - - Application.EnableVisualStyles(); - - using SubCommonDialog dialog = new() + try { - RunDialogResult = runDialogResult - }; - using Control owner = new(); - Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner)); - }, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose(); + Application.EnableVisualStyles(); + + using SubCommonDialog dialog = new() + { + RunDialogResult = runDialogResultParam + }; + using Control owner = new(); + Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner)); + } + finally + { + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsTheory] @@ -190,27 +195,30 @@ public void ShowDialog_ControlOwnerWithHandle_ReturnsExpected(bool runDialogResu Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner)); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [InlineData(true, DialogResult.OK)] [InlineData(false, DialogResult.Cancel)] public void ShowDialog_ControlOwnerWithHandleWithVisualStyles_ReturnsExpected(bool runDialogResultParam, DialogResult expectedDialogResultParam) { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((runDialogResultString, expectedDialogResultString) => + Task.Run(() => { - bool runDialogResult = bool.Parse(runDialogResultString); - DialogResult expectedDialogResult = (DialogResult)Enum.Parse(typeof(DialogResult), expectedDialogResultString); - - Application.EnableVisualStyles(); - - using SubCommonDialog dialog = new() + try + { + Application.EnableVisualStyles(); + + using SubCommonDialog dialog = new() + { + RunDialogResult = runDialogResultParam + }; + using Control owner = new(); + Assert.NotEqual(IntPtr.Zero, owner.Handle); + Assert.Equal(expectedDialogResultParam, dialog.ShowDialog(owner)); + } + finally { - RunDialogResult = runDialogResult - }; - using Control owner = new(); - Assert.NotEqual(IntPtr.Zero, owner.Handle); - Assert.Equal(expectedDialogResult, dialog.ShowDialog(owner)); - }, runDialogResultParam.ToString(), expectedDialogResultParam.ToString()).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewHeaderCellTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewHeaderCellTests.cs index 30ede7d2dcc..b5e820058c9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewHeaderCellTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewHeaderCellTests.cs @@ -4012,35 +4012,37 @@ public static IEnumerable MouseLeaveUnsharesRow_WithDataGridViewMouseD yield return new object[] { false, 1, ButtonState.Normal }; } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [MemberData(nameof(MouseLeaveUnsharesRow_WithDataGridViewMouseDown_TestData))] public void DataGridViewHeaderCell_MouseLeaveUnsharesRow_InvokeWithDataGridViewMouseDown_ReturnsExpected(bool enableHeadersVisualStylesParam, int rowIndexParam, ButtonState expectedButtonStateParam) { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((enableHeadersVisualStylesString, rowIndexString, expectedButtonStateString) => + Task.Run(() => { - bool enableHeadersVisualStyles = bool.Parse(enableHeadersVisualStylesString); - int rowIndex = int.Parse(rowIndexString); - ButtonState expectedButtonState = (ButtonState)Enum.Parse(typeof(ButtonState), expectedButtonStateString); - - Application.EnableVisualStyles(); - - using SubDataGridViewHeaderCell cellTemplate = new(); - using DataGridViewColumn column = new() + try { - CellTemplate = cellTemplate - }; - using DataGridView control = new() + Application.EnableVisualStyles(); + + using SubDataGridViewHeaderCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new() + { + EnableHeadersVisualStyles = enableHeadersVisualStylesParam + }; + control.Columns.Add(column); + SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; + cell.OnMouseDown(new DataGridViewCellMouseEventArgs(-1, -1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0))); + Assert.Equal(enableHeadersVisualStylesParam && VisualStyleRenderer.IsSupported, cell.MouseLeaveUnsharesRow(rowIndexParam)); + Assert.Equal(expectedButtonStateParam, cell.ButtonState); + Assert.False(control.IsHandleCreated); + } + finally { - EnableHeadersVisualStyles = enableHeadersVisualStyles - }; - control.Columns.Add(column); - SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; - cell.OnMouseDown(new DataGridViewCellMouseEventArgs(-1, -1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0))); - Assert.Equal(enableHeadersVisualStyles && VisualStyleRenderer.IsSupported, cell.MouseLeaveUnsharesRow(rowIndex)); - Assert.Equal(expectedButtonState, cell.ButtonState); - Assert.False(control.IsHandleCreated); - }, enableHeadersVisualStylesParam.ToString(), rowIndexParam.ToString(), expectedButtonStateParam.ToString()).Dispose(); + Application.VisualStyleState = VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsTheory] @@ -4191,29 +4193,36 @@ public void DataGridViewHeaderCell_OnMouseDown_InvokeWithDataGridView_Nop() }).Dispose(); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public void DataGridViewHeaderCell_OnMouseDown_InvalidRowIndexVisualStyles_ThrowsArgumentOutOfRangeException() { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - - using SubDataGridViewHeaderCell cellTemplate = new(); - using DataGridViewColumn column = new() + try { - CellTemplate = cellTemplate - }; - using DataGridView control = new() + Application.EnableVisualStyles(); + + using SubDataGridViewHeaderCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new() + { + EnableHeadersVisualStyles = true + }; + control.Columns.Add(column); + SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; + DataGridViewCellMouseEventArgs e = new(0, 1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); + Assert.Throws("rowIndex", () => cell.OnMouseDown(e)); + Assert.Equal(VisualStyleRenderer.IsSupported ? ButtonState.Pushed : ButtonState.Normal, cell.ButtonState); + } + finally { - EnableHeadersVisualStyles = true - }; - control.Columns.Add(column); - SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; - DataGridViewCellMouseEventArgs e = new(0, 1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); - Assert.Throws("rowIndex", () => cell.OnMouseDown(e)); - Assert.Equal(VisualStyleRenderer.IsSupported ? ButtonState.Pushed : ButtonState.Normal, cell.ButtonState); - }).Dispose(); + Application.VisualStyleState = VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] @@ -4574,29 +4583,36 @@ public void DataGridViewHeaderCell_OnMouseUp_InvokeWithDataGridViewMouseDown_Ret }).Dispose(); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public void DataGridViewHeaderCell_OnMouseUp_InvalidRowIndexVisualStyles_ThrowsArgumentOutOfRangeException() { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - - using SubDataGridViewHeaderCell cellTemplate = new(); - using DataGridViewColumn column = new() + try { - CellTemplate = cellTemplate - }; - using DataGridView control = new() + Application.EnableVisualStyles(); + + using SubDataGridViewHeaderCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new() + { + EnableHeadersVisualStyles = true + }; + control.Columns.Add(column); + SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; + DataGridViewCellMouseEventArgs e = new(0, 1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); + Assert.Throws("rowIndex", () => cell.OnMouseUp(e)); + Assert.Equal(ButtonState.Normal, cell.ButtonState); + } + finally { - EnableHeadersVisualStyles = true - }; - control.Columns.Add(column); - SubDataGridViewHeaderCell cell = (SubDataGridViewHeaderCell)control.Rows[0].Cells[0]; - DataGridViewCellMouseEventArgs e = new(0, 1, 0, 0, new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0)); - Assert.Throws("rowIndex", () => cell.OnMouseUp(e)); - Assert.Equal(ButtonState.Normal, cell.ButtonState); - }).Dispose(); + Application.VisualStyleState = VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs index 84a87cd4c29..1647504f768 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewInsertionMarkTests.cs @@ -3,7 +3,6 @@ using System.Drawing; using System.Windows.Forms.TestUtilities; -using Microsoft.DotNet.RemoteExecutor; using Point = System.Drawing.Point; namespace System.Windows.Forms.Tests; @@ -79,105 +78,118 @@ public void ListViewInsertionMark_AppearsAfterItem_SetWithHandle_GetReturnsExpec Assert.Equal(0, createdCallCount); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public unsafe void ListViewInsertionMark_AppearsAfterItem_GetInsertMark_Success() { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - - using ListView control = new(); - ListViewInsertionMark insertionMark = control.InsertionMark; - - // Set same. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.AppearsAfterItem = false; - LVINSERTMARK insertMark = new() + try { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set true. - control.InsertionMark.AppearsAfterItem = true; - insertMark = new LVINSERTMARK - { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000001, insertMark.dwFlags); - Assert.Equal(0, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set false. - control.InsertionMark.AppearsAfterItem = false; - insertMark = new LVINSERTMARK + Application.EnableVisualStyles(); + + using ListView control = new(); + ListViewInsertionMark insertionMark = control.InsertionMark; + + // Set same. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.AppearsAfterItem = false; + LVINSERTMARK insertMark = new() + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set true. + control.InsertionMark.AppearsAfterItem = true; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000001, insertMark.dwFlags); + Assert.Equal(0, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set false. + control.InsertionMark.AppearsAfterItem = false; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(0, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + } + finally { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(0, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - }).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public unsafe void ListViewInsertionMark_AppearsAfterItem_GetInsertMarkWithColor_Success() { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - - using ListView control = new(); - ListViewInsertionMark insertionMark = control.InsertionMark; - control.InsertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); - - // Set same. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.AppearsAfterItem = false; - LVINSERTMARK insertMark = new() + try { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set true. - control.InsertionMark.AppearsAfterItem = true; - insertMark = new LVINSERTMARK - { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000001, insertMark.dwFlags); - Assert.Equal(0, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set false. - control.InsertionMark.AppearsAfterItem = false; - insertMark = new LVINSERTMARK + Application.EnableVisualStyles(); + + using ListView control = new(); + ListViewInsertionMark insertionMark = control.InsertionMark; + control.InsertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); + + // Set same. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.AppearsAfterItem = false; + LVINSERTMARK insertMark = new() + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set true. + control.InsertionMark.AppearsAfterItem = true; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000001, insertMark.dwFlags); + Assert.Equal(0, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set false. + control.InsertionMark.AppearsAfterItem = false; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(0, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + } + finally { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(0, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - }).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] @@ -355,42 +367,49 @@ public void ListViewInsertionMark_Color_SetWithHandle_ReturnsExpected(Color valu Assert.Equal(0, createdCallCount); } - [WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsFact] public unsafe void ListViewInsertionMark_Color_GetInsertMarkColor_Success() { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke(() => + Task.Run(() => { - Application.EnableVisualStyles(); - - using ListView control = new(); - ListViewInsertionMark insertionMark = control.InsertionMark; - Assert.NotEqual(IntPtr.Zero, control.Handle); - - // Set same. - control.InsertionMark.Color = Color.Empty; - LVINSERTMARK insertMark = new() + try { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set different. - control.InsertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); - insertMark = new LVINSERTMARK + Application.EnableVisualStyles(); + + using ListView control = new(); + ListViewInsertionMark insertionMark = control.InsertionMark; + Assert.NotEqual(IntPtr.Zero, control.Handle); + + // Set same. + control.InsertionMark.Color = Color.Empty; + LVINSERTMARK insertMark = new() + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set different. + control.InsertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + } + finally { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - }).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] @@ -449,113 +468,125 @@ public void ListViewInsertionMark_Index_SetWithHandle_GetReturnsExpected(int val Assert.Equal(value, insertionMark.Index); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [InlineData(-2)] [InlineData(1)] public unsafe void ListViewInsertionMark_Index_GetInsertMark_Success(int indexParam) { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((indexString) => + Task.Run(() => { - int index = int.Parse(indexString); - Application.EnableVisualStyles(); - - using ListView control = new(); - ListViewInsertionMark insertionMark = control.InsertionMark; - - // Set same. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.Index = 0; - LVINSERTMARK insertMark = new() + try { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set negative one. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.Index = -1; - insertMark = new LVINSERTMARK - { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set different. - control.InsertionMark.Index = index; - insertMark = new LVINSERTMARK + Application.EnableVisualStyles(); + + using ListView control = new(); + ListViewInsertionMark insertionMark = control.InsertionMark; + + // Set same. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.Index = 0; + LVINSERTMARK insertMark = new() + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set negative one. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.Index = -1; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set different. + control.InsertionMark.Index = indexParam; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(indexParam, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + } + finally { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(index, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - }, indexParam.ToString()).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [InlineData(-2)] [InlineData(1)] public unsafe void ListViewInsertionMark_Index_GetInsertMarkWithColor_Success(int indexParam) { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((indexString) => + Task.Run(() => { - int index = int.Parse(indexString); - Application.EnableVisualStyles(); - - using ListView control = new(); - ListViewInsertionMark insertionMark = control.InsertionMark; - insertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); - - // Set same. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.Index = 0; - LVINSERTMARK insertMark = new() + try { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set negative one. - Assert.NotEqual(IntPtr.Zero, control.Handle); - control.InsertionMark.Index = -1; - insertMark = new LVINSERTMARK - { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(-1, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - - // Set different. - control.InsertionMark.Index = index; - insertMark = new LVINSERTMARK + Application.EnableVisualStyles(); + + using ListView control = new(); + ListViewInsertionMark insertionMark = control.InsertionMark; + insertionMark.Color = Color.FromArgb(0x12, 0x34, 0x56, 0x78); + + // Set same. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.Index = 0; + LVINSERTMARK insertMark = new() + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set negative one. + Assert.NotEqual(IntPtr.Zero, control.Handle); + control.InsertionMark.Index = -1; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(0, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(-1, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + + // Set different. + control.InsertionMark.Index = indexParam; + insertMark = new LVINSERTMARK + { + cbSize = (uint)sizeof(LVINSERTMARK) + }; + Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); + Assert.Equal(0x80000000, insertMark.dwFlags); + Assert.Equal(indexParam, insertMark.iItem); + Assert.Equal(0u, insertMark.dwReserved); + Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); + } + finally { - cbSize = (uint)sizeof(LVINSERTMARK) - }; - Assert.Equal(1, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARK, 0, ref insertMark)); - Assert.Equal(0x80000000, insertMark.dwFlags); - Assert.Equal(index, insertMark.iItem); - Assert.Equal(0u, insertMark.dwReserved); - Assert.Equal(0x785634, (int)PInvokeCore.SendMessage(control, PInvoke.LVM_GETINSERTMARKCOLOR)); - }, indexParam.ToString()).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsFact] diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabPageTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabPageTests.cs index 014c5e082e7..246f7226d52 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabPageTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/TabPageTests.cs @@ -6,7 +6,6 @@ using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms.TestUtilities; -using Microsoft.DotNet.RemoteExecutor; using Moq; using Point = System.Drawing.Point; using Size = System.Drawing.Size; @@ -534,23 +533,27 @@ public static void TabPage_BackColor_Get_ReturnsExpected(bool useVisualStyleBack Assert.Equal(Control.DefaultBackColor, control.BackColor); } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [BoolData] public static void TabPage_BackColor_GetVisualStyles_ReturnsExpected(bool useVisualStyleBackColorParam) { - // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((useVisualStyleBackColorString) => + Task.Run(() => { - bool useVisualStyleBackColor = bool.Parse(useVisualStyleBackColorString); - - Application.EnableVisualStyles(); + try + { + Application.EnableVisualStyles(); - using TabPage control = new() + using TabPage control = new() + { + UseVisualStyleBackColor = useVisualStyleBackColorParam + }; + Assert.Equal(Control.DefaultBackColor, control.BackColor); + } + finally { - UseVisualStyleBackColor = useVisualStyleBackColor - }; - Assert.Equal(Control.DefaultBackColor, control.BackColor); - }, useVisualStyleBackColorParam.ToString()).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsTheory] @@ -614,30 +617,33 @@ public static IEnumerable BackColor_GetVisualStylesWithParent_TestData yield return new object[] { false, TabAppearance.Normal, Control.DefaultBackColor }; } - [WinFormsTheory(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")] + [WinFormsTheory] [MemberData(nameof(BackColor_GetVisualStylesWithParent_TestData))] public static void TabPage_BackColor_GetVisualStylesWithParent_ReturnsExpected(bool useVisualStyleBackColorParam, TabAppearance parentAppearanceParam, Color expectedParam) { // Run this from another thread as we call Application.EnableVisualStyles. - RemoteExecutor.Invoke((useVisualStyleBackColorString, parentAppearanceString, expectedString) => + Task.Run(() => { - bool useVisualStyleBackColor = bool.Parse(useVisualStyleBackColorString); - TabAppearance parentAppearance = (TabAppearance)Enum.Parse(typeof(TabAppearance), parentAppearanceString); - Color expected = Color.FromArgb(int.Parse(expectedString)); - - Application.EnableVisualStyles(); - - using TabControl parent = new() + try { - Appearance = parentAppearance - }; - using TabPage control = new() + Application.EnableVisualStyles(); + + using TabControl parent = new() + { + Appearance = parentAppearanceParam + }; + using TabPage control = new() + { + UseVisualStyleBackColor = useVisualStyleBackColorParam, + Parent = parent + }; + Assert.Equal(expectedParam.ToArgb(), control.BackColor.ToArgb()); + } + finally { - UseVisualStyleBackColor = useVisualStyleBackColor, - Parent = parent - }; - Assert.Equal(expected.ToArgb(), control.BackColor.ToArgb()); - }, useVisualStyleBackColorParam.ToString(), parentAppearanceParam.ToString(), expectedParam.ToArgb().ToString()).Dispose(); + Application.VisualStyleState = VisualStyles.VisualStyleState.NoneEnabled; + } + }).Wait(); } [WinFormsTheory]