def test_209(self): """ Parametry serwera: -v 2 -s 10 -w 800 -h 600 Klient 0: turn_direction = 2, next_expected_event_no = 0, player_name = abcdefghijklmnopqrstu Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = ala210 Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = bob210 Błędna nazwa gracza – klient 0 wysyła za długą nazwę gracza (21 znaków). """ self.server = self.start_server(10) self.clients = self.new_clients( ["abcdefghijklmnopqrstu", "ala210", "bob210"]) self.clients[0].send_message(2) self.clients[1].send_message(1) self.clients[2].send_message(2) self.wait_server() expected_events = communication.ServerMessage(10, [ event_new_game(0, 800, 600, ["ala210", "bob210"]), event_pixel(1, 0, 330, 552), event_pixel(2, 1, 207, 316), event_pixel(3, 0, 329, 553), event_pixel(4, 1, 206, 316), ]) self.assertClientsReceived(self.clients[1:], expected_events) self.assertEqual(self.clients[0].pull_events(), [])
def test_214(self): """ Parametry serwera: -v 2 -s 15 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Ala215 Tu jest przerwa 3 sekundy. Ala215 zostaje odłączona. Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Bobek215 Klient 2: turn_direction = 1, next_expected_event_no = 0, player_name = Cezary215 """ self.server = self.start_server(15) self.clients = self.new_clients(["Ala215", "Bobek215", "Cezary215"]) self.clients[0].send_message(1) time.sleep(3) self.clients[1].send_message(1) self.clients[2].send_message(1) self.wait_server() expected_events = communication.ServerMessage(15, [ event_new_game(0, 800, 600, ["Bobek215", "Cezary215"]), event_pixel(1, 0, 495, 528), event_pixel(2, 1, 665, 474), event_pixel(3, 0, 494, 529), event_pixel(4, 1, 664, 475), ]) self.assertClientsReceived(self.clients[1:], expected_events) self.assertEqual(self.clients[0].pull_events(), [], "Disconnected client0 received events.")
def test_212(self): """ Parametry serwera: -v 2 -s 13 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Alicja213 Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Bolek213 Klient 2: turn_direction = 1, next_expected_event_no = 0, player_name = Cezary213 Gracz Cezary213 nie załapuje się na rozgrywkę. """ # I don't know how the official tests are implemented, but # this test probably does not makes sense with zero AFTER_MSG_WAIT # because messages not always would be sent in the same order. self.server = self.start_server(13) self.clients = self.new_clients(["Alicja213", "Bolek213", "Cezary213"]) self.clients[0].send_message(1) self.clients[1].send_message(1) self.clients[2].send_message(1) self.wait_server() expected_events = communication.ServerMessage(13, [ event_new_game(0, 800, 600, ["Alicja213", "Bolek213"]), event_pixel(1, 0, 749, 254), event_pixel(2, 1, 20, 29), event_pixel(3, 0, 749, 255), event_pixel(4, 1, 20, 28), ]) self.assertClientsReceived(self.clients, expected_events)
def test_210(self): """ Parametry serwera: -v 2 -s 11 -w 800 -h 600 Klient 0: turn_direction = 0, next_expected_event_no = 0, player_name = Ala211, używa IPv4 Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Bob211, używa IPv6 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Ala211, używa IPv4 """ self.server = self.start_server(11) self.clients = [ self.new_client("Ala211", socket.AF_INET), self.new_client("Bob211", socket.AF_INET6) ] self.clients[0].send_message(0) self.clients[1].send_message(1) self.clients[0].send_message(1) self.wait_server() expected_events = communication.ServerMessage(11, [ event_new_game(0, 800, 600, ["Ala211", "Bob211"]), event_pixel(1, 0, 203, 580), event_pixel(2, 1, 84, 293), event_pixel(3, 0, 203, 581), event_pixel(4, 1, 85, 293), ]) self.assertClientsReceived(self.clients, expected_events)
def test_207(self): """ Parametry serwera: -v 2 -s 8 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, błędna nazwa gracza – pojedyncza spacja Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Ala208 Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = Bob208 """ self.server = self.start_server(8) self.clients = self.new_clients([" ", "Ala208", "Bob208"]) self.clients[0].send_message(1, 0) self.clients[1].send_message(1, 0) self.clients[2].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(8, [ event_new_game(0, 800, 600, ["Ala208", "Bob208"]), event_pixel(1, 0, 584, 278), event_pixel(2, 1, 271, 471), event_pixel(3, 0, 584, 279), event_pixel(4, 1, 271, 470), ]) self.assertClientsReceived(self.clients[1:], expected_events) self.assertEqual(self.clients[0].pull_events(), [])
def test_208(self): """ Parametry serwera: -v 2 -s 9 -w 800 -h 600 Klient 0: turn_direction = 2, next_expected_event_no = 0, błędna nazwa gracza – znak o kodzie 0 Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Ala209 Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = Bob209 """ self.server = self.start_server(9) self.clients = self.new_clients(["\0", "Ala209", "Bob209"]) self.clients[0].send_message(2) self.clients[1].send_message(1) self.clients[2].send_message(2) self.wait_server() expected_events = communication.ServerMessage(9, [ event_new_game(0, 800, 600, ["Ala209", "Bob209"]), event_pixel(1, 0, 457, 415), event_pixel(2, 1, 239, 448), event_pixel(3, 0, 458, 416), event_pixel(4, 1, 239, 449), ]) self.assertClientsReceived(self.clients[1:], expected_events) self.assertEqual(self.clients[0].pull_events(), [])
def test_206(self): """ Parametry serwera: -v 2 -s 7 -w 800 -h 600 Klient 0: turn_direction = 3, next_expected_event_no = 0, player_name = Cezary207 Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Ala207 Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = Bob207 Klient 0 wysyła błędną wartość turn_direction. """ self.server = self.start_server(7) self.clients = self.new_clients(["Cezary207", "Ala207", "Bob207"]) self.clients[0].send_message(3, 0) self.clients[1].send_message(1, 0) self.clients[2].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(7, [ event_new_game(0, 800, 600, ["Ala207", "Bob207"]), event_pixel(1, 0, 711, 141), event_pixel(2, 1, 394, 3), event_pixel(3, 0, 712, 142), event_pixel(4, 1, 393, 3), ]) self.assertClientsReceived(self.clients[1:], expected_events) self.assertEqual(self.clients[0].pull_events(), [])
def test_203(self): """ Parametry serwera: -v 2 -s 2 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Bob203 Klient 1: za krótki komunikat – jeden bajt o wartości 0 Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = Cezary203 """ self.server = self.start_server(2) self.clients = self.new_clients(["Bob203", "", "Cezary203"]) self.clients[0].send_message(1, 0) self.clients[1].sock.send(b"\0") self.clients[2].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(2, [ event_new_game(0, 800, 600, ["Bob203", "Cezary203"]), event_pixel(1, 0, 546, 165), event_pixel(2, 1, 736, 336), event_pixel(3, 0, 547, 165), event_pixel(4, 1, 736, 335), ]) self.assertClientReceived(self.clients[0], expected_events) self.assertClientReceived(self.clients[2], expected_events)
def test_211(self): """ Parametry serwera: -v 2 -s 12 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Ala212 Klient 1: turn_direction = 1, next_expected_event_no = 0, player_name = Bob212 Klient 0: turn_direction = 1, next_expected_event_no = 1, player_name = Ala212 """ self.server = self.start_server(12) self.clients = self.new_clients(["Ala212", "Bob212"]) self.clients[0].send_message(1, 0) self.clients[1].send_message(1, 0) time.sleep(1) self.clients[0].send_message(1, 1) time.sleep(1) events = [ event_new_game(0, 800, 600, ["Ala212", "Bob212"]), event_pixel(1, 0, 76, 117), event_pixel(2, 1, 52, 161), event_pixel(3, 0, 75, 118), event_pixel(4, 1, 52, 162), event_pixel(5, 0, 74, 118), event_pixel(6, 1, 53, 163), ] expected_events = communication.ServerMessage(12, events) c0_messages = self.clients[0].pull_events() c1_messages = self.clients[1].pull_events() # Check for all messages. self.assertContainsEvents(expected_events, c0_messages) self.assertContainsEvents(expected_events, c1_messages) # Check for duplicates in client0. c0_events = get_events(c0_messages) for dup_event in events[1:5]: num = len( list(filter(lambda x: events_equal(dup_event, x), c0_events))) self.assertEqual(2, num, f"Event ({dup_event}) is not duplicated")
def test_201(self): """ Parametry serwera: -v 2 -s 777 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Bob201 Klient 1: turn_direction = 2, next_expected_event_no = 0, player_name = Cezary201 """ self.server = self.start_server(777) self.clients = self.new_clients(["Bob201", "Cezary201"]) self.clients[0].send_message(1, 0) self.clients[1].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(777, [ event_new_game(0, 800, 600, ["Bob201", "Cezary201"]), event_pixel(1, 0, 771, 99), event_pixel(2, 1, 18, 331), event_pixel(3, 0, 772, 99), event_pixel(4, 1, 17, 330), ]) self.assertClientsReceived(self.clients, expected_events)
def test_213(self): """ Parametry serwera: -v 2 -s 14 -w 800 -h 600 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = ala214 Klient 1: turn_direction = 2, next_expected_event_no = 0, player_name = abcdefghijklmnopqrst Klient 1 wysyła nazwę gracza o maksymalnej długości (20 znaków). """ self.server = self.start_server(14) self.clients = self.new_clients(["ala214", "abcdefghijklmnopqrst"]) self.clients[0].send_message(1) self.clients[1].send_message(2) self.wait_server() expected_events = communication.ServerMessage(14, [ event_new_game(0, 800, 600, ["abcdefghijklmnopqrst", "ala214"]), event_pixel(1, 0, 622, 391), event_pixel(2, 1, 697, 6), event_pixel(3, 0, 621, 391), event_pixel(4, 1, 697, 7), ]) self.assertClientsReceived(self.clients, expected_events)
def test_205(self): """ Parametry serwera: -v 2 -s 65535 -h 2048 -w 2048 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Bob206, używa IPv6 Klient 1: turn_direction = 2, next_expected_event_no = 0, player_name = Ala206, używa IPv6 Sprawdza sortowanie nazw graczy. """ self.server = self.start_server(65535, 2048, 2048) self.clients = self.new_clients(["Bob206", "Ala206"], socket.AF_INET6) self.clients[0].send_message(1, 0) self.clients[1].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(65535, [ event_new_game(0, 2048, 2048, ["Ala206", "Bob206"]), event_pixel(1, 0, 1250, 789), event_pixel(2, 1, 1415, 1456), event_pixel(3, 0, 1250, 790), event_pixel(4, 1, 1415, 1457), ]) self.assertClientsReceived(self.clients, expected_events)
def test_202(self): """ Parametry serwera: -v 2 -s 3 -h 200 -w 100 Klient 0: turn_direction = 1, next_expected_event_no = 0, player_name = Bob202 Klient 1: turn_direction = 0, next_expected_event_no = 0, bez nazwy gracza Klient 2: turn_direction = 2, next_expected_event_no = 0, player_name = Cezary202 """ self.server = self.start_server(3, 100, 200) self.clients = self.new_clients(["Bob202", "", "Cezary202"]) self.clients[0].send_message(1, 0) self.clients[1].send_message(0, 0) self.clients[2].send_message(2, 0) self.wait_server() expected_events = communication.ServerMessage(3, [ event_new_game(0, 100, 200, ["Bob202", "Cezary202"]), event_pixel(1, 0, 19, 102), event_pixel(2, 1, 13, 113), event_pixel(3, 0, 20, 102), event_pixel(4, 1, 14, 112), ]) self.assertClientsReceived(self.clients, expected_events)