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 "get_total_number_of_items.h"
21 #include "packet_test_helper.h"
22 
23 namespace bluetooth {
24 namespace avrcp {
25 
26 using TestGetTotalNumItemsReqPacket =
27     TestPacketType<GetTotalNumberOfItemsRequest>;
28 
TEST(GetTotalNumberOfItemsResponseBuilderTest,builderTest)29 TEST(GetTotalNumberOfItemsResponseBuilderTest, builderTest) {
30   auto builder = GetTotalNumberOfItemsResponseBuilder::MakeBuilder(
31       Status::NO_ERROR, 0x0000u, 0x00000005u);
32   ASSERT_EQ(builder->size(), get_total_number_of_items_response.size());
33 
34   auto test_packet = TestGetTotalNumItemsReqPacket::Make();
35   builder->Serialize(test_packet);
36   ASSERT_EQ(test_packet->GetData(), get_total_number_of_items_response);
37 }
38 
TEST(GetTotalNumberOfItemsResponseBuilderTest,errorStatusTest)39 TEST(GetTotalNumberOfItemsResponseBuilderTest, errorStatusTest) {
40   std::vector<uint8_t> inv_scope_status_packet = {0x75, 0x00, 0x01, 0x0a};
41   auto builder = GetTotalNumberOfItemsResponseBuilder::MakeBuilder(
42       Status::INVALID_SCOPE, 0x1234u, 0x56789abcu);
43   ASSERT_EQ(builder->size(), inv_scope_status_packet.size());
44 
45   auto test_packet = TestGetTotalNumItemsReqPacket::Make();
46   builder->Serialize(test_packet);
47   ASSERT_EQ(test_packet->GetData(), inv_scope_status_packet);
48 }
49 
TEST(GetTotalNumberOfItemsRequestTest,getterTest)50 TEST(GetTotalNumberOfItemsRequestTest, getterTest) {
51   auto test_packet = TestGetTotalNumItemsReqPacket::Make(
52       get_total_number_of_items_request_now_playing);
53   ASSERT_EQ(test_packet->GetScope(), Scope::NOW_PLAYING);
54 }
55 
TEST(GetTotalNumberOfItemsRequestTest,validTest)56 TEST(GetTotalNumberOfItemsRequestTest, validTest) {
57   auto test_packet = TestGetTotalNumItemsReqPacket::Make(
58       get_total_number_of_items_request_now_playing);
59   ASSERT_TRUE(test_packet->IsValid());
60 }
61 
TEST(GetTotalNumberOfItemsRequestTest,invalidTest)62 TEST(GetTotalNumberOfItemsRequestTest, invalidTest) {
63   auto packet_copy = get_total_number_of_items_request_now_playing;
64   packet_copy.push_back(0x00);
65   auto test_packet = TestGetTotalNumItemsReqPacket::Make(packet_copy);
66   ASSERT_FALSE(test_packet->IsValid());
67 
68   std::vector<uint8_t> short_packet = {0x00, 0x01, 0x02, 0x03};
69   ASSERT_FALSE(test_packet->IsValid());
70 }
71 
72 }  // namespace avrcp
73 }  // namespace bluetooth