1+ /*
2+ * Copyright (C) 2025, Yasumasa Suenaga
3+ *
4+ * This program is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public License
6+ * as published by the Free Software Foundation; either version 2
7+ * of the License, or (at your option) any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17+ * 02110-1301, USA.
18+ */
19+ #include " pch.h"
20+ #include " CppUnitTest.h"
21+
22+ #include " TerminalRedirectorBase.h"
23+
24+ using namespace Microsoft ::VisualStudio::CppUnitTestFramework;
25+
26+ static constexpr DWORD stdin_redirector_result = 100 ;
27+ static constexpr DWORD stdout_redirector_result = 200 ;
28+
29+ static DWORD WINAPI RedirectorTestThreadEntry (_In_ LPVOID lpParameter) {
30+ return reinterpret_cast <DWORD>(lpParameter);
31+ }
32+
33+ namespace SimpleComTest
34+ {
35+
36+ class TestRedirector : public SimpleCom ::TerminalRedirectorBase
37+ {
38+ public:
39+ TestRedirector () : SimpleCom::TerminalRedirectorBase(INVALID_HANDLE_VALUE) {}
40+
41+ virtual std::tuple<LPTHREAD_START_ROUTINE, LPVOID> GetStdInRedirector () override
42+ {
43+ return { &RedirectorTestThreadEntry, reinterpret_cast <LPVOID>(stdin_redirector_result) };
44+ }
45+
46+ virtual std::tuple<LPTHREAD_START_ROUTINE, LPVOID> GetStdOutRedirector () override
47+ {
48+ return { &RedirectorTestThreadEntry, reinterpret_cast <LPVOID>(stdout_redirector_result) };
49+ }
50+
51+ DWORD GetStdInRedirectorResult ()
52+ {
53+ DWORD result;
54+ if (!GetExitCodeThread (_hThreadStdIn, &result)) {
55+ result = -1 ;
56+ }
57+ return result;
58+ }
59+
60+ DWORD GetStdOutRedirectorResult ()
61+ {
62+ DWORD result;
63+ if (!GetExitCodeThread (_hThreadStdOut, &result)) {
64+ result = -1 ;
65+ }
66+ return result;
67+ }
68+
69+ };
70+
71+ TEST_CLASS (TerminalRedirectorBaseTest)
72+ {
73+ public:
74+
75+ TEST_METHOD (RedirectorTest)
76+ {
77+ TestRedirector redirector;
78+ redirector.StartRedirector ();
79+ redirector.AwaitTermination ();
80+
81+ Assert::AreEqual (stdin_redirector_result, redirector.GetStdInRedirectorResult ());
82+ Assert::AreEqual (stdout_redirector_result, redirector.GetStdOutRedirectorResult ());
83+ }
84+
85+ TEST_METHOD (ReattachableTest) {
86+ TestRedirector redirector;
87+ Assert::IsFalse (redirector.Reattachable ());
88+ }
89+
90+ };
91+
92+ }
0 commit comments