122736c2fSopenharmony_ci/* 222736c2fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 422736c2fSopenharmony_ci * you may not use this file except in compliance with the License. 522736c2fSopenharmony_ci * You may obtain a copy of the License at 622736c2fSopenharmony_ci * 722736c2fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 822736c2fSopenharmony_ci * 922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and 1322736c2fSopenharmony_ci * limitations under the License. 1422736c2fSopenharmony_ci */ 1522736c2fSopenharmony_ci 1622736c2fSopenharmony_ci#define private public 1722736c2fSopenharmony_ci#include "settings_data_utils.h" 1822736c2fSopenharmony_ci#undef private 1922736c2fSopenharmony_ci 2022736c2fSopenharmony_ci#include "settingsdatautils_fuzzer.h" 2122736c2fSopenharmony_ci 2222736c2fSopenharmony_ciusing namespace OHOS::MiscServices; 2322736c2fSopenharmony_cinamespace OHOS { 2422736c2fSopenharmony_civoid FuzzGetToken() 2522736c2fSopenharmony_ci{ 2622736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->GetToken(); 2722736c2fSopenharmony_ci} 2822736c2fSopenharmony_ci 2922736c2fSopenharmony_civoid FuzzDataShareHelper() 3022736c2fSopenharmony_ci{ 3122736c2fSopenharmony_ci auto helper = SettingsDataUtils::GetInstance()->CreateDataShareHelper(); 3222736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->ReleaseDataShareHelper(helper); 3322736c2fSopenharmony_ci} 3422736c2fSopenharmony_ci 3522736c2fSopenharmony_civoid FuzzCreateAndRegisterObserver(const std::string &key, SettingsDataObserver::CallbackFunc func) 3622736c2fSopenharmony_ci{ 3722736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->CreateAndRegisterObserver(key, func); 3822736c2fSopenharmony_ci} 3922736c2fSopenharmony_ci 4022736c2fSopenharmony_civoid FuzzRegisterObserver(const std::string &key, SettingsDataObserver::CallbackFunc &func) 4122736c2fSopenharmony_ci{ 4222736c2fSopenharmony_ci sptr<SettingsDataObserver> observer = new SettingsDataObserver(key, func); 4322736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->RegisterObserver(observer); 4422736c2fSopenharmony_ci} 4522736c2fSopenharmony_ci 4622736c2fSopenharmony_civoid FuzzUnregisterObserver(const std::string &key, SettingsDataObserver::CallbackFunc &func) 4722736c2fSopenharmony_ci{ 4822736c2fSopenharmony_ci sptr<SettingsDataObserver> observer = new SettingsDataObserver(key, func); 4922736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->UnregisterObserver(observer); 5022736c2fSopenharmony_ci} 5122736c2fSopenharmony_ci 5222736c2fSopenharmony_civoid FuzzGenerateTargetUri(const std::string &key) 5322736c2fSopenharmony_ci{ 5422736c2fSopenharmony_ci SettingsDataUtils::GetInstance()->GenerateTargetUri(key); 5522736c2fSopenharmony_ci} 5622736c2fSopenharmony_ci} // namespace OHOS 5722736c2fSopenharmony_ci 5822736c2fSopenharmony_ci/* Fuzzer entry point */ 5922736c2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 6022736c2fSopenharmony_ci{ 6122736c2fSopenharmony_ci /* Run your code on data */ 6222736c2fSopenharmony_ci std::string fuzzedString(reinterpret_cast<const char *>(data), size); 6322736c2fSopenharmony_ci SettingsDataObserver::CallbackFunc func; 6422736c2fSopenharmony_ci 6522736c2fSopenharmony_ci OHOS::FuzzGetToken(); 6622736c2fSopenharmony_ci OHOS::FuzzDataShareHelper(); 6722736c2fSopenharmony_ci OHOS::FuzzCreateAndRegisterObserver(fuzzedString, func); 6822736c2fSopenharmony_ci OHOS::FuzzRegisterObserver(fuzzedString, func); 6922736c2fSopenharmony_ci OHOS::FuzzUnregisterObserver(fuzzedString, func); 7022736c2fSopenharmony_ci OHOS::FuzzGenerateTargetUri(fuzzedString); 7122736c2fSopenharmony_ci return 0; 7222736c2fSopenharmony_ci}