diff options
Diffstat (limited to '')
| -rw-r--r-- | .clang-format | 10 | ||||
| -rw-r--r-- | .github/workflows/ci.yml | 7 | ||||
| -rw-r--r-- | include/winapi/buffer.hpp | 4 | ||||
| -rw-r--r-- | include/winapi/cmd_line.hpp | 20 | ||||
| -rw-r--r-- | include/winapi/error.hpp | 4 | ||||
| -rw-r--r-- | include/winapi/handle.hpp | 17 | ||||
| -rw-r--r-- | include/winapi/path.hpp | 9 | ||||
| -rw-r--r-- | include/winapi/pipe.hpp | 16 | ||||
| -rw-r--r-- | include/winapi/process.hpp | 9 | ||||
| -rw-r--r-- | include/winapi/resource.hpp | 4 | ||||
| -rw-r--r-- | include/winapi/shmem.hpp | 25 | ||||
| -rw-r--r-- | include/winapi/sid.hpp | 18 | ||||
| -rw-r--r-- | src/process.cpp | 12 | ||||
| -rw-r--r-- | test/unit_tests/fixtures.hpp | 12 | ||||
| -rw-r--r-- | test/unit_tests/resource_ids.h | 4 | ||||
| -rw-r--r-- | test/unit_tests/shared/command.hpp | 9 | ||||
| -rw-r--r-- | test/unit_tests/shared/console.hpp | 28 |
17 files changed, 159 insertions, 49 deletions
diff --git a/.clang-format b/.clang-format index d0eec4c..cc61b8a 100644 --- a/.clang-format +++ b/.clang-format @@ -2,16 +2,22 @@ Language: Cpp BasedOnStyle: Chromium +IndentWidth: 4 + AccessModifierOffset: -4 +AlignConsecutiveMacros: AcrossComments +AllowShortFunctionsOnASingleLine: Empty BinPackArguments: false +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma BreakStringLiterals: false ColumnLimit: 100 IncludeBlocks: Regroup -IndentWidth: 4 SpacesBeforeTrailingComments: 1 +WrapNamespaceBodyWithEmptyLines: Always IncludeCategories: - - Regex: '^".*' + - Regex: '^".+' Priority: 1 - Regex: '^<winapi\/' Priority: 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9a2b66..896f76e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,15 @@ jobs: uses: actions/checkout@v6 with: submodules: recursive + - name: Set up clang-format + uses: egor-tensin/setup-clang@v2 + with: + # To use the latest clang-format features: + version: 22 - name: Run clang-format uses: egor-tensin/clang-format@v1 + with: + version: 22 build: strategy: diff --git a/include/winapi/buffer.hpp b/include/winapi/buffer.hpp index 1009ebb..17b7e9c 100644 --- a/include/winapi/buffer.hpp +++ b/include/winapi/buffer.hpp @@ -41,7 +41,9 @@ public: } /** Construct a buffer from a memory region. */ - Buffer(const void* src, std::size_t nb) { set(src, nb); } + Buffer(const void* src, std::size_t nb) { + set(src, nb); + } /** Replace the buffer's contents with the data from a string view. */ template <typename CharT> diff --git a/include/winapi/cmd_line.hpp b/include/winapi/cmd_line.hpp index af83cac..97ca50f 100644 --- a/include/winapi/cmd_line.hpp +++ b/include/winapi/cmd_line.hpp @@ -85,16 +85,22 @@ public: * Get argv[0] for this command line. * @return UTF-8 string. */ - std::string get_argv0() const { return m_argv0; } + std::string get_argv0() const { + return m_argv0; + } /** Test if this command line has any additional arguments besides argv[0]. */ - bool has_args() const { return !get_args().empty(); } + bool has_args() const { + return !get_args().empty(); + } /** * Get list of arguments for this command line beyond argv[0]. * @return List of UTF-8 strings. */ - const std::vector<std::string>& get_args() const { return m_args; } + const std::vector<std::string>& get_args() const { + return m_args; + } /** * Get list of arguments for this command line. @@ -103,9 +109,13 @@ public: std::vector<std::string> get_argv() const; private: - static constexpr char token_sep() { return ' '; } + static constexpr char token_sep() { + return ' '; + } - std::string escape_argv0() const { return escape(get_argv0()); } + std::string escape_argv0() const { + return escape(get_argv0()); + } std::vector<std::string> escape_args() const; diff --git a/include/winapi/error.hpp b/include/winapi/error.hpp index 259c18b..89e7c4c 100644 --- a/include/winapi/error.hpp +++ b/include/winapi/error.hpp @@ -24,7 +24,9 @@ class CategoryWindows : public std::error_category { public: CategoryWindows() = default; - const char* name() const noexcept { return "Windows"; } + const char* name() const noexcept { + return "Windows"; + } std::string message(int32_t) const; }; diff --git a/include/winapi/handle.hpp b/include/winapi/handle.hpp index 23e5a3c..c0f85f4 100644 --- a/include/winapi/handle.hpp +++ b/include/winapi/handle.hpp @@ -27,10 +27,17 @@ public: Handle() = default; explicit Handle(HANDLE); - HANDLE get() const { return m_impl.get(); } - HANDLE ptr() const { return get(); } + HANDLE get() const { + return m_impl.get(); + } - explicit operator HANDLE() const { return ptr(); } + HANDLE ptr() const { + return get(); + } + + explicit operator HANDLE() const { + return ptr(); + } bool is_valid() const; static bool is_valid(HANDLE); @@ -89,7 +96,9 @@ public: } void inherit(bool yes = true) const; - void dont_inherit() const { inherit(false); } + void dont_inherit() const { + inherit(false); + } private: struct Close { diff --git a/include/winapi/path.hpp b/include/winapi/path.hpp index 8de2559..1c9ccd7 100644 --- a/include/winapi/path.hpp +++ b/include/winapi/path.hpp @@ -17,8 +17,13 @@ public: explicit CanonicalPath(std::string_view); - std::string get() const { return m_path; } - std::string path() const { return get(); } + std::string get() const { + return m_path; + } + + std::string path() const { + return get(); + } private: std::string m_path; diff --git a/include/winapi/pipe.hpp b/include/winapi/pipe.hpp index e4f8624..70d5e81 100644 --- a/include/winapi/pipe.hpp +++ b/include/winapi/pipe.hpp @@ -18,13 +18,21 @@ public: Pipe(); /** Get the read end of the pipe. */ - Handle& read_end() { return m_read_end; } + Handle& read_end() { + return m_read_end; + } /** @overload */ - const Handle& read_end() const { return m_read_end; } + const Handle& read_end() const { + return m_read_end; + } /** Get the write end of the pipe. */ - Handle& write_end() { return m_write_end; } + Handle& write_end() { + return m_write_end; + } /** @overload */ - const Handle& write_end() const { return m_write_end; } + const Handle& write_end() const { + return m_write_end; + } private: Handle m_read_end; diff --git a/include/winapi/process.hpp b/include/winapi/process.hpp index 4d9ca28..f1f47f1 100644 --- a/include/winapi/process.hpp +++ b/include/winapi/process.hpp @@ -83,9 +83,14 @@ public: static DWORD read_permissions(); /** Get this process's ID. */ - ID get_id() const { return m_id; } + ID get_id() const { + return m_id; + } + /** Get this process's handle. */ - const Handle& get_handle() const { return m_handle; } + const Handle& get_handle() const { + return m_handle; + } /** Check if this process is running (i.e. not terminated). */ bool is_running() const; diff --git a/include/winapi/resource.hpp b/include/winapi/resource.hpp index 8b6e41b..276dedf 100644 --- a/include/winapi/resource.hpp +++ b/include/winapi/resource.hpp @@ -20,7 +20,9 @@ struct Resource { Resource(const void* data, std::size_t nb) : data{data}, nb{nb} {} /** Extract resource data into a Buffer instance. */ - Buffer copy() const { return {data, nb}; } + Buffer copy() const { + return {data, nb}; + } const void* data = nullptr; std::size_t nb = 0; diff --git a/include/winapi/shmem.hpp b/include/winapi/shmem.hpp index aecae85..c240d49 100644 --- a/include/winapi/shmem.hpp +++ b/include/winapi/shmem.hpp @@ -31,9 +31,13 @@ public: static SharedMemory open(std::string_view name); /** Get pointer to the data. */ - void* get() const { return m_addr.get(); } + void* get() const { + return m_addr.get(); + } /** @overload */ - void* ptr() const { return get(); } + void* ptr() const { + return get(); + } private: struct Unmap { @@ -87,12 +91,21 @@ public: } /** Get pointer to the object. */ - T* ptr() const { return reinterpret_cast<T*>(m_shmem.ptr()); } + T* ptr() const { + return reinterpret_cast<T*>(m_shmem.ptr()); + } /** Get reference to the object. */ - T& get() const { return *ptr(); } + T& get() const { + return *ptr(); + } - T* operator->() const { return ptr(); } - T& operator*() const { return get(); } + T* operator->() const { + return ptr(); + } + + T& operator*() const { + return get(); + } private: explicit SharedObject(SharedMemory&& shmem) : m_shmem{std::move(shmem)} {} diff --git a/include/winapi/sid.hpp b/include/winapi/sid.hpp index af4251b..008d250 100644 --- a/include/winapi/sid.hpp +++ b/include/winapi/sid.hpp @@ -26,14 +26,24 @@ public: explicit Sid(const Buffer& buffer) : m_buffer{buffer} {} - explicit operator SID&() { return get_impl(); } - explicit operator const SID&() const { return get_impl(); } + explicit operator SID&() { + return get_impl(); + } + + explicit operator const SID&() const { + return get_impl(); + } std::string to_string() const; private: - Impl& get_impl() { return *reinterpret_cast<SID*>(m_buffer.data()); } - const Impl& get_impl() const { return *reinterpret_cast<const SID*>(m_buffer.data()); } + Impl& get_impl() { + return *reinterpret_cast<SID*>(m_buffer.data()); + } + + const Impl& get_impl() const { + return *reinterpret_cast<const SID*>(m_buffer.data()); + } Buffer m_buffer; }; diff --git a/src/process.cpp b/src/process.cpp index 5886c41..e323135 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -167,11 +167,17 @@ Handle open_process(DWORD id, DWORD permissions) { class PathBuffer { public: - PathBuffer() : m_size{min_size} { m_data.resize(m_size); } + PathBuffer() : m_size{min_size} { + m_data.resize(m_size); + } - DWORD get_size() const { return m_size; } + DWORD get_size() const { + return m_size; + } - wchar_t* get_data() { return m_data.data(); } + wchar_t* get_data() { + return m_data.data(); + } void grow() { if (m_size < min_size) { diff --git a/test/unit_tests/fixtures.hpp b/test/unit_tests/fixtures.hpp index f3e8a8e..ce8e1f4 100644 --- a/test/unit_tests/fixtures.hpp +++ b/test/unit_tests/fixtures.hpp @@ -40,7 +40,9 @@ class WithParam { public: WithParam(const std::string& param_prefix) : m_value{find_param_value(param_prefix)} {} - const std::string& get_value() { return m_value; } + const std::string& get_value() { + return m_value; + } private: static std::string find_param_value(const std::string& param_prefix) { @@ -61,14 +63,18 @@ class WithEchoExe : public WithParam { public: WithEchoExe() : WithParam{"--echo_exe="} {} - const std::string& get_echo_exe() { return get_value(); } + const std::string& get_echo_exe() { + return get_value(); + } }; class WithWorkerExe : public WithParam { public: WithWorkerExe() : WithParam{"--worker_exe="}, m_cmd{worker::Command::create()} {} - const std::string& get_worker_exe() { return get_value(); } + const std::string& get_worker_exe() { + return get_value(); + } worker::Command::Shared m_cmd; }; diff --git a/test/unit_tests/resource_ids.h b/test/unit_tests/resource_ids.h index 46046bf..5aeec99 100644 --- a/test/unit_tests/resource_ids.h +++ b/test/unit_tests/resource_ids.h @@ -1,3 +1,3 @@ -#define IDS_TEST_STRING 69 +#define IDS_TEST_STRING 69 #define IDS_TEST_STRING_WIDE 70 -#define ID_TEST_DATA 420 +#define ID_TEST_DATA 420 diff --git a/test/unit_tests/shared/command.hpp b/test/unit_tests/shared/command.hpp index a24370a..95fd0d6 100644 --- a/test/unit_tests/shared/command.hpp +++ b/test/unit_tests/shared/command.hpp @@ -62,8 +62,13 @@ public: using ReadResult = std::function<void(const Result&)>; using ProcessAction = std::function<void(Action, const Args&, Result&)>; - static Shared create() { return Shared::create(COMMAND_SHMEM_NAME); } - static Shared open() { return Shared::open(COMMAND_SHMEM_NAME); } + static Shared create() { + return Shared::create(COMMAND_SHMEM_NAME); + } + + static Shared open() { + return Shared::open(COMMAND_SHMEM_NAME); + } void get_result(Action action, const SetArgs& set_args, const ReadResult& read_result) { { diff --git a/test/unit_tests/shared/console.hpp b/test/unit_tests/shared/console.hpp index 55907c2..86a317a 100644 --- a/test/unit_tests/shared/console.hpp +++ b/test/unit_tests/shared/console.hpp @@ -32,15 +32,25 @@ public: Buffer(winapi::Handle&& handle) : m_handle{std::move(handle)}, m_info{get_info(m_handle)} {} - int16_t get_columns() const { return m_info.dwSize.X; } + int16_t get_columns() const { + return m_info.dwSize.X; + } - int16_t get_lines() const { return m_info.dwSize.Y; } + int16_t get_lines() const { + return m_info.dwSize.Y; + } - int16_t get_cursor_column() const { return m_info.dwCursorPosition.X; } + int16_t get_cursor_column() const { + return m_info.dwCursorPosition.X; + } - int16_t get_cursor_line() const { return m_info.dwCursorPosition.Y; } + int16_t get_cursor_line() const { + return m_info.dwCursorPosition.Y; + } - void update() { m_info = get_info(m_handle); } + void update() { + m_info = get_info(m_handle); + } /* * This is a stupid little function to read the console screen buffer. @@ -121,9 +131,13 @@ public: return read_lines(-static_cast<int16_t>(numof_lines), -1); } - std::string read_last_line() const { return read_lines(-1, -1)[0]; } + std::string read_last_line() const { + return read_lines(-1, -1)[0]; + } - std::string read_line(int16_t n) const { return read_lines(n, n)[0]; } + std::string read_line(int16_t n) const { + return read_lines(n, n)[0]; + } private: static Info get_info(const winapi::Handle& handle) { |
