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 = SetAddressedPlayerResponseBuilder::MakeBuilder(Status::NO_ERROR);
30 ASSERT_EQ(builder->size(), set_addressed_player_response.size());
31
32 auto test_packet = TestSetAddrPlayerPacket::Make();
33 builder->Serialize(test_packet);
34 ASSERT_EQ(test_packet->GetData(), set_addressed_player_response);
35 }
36
TEST(SetAddressedPlayerRequestTest,getterTest)37 TEST(SetAddressedPlayerRequestTest, getterTest) {
38 auto test_packet = TestSetAddrPlayerPacket::Make(set_addressed_player_request);
39
40 ASSERT_EQ(test_packet->GetPlayerId(), 0x0000u);
41 }
42
TEST(SetAddressedPlayerRequestTest,validTest)43 TEST(SetAddressedPlayerRequestTest, validTest) {
44 auto test_packet = TestSetAddrPlayerPacket::Make(set_addressed_player_request);
45 ASSERT_TRUE(test_packet->IsValid());
46 }
47
TEST(SetAddressedPlayerRequestTest,invalidTest)48 TEST(SetAddressedPlayerRequestTest, invalidTest) {
49 auto packet_copy = set_addressed_player_request;
50 packet_copy.push_back(0x00);
51 auto test_packet = TestSetAddrPlayerPacket::Make(packet_copy);
52 ASSERT_FALSE(test_packet->IsValid());
53
54 std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03, 0x04};
55 test_packet = TestSetAddrPlayerPacket::Make(short_packet);
56 ASSERT_FALSE(test_packet->IsValid());
57 }
58
59 } // namespace avrcp
60 } // namespace bluetooth
61