1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "matchingskills_fuzzer.h" 17 #include "fuzz_common_base.h" 18 #include <fuzzer/FuzzedDataProvider.h> 19 #define private public 20 #define protected public 21 #include "matching_skills.h" 22 #undef private 23 #undef protected 24 25 namespace OHOS { DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)26bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) 27 { 28 std::string stringData = fdp->ConsumeRandomLengthString(); 29 size_t index = fdp->ConsumeIntegral<size_t>(); 30 Parcel parcel; 31 // test MatchingSkills class function 32 EventFwk::MatchingSkills matchingSkills; 33 // test HasEntity function 34 matchingSkills.HasEntity(stringData); 35 // test RemoveEntity function 36 matchingSkills.RemoveEntity(stringData); 37 // test CountEntities function 38 matchingSkills.CountEntities(); 39 // test GetEvents function 40 matchingSkills.GetEvents(); 41 // test RemoveEvent function 42 matchingSkills.RemoveEvent(stringData); 43 // test HasEvent function 44 matchingSkills.HasEvent(stringData); 45 // test HasScheme function 46 matchingSkills.HasScheme(stringData); 47 // test RemoveScheme function 48 matchingSkills.RemoveScheme(stringData); 49 // test CountSchemes function 50 matchingSkills.CountSchemes(); 51 // test MatchEvent function 52 matchingSkills.MatchEvent(stringData); 53 // test MatchEntity function 54 std::vector<std::string> permissions; 55 permissions.emplace_back(stringData); 56 matchingSkills.MatchEntity(permissions); 57 // test MatchScheme function 58 matchingSkills.MatchScheme(stringData); 59 matchingSkills.GetEntity(index); 60 matchingSkills.GetEvent(index); 61 matchingSkills.GetScheme(index); 62 matchingSkills.ReadFromParcel(parcel); 63 matchingSkills.Unmarshalling(parcel); 64 matchingSkills.AddEntity(stringData); 65 matchingSkills.AddEvent(stringData); 66 matchingSkills.CountEvent(); 67 matchingSkills.AddScheme(stringData); 68 matchingSkills.Marshalling(parcel); 69 // test Match function 70 AAFwk::Want want; 71 return matchingSkills.Match(want); 72 } 73 } 74 75 /* Fuzzer entry point */ LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)76extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 77 { 78 /* Run your code on data */ 79 FuzzedDataProvider fdp(data, size); 80 OHOS::DoSomethingInterestingWithMyAPI(&fdp); 81 return 0; 82 } 83