Skip to content

Commit 45b3e8d

Browse files
committed
some tests that fail, intentionally
1 parent 2ec30ef commit 45b3e8d

File tree

1 file changed

+110
-17
lines changed

1 file changed

+110
-17
lines changed

src/cascadia/UnitTests_Control/ControlInteractivityTests.cpp

Lines changed: 110 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace ControlUnitTests
4444
TEST_METHOD(AltBufferClampMouse);
4545

4646
TEST_METHOD(CopyOnSelectSimple);
47+
TEST_METHOD(CopyOnSelectAltBuffer);
4748

4849
TEST_CLASS_SETUP(ClassSetup)
4950
{
@@ -971,8 +972,6 @@ namespace ControlUnitTests
971972

972973
void ControlInteractivityTests::CopyOnSelectSimple()
973974
{
974-
WEX::TestExecution::DisableVerifyExceptions disableVerifyExceptions{};
975-
976975
auto [settings, conn] = _createSettingsAndConnection();
977976
settings->CopyOnSelect(true);
978977
auto [core, interactivity] = _createCoreAndInteractivity(*settings, *conn);
@@ -985,34 +984,113 @@ namespace ControlUnitTests
985984
conn->WriteInput(winrt::hstring{ fmt::format(L"line {}\r\n", i) });
986985
}
987986

987+
// A callback for checking Copy events. expectedCopyContents=nullopt
988+
// indicates that we're not expecting any copy events.
988989
std::optional<std::wstring> expectedCopyContents{ std::nullopt };
989990
core->CopyToClipboard([&](auto&&, auto& args) {
990991
VERIFY_IS_TRUE(expectedCopyContents.has_value());
991992
const std::wstring expected{ expectedCopyContents->c_str() };
992993
const std::wstring actual{ args.Text().c_str() };
993994
VERIFY_ARE_EQUAL(expected, actual);
994995
});
995-
// Start checking output
996-
// std::deque<std::wstring> expectedOutput{};
997-
// auto validateDrained = _addInputCallback(conn, expectedOutput);
996+
bool expectedPaste = false;
997+
interactivity->PasteFromClipboard([&](auto&&, auto&&) {
998+
VERIFY_IS_TRUE(expectedPaste);
999+
});
1000+
1001+
const auto originalViewport{ term.GetViewport() };
1002+
VERIFY_ARE_EQUAL(originalViewport.Width(), 30);
1003+
1004+
// For this test, don't use any modifiers
1005+
const auto modifiers = ControlKeyStates();
1006+
const auto leftMouseDown{ Control::MouseButtonState::IsLeftButtonDown };
1007+
const auto rightMouseDown{ Control::MouseButtonState::IsRightButtonDown };
1008+
const Control::MouseButtonState noMouseDown{};
1009+
const til::size fontSize{ 9, 21 };
1010+
const til::point terminalPosition0{ 0, 5 };
1011+
const til::point terminalPosition1{ 5, 5 };
1012+
const auto cursorPosition0{ terminalPosition0 * fontSize };
1013+
const auto cursorPosition1{ terminalPosition1 * fontSize };
1014+
1015+
Log::Comment(L" --- Click on the terminal at 0,5 ---");
1016+
1017+
interactivity->PointerPressed(leftMouseDown,
1018+
WM_LBUTTONDOWN, //pointerUpdateKind
1019+
0, // timestamp
1020+
modifiers,
1021+
cursorPosition0.to_core_point());
1022+
VERIFY_IS_FALSE(core->HasSelection());
1023+
1024+
Log::Comment(L" --- Drag to 5,5 ---");
1025+
1026+
interactivity->PointerMoved(leftMouseDown,
1027+
WM_LBUTTONDOWN, //pointerUpdateKind
1028+
modifiers,
1029+
true, // focused,
1030+
cursorPosition1.to_core_point(),
1031+
true); // pointerPressedInBounds
1032+
VERIFY_IS_TRUE(core->HasSelection());
1033+
// expectedCopyContents being nullopt here will ensure that we don't send the copy event till the pointer released
1034+
1035+
Log::Comment(L" --- Release the mouse --- ");
1036+
expectedCopyContents = L"line 5";
1037+
interactivity->PointerReleased(noMouseDown,
1038+
WM_LBUTTONUP, //pointerUpdateKind
1039+
modifiers,
1040+
cursorPosition1.to_core_point());
1041+
VERIFY_IS_TRUE(core->HasSelection());
1042+
1043+
Log::Comment(L" --- Right-click to paste --- ");
1044+
expectedCopyContents = std::nullopt;
1045+
expectedPaste = true;
1046+
interactivity->PointerPressed(rightMouseDown,
1047+
WM_RBUTTONDOWN, //pointerUpdateKind
1048+
0, // timestamp
1049+
modifiers,
1050+
cursorPosition1.to_core_point());
1051+
VERIFY_IS_FALSE(core->HasSelection());
1052+
}
1053+
1054+
void ControlInteractivityTests::CopyOnSelectAltBuffer()
1055+
{
1056+
auto [settings, conn] = _createSettingsAndConnection();
1057+
settings->CopyOnSelect(true);
1058+
auto [core, interactivity] = _createCoreAndInteractivity(*settings, *conn);
1059+
_standardInit(core, interactivity);
1060+
auto& term{ *core->_terminal };
1061+
1062+
Log::Comment(L" --- Switch to alt buffer ---");
1063+
term.Write(L"\x1b[?1049h");
1064+
auto returnToMain = wil::scope_exit([&]() { term.Write(L"\x1b[?1049h"); });
1065+
1066+
// Output some text
1067+
auto i = 0;
1068+
for (i = 0; i < core->ViewHeight() - 1; ++i)
1069+
{
1070+
conn->WriteInput(winrt::hstring{ fmt::format(L"line {}\r\n", i) });
1071+
}
1072+
1073+
// A callback for checking Copy events. expectedCopyContents=nullopt
1074+
// indicates that we're not expecting any copy events.
1075+
std::optional<std::wstring> expectedCopyContents{ std::nullopt };
1076+
core->CopyToClipboard([&](auto&&, auto& args) {
1077+
VERIFY_IS_TRUE(expectedCopyContents.has_value());
1078+
const std::wstring expected{ expectedCopyContents->c_str() };
1079+
const std::wstring actual{ args.Text().c_str() };
1080+
VERIFY_ARE_EQUAL(expected, actual);
1081+
});
1082+
bool expectedPaste = false;
1083+
interactivity->PasteFromClipboard([&](auto&&, auto&&) {
1084+
VERIFY_IS_TRUE(expectedPaste);
1085+
});
9981086

9991087
const auto originalViewport{ term.GetViewport() };
10001088
VERIFY_ARE_EQUAL(originalViewport.Width(), 30);
10011089

1002-
// Log::Comment(L" --- Enable mouse mode ---");
1003-
// term.Write(L"\x1b[?1000h");
1004-
1005-
// Log::Comment(L" --- Click on the terminal ---");
1006-
// // Recall:
1007-
// //
1008-
// // > ! specifies the value 1. The upper left character position on
1009-
// // > the terminal is denoted as 1,1
1010-
// //
1011-
// // So 5 in our buffer is 32+5+1 = '&'
1012-
// expectedOutput.push_back(L"\x1b[M &&");
10131090
// For this test, don't use any modifiers
10141091
const auto modifiers = ControlKeyStates();
10151092
const auto leftMouseDown{ Control::MouseButtonState::IsLeftButtonDown };
1093+
const auto rightMouseDown{ Control::MouseButtonState::IsRightButtonDown };
10161094
const Control::MouseButtonState noMouseDown{};
10171095
const til::size fontSize{ 9, 21 };
10181096
const til::point terminalPosition0{ 0, 5 };
@@ -1027,7 +1105,6 @@ namespace ControlUnitTests
10271105
0, // timestamp
10281106
modifiers,
10291107
cursorPosition0.to_core_point());
1030-
// VERIFY_ARE_EQUAL(0u, expectedOutput.size(), L"Validate we drained all the expected output");
10311108
VERIFY_IS_FALSE(core->HasSelection());
10321109

10331110
Log::Comment(L" --- Drag to 5,5 ---");
@@ -1048,5 +1125,21 @@ namespace ControlUnitTests
10481125
modifiers,
10491126
cursorPosition1.to_core_point());
10501127
VERIFY_IS_TRUE(core->HasSelection());
1128+
1129+
// Output some text
1130+
for (; i < 5; ++i)
1131+
{
1132+
conn->WriteInput(winrt::hstring{ fmt::format(L"line {}\r\n", i) });
1133+
}
1134+
1135+
Log::Comment(L" --- Right-click to paste --- ");
1136+
expectedCopyContents = std::nullopt;
1137+
expectedPaste = true;
1138+
interactivity->PointerPressed(rightMouseDown,
1139+
WM_RBUTTONDOWN, //pointerUpdateKind
1140+
0, // timestamp
1141+
modifiers,
1142+
cursorPosition1.to_core_point());
1143+
VERIFY_IS_FALSE(core->HasSelection());
10511144
}
10521145
}

0 commit comments

Comments
 (0)