1 /*
2 * Copyright (c) 2023 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 "display_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20
21 #include "message_parcel.h"
22 #include "securec.h"
23
24 using namespace OHOS::DisplayPowerMgr;
25 using namespace OHOS;
26
27 namespace {
28 const int32_t REWIND_READ_DATA = 0;
29 const int32_t SLEEP_TIME = 5;
30 } // namespace
31
DisplayFuzzerTest()32 DisplayFuzzerTest::DisplayFuzzerTest()
33 {
34 service_ = DelayedSpSingleton<DisplayPowerMgrService>::GetInstance();
35 service_->Init();
36 }
37
~DisplayFuzzerTest()38 DisplayFuzzerTest::~DisplayFuzzerTest()
39 {
40 if (service_ != nullptr) {
41 sleep(SLEEP_TIME);
42 service_->Deinit();
43 service_->Reset();
44 }
45 service_ = nullptr;
46 }
47
TestDisplayServiceStub(const uint32_t code,const uint8_t * data,size_t size)48 void DisplayFuzzerTest::TestDisplayServiceStub(const uint32_t code, const uint8_t* data, size_t size)
49 {
50 MessageParcel datas;
51 datas.WriteInterfaceToken(DisplayPowerMgrService::GetDescriptor());
52 datas.WriteBuffer(data, size);
53 datas.RewindRead(REWIND_READ_DATA);
54 MessageParcel reply;
55 MessageOption option;
56 service_->OnRemoteRequest(code, datas, reply, option);
57 }
58