|
| 1 | +/* |
| 2 | +* Copyright (c) Microsoft Corporation. |
| 3 | +* Licensed under the MIT license. |
| 4 | +*/ |
| 5 | +#include "precomp.h" |
| 6 | +#include <WexTestClass.h> |
| 7 | + |
| 8 | +#include "../cascadia/TerminalCore/Terminal.hpp" |
| 9 | +#include "../cascadia/UnitTests_TerminalCore/MockTermSettings.h" |
| 10 | +#include "../renderer/inc/DummyRenderTarget.hpp" |
| 11 | +#include "consoletaeftemplates.hpp" |
| 12 | + |
| 13 | +using namespace WEX::Logging; |
| 14 | +using namespace WEX::TestExecution; |
| 15 | + |
| 16 | +using namespace Microsoft::Terminal::Core; |
| 17 | +using namespace winrt::Microsoft::Terminal::Settings; |
| 18 | + |
| 19 | +namespace TerminalCoreUnitTests |
| 20 | +{ |
| 21 | + class TerminalApiTests |
| 22 | + { |
| 23 | + TEST_CLASS(TerminalApiTests); |
| 24 | + |
| 25 | + struct Baton |
| 26 | + { |
| 27 | + HANDLE ev; |
| 28 | + std::wstring text; |
| 29 | + Terminal* pTerm; |
| 30 | + }; |
| 31 | + |
| 32 | + TEST_METHOD(PrintStringOfEmojiBisectingFinalColumn) |
| 33 | + { |
| 34 | + Terminal term; |
| 35 | + DummyRenderTarget emptyRT; |
| 36 | + term.Create({ 100, 100 }, 0, emptyRT); |
| 37 | + |
| 38 | + std::wstring textToPrint; |
| 39 | + textToPrint.push_back(L'A'); // A is half-width, push it in. |
| 40 | + |
| 41 | + // Put a ton of copies of a full-width emoji here. |
| 42 | + const wchar_t* emoji = L"\xD83D\xDE00"; // 1F600 is wide in https://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt |
| 43 | + for (size_t i = 0; i < 120; ++i) |
| 44 | + { |
| 45 | + textToPrint = textToPrint.append(emoji); |
| 46 | + } |
| 47 | + |
| 48 | + Baton b; |
| 49 | + b.ev = CreateEventW(nullptr, TRUE, FALSE, L"It is an event"); |
| 50 | + b.text = textToPrint; |
| 51 | + b.pTerm = &term; |
| 52 | + |
| 53 | + Log::Comment(L"Launching thread to write data."); |
| 54 | + |
| 55 | + HANDLE hThread = CreateThread( |
| 56 | + nullptr, 0, [](LPVOID c) -> DWORD { |
| 57 | + Baton& b = *reinterpret_cast<Baton*>(c); |
| 58 | + Log::Comment(L"Writing data."); |
| 59 | + b.pTerm->PrintString(b.text); |
| 60 | + Log::Comment(L"Setting event."); |
| 61 | + SetEvent(b.ev); |
| 62 | + return 0; |
| 63 | + }, |
| 64 | + (LPVOID)&b, |
| 65 | + 0, |
| 66 | + nullptr); |
| 67 | + |
| 68 | + Log::Comment(L"Waiting for the write."); |
| 69 | + switch (WaitForSingleObject(b.ev, 2000)) |
| 70 | + { |
| 71 | + case WAIT_OBJECT_0: |
| 72 | + Log::Comment(L"Didn't get stuck. Success."); |
| 73 | + break; |
| 74 | + case WAIT_TIMEOUT: |
| 75 | + Log::Comment(L"Wait timed out. It got stuck."); |
| 76 | + Log::Result(WEX::Logging::TestResults::Failed); |
| 77 | + break; |
| 78 | + case WAIT_FAILED: |
| 79 | + Log::Comment(L"Wait failed for some reason. We didn't expect this."); |
| 80 | + Log::Result(WEX::Logging::TestResults::Failed); |
| 81 | + break; |
| 82 | + default: |
| 83 | + Log::Comment(L"Wait return code that no one expected. Fail."); |
| 84 | + Log::Result(WEX::Logging::TestResults::Failed); |
| 85 | + break; |
| 86 | + } |
| 87 | + |
| 88 | + TerminateThread(hThread, 0); |
| 89 | + return; |
| 90 | + } |
| 91 | + }; |
| 92 | +} |
0 commit comments