15c735df2Sopenharmony_ci/*
25c735df2Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
35c735df2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45c735df2Sopenharmony_ci * you may not use this file except in compliance with the License.
55c735df2Sopenharmony_ci * You may obtain a copy of the License at
65c735df2Sopenharmony_ci *
75c735df2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85c735df2Sopenharmony_ci *
95c735df2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105c735df2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115c735df2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125c735df2Sopenharmony_ci * See the License for the specific language governing permissions and
135c735df2Sopenharmony_ci * limitations under the License.
145c735df2Sopenharmony_ci */
155c735df2Sopenharmony_ci
165c735df2Sopenharmony_ci#ifdef FEATURE_GEOCODE_SUPPORT
175c735df2Sopenharmony_ci#include "geoconvertproxy_fuzzer.h"
185c735df2Sopenharmony_ci
195c735df2Sopenharmony_ci#include "geo_convert_proxy.h"
205c735df2Sopenharmony_ci#include "geo_convert_service.h"
215c735df2Sopenharmony_ci#include "geo_coding_mock_info.h"
225c735df2Sopenharmony_ci#include "message_parcel.h"
235c735df2Sopenharmony_ci
245c735df2Sopenharmony_cinamespace OHOS {
255c735df2Sopenharmony_ci    using namespace OHOS::Location;
265c735df2Sopenharmony_ci    const int MIN_DATA_LEN = 3;
275c735df2Sopenharmony_ci    bool GeoConvertProxyFuzzerTest(const uint8_t* data, size_t size)
285c735df2Sopenharmony_ci    {
295c735df2Sopenharmony_ci        if (size < MIN_DATA_LEN) {
305c735df2Sopenharmony_ci            return true;
315c735df2Sopenharmony_ci        }
325c735df2Sopenharmony_ci        int index = 0;
335c735df2Sopenharmony_ci        sptr<GeoConvertService> service =
345c735df2Sopenharmony_ci            new (std::nothrow) GeoConvertService();
355c735df2Sopenharmony_ci        std::shared_ptr<GeoConvertProxy> geoConvertProxy =
365c735df2Sopenharmony_ci            std::make_shared<GeoConvertProxy>(service);
375c735df2Sopenharmony_ci        MessageParcel request;
385c735df2Sopenharmony_ci        MessageParcel reply;
395c735df2Sopenharmony_ci        geoConvertProxy->IsGeoConvertAvailable(request);
405c735df2Sopenharmony_ci        geoConvertProxy->GetAddressByCoordinate(request, reply);
415c735df2Sopenharmony_ci        geoConvertProxy->GetAddressByLocationName(request, reply);
425c735df2Sopenharmony_ci        geoConvertProxy->EnableReverseGeocodingMock();
435c735df2Sopenharmony_ci        geoConvertProxy->DisableReverseGeocodingMock();
445c735df2Sopenharmony_ci        std::vector<std::shared_ptr<GeocodingMockInfo>> geocodingMockInfos;
455c735df2Sopenharmony_ci        geoConvertProxy->SetReverseGeocodingMockInfo(geocodingMockInfos);
465c735df2Sopenharmony_ci        geoConvertProxy->SendSimpleMsgAndParseResult(data[index++]);
475c735df2Sopenharmony_ci        geoConvertProxy->SendSimpleMsg(data[index++], request);
485c735df2Sopenharmony_ci        geoConvertProxy->SendMsgWithDataReply(data[index++], request, reply);
495c735df2Sopenharmony_ci        return true;
505c735df2Sopenharmony_ci    }
515c735df2Sopenharmony_ci}
525c735df2Sopenharmony_ci
535c735df2Sopenharmony_ci/* Fuzzer entry point */
545c735df2Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
555c735df2Sopenharmony_ci{
565c735df2Sopenharmony_ci    /* Run your code on data */
575c735df2Sopenharmony_ci    OHOS::GeoConvertProxyFuzzerTest(data, size);
585c735df2Sopenharmony_ci    return 0;
595c735df2Sopenharmony_ci}
605c735df2Sopenharmony_ci#endif // FEATURE_GEOCODE_SUPPORT