def test_send(self, tco, pdu): assert tco.send(pdu, flags=nfc.llcp.MSG_DONTWAIT) is None assert tco.dequeue(1, 0, False) is None assert tco.dequeue(10, 4, False) == pdu assert tco.dequeue(10, 4) is None threading.Timer(0.01, tco.dequeue, (10, 4)).start() tco.send(pdu, 0)
def test_enqueue_state_listen_recv_connect(self, tco): tco.listen(backlog=1) tco.enqueue(nfc.llcp.pdu.Connect(tco.addr, 17)) tco.enqueue(nfc.llcp.pdu.Connect(tco.addr, 18)) tco.accept() assert tco.dequeue(128, 0) == \ nfc.llcp.pdu.DisconnectedMode(18, tco.addr, reason=0x20) assert tco.dequeue(128, 1) == \ nfc.llcp.pdu.ConnectionComplete(17, tco.addr)
def test_enqueue_state_closed_recv_any(self, tco): pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17) threading.Timer(0.01, tco.enqueue, (pdu, )).start() with pytest.raises(nfc.llcp.ConnectRefused): tco.connect(17) assert tco.state.CLOSED is True assert tco.dequeue(128, 0) == nfc.llcp.pdu.Connect(17, tco.addr) pdu = nfc.llcp.pdu.Information(tco.addr, 17, 0, 0, b'123') assert tco.enqueue(pdu) is None assert tco.dequeue(128, 0) == \ nfc.llcp.pdu.DisconnectedMode(17, tco.addr, reason=1)
def test_enqueue_state_closed_recv_any(self, tco): pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17) threading.Timer(0.01, tco.enqueue, (pdu,)).start() with pytest.raises(nfc.llcp.ConnectRefused): tco.connect(17) assert tco.state.CLOSED is True assert tco.dequeue(128, 0) == nfc.llcp.pdu.Connect(17, tco.addr) pdu = nfc.llcp.pdu.Information(tco.addr, 17, 0, 0, b'123') assert tco.enqueue(pdu) is None assert tco.dequeue(128, 0) == \ nfc.llcp.pdu.DisconnectedMode(17, tco.addr, reason=1)
def dlc(self, tco): pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 128, 1) threading.Timer(0.01, tco.enqueue, (pdu, )).start() tco.connect(17) assert tco.state.ESTABLISHED is True assert tco.dequeue(128, 4) == nfc.llcp.pdu.Connect(17, 16, 128, 1) return tco
def dlc(self, tco): pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 128, 1) threading.Timer(0.01, tco.enqueue, (pdu,)).start() tco.connect(17) assert tco.state.ESTABLISHED is True assert tco.dequeue(128, 4) == nfc.llcp.pdu.Connect(17, 16, 128, 1) return tco
def test_send(self, tco): pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122')) assert tco.send(pdu, flags=nfc.llcp.MSG_DONTWAIT) is True assert tco.dequeue(10, 4) == pdu threading.Timer(0.01, tco.dequeue, (10, 4)).start() assert tco.send(pdu, 0) is True tco.close() with pytest.raises(nfc.llcp.Error) as excinfo: tco.send(pdu, 0) assert excinfo.value.errno == errno.ESHUTDOWN
def test_poll(self, tco): pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122')) assert tco.poll("", 1.0) is None assert tco.poll("recv", 0.001) is None assert tco.enqueue(pdu) is True assert tco.poll("recv", 0.001) == pdu assert tco.poll("send", 1.0) is True assert tco.send(pdu, flags=nfc.llcp.MSG_DONTWAIT) is None assert tco.poll("send", 0.001) is False assert tco.dequeue(10, 4, False) == pdu assert tco.poll("send", 1.0) is True
def test_sendto(self, tco): pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122')) assert tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT) is True assert tco.dequeue(10, 4) == pdu assert tco.connect(2) is True with pytest.raises(nfc.llcp.Error) as excinfo: tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT) assert excinfo.value.errno == errno.EDESTADDRREQ with pytest.raises(nfc.llcp.Error) as excinfo: data = (tco.send_miu + 1) * HEX('11') tco.sendto(data, 2, flags=nfc.llcp.MSG_DONTWAIT) assert excinfo.value.errno == errno.EMSGSIZE tco.close() with pytest.raises(nfc.llcp.Error) as excinfo: tco.sendto(pdu.data, 1, 0) assert excinfo.value.errno == errno.ESHUTDOWN
def test_accept(self, tco): with pytest.raises(nfc.llcp.Error) as excinfo: tco.accept() assert excinfo.value.errno == errno.EINVAL tco.setsockopt(nfc.llcp.SO_RCVMIU, 1000) tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) tco.listen(backlog=1) assert tco.state.LISTEN is True tco.enqueue(nfc.llcp.pdu.Connect(tco.addr, 17, 500, 15)) dlc = tco.accept() assert isinstance(dlc, nfc.llcp.tco.DataLinkConnection) assert dlc.state.ESTABLISHED is True assert dlc.getsockopt(nfc.llcp.SO_RCVMIU) == 1000 assert dlc.getsockopt(nfc.llcp.SO_SNDMIU) == 500 assert dlc.getsockopt(nfc.llcp.SO_RCVBUF) == 2 assert tco.dequeue(128, 4) == \ nfc.llcp.pdu.ConnectionComplete(17, tco.addr, 1000, 2) threading.Timer(0.01, tco.close).start() with pytest.raises(nfc.llcp.Error) as excinfo: tco.accept() assert excinfo.value.errno == errno.EPIPE with pytest.raises(nfc.llcp.Error) as excinfo: tco.accept() assert excinfo.value.errno == errno.ESHUTDOWN