Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6a88335 authored by Sal Savage's avatar Sal Savage
Browse files

Add tests for the AVRCP Target Cover Art feature

Tag: #feature
Bug: 153076316
Test: atest net_test_avrcp
Test: atest net_test_btpackets
Test: atest net_test_btif
Change-Id: I38e2b4aae5a5f2b1e379f1d3f071f18214d7d5e9
parent dedbea20
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -58,6 +58,17 @@ std::vector<uint8_t> get_element_attributes_request_full = {
    0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00,
    0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06};


// AVRCP Get Element Attributes request for current playing song and attributes
// Title, Artist, Album, Media Number, Playing Time, Total Number of Media,
// Genre, and Cover Art
std::vector<uint8_t> get_element_attributes_request_full_cover_art = {
    0x01, 0x48, 0x00, 0x00, 0x19, 0x58, 0x20, 0x00, 0x00, 0x29, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00,
    0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00,
    0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
    0x00, 0x00, 0x08};

// AVRCP Get Element Attributes response with attribute values as follows
// Title: "Test Song"
// Artist: "Test Artist"
@@ -278,6 +289,20 @@ std::vector<uint8_t> get_item_attributes_request_all_attributes = {
    0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
    0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07};

// AVRCP Get Item Attributes request with all attributes requested
// with the following fields:
//    scope = 0x03 (Now Playing List)
//    uid_counter = 0x0000
//    uid = 0x0000000000000001
//    attributes = Title, Artist, Album, Media Number, Playing Time,
//                 Total Number of Media, Genre, and Cover Art
std::vector<uint8_t> get_item_attributes_request_all_attributes_with_cover_art = {
    0x73, 0x00, 0x2C, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
    0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00,
    0x00, 0x00, 0x08};

// AVRCP Get Item Attributes request with all attributes requested
// with the following fields:
//    scope = 0x03 (Now Playing List)
+190 −8
Original line number Diff line number Diff line
@@ -84,6 +84,19 @@ class AvrcpDeviceTest : public ::testing::Test {
    test_device->BrowseMessageReceived(label, message);
  }

  void SetBipClientStatus(bool connected) {
      test_device->SetBipClientStatus(connected);
  }

  void FilterCoverArt(SongInfo& s) {
    for (auto it = s.attributes.begin(); it != s.attributes.end(); it++) {
      if (it->attribute() == Attribute::DEFAULT_COVER_ART) {
        s.attributes.erase(it);
        break;
      }
    }
  }

  MockFunction<void(uint8_t, bool, const AvrcpResponse&)> response_cb;
  Device* test_device;
};
@@ -98,6 +111,14 @@ TEST_F(AvrcpDeviceTest, addressTest) {
  ASSERT_EQ(device.GetAddress(), RawAddress::kAny);
}

TEST_F(AvrcpDeviceTest, setBipClientStatusTest) {
  ASSERT_EQ(test_device->HasBipClient(), false);
  SetBipClientStatus(true);
  ASSERT_EQ(test_device->HasBipClient(), true);
  SetBipClientStatus(false);
  ASSERT_EQ(test_device->HasBipClient(), false);
}

