sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\multimedia\t_sound_api.cpp sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file Shared chunk sound driver API test code. sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include "t_soundutils.h" sl@0: sl@0: #define CHECK(aValue) {Test(aValue);} sl@0: #define CHECK_NOERROR(aValue) { TInt v=(aValue); if(v) { Test.Printf(_L("Error value = %d\n"),v); Test(EFalse,__LINE__); }} sl@0: #define CHECK_EQUAL(aValue1,aValue2) { TInt v1=(aValue1); TInt v2=(aValue2); if(v1!=v2) { Test.Printf(_L("Error value = %d\n"),v1); Test(EFalse,__LINE__); }} sl@0: sl@0: _LIT(KSndLddFileName,"ESOUNDSC.LDD"); sl@0: _LIT(KSndPddFileName,"SOUNDSC.PDD"); sl@0: sl@0: RTest Test(_L("T_SOUND_API")); sl@0: RSoundSc TxSoundDevice; sl@0: RSoundSc RxSoundDevice; sl@0: sl@0: TSoundFormatsSupportedV02Buf RecordCapsBuf; sl@0: TSoundFormatsSupportedV02Buf PlayCapsBuf; sl@0: TCurrentSoundFormatV02Buf PlayFormatBuf; sl@0: TCurrentSoundFormatV02Buf RecordFormatBuf; sl@0: sl@0: LOCAL_C TInt Load() sl@0: { sl@0: TInt r; sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-219 sl@0: @SYMTestCaseDesc Installing the PDD sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions 1) Attempt to install the PDD (using User::LoadPhysicalDevice()). sl@0: 2) Without un-installing it, attempt to install it a second time. sl@0: @SYMTestExpectedResults 1) KErrNone - PDD loads successfully. sl@0: 2) Should fail with KErrAlreadyExists. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Start(_L("Load sound PDD")); sl@0: r=User::LoadPhysicalDevice(KSndPddFileName); sl@0: if (r==KErrNotFound) sl@0: { sl@0: Test.End(); sl@0: return(r); sl@0: } sl@0: CHECK(r==KErrNone || r==KErrAlreadyExists); sl@0: r=User::LoadPhysicalDevice(KSndPddFileName); sl@0: CHECK(r==KErrAlreadyExists); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-220 sl@0: @SYMTestCaseDesc Installing the LDD sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions 1) Attempt to install the LDD (using User::LoadLogicalDevice()). sl@0: 2) Without un-installing it, attempt to install it a second time. sl@0: @SYMTestExpectedResults 1) KErrNone - LDD loads successfully. sl@0: 2) Should fail with KErrAlreadyExists. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Load sound LDD")); sl@0: r=User::LoadLogicalDevice(KSndLddFileName); sl@0: CHECK(r==KErrNone || r==KErrAlreadyExists); sl@0: r=User::LoadPhysicalDevice(KSndPddFileName); sl@0: CHECK(r==KErrAlreadyExists); sl@0: sl@0: Test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void TestSetAudioFormat() sl@0: { sl@0: TInt r; sl@0: Test.Printf(_L("Testing setting the audio format\r\n")); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-227 sl@0: @SYMTestCaseDesc Setting the audio configuration - channel configuration. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Read the audio capabilities of the playback channel. For each of the possible 6 channel sl@0: configurations, issue a request on the playback channel to set this audio configuration. sl@0: @SYMTestExpectedResults Either KErrNone if the playback channel supports the channel configuration, or sl@0: KErrNotSupported if the playback channel does not support the channel configuration. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Try to set every possible audio channel configuration")); sl@0: TxSoundDevice.AudioFormat(PlayFormatBuf); // Read back the current setting which must be valid. sl@0: TInt i; sl@0: for (i=0 ; i < 6 ; i++) sl@0: { sl@0: PlayFormatBuf().iChannels = (i+1); sl@0: r=TxSoundDevice.SetAudioFormat(PlayFormatBuf); sl@0: if (PlayCapsBuf().iChannels & (1< bufferConfigBuf(bufferConfig); sl@0: r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: CHECK(bufferConfig.iBufferSizeInBytes==bufSize); sl@0: sl@0: // Start playing sl@0: r=MakeSineTable(PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: r=SetToneFrequency(660,PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize); sl@0: WriteTone(ptr,PlayFormatBuf()); sl@0: TRequestStatus stat; sl@0: TxSoundDevice.PlayData(stat,bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample); sl@0: sl@0: // Check that altering the audio format while playing - fails sl@0: r=TxSoundDevice.SetAudioFormat(PlayFormatBuf); sl@0: CHECK(r==KErrInUse); sl@0: sl@0: User::WaitForRequest(stat); sl@0: CHECK_EQUAL(stat.Int(),KErrNone); sl@0: sl@0: Test.Next(_L("Try to alter the audio format while recording")); sl@0: sl@0: // Set the audio configuration of the record channel ready to start recording sl@0: RxSoundDevice.AudioFormat(RecordFormatBuf); // Read back the current setting which must be valid. sl@0: if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM) sl@0: RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM; sl@0: RecordFormatBuf().iChannels = 2; sl@0: sl@0: // find first supported rate and set the the audio configuration to use it sl@0: for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++) sl@0: { sl@0: RecordFormatBuf().iRate = (TSoundRate)i; sl@0: r=TxSoundDevice.SetAudioFormat(RecordFormatBuf); sl@0: if (RecordCapsBuf().iRates & (1<=0); sl@0: CHECK(length>0); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: RxSoundDevice.CancelRecordData(); // Stop the driver from recording. sl@0: chunk.Close(); sl@0: } sl@0: sl@0: LOCAL_C void TestSetBufferConfig(TInt aBufferConfigFlags) sl@0: { sl@0: sl@0: Test.Printf(_L("Testing setting the buffer configuration\r\n")); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-232 sl@0: @SYMTestCaseDesc Setting the buffer configuration - varying the number of buffers. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Issue a request on the playback channel to create a shared chunk (i.e. using sl@0: SetBufferChunkCreate()) with a buffer configuration containing a single buffer. Attempt sl@0: to open the same shared chunk on the record channel (i.e. using SetBufferChunkOpen()). sl@0: Then close the chunk. sl@0: Repeat this same sequence using buffer configurations containing 2 - 8 buffers. sl@0: @SYMTestExpectedResults In every case the attempt to create and open the shared chunk should return KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test creating/opening a chunk, varying the number of buffers ")); sl@0: TInt r; sl@0: RChunk chunk; sl@0: TTestSharedChunkBufConfig bufferConfig; sl@0: bufferConfig.iBufferSizeInBytes=0x7FE0; // 32K - 32 bytes sl@0: if (PlayCapsBuf().iRequestMinSize) sl@0: bufferConfig.iBufferSizeInBytes&=~(PlayCapsBuf().iRequestMinSize-1); // Assumes iRequestMinSize is same for play and record sl@0: TPckg bufferConfigBuf(bufferConfig); sl@0: sl@0: TInt i; sl@0: for (i=1 ; i<=8 ; i++) sl@0: { sl@0: bufferConfig.iFlags=aBufferConfigFlags; sl@0: bufferConfig.iNumBuffers=i; sl@0: sl@0: // Create the shared chunk on the play channel sl@0: r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: sl@0: // Open the same shared chunk on the record channel sl@0: r=RxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: sl@0: chunk.Close(); sl@0: } sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-233 sl@0: @SYMTestCaseDesc Setting the buffer configuration - varying the size of the buffers. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Issue a request on the playback channel to create a shared chunk (i.e. using sl@0: SetBufferChunkCreate()) with a buffer configuration containing multiple buffers sl@0: each of size 32K bytes. Attempt to open the same shared chunk on the record channel sl@0: (i.e. using SetBufferChunkOpen()). Then close the chunk. Repeat this same sequence sl@0: using buffer configurations containing buffers of size 16K, 8K and 4K bytes. sl@0: @SYMTestExpectedResults In every case the attempt to create and open the shared chunk should return KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test creating/opening a chunk, varying the size of the buffers ")); sl@0: bufferConfig.iNumBuffers=4; sl@0: sl@0: for (i=1 ; i<=8 ; i*=2) sl@0: { sl@0: bufferConfig.iFlags=aBufferConfigFlags; sl@0: bufferConfig.iBufferSizeInBytes=(0x8000/i); sl@0: sl@0: // Create the shared chunk on the play channel sl@0: r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: sl@0: // Open the same shared chunk on the record channel sl@0: r=RxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: sl@0: chunk.Close(); sl@0: } sl@0: sl@0: // Try creating a shared chunk for the record channel specifying an illegal buffer size. sl@0: if (RecordCapsBuf().iRequestMinSize) sl@0: { sl@0: Test.Next(_L("Test creating a chunk, with an illegal buffer size")); sl@0: bufferConfig.iNumBuffers=1; sl@0: bufferConfig.iBufferSizeInBytes=0x1001; // 4K + 1byte sl@0: bufferConfig.iFlags=aBufferConfigFlags; sl@0: r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK(r==KErrArgument); sl@0: chunk.Close(); sl@0: } sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-234 sl@0: @SYMTestCaseDesc Setting the buffer configuration - specifying the buffer offsets. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Issue a request on the record channel to create a shared chunk (i.e. sl@0: using SetBufferChunkCreate()) with an buffer configuration containing multiple buffers sl@0: where the offset of each buffer is specified by the client. Perform this test repeatedly sl@0: with buffer offsets specified as follows:- sl@0: 1) Valid buffer offsets sl@0: 2) Offsets resulting on overlapping buffers sl@0: 3) Offsets which aren't aligned with the request alignment restrictions for the device (if it has any). sl@0: @SYMTestExpectedResults 1) Setting the buffer configuration should return KErrNone. sl@0: 2) Setting the buffer configuration should fail with KErrArgument. sl@0: 3) Setting the buffer configuration should fail with KErrArgument. sl@0: @SYMREQ PREQ1073.4 */ sl@0: /* sl@0: // ***** Setting the buffer configuration - specifying the buffer offsets is not supported. ***** sl@0: sl@0: Test.Next(_L("Test creating a chunk, specifying the buffer offsets")); sl@0: TInt bufSize=0x2000; sl@0: bufferConfig.iNumBuffers=8; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iBufferOffsetList[0]=0; sl@0: bufferConfig.iBufferOffsetList[1]=bufSize; sl@0: bufferConfig.iBufferOffsetList[2]=bufSize*4; sl@0: bufferConfig.iBufferOffsetList[3]=bufSize*6; sl@0: bufferConfig.iBufferOffsetList[4]=bufSize*7; sl@0: bufferConfig.iBufferOffsetList[5]=bufSize*9; sl@0: bufferConfig.iBufferOffsetList[6]=bufSize*10; sl@0: bufferConfig.iBufferOffsetList[7]=bufSize*12; sl@0: bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse); sl@0: bufferConfigBuf.SetLength(sizeof(bufferConfig)); // Otherwise set shorter by previous GetBufferConfig(). sl@0: r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: RxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: chunk.Close(); sl@0: sl@0: Test.Next(_L("Test creating a chunk, with invalid buffer offsets specified")); sl@0: sl@0: // Firstly with 2nd buffer overlapping the 1st sl@0: bufSize=0x2000; sl@0: bufferConfig.iNumBuffers=3; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iBufferOffsetList[0]=0; sl@0: bufferConfig.iBufferOffsetList[1]=bufSize/2; sl@0: bufferConfig.iBufferOffsetList[2]=bufSize*2; sl@0: bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse); sl@0: r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK(r==KErrArgument); sl@0: chunk.Close(); sl@0: sl@0: // Now with offset of 3rd buffer not on a page boundary sl@0: if (RecordCapsBuf().iRequestAlignment) sl@0: { sl@0: bufSize=0x2000; sl@0: bufferConfig.iNumBuffers=3; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iBufferOffsetList[0]=0; sl@0: bufferConfig.iBufferOffsetList[1]=bufSize; sl@0: bufferConfig.iBufferOffsetList[2]=(bufSize*2)+1; sl@0: bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse); sl@0: r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK(r==KErrArgument); sl@0: chunk.Close(); sl@0: } sl@0: */ sl@0: } sl@0: sl@0: LOCAL_C void TestPlay() sl@0: { sl@0: sl@0: Test.Printf(_L("Testing play operation\r\n")); sl@0: sl@0: // Close and re-open the playback channel to reset the driver. sl@0: TxSoundDevice.Close(); sl@0: TInt r = TxSoundDevice.Open(KSoundScTxUnit0); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-235 sl@0: @SYMTestCaseDesc Play operation - playing without having set the buffer configuration. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Issue a request on the playback channel to play some audio data before having set-up sl@0: the buffer configuration. sl@0: @SYMTestExpectedResults The play request should fail with KErrNotReady. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test playing without setting buffer config")); sl@0: TRequestStatus stat[2]; sl@0: TxSoundDevice.PlayData(stat[0],0,0x2000); // 8K sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrNotReady); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-236 sl@0: @SYMTestCaseDesc Play operation - playing without having set the audio configuration. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the buffer configuration on the playback channel and then issue a request to sl@0: play audio data before having set-up the audio configuration sl@0: @SYMTestExpectedResults The play request should complete with KErrNone - with the driver using its default sl@0: audio configuration for the transfer. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test playing without setting audio config")); sl@0: sl@0: // Read back the default play configuration sl@0: TxSoundDevice.AudioFormat(PlayFormatBuf); sl@0: TCurrentSoundFormatV02 playFormat=PlayFormatBuf(); sl@0: PrintConfig(playFormat,Test); sl@0: sl@0: // Set the play buffer configuration. sl@0: RChunk chunk; sl@0: TInt bufSize=BytesPerSecond(PlayFormatBuf()); // Large enough to hold 1 second of data. sl@0: bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver. sl@0: TTestSharedChunkBufConfig bufferConfig; sl@0: bufferConfig.iNumBuffers=1; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iFlags=0; sl@0: TPckg bufferConfigBuf(bufferConfig); sl@0: r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: CHECK(bufferConfig.iBufferSizeInBytes==bufSize); sl@0: sl@0: // Start playing sl@0: r=MakeSineTable(PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: r=SetToneFrequency(660,PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize); sl@0: WriteTone(ptr,PlayFormatBuf()); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_NOERROR(stat[0].Int()); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-239 sl@0: @SYMTestCaseDesc Play operation - with invalid arguments. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the playback channel to commence playing audio data using a buffer configuration sl@0: containing multiple buffers. Now issue a series of transfer requests to play data where the sl@0: requests contain invalid request arguments as follows:- sl@0: 1) A request with a buffer offset before the start of the first buffer. sl@0: 2) A request with a buffer offset between buffers. sl@0: 3) A request with a length too large for a buffer. sl@0: 4) A request with a buffer offset that doesn't comply with the offset restrictions of sl@0: the driver (i.e. TSoundFormatsSupportedV02:: iRequestAlignment). sl@0: 5) A request with a length that doesn't comply with the length restrictions of sl@0: the driver (i.e. TSoundFormatsSupportedV02::iRequestMinSize). sl@0: @SYMTestExpectedResults 1) The play request should fail with KErrArgument. sl@0: 2) The play request should fail with KErrArgument. sl@0: 3) The play request should fail with KErrArgument. sl@0: 4) The play request should fail with KErrArgument. sl@0: 5) The play request should fail with KErrArgument sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test playing with invalid arguments")); sl@0: sl@0: // With a buffer offset before the start of the buffer. sl@0: TxSoundDevice.PlayData(stat[0],(bufferConfig.iBufferOffsetList[0]-0x100),bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrArgument); sl@0: sl@0: // With a buffer offset beyond the end of the buffer sl@0: TxSoundDevice.PlayData(stat[0],(bufferConfig.iBufferOffsetList[0]+bufSize+0x100),bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrArgument); sl@0: sl@0: // With a length too large for the buffer sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],(bufSize+0x100),KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrArgument); sl@0: sl@0: // With a length that doesn't comply with the length restrictions of the driver sl@0: if (PlayCapsBuf().iRequestMinSize) sl@0: { sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],(bufSize-1),KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrArgument); sl@0: } sl@0: sl@0: // With an offset that doesn't comply with the offset restrictions of the driver sl@0: if (PlayCapsBuf().iRequestAlignment) sl@0: { sl@0: TInt ln=bufSize/2; sl@0: if (PlayCapsBuf().iRequestMinSize) sl@0: ln&=~(PlayCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver. sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0]+1,ln,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrArgument); sl@0: } sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-242 sl@0: @SYMTestCaseDesc Play operation - play underflow detection. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the audio configuration on the playback channel and then setup the buffer sl@0: configuration. Issue a single request to play audio data from one of the buffers sl@0: (without supplying the KSndFlagLastSample flag) and wait for the request to complete. sl@0: @SYMTestExpectedResults The driver should successfully play the audio data supplied but the request should sl@0: return the error value: KErrUnderflow. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test play underflow detection")); sl@0: sl@0: // Now set the audio configuration to a known state. sl@0: if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM) sl@0: PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM; sl@0: if (PlayCapsBuf().iRates&KSoundRate16000Hz) sl@0: PlayFormatBuf().iRate = ESoundRate16000Hz; sl@0: if (PlayCapsBuf().iChannels&KSoundStereoChannel) sl@0: PlayFormatBuf().iChannels = 2; sl@0: PrintConfig(PlayFormatBuf(),Test); sl@0: r=TxSoundDevice.SetAudioFormat(PlayFormatBuf); sl@0: CHECK_NOERROR(r); sl@0: sl@0: // Reset the play buffer configuration to correspond to the audio configuration. sl@0: bufSize=BytesPerSecond(PlayFormatBuf()); // Large enough to hold 1 second of data (64K) sl@0: bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf()); // Keep the buffer length valid for driver. sl@0: bufferConfig.iNumBuffers=1; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iFlags=0; sl@0: r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: CHECK(bufferConfig.iBufferSizeInBytes==bufSize); sl@0: sl@0: // Start playing sl@0: r=MakeSineTable(PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: r=SetToneFrequency(660,PlayFormatBuf()); sl@0: CHECK_NOERROR(r); sl@0: ptr.Set(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize,bufSize); sl@0: WriteTone(ptr,PlayFormatBuf()); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrUnderflow); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-243 sl@0: @SYMTestCaseDesc Play operation - playing multiple transfers from a single buffer. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the audio configuration on the playback channel and setup the buffer configuration sl@0: so the shared chunk contains just a single large buffer. Issue a pair of requests to play sl@0: audio data from the buffer (marking the last with the KSndFlagLastSample flag) and wait sl@0: for the requests to complete. sl@0: @SYMTestExpectedResults The driver should successfully play the audio data supplied and both requests should sl@0: complete with KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test playing multiple transfers from a single buffer")); sl@0: sl@0: // Start playing sl@0: TInt len=bufSize/2; sl@0: if (PlayCapsBuf().iRequestMinSize) sl@0: len&=~(PlayCapsBuf().iRequestMinSize-1); // Keep the buffer length valid for the driver. sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len); sl@0: TxSoundDevice.PlayData(stat[1],(bufferConfig.iBufferOffsetList[0]+len),len,KSndFlagLastSample); sl@0: bool brokenByPaging = false; sl@0: if((stat[0] != KRequestPending) || (stat[1] != KRequestPending)) sl@0: { sl@0: brokenByPaging = true; sl@0: Test.Printf(_L("Paging gap between PlayData calls - skipping test\n")); sl@0: } sl@0: User::WaitForRequest(stat[0]); sl@0: if(!brokenByPaging) CHECK_NOERROR(stat[0].Int()); sl@0: User::WaitForRequest(stat[1]); sl@0: if(!brokenByPaging) CHECK_NOERROR(stat[1].Int()); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-244 sl@0: @SYMTestCaseDesc Play operation - tracking the count of bytes transferred. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the playback channel for playing audio data. sl@0: 1) Reset the channel's count of bytes transferred and read back the count. sl@0: 2) Issue a play request of known length and wait for it to complete. Now read the sl@0: count of bytes transferred. sl@0: 3) Reset the channel's count of bytes transferred and read back the count. sl@0: @SYMTestExpectedResults 1) The count of bytes transferred should equal zero. sl@0: 2) The count of bytes transferred should equal the length of the play request. sl@0: 3) The count of bytes transferred should equal zero. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test tracking the number of bytes played")); sl@0: TxSoundDevice.ResetBytesTransferred(); sl@0: TInt bytesPlayed=TxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesPlayed==0); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_NOERROR(stat[0].Int()); sl@0: bytesPlayed=TxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesPlayed==len); sl@0: TxSoundDevice.ResetBytesTransferred(); sl@0: bytesPlayed=TxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesPlayed==0); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-246 sl@0: @SYMTestCaseDesc Play operation - testing the driver's handling of PDD play errors. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the playback channel for playing audio data. Using the CustomConfig() test mode sl@0: supported by the driver, induce the following errors returned from the driver PDD back sl@0: to the LDD:- sl@0: 1) Induce a KErrTimedOut error at the start of the transfer and then issue a play request. sl@0: 2) Induce a KErrTimedOut error once transfer has commenced and then issue a play request. sl@0: Once this completes, issue a further play request. sl@0: @SYMTestExpectedResults 1) The play request should fail immediately with KErrTimedOut (with no audible output being sl@0: heard). sl@0: 2) The driver should output a short section of audible data before the first play request sl@0: fails with KErrTimedOut. However, the driver should recover from this and the second sl@0: play request should complete with KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: #ifdef _DEBUG sl@0: Test.Next(_L("Test the driver's handling of PDD play errors")); sl@0: sl@0: // First induce an error at the start of the transfer sl@0: // Use an LDD test mode which induces KErrTimedOut at the start of the transfer. sl@0: r=TxSoundDevice.CustomConfig(KSndCustom_ForceStartTransferError); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrTimedOut); sl@0: sl@0: // Now induce an error once transfer has commenced sl@0: // Use an LDD test mode which induces KErrTimedOut once transfer has commenced. sl@0: r=TxSoundDevice.CustomConfig(KSndCustom_ForceTransferDataError); sl@0: CHECK_NOERROR(r); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_EQUAL(stat[0].Int(),KErrTimedOut); sl@0: sl@0: // Check that the driver recovers sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK_NOERROR(stat[0].Int()); sl@0: #endif sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-247 sl@0: @SYMTestCaseDesc Play operation - closing the channel cancels any play requests. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the playback channel for playing audio data. Issue a play request and sl@0: while this is outstanding, close the playback channel. sl@0: @SYMTestExpectedResults The outstanding request should complete with KErrCancel. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test that closing the channel cancels a play request")); sl@0: TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len,KSndFlagLastSample); sl@0: CHECK(stat[0]==KRequestPending); sl@0: TxSoundDevice.Close(); sl@0: User::WaitForRequest(stat[0]); sl@0: CHECK(stat[0]==KErrCancel); sl@0: sl@0: Test.Next(_L("Re-open the channel")); sl@0: r = TxSoundDevice.Open(KSoundScTxUnit0); sl@0: CHECK_NOERROR(r); sl@0: sl@0: chunk.Close(); sl@0: } sl@0: sl@0: LOCAL_C void TestRecord() sl@0: { sl@0: sl@0: Test.Printf(_L("Testing record operation\r\n")); sl@0: sl@0: // Close and re-open the record channel to reset the driver. sl@0: RxSoundDevice.Close(); sl@0: TInt r = RxSoundDevice.Open(KSoundScRxUnit0); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-251 sl@0: @SYMTestCaseDesc Record operation - recording without having set the buffer configuration. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Issue a request on the record channel to record some audio data before sl@0: having set-up the buffer configuration. sl@0: @SYMTestExpectedResults The record request should fail with KErrNotReady. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test recording without setting buffer config")); sl@0: sl@0: TRequestStatus stat; sl@0: TInt length; sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: TInt retOffset=stat.Int(); sl@0: CHECK_EQUAL(retOffset,KErrNotReady); sl@0: sl@0: // Test releasing a buffer without setting buffer config sl@0: r=RxSoundDevice.ReleaseBuffer(0); sl@0: CHECK(r==KErrNotReady); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-252 sl@0: @SYMTestCaseDesc Record operation - recording without having set the audio configuration. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the buffer configuration on the record channel. sl@0: 1) Issue a request to record a buffer of audio data before having set-up the audio sl@0: configuration. sl@0: 2) Release the buffer. sl@0: @SYMTestExpectedResults 1) The record request should complete with KErrNone - with the driver using its sl@0: default audio configuration for the transfer. sl@0: 2) The request to release the buffer should return KErrNone sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test recording without setting audio config")); sl@0: sl@0: // Read back the default record configuration sl@0: RxSoundDevice.AudioFormat(RecordFormatBuf); sl@0: TCurrentSoundFormatV02 recordFormat=RecordFormatBuf(); sl@0: PrintConfig(recordFormat,Test); sl@0: sl@0: // Set the record buffer configuration. sl@0: RChunk chunk; sl@0: TInt bufSize=BytesPerSecond(RecordFormatBuf()); // Large enough to hold 1 second of data. sl@0: bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf()); // Keep the buffer length valid for driver. sl@0: TTestSharedChunkBufConfig bufferConfig; sl@0: bufferConfig.iNumBuffers=3; sl@0: bufferConfig.iBufferSizeInBytes=bufSize; sl@0: bufferConfig.iFlags=0; sl@0: TPckg bufferConfigBuf(bufferConfig); sl@0: r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk); sl@0: CHECK_NOERROR(r); sl@0: RxSoundDevice.GetBufferConfig(bufferConfigBuf); sl@0: PrintBufferConf(bufferConfig,Test); sl@0: CHECK(bufferConfig.iBufferSizeInBytes==bufSize); sl@0: sl@0: // Start recording sl@0: RxSoundDevice.SetVolume(KSoundMaxVolume); sl@0: RxSoundDevice.RecordData(stat,length); // Start recording here sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset>=0); sl@0: CHECK(length==bufSize); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-255 sl@0: @SYMTestCaseDesc Record operation - invalid attempts to release a record buffer. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the record channel to record audio data. Issue a request to record a buffer of audio data sl@0: and then release the buffer. sl@0: 1) Request to release the same buffer just released (without having re-claimed it with a sl@0: further record request). sl@0: 2) Release a further buffer - specifying an illegal buffer offset for the buffer. sl@0: 3) Stop the driver from recording (using CancelRecordData()). Now release a buffer while sl@0: recording is disabled. sl@0: @SYMTestExpectedResults 1) The request to release the buffer should fail with KErrNotFound. sl@0: 2) The request to release the buffer should fail with KErrNotFound. sl@0: 3) The request to release the buffer should fail with KErrNotFound. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: // Test releasing a buffer twice sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK(r==KErrNotFound); sl@0: sl@0: // Test releasing an invalid buffer offset sl@0: r=RxSoundDevice.ReleaseBuffer(0); sl@0: CHECK(r==KErrNotFound); sl@0: sl@0: // Third test case for PBASE-T_SOUND_API-255 is performed later in this function. sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-256 sl@0: @SYMTestCaseDesc Record operation - record overflow detection. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration sl@0: so the shared chunk contains three record buffers. sl@0: 1) Issue a request to record a buffer of audio data (to start the driver recording). sl@0: 2) When the request completes, release the buffer immediately. sl@0: 3) Wait just over 2 buffer periods (i.e. the time it takes for the driver to fill 2 record sl@0: buffers) and then issue a further record request. sl@0: 4) To test that the driver recovers from the overflow situation, immediately issue a further sl@0: record request. sl@0: @SYMTestExpectedResults 1) The record request should complete with KErrNone. sl@0: 2) The request to release the buffer should return KErrNone. sl@0: 3) The record request should fail with KErrOverflow. sl@0: 4) The record request should complete with KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test for record overflow")); sl@0: sl@0: // Now set the audio configuration to a known state. sl@0: RxSoundDevice.CancelRecordData(); // Stop the driver from recording. sl@0: sl@0: RxSoundDevice.AudioFormat(RecordFormatBuf); // Read back the current setting which must be valid. sl@0: if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM) sl@0: RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM; sl@0: if (RecordCapsBuf().iChannels&KSoundStereoChannel) sl@0: RecordFormatBuf().iChannels = 2; sl@0: sl@0: // find first supported rate and set the the audio configuration to use it sl@0: for (TInt i=0 ; i <= (TInt)ESoundRate48000Hz ; i++) sl@0: { sl@0: RecordFormatBuf().iRate = (TSoundRate)i; sl@0: r = RxSoundDevice.SetAudioFormat(RecordFormatBuf); sl@0: if (RecordCapsBuf().iRates & (1<=0); sl@0: CHECK(length==bufSize); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: User::After(1100000); // Wait 2 buffer periods (1.1 seconds) for data overflow. sl@0: sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset==KErrOverflow); sl@0: sl@0: Test.Next(_L("Test that the driver recovers from overflow")); sl@0: sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset>=0); sl@0: CHECK(length==bufSize); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-257 sl@0: @SYMTestCaseDesc Record operation - when client is too slow releasing buffers. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the audio configuration on the record channel and then setup the buffer configuration sl@0: so the shared chunk contains three record buffers. Issue a request to record a buffer of sl@0: audio data (to start the driver recording). When this request completes, issue a further sl@0: record request without releasing the first buffer. sl@0: @SYMTestExpectedResults The second record request should fail with KErrInUse. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test when client is too slow releasing buffers")); sl@0: sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: TInt retOffset1=stat.Int(); sl@0: CHECK(retOffset1==KErrInUse); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-258 sl@0: @SYMTestCaseDesc Record operation - tracking the count of bytes transferred. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the record channel for recording audio data. sl@0: 1) Reset the channel's count of bytes transferred and read back the count. sl@0: 2) Issue a record request (to start the driver recording) and wait for it to complete. Immediately read the count of bytes transferred. sl@0: 3) Reset the channel's count of bytes transferred and read back the count sl@0: @SYMTestExpectedResults 1) The count of bytes transferred should equal zero. sl@0: 2) The count of bytes transferred should equal the size of a record buffer. sl@0: 3) The count of bytes transferred should equal zero. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test tracking the number of bytes recorded")); sl@0: RxSoundDevice.CancelRecordData(); // Stop the driver from recording. sl@0: RxSoundDevice.ResetBytesTransferred(); sl@0: TInt bytesRecorded=RxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesRecorded==0); sl@0: RxSoundDevice.RecordData(stat,length); // Re-start recording here sl@0: User::WaitForRequest(stat); sl@0: sl@0: // Quickly check the number of bytes recorded sl@0: bytesRecorded=RxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesRecorded==bufSize); sl@0: sl@0: // Now check the request was successful and release the buffer sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset>=0); sl@0: CHECK(length==bufSize); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: RxSoundDevice.ResetBytesTransferred(); sl@0: bytesRecorded=RxSoundDevice.BytesTransferred(); sl@0: CHECK(bytesRecorded==0); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-260 sl@0: @SYMTestCaseDesc Record operation - testing the driver's handling of PDD record errors. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Setup the record channel for recording. Using the CustomConfig() test mode supported by the driver, induce sl@0: the following errors returned from the driver PDD back to the LDD:- sl@0: 1) Induce a KErrTimedOut error at the start of the transfer. Then, issue a record request to sl@0: start the driver recording. Once this completes, stop the channel from recording. sl@0: 2) Induce a KErrTimedOut error once transfer has commenced. Then, issue a record request to sl@0: re-start the driver recording. Once this completes, issue a further record request. sl@0: @SYMTestExpectedResults 1) The record request should fail immediately with KErrTimedOut. sl@0: 2) The first record request should soon fail with KErrTimedOut. However, the driver should sl@0: recover from this and the subsequent record request should complete with KErrNone. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: #ifdef _DEBUG sl@0: Test.Next(_L("Test the driver's handling of PDD record errors")); sl@0: sl@0: Test.Printf(_L("Induce an error at the start of the transfer.\r\n")); sl@0: // Use an LDD test mode which induces KErrTimedOut at the start of the transfer. sl@0: RxSoundDevice.CancelRecordData(); // Stop the driver from recording. sl@0: r=RxSoundDevice.CustomConfig(KSndCustom_ForceStartTransferError); sl@0: CHECK_NOERROR(r); sl@0: RxSoundDevice.RecordData(stat,length); // Re-start recording here sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset==KErrTimedOut); sl@0: RxSoundDevice.CancelRecordData(); // Stop the driver from recording. sl@0: sl@0: Test.Printf(_L("Induce an error once transfer has commenced.\r\n")); sl@0: // Use an LDD test mode which induces KErrTimedOut once transfer has commenced. sl@0: r=RxSoundDevice.CustomConfig(KSndCustom_ForceTransferDataError); sl@0: CHECK_NOERROR(r); sl@0: RxSoundDevice.RecordData(stat,length); // Re-start recording here sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset==KErrTimedOut); sl@0: sl@0: Test.Printf(_L("Check that the driver recovers.\r\n")); sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: CHECK(retOffset>=0); sl@0: CHECK(length==bufSize); sl@0: r=RxSoundDevice.ReleaseBuffer(retOffset); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /* Test disabled sl@0: Test.Printf(_L("Induce LDD to be slow servicing transfer completes from PDD.\r\n")); sl@0: r=RxSoundDevice.CustomConfig(KSndCustom_ForceTransferTimeout); sl@0: CHECK_NOERROR(r); sl@0: RxSoundDevice.RecordData(stat,length); sl@0: User::WaitForRequest(stat); sl@0: retOffset=stat.Int(); sl@0: Test.Printf(_L("Driver returned %d.\r\n"),retOffset); */ sl@0: #endif sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-261 sl@0: @SYMTestCaseDesc Record operation - closing the channel cancels any record requests. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Start the record channel for recording audio data. Issue a record request and while this is sl@0: outstanding, close the record channel sl@0: @SYMTestExpectedResults The outstanding request should complete with KErrCancel. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test that closing the channel cancels a play request")); sl@0: RxSoundDevice.RecordData(stat,length); sl@0: CHECK(stat==KRequestPending); sl@0: RxSoundDevice.Close(); sl@0: User::WaitForRequest(stat); sl@0: CHECK(stat==KErrCancel); sl@0: sl@0: Test.Next(_L("Re-open the channel")); sl@0: r = RxSoundDevice.Open(KSoundScRxUnit0); sl@0: CHECK_NOERROR(r); sl@0: sl@0: chunk.Close(); sl@0: } sl@0: sl@0: #ifdef _DEBUG sl@0: LOCAL_C void TestChangeOfHwConfigNotifier() sl@0: { sl@0: sl@0: Test.Printf(_L("Testing the change of h/w config notifier\r\n")); sl@0: sl@0: // If support for the notifier is not supported on this platform, use a debug custom config command to force sl@0: // support for the notifier. sl@0: TInt r; sl@0: if (!PlayCapsBuf().iHwConfigNotificationSupport) sl@0: { sl@0: r=TxSoundDevice.CustomConfig(KSndCustom_ForceHwConfigNotifSupported); sl@0: CHECK_NOERROR(r); sl@0: } sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-264 sl@0: @SYMTestCaseDesc Change of h/w config. notifier - receiving notification. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions 1) Register for notification of a change in the hardware configuration of the device on sl@0: either the record or playback channel. Using the CustomConfig() test mode supported by the sl@0: driver, trigger the notifier - signalling that the headset is not present. sl@0: 2) Re-register for notification of a change in the hardware configuration on the same channel. sl@0: Again using the CustomConfig() test mode, trigger the notifier - this time signalling that the sl@0: headset is present. sl@0: @SYMTestExpectedResults 1) The outstanding request for notification should complete with KErrNone and the status of sl@0: the bolean aHeadsetPresent should be false. sl@0: 2) The outstanding request for notification should complete with KErrNone and the status of sl@0: the bolean aHeadsetPresent should be true. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: // Register for notification of a change in the hardware configuration of the device. sl@0: TRequestStatus stat; sl@0: TBool headsetPresent=ETrue; sl@0: TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent); sl@0: CHECK(stat==KRequestPending); sl@0: sl@0: Test.Next(_L("Trigger the notifier")); sl@0: // Use another debug custom config command to trigger the notifier. sl@0: r=TxSoundDevice.CustomConfig(KSndCustom_CompleteChangeOfHwConfig,(TAny*)0x00); // Signal headset not present. sl@0: CHECK_NOERROR(r); sl@0: User::WaitForRequest(stat); sl@0: CHECK_NOERROR(stat.Int()); sl@0: CHECK(!headsetPresent); sl@0: sl@0: Test.Next(_L("Trigger the notifier again")); sl@0: TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent); sl@0: CHECK(stat==KRequestPending); sl@0: r=TxSoundDevice.CustomConfig(KSndCustom_CompleteChangeOfHwConfig,(TAny*)0x01); // Signal headset is present. sl@0: CHECK_NOERROR(r); sl@0: User::WaitForRequest(stat); sl@0: CHECK_NOERROR(stat.Int()); sl@0: CHECK(headsetPresent); sl@0: sl@0: Test.Next(_L("Test cancelling the notifier")); sl@0: TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent); sl@0: CHECK(stat==KRequestPending); sl@0: TxSoundDevice.CancelNotifyChangeOfHwConfig(); sl@0: User::WaitForRequest(stat); sl@0: CHECK(stat==KErrCancel); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-265 sl@0: @SYMTestCaseDesc Change of h/w config. notifier - receiving notification. sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions 1) Register for notification of a change in the hardware configuration of the device on sl@0: either the record or playback channel. Using the CustomConfig() test mode supported by the sl@0: driver, trigger the notifier - signalling that the headset is not present. sl@0: 2) Re-register for notification of a change in the hardware configuration on the same channel. sl@0: Again using the CustomConfig() test mode, trigger the notifier - this time signalling that the sl@0: headset is present. sl@0: @SYMTestExpectedResults 1) The outstanding request for notification should complete with KErrNone and the status of sl@0: the bolean aHeadsetPresent should be false. sl@0: 2) The outstanding request for notification should complete with KErrNone and the status of sl@0: the bolean aHeadsetPresent should be true. sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: Test.Next(_L("Test that closing the channel cancels the notifier")); sl@0: TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent); sl@0: CHECK(stat==KRequestPending); sl@0: TxSoundDevice.Close(); sl@0: User::WaitForRequest(stat); sl@0: CHECK(stat==KErrCancel); sl@0: sl@0: Test.Next(_L("Re-open the channel")); sl@0: r = TxSoundDevice.Open(KSoundScTxUnit0); sl@0: CHECK_NOERROR(r); sl@0: } sl@0: #endif sl@0: sl@0: LOCAL_C void TestUnloadDrivers() sl@0: { sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-221 sl@0: @SYMTestCaseDesc Un-installing the LDD sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Attempt to un-install the LDD (using User::FreeLogicalDevice()). sl@0: @SYMTestExpectedResults KErrNone - LDD unloads successfully sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: TInt r=User::FreeLogicalDevice(KDevSoundScName); sl@0: Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r); sl@0: CHECK_NOERROR(r); sl@0: sl@0: /** @SYMTestCaseID PBASE-T_SOUND_API-222 sl@0: @SYMTestCaseDesc Un-installing the PDD sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions Attempt to un-install the PDD (using User::FreePhysicalDevice()). sl@0: @SYMTestExpectedResults KErrNone - PDD unloads successfully sl@0: @SYMREQ PREQ1073.4 */ sl@0: sl@0: TName pddName(KDevSoundScName); sl@0: _LIT(KPddWildcardExtension,".*"); sl@0: pddName.Append(KPddWildcardExtension); sl@0: TFindPhysicalDevice findPD(pddName); sl@0: TFullName findResult; sl@0: r=findPD.Next(findResult); sl@0: while (r==KErrNone) sl@0: { sl@0: r=User::FreePhysicalDevice(findResult); sl@0: Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r); sl@0: CHECK_NOERROR(r); sl@0: findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container. sl@0: r=findPD.Next(findResult); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Invoke the helper executable, tell it what unit to open RSoundSc for. sl@0: sl@0: @param aUnit Parameter to supply to RSoundSc ie. KSoundScTxUnit0, KSoundScRxUnit0 sl@0: @param aExpectedError The expected return code from RSoundSc::Open sl@0: */ sl@0: static void RunHelper(TInt aUnit, TInt aExpectedError) sl@0: { sl@0: TInt r; sl@0: sl@0: RProcess ph; sl@0: r = ph.Create(KHelperExe, KNullDesC); sl@0: CHECK_NOERROR(r); sl@0: r = ph.SetParameter(KSlot, aUnit); sl@0: CHECK_NOERROR(r); sl@0: sl@0: TRequestStatus rsh; sl@0: ph.Logon(rsh); sl@0: Test(rsh == KRequestPending); sl@0: ph.Resume(); sl@0: User::WaitForRequest(rsh); sl@0: sl@0: // process has died so check the panic category and reason match the expected values sl@0: CHECK_EQUAL(ph.ExitType(), EExitPanic); sl@0: Test(ph.ExitCategory()==KSoundAPICaps,__LINE__,(const TText*)__FILE__); sl@0: CHECK_EQUAL(ph.ExitReason(), aExpectedError); sl@0: sl@0: ph.Close(); sl@0: } sl@0: sl@0: /** sl@0: Delete the copy of the helper exe which was created with altered capabilities sl@0: */ sl@0: static TInt DeleteHelper() sl@0: { sl@0: RFs fs; sl@0: TInt r = fs.Connect(); sl@0: CHECK_NOERROR(r); sl@0: TFileName fileName(KSysBin); sl@0: fileName.Append(KPathDelimiter); sl@0: fileName+=KHelperExe; sl@0: //delete modified version of helper exe sl@0: r = fs.Delete(fileName); sl@0: fs.Close(); sl@0: return r; sl@0: } sl@0: sl@0: /** sl@0: Use setcap.exe to create a copy of the helper executable, t_sound_api_helper.exe sl@0: called t_sound_api_helper_caps.exe with the supplied capabilities. sl@0: sl@0: @param aCaps A bitmask of capabilities to assign to helper exe. sl@0: */ sl@0: static void SetHelperCaps(TUint32 aCaps) sl@0: { sl@0: TInt r; sl@0: _LIT(KCommandLineArgsFormat, "%S %08x %S\\%S"); sl@0: TBuf<128> cmdLine; sl@0: cmdLine.Format(KCommandLineArgsFormat, &KHelperExeBase, aCaps, &KSysBin, &KHelperExe); sl@0: sl@0: RProcess p; sl@0: r = p.Create(_L("setcap.exe"), cmdLine); sl@0: CHECK_NOERROR(r); sl@0: sl@0: TRequestStatus rs; sl@0: p.Logon(rs); sl@0: CHECK_EQUAL(rs.Int(),KRequestPending); sl@0: p.Resume(); sl@0: User::WaitForRequest(rs); sl@0: sl@0: p.Close(); sl@0: } sl@0: sl@0: /** sl@0: Test that ECapabilityMultimediaDD is required sl@0: in order to open RSoundSc for playback and that sl@0: ECapabilityUserEnvironment is needed, in addition, sl@0: to open for record. sl@0: */ sl@0: static void TestCapabilityChecks() sl@0: { sl@0: //convert capabilities into bitmask understood by setcap.exe sl@0: const TUint32 KUserEnvironment = 1<