os/kernelhwsrv/kerneltest/e32test/multimedia/t_sound_api.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\multimedia\t_sound_api.cpp
    15 // 
    16 //
    17 
    18 /**
    19  @file Shared chunk sound driver API test code.
    20 */
    21 
    22 #include <e32test.h>
    23 #include <f32file.h>
    24 #include "t_soundutils.h"
    25 
    26 #define CHECK(aValue) {Test(aValue);}
    27 #define CHECK_NOERROR(aValue) { TInt v=(aValue); if(v) { Test.Printf(_L("Error value = %d\n"),v); Test(EFalse,__LINE__); }}
    28 #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__); }}
    29 
    30 _LIT(KSndLddFileName,"ESOUNDSC.LDD");
    31 _LIT(KSndPddFileName,"SOUNDSC.PDD");
    32 
    33 RTest Test(_L("T_SOUND_API"));
    34 RSoundSc TxSoundDevice;
    35 RSoundSc RxSoundDevice;
    36 
    37 TSoundFormatsSupportedV02Buf RecordCapsBuf;
    38 TSoundFormatsSupportedV02Buf PlayCapsBuf;
    39 TCurrentSoundFormatV02Buf PlayFormatBuf;
    40 TCurrentSoundFormatV02Buf RecordFormatBuf;
    41 
    42 LOCAL_C TInt Load()
    43 	{
    44 	TInt r;
    45 	
    46 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-219
    47 	@SYMTestCaseDesc 		Installing the PDD
    48 	@SYMTestPriority 		Critical
    49 	@SYMTestActions			1)	Attempt to install the PDD (using User::LoadPhysicalDevice()). 
    50 							2)	Without un-installing it, attempt to install it a second time.
    51 	@SYMTestExpectedResults	1)	KErrNone - PDD loads successfully. 
    52 							2)	Should fail with KErrAlreadyExists.
    53 	@SYMREQ					PREQ1073.4 */
    54 
    55 	Test.Start(_L("Load sound PDD"));
    56 	r=User::LoadPhysicalDevice(KSndPddFileName);
    57 	if (r==KErrNotFound)
    58 		{
    59 		Test.End();
    60 		return(r);
    61 		}
    62 	CHECK(r==KErrNone || r==KErrAlreadyExists);
    63 	r=User::LoadPhysicalDevice(KSndPddFileName);
    64 	CHECK(r==KErrAlreadyExists);
    65 	
    66 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-220
    67 	@SYMTestCaseDesc 		Installing the LDD
    68 	@SYMTestPriority 		Critical
    69 	@SYMTestActions			1)	Attempt to install the LDD (using User::LoadLogicalDevice()). 
    70 							2)	Without un-installing it, attempt to install it a second time.
    71 	@SYMTestExpectedResults	1)	KErrNone - LDD loads successfully. 
    72 							2)	Should fail with KErrAlreadyExists.
    73 	@SYMREQ					PREQ1073.4 */
    74 	
    75 	Test.Next(_L("Load sound LDD"));
    76 	r=User::LoadLogicalDevice(KSndLddFileName);
    77 	CHECK(r==KErrNone || r==KErrAlreadyExists);
    78 	r=User::LoadPhysicalDevice(KSndPddFileName);
    79 	CHECK(r==KErrAlreadyExists);
    80 
    81 	Test.End();
    82 	return(KErrNone);
    83 	}
    84 
    85 LOCAL_C void TestSetAudioFormat()
    86 	{
    87 	TInt r;
    88 	Test.Printf(_L("Testing setting the audio format\r\n"));
    89 	
    90 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-227
    91 	@SYMTestCaseDesc 		Setting the audio configuration - channel configuration.
    92 	@SYMTestPriority 		Critical
    93 	@SYMTestActions			Read the audio capabilities of the playback channel. For each of the possible 6 channel 
    94 							configurations, issue a request on the playback channel to set this audio configuration.
    95 	@SYMTestExpectedResults	Either KErrNone if the playback channel supports the channel configuration, or
    96 							KErrNotSupported if the playback channel does not support the channel configuration. 
    97 	@SYMREQ					PREQ1073.4 */
    98 	
    99 	Test.Next(_L("Try to set every possible audio channel configuration"));
   100 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   101 	TInt i;
   102 	for (i=0 ; i < 6 ; i++)
   103 		{
   104 		PlayFormatBuf().iChannels = (i+1);
   105 		r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   106 		if (PlayCapsBuf().iChannels & (1<<i))
   107 			{
   108 			CHECK_NOERROR(r);				// Caps reports it is supported
   109 			}					
   110 		else
   111 			{
   112 			CHECK(r==KErrNotSupported);		// Caps reports it is not supported
   113 			}		
   114 		}
   115 		
   116 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-228
   117 	@SYMTestCaseDesc 		Setting the audio configuration - sample rate.
   118 	@SYMTestPriority 		Critical
   119 	@SYMTestActions			Read the audio capabilities of the playback channel. For each of the possible 14 sample 
   120 							rates, issue a request on the playback channel to set this audio configuration.
   121 	@SYMTestExpectedResults	Either KErrNone if the playback channel supports the sample rate, or
   122 							KErrNotSupported if the playback channel does not support the sample rate. 
   123 	@SYMREQ					PREQ1073.4 */
   124 		
   125 	Test.Next(_L("Try to set every possible sample rate"));
   126 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   127 	for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
   128 		{
   129 		PlayFormatBuf().iRate = (TSoundRate)i;
   130 		r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   131 		if (PlayCapsBuf().iRates & (1<<i))
   132 			{
   133 			CHECK_NOERROR(r);				// Caps reports it is supported
   134 			}					
   135 		else
   136 			{
   137 			CHECK(r==KErrNotSupported);		// Caps reports it is not supported
   138 			}		
   139 		}	
   140 		
   141 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-229
   142 	@SYMTestCaseDesc 		Setting the audio configuration - audio encoding.
   143 	@SYMTestPriority 		Critical
   144 	@SYMTestActions			Read the audio capabilities of the playback channel. For each of the possible 3 audio 
   145 							encodings, issue a request on the playback channel to set this audio configuration.
   146 	@SYMTestExpectedResults	Either KErrNone if the playback channel supports the audio encoding, or
   147 							KErrNotSupported if the playback channel does not support the audio encoding. 
   148 	@SYMREQ					PREQ1073.4 */	
   149 		
   150 	Test.Next(_L("Try to set every possible encoding"));
   151 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   152 	for (i=0 ; i <= (TInt)ESoundEncoding24BitPCM ; i++)
   153 		{
   154 		PlayFormatBuf().iEncoding = (TSoundEncoding)i;
   155 		r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   156 		if (PlayCapsBuf().iEncodings & (1<<i))
   157 			{
   158 			CHECK_NOERROR(r);				// Caps reports it is supported
   159 			}					
   160 		else
   161 			{
   162 			CHECK(r==KErrNotSupported);		// Caps reports it is not supported
   163 			}		
   164 		}		
   165 		
   166 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-230
   167 	@SYMTestCaseDesc 		Setting the audio configuration - audio data format.
   168 	@SYMTestPriority 		Critical
   169 	@SYMTestActions			Read the audio capabilities of the playback channel. For each of the possible 2 audio data 
   170 							formats, issue a request on the playback channel to set this audio configuration.
   171 	@SYMTestExpectedResults	Either KErrNone if the playback channel supports the audio data format, or
   172 							KErrNotSupported if the playback channel does not support the audio data format. 
   173 	@SYMREQ					PREQ1073.4 */	
   174 	
   175 	Test.Next(_L("Try to set every possible data format"));
   176 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   177 	for (i=0 ; i <= (TInt)ESoundDataFormatNonInterleaved ; i++)
   178 		{
   179 		PlayFormatBuf().iDataFormat = (TSoundDataFormat)i;
   180 		r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   181 		if (PlayCapsBuf().iDataFormats & (1<<i))
   182 			{
   183 			CHECK_NOERROR(r);				// Caps reports it is supported
   184 			}					
   185 		else
   186 			{
   187 			CHECK(r==KErrNotSupported);		// Caps reports it is not supported
   188 			}		
   189 		}
   190 		
   191 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-231
   192 	@SYMTestCaseDesc 		Setting the audio configuration - altering the configuration while transferring data.
   193 	@SYMTestPriority 		Critical
   194 	@SYMTestActions			1)	Read the audio capabilities of the playback channel and apply a playback audio 
   195 								configuration that is supported by channel. Set the play buffer configuration and 
   196 								then start playing data from one of the buffers. While still playing, attempt to alter 
   197 								the audio configuration of the playback channel.
   198 							2)	Read the audio capabilities of the record channel and apply an audio record 
   199 								configuration that is supported by channel. Set the record buffer configuration and 
   200 								then start recording data into one of the buffers. While still recording, attempt 
   201 								to alter the audio configuration of the record channel.
   202 	@SYMTestExpectedResults	1)	Altering the audio configuration should fail with KErrInUse. 
   203 							2)	Altering the audio configuration should fail with KErrInUse.
   204 	@SYMREQ					PREQ1073.4 */
   205 		
   206 	Test.Next(_L("Try to alter the audio format while playing"));
   207 
   208 	// Set the audio configuration of the playback channel ready to start playing
   209 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   210 	if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
   211 		PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
   212 
   213 	PlayFormatBuf().iChannels = 2;
   214 	
   215 	// find first supported rate and set the the audio configuration to use it
   216 	TxSoundDevice.AudioFormat(PlayFormatBuf);	// Read back the current setting which must be valid.
   217 	for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
   218 		{
   219 		PlayFormatBuf().iRate = (TSoundRate)i;
   220 		r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   221 		if (PlayCapsBuf().iRates & (1<<i))
   222 			{
   223 			CHECK_NOERROR(r);				// Caps reports it is supported
   224 			break;
   225 			}					
   226 		}	
   227 	
   228 	PrintConfig(PlayFormatBuf(),Test);
   229 	r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   230 	CHECK_NOERROR(r);
   231 	
   232 	// Set the play buffer configuration.
   233 	RChunk chunk;
   234 	TInt bufSize=BytesPerSecond(PlayFormatBuf()); 										// Large enough to hold 1 second of data.
   235 	bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf());		// Keep the buffer length valid for driver.
   236 	TTestSharedChunkBufConfig bufferConfig;
   237 	bufferConfig.iNumBuffers=3;
   238 	bufferConfig.iBufferSizeInBytes=bufSize;
   239 	bufferConfig.iFlags=0;	
   240 	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   241 	r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   242 	CHECK_NOERROR(r);
   243 	TxSoundDevice.GetBufferConfig(bufferConfigBuf);
   244 	PrintBufferConf(bufferConfig,Test);
   245 	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
   246 	
   247 	// Start playing
   248 	r=MakeSineTable(PlayFormatBuf());
   249 	CHECK_NOERROR(r);
   250 	r=SetToneFrequency(660,PlayFormatBuf());
   251 	CHECK_NOERROR(r);
   252 	TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize);
   253 	WriteTone(ptr,PlayFormatBuf());
   254 	TRequestStatus stat;
   255 	TxSoundDevice.PlayData(stat,bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
   256 
   257 	// Check that altering the audio format while playing - fails
   258 	r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   259 	CHECK(r==KErrInUse);
   260 
   261 	User::WaitForRequest(stat);
   262 	CHECK_EQUAL(stat.Int(),KErrNone);
   263 	
   264 	Test.Next(_L("Try to alter the audio format while recording"));
   265 	
   266 	// Set the audio configuration of the record channel ready to start recording
   267 	RxSoundDevice.AudioFormat(RecordFormatBuf);	// Read back the current setting which must be valid.
   268 	if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
   269 		RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
   270 	RecordFormatBuf().iChannels = 2;
   271 
   272 	// find first supported rate and set the the audio configuration to use it
   273 	for (i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
   274 		{
   275 		RecordFormatBuf().iRate = (TSoundRate)i;
   276 		r=TxSoundDevice.SetAudioFormat(RecordFormatBuf);
   277 		if (RecordCapsBuf().iRates & (1<<i))
   278 			{
   279 			CHECK_NOERROR(r);				// Caps reports it is supported
   280 			break;
   281 			}					
   282 		}
   283 	
   284 	// Use the same shared chunk for recording
   285 	r=RxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk);
   286 	CHECK_NOERROR(r);
   287 	
   288 	// Start recording
   289 	TInt length;
   290 	RxSoundDevice.RecordData(stat,length);
   291 	
   292 	// Check that altering the audio format while recording - fails
   293 	r=RxSoundDevice.SetAudioFormat(RecordFormatBuf);
   294 	CHECK(r==KErrInUse);
   295 	
   296 	User::WaitForRequest(stat);
   297 	TInt retOffset=stat.Int();
   298 	CHECK(retOffset>=0);
   299 	CHECK(length>0);
   300 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   301 	CHECK_NOERROR(r);
   302 	
   303 	RxSoundDevice.CancelRecordData();	// Stop the driver from recording.
   304 	chunk.Close();
   305 	}
   306 
   307 LOCAL_C void TestSetBufferConfig(TInt aBufferConfigFlags)
   308 	{
   309 	
   310 	Test.Printf(_L("Testing setting the buffer configuration\r\n"));
   311 	
   312 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-232
   313 	@SYMTestCaseDesc 		Setting the buffer configuration - varying the number of buffers.
   314 	@SYMTestPriority 		Critical
   315 	@SYMTestActions			Issue a request on the playback channel to create a shared chunk (i.e. using 
   316 							SetBufferChunkCreate()) with a buffer configuration containing a single buffer. Attempt 
   317 							to open the same shared chunk on the record channel (i.e. using SetBufferChunkOpen()). 
   318 							Then close the chunk.
   319 							Repeat this same sequence using buffer configurations containing 2 - 8 buffers.
   320 	@SYMTestExpectedResults	In every case the attempt to create and open the shared chunk should return KErrNone. 
   321 	@SYMREQ					PREQ1073.4 */	
   322 	
   323 	Test.Next(_L("Test creating/opening a chunk, varying the number of buffers "));
   324 	TInt r;
   325 	RChunk chunk;
   326 	TTestSharedChunkBufConfig bufferConfig;
   327 	bufferConfig.iBufferSizeInBytes=0x7FE0;			// 32K - 32 bytes
   328 	if (PlayCapsBuf().iRequestMinSize)
   329 		bufferConfig.iBufferSizeInBytes&=~(PlayCapsBuf().iRequestMinSize-1); 	// Assumes iRequestMinSize is same for play and record
   330 	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   331 	
   332 	TInt i;
   333 	for (i=1 ; i<=8 ; i++)
   334 		{
   335 		bufferConfig.iFlags=aBufferConfigFlags;
   336 		bufferConfig.iNumBuffers=i;
   337 		
   338 		// Create the shared chunk on the play channel
   339 		r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   340 		CHECK_NOERROR(r);
   341 		TxSoundDevice.GetBufferConfig(bufferConfigBuf);
   342 		PrintBufferConf(bufferConfig,Test);
   343 		
   344 		// Open the same shared chunk on the record channel
   345 		r=RxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk);
   346 		CHECK_NOERROR(r);
   347 	
   348 		chunk.Close();
   349 		}
   350 		
   351 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-233
   352 	@SYMTestCaseDesc 		Setting the buffer configuration - varying the size of the buffers.
   353 	@SYMTestPriority 		Critical
   354 	@SYMTestActions			Issue a request on the playback channel to create a shared chunk (i.e. using 
   355 							SetBufferChunkCreate()) with a buffer configuration containing multiple buffers 
   356 							each of size 32K bytes. Attempt to open the same shared chunk on the record channel 
   357 							(i.e. using SetBufferChunkOpen()). Then close the chunk. Repeat this same sequence 
   358 							using buffer configurations containing buffers of size 16K, 8K and 4K bytes. 
   359 	@SYMTestExpectedResults	In every case the attempt to create and open the shared chunk should return KErrNone. 
   360 	@SYMREQ					PREQ1073.4 */		
   361 		
   362 	Test.Next(_L("Test creating/opening a chunk, varying the size of the buffers "));
   363 	bufferConfig.iNumBuffers=4;
   364 	
   365 	for (i=1 ; i<=8 ; i*=2)
   366 		{
   367 		bufferConfig.iFlags=aBufferConfigFlags;
   368 		bufferConfig.iBufferSizeInBytes=(0x8000/i);
   369 		
   370 		// Create the shared chunk on the play channel
   371 		r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   372 		CHECK_NOERROR(r);
   373 		TxSoundDevice.GetBufferConfig(bufferConfigBuf);
   374 		PrintBufferConf(bufferConfig,Test);
   375 		
   376 		// Open the same shared chunk on the record channel
   377 		r=RxSoundDevice.SetBufferChunkOpen(bufferConfigBuf,chunk);
   378 		CHECK_NOERROR(r);
   379 		
   380 		chunk.Close();
   381 		}
   382 		
   383 	// Try creating a shared chunk for the record channel specifying an illegal buffer size.
   384 	if (RecordCapsBuf().iRequestMinSize)
   385 		{
   386 		Test.Next(_L("Test creating a chunk, with an illegal buffer size"));
   387 		bufferConfig.iNumBuffers=1;
   388 		bufferConfig.iBufferSizeInBytes=0x1001;		// 4K + 1byte
   389 		bufferConfig.iFlags=aBufferConfigFlags;
   390 		r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   391 		CHECK(r==KErrArgument);
   392 		chunk.Close();		
   393 		}	
   394 			
   395 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-234
   396 	@SYMTestCaseDesc 		Setting the buffer configuration - specifying the buffer offsets.
   397 	@SYMTestPriority 		Critical
   398 	@SYMTestActions			Issue a request on the record channel to create a shared chunk (i.e. 
   399 							using SetBufferChunkCreate()) with an buffer configuration containing multiple buffers 
   400 							where the offset of each buffer is specified by the client. Perform this test repeatedly 
   401 							with buffer offsets specified as follows:-
   402 							1)	Valid buffer offsets
   403 							2)	Offsets resulting on overlapping  buffers
   404 							3)	Offsets which aren't aligned with the request alignment restrictions for the device (if it has any).
   405 	@SYMTestExpectedResults	1)	Setting the buffer configuration should return KErrNone. 
   406 							2)	Setting the buffer configuration should fail with KErrArgument.
   407 							3)	Setting the buffer configuration should fail with KErrArgument.
   408 	@SYMREQ					PREQ1073.4 */			
   409 /*		
   410 	// ***** Setting the buffer configuration - specifying the buffer offsets is not supported. *****
   411 	
   412 	Test.Next(_L("Test creating a chunk, specifying the buffer offsets"));
   413 	TInt bufSize=0x2000;
   414 	bufferConfig.iNumBuffers=8;
   415 	bufferConfig.iBufferSizeInBytes=bufSize;
   416 	bufferConfig.iBufferOffsetList[0]=0;
   417 	bufferConfig.iBufferOffsetList[1]=bufSize;
   418 	bufferConfig.iBufferOffsetList[2]=bufSize*4;
   419 	bufferConfig.iBufferOffsetList[3]=bufSize*6;
   420 	bufferConfig.iBufferOffsetList[4]=bufSize*7;
   421 	bufferConfig.iBufferOffsetList[5]=bufSize*9;
   422 	bufferConfig.iBufferOffsetList[6]=bufSize*10;
   423 	bufferConfig.iBufferOffsetList[7]=bufSize*12;
   424 	bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse);
   425 	bufferConfigBuf.SetLength(sizeof(bufferConfig));	// Otherwise set shorter by previous GetBufferConfig().
   426 	r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   427 	CHECK_NOERROR(r);
   428 	RxSoundDevice.GetBufferConfig(bufferConfigBuf);
   429 	PrintBufferConf(bufferConfig,Test);
   430 	chunk.Close();	
   431 	
   432 	Test.Next(_L("Test creating a chunk, with invalid buffer offsets specified"));
   433 	
   434 	// Firstly with 2nd buffer overlapping the 1st
   435 	bufSize=0x2000;
   436 	bufferConfig.iNumBuffers=3;
   437 	bufferConfig.iBufferSizeInBytes=bufSize;
   438 	bufferConfig.iBufferOffsetList[0]=0;
   439 	bufferConfig.iBufferOffsetList[1]=bufSize/2;
   440 	bufferConfig.iBufferOffsetList[2]=bufSize*2;
   441 	bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse);
   442 	r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   443 	CHECK(r==KErrArgument);
   444 	chunk.Close();	
   445 	
   446 	// Now with offset of 3rd buffer not on a page boundary
   447 	if (RecordCapsBuf().iRequestAlignment)
   448 		{
   449 		bufSize=0x2000;
   450 		bufferConfig.iNumBuffers=3;
   451 		bufferConfig.iBufferSizeInBytes=bufSize;
   452 		bufferConfig.iBufferOffsetList[0]=0;
   453 		bufferConfig.iBufferOffsetList[1]=bufSize;
   454 		bufferConfig.iBufferOffsetList[2]=(bufSize*2)+1;
   455 		bufferConfig.iFlags=(aBufferConfigFlags|KScFlagBufOffsetListInUse);
   456 		r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   457 		CHECK(r==KErrArgument);
   458 		chunk.Close();		
   459 		}
   460 */		
   461 	}
   462 
   463 LOCAL_C void TestPlay()
   464 	{
   465 	
   466 	Test.Printf(_L("Testing play operation\r\n"));
   467 	
   468 	// Close and re-open the playback channel to reset the driver.
   469 	TxSoundDevice.Close();
   470 	TInt r = TxSoundDevice.Open(KSoundScTxUnit0);
   471 	CHECK_NOERROR(r);
   472 	
   473 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-235
   474 	@SYMTestCaseDesc 		Play operation - playing without having set the buffer configuration.
   475 	@SYMTestPriority 		Critical
   476 	@SYMTestActions			Issue a request on the playback channel to play some audio data before having set-up 
   477 							the buffer configuration.
   478 	@SYMTestExpectedResults	The play request should fail with KErrNotReady.
   479 	@SYMREQ					PREQ1073.4 */			
   480 	
   481 	Test.Next(_L("Test playing without setting buffer config"));
   482 	TRequestStatus stat[2];
   483 	TxSoundDevice.PlayData(stat[0],0,0x2000);	// 8K
   484 	User::WaitForRequest(stat[0]);
   485 	CHECK_EQUAL(stat[0].Int(),KErrNotReady);
   486 	
   487 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-236
   488 	@SYMTestCaseDesc 		Play operation - playing without having set the audio configuration.
   489 	@SYMTestPriority 		Critical
   490 	@SYMTestActions			Setup the buffer configuration on the playback channel and then issue a request to 
   491 							play audio data before having set-up the audio configuration
   492 	@SYMTestExpectedResults	The play request should complete with KErrNone - with the driver using its default 
   493 							audio configuration for the transfer.
   494 	@SYMREQ					PREQ1073.4 */	
   495 	
   496 	Test.Next(_L("Test playing without setting audio config"));
   497 	
   498 	// Read back the default play configuration
   499 	TxSoundDevice.AudioFormat(PlayFormatBuf);
   500 	TCurrentSoundFormatV02 playFormat=PlayFormatBuf();
   501 	PrintConfig(playFormat,Test);
   502 	
   503 	// Set the play buffer configuration.
   504 	RChunk chunk;
   505 	TInt bufSize=BytesPerSecond(PlayFormatBuf()); 										// Large enough to hold 1 second of data.
   506 	bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf());		// Keep the buffer length valid for driver.
   507 	TTestSharedChunkBufConfig bufferConfig;
   508 	bufferConfig.iNumBuffers=1;
   509 	bufferConfig.iBufferSizeInBytes=bufSize;
   510 	bufferConfig.iFlags=0;	
   511 	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   512 	r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   513 	CHECK_NOERROR(r);
   514 	TxSoundDevice.GetBufferConfig(bufferConfigBuf);
   515 	PrintBufferConf(bufferConfig,Test);
   516 	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
   517 	
   518 	// Start playing
   519 	r=MakeSineTable(PlayFormatBuf());
   520 	CHECK_NOERROR(r);
   521 	r=SetToneFrequency(660,PlayFormatBuf());
   522 	CHECK_NOERROR(r); 
   523 	TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize);
   524 	WriteTone(ptr,PlayFormatBuf());
   525 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
   526 	User::WaitForRequest(stat[0]);
   527 	CHECK_NOERROR(stat[0].Int());
   528 	
   529 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-239
   530 	@SYMTestCaseDesc 		Play operation - with invalid arguments.
   531 	@SYMTestPriority 		Critical
   532 	@SYMTestActions			Setup the playback channel to commence playing audio data using a buffer configuration 
   533 							containing multiple buffers. Now issue a series of transfer requests to play data where the 
   534 							requests contain invalid request arguments as follows:-
   535 							1)	A request with a buffer offset before the start of the first buffer.
   536 							2)	A request with a buffer offset between buffers.
   537 							3)	A request with a length too large for a buffer.
   538 							4)	A request with a buffer offset that doesn't comply with the offset restrictions of 
   539 								the driver (i.e. TSoundFormatsSupportedV02:: iRequestAlignment).
   540 							5)	A request with a length that doesn't comply with the length restrictions of 
   541 								the driver (i.e. TSoundFormatsSupportedV02::iRequestMinSize).
   542 	@SYMTestExpectedResults	1)	The play request should fail with KErrArgument.
   543 							2)	The play request should fail with KErrArgument.
   544 							3)	The play request should fail with KErrArgument.
   545 							4)	The play request should fail with KErrArgument.
   546 							5)	The play request should fail with KErrArgument
   547 	@SYMREQ					PREQ1073.4 */	
   548 	
   549 	Test.Next(_L("Test playing with invalid arguments"));
   550 	
   551 	// With a buffer offset before the start of the buffer.
   552 	TxSoundDevice.PlayData(stat[0],(bufferConfig.iBufferOffsetList[0]-0x100),bufSize,KSndFlagLastSample);
   553 	User::WaitForRequest(stat[0]);
   554 	CHECK_EQUAL(stat[0].Int(),KErrArgument);
   555 	
   556 	// With a buffer offset beyond the end of the buffer
   557 	TxSoundDevice.PlayData(stat[0],(bufferConfig.iBufferOffsetList[0]+bufSize+0x100),bufSize,KSndFlagLastSample);
   558 	User::WaitForRequest(stat[0]);
   559 	CHECK_EQUAL(stat[0].Int(),KErrArgument);
   560 	
   561 	// With a length too large for the buffer
   562 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],(bufSize+0x100),KSndFlagLastSample);
   563 	User::WaitForRequest(stat[0]);
   564 	CHECK_EQUAL(stat[0].Int(),KErrArgument);
   565 	
   566 	// With a length that doesn't comply with the length restrictions of the driver
   567 	if (PlayCapsBuf().iRequestMinSize)
   568 		{
   569 		TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],(bufSize-1),KSndFlagLastSample);
   570 		User::WaitForRequest(stat[0]);
   571 		CHECK_EQUAL(stat[0].Int(),KErrArgument);
   572 		}
   573 		
   574 	// With an offset that doesn't comply with the offset restrictions of the driver
   575 	if (PlayCapsBuf().iRequestAlignment)
   576 		{
   577 		TInt ln=bufSize/2;
   578 		if (PlayCapsBuf().iRequestMinSize)
   579 			ln&=~(PlayCapsBuf().iRequestMinSize-1);	// Keep the buffer length valid for the driver.
   580 		TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0]+1,ln,KSndFlagLastSample);
   581 		User::WaitForRequest(stat[0]);
   582 		CHECK_EQUAL(stat[0].Int(),KErrArgument);
   583 		}	
   584 		
   585 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-242
   586 	@SYMTestCaseDesc 		Play operation - play underflow detection.
   587 	@SYMTestPriority 		Critical
   588 	@SYMTestActions			Setup the audio configuration on the playback channel and then setup the buffer 
   589 							configuration. Issue a single request to play audio data from one of the buffers 
   590 							(without supplying the KSndFlagLastSample flag) and wait for the request to complete.
   591 	@SYMTestExpectedResults	The driver should successfully play the audio data supplied but the request should 
   592 							return the error value: KErrUnderflow.
   593 	@SYMREQ					PREQ1073.4 */		
   594 	
   595 	Test.Next(_L("Test play underflow detection"));
   596 	
   597 	// Now set the audio configuration to a known state.
   598 	if (PlayCapsBuf().iEncodings&KSoundEncoding16BitPCM)
   599 		PlayFormatBuf().iEncoding = ESoundEncoding16BitPCM;
   600 	if (PlayCapsBuf().iRates&KSoundRate16000Hz)
   601 		PlayFormatBuf().iRate = ESoundRate16000Hz;
   602 	if (PlayCapsBuf().iChannels&KSoundStereoChannel)
   603 		PlayFormatBuf().iChannels = 2;
   604 	PrintConfig(PlayFormatBuf(),Test);
   605 	r=TxSoundDevice.SetAudioFormat(PlayFormatBuf);
   606 	CHECK_NOERROR(r);
   607 	
   608 	// Reset the play buffer configuration to correspond to the audio configuration.
   609 	bufSize=BytesPerSecond(PlayFormatBuf()); 											// Large enough to hold 1 second of data (64K)
   610 	bufSize=ValidBufferSize(bufSize,PlayCapsBuf().iRequestMinSize,PlayFormatBuf());		// Keep the buffer length valid for driver.
   611 	bufferConfig.iNumBuffers=1;
   612 	bufferConfig.iBufferSizeInBytes=bufSize;
   613 	bufferConfig.iFlags=0;	
   614 	r=TxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   615 	CHECK_NOERROR(r);
   616 	TxSoundDevice.GetBufferConfig(bufferConfigBuf);
   617 	PrintBufferConf(bufferConfig,Test);
   618 	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
   619 	
   620 	// Start playing
   621 	r=MakeSineTable(PlayFormatBuf());
   622 	CHECK_NOERROR(r);
   623 	r=SetToneFrequency(660,PlayFormatBuf());
   624 	CHECK_NOERROR(r); 
   625 	ptr.Set(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize,bufSize);
   626 	WriteTone(ptr,PlayFormatBuf());
   627 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize);
   628 	User::WaitForRequest(stat[0]);
   629 	CHECK_EQUAL(stat[0].Int(),KErrUnderflow);
   630 	
   631 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-243
   632 	@SYMTestCaseDesc 		Play operation - playing multiple transfers from a single buffer.
   633 	@SYMTestPriority 		Critical
   634 	@SYMTestActions			Setup the audio configuration on the playback channel and setup the buffer configuration 
   635 							so the shared chunk contains just a single large buffer. Issue a pair of requests to play 
   636 							audio data from the buffer (marking the last with the KSndFlagLastSample flag) and wait 
   637 							for the requests to complete.
   638 	@SYMTestExpectedResults	The driver should successfully play the audio data supplied and both requests should 
   639 							complete with KErrNone.
   640 	@SYMREQ					PREQ1073.4 */	
   641 	
   642 	Test.Next(_L("Test playing multiple transfers from a single buffer"));
   643 	
   644 	// Start playing
   645 	TInt len=bufSize/2;
   646 	if (PlayCapsBuf().iRequestMinSize)
   647 		len&=~(PlayCapsBuf().iRequestMinSize-1);	// Keep the buffer length valid for the driver.
   648 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len);
   649 	TxSoundDevice.PlayData(stat[1],(bufferConfig.iBufferOffsetList[0]+len),len,KSndFlagLastSample);
   650 	bool brokenByPaging = false;
   651 	if((stat[0] != KRequestPending) || (stat[1] != KRequestPending))
   652 		{
   653 		brokenByPaging = true;
   654 		Test.Printf(_L("Paging gap between PlayData calls - skipping test\n"));
   655 		}
   656 	User::WaitForRequest(stat[0]);
   657 	if(!brokenByPaging) CHECK_NOERROR(stat[0].Int());
   658 	User::WaitForRequest(stat[1]);
   659 	if(!brokenByPaging) CHECK_NOERROR(stat[1].Int());
   660 	
   661 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-244
   662 	@SYMTestCaseDesc 		Play operation - tracking the count of bytes transferred.
   663 	@SYMTestPriority 		Critical
   664 	@SYMTestActions			Setup the playback channel for playing audio data. 
   665 							1)	Reset the channel's count of bytes transferred and read back the count.
   666 							2)	Issue a play request of known length and wait for it to complete. Now read the 
   667 								count of bytes transferred.
   668 							3)	Reset the channel's count of bytes transferred and read back the count.
   669 	@SYMTestExpectedResults	1)	The count of bytes transferred should equal zero.
   670 							2)	The count of bytes transferred should equal the length of the play request.
   671 							3)	The count of bytes transferred should equal zero.
   672 	@SYMREQ					PREQ1073.4 */
   673 	
   674 	Test.Next(_L("Test tracking the number of bytes played"));
   675 	TxSoundDevice.ResetBytesTransferred();
   676 	TInt bytesPlayed=TxSoundDevice.BytesTransferred();
   677 	CHECK(bytesPlayed==0);
   678 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len,KSndFlagLastSample);
   679 	User::WaitForRequest(stat[0]);
   680 	CHECK_NOERROR(stat[0].Int());
   681 	bytesPlayed=TxSoundDevice.BytesTransferred();
   682 	CHECK(bytesPlayed==len);
   683 	TxSoundDevice.ResetBytesTransferred();
   684 	bytesPlayed=TxSoundDevice.BytesTransferred();
   685 	CHECK(bytesPlayed==0);
   686 	
   687 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-246
   688 	@SYMTestCaseDesc 		Play operation - testing the driver's handling of PDD play errors.
   689 	@SYMTestPriority 		Critical
   690 	@SYMTestActions			Setup the playback channel for playing audio data. Using the CustomConfig() test mode 
   691 							supported by the driver, induce the following errors returned from the driver PDD back 
   692 							to the LDD:-
   693 								1)	Induce a KErrTimedOut error at the start of the transfer and then issue a play request.
   694 								2)	Induce a KErrTimedOut error once transfer has commenced and then issue a play request. 
   695 								Once this completes, issue a further play request.
   696 	@SYMTestExpectedResults	1)	The play request should fail immediately with KErrTimedOut (with no audible output being 
   697 								heard).
   698 							2)	The driver should output a short section of audible data before the first play request 
   699 								fails with KErrTimedOut. However, the driver should recover from this and the second 
   700 								play request should complete with KErrNone.
   701 	@SYMREQ					PREQ1073.4 */
   702 	
   703 #ifdef _DEBUG	
   704 	Test.Next(_L("Test the driver's handling of PDD play errors"));
   705 	
   706 	// First induce an error at the start of the transfer
   707 	// Use an LDD test mode which induces KErrTimedOut at the start of the transfer.
   708 	r=TxSoundDevice.CustomConfig(KSndCustom_ForceStartTransferError);
   709 	CHECK_NOERROR(r);
   710 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
   711 	User::WaitForRequest(stat[0]);
   712 	CHECK_EQUAL(stat[0].Int(),KErrTimedOut);
   713 	
   714 	// Now induce an error once transfer has commenced
   715 	// Use an LDD test mode which induces KErrTimedOut once transfer has commenced.
   716 	r=TxSoundDevice.CustomConfig(KSndCustom_ForceTransferDataError);
   717 	CHECK_NOERROR(r);
   718 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
   719 	User::WaitForRequest(stat[0]);
   720 	CHECK_EQUAL(stat[0].Int(),KErrTimedOut);
   721 	
   722 	// Check that the driver recovers
   723 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
   724 	User::WaitForRequest(stat[0]);
   725 	CHECK_NOERROR(stat[0].Int());
   726 #endif	
   727 	
   728 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-247
   729 	@SYMTestCaseDesc 		Play operation - closing the channel cancels any play requests.
   730 	@SYMTestPriority 		Critical
   731 	@SYMTestActions			Setup the playback channel for playing audio data. Issue a play request and 
   732 							while this is outstanding, close the playback channel.
   733 	@SYMTestExpectedResults	The outstanding request should complete with KErrCancel.
   734 	@SYMREQ					PREQ1073.4 */
   735 	
   736 	Test.Next(_L("Test that closing the channel cancels a play request"));
   737 	TxSoundDevice.PlayData(stat[0],bufferConfig.iBufferOffsetList[0],len,KSndFlagLastSample);
   738 	CHECK(stat[0]==KRequestPending);
   739 	TxSoundDevice.Close();
   740 	User::WaitForRequest(stat[0]);
   741 	CHECK(stat[0]==KErrCancel);
   742 	
   743 	Test.Next(_L("Re-open the channel"));
   744 	r = TxSoundDevice.Open(KSoundScTxUnit0);
   745 	CHECK_NOERROR(r);
   746 	
   747 	chunk.Close();
   748 	}
   749 	
   750 LOCAL_C void TestRecord()
   751 	{
   752 	
   753 	Test.Printf(_L("Testing record operation\r\n"));
   754 	
   755 	// Close and re-open the record channel to reset the driver.
   756 	RxSoundDevice.Close();
   757 	TInt r = RxSoundDevice.Open(KSoundScRxUnit0);
   758 	CHECK_NOERROR(r);
   759 	
   760 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-251
   761 	@SYMTestCaseDesc 		Record operation - recording without having set the buffer configuration.
   762 	@SYMTestPriority 		Critical
   763 	@SYMTestActions			Issue a request on the record channel to record some audio data before 
   764 							having set-up the buffer configuration.
   765 	@SYMTestExpectedResults	The record request should fail with KErrNotReady.
   766 	@SYMREQ					PREQ1073.4 */
   767 	
   768 	Test.Next(_L("Test recording without setting buffer config"));
   769 	
   770 	TRequestStatus stat;
   771 	TInt length;
   772 	RxSoundDevice.RecordData(stat,length);
   773 	User::WaitForRequest(stat);
   774 	TInt retOffset=stat.Int();
   775 	CHECK_EQUAL(retOffset,KErrNotReady);
   776 	
   777 	// Test releasing a buffer without setting buffer config
   778 	r=RxSoundDevice.ReleaseBuffer(0);
   779 	CHECK(r==KErrNotReady);
   780 	
   781 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-252
   782 	@SYMTestCaseDesc 		Record operation - recording without having set the audio configuration.
   783 	@SYMTestPriority 		Critical
   784 	@SYMTestActions			Setup the buffer configuration on the record channel. 
   785 							1)	Issue a request to record a buffer of audio data before having set-up the audio 
   786 								configuration.
   787 							2)	Release the buffer.
   788 	@SYMTestExpectedResults	1)	The record request should complete with KErrNone - with the driver using its 
   789 								default audio configuration for the transfer.
   790 							2)	The request to release the buffer should return KErrNone
   791 	@SYMREQ					PREQ1073.4 */
   792 	
   793 	Test.Next(_L("Test recording without setting audio config"));
   794 	
   795 	// Read back the default record configuration
   796 	RxSoundDevice.AudioFormat(RecordFormatBuf);
   797 	TCurrentSoundFormatV02 recordFormat=RecordFormatBuf();
   798 	PrintConfig(recordFormat,Test);
   799 	
   800 	// Set the record buffer configuration.
   801 	RChunk chunk;
   802 	TInt bufSize=BytesPerSecond(RecordFormatBuf()); 										// Large enough to hold 1 second of data.
   803 	bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf());		// Keep the buffer length valid for driver.
   804 	TTestSharedChunkBufConfig bufferConfig;
   805 	bufferConfig.iNumBuffers=3;
   806 	bufferConfig.iBufferSizeInBytes=bufSize;
   807 	bufferConfig.iFlags=0;	
   808 	TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   809 	r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   810 	CHECK_NOERROR(r);
   811 	RxSoundDevice.GetBufferConfig(bufferConfigBuf);
   812 	PrintBufferConf(bufferConfig,Test);
   813 	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
   814 	
   815 	// Start recording
   816 	RxSoundDevice.SetVolume(KSoundMaxVolume);
   817 	RxSoundDevice.RecordData(stat,length);		// Start recording here
   818 	User::WaitForRequest(stat);
   819 	retOffset=stat.Int();
   820 	CHECK(retOffset>=0);
   821 	CHECK(length==bufSize);
   822 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   823 	CHECK_NOERROR(r);
   824 	
   825 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-255
   826 	@SYMTestCaseDesc 		Record operation - invalid attempts to release a record buffer.
   827 	@SYMTestPriority 		Critical
   828 	@SYMTestActions			Setup the record channel to record audio data. Issue a request to record a buffer of audio data
   829 							and then release the buffer.
   830 							1)	Request to release the same buffer just released (without having re-claimed it with a 
   831 								further record request).
   832 							2)	Release a further buffer - specifying an illegal buffer offset for the buffer.
   833 							3)	Stop the driver from recording (using CancelRecordData()). Now release a buffer while 
   834 								recording is disabled.
   835 	@SYMTestExpectedResults	1)	The request to release the buffer should fail with KErrNotFound.
   836 							2)	The request to release the buffer should fail with KErrNotFound.
   837 							3)	The request to release the buffer should fail with KErrNotFound.
   838 	@SYMREQ					PREQ1073.4 */
   839 	
   840 	// Test releasing a buffer twice
   841 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   842 	CHECK(r==KErrNotFound);
   843 	
   844 	// Test releasing an invalid buffer offset
   845 	r=RxSoundDevice.ReleaseBuffer(0);
   846 	CHECK(r==KErrNotFound);
   847 	
   848 	// Third test case for PBASE-T_SOUND_API-255 is performed later in this function.
   849 	
   850 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-256
   851 	@SYMTestCaseDesc 		Record operation - record overflow detection.
   852 	@SYMTestPriority 		Critical
   853 	@SYMTestActions			Setup the audio configuration on the record channel and then setup the buffer configuration 
   854 							so the shared chunk contains three record buffers.
   855 							1)	Issue a request to record a buffer of audio data (to start the driver recording).
   856 							2)	When the request completes, release the buffer immediately.
   857 							3)	Wait just over 2 buffer periods (i.e. the time it takes for the driver to fill 2 record 
   858 								buffers) and then issue a further record request.
   859 							4)	To test that the driver recovers from the overflow situation, immediately issue a further 
   860 								record request. 
   861 	@SYMTestExpectedResults	1)	The record request should complete with KErrNone.
   862 							2)	The request to release the buffer should return KErrNone.
   863 							3)	The record request should fail with KErrOverflow.
   864 							4)	The record request should complete with KErrNone.
   865 	@SYMREQ					PREQ1073.4 */
   866 	
   867 	Test.Next(_L("Test for record overflow"));
   868 
   869 	// Now set the audio configuration to a known state.
   870 	RxSoundDevice.CancelRecordData();	// Stop the driver from recording.
   871 
   872 	RxSoundDevice.AudioFormat(RecordFormatBuf);	// Read back the current setting which must be valid.
   873 	if (RecordCapsBuf().iEncodings&KSoundEncoding16BitPCM)
   874 		RecordFormatBuf().iEncoding = ESoundEncoding16BitPCM;
   875 	if (RecordCapsBuf().iChannels&KSoundStereoChannel)
   876 		RecordFormatBuf().iChannels = 2;
   877 
   878 	// find first supported rate and set the the audio configuration to use it
   879 	for (TInt i=0 ; i <= (TInt)ESoundRate48000Hz ; i++)
   880 		{
   881 		RecordFormatBuf().iRate = (TSoundRate)i;
   882 		r = RxSoundDevice.SetAudioFormat(RecordFormatBuf);
   883 		if (RecordCapsBuf().iRates & (1<<i))
   884 			{
   885 			CHECK_NOERROR(r);				// Caps reports it is supported
   886 			break;
   887 			}					
   888 		}
   889 
   890 	PrintConfig(RecordFormatBuf(),Test);
   891 	
   892 	// Reset the record buffer configuration to correspond to the audio configuration.
   893 	bufSize=BytesPerSecond(RecordFormatBuf())/2; 	 										// Large enough to hold 0.5 seconds of data (64K)
   894 	bufSize=ValidBufferSize(bufSize,RecordCapsBuf().iRequestMinSize,RecordFormatBuf());		// Keep the buffer length valid for driver.
   895 	bufferConfig.iNumBuffers=3;
   896 	bufferConfig.iBufferSizeInBytes=bufSize;
   897 	bufferConfig.iFlags=0;	
   898 	r=RxSoundDevice.SetBufferChunkCreate(bufferConfigBuf,chunk);
   899 	CHECK_NOERROR(r);
   900 	RxSoundDevice.GetBufferConfig(bufferConfigBuf);
   901 	PrintBufferConf(bufferConfig,Test);
   902 	CHECK(bufferConfig.iBufferSizeInBytes==bufSize);
   903 	
   904 	// Test releasing a buffer before we have started recording
   905 	r=RxSoundDevice.ReleaseBuffer(bufferConfig.iBufferOffsetList[0]);
   906 	CHECK(r==KErrNotFound);
   907 	
   908 	RxSoundDevice.RecordData(stat,length);	// Start recording here
   909 	User::WaitForRequest(stat);
   910 	retOffset=stat.Int();
   911 	CHECK(retOffset>=0);
   912 	CHECK(length==bufSize);
   913 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   914 	CHECK_NOERROR(r);
   915 	
   916 	User::After(1100000); // Wait 2 buffer periods (1.1 seconds) for data overflow. 
   917 	
   918 	RxSoundDevice.RecordData(stat,length);
   919 	User::WaitForRequest(stat);
   920 	retOffset=stat.Int();
   921 	CHECK(retOffset==KErrOverflow);
   922 	
   923 	Test.Next(_L("Test that the driver recovers from overflow"));
   924 	
   925 	RxSoundDevice.RecordData(stat,length);
   926 	User::WaitForRequest(stat);
   927 	retOffset=stat.Int();
   928 	CHECK(retOffset>=0);
   929 	CHECK(length==bufSize);
   930 	
   931 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-257
   932 	@SYMTestCaseDesc 		Record operation - when client is too slow releasing buffers.
   933 	@SYMTestPriority 		Critical
   934 	@SYMTestActions			Setup the audio configuration on the record channel and then setup the buffer configuration 
   935 							so the shared chunk contains three record buffers. Issue a request to record a buffer of 
   936 							audio data (to start the driver recording). When this request completes, issue a further 
   937 							record request without releasing the first buffer.
   938 	@SYMTestExpectedResults	The second record request should fail with KErrInUse.
   939 	@SYMREQ					PREQ1073.4 */
   940 	
   941 	Test.Next(_L("Test when client is too slow releasing buffers"));
   942 	
   943 	RxSoundDevice.RecordData(stat,length);
   944 	User::WaitForRequest(stat);
   945 	TInt retOffset1=stat.Int();
   946 	CHECK(retOffset1==KErrInUse);	
   947 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   948 	CHECK_NOERROR(r);
   949 	
   950 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-258
   951 	@SYMTestCaseDesc 		Record operation - tracking the count of bytes transferred.
   952 	@SYMTestPriority 		Critical
   953 	@SYMTestActions			Setup the record channel for recording audio data. 
   954 							1)	Reset the channel's count of bytes transferred and read back the count.
   955 							2)	Issue a record request (to start the driver recording) and wait for it to complete. Immediately read the count of bytes transferred.
   956 							3)	Reset the channel's count of bytes transferred and read back the count
   957 	@SYMTestExpectedResults	1)	The count of bytes transferred should equal zero.
   958 							2)	The count of bytes transferred should equal the size of a record buffer.
   959 							3)	The count of bytes transferred should equal zero.
   960 	@SYMREQ					PREQ1073.4 */
   961 	
   962 	Test.Next(_L("Test tracking the number of bytes recorded"));
   963 	RxSoundDevice.CancelRecordData();				// Stop the driver from recording.
   964 	RxSoundDevice.ResetBytesTransferred();
   965 	TInt bytesRecorded=RxSoundDevice.BytesTransferred();
   966 	CHECK(bytesRecorded==0);
   967 	RxSoundDevice.RecordData(stat,length);			// Re-start recording here
   968 	User::WaitForRequest(stat);
   969 	
   970 	// Quickly check the number of bytes recorded
   971 	bytesRecorded=RxSoundDevice.BytesTransferred();
   972 	CHECK(bytesRecorded==bufSize);
   973 	
   974 	// Now check the request was successful and release the buffer
   975 	retOffset=stat.Int();
   976 	CHECK(retOffset>=0);
   977 	CHECK(length==bufSize);
   978 	r=RxSoundDevice.ReleaseBuffer(retOffset);
   979 	CHECK_NOERROR(r);
   980 	
   981 	RxSoundDevice.ResetBytesTransferred();
   982 	bytesRecorded=RxSoundDevice.BytesTransferred();
   983 	CHECK(bytesRecorded==0);
   984 	
   985 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-260
   986 	@SYMTestCaseDesc 		Record operation - testing the driver's handling of PDD record errors.
   987 	@SYMTestPriority 		Critical
   988 	@SYMTestActions			Setup the record channel for recording. Using the CustomConfig() test mode supported by the driver, induce 
   989 							the following errors returned from the driver PDD back to the LDD:-
   990 							1)	Induce a KErrTimedOut error at the start of the transfer. Then, issue a record request to 
   991 								start the driver recording. Once this completes, stop the channel from recording. 
   992 							2)	Induce a KErrTimedOut error once transfer has commenced. Then, issue a record request to 
   993 								re-start the driver recording. Once this completes, issue a further record request.
   994 	@SYMTestExpectedResults	1)	The record request should fail immediately with KErrTimedOut. 
   995 							2)	The first record request should soon fail with KErrTimedOut. However, the driver should 
   996 								recover from this and the subsequent record request should complete with KErrNone.
   997 	@SYMREQ					PREQ1073.4 */
   998 	
   999 #ifdef _DEBUG	
  1000 	Test.Next(_L("Test the driver's handling of PDD record errors"));
  1001 	
  1002 	Test.Printf(_L("Induce an error at the start of the transfer.\r\n"));
  1003 	// Use an LDD test mode which induces KErrTimedOut at the start of the transfer.
  1004 	RxSoundDevice.CancelRecordData();				// Stop the driver from recording.
  1005 	r=RxSoundDevice.CustomConfig(KSndCustom_ForceStartTransferError);
  1006 	CHECK_NOERROR(r);
  1007 	RxSoundDevice.RecordData(stat,length);			// Re-start recording here
  1008 	User::WaitForRequest(stat);
  1009 	retOffset=stat.Int();
  1010 	CHECK(retOffset==KErrTimedOut);
  1011 	RxSoundDevice.CancelRecordData();				// Stop the driver from recording.
  1012 	
  1013 	Test.Printf(_L("Induce an error once transfer has commenced.\r\n"));
  1014 	// Use an LDD test mode which induces KErrTimedOut once transfer has commenced.
  1015 	r=RxSoundDevice.CustomConfig(KSndCustom_ForceTransferDataError);
  1016 	CHECK_NOERROR(r);
  1017 	RxSoundDevice.RecordData(stat,length);			// Re-start recording here
  1018 	User::WaitForRequest(stat);
  1019 	retOffset=stat.Int();
  1020 	CHECK(retOffset==KErrTimedOut);
  1021 	
  1022 	Test.Printf(_L("Check that the driver recovers.\r\n"));
  1023 	RxSoundDevice.RecordData(stat,length);
  1024 	User::WaitForRequest(stat);
  1025 	retOffset=stat.Int();
  1026 	CHECK(retOffset>=0);
  1027 	CHECK(length==bufSize);
  1028 	r=RxSoundDevice.ReleaseBuffer(retOffset);
  1029 	CHECK_NOERROR(r);
  1030 	
  1031 /*	Test disabled 	
  1032 	Test.Printf(_L("Induce LDD to be slow servicing transfer completes from PDD.\r\n"));
  1033 	r=RxSoundDevice.CustomConfig(KSndCustom_ForceTransferTimeout);
  1034 	CHECK_NOERROR(r);
  1035 	RxSoundDevice.RecordData(stat,length);
  1036 	User::WaitForRequest(stat);
  1037 	retOffset=stat.Int();
  1038 	Test.Printf(_L("Driver returned %d.\r\n"),retOffset); */
  1039 #endif	
  1040 	
  1041 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-261
  1042 	@SYMTestCaseDesc 		Record operation - closing the channel cancels any record requests.
  1043 	@SYMTestPriority 		Critical
  1044 	@SYMTestActions			Start the record channel for recording audio data. Issue a record request and while this is 
  1045 							outstanding, close the record channel
  1046 	@SYMTestExpectedResults	The outstanding request should complete with KErrCancel.
  1047 	@SYMREQ					PREQ1073.4 */
  1048 	
  1049 	Test.Next(_L("Test that closing the channel cancels a play request"));
  1050 	RxSoundDevice.RecordData(stat,length);
  1051 	CHECK(stat==KRequestPending);
  1052 	RxSoundDevice.Close();
  1053 	User::WaitForRequest(stat);
  1054 	CHECK(stat==KErrCancel);
  1055 	
  1056 	Test.Next(_L("Re-open the channel"));
  1057 	r = RxSoundDevice.Open(KSoundScRxUnit0);
  1058 	CHECK_NOERROR(r);
  1059 	
  1060 	chunk.Close();
  1061 	}
  1062 
  1063 #ifdef _DEBUG
  1064 LOCAL_C void TestChangeOfHwConfigNotifier()
  1065 	{
  1066 	
  1067 	Test.Printf(_L("Testing the change of h/w config notifier\r\n"));
  1068 	
  1069 	// If support for the notifier is not supported on this platform, use a debug custom config command to force
  1070 	// support for the notifier.
  1071 	TInt r;
  1072 	if (!PlayCapsBuf().iHwConfigNotificationSupport)
  1073 		{
  1074 		r=TxSoundDevice.CustomConfig(KSndCustom_ForceHwConfigNotifSupported);
  1075 		CHECK_NOERROR(r);
  1076 		}
  1077 		
  1078 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-264
  1079 	@SYMTestCaseDesc 		Change of h/w config. notifier - receiving notification.
  1080 	@SYMTestPriority 		Critical
  1081 	@SYMTestActions			1)	Register for notification of a change in the hardware configuration of the device on 
  1082 								either the record or playback channel. Using the CustomConfig() test mode supported by the 
  1083 								driver, trigger the notifier - signalling that the headset is not present.
  1084 							2) 	Re-register for notification of a change in the hardware configuration on the same channel.
  1085 								Again using the CustomConfig() test mode, trigger the notifier - this time signalling that the 
  1086 								headset is present.
  1087 	@SYMTestExpectedResults	1)	The outstanding request for notification should complete with KErrNone and the status of 
  1088 								the bolean aHeadsetPresent should be false.
  1089 							2)	The outstanding request for notification should complete with KErrNone and the status of
  1090 								the bolean aHeadsetPresent should be true.
  1091 	@SYMREQ					PREQ1073.4 */	
  1092 	
  1093 	// Register for notification of a change in the hardware configuration of the device.
  1094 	TRequestStatus stat;
  1095 	TBool headsetPresent=ETrue;
  1096 	TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent);
  1097 	CHECK(stat==KRequestPending);
  1098 	
  1099 	Test.Next(_L("Trigger the notifier"));
  1100 	// Use another debug custom config command to trigger the notifier.
  1101 	r=TxSoundDevice.CustomConfig(KSndCustom_CompleteChangeOfHwConfig,(TAny*)0x00);	// Signal headset not present.
  1102 	CHECK_NOERROR(r);
  1103 	User::WaitForRequest(stat);
  1104 	CHECK_NOERROR(stat.Int());
  1105 	CHECK(!headsetPresent);
  1106 	
  1107 	Test.Next(_L("Trigger the notifier again"));
  1108 	TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent);
  1109 	CHECK(stat==KRequestPending);
  1110 	r=TxSoundDevice.CustomConfig(KSndCustom_CompleteChangeOfHwConfig,(TAny*)0x01);	// Signal headset is present.
  1111 	CHECK_NOERROR(r);
  1112 	User::WaitForRequest(stat);
  1113 	CHECK_NOERROR(stat.Int());
  1114 	CHECK(headsetPresent);
  1115 	
  1116 	Test.Next(_L("Test cancelling the notifier"));
  1117 	TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent);
  1118 	CHECK(stat==KRequestPending);
  1119 	TxSoundDevice.CancelNotifyChangeOfHwConfig();
  1120 	User::WaitForRequest(stat);
  1121 	CHECK(stat==KErrCancel);
  1122 	
  1123 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-265
  1124 	@SYMTestCaseDesc 		Change of h/w config. notifier - receiving notification.
  1125 	@SYMTestPriority 		Critical
  1126 	@SYMTestActions			1)	Register for notification of a change in the hardware configuration of the device on 
  1127 								either the record or playback channel. Using the CustomConfig() test mode supported by the 
  1128 								driver, trigger the notifier - signalling that the headset is not present.
  1129 							2) 	Re-register for notification of a change in the hardware configuration on the same channel.
  1130 								Again using the CustomConfig() test mode, trigger the notifier - this time signalling that the 
  1131 								headset is present.
  1132 	@SYMTestExpectedResults	1)	The outstanding request for notification should complete with KErrNone and the status of 
  1133 								the bolean aHeadsetPresent should be false.
  1134 							2)	The outstanding request for notification should complete with KErrNone and the status of
  1135 								the bolean aHeadsetPresent should be true.
  1136 	@SYMREQ					PREQ1073.4 */	
  1137 	
  1138 	Test.Next(_L("Test that closing the channel cancels the notifier"));
  1139 	TxSoundDevice.NotifyChangeOfHwConfig(stat,headsetPresent);
  1140 	CHECK(stat==KRequestPending);
  1141 	TxSoundDevice.Close();
  1142 	User::WaitForRequest(stat);
  1143 	CHECK(stat==KErrCancel);
  1144 	
  1145 	Test.Next(_L("Re-open the channel"));
  1146 	r = TxSoundDevice.Open(KSoundScTxUnit0);
  1147 	CHECK_NOERROR(r);
  1148 	}
  1149 #endif	
  1150 	
  1151 LOCAL_C void TestUnloadDrivers()
  1152 	{
  1153 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-221
  1154 	@SYMTestCaseDesc 		Un-installing the LDD
  1155 	@SYMTestPriority 		Critical
  1156 	@SYMTestActions 		Attempt to un-install the LDD (using User::FreeLogicalDevice()). 
  1157 	@SYMTestExpectedResults KErrNone - LDD unloads successfully 
  1158 	@SYMREQ					PREQ1073.4 */
  1159 	
  1160 	TInt r=User::FreeLogicalDevice(KDevSoundScName);
  1161 	Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
  1162 	CHECK_NOERROR(r);
  1163 	
  1164 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-222
  1165 	@SYMTestCaseDesc 		Un-installing the PDD
  1166 	@SYMTestPriority 		Critical
  1167 	@SYMTestActions 		Attempt to un-install the PDD (using User::FreePhysicalDevice()). 
  1168 	@SYMTestExpectedResults KErrNone - PDD unloads successfully 
  1169 	@SYMREQ					PREQ1073.4 */
  1170 	
  1171 	TName pddName(KDevSoundScName);
  1172 	_LIT(KPddWildcardExtension,".*");
  1173 	pddName.Append(KPddWildcardExtension);
  1174 	TFindPhysicalDevice findPD(pddName);
  1175 	TFullName findResult;
  1176 	r=findPD.Next(findResult);
  1177 	while (r==KErrNone)
  1178 		{
  1179 		r=User::FreePhysicalDevice(findResult);
  1180 		Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
  1181 		CHECK_NOERROR(r);
  1182 		findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
  1183 		r=findPD.Next(findResult);
  1184 		} 
  1185 	}
  1186 
  1187 /**
  1188 Invoke the helper executable, tell it what unit to open RSoundSc for.
  1189 
  1190 @param aUnit Parameter to supply to RSoundSc ie. KSoundScTxUnit0, KSoundScRxUnit0
  1191 @param aExpectedError The expected return code from RSoundSc::Open
  1192  */
  1193 static void RunHelper(TInt aUnit, TInt aExpectedError)
  1194 	{
  1195 	TInt r;
  1196 	
  1197 	RProcess ph;
  1198 	r = ph.Create(KHelperExe, KNullDesC);
  1199 	CHECK_NOERROR(r);
  1200 	r = ph.SetParameter(KSlot, aUnit); 
  1201 	CHECK_NOERROR(r);
  1202 
  1203 	TRequestStatus rsh;
  1204 	ph.Logon(rsh);
  1205 	Test(rsh == KRequestPending);
  1206 	ph.Resume();
  1207 	User::WaitForRequest(rsh);
  1208 
  1209 	// process has died so check the panic category and reason match the expected values
  1210 	CHECK_EQUAL(ph.ExitType(), EExitPanic);
  1211 	Test(ph.ExitCategory()==KSoundAPICaps,__LINE__,(const TText*)__FILE__);
  1212 	CHECK_EQUAL(ph.ExitReason(), aExpectedError);
  1213 
  1214 	ph.Close();
  1215 	}
  1216 
  1217 /**
  1218 Delete the copy of the helper exe which was created with altered capabilities
  1219 */
  1220 static TInt DeleteHelper()
  1221 	{
  1222 	RFs fs;
  1223 	TInt r = fs.Connect();
  1224 	CHECK_NOERROR(r);
  1225 	TFileName fileName(KSysBin);
  1226 	fileName.Append(KPathDelimiter);
  1227 	fileName+=KHelperExe;
  1228 	//delete modified version of helper exe
  1229 	r = fs.Delete(fileName);
  1230 	fs.Close();
  1231 	return r;
  1232 	}
  1233 
  1234 /**
  1235 Use setcap.exe to create a copy of the helper executable, t_sound_api_helper.exe
  1236 called t_sound_api_helper_caps.exe with the supplied capabilities.
  1237 
  1238 @param aCaps A bitmask of capabilities to assign to helper exe.
  1239 */
  1240 static void SetHelperCaps(TUint32 aCaps)
  1241 	{
  1242 	TInt r;
  1243 	_LIT(KCommandLineArgsFormat, "%S %08x %S\\%S");
  1244 	TBuf<128> cmdLine;
  1245 	cmdLine.Format(KCommandLineArgsFormat, &KHelperExeBase, aCaps, &KSysBin, &KHelperExe);
  1246 
  1247 	RProcess p;
  1248 	r = p.Create(_L("setcap.exe"), cmdLine);
  1249 	CHECK_NOERROR(r);
  1250 
  1251 	TRequestStatus rs;
  1252 	p.Logon(rs);
  1253 	CHECK_EQUAL(rs.Int(),KRequestPending);
  1254 	p.Resume();
  1255 	User::WaitForRequest(rs);
  1256 
  1257 	p.Close();
  1258 	}
  1259 
  1260 /**
  1261 Test that ECapabilityMultimediaDD is required
  1262 in order to open RSoundSc for playback and that
  1263 ECapabilityUserEnvironment is needed, in addition,
  1264 to open for record.
  1265 */
  1266 static void TestCapabilityChecks()
  1267 	{
  1268 	//convert capabilities into bitmask understood by setcap.exe
  1269 	const TUint32 KUserEnvironment = 1<<ECapabilityUserEnvironment;
  1270 	const TUint32 KMultimediaDD= 1<<ECapabilityMultimediaDD;
  1271 	
  1272 	//try to delete helper just in case it has been left hanging about from a previous run which failed
  1273 	DeleteHelper();
  1274 	SetHelperCaps(NULL);
  1275 	RunHelper(KSoundScTxUnit0,KErrPermissionDenied);
  1276 	RunHelper(KSoundScRxUnit0,KErrPermissionDenied);
  1277 	
  1278 	CHECK_NOERROR(DeleteHelper());
  1279 	SetHelperCaps(KMultimediaDD);
  1280 	RunHelper(KSoundScTxUnit0,KErrNone);
  1281 	RunHelper(KSoundScRxUnit0,KErrPermissionDenied);
  1282 
  1283 	CHECK_NOERROR(DeleteHelper());
  1284 	SetHelperCaps(KUserEnvironment);
  1285 	RunHelper(KSoundScTxUnit0,KErrPermissionDenied);
  1286 	RunHelper(KSoundScRxUnit0,KErrPermissionDenied);
  1287 
  1288 	CHECK_NOERROR(DeleteHelper());
  1289 	SetHelperCaps(KUserEnvironment|KMultimediaDD);
  1290 	RunHelper(KSoundScTxUnit0,KErrNone);
  1291 	RunHelper(KSoundScRxUnit0,KErrNone);
  1292 
  1293 	CHECK_NOERROR(DeleteHelper());
  1294 	}
  1295 
  1296 TInt E32Main()
  1297 	{
  1298 	TInt r;
  1299 
  1300 	__UHEAP_MARK;
  1301 
  1302 	Test.Title();
  1303 
  1304 	Test.Start(_L("Load"));
  1305 	if (Load()==KErrNotFound)
  1306 		{
  1307 		Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
  1308 		Test.End();
  1309 		Test.Close();
  1310 		__UHEAP_MARKEND;
  1311 		return(KErrNone);
  1312 		}
  1313 
  1314 	// The __KHEAP_MARK and __KHEAP_MARKEND macros unfortunately have to be commented out or they
  1315 	// generate false positives on the x86pc target build.  This is to do with the launching of the
  1316 	// helper executable, which results in another component allocating memory and not freeing it,
  1317 	// thus causing the macros here to trigger a kern-exec 17 that is not related to the sound driver
  1318 	// itself.  The same macros are fine on other platforms.  See DEF129273 for more information
  1319 	//__KHEAP_MARK;
  1320 
  1321 	Test.Next(_L("Test Capability Checking"));
  1322 	TestCapabilityChecks();
  1323 		
  1324 	Test.Next(_L("Open playback channel"));
  1325 	r = TxSoundDevice.Open(KSoundScTxUnit0);
  1326 	CHECK_NOERROR(r);
  1327 	
  1328 	Test.Next(_L("Open record channel"));
  1329 	r = RxSoundDevice.Open(KSoundScRxUnit0);
  1330 	CHECK_NOERROR(r);
  1331 	
  1332 	Test.Next(_L("Query play formats supported"));
  1333 	TxSoundDevice.Caps(PlayCapsBuf);
  1334 	TSoundFormatsSupportedV02 playCaps=PlayCapsBuf();
  1335 	PrintCaps(playCaps,Test);
  1336 
  1337 	Test.Next(_L("Query record formats supported"));
  1338 	RxSoundDevice.Caps(RecordCapsBuf);
  1339 	TSoundFormatsSupportedV02 recordCaps=RecordCapsBuf();
  1340 	PrintCaps(recordCaps,Test);
  1341 	
  1342 	TestSetAudioFormat();
  1343 	TestSetBufferConfig(0);							// Without guard pages.
  1344 	TestSetBufferConfig(KScFlagUseGuardPages);		// With guard pages.
  1345 	TestPlay();
  1346 	TestRecord();
  1347 #ifdef _DEBUG		
  1348 	TestChangeOfHwConfigNotifier();
  1349 #endif			
  1350 	// Note that API testing of pause/resume and volume setting are covered in T_SOUND2.
  1351 	
  1352 	/**	@SYMTestCaseID 		PBASE-T_SOUND_API-226
  1353 	@SYMTestCaseDesc 		Closing the channel
  1354 	@SYMTestPriority 		Critical
  1355 	@SYMTestActions			1)	With a playback channel open on the device, close the channel. 
  1356 							2)	With a record channel open on the device, close the channel. 
  1357 	@SYMTestExpectedResults	1)	No errors occur closing the channel.
  1358 							2)	No errors occur closing the channel.
  1359 	@SYMREQ					PREQ1073.4 */
  1360 	
  1361 	Test.Next(_L("Close channels"));
  1362 	RxSoundDevice.Close();
  1363 	TxSoundDevice.Close();
  1364 	
  1365 	//__KHEAP_MARKEND;
  1366 
  1367 	// Now that both the channels are closed, unload the LDD and the PDDs.
  1368 	TestUnloadDrivers();
  1369 
  1370 	Test.End();
  1371 	Test.Close();
  1372 
  1373 	Cleanup();
  1374 	
  1375 	__UHEAP_MARKEND;
  1376 
  1377 	return(KErrNone);
  1378 	}