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 "screen_data_channel_impl_test.h"
18 #undef private
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace DistributedHardware {
SetUpTestCase(void)25 void ScreenDataChannelImplTest::SetUpTestCase(void) {}
26
TearDownTestCase(void)27 void ScreenDataChannelImplTest::TearDownTestCase(void) {}
28
SetUp(void)29 void ScreenDataChannelImplTest::SetUp(void)
30 {
31 std::string peerDevId = "test";
32 dataChannelImpl_ = std::make_shared<ScreenDataChannelImpl>(peerDevId);
33 }
34
TearDown(void)35 void ScreenDataChannelImplTest::TearDown(void) {}
36
37 /**
38 * @tc.name: CreateSession_001
39 * @tc.desc: Verify the CreateSession function.
40 * @tc.type: FUNC
41 * @tc.require: Issue Number
42 */
43 HWTEST_F(ScreenDataChannelImplTest, CreateSession_001, TestSize.Level1)
44 {
45 std::shared_ptr<IScreenChannelListener> listener = nullptr;
46 int32_t ret = dataChannelImpl_->CreateSession(listener);
47
48 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret);
49 }
50
51 /**
52 * @tc.name: release_session_test_001
53 * @tc.desc: Verify the ReleaseSession function.
54 * @tc.type: FUNC
55 * @tc.require: Issue Number
56 */
57 HWTEST_F(ScreenDataChannelImplTest, release_session_test_001, TestSize.Level1)
58 {
59 std::shared_ptr<IScreenChannelListener> listener =
60 std::make_shared<MockIScreenChannelListener>();
61
62 dataChannelImpl_->CreateSession(listener);
63 int32_t ret = dataChannelImpl_->ReleaseSession();
64 EXPECT_EQ(DH_SUCCESS, ret);
65 }
66
67 /**
68 * @tc.name: release_session_test_002
69 * @tc.desc: Verify the ReleaseSession function.
70 * @tc.type: FUNC
71 * @tc.require: Issue Number
72 */
73 HWTEST_F(ScreenDataChannelImplTest, release_session_test_002, TestSize.Level1)
74 {
75 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, dataChannelImpl_->ReleaseSession());
76 }
77
78 /**
79 * @tc.name: close_session_test_001
80 * @tc.desc: Verify the CloseSession function.
81 * @tc.type: FUNC
82 * @tc.require: Issue Number
83 */
84 HWTEST_F(ScreenDataChannelImplTest, close_session_test_001, TestSize.Level1)
85 {
86 dataChannelImpl_->sessionId_ = 1;
87 EXPECT_EQ(DH_SUCCESS, dataChannelImpl_->CloseSession());
88 }
89
90 /**
91 * @tc.name: close_session_test_002
92 * @tc.desc: Verify the CloseSession function.
93 * @tc.type: FUNC
94 * @tc.require: Issue Number
95 */
96 HWTEST_F(ScreenDataChannelImplTest, close_session_test_002, TestSize.Level1)
97 {
98 dataChannelImpl_->sessionId_ = 0;
99 EXPECT_EQ(ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN, dataChannelImpl_->CloseSession());
100 }
101
102 /**
103 * @tc.name: send_data_test_002
104 * @tc.desc: Verify the SendData function.
105 * @tc.type: FUNC
106 * @tc.require: Issue Number
107 */
108 HWTEST_F(ScreenDataChannelImplTest, send_data_test_002, TestSize.Level1)
109 {
110 std::shared_ptr<DataBuffer> data = nullptr;
111 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, dataChannelImpl_->SendData(data));
112 }
113
114 /**
115 * @tc.name: on_session_opened_test_001
116 * @tc.desc: Verify the OnSessionOpened function.
117 * @tc.type: FUNC
118 * @tc.require: Issue Number
119 */
120 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_001, TestSize.Level1)
121 {
122 std::shared_ptr<IScreenChannelListener> listener =
123 std::make_shared<MockIScreenChannelListener>();
124 dataChannelImpl_->channelListener_ = listener;
125 int32_t sessionId = 0;
126 int32_t result = 0;
127
128 dataChannelImpl_->OnSessionOpened(sessionId, result);
129 }
130
131 /**
132 * @tc.name: on_session_opened_test_002
133 * @tc.desc: Verify the OnSessionOpened function.
134 * @tc.type: FUNC
135 * @tc.require: Issue Number
136 */
137 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_002, TestSize.Level1)
138 {
139 std::shared_ptr<IScreenChannelListener> listener =
140 std::make_shared<MockIScreenChannelListener>();
141 dataChannelImpl_->channelListener_ = listener;
142 int32_t sessionId = -1;
143 int32_t result = -1;
144
145 dataChannelImpl_->OnSessionOpened(sessionId, result);
146 }
147
148 /**
149 * @tc.name: on_session_opened_test_003
150 * @tc.desc: Verify the OnSessionOpened function.
151 * @tc.type: FUNC
152 * @tc.require: Issue Number
153 */
154 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_003, TestSize.Level1)
155 {
156 std::shared_ptr<IScreenChannelListener> listener = nullptr;
157 dataChannelImpl_->channelListener_ = listener;
158 int32_t sessionId = 0;
159 int32_t result = 0;
160
161 dataChannelImpl_->OnSessionOpened(sessionId, result);
162 }
163
164 /**
165 * @tc.name: on_session_closed_test_001
166 * @tc.desc: Verify the OnSessionClosed function.
167 * @tc.type: FUNC
168 * @tc.require: Issue Number
169 */
170 HWTEST_F(ScreenDataChannelImplTest, on_session_closed_test_001, TestSize.Level1)
171 {
172 std::shared_ptr<IScreenChannelListener> listener = nullptr;
173 dataChannelImpl_->channelListener_ = listener;
174 int32_t sessionId = 0;
175
176 dataChannelImpl_->OnSessionClosed(sessionId);
177 }
178
179 /**
180 * @tc.name: on_stream_received_test_001
181 * @tc.desc: Verify the OnStreamReceived function.
182 * @tc.type: FUNC
183 * @tc.require: Issue Number
184 */
185 HWTEST_F(ScreenDataChannelImplTest, on_stream_received_test_001, TestSize.Level1)
186 {
187 std::shared_ptr<IScreenChannelListener> listener =
188 std::make_shared<MockIScreenChannelListener>();
189 dataChannelImpl_->channelListener_ = listener;
190
191 StreamData *ext = nullptr;
192 StreamFrameInfo *param = nullptr;
193
194 int32_t sessionId = 0;
195 StreamData data;
196 data.buf = new char[DATA_LEN];
197 data.bufLen = DATA_LEN;
198
199 dataChannelImpl_->OnStreamReceived(sessionId, &data, ext, param);
200 delete[] data.buf;
201 }
202 } // DistributedHardware
203 } // OHOS