diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardComTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardComTests.cs deleted file mode 100644 index 381ee7a2741..00000000000 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardComTests.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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 ClipboardTests -{ - [WinFormsFact] - public void Clipboard_SetText_InvokeString_GetReturnsExpected() - { - Clipboard.SetText("text"); - Assert.Equal("text", Clipboard.GetText()); - Assert.True(Clipboard.ContainsText()); - } -} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs index 4fbf8e76066..131eaa0c8ec 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ClipboardTests.cs @@ -16,8 +16,16 @@ namespace System.Windows.Forms.Tests; [Collection("Sequential")] [CollectionDefinition("Sequential", DisableParallelization = true)] -public partial class ClipboardTests +public class ClipboardTests { + [WinFormsFact] + public void Clipboard_SetText_InvokeString_GetReturnsExpected() + { + Clipboard.SetText("text"); + Clipboard.GetText().Should().Be("text"); + Clipboard.ContainsText().Should().BeTrue(); + } + [WinFormsFact] public void Clipboard_Clear_InvokeMultipleTimes_Success() { diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.ClipboardTests.cs new file mode 100644 index 00000000000..f5eeac03e37 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.ClipboardTests.cs @@ -0,0 +1,135 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +namespace System.Windows.Forms.Tests; + +public partial class DataGridViewCellTests +{ + [Collection("Sequential")] + public class ClipboardTests + { + public static TheoryData GetClipboardContent_TheoryData() => new() + { + { -2, true, true, true, true, "format", null }, + { -2, true, true, true, true, null, null }, + { -1, true, true, true, true, "format", null }, + { -1, true, true, true, true, null, null }, + { 0, true, true, true, true, "format", null }, + { 0, true, true, true, true, null, null }, + }; + + [WinFormsTheory] + [MemberData(nameof(GetClipboardContent_TheoryData))] + public void DataGridViewCell_GetClipboardContent_Invoke_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected) + { + using SubDataGridViewCell cell = new(); + cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected); + } + + [WinFormsTheory] + [MemberData(nameof(GetClipboardContent_TheoryData))] + public void DataGridViewCell_GetClipboardContent_InvokeWithRow_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected) + { + using DataGridViewRow row = new(); + using SubDataGridViewCell cell = new(); + row.Cells.Add(cell); + cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected); + } + + public static TheoryData GetClipboardContent_WithColumn_TheoryData() => new() + { + { true, true, true, true, "format", null }, + { true, true, true, true, null, null } + }; + + [WinFormsTheory] + [MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))] + public void DataGridViewCell_GetClipboardContent_InvokeWithColumn_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected) + { + using DataGridViewColumn column = new(); + using SubDataGridViewColumnHeaderCell cell = new(); + column.HeaderCell = cell; + cell.GetClipboardContent(-1, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected); + } + + [WinFormsTheory] + [MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))] + public void DataGridViewCell_GetClipboardContent_InvokeWithDataGridView_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected) + { + using SubDataGridViewCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new(); + control.Columns.Add(column); + SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0]; + cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected); + } + + [WinFormsTheory] + [MemberData(nameof(GetClipboardContent_WithColumn_TheoryData))] + public void DataGridViewCell_GetClipboardContent_InvokeShared_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string? format, object? expected) + { + using SubDataGridViewCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new(); + control.Columns.Add(column); + SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0]; + cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format).Should().Be(expected); + } + + [WinFormsTheory] + [InlineData(-2)] + [InlineData(0)] + public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithColumn_ThrowsArgumentOutOfRangeException(int rowIndex) + { + using DataGridViewColumn column = new(); + using SubDataGridViewColumnHeaderCell cell = new(); + column.HeaderCell = cell; + Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"); + action.Should().Throw().WithParameterName("rowIndex"); + } + + [WinFormsTheory] + [InlineData(-2)] + [InlineData(-1)] + [InlineData(1)] + public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithDataGridView_ThrowsArgumentOutOfRangeException(int rowIndex) + { + using SubDataGridViewCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new(); + control.Columns.Add(column); + SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0]; + Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"); + action.Should().Throw().WithParameterName("rowIndex"); + } + + [WinFormsTheory] + [InlineData(-2)] + [InlineData(-1)] + [InlineData(1)] + public void DataGridViewCell_GetClipboardContent_InvalidRowIndexShared_ThrowsArgumentOutOfRangeException(int rowIndex) + { + using SubDataGridViewCell cellTemplate = new(); + using DataGridViewColumn column = new() + { + CellTemplate = cellTemplate + }; + using DataGridView control = new(); + control.Columns.Add(column); + SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0]; + Action action = () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format"); + action.Should().Throw().WithParameterName("rowIndex"); + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs index d46d515f5e9..0f5aa66fe47 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellTests.cs @@ -11,7 +11,7 @@ namespace System.Windows.Forms.Tests; -public class DataGridViewCellTests +public partial class DataGridViewCellTests { [WinFormsFact] public void DataGridViewCell_Ctor_Default() @@ -3561,125 +3561,6 @@ public void DataGridViewCell_EnterUnsharesRow_Invoke_ReturnsFalse() Assert.False(cell.EnterUnsharesRow(-1, true)); } - public static IEnumerable GetClipboardContent_TestData() - { - yield return new object[] { -2, true, true, true, true, "format", null }; - yield return new object[] { -2, true, true, true, true, null, null }; - yield return new object[] { -1, true, true, true, true, "format", null }; - yield return new object[] { -1, true, true, true, true, null, null }; - yield return new object[] { 0, true, true, true, true, "format", null }; - yield return new object[] { 0, true, true, true, true, null, null }; - } - - [WinFormsTheory] - [MemberData(nameof(GetClipboardContent_TestData))] - public void DataGridViewCell_GetClipboardContent_Invoke_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected) - { - using SubDataGridViewCell cell = new(); - Assert.Equal(expected, cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format)); - } - - [WinFormsTheory] - [MemberData(nameof(GetClipboardContent_TestData))] - public void DataGridViewCell_GetClipboardContent_InvokeWithRow_ReturnsExpected(int rowIndex, bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected) - { - using DataGridViewRow row = new(); - using SubDataGridViewCell cell = new(); - row.Cells.Add(cell); - Assert.Equal(expected, cell.GetClipboardContent(rowIndex, firstCell, lastCell, inFirstRow, inLastRow, format)); - } - - public static IEnumerable GetClipboardContent_WithColumn_TestData() - { - yield return new object[] { true, true, true, true, "format", null }; - yield return new object[] { true, true, true, true, null, null }; - } - - [WinFormsTheory] - [MemberData(nameof(GetClipboardContent_WithColumn_TestData))] - public void DataGridViewCell_GetClipboardContent_InvokeWithColumn_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected) - { - using DataGridViewColumn column = new(); - using SubDataGridViewColumnHeaderCell cell = new(); - column.HeaderCell = cell; - Assert.Equal(expected, cell.GetClipboardContent(-1, firstCell, lastCell, inFirstRow, inLastRow, format)); - } - - [WinFormsTheory] - [MemberData(nameof(GetClipboardContent_WithColumn_TestData))] - public void DataGridViewCell_GetClipboardContent_InvokeWithDataGridView_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected) - { - using SubDataGridViewCell cellTemplate = new(); - using DataGridViewColumn column = new() - { - CellTemplate = cellTemplate - }; - using DataGridView control = new(); - control.Columns.Add(column); - SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0]; - Assert.Equal(expected, cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format)); - } - - [WinFormsTheory] - [MemberData(nameof(GetClipboardContent_WithColumn_TestData))] - public void DataGridViewCell_GetClipboardContent_InvokeShared_ReturnsExpected(bool firstCell, bool lastCell, bool inFirstRow, bool inLastRow, string format, object expected) - { - using SubDataGridViewCell cellTemplate = new(); - using DataGridViewColumn column = new() - { - CellTemplate = cellTemplate - }; - using DataGridView control = new(); - control.Columns.Add(column); - SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0]; - Assert.Equal(expected, cell.GetClipboardContent(0, firstCell, lastCell, inFirstRow, inLastRow, format)); - } - - [WinFormsTheory] - [InlineData(-2)] - [InlineData(0)] - public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithColumn_ThrowsArgumentOutOfRangeException(int rowIndex) - { - using DataGridViewColumn column = new(); - using SubDataGridViewColumnHeaderCell cell = new(); - column.HeaderCell = cell; - Assert.Throws("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format")); - } - - [WinFormsTheory] - [InlineData(-2)] - [InlineData(-1)] - [InlineData(1)] - public void DataGridViewCell_GetClipboardContent_InvalidRowIndexWithDataGridView_ThrowsArgumentOutOfRangeException(int rowIndex) - { - using SubDataGridViewCell cellTemplate = new(); - using DataGridViewColumn column = new() - { - CellTemplate = cellTemplate - }; - using DataGridView control = new(); - control.Columns.Add(column); - SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows[0].Cells[0]; - Assert.Throws("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format")); - } - - [WinFormsTheory] - [InlineData(-2)] - [InlineData(-1)] - [InlineData(1)] - public void DataGridViewCell_GetClipboardContent_InvalidRowIndexShared_ThrowsArgumentOutOfRangeException(int rowIndex) - { - using SubDataGridViewCell cellTemplate = new(); - using DataGridViewColumn column = new() - { - CellTemplate = cellTemplate - }; - using DataGridView control = new(); - control.Columns.Add(column); - SubDataGridViewCell cell = (SubDataGridViewCell)control.Rows.SharedRow(0).Cells[0]; - Assert.Throws("rowIndex", () => cell.GetClipboardContent(rowIndex, true, true, true, true, "format")); - } - [WinFormsTheory] [InlineData(-2)] [InlineData(-1)] @@ -6613,9 +6494,9 @@ public SubDataGridViewCheckBoxCell() protected override AccessibleObject CreateAccessibilityInstance() => MockAccessibleObject; - public void MouseClick(DataGridViewCellMouseEventArgs e) => base.OnMouseUpInternal(e); + public void MouseClick(DataGridViewCellMouseEventArgs e) => OnMouseUpInternal(e); - public void OnKeyClick(KeyEventArgs e, int rowIndex) => base.OnKeyUp(e, rowIndex); + public void OnKeyClick(KeyEventArgs e, int rowIndex) => OnKeyUp(e, rowIndex); } private class SubDataGridViewColumnHeaderCell : DataGridViewColumnHeaderCell diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.ClipboardTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.ClipboardTests.cs new file mode 100644 index 00000000000..ffe5fc0ca61 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.ClipboardTests.cs @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Drawing; + +namespace System.Windows.Forms.Tests; + +public partial class RichTextBoxTests +{ + [Collection("Sequential")] + public class ClipboardTests + { + [WinFormsFact] + public void RichTextBox_OleObject_IncompleteOleObject_DoNothing() + { + using RichTextBox control = new(); + control.Handle.Should().NotBe(IntPtr.Zero); + + using MemoryStream memoryStream = new(); + using Bitmap bitmap = new(100, 100); + bitmap.Save(memoryStream, Drawing.Imaging.ImageFormat.Png); + Clipboard.SetData("Embed Source", memoryStream); + + control.Text.Should().BeEmpty(); + } + + public static TheoryData PlainTextData => new() + { + { "Hello World"}, + { new string('a', 10000) }, + { "Special characters: !@#$%^&*()" }, + }; + + [WinFormsTheory] + [MemberData(nameof(PlainTextData))] + public void RichTextBox_Paste_PlainText_Data(string value) + { + using RichTextBox richTextBox1 = new(); + + if (!string.IsNullOrEmpty(value)) + { + Clipboard.SetText(value); + richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); + + richTextBox1.Text.Should().Be(value); + } + } + + [WinFormsFact] + public void RichTextBox_Paste_EmptyString_Data() + { + using RichTextBox richTextBox1 = new(); + + Clipboard.SetText("non-empty"); + Clipboard.Clear(); + richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); + + richTextBox1.Text.Should().BeEmpty(); + } + + public static TheoryData RtfData => new() + { + { "{\\rtf Hello World}" }, + { "{\\rtf1\\ansi{Sample for {\\v HIDDEN }text}}" }, + { "{\\rtf1\\ansi{Invalid RTF data" }, + }; + + [WinFormsTheory] + [MemberData(nameof(RtfData))] + public void RichTextBox_Paste_Rtf_Data(string rtf) + { + using RichTextBox richTextBox1 = new(); + + if (!string.IsNullOrEmpty(rtf)) + { + Clipboard.SetText(rtf); + richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Rtf)); + + richTextBox1.Rtf.Should().StartWith("{\\rtf"); + } + } + } +} diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs index fbaefdd9b7e..f5cd46675be 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/RichTextBoxTests.cs @@ -17,7 +17,7 @@ namespace System.Windows.Forms.Tests; -public class RichTextBoxTests +public partial class RichTextBoxTests { private static readonly int s_preferredHeight = Control.DefaultFont.Height + SystemInformation.BorderSize.Height * 4 + 3; @@ -7905,20 +7905,6 @@ protected override unsafe void WndProc(ref Message m) } } - [WinFormsFact] - public void RichTextBox_OleObject_IncompleteOleObject_DoNothing() - { - using RichTextBox control = new(); - Assert.NotEqual(IntPtr.Zero, control.Handle); - - using MemoryStream memoryStream = new(); - using Bitmap bitmap = new(100, 100); - bitmap.Save(memoryStream, Drawing.Imaging.ImageFormat.Png); - Clipboard.SetData("Embed Source", memoryStream); - - Assert.Equal(string.Empty, control.Text); - } - [WinFormsFact] public void RichTextBox_CanPaste_NullFormat_ThrowsNullReferenceException() { @@ -10734,62 +10720,6 @@ public void RichTextBox_SaveFile_Invoke_Success(RichTextBoxStreamType fileType) } } - public static TheoryData PlainTextData => new() - { - { "Hello World"}, - { new string('a', 10000) }, - { "Special characters: !@#$%^&*()" }, - }; - - [WinFormsTheory] - [MemberData(nameof(PlainTextData))] - public void RichTextBox_Paste_PlainText_Data(string value) - { - using RichTextBox richTextBox1 = new(); - - if (!string.IsNullOrEmpty(value)) - { - Clipboard.SetText(value); - richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); - - richTextBox1.Text.Should().Be(value); - } - } - - [WinFormsFact] - public void RichTextBox_Paste_EmptyString_Data() - { - using RichTextBox richTextBox1 = new(); - - Clipboard.SetText("non-empty"); - Clipboard.Clear(); - richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Text)); - - richTextBox1.Text.Should().Be(""); - } - - public static TheoryData RtfData => new() - { - { "{\\rtf Hello World}" }, - { "{\\rtf1\\ansi{Sample for {\\v HIDDEN }text}}" }, - { "{\\rtf1\\ansi{Invalid RTF data" }, - }; - - [WinFormsTheory] - [MemberData(nameof(RtfData))] - public void RichTextBox_Paste_Rtf_Data(string rtf) - { - using RichTextBox richTextBox1 = new(); - - if (!string.IsNullOrEmpty(rtf)) - { - Clipboard.SetText(rtf); - richTextBox1.Paste(DataFormats.GetFormat(DataFormats.Rtf)); - - richTextBox1.Rtf.Should().StartWith("{\\rtf"); - } - } - [WinFormsFact] public void RichTextBox_DragDropEvent_AddRemove_Success() {