1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <gtest/gtest.h> 18 19 #include "avrcp_test_packets.h" 20 #include "packet_test_helper.h" 21 #include "play_item.h" 22 23 namespace bluetooth { 24 namespace avrcp { 25 26 using TestPlayItemReqPacket = TestPacketType<PlayItemRequest>; 27 28 TEST(PlayItemResponseBuilderTest, builderTest) { 29 auto builder = PlayItemResponseBuilder::MakeBuilder(Status::NO_ERROR); 30 ASSERT_EQ(builder->size(), play_item_response.size()); 31 32 auto test_packet = TestPlayItemReqPacket::Make(); 33 builder->Serialize(test_packet); 34 ASSERT_EQ(test_packet->GetData(), play_item_response); 35 } 36 37 TEST(PlayItemResponseTest, getterTest) { 38 auto test_packet = TestPlayItemReqPacket::Make(play_item_request); 39 40 ASSERT_EQ(test_packet->GetScope(), Scope::NOW_PLAYING); 41 ASSERT_EQ(test_packet->GetUid(), 0x0000000000000003u); 42 ASSERT_EQ(test_packet->GetUidCounter(), 0x0000u); 43 } 44 45 TEST(PlayItemResponseTest, validTest) { 46 auto test_packet = TestPlayItemReqPacket::Make(play_item_request); 47 48 ASSERT_TRUE(test_packet->IsValid()); 49 } 50 51 TEST(PlayItemResponseTest, invalidTest) { 52 auto packet_copy = play_item_request; 53 packet_copy.push_back(0x00); 54 auto test_packet = TestPlayItemReqPacket::Make(packet_copy); 55 ASSERT_FALSE(test_packet->IsValid()); 56 57 std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03, 0x04}; 58 test_packet = TestPlayItemReqPacket::Make(short_packet); 59 ASSERT_FALSE(test_packet->IsValid()); 60 } 61 62 } // namespace avrcp 63 } // namespace bluetooth 64