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_absolute_volume.h"
22
23 namespace bluetooth {
24 namespace avrcp {
25
26 using TestSetVolumeRspPacket = TestPacketType<SetAbsoluteVolumeResponse>;
27
TEST(SetAbsoluteVolumeRequestBuilderTest,builderTest)28 TEST(SetAbsoluteVolumeRequestBuilderTest, builderTest) {
29 auto builder = SetAbsoluteVolumeRequestBuilder::MakeBuilder(0x48);
30 ASSERT_EQ(builder->size(), set_absolute_volume_request.size());
31
32 auto test_packet = TestSetVolumeRspPacket::Make();
33 builder->Serialize(test_packet);
34 ASSERT_EQ(test_packet->GetData(), set_absolute_volume_request);
35 }
36
37 // Test whether the volume field has the highest bit masked
TEST(SetAbsoluteVolumeRequestBuilderTest,volumeMaskTest)38 TEST(SetAbsoluteVolumeRequestBuilderTest, volumeMaskTest) {
39 auto builder = SetAbsoluteVolumeRequestBuilder::MakeBuilder(0xc8);
40 auto test_packet = TestSetVolumeRspPacket::Make();
41 builder->Serialize(test_packet);
42 ASSERT_EQ(test_packet->GetData(), set_absolute_volume_request);
43 }
44
TEST(SetAbsoluteVolumeResponseTest,getterTest)45 TEST(SetAbsoluteVolumeResponseTest, getterTest) {
46 auto test_packet = TestSetVolumeRspPacket::Make(set_absolute_volume_response);
47
48 ASSERT_EQ(test_packet->GetVolume(), 0x43);
49 }
50
TEST(SetAbsoluteVolumeResponseTest,validTest)51 TEST(SetAbsoluteVolumeResponseTest, validTest) {
52 auto test_packet = TestSetVolumeRspPacket::Make(set_absolute_volume_response);
53
54 ASSERT_TRUE(test_packet->IsValid());
55 }
56
TEST(SetAbsoluteVolumeResponseTest,invalidTest)57 TEST(SetAbsoluteVolumeResponseTest, invalidTest) {
58 auto packet_copy = set_absolute_volume_request;
59 packet_copy.push_back(0x00);
60 auto test_packet = TestSetVolumeRspPacket::Make(packet_copy);
61 ASSERT_FALSE(test_packet->IsValid());
62
63 std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03, 0x04};
64 test_packet = TestSetVolumeRspPacket::Make(short_packet);
65 ASSERT_FALSE(test_packet->IsValid());
66
67 auto wrong_ctype = set_absolute_volume_request;
68 wrong_ctype[0] = 0x00;
69 test_packet = TestSetVolumeRspPacket::Make(wrong_ctype);
70 ASSERT_FALSE(test_packet->IsValid());
71 }
72
73 } // namespace avrcp
74 } // namespace bluetooth