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_conversational_content.h"
19 #undef private
20 #undef protected
21 #include "notificationconversationalcontent_fuzzer.h"
22
23 #define DISABLE_FUZZ
24 namespace OHOS {
25 namespace {
26 constexpr uint8_t ENABLE = 2;
27 }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
29 {
30 Notification::MessageUser messageUser;
31 Notification::NotificationConversationalContent NotificationConversationalContent(messageUser);
32 NotificationConversationalContent.GetMessageUser();
33 std::string stringData(data);
34 NotificationConversationalContent.SetConversationTitle(stringData);
35 NotificationConversationalContent.GetConversationTitle();
36 NotificationConversationalContent.IsConversationGroup();
37 bool enabled = *data % ENABLE;
38 NotificationConversationalContent.SetConversationGroup(enabled);
39 int64_t timestamp = 1;
40 NotificationConversationalContent.AddConversationalMessage(stringData, timestamp, messageUser);
41 Notification::NotificationConversationalContent::MessagePtr message;
42 NotificationConversationalContent.AddConversationalMessage(message);
43 NotificationConversationalContent.GetAllConversationalMessages();
44 NotificationConversationalContent.Dump();
45 Parcel parcel;
46 NotificationConversationalContent.Marshalling(parcel);
47 NotificationConversationalContent.Unmarshalling(parcel);
48 return NotificationConversationalContent.ReadFromParcel(parcel);
49 }
50 }
51
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55 /* Run your code on data */
56 char *ch = ParseData(data, size);
57 if (ch != nullptr && size >= GetU32Size()) {
58 #ifndef DISABLE_FUZZ
59 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
60 #endif
61 free(ch);
62 ch = nullptr;
63 }
64 return 0;
65 }
66