1 /* 2 * Copyright 2020 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 "stack/include/a2dp_vendor_ldac_decoder.h" 18 19 #include <gtest/gtest.h> 20 21 #include <cstdint> 22 23 #include "osi/include/allocator.h" 24 #include "stack/include/bt_hdr.h" 25 26 namespace { 27 Data(BT_HDR * packet)28uint8_t* Data(BT_HDR* packet) { return packet->data + packet->offset; } 29 30 } // namespace 31 32 /** 33 * Test class to test selected functionality in stack/a2dp 34 */ 35 class A2dpStackTest : public ::testing::Test { 36 protected: AllocateL2capPacket(const std::vector<uint8_t> data) const37 BT_HDR* AllocateL2capPacket(const std::vector<uint8_t> data) const { 38 auto packet = AllocatePacket(data.size()); 39 std::copy(data.cbegin(), data.cend(), Data(packet)); 40 return packet; 41 } 42 43 private: AllocatePacket(size_t packet_length) const44 BT_HDR* AllocatePacket(size_t packet_length) const { 45 BT_HDR* packet = 46 static_cast<BT_HDR*>(osi_calloc(sizeof(BT_HDR) + packet_length)); 47 packet->len = packet_length; 48 return packet; 49 } 50 }; 51 TEST_F(A2dpStackTest,DecodePacket_ZeroLength)52TEST_F(A2dpStackTest, DecodePacket_ZeroLength) { 53 const std::vector<uint8_t> data; 54 BT_HDR* p_buf = AllocateL2capPacket(data); 55 ASSERT_FALSE(a2dp_vendor_ldac_decoder_decode_packet(p_buf)); 56 osi_free(p_buf); 57 } 58