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 <iostream>
17 
18 #include "thermal_collector.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS::HiviewDFX;
22 using namespace OHOS::HiviewDFX::UCollectUtil;
23 
24 class ThermalCollectorTest : public testing::Test {
25 public:
SetUp()26     void SetUp() {};
TearDown()27     void TearDown() {};
SetUpTestCase()28     static void SetUpTestCase() {};
TearDownTestCase()29     static void TearDownTestCase() {};
30 };
31 
TestResult(const CollectResult<int32_t>& result)32 void TestResult(const CollectResult<int32_t>& result)
33 {
34     if (result.retCode == UCollect::UcError::SUCCESS) {
35         ASSERT_NE(result.data, 0);
36     } else {
37         ASSERT_EQ(result.retCode, UCollect::UcError::UNSUPPORT);
38     }
39 }
40 
41 /**
42  * @tc.name: ThermalCollectorTest001
43  * @tc.desc: used to test ThermalCollector.CollectDevThermal
44  * @tc.type: FUNC
45 */
HWTEST_F(ThermalCollectorTest, ThermalCollectorTest001, TestSize.Level1)46 HWTEST_F(ThermalCollectorTest, ThermalCollectorTest001, TestSize.Level1)
47 {
48     std::shared_ptr<ThermalCollector> collector = ThermalCollector::Create();
49     CollectResult<int32_t> result;
50     result = collector->CollectDevThermal(ThermalZone::SHELL_FRONT);
51     TestResult(result);
52     result = collector->CollectDevThermal(ThermalZone::SHELL_FRAME);
53     TestResult(result);
54     result = collector->CollectDevThermal(ThermalZone::SHELL_BACK);
55     TestResult(result);
56     result = collector->CollectDevThermal(ThermalZone::SOC_THERMAL);
57     TestResult(result);
58     result = collector->CollectDevThermal(ThermalZone::SYSTEM);
59     TestResult(result);
60 }
61 
62 /**
63  * @tc.name: ThermalCollectorTest002
64  * @tc.desc: used to test ThermalCollector.CollectThermaLevel
65  * @tc.type: FUNC
66 */
HWTEST_F(ThermalCollectorTest, ThermalCollectorTest002, TestSize.Level1)67 HWTEST_F(ThermalCollectorTest, ThermalCollectorTest002, TestSize.Level1)
68 {
69     std::shared_ptr<ThermalCollector> collector = ThermalCollector::Create();
70     CollectResult<uint32_t> result = collector->CollectThermaLevel();
71 #ifdef THERMAL_MANAGER_ENABLE
72     ASSERT_EQ(result.retCode, UCollect::UcError::SUCCESS);
73 #else
74     ASSERT_EQ(result.retCode, UCollect::UcError::UNSUPPORT);
75 #endif
76 }
77