diff options
Diffstat (limited to 'test/unit_tests')
-rw-r--r-- | test/unit_tests/fixtures.hpp | 4 | ||||
-rw-r--r-- | test/unit_tests/shared/command.hpp | 21 | ||||
-rw-r--r-- | test/unit_tests/shared/console.hpp | 4 | ||||
-rw-r--r-- | test/unit_tests/shared/fixed_size.hpp | 2 | ||||
-rw-r--r-- | test/unit_tests/shared/worker.hpp | 33 |
5 files changed, 46 insertions, 18 deletions
diff --git a/test/unit_tests/fixtures.hpp b/test/unit_tests/fixtures.hpp index aaf6571..011fb75 100644 --- a/test/unit_tests/fixtures.hpp +++ b/test/unit_tests/fixtures.hpp @@ -59,14 +59,14 @@ private: class WithEchoExe : public WithParam { public: - WithEchoExe() : WithParam{"--echo_exe="} {} + WithEchoExe() : WithParam("--echo_exe=") {} const std::string& get_echo_exe() { return get_value(); } }; class WithWorkerExe : public WithParam { public: - WithWorkerExe() : WithParam{"--worker_exe="}, m_cmd{worker::Command::create()} {} + WithWorkerExe() : WithParam("--worker_exe="), m_cmd(worker::Command::create()) {} const std::string& get_worker_exe() { return get_value(); } diff --git a/test/unit_tests/shared/command.hpp b/test/unit_tests/shared/command.hpp index 266903f..4a91370 100644 --- a/test/unit_tests/shared/command.hpp +++ b/test/unit_tests/shared/command.hpp @@ -33,15 +33,6 @@ BOOST_STATIC_CONSTEXPR auto COMMAND_SHMEM_NAME = "shmem-test-cmd"; class Command { public: - typedef winapi::SharedObject<Command> Shared; - - static Shared create() { return Shared::create(COMMAND_SHMEM_NAME); } - static Shared open() { return Shared::open(COMMAND_SHMEM_NAME); } - - typedef boost::interprocess::interprocess_mutex mutex; - typedef boost::interprocess::interprocess_condition condition_variable; - typedef boost::interprocess::scoped_lock<mutex> lock; - enum Action { EXIT = 1, GET_CONSOLE_WINDOW, @@ -62,8 +53,18 @@ public: fixed_size::StringList<> console_buffer; }; + typedef winapi::SharedObject<Command> Shared; + + typedef boost::interprocess::interprocess_mutex mutex; + typedef boost::interprocess::interprocess_condition condition_variable; + typedef boost::interprocess::scoped_lock<mutex> lock; + typedef std::function<void(Args&)> SetArgs; typedef std::function<void(const Result&)> ReadResult; + typedef std::function<void(Action, const Args&, Result&)> ProcessAction; + + 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) { { @@ -104,8 +105,6 @@ public: return get_result(action, [](const Result&) {}); } - typedef std::function<void(Action, const Args&, Result&)> ProcessAction; - void process_action(const ProcessAction& callback) { { lock lck{m_mtx}; diff --git a/test/unit_tests/shared/console.hpp b/test/unit_tests/shared/console.hpp index faa887c..274c232 100644 --- a/test/unit_tests/shared/console.hpp +++ b/test/unit_tests/shared/console.hpp @@ -26,9 +26,9 @@ class Buffer { public: typedef CONSOLE_SCREEN_BUFFER_INFO Info; - Buffer() : m_handle{winapi::Handle::std_out()}, m_info(get_info(m_handle)) {} + Buffer() : m_handle(winapi::Handle::std_out()), m_info(get_info(m_handle)) {} - Buffer(winapi::Handle&& handle) : m_handle{std::move(handle)}, m_info(get_info(m_handle)) {} + Buffer(winapi::Handle&& handle) : m_handle(std::move(handle)), m_info(get_info(m_handle)) {} std::size_t get_columns() const { return m_info.dwSize.X; } diff --git a/test/unit_tests/shared/fixed_size.hpp b/test/unit_tests/shared/fixed_size.hpp index e4b11c7..ba9a128 100644 --- a/test/unit_tests/shared/fixed_size.hpp +++ b/test/unit_tests/shared/fixed_size.hpp @@ -38,8 +38,6 @@ public: // Lines are null-terminated, and don't store their lenghts, so... return data(); } - -private: }; // 5 lines to store is also arbitrary, set it higher if needed. diff --git a/test/unit_tests/shared/worker.hpp b/test/unit_tests/shared/worker.hpp index 320a924..a1067ac 100644 --- a/test/unit_tests/shared/worker.hpp +++ b/test/unit_tests/shared/worker.hpp @@ -9,6 +9,8 @@ #include <winapi/process.hpp> +#include <boost/config.hpp> + #include <windows.h> #include <exception> @@ -20,7 +22,23 @@ namespace worker { class Worker { public: - Worker(winapi::Process&& process) : m_cmd{Command::create()}, m_process{std::move(process)} {} + Worker(winapi::Process&& process) : m_cmd(Command::create()), m_process(std::move(process)) {} + + Worker(Worker&& other) BOOST_NOEXCEPT_OR_NOTHROW : m_cmd(std::move(other.m_cmd)), + m_process(std::move(other.m_process)) {} + + Worker& operator=(Worker other) BOOST_NOEXCEPT_OR_NOTHROW { + swap(other); + return *this; + } + + void swap(Worker& other) BOOST_NOEXCEPT_OR_NOTHROW { + using std::swap; + swap(m_cmd, other.m_cmd); + swap(m_process, other.m_process); + } + + Worker(const Worker&) = delete; ~Worker() { try { @@ -83,4 +101,17 @@ private: winapi::Process m_process; }; +inline void swap(Worker& a, Worker& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + } // namespace worker + +namespace std { + +template <> +inline void swap(worker::Worker& a, worker::Worker& b) BOOST_NOEXCEPT_OR_NOTHROW { + a.swap(b); +} + +} // namespace std |