• 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 "audio_data_channel_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void AudioDataChannelTest::SetUpTestCase(void) {}
23 
TearDownTestCase(void)24 void AudioDataChannelTest::TearDownTestCase(void) {}
25 
SetUp(void)26 void AudioDataChannelTest::SetUp(void)
27 {
28     std::string peerDevId = "peerDevId";
29     dataChannel_ = std::make_shared<AudioDataChannel>(peerDevId);
30 }
31 
TearDown(void)32 void AudioDataChannelTest::TearDown(void)
33 {
34     dataChannel_ = nullptr;
35 }
36 
37 /**
38  * @tc.name: CreateSession_001
39  * @tc.desc: Verify the CreateSession and ReleaseSession function.
40  * @tc.type: FUNC
41  * @tc.require: AR000H0E5U
42  */
43 HWTEST_F(AudioDataChannelTest, CreateSession_001, TestSize.Level1)
44 {
45     std::shared_ptr<IAudioChannelListener> listener = nullptr;
46     dataChannel_->channelListener_ = listener;
47     int32_t sessionId = 0;
48 
49     dataChannel_->OnSessionClosed(sessionId);
50 
51     EXPECT_NE(DH_SUCCESS, dataChannel_->CreateSession(listener, DATA_SPEAKER_SESSION_NAME));
52     EXPECT_EQ(DH_SUCCESS, dataChannel_->ReleaseSession());
53 }
54 
55 /**
56  * @tc.name: OpenSession_002
57  * @tc.desc: Verify the OpenSession and CloseSession function.
58  * @tc.type: FUNC
59  * @tc.require: AR000H0E5U
60  */
61 HWTEST_F(AudioDataChannelTest, OpenSession_002, TestSize.Level1)
62 {
63     std::shared_ptr<IAudioChannelListener> listener = nullptr;
64     dataChannel_->channelListener_ = listener;
65     int32_t sessionId = 0;
66     int32_t result = 0;
67 
68     dataChannel_->OnSessionOpened(sessionId, result);
69 
70     std::shared_ptr<IAudioChannelListener> channelListener = std::make_shared<MockIAudioChannelListener>();
71     dataChannel_->channelListener_ = channelListener;
72 
73     StreamData *ext = nullptr;
74     StreamFrameInfo *param = nullptr;
75 
76     int32_t sessionIdTmp = 0;
77     StreamData data;
78     data.buf = new char[DATA_LEN];
79     data.bufLen = DATA_LEN;
80 
81     dataChannel_->OnStreamReceived(sessionIdTmp, &data, ext, param);
82     delete[] data.buf;
83 
84     EXPECT_NE(DH_SUCCESS, dataChannel_->CreateSession(channelListener, DATA_SPEAKER_SESSION_NAME));
85     EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, dataChannel_->OpenSession());
86     EXPECT_EQ(DH_SUCCESS, dataChannel_->CloseSession());
87 }
88 
89 /**
90  * @tc.name: SendData_001
91  * @tc.desc: Verify the SendData function.
92  * @tc.type: FUNC
93  * @tc.require: AR000H0E5U
94  */
95 HWTEST_F(AudioDataChannelTest, SendData_001, TestSize.Level1)
96 {
97     std::shared_ptr<IAudioChannelListener> listener = std::make_shared<MockIAudioChannelListener>();
98     dataChannel_->channelListener_ = listener;
99     int32_t sessionId = -1;
100     int32_t result = -1;
101 
102     dataChannel_->OnSessionOpened(sessionId, result);
103 
104     std::shared_ptr<AudioData> data = nullptr;
105     EXPECT_EQ(ERR_DH_AUDIO_TRANS_NULL_VALUE, dataChannel_->SendData(data));
106 }
107 
108 /**
109  * @tc.name: SendData_002
110  * @tc.desc: Verify the SendData function.
111  * @tc.type: FUNC
112  * @tc.require: AR000H0E5U
113  */
114 HWTEST_F(AudioDataChannelTest, SendData_002, TestSize.Level1)
115 {
116     std::shared_ptr<IAudioChannelListener> listener = std::make_shared<MockIAudioChannelListener>();
117     dataChannel_->channelListener_ = listener;
118     int32_t sessionId = 0;
119     int32_t result = 0;
120 
121     dataChannel_->OnSessionOpened(sessionId, result);
122 
123     std::shared_ptr<AudioData> audioData = std::make_shared<AudioData>(DEFAULT_AUDIO_DATA_SIZE);
124     EXPECT_EQ(DH_SUCCESS, dataChannel_->SendData(audioData));
125 }
126 } // namespace DistributedHardware
127 } // namespace OHOS
128