• 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         // test IsContextDependent function
53         actionButton->IsContextDependent();
54        // test GetSemanticActionButton function
55         actionButton->GetSemanticActionButton();
56         // test GetIcon function
57         actionButton->GetIcon();
58         // test GetTitle function
59         actionButton->GetTitle();
60         // test GetWantAgent function
61         actionButton->GetWantAgent();
62         // test Dump function
63         actionButton->Dump();
64         // test ToJson function
65         nlohmann::json jsonObject;
66         actionButton->ToJson(jsonObject);
67         actionButton->FromJson(jsonObject);
68         // test Unmarshalling function
69         Parcel parcel;
70         actionButton->Marshalling(parcel);
71         actionButton->Unmarshalling(parcel);
72         actionButton->ReadFromParcel(parcel);
73         return true;
74     }
75 }
76 
77 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)78 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
79 {
80     /* Run your code on data */
81     char *ch = ParseData(data, size);
82     if (ch != nullptr && size >= GetU32Size()) {
83         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
84         free(ch);
85         ch = nullptr;
86     }
87     return 0;
88 }
89