• 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 "process_status.h"
18 
19 using namespace testing::ext;
20 using namespace OHOS::HiviewDFX;
21 using namespace OHOS::HiviewDFX::UCollectUtil;
22 
23 class ProcessStatusTest : 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 
31 /**
32  * @tc.name: ProcessStatusTest001
33  * @tc.desc: used to test func of ProcessStatus class
34  * @tc.type: FUNC
35 */
36 HWTEST_F(ProcessStatusTest, ProcessStatusTest001, TestSize.Level1)
37 {
38     std::string procName = ProcessStatus::GetInstance().GetProcessName(-1);
39     ASSERT_EQ(procName, "");
40     procName = ProcessStatus::GetInstance().GetProcessName(1);
41     ASSERT_EQ(procName, "init");
42     procName = ProcessStatus::GetInstance().GetProcessName(1);
43     ASSERT_EQ(procName, "init");
44 }
45 
46 /**
47  * @tc.name: ProcessStatusTest002
48  * @tc.desc: used to test func of ProcessStatus class
49  * @tc.type: FUNC
50 */
51 HWTEST_F(ProcessStatusTest, ProcessStatusTest002, TestSize.Level1)
52 {
53     ProcessState state = ProcessStatus::GetInstance().GetProcessState(1);
54     ASSERT_EQ(state, ProcessState::BACKGROUND);
55     uint64_t lastForegroundTime = ProcessStatus::GetInstance().GetProcessLastForegroundTime(1);
56     ASSERT_EQ(lastForegroundTime, 0);
57 }
58 
59 /**
60  * @tc.name: ProcessStatusTest003
61  * @tc.desc: used to test func of ProcessStatus class
62  * @tc.type: FUNC
63 */
64 HWTEST_F(ProcessStatusTest, ProcessStatusTest003, TestSize.Level1)
65 {
66     // update init process to forground state for test purpose
67     ProcessStatus::GetInstance().NotifyProcessState(1, ProcessState::FOREGROUND);
68     ProcessState state = ProcessStatus::GetInstance().GetProcessState(1);
69     ASSERT_EQ(state, ProcessState::FOREGROUND);
70     uint64_t lastForegroundTime = ProcessStatus::GetInstance().GetProcessLastForegroundTime(1);
71     ASSERT_GT(lastForegroundTime, 0);
72 }
73