From 68ed09d929929bdfc989128fc09752e0190101fe Mon Sep 17 00:00:00 2001 From: Fei Chong Date: Thu, 8 Nov 2018 17:26:56 +0800 Subject: [PATCH] Update C++11 version: renaming Tcp -> TCP * Migrate the project from C++14 to C++11. All tests passed. * Remove CONSTEXPR_SPECIFIER macro cause fall back to const in c++11. * Remove C++14 code in test/main.cpp Change sample code from C++14 to C++11 in README.md * Fixed warnings in old-version gcc since C++11 doesn't support empty braced initialization well. * Fixed warnings in old-version gcc since C++11 doesn't support empty braced initialization well. * renaming * fixed conan cpp * fixed appveyor configuration * skip tests from libuv * Add line-feed to tcp.hpp:21 --- .conan/test_package/test_package.cpp | 18 +++--- CMakeLists.txt | 6 +- README.md | 39 ++++++------ appveyor.yml | 2 +- src/uvw/handle.hpp | 20 +++---- src/uvw/loop.hpp | 2 +- src/uvw/stream.hpp | 6 +- src/uvw/tcp.hpp | 18 +++--- src/uvw/udp.hpp | 14 ++--- src/uvw/util.hpp | 2 +- test/main.cpp | 28 ++++----- test/uvw/tcp.cpp | 88 ++++++++++++++-------------- test/uvw/udp.cpp | 48 +++++++-------- test/uvw/util.cpp | 4 +- 14 files changed, 149 insertions(+), 146 deletions(-) diff --git a/.conan/test_package/test_package.cpp b/.conan/test_package/test_package.cpp index 8f08f9bd..2ae52b31 100644 --- a/.conan/test_package/test_package.cpp +++ b/.conan/test_package/test_package.cpp @@ -4,13 +4,13 @@ #include void listen(uvw::Loop &loop) { - std::shared_ptr tcp = loop.resource(); + std::shared_ptr tcp = loop.resource(); - tcp->once([](const uvw::ListenEvent &, uvw::TcpHandle &srv) { - std::shared_ptr client = srv.loop().resource(); + tcp->once([](const uvw::ListenEvent &, uvw::TCPHandle &srv) { + std::shared_ptr client = srv.loop().resource(); - client->on([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TcpHandle &) { ptr->close(); }); - client->on([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); }); + client->on([ptr = srv.shared_from_this()](const uvw::CloseEvent &, uvw::TCPHandle &) { ptr->close(); }); + client->on([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); }); srv.accept(*client); client->read(); @@ -21,11 +21,11 @@ void listen(uvw::Loop &loop) { } void conn(uvw::Loop &loop) { - auto tcp = loop.resource(); + auto tcp = loop.resource(); - tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* handle errors */ }); + tcp->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ }); - tcp->once([](const uvw::ConnectEvent &, uvw::TcpHandle &tcp) { + tcp->once([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) { auto dataWrite = std::unique_ptr(new char[2]{ 'b', 'c' }); tcp.write(std::move(dataWrite), 2); tcp.close(); @@ -45,4 +45,4 @@ int main() { std::cout << "Done!\n"; return EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/CMakeLists.txt b/CMakeLists.txt index bb5ee5b8..d9f03e76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,8 @@ if(DOXYGEN_FOUND) endif() if(BUILD_TESTING) - enable_testing() + set(BUILD_TESTING OFF) + set(GOOGLETEST_DEPS_DIR ${PROJECT_DEPS_DIR}/googletest) set(LIBUV_DEPS_DIR ${PROJECT_DEPS_DIR}/libuv) @@ -83,6 +84,9 @@ if(BUILD_TESTING) add_subdirectory(${LIBUV_DEPS_DIR}) include_directories(${LIBUV_DEPS_DIR}/include) + set(BUILD_TESTING ON) + enable_testing() + add_subdirectory(test) endif() diff --git a/README.md b/README.md index c730e0f6..b37f9b18 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,14 @@ As an example, a *handle* should be initialized before any other operation and c #include void listen(uvw::Loop &loop) { - std::shared_ptr tcp = loop.resource(); + std::shared_ptr tcp = loop.resource(); - tcp->once([](const uvw::ListenEvent &, uvw::TcpHandle &srv) { - std::shared_ptr client = srv.loop().resource(); + tcp->once([](const uvw::ListenEvent &, uvw::TCPHandle &srv) { + std::shared_ptr client = srv.loop().resource(); auto ptr = srv.shared_from_this(); - client->on([ptr](const uvw::CloseEvent &, uvw::TcpHandle &) { ptr->close(); }); - client->on([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); }); - + client->on([ptr](const uvw::CloseEvent &, uvw::TCPHandle &) { ptr->close(); }); + client->on([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); }); srv.accept(*client); client->read(); }); @@ -48,11 +47,11 @@ void listen(uvw::Loop &loop) { } void conn(uvw::Loop &loop) { - auto tcp = loop.resource(); + auto tcp = loop.resource(); - tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* handle errors */ }); + tcp->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* handle errors */ }); - tcp->once([](const uvw::ConnectEvent &, uvw::TcpHandle &tcp) { + tcp->once([](const uvw::ConnectEvent &, uvw::TCPHandle &tcp) { auto dataWrite = std::unique_ptr(new char[2]{ 'b', 'c' }); tcp.write(std::move(dataWrite), 2); tcp.close(); @@ -203,7 +202,7 @@ Available modes are: `DEFAULT`, `ONCE`, `NOWAIT`. Please refer to the documentat In order to create a resource and to bind it to the given loop, just do the following: ```cpp -auto tcp = loop.resource(); +auto tcp = loop.resource(); ``` The line above will create and initialize a tcp handle, then a shared pointer to that resource will be returned.
@@ -211,7 +210,7 @@ Users should check if pointers have been correctly initialized: in case of error Another way to create a resource is: ```cpp -auto tcp = TcpHandle::create(loop); +auto tcp = TCPHandle::create(loop); tcp->init(); ``` @@ -273,7 +272,7 @@ There exist two methods to attach an event to a resource: * `resource.once(listener)`: the listener will be automatically removed after the first event of the given type. * `resource.on(listener)`: to be used for long-running listeners. -Both of them return an object of type `ResourceType::Connection` (as an example, `TcpHandle::Connection`).
+Both of them return an object of type `ResourceType::Connection` (as an example, `TCPHandle::Connection`).
A connection object can be used later as an argument to the `erase` member function of the resource to remove the listener.
There exists also the `clear` member function to drop all the listeners at once. @@ -284,14 +283,14 @@ The code below shows how to create a simple tcp server using `uvw`: ```cpp auto loop = uvw::Loop::getDefault(); -auto tcp = loop.resource(); +auto tcp = loop.resource(); -tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { /* something went wrong */ }); +tcp->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { /* something went wrong */ }); -tcp->on([](const uvw::ListenEvent &, uvw::TcpHandle &srv) { - std::shared_ptr client = srv.loop().resource(); - client->once([](const uvw::EndEvent &, uvw::TcpHandle &client) { client.close(); }); - client->on([](const uvw::DataEvent &, uvw::TcpHandle &) { /* data received */ }); +tcp->on([](const uvw::ListenEvent &, uvw::TCPHandle &srv) { + std::shared_ptr client = srv.loop().resource(); + client->once([](const uvw::EndEvent &, uvw::TCPHandle &client) { client.close(); }); + client->on([](const uvw::DataEvent &, uvw::TCPHandle &) { /* data received */ }); srv.accept(*client); client->read(); }); @@ -300,7 +299,7 @@ tcp->bind("127.0.0.1", 4242); tcp->listen(); ``` -Note also that `uvw::TcpHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind("127.0.0.1", 4242)`.
+Note also that `uvw::TCPHandle` already supports _IPv6_ out-of-the-box. The statement above is equivalent to `tcp->bind("127.0.0.1", 4242)`.
It's suffice to explicitly specify `uvw::IPv6` as the underlying protocol to use it. The API reference is the recommended documentation for further details about resources and their methods. @@ -320,7 +319,7 @@ That being said, _going raw_ is a matter of using the `raw` member functions: ```cpp auto loop = uvw::Loop::getDefault(); -auto tcp = loop.resource(); +auto tcp = loop.resource(); uv_loop_t *raw = loop->raw(); uv_tcp_t *handle = tcp->raw(); diff --git a/appveyor.yml b/appveyor.yml index f72f762d..411e5f74 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ configuration: before_build: - cd %BUILD_DIR% - - cmake .. -G"Visual Studio 15 2017" + - cmake .. -DBUILD_TESTING=ON -G"Visual Studio 15 2017" build: parallel: true diff --git a/src/uvw/handle.hpp b/src/uvw/handle.hpp index 6f2605dd..f5322be0 100644 --- a/src/uvw/handle.hpp +++ b/src/uvw/handle.hpp @@ -99,7 +99,7 @@ public: * * * An AsyncHandle handle is always active and cannot be deactivated, * except by closing it with uv_close(). - * * A PipeHandle, TcpHandle, UDPHandle, etc. handle - basically any handle + * * A PipeHandle, TCPHandle, UDPHandle, etc. handle - basically any handle * that deals with I/O - is active when it is doing something that involves * I/O, like reading, writing, connecting, accepting new connections, etc. * * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it @@ -183,8 +183,8 @@ public: * * Gets the size of the send buffer that the operating system uses for the * socket.
- * This function works for TcpHandle, PipeHandle and UDPHandle handles on - * Unix and for TcpHandle and UDPHandle handles on Windows.
+ * This function works for TCPHandle, PipeHandle and UDPHandle handles on + * Unix and for TCPHandle and UDPHandle handles on Windows.
* Note that Linux will return double the size of the original set value. * * @return The size of the send buffer, 0 in case of errors. @@ -200,8 +200,8 @@ public: * * Sets the size of the send buffer that the operating system uses for the * socket.
- * This function works for TcpHandle, PipeHandle and UDPHandle handles on - * Unix and for TcpHandle and UDPHandle handles on Windows.
+ * This function works for TCPHandle, PipeHandle and UDPHandle handles on + * Unix and for TCPHandle and UDPHandle handles on Windows.
* Note that Linux will set double the size. * * @return True in case of success, false otherwise. @@ -215,8 +215,8 @@ public: * * Gets the size of the receive buffer that the operating system uses for * the socket.
- * This function works for TcpHandle, PipeHandle and UDPHandle handles on - * Unix and for TcpHandle and UDPHandle handles on Windows.
+ * This function works for TCPHandle, PipeHandle and UDPHandle handles on + * Unix and for TCPHandle and UDPHandle handles on Windows.
* Note that Linux will return double the size of the original set value. * * @return The size of the receive buffer, 0 in case of errors. @@ -232,8 +232,8 @@ public: * * Sets the size of the receive buffer that the operating system uses for * the socket.
- * This function works for TcpHandle, PipeHandle and UDPHandle handles on - * Unix and for TcpHandle and UDPHandle handles on Windows.
+ * This function works for TCPHandle, PipeHandle and UDPHandle handles on + * Unix and for TCPHandle and UDPHandle handles on Windows.
* Note that Linux will set double the size. * * @return True in case of success, false otherwise. @@ -247,7 +247,7 @@ public: * * Supported handles: * - * * TcpHandle + * * TCPHandle * * PipeHandle * * TTYHandle * * UDPHandle diff --git a/src/uvw/loop.hpp b/src/uvw/loop.hpp index 425bca38..c4946a3f 100644 --- a/src/uvw/loop.hpp +++ b/src/uvw/loop.hpp @@ -74,7 +74,7 @@ struct BaseHandle { * * * An AsyncHandle handle is always active and cannot be deactivated, * except by closing it with uv_close(). - * * A PipeHandle, TcpHandle, UDPHandle, etc. handle - basically any handle + * * A PipeHandle, TCPHandle, UDPHandle, etc. handle - basically any handle * that deals with I/O - is active when it is doing something that involves * I/O, like reading, writing, connecting, accepting new connections, etc. * * A CheckHandle, IdleHandle, TimerHandle, etc. handle is active when it diff --git a/src/uvw/stream.hpp b/src/uvw/stream.hpp index 1c034892..69020e28 100644 --- a/src/uvw/stream.hpp +++ b/src/uvw/stream.hpp @@ -124,7 +124,7 @@ private: * * Stream handles provide an abstraction of a duplex communication channel. * StreamHandle is an intermediate type, `uvw` provides three stream - * implementations: TcpHandle, PipeHandle and TTYHandle. + * implementations: TCPHandle, PipeHandle and TTYHandle. */ template class StreamHandle: public Handle { @@ -314,7 +314,7 @@ public: * * The pipe must be initialized with `ipc == true`. * - * `send` must be a TcpHandle or PipeHandle handle, which is a server or a + * `send` must be a TCPHandle or PipeHandle handle, which is a server or a * connection (listening or connected state). Bound sockets or pipes will be * assumed to be servers. * @@ -353,7 +353,7 @@ public: * * The pipe must be initialized with `ipc == true`. * - * `send` must be a TcpHandle or PipeHandle handle, which is a server or a + * `send` must be a TCPHandle or PipeHandle handle, which is a server or a * connection (listening or connected state). Bound sockets or pipes will be * assumed to be servers. * diff --git a/src/uvw/tcp.hpp b/src/uvw/tcp.hpp index bf199220..61dac052 100644 --- a/src/uvw/tcp.hpp +++ b/src/uvw/tcp.hpp @@ -18,7 +18,7 @@ namespace uvw { namespace details { -enum class UVTcpFlags: typename std::underlying_type::type { +enum class UVTCPFlags: typename std::underlying_type::type { IPV6ONLY = UV_TCP_IPV6ONLY }; @@ -27,13 +27,13 @@ enum class UVTcpFlags: typename std::underlying_type::type { /** - * @brief The TcpHandle handle. + * @brief The TCPHandle handle. * * TCP handles are used to represent both TCP streams and servers.
* By default, _IPv4_ is used as a template parameter. The handle already * supports _IPv6_ out-of-the-box by using `uvw::IPv6`. * - * To create a `TcpHandle` through a `Loop`, arguments follow: + * To create a `TCPHandle` through a `Loop`, arguments follow: * * * An optional integer value that indicates the flags used to initialize * the socket. @@ -42,14 +42,14 @@ enum class UVTcpFlags: typename std::underlying_type::type { * [documentation](http://docs.libuv.org/en/v1.x/tcp.html#c.uv_tcp_init_ex) * for further details. */ -class TcpHandle final: public StreamHandle { +class TCPHandle final: public StreamHandle { public: using Time = std::chrono::duration; - using Bind = details::UVTcpFlags; + using Bind = details::UVTCPFlags; using IPv4 = uvw::IPv4; using IPv6 = uvw::IPv6; - explicit TcpHandle(ConstructorAccess ca, std::shared_ptr ref, unsigned int f = {}) + explicit TCPHandle(ConstructorAccess ca, std::shared_ptr ref, unsigned int f = {}) : StreamHandle{ca, std::move(ref)}, tag{f ? FLAGS : DEFAULT}, flags{f} {} @@ -123,7 +123,7 @@ public: * * Available flags are: * - * * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only + * * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only * IPv6 is used. * * @param addr Initialized `sockaddr_in` or `sockaddr_in6` data structure. @@ -143,7 +143,7 @@ public: * * Available flags are: * - * * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only + * * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only * IPv6 is used. * * @param ip The address to which to bind. @@ -167,7 +167,7 @@ public: * * Available flags are: * - * * `TcpHandle::Bind::IPV6ONLY`: it disables dual-stack support and only + * * `TCPHandle::Bind::IPV6ONLY`: it disables dual-stack support and only * IPv6 is used. * * @param addr A valid instance of Addr. diff --git a/src/uvw/udp.hpp b/src/uvw/udp.hpp index a55177e1..a796bce0 100644 --- a/src/uvw/udp.hpp +++ b/src/uvw/udp.hpp @@ -45,7 +45,7 @@ struct UDPDataEvent { namespace details { -enum class UVUdpFlags: typename std::underlying_type::type { +enum class UVUDPFlags: typename std::underlying_type::type { IPV6ONLY = UV_UDP_IPV6ONLY, REUSEADDR = UV_UDP_REUSEADDR }; @@ -81,13 +81,13 @@ private: /** - * @brief The UdpHandle handle. + * @brief The UDPHandle handle. * * UDP handles encapsulate UDP communication for both clients and servers.
* By default, _IPv4_ is used as a template parameter. The handle already * supports _IPv6_ out-of-the-box by using `uvw::IPv6`. * - * To create an `UdpHandle` through a `Loop`, arguments follow: + * To create an `UDPHandle` through a `Loop`, arguments follow: * * * An optional integer value that indicates optional flags used to initialize * the socket. @@ -96,12 +96,12 @@ private: * [documentation](http://docs.libuv.org/en/v1.x/udp.html#c.uv_udp_init_ex) * for further details. */ -class UdpHandle final: public Handle { +class UDPHandle final: public Handle { template static void recvCallback(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const sockaddr *addr, unsigned flags) { const typename details::IpTraits::Type *aptr = reinterpret_cast::Type *>(addr); - UdpHandle &udp = *(static_cast(handle->data)); + UDPHandle &udp = *(static_cast(handle->data)); // data will be destroyed no matter of what the value of nread is std::unique_ptr data{buf->base}; @@ -121,13 +121,13 @@ class UdpHandle final: public Handle { public: using Membership = details::UVMembership; - using Bind = details::UVUdpFlags; + using Bind = details::UVUDPFlags; using IPv4 = uvw::IPv4; using IPv6 = uvw::IPv6; using Handle::Handle; - explicit UdpHandle(ConstructorAccess ca, std::shared_ptr ref, unsigned int f) + explicit UDPHandle(ConstructorAccess ca, std::shared_ptr ref, unsigned int f) : Handle{ca, std::move(ref)}, tag{FLAGS}, flags{f} {} diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index 5f7c71b6..eabc7e86 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -378,7 +378,7 @@ template Addr address(F &&f, const H *handle) noexcept { sockaddr_storage ssto; int len = sizeof(ssto); - Addr addr{}; + Addr addr; int err = std::forward(f)(handle, reinterpret_cast(&ssto), &len); diff --git a/test/main.cpp b/test/main.cpp index 7d6bf862..000dcfee 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -6,23 +6,23 @@ void listen(uvw::Loop &loop) { - std::shared_ptr tcp = loop.resource(); + std::shared_ptr tcp = loop.resource(); - tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { + tcp->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { std::cout << "error " << std::endl; }); - tcp->once([](const uvw::ListenEvent &, uvw::TcpHandle &srv) { + tcp->once([](const uvw::ListenEvent &, uvw::TCPHandle &srv) { std::cout << "listen" << std::endl; - std::shared_ptr client = srv.loop().resource(); + std::shared_ptr client = srv.loop().resource(); - client->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { + client->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { std::cout << "error " << std::endl; }); auto ptr = srv.shared_from_this(); - client->on([ptr](const uvw::CloseEvent &, uvw::TcpHandle &) { + client->on([ptr](const uvw::CloseEvent &, uvw::TCPHandle &) { std::cout << "close" << std::endl; ptr->close(); }); @@ -35,12 +35,12 @@ void listen(uvw::Loop &loop) { uvw::Addr remote = client->peer(); std::cout << "remote: " << remote.ip << " " << remote.port << std::endl; - client->on([](const uvw::DataEvent &event, uvw::TcpHandle &) { + client->on([](const uvw::DataEvent &event, uvw::TCPHandle &) { std::cout.write(event.data.get(), event.length) << std::endl; std::cout << "data length: " << event.length << std::endl; }); - client->on([](const uvw::EndEvent &, uvw::TcpHandle &handle) { + client->on([](const uvw::EndEvent &, uvw::TCPHandle &handle) { std::cout << "end" << std::endl; int count = 0; handle.loop().walk([&count](uvw::BaseHandle &) { ++count; }); @@ -51,7 +51,7 @@ void listen(uvw::Loop &loop) { client->read(); }); - tcp->once([](const uvw::CloseEvent &, uvw::TcpHandle &) { + tcp->once([](const uvw::CloseEvent &, uvw::TCPHandle &) { std::cout << "close" << std::endl; }); @@ -61,18 +61,18 @@ void listen(uvw::Loop &loop) { void conn(uvw::Loop &loop) { - auto tcp = loop.resource(); + auto tcp = loop.resource(); - tcp->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { + tcp->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { std::cout << "error " << std::endl; }); - tcp->once([](const uvw::WriteEvent &, uvw::TcpHandle &handle) { + tcp->once([](const uvw::WriteEvent &, uvw::TCPHandle &handle) { std::cout << "write" << std::endl; handle.close(); }); - tcp->once([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) { + tcp->once([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) { std::cout << "connect" << std::endl; auto dataTryWrite = std::unique_ptr(new char[1]{ 'a' }); @@ -83,7 +83,7 @@ void conn(uvw::Loop &loop) { handle.write(std::move(dataWrite), 2); }); - tcp->once([](const uvw::CloseEvent &, uvw::TcpHandle &) { + tcp->once([](const uvw::CloseEvent &, uvw::TCPHandle &) { std::cout << "close" << std::endl; }); diff --git a/test/uvw/tcp.cpp b/test/uvw/tcp.cpp index ada58cbe..50364b81 100644 --- a/test/uvw/tcp.cpp +++ b/test/uvw/tcp.cpp @@ -2,12 +2,12 @@ #include -TEST(Tcp, Functionalities) { +TEST(TCP, Functionalities) { auto loop = uvw::Loop::getDefault(); - auto handle = loop->resource(); + auto handle = loop->resource(); ASSERT_TRUE(handle->noDelay(true)); - ASSERT_TRUE(handle->keepAlive(true, uvw::TcpHandle::Time{128})); + ASSERT_TRUE(handle->keepAlive(true, uvw::TCPHandle::Time{128})); ASSERT_TRUE(handle->simultaneousAccepts()); handle->close(); @@ -15,33 +15,33 @@ TEST(Tcp, Functionalities) { } -TEST(Tcp, ReadWrite) { +TEST(TCP, ReadWrite) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto server = loop->resource(); - auto client = loop->resource(); + auto server = loop->resource(); + auto client = loop->resource(); - server->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - client->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); + server->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + client->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); - server->once([](const uvw::ListenEvent &, uvw::TcpHandle &handle) { - std::shared_ptr socket = handle.loop().resource(); + server->once([](const uvw::ListenEvent &, uvw::TCPHandle &handle) { + std::shared_ptr socket = handle.loop().resource(); - socket->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - socket->on([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); }); - socket->on([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); }); + socket->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + socket->on([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); }); + socket->on([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); }); handle.accept(*socket); socket->read(); }); - client->once([](const uvw::WriteEvent &, uvw::TcpHandle &handle) { + client->once([](const uvw::WriteEvent &, uvw::TCPHandle &handle) { handle.close(); }); - client->once([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) { + client->once([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) { ASSERT_TRUE(handle.writable()); ASSERT_TRUE(handle.readable()); @@ -59,23 +59,23 @@ TEST(Tcp, ReadWrite) { } -TEST(Tcp, SockPeer) { +TEST(TCP, SockPeer) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto server = loop->resource(); - auto client = loop->resource(); + auto server = loop->resource(); + auto client = loop->resource(); - server->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - client->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); + server->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + client->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); - server->once([&address, port](const uvw::ListenEvent &, uvw::TcpHandle &handle) { - std::shared_ptr socket = handle.loop().resource(); + server->once([&address, port](const uvw::ListenEvent &, uvw::TCPHandle &handle) { + std::shared_ptr socket = handle.loop().resource(); - socket->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - socket->on([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); }); - socket->on([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); }); + socket->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + socket->on([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); }); + socket->on([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); }); handle.accept(*socket); socket->read(); @@ -86,7 +86,7 @@ TEST(Tcp, SockPeer) { ASSERT_EQ(addr.port, decltype(addr.port){port}); }); - client->once([&address](const uvw::ConnectEvent &, uvw::TcpHandle &handle) { + client->once([&address](const uvw::ConnectEvent &, uvw::TCPHandle &handle) { uvw::Addr addr = handle.peer(); ASSERT_EQ(addr.ip, address); @@ -103,33 +103,33 @@ TEST(Tcp, SockPeer) { } -TEST(Tcp, Shutdown) { +TEST(TCP, Shutdown) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto server = loop->resource(); - auto client = loop->resource(); + auto server = loop->resource(); + auto client = loop->resource(); - server->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - client->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); + server->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + client->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); - server->once([](const uvw::ListenEvent &, uvw::TcpHandle &handle) { - std::shared_ptr socket = handle.loop().resource(); + server->once([](const uvw::ListenEvent &, uvw::TCPHandle &handle) { + std::shared_ptr socket = handle.loop().resource(); - socket->on([](const uvw::ErrorEvent &, uvw::TcpHandle &) { FAIL(); }); - socket->on([&handle](const uvw::CloseEvent &, uvw::TcpHandle &) { handle.close(); }); - socket->on([](const uvw::EndEvent &, uvw::TcpHandle &sock) { sock.close(); }); + socket->on([](const uvw::ErrorEvent &, uvw::TCPHandle &) { FAIL(); }); + socket->on([&handle](const uvw::CloseEvent &, uvw::TCPHandle &) { handle.close(); }); + socket->on([](const uvw::EndEvent &, uvw::TCPHandle &sock) { sock.close(); }); handle.accept(*socket); socket->read(); }); - client->once([](const uvw::ShutdownEvent &, uvw::TcpHandle &handle) { + client->once([](const uvw::ShutdownEvent &, uvw::TCPHandle &handle) { handle.close(); }); - client->once([](const uvw::ConnectEvent &, uvw::TcpHandle &handle) { + client->once([](const uvw::ConnectEvent &, uvw::TCPHandle &handle) { handle.shutdown(); }); @@ -141,9 +141,9 @@ TEST(Tcp, Shutdown) { } -TEST(Tcp, WriteError) { +TEST(TCP, WriteError) { auto loop = uvw::Loop::getDefault(); - auto handle = loop->resource(); + auto handle = loop->resource(); bool checkWriteSmartPtrErrorEvent = false; bool checkWriteNakedPtrErrorEvent = false; @@ -151,13 +151,13 @@ TEST(Tcp, WriteError) { bool checkTryWriteNakedPtrErrorEvent = false; handle->close(); - handle->once([&checkWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TcpHandle &) { checkWriteSmartPtrErrorEvent = true; }); + handle->once([&checkWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkWriteSmartPtrErrorEvent = true; }); handle->write(std::unique_ptr{}, 0); - handle->once([&checkWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TcpHandle &) { checkWriteNakedPtrErrorEvent = true; }); + handle->once([&checkWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkWriteNakedPtrErrorEvent = true; }); handle->write(nullptr, 0); - handle->once([&checkTryWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TcpHandle &) { checkTryWriteSmartPtrErrorEvent = true; }); + handle->once([&checkTryWriteSmartPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkTryWriteSmartPtrErrorEvent = true; }); handle->tryWrite(std::unique_ptr{}, 0); - handle->once([&checkTryWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TcpHandle &) { checkTryWriteNakedPtrErrorEvent = true; }); + handle->once([&checkTryWriteNakedPtrErrorEvent](const uvw::ErrorEvent &, uvw::TCPHandle &) { checkTryWriteNakedPtrErrorEvent = true; }); handle->tryWrite(nullptr, 0); loop->run(); diff --git a/test/uvw/udp.cpp b/test/uvw/udp.cpp index ad61551d..2b6ba400 100644 --- a/test/uvw/udp.cpp +++ b/test/uvw/udp.cpp @@ -2,13 +2,13 @@ #include -TEST(Udp, Functionalities) { +TEST(UDP, Functionalities) { auto loop = uvw::Loop::getDefault(); - auto handle = loop->resource(); + auto handle = loop->resource(); - ASSERT_FALSE(handle->multicastMembership("0.0.0.0", "127.0.0.1", uvw::UdpHandle::Membership::JOIN_GROUP)); - ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UdpHandle::Membership::JOIN_GROUP)); - ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UdpHandle::Membership::LEAVE_GROUP)); + ASSERT_FALSE(handle->multicastMembership("0.0.0.0", "127.0.0.1", uvw::UDPHandle::Membership::JOIN_GROUP)); + ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UDPHandle::Membership::JOIN_GROUP)); + ASSERT_TRUE(handle->multicastMembership("224.0.0.1", "127.0.0.1", uvw::UDPHandle::Membership::LEAVE_GROUP)); ASSERT_TRUE(handle->multicastLoop(true)); ASSERT_TRUE(handle->multicastTtl(42)); ASSERT_TRUE(handle->multicastInterface("127.0.0.1")); @@ -21,14 +21,14 @@ TEST(Udp, Functionalities) { } -TEST(Udp, BindRecvStop) { +TEST(UDP, BindRecvStop) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto handle = loop->resource(); + auto handle = loop->resource(); - handle->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); + handle->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); handle->bind(address, port); handle->recv(); @@ -39,18 +39,18 @@ TEST(Udp, BindRecvStop) { } -TEST(Udp, ReadTrySend) { +TEST(UDP, ReadTrySend) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto server = loop->resource(); - auto client = loop->resource(); + auto server = loop->resource(); + auto client = loop->resource(); - server->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); - client->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); + server->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); + client->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); - server->once([&client](const uvw::UDPDataEvent &, uvw::UdpHandle &handle) { + server->once([&client](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) { client->close(); handle.close(); }); @@ -70,22 +70,22 @@ TEST(Udp, ReadTrySend) { } -TEST(Udp, ReadSend) { +TEST(UDP, ReadSend) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto server = loop->resource(); - auto client = loop->resource(); + auto server = loop->resource(); + auto client = loop->resource(); - server->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); - client->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); + server->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); + client->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); - server->once([](const uvw::UDPDataEvent &, uvw::UdpHandle &handle) { + server->once([](const uvw::UDPDataEvent &, uvw::UDPHandle &handle) { handle.close(); }); - client->once([](const uvw::SendEvent &, uvw::UdpHandle &handle) { + client->once([](const uvw::SendEvent &, uvw::UDPHandle &handle) { handle.close(); }); @@ -104,14 +104,14 @@ TEST(Udp, ReadSend) { } -TEST(Udp, Sock) { +TEST(UDP, Sock) { const std::string address = std::string{"127.0.0.1"}; const unsigned int port = 4242; auto loop = uvw::Loop::getDefault(); - auto handle = loop->resource(); + auto handle = loop->resource(); - handle->on([](const uvw::ErrorEvent &, uvw::UdpHandle &) { FAIL(); }); + handle->on([](const uvw::ErrorEvent &, uvw::UDPHandle &) { FAIL(); }); handle->bind(address, port); handle->recv(); diff --git a/test/uvw/util.cpp b/test/uvw/util.cpp index 5c4b43f0..a673f9bd 100644 --- a/test/uvw/util.cpp +++ b/test/uvw/util.cpp @@ -113,9 +113,9 @@ TEST(Util, Utilities) { guessHandle(tag{}, uvw::HandleType::IDLE); guessHandle(tag{}, uvw::HandleType::PIPE); guessHandle(tag{}, uvw::HandleType::PREPARE); - guessHandle(tag{}, uvw::HandleType::TCP); + guessHandle(tag{}, uvw::HandleType::TCP); guessHandle(tag{}, uvw::HandleType::TIMER); - guessHandle(tag{}, uvw::HandleType::UDP); + guessHandle(tag{}, uvw::HandleType::UDP); guessHandle(tag{}, uvw::HandleType::SIGNAL); auto cpuInfo = uvw::Utilities::cpuInfo();