• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_utils_test.h"
17 
18 #include "errors.h"
19 #include "file_operation.h"
20 #include "string_operation.h"
21 #include "thermal_hisysevent.h"
22 #include "thermal_log.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::PowerMgr;
26 using namespace OHOS;
27 using namespace std;
28 
29 namespace {
30 /**
31  * @tc.name: ThermalUtilsTest001
32  * @tc.desc: utils test
33  * @tc.type: FUNC
34  * @tc.require: issueI5YZQ2
35  */
36 HWTEST_F(ThermalUtilsTest, ThermalUtilsTest001, TestSize.Level0)
37 {
38     THERMAL_HILOGD(LABEL_TEST, "ThermalUtilsTest001 start.");
39     std::string dir = "";
40     char* buf = nullptr;
41     EXPECT_EQ(true, FileOperation::CreateNodeDir(dir) != ERR_OK);
42     EXPECT_EQ(true, FileOperation::CreateNodeFile(dir) != ERR_OK);
43     dir = "/thermaltest/";
44     EXPECT_EQ(true, FileOperation::CreateNodeDir(dir) == ERR_OK);
45     dir = "/thermaltest/thermaltest.txt";
46     EXPECT_EQ(true, FileOperation::CreateNodeFile(dir) == ERR_OK);
47     size_t size = 1;
48     EXPECT_EQ(true, FileOperation::WriteFile(dir, dir, size) == ERR_OK);
49     dir = "";
50     EXPECT_EQ(true, FileOperation::ReadFile(dir.c_str(), buf, size) != ERR_OK);
51     dir = "/thermaltest/thermaltest.txt";
52     EXPECT_EQ(false, FileOperation::ReadFile(dir.c_str(), buf, size) == ERR_OK);
53     dir = "";
54     EXPECT_EQ(true, FileOperation::WriteFile(dir, dir, size) != ERR_OK);
55     dir = "1";
56     EXPECT_EQ(1, FileOperation::ConvertInt(dir));
57     THERMAL_HILOGD(LABEL_TEST, "ThermalUtilsTest001 end.");
58 }
59 
60 /**
61  * @tc.name: ThermalUtilsTest002
62  * @tc.desc: utils test
63  * @tc.require: issueI5YZQ2
64  * @tc.type: FUNC
65  */
66 HWTEST_F(ThermalUtilsTest, ThermalUtilsTest002, TestSize.Level0)
67 {
68     THERMAL_HILOGD(LABEL_TEST, "ThermalUtilsTest002 start.");
69     std::string str;
70     std::vector<std::string> ret;
71     std::string sep;
72     StringOperation::SplitString(str, ret, sep);
73     StringOperation::ClearAllSpace(str);
74     str = "str";
75     StringOperation::ClearAllSpace(str);
76     EXPECT_EQ(false, StringOperation::Compare(str, sep));
77     sep = "str";
78     EXPECT_EQ(true, StringOperation::Compare(str, sep));
79     EXPECT_EQ(true, StringOperation::Find(str, sep));
80     str = "";
81     EXPECT_EQ(false, StringOperation::Find(str, sep));
82     std::string configDir = "/data/service/el0/thermal/config/%s";
83     WriteLevelChangedHiSysEvent(true, 1);
84     WriteLevelChangedHiSysEvent(false, 1);
85     WriteActionTriggeredHiSysEvent(true, configDir, 1);
86     WriteActionTriggeredHiSysEvent(false, configDir, 1);
87     WriteActionTriggeredHiSysEventWithRatio(true, configDir, 1);
88     WriteActionTriggeredHiSysEventWithRatio(false, configDir, 1);
89     THERMAL_HILOGD(LABEL_TEST, "ThermalUtilsTest002 end.");
90 }
91 } // namespace
92