From 76e6bacc80be8f8f435265d9884987a4564cfaec Mon Sep 17 00:00:00 2001 From: Gudmundur Adalsteinsson Date: Sat, 16 May 2020 13:22:52 +0000 Subject: [PATCH] Move string literal into variable --- tests/active_poller.cpp | 23 +++++++++++++---------- tests/poller.cpp | 14 ++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/tests/active_poller.cpp b/tests/active_poller.cpp index df087db..55644f7 100644 --- a/tests/active_poller.cpp +++ b/tests/active_poller.cpp @@ -165,13 +165,16 @@ struct server_client_setup : common_server_client_setup zmq::event_flags events = zmq::event_flags::none; }; + +const std::string hi_str = "Hi"; + } TEST_CASE("poll basic", "[active_poller]") { server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::active_poller_t active_poller; bool message_received = false; @@ -189,7 +192,7 @@ TEST_CASE("poll basic", "[active_poller]") /// \todo this contains multiple test cases that should be split up TEST_CASE("client server", "[active_poller]") { - const std::string send_msg = "Hi"; + const std::string send_msg = hi_str; // Setup server and client server_client_setup s; @@ -258,7 +261,7 @@ TEST_CASE("remove invalid socket throws", "[active_poller]") TEST_CASE("wait on added empty handler", "[active_poller]") { server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::active_poller_t active_poller; zmq::active_poller_t::handler_type handler; CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin, handler)); @@ -320,7 +323,7 @@ TEST_CASE("poll client server", "[active_poller]") CHECK_NOTHROW(active_poller.add(s.server, zmq::event_flags::pollin, s.handler)); // client sends message - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify events CHECK_NOTHROW(active_poller.wait(std::chrono::milliseconds{500})); @@ -348,7 +351,7 @@ TEST_CASE("wait one return", "[active_poller]") event_flags) { ++count; })); // client sends message - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify events CHECK(1 == active_poller.wait(std::chrono::milliseconds{500})); @@ -358,7 +361,7 @@ TEST_CASE("wait one return", "[active_poller]") TEST_CASE("wait on move constructed active_poller", "[active_poller]") { server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::active_poller_t a; zmq::active_poller_t::handler_type handler; CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, handler)); @@ -372,7 +375,7 @@ TEST_CASE("wait on move constructed active_poller", "[active_poller]") TEST_CASE("wait on move assigned active_poller", "[active_poller]") { server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::active_poller_t a; zmq::active_poller_t::handler_type handler; CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin, handler)); @@ -395,14 +398,14 @@ TEST_CASE("received on move constructed active_poller", "[active_poller]") a.add(s.server, zmq::event_flags::pollin, [&count](zmq::event_flags) { ++ count; })); // client sends message - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify it is received CHECK(1 == a.wait(std::chrono::milliseconds{500})); CHECK(1u == count); // Move construct active_poller b zmq::active_poller_t b{std::move(a)}; // client sends message again - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify it is received CHECK(1 == b.wait(std::chrono::milliseconds{500})); CHECK(2u == count); @@ -434,7 +437,7 @@ TEST_CASE("remove from handler", "[active_poller]") CHECK(ITER_NO == active_poller.size()); // Clients send messages for (auto &s : setup_list) { - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); } // Wait for all servers to receive a message diff --git a/tests/poller.cpp b/tests/poller.cpp index 4a133f7..7244357 100644 --- a/tests/poller.cpp +++ b/tests/poller.cpp @@ -161,11 +161,13 @@ TEST_CASE("poller remove registered non empty", "[poller]") CHECK_NOTHROW(poller.remove(socket)); } +const std::string hi_str = "Hi"; + TEST_CASE("poller poll basic", "[poller]") { common_server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::poller_t poller; std::vector> events{1}; @@ -245,7 +247,7 @@ TEST_CASE("poller poll client server", "[poller]") CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin, &s.server)); // client sends message - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify events std::vector> events(1); @@ -271,7 +273,7 @@ TEST_CASE("poller wait one return", "[poller]") CHECK_NOTHROW(poller.add(s.server, zmq::event_flags::pollin)); // client sends message - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); // wait for message and verify events std::vector> events(1); @@ -281,7 +283,7 @@ TEST_CASE("poller wait one return", "[poller]") TEST_CASE("poller wait on move constructed", "[poller]") { common_server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::poller_t<> a; CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin)); zmq::poller_t<> b{std::move(a)}; @@ -295,7 +297,7 @@ TEST_CASE("poller wait on move constructed", "[poller]") TEST_CASE("poller wait on move assigned", "[poller]") { common_server_client_setup s; - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); zmq::poller_t<> a; CHECK_NOTHROW(a.add(s.server, zmq::event_flags::pollin)); zmq::poller_t<> b; @@ -323,7 +325,7 @@ TEST_CASE("poller remove from handler", "[poller]") } // Clients send messages for (auto &s : setup_list) { - CHECK_NOTHROW(s.client.send(zmq::message_t{"Hi"}, zmq::send_flags::none)); + CHECK_NOTHROW(s.client.send(zmq::message_t{hi_str}, zmq::send_flags::none)); } // Wait for all servers to receive a message