From 43f6876aecb5e18d3bdea1db5700ef374ff016ad Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Fri, 28 Jun 2024 14:21:54 +0800 Subject: [PATCH 1/2] MoveAllClipboard related tests to a new class --- .../TextBoxBaseTests.ClipboardTests.cs | 245 ++++++++++++++++++ .../tests/UnitTests/TextBoxBaseTests.cs | 234 ----------------- 2 files changed, 245 insertions(+), 234 deletions(-) create mode 100644 src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs diff --git a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs new file mode 100644 index 00000000000..6707dbb7d39 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs @@ -0,0 +1,245 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Windows.Forms.Tests; + +public partial class TextBoxBaseTests +{ + [Collection("Sequential")] + public class ClipboardTests + { + [ActiveIssue("https://github.com/dotnet/winforms/issues/11497")] + [WinFormsFact] + [SkipOnArchitecture(TestArchitectures.X86, + "Flaky tests, see: https://github.com/dotnet/winforms/issues/11497")] + public void TextBoxBase_ClearUndo_CanUndo_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + control.Copy(); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + + control.ClearUndo(); + control.Undo(); + Assert.Equal("bcxt", control.Text); + } + + [ActiveIssue("https://github.com/dotnet/winforms/issues/11558")] + [WinFormsFact] + [SkipOnArchitecture(TestArchitectures.X86, + "Flaky tests, see: https://github.com/dotnet/winforms/issues/11558")] + public void TextBoxBase_Copy_PasteNotEmpty_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + control.Copy(); + Assert.Equal("abc", control.Text); + Assert.True(control.IsHandleCreated); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + Assert.True(control.CanUndo); + Assert.True(control.Modified); + Assert.True(control.IsHandleCreated); + } + + [ActiveIssue("https://github.com/dotnet/winforms/issues/11498")] + [WinFormsFact] + [SkipOnArchitecture(TestArchitectures.X86, + "Flaky tests, see: https://github.com/dotnet/winforms/issues/11498")] + public void TextBoxBase_Copy_PasteNotEmptyWithHandle_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + Assert.NotEqual(IntPtr.Zero, control.Handle); + int invalidatedCallCount = 0; + control.Invalidated += (sender, e) => invalidatedCallCount++; + int styleChangedCallCount = 0; + control.StyleChanged += (sender, e) => styleChangedCallCount++; + int createdCallCount = 0; + control.HandleCreated += (sender, e) => createdCallCount++; + + control.Copy(); + Assert.Equal("abc", control.Text); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + Assert.True(control.CanUndo); + Assert.True(control.Modified); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + } + + [WinFormsFact] + public void TextBoxBase_Cut_PasteNotEmpty_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + control.Cut(); + Assert.Equal("a", control.Text); + Assert.True(control.IsHandleCreated); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + Assert.True(control.CanUndo); + Assert.True(control.Modified); + Assert.True(control.IsHandleCreated); + } + + [WinFormsFact] + public void TextBoxBase_Cut_PasteNotEmptyWithHandle_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + Assert.NotEqual(IntPtr.Zero, control.Handle); + int invalidatedCallCount = 0; + control.Invalidated += (sender, e) => invalidatedCallCount++; + int styleChangedCallCount = 0; + control.StyleChanged += (sender, e) => styleChangedCallCount++; + int createdCallCount = 0; + control.HandleCreated += (sender, e) => createdCallCount++; + + control.Cut(); + Assert.Equal("a", control.Text); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + Assert.True(control.CanUndo); + Assert.True(control.Modified); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + } + + [WinFormsFact] + public void TextBoxBase_Paste_InvokeEmpty_Success() + { + using SubTextBox control = new(); + control.Paste(); + Assert.NotNull(control.Text); + Assert.True(control.IsHandleCreated); + } + + [WinFormsFact] + public void TextBoxBase_Paste_InvokeNotEmpty_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + control.Paste(); + Assert.Equal("abc", control.Text); + Assert.True(control.IsHandleCreated); + } + + [ActiveIssue("https://github.com/dotnet/winforms/issues/11559")] + [WinFormsFact] + [SkipOnArchitecture(TestArchitectures.X86, + "Flaky tests, see: https://github.com/dotnet/winforms/issues/11559")] + public void TextBoxBase_Undo_CanUndo_Success() + { + using SubTextBox control = new() + { + Text = "abc", + SelectionStart = 1, + SelectionLength = 2 + }; + control.Copy(); + + control.Text = "text"; + control.SelectionLength = 2; + control.Paste(); + Assert.Equal("bcxt", control.Text); + + control.Undo(); + Assert.Equal("text", control.Text); + } + + [WinFormsFact] + public void TextBoxBase_Copy_PasteEmpty_Success() + { + using SubTextBox control = new(); + control.Copy(); + Assert.Empty(control.Text); + Assert.True(control.IsHandleCreated); + + control.Text = "text"; + control.SelectionLength = 2; + Assert.Equal("text", control.Text); + Assert.True(control.IsHandleCreated); + } + + [WinFormsFact] + public void TextBoxBase_Copy_PasteEmptyWithHandle_Success() + { + using SubTextBox control = new(); + Assert.NotEqual(IntPtr.Zero, control.Handle); + int invalidatedCallCount = 0; + control.Invalidated += (sender, e) => invalidatedCallCount++; + int styleChangedCallCount = 0; + control.StyleChanged += (sender, e) => styleChangedCallCount++; + int createdCallCount = 0; + control.HandleCreated += (sender, e) => createdCallCount++; + + control.Copy(); + Assert.Empty(control.Text); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + + control.Text = "text"; + control.SelectionLength = 2; + Assert.Equal("text", control.Text); + Assert.True(control.IsHandleCreated); + Assert.Equal(0, invalidatedCallCount); + Assert.Equal(0, styleChangedCallCount); + Assert.Equal(0, createdCallCount); + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs index b2b56fe5525..a5d4a0937e9 100644 --- a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.cs @@ -4131,136 +4131,6 @@ public void TextBoxBase_ClearUndo_InvokeWithHandle_Success() Assert.Equal(0, createdCallCount); } - [ActiveIssue("https://github.com/dotnet/winforms/issues/11497")] - [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11497")] - public void TextBoxBase_ClearUndo_CanUndo_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - control.Copy(); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - - control.ClearUndo(); - control.Undo(); - Assert.Equal("bcxt", control.Text); - } - - [WinFormsFact] - public void TextBoxBase_Copy_PasteEmpty_Success() - { - using SubTextBox control = new(); - control.Copy(); - Assert.Empty(control.Text); - Assert.True(control.IsHandleCreated); - - control.Text = "text"; - control.SelectionLength = 2; - Assert.Equal("text", control.Text); - Assert.True(control.IsHandleCreated); - } - - [ActiveIssue("https://github.com/dotnet/winforms/issues/11558")] - [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11558")] - public void TextBoxBase_Copy_PasteNotEmpty_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - control.Copy(); - Assert.Equal("abc", control.Text); - Assert.True(control.IsHandleCreated); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - Assert.True(control.CanUndo); - Assert.True(control.Modified); - Assert.True(control.IsHandleCreated); - } - - [WinFormsFact] - public void TextBoxBase_Copy_PasteEmptyWithHandle_Success() - { - using SubTextBox control = new(); - Assert.NotEqual(IntPtr.Zero, control.Handle); - int invalidatedCallCount = 0; - control.Invalidated += (sender, e) => invalidatedCallCount++; - int styleChangedCallCount = 0; - control.StyleChanged += (sender, e) => styleChangedCallCount++; - int createdCallCount = 0; - control.HandleCreated += (sender, e) => createdCallCount++; - - control.Copy(); - Assert.Empty(control.Text); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - - control.Text = "text"; - control.SelectionLength = 2; - Assert.Equal("text", control.Text); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - } - - [ActiveIssue("https://github.com/dotnet/winforms/issues/11498")] - [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11498")] - public void TextBoxBase_Copy_PasteNotEmptyWithHandle_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - Assert.NotEqual(IntPtr.Zero, control.Handle); - int invalidatedCallCount = 0; - control.Invalidated += (sender, e) => invalidatedCallCount++; - int styleChangedCallCount = 0; - control.StyleChanged += (sender, e) => styleChangedCallCount++; - int createdCallCount = 0; - control.HandleCreated += (sender, e) => createdCallCount++; - - control.Copy(); - Assert.Equal("abc", control.Text); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - Assert.True(control.CanUndo); - Assert.True(control.Modified); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - } - [WinFormsFact] public void TextBoxBase_CreateHandle_Invoke_Success() { @@ -4309,28 +4179,6 @@ public void TextBoxBase_Cut_PasteEmpty_Success() Assert.True(control.IsHandleCreated); } - [WinFormsFact] - public void TextBoxBase_Cut_PasteNotEmpty_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - control.Cut(); - Assert.Equal("a", control.Text); - Assert.True(control.IsHandleCreated); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - Assert.True(control.CanUndo); - Assert.True(control.Modified); - Assert.True(control.IsHandleCreated); - } - [WinFormsFact] public void TextBoxBase_Cut_PasteEmptyWithHandle_Success() { @@ -4359,42 +4207,6 @@ public void TextBoxBase_Cut_PasteEmptyWithHandle_Success() Assert.Equal(0, createdCallCount); } - [WinFormsFact] - public void TextBoxBase_Cut_PasteNotEmptyWithHandle_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - Assert.NotEqual(IntPtr.Zero, control.Handle); - int invalidatedCallCount = 0; - control.Invalidated += (sender, e) => invalidatedCallCount++; - int styleChangedCallCount = 0; - control.StyleChanged += (sender, e) => styleChangedCallCount++; - int createdCallCount = 0; - control.HandleCreated += (sender, e) => createdCallCount++; - - control.Cut(); - Assert.Equal("a", control.Text); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - Assert.True(control.CanUndo); - Assert.True(control.Modified); - Assert.True(control.IsHandleCreated); - Assert.Equal(0, invalidatedCallCount); - Assert.Equal(0, styleChangedCallCount); - Assert.Equal(0, createdCallCount); - } - [WinFormsFact] public void TextBoxBase_DeselectAll_InvokeEmpty_Success() { @@ -5987,29 +5799,6 @@ public void TextBoxBase_OnTextChanged_Invoke_CallsTextChanged(EventArgs eventArg Assert.False(control.IsHandleCreated); } - [WinFormsFact] - public void TextBoxBase_Paste_InvokeEmpty_Success() - { - using SubTextBox control = new(); - control.Paste(); - Assert.NotNull(control.Text); - Assert.True(control.IsHandleCreated); - } - - [WinFormsFact] - public void TextBoxBase_Paste_InvokeNotEmpty_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - control.Paste(); - Assert.Equal("abc", control.Text); - Assert.True(control.IsHandleCreated); - } - public static IEnumerable ProcessCmdKey_TestData() { foreach (bool shortcutsEnabled in new bool[] { true, false }) @@ -7138,29 +6927,6 @@ public void TextBoxBase_Undo_InvokeNotEmptyWithHandle_Success() Assert.Equal(0, createdCallCount); } - [ActiveIssue("https://github.com/dotnet/winforms/issues/11559")] - [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11559")] - public void TextBoxBase_Undo_CanUndo_Success() - { - using SubTextBox control = new() - { - Text = "abc", - SelectionStart = 1, - SelectionLength = 2 - }; - control.Copy(); - - control.Text = "text"; - control.SelectionLength = 2; - control.Paste(); - Assert.Equal("bcxt", control.Text); - - control.Undo(); - Assert.Equal("text", control.Text); - } - public static IEnumerable WndProc_ContextMenuWithoutContextMenuStrip_TestData() { foreach (bool shortcutsEnabled in new bool[] { true, false }) From c78800ed07d3248d70f111f531ad4ba5848ca075 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Fri, 28 Jun 2024 14:23:22 +0800 Subject: [PATCH 2/2] Removing SkipOnArchitecture label --- .../UnitTests/TextBoxBaseTests.ClipboardTests.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs index 6707dbb7d39..e4596cac5f2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/TextBoxBaseTests.ClipboardTests.cs @@ -8,10 +8,7 @@ public partial class TextBoxBaseTests [Collection("Sequential")] public class ClipboardTests { - [ActiveIssue("https://github.com/dotnet/winforms/issues/11497")] [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11497")] public void TextBoxBase_ClearUndo_CanUndo_Success() { using SubTextBox control = new() @@ -32,10 +29,7 @@ public void TextBoxBase_ClearUndo_CanUndo_Success() Assert.Equal("bcxt", control.Text); } - [ActiveIssue("https://github.com/dotnet/winforms/issues/11558")] [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11558")] public void TextBoxBase_Copy_PasteNotEmpty_Success() { using SubTextBox control = new() @@ -57,10 +51,7 @@ public void TextBoxBase_Copy_PasteNotEmpty_Success() Assert.True(control.IsHandleCreated); } - [ActiveIssue("https://github.com/dotnet/winforms/issues/11498")] [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11498")] public void TextBoxBase_Copy_PasteNotEmptyWithHandle_Success() { using SubTextBox control = new() @@ -177,10 +168,7 @@ public void TextBoxBase_Paste_InvokeNotEmpty_Success() Assert.True(control.IsHandleCreated); } - [ActiveIssue("https://github.com/dotnet/winforms/issues/11559")] [WinFormsFact] - [SkipOnArchitecture(TestArchitectures.X86, - "Flaky tests, see: https://github.com/dotnet/winforms/issues/11559")] public void TextBoxBase_Undo_CanUndo_Success() { using SubTextBox control = new()