• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
17 #include "collect_device_client.h"
18 #include "common_utils.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS::HiviewDFX;
22 
23 class CollectDeviceClientTest : public testing::Test {
24 public:
SetUp()25     void SetUp() {};
TearDown()26     void TearDown() {};
SetUpTestCase()27     static void SetUpTestCase() {};
TearDownTestCase()28     static void TearDownTestCase() {};
29 };
30 
GetTestPid()31 int32_t GetTestPid()
32 {
33     auto systemuiPid = CommonUtils::GetPidByName("com.ohos.systemui");
34     auto launcherPid = CommonUtils::GetPidByName("com.ohos.sceneboard");
35     auto pid = static_cast<int32_t>(systemuiPid > 0 ? systemuiPid : launcherPid);
36     return pid;
37 }
38 
39 /**
40  * @tc.name: CollectDeviceClientTest001
41  * @tc.desc: used to test func in CollectDeviceClient
42  * @tc.type: FUNC
43 */
44 HWTEST_F(CollectDeviceClientTest, CollectDeviceClientTest001, TestSize.Level1)
45 {
46     auto deviceClient = std::make_shared<CollectDeviceClient>();
47     int ret = deviceClient->Open();
48     ASSERT_EQ(ret, 0);
49 }
50 
51 /**
52  * @tc.name: CollectDeviceClientTest002
53  * @tc.desc: used to test func in CollectDeviceClient
54  * @tc.type: FUNC
55 */
56 HWTEST_F(CollectDeviceClientTest, CollectDeviceClientTest002, TestSize.Level1)
57 {
58     auto deviceClient = std::make_shared<CollectDeviceClient>();
59     (void)deviceClient->Open();
60     std::shared_ptr<ProcessCpuData> data = deviceClient->FetchProcessCpuData();
61     auto item = data->GetNextProcess();
62     ASSERT_NE(item, nullptr);
63 }
64 
65 /**
66  * @tc.name: CollectDeviceClientTest003
67  * @tc.desc: used to test func in CollectDeviceClient
68  * @tc.type: FUNC
69 */
70 HWTEST_F(CollectDeviceClientTest, CollectDeviceClientTest003, TestSize.Level1)
71 {
72     auto deviceClient = std::make_shared<CollectDeviceClient>();
73     (void)deviceClient->Open();
74     std::shared_ptr<ProcessCpuData> data = deviceClient->FetchProcessCpuData(GetTestPid());
75     auto item = data->GetNextProcess();
76     ASSERT_NE(item, nullptr);
77 }
78 
79 /**
80  * @tc.name: CollectDeviceClientTest004
81  * @tc.desc: used to test func in CollectDeviceClient
82  * @tc.type: FUNC
83 */
84 HWTEST_F(CollectDeviceClientTest, CollectDeviceClientTest004, TestSize.Level1)
85 {
86     auto deviceClient = std::make_shared<CollectDeviceClient>();
87     (void)deviceClient->Open();
88     std::shared_ptr<ThreadCpuData> data = deviceClient->FetchThreadCpuData(GetTestPid());
89     auto item = data->GetNextThread();
90     ASSERT_NE(item, nullptr);
91 }
92 
93 /**
94  * @tc.name: CollectDeviceClientTest005
95  * @tc.desc: used to test func in CollectDeviceClient
96  * @tc.type: FUNC
97 */
98 HWTEST_F(CollectDeviceClientTest, CollectDeviceClientTest005, TestSize.Level1)
99 {
100     auto deviceClient = std::make_shared<CollectDeviceClient>();
101     (void)deviceClient->Open();
102     std::shared_ptr<ThreadCpuData> data = deviceClient->FetchSelfThreadCpuData(getpid());
103     auto item = data->GetNextThread();
104     ASSERT_NE(item, nullptr);
105 }
106