예제 #1
0
    def test_dataReceived(self):
        global packetReceived_args
        packetReceived_args = []
        self.protocol.packetReceived = lambda *a: packetReceived_args.append(a)
        self.protocol.transport = self.mock_transport([])

        self.protocol.dataReceived(protocol.protocol_handshake)
        assert self.protocol.established

        packed = binarypack.pack(packets.PacketLogin())
        self.protocol.dataReceived(packed)
        assert packetReceived_args == [(packets.PacketLogin(), )]
        packetReceived_args = []

        # small chunks
        for c in packed:
            self.protocol.dataReceived(c)
        assert packetReceived_args == [(packets.PacketLogin(), )]
        packetReceived_args = []

        # big chunks (2.5 + 0.5 packets)
        self.protocol.dataReceived(packed + packed + packed[:-3])
        assert len(packetReceived_args) == 2
        assert packetReceived_args[0] == (packets.PacketLogin(), )
        assert packetReceived_args[1] == (packets.PacketLogin(), )
        self.protocol.dataReceived(packed[-3:])
        assert len(packetReceived_args) == 3
        assert packetReceived_args[2] == (packets.PacketLogin(), )
예제 #2
0
    def test_dataReceived(self):
        global packetReceived_args
        packetReceived_args = []
        self.protocol.packetReceived = lambda *a: packetReceived_args.append(a)
        self.protocol.transport = self.mock_transport([])

        self.protocol.dataReceived(protocol.protocol_handshake)
        assert self.protocol.established

        packed = binarypack.pack(packets.PacketLogin())
        self.protocol.dataReceived(packed)
        assert packetReceived_args == [(packets.PacketLogin(),)]
        packetReceived_args = []

        # small chunks
        for c in packed:
            self.protocol.dataReceived(c)
        assert packetReceived_args == [(packets.PacketLogin(),)]
        packetReceived_args = []

        # big chunks (2.5 + 0.5 packets)
        self.protocol.dataReceived(packed + packed + packed[:-3])
        assert len(packetReceived_args) == 2
        assert packetReceived_args[0] == (packets.PacketLogin(),)
        assert packetReceived_args[1] == (packets.PacketLogin(),)
        self.protocol.dataReceived(packed[-3:])
        assert len(packetReceived_args) == 3
        assert packetReceived_args[2] == (packets.PacketLogin(),)
예제 #3
0
    def test_sendPacket(self):
        "UGAMEProtocol::sendPacket should take a packet, check if connection is" " established and either dataWrite the packed packet or push the packet onto the _out_buffer"
        data_list = []
        self.protocol.transport = self.mock_transport(data_list)

        # not established
        self.protocol.sendPacket(packets.PacketPing())
        assert self.protocol._out_buffer == [packets.PacketPing()]

        # established
        self.protocol.established = True
        self.protocol.sendPacket(packets.PacketPing())
        assert data_list == [binarypack.pack(packets.PacketPing())]
예제 #4
0
    def test_sendPacket(self):
        "UGAMEProtocol::sendPacket should take a packet, check if connection is" \
        " established and either dataWrite the packed packet or push the packet onto the _out_buffer"
        data_list = []
        self.protocol.transport = self.mock_transport(data_list)

        # not established
        self.protocol.sendPacket(packets.PacketPing())
        assert self.protocol._out_buffer == [packets.PacketPing()]

        # established
        self.protocol.established = True
        self.protocol.sendPacket(packets.PacketPing())
        assert data_list == [binarypack.pack(packets.PacketPing())]
예제 #5
0
 def sendPacket(self, packet, reset_keepalive=True):
     if self.established:
         self.dataWrite(binarypack.pack(packet), reset_keepalive)
     else:
         self._out_buffer.append(packet)
예제 #6
0
 def sendPackets(self, packets, reset_keepalive=True):
     if self.established:
         self.dataWrite(''.join(
             [binarypack.pack(packet) for packet in packets]))
     else:
         self._out_buffer.extend(packets)
예제 #7
0
 def check_pack_unpack(packet):
     assert packet.type != -1 
     packed = binarypack.pack(packet)
     assert binarypack.unpack(packed) == packet
예제 #8
0
 def check_pack_unpack(packet):
     assert packet.type != -1
     packed = binarypack.pack(packet)
     assert binarypack.unpack(packed) == packet
예제 #9
0
 def sendPackets(self, packets, reset_keepalive=True):
     if self.established:
         self.dataWrite(''.join([binarypack.pack(packet) for packet in packets]))
     else:
         self._out_buffer.extend(packets)
예제 #10
0
 def sendPacket(self, packet, reset_keepalive=True):
     if self.established:
         self.dataWrite(binarypack.pack(packet), reset_keepalive)
     else:
         self._out_buffer.append(packet)