1 /*
2  * Copyright 2023 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 "set_player_application_setting_value.h"
18 
19 #include <gtest/gtest.h>
20 
21 #include "avrcp_test_packets.h"
22 #include "packet_test_helper.h"
23 
24 namespace bluetooth {
25 namespace avrcp {
26 
27 using SetPlayerApplicationSettingValueRequestTestPacket =
28         TestPacketType<SetPlayerApplicationSettingValueRequest>;
29 using SetPlayerApplicationSettingValueRspTestPacket = TestPacketType<Packet>;
30 
31 // Test parsing a Set Player Application Setting Value Request
TEST(SetPlayerApplicationSettingValueRequestPacketTest,getterTest)32 TEST(SetPlayerApplicationSettingValueRequestPacketTest, getterTest) {
33   std::vector<PlayerAttribute> attrs = {PlayerAttribute::REPEAT, PlayerAttribute::SHUFFLE};
34   std::vector<uint8_t> vals = {0x01, 0x01};  // All values: OFF
35   auto test_packet = SetPlayerApplicationSettingValueRequestTestPacket::Make(
36           set_player_application_setting_value_request);
37 
38   ASSERT_EQ(test_packet->GetNumberOfRequestedAttributes(), 2);
39   ASSERT_EQ(test_packet->GetRequestedAttributes(), attrs);
40   ASSERT_EQ(test_packet->GetRequestedValues(), vals);
41 }
42 
TEST(SetPlayerApplicationSettingValueRequestPacketTest,validTest)43 TEST(SetPlayerApplicationSettingValueRequestPacketTest, validTest) {
44   auto test_packet = SetPlayerApplicationSettingValueRequestTestPacket::Make(
45           set_player_application_setting_value_request);
46   ASSERT_TRUE(test_packet->IsValid());
47 }
48 
TEST(SetPlayerApplicationSettingValueRequestPacketTest,invalidTest)49 TEST(SetPlayerApplicationSettingValueRequestPacketTest, invalidTest) {
50   std::vector<uint8_t> packet_copy = set_player_application_setting_value_request;
51   packet_copy.push_back(0x00);
52   auto test_packet = SetPlayerApplicationSettingValueRequestTestPacket::Make(packet_copy);
53   ASSERT_FALSE(test_packet->IsValid());
54 
55   std::vector<uint8_t> short_packet = {
56           0, 1, 2, 3, 4, 5, 6,
57   };
58   test_packet = SetPlayerApplicationSettingValueRequestTestPacket::Make(short_packet);
59   ASSERT_FALSE(test_packet->IsValid());
60 }
61 
TEST(SetPlayerApplicationSettingValueResponseBuilderBuilderTest,builderTest)62 TEST(SetPlayerApplicationSettingValueResponseBuilderBuilderTest, builderTest) {
63   auto builder = SetPlayerApplicationSettingValueResponseBuilder::MakeBuilder();
64 
65   ASSERT_EQ(builder->size(), set_player_application_setting_value_response.size());
66 
67   auto test_packet = SetPlayerApplicationSettingValueRspTestPacket::Make();
68   builder->Serialize(test_packet);
69   ASSERT_EQ(test_packet->GetData(), set_player_application_setting_value_response);
70 }
71 
72 }  // namespace avrcp
73 }  // namespace bluetooth
74