src/connectivity/bluetooth/core/bt-host/gap/low_energy_discovery_manager_unittest.cc
// Emulate a number of connectable and non-connectable advertisers in both undirected connectable
// and directed connectable modes. This test is to ensure that the only peers notified during a
// passive background scan are from connectable peers that are already in the cache.
Emulate a number of connectable and non-connectable advertisers in both undirected connectable
and directed connectable modes. This test is to ensure that the only peers notified during a
passive background scan are from connectable peers that are already in the cache.
Emulate a number of connectable and non - connectable advertisers in both undirected connectable and directed connectable modes . This test is to ensure that the only peers notified during a passive background scan are from connectable peers that are already in the cache .
TEST_F(GAP_LowEnergyDiscoveryManagerTest,
       BackgroundScanOnlyHandlesEventsFromKnownConnectableDevices) {
  {
    auto peer = std::make_unique<FakePeer>(kAddress0, true, true);
    test_device()->AddPeer(std::move(peer));
  }
  {
    auto peer = std::make_unique<FakePeer>(kAddress1, true, true);
    test_device()->AddPeer(std::move(peer));
  }
  {
    auto peer = std::make_unique<FakePeer>(kAddress2, false, false);
    test_device()->AddPeer(std::move(peer));
  }
   added to cache below
  {
    auto peer = std::make_unique<FakePeer>(kAddress3, false, false);
    peer->enable_directed_advertising(true);
    test_device()->AddPeer(std::move(peer));
  }
   Address 4: directed connectable; added to cache below
  {
    auto peer = std::make_unique<FakePeer>(kAddress4, true, false);
    peer->enable_directed_advertising(true);
    test_device()->AddPeer(std::move(peer));
  }
   Address 5: directed connectable; NOT in cache
  {
    auto peer = std::make_unique<FakePeer>(kAddress5, true, false);
    peer->enable_directed_advertising(true);
    test_device()->AddPeer(std::move(peer));
  }
   Add cache entries for addresses 0, 2, 3, and 4. The callback should only run for addresses 0
   and 4 as the only known connectable peers. All other advertisements should be ignored.
  auto address0_id = peer_cache()->NewPeer(kAddress0, true)->identifier();
  peer_cache()->NewPeer(kAddress2, false);
  peer_cache()->NewPeer(kAddress3, false);
  auto address4_id = peer_cache()->NewPeer(kAddress4, true)->identifier();
  EXPECT_EQ(4u, peer_cache()->count());
  int count = 0;
  discovery_manager()->set_peer_connectable_callback([&](Peer* peer) {
    ASSERT_TRUE(peer);
    auto id = peer->identifier();
    count++;
    EXPECT_TRUE(id == address0_id || id == address4_id) << id.ToString();
  });
  discovery_manager()->EnableBackgroundScan(true);
  RunLoopUntilIdle();
  EXPECT_EQ(2, count);
   No new remote peer cache entries should have been created.
  EXPECT_EQ(4u, peer_cache()->count());
}
TEST_F ( GAP_LowEnergyDiscoveryManagerTest , BackgroundScanOnlyHandlesEventsFromKnownConnectableDevices ) { { auto peer = std :: make_unique < FakePeer > ( kAddress0 , true , true ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } { auto peer = std :: make_unique < FakePeer > ( kAddress1 , true , true ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } { auto peer = std :: make_unique < FakePeer > ( kAddress2 , false , false ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } { auto peer = std :: make_unique < FakePeer > ( kAddress3 , false , false ) ; peer -> enable_directed_advertising ( true ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } { auto peer = std :: make_unique < FakePeer > ( kAddress4 , true , false ) ; peer -> enable_directed_advertising ( true ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } { auto peer = std :: make_unique < FakePeer > ( kAddress5 , true , false ) ; peer -> enable_directed_advertising ( true ) ; test_device ( ) -> AddPeer ( std :: move ( peer ) ) ; } auto address0_id = peer_cache ( ) -> NewPeer ( kAddress0 , true ) -> identifier ( ) ; peer_cache ( ) -> NewPeer ( kAddress2 , false ) ; peer_cache ( ) -> NewPeer ( kAddress3 , false ) ; auto address4_id = peer_cache ( ) -> NewPeer ( kAddress4 , true ) -> identifier ( ) ; EXPECT_EQ ( 4u , peer_cache ( ) -> count ( ) ) ; int count = 0 ; discovery_manager ( ) -> set_peer_connectable_callback ( [ & ] ( Peer * peer ) { ASSERT_TRUE ( peer ) ; auto id = peer -> identifier ( ) ; count ++ ; EXPECT_TRUE ( id == address0_id || id == address4_id ) << id . ToString ( ) ; } ) ; discovery_manager ( ) -> EnableBackgroundScan ( true ) ; RunLoopUntilIdle ( ) ; EXPECT_EQ ( 2 , count ) ; EXPECT_EQ ( 4u , peer_cache ( ) -> count ( ) ) ; }
Emulate a number of connectable and non-connectable advertisers in both undirected connectable
and directed connectable modes.
Emulate a number of connectable and non - connectable advertisers in both undirected connectable and directed connectable modes .
// Address 0: undirected connectable; added to cache below /*connectable=*/ /*scannable=*/ // Address 1: undirected connectable; NOT in cache /*connectable=*/ /*scannable=*/ // Address 2: not connectable; added to cache below /*connectable=*/ /*scannable=*/ // Address 3: not connectable but directed advertising (NOTE: although a directed advertising PDU // is inherently connectable, it is theoretically possible for the peer_cache() to be in this // state, even if unlikely in practice). // // added to cache below /*connectable=*/ /*scannable=*/ // Address 4: directed connectable; added to cache below /*connectable=*/ /*scannable=*/ // Address 5: directed connectable; NOT in cache /*connectable=*/ /*scannable=*/ // Add cache entries for addresses 0, 2, 3, and 4. The callback should only run for addresses 0 // and 4 as the only known connectable peers. All other advertisements should be ignored. /*connectable=*/ /*connectable=*/ /*connectable=*/ /*connectable=*/ // No new remote peer cache entries should have been created.