[zeromq-dev] [PATCH] tests: getting rid of warnings when build with NDEBUG.

Pieter Hintjens ph at imatix.com
Fri Jul 27 07:58:24 CEST 2012


Hi Vitally,

Can you send any patch to 2.2 as a pull request, with a corresponding
issue in the issue tracker?

Thanks a lot
Pieter

On Mon, Jul 23, 2012 at 4:15 PM, Vitaliy Ivanov <vitaliy at toroki.com> wrote:
> Hi,
>
> ZMQ tree 2-x.
> I didn't use ZMQ_ASSERT as tests are not using this macro.
>
> Vitaliy
>
> ----------------------------------------------------------------------
>
> >From 12e7514e9c076f35cd525fee5f2c68a1228e53f2 Mon Sep 17 00:00:00 2001
> From: Vitaliy Ivanov <vitaliy at toroki.com>
> Date: Mon, 23 Jul 2012 16:06:13 +0300
> Subject: [PATCH] tests: getting rid of warnings when build with NDEBUG.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Correcting the following warnings when build in non asserts mode:
> a.
> testutil.hpp: In function ‘void zmqtestutil::basic_tests(const char*, int, int)’:
> testutil.hpp:114: error: unused variable ‘rc’
> b.
> test_hwm.cpp: In function ‘int main(int, char**)’:
> test_hwm.cpp:47: error: unused variable ‘sent’
> test_hwm.cpp:60: error: unused variable ‘received’
> test_hwm.cpp:64: error: unused variable ‘sent’
>
> Signed-off-by: Vitaliy Ivanov <vitalivanov at gmail.com>
> ---
>  tests/test_hwm.cpp   |   17 +++++++++--------
>  tests/test_timeo.cpp |    4 ++--
>  tests/testutil.hpp   |   17 +++++++++--------
>  3 files changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/tests/test_hwm.cpp b/tests/test_hwm.cpp
> index d73c25f..e1fcec2 100644
> --- a/tests/test_hwm.cpp
> +++ b/tests/test_hwm.cpp
> @@ -28,6 +28,7 @@ int main (int argc, char *argv [])
>  {
>      uint64_t hwm = 5;
>      int linger = 0;
> +    bool rc;
>
>      zmq::context_t context (1);
>      zmq::socket_t s1 (context, ZMQ_PULL);
> @@ -44,25 +45,25 @@ int main (int argc, char *argv [])
>          zmq::message_t msg (sizeof ("test") - 1);
>          memcpy (msg.data (), "test", sizeof ("test") - 1);
>
> -        bool sent = s2.send (msg, ZMQ_NOBLOCK);
> +        rc = s2.send (msg, ZMQ_NOBLOCK);
>
>          // Anything below HWM should be sent
>          if (i < 5) {
> -            assert (sent);
> +            assert (rc);
>          } else {
> -            assert (!sent && errno == EAGAIN);
> +            assert (!rc && errno == EAGAIN);
>          }
>      }
>
>      // There should be now 5 messages pending, consume one
>      zmq::message_t msg;
>
> -    bool received = s1.recv (&msg, 0);
> -    assert (received);
> +    rc = s1.recv (&msg, 0);
> +    assert (rc);
>
>      // Now it should be possible to send one more
> -    bool sent = s2.send (msg, 0);
> -    assert (sent);
> +    rc = s2.send (msg, 0);
> +    assert (rc);
>
> -       return 0;
> +    return 0;
>  }
> diff --git a/tests/test_timeo.cpp b/tests/test_timeo.cpp
> index b9cd512..251972e 100644
> --- a/tests/test_timeo.cpp
> +++ b/tests/test_timeo.cpp
> @@ -107,7 +107,7 @@ int main (int argc, char *argv [])
>      memcpy (zmq_msg_data (&msg), "12345678ABCDEFGH12345678abcdefgh", 32);
>      rc = zmq_send (sc, &msg, 0);
>      assert (rc == 0);
> -
> +
>      rc = zmq_recv (sb, &msg, 0);
>      assert (rc == 0);
>      assert (32 == zmq_msg_size(&msg));
> @@ -120,6 +120,6 @@ int main (int argc, char *argv [])
>      rc = zmq_term (ctx);
>      assert (rc == 0);
>
> -    return 0 ;
> +    return 0;
>  }
>
> diff --git a/tests/testutil.hpp b/tests/testutil.hpp
> index 7f182c1..550ecf0 100644
> --- a/tests/testutil.hpp
> +++ b/tests/testutil.hpp
> @@ -30,8 +30,7 @@
>
>  namespace zmqtestutil
>  {
> -
> -    using namespace std ;
> +    using namespace std;
>
>      typedef std::pair <zmq::socket_t*, zmq::socket_t*> socket_pair;
>
> @@ -68,7 +67,7 @@ namespace zmqtestutil
>          s2.send (pong, 0);
>
>          //  Return received data as std::string.
> -        return ret ;
> +        return ret;
>      }
>
>      /*  Run basic tests for the given transport.
> @@ -79,6 +78,8 @@ namespace zmqtestutil
>      */
>      void basic_tests (const char *transport_, int t1_, int t2_)
>      {
> +        int rc = 0;
> +        string returned;
>          zmq::context_t context (1);
>
>          zmq::pollitem_t items [2];
> @@ -88,7 +89,7 @@ namespace zmqtestutil
>          const string expect ("XXX");
>
>          {
> -            const string returned = zmqtestutil::ping_pong (p, expect);
> +            returned = zmqtestutil::ping_pong (p, expect);
>              assert (expect == returned);
>
>              //  Adjust socket state so that poll shows only 1 pending message.
> @@ -97,7 +98,7 @@ namespace zmqtestutil
>          }
>
>          {
> -            //  Now poll is used to singal that a message is ready to read.
> +            //  Now poll is used to signal that a message is ready to read.
>              zmq::message_t m1 (expect.size ());
>              memcpy (m1.data (), expect.c_str (), expect.size ());
>              items [0].socket = *p.first;
> @@ -111,14 +112,14 @@ namespace zmqtestutil
>
>              p.first->send (m1, 0);
>
> -            int rc = zmq::poll (&items [0], 2, -1);
> +            rc = zmq::poll (&items [0], 2, -1);
>              assert (rc == 1);
>              assert ((items [1].revents & ZMQ_POLLIN) != 0);
>
>              zmq::message_t m2;
>              p.second->recv (&m2, 0);
> -            const string ret ((char*) m2.data (), m2.size ());
> -            assert (expect == ret);
> +            returned = string((char*) m2.data (), m2.size ());
> +            assert (expect == returned);
>          }
>
>          //  Delete sockets.
> --
> 1.7.0.4
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



More information about the zeromq-dev mailing list