• 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 #define private public
17 #include "dscreen_sink_load_callback.h"
18 #include "dscreen_sink_handler_test.h"
19 #undef private
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace DistributedHardware {
SetUpTestCase(void)26 void DScreenSinkHandlerTest::SetUpTestCase(void) {}
27 
TearDownTestCase(void)28 void DScreenSinkHandlerTest::TearDownTestCase(void) {}
29 
SetUp(void)30 void DScreenSinkHandlerTest::SetUp(void)
31 {
32     DScreenSinkHandler::GetInstance().InitSink("DScreenSinkHandlerTest");
33 }
34 
TearDown(void)35 void DScreenSinkHandlerTest::TearDown(void)
36 {
37     DScreenSinkHandler::GetInstance().ReleaseSink();
38 }
39 
40 /**
41  * @tc.name: InitSink_001
42  * @tc.desc: Verify the InitSink function.
43  * @tc.type: FUNC
44  * @tc.require: Issue Number
45  */
46 HWTEST_F(DScreenSinkHandlerTest, InitSink_001, TestSize.Level1)
47 {
48     const std::string param = "";
49     int32_t ret = DScreenSinkHandler::GetInstance().InitSink(param);
50     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
51 }
52 
53 /**
54  * @tc.name: InitSink_002
55  * @tc.desc: Verify the InitSink function.
56  * @tc.type: FUNC
57  * @tc.require: Issue Number
58  */
59 HWTEST_F(DScreenSinkHandlerTest, InitSink_002, TestSize.Level1)
60 {
61     const std::string param = "DScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandler \
62         TestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandler \
63         TestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandler \
64         TestDScreenSinkHandlerTestDScreenSinkHandlerTestDScreenSinkHandlerTest";
65     int32_t ret = DScreenSinkHandler::GetInstance().InitSink(param);
66     EXPECT_EQ(DH_SUCCESS, ret);
67 }
68 
69 /**
70  * @tc.name: LocalHardware_001
71  * @tc.desc: Verify the SubscribeLocalHardware function.
72  * @tc.type: FUNC
73  * @tc.require: Issue Number
74  */
75 HWTEST_F(DScreenSinkHandlerTest, LocalHardware_001, TestSize.Level1)
76 {
77     const std::string dhId = "DScreenSinkHandlerTest";
78     const std::string param = "DScreenSinkHandlerTest";
79     sptr<DScreenSinkLoadCallback> loadCallback = new DScreenSinkLoadCallback(param);
80     loadCallback->OnLoadSystemAbilitySuccess(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, nullptr);
81     loadCallback->OnLoadSystemAbilitySuccess(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, nullptr);
82     int32_t ret = DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param);
83     EXPECT_EQ(DH_SUCCESS, ret);
84 
85     ret = DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId);
86     EXPECT_EQ(DH_SUCCESS, ret);
87 
88     DScreenSinkHandler::GetInstance().dScreenSinkProxy_ = nullptr;
89     ret = DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId);
90     EXPECT_EQ(ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, ret);
91 }
92 
93 /**
94  * @tc.name: SubscribeLocalHardware_001
95  * @tc.desc: Verify the SubscribeLocalHardware function.
96  * @tc.type: FUNC
97  * @tc.require: Issue Number
98  */
99 HWTEST_F(DScreenSinkHandlerTest, SubscribeLocalHardware_001, TestSize.Level1)
100 {
101     const std::string dhId = "";
102     const std::string param = "DScreenSinkHandlerTest";
103     int32_t ret = DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param);
104     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
105 
106     ret = DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId);
107     EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, ret);
108 }
109 
110 /**
111  * @tc.name: OnRemoteSinkSvrDied_001
112  * @tc.desc: Verify the OnRemoteSinkSvrDied function.
113  * @tc.type: FUNC
114  * @tc.require: Issue Number
115  */
116 HWTEST_F(DScreenSinkHandlerTest, OnRemoteSinkSvrDied_001, TestSize.Level1)
117 {
118     sptr<ISystemAbilityManager> samgr =
119             SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
120 
121     sptr<IRemoteObject> remoteObject =
122             samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID);
123 
124     wptr<IRemoteObject> remote(remoteObject);
125 
126     DScreenSinkHandler::GetInstance().sinkSvrRecipient_->OnRemoteDied(remote);
127     EXPECT_EQ(nullptr, DScreenSinkHandler::GetInstance().dScreenSinkProxy_);
128 }
129 }
130 }