OSDN Git Service

Simplify sending information requests
authorZach Johnson <zachoverflow@google.com>
Tue, 3 Mar 2020 21:31:01 +0000 (13:31 -0800)
committerZach Johnson <zachoverflow@google.com>
Tue, 3 Mar 2020 22:32:28 +0000 (14:32 -0800)
Test: cert/run --host --test_filter=L2capTest
Change-Id: Ic8b731582ad2087922c18c06ad40e0319ae80b99

gd/l2cap/classic/cert/cert_l2cap.py
gd/l2cap/classic/cert/l2cap_test.py

index 9fae240..06b0f7b 100644 (file)
@@ -25,6 +25,7 @@ from bluetooth_packets_python3.l2cap_packets import Final
 from bluetooth_packets_python3.l2cap_packets import SegmentationAndReassembly
 from bluetooth_packets_python3.l2cap_packets import SupervisoryFunction
 from bluetooth_packets_python3.l2cap_packets import Poll
+from bluetooth_packets_python3.l2cap_packets import InformationRequestInfoType
 from cert.event_stream import FilteringEventStream
 from cert.event_stream import IEventStream
 from cert.matchers import L2capMatchers
@@ -68,6 +69,17 @@ class CertL2capChannel(IEventStream):
             self._dcid, s, p, f, req_seq)
         self._acl.send(frame.Serialize())
 
+    def send_information_request(self, type):
+        assertThat(self._scid).isEqualTo(1)
+        signal_id = 3
+        information_request = l2cap_packets.InformationRequestBuilder(
+            signal_id, type)
+        self.send(information_request)
+
+    def send_extended_features_request(self):
+        self.send_information_request(
+            InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED)
+
 
 class CertL2cap(Closable):
 
index 115295c..473d409 100644 (file)
@@ -263,16 +263,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
         L2CAP/COS/IEX/BV-01-C [Query for 1.2 Features]
         """
         self._setup_link_from_cert()
-        signal_id = 3
-        information_request = l2cap_packets.InformationRequestBuilder(
-            signal_id,
-            l2cap_packets.InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED
-        )
-        information_request_l2cap = l2cap_packets.BasicFrameBuilder(
-            1, information_request)
-        self.cert_send_b_frame(information_request_l2cap)
+        control_channel = self.cert_l2cap.get_control_channel()
 
-        assertThat(self.cert_l2cap.get_control_channel()).emits(
+        control_channel.send_extended_features_request()
+
+        assertThat(control_channel).emits(
             L2capMatchers.InformationResponseExtendedFeatures())
 
     def test_extended_feature_info_response_ertm(self):
@@ -281,17 +276,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
         Retransmission Mode]
         """
         self._setup_link_from_cert()
+        control_channel = self.cert_l2cap.get_control_channel()
 
-        signal_id = 3
-        information_request = l2cap_packets.InformationRequestBuilder(
-            signal_id,
-            l2cap_packets.InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED
-        )
-        information_request_l2cap = l2cap_packets.BasicFrameBuilder(
-            1, information_request)
-        self.cert_send_b_frame(information_request_l2cap)
+        control_channel.send_extended_features_request()
 
-        assertThat(self.cert_l2cap.get_control_channel()).emits(
+        assertThat(control_channel).emits(
             L2capMatchers.InformationResponseExtendedFeatures(
                 supports_ertm=True))
 
@@ -301,17 +290,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
         """
         asserts.skip("Streaming not supported")
         self._setup_link_from_cert()
+        control_channel = self.cert_l2cap.get_control_channel()
 
-        signal_id = 3
-        information_request = l2cap_packets.InformationRequestBuilder(
-            signal_id,
-            l2cap_packets.InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED
-        )
-        information_request_l2cap = l2cap_packets.BasicFrameBuilder(
-            1, information_request)
-        self.cert_send_b_frame(information_request_l2cap)
+        control_channel.send_extended_features_request()
 
-        assertThat(self.cert_l2cap.get_control_channel()).emits(
+        assertThat(control_channel).emits(
             L2capMatchers.InformationResponseExtendedFeatures(
                 supports_streaming=True))
 
@@ -321,17 +304,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
         Note: This is not mandated by L2CAP Spec
         """
         self._setup_link_from_cert()
+        control_channel = self.cert_l2cap.get_control_channel()
 
-        signal_id = 3
-        information_request = l2cap_packets.InformationRequestBuilder(
-            signal_id,
-            l2cap_packets.InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED
-        )
-        information_request_l2cap = l2cap_packets.BasicFrameBuilder(
-            1, information_request)
-        self.cert_send_b_frame(information_request_l2cap)
+        control_channel.send_extended_features_request()
 
-        assertThat(self.cert_l2cap.get_control_channel()).emits(
+        assertThat(control_channel).emits(
             L2capMatchers.InformationResponseExtendedFeatures(
                 supports_fcs=True))
 
@@ -340,17 +317,11 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
         L2CAP/EXF/BV-05-C
         """
         self._setup_link_from_cert()
+        control_channel = self.cert_l2cap.get_control_channel()
 
-        signal_id = 3
-        information_request = l2cap_packets.InformationRequestBuilder(
-            signal_id,
-            l2cap_packets.InformationRequestInfoType.EXTENDED_FEATURES_SUPPORTED
-        )
-        information_request_l2cap = l2cap_packets.BasicFrameBuilder(
-            1, information_request)
-        self.cert_send_b_frame(information_request_l2cap)
+        control_channel.send_extended_features_request()
 
-        assertThat(self.cert_l2cap.get_control_channel()).emits(
+        assertThat(control_channel).emits(
             L2capMatchers.InformationResponseExtendedFeatures(
                 supports_fixed_channels=True))