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 */
HWTEST_F(ThermalMockProxyRemoteTest, ThermalClientMockPeerTest001, TestSize.Level0)40 HWTEST_F(ThermalMockProxyRemoteTest, ThermalClientMockPeerTest001, TestSize.Level0)
41 {
42 THERMAL_HILOGD(LABEL_TEST, "ThermalClientMockPeerTest001 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_HILOGD(LABEL_TEST, "ThermalClientMockPeerTest001 end");
72 }
73
74 /**
75 * @tc.name: ThermalMockProxyRemoteTest001
76 * @tc.desc: proxy test
77 * @tc.type: FUNC
78 * @tc.require: issueI5YZQ2
79 */
HWTEST_F(ThermalMockProxyRemoteTest, ThermalMockProxyRemoteTest001, TestSize.Level0)80 HWTEST_F(ThermalMockProxyRemoteTest, ThermalMockProxyRemoteTest001, TestSize.Level0)
81 {
82 THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxyRemoteTest001 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 EXPECT_FALSE(srvProxy->GetThermalSrvSensorInfo(type, *sensorInfo));
106 EXPECT_FALSE(srvProxy->GetThermalLevel(level));
107 std::string sence;
108 EXPECT_FALSE(srvProxy->SetScene(sence));
109 std::vector<std::string> args;
110 uint32_t argc = 0;
111 EXPECT_TRUE(srvProxy->ShellDump(args, argc) == "remote error");
112 std::vector<std::string> typeList;
113 std::string desc;
114 sptr<IThermalTempCallback> tempCallback;
115 EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback));
116 EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback));
117 sptr<IThermalLevelCallback> levelCallback;
118 EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback));
119 EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback));
120 sptr<IThermalActionCallback> actionCallback;
121 EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback));
122 EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback));
123 THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxyRemoteTest001 end");
124 }
125 } // namespace
126