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