1 /*
2 * Copyright (c) 2024 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 "daudio_sink_ctrl_trans_test.h"
17
18 #include "audio_data.h"
19 #include "daudio_constants.h"
20 #include "daudio_errorcode.h"
21 #include "daudio_log.h"
22 #include "daudio_util.h"
23
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace DistributedHardware {
SetUpTestCase(void)28 void DaudioSinkCtrlTransTest::SetUpTestCase(void) {}
29
TearDownTestCase(void)30 void DaudioSinkCtrlTransTest::TearDownTestCase(void) {}
31
SetUp()32 void DaudioSinkCtrlTransTest::SetUp()
33 {
34 std::string devId = "devId";
35 std::string sessionName = "sessionName";
36 std::string peerSessName = "peerSessName";
37 sinkCtrlTransCallback_ = std::make_shared<SinkCtrlTransCallback>();
38 ctrlTrans_ = std::make_shared<DaudioSinkCtrlTrans>(devId, sessionName, peerSessName, sinkCtrlTransCallback_);
39 }
40
TearDown()41 void DaudioSinkCtrlTransTest::TearDown()
42 {
43 ctrlTrans_ = nullptr;
44 sinkCtrlTransCallback_ = nullptr;
45 }
46
OnCtrlTransEvent(const AVTransEvent & event)47 void SinkCtrlTransCallback::OnCtrlTransEvent(const AVTransEvent &event)
48 {
49 (void)event;
50 }
51
OnCtrlTransMessage(const std::shared_ptr<AVTransMessage> & message)52 void SinkCtrlTransCallback::OnCtrlTransMessage(const std::shared_ptr<AVTransMessage> &message)
53 {
54 (void)message;
55 }
56
57 /**
58 * @tc.name: SendAudioEvent_001
59 * @tc.desc: Verify the SendAudioEvent function.
60 * @tc.type: FUNC
61 * @tc.require: AR000HTAPM
62 */
63 HWTEST_F(DaudioSinkCtrlTransTest, SendAudioEvent_001, TestSize.Level1)
64 {
65 sinkCtrlTransCallback_ = nullptr;
66 uint32_t type = 0;
67 EventType eventType = EventType::EVENT_CHANNEL_OPEN_FAIL;
68 std::string content = "content";
69 std::string devId = "devId";
70 AVTransEvent event = {eventType, content, devId};
71 ctrlTrans_->OnChannelEvent(event);
72 EXPECT_NE(DH_SUCCESS, ctrlTrans_->SendAudioEvent(type, content, devId));
73 }
74
75 /**
76 * @tc.name: OnChannelEvent_001
77 * @tc.desc: Verify the OnChannelEvent function.
78 * @tc.type: FUNC
79 * @tc.require: AR000HTAPM
80 */
81 HWTEST_F(DaudioSinkCtrlTransTest, OnChannelEvent_001, TestSize.Level1)
82 {
83 uint32_t eventType = 0;
84 EventType type = EventType::EVENT_CHANNEL_OPEN_FAIL;
85 std::string content = "content";
86 std::string devId = "devId";
87 AVTransEvent event = {type, content, devId};
88 ctrlTrans_->OnChannelEvent(event);
89 event.type = EventType::EVENT_CHANNEL_OPENED;
90 ctrlTrans_->OnChannelEvent(event);
91 event.type = EventType::EVENT_CHANNEL_CLOSED;
92 ctrlTrans_->OnChannelEvent(event);
93 event.type = EventType::EVENT_START_FAIL;
94 ctrlTrans_->OnChannelEvent(event);
95 event.type = EventType::EVENT_START_SUCCESS;
96 ctrlTrans_->OnChannelEvent(event);
97 event.type = EventType::EVENT_STOP_SUCCESS;
98 ctrlTrans_->OnChannelEvent(event);
99 event.type = EventType::EVENT_ENGINE_ERROR;
100 ctrlTrans_->OnChannelEvent(event);
101 event.type = EventType::EVENT_REMOTE_ERROR;
102 ctrlTrans_->OnChannelEvent(event);
103 event.type = EventType::EVENT_DATA_RECEIVED;
104 ctrlTrans_->OnChannelEvent(event);
105 event.type = EventType::EVENT_ADD_STREAM;
106 ctrlTrans_->OnChannelEvent(event);
107 EXPECT_NE(DH_SUCCESS, ctrlTrans_->SendAudioEvent(eventType, content, devId));
108 }
109 } // namespace DistributedHardware
110 } // namespace OHOS