[zeromq-dev] Boost Unit Testing with 0MQ PUB/SUB Sockets

Dimiter 'malkia' Stanev malkia at gmail.com
Fri Aug 31 23:18:20 CEST 2012


I've never used BOOST, but looking at your code I don't see where are 
your conditions that the test succeeded or not?

(Or is it simply if it hangs or not? I doubt it).

e.g. shouldn't there be something like EXPECT(this) and EXPECT(that) or 
at least return that means something?

On 8/30/2012 9:24 PM, Daniel Ng wrote:
> Hi,
>
> socket_t::getsockopt() seems to erroneously report 'ZMQ_RCVMORE', but only in a
> Boost Unit Test!
>
> Here' my Boost Unit Test code:
>
> #define BOOST_TEST_MODULE MyTest
> #include <boost/test/unit_test.hpp>
>
> #include <iostream>
> #include <zmq.hpp>
> #include "zhelpers.hpp" //copied from the zguide examples directory
>
> BOOST_AUTO_TEST_CASE( MyTest )
> {
>      zmq::context_t context (1);
>
>      zmq::socket_t subscriber (context, ZMQ_SUB);
>      subscriber.connect("tcp://localhost:5556");
>
>      subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0);
>
>      s_dump(subscriber);
> }
>
> -The above gets stuck in s_dump(), waiting to receive for another message part
> that never arrives.
>
> -If I move the guts of BOOST_AUTO_TEST_CASE() into a regular main(), it's fine!
>
> Here's the server-side code:
>
> #include <zmq.hpp>
> #include <stdlib.h>
> #include <iostream>
> #include "zhelpers.hpp"
>
> int main() {
>      zmq::context_t context (1);
>      uint8_t *data = new uint8_t[1024];
>      zmq::socket_t sock (context, ZMQ_PUB);
>      sock.bind("tcp://*:5556);
>      sleep(2);
>      zmq::message_t message(1024);
>      memcpy(message.data(), data, 1024);
>
>      bool rc = sock.send(message);
>
>      return 0;
> }
>
> I'm new to Boost and 0MQ. Maybe I've done something silly?
>
> Any help would be most appreciated.
>
> 0MQ Version: 3.2.0
> Boost Library Version: 1.51.0
>
> Cheers,
> Daniel
>



More information about the zeromq-dev mailing list