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 #define MEDIA_OHOS 1
17 #include <cstdint>
18 #include "calc_max_amplitude_unittest.h"
19
20 namespace OHOS {
21 namespace Media {
22 namespace CalcMaxAmplitude {
23 using namespace std;
24 using namespace testing;
25 using namespace testing::ext;
26
27 static const int32_t INT_1 = 1;
28 static const float FLOAT_1 = 1.0f;
29
SetUpTestCase(void)30 void CalcMaxAmplitudeUnitTest::SetUpTestCase(void)
31 {
32 }
33
TearDownTestCase(void)34 void CalcMaxAmplitudeUnitTest::TearDownTestCase(void)
35 {
36 }
37
SetUp(void)38 void CalcMaxAmplitudeUnitTest::SetUp(void)
39 {
40 }
41
TearDown(void)42 void CalcMaxAmplitudeUnitTest::TearDown(void)
43 {
44 }
45
46 /**
47 * @tc.name : Test CalculateMaxAmplitudeForPCM8Bit
48 * @tc.number: CalculateMaxAmplitudeForPCM8Bit_001
49 * @tc.desc : Test value == INT8_MIN
50 */
51 HWTEST_F(CalcMaxAmplitudeUnitTest, CalculateMaxAmplitudeForPCM8Bit_001, TestSize.Level0)
52 {
53 int8_t data[1] = {INT8_MIN};
54 float result = CalculateMaxAmplitudeForPCM8Bit(data, INT_1);
55 EXPECT_FLOAT_EQ(result, FLOAT_1);
56 }
57
58 /**
59 * @tc.name : Test CalculateMaxAmplitudeForPCM24Bit
60 * @tc.number: CalculateMaxAmplitudeForPCM24Bit_001
61 * @tc.desc : Test Test curValue < 0
62 */
63 HWTEST_F(CalcMaxAmplitudeUnitTest, CalculateMaxAmplitudeForPCM24Bit_001, TestSize.Level0)
64 {
65 char frame[3];
66 frame[0] = 0x00;
67 frame[1] = 0x00;
68 frame[2] = static_cast<char>(0x80);
69
70 float result = CalculateMaxAmplitudeForPCM24Bit(frame, INT_1);
71 EXPECT_FLOAT_EQ(result, FLOAT_1);
72 }
73
74 /**
75 * @tc.name : Test CalculateMaxAmplitudeForPCM32Bit
76 * @tc.number: CalculateMaxAmplitudeForPCM32Bit_001
77 * @tc.desc : Test value == INT32_MIN
78 */
79 HWTEST_F(CalcMaxAmplitudeUnitTest, CalculateMaxAmplitudeForPCM32Bit_001, TestSize.Level0)
80 {
81 int32_t data[1] = {INT32_MIN};
82 float result = CalculateMaxAmplitudeForPCM32Bit(data, INT_1);
83 EXPECT_FLOAT_EQ(result, FLOAT_1);
84 }
85
86 } // namespace CalcMaxAmplitude
87 } // namespace Media
88 } // namespace OHOS