1 /*
2  * Copyright (c) 2024 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 #include <gtest/gtest.h>
16 #include <message_parcel.h>
17 #include "dump_broker_stub.h"
18 #include "hidumper_service_ipc_interface_code.h"
19 using namespace std;
20 using namespace testing::ext;
21 using namespace OHOS;
22 using namespace OHOS::HiviewDFX;
23 namespace OHOS {
24 namespace HiviewDFX {
25 class HidumperZidlTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 };
32 
33 class TestDumpBrokerStub : public DumpBrokerStub {
34 public:
TestDumpBrokerStub()35     TestDumpBrokerStub() {};
~TestDumpBrokerStub()36     virtual ~TestDumpBrokerStub() {};
Request(std::vector<std::u16string> & args,int outfd)37     int32_t Request(std::vector<std::u16string> &args, int outfd)
38     {
39         return 0;
40     }
ScanPidOverLimit(std::string requestType,int32_t limitSize,std::vector<int32_t> & pidList)41     int32_t ScanPidOverLimit(std::string requestType, int32_t limitSize, std::vector<int32_t> &pidList)
42     {
43         return 0;
44     }
CountFdNums(int32_t pid,uint32_t & fdNums,std::string & detailFdInfo,std::string & topLeakedType)45     int32_t CountFdNums(int32_t pid, uint32_t &fdNums, std::string &detailFdInfo, std::string &topLeakedType)
46     {
47         return 0;
48     }
49 };
50 
SetUpTestCase(void)51 void HidumperZidlTest::SetUpTestCase(void)
52 {
53 }
54 
TearDownTestCase(void)55 void HidumperZidlTest::TearDownTestCase(void)
56 {
57 }
58 
SetUp(void)59 void HidumperZidlTest::SetUp(void)
60 {
61 }
62 
TearDown(void)63 void HidumperZidlTest::TearDown(void)
64 {
65 }
66 
67 /**
68  * @tc.name: HidumperZidlTest001
69  * @tc.desc: Test hidumper service stub.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(HidumperZidlTest, HidumperZidlTest001, TestSize.Level3)
73 {
74     DumpBrokerStub* stub = new(std::nothrow) TestDumpBrokerStub();
75     MessageParcel data, reply;
76     MessageOption option;
77     int ret = stub->OnRemoteRequest(static_cast<uint32_t>(HidumperServiceInterfaceCode::DUMP_REQUEST_FILEFD),
78         data, reply, option);
79     ASSERT_TRUE(ret != 0);
80     ret = stub->OnRemoteRequest(static_cast<uint32_t>(HidumperServiceInterfaceCode::SCAN_PID_OVER_LIMIT),
81         data, reply, option);
82     ASSERT_TRUE(ret != 0);
83     ret = stub->OnRemoteRequest(static_cast<uint32_t>(HidumperServiceInterfaceCode::COUNT_FD_NUMS),
84         data, reply, option);
85     ASSERT_TRUE(ret != 0);
86     stub->RequestFileFdStub(data, reply);
87     stub->ScanPidOverLimitStub(data, reply);
88     stub->CountFdNumsStub(data, reply);
89 }
90 } // namespace HiviewDFX
91 } // namespace OHOS