1 /*
2 * Copyright (c) 2023 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 <gtest/gtest.h>
17 #include "distributedaudiotest.h"
18
19 using namespace testing::ext;
20 using namespace OHOS::DistributedHardware;
21
22 int32_t g_audioOk = 0;
23 int32_t g_audioDelay = 5;
24 std::string res = "true";
25
26 class DAudioAutomatTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32 DAudioAutomatTest();
33 };
SetUpTestCase(void)34 void DAudioAutomatTest::SetUpTestCase(void){
35 int ret = InitTestDemo();
36 if (ret != g_audioOk) {
37 DHLOGI("demo test:InitTestDemo error");
38 return;
39 }
40 }
TearDownTestCase(void)41 void DAudioAutomatTest::TearDownTestCase(void) {}
SetUp(void)42 void DAudioAutomatTest::SetUp(void) {}
TearDown(void)43 void DAudioAutomatTest::TearDown(void) {}
DAudioAutomatTest(void)44 DAudioAutomatTest::DAudioAutomatTest(void) {}
45
46
47 /**
48 * @tc.name FindAudioDevice()
49 * @tc.number SUB_DH_DAudio_Dcts_0100
50 * @tc.desc Find Audio Device Test
51 * @tc.size MediumTest
52 * @tc.type Function
53 * @tc.level Level 1
54 */
55 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0100, TestSize.Level1)
56 {
57 std::string ret = HandleAudioEvent(9);
58 EXPECT_EQ(res, ret) << "FindAudioDevice fail";
59 sleep(g_audioDelay);
60 }
61
62 /**
63 * @tc.name OpenSpk()
64 * @tc.number SUB_DH_DAudio_Dcts_0200
65 * @tc.desc Open Spk Test
66 * @tc.size MediumTest
67 * @tc.type Function
68 * @tc.level Level 1
69 */
70 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0200, TestSize.Level1)
71 {
72 std::string ret = HandleAudioEvent(1);
73 EXPECT_EQ(res, ret) << "OpenSpk fail";
74 sleep(g_audioDelay);
75 }
76
77 /**
78 * @tc.name StartRender()
79 * @tc.number SUB_DH_DAudio_Dcts_0300
80 * @tc.desc Start Render Test
81 * @tc.size MediumTest
82 * @tc.type Function
83 * @tc.level Level 1
84 */
85 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0300, TestSize.Level1)
86 {
87
88 std::string ret = HandleAudioEvent(3);
89 EXPECT_EQ(res, ret) << "StartRender fail";
90 sleep(g_audioDelay);
91 }
92
93 /**
94 * @tc.name StopRender()
95 * @tc.number SUB_DH_DAudio_Dcts_0400
96 * @tc.desc Stop Render Test
97 * @tc.size MediumTest
98 * @tc.type Function
99 * @tc.level Level 1
100 */
101 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0400, TestSize.Level1)
102 {
103 std::string ret = HandleAudioEvent(4);
104 EXPECT_EQ(res, ret) << "StopRender fail";
105 sleep(g_audioDelay);
106 }
107
108 /**
109 * @tc.name SetVolume()
110 * @tc.number SUB_DH_DAudio_Dcts_0500
111 * @tc.desc Set Volume Test
112 * @tc.size MediumTest
113 * @tc.type Function
114 * @tc.level Level 1
115 */
116 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0500, TestSize.Level1)
117 {
118 std::string ret = HandleAudioEvent(11);
119 EXPECT_EQ(res, ret) << "SetVolume five fail";
120 sleep(g_audioDelay);
121 }
122
123 /**
124 * @tc.name GetVolume()
125 * @tc.number SUB_DH_DAudio_Dcts_0600
126 * @tc.desc Get Volume Test
127 * @tc.size MediumTest
128 * @tc.type Function
129 * @tc.level Level 1
130 */
131 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0600, TestSize.Level1)
132 {
133 std::string ret = HandleAudioEvent(12);
134 EXPECT_EQ(res, ret) << "GetVolume fail";
135 sleep(g_audioDelay);
136 }
137
138 /**
139 * @tc.name CloseSpk()
140 * @tc.number SUB_DH_DAudio_Dcts_0700
141 * @tc.desc Close Spk Test
142 * @tc.size MediumTest
143 * @tc.type Function
144 * @tc.level Level 1
145 */
146 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0700, TestSize.Level1)
147 {
148 std::string ret = HandleAudioEvent(2);
149 EXPECT_EQ(res, ret) << "CloseSpk fail";
150 sleep(g_audioDelay);
151 }
152
153 /**
154 * @tc.name OpenMic()
155 * @tc.number SUB_DH_DAudio_Dcts_0800
156 * @tc.desc Open Mic Test
157 * @tc.size MediumTest
158 * @tc.type Function
159 * @tc.level Level 1
160 */
161 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0800, TestSize.Level1)
162 {
163 std::string ret = HandleAudioEvent(5);
164 EXPECT_EQ(res, ret) << "OpenMic fail";
165 sleep(g_audioDelay);
166 }
167
168 /**
169 * @tc.name StartCapture()
170 * @tc.number SUB_DH_DAudio_Dcts_0900
171 * @tc.desc Start Capture Test
172 * @tc.size MediumTest
173 * @tc.type Function
174 * @tc.level Level 1
175 */
176 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_0900, TestSize.Level1)
177 {
178 std::string ret = HandleAudioEvent(7);
179 EXPECT_EQ(res, ret) << "StartCapture fail";
180 sleep(g_audioDelay);
181 }
182
183 /**
184 * @tc.name StopCapture()
185 * @tc.number SUB_DH_DAudio_Dcts_1000
186 * @tc.desc Stop Capture Test
187 * @tc.size MediumTest
188 * @tc.type Function
189 * @tc.level Level 1
190 */
191 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_1000, TestSize.Level1)
192 {
193 std::string ret = HandleAudioEvent(8);
194 EXPECT_EQ(res, ret) << "StopCapture fail";
195 sleep(g_audioDelay);
196 }
197
198 /**
199 * @tc.name CloseMic()
200 * @tc.number SUB_DH_DAudio_Dcts_1100
201 * @tc.desc Close Mic Test
202 * @tc.size MediumTest
203 * @tc.type Function
204 * @tc.level Level 1
205 */
206 HWTEST_F(DAudioAutomatTest, SUB_DH_DAudio_Dcts_1100, TestSize.Level1)
207 {
208 std::string ret = HandleAudioEvent(6);
209 EXPECT_EQ(res, ret) << "CloseMic fail";
210 sleep(g_audioDelay);
211 }
212
213