diff --git a/powermgr/battery/hdi_battery/common/hdi_battery_test.cpp b/powermgr/battery/hdi_battery/common/hdi_battery_test.cpp index f2c89c73..ad21a68d 100644 --- a/powermgr/battery/hdi_battery/common/hdi_battery_test.cpp +++ b/powermgr/battery/hdi_battery/common/hdi_battery_test.cpp @@ -93,11 +93,11 @@ HWTEST_F(HdfBatteryHdiTest, HdfBatteryHdiTest001, TestSize.Level1) */ HWTEST_F(HdfBatteryHdiTest, HdfBatteryHdiTest002, TestSize.Level1) { - printf("HdfBatteryHdiTest002: start."); - int32_t ret = g_batteryInterface->Register(sptr(g_callback) = nullptr); - EXPECT_NE(0, ret) << "HdfBatteryHdiTest002 failed"; + printf("HdfBatteryHdiTest002: start."); + int32_t ret = g_batteryInterface->Register(sptr(g_callback) = nullptr); + EXPECT_NE(0, ret) << "HdfBatteryHdiTest002 failed"; - printf("HdfBatteryHdiTest002: return."); + printf("HdfBatteryHdiTest002: return."); } /** @@ -107,11 +107,11 @@ HWTEST_F(HdfBatteryHdiTest, HdfBatteryHdiTest002, TestSize.Level1) */ HWTEST_F(HdfBatteryHdiTest, HdfBatteryHdiTest003, TestSize.Level1) { - printf("HdfBatteryHdiTest003: start."); - int32_t ret = g_batteryInterface->UnRegister(); - EXPECT_EQ(0, ret) << "HdfBatteryHdiTest002 failed"; + printf("HdfBatteryHdiTest003: start."); + int32_t ret = g_batteryInterface->UnRegister(); + EXPECT_EQ(0, ret) << "HdfBatteryHdiTest002 failed"; - printf("HdfBatteryHdiTest003: return."); + printf("HdfBatteryHdiTest003: return."); } /** @@ -286,8 +286,8 @@ HWTEST_F(HdfBatteryHdiTest, HdfBatteryHdiTest015, TestSize.Level1) { printf("HdfBatteryHdiTest015: start."); int32_t nowCurr = -1; - g_batteryInterface->GetCurrentNow(nowCurr); - EXPECT_TRUE(nowCurr != -1); + int32_t ret = g_batteryInterface->GetCurrentNow(nowCurr); + EXPECT_EQ(0, ret); printf("HdfBatteryHdiTest015: return."); } diff --git a/powermgr/power/hdi_power/common/hdi_power_test.cpp b/powermgr/power/hdi_power/common/hdi_power_test.cpp index 4b1687a4..4cfaa200 100644 --- a/powermgr/power/hdi_power/common/hdi_power_test.cpp +++ b/powermgr/power/hdi_power/common/hdi_power_test.cpp @@ -49,8 +49,71 @@ public: }; }; +class PowerMockInterfaceImpl : public IPowerInterface { +public: + ~PowerMockInterfaceImpl() override {}; + + int32_t RegisterCallback(const sptr &ipowerHdiCallback) override + { + (void)ipowerHdiCallback; + return 0; + } + + int32_t StartSuspend() override + { + return 0; + } + + int32_t StopSuspend() override + { + return 0; + } + + int32_t ForceSuspend() override + { + return 0; + } + + int32_t SuspendBlock(const std::string &name) override + { + (void)name; + return 0; + } + + int32_t SuspendUnblock(const std::string &name) override + { + (void)name; + return 0; + } + + int32_t PowerDump(std::string &info) override + { + (void)info; + return 0; + } + + int32_t HoldRunningLock(const RunningLockInfo &info) override + { + (void)info; + return 0; + } + + int32_t UnholdRunningLock(const RunningLockInfo &info) override + { + (void)info; + return 0; + } + + int32_t GetWakeupReason(std::string &reason) override + { + (void)reason; + return 0; + } +}; + sptr g_callback = new PowerHdiCallback(); sptr g_powerInterface = nullptr; +sptr powerInterface = nullptr; std::mutex g_mutex; const uint32_t MAX_PATH = 256; const uint32_t WAIT_TIME = 1; @@ -72,6 +135,7 @@ public: void HdfPowerHdiTest::SetUpTestCase() { g_powerInterface = IPowerInterface::Get(true); + powerInterface = new PowerMockInterfaceImpl(); } void HdfPowerHdiTest::TearDownTestCase() @@ -126,10 +190,8 @@ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest001, TestSize.Level1) */ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest002, TestSize.Level1) { - if (false) { - EXPECT_TRUE(HDF_SUCCESS == - g_powerInterface->RegisterCallback(g_callback))<< "HdfPowerHdiTest002 failed"; - } + EXPECT_TRUE(HDF_SUCCESS == + powerInterface->RegisterCallback(g_callback))<< "HdfPowerHdiTest002 failed"; } /** @@ -139,23 +201,21 @@ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest002, TestSize.Level1) */ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest003, TestSize.Level1) { - if (false) { - int32_t ret = g_powerInterface->StartSuspend(); - EXPECT_EQ(0, ret); + int32_t ret = g_powerInterface->StartSuspend(); + EXPECT_EQ(0, ret); - char stateBuf[MAX_PATH] = {0}; - char stateValue[MAX_PATH] = {0}; + char stateBuf[MAX_PATH] = {0}; + char stateValue[MAX_PATH] = {0}; - ret = snprintf_s(stateBuf, MAX_PATH, sizeof(stateBuf) - 1, SUSPEND_STATE_PATH.c_str()); - EXPECT_FALSE(ret < EOK); - sleep(WAIT_TIME); - ret = HdfPowerHdiTest::ReadFile(stateBuf, stateValue, sizeof(stateValue)); - EXPECT_EQ(0, ret); - std::string state = stateValue; - EXPECT_FALSE(state.empty()); - auto pos = state.find(SUSPEND_STATE); - EXPECT_TRUE(pos != std::string::npos) << "HdfPowerHdiTest003 failed state: " << state; - } + ret = snprintf_s(stateBuf, MAX_PATH, sizeof(stateBuf) - 1, SUSPEND_STATE_PATH.c_str()); + EXPECT_FALSE(ret < EOK); + sleep(WAIT_TIME); + ret = HdfPowerHdiTest::ReadFile(stateBuf, stateValue, sizeof(stateValue)); + EXPECT_EQ(0, ret); + std::string state = stateValue; + EXPECT_FALSE(state.empty()); + auto pos = state.find(SUSPEND_STATE); + EXPECT_TRUE(pos != std::string::npos) << "HdfPowerHdiTest003 failed state: " << state; } /** @@ -176,10 +236,8 @@ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest004, TestSize.Level1) */ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest005, TestSize.Level1) { - if (false) { - int32_t ret = g_powerInterface->ForceSuspend(); - EXPECT_EQ(0, ret) << "HdfPowerHdiTest005 failed"; - } + int32_t ret = powerInterface->ForceSuspend(); + EXPECT_EQ(0, ret) << "HdfPowerHdiTest005 failed"; } /** @@ -245,11 +303,9 @@ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest007, TestSize.Level1) */ HWTEST_F(HdfPowerHdiTest, HdfPowerHdiTest008, TestSize.Level1) { - if (false) { - std::string dump; - EXPECT_TRUE(HDF_SUCCESS == - g_powerInterface->PowerDump(dump))<< "HdfPowerHdiTest008 failed"; - } + std::string dump; + EXPECT_TRUE(HDF_SUCCESS == + g_powerInterface->PowerDump(dump))<< "HdfPowerHdiTest008 failed"; } /**