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_writeremoteobject_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_log.h"
22 #include "thermal_mgr_client.h"
23 #include "thermal_srv_proxy.h"
24 #include "thermal_temp_callback_proxy.h"
25
26 using namespace testing::ext;
27 using namespace OHOS::PowerMgr;
28 using namespace OHOS;
29 using namespace std;
30
31 namespace {
32 /**
33 * @tc.name: ThermalClientMockParcelTest001
34 * @tc.desc: Thermal client test by mock parcel
35 * @tc.type: FUNC
36 * @tc.require: issueI64U2R
37 */
HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalClientMockParcelTest001, TestSize.Level0)38 HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalClientMockParcelTest001, TestSize.Level0)
39 {
40 THERMAL_HILOGD(LABEL_TEST, "ThermalClientMockParcelTest001 start");
41 auto& thermalMgrClient = ThermalMgrClient::GetInstance();
42
43 sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
44 EXPECT_FALSE(sptrRemoteObj == nullptr);
45 std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj);
46 EXPECT_FALSE(srvProxy == nullptr);
47 std::vector<std::string> typeList {};
48 std::string desc {};
49 sptr<IThermalTempCallback> tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj);
50 EXPECT_FALSE(tempCallback == nullptr);
51 EXPECT_FALSE(thermalMgrClient.SubscribeThermalTempCallback(typeList, tempCallback));
52 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalTempCallback(tempCallback));
53 sptr<IThermalLevelCallback> levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj);
54 EXPECT_FALSE(levelCallback == nullptr);
55 EXPECT_FALSE(thermalMgrClient.SubscribeThermalLevelCallback(levelCallback));
56 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalLevelCallback(levelCallback));
57 sptr<IThermalActionCallback> actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj);
58 EXPECT_FALSE(actionCallback == nullptr);
59 EXPECT_FALSE(thermalMgrClient.SubscribeThermalActionCallback(typeList, desc, actionCallback));
60 EXPECT_FALSE(thermalMgrClient.UnSubscribeThermalActionCallback(actionCallback));
61
62 SensorType sensorType = SensorType::SOC;
63 EXPECT_TRUE(thermalMgrClient.GetThermalSensorTemp(sensorType) == 0);
64 EXPECT_TRUE(thermalMgrClient.GetThermalLevel() == ThermalLevel::COOL);
65 std::string sence = "";
66 EXPECT_FALSE(thermalMgrClient.SetScene(sence));
67 std::vector<std::string> args {};
68 EXPECT_TRUE(thermalMgrClient.Dump(args) == "can't connect service");
69 THERMAL_HILOGD(LABEL_TEST, "ThermalClientMockParcelTest001 end");
70 }
71
72 /**
73 * @tc.name: ThermalClientMockParcelTest002
74 * @tc.desc: ThermalSrvSensorInfo test by mock parcel
75 * @tc.type: FUNC
76 * @tc.require: issueI64U2R
77 */
HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalClientMockParcelTest002, TestSize.Level0)78 HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalClientMockParcelTest002, TestSize.Level0)
79 {
80 THERMAL_HILOGD(LABEL_TEST, "ThermalClientMockParcelTest002 start");
81 std::string type = "test";
82 int32_t temp = 100;
83 sptr<ThermalSrvSensorInfo> info = new ThermalSrvSensorInfo(type, temp);
84 EXPECT_TRUE(type == info->GetType());
85 EXPECT_TRUE(temp == info->GetTemp());
86 MessageParcel parcel {};
87 EXPECT_FALSE(info->Marshalling(parcel));
88 THERMAL_HILOGD(LABEL_TEST, "ThermalClientMockParcelTest002 end");
89 }
90
91 /**
92 * @tc.name: ThermalMockProxyWriteremoteobjectTest001
93 * @tc.desc: proxy test
94 * @tc.type: FUNC
95 * @tc.require: issueI5YZQ2
96 */
HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalMockProxyWriteremoteobjectTest001, TestSize.Level0)97 HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalMockProxyWriteremoteobjectTest001, TestSize.Level0)
98 {
99 THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxyWriteremoteobjectTest001 start");
100 std::string result = "a";
101 sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
102 EXPECT_FALSE(sptrRemoteObj == nullptr);
103 std::shared_ptr<ThermalActionCallbackProxy> actionProxy =
104 std::make_shared<ThermalActionCallbackProxy>(sptrRemoteObj);
105 EXPECT_FALSE(actionProxy == nullptr);
106 using ActionCallbackMap = std::map<std::string, std::string>;
107 ActionCallbackMap map;
108 EXPECT_FALSE(actionProxy->OnThermalActionChanged(map));
109 std::shared_ptr<ThermalLevelCallbackProxy> levalProxy = std::make_shared<ThermalLevelCallbackProxy>(sptrRemoteObj);
110 EXPECT_FALSE(levalProxy == nullptr);
111 ThermalLevel leval = ThermalLevel::COOL;
112 EXPECT_FALSE(levalProxy->OnThermalLevelChanged(leval));
113
114 std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj);
115 EXPECT_FALSE(srvProxy == nullptr);
116 std::vector<std::string> typeList;
117 std::string desc;
118 sptr<IThermalTempCallback> tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj);
119 EXPECT_FALSE(tempCallback == nullptr);
120 EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback));
121 EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback));
122 sptr<IThermalLevelCallback> levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj);
123 EXPECT_FALSE(levelCallback == nullptr);
124 EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback));
125 EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback));
126 sptr<IThermalActionCallback> actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj);
127 EXPECT_FALSE(actionCallback == nullptr);
128 EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback));
129 EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback));
130 THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxyWriteremoteobjectTest001 end");
131 }
132 } // namespace
133