예제 #1
0
def test_rmr_set_get():
    """
    test set functions
    """
    sbuf = rmr.rmr_alloc_msg(MRC_SEND, SIZE)
    _assert_new_sbuf(sbuf)

    # test payload
    pay = b"\x01\x00\x80"
    rmr.set_payload_and_length(pay, sbuf)
    summary = rmr.message_summary(sbuf)
    assert summary[rmr.RMR_MS_PAYLOAD] == pay
    assert summary[rmr.RMR_MS_PAYLOAD_LEN] == 3

    # test transid (note we cant test payload because it's randomly gen)
    assert summary[rmr.RMR_MS_TRN_ID] == b""
    assert len(summary[rmr.RMR_MS_TRN_ID]) == 0
    rmr.generate_and_set_transaction_id(sbuf)
    summary = rmr.message_summary(sbuf)
    assert summary[rmr.RMR_MS_TRN_ID] != b""
    assert len(summary[rmr.RMR_MS_TRN_ID]) == 32

    # test meid
    assert rmr.rmr_get_meid(sbuf) == summary[rmr.RMR_MS_MEID] == b""
    rmr.rmr_set_meid(sbuf, b"666\x01\x00\x01")
    summary = rmr.message_summary(sbuf)
    assert rmr.rmr_get_meid(sbuf) == summary[rmr.RMR_MS_MEID] == b"666\x01"
    assert (len(summary[rmr.RMR_MS_MEID])) == 4

    # exercise the logging setter; cannot test the result
    rmr.rmr_set_vlevel(0)
예제 #2
0
def test_meid():
    """
    test meid stringification
    """
    sbuf = rmr.rmr_alloc_msg(MRC_SEND, SIZE)

    rmr.rmr_set_meid(sbuf, b"\x01\x02")
    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)[
        rmr.RMR_MS_MEID] == b"\x01\x02"
    assert len(rmr.rmr_get_meid(sbuf)) == 2

    rmr.rmr_set_meid(sbuf, b"\x00" * 31)
    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)[
        rmr.RMR_MS_MEID] == b""  # NULL bytes get truncated

    rmr.rmr_set_meid(sbuf, b"6" * 31)
    assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)[
        rmr.RMR_MS_MEID] == b"6" * 31  # string in string out

    rmr.rmr_set_meid(sbuf, b"\x01\x02")
    assert (rmr.rmr_get_meid(sbuf) ==
            rmr.message_summary(sbuf)[rmr.RMR_MS_MEID] == b"\x01\x02"
            )  # Ctypes will chop at first nil, so expect only 2 bytes back

    assert len(rmr.rmr_get_meid(sbuf)) == 2

    # test that an exception is raised for buffers which are too long
    with pytest.raises(exceptions.MeidSizeOutOfRange):
        rmr.rmr_set_meid(sbuf, b"8" * 32)
예제 #3
0
def test_alloc_fancy():
    """test allocation with setting payload, trans, mtype, subid"""
    pay = b"yoo\x01\x00\x80"
    sbuf = rmr.rmr_alloc_msg(MRC_SEND,
                             SIZE,
                             payload=pay,
                             gen_transaction_id=True,
                             mtype=14,
                             meid=b"asdf",
                             sub_id=654321)
    summary = rmr.message_summary(sbuf)
    assert summary[rmr.RMR_MS_PAYLOAD] == pay
    assert summary[rmr.RMR_MS_PAYLOAD_LEN] == 6
    assert summary[
        rmr.
        RMR_MS_TRN_ID] != b""  # hard to test what it will be, but make sure not empty
    assert len(summary[rmr.RMR_MS_TRN_ID]) == 32
    assert summary[rmr.RMR_MS_MSG_STATE] == rmr.RMR_OK
    assert summary[rmr.RMR_MS_MSG_TYPE] == sbuf.contents.mtype == 14
    assert rmr.rmr_get_meid(sbuf) == summary[rmr.RMR_MS_MEID] == b"asdf"
    assert sbuf.contents.sub_id == summary[rmr.RMR_MS_SUB_ID] == 654321