void zproto_example_test (bool verbose) { printf (" * zproto_example:"); if (verbose) printf ("\n"); // @selftest // Simple create/destroy test zproto_example_t *self = zproto_example_new (); assert (self); zproto_example_destroy (&self); // Create pair of sockets we can send through // We must bind before connect if we wish to remain compatible with ZeroMQ < v4 zsock_t *output = zsock_new (ZMQ_DEALER); assert (output); int rc = zsock_bind (output, "inproc://selftest-zproto_example"); assert (rc == 0); zsock_t *input = zsock_new (ZMQ_ROUTER); assert (input); rc = zsock_connect (input, "inproc://selftest-zproto_example"); assert (rc == 0); // Encode/send/decode and verify each message type int instance; self = zproto_example_new (); zproto_example_set_id (self, ZPROTO_EXAMPLE_LOG); zproto_example_set_sequence (self, 123); zproto_example_set_level (self, 2); zproto_example_set_event (self, 3); zproto_example_set_node (self, 45536); zproto_example_set_peer (self, 65535); zproto_example_set_time (self, 1427261426); zproto_example_set_host (self, "localhost"); zproto_example_set_data (self, "This is the message to log"); // Send twice zproto_example_send (self, output); zproto_example_send (self, output); for (instance = 0; instance < 2; instance++) { zproto_example_recv (self, input); assert (zproto_example_routing_id (self)); assert (zproto_example_sequence (self) == 123); assert (zproto_example_level (self) == 2); assert (zproto_example_event (self) == 3); assert (zproto_example_node (self) == 45536); assert (zproto_example_peer (self) == 65535); assert (zproto_example_time (self) == 1427261426); assert (streq (zproto_example_host (self), "localhost")); assert (streq (zproto_example_data (self), "This is the message to log")); } zproto_example_set_id (self, ZPROTO_EXAMPLE_STRUCTURES); zproto_example_set_sequence (self, 123); zlist_t *structures_aliases = zlist_new (); zlist_append (structures_aliases, "First alias"); zlist_append (structures_aliases, "Second alias"); zlist_append (structures_aliases, "Third alias"); zproto_example_set_aliases (self, &structures_aliases); zhash_t *structures_headers = zhash_new (); zhash_insert (structures_headers, "endpoint", "tcp://*****:*****@example.com"); zproto_example_set_supplier_forename (self, "Leslie"); zproto_example_set_supplier_surname (self, "Lamport"); zproto_example_set_supplier_mobile (self, "01987654321"); zproto_example_set_supplier_email (self, "*****@*****.**"); // Send twice zproto_example_send (self, output); zproto_example_send (self, output); for (instance = 0; instance < 2; instance++) { zproto_example_recv (self, input); assert (zproto_example_routing_id (self)); assert (zproto_example_sequence (self) == 123); assert (streq (zproto_example_client_forename (self), "Lucius Junius")); assert (streq (zproto_example_client_surname (self), "Brutus")); assert (streq (zproto_example_client_mobile (self), "01234567890")); assert (streq (zproto_example_client_email (self), "*****@*****.**")); assert (streq (zproto_example_supplier_forename (self), "Leslie")); assert (streq (zproto_example_supplier_surname (self), "Lamport")); assert (streq (zproto_example_supplier_mobile (self), "01987654321")); assert (streq (zproto_example_supplier_email (self), "*****@*****.**")); } zproto_example_destroy (&self); zsock_destroy (&input); zsock_destroy (&output); // @end printf ("OK\n"); }
/// // Check if UUID is same as supplied value bool QZuuid::eq (const byte *compare) { bool rv = zuuid_eq (self, compare); return rv; }
void xrap_traffic_test (bool verbose) { printf (" * xrap_traffic:"); if (verbose) printf ("\n"); // @selftest // Simple create/destroy test xrap_traffic_t *self = xrap_traffic_new (); assert (self); xrap_traffic_destroy (&self); // Create pair of sockets we can send through // We must bind before connect if we wish to remain compatible with ZeroMQ < v4 zsock_t *output = zsock_new (ZMQ_DEALER); assert (output); int rc = zsock_bind (output, "inproc://selftest-xrap_traffic"); assert (rc == 0); zsock_t *input = zsock_new (ZMQ_ROUTER); assert (input); rc = zsock_connect (input, "inproc://selftest-xrap_traffic"); assert (rc == 0); // Encode/send/decode and verify each message type int instance; self = xrap_traffic_new (); xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_OPEN); xrap_traffic_set_address (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (streq (xrap_traffic_address (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PING); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_PONG); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_CONNECTION_CLOSE); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_SEND); xrap_traffic_set_timeout (self, 123); zmsg_t *xrap_send_content = zmsg_new (); xrap_traffic_set_content (self, &xrap_send_content); zmsg_addstr (xrap_traffic_content (self), "Captcha Diem"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_timeout (self) == 123); assert (zmsg_size (xrap_traffic_content (self)) == 1); char *content = zmsg_popstr (xrap_traffic_content (self)); assert (streq (content, "Captcha Diem")); zstr_free (&content); if (instance == 1) zmsg_destroy (&xrap_send_content); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_OFFER); xrap_traffic_set_route (self, "Life is short but Now lasts for ever"); xrap_traffic_set_method (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (streq (xrap_traffic_route (self), "Life is short but Now lasts for ever")); assert (streq (xrap_traffic_method (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_XRAP_DELIVER); zuuid_t *xrap_deliver_sender = zuuid_new (); xrap_traffic_set_sender (self, xrap_deliver_sender); zmsg_t *xrap_deliver_content = zmsg_new (); xrap_traffic_set_content (self, &xrap_deliver_content); zmsg_addstr (xrap_traffic_content (self), "Captcha Diem"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (zuuid_eq (xrap_deliver_sender, zuuid_data (xrap_traffic_sender (self)))); if (instance == 1) zuuid_destroy (&xrap_deliver_sender); assert (zmsg_size (xrap_traffic_content (self)) == 1); char *content = zmsg_popstr (xrap_traffic_content (self)); assert (streq (content, "Captcha Diem")); zstr_free (&content); if (instance == 1) zmsg_destroy (&xrap_deliver_content); } xrap_traffic_set_id (self, XRAP_TRAFFIC_OK); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_FAIL); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_set_id (self, XRAP_TRAFFIC_ERROR); xrap_traffic_set_status_code (self, 123); xrap_traffic_set_status_reason (self, "Life is short but Now lasts for ever"); // Send twice xrap_traffic_send (self, output); xrap_traffic_send (self, output); for (instance = 0; instance < 2; instance++) { xrap_traffic_recv (self, input); assert (xrap_traffic_routing_id (self)); assert (xrap_traffic_status_code (self) == 123); assert (streq (xrap_traffic_status_reason (self), "Life is short but Now lasts for ever")); } xrap_traffic_destroy (&self); zsock_destroy (&input); zsock_destroy (&output); // @end printf ("OK\n"); }