def test_parse_timeout_packet(self): address = (('212.193.163.7', 80), ) program = TCPing.TCPing(0, address, (1, 3, 3), FakeStat(), FakeVisualiser(), FakeSocket([]), FakeTimer(), False) program.packets[10] = test_statistic.FPacket(0) program.parse_packet((self.VALID_PACKET, ('212.193.163.7', 80)), 10) self.assertTrue(program.packets[10].is_answered) self.assertEqual(program.packets[10].time, 10) self.assertEqual(program.count_of_received_packets, 0)
def test_parse_non_tcp(self): address = (('212.193.163.7', 80), ) program = TCPing.TCPing(0, address, (1, 3, 3), FakeStat(), FakeVisualiser(), FakeSocket([]), FakeTimer(), False) program.packets[10] = test_statistic.FPacket(0) val1 = copy.deepcopy(program.packets) program.parse_packet( (b'asdasdadsasdasdasdasdasdasdasdasdasdasdasdasdasd', ('212.193.163.7', 80)), 0) val2 = program.packets self.assertDictEqual(val1, val2, 'Invalid packet don\'t sorted')
def test_parse_valid_packet(self): address = (('212.193.163.7', 80), ) program = TCPing.TCPing(0, address, (1, 3, 3), FakeStat(), FakeVisualiser(), FakeSocket([]), FakeTimer(), False) program.packets[10] = test_statistic.FPacket(0) program.parse_packet((self.VALID_PACKET, ('212.193.163.7', 80)), 2) self.assertTrue(program.packets[10].is_answered, 'Wrong is_answered flag value') self.assertEqual(program.packets[10].time, 2, 'Wrong packet time') self.assertEqual(program.count_of_received_packets, 1, 'Wrong count of received packets')
def test_parse_bad_ack_packet(self): packet = b"\x45\x00\x00\x2c\x00\x00\x40\x00\x36\x06\x0b" \ b"\xf3\xd4\xc1\xa3\x07\xc0\xa8\x00\x68\x00\x50" \ b"\x00\x00\xee\x94\xcf\x8f\x00\x00\x0a\x0b\x60" \ b"\x12\x72\x10\x2e\xe9\x00\x00\x02\x04\x05\x78" \ b"\x00\x00" address = (('212.193.163.7', 80), ) program = TCPing.TCPing(0, address, (1, 3, 3), FakeStat(), FakeVisualiser(), FakeSocket([]), FakeTimer(), False) program.packets[10] = test_statistic.FPacket(0) val1 = copy.deepcopy(program.packets) program.parse_packet((packet, ('212.193.163.7', 80)), 0) val2 = program.packets self.assertDictEqual(val1, val2, 'Invalid packet don\'t sorted')