1 /*
2  * Copyright (c) 2024 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 #include "datashare_adapter_impl_fuzzer.h"
17 
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21 
22 #include "base/web/webview/ohos_adapter/datashare_adapter/include/datashare_adapter_impl.h"
23 
24 namespace OHOS::NWeb {
25 
DatashareAdapterFuzzTest(const uint8_t * data,size_t size)26 bool DatashareAdapterFuzzTest(const uint8_t* data, size_t size)
27 {
28     std::string uriString(reinterpret_cast<const char*>(data), size);
29 
30     DatashareAdapterImpl& adapter = DatashareAdapterImpl::GetInstance();
31 
32     adapter.GetRealPath(uriString);
33 
34     adapter.OpenDataShareUriForRead(uriString);
35 
36     adapter.GetFileDisplayName(uriString);
37 
38     return true;
39 }
40 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
42 {
43     OHOS::NWeb::DatashareAdapterFuzzTest(data, size);
44     return 0;
45 }
46 } // namespace OHOS::NWeb