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 "audio_stream_descriptor.h" 17 #include "audio_pipe_info.h" 18 19 #include <cinttypes> 20 #include "audio_common_log.h" 21 #include "audio_utils.h" 22 #include <gtest/gtest.h> 23 24 using namespace testing::ext; 25 using namespace std; 26 27 namespace OHOS { 28 namespace AudioStandard { 29 30 static const int32_t MAX_STREAM_DESCRIPTORS_SIZE = 1003; 31 32 class AudioStreamDescriptorUnitTest : public ::testing::Test { 33 public: SetUpTestCase()34 static void SetUpTestCase(){}; TearDownTestCase()35 static void TearDownTestCase(){}; SetUp()36 virtual void SetUp(){}; TearDown()37 virtual void TearDown(){}; 38 }; 39 40 class AudioPipeInfoUnitTest : public ::testing::Test { 41 public: SetUpTestCase()42 static void SetUpTestCase(){}; TearDownTestCase()43 static void TearDownTestCase(){}; SetUp()44 virtual void SetUp(){}; TearDown()45 virtual void TearDown(){}; 46 }; 47 48 /** 49 * @tc.name : Test InitAudioStreamInfo 50 * @tc.number : InitAudioStreamInfo_001 51 * @tc.desc : Test InitAudioStreamInfo 52 */ 53 HWTEST_F(AudioPipeInfoUnitTest, InitAudioStreamInfo_001, TestSize.Level1) 54 { 55 AudioPipeInfo info; 56 info.InitAudioStreamInfo(); 57 EXPECT_EQ(info.audioStreamInfo_.format, AudioSampleFormat::INVALID_WIDTH); 58 59 info.moduleInfo_.rate = "48000"; 60 info.moduleInfo_.channels = "2"; 61 info.moduleInfo_.format = "s16"; 62 info.InitAudioStreamInfo(); 63 EXPECT_NE(info.audioStreamInfo_.format, AudioSampleFormat::INVALID_WIDTH); 64 } 65 66 /** 67 * @tc.name : Test WriteDeviceDescVectorToParcel 68 * @tc.number : WriteDeviceDescVectorToParcel_001 69 * @tc.desc : Test WriteDeviceDescVectorToParcel 70 */ 71 HWTEST_F(AudioStreamDescriptorUnitTest, WriteDeviceDescVectorToParcel_001, TestSize.Level1) 72 { 73 AudioStreamDescriptor audioStreamDescriptor; 74 Parcel parcel; 75 std::vector<std::shared_ptr<AudioDeviceDescriptor>> descs(MAX_STREAM_DESCRIPTORS_SIZE, 76 std::make_shared<AudioDeviceDescriptor>(DEVICE_TYPE_SPEAKER, OUTPUT_DEVICE)); 77 EXPECT_TRUE(audioStreamDescriptor.WriteDeviceDescVectorToParcel(parcel, descs)); 78 } 79 80 /** 81 * @tc.name : Test Dump 82 * @tc.number : Dump_001 83 * @tc.desc : Test Dump 84 */ 85 HWTEST_F(AudioStreamDescriptorUnitTest, Dump_001, TestSize.Level1) 86 { 87 AudioDeviceDescriptor audioDeviceDescriptor(DeviceType::DEVICE_TYPE_SPEAKER, DeviceRole::OUTPUT_DEVICE); 88 audioDeviceDescriptor.deviceId_ = 1; 89 audioDeviceDescriptor.deviceName_ = "BuiltinSpeaker"; 90 std::string dumpString; 91 std::string expected = " - device 1: role Output type 2 (SPEAKER) name: BuiltinSpeaker\n"; 92 audioDeviceDescriptor.Dump(dumpString); 93 EXPECT_EQ(dumpString, expected); 94 } 95 96 /** 97 * @tc.name : Test Dump 98 * @tc.number : Dump_002 99 * @tc.desc : Test Dump 100 */ 101 HWTEST_F(AudioStreamDescriptorUnitTest, Dump_002, TestSize.Level1) 102 { 103 AudioDeviceDescriptor audioDeviceDescriptor(DeviceType::DEVICE_TYPE_MIC, DeviceRole::INPUT_DEVICE); 104 audioDeviceDescriptor.deviceId_ = 2; 105 audioDeviceDescriptor.deviceName_ = "BuiltinMic"; 106 std::string dumpString; 107 std::string expected = " - device 2: role Input type 15 (MIC) name: BuiltinMic\n"; 108 audioDeviceDescriptor.Dump(dumpString); 109 EXPECT_EQ(dumpString, expected); 110 } 111 } // namespace AudioStandard 112 } // namespace OHOS