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