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 #include "streamadaptor_fuzzer.h"
17
18 #include <string>
19
20 #include "client_trans_udp_stream_interface.h"
21 #include "stream_adaptor.h"
22
23 #define STANDARD_NUMBER 2
24 using namespace std;
25
26 namespace OHOS {
SetAliveStateDataTest(const uint8_t * data,size_t size)27 void SetAliveStateDataTest(const uint8_t* data, size_t size)
28 {
29 if ((data == nullptr) || (size == 0)) {
30 return;
31 }
32 bool state;
33 if (size % STANDARD_NUMBER == 0) {
34 state = true;
35 } else {
36 state = false;
37 }
38 const std::string &pkgName = "ohos.msdp.spatialawareness";
39
40 OHOS::StreamAdaptor streamadaptor(pkgName);
41 streamadaptor.SetAliveState(state);
42 }
43
InitAdaptorTest(const uint8_t * data,size_t size)44 void InitAdaptorTest(const uint8_t* data, size_t size)
45 {
46 if ((data == nullptr) || (size == 0)) {
47 return;
48 }
49 VtpStreamOpenParam *param = nullptr;
50 IStreamListener *callback = nullptr;
51 const std::string &pkgName = "ohos.msdp.spatialawareness";
52
53 OHOS::StreamAdaptor streamadaptor(pkgName);
54 streamadaptor.InitAdaptor(size, param, true, callback);
55 }
56 } // namespace OHOS
57
58 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
60 {
61 /* Run your code on data */
62 OHOS::SetAliveStateDataTest(data, size);
63 return 0;
64 }
65