Exemple #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'
Exemple #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'
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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'
Exemple #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
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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
Exemple #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'
Exemple #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