Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all Clipboard related tests to a new class and remove SkipOnArchitecture label #11606

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,233 @@
// 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
{
[WinFormsFact]
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_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_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);
}

[WinFormsFact]
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);
}
}
}
Loading