• 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 "softbus_adapter_test.h"
17 
18 using namespace testing::ext;
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SetUpTestCase(void)22 void SoftbusAdapterTest::SetUpTestCase(void) {}
23 
TearDownTestCase(void)24 void SoftbusAdapterTest::TearDownTestCase(void) {}
25 
SetUp(void)26 void SoftbusAdapterTest::SetUp(void) {}
27 
TearDown(void)28 void SoftbusAdapterTest::TearDown(void) {}
29 
30 /**
31  * @tc.name: RegisterSoftbusListener_001
32  * @tc.desc: Verify the RegisterSoftbusListener and UnRegisterSoftbusListener function.
33  * @tc.type: FUNC
34  * @tc.require: AR000H0E5U
35  */
36 HWTEST_F(SoftbusAdapterTest, RegisterSoftbusListener_001, TestSize.Level1)
37 {
38     std::string sessionName = CTRL_SESSION_NAME;
39     std::string peerDevId = "peerDevId";
40     std::shared_ptr<ISoftbusListener> listener = std::make_shared<MockISoftbusListener>();
41 
42     EXPECT_EQ(DH_SUCCESS, softbusAdapter.RegisterSoftbusListener(listener, sessionName, peerDevId));
43     EXPECT_EQ(DH_SUCCESS, softbusAdapter.UnRegisterSoftbusListener(sessionName, peerDevId));
44 }
45 
46 /**
47  * @tc.name: CreateSoftbusSessionServer_001
48  * @tc.desc: Verify the CreateSoftbusSessionServer and RemoveSoftbusSessionServer function.
49  * @tc.type: FUNC
50  * @tc.require: AR000H0E5U
51  */
52 HWTEST_F(SoftbusAdapterTest, CreateSoftbusSessionServer_001, TestSize.Level1)
53 {
54     std::string pkgname;
55     std::string sessionName = CTRL_SESSION_NAME;
56     std::string peerDevId = "peerDevId";
57 
58     EXPECT_NE(DH_SUCCESS, softbusAdapter.CreateSoftbusSessionServer(pkgname, sessionName, peerDevId));
59     EXPECT_EQ(DH_SUCCESS, softbusAdapter.RemoveSoftbusSessionServer(pkgname, sessionName, peerDevId));
60 }
61 
62 /**
63  * @tc.name: OpenSoftbusSession_001
64  * @tc.desc: Verify the OpenSoftbusSession and CloseSoftbusSession function.
65  * @tc.type: FUNC
66  * @tc.require: AR000H0E5U
67  */
68 HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_001, TestSize.Level1)
69 {
70     std::string localSessionName;
71     std::string peerSessionName;
72     std::string peerDevId;
73     int32_t actual = softbusAdapter.OpenSoftbusSession(localSessionName, peerSessionName, peerDevId);
74 
75     EXPECT_EQ(ERR_DH_AUDIO_ADAPTER_OPEN_SESSION_FAIL, actual);
76     EXPECT_EQ(DH_SUCCESS, softbusAdapter.CloseSoftbusSession(actual));
77 }
78 
79 /**
80  * @tc.name: OpenSoftbusSession_002
81  * @tc.desc: Verify the OpenSoftbusSession and CloseSoftbusSession function.
82  * @tc.type: FUNC
83  * @tc.require: AR000H0E5U
84  */
85 HWTEST_F(SoftbusAdapterTest, OpenSoftbusSession_002, TestSize.Level1)
86 {
87     std::string localSessionName = CTRL_SESSION_NAME;
88     std::string peerSessionName = CTRL_SESSION_NAME;
89     std::string peerDevId = "peerDevId";
90     int actual = softbusAdapter.OpenSoftbusSession(localSessionName, peerSessionName, peerDevId);
91 
92     EXPECT_NE(DH_SUCCESS, actual);
93     EXPECT_EQ(DH_SUCCESS, softbusAdapter.CloseSoftbusSession(actual));
94 }
95 
96 /**
97  * @tc.name: SendSoftbusBytes_001
98  * @tc.desc: Verify the SendSoftbusBytes function.
99  * @tc.type: FUNC
100  * @tc.require: AR000H0E5U
101  */
102 HWTEST_F(SoftbusAdapterTest, SendSoftbusBytes_001, TestSize.Level1)
103 {
104     int32_t sessionId = -1;
105     uint8_t *data = nullptr;
106     int32_t dataLen = 0;
107 
108     EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, softbusAdapter.SendSoftbusBytes(sessionId, data, dataLen));
109 }
110 
111 /**
112  * @tc.name: SendSoftbusStream_001
113  * @tc.desc: Verify the SendSoftbusStream function.
114  * @tc.type: FUNC
115  * @tc.require: AR000H0E5U
116  */
117 HWTEST_F(SoftbusAdapterTest, SendSoftbusStream_001, TestSize.Level1)
118 {
119     int32_t sessionId = 0;
120     std::shared_ptr<AudioData> audioData = std::make_shared<AudioData>(DEFAULT_AUDIO_DATA_SIZE);
121 
122     EXPECT_EQ(DH_SUCCESS, softbusAdapter.SendSoftbusStream(sessionId, audioData));
123 }
124 
125 /**
126  * @tc.name: OnSoftbusSessionOpened_001
127  * @tc.desc: Verify the OnSoftbusSessionOpened function.
128  * @tc.type: FUNC
129  * @tc.require: AR000H0E5U
130  */
131 HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_001, TestSize.Level1)
132 {
133     int32_t sessionId = 1;
134     int32_t result = -1;
135 
136     EXPECT_EQ(ERR_DH_AUDIO_ADAPTER_OPEN_SESSION_FAIL, softbusAdapter.OnSoftbusSessionOpened(sessionId, result));
137 }
138 
139 /**
140  * @tc.name: OnSoftbusSessionOpened_001
141  * @tc.desc: Verify the OnSoftbusSessionClosed function.
142  * @tc.type: FUNC
143  * @tc.require: AR000H0E5U
144  */
145 HWTEST_F(SoftbusAdapterTest, OnSoftbusSessionOpened_002, TestSize.Level1)
146 {
147     int32_t sessionId = 1;
148     int32_t result = 0;
149 
150     EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, softbusAdapter.OnSoftbusSessionOpened(sessionId, result));
151     softbusAdapter.OnSoftbusSessionClosed(sessionId);
152 }
153 } // namespace DistributedHardware
154 } // namespace OHOS
155