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 "get_current_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 GetCurrentPlayerApplicationSettingValueRequestTestPacket =
28         TestPacketType<GetCurrentPlayerApplicationSettingValueRequest>;
29 using GetCurrentPlayerApplicationSettingValueRspTestPacket = TestPacketType<Packet>;
30 
31 // Test parsing a Get Current Player Application Setting Value Request
TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest,getterTest)32 TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest, getterTest) {
33   std::vector<PlayerAttribute> attrs = {PlayerAttribute::REPEAT, PlayerAttribute::SHUFFLE};
34   auto test_packet = GetCurrentPlayerApplicationSettingValueRequestTestPacket::Make(
35           get_current_player_application_setting_value_request);
36 
37   ASSERT_EQ(test_packet->GetNumberOfRequestedAttributes(), 2);
38   ASSERT_EQ(test_packet->GetRequestedAttributes(), attrs);
39 }
40 
TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest,validTest)41 TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest, validTest) {
42   auto test_packet = GetCurrentPlayerApplicationSettingValueRequestTestPacket::Make(
43           get_current_player_application_setting_value_request);
44   ASSERT_TRUE(test_packet->IsValid());
45 }
46 
TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest,invalidTest)47 TEST(GetCurrentPlayerApplicationSettingValueRequestPacketTest, invalidTest) {
48   std::vector<uint8_t> packet_copy = get_current_player_application_setting_value_request;
49   packet_copy.push_back(0x00);
50   auto test_packet = GetCurrentPlayerApplicationSettingValueRequestTestPacket::Make(packet_copy);
51   ASSERT_FALSE(test_packet->IsValid());
52 
53   std::vector<uint8_t> short_packet = {
54           0, 1, 2, 3, 4, 5, 6,
55   };
56   test_packet = GetCurrentPlayerApplicationSettingValueRequestTestPacket::Make(short_packet);
57   ASSERT_FALSE(test_packet->IsValid());
58 }
59 
TEST(GetCurrentPlayerApplicationSettingValueResponseBuilderTest,builderTest)60 TEST(GetCurrentPlayerApplicationSettingValueResponseBuilderTest, builderTest) {
61   std::vector<PlayerAttribute> attrs = {PlayerAttribute::REPEAT, PlayerAttribute::SHUFFLE};
62   std::vector<uint8_t> vals = {0x01, 0x01};  // All values: OFF
63   auto builder = GetCurrentPlayerApplicationSettingValueResponseBuilder::MakeBuilder(attrs, vals);
64 
65   ASSERT_EQ(builder->size(), get_current_player_application_setting_value_response.size());
66 
67   auto test_packet = GetCurrentPlayerApplicationSettingValueRspTestPacket::Make();
68   builder->Serialize(test_packet);
69   ASSERT_EQ(test_packet->GetData(), get_current_player_application_setting_value_response);
70 }
71 
72 }  // namespace avrcp
73 }  // namespace bluetooth
74