diff options
Diffstat (limited to '')
| -rw-r--r-- | .clang-format | 3 | ||||
| -rw-r--r-- | include/winapi/handle.hpp | 7 | ||||
| -rw-r--r-- | src/error.cpp | 6 | ||||
| -rw-r--r-- | src/file.cpp | 16 | ||||
| -rw-r--r-- | src/handle.cpp | 3 | ||||
| -rw-r--r-- | src/process.cpp | 25 | ||||
| -rw-r--r-- | src/shmem.cpp | 3 | ||||
| -rw-r--r-- | test/unit_tests/cmd_line.cpp | 10 | ||||
| -rw-r--r-- | test/unit_tests/process_worker.cpp | 34 | ||||
| -rw-r--r-- | test/unit_tests/shared/console.hpp | 3 | ||||
| -rw-r--r-- | test/unit_tests/shared/worker.hpp | 15 | ||||
| -rw-r--r-- | test/unit_tests/worker/worker.cpp | 18 |
12 files changed, 86 insertions, 57 deletions
diff --git a/.clang-format b/.clang-format index cc61b8a..25d1caf 100644 --- a/.clang-format +++ b/.clang-format @@ -5,14 +5,17 @@ BasedOnStyle: Chromium IndentWidth: 4 AccessModifierOffset: -4 +AlignAfterOpenBracket: BlockIndent AlignConsecutiveMacros: AcrossComments AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false +BinPackParameters: OnePerLine BreakConstructorInitializers: BeforeComma BreakInheritanceList: BeforeComma BreakStringLiterals: false ColumnLimit: 100 IncludeBlocks: Regroup +PenaltyReturnTypeOnItsOwnLine: 1000 SpacesBeforeTrailingComments: 1 WrapNamespaceBodyWithEmptyLines: Always diff --git a/include/winapi/handle.hpp b/include/winapi/handle.hpp index c0f85f4..a440069 100644 --- a/include/winapi/handle.hpp +++ b/include/winapi/handle.hpp @@ -88,9 +88,10 @@ public: * Write data to this handle. * @param src Binary data to write. */ - template <typename CharT, - typename Traits = std::char_traits<CharT>, - typename Allocator = std::allocator<CharT>> + template < + typename CharT, + typename Traits = std::char_traits<CharT>, + typename Allocator = std::allocator<CharT>> void write(const std::basic_string<CharT, Traits, Allocator>& src) const { write(std::basic_string_view<CharT>{src}); } diff --git a/src/error.cpp b/src/error.cpp index 7266e63..4993866 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -39,7 +39,8 @@ std::string format_message(int32_t code) { MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<wchar_t*>(&buf), 0, - NULL); + NULL + ); if (0 == len) { ::LocalFree(buf); @@ -60,7 +61,8 @@ std::string CategoryWindows::message(int32_t code) const { std::system_error windows(DWORD code, const char* function) { static_assert(sizeof(DWORD) == sizeof(int32_t), "Aren't DWORDs the same size as ints?"); return std::system_error{ - static_cast<int32_t>(code), category_windows(), build_what(code, function)}; + static_cast<int32_t>(code), category_windows(), build_what(code, function) + }; } } // namespace winapi::error diff --git a/src/file.cpp b/src/file.cpp index 7d1df8e..9c004c2 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -65,13 +65,15 @@ File open_file(std::wstring_view path, const CreateFileParams& params) { attributes.nLength = sizeof(attributes); attributes.bInheritHandle = TRUE; - const auto handle = ::CreateFileW(path.data(), - params.dwDesiredAccess, - params.dwShareMode, - &attributes, - params.dwCreationDisposition, - FILE_ATTRIBUTE_NORMAL, - NULL); + const auto handle = ::CreateFileW( + path.data(), + params.dwDesiredAccess, + params.dwShareMode, + &attributes, + params.dwCreationDisposition, + FILE_ATTRIBUTE_NORMAL, + NULL + ); if (handle == INVALID_HANDLE_VALUE) { throw error::windows(GetLastError(), "CreateFileW"); diff --git a/src/handle.cpp b/src/handle.cpp index 916b8ae..89a9c6e 100644 --- a/src/handle.cpp +++ b/src/handle.cpp @@ -21,7 +21,8 @@ namespace { std::runtime_error write_file_incomplete(std::size_t expected, std::size_t actual) { return std::runtime_error{ - std::format("WriteFile could only write {} bytes instead of {}", actual, expected)}; + std::format("WriteFile could only write {} bytes instead of {}", actual, expected) + }; } bool is_std_handle(HANDLE handle) { diff --git a/src/process.cpp b/src/process.cpp index e323135..b251003 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -92,16 +92,18 @@ Handle create_process(ProcessParameters& params) { { auto cmd_line = escape_command_line(params.cmd_line); - const auto ret = ::CreateProcessW(NULL, - cmd_line.data(), - NULL, - NULL, - TRUE, - dwCreationFlags, - NULL, - NULL, - &startup_info, - &child_info); + const auto ret = ::CreateProcessW( + NULL, + cmd_line.data(), + NULL, + NULL, + TRUE, + dwCreationFlags, + NULL, + NULL, + &startup_info, + &child_info + ); if (!ret) { throw error::windows(GetLastError(), "CreateProcessW"); @@ -392,7 +394,8 @@ Resource Process::get_resource(uint32_t id) { if (data == NULL) throw std::runtime_error{ - std::format("Couldn't get data pointer for resource with ID {}", id)}; + std::format("Couldn't get data pointer for resource with ID {}", id) + }; const auto nb = ::SizeofResource(module, src); diff --git a/src/shmem.cpp b/src/shmem.cpp index 0d747b3..fd42a6d 100644 --- a/src/shmem.cpp +++ b/src/shmem.cpp @@ -45,7 +45,8 @@ SharedMemory SharedMemory::create(std::string_view name, std::size_t nb) { const auto nb_high = static_cast<DWORD>(nb64 >> 32); const auto mapping_impl = ::CreateFileMappingW( - INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, nb_high, nb_low, widen(name).c_str()); + INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, nb_high, nb_low, widen(name).c_str() + ); if (mapping_impl == NULL) { throw error::windows(GetLastError(), "CreateFileMappingW"); diff --git a/test/unit_tests/cmd_line.cpp b/test/unit_tests/cmd_line.cpp index 42f4a93..df34fb1 100644 --- a/test/unit_tests/cmd_line.cpp +++ b/test/unit_tests/cmd_line.cpp @@ -75,10 +75,12 @@ BOOST_AUTO_TEST_CASE(to_string) { BOOST_TEST(cmd_line.to_string() == expected); } -BOOST_DATA_TEST_CASE(msdn_parse, - boost::unit_test::data::make(msdn_string) ^ msdn_argv, - input, - expected) { +BOOST_DATA_TEST_CASE( + msdn_parse, + boost::unit_test::data::make(msdn_string) ^ msdn_argv, + input, + expected +) { const auto cmd_line = CommandLine::parse(input); const auto actual = cmd_line.get_argv(); BOOST_TEST(actual == expected, "actual: " << actual); diff --git a/test/unit_tests/process_worker.cpp b/test/unit_tests/process_worker.cpp index a08ab10..9999798 100644 --- a/test/unit_tests/process_worker.cpp +++ b/test/unit_tests/process_worker.cpp @@ -69,10 +69,12 @@ void check_std_handles(Worker& worker, const StdHandles& expected) { } void check_std_handles_same(Worker& worker) { - check_std_handles(worker, - {::GetStdHandle(STD_INPUT_HANDLE), - ::GetStdHandle(STD_OUTPUT_HANDLE), - ::GetStdHandle(STD_ERROR_HANDLE)}); + check_std_handles( + worker, + {::GetStdHandle(STD_INPUT_HANDLE), + ::GetStdHandle(STD_OUTPUT_HANDLE), + ::GetStdHandle(STD_ERROR_HANDLE)} + ); } void check_std_handles_different(Worker& worker) { @@ -186,7 +188,8 @@ BOOST_FIXTURE_TEST_CASE(create_inherit_override, WithWorkerExe) { Pipe stdin_pipe, stderr_pipe; const StdHandles expected_handles{ - stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get()}; + stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get() + }; process::IO io; io.std_in = process::Stdin{stdin_pipe}; @@ -199,8 +202,9 @@ BOOST_FIXTURE_TEST_CASE(create_inherit_override, WithWorkerExe) { check_write(worker); check_console_buffer_inherit(worker, {worker::test_data::out()}); BOOST_TEST(worker.exit() == 0); - check_redirected_output(stderr_pipe.read_end().read(), - {worker::test_data::err(), worker::test_data::err()}); + check_redirected_output( + stderr_pipe.read_end().read(), {worker::test_data::err(), worker::test_data::err()} + ); } BOOST_FIXTURE_TEST_CASE(create_none, WithWorkerExe) { @@ -223,7 +227,8 @@ BOOST_FIXTURE_TEST_CASE(create_none_override, WithWorkerExe) { Pipe stdin_pipe, stderr_pipe; const StdHandles expected_handles{ - stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get()}; + stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get() + }; process::IO io; io.std_in = process::Stdin{stdin_pipe}; @@ -236,8 +241,9 @@ BOOST_FIXTURE_TEST_CASE(create_none_override, WithWorkerExe) { check_write(worker); check_console_buffer_none(worker, {worker::test_data::out()}); BOOST_TEST(worker.exit() == 0); - check_redirected_output(stderr_pipe.read_end().read(), - {worker::test_data::err(), worker::test_data::err()}); + check_redirected_output( + stderr_pipe.read_end().read(), {worker::test_data::err(), worker::test_data::err()} + ); } BOOST_FIXTURE_TEST_CASE(create_new, WithWorkerExe) { @@ -260,7 +266,8 @@ BOOST_FIXTURE_TEST_CASE(create_new_override, WithWorkerExe) { Pipe stdin_pipe, stderr_pipe; const StdHandles expected_handles{ - stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get()}; + stdin_pipe.read_end().get(), Handle::std_out().get(), stderr_pipe.write_end().get() + }; process::IO io; io.std_in = process::Stdin{stdin_pipe}; @@ -273,8 +280,9 @@ BOOST_FIXTURE_TEST_CASE(create_new_override, WithWorkerExe) { check_write(worker); check_console_buffer_new(worker, {worker::test_data::out()}); BOOST_TEST(worker.exit() == 0); - check_redirected_output(stderr_pipe.read_end().read(), - {worker::test_data::err(), worker::test_data::err()}); + check_redirected_output( + stderr_pipe.read_end().read(), {worker::test_data::err(), worker::test_data::err()} + ); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/unit_tests/shared/console.hpp b/test/unit_tests/shared/console.hpp index 86a317a..8b11d9b 100644 --- a/test/unit_tests/shared/console.hpp +++ b/test/unit_tests/shared/console.hpp @@ -107,7 +107,8 @@ public: read_region.Right = buffer_size.X - 1; if (!::ReadConsoleOutputW( - m_handle.get(), buffer.data(), buffer_size, buffer_coord, &read_region)) { + m_handle.get(), buffer.data(), buffer_size, buffer_coord, &read_region + )) { throw winapi::error::windows(GetLastError(), "ReadConsoleOutputW"); } diff --git a/test/unit_tests/shared/worker.hpp b/test/unit_tests/shared/worker.hpp index 9ba7020..fe11ddb 100644 --- a/test/unit_tests/shared/worker.hpp +++ b/test/unit_tests/shared/worker.hpp @@ -37,8 +37,9 @@ public: HWND get_console_window() { HWND ret = NULL; - m_cmd->get_result(Command::GET_CONSOLE_WINDOW, - [&ret](const Command::Result& result) { ret = result.console_window; }); + m_cmd->get_result(Command::GET_CONSOLE_WINDOW, [&ret](const Command::Result& result) { + ret = result.console_window; + }); return ret; } @@ -52,15 +53,17 @@ public: StdHandles get_std_handles() { StdHandles ret; - m_cmd->get_result(Command::GET_STD_HANDLES, - [&ret](const Command::Result& result) { ret = result.std_handles; }); + m_cmd->get_result(Command::GET_STD_HANDLES, [&ret](const Command::Result& result) { + ret = result.std_handles; + }); return ret; } StdHandles test_write() { StdHandles ret; - m_cmd->get_result(Command::TEST_WRITE, - [&ret](const Command::Result& result) { ret = result.std_handles; }); + m_cmd->get_result(Command::TEST_WRITE, [&ret](const Command::Result& result) { + ret = result.std_handles; + }); return ret; } diff --git a/test/unit_tests/worker/worker.cpp b/test/unit_tests/worker/worker.cpp index c4dadf8..6f035ff 100644 --- a/test/unit_tests/worker/worker.cpp +++ b/test/unit_tests/worker/worker.cpp @@ -96,15 +96,17 @@ int loop() { const auto cmd = Command::open(); while (!exit_loop) { - cmd->process_action([&exit_loop](Command::Action action, - const Command::Args& args, - Command::Result& result) { - if (action == Command::EXIT) { - exit_loop = true; - } else { - process_action(action, args, result); + cmd->process_action( + [&exit_loop]( + Command::Action action, const Command::Args& args, Command::Result& result + ) { + if (action == Command::EXIT) { + exit_loop = true; + } else { + process_action(action, args, result); + } } - }); + ); } return 0; } |
