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 #define private public
17 #define protected public
18 #include "notification_action_button.h"
19 #undef private
20 #undef protected
21 #include "notificationactionbutton_fuzzer.h"
22 #include "want_agent_info.h"
23 #include "want_agent_helper.h"
24 #include "want_params.h"
25 #include <fuzzer/FuzzedDataProvider.h>
26
27 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)28 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
29 {
30 AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
31 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
32 AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
33 std::string title = fdp->ConsumeRandomLengthString();
34 std::shared_ptr<Notification::NotificationActionButton> actionButton =
35 Notification::NotificationActionButton::Create(nullptr, title, wantAgent);
36 if (actionButton == nullptr) {
37 return false;
38 }
39 // test AddAdditionalData function
40 AAFwk::WantParams extras;
41 actionButton->AddAdditionalData(extras);
42 // test AddMimeTypeOnlyUserInput function
43 std::shared_ptr<Notification::NotificationUserInput> userInput =
44 std::make_shared<Notification::NotificationUserInput>();
45 actionButton->AddMimeTypeOnlyUserInput(userInput);
46 actionButton->AddNotificationUserInput(userInput);
47 // test GetMimeTypeOnlyUserInputs function
48 actionButton->GetMimeTypeOnlyUserInputs();
49 // test GetUserInput function
50 actionButton->GetUserInput();
51 // test IsAutoCreatedReplies function
52 actionButton->IsAutoCreatedReplies();
53 return true;
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