From 034b268321a8845557ab69a431aeaf03c2d1352e Mon Sep 17 00:00:00 2001 From: Sal Savage Date: Mon, 9 Mar 2020 16:01:25 -0700 Subject: [PATCH] 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 --- packet/tests/avrcp/avrcp_test_packets.h | 25 ++++ profile/avrcp/tests/avrcp_device_test.cc | 198 +++++++++++++++++++++++++++++-- 2 files changed, 215 insertions(+), 8 deletions(-) diff --git a/packet/tests/avrcp/avrcp_test_packets.h b/packet/tests/avrcp/avrcp_test_packets.h index 9028805d6..c0ac161ee 100644 --- a/packet/tests/avrcp/avrcp_test_packets.h +++ b/packet/tests/avrcp/avrcp_test_packets.h @@ -58,6 +58,17 @@ std::vector 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 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" @@ -281,6 +292,20 @@ std::vector get_item_attributes_request_all_attributes = { // 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 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) // uid_counter = 0x0001 // uid = 0x0000000000000001 std::vector get_item_attributes_request_all_attributes_invalid = { diff --git a/profile/avrcp/tests/avrcp_device_test.cc b/profile/avrcp/tests/avrcp_device_test.cc index 8d70e43a6..516949291 100644 --- a/profile/avrcp/tests/avrcp_device_test.cc +++ b/profile/avrcp/tests/avrcp_device_test.cc @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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); -- 2.11.0