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_sendrequest_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_temp_callback_proxy.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::PowerMgr;
27 using namespace OHOS;
28 using namespace std;
29 
30 namespace {
31 /**
32  * @tc.name: ThermalMockProxySendrequestTest001
33  * @tc.desc: proxy test
34  * @tc.type: FUNC
35  * @tc.require: issueI5YZQ2
36  */
37 HWTEST_F(ThermalMockProxySendrequestTest, ThermalMockProxySendrequestTest001, TestSize.Level0)
38 {
39     THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxySendrequestTest001 start.");
40     sptr<MockThermalRemoteObject> sptrRemoteObj = new MockThermalRemoteObject();
41     EXPECT_FALSE(sptrRemoteObj == nullptr);
42     std::shared_ptr<ThermalActionCallbackProxy> actionProxy =
43         std::make_shared<ThermalActionCallbackProxy>(sptrRemoteObj);
44     EXPECT_FALSE(actionProxy == nullptr);
45     using ActionCallbackMap = std::map<std::string, std::string>;
46     ActionCallbackMap map;
47     EXPECT_FALSE(actionProxy->OnThermalActionChanged(map));
48     std::shared_ptr<ThermalLevelCallbackProxy> levalProxy = std::make_shared<ThermalLevelCallbackProxy>(sptrRemoteObj);
49     EXPECT_FALSE(levalProxy == nullptr);
50     ThermalLevel leval = ThermalLevel::COOL;
51     EXPECT_FALSE(levalProxy->OnThermalLevelChanged(leval));
52 
53     std::shared_ptr<ThermalSrvProxy> srvProxy = std::make_shared<ThermalSrvProxy>(sptrRemoteObj);
54     EXPECT_FALSE(srvProxy == nullptr);
55     std::vector<std::string> typeList;
56     std::string desc;
57     sptr<IThermalTempCallback> tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj);
58     EXPECT_FALSE(tempCallback == nullptr);
59     EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback));
60     EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback));
61     sptr<IThermalLevelCallback> levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj);
62     EXPECT_FALSE(levelCallback == nullptr);
63     EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback));
64     EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback));
65     sptr<IThermalActionCallback> actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj);
66     EXPECT_FALSE(actionCallback == nullptr);
67     EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback));
68     EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback));
69     THERMAL_HILOGD(LABEL_TEST, "ThermalMockProxySendrequestTest001 end.");
70 }
71 } // namespace
72