• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "async_common_event_result.h"
17 #include "asynccommoneventresult_fuzzer.h"
18 #include "fuzz_common_base.h"
19 #include <fuzzer/FuzzedDataProvider.h>
20 
21 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)22 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp)
23 {
24     std::string stringData = fdp->ConsumeRandomLengthString();
25     int32_t code = fdp->ConsumeIntegral<int32_t>();
26     bool enabled = fdp->ConsumeBool();
27     std::shared_ptr<EventFwk::AsyncCommonEventResult> result = std::make_shared<EventFwk::AsyncCommonEventResult>(
28         code, stringData, enabled, enabled, nullptr);
29     if (result != nullptr) {
30         // test SetCode function
31         result->SetCode(code);
32         // test GetCode function
33         result->GetCode();
34         // test SetData function
35         result->SetData(stringData);
36         // test GetData function
37         result->GetData();
38         // test SetCodeAndData function
39         result->SetCodeAndData(code, stringData);
40         // test AbortCommonEvent function
41         result->AbortCommonEvent();
42         // test ClearAbortCommonEvent function
43         result->ClearAbortCommonEvent();
44         // test GetAbortCommonEvent function
45         result->GetAbortCommonEvent();
46         // test IsOrderedCommonEvent function
47         result->IsOrderedCommonEvent();
48         // test CheckSynchronous function
49         result->CheckSynchronous();
50         // test IsStickyCommonEvent function
51         return result->IsStickyCommonEvent();
52     }
53     return false;
54 }
55 }
56 
57 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
59 {
60     /* Run your code on data */
61     FuzzedDataProvider fdp(data, size);
62     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
63     return 0;
64 }
65