1 /* 2 * Copyright (c) 2025 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 #ifndef MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H 17 #define MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H 18 19 #include "mock_fuzz_object.h" 20 #include "notification_subscribe_info.h" 21 #include "notification_constant.h" 22 23 namespace OHOS { 24 namespace Notification { 25 26 template <> Build(FuzzedDataProvider * fdp)27NotificationSubscribeInfo* ObjectBuilder<NotificationSubscribeInfo>::Build(FuzzedDataProvider *fdp) 28 { 29 auto subscribeInfo = new NotificationSubscribeInfo(); 30 31 subscribeInfo->AddAppName(fdp->ConsumeRandomLengthString()); 32 subscribeInfo->AddAppUserId(fdp->ConsumeIntegral<int32_t>()); 33 subscribeInfo->AddDeviceType(fdp->ConsumeRandomLengthString()); 34 subscribeInfo->SetSubscriberUid(fdp->ConsumeIntegral<int32_t>()); 35 subscribeInfo->SetFilterType(fdp->ConsumeIntegral<uint32_t>()); 36 subscribeInfo->SetNeedNotifyResponse(fdp->ConsumeBool()); 37 38 std::vector<NotificationConstant::SlotType> slotTypes; 39 size_t slotTypeCnt = fdp->ConsumeIntegralInRange<uint32_t>(0, 6); 40 for (size_t i = 0; i < slotTypeCnt; ++i) { 41 auto slotType = static_cast<NotificationConstant::SlotType>( 42 fdp->ConsumeIntegralInRange<int32_t>(0, 7)); 43 slotTypes.push_back(slotType); 44 } 45 subscribeInfo->SetSlotTypes(slotTypes); 46 return subscribeInfo; 47 } 48 49 } // namespace Notification 50 } // namespace OHOS 51 52 #endif // MOCK_NOTIFICATION_SUBSCRIBE_INFO_BUILDER_H 53