aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests/console.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-24 21:33:44 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-27 00:11:41 +0300
commita864099ba77157090c4cd12817245122c163ec24 (patch)
treef15b1f2801219fa9af6111fa28591858d87711ec /test/unit_tests/console.cpp
parentProcess: add termination methods (diff)
downloadwinapi-common-a864099ba77157090c4cd12817245122c163ec24.tar.gz
winapi-common-a864099ba77157090c4cd12817245122c163ec24.zip
rework Process API & tests
* Add separate classes ProcessParameters & ShellParameters for Process::create() and Process::shell() methods. * Add a separate "worker" executable. It's used in tests via a fairly complicated scheme, receiving orders to execute via a shared memory region. * Add tests that utilize the Console API, reading console window's screen buffer directly, making for more reliable tests & broader coverage.
Diffstat (limited to 'test/unit_tests/console.cpp')
-rw-r--r--test/unit_tests/console.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/unit_tests/console.cpp b/test/unit_tests/console.cpp
new file mode 100644
index 0000000..9eb787c
--- /dev/null
+++ b/test/unit_tests/console.cpp
@@ -0,0 +1,40 @@
+// Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
+// This file is part of the "winapi-common" project.
+// For details, see https://github.com/egor-tensin/winapi-common.
+// Distributed under the MIT License.
+
+#include "shared/console.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+BOOST_AUTO_TEST_SUITE(console_tests)
+
+BOOST_AUTO_TEST_CASE(read_last_lines) {
+ std::cout << "abc\ndef" << std::endl;
+ console::Buffer buffer;
+ const auto last = buffer.read_last_line();
+ const auto last2 = buffer.read_last_lines(2);
+ const std::string expected{"def"};
+ const std::vector<std::string> expected2{"abc", "def"};
+ BOOST_TEST(last == expected);
+ BOOST_TEST(last2 == expected2);
+}
+
+BOOST_AUTO_TEST_CASE(read_last_lines_overflow) {
+ console::Buffer buffer;
+ const std::string output(buffer.get_columns() + 5, 'X');
+ std::cout << output << std::endl;
+ buffer.update();
+ const auto last = buffer.read_last_lines(1);
+ const auto last2 = buffer.read_last_lines(2);
+ const std::vector<std::string> expected{"XXXXX"};
+ const std::vector<std::string> expected2{std::string(buffer.get_columns(), 'X'), "XXXXX"};
+ BOOST_TEST(last == expected);
+ BOOST_TEST(last2 == expected2);
+}
+
+BOOST_AUTO_TEST_SUITE_END()