def test_bind_by_none(self, llc, raw, ldl, dlc): llc.bind(dlc) assert llc.getsockname(dlc) == 32 for sap in range(33, 64): sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT) llc.bind(sock) assert llc.getsockname(sock) == sap with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(ldl) assert excinfo.value.errno == errno.EAGAIN
def test_bind_by_name(self, llc, raw, ldl, dlc): with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(dlc, 'urn:nfc:snep') assert excinfo.value.errno == errno.EFAULT llc.bind(dlc, 'urn:nfc:sn:snep') assert llc.getsockname(dlc) == 4 with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(ldl, 'urn:nfc:sn:snep') assert excinfo.value.errno == errno.EADDRINUSE llc.bind(ldl, 'urn:nfc:xsn:nfcpy.org:service') assert llc.getsockname(ldl) == 16 for sap in range(17, 32): sock = llc.socket(nfc.llcp.llc.RAW_ACCESS_POINT) llc.bind(sock, 'urn:nfc:sn:use_sap-{}'.format(sap)) assert llc.getsockname(sock) == sap with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(raw, 'urn:nfc:sn:sap-32') assert excinfo.value.errno == errno.EADDRNOTAVAIL
def test_bind_by_addr(self, llc, raw, ldl, dlc): llc.bind(raw, 16) assert llc.getsockname(raw) == 16 for i, sock in enumerate([ldl, dlc]): with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(sock, 16) assert excinfo.value.errno == errno.EACCES llc.bind(ldl, 63) assert llc.getsockname(ldl) == 63 with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(dlc, 63) assert excinfo.value.errno == errno.EADDRINUSE with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(dlc, 64) assert excinfo.value.errno == errno.EFAULT with pytest.raises(nfc.llcp.Error) as excinfo: llc.bind(dlc, -1) assert excinfo.value.errno == errno.EFAULT llc.bind(dlc, 62) assert llc.getsockname(dlc) == 62
def test_connect(self, llc, ldl, dlc, peer_miu, send_miu): def collect_and_dispatch(llc): llc.collect() llc.dispatch(nfc.llcp.pdu.ConnectionComplete(32, 16, peer_miu)) threading.Timer(0.01, collect_and_dispatch, (llc,)).start() llc.bind(dlc, 32) llc.connect(dlc, 16) assert llc.getsockopt(dlc, nfc.llcp.SO_SNDMIU) == send_miu llc.connect(ldl, 17) assert llc.getsockname(ldl) == 33 assert llc.getpeername(ldl) == 17 with pytest.raises(nfc.llcp.Error) as excinfo: llc.connect(object(), 18) assert excinfo.value.errno == errno.ENOTSOCK
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
def test_getsockname_with_invalid_socket_type(self, llc): with pytest.raises(nfc.llcp.Error) as excinfo: llc.getsockname(object()) assert excinfo.value.errno == errno.ENOTSOCK