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