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