def test_recv(self, tco, pdu): assert tco.enqueue(pdu) is True assert tco.enqueue(pdu) is False tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert tco.enqueue(pdu) is True assert tco.enqueue(pdu) is False assert tco.recv() == pdu assert tco.recv() == pdu threading.Timer(0.01, tco.enqueue, (pdu, )).start() tco.recv()
def test_recv(self, tco, pdu): assert tco.enqueue(pdu) is True assert tco.enqueue(pdu) is False tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert tco.enqueue(pdu) is True assert tco.enqueue(pdu) is False assert tco.recv() == pdu assert tco.recv() == pdu threading.Timer(0.01, tco.enqueue, (pdu,)).start() tco.recv()
def test_sockopt(self, tco): assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 1 tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 2 tco.close() with pytest.raises(nfc.llcp.Error) as excinfo: tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert excinfo.value.errno == errno.ESHUTDOWN with pytest.raises(nfc.llcp.Error) as excinfo: tco.getsockopt(nfc.llcp.SO_RCVBUF) assert excinfo.value.errno == errno.ESHUTDOWN
def test_sockopt(self, tco): assert tco.getsockopt(nfc.llcp.SO_SNDBUF) == 1 assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 1 assert tco.getsockopt(nfc.llcp.SO_SNDMIU) == 128 assert tco.getsockopt(nfc.llcp.SO_RCVMIU) == 128 assert tco.getsockopt(nfc.llcp.SO_SNDBSY) is False assert tco.getsockopt(nfc.llcp.SO_RCVBSY) is False tco.setsockopt(nfc.llcp.SO_RCVMIU, 200) tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) tco.setsockopt(nfc.llcp.SO_RCVBSY, True) assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 2 assert tco.getsockopt(nfc.llcp.SO_RCVMIU) == 200 assert tco.getsockopt(nfc.llcp.SO_RCVBSY) is True with pytest.raises(NotImplementedError) as excinfo: tco.setsockopt(nfc.llcp.SO_SNDBUF, 2) assert str(excinfo.value) == "SO_SNDBUF can not be set"
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
def test_sockopt(self, tco): assert tco.getsockopt(nfc.llcp.SO_SNDMIU) == tco.send_miu assert tco.getsockopt(nfc.llcp.SO_RCVMIU) == tco.recv_miu with pytest.raises(NotImplementedError) as excinfo: tco.setsockopt(nfc.llcp.SO_SNDBUF, 0) assert str(excinfo.value) == "SO_SNDBUF can not be set" assert tco.getsockopt(nfc.llcp.SO_SNDBUF) == 1 tco.setsockopt(nfc.llcp.SO_RCVBUF, 2) assert tco.getsockopt(nfc.llcp.SO_RCVBUF) == 2 assert tco.getsockopt(-1) is None with pytest.raises(ValueError) as excinfo: tco.setsockopt(-1, 0) assert str(excinfo.value) == "invalid option value"