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 "pass_through_packet.h"
22
23 namespace bluetooth {
24 namespace avrcp {
25
26 using TestPassThroughPacket = TestPacketType<PassThroughPacket>;
27
TEST(PassThroughPacketBuilderTest,builderTest)28 TEST(PassThroughPacketBuilderTest, builderTest) {
29 auto builder = PassThroughPacketBuilder::MakeBuilder(false, true, 0x44);
30 ASSERT_EQ(builder->size(), pass_through_command_play_pushed.size());
31 auto test_packet = TestPassThroughPacket::Make();
32 builder->Serialize(test_packet);
33 ASSERT_EQ(test_packet->GetData(), pass_through_command_play_pushed);
34
35 builder = PassThroughPacketBuilder::MakeBuilder(true, false, 0x44);
36 ASSERT_EQ(builder->size(), pass_through_command_play_released.size());
37 test_packet = TestPassThroughPacket::Make();
38 builder->Serialize(test_packet);
39 ASSERT_EQ(test_packet->GetData(), pass_through_command_play_released);
40 }
41
TEST(PassThroughPacketTest,getterTest)42 TEST(PassThroughPacketTest, getterTest) {
43 auto test_packet =
44 TestPassThroughPacket::Make(pass_through_command_play_pushed);
45 ASSERT_EQ(test_packet->GetKeyState(), KeyState::PUSHED);
46 ASSERT_EQ(test_packet->GetOperationId(), 0x44);
47
48 test_packet = TestPassThroughPacket::Make(pass_through_command_play_released);
49 ASSERT_EQ(test_packet->GetKeyState(), KeyState::RELEASED);
50 ASSERT_EQ(test_packet->GetOperationId(), 0x44);
51 }
52
TEST(PassThroughPacketTest,validTest)53 TEST(PassThroughPacketTest, validTest) {
54 auto test_packet =
55 TestPassThroughPacket::Make(pass_through_command_play_pushed);
56 ASSERT_TRUE(test_packet->IsValid());
57
58 test_packet = TestPassThroughPacket::Make(pass_through_command_play_released);
59 ASSERT_TRUE(test_packet->IsValid());
60 }
61
TEST(PassThroughPacketTest,invalidTest)62 TEST(PassThroughPacketTest, invalidTest) {
63 std::vector<uint8_t> packet_copy = pass_through_command_play_pushed;
64 packet_copy.push_back(0x00);
65 auto test_packet = TestPassThroughPacket::Make(packet_copy);
66 ASSERT_FALSE(test_packet->IsValid());
67
68 std::vector<uint8_t> short_packet = {0, 1, 2, 3, 4, 5};
69 test_packet = TestPassThroughPacket::Make(short_packet);
70 ASSERT_FALSE(test_packet->IsValid());
71 }
72
73 } // namespace avrcp
74 } // namespace bluetooth