コード例 #1
0
ファイル: zre_log_msg.c プロジェクト: codebrainz/zyre
int
zre_log_msg_test (bool verbose)
{
    printf (" * zre_log_msg: ");

    //  @selftest
    //  Simple create/destroy test
    zre_log_msg_t *self = zre_log_msg_new (0);
    assert (self);
    zre_log_msg_destroy (&self);

    //  Create pair of sockets we can send through
    zctx_t *ctx = zctx_new ();
    assert (ctx);

    void *output = zsocket_new (ctx, ZMQ_DEALER);
    assert (output);
    zsocket_bind (output, "inproc://selftest");
    void *input = zsocket_new (ctx, ZMQ_ROUTER);
    assert (input);
    zsocket_connect (input, "inproc://selftest");
    
    //  Encode/send/decode and verify each message type

    self = zre_log_msg_new (ZRE_LOG_MSG_LOG);
    zre_log_msg_set_level (self, 123);
    zre_log_msg_set_event (self, 123);
    zre_log_msg_set_node (self, 123);
    zre_log_msg_set_peer (self, 123);
    zre_log_msg_set_time (self, 123);
    zre_log_msg_set_data (self, "Life is short but Now lasts for ever");
    zre_log_msg_send (&self, output);
    
    self = zre_log_msg_recv (input);
    assert (self);
    assert (zre_log_msg_level (self) == 123);
    assert (zre_log_msg_event (self) == 123);
    assert (zre_log_msg_node (self) == 123);
    assert (zre_log_msg_peer (self) == 123);
    assert (zre_log_msg_time (self) == 123);
    assert (streq (zre_log_msg_data (self), "Life is short but Now lasts for ever"));
    zre_log_msg_destroy (&self);

    zctx_destroy (&ctx);
    //  @end

    printf ("OK\n");
    return 0;
}
コード例 #2
0
ファイル: zre_log_msg.c プロジェクト: alex-components/zyre
zmsg_t * 
zre_log_msg_encode_log (
    byte level,
    byte event,
    uint16_t node,
    uint16_t peer,
    uint64_t time,
    const char *data)
{
    zre_log_msg_t *self = zre_log_msg_new (ZRE_LOG_MSG_LOG);
    zre_log_msg_set_level (self, level);
    zre_log_msg_set_event (self, event);
    zre_log_msg_set_node (self, node);
    zre_log_msg_set_peer (self, peer);
    zre_log_msg_set_time (self, time);
    zre_log_msg_set_data (self, data);
    return zre_log_msg_encode (&self);
}
コード例 #3
0
ファイル: zre_log_msg.c プロジェクト: codebrainz/zyre
int
zre_log_msg_send_log (
    void *output,
    byte level,
    byte event,
    uint16_t node,
    uint16_t peer,
    uint64_t time,
    char *data)
{
    zre_log_msg_t *self = zre_log_msg_new (ZRE_LOG_MSG_LOG);
    zre_log_msg_set_level (self, level);
    zre_log_msg_set_event (self, event);
    zre_log_msg_set_node (self, node);
    zre_log_msg_set_peer (self, peer);
    zre_log_msg_set_time (self, time);
    zre_log_msg_set_data (self, data);
    return zre_log_msg_send (&self, output);
}
コード例 #4
0
ファイル: zre_log_msg.c プロジェクト: alex-components/zyre
int
zre_log_msg_test (bool verbose)
{
    printf (" * zre_log_msg: ");

    //  @selftest
    //  Simple create/destroy test
    zre_log_msg_t *self = zre_log_msg_new (0);
    assert (self);
    zre_log_msg_destroy (&self);

    //  Create pair of sockets we can send through
    zsock_t *input = zsock_new (ZMQ_ROUTER);
    assert (input);
    zsock_connect (input, "inproc://selftest");

    zsock_t *output = zsock_new (ZMQ_DEALER);
    assert (output);
    zsock_bind (output, "inproc://selftest");

    //  Encode/send/decode and verify each message type
    int instance;
    zre_log_msg_t *copy;
    self = zre_log_msg_new (ZRE_LOG_MSG_LOG);
    
    //  Check that _dup works on empty message
    copy = zre_log_msg_dup (self);
    assert (copy);
    zre_log_msg_destroy (&copy);

    zre_log_msg_set_level (self, 123);
    zre_log_msg_set_event (self, 123);
    zre_log_msg_set_node (self, 123);
    zre_log_msg_set_peer (self, 123);
    zre_log_msg_set_time (self, 123);
    zre_log_msg_set_data (self, "Life is short but Now lasts for ever");
    //  Send twice from same object
    zre_log_msg_send_again (self, output);
    zre_log_msg_send (&self, output);

    for (instance = 0; instance < 2; instance++) {
        self = zre_log_msg_recv (input);
        assert (self);
        assert (zre_log_msg_routing_id (self));
        
        assert (zre_log_msg_level (self) == 123);
        assert (zre_log_msg_event (self) == 123);
        assert (zre_log_msg_node (self) == 123);
        assert (zre_log_msg_peer (self) == 123);
        assert (zre_log_msg_time (self) == 123);
        assert (streq (zre_log_msg_data (self), "Life is short but Now lasts for ever"));
        zre_log_msg_destroy (&self);
    }

    zsock_destroy (&input);
    zsock_destroy (&output);
    //  @end

    printf ("OK\n");
    return 0;
}