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_mock_proxy_remote_test.h" 17 18 #include "mock_thermal_remote_object.h" 19 #include "thermal_action_callback_proxy.h" 20 #include "thermal_level_callback_proxy.h" 21 #include "thermal_level_info.h" 22 #include "thermal_log.h" 23 #include "thermal_mgr_client.h" 24 #include "thermal_srv_proxy.h" 25 #include "thermal_srv_sensor_info.h" 26 #include "thermal_temp_callback_proxy.h" 27 28 using namespace testing::ext; 29 using namespace OHOS::PowerMgr; 30 using namespace OHOS; 31 using namespace std; 32 33 namespace { 34 /** 35 * @tc.name: ThermalClientMockPeerTest001 36 * @tc.desc: Thermal client test by mock peer 37 * @tc.type: FUNC 38 * @tc.require: issueI64U2R 39 */ 40 HWTEST_F(ThermalMockProxyRemoteTest, ThermalClientMockPeerTest001, TestSize.Level0) 41 { 42 THERMAL_HILOGI(LABEL_TEST, "ThermalClientMockPeerTest001 function start!"); 43 auto& thermalMgrClient = ThermalMgrClient::GetInstance(); 44 45 sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject(); 46 EXPECT_FALSE(sptrRemoteObj == nullptr); 47 std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj); 48 EXPECT_FALSE(srvProxy == nullptr); 49 std::vector<std::string> typeList {}; 50 std::string desc {}; 51 sptr<IThermalTempCallback> tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); 52 EXPECT_FALSE(tempCallback == nullptr); 53 EXPECT_FALSE(thermalMgrClient.SubscribeThermalTempCallback(typeList, tempCallback)); 54 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalTempCallback(tempCallback)); 55 sptr<IThermalLevelCallback> levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); 56 EXPECT_FALSE(levelCallback == nullptr); 57 EXPECT_FALSE(thermalMgrClient.SubscribeThermalLevelCallback(levelCallback)); 58 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalLevelCallback(levelCallback)); 59 sptr<IThermalActionCallback> actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); 60 EXPECT_FALSE(actionCallback == nullptr); 61 EXPECT_FALSE(thermalMgrClient.SubscribeThermalActionCallback(typeList, desc, actionCallback)); 62 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalActionCallback(actionCallback)); 63 64 SensorType sensorType = SensorType::SOC; 65 EXPECT_TRUE(thermalMgrClient.GetThermalSensorTemp(sensorType) == 0); 66 EXPECT_TRUE(thermalMgrClient.GetThermalLevel() == ThermalLevel::COOL); 67 std::string sence = ""; 68 EXPECT_FALSE(thermalMgrClient.SetScene(sence)); 69 std::vector<std::string> args {}; 70 EXPECT_TRUE(thermalMgrClient.Dump(args) == "can't connect service"); 71 THERMAL_HILOGI(LABEL_TEST, "ThermalClientMockPeerTest001 function end!"); 72 } 73 74 /** 75 * @tc.name: ThermalMockProxyRemoteTest001 76 * @tc.desc: proxy test 77 * @tc.type: FUNC 78 * @tc.require: issueI5YZQ2 79 */ 80 HWTEST_F(ThermalMockProxyRemoteTest, ThermalMockProxyRemoteTest001, TestSize.Level0) 81 { 82 THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyRemoteTest001 function start!"); 83 sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject(); 84 EXPECT_FALSE(sptrRemoteObj == nullptr); 85 std::shared_ptr<ThermalTempCallbackProxy> tempProxy = std::make_shared<ThermalTempCallbackProxy>(sptrRemoteObj); 86 EXPECT_FALSE(tempProxy == nullptr); 87 using TempCallbackMap = std::map<std::string, int32_t>; 88 TempCallbackMap tempCbMap; 89 EXPECT_FALSE(tempProxy->OnThermalTempChanged(tempCbMap)); 90 std::shared_ptr<ThermalActionCallbackProxy> actionProxy = 91 std::make_shared<ThermalActionCallbackProxy>(sptrRemoteObj); 92 EXPECT_FALSE(actionProxy == nullptr); 93 using ActionCallbackMap = std::map<std::string, std::string>; 94 ActionCallbackMap map; 95 EXPECT_FALSE(actionProxy->OnThermalActionChanged(map)); 96 std::shared_ptr<ThermalLevelCallbackProxy> levalProxy = std::make_shared<ThermalLevelCallbackProxy>(sptrRemoteObj); 97 EXPECT_FALSE(levalProxy == nullptr); 98 ThermalLevel level = ThermalLevel::COOL; 99 EXPECT_FALSE(levalProxy->OnThermalLevelChanged(level)); 100 101 std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj); 102 EXPECT_FALSE(srvProxy == nullptr); 103 SensorType type = SensorType::SOC; 104 sptr<ThermalSrvSensorInfo> sensorInfo = new ThermalSrvSensorInfo(); 105 bool thermalInfoRet = false; 106 srvProxy->GetThermalSrvSensorInfo(static_cast<int32_t>(type), *sensorInfo, thermalInfoRet); 107 EXPECT_FALSE(thermalInfoRet); 108 int32_t levelValue = static_cast<int32_t>(level); 109 EXPECT_NE(srvProxy->GetThermalLevel(levelValue), ERR_OK); 110 std::string sence; 111 EXPECT_NE(srvProxy->SetScene(sence), ERR_OK); 112 std::vector<std::string> args; 113 uint32_t argc = 0; 114 std::string dumpShell; 115 srvProxy->ShellDump(args, argc, dumpShell); 116 EXPECT_TRUE(dumpShell == ""); 117 std::vector<std::string> typeList; 118 std::string desc; 119 sptr<IThermalTempCallback> tempCallback; 120 EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); 121 EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); 122 sptr<IThermalLevelCallback> levelCallback; 123 EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); 124 EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); 125 sptr<IThermalActionCallback> actionCallback; 126 EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); 127 EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); 128 THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyRemoteTest001 function end!"); 129 } 130 } // namespace 131