From: Zach Johnson Date: Mon, 2 Mar 2020 05:48:40 +0000 (-0800) Subject: Replace a few more matchers X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=40123cf79c4a481cc1307aaecf604062ab437ae3;p=android-x86%2Fsystem-bt.git Replace a few more matchers Test: cert/run --host --test_filter=L2capTest Change-Id: I6879d05699b406b9b0d1604199ce18e29d7b5d03 --- diff --git a/gd/cert/matchers.py b/gd/cert/matchers.py index 09990ed27..acb8e0787 100644 --- a/gd/cert/matchers.py +++ b/gd/cert/matchers.py @@ -43,6 +43,14 @@ class L2capMatchers(object): return lambda packet: L2capMatchers._is_control_frame_with_code(packet, CommandCode.DISCONNECTION_REQUEST) @staticmethod + def DisconnectionResponse(scid, dcid): + return lambda packet: L2capMatchers._is_matching_disconnection_response(packet, scid, dcid) + + @staticmethod + def CommandReject(): + return lambda packet: L2capMatchers._is_control_frame_with_code(packet, CommandCode.COMMAND_REJECT) + + @staticmethod def _basic_frame(packet): if packet is None: return None @@ -77,3 +85,13 @@ class L2capMatchers(object): return response.GetSourceCid() == scid and response.GetResult( ) == ConnectionResponseResult.SUCCESS and response.GetDestinationCid( ) != 0 + + @staticmethod + def _is_matching_disconnection_response(packet, scid, dcid): + frame = L2capMatchers._control_frame_with_code( + packet, CommandCode.DISCONNECTION_RESPONSE) + if frame is None: + return False + response = l2cap_packets.DisconnectionResponseView(frame) + return response.GetSourceCid() == scid and response.GetDestinationCid( + ) == dcid diff --git a/gd/l2cap/classic/cert/l2cap_test.py b/gd/l2cap/classic/cert/l2cap_test.py index ac623e495..639e8f031 100644 --- a/gd/l2cap/classic/cert/l2cap_test.py +++ b/gd/l2cap/classic/cert/l2cap_test.py @@ -470,21 +470,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass): close_channel_l2cap = l2cap_packets.BasicFrameBuilder(1, close_channel) self.cert_send_b_frame(close_channel_l2cap) - def verify_disconnection_response(packet): - packet_bytes = packet.payload - l2cap_view = l2cap_packets.BasicFrameView( - bt_packets.PacketViewLittleEndian(list(packet_bytes))) - l2cap_control_view = l2cap_packets.ControlView( - l2cap_view.GetPayload()) - if l2cap_control_view.GetCode( - ) != l2cap_packets.CommandCode.DISCONNECTION_RESPONSE: - return False - disconnection_response_view = l2cap_packets.DisconnectionResponseView( - l2cap_control_view) - return disconnection_response_view.GetSourceCid( - ) == scid and disconnection_response_view.GetDestinationCid() == dcid - - assertThat(self.cert_acl).emits(verify_disconnection_response) + assertThat(self.cert_acl).emits( + L2capMatchers.DisconnectionResponse(scid, dcid)) def test_disconnect_on_timeout(self): """ @@ -502,18 +489,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass): self._open_channel(1, scid, psm) - def is_configuration_response(l2cap_packet): - packet_bytes = l2cap_packet.payload - l2cap_view = l2cap_packets.BasicFrameView( - bt_packets.PacketViewLittleEndian(list(packet_bytes))) - if l2cap_view.GetChannelId() != 1: - return False - l2cap_control_view = l2cap_packets.ControlView( - l2cap_view.GetPayload()) - return l2cap_control_view.GetCode( - ) == l2cap_packets.CommandCode.CONFIGURATION_RESPONSE - - cert_acl_data_stream.assert_none_matching(is_configuration_response) + cert_acl_data_stream.assert_none_matching( + L2capMatchers.ConfigurationResponse()) def test_retry_config_after_rejection(self): """ @@ -563,18 +540,7 @@ class L2capTest(GdFacadeOnlyBaseTestClass): invalid_command_packet = b"\x04\x00\x01\x00\xff\x01\x00\x00" self.cert_acl.send(invalid_command_packet) - def is_command_reject(l2cap_packet): - packet_bytes = l2cap_packet.payload - l2cap_view = l2cap_packets.BasicFrameView( - bt_packets.PacketViewLittleEndian(list(packet_bytes))) - if l2cap_view.GetChannelId() != 1: - return False - l2cap_control_view = l2cap_packets.ControlView( - l2cap_view.GetPayload()) - return l2cap_control_view.GetCode( - ) == l2cap_packets.CommandCode.COMMAND_REJECT - - assertThat(self.cert_acl).emits(is_command_reject) + assertThat(self.cert_acl).emits(L2capMatchers.CommandReject()) def test_query_for_1_2_features(self): """