END_TEST // -------------------------------------------------------------------------- /// Try to _get () a zframe pointer. START_TEST(test_msg_get_f) { sam_selftest_introduce ("test_msg_get_f"); zmsg_t *zmsg = zmsg_new (); char payload = 'a'; zframe_t *frame = zframe_new (&payload, sizeof (payload)); int rc = zmsg_push (zmsg, frame); ck_assert_int_eq (rc, 0); sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 1); zframe_t *ref; rc = sam_msg_get (msg, "f", &ref); ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 1); ck_assert (zframe_eq (ref, frame)); zframe_destroy (&ref); // check idempotency of _get () rc = sam_msg_get (msg, "f", &ref); ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 1); ck_assert (zframe_eq (ref, frame)); zframe_destroy (&ref); sam_msg_destroy (&msg); }
END_TEST // -------------------------------------------------------------------------- /// Try to _pop () a zframe pointer. START_TEST(test_msg_pop_f) { sam_selftest_introduce ("test_msg_pop_f"); zmsg_t *zmsg = zmsg_new (); char payload = 'a'; zframe_t *frame = zframe_new (&payload, sizeof (payload)), *ref = zframe_dup (frame); int rc = zmsg_push (zmsg, frame); ck_assert_int_eq (rc, 0); sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 1); zframe_t *popped; rc = sam_msg_pop (msg, "f", &popped); ck_assert_int_eq (rc, 0); ck_assert (zframe_eq (ref, popped)); ck_assert_int_eq (sam_msg_size (msg), 0); zframe_destroy (&ref); sam_msg_destroy (&msg); }
static VALUE rb_czmq_frame_eql_p(VALUE obj, VALUE other_frame) { zframe_t *other = NULL; ZmqGetFrame(obj); ZmqAssertFrame(other_frame); Data_Get_Struct(other_frame, zframe_t, other); if (!other) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!"); \ if (!(st_lookup(frames_map, (st_data_t)other, 0))) rb_raise(rb_eZmqError, "object %p has been destroyed by the ZMQ framework", (void *)other_frame); return (zframe_eq(frame, other)) ? Qtrue : Qfalse; }
bool zmsg_eq (zmsg_t *self, zmsg_t *other) { if (!self || !other) return false; if (zlist_size (self->frames) != zlist_size (other->frames)) return false; zframe_t *self_frame = (zframe_t *) zlist_first (self->frames); zframe_t *other_frame = (zframe_t *) zlist_first (other->frames); while (self_frame && other_frame) { if (!zframe_eq (self_frame, other_frame)) return false; self_frame = (zframe_t *) zlist_next (self->frames); other_frame = (zframe_t *) zlist_next (other->frames); } return true; }
/// // Return TRUE if two frames have identical size and data // If either frame is NULL, equality is always false. bool QmlZframe::eq (QmlZframe *other) { return zframe_eq (self, other->self); };
/// // Return TRUE if two frames have identical size and data // If either frame is NULL, equality is always false. bool QZframe::eq (QZframe *other) { bool rv = zframe_eq (self, other->self); return rv; }
JNIEXPORT jboolean JNICALL Java_org_zeromq_czmq_Zframe__1_1eq (JNIEnv *env, jclass c, jlong self, jlong other) { jboolean eq_ = (jboolean) zframe_eq ((zframe_t *) (intptr_t) self, (zframe_t *) (intptr_t) other); return eq_; }
Z K2(zframeeq){PC(x); PC(y); R kb(zframe_eq(VSK(x), VSK(y)));}
END_TEST // -------------------------------------------------------------------------- /// Try to _get () a combination of data. START_TEST(test_msg_get) { sam_selftest_introduce ("test_msg_get"); zmsg_t *zmsg = zmsg_new (); char *str = "str 1", *nbr = "1"; char c = 'a'; zframe_t *frame = zframe_new (&c, sizeof (c)); void *ptr = (void *) 0xbadc0de; zframe_t *ptr_f = zframe_new (&ptr, sizeof (ptr)); // compose zmsg zmsg_addstr (zmsg, str); zmsg_addstr (zmsg, nbr); zmsg_addstr (zmsg, "skipped"); zframe_t *frame_dup = zframe_dup (frame); zmsg_append (zmsg, &frame_dup); frame_dup = zframe_dup (ptr_f); zmsg_append (zmsg, &frame_dup); // create sam_msg sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 5); // test idempotent _get () int round_c; for (round_c = 0; round_c < 2; round_c++) { char *pic_str = NULL; int pic_nbr = -1; zframe_t *pic_frame = NULL; void *pic_ptr = NULL; int rc = sam_msg_get ( msg, "si?fp", &pic_str, &pic_nbr, &pic_frame, &pic_ptr); ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 5); ck_assert_str_eq (pic_str, str); ck_assert_int_eq (pic_nbr, atoi (nbr)); ck_assert (zframe_eq (pic_frame, frame)); ck_assert (pic_ptr == ptr); free (pic_str); zframe_destroy (&pic_frame); } zframe_destroy (&frame); zframe_destroy (&ptr_f); sam_msg_destroy (&msg); }
END_TEST // -------------------------------------------------------------------------- /// Try to _pop () multiple different values. START_TEST(test_msg_pop) { sam_selftest_introduce ("test_msg_pop"); zmsg_t *zmsg = zmsg_new (); // data to be pop()'d char *nbr = "17"; char *str = "test"; char a = 'a'; zframe_t *char_frame = zframe_new (&a, sizeof (a)); void *ptr = (void *) 0xbadc0de; // compose zmsg out of // a number (i) int rc = zmsg_pushstr (zmsg, nbr); ck_assert_int_eq (rc, 0); // a char * (s) rc = zmsg_pushstr (zmsg, str); ck_assert_int_eq (rc, 0); // a frame * (f) zframe_t *frame_dup = zframe_dup (char_frame); rc = zmsg_prepend (zmsg, &frame_dup); ck_assert_int_eq (rc, 0); // a void * (p) rc = zmsg_pushmem (zmsg, &ptr, sizeof (ptr)); ck_assert_int_eq (rc, 0); // values to be filled int pic_nbr; char *pic_str; zframe_t *pic_frame; void *pic_ptr; // create message sam_msg_t *msg = sam_msg_new (&zmsg); ck_assert_int_eq (sam_msg_size (msg), 4); rc = sam_msg_pop (msg, "pfsi", &pic_ptr, &pic_frame, &pic_str, &pic_nbr); // test data ck_assert_int_eq (rc, 0); ck_assert_int_eq (sam_msg_size (msg), 0); ck_assert (zframe_eq (char_frame, pic_frame)); ck_assert_int_eq (pic_nbr, atoi (nbr)); ck_assert_str_eq (pic_str, str); ck_assert_ptr_eq (pic_ptr, ptr); // clean up zframe_destroy (&char_frame); sam_msg_destroy (&msg); }