def test_dispatch_connect_by_name(self, llc, dlc): llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service')) assert llc.collect() == nfc.llcp.pdu.DisconnectedMode(32, 1, 2) llc.bind(dlc, b'urn:nfc:sn:service') llc.listen(dlc, 1) llc.dispatch(nfc.llcp.pdu.Connect(1, 32, sn=b'urn:nfc:sn:service')) llc.accept(dlc) assert llc.collect() == nfc.llcp.pdu.ConnectionComplete(32, 16)
def test_accept_send_cc(self, llc, dlc): llc.bind(dlc, b'urn:nfc:sn:snep') llc.listen(dlc, 0) threading.Timer(0, llc.accept, (dlc,)).start() time.sleep(0.01) llc.dispatch(nfc.llcp.pdu.Connect(4, 32)) pdu = llc.collect(0.01) assert isinstance(pdu, nfc.llcp.pdu.ConnectionComplete) assert pdu.dsap == 32 and pdu.ssap == 4
def test_listen(self, llc, ldl, dlc, bind): with pytest.raises(nfc.llcp.Error) as excinfo: llc.listen(object(), 0) assert excinfo.value.errno == errno.ENOTSOCK with pytest.raises(nfc.llcp.Error) as excinfo: llc.listen(ldl, 0) assert excinfo.value.errno == errno.EOPNOTSUPP with pytest.raises(TypeError) as excinfo: llc.listen(dlc, 0.1) assert str(excinfo.value) == "backlog must be int type" with pytest.raises(ValueError) as excinfo: llc.listen(dlc, -1) assert str(excinfo.value) == "backlog can not be negative" if bind: llc.bind(dlc) llc.listen(dlc, 0) assert dlc.state.LISTEN is True
def test_accept_connect(self, llc, ldl, dlc, peer_miu, send_miu): with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(object()) assert excinfo.value.errno == errno.ENOTSOCK with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(ldl) assert excinfo.value.errno == errno.EOPNOTSUPP with pytest.raises(nfc.llcp.Error) as excinfo: llc.accept(dlc) assert excinfo.value.errno == errno.EINVAL connect_pdu = nfc.llcp.pdu.Connect(4, 32, peer_miu) threading.Timer(0.01, llc.dispatch, (connect_pdu,)).start() llc.bind(dlc, b'urn:nfc:sn:snep') llc.listen(dlc, 0) sock = llc.accept(dlc) assert isinstance(sock, nfc.llcp.tco.DataLinkConnection) assert llc.getsockopt(sock, nfc.llcp.SO_SNDMIU) == send_miu assert llc.getpeername(sock) == 32 assert llc.getsockname(sock) == 4