• 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 #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 
26 namespace OHOS {
DoSomethingInterestingWithMyAPI(const char * data,size_t size)27     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
28     {
29         AbilityRuntime::WantAgent::WantAgentInfo paramsInfo;
30         std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent =
31             AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(paramsInfo);
32         std::string title(data);
33         std::shared_ptr<Notification::NotificationActionButton> actionButton =
34             Notification::NotificationActionButton::Create(nullptr, title, wantAgent);
35         if (actionButton == nullptr) {
36             return false;
37         }
38         // test AddAdditionalData function
39         AAFwk::WantParams extras;
40         actionButton->AddAdditionalData(extras);
41         // test AddMimeTypeOnlyUserInput function
42         std::shared_ptr<Notification::NotificationUserInput> userInput =
43             std::make_shared<Notification::NotificationUserInput>();
44         actionButton->AddMimeTypeOnlyUserInput(userInput);
45         actionButton->AddNotificationUserInput(userInput);
46         // test GetMimeTypeOnlyUserInputs function
47         actionButton->GetMimeTypeOnlyUserInputs();
48         // test GetUserInput function
49         actionButton->GetUserInput();
50         // test IsAutoCreatedReplies function
51         actionButton->IsAutoCreatedReplies();
52         return true;
53     }
54 }
55 
56 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)57 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
58 {
59     /* Run your code on data */
60     char *ch = ParseData(data, size);
61     if (ch != nullptr && size >= GetU32Size()) {
62         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
63         free(ch);
64         ch = nullptr;
65     }
66     return 0;
67 }
68