• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "devicestatusclient_fuzzer.h"
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 using namespace std;
22 using namespace OHOS;
23 using namespace OHOS::Msdp;
24 auto &client_ = DevicestatusClient::GetInstance();
25 sptr<DevicestatusClientFuzzer::DevicestatusTestCallback> cb = new DevicestatusClientFuzzer::DevicestatusTestCallback();
26 const int WAIT_TIME = 1000;
OnDevicestatusChanged(const DevicestatusDataUtils::DevicestatusData & devicestatusData)27 void DevicestatusClientFuzzer::DevicestatusTestCallback::OnDevicestatusChanged(const \
28     DevicestatusDataUtils::DevicestatusData& devicestatusData)
29 {
30     std::cout << "DevicestatusTestCallback type: " << devicestatusData.type << std::endl;
31     std::cout << "DevicestatusTestCallback value: " << devicestatusData.value << std::endl;
32 }
33 
TestSubscribeCallback(const uint8_t * data)34 void DevicestatusClientFuzzer::TestSubscribeCallback(const uint8_t* data)
35 {
36     std::cout << "TestSubscribeCallback: Enter " << std::endl;
37 
38     client_.SubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, cb);
39 
40     std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
41     TestGetDevicestatusData();
42 }
43 
TestGetDevicestatusData()44 void DevicestatusClientFuzzer::TestGetDevicestatusData()
45 {
46     std::cout << "TestGetDevicestatusData: Enter " << std::endl;
47     client_.GetDevicestatusData(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN);
48 
49     std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_TIME));
50     TestUnSubscribeCallback();
51 }
52 
TestUnSubscribeCallback()53 void DevicestatusClientFuzzer::TestUnSubscribeCallback()
54 {
55     std::cout << "TestUnSubscribeCallback: Enter " << std::endl;
56 
57     client_.UnSubscribeCallback(DevicestatusDataUtils::DevicestatusType::TYPE_LID_OPEN, cb);
58 }
59 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)60 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
61 {
62     DevicestatusClientFuzzer::TestSubscribeCallback(data);
63     return true;
64 }
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     /* Run your code on data */
70     DoSomethingInterestingWithMyAPI(data, size);
71     return 0;
72 }
73