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 "set_addressed_player.h"
22
23 namespace bluetooth {
24 namespace avrcp {
25
26 using TestSetAddrPlayerPacket = TestPacketType<SetAddressedPlayerRequest>;
27
TEST(SetAddressedPlayerResponseBuilderTest,builderTest)28 TEST(SetAddressedPlayerResponseBuilderTest, builderTest) {
29 auto builder =
30 SetAddressedPlayerResponseBuilder::MakeBuilder(Status::NO_ERROR);
31 ASSERT_EQ(builder->size(), set_addressed_player_response.size());
32
33 auto test_packet = TestSetAddrPlayerPacket::Make();
34 builder->Serialize(test_packet);
35 ASSERT_EQ(test_packet->GetData(), set_addressed_player_response);
36 }
37
TEST(SetAddressedPlayerRequestTest,getterTest)38 TEST(SetAddressedPlayerRequestTest, getterTest) {
39 auto test_packet =
40 TestSetAddrPlayerPacket::Make(set_addressed_player_request);
41
42 ASSERT_EQ(test_packet->GetPlayerId(), 0x0000u);
43 }
44
TEST(SetAddressedPlayerRequestTest,validTest)45 TEST(SetAddressedPlayerRequestTest, validTest) {
46 auto test_packet =
47 TestSetAddrPlayerPacket::Make(set_addressed_player_request);
48 ASSERT_TRUE(test_packet->IsValid());
49 }
50
TEST(SetAddressedPlayerRequestTest,invalidTest)51 TEST(SetAddressedPlayerRequestTest, invalidTest) {
52 auto packet_copy = set_addressed_player_request;
53 packet_copy.push_back(0x00);
54 auto test_packet = TestSetAddrPlayerPacket::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 = TestSetAddrPlayerPacket::Make(short_packet);
59 ASSERT_FALSE(test_packet->IsValid());
60 }
61
62 } // namespace avrcp
63 } // namespace bluetooth
64