Exemplo n.º 1
0
 def test_sendto_on_raw_prebound_socket(self, llc, raw):
     llc.bind(raw, 33)
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 33, b'123')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 33 and pdu.data == b'123'
Exemplo n.º 2
0
 def test_sendto_on_raw_prebound_socket(self, llc, raw):
     llc.bind(raw, 33)
     pdu = nfc.llcp.pdu.UnnumberedInformation(16, 33, b'123')
     llc.sendto(raw, pdu, 16, nfc.llcp.MSG_DONTWAIT)
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 33 and pdu.data == b'123'
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 def test_close(self, llc, ldl, dlc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.close(object())
     assert excinfo.value.errno == errno.ENOTSOCK
     llc.bind(ldl)
     llc.close(ldl)
     assert ldl.state.SHUTDOWN is True
     llc.close(dlc)
     assert dlc.state.SHUTDOWN is True
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 def test_close(self, llc, ldl, dlc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.close(object())
     assert excinfo.value.errno == errno.ENOTSOCK
     llc.bind(ldl)
     llc.close(ldl)
     assert ldl.state.SHUTDOWN is True
     llc.close(dlc)
     assert dlc.state.SHUTDOWN is True
Exemplo n.º 9
0
 def test_poll(self, llc, ldl):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.poll(object(), 'recv')
     assert excinfo.value.errno == errno.ENOTSOCK
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.poll(ldl, 'recv')
     assert excinfo.value.errno == errno.EBADF
     llc.bind(ldl)
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.poll(ldl, 'recv') is True
Exemplo n.º 10
0
 def test_poll(self, llc, ldl):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.poll(object(), 'recv')
     assert excinfo.value.errno == errno.ENOTSOCK
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.poll(ldl, 'recv')
     assert excinfo.value.errno == errno.EBADF
     llc.bind(ldl)
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     assert llc.poll(ldl, 'recv') is True
Exemplo n.º 11
0
 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
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
 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
Exemplo n.º 16
0
 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
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 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
Exemplo n.º 19
0
 def test_bind_notsock(self, llc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(object())
     assert excinfo.value.errno == errno.ENOTSOCK
Exemplo n.º 20
0
 def test_recvfrom_with_ldl_socket(self, llc, ldl):
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     llc.bind(ldl, 32)
     assert llc.recvfrom(ldl) == (b'123', 17)
Exemplo n.º 21
0
 def test_recvfrom_with_raw_socket(self, llc, raw):
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     llc.bind(raw, 32)
     assert llc.recvfrom(raw) == (pdu, None)
Exemplo n.º 22
0
 def test_bind_isbound(self, llc, raw):
     llc.bind(raw)
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw)
     assert excinfo.value.errno == errno.EINVAL
Exemplo n.º 23
0
 def test_sendto_with_prebound_socket(self, llc, ldl):
     llc.bind(ldl, 32)
     assert llc.sendto(ldl, b'123', 16, nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemplo n.º 24
0
 def test_bind_notype(self, llc, raw):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw, float(0))
     assert excinfo.value.errno == errno.EFAULT
Exemplo n.º 25
0
 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
Exemplo n.º 26
0
 def test_recvfrom_with_raw_socket(self, llc, raw):
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     llc.bind(raw, 32)
     assert llc.recvfrom(raw) == (pdu, None)
Exemplo n.º 27
0
 def test_recvfrom_with_ldl_socket(self, llc, ldl):
     pdu = nfc.llcp.pdu.UnnumberedInformation(32, 17, b'123')
     threading.Timer(0.01, llc.dispatch, (pdu,)).start()
     llc.bind(ldl, 32)
     assert llc.recvfrom(ldl) == (b'123', 17)
Exemplo n.º 28
0
 def test_bind_notype(self, llc, raw):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw, float(0))
     assert excinfo.value.errno == errno.EFAULT
Exemplo n.º 29
0
 def test_bind_isbound(self, llc, raw):
     llc.bind(raw)
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(raw)
     assert excinfo.value.errno == errno.EINVAL
Exemplo n.º 30
0
 def test_bind_notsock(self, llc):
     with pytest.raises(nfc.llcp.Error) as excinfo:
         llc.bind(object())
     assert excinfo.value.errno == errno.ENOTSOCK
Exemplo n.º 31
0
 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
Exemplo n.º 32
0
 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
Exemplo n.º 33
0
 def test_sendto_with_prebound_socket(self, llc, ldl):
     llc.bind(ldl, 32)
     assert llc.sendto(ldl, b'123', 16, nfc.llcp.MSG_DONTWAIT) is True
     pdu = llc.collect()
     assert isinstance(pdu, nfc.llcp.pdu.UnnumberedInformation)
     assert pdu.dsap == 16 and pdu.ssap == 32 and pdu.data == b'123'
Exemplo n.º 34
0
 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