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 // Adapted from vendor_packet_test.cc 18 19 #include <gtest/gtest.h> 20 #include <tuple> 21 22 #include "avrcp_test_packets.h" 23 #include "packet_test_helper.h" 24 #include "vendor_packet.h" 25 26 namespace bluetooth { 27 28 namespace avrcp { 29 30 using TestVendorPacket = TestPacketType<VendorPacket>; 31 32 using TestParam = std::tuple<std::vector<uint8_t>, CommandPdu>; 33 class VendorPacketTest : public ::testing::TestWithParam<TestParam> { 34 public: GetPacketData()35 std::vector<uint8_t> GetPacketData() { return std::get<0>(GetParam()); } GetCommandPdu()36 CommandPdu GetCommandPdu() { return std::get<1>(GetParam()); } 37 }; 38 LLVMFuzzerTestOneInput(const char * data,size_t size)39extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) { 40 std::vector<uint8_t> short_vendor_packet; 41 42 // Expected packet size by the library is > 19 43 if (size >= 19) { 44 for (size_t x = 0; x < size; x++) { 45 short_vendor_packet.push_back(data[x]); 46 } 47 48 } else { 49 return 0; 50 } 51 52 auto test_packet = TestVendorPacket::Make(short_vendor_packet); 53 54 test_packet->GetCompanyId(); 55 test_packet->GetCommandPdu(); 56 test_packet->GetPacketType(); 57 test_packet->GetParameterLength(); 58 test_packet->IsValid(); 59 test_packet->ToString(); 60 61 return 0; 62 } 63 64 } // namespace avrcp 65 } // namespace bluetooth 66