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