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_browsed_player.h"
22
23 namespace bluetooth {
24 namespace avrcp {
25
26 using TestSetBrowsedPlayerPacket = TestPacketType<SetBrowsedPlayerRequest>;
27
TEST(SetBrowsedPlayerResponseBuilder,builderTest)28 TEST(SetBrowsedPlayerResponseBuilder, builderTest) {
29 auto builder = SetBrowsedPlayerResponseBuilder::MakeBuilder(Status::NO_ERROR,
30 0x0000, 4, 0, "");
31 ASSERT_EQ(builder->size(), set_browsed_player_response.size());
32
33 auto test_packet = TestSetBrowsedPlayerPacket::Make();
34 builder->Serialize(test_packet);
35 ASSERT_EQ(test_packet->GetData(), set_browsed_player_response);
36 }
37
TEST(SetBrowsedPlayerResponseBuilder,errorStatusTest)38 TEST(SetBrowsedPlayerResponseBuilder, errorStatusTest) {
39 std::vector<uint8_t> player_not_browsable_status = {0x70, 0x00, 0x01, 0x12};
40 auto builder = SetBrowsedPlayerResponseBuilder::MakeBuilder(
41 Status::PLAYER_NOT_BROWSABLE, 0x1234, 5, 6, "Field Not Used");
42 ASSERT_EQ(builder->size(), player_not_browsable_status.size());
43
44 auto test_packet = TestSetBrowsedPlayerPacket::Make();
45 builder->Serialize(test_packet);
46 ASSERT_EQ(test_packet->GetData(), player_not_browsable_status);
47 }
48
TEST(SetBrowsedPlayerRequestTest,getterTest)49 TEST(SetBrowsedPlayerRequestTest, getterTest) {
50 auto test_packet =
51 TestSetBrowsedPlayerPacket::Make(set_browsed_player_request);
52
53 ASSERT_EQ(test_packet->GetPlayerId(), 0x0002u);
54 }
55
TEST(SetBrowsedPlayerRequestTest,validTest)56 TEST(SetBrowsedPlayerRequestTest, validTest) {
57 auto test_packet =
58 TestSetBrowsedPlayerPacket::Make(set_browsed_player_request);
59 ASSERT_TRUE(test_packet->IsValid());
60 }
61
TEST(SetBrowsedPlayerRequestTest,invalidTest)62 TEST(SetBrowsedPlayerRequestTest, invalidTest) {
63 auto packet_copy = set_browsed_player_request;
64 packet_copy.push_back(0x00);
65 auto test_packet = TestSetBrowsedPlayerPacket::Make(packet_copy);
66 ASSERT_FALSE(test_packet->IsValid());
67
68 std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03, 0x04};
69 test_packet = TestSetBrowsedPlayerPacket::Make(short_packet);
70 ASSERT_FALSE(test_packet->IsValid());
71 }
72
73 } // namespace avrcp
74 } // namespace bluetooth