• 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 "audio_effect.h"
17 #include "audio_session_device_info.h"
18 #include "audio_policy_interface.h"
19 #include "audio_system_manager.h"
20 #include "audio_stream_descriptor.h"
21 #include "audio_zone_info.h"
22 #include "hdi_adapter_type.h"
23 #include "audio_device_info.h"
24 #include "audio_device_stream_info.h"
25 #include "oh_audio_buffer.h"
26 #include "audio_shared_memory.h"
27 #include "audio_ipc_serialization_unit_test.h"
28 
29 using namespace testing::ext;
30 namespace {
31 constexpr int32_t TEST_VALUE_1 = 10;
32 constexpr int32_t TEST_VALUE_2 = 20;
33 constexpr int32_t TEST_VALUE_3 = 30;
34 constexpr int32_t TEST_VALUE_4 = 40;
35 constexpr uint32_t TOTAL_SIZE_IN_FRAME = 882;
36 constexpr uint32_t BYTE_SIZE_PER_FRAME = 4;
37 const std::string TEST_STRING_VALUE_1 = "abc";
38 const std::string TEST_STRING_VALUE_2 = "cba";
39 const std::string TEST_STRING_VALUE_3 = "abcd";
40 const std::string TEST_STRING_VALUE_4 = "dbca";
41 }
42 
43 namespace OHOS {
44 namespace AudioStandard {
45 
SetUpTestCase(void)46 void AudioIpcSerializationUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)47 void AudioIpcSerializationUnitTest::TearDownTestCase(void) {}
SetUp(void)48 void AudioIpcSerializationUnitTest::SetUp(void) {}
TearDown(void)49 void AudioIpcSerializationUnitTest::TearDown(void) {}
50 
IsAppInfoEqual(const AppInfo & a,const AppInfo & b)51 static bool IsAppInfoEqual(const AppInfo &a, const AppInfo &b)
52 {
53     return a.appFullTokenId == b.appFullTokenId &&
54         a.appTokenId == b.appTokenId &&
55         a.appPid == b.appPid &&
56         a.appUid == b.appUid;
57 }
58 
IsStreamEffectModeEqual(const StreamEffectMode & a,const StreamEffectMode & b)59 static bool IsStreamEffectModeEqual(const StreamEffectMode &a, const StreamEffectMode &b)
60 {
61     if (a.mode != b.mode || a.devicePort.size() != b.devicePort.size()) {
62         return false;
63     }
64     for (int32_t i = 0; i < a.devicePort.size(); i++) {
65         if (a.devicePort[i].type != b.devicePort[i].type ||
66             a.devicePort[i].chain != b.devicePort[i].chain) {
67             return false;
68         }
69     }
70     return true;
71 }
72 
IsProcessNewEqual(const ProcessNew & a,const ProcessNew & b)73 static bool IsProcessNewEqual(const ProcessNew &a, const ProcessNew &b)
74 {
75     if (a.stream.size() != b.stream.size()) {
76         return false;
77     }
78     for (int32_t i = 0; i < a.stream.size(); i++) {
79         if (a.stream[i].priority != b.stream[i].priority ||
80             a.stream[i].scene != b.stream[i].scene ||
81             a.stream[i].streamEffectMode.size() != b.stream[i].streamEffectMode.size()) {
82             return false;
83         }
84         for (int32_t j = 0; j < a.stream[i].streamEffectMode.size(); j++) {
85             if (!IsStreamEffectModeEqual(a.stream[i].streamEffectMode[j], b.stream[i].streamEffectMode[j])) {
86                 return false;
87             }
88         }
89     }
90     return true;
91 }
92 
IsSceneMappingItemArrayEqual(const std::vector<SceneMappingItem> & a,const std::vector<SceneMappingItem> & b)93 static bool IsSceneMappingItemArrayEqual(const std::vector<SceneMappingItem> &a,
94     const std::vector<SceneMappingItem> &b)
95 {
96     if (a.size() != b.size()) {
97         return false;
98     }
99     for (int32_t i = 0; i < a.size(); i++) {
100         if (a[i].name != b[i].name || a[i].sceneType != b[i].sceneType) {
101             return false;
102         }
103     }
104     return true;
105 }
106 
IsAudioDeviceDescriptorEqual(const AudioDeviceDescriptor & a,const AudioDeviceDescriptor & b)107 static bool IsAudioDeviceDescriptorEqual(const AudioDeviceDescriptor &a, const AudioDeviceDescriptor &b)
108 {
109     return a.deviceType_ == b.deviceType_ &&
110         a.deviceRole_ == b.deviceRole_ &&
111         a.deviceId_ == b.deviceId_ &&
112         a.channelMasks_ == b.channelMasks_ &&
113         a.channelIndexMasks_ == b.channelIndexMasks_ &&
114         a.deviceName_ == b.deviceName_ &&
115         a.interruptGroupId_ == b.interruptGroupId_ &&
116         a.volumeGroupId_ == b.volumeGroupId_ &&
117         a.networkId_ == b.networkId_ &&
118         a.dmDeviceType_ == b.dmDeviceType_ &&
119         a.displayName_ == b.displayName_ &&
120         a.audioStreamInfo_.size() == b.audioStreamInfo_.size() &&
121         a.deviceCategory_ == b.deviceCategory_ &&
122         a.connectState_ == b.connectState_ &&
123         a.exceptionFlag_ == b.exceptionFlag_ &&
124         a.connectTimeStamp_ == b.connectTimeStamp_ &&
125         a.isScoRealConnected_ == b.isScoRealConnected_ &&
126         a.isEnable_ == b.isEnable_ &&
127         a.mediaVolume_ == b.mediaVolume_ &&
128         a.isLowLatencyDevice_ == b.isLowLatencyDevice_ &&
129         a.a2dpOffloadFlag_ == b.a2dpOffloadFlag_ &&
130         a.descriptorType_ == b.descriptorType_ &&
131         a.spatializationSupported_ == b.spatializationSupported_ &&
132         a.hasPair_ == b.hasPair_ &&
133         a.isVrSupported_ == b.isVrSupported_;
134 }
135 
IsAudioProcessConfigEqual(const AudioProcessConfig & a,const AudioProcessConfig & b)136 static bool IsAudioProcessConfigEqual(const AudioProcessConfig &a, const AudioProcessConfig &b)
137 {
138     return a.appInfo.appUid == b.appInfo.appUid &&
139         a.appInfo.appTokenId == b.appInfo.appTokenId &&
140         a.appInfo.appPid == b.appInfo.appPid &&
141         a.appInfo.appFullTokenId == b.appInfo.appFullTokenId &&
142         a.streamInfo.samplingRate == b.streamInfo.samplingRate &&
143         a.streamInfo.encoding == b.streamInfo.encoding &&
144         a.streamInfo.format == b.streamInfo.format &&
145         a.streamInfo.channels == b.streamInfo.channels &&
146         a.streamInfo.channelLayout == b.streamInfo.channelLayout &&
147         a.audioMode == b.audioMode &&
148         a.rendererInfo.contentType == b.rendererInfo.contentType &&
149         a.rendererInfo.streamUsage == b.rendererInfo.streamUsage &&
150         a.rendererInfo.rendererFlags == b.rendererInfo.rendererFlags &&
151         a.rendererInfo.originalFlag == b.rendererInfo.originalFlag &&
152         a.rendererInfo.sceneType == b.rendererInfo.sceneType &&
153         a.rendererInfo.spatializationEnabled == b.rendererInfo.spatializationEnabled &&
154         a.rendererInfo.headTrackingEnabled == b.rendererInfo.headTrackingEnabled &&
155         a.rendererInfo.isSatellite == b.rendererInfo.isSatellite &&
156         a.rendererInfo.pipeType == b.rendererInfo.pipeType &&
157         a.rendererInfo.playerType == b.rendererInfo.playerType &&
158         a.rendererInfo.expectedPlaybackDurationBytes == b.rendererInfo.expectedPlaybackDurationBytes &&
159         a.rendererInfo.effectMode == b.rendererInfo.effectMode &&
160         a.rendererInfo.isLoopback == b.rendererInfo.isLoopback &&
161         a.rendererInfo.loopbackMode == b.rendererInfo.loopbackMode &&
162         a.rendererInfo.isVirtualKeyboard == b.rendererInfo.isVirtualKeyboard &&
163         a.privacyType == b.privacyType &&
164         a.capturerInfo.sourceType == b.capturerInfo.sourceType &&
165         a.capturerInfo.capturerFlags == b.capturerInfo.capturerFlags &&
166         a.capturerInfo.originalFlag == b.capturerInfo.originalFlag &&
167         a.capturerInfo.pipeType == b.capturerInfo.pipeType &&
168         a.capturerInfo.recorderType == b.capturerInfo.recorderType &&
169         a.capturerInfo.isLoopback == b.capturerInfo.isLoopback &&
170         a.capturerInfo.loopbackMode == b.capturerInfo.loopbackMode &&
171         a.streamType == b.streamType &&
172         a.deviceType == b.deviceType &&
173         a.isInnerCapturer == b.isInnerCapturer &&
174         a.isWakeupCapturer == b.isWakeupCapturer &&
175         a.originalSessionId == b.originalSessionId &&
176         a.innerCapId == b.innerCapId;
177 }
178 
InitAudioStreamInfo(AudioStreamInfo & info)179 void InitAudioStreamInfo(AudioStreamInfo &info)
180 {
181     info.samplingRate = SAMPLE_RATE_44100;
182     info.encoding = ENCODING_EAC3;
183     info.format = SAMPLE_F32LE;
184     info.channels = STEREO;
185     info.channelLayout = CH_LAYOUT_MONO;
186 }
187 
InitAudioRendererInfo(AudioRendererInfo & info)188 void InitAudioRendererInfo(AudioRendererInfo &info)
189 {
190     info.contentType = CONTENT_TYPE_SPEECH;
191     info.streamUsage = STREAM_USAGE_SYSTEM;
192     info.rendererFlags = TEST_VALUE_1;
193     info.originalFlag = TEST_VALUE_2;
194     info.sceneType = TEST_STRING_VALUE_1;
195     info.spatializationEnabled = true;
196     info.headTrackingEnabled = false;
197     info.pipeType = PIPE_TYPE_DIRECT_OUT;
198     info.samplingRate = SAMPLE_RATE_44100;
199     info.encodingType = TEST_VALUE_1;
200     info.channelLayout = TEST_VALUE_3;
201     info.format = SAMPLE_S32LE;
202     info.isOffloadAllowed = true;
203     info.playerType = PLAYER_TYPE_OPENSL_ES;
204     info.expectedPlaybackDurationBytes = TEST_VALUE_4;
205     info.effectMode = TEST_VALUE_1;
206     info.volumeMode = AUDIOSTREAM_VOLUMEMODE_APP_INDIVIDUAL;
207     info.isLoopback = true;
208     info.loopbackMode = LOOPBACK_HARDWARE;
209     info.isVirtualKeyboard = true;
210     info.audioFlag = TEST_VALUE_3;
211 }
212 
InitAudioCapturerInfo(AudioCapturerInfo & info)213 void InitAudioCapturerInfo(AudioCapturerInfo &info)
214 {
215     info.sceneType = SOURCE_TYPE_WAKEUP;
216     info.capturerFlags = TEST_VALUE_1;
217     info.originalFlag = TEST_VALUE_2;
218     info.pipeType = PIPE_TYPE_DIRECT_OUT;
219     info.samplingRate = SAMPLE_RATE_44100;
220     info.encodingType = TEST_VALUE_1;
221     info.channelLayout = TEST_VALUE_2;
222     info.sceneType = TEST_STRING_VALUE_1;
223     info.recorderType = RECORDER_TYPE_OPENSL_ES;
224     info.isLoopback = true;
225     info.loopbackMode = LOOPBACK_HARDWARE;
226 }
227 
228 /**
229  * @tc.name  : Test AudioStreamDescriptor.
230  * @tc.number: AudioStreamDescriptor_001
231  * @tc.desc  : Test AudioStreamDescriptor Serialization.
232  */
233 HWTEST(AudioIpcSerializationUnitTest, AudioStreamDescriptor_001, TestSize.Level1)
234 {
235     Parcel parcel;
236     auto device = std::make_shared<AudioDeviceDescriptor>();
237     EXPECT_NE(device, nullptr);
238     AudioStreamDescriptor descriptor = {};
239     descriptor.streamInfo_.samplingRate = SAMPLE_RATE_11025;
240     descriptor.audioMode_ = AUDIO_MODE_RECORD;
241     descriptor.audioFlag_ = AUDIO_OUTPUT_FLAG_HWDECODING;
242     descriptor.routeFlag_ = AUDIO_INPUT_FLAG_NORMAL;
243     descriptor.startTimeStamp_ = TEST_VALUE_1;
244     descriptor.rendererInfo_.streamUsage = STREAM_USAGE_MUSIC;
245     descriptor.capturerInfo_.sourceType = SOURCE_TYPE_REMOTE_CAST;
246     descriptor.appInfo_ = { TEST_VALUE_1, TEST_VALUE_2, TEST_VALUE_3, TEST_VALUE_4 };
247     descriptor.sessionId_ = TEST_VALUE_1;
248     descriptor.callerUid_ = TEST_VALUE_2;
249     descriptor.callerPid_ = TEST_VALUE_3;
250     descriptor.streamAction_ = AUDIO_STREAM_ACTION_MOVE;
251     descriptor.oldDeviceDescs_.push_back(device);
252     descriptor.newDeviceDescs_.push_back(device);
253     descriptor.newDeviceDescs_.push_back(device);
254 
255     EXPECT_TRUE(descriptor.Marshalling(parcel));
256     auto newDescriptor = std::shared_ptr<AudioStreamDescriptor>(AudioStreamDescriptor::Unmarshalling(parcel));
257     ASSERT_NE(newDescriptor, nullptr);
258 
259     EXPECT_EQ(newDescriptor->streamInfo_.samplingRate, descriptor.streamInfo_.samplingRate);
260     EXPECT_EQ(newDescriptor->audioMode_, descriptor.audioMode_);
261     EXPECT_EQ(newDescriptor->audioFlag_, descriptor.audioFlag_);
262     EXPECT_EQ(newDescriptor->routeFlag_, descriptor.routeFlag_);
263     EXPECT_EQ(newDescriptor->startTimeStamp_, descriptor.startTimeStamp_);
264     EXPECT_EQ(newDescriptor->rendererInfo_.streamUsage, descriptor.rendererInfo_.streamUsage);
265     EXPECT_EQ(newDescriptor->capturerInfo_.sourceType, descriptor.capturerInfo_.sourceType);
266     EXPECT_TRUE(IsAppInfoEqual(newDescriptor->appInfo_, descriptor.appInfo_));
267     EXPECT_EQ(newDescriptor->sessionId_, descriptor.sessionId_);
268     EXPECT_EQ(newDescriptor->callerUid_, descriptor.callerUid_);
269     EXPECT_EQ(newDescriptor->callerPid_, descriptor.callerPid_);
270     EXPECT_EQ(newDescriptor->streamAction_, descriptor.streamAction_);
271     EXPECT_EQ(newDescriptor->oldDeviceDescs_.size(), descriptor.oldDeviceDescs_.size());
272     EXPECT_EQ(newDescriptor->newDeviceDescs_.size(), descriptor.newDeviceDescs_.size());
273 }
274 
275 /**
276  * @tc.name  : Test AudioZoneContext.
277  * @tc.number: AudioZoneContext_001
278  * @tc.desc  : Test AudioZoneContext Serialization.
279  */
280 HWTEST(AudioIpcSerializationUnitTest, AudioZoneContext_001, TestSize.Level1)
281 {
282     Parcel parcel;
283     AudioZoneContext context = {};
284     context.focusStrategy_ = AudioZoneFocusStrategy::DISTRIBUTED_FOCUS_STRATEGY;
285 
286     EXPECT_TRUE(context.Marshalling(parcel));
287     auto newContext = std::shared_ptr<AudioZoneContext>(AudioZoneContext::Unmarshalling(parcel));
288     ASSERT_NE(newContext, nullptr);
289     EXPECT_TRUE(newContext->focusStrategy_ == context.focusStrategy_);
290 }
291 
292 /**
293  * @tc.name  : Test AudioZoneDescriptor.
294  * @tc.number: AudioZoneDescriptor_001
295  * @tc.desc  : Test AudioZoneDescriptor Serialization.
296  */
297 HWTEST(AudioIpcSerializationUnitTest, AudioZoneDescriptor_001, TestSize.Level1)
298 {
299     Parcel parcel;
300     auto device = std::make_shared<AudioDeviceDescriptor>();
301     EXPECT_NE(device, nullptr);
302     AudioZoneDescriptor descriptor = {};
303     descriptor.zoneId_ = TEST_VALUE_1;
304     descriptor.name_ = TEST_STRING_VALUE_1;
305     descriptor.uids_ = {TEST_VALUE_1, TEST_VALUE_2};
306     descriptor.devices_.push_back(device);
307 
308     EXPECT_TRUE(descriptor.Marshalling(parcel));
309     auto newDescriptor = std::shared_ptr<AudioZoneDescriptor>(AudioZoneDescriptor::Unmarshalling(parcel));
310     ASSERT_NE(newDescriptor, nullptr);
311     EXPECT_TRUE(newDescriptor->zoneId_ == descriptor.zoneId_);
312     EXPECT_TRUE(newDescriptor->name_ == descriptor.name_);
313     EXPECT_TRUE(newDescriptor->uids_ == descriptor.uids_);
314     EXPECT_TRUE(newDescriptor->devices_.size() == descriptor.devices_.size());
315 }
316 
317 /**
318  * @tc.name  : Test AudioZoneStream.
319  * @tc.number: AudioZoneStream_001
320  * @tc.desc  : Test AudioZoneStream Serialization.
321  */
322 HWTEST(AudioIpcSerializationUnitTest, AudioZoneStream_001, TestSize.Level1)
323 {
324     Parcel parcel;
325     AudioZoneStream stream = {};
326     stream.streamUsage = STREAM_USAGE_VOICE_COMMUNICATION;
327     stream.sourceType = SOURCE_TYPE_CAMCORDER;
328     stream.isPlay = true;
329 
330     EXPECT_TRUE(stream.Marshalling(parcel));
331     auto newStream = std::shared_ptr<AudioZoneStream>(AudioZoneStream::Unmarshalling(parcel));
332     ASSERT_NE(newStream, nullptr);
333     EXPECT_TRUE((*newStream) == stream);
334 }
335 
336 /**
337  * @tc.name  : Test IAudioSinkAttr.
338  * @tc.number: IAudioSinkAttr_001
339  * @tc.desc  : Test IAudioSinkAttr Serialization.
340  */
341 HWTEST(AudioIpcSerializationUnitTest, IAudioSinkAttr_001, TestSize.Level1)
342 {
343     Parcel parcel;
344     IAudioSinkAttr attr = {};
345     attr.adapterName = TEST_STRING_VALUE_1;
346     attr.openMicSpeaker = TEST_VALUE_1;
347     attr.format = static_cast<AudioSampleFormat>(TEST_VALUE_2);
348     attr.sampleRate = TEST_VALUE_3;
349     attr.channel = TEST_VALUE_4;
350     attr.volume = TEST_VALUE_1;
351     attr.filePath = TEST_STRING_VALUE_1;
352     attr.deviceNetworkId = TEST_STRING_VALUE_2;
353     attr.deviceType = TEST_VALUE_2;
354     attr.channelLayout = TEST_VALUE_3;
355     attr.audioStreamFlag = TEST_VALUE_4;
356     attr.address = TEST_STRING_VALUE_1;
357     attr.aux = TEST_STRING_VALUE_2;
358 
359 
360     EXPECT_TRUE(attr.Marshalling(parcel));
361     auto newAttr = std::shared_ptr<IAudioSinkAttr>(IAudioSinkAttr::Unmarshalling(parcel));
362     ASSERT_NE(newAttr, nullptr);
363     EXPECT_TRUE(newAttr->adapterName == attr.adapterName);
364     EXPECT_TRUE(newAttr->openMicSpeaker == attr.openMicSpeaker);
365     EXPECT_TRUE(newAttr->format == attr.format);
366     EXPECT_TRUE(newAttr->sampleRate == attr.sampleRate);
367     EXPECT_TRUE(newAttr->channel == attr.channel);
368     EXPECT_TRUE(newAttr->volume == attr.volume);
369     EXPECT_TRUE(newAttr->filePath == attr.filePath);
370     EXPECT_TRUE(newAttr->deviceNetworkId == attr.deviceNetworkId);
371     EXPECT_TRUE(newAttr->deviceType == attr.deviceType);
372     EXPECT_TRUE(newAttr->channelLayout == attr.channelLayout);
373     EXPECT_TRUE(newAttr->audioStreamFlag == attr.audioStreamFlag);
374     EXPECT_TRUE(newAttr->address == attr.address);
375     EXPECT_TRUE(newAttr->aux == attr.aux);
376 }
377 
378 /**
379  * @tc.name  : Test IAudioSourceAttr.
380  * @tc.number: IAudioSourceAttr_001
381  * @tc.desc  : Test IAudioSourceAttr Serialization.
382  */
383 HWTEST(AudioIpcSerializationUnitTest, IAudioSourceAttr_001, TestSize.Level1)
384 {
385     Parcel parcel;
386     IAudioSourceAttr attr = {};
387     attr.adapterName = TEST_STRING_VALUE_1;
388     attr.openMicSpeaker = TEST_VALUE_1;
389     attr.format = static_cast<AudioSampleFormat>(TEST_VALUE_2);
390     attr.sampleRate = TEST_VALUE_3;
391     attr.channel = TEST_VALUE_4;
392     attr.volume = TEST_VALUE_1;
393     attr.bufferSize = TEST_VALUE_2;
394     attr.isBigEndian = true;
395     attr.filePath = TEST_STRING_VALUE_1;
396     attr.deviceNetworkId = TEST_STRING_VALUE_2;
397     attr.deviceType = TEST_VALUE_2;
398     attr.sourceType = TEST_VALUE_1;
399     attr.channelLayout = TEST_VALUE_3;
400     attr.audioStreamFlag = TEST_VALUE_4;
401     attr.hasEcConfig = false;
402     attr.formatEc = static_cast<AudioSampleFormat>(TEST_VALUE_2);;
403     attr.sampleRateEc = TEST_VALUE_4;
404     attr.channelEc = TEST_VALUE_1;
405 
406     EXPECT_TRUE(attr.Marshalling(parcel));
407     auto newAttr = std::shared_ptr<IAudioSourceAttr>(IAudioSourceAttr::Unmarshalling(parcel));
408     ASSERT_NE(newAttr, nullptr);
409     EXPECT_TRUE(newAttr->adapterName == attr.adapterName);
410     EXPECT_TRUE(newAttr->openMicSpeaker == attr.openMicSpeaker);
411     EXPECT_TRUE(newAttr->format == attr.format);
412     EXPECT_TRUE(newAttr->sampleRate == attr.sampleRate);
413     EXPECT_TRUE(newAttr->channel == attr.channel);
414     EXPECT_TRUE(newAttr->volume == attr.volume);
415     EXPECT_TRUE(newAttr->bufferSize == attr.bufferSize);
416     EXPECT_TRUE(newAttr->isBigEndian == attr.isBigEndian);
417     EXPECT_TRUE(newAttr->filePath == attr.filePath);
418     EXPECT_TRUE(newAttr->deviceNetworkId == attr.deviceNetworkId);
419     EXPECT_TRUE(newAttr->deviceType == attr.deviceType);
420     EXPECT_TRUE(newAttr->sourceType == attr.sourceType);
421     EXPECT_TRUE(newAttr->channelLayout == attr.channelLayout);
422     EXPECT_TRUE(newAttr->audioStreamFlag == attr.audioStreamFlag);
423     EXPECT_TRUE(newAttr->hasEcConfig == attr.hasEcConfig);
424     EXPECT_TRUE(newAttr->formatEc == attr.formatEc);
425     EXPECT_TRUE(newAttr->sampleRateEc == attr.sampleRateEc);
426     EXPECT_TRUE(newAttr->channelEc == attr.channelEc);
427 }
428 
429 /**
430  * @tc.name  : Test DeviceStreamInfo.
431  * @tc.number: DeviceStreamInfo_001
432  * @tc.desc  : Test DeviceStreamInfo Serialization.
433  */
434 HWTEST(AudioIpcSerializationUnitTest, DeviceStreamInfo_001, TestSize.Level1)
435 {
436     Parcel parcel;
437     DeviceStreamInfo info = {};
438     info.encoding = AudioEncodingType::ENCODING_EAC3;
439     info.format = AudioSampleFormat::SAMPLE_S16LE;
440     info.channelLayout = { CH_LAYOUT_MONO, CH_LAYOUT_STEREO };
441     info.samplingRate = { SAMPLE_RATE_44100, SAMPLE_RATE_64000 };
442 
443     EXPECT_TRUE(info.Marshalling(parcel));
444     DeviceStreamInfo newInfo = {};
445     newInfo.Unmarshalling(parcel);
446     EXPECT_TRUE(info == newInfo);
447 }
448 
449 /**
450  * @tc.name  : Test AudioDeviceDescriptor.
451  * @tc.number: AudioDeviceDescriptor_001
452  * @tc.desc  : Test AudioDeviceDescriptor Serialization.
453  */
454 HWTEST(AudioIpcSerializationUnitTest, AudioDeviceDescriptor_001, TestSize.Level1)
455 {
456     Parcel parcel;
457     AudioDeviceDescriptor descriptor = {};
458     descriptor.deviceType_ = DEVICE_TYPE_EARPIECE;
459     descriptor.deviceRole_ = DEVICE_ROLE_MAX;
460     descriptor.deviceId_ = TEST_VALUE_1;
461     descriptor.channelMasks_ = TEST_VALUE_2;
462     descriptor.channelIndexMasks_ = TEST_VALUE_3;
463     descriptor.deviceName_ = TEST_STRING_VALUE_1;
464     descriptor.macAddress_ = TEST_STRING_VALUE_2;
465     descriptor.interruptGroupId_ = TEST_VALUE_1;
466     descriptor.volumeGroupId_ = TEST_VALUE_2;
467     descriptor.networkId_ = TEST_STRING_VALUE_1;
468     descriptor.dmDeviceType_ = TEST_VALUE_1;
469     descriptor.displayName_ = TEST_STRING_VALUE_2;
470     DeviceStreamInfo info = {};
471     descriptor.audioStreamInfo_.assign(TEST_VALUE_1, info);
472     descriptor.deviceCategory_ = BT_HEARAID;
473     descriptor.connectState_ = VIRTUAL_CONNECTED;
474     // AudioDeviceDescriptor
475     descriptor.exceptionFlag_ = false;
476     descriptor.connectTimeStamp_ = TEST_VALUE_1;
477     descriptor.isScoRealConnected_ = true;
478     descriptor.isEnable_ = false;
479     descriptor.mediaVolume_ = TEST_VALUE_2;
480     descriptor.callVolume_ = TEST_VALUE_3;
481     // DeviceInfo
482     descriptor.isLowLatencyDevice_ = true;
483     descriptor.a2dpOffloadFlag_ = TEST_VALUE_4;
484     // Other
485     descriptor.descriptorType_ = AudioDeviceDescriptor::DEVICE_INFO;
486     descriptor.spatializationSupported_ = true;
487     descriptor.hasPair_ = false;
488     descriptor.routerType_ = ROUTER_TYPE_COCKPIT_PHONE;
489     descriptor.isVrSupported_ = true;
490 
491     EXPECT_TRUE(descriptor.Marshalling(parcel));
492     auto newDescriptor = std::shared_ptr<AudioDeviceDescriptor>(AudioDeviceDescriptor::Unmarshalling(parcel));
493     ASSERT_NE(newDescriptor, nullptr);
494     EXPECT_TRUE(IsAudioDeviceDescriptorEqual(*newDescriptor, descriptor));
495 }
496 
497 /**
498  * @tc.name  : Test AudioStreamDeviceChangeReasonExt.
499  * @tc.number: AudioStreamDeviceChangeReasonExt_001
500  * @tc.desc  : Test AudioStreamDeviceChangeReasonExt Serialization.
501  */
502 HWTEST(AudioIpcSerializationUnitTest, AudioStreamDeviceChangeReasonExt_001, TestSize.Level1)
503 {
504     Parcel parcel;
505     AudioStreamDeviceChangeReasonExt reason = {};
506     reason.reason_ = AudioStreamDeviceChangeReasonExt::ExtEnum::OLD_DEVICE_UNAVALIABLE_EXT;
507 
508     EXPECT_TRUE(reason.Marshalling(parcel));
509     auto newReason = std::shared_ptr<AudioStreamDeviceChangeReasonExt>(
510         AudioStreamDeviceChangeReasonExt::Unmarshalling(parcel));
511     ASSERT_NE(newReason, nullptr);
512     EXPECT_TRUE(newReason->reason_ == reason.reason_);
513 }
514 
515 /**
516  * @tc.name  : Test AudioSpatialDeviceState.
517  * @tc.number: AudioSpatialDeviceState_001
518  * @tc.desc  : Test AudioSpatialDeviceState Serialization.
519  */
520 HWTEST(AudioIpcSerializationUnitTest, AudioSpatialDeviceState_001, TestSize.Level1)
521 {
522     Parcel parcel;
523     AudioSpatialDeviceState deviceState = {};
524     deviceState.address = TEST_STRING_VALUE_1;
525     deviceState.isSpatializationSupported = true;
526     deviceState.isHeadTrackingSupported = false;
527     deviceState.spatialDeviceType = EARPHONE_TYPE_GLASSES;
528 
529     EXPECT_TRUE(deviceState.Marshalling(parcel));
530     auto newDeviceState = std::shared_ptr<AudioSpatialDeviceState>(AudioSpatialDeviceState::Unmarshalling(parcel));
531     ASSERT_NE(newDeviceState, nullptr);
532     EXPECT_TRUE(newDeviceState->address == deviceState.address);
533     EXPECT_TRUE(newDeviceState->isSpatializationSupported == deviceState.isSpatializationSupported);
534     EXPECT_TRUE(newDeviceState->isHeadTrackingSupported == deviceState.isHeadTrackingSupported);
535     EXPECT_TRUE(newDeviceState->spatialDeviceType == deviceState.spatialDeviceType);
536 }
537 
538 /**
539  * @tc.name  : Test Library.
540  * @tc.number: Library_001
541  * @tc.desc  : Test Library Serialization.
542  */
543 HWTEST(AudioIpcSerializationUnitTest, Library_001, TestSize.Level1)
544 {
545     Parcel parcel;
546     Library library = {};
547     library.name = TEST_STRING_VALUE_1;
548     library.path = TEST_STRING_VALUE_2;
549 
550     EXPECT_TRUE(library.Marshalling(parcel));
551     auto newLibrary = std::shared_ptr<Library>(Library::Unmarshalling(parcel));
552     ASSERT_NE(newLibrary, nullptr);
553     EXPECT_TRUE(newLibrary->name == library.name);
554     EXPECT_TRUE(newLibrary->path == library.path);
555 }
556 
557 /**
558  * @tc.name  : Test Effect.
559  * @tc.number: Effect_001
560  * @tc.desc  : Test Effect Serialization.
561  */
562 HWTEST(AudioIpcSerializationUnitTest, Effect_001, TestSize.Level1)
563 {
564     Parcel parcel;
565     Effect effect = {};
566     effect.name = TEST_STRING_VALUE_1;
567     effect.libraryName = TEST_STRING_VALUE_2;
568     effect.effectProperty = { TEST_STRING_VALUE_3, TEST_STRING_VALUE_4 };
569 
570     EXPECT_TRUE(effect.Marshalling(parcel));
571     auto newEffect = std::shared_ptr<Effect>(Effect::Unmarshalling(parcel));
572     ASSERT_NE(newEffect, nullptr);
573     EXPECT_TRUE(newEffect->name == effect.name);
574     EXPECT_TRUE(newEffect->libraryName == effect.libraryName);
575     EXPECT_TRUE(newEffect->effectProperty == effect.effectProperty);
576 }
577 
578 /**
579  * @tc.name  : Test Effect.
580  * @tc.number: Effect_002
581  * @tc.desc  : Test Effect Deserialization.
582  */
583 HWTEST(AudioIpcSerializationUnitTest, Effect_002, TestSize.Level1)
584 {
585     Parcel parcel;
586     Effect effect = {};
587     effect.effectProperty.assign(Effect::MAX_EFFECT_PROPERTY_SIZE + 1, TEST_STRING_VALUE_1);
588     EXPECT_TRUE(effect.Marshalling(parcel));
589     auto newEffect = std::shared_ptr<Effect>(Effect::Unmarshalling(parcel));
590     EXPECT_EQ(newEffect, nullptr);
591 }
592 
593 /**
594  * @tc.name  : Test EffectChain.
595  * @tc.number: EffectChain_001
596  * @tc.desc  : Test EffectChain Serialization.
597  */
598 HWTEST(AudioIpcSerializationUnitTest, EffectChain_001, TestSize.Level1)
599 {
600     Parcel parcel;
601     EffectChain effectChain = {};
602     effectChain.name = TEST_STRING_VALUE_1;
603     effectChain.apply = { TEST_STRING_VALUE_2, TEST_STRING_VALUE_3 };
604     effectChain.label = TEST_STRING_VALUE_4;
605 
606     EXPECT_TRUE(effectChain.Marshalling(parcel));
607     auto newEffectChain = std::shared_ptr<EffectChain>(EffectChain::Unmarshalling(parcel));
608     ASSERT_NE(newEffectChain, nullptr);
609     EXPECT_TRUE(newEffectChain->name == effectChain.name);
610     EXPECT_TRUE(newEffectChain->apply == effectChain.apply);
611     EXPECT_TRUE(newEffectChain->label == effectChain.label);
612 }
613 
614 /**
615  * @tc.name  : Test EffectChainManagerParam.
616  * @tc.number: EffectChainManagerParam_001
617  * @tc.desc  : Test EffectChainManagerParam Serialization.
618  */
619 HWTEST(AudioIpcSerializationUnitTest, EffectChainManagerParam_001, TestSize.Level1)
620 {
621     Parcel parcel;
622     EffectChainManagerParam param = {};
623     param.maxExtraNum = TEST_VALUE_1;
624     param.defaultSceneName = TEST_STRING_VALUE_1;
625     param.priorSceneList = { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2 };
626     param.sceneTypeToChainNameMap = {
627         {TEST_STRING_VALUE_3, TEST_STRING_VALUE_3},
628         {TEST_STRING_VALUE_4, TEST_STRING_VALUE_4}};
629     param.effectDefaultProperty = {
630         {TEST_STRING_VALUE_1, TEST_STRING_VALUE_1},
631         {TEST_STRING_VALUE_2, TEST_STRING_VALUE_2}};
632 
633     EXPECT_TRUE(param.Marshalling(parcel));
634     auto newParam = std::shared_ptr<EffectChainManagerParam>(EffectChainManagerParam::Unmarshalling(parcel));
635     ASSERT_NE(newParam, nullptr);
636     EXPECT_TRUE(newParam->maxExtraNum == param.maxExtraNum);
637     EXPECT_TRUE(newParam->defaultSceneName == param.defaultSceneName);
638     EXPECT_TRUE(newParam->priorSceneList == param.priorSceneList);
639     EXPECT_TRUE(newParam->sceneTypeToChainNameMap == param.sceneTypeToChainNameMap);
640     EXPECT_TRUE(newParam->effectDefaultProperty == param.effectDefaultProperty);
641 }
642 
643 /**
644  * @tc.name  : Test EffectChainManagerParam.
645  * @tc.number: EffectChainManagerParam_002
646  * @tc.desc  : Test EffectChainManagerParam Deserialization.
647  */
648 HWTEST(AudioIpcSerializationUnitTest, EffectChainManagerParam_002, TestSize.Level1)
649 {
650     Parcel parcel;
651     EffectChainManagerParam param = {};
652     param.priorSceneList.assign(AUDIO_EFFECT_PRIOR_SCENE_UPPER_LIMIT + 1, TEST_STRING_VALUE_1);
653     EXPECT_TRUE(param.Marshalling(parcel));
654     auto newParam = std::shared_ptr<EffectChainManagerParam>(EffectChainManagerParam::Unmarshalling(parcel));
655     EXPECT_EQ(newParam, nullptr);
656 }
657 
658 /**
659  * @tc.name  : Test EffectChainManagerParam.
660  * @tc.number: EffectChainManagerParam_003
661  * @tc.desc  : Test EffectChainManagerParam Deserialization.
662  */
663 HWTEST(AudioIpcSerializationUnitTest, EffectChainManagerParam_003, TestSize.Level1)
664 {
665     Parcel parcel;
666     EffectChainManagerParam param = {};
667     for (int i = 0; i <= AUDIO_EFFECT_CHAIN_CONFIG_UPPER_LIMIT; i++) {
668         param.sceneTypeToChainNameMap[std::to_string(i)] = TEST_STRING_VALUE_1;
669     }
670     EXPECT_TRUE(param.Marshalling(parcel));
671     auto newParam = std::shared_ptr<EffectChainManagerParam>(EffectChainManagerParam::Unmarshalling(parcel));
672     EXPECT_EQ(newParam, nullptr);
673 }
674 
675 /**
676  * @tc.name  : Test EffectChainManagerParam.
677  * @tc.number: EffectChainManagerParam_004
678  * @tc.desc  : Test EffectChainManagerParam Deserialization.
679  */
680 HWTEST(AudioIpcSerializationUnitTest, EffectChainManagerParam_004, TestSize.Level1)
681 {
682     Parcel parcel;
683     EffectChainManagerParam param = {};
684     for (int i = 0; i <= AUDIO_EFFECT_COUNT_PROPERTY_UPPER_LIMIT; i++) {
685         param.effectDefaultProperty[std::to_string(i)] = TEST_STRING_VALUE_1;
686     }
687     EXPECT_TRUE(param.Marshalling(parcel));
688     auto newParam = std::shared_ptr<EffectChainManagerParam>(EffectChainManagerParam::Unmarshalling(parcel));
689     EXPECT_EQ(newParam, nullptr);
690 }
691 
692 /**
693  * @tc.name  : Test SupportedEffectConfig.
694  * @tc.number: SupportedEffectConfig_001
695  * @tc.desc  : Test SupportedEffectConfig Serialization.
696  */
697 HWTEST(AudioIpcSerializationUnitTest, SupportedEffectConfig_001, TestSize.Level1)
698 {
699     Parcel parcel;
700     SupportedEffectConfig config = {};
701     Device device1 = { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2 };
702     Device device2 = { TEST_STRING_VALUE_2, TEST_STRING_VALUE_3 };
703     StreamEffectMode mode1 = { TEST_STRING_VALUE_3, { device1 } };
704     StreamEffectMode mode2 = { TEST_STRING_VALUE_4, { device2 } };
705     Stream stream1 = { PRIOR_SCENE, TEST_STRING_VALUE_1, { mode1 } };
706     Stream stream2 = { NORMAL_SCENE, TEST_STRING_VALUE_2, { mode2 } };
707     config.preProcessNew.stream = { stream1 };
708     config.postProcessNew.stream = { stream2, stream2 };
709     config.postProcessSceneMap = { { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2 },
710         { TEST_STRING_VALUE_2, TEST_STRING_VALUE_3 } };
711 
712     EXPECT_TRUE(config.Marshalling(parcel));
713     auto newConfig = std::shared_ptr<SupportedEffectConfig>(SupportedEffectConfig::Unmarshalling(parcel));
714     ASSERT_NE(newConfig, nullptr);
715     EXPECT_TRUE(IsProcessNewEqual(newConfig->preProcessNew, config.preProcessNew));
716     EXPECT_TRUE(IsProcessNewEqual(newConfig->postProcessNew, config.postProcessNew));
717     EXPECT_TRUE(IsSceneMappingItemArrayEqual(newConfig->postProcessSceneMap, config.postProcessSceneMap));
718 }
719 
720 /**
721  * @tc.name  : Test SupportedEffectConfig.
722  * @tc.number: SupportedEffectConfig_002
723  * @tc.desc  : Test SupportedEffectConfig Deserialization.
724  */
725 HWTEST(AudioIpcSerializationUnitTest, SupportedEffectConfig_002, TestSize.Level1)
726 {
727     Parcel parcel;
728     SupportedEffectConfig config = {};
729     Stream stream = {};
730     config.preProcessNew.stream.assign(AUDIO_EFFECT_COUNT_UPPER_LIMIT + 1, stream);
731     EXPECT_TRUE(config.Marshalling(parcel));
732     auto newConfig = std::shared_ptr<SupportedEffectConfig>(SupportedEffectConfig::Unmarshalling(parcel));
733     EXPECT_EQ(newConfig, nullptr);
734 }
735 
736 /**
737  * @tc.name  : Test SupportedEffectConfig.
738  * @tc.number: SupportedEffectConfig_003
739  * @tc.desc  : Test SupportedEffectConfig Deserialization.
740  */
741 HWTEST(AudioIpcSerializationUnitTest, SupportedEffectConfig_003, TestSize.Level1)
742 {
743     Parcel parcel;
744     SupportedEffectConfig config = {};
745     Stream stream = {};
746     config.postProcessNew.stream.assign(AUDIO_EFFECT_COUNT_UPPER_LIMIT + 1, stream);
747     EXPECT_TRUE(config.Marshalling(parcel));
748     auto newConfig = std::shared_ptr<SupportedEffectConfig>(SupportedEffectConfig::Unmarshalling(parcel));
749     EXPECT_EQ(newConfig, nullptr);
750 }
751 
752 /**
753  * @tc.name  : Test SupportedEffectConfig.
754  * @tc.number: SupportedEffectConfig_004
755  * @tc.desc  : Test SupportedEffectConfig Deserialization.
756  */
757 HWTEST(AudioIpcSerializationUnitTest, SupportedEffectConfig_004, TestSize.Level1)
758 {
759     Parcel parcel;
760     SupportedEffectConfig config = {};
761     SceneMappingItem item = {};
762     config.postProcessSceneMap.assign(SupportedEffectConfig::POST_PROCESS_SCENE_MAP_MAX_SIZE + 1, item);
763     EXPECT_TRUE(config.Marshalling(parcel));
764     auto newConfig = std::shared_ptr<SupportedEffectConfig>(SupportedEffectConfig::Unmarshalling(parcel));
765     EXPECT_EQ(newConfig, nullptr);
766 }
767 
768 /**
769  * @tc.name  : Test AudioEffectPropertyArrayV3.
770  * @tc.number: AudioEffectPropertyArrayV3_001
771  * @tc.desc  : Test AudioEffectPropertyArrayV3 Serialization.
772  */
773 HWTEST(AudioIpcSerializationUnitTest, AudioEffectPropertyArrayV3_001, TestSize.Level1)
774 {
775     Parcel parcel;
776     AudioEffectPropertyArrayV3 propertyArray = {};
777     AudioEffectPropertyV3 property = { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2, CAPTURE_EFFECT_FLAG };
778     propertyArray.property.push_back(property);
779 
780     EXPECT_TRUE(propertyArray.Marshalling(parcel));
781     auto newPropertyArray = std::shared_ptr<AudioEffectPropertyArrayV3>(
782         AudioEffectPropertyArrayV3::Unmarshalling(parcel));
783     ASSERT_NE(newPropertyArray, nullptr);
784     EXPECT_EQ(newPropertyArray->property.size(), propertyArray.property.size());
785     if (newPropertyArray->property.size() == propertyArray.property.size()) {
786         for (int32_t i = 0; i < propertyArray.property.size(); i++) {
787             EXPECT_EQ(newPropertyArray->property[i], propertyArray.property[i]);
788         }
789     }
790 }
791 
792 /**
793  * @tc.name  : Test AudioEffectPropertyArrayV3.
794  * @tc.number: AudioEffectPropertyArrayV3_002
795  * @tc.desc  : Test AudioEffectPropertyArrayV3 Deserialization.
796  */
797 HWTEST(AudioIpcSerializationUnitTest, AudioEffectPropertyArrayV3_002, TestSize.Level1)
798 {
799     Parcel parcel;
800     AudioEffectPropertyArrayV3 propertyArray = {};
801     AudioEffectPropertyV3 property = {};
802 
803     propertyArray.property.assign(AUDIO_EFFECT_COUNT_UPPER_LIMIT + 1, property);
804     EXPECT_TRUE(propertyArray.Marshalling(parcel));
805     auto newPropertyArray = std::shared_ptr<AudioEffectPropertyArrayV3>(
806         AudioEffectPropertyArrayV3::Unmarshalling(parcel));
807     EXPECT_EQ(newPropertyArray, nullptr);
808 }
809 
810 /**
811  * @tc.name  : Test AudioEnhancePropertyArray.
812  * @tc.number: AudioEnhancePropertyArray_001
813  * @tc.desc  : Test AudioEnhancePropertyArray Deserialization.
814  */
815 HWTEST(AudioIpcSerializationUnitTest, AudioEnhancePropertyArray_001, TestSize.Level1)
816 {
817     Parcel parcel;
818     AudioEnhancePropertyArray propertyArray = {};
819     AudioEnhanceProperty property = { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2 };
820     propertyArray.property.push_back(property);
821 
822     EXPECT_TRUE(propertyArray.Marshalling(parcel));
823     auto newPropertyArray = std::shared_ptr<AudioEnhancePropertyArray>(
824         AudioEnhancePropertyArray::Unmarshalling(parcel));
825     ASSERT_NE(newPropertyArray, nullptr);
826     EXPECT_EQ(newPropertyArray->property.size(), propertyArray.property.size());
827     if (newPropertyArray->property.size() == propertyArray.property.size()) {
828         for (int32_t i = 0; i < propertyArray.property.size(); i++) {
829             EXPECT_EQ(newPropertyArray->property[i], propertyArray.property[i]);
830         }
831     }
832 }
833 
834 /**
835  * @tc.name  : Test AudioEnhancePropertyArray.
836  * @tc.number: AudioEnhancePropertyArray_002
837  * @tc.desc  : Test AudioEnhancePropertyArray Deserialization.
838  */
839 HWTEST(AudioIpcSerializationUnitTest, AudioEnhancePropertyArray_002, TestSize.Level1)
840 {
841     Parcel parcel;
842     AudioEnhancePropertyArray propertyArray = {};
843     AudioEnhanceProperty property = {};
844 
845     propertyArray.property.assign(AUDIO_EFFECT_COUNT_UPPER_LIMIT + 1, property);
846     EXPECT_TRUE(propertyArray.Marshalling(parcel));
847     auto newPropertyArray = std::shared_ptr<AudioEnhancePropertyArray>(
848         AudioEnhancePropertyArray::Unmarshalling(parcel));
849     EXPECT_EQ(newPropertyArray, nullptr);
850 }
851 
852 /**
853  * @tc.name  : Test AudioEffectPropertyArray.
854  * @tc.number: AudioEffectPropertyArray_001
855  * @tc.desc  : Test AudioEffectPropertyArray Deserialization.
856  */
857 HWTEST(AudioIpcSerializationUnitTest, AudioEffectPropertyArray_001, TestSize.Level1)
858 {
859     Parcel parcel;
860     AudioEffectPropertyArray propertyArray = {};
861     AudioEffectProperty property = { TEST_STRING_VALUE_1, TEST_STRING_VALUE_2 };
862     propertyArray.property.push_back(property);
863 
864     EXPECT_TRUE(propertyArray.Marshalling(parcel));
865     auto newPropertyArray = std::shared_ptr<AudioEffectPropertyArray>(
866         AudioEffectPropertyArray::Unmarshalling(parcel));
867     ASSERT_NE(newPropertyArray, nullptr);
868     EXPECT_EQ(newPropertyArray->property.size(), propertyArray.property.size());
869     if (newPropertyArray->property.size() == propertyArray.property.size()) {
870         for (int32_t i = 0; i < propertyArray.property.size(); i++) {
871             EXPECT_EQ(newPropertyArray->property[i], propertyArray.property[i]);
872         }
873     }
874 }
875 
876 /**
877  * @tc.name  : Test AudioEffectPropertyArray.
878  * @tc.number: AudioEffectPropertyArray_002
879  * @tc.desc  : Test AudioEffectPropertyArray Deserialization.
880  */
881 HWTEST(AudioIpcSerializationUnitTest, AudioEffectPropertyArray_002, TestSize.Level1)
882 {
883     Parcel parcel;
884     AudioEffectPropertyArray propertyArray = {};
885     AudioEffectProperty property = {};
886 
887     propertyArray.property.assign(AUDIO_EFFECT_COUNT_UPPER_LIMIT + 1, property);
888     EXPECT_TRUE(propertyArray.Marshalling(parcel));
889     auto newPropertyArray = std::shared_ptr<AudioEffectPropertyArray>(
890         AudioEffectPropertyArray::Unmarshalling(parcel));
891     EXPECT_EQ(newPropertyArray, nullptr);
892 }
893 
894 /**
895  * @tc.name  : Test AudioSpatializationState.
896  * @tc.number: AudioSpatializationState_001
897  * @tc.desc  : Test AudioSpatializationState Serialization.
898  */
899 HWTEST(AudioIpcSerializationUnitTest, AudioSpatializationState_001, TestSize.Level1)
900 {
901     Parcel parcel;
902     AudioSpatializationState state = { true, false };
903 
904     EXPECT_TRUE(state.Marshalling(parcel));
905     auto newState = std::shared_ptr<AudioSpatializationState>(AudioSpatializationState::Unmarshalling(parcel));
906     ASSERT_NE(newState, nullptr);
907     EXPECT_EQ(newState->spatializationEnabled, state.spatializationEnabled);
908     EXPECT_EQ(newState->headTrackingEnabled, state.headTrackingEnabled);
909 }
910 
911 /**
912  * @tc.name  : Test ConverterConfig.
913  * @tc.number: ConverterConfig_001
914  * @tc.desc  : Test ConverterConfig Serialization.
915  */
916 HWTEST(AudioIpcSerializationUnitTest, ConverterConfig_001, TestSize.Level1)
917 {
918     Parcel parcel;
919     ConverterConfig config = {};
920     config.version = TEST_STRING_VALUE_1;
921     config.library.name = TEST_STRING_VALUE_2;
922     config.library.path = TEST_STRING_VALUE_3;
923     config.outChannelLayout = TEST_VALUE_1;
924 
925     EXPECT_TRUE(config.Marshalling(parcel));
926     auto newConfig = std::shared_ptr<ConverterConfig>(ConverterConfig::Unmarshalling(parcel));
927     ASSERT_NE(newConfig, nullptr);
928     EXPECT_EQ(newConfig->version, config.version);
929     EXPECT_EQ(newConfig->library.name, config.library.name);
930     EXPECT_EQ(newConfig->library.path, config.library.path);
931     EXPECT_EQ(newConfig->outChannelLayout, config.outChannelLayout);
932 }
933 
934 /**
935  * @tc.name  : Test ToneSegment.
936  * @tc.number: ToneSegment_001
937  * @tc.desc  : Test ToneSegment Serialization.
938  */
939 HWTEST(AudioIpcSerializationUnitTest, ToneSegment_001, TestSize.Level1)
940 {
941     Parcel parcel;
942     ToneSegment toneSegment = {};
943     toneSegment.duration = TEST_VALUE_1;
944     for (int32_t i = 0; i < TONEINFO_MAX_WAVES + 1; i++) {
945         toneSegment.waveFreq[i] = TEST_VALUE_2 + i;
946     }
947     toneSegment.loopCnt = TEST_VALUE_2;
948     toneSegment.loopIndx = TEST_VALUE_3;
949 
950     EXPECT_TRUE(toneSegment.Marshalling(parcel));
951     auto newToneSegment = std::shared_ptr<ToneSegment>(ToneSegment::Unmarshalling(parcel));
952     ASSERT_NE(newToneSegment, nullptr);
953     EXPECT_EQ(newToneSegment->duration, toneSegment.duration);
954     EXPECT_EQ(newToneSegment->loopCnt, toneSegment.loopCnt);
955     EXPECT_EQ(newToneSegment->loopIndx, toneSegment.loopIndx);
956     for (int32_t i = 0; i < TONEINFO_MAX_WAVES + 1; i++) {
957         EXPECT_EQ(newToneSegment->waveFreq[i], toneSegment.waveFreq[i]);
958     }
959 }
960 
961 /**
962  * @tc.name  : Test ToneInfo.
963  * @tc.number: ToneInfo_001
964  * @tc.desc  : Test ToneInfo Serialization.
965  */
966 HWTEST(AudioIpcSerializationUnitTest, ToneInfo_001, TestSize.Level1)
967 {
968     Parcel parcel;
969     ToneInfo toneInfo = {};
970     toneInfo.segmentCnt = TONEINFO_MAX_SEGMENTS;
971     toneInfo.repeatCnt = TEST_VALUE_1;
972     toneInfo.repeatSegment = TEST_VALUE_2;
973     toneInfo.segments[0].duration = TEST_VALUE_3;
974     toneInfo.segments[0].loopCnt = TEST_VALUE_4;
975 
976     EXPECT_TRUE(toneInfo.Marshalling(parcel));
977     auto newToneInfo = std::shared_ptr<ToneInfo>(ToneInfo::Unmarshalling(parcel));
978     ASSERT_NE(newToneInfo, nullptr);
979     EXPECT_EQ(newToneInfo->segmentCnt, toneInfo.segmentCnt);
980     EXPECT_EQ(newToneInfo->repeatCnt, toneInfo.repeatCnt);
981     EXPECT_EQ(newToneInfo->repeatSegment, toneInfo.repeatSegment);
982     EXPECT_EQ(newToneInfo->segments[0].duration, toneInfo.segments[0].duration);
983     EXPECT_EQ(newToneInfo->segments[0].loopCnt, toneInfo.segments[0].loopCnt);
984 }
985 
986 /**
987  * @tc.name  : Test VolumeEvent.
988  * @tc.number: VolumeEvent_001
989  * @tc.desc  : Test VolumeEvent Serialization.
990  */
991 HWTEST(AudioIpcSerializationUnitTest, VolumeEvent_001, TestSize.Level1)
992 {
993     Parcel parcel;
994     VolumeEvent event = {};
995     event.volumeType = STREAM_RING;
996     event.volume = TEST_VALUE_1;
997     event.updateUi = true;
998     event.volumeGroupId = TEST_VALUE_2;
999     event.networkId = TEST_STRING_VALUE_1;
1000     event.volumeMode = AUDIOSTREAM_VOLUMEMODE_APP_INDIVIDUAL;
1001     event.notifyRssWhenAccountsChange = true;
1002 
1003     EXPECT_TRUE(event.Marshalling(parcel));
1004     auto newEvent = std::shared_ptr<VolumeEvent>(VolumeEvent::Unmarshalling(parcel));
1005     ASSERT_NE(newEvent, nullptr);
1006     EXPECT_EQ(newEvent->volumeType, event.volumeType);
1007     EXPECT_EQ(newEvent->volume, event.volume);
1008     EXPECT_EQ(newEvent->updateUi, event.updateUi);
1009     EXPECT_EQ(newEvent->volumeGroupId, event.volumeGroupId);
1010     EXPECT_EQ(newEvent->networkId, event.networkId);
1011     EXPECT_EQ(newEvent->volumeMode, event.volumeMode);
1012     EXPECT_EQ(newEvent->notifyRssWhenAccountsChange, event.notifyRssWhenAccountsChange);
1013 }
1014 
1015 /**
1016  * @tc.name  : Test StreamVolumeEvent.
1017  * @tc.number: StreamVolumeEvent_001
1018  * @tc.desc  : Test StreamVolumeEvent Serialization.
1019  */
1020 HWTEST(AudioIpcSerializationUnitTest, StreamVolumeEvent_001, TestSize.Level1)
1021 {
1022     Parcel parcel;
1023     StreamVolumeEvent event = {};
1024     event.streamUsage = STREAM_USAGE_NOTIFICATION_RINGTONE;
1025     event.volume = TEST_VALUE_1;
1026     event.updateUi = true;
1027     event.volumeGroupId = TEST_VALUE_2;
1028     event.networkId = TEST_STRING_VALUE_1;
1029     event.volumeMode = AUDIOSTREAM_VOLUMEMODE_APP_INDIVIDUAL;
1030 
1031     EXPECT_TRUE(event.Marshalling(parcel));
1032     auto newEvent = std::shared_ptr<StreamVolumeEvent>(StreamVolumeEvent::Unmarshalling(parcel));
1033     ASSERT_NE(newEvent, nullptr);
1034     EXPECT_EQ(newEvent->streamUsage, event.streamUsage);
1035     EXPECT_EQ(newEvent->volume, event.volume);
1036     EXPECT_EQ(newEvent->updateUi, event.updateUi);
1037     EXPECT_EQ(newEvent->volumeGroupId, event.volumeGroupId);
1038     EXPECT_EQ(newEvent->networkId, event.networkId);
1039     EXPECT_EQ(newEvent->volumeMode, event.volumeMode);
1040 }
1041 
1042 /**
1043  * @tc.name  : Test AudioWorkgroupChangeInfoIpc.
1044  * @tc.number: AudioWorkgroupChangeInfoIpc_001
1045  * @tc.desc  : Test AudioWorkgroupChangeInfoIpc Serialization.
1046  */
1047 HWTEST(AudioIpcSerializationUnitTest, AudioWorkgroupChangeInfoIpc_001, TestSize.Level1)
1048 {
1049     Parcel parcel;
1050     AudioWorkgroupChangeInfoIpc info = {};
1051     info.changeInfo = { TEST_VALUE_1, TEST_VALUE_2, true };
1052 
1053     EXPECT_TRUE(info.Marshalling(parcel));
1054     auto newInfo = std::shared_ptr<AudioWorkgroupChangeInfoIpc>(AudioWorkgroupChangeInfoIpc::Unmarshalling(parcel));
1055     ASSERT_NE(newInfo, nullptr);
1056     EXPECT_EQ(newInfo->changeInfo.pid, info.changeInfo.pid);
1057     EXPECT_EQ(newInfo->changeInfo.groupId, info.changeInfo.groupId);
1058     EXPECT_EQ(newInfo->changeInfo.startAllowed, info.changeInfo.startAllowed);
1059 }
1060 
1061 /**
1062  * @tc.name  : Test CurrentOutputDeviceChangedEvent.
1063  * @tc.number: CurrentOutputDeviceChangedEvent_001
1064  * @tc.desc  : Test CurrentOutputDeviceChangedEvent Deserialization.
1065  */
1066 HWTEST(AudioIpcSerializationUnitTest, CurrentOutputDeviceChangedEvent_001, TestSize.Level1)
1067 {
1068     Parcel parcel;
1069     CurrentOutputDeviceChangedEvent event = {};
1070     auto device = std::make_shared<AudioDeviceDescriptor>();
1071     EXPECT_NE(device, nullptr);
1072 
1073     event.devices.assign(CurrentOutputDeviceChangedEvent::DEVICE_CHANGE_VALID_SIZE + 1, device);
1074     EXPECT_TRUE(event.Marshalling(parcel));
1075     auto newEvent = std::shared_ptr<CurrentOutputDeviceChangedEvent>(
1076         CurrentOutputDeviceChangedEvent::Unmarshalling(parcel));
1077     EXPECT_EQ(newEvent, nullptr);
1078 }
1079 
1080 /**
1081  * @tc.name  : Test MicrophoneBlockedInfo.
1082  * @tc.number: MicrophoneBlockedInfo_001
1083  * @tc.desc  : Test MicrophoneBlockedInfo Deserialization.
1084  */
1085 HWTEST(AudioIpcSerializationUnitTest, MicrophoneBlockedInfo_001, TestSize.Level1)
1086 {
1087     Parcel parcel;
1088     MicrophoneBlockedInfo info = {};
1089     auto device = std::make_shared<AudioDeviceDescriptor>();
1090     EXPECT_NE(device, nullptr);
1091 
1092     info.devices.assign(MicrophoneBlockedInfo::DEVICE_CHANGE_VALID_SIZE + 1, device);
1093     EXPECT_TRUE(info.Marshalling(parcel));
1094     auto newInfo = std::shared_ptr<MicrophoneBlockedInfo>(MicrophoneBlockedInfo::Unmarshalling(parcel));
1095     EXPECT_EQ(newInfo, nullptr);
1096 }
1097 
1098 /**
1099  * @tc.name  : Test OHAudioBuffer.
1100  * @tc.number: OHAudioBuffer_001
1101  * @tc.desc  : Test OHAudioBuffer Serialization.
1102  */
1103 HWTEST(AudioIpcSerializationUnitTest, OHAudioBuffer_001, TestSize.Level1)
1104 {
1105     Parcel parcel;
1106     uint32_t totalSizeInFrame = TOTAL_SIZE_IN_FRAME;
1107     uint32_t spanSizeInFrame = TOTAL_SIZE_IN_FRAME;
1108     uint32_t byteSizePerFrame = BYTE_SIZE_PER_FRAME;
1109     auto audioBuffer = OHAudioBuffer::CreateFromLocal(totalSizeInFrame, spanSizeInFrame, byteSizePerFrame);
1110     ASSERT_NE(audioBuffer, nullptr);
1111 
1112     EXPECT_TRUE(audioBuffer->Marshalling(parcel));
1113     auto newAudioBuffer = std::shared_ptr<OHAudioBuffer>(OHAudioBuffer::Unmarshalling(parcel));
1114     ASSERT_NE(newAudioBuffer, nullptr);
1115     auto initInfo = newAudioBuffer->ohAudioBufferBase_.GetInitializationInfo();
1116     EXPECT_EQ(initInfo.totalSizeInFrame, totalSizeInFrame);
1117     EXPECT_EQ(initInfo.byteSizePerFrame, byteSizePerFrame);
1118     EXPECT_EQ(newAudioBuffer->spanBasicInfo_.spanSizeInFrame_, spanSizeInFrame);
1119 }
1120 
1121 /**
1122  * @tc.name  : Test OHAudioBufferBase.
1123  * @tc.number: OHAudioBufferBase_001
1124  * @tc.desc  : Test OHAudioBufferBase Serialization.
1125  */
1126 HWTEST(AudioIpcSerializationUnitTest, OHAudioBufferBase_001, TestSize.Level1)
1127 {
1128     Parcel parcel;
1129     uint32_t totalSizeInFrame = TOTAL_SIZE_IN_FRAME;
1130     uint32_t byteSizePerFrame = BYTE_SIZE_PER_FRAME;
1131     auto audioBuffer = OHAudioBufferBase::CreateFromLocal(totalSizeInFrame, byteSizePerFrame);
1132     ASSERT_NE(audioBuffer, nullptr);
1133 
1134     EXPECT_TRUE(audioBuffer->Marshalling(parcel));
1135     auto newAudioBuffer = std::shared_ptr<OHAudioBufferBase>(OHAudioBufferBase::Unmarshalling(parcel));
1136     ASSERT_NE(newAudioBuffer, nullptr);
1137     EXPECT_EQ(newAudioBuffer->totalSizeInFrame_, totalSizeInFrame);
1138     EXPECT_EQ(newAudioBuffer->byteSizePerFrame_, byteSizePerFrame);
1139 }
1140 
1141 /**
1142  * @tc.name  : Test AudioSharedMemory.
1143  * @tc.number: AudioSharedMemory_001
1144  * @tc.desc  : Test AudioSharedMemory Serialization.
1145  */
1146 HWTEST(AudioIpcSerializationUnitTest, AudioSharedMemory_001, TestSize.Level1)
1147 {
1148     Parcel parcel;
1149     size_t mapSize = 100;
1150     std::string name = "test";
1151     auto sharedMemory = AudioSharedMemory::CreateFormLocal(mapSize, name);
1152     ASSERT_NE(sharedMemory, nullptr);
1153 
1154     EXPECT_TRUE(sharedMemory->Marshalling(parcel));
1155     auto newSharedMemory = std::shared_ptr<AudioSharedMemory>(AudioSharedMemory::Unmarshalling(parcel));
1156     ASSERT_NE(newSharedMemory, nullptr);
1157     EXPECT_EQ(newSharedMemory->GetSize(), mapSize);
1158     EXPECT_EQ(newSharedMemory->GetName(), name);
1159 }
1160 
1161 /**
1162  * @tc.name  : Test AudioProcessConfig.
1163  * @tc.number: AudioProcessConfig_001
1164  * @tc.desc  : Test AudioProcessConfig Serialization.
1165  */
1166 HWTEST(AudioIpcSerializationUnitTest, AudioProcessConfig_001, TestSize.Level1)
1167 {
1168     Parcel parcel;
1169     AudioProcessConfig config = {};
1170     config.appInfo = { TEST_VALUE_1, TEST_VALUE_2, TEST_VALUE_3, TEST_VALUE_4 };
1171     InitAudioStreamInfo(config.streamInfo);
1172     InitAudioRendererInfo(config.rendererInfo);
1173     InitAudioCapturerInfo(config.capturerInfo);
1174     config.audioMode = AUDIO_MODE_RECORD;
1175     config.privacyType = PRIVACY_TYPE_PRIVATE;
1176     config.streamType = STREAM_ALARM;
1177     config.deviceType = DEVICE_TYPE_SPEAKER;
1178     config.isInnerCapturer = true;
1179     config.isWakeupCapturer = false;
1180     config.originalSessionId = TEST_VALUE_3;
1181     config.innerCapId = TEST_VALUE_4;
1182 
1183     EXPECT_TRUE(config.Marshalling(parcel));
1184     auto newConfig = std::shared_ptr<AudioProcessConfig>(AudioProcessConfig::Unmarshalling(parcel));
1185     ASSERT_NE(newConfig, nullptr);
1186     EXPECT_TRUE(IsAudioProcessConfigEqual(*newConfig, config));
1187 }
1188 } // namespace AudioStandard
1189 } // namespace OHOS
1190