TEST_F(AvrcpDeviceTest, trackChangedTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;
@@ -112,7 +133,8 @@ TEST_F(AvrcpDeviceTest, trackChangedTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
@@ -246,7 +268,8 @@ TEST_F(AvrcpDeviceTest, trackChangedBeforeInterimTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  MediaInterface::NowPlayingCallback interim_cb;
@@ -411,7 +434,8 @@ TEST_F(AvrcpDeviceTest, nowPlayingChangedBeforeInterim) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  MediaInterface::NowPlayingCallback interim_cb;
@@ -525,7 +549,8 @@ TEST_F(AvrcpDeviceTest, nowPlayingTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};
  EXPECT_CALL(interface, GetNowPlayingList(_))
      .Times(2)
@@ -593,7 +618,8 @@ TEST_F(AvrcpDeviceTest, getElementAttributesTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};

  EXPECT_CALL(interface, GetSongInfo(_)).WillRepeatedly(InvokeCb<0>(info));

@@ -620,6 +646,60 @@ TEST_F(AvrcpDeviceTest, getElementAttributesTest) {
  SendMessage(3, TestAvrcpPacket::Make(get_element_attributes_request_full));
}

TEST_F(AvrcpDeviceTest, getElementAttributesWithCoverArtTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);

  SongInfo info = {"test_id",
                   {// The attribute map
                    AttributeEntry(Attribute::TITLE, "Test Song"),
                    AttributeEntry(Attribute::ARTIST_NAME, "Test Artist"),
                    AttributeEntry(Attribute::ALBUM_NAME, "Test Album"),
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};

  EXPECT_CALL(interface, GetSongInfo(_)).WillRepeatedly(InvokeCb<0>(info));
  SetBipClientStatus(false);

  auto compare_to_no_art =
      GetElementAttributesResponseBuilder::MakeBuilder(0xFFFF);
  compare_to_no_art->AddAttributeEntry(Attribute::TITLE, "Test Song");
  compare_to_no_art->AddAttributeEntry(Attribute::ARTIST_NAME, "Test Artist");
  compare_to_no_art->AddAttributeEntry(Attribute::ALBUM_NAME, "Test Album");
  compare_to_no_art->AddAttributeEntry(Attribute::TRACK_NUMBER, "1");
  compare_to_no_art->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_no_art->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_no_art->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  EXPECT_CALL(response_cb,
              Call(3, false, matchPacket(std::move(compare_to_no_art))))
      .Times(1);
  SendMessage(3,
        TestAvrcpPacket::Make(get_element_attributes_request_full_cover_art));

  SetBipClientStatus(true);

  auto compare_to_full =
      GetElementAttributesResponseBuilder::MakeBuilder(0xFFFF);
  compare_to_full->AddAttributeEntry(Attribute::TITLE, "Test Song");
  compare_to_full->AddAttributeEntry(Attribute::ARTIST_NAME, "Test Artist");
  compare_to_full->AddAttributeEntry(Attribute::ALBUM_NAME, "Test Album");
  compare_to_full->AddAttributeEntry(Attribute::TRACK_NUMBER, "1");
  compare_to_full->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_full->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_full->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  compare_to_full->AddAttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001");
  EXPECT_CALL(response_cb,
              Call(3, false, matchPacket(std::move(compare_to_full))))
      .Times(1);
  SendMessage(3,
        TestAvrcpPacket::Make(get_element_attributes_request_full_cover_art));
}

TEST_F(AvrcpDeviceTest, getElementAttributesMtuTest) {
  auto truncated_packet =
      GetElementAttributesResponseBuilder::MakeBuilder(0xFFFF);
@@ -750,6 +830,7 @@ TEST_F(AvrcpDeviceTest, getNowPlayingListTest) {
  NiceMock<MockA2dpInterface> a2dp_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);
  SetBipClientStatus(false);

  SongInfo info = {"test_id",
                   {// The attribute map
@@ -759,19 +840,53 @@ TEST_F(AvrcpDeviceTest, getNowPlayingListTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  FilterCoverArt(info);
  auto expected_response = GetFolderItemsResponseBuilder::MakeNowPlayingBuilder(
      Status::NO_ERROR, 0x0000, 0xFFFF);
  expected_response->AddSong(MediaElementItem(1, "Test Song", info.attributes));
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(expected_response))))
      .Times(1);
  auto request = TestBrowsePacket::Make(get_folder_items_request_now_playing);
  SendBrowseMessage(1, request);
}

TEST_F(AvrcpDeviceTest, getNowPlayingListWithCoverArtTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);
  SetBipClientStatus(true);

  SongInfo info = {"test_id",
                   {// The attribute map
                    AttributeEntry(Attribute::TITLE, "Test Song"),
                    AttributeEntry(Attribute::ARTIST_NAME, "Test Artist"),
                    AttributeEntry(Attribute::ALBUM_NAME, "Test Album"),
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  auto expected_response = GetFolderItemsResponseBuilder::MakeNowPlayingBuilder(
      Status::NO_ERROR, 0x0000, 0xFFFF);
  expected_response->AddSong(MediaElementItem(1, "Test Song", info.attributes));

  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(expected_response))))
      .Times(1);
  auto request = TestBrowsePacket::Make(get_folder_items_request_now_playing);
  SendBrowseMessage(1, request);
}
@@ -950,12 +1065,15 @@ TEST_F(AvrcpDeviceTest, getItemAttributesNowPlayingTest) {
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000")}};
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  SetBipClientStatus(false);

  auto compare_to_full =
      GetItemAttributesResponseBuilder::MakeBuilder(Status::NO_ERROR, 0xFFFF);
  compare_to_full->AddAttributeEntry(Attribute::TITLE, "Test Song");
@@ -974,7 +1092,70 @@ TEST_F(AvrcpDeviceTest, getItemAttributesNowPlayingTest) {
  SendBrowseMessage(1, request);
}

TEST_F(AvrcpDeviceTest, geItemAttributesMtuTest) {
TEST_F(AvrcpDeviceTest, getItemAttributesNowPlayingWithCoverArtTest) {
  MockMediaInterface interface;
  NiceMock<MockA2dpInterface> a2dp_interface;

  test_device->RegisterInterfaces(&interface, &a2dp_interface, nullptr);

  SongInfo info = {"test_id",
                   {// The attribute map
                    AttributeEntry(Attribute::TITLE, "Test Song"),
                    AttributeEntry(Attribute::ARTIST_NAME, "Test Artist"),
                    AttributeEntry(Attribute::ALBUM_NAME, "Test Album"),
                    AttributeEntry(Attribute::TRACK_NUMBER, "1"),
                    AttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2"),
                    AttributeEntry(Attribute::GENRE, "Test Genre"),
                    AttributeEntry(Attribute::PLAYING_TIME, "1000"),
                    AttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001")}};
  std::vector<SongInfo> list = {info};

  EXPECT_CALL(interface, GetNowPlayingList(_))
      .WillRepeatedly(InvokeCb<0>("test_id", list));

  SetBipClientStatus(true);

  auto compare_to_full =
      GetItemAttributesResponseBuilder::MakeBuilder(Status::NO_ERROR, 0xFFFF);
  compare_to_full->AddAttributeEntry(Attribute::TITLE,"Test Song");
  compare_to_full->AddAttributeEntry(Attribute::ARTIST_NAME, "Test Artist");
  compare_to_full->AddAttributeEntry(Attribute::ALBUM_NAME, "Test Album");
  compare_to_full->AddAttributeEntry(Attribute::TRACK_NUMBER, "1");
  compare_to_full->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_full->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_full->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  compare_to_full->AddAttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001");
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(compare_to_full))))
      .Times(1);

  auto requestWithBip =
      TestBrowsePacket::Make(
          get_item_attributes_request_all_attributes_with_cover_art);
  SendBrowseMessage(1, requestWithBip);

  SetBipClientStatus(false);

  auto compare_to_no_art =
      GetItemAttributesResponseBuilder::MakeBuilder(Status::NO_ERROR, 0xFFFF);
  compare_to_no_art->AddAttributeEntry(Attribute::TITLE, "Test Song");
  compare_to_no_art->AddAttributeEntry(Attribute::ARTIST_NAME, "Test Artist");
  compare_to_no_art->AddAttributeEntry(Attribute::ALBUM_NAME, "Test Album");
  compare_to_no_art->AddAttributeEntry(Attribute::TRACK_NUMBER, "1");
  compare_to_no_art->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_no_art->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_no_art->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(compare_to_no_art))))
      .Times(1);

  auto requestWithoutBip =
      TestBrowsePacket::Make(
          get_item_attributes_request_all_attributes_with_cover_art);
  SendBrowseMessage(1, requestWithoutBip);
}

TEST_F(AvrcpDeviceTest, getItemAttributesMtuTest) {
  auto truncated_packet =
      GetItemAttributesResponseBuilder::MakeBuilder(Status::NO_ERROR, 0xFFFF);
  truncated_packet->AddAttributeEntry(Attribute::TITLE, "1234");
@@ -1371,6 +1552,7 @@ TEST_F(AvrcpDeviceTest, getInvalidItemAttributesTest) {
  compare_to_full->AddAttributeEntry(Attribute::TOTAL_NUMBER_OF_TRACKS, "2");
  compare_to_full->AddAttributeEntry(Attribute::GENRE, "Test Genre");
  compare_to_full->AddAttributeEntry(Attribute::PLAYING_TIME, "1000");
  compare_to_full->AddAttributeEntry(Attribute::DEFAULT_COVER_ART, "0000001");
  EXPECT_CALL(response_cb,
              Call(1, true, matchPacket(std::move(compare_to_full))))
      .Times(1);