/// Tests that A2DP sink assumes the initiator role when a peer is found, but
/// not connected, and the timeout completes.
Tests that A2DP sink assumes the initiator role when a peer is found, but
not connected, and the timeout completes.
Tests that A2DP sink assumes the initiator role when a peer is found but not connected and the timeout completes .
fn wait_to_initiate_success_with_no_connected_peer() {
        let (mut exec, peers, proxy, mut prof_stream, controller_pool) =
            setup_connected_peer_test();
        // Initialize context to a fixed point in time.
        exec.set_fake_time(fasync::Time::from_nanos(1000000000));
        let peer_id = PeerId(1);
        // Simulate getting the service found event.
        let attributes = vec![Attribute {
            id: ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
            element: DataElement::Sequence(vec![Some(Box::new(DataElement::Sequence(vec![
                Some(Box::new(Uuid::from(ServiceClassProfileIdentifier::AudioSource).into())),
                Some(Box::new(DataElement::Uint16(0x0103))), // Version 1.3
            ])))]),
        }];
        handle_services_found(
            &peer_id,
            &attributes,
            peers.clone(),
            controller_pool.clone(),
            proxy.clone(),
        );
        run_to_stalled(&mut exec);
        // At this point, a remote peer was found, but hasn't connected yet. There
        // should be no entry for it.
        assert!(!peers.lock().is_connected(&peer_id));
        // Fast forward time by 5 seconds. In this time, the remote peer has not
        // connected.
        exec.set_fake_time(fasync::Time::from_nanos(6000000000));
        exec.wake_expired_timers();
        run_to_stalled(&mut exec);
        // After fast forwarding time, expect and handle the `connect` request
        // because A2DP-sink should be initiating.
        let (_test, transport) =
            zx::Socket::create(zx::SocketOpts::DATAGRAM).expect("socket creation fail");
        let request = exec.run_until_stalled(&mut prof_stream.next());
        match request {
            Poll::Ready(Some(Ok(ProfileRequest::Connect { peer_id, responder, .. }))) => {
                assert_eq!(PeerId(1), peer_id.into());
                responder
                    .send(&mut Ok(Channel { socket: Some(transport), ..Channel::new_empty() }))
                    .expect("responder sends");
            }
            x => panic!("Should have sent a connect request, but got {:?}", x),
        };
        run_to_stalled(&mut exec);
        // The remote peer did not connect to us, A2DP Sink should initiate a connection
        // and insert into `peers`.
        assert!(peers.lock().is_connected(&peer_id));
    }
fn wait_to_initiate_success_with_no_connected_peer ( ) { let ( mut exec , peers , proxy , mut prof_stream , controller_pool ) = setup_connected_peer_test ( ) ; // Initialize context to a fixed point in time. exec . set_fake_time ( fasync :: Time :: from_nanos ( 1000000000 ) ) ; let peer_id = PeerId ( 1 ) ; // Simulate getting the service found event. let attributes = vec ! [ Attribute { id ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST element DataElement Sequence ( vec [ Some ( Box new ( DataElement Sequence ( vec [ Some ( Box new ( Uuid from ( ServiceClassProfileIdentifier AudioSource ) into ( ) ) ) Some ( Box new ( DataElement Uint16 ( 0x0103 ) ) ) // Version 1.3 ] ) ) ) ] ) } ] ; handle_services_found ( & peer_id , & attributes , peers . clone ( ) , controller_pool . clone ( ) , proxy . clone ( ) , ) ; run_to_stalled ( & mut exec ) ; // At this point, a remote peer was found, but hasn't connected yet. There // should be no entry for it. assert ! ( peers lock ( ) is_connected ( peer_id ) ) ; // Fast forward time by 5 seconds. In this time, the remote peer has not // connected. exec . set_fake_time ( fasync :: Time :: from_nanos ( 6000000000 ) ) ; exec . wake_expired_timers ( ) ; run_to_stalled ( & mut exec ) ; // After fast forwarding time, expect and handle the `connect` request // because A2DP-sink should be initiating. let ( _test , transport ) = zx :: Socket :: create ( zx :: SocketOpts :: DATAGRAM ) . expect ( " " ) ; let request = exec . run_until_stalled ( & mut prof_stream . next ( ) ) ; match request { Poll :: Ready ( Some ( Ok ( ProfileRequest :: Connect { peer_id , responder , .. } ) ) ) => { assert_eq ! ( PeerId ( 1 ) peer_id into ( ) ) ; responder . send ( & mut Ok ( Channel { socket : Some ( transport ) , .. Channel :: new_empty ( ) } ) ) . expect ( " " ) ; } x => panic ! ( " " x ) , } ; run_to_stalled ( & mut exec ) ; // The remote peer did not connect to us, A2DP Sink should initiate a connection // and insert into `peers`. assert ! ( peers lock ( ) is_connected ( peer_id ) ) ; }
Tests that A2DP sink assumes the initiator role when a peer is found, but
not connected, and the timeout completes.
Tests that A2DP sink assumes the initiator role when a peer is found but not connected and the timeout completes .