• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "audio_errors.h"
19 #include "format_converter.h"
20 
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace AudioStandard {
25 class FormatConverterUnitTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase(void)33 void FormatConverterUnitTest::SetUpTestCase(void)
34 {
35 }
36 
TearDownTestCase(void)37 void FormatConverterUnitTest::TearDownTestCase(void)
38 {
39 }
40 
SetUp(void)41 void FormatConverterUnitTest::SetUp(void)
42 {
43 }
44 
TearDown(void)45 void FormatConverterUnitTest::TearDown(void)
46 {
47 }
48 
49 /**
50  * @tc.name  : Test FormatConverter API
51  * @tc.type  : FUNC
52  * @tc.number: S16StereoToF32Stereo_001
53  * @tc.desc  : Test FormatConverter interface.
54  */
55 HWTEST_F(FormatConverterUnitTest, S16StereoToF32Stereo_001, TestSize.Level1)
56 {
57     BufferDesc srcDesc;
58     BufferDesc dstDesc;
59     int32_t ret = -1;
60     uint8_t srcBuffer[4] = {0};
61     uint8_t dstBuffer[8] = {0};
62 
63     srcDesc.bufLength = 4;
64     srcDesc.buffer = srcBuffer;
65     dstDesc.bufLength = 2;
66     dstDesc.buffer = dstBuffer;
67 
68     ret = FormatConverter::S16StereoToF32Stereo(srcDesc, dstDesc);
69     EXPECT_EQ(ret, -1);
70 
71     dstDesc.bufLength = 8;
72 
73     ret = FormatConverter::S16StereoToF32Stereo(srcDesc, dstDesc);
74     EXPECT_EQ(ret, 0);
75 }
76 
77 /**
78  * @tc.name  : Test FormatConverter API
79  * @tc.type  : FUNC
80  * @tc.number: S16StereoToF32Mono_001
81  * @tc.desc  : Test FormatConverter interface.
82  */
83 HWTEST_F(FormatConverterUnitTest, S16StereoToF32Mono_001, TestSize.Level1)
84 {
85     BufferDesc srcDesc;
86     BufferDesc dstDesc;
87     int32_t ret = -1;
88     uint8_t srcBuffer[4] = {0};
89     uint8_t dstBuffer[4] = {0};
90 
91     srcDesc.bufLength = 4;
92     srcDesc.buffer = srcBuffer;
93     dstDesc.bufLength = 2;
94     dstDesc.buffer = dstBuffer;
95 
96     ret = FormatConverter::S16StereoToF32Mono(srcDesc, dstDesc);
97     EXPECT_EQ(ret, -1);
98 
99     dstDesc.bufLength = 4;
100 
101     ret = FormatConverter::S16StereoToF32Mono(srcDesc, dstDesc);
102     EXPECT_EQ(ret, 0);
103 }
104 
105 /**
106  * @tc.name  : Test FormatConverter API
107  * @tc.type  : FUNC
108  * @tc.number: F32MonoToS16Stereo_001
109  * @tc.desc  : Test FormatConverter interface.
110  */
111 HWTEST_F(FormatConverterUnitTest, F32MonoToS16Stereo_001, TestSize.Level1)
112 {
113     BufferDesc srcDesc;
114     BufferDesc dstDesc;
115     int32_t ret = -1;
116     uint8_t srcBuffer[4] = {0};
117     uint8_t dstBuffer[4] = {0};
118 
119     srcDesc.bufLength = 4;
120     srcDesc.buffer = srcBuffer;
121     dstDesc.bufLength = 2;
122     dstDesc.buffer = dstBuffer;
123 
124     ret = FormatConverter::F32MonoToS16Stereo(srcDesc, dstDesc);
125     EXPECT_EQ(ret, -1);
126 
127     dstDesc.bufLength = 4;
128 
129     ret = FormatConverter::F32MonoToS16Stereo(srcDesc, dstDesc);
130     EXPECT_EQ(ret, 0);
131 }
132 
133 /**
134  * @tc.name  : Test FormatConverter API
135  * @tc.type  : FUNC
136  * @tc.number: F32StereoToS16Stereo_001
137  * @tc.desc  : Test FormatConverter interface.
138  */
139 HWTEST_F(FormatConverterUnitTest, F32StereoToS16Stereo_001, TestSize.Level1)
140 {
141     BufferDesc srcDesc;
142     BufferDesc dstDesc;
143     int32_t ret = -1;
144     uint8_t srcBuffer[8] = {0};
145     uint8_t dstBuffer[4] = {0};
146 
147     srcDesc.bufLength = 8;
148     srcDesc.buffer = srcBuffer;
149     dstDesc.bufLength = 2;
150     dstDesc.buffer = dstBuffer;
151 
152     ret = FormatConverter::F32StereoToS16Stereo(srcDesc, dstDesc);
153     EXPECT_EQ(ret, -1);
154 
155     dstDesc.bufLength = 4;
156 
157     ret = FormatConverter::F32StereoToS16Stereo(srcDesc, dstDesc);
158     EXPECT_EQ(ret, 0);
159 }
160 }  // namespace OHOS::AudioStandard
161 }  // namespace OHOS
162