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 #ifndef STATS_TEST_H 17 #define STATS_TEST_H 18 19 #include <gtest/gtest.h> 20 21 #include "battery_stats_parser.h" 22 23 namespace OHOS { 24 namespace PowerMgr { 25 class StatsTest { 26 public: 27 static constexpr int64_t US_PER_HOUR = 3600000000; 28 static constexpr int32_t MS_PER_HOUR = 3600000; 29 static constexpr int32_t US_PER_SECOND = 1000000; 30 static constexpr int32_t US_PER_MS = 1000; 31 static constexpr int32_t POWER_CONSUMPTION_TRIGGERED_US = 20000; 32 static constexpr int32_t POWER_CONSUMPTION_DURATION_US = 300000; 33 static constexpr double DEVIATION_PERCENT_THRESHOLD = 0.05; 34 static constexpr int64_t TIMER_DURATION_MS = 50; 35 static constexpr int32_t DEVIATION_TIMER_THRESHOLD = 5; 36 static std::shared_ptr<BatteryStatsParser> g_statsParser; 37 ParserAveragePowerFile()38static void ParserAveragePowerFile() 39 { 40 if (g_statsParser == nullptr) { 41 g_statsParser = std::make_shared<BatteryStatsParser>(); 42 if (!g_statsParser->Init()) { 43 GTEST_LOG_(INFO) << __func__ << ": Battery stats parser initialization failed"; 44 } 45 } 46 } 47 }; 48 std::shared_ptr<BatteryStatsParser> StatsTest::g_statsParser = nullptr; 49 } // namespace PowerMgr 50 } // namespace OHOS 51 #endif // STATS_TEST_H