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 
16 #include "thermal_mgr_dump_test.h"
17 
18 #ifdef THERMAL_GTEST
19 #define private   public
20 #define protected public
21 #define final
22 #endif
23 
24 #include <map>
25 #include <string>
26 #include <vector>
27 
28 #include "thermal_log.h"
29 #include "thermal_mgr_dumper.h"
30 
31 
32 using namespace OHOS::PowerMgr;
33 using namespace OHOS;
34 using namespace testing::ext;
35 using namespace std;
36 
37 namespace {
38 sptr<ThermalService> g_service = nullptr;
39 } // namespace
40 
GetOneCfgFile(const char * pathSuffix,char * buf,unsigned int bufLength)41 char* GetOneCfgFile(const char *pathSuffix, char *buf, unsigned int bufLength)
42 {
43     THERMAL_HILOGI(LABEL_TEST, "mock GetOneCfgFile.");
44     return nullptr;
45 }
46 
SetUpTestCase()47 void ThermalMgrDumperTest::SetUpTestCase()
48 {
49     g_service = ThermalService::GetInstance();
50     g_service->InitSystemTestModules();
51     g_service->OnStart();
52 }
53 
54 namespace {
55 /**
56  * @tc.name: ThermalMgrDumperTest001
57  * @tc.desc: test dump help
58  * @tc.type: FUNC
59  */
60 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest001, TestSize.Level0)
61 {
62     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest001 start.");
63     std::vector<std::string> args;
64     std::string result;
65     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
66     EXPECT_TRUE(!result.empty());
67 
68     result.clear();
69     args.push_back("-h");
70     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
71     EXPECT_TRUE(!result.empty());
72 
73     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest001 end.");
74 }
75 
76 /**
77  * @tc.name: ThermalMgrDumperTest002
78  * @tc.desc: test dump -d
79  * @tc.type: FUNC
80  */
81 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest002, TestSize.Level0)
82 {
83     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest002 start.");
84     std::vector<std::string> args;
85     std::string result;
86 
87     args.push_back("-d");
88     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
89     EXPECT_TRUE(result.empty());
90     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest002 end.");
91 }
92 
93 /**
94  * @tc.name: ThermalMgrDumperTest003
95  * @tc.desc: test dump -t
96  * @tc.type: FUNC
97  */
98 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest003, TestSize.Level0)
99 {
100     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest003 start.");
101     std::vector<std::string> args;
102     std::string result;
103 
104     g_service->RegisterThermalHdiCallback();
105     args.push_back("-t");
106     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
107     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest003 end.");
108 }
109 
110 /**
111  * @tc.name: ThermalMgrDumperTest004
112  * @tc.desc: test dump Invalid value
113  * @tc.type: FUNC
114  */
115 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest004, TestSize.Level0)
116 {
117     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest004 start.");
118     std::vector<std::string> args;
119     std::string result;
120 
121     args.push_back("---");
122     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
123     EXPECT_TRUE(result.empty());
124     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest004 end.");
125 }
126 
127 /**
128  * @tc.name: ThermalMgrDumperTest005
129  * @tc.desc: test dump switch temp report
130  * @tc.type: FUNC
131  */
132 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest005, TestSize.Level0)
133 {
134     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest005 start.");
135     std::vector<std::string> args;
136     std::string result;
137 
138     args.push_back("-st");
139     args.push_back("0");
140     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
141     args.clear();
142     args.push_back("-st");
143     args.push_back("1");
144     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
145     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest005 end.");
146 }
147 
148 /**
149  * @tc.name: ThermalMgrDumperTest006
150  * @tc.desc: test dump temp emul
151  * @tc.type: FUNC
152  */
153 HWTEST_F(ThermalMgrDumperTest, ThermalMgrDumperTest006, TestSize.Level0)
154 {
155     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest006 start.");
156     std::vector<std::string> args;
157     std::string result;
158 
159     args.push_back("-te");
160     args.push_back("battery");
161     args.push_back("43000");
162     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
163     args.clear();
164     args.push_back("-te");
165     EXPECT_TRUE(ThermalMgrDumper::Dump(args, result));
166     THERMAL_HILOGI(LABEL_TEST, "ThermalMgrDumperTest006 end.");
167 }
168 } // namespace
169