• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_writeinterfacetoken_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_srv_proxy.h"
23 #include "thermal_srv_sensor_info.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: ThermalMockProxyWriteinterfacetokenTest001
34  * @tc.desc: proxy test
35  * @tc.type: FUNC
36  * @tc.require: issueI5YZQ2
37  */
38 HWTEST_F(ThermalMockProxyWriteinterfacetokenTest, ThermalMockProxyWriteinterfacetokenTest001, TestSize.Level0)
39 {
40     THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteinterfacetokenTest001 function start!");
41     sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
42     EXPECT_FALSE(sptrRemoteObj == nullptr);
43     std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj);
44     EXPECT_FALSE(srvProxy == nullptr);
45     std::vector<std::string> typeList;
46     std::string desc;
47     sptr<IThermalTempCallback> tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj);
48     EXPECT_FALSE(tempCallback == nullptr);
49     EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK);
50     EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK);
51     sptr<IThermalLevelCallback> levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj);
52     EXPECT_FALSE(levelCallback == nullptr);
53     EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK);
54     EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK);
55     sptr<IThermalActionCallback> actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj);
56     EXPECT_FALSE(actionCallback == nullptr);
57     EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK);
58     EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK);
59 
60     SensorType type = SensorType::SOC;
61     sptr<ThermalSrvSensorInfo> sensorInfo = new ThermalSrvSensorInfo();
62     EXPECT_FALSE(sensorInfo == nullptr);
63     bool thermalInfoRet = false;
64     srvProxy->GetThermalSrvSensorInfo(static_cast<int32_t>(type), *sensorInfo, thermalInfoRet);
65     EXPECT_FALSE(thermalInfoRet);
66     ThermalLevel level = ThermalLevel::COOL;
67     int32_t levelValue = static_cast<int32_t>(level);
68     EXPECT_NE(srvProxy->GetThermalLevel(levelValue), ERR_OK);
69     std::string sence;
70     EXPECT_NE(srvProxy->SetScene(sence), ERR_OK);
71     THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteinterfacetokenTest001 function end!");
72 }
73 
74 /**
75  * @tc.name: ThermalMockProxyWriteinterfacetokenTest002
76  * @tc.desc: proxy test
77  * @tc.type: FUNC
78  * @tc.require: issueI5YZQ2
79  */
80 HWTEST_F(ThermalMockProxyWriteinterfacetokenTest, ThermalMockProxyWriteinterfacetokenTest002, TestSize.Level0)
81 {
82     THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteinterfacetokenTest002 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     THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteinterfacetokenTest002 function end!");
101 }
102 } // namespace
103