# HG changeset patch # User David Demelier # Date 1562784300 -7200 # Node ID 64f8f82ab110bfdc8442261e6d12a7341a571043 # Parent 800b025f98426a56ec5fc6b20e05bd75c56d3c3c misc: cleanup, warnings and dos2unix diff -r 800b025f9842 -r 64f8f82ab110 irccdctl/cli.cpp --- a/irccdctl/cli.cpp Wed Jul 10 20:15:00 2019 +0200 +++ b/irccdctl/cli.cpp Wed Jul 10 20:45:00 2019 +0200 @@ -705,7 +705,7 @@ void rule_list_cli::exec(ctl::controller& ctl, const std::vector&) { request(ctl, {{ "command", "rule-list" }}, [] (auto result) { - auto pos = 0; + auto pos = 0U; auto length = result["list"].size(); for (const auto& obj : result["list"]) { diff -r 800b025f9842 -r 64f8f82ab110 libirccd-daemon/irccd/daemon/server.cpp --- a/libirccd-daemon/irccd/daemon/server.cpp Wed Jul 10 20:15:00 2019 +0200 +++ b/libirccd-daemon/irccd/daemon/server.cpp Wed Jul 10 20:45:00 2019 +0200 @@ -724,7 +724,7 @@ const auto self = shared_from_this(); timer_.expires_from_now(boost::posix_time::seconds(recodelay_)); - timer_.async_wait([this, handler, self, c = conn_] (auto code) { + timer_.async_wait([handler, self, c = conn_] (auto code) { if (code != boost::asio::error::operation_aborted) handler({}); }); diff -r 800b025f9842 -r 64f8f82ab110 libirccd-test/irccd/test/js_plugin_fixture.cpp --- a/libirccd-test/irccd/test/js_plugin_fixture.cpp Wed Jul 10 20:15:00 2019 +0200 +++ b/libirccd-test/irccd/test/js_plugin_fixture.cpp Wed Jul 10 20:45:00 2019 +0200 @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include diff -r 800b025f9842 -r 64f8f82ab110 libirccd/irccd/acceptor.hpp --- a/libirccd/irccd/acceptor.hpp Wed Jul 10 20:15:00 2019 +0200 +++ b/libirccd/irccd/acceptor.hpp Wed Jul 10 20:45:00 2019 +0200 @@ -236,9 +236,9 @@ */ class ip_acceptor : public basic_socket_acceptor { private: - void open(bool ipv4, bool ipv6); + void open(bool ipv6); void set(bool ipv4, bool ipv6); - void bind(const std::string& address, std::uint16_t port, bool ipv4, bool ipv6); + void bind(const std::string& address, std::uint16_t port, bool ipv6); public: /** @@ -278,7 +278,7 @@ void accept(handler handler) override; }; -inline void ip_acceptor::open(bool ipv4, bool ipv6) +inline void ip_acceptor::open(bool ipv6) { using boost::asio::ip::tcp; @@ -299,7 +299,7 @@ acceptor_.set_option(socket_base::reuse_address(true)); } -inline void ip_acceptor::bind(const std::string& address, std::uint16_t port, bool ipv4, bool ipv6) +inline void ip_acceptor::bind(const std::string& address, std::uint16_t port, bool ipv6) { using boost::asio::ip::make_address_v4; using boost::asio::ip::make_address_v6; @@ -325,9 +325,11 @@ bool ipv6) : basic_socket_acceptor(service) { - open(ipv4, ipv6); + assert(ipv4 || ipv6); + + open(ipv6); set(ipv4, ipv6); - bind(address, port, ipv4, ipv6); + bind(address, port, ipv6); } inline void ip_acceptor::accept(handler handler) diff -r 800b025f9842 -r 64f8f82ab110 tests/src/libirccd-daemon/server/CMakeLists.txt --- a/tests/src/libirccd-daemon/server/CMakeLists.txt Wed Jul 10 20:15:00 2019 +0200 +++ b/tests/src/libirccd-daemon/server/CMakeLists.txt Wed Jul 10 20:45:00 2019 +0200 @@ -1,23 +1,23 @@ -# -# CMakeLists.txt -- CMake build system for irccd -# -# Copyright (c) 2013-2019 David Demelier -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# - -irccd_define_test( - NAME server - SOURCES main.cpp - LIBRARIES libirccd -) +# +# CMakeLists.txt -- CMake build system for irccd +# +# Copyright (c) 2013-2019 David Demelier +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +irccd_define_test( + NAME server + SOURCES main.cpp + LIBRARIES libirccd +) diff -r 800b025f9842 -r 64f8f82ab110 tests/src/libirccd-daemon/server/main.cpp --- a/tests/src/libirccd-daemon/server/main.cpp Wed Jul 10 20:15:00 2019 +0200 +++ b/tests/src/libirccd-daemon/server/main.cpp Wed Jul 10 20:45:00 2019 +0200 @@ -1,223 +1,223 @@ -/* - * main.cpp -- test server object - * - * Copyright (c) 2013-2019 David Demelier - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#define BOOST_TEST_MODULE "server" -#include - -#include -#include -#include -#include - -#include - -using std::errc; -using std::error_code; -using std::make_shared; -using std::move; -using std::ostream; -using std::shared_ptr; -using std::string; -using std::system_error; - -using boost::asio::io_context; -using boost::asio::ip::tcp; -using boost::asio::streambuf; - -using irccd::daemon::server; - -BOOST_TEST_DONT_PRINT_LOG_VALUE(errc) -BOOST_TEST_DONT_PRINT_LOG_VALUE(server::state) - -namespace irccd { - -namespace { - -class fixture { -protected: - io_context context_; - streambuf output_; - tcp::acceptor acceptor_{context_}; - tcp::socket socket_{context_}; - shared_ptr server_; - - fixture(); - - void accept(); - void feed(string); - void pair(); -}; - -void fixture::accept() -{ - acceptor_.async_accept(socket_, [] (auto code) { - if (code) - throw system_error(move(code)); - }); -} - -void fixture::feed(string data) -{ - assert(server_->get_state() != server::state::disconnected); - - ostream out(&output_); - - out << data; - out << std::flush; - - async_write(socket_, output_, [] (auto code, auto) { - if (code) - throw system_error(move(code)); - }); -} - -void fixture::pair() -{ - accept(); - - server_->connect([] (auto code) { - if (code) - throw system_error(move(code)); - }); - - context_.run(); - context_.reset(); - - BOOST_TEST(server_->get_state() == server::state::identifying); -} - -fixture::fixture() -{ - acceptor_.open(tcp::v4()); - acceptor_.bind(tcp::endpoint(tcp::v4(), 0U)); - acceptor_.listen(1); - - server_ = make_shared(context_, "test", "127.0.0.1"); - server_->set_port(acceptor_.local_endpoint().port()); - server_->set_options(server::options::ipv4); - server_->set_ping_timeout(3); -} - -BOOST_FIXTURE_TEST_SUITE(fixture_suite, fixture) - -BOOST_AUTO_TEST_SUITE(interrupts) - -/* - * This test checks that interrupting any pending operations will never - * trigger the handlers. - */ -BOOST_AUTO_TEST_CASE(not_connected_yet) -{ - accept(); - - server_->connect([] (auto code) { - BOOST_FAIL("handler called (not expected"); - }); - server_->disconnect(); - - context_.run(); -} - -/* - * This test checks that interrupting a connected server will never trigger - * handlers. - */ -BOOST_AUTO_TEST_CASE(connected) -{ - pair(); - - server_->recv([] (auto, auto) { - BOOST_FAIL("handler called (not expected"); - }); - server_->disconnect(); - - context_.run(); -} - -/* - * This test checks that interrupting the wait timer will never trigger - * handlers. - */ -BOOST_AUTO_TEST_CASE(waiting) -{ - server_->wait([] (auto) { - BOOST_FAIL("handler called (not expected"); - }); - server_->disconnect(); - - context_.run(); -} - -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(errors) - -BOOST_AUTO_TEST_CASE(timeout) -{ - pair(); - - error_code result; - - server_->recv([&] (auto code, auto) { - result = move(code); - }); - - context_.run(); - - BOOST_TEST(result == errc::timed_out); -} - -BOOST_AUTO_TEST_CASE(connection_reset) -{ - pair(); - - error_code result; - - server_->recv([&] (auto code, auto) { - result = move(code); - }); - socket_.close(); - - context_.run(); - - BOOST_TEST(result == errc::connection_reset); -} - -BOOST_AUTO_TEST_CASE(argument_list_too_long) -{ - pair(); - feed(string(2048, 'a')); - - error_code result; - - server_->recv([&] (auto code, auto) { - result = move(code); - }); - - context_.run(); - - BOOST_TEST(result == errc::argument_list_too_long); -} - -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE_END() - -} // !namespace - -} // !irccd +/* + * main.cpp -- test server object + * + * Copyright (c) 2013-2019 David Demelier + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#define BOOST_TEST_MODULE "server" +#include + +#include +#include +#include +#include + +#include + +using std::errc; +using std::error_code; +using std::make_shared; +using std::move; +using std::ostream; +using std::shared_ptr; +using std::string; +using std::system_error; + +using boost::asio::io_context; +using boost::asio::ip::tcp; +using boost::asio::streambuf; + +using irccd::daemon::server; + +BOOST_TEST_DONT_PRINT_LOG_VALUE(errc) +BOOST_TEST_DONT_PRINT_LOG_VALUE(server::state) + +namespace irccd { + +namespace { + +class fixture { +protected: + io_context context_; + streambuf output_; + tcp::acceptor acceptor_{context_}; + tcp::socket socket_{context_}; + shared_ptr server_; + + fixture(); + + void accept(); + void feed(string); + void pair(); +}; + +void fixture::accept() +{ + acceptor_.async_accept(socket_, [] (auto code) { + if (code) + throw system_error(move(code)); + }); +} + +void fixture::feed(string data) +{ + assert(server_->get_state() != server::state::disconnected); + + ostream out(&output_); + + out << data; + out << std::flush; + + async_write(socket_, output_, [] (auto code, auto) { + if (code) + throw system_error(move(code)); + }); +} + +void fixture::pair() +{ + accept(); + + server_->connect([] (auto code) { + if (code) + throw system_error(move(code)); + }); + + context_.run(); + context_.reset(); + + BOOST_TEST(server_->get_state() == server::state::identifying); +} + +fixture::fixture() +{ + acceptor_.open(tcp::v4()); + acceptor_.bind(tcp::endpoint(tcp::v4(), 0U)); + acceptor_.listen(1); + + server_ = make_shared(context_, "test", "127.0.0.1"); + server_->set_port(acceptor_.local_endpoint().port()); + server_->set_options(server::options::ipv4); + server_->set_ping_timeout(3); +} + +BOOST_FIXTURE_TEST_SUITE(fixture_suite, fixture) + +BOOST_AUTO_TEST_SUITE(interrupts) + +/* + * This test checks that interrupting any pending operations will never + * trigger the handlers. + */ +BOOST_AUTO_TEST_CASE(not_connected_yet) +{ + accept(); + + server_->connect([] (auto) { + BOOST_FAIL("handler called (not expected"); + }); + server_->disconnect(); + + context_.run(); +} + +/* + * This test checks that interrupting a connected server will never trigger + * handlers. + */ +BOOST_AUTO_TEST_CASE(connected) +{ + pair(); + + server_->recv([] (auto, auto) { + BOOST_FAIL("handler called (not expected"); + }); + server_->disconnect(); + + context_.run(); +} + +/* + * This test checks that interrupting the wait timer will never trigger + * handlers. + */ +BOOST_AUTO_TEST_CASE(waiting) +{ + server_->wait([] (auto) { + BOOST_FAIL("handler called (not expected"); + }); + server_->disconnect(); + + context_.run(); +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE(errors) + +BOOST_AUTO_TEST_CASE(timeout) +{ + pair(); + + error_code result; + + server_->recv([&] (auto code, auto) { + result = move(code); + }); + + context_.run(); + + BOOST_TEST(result == errc::timed_out); +} + +BOOST_AUTO_TEST_CASE(connection_reset) +{ + pair(); + + error_code result; + + server_->recv([&] (auto code, auto) { + result = move(code); + }); + socket_.close(); + + context_.run(); + + BOOST_TEST(result == errc::connection_reset); +} + +BOOST_AUTO_TEST_CASE(argument_list_too_long) +{ + pair(); + feed(string(2048, 'a')); + + error_code result; + + server_->recv([&] (auto code, auto) { + result = move(code); + }); + + context_.run(); + + BOOST_TEST(result == errc::argument_list_too_long); +} + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_SUITE_END() + +} // !namespace + +} // !irccd diff -r 800b025f9842 -r 64f8f82ab110 tests/src/libirccd-js/js-api-system/main.cpp --- a/tests/src/libirccd-js/js-api-system/main.cpp Wed Jul 10 20:15:00 2019 +0200 +++ b/tests/src/libirccd-js/js-api-system/main.cpp Wed Jul 10 20:45:00 2019 +0200 @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(popen) { auto ret = duk_peval_string(plugin_->get_context(), - "f = Irccd.System.popen(\"" IRCCD_EXECUTABLE " --version\", \"r\");" + "f = Irccd.System.popen(\"" IRCCD_EXECUTABLE " version\", \"r\");" "r = f.readline();" );