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_002
53 * @tc.desc: Verify the ReleaseSession function.
54 * @tc.type: FUNC
55 * @tc.require: Issue Number
56 */
57 HWTEST_F(ScreenDataChannelImplTest, release_session_test_002, TestSize.Level1)
58 {
59 EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, dataChannelImpl_->ReleaseSession());
60 }
61
62 /**
63 * @tc.name: close_session_test_001
64 * @tc.desc: Verify the CloseSession function.
65 * @tc.type: FUNC
66 * @tc.require: Issue Number
67 */
68 HWTEST_F(ScreenDataChannelImplTest, close_session_test_001, TestSize.Level1)
69 {
70 dataChannelImpl_->sessionId_ = 1;
71 EXPECT_EQ(DH_SUCCESS, dataChannelImpl_->CloseSession());
72 }
73
74 /**
75 * @tc.name: close_session_test_002
76 * @tc.desc: Verify the CloseSession function.
77 * @tc.type: FUNC
78 * @tc.require: Issue Number
79 */
80 HWTEST_F(ScreenDataChannelImplTest, close_session_test_002, TestSize.Level1)
81 {
82 dataChannelImpl_->sessionId_ = 0;
83 EXPECT_EQ(ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN, dataChannelImpl_->CloseSession());
84 }
85
86 /**
87 * @tc.name: send_data_test_002
88 * @tc.desc: Verify the SendData function.
89 * @tc.type: FUNC
90 * @tc.require: Issue Number
91 */
92 HWTEST_F(ScreenDataChannelImplTest, send_data_test_002, TestSize.Level1)
93 {
94 std::shared_ptr<DataBuffer> data = nullptr;
95 EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, dataChannelImpl_->SendData(data));
96 }
97
98 /**
99 * @tc.name: on_session_opened_test_001
100 * @tc.desc: Verify the OnSessionOpened function.
101 * @tc.type: FUNC
102 * @tc.require: Issue Number
103 */
104 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_001, TestSize.Level1)
105 {
106 std::shared_ptr<IScreenChannelListener> listener =
107 std::make_shared<MockIScreenChannelListener>();
108 dataChannelImpl_->channelListener_ = listener;
109 int32_t sessionId = 0;
110 int32_t result = 0;
111
112 dataChannelImpl_->OnSessionOpened(sessionId, result);
113 }
114
115 /**
116 * @tc.name: on_session_opened_test_002
117 * @tc.desc: Verify the OnSessionOpened function.
118 * @tc.type: FUNC
119 * @tc.require: Issue Number
120 */
121 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_002, TestSize.Level1)
122 {
123 std::shared_ptr<IScreenChannelListener> listener =
124 std::make_shared<MockIScreenChannelListener>();
125 dataChannelImpl_->channelListener_ = listener;
126 int32_t sessionId = -1;
127 int32_t result = -1;
128
129 dataChannelImpl_->OnSessionOpened(sessionId, result);
130 }
131
132 /**
133 * @tc.name: on_session_opened_test_003
134 * @tc.desc: Verify the OnSessionOpened function.
135 * @tc.type: FUNC
136 * @tc.require: Issue Number
137 */
138 HWTEST_F(ScreenDataChannelImplTest, on_session_opened_test_003, TestSize.Level1)
139 {
140 std::shared_ptr<IScreenChannelListener> listener = nullptr;
141 dataChannelImpl_->channelListener_ = listener;
142 int32_t sessionId = 0;
143 int32_t result = 0;
144
145 dataChannelImpl_->OnSessionOpened(sessionId, result);
146 }
147
148 /**
149 * @tc.name: on_session_closed_test_001
150 * @tc.desc: Verify the OnSessionClosed function.
151 * @tc.type: FUNC
152 * @tc.require: Issue Number
153 */
154 HWTEST_F(ScreenDataChannelImplTest, on_session_closed_test_001, TestSize.Level1)
155 {
156 std::shared_ptr<IScreenChannelListener> listener = nullptr;
157 dataChannelImpl_->channelListener_ = listener;
158 int32_t sessionId = 0;
159
160 dataChannelImpl_->OnSessionClosed(sessionId);
161 }
162
163 /**
164 * @tc.name: on_stream_received_test_001
165 * @tc.desc: Verify the OnStreamReceived function.
166 * @tc.type: FUNC
167 * @tc.require: Issue Number
168 */
169 HWTEST_F(ScreenDataChannelImplTest, on_stream_received_test_001, TestSize.Level1)
170 {
171 std::shared_ptr<IScreenChannelListener> listener =
172 std::make_shared<MockIScreenChannelListener>();
173 dataChannelImpl_->channelListener_ = listener;
174
175 StreamData *ext = nullptr;
176 StreamFrameInfo *param = nullptr;
177
178 int32_t sessionId = 0;
179 StreamData data;
180 data.buf = new char[DATA_LEN];
181 data.bufLen = DATA_LEN;
182
183 dataChannelImpl_->OnStreamReceived(sessionId, &data, ext, param);
184 delete[] data.buf;
185 }
186 } // DistributedHardware
187 } // OHOS