Exemple #1
0
 def dlc(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 128, 1)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
     assert tco.dequeue(128, 4) == nfc.llcp.pdu.Connect(17, 16, 128, 1)
     return tco
Exemple #2
0
 def test_connect_with_connect_rejected(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     with pytest.raises(nfc.llcp.ConnectRefused) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.ECONNREFUSED
     assert tco.state.CLOSED is True
 def dlc(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 128, 1)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
     assert tco.dequeue(128, 4) == nfc.llcp.pdu.Connect(17, 16, 128, 1)
     return tco
Exemple #4
0
 def test_str(self):
     tco = nfc.llcp.tco.LogicalDataLink(128)
     assert str(tco) == "LDL None -> None"
     tco.bind(1)
     assert str(tco) == "LDL  1 -> None"
     tco.connect(1)
     assert str(tco) == "LDL  1 ->  1"
 def test_connect_with_connect_rejected(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     with pytest.raises(nfc.llcp.ConnectRefused) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.ECONNREFUSED
     assert tco.state.CLOSED is True
Exemple #6
0
 def test_str(self):
     tco = nfc.llcp.tco.LogicalDataLink(128)
     assert str(tco) == "LDL None -> None"
     tco.bind(1)
     assert str(tco) == "LDL  1 -> None"
     tco.connect(1)
     assert str(tco) == "LDL  1 ->  1"
 def test_connect_with_error_is_connected(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(18)
     assert excinfo.value.errno == errno.EISCONN
 def test_connect_with_error_is_connecting(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     threading.Timer(0, tco.connect, (17, )).start()
     time.sleep(0.001)
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(18)
     assert excinfo.value.errno == errno.EALREADY
Exemple #9
0
 def test_connect_with_error_is_connecting(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     threading.Timer(0, tco.connect, (17,)).start()
     time.sleep(0.001)
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(18)
     assert excinfo.value.errno == errno.EALREADY
Exemple #10
0
 def test_connect_with_error_is_connected(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, 17, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(18)
     assert excinfo.value.errno == errno.EISCONN
Exemple #11
0
 def test_connect_with_error_broken_pipe(self, tco):
     threading.Timer(0.01, tco.close).start()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.EPIPE
     assert tco.state.SHUTDOWN is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.EPIPE
Exemple #12
0
 def test_connect_by_addr_or_name(self, tco, dest, dsap):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, dsap, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     tco.connect(dest)
     assert tco.state.ESTABLISHED is True
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, dsap)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     tco.close()
     assert tco.state.SHUTDOWN is True
 def test_connect_by_addr_or_name(self, tco, dest, dsap):
     pdu = nfc.llcp.pdu.ConnectionComplete(tco.addr, dsap, 1000, 2)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     tco.connect(dest)
     assert tco.state.ESTABLISHED is True
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, dsap)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     tco.close()
     assert tco.state.SHUTDOWN is True
 def test_connect_with_error_broken_pipe(self, tco):
     threading.Timer(0.01, tco.close).start()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.EPIPE
     assert tco.state.SHUTDOWN is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(17)
     assert excinfo.value.errno == errno.EPIPE
 def test_enqueue_state_closed_recv_any(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     with pytest.raises(nfc.llcp.ConnectRefused):
         tco.connect(17)
     assert tco.state.CLOSED is True
     assert tco.dequeue(128, 0) == nfc.llcp.pdu.Connect(17, tco.addr)
     pdu = nfc.llcp.pdu.Information(tco.addr, 17, 0, 0, b'123')
     assert tco.enqueue(pdu) is None
     assert tco.dequeue(128, 0) == \
         nfc.llcp.pdu.DisconnectedMode(17, tco.addr, reason=1)
Exemple #16
0
 def test_enqueue_state_closed_recv_any(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(tco.addr, 17)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     with pytest.raises(nfc.llcp.ConnectRefused):
         tco.connect(17)
     assert tco.state.CLOSED is True
     assert tco.dequeue(128, 0) == nfc.llcp.pdu.Connect(17, tco.addr)
     pdu = nfc.llcp.pdu.Information(tco.addr, 17, 0, 0, b'123')
     assert tco.enqueue(pdu) is None
     assert tco.dequeue(128, 0) == \
         nfc.llcp.pdu.DisconnectedMode(17, tco.addr, reason=1)
Exemple #17
0
 def test_sendto(self, tco):
     pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122'))
     assert tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT) is True
     assert tco.dequeue(10, 4) == pdu
     assert tco.connect(2) is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT)
     assert excinfo.value.errno == errno.EDESTADDRREQ
     with pytest.raises(nfc.llcp.Error) as excinfo:
         data = (tco.send_miu + 1) * HEX('11')
         tco.sendto(data, 2, flags=nfc.llcp.MSG_DONTWAIT)
     assert excinfo.value.errno == errno.EMSGSIZE
     tco.close()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.sendto(pdu.data, 1, 0)
     assert excinfo.value.errno == errno.ESHUTDOWN
Exemple #18
0
 def test_sendto(self, tco):
     pdu = nfc.llcp.pdu.UnnumberedInformation(1, 1, HEX('1122'))
     assert tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT) is True
     assert tco.dequeue(10, 4) == pdu
     assert tco.connect(2) is True
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.sendto(pdu.data, 1, flags=nfc.llcp.MSG_DONTWAIT)
     assert excinfo.value.errno == errno.EDESTADDRREQ
     with pytest.raises(nfc.llcp.Error) as excinfo:
         data = (tco.send_miu + 1) * HEX('11')
         tco.sendto(data, 2, flags=nfc.llcp.MSG_DONTWAIT)
     assert excinfo.value.errno == errno.EMSGSIZE
     tco.close()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.sendto(pdu.data, 1, 0)
     assert excinfo.value.errno == errno.ESHUTDOWN
Exemple #19
0
 def test_connect(self, tco):
     assert tco.connect(1) == 1
     tco.close()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(2)
     assert excinfo.value.errno == errno.ESHUTDOWN
 def test_enqueue_state_connect_recv_dm(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(17, tco.addr)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     with pytest.raises(nfc.llcp.ConnectRefused):
         tco.connect(17)
     assert tco.state.CLOSED is True
 def test_enqueue_state_connect_recv_cc(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(17, tco.addr)
     threading.Timer(0.01, tco.enqueue, (pdu, )).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
Exemple #22
0
 def test_connect_with_invalid_dest_type(self, tco):
     with pytest.raises(TypeError) as excinfo:
         tco.connect(1.0)
     assert str(excinfo.value) == "connect destination must be int or bytes"
Exemple #23
0
 def test_enqueue_state_connect_recv_cc(self, tco):
     pdu = nfc.llcp.pdu.ConnectionComplete(17, tco.addr)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     tco.connect(17)
     assert tco.state.ESTABLISHED is True
Exemple #24
0
 def test_enqueue_state_connect_recv_dm(self, tco):
     pdu = nfc.llcp.pdu.DisconnectedMode(17, tco.addr)
     threading.Timer(0.01, tco.enqueue, (pdu,)).start()
     with pytest.raises(nfc.llcp.ConnectRefused):
         tco.connect(17)
     assert tco.state.CLOSED is True
 def test_connect_with_invalid_dest_type(self, tco):
     with pytest.raises(TypeError) as excinfo:
         tco.connect(1.0)
     assert str(excinfo.value) == "connect destination must be int or bytes"
Exemple #26
0
 def test_connect(self, tco):
     assert tco.connect(1) == 1
     tco.close()
     with pytest.raises(nfc.llcp.Error) as excinfo:
         tco.connect(2)
     assert excinfo.value.errno == errno.ESHUTDOWN