Commit 49e1b8b7 authored by sigiesec's avatar sigiesec

Problem: test case in main function

Solution: extracted test_basic function
parent 4691714d
...@@ -29,9 +29,8 @@ ...@@ -29,9 +29,8 @@
#include "testutil.hpp" #include "testutil.hpp"
int main (void) void test_basic ()
{ {
setup_test_environment();
size_t len = MAX_SOCKET_STRING; size_t len = MAX_SOCKET_STRING;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
void *ctx = zmq_ctx_new (); void *ctx = zmq_ctx_new ();
...@@ -55,7 +54,8 @@ int main (void) ...@@ -55,7 +54,8 @@ int main (void)
// Send a message to an unknown peer with mandatory routing // Send a message to an unknown peer with mandatory routing
// This will fail // This will fail
int mandatory = 1; int mandatory = 1;
rc = zmq_setsockopt (router, ZMQ_ROUTER_MANDATORY, &mandatory, sizeof (mandatory)); rc = zmq_setsockopt (router, ZMQ_ROUTER_MANDATORY, &mandatory,
sizeof (mandatory));
assert (rc == 0); assert (rc == 0);
rc = zmq_send (router, "UNKNOWN", 7, ZMQ_SNDMORE); rc = zmq_send (router, "UNKNOWN", 7, ZMQ_SNDMORE);
assert (rc == -1 && errno == EHOSTUNREACH); assert (rc == -1 && errno == EHOSTUNREACH);
...@@ -69,12 +69,12 @@ int main (void) ...@@ -69,12 +69,12 @@ int main (void)
assert (rc == 0); assert (rc == 0);
// Get message from dealer to know when connection is ready // Get message from dealer to know when connection is ready
char buffer [255]; char buffer[255];
rc = zmq_send (dealer, "Hello", 5, 0); rc = zmq_send (dealer, "Hello", 5, 0);
assert (rc == 5); assert (rc == 5);
rc = zmq_recv (router, buffer, 255, 0); rc = zmq_recv (router, buffer, 255, 0);
assert (rc == 1); assert (rc == 1);
assert (buffer [0] == 'X'); assert (buffer[0] == 'X');
// Send a message to connected dealer now // Send a message to connected dealer now
// It should work // It should work
...@@ -82,7 +82,7 @@ int main (void) ...@@ -82,7 +82,7 @@ int main (void)
assert (rc == 1); assert (rc == 1);
rc = zmq_send (router, "Hello", 5, 0); rc = zmq_send (router, "Hello", 5, 0);
assert (rc == 5); assert (rc == 5);
rc = zmq_close (router); rc = zmq_close (router);
assert (rc == 0); assert (rc == 0);
...@@ -91,6 +91,13 @@ int main (void) ...@@ -91,6 +91,13 @@ int main (void)
rc = zmq_ctx_term (ctx); rc = zmq_ctx_term (ctx);
assert (rc == 0); assert (rc == 0);
}
int main (void)
{
setup_test_environment ();
test_basic ();
return 0 ; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment