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