• 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 "message_user.h"
19 #undef private
20 #undef protected
21 #include "messageuser_fuzzer.h"
22 #include <fuzzer/FuzzedDataProvider.h>
23 
24 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)25     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
26     {
27         std::string key = fdp->ConsumeRandomLengthString();
28         Notification::MessageUser messageUser;
29         // test SetKey function
30         messageUser.SetKey(key);
31         // test SetName function
32         std::string name = fdp->ConsumeRandomLengthString();
33         messageUser.SetName(name);
34         // test SetPixelMap function
35         messageUser.SetPixelMap(nullptr);
36         // test SetUri function
37         Uri uri(key);
38         messageUser.SetUri(uri);
39         // test SetMachine function
40         bool enabled = fdp->ConsumeBool();
41         messageUser.SetMachine(enabled);
42         // test SetUserAsImportant function
43         messageUser.SetUserAsImportant(enabled);
44         // test GetKey function
45         messageUser.GetKey();
46         // test GetName function
47         messageUser.GetName();
48         // test GetPixelMap function
49         messageUser.GetPixelMap();
50         // test GetUri function
51         messageUser.GetUri();
52         // test IsMachine function
53         messageUser.IsMachine();
54         // test IsUserImportant function
55         messageUser.IsUserImportant();
56         // test ToJson function
57         nlohmann::json jsonObject;
58         messageUser.ToJson(jsonObject);
59         messageUser.FromJson(jsonObject);
60         return true;
61     }
62 }
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67     /* Run your code on data */
68     FuzzedDataProvider fdp(data, size);
69     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
70     return 0;
71 }
72