• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #include "i_audio_stream.h"
19 #include <map>
20 
21 #include "audio_errors.h"
22 #include "audio_service_log.h"
23 #include "audio_utils.h"
24 #include "audio_policy_manager.h"
25 #include "capturer_in_client.h"
26 #include "renderer_in_client.h"
27 
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 
33 class IAudioStreamUnitTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
37     void SetUp();
38     void TearDown();
39 };
40 
41 const std::vector<AudioSamplingRate> AUDIO_FAST_STREAM_SUPPORTED_SAMPLING_RATES {
42     SAMPLE_RATE_48000,
43 };
44 
45 const std::vector<AudioSampleFormat> AUDIO_FAST_STREAM_SUPPORTED_FORMATS {
46     SAMPLE_S16LE,
47     SAMPLE_S32LE,
48     SAMPLE_F32LE
49 };
50 
51 /**
52  * @tc.name  : Test GetByteSizePerFrame API
53  * @tc.type  : FUNC
54  * @tc.number: GetByteSizePerFrame_001
55  * @tc.desc  : Test GetByteSizePerFrame interface.
56  */
57 HWTEST(IAudioStreamUnitTest, GetByteSizePerFrame_001, TestSize.Level1)
58 {
59     AudioStreamParams params = {SAMPLE_RATE_48000, SAMPLE_S16LE, 2};
60     size_t result = 0;
61     int32_t ret = IAudioStream::GetByteSizePerFrame(params, result);
62     EXPECT_NE(ret, ERR_INVALID_OPERATION);
63 }
64 
65 /**
66  * @tc.name  : Test GetByteSizePerFrame API
67  * @tc.type  : FUNC
68  * @tc.number: GetByteSizePerFrame_002
69  * @tc.desc  : Test GetByteSizePerFrame interface.
70  */
71 HWTEST(IAudioStreamUnitTest, GetByteSizePerFrame_002, TestSize.Level1)
72 {
73     AudioStreamParams params = {SAMPLE_RATE_48000, 100, 2};
74     size_t result = 0;
75     int32_t ret = IAudioStream::GetByteSizePerFrame(params, result);
76     EXPECT_EQ(ret, ERR_INVALID_PARAM);
77 }
78 
79 /**
80  * @tc.name  : Test GetByteSizePerFrame API
81  * @tc.type  : FUNC
82  * @tc.number: GetByteSizePerFrame_003
83  * @tc.desc  : Test GetByteSizePerFrame interface.
84  */
85 HWTEST(IAudioStreamUnitTest, GetByteSizePerFrame_003, TestSize.Level1)
86 {
87     AudioStreamParams params = {SAMPLE_RATE_48000, 100, -1};
88     size_t result = 0;
89     int32_t ret = IAudioStream::GetByteSizePerFrame(params, result);
90     EXPECT_EQ(ret, ERR_INVALID_PARAM);
91 }
92 
93 /**
94  * @tc.name  : Test IsStreamSupported API
95  * @tc.type  : FUNC
96  * @tc.number: IsStreamSupported_001
97  * @tc.desc  : Test IsStreamSupported interface.
98  */
99 HWTEST(IAudioStreamUnitTest, IsStreamSupported_001, TestSize.Level1)
100 {
101     int32_t streamFlags = 0;
102     AudioStreamParams params = {SAMPLE_RATE_48000, SAMPLE_S16LE, 2};
103     bool result = IAudioStream::IsStreamSupported(streamFlags, params);
104     EXPECT_TRUE(result);
105 }
106 
107 /**
108  * @tc.name  : Test IsStreamSupported API
109  * @tc.type  : FUNC
110  * @tc.number: IsStreamSupported_002
111  * @tc.desc  : Test IsStreamSupported interface.
112  */
113 HWTEST(IAudioStreamUnitTest, IsStreamSupported_002, TestSize.Level1)
114 {
115     int32_t streamFlags = STREAM_FLAG_FAST;
116     AudioStreamParams params = {SAMPLE_RATE_48000, SAMPLE_S16LE, 2};
117     bool result = IAudioStream::IsStreamSupported(streamFlags, params);
118     EXPECT_FALSE(result);
119 }
120 } // namespace AudioStandard
121 } // namespace OHOS
122