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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include "avrcp_test_packets.h"
21 #include "change_path.h"
22 #include "packet_test_helper.h"
23 
24 namespace bluetooth {
25 namespace avrcp {
26 
27 using TestChangePathReqPacket = TestPacketType<ChangePathRequest>;
28 
TEST(ChangePathResponseBuilderTest,builderTest)29 TEST(ChangePathResponseBuilderTest, builderTest) {
30   auto builder = ChangePathResponseBuilder::MakeBuilder(Status::NO_ERROR, 2);
31   ASSERT_EQ(builder->size(), change_path_response.size());
32 
33   auto test_packet = TestChangePathReqPacket::Make();
34   builder->Serialize(test_packet);
35   ASSERT_EQ(test_packet->GetData(), change_path_response);
36 }
37 
TEST(ChangePathResponseBuilderTest,builderErrorStatusTest)38 TEST(ChangePathResponseBuilderTest, builderErrorStatusTest) {
39   // NOTE: The num items in folder field doesn't matter when the status is
40   // not NO_ERROR
41   auto builder =
42       ChangePathResponseBuilder::MakeBuilder(Status::INVALID_DIRECTION, 2);
43   ASSERT_EQ(builder->size(), change_path_error_response.size());
44 
45   auto test_packet = TestChangePathReqPacket::Make();
46   builder->Serialize(test_packet);
47   ASSERT_EQ(test_packet->GetData(), change_path_error_response);
48 }
49 
TEST(ChangePathRequestTest,getterTest)50 TEST(ChangePathRequestTest, getterTest) {
51   auto test_packet = TestChangePathReqPacket::Make(change_path_request);
52 
53   ASSERT_EQ(test_packet->GetUidCounter(), 0x0000u);
54   ASSERT_EQ(test_packet->GetDirection(), Direction::DOWN);
55   ASSERT_EQ(test_packet->GetUid(), 0x0000000000000002u);
56 }
57 
TEST(ChangePathRequestTest,validTest)58 TEST(ChangePathRequestTest, validTest) {
59   auto test_packet = TestChangePathReqPacket::Make(change_path_request);
60   ASSERT_TRUE(test_packet->IsValid());
61 }
62 
TEST(ChangePathRequestTest,invalidTest)63 TEST(ChangePathRequestTest, invalidTest) {
64   auto packet_copy = change_path_request;
65   packet_copy.push_back(0x00);
66   auto test_packet = TestChangePathReqPacket::Make(packet_copy);
67   ASSERT_FALSE(test_packet->IsValid());
68 
69   std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03, 0x04};
70   test_packet = TestChangePathReqPacket::Make(short_packet);
71   ASSERT_FALSE(test_packet->IsValid());
72 }
73 
TEST(ChangePathRequestBuilder,builderTest)74 TEST(ChangePathRequestBuilder, builderTest) {
75   auto builder = ChangePathRequestBuilder::MakeBuilder(0, Direction::DOWN, 2);
76   ASSERT_EQ(builder->size(), change_path_request.size());
77 
78   auto test_packet = TestChangePathReqPacket::Make();
79   builder->Serialize(test_packet);
80   ASSERT_EQ(test_packet->GetData(), change_path_request);
81 }
82 
83 }  // namespace avrcp
84 }  // namespace bluetooth