kerneltest/e32test/multimedia/t_camera_api.cpp
changeset 247 d8d70de2bd36
parent 201 43365a9b78a3
child 250 ac18961ed598
child 259 57b9594f5772
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
     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_camera_api.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <d32camerasc.h>
       
    20 #include <e32def.h>
       
    21 #include <e32def_private.h>
       
    22 #include "t_camera_display.h"
       
    23 #include "t_camera_bitmap.h"
       
    24 #include "d_mmcsc.h"
       
    25 
       
    26 _LIT(KTstLddFileName,"D_MMCSC.LDD");
       
    27 _LIT(KCamLddFileName,"ECAMERASC.LDD");
       
    28 
       
    29 #ifdef __WINSCW__
       
    30 _LIT(KCamPddFileName,"_TEMPLATE_CAMERASC.PDD");
       
    31 #else
       
    32 _LIT(KCamPddFileName,"CAMERASC.PDD");
       
    33 #endif
       
    34 
       
    35 
       
    36 _LIT(KCamFreePddExtension,".*");
       
    37 
       
    38 _LIT(KFrameSize, "%dx%d");
       
    39 _LIT(KSensor, "d:\\Sensor_");
       
    40 _LIT(KUnderscore, "_");
       
    41 _LIT(KBmp, ".bmp");
       
    42 _LIT(KJpeg, ".jpg");
       
    43 _LIT(KSpeedTaggedJpeg, ".stj");
       
    44 
       
    45 LOCAL_D TCameraCapsV02* CameraCaps;
       
    46 LOCAL_D TInt CapsSize;
       
    47 LOCAL_D TAny* CapsBufPtr;
       
    48 RTest Test(_L("T_CAMERA_API"));
       
    49 
       
    50 const TInt KNumVideoFramesToAllocate=6;
       
    51 const TInt KNumVideoFramesToCapture=(KNumVideoFramesToAllocate-2);
       
    52 const TInt KHeapSize=0x4000;
       
    53 const TInt KUnit0=0;
       
    54 
       
    55 enum TSecThreadTestId
       
    56 	{
       
    57 	ESecThreadTestOpen,
       
    58 	ESecThreadTestDuplicateHandle,
       
    59 	ESecThreadReuseHandle
       
    60 	};
       
    61 
       
    62 struct SSecondaryThreadInfo
       
    63 	{
       
    64 	TSecThreadTestId iTestId;
       
    65 	TInt iExpectedRetVal;
       
    66 	TThreadId iThreadId;
       
    67 	TInt iDrvHandle;
       
    68 	TInt iCameraModuleIndex;
       
    69 	};
       
    70 
       
    71 LOCAL_C TInt secondaryThread(TAny* aTestInfo)
       
    72 	{
       
    73 	RTest stest(_L("Secondary test camera thread"));
       
    74 	stest.Title();
       
    75 
       
    76 	stest.Start(_L("Check which test to perform"));
       
    77 	SSecondaryThreadInfo sti =*((SSecondaryThreadInfo*)aTestInfo);
       
    78 	
       
    79 	TInt r;
       
    80 	switch(sti.iTestId)
       
    81 		{
       
    82 		case ESecThreadTestOpen:
       
    83 			{
       
    84 			stest.Next(_L("Open channel test"));
       
    85 			RDevCameraSc cam;
       
    86 			r=cam.Open(sti.iCameraModuleIndex);
       
    87 			stest(r==sti.iExpectedRetVal);
       
    88 			cam.Close();
       
    89 			break;
       
    90 			}
       
    91 		case ESecThreadTestDuplicateHandle:
       
    92 			{
       
    93 			stest.Next(_L("Duplicate channel handle test"));
       
    94 
       
    95 			// Get a reference to the main thread - which created the handle
       
    96 			RThread thread;
       
    97 			r=thread.Open(sti.iThreadId);
       
    98 			stest(r==KErrNone);
       
    99 
       
   100 			// Duplicate the driver handle passed from the other thread - for this thread
       
   101 			RDevCameraSc cam;
       
   102 			cam.SetHandle(sti.iDrvHandle);
       
   103 			r=cam.Duplicate(thread);
       
   104 			stest(r==sti.iExpectedRetVal);
       
   105 			cam.Close();
       
   106 			thread.Close();
       
   107 			break;
       
   108 			}
       
   109 		case ESecThreadReuseHandle:
       
   110 			{
       
   111 			stest.Next(_L("Re-use channel test"));
       
   112 			RDevCameraSc* camPtr=(RDevCameraSc*)sti.iDrvHandle;
       
   113 			TCameraConfigV02Buf camConfBuf;
       
   114 			camPtr->GetCamConfig(ECamCaptureModeImage, camConfBuf);	// This should cause a panic.
       
   115 			break;
       
   116 			}
       
   117 		default:
       
   118 			break;
       
   119 		}
       
   120 
       
   121 	stest.End();
       
   122 	return(KErrNone);
       
   123 	}
       
   124 
       
   125 /** Test for defect DEF135950. */
       
   126 LOCAL_C void DoCamDynamicSettingsTests(RDevCameraSc& aCam, RTest& aTest)
       
   127 	{
       
   128 	aTest.Next(_L("DYNAMIC SETTINGS TESTS"));
       
   129 	
       
   130 	aTest.Next(_L("Get the Caps size. Should be non-zero"));
       
   131 	TInt capsSize = aCam.CapsSize();
       
   132 	aTest(capsSize>0);
       
   133 
       
   134 	aTest.Next(_L("Get the Capabilities (driver owned copy)."));
       
   135 	TPtrC8 driverCopy = aCam.Caps();
       
   136 	aTest(driverCopy.Ptr() != NULL);
       
   137 	aTest(driverCopy.Length()>0);
       
   138 
       
   139 	aTest.Next(_L("Test failure (buffer too small)."));
       
   140 	TAny* capsBufPtr = User::Alloc(capsSize-1);
       
   141 	aTest(capsBufPtr != NULL);
       
   142 	TPtr8 smallBuf((TUint8*) capsBufPtr, capsSize-1, capsSize-1);
       
   143 	aTest(KErrArgument==aCam.Caps(smallBuf));
       
   144 	User::Free(capsBufPtr);
       
   145 
       
   146 	aTest.Next(_L("Get the Capabilities (client owned copy)."));
       
   147 	capsBufPtr = User::Alloc(capsSize);
       
   148 	aTest(capsBufPtr != NULL);
       
   149 	TPtr8 clientCopy((TUint8*) capsBufPtr, capsSize, capsSize);
       
   150 	aTest(KErrNone==aCam.Caps(clientCopy));
       
   151 	aTest(clientCopy.Ptr() != NULL);
       
   152 	aTest(clientCopy.Length()>0);
       
   153 
       
   154 	aTest.Next(_L("Obtain the range for Dynamic Settings from both copies (should be the same)."));
       
   155 	
       
   156 	TDynamicRange &driverRangeBrightness = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
       
   157 	TDynamicRange &clientRangeBrightness = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
       
   158 	
       
   159 	aTest(driverRangeBrightness.iMin == 0);
       
   160 	aTest(driverRangeBrightness.iMax == 6);
       
   161 	aTest(driverRangeBrightness.iMin == clientRangeBrightness.iMin);
       
   162 	aTest(driverRangeBrightness.iMax == clientRangeBrightness.iMax);
       
   163 
       
   164 	TDynamicRange &driverRangeContrast = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
       
   165 	TDynamicRange &clientRangeContrast = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
       
   166 
       
   167 	aTest(driverRangeContrast.iMin == 0);
       
   168 	aTest(driverRangeContrast.iMax == 6);
       
   169 	aTest(driverRangeContrast.iMin == clientRangeContrast.iMin);
       
   170 	aTest(driverRangeContrast.iMax == clientRangeContrast.iMax);
       
   171 	
       
   172 	TDynamicRange &driverRangeColorEffect = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
       
   173 	TDynamicRange &clientRangeColorEffect = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
       
   174 
       
   175 	aTest(driverRangeColorEffect.iMin == 0);
       
   176 	aTest(driverRangeColorEffect.iMax == 7); // TBC::OV3640 set to 7, template driver set to 0x0040 (enum)
       
   177 	aTest(driverRangeColorEffect.iMin == clientRangeColorEffect.iMin);
       
   178 	aTest(driverRangeColorEffect.iMax == clientRangeColorEffect.iMax);
       
   179 
       
   180 	aTest.Next(_L("Test for invalid Min range."));
       
   181 	aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMin-1)==KErrArgument);
       
   182 	aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMin-1)==KErrArgument);
       
   183 	aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMin-1)==KErrArgument);
       
   184 
       
   185 	aTest.Next(_L("Test for invalid Max range."));
       
   186 	aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMax+1)==KErrArgument);
       
   187 	aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMax+1)==KErrArgument);
       
   188 	aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMax+1)==KErrArgument);
       
   189 
       
   190 	aTest.Next(_L("Test all valid settings as reported by range - Brightness"));
       
   191 	for (TUint i=driverRangeBrightness.iMin; i <= driverRangeBrightness.iMax; ++i)
       
   192 		{
       
   193 		aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, i)==KErrNone);
       
   194 		}
       
   195 
       
   196 	aTest.Next(_L("Test all valid settings as reported by range - Contrast"));
       
   197 	for (TUint j=driverRangeContrast.iMin; j <= driverRangeContrast.iMax; ++j)
       
   198 		{
       
   199 		aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, j)==KErrNone);
       
   200 		}
       
   201 
       
   202 	aTest.Next(_L("Test all valid settings as reported by range - ColorEffect"));
       
   203 	for (TUint k=driverRangeColorEffect.iMin; k <= driverRangeColorEffect.iMax; ++k)
       
   204 		{
       
   205 		aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, k)==KErrNone);
       
   206 		}
       
   207 
       
   208 	User::Free(capsBufPtr);
       
   209 	}
       
   210 
       
   211 /** Test for defect DEF135949. */
       
   212 LOCAL_C void DoCamBufferOffsetTests(RDevCameraSc& aCam, RTest& aTest, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
       
   213 	{
       
   214 	TInt r;
       
   215 
       
   216 	aTest.Next(_L("BUFFER ID OFFSET TESTS"));
       
   217 	aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
       
   218 
       
   219 	// Configure Image Capture
       
   220 	aTest.Next(_L("Get the camera config of Image mode"));
       
   221 	TCameraConfigV02Buf camConfBuf;
       
   222 	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
   223 	TCameraConfigV02 &camConf=camConfBuf();
       
   224 
       
   225 	camConf.iFrameSize=aFrameSize;
       
   226 	camConf.iPixelFormat=aPixelFormat;
       
   227 	camConf.iFrameRate=aFrameRate;
       
   228 
       
   229 	// Set the Image configuration.
       
   230 	aTest.Next(_L("Set the Get the camera config of Image mode"));
       
   231 	r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
       
   232 	aTest(r==KErrNone);
       
   233 	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
   234 	PrintCamConf(camConf,aTest);
       
   235 
       
   236 	// Create an Image chunk handle.
       
   237 	aTest.Next(_L("Create the Image chunk"));
       
   238 	RChunk imgChunkImage;
       
   239 	TInt numBuffers=KNumVideoFramesToAllocate;
       
   240 	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,imgChunkImage);
       
   241 	aTest(r==KErrNone);
       
   242 
       
   243 	aTest.Next(_L("Read and display the Image buffer config"));
       
   244 	TMmSharedChunkBufConfig bufferConfig;
       
   245 	TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
       
   246 	aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBuf);
       
   247 	PrintBufferConf(bufferConfig,aTest);
       
   248 
       
   249 	// Configure Video Capture
       
   250 	aTest.Next(_L("Get the camera config of Video mode"));
       
   251 	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
   252 	camConf=camConfBuf();
       
   253 
       
   254 	camConf.iFrameSize=aFrameSize;
       
   255 	camConf.iPixelFormat=aPixelFormat;
       
   256 	camConf.iFrameRate=aFrameRate;
       
   257 
       
   258 	// Set the video configuration.
       
   259 	aTest.Next(_L("Set the Get the camera config of Video mode"));
       
   260 	r=aCam.SetCamConfig(ECamCaptureModeVideo,camConfBuf);
       
   261 	aTest(r==KErrNone);
       
   262 	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
   263 	PrintCamConf(camConf,aTest);
       
   264 
       
   265 	// Create an Video chunk handle.
       
   266 	aTest.Next(_L("Create the Video chunk"));
       
   267 	RChunk chunkVideo;
       
   268 	numBuffers=KNumVideoFramesToAllocate;
       
   269 	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
       
   270 	aTest(r==KErrNone);
       
   271 
       
   272 	aTest.Next(_L("Read and display the Video buffer config"));
       
   273 	aCam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBuf);
       
   274 	PrintBufferConf(bufferConfig,aTest);
       
   275 
       
   276 	// Test that stop still returns an error.
       
   277 	r=aCam.Stop();
       
   278 	aTest(r==KErrGeneral);
       
   279 
       
   280 	// Set the current capture mode to image
       
   281 	aTest.Next(_L("Set the camera in Image mode and capture a buffer, then requesting the buffer offset."));
       
   282 	r=aCam.SetCaptureMode(ECamCaptureModeImage);
       
   283 	aTest(r==KErrNone);
       
   284 
       
   285 	// Start the camera
       
   286 	r=aCam.Start();
       
   287 	aTest(r==KErrNone);
       
   288 
       
   289 	aTest.Next(_L("Issue a capture request"));
       
   290 	TRequestStatus rs1;
       
   291 	aCam.NotifyNewImage(rs1);
       
   292 	User::WaitForRequest(rs1);
       
   293 	TInt retId=rs1.Int();
       
   294 	TInt retOffset=-1;
       
   295 	aTest(retId>=0);
       
   296 	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
   297 	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
       
   298 	aTest(retOffset>=0);
       
   299 
       
   300 	// Change capture mode
       
   301 	aTest.Next(_L("Set the capture mode to Video."));
       
   302 	r=aCam.SetCaptureMode(ECamCaptureModeVideo);
       
   303 	aTest(r==KErrNone);
       
   304 
       
   305 	aTest.Next(_L("Request again the offset for the buffer in Image mode."));
       
   306 	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
   307 	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
       
   308 	aTest(retOffset>=0);
       
   309 
       
   310 	// Stop the camera.
       
   311 	r=aCam.Stop();
       
   312 	aTest(r==KErrNone);
       
   313 
       
   314 	aTest.Next(_L("Close the chunk"));
       
   315 	r=aCam.ChunkClose(ECamCaptureModeImage);
       
   316 	aTest(r==KErrNone);
       
   317 	r=aCam.ChunkClose(ECamCaptureModeVideo);
       
   318 	aTest(r==KErrNone);
       
   319 	}
       
   320 
       
   321 
       
   322 LOCAL_C void DoCamOpenCapTests(RTest& aTest,TInt aCameraSensorIndex)
       
   323 	{
       
   324 	TInt r;
       
   325 
       
   326 	// Open the camera driver to obtain the basic capabilities for use throughout the tests and
       
   327 	// then close it again so that it may be confirmed that opening multiple times is ok
       
   328 	aTest.Next(_L("CHANNEL OPEN AND CAPABILITIES TESTS"));
       
   329 	RDevCameraSc cam;
       
   330 	aTest.Next(_L("Open a channel on the camera driver"));
       
   331 	r=cam.Open(aCameraSensorIndex);
       
   332 	aTest(r==KErrNone);
       
   333 
       
   334 	// Make sure that the driver can handle attempts to start it before it has been configured
       
   335 	aTest.Next(_L("Try to start/stop camera before its configured"));
       
   336 	r=cam.Start();
       
   337 	aTest(r==KErrNotReady);
       
   338 	r=cam.Stop();
       
   339 	aTest(r==KErrGeneral);
       
   340 
       
   341 	aTest.Next(_L("Read the capabilities structure size of this device"));
       
   342 	CapsSize=cam.CapsSize();
       
   343 	aTest.Next(_L("Read and display the capabilities of this device"));
       
   344 	CapsBufPtr = User::Alloc(CapsSize);
       
   345 	TPtr8 capsPtr( (TUint8*)CapsBufPtr, CapsSize, CapsSize );
       
   346 	r=cam.Caps(capsPtr);
       
   347 	aTest(r==KErrNone);
       
   348 	CameraCaps = (TCameraCapsV02*) capsPtr.Ptr();
       
   349 	PrintCamModes(CameraCaps,aTest);
       
   350 
       
   351 	TAny* frameSizeCapsBuf;
       
   352 	SDevCamPixelFormat* pixelFormat;
       
   353 	TBuf<80> buf;
       
   354 	SDevCamFrameSize* frameSize;
       
   355 	TPtr8 frameSizeCapsPtr(0,0,0);
       
   356 	TUint fsCount, pfCount, theCount = 0;
       
   357 
       
   358 	/* IMAGE */
       
   359 	/* Use pixel formats from 0 to CapsBuf->iNumImagePixelFormats */
       
   360 	buf.Zero();
       
   361 	buf.Append(KCaptureModeImage);
       
   362 	buf.Append(_L("\r\n"));
       
   363 	aTest.Printf(buf);
       
   364 	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
       
   365 	for (pfCount = theCount; pfCount < CameraCaps->iNumImagePixelFormats; pfCount++)
       
   366 		{
       
   367 		buf.Zero();
       
   368 		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
       
   369 		aTest.Printf(buf);
       
   370 		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   371 		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   372 		r=cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizeCapsPtr);
       
   373 		aTest(r==KErrNone);
       
   374 		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
       
   375 		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
       
   376 			{
       
   377 			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
       
   378 			frameSize++;
       
   379 			}
       
   380 		aTest.Printf(_L("\n"));
       
   381 		User::Free(frameSizeCapsBuf);
       
   382 		pixelFormat++;
       
   383 		}
       
   384 
       
   385 	/* VIDEO */
       
   386 	buf.Zero();
       
   387 	buf.Append(KCaptureModeVideo);
       
   388 	buf.Append(_L("\r\n"));
       
   389 	aTest.Printf(buf);
       
   390 	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
       
   391 	pixelFormat += CameraCaps->iNumImagePixelFormats;
       
   392 	theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats;
       
   393 	for (pfCount = CameraCaps->iNumImagePixelFormats; pfCount < theCount; pfCount++)
       
   394 		{
       
   395 		buf.Zero();
       
   396 		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
       
   397 		aTest.Printf(buf);
       
   398 		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   399 		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   400 		r=cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizeCapsPtr);
       
   401 		aTest(r==KErrNone);
       
   402 		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
       
   403 		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
       
   404 			{
       
   405 			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
       
   406 			frameSize++;
       
   407 			}
       
   408 		aTest.Printf(_L("\n"));
       
   409 		User::Free(frameSizeCapsBuf);
       
   410 		pixelFormat++;
       
   411 		}
       
   412 
       
   413 	/* VIEW FINDER */
       
   414 	buf.Zero();
       
   415 	buf.Append(KCaptureModeViewFinder);
       
   416 	buf.Append(_L("\r\n"));
       
   417 	aTest.Printf(buf);
       
   418 	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
       
   419 	pixelFormat += (CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats);
       
   420 	theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats + CameraCaps->iNumViewFinderPixelFormats;
       
   421 	for (pfCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats; pfCount < theCount; pfCount++)
       
   422 		{
       
   423 		buf.Zero();
       
   424 		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
       
   425 		aTest.Printf(buf);
       
   426 		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   427 		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
       
   428 		r=cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizeCapsPtr);
       
   429 		aTest(r==KErrNone);
       
   430 		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
       
   431 		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
       
   432 			{
       
   433 			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
       
   434 			frameSize++;
       
   435 			}
       
   436 		aTest.Printf(_L("\n"));
       
   437 		User::Free(frameSizeCapsBuf);
       
   438 		pixelFormat++;
       
   439 		}
       
   440 
       
   441 	aTest.Next(_L("Try opening the same unit a second time."));
       
   442 	RDevCameraSc cam2;
       
   443 	r=cam2.Open(aCameraSensorIndex);
       
   444 	aTest(r==KErrInUse);
       
   445 
       
   446 	aTest.Next(_L("Open a channel from the 2nd thread without closing the 1st"));
       
   447 	RThread thread;
       
   448 	TRequestStatus stat;
       
   449 	SSecondaryThreadInfo sti;
       
   450 
       
   451 	// Setup the 2nd thread to open a channel on the same unit
       
   452 	sti.iTestId=ESecThreadTestOpen;
       
   453 	sti.iExpectedRetVal=KErrInUse;
       
   454 	sti.iCameraModuleIndex=aCameraSensorIndex;
       
   455 	r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
       
   456 	Test(r==KErrNone);
       
   457 	thread.Logon(stat);
       
   458 	thread.Resume();
       
   459 	User::WaitForRequest(stat);
       
   460 	Test(stat.Int()==KErrNone);
       
   461 	Test(thread.ExitType()==EExitKill);
       
   462 	thread.Close();
       
   463 	User::After(10000);	// Wait 10ms
       
   464 
       
   465 	aTest.Next(_L("Open a channel from the 2nd thread having closed the 1st"));
       
   466 	cam.Close();		// Close the 1st channel
       
   467 	sti.iTestId=ESecThreadTestOpen;
       
   468 	sti.iExpectedRetVal=KErrNone;
       
   469 	r=thread.Create(_L("Thread02"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
       
   470 	Test(r==KErrNone);
       
   471 	thread.Logon(stat);
       
   472 	thread.Resume();
       
   473 	User::WaitForRequest(stat);
       
   474 	Test(stat.Int()==KErrNone);
       
   475 	Test(thread.ExitType()==EExitKill);
       
   476 	thread.Close();
       
   477 	User::After(10000);	// Wait 10ms
       
   478 
       
   479 	aTest.Next(_L("Re-open channel and duplicate it from 2nd thread"));
       
   480 	r=cam.Open(aCameraSensorIndex);		// Re-open the channel
       
   481 	aTest(r==KErrNone);
       
   482 	sti.iTestId=ESecThreadTestDuplicateHandle;
       
   483 	sti.iExpectedRetVal=KErrAccessDenied;
       
   484 	sti.iThreadId=RThread().Id();	// Get the ID of this thread
       
   485 	sti.iDrvHandle=cam.Handle();	// Pass the channel handle
       
   486 
       
   487 	r=thread.Create(_L("Thread03"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
       
   488 	Test(r==KErrNone);
       
   489 	thread.Logon(stat);
       
   490 	thread.Resume();
       
   491 	User::WaitForRequest(stat);
       
   492 	Test(stat.Int()==KErrNone);
       
   493 	Test(thread.ExitType()==EExitKill);
       
   494 	thread.Close();
       
   495 	User::After(10000);	// Wait 10ms
       
   496 
       
   497 	aTest.Next(_L("Re-use the same channel from 2nd thread"));
       
   498 	sti.iTestId=ESecThreadReuseHandle;
       
   499 	sti.iDrvHandle=(TInt)&cam;	// Pass a pointer to the channel
       
   500 	r=thread.Create(_L("Thread04"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
       
   501 	Test(r==KErrNone);
       
   502 	thread.Logon(stat);
       
   503 	thread.Resume();
       
   504 	User::WaitForRequest(stat);
       
   505 	TExitCategoryName exitCategoryName = thread.ExitCategory();
       
   506 	Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&exitCategoryName,thread.ExitReason(),thread.ExitType());
       
   507 	Test(thread.ExitType()==EExitPanic);	// Secondary thread is expected to panic
       
   508 	Test(stat.Int()==KErrNone);
       
   509 	thread.Close();
       
   510 	User::After(10000);	// Wait 10ms
       
   511 
       
   512 	cam.Close();
       
   513 	}
       
   514 
       
   515 LOCAL_C void DoCamConfigTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize)
       
   516 	{
       
   517 	TInt r;
       
   518 
       
   519 	aTest.Next(_L("GETTING & SETTING CONFIG TESTS"));
       
   520 	aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
       
   521 
       
   522 	aTest.Next(_L("Read and display the default camera config for requested capture mode"));
       
   523 	TCameraConfigV02Buf camConfBuf;
       
   524 	aCam.GetCamConfig(aCaptureMode, camConfBuf);
       
   525 	TCameraConfigV02 &camConf=camConfBuf();
       
   526 	PrintCamConf(camConf,aTest);
       
   527 
       
   528 	aTest.Next(_L("Read and display the default buffer config for requested capture mode"));
       
   529 	TMmSharedChunkBufConfig bufferConfig;
       
   530 	TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
       
   531 	aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
       
   532 	PrintBufferConf(bufferConfig,aTest);
       
   533 
       
   534 	aTest.Next(_L("Setup the config - creating a chunk"));
       
   535 	camConf.iFrameSize=aFrameSize;
       
   536 	camConf.iPixelFormat=aPixelFormat;
       
   537 	camConf.iFrameRate=aFrameSize.iMaxFrameRate;
       
   538 	r=aCam.SetCamConfig(aCaptureMode, camConfBuf);
       
   539 	aTest(r==KErrNone);
       
   540 	RChunk chunk;
       
   541 	r=aCam.SetBufConfigChunkCreate(aCaptureMode, KNumVideoFramesToAllocate, chunk);
       
   542 	aTest(r==KErrNone);
       
   543 	aCam.GetCamConfig(aCaptureMode, camConfBuf);
       
   544 	PrintCamConf(camConf,aTest);
       
   545 
       
   546 	aTest.Next(_L("Read and display the resulting buffer config"));
       
   547 	aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
       
   548 	PrintBufferConf(bufferConfig,aTest);
       
   549 
       
   550 	aTest.Next(_L("Close the chunk created"));
       
   551 	chunk.Close();
       
   552 
       
   553 	aTest.Next(_L("Open a channel on the test driver"));
       
   554 	RMmCreateSc tstDrv;
       
   555 	r=tstDrv.Open();		// Opening the channel results in the creation of a shared chunk.
       
   556 	aTest(r==KErrNone);
       
   557 
       
   558 	aTest.Next(_L("Get a handle on its shared chunk"));
       
   559 	r=tstDrv.GetChunkHandle(chunk);	// Get a handle on the shared chunk created by the test driver
       
   560 	aTest(r==KErrNone);
       
   561 
       
   562 	aTest.Next(_L("Read and display the buffer config"));
       
   563 	TMmSharedChunkBufConfig bufferConfigTest;
       
   564 	TPckg<TMmSharedChunkBufConfig> bufferConfigBufTest(bufferConfigTest);
       
   565 
       
   566 	// Get info on the buffers within the shared chunk
       
   567 	aTest.Next(_L("Get info. on the shared chunk"));
       
   568 	r=tstDrv.GetBufInfo(bufferConfigBufTest);
       
   569 	aTest(r==KErrNone);
       
   570 
       
   571 	PrintBufferConf(bufferConfigTest,aTest);
       
   572 	aTest.Next(_L("Setup the config - supplying a chunk"));
       
   573 	r=aCam.SetBufConfigChunkOpen(aCaptureMode, bufferConfigBufTest, chunk);
       
   574 	aTest(r==KErrNone);
       
   575 	aCam.GetCamConfig(aCaptureMode, camConfBuf);
       
   576 	PrintCamConf(camConf,aTest);
       
   577 	aCam.GetBufferConfig(aCaptureMode, bufferConfigBufTest);
       
   578 	PrintBufferConf(bufferConfigTest,aTest);
       
   579 
       
   580 	aTest.Next(_L("Close the chunk driver and the 2nd chunk"));
       
   581 	tstDrv.Close();
       
   582 	chunk.Close();
       
   583 	}
       
   584 
       
   585 LOCAL_C void DoCamVideoCaptureTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
       
   586 	{
       
   587 	TInt r;
       
   588 
       
   589 	aTest.Next(_L("VIDEO CAPTURE TESTS"));
       
   590 	aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
       
   591 
       
   592 	// Configure Video or Viewfinder Capture
       
   593 	TCameraConfigV02Buf camConfBuf;
       
   594 	aCam.GetCamConfig(aCaptureMode, camConfBuf);
       
   595 	TCameraConfigV02 &camConf=camConfBuf();
       
   596 
       
   597 	camConf.iFrameSize=aFrameSize;
       
   598 	camConf.iPixelFormat=aPixelFormat;
       
   599 	camConf.iFrameRate=aFrameRate;
       
   600 
       
   601 	// Set the camera configuration.
       
   602 	r=aCam.SetCamConfig(aCaptureMode,camConfBuf);
       
   603 	aTest(r==KErrNone);
       
   604 	aCam.GetCamConfig(aCaptureMode, camConfBuf);
       
   605 	PrintCamConf(camConf,aTest);
       
   606 
       
   607 	// Create a chunk handle and trigger the buffer creation.
       
   608 	aTest.Next(_L("Setup the config - creating a chunk"));
       
   609 	RChunk chunkVideo;
       
   610 	TInt numBuffers=KNumVideoFramesToAllocate;
       
   611 	r=aCam.SetBufConfigChunkCreate(aCaptureMode,numBuffers,chunkVideo);
       
   612 	aTest(r==KErrNone);
       
   613 
       
   614 	aTest.Next(_L("Read and display the resulting buffer config"));
       
   615 	TMmSharedChunkBufConfig bufferConfig;
       
   616 	TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
       
   617 	aCam.GetBufferConfig(aCaptureMode, bufferConfigBufVideo);
       
   618 	PrintBufferConf(bufferConfig,aTest);
       
   619 
       
   620 	// Request and print the camera and buffer configurations for all three capture modes
       
   621 	aTest.Next(_L("Read and display the camera configs"));
       
   622 	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
   623 	PrintCamConf(camConf,aTest);
       
   624 	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
   625 	PrintCamConf(camConf,aTest);
       
   626 	aCam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
       
   627 	PrintCamConf(camConf,aTest);
       
   628 
       
   629 	// Create and configure a display handler
       
   630 	TCamDisplayHandler dispHand;
       
   631 	r=dispHand.Init();
       
   632 	aTest(r==KErrNone);
       
   633 
       
   634 	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   635 		{
       
   636 		r=dispHand.SetConfig(aFrameSize,aPixelFormat);
       
   637 		aTest(r==KErrNone);
       
   638 		}
       
   639 
       
   640 	// Test that stop still returns an error.
       
   641 	r=aCam.Stop();
       
   642 	aTest(r==KErrGeneral);
       
   643 
       
   644 	// Set the current capture mode
       
   645 	r=aCam.SetCaptureMode(aCaptureMode);
       
   646 	aTest(r==KErrNone);
       
   647 
       
   648 	aTest.Next(_L("Start the camera in video mode"));
       
   649 	r=aCam.Start();
       
   650 	aTest(r==KErrNone);
       
   651 
       
   652 	aTest.Next(_L("Issue capture requests"));
       
   653 	aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
       
   654 	// Issue new image requests immediately. We'll have to wait while the
       
   655 	// camera captures the images.
       
   656 	TRequestStatus rs[KNumVideoFramesToCapture];
       
   657 	TInt i;
       
   658 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   659 		{
       
   660 		aTest.Printf(_L("Requesting new image... %d\n"), i);
       
   661 		aCam.NotifyNewImage(rs[i]);
       
   662 		aTest.Printf(_L("Requested new image... %d\n"), i);
       
   663 		}
       
   664 
       
   665 	TInt retId=-1;
       
   666 	TInt retOffset=-1;
       
   667 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   668 		{
       
   669 		aTest.Printf(_L("Waiting for... %d\n"), i);
       
   670 		User::WaitForRequest(rs[i]);
       
   671 		retId=rs[i].Int();
       
   672 		aTest(retId>=0);
       
   673 		aTest.Printf(_L("Getting buffer offset for... %d\n"), i);
       
   674 		aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
       
   675 		aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
       
   676 		aTest(retOffset>=0);
       
   677 		}
       
   678 
       
   679 	TUint8* imgBase;
       
   680 
       
   681 	// Display each image received for 333ms
       
   682 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   683 		{
       
   684 		if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   685 			{
       
   686 			retId=rs[i].Int();
       
   687 			aTest(retId>=0);
       
   688 			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
       
   689 			aTest(retOffset>=0);
       
   690 			imgBase=chunkVideo.Base()+retOffset;
       
   691 			r=dispHand.Process(imgBase);
       
   692 			
       
   693 #ifdef __WINSCW__
       
   694 			aTest(r==KErrNotSupported);
       
   695 #else
       
   696 			aTest(r==KErrNone);
       
   697 #endif
       
   698 
       
   699 			User::After(333000);	// 0.33sec
       
   700 			}
       
   701 		}
       
   702 
       
   703 	aTest.Next(_L("Free the buffers"));
       
   704 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   705 		{
       
   706 		aTest.Printf(_L("Releasing %d(i:%d) "),rs[i].Int(), i);
       
   707 		r=aCam.ReleaseBuffer(rs[i].Int());
       
   708 		aTest.Printf(_L("buffer(%d), r=%d\n"),rs[i].Int(),r);
       
   709 		aTest(r==KErrNone);
       
   710 		}
       
   711 
       
   712 	aTest.Next(_L("Issue more capture requests"));
       
   713 	// Wait a bit more so camera has images ready as soon as we issue the requests
       
   714 	User::After(500000);	// 0.5sec
       
   715 
       
   716 	aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
       
   717 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   718 		aCam.NotifyNewImage(rs[i]);
       
   719 
       
   720 	for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
   721 		{
       
   722 		User::WaitForRequest(rs[i]);
       
   723 		retId=rs[i].Int();
       
   724 		aTest(retId>=0);
       
   725 		aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
       
   726 		aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
       
   727 		aTest(retOffset>=0);
       
   728 		}
       
   729 
       
   730 	aTest.Next(_L("Stop the camera."));
       
   731 	r=aCam.Stop();
       
   732 	aTest(r==KErrNone);
       
   733 
       
   734 	aTest.Next(_L("Start it again."));
       
   735 	r=aCam.Start();
       
   736 	aTest(r==KErrNone);
       
   737 
       
   738 	aTest.Next(_L("Continuously display for 10 secs"));
       
   739 	RTimer tim;
       
   740 	tim.CreateLocal();
       
   741 	TRequestStatus timStatus;
       
   742 	const TUint KTimeOut=10000000;	// 10 seconds
       
   743 	tim.After(timStatus,KTimeOut);
       
   744 	aTest(timStatus==KRequestPending);
       
   745 	aCam.NotifyNewImage(rs[0]);
       
   746 	aCam.NotifyNewImage(rs[1]);
       
   747 	FOREVER
       
   748 		{
       
   749 		User::WaitForAnyRequest();
       
   750 		if (timStatus!=KRequestPending)
       
   751 			{
       
   752 			aCam.NotifyNewImageCancel();
       
   753 			User::WaitForRequest(rs[0]);
       
   754 			User::WaitForRequest(rs[1]);
       
   755 			break;
       
   756 			}
       
   757 		else if (rs[0]!=KRequestPending)
       
   758 			{
       
   759 			retId=rs[0].Int();
       
   760 			aTest(retId>=0);
       
   761 			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
       
   762 			aTest(retOffset>=0);
       
   763 			imgBase=chunkVideo.Base()+retOffset;
       
   764 			if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   765 				{
       
   766 				r=dispHand.Process(imgBase);
       
   767 				
       
   768 #ifdef __WINSCW__
       
   769 				aTest(r==KErrNotSupported);
       
   770 #else
       
   771 				aTest(r==KErrNone);
       
   772 #endif
       
   773 				
       
   774 				}
       
   775 			r=aCam.ReleaseBuffer(retId);
       
   776 			aTest(r==KErrNone);
       
   777 			aCam.NotifyNewImage(rs[0]);
       
   778 			}
       
   779 		else if (rs[1]!=KRequestPending)
       
   780 			{
       
   781 			retId=rs[1].Int();
       
   782 			aTest(retId>=0);
       
   783 			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
       
   784 			aTest(retOffset>=0);
       
   785 			imgBase=chunkVideo.Base()+retOffset;
       
   786 			if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   787 				{
       
   788 				r=dispHand.Process(imgBase);
       
   789 				
       
   790 #ifdef __WINSCW__
       
   791 				aTest(r==KErrNotSupported);
       
   792 #else
       
   793 				aTest(r==KErrNone);
       
   794 #endif
       
   795 				
       
   796 				}
       
   797 			r=aCam.ReleaseBuffer(retId);
       
   798 			aTest(r==KErrNone);
       
   799 			aCam.NotifyNewImage(rs[1]);
       
   800 			}
       
   801 		else
       
   802 			aTest(0);
       
   803 		}
       
   804 
       
   805 	tim.Close();
       
   806 
       
   807 	aTest.Next(_L("Stop the camera."));
       
   808 	r=aCam.Stop();
       
   809 	aTest(r==KErrNone);
       
   810 
       
   811 	aTest.Next(_L("Close the chunk"));
       
   812 	r=aCam.ChunkClose(aCaptureMode);
       
   813 	}
       
   814 
       
   815 LOCAL_C void DoCamImageCaptureTests(RDevCameraSc& aCam, RTest& aTest, TInt aCameraSensorIndex, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
       
   816 	{
       
   817 	TInt r;
       
   818 
       
   819 	aTest.Next(_L("IMAGE CAPTURE TESTS"));
       
   820 	aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
       
   821 
       
   822 	// Configure Image Capture
       
   823 	TCameraConfigV02Buf camConfBuf;
       
   824 	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
   825 	TCameraConfigV02 &camConf=camConfBuf();
       
   826 
       
   827 	camConf.iFrameSize=aFrameSize;
       
   828 	camConf.iPixelFormat=aPixelFormat;
       
   829 	camConf.iFrameRate=aFrameRate;
       
   830 
       
   831 	// Set the camera configuration.
       
   832 	r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
       
   833 	aTest(r==KErrNone);
       
   834 	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
   835 	PrintCamConf(camConf,aTest);
       
   836 
       
   837 	// Create a chunk handle and trigger the buffer creation.
       
   838 	aTest.Next(_L("Setup the config - creating a chunk"));
       
   839 	RChunk chunkImage;
       
   840 	TInt numBuffers=KNumVideoFramesToAllocate;
       
   841 	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
       
   842 	aTest(r==KErrNone);
       
   843 
       
   844 	aTest.Next(_L("Read and display the resulting buffer config"));
       
   845 	TMmSharedChunkBufConfig bufferConfig;
       
   846 	TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
       
   847 	aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
       
   848 	PrintBufferConf(bufferConfig,aTest);
       
   849 
       
   850 	// Create and configure a display handler
       
   851 	TCamDisplayHandler dispHand;
       
   852 	r=dispHand.Init();
       
   853 	aTest(r==KErrNone);
       
   854 
       
   855 	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   856 		{
       
   857 		r=dispHand.SetConfig(aFrameSize,aPixelFormat);
       
   858 		aTest(r==KErrNone);
       
   859 		}
       
   860 
       
   861 	// Test that stop still returns an error.
       
   862 	r=aCam.Stop();
       
   863 	aTest(r==KErrGeneral);
       
   864 
       
   865 	// Set the current capture mode
       
   866 	r=aCam.SetCaptureMode(ECamCaptureModeImage);
       
   867 	aTest(r==KErrNone);
       
   868 
       
   869 	aTest.Next(_L("Start the camera in image capture mode"));
       
   870 	r=aCam.Start();
       
   871 	aTest(r==KErrNone);
       
   872 
       
   873 	aTest.Next(_L("Issue a capture request"));
       
   874 	TRequestStatus rs1;
       
   875 	aCam.NotifyNewImage(rs1);
       
   876 	User::WaitForRequest(rs1);
       
   877 	TInt retId=rs1.Int();
       
   878 	TInt retOffset=-1;
       
   879 	aTest(retId>=0);
       
   880 	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
   881 	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
       
   882 	aTest(retOffset>=0);
       
   883 
       
   884 	TUint8* imgBase;
       
   885 	imgBase=chunkImage.Base()+retOffset;
       
   886 
       
   887 	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   888 		{
       
   889 		// Display the image received for 1s
       
   890 		r=dispHand.Process(imgBase);
       
   891 		
       
   892 #ifdef __WINSCW__
       
   893         aTest(r==KErrNotSupported);
       
   894 #else
       
   895         aTest(r==KErrNone);
       
   896 #endif
       
   897         
       
   898 		User::After(1000000);	// 1 sec
       
   899 		}
       
   900 
       
   901 	// Save the to do MMC card with a filename to indicate its size.  If no MMC card is present
       
   902 	// then we will just display a warning rather than fail as this is an optional manual step
       
   903 	TBuf<100> fileName(KSensor);
       
   904 	fileName.AppendNum(aCameraSensorIndex);
       
   905 	fileName.Append(KUnderscore);
       
   906 	fileName.AppendFormat(KFrameSize, aFrameSize.iWidth, aFrameSize.iHeight);
       
   907 	fileName.Append(KUnderscore);
       
   908 	AppendPixelFormat(fileName, aPixelFormat.iPixelFormat);
       
   909 
       
   910 	TBool wrote = ETrue;
       
   911 	RBitmap bitmap;
       
   912 
       
   913 	if ((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) || (aPixelFormat.iPixelFormat == EUidPixelFormatSpeedTaggedJPEG))
       
   914 		{
       
   915 		fileName.Append((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) ? KJpeg : KSpeedTaggedJpeg);
       
   916 		r=bitmap.WriteBuffer(fileName, imgBase, (aFrameSize.iWidth * aFrameSize.iHeight * aPixelFormat.iPixelWidthInBytes));
       
   917 		}
       
   918 	else if ((aPixelFormat.iPixelFormat == EUidPixelFormatYUV_422Interleaved) || (aPixelFormat.iPixelFormat == EUidPixelFormatRGB_565))
       
   919 		{
       
   920 		fileName.Append(KBmp);
       
   921 		r=bitmap.WriteBMP(fileName, imgBase, aPixelFormat, aFrameSize.iWidth, aFrameSize.iHeight);
       
   922 		}
       
   923 	else
       
   924 		{
       
   925 		wrote = EFalse;
       
   926 		}
       
   927 
       
   928 	if (wrote)
       
   929 		{
       
   930 		if (r==KErrNone)
       
   931 			{
       
   932 			aTest.Printf(_L("Wrote image to %S\n"),&fileName);
       
   933 			}
       
   934 		else
       
   935 			{
       
   936 			aTest.Printf(_L("Warning: Unable to write %S (error = %d)\r\n"),&fileName,r);
       
   937 			}
       
   938 		}
       
   939 
       
   940 	aTest.Next(_L("Free the buffer"));
       
   941 	r=aCam.ReleaseBuffer(retId);
       
   942 	aTest(r==KErrNone);
       
   943 
       
   944 	aTest.Next(_L("Issue two consecutive capture requests"));
       
   945 	TRequestStatus rs2;
       
   946 	aCam.NotifyNewImage(rs1);
       
   947 	aCam.NotifyNewImage(rs2);
       
   948 
       
   949 	User::WaitForRequest(rs1);
       
   950 	retId=rs1.Int();
       
   951 	aTest(retId>=0);
       
   952 	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
   953 	aTest.Printf(_L("Buffer0 offset: %d(%xH)\r\n"),retOffset,retOffset);
       
   954 	aTest(retOffset>=0);
       
   955 
       
   956 	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   957 		{
       
   958 		// Display the image received for 1s
       
   959 		imgBase=chunkImage.Base()+retOffset;
       
   960 		r=dispHand.Process(imgBase);
       
   961 		
       
   962 #ifdef __WINSCW__
       
   963         aTest(r==KErrNotSupported);
       
   964 #else
       
   965         aTest(r==KErrNone);
       
   966 #endif
       
   967         
       
   968 		User::After(1000000);	// 1 sec
       
   969 		}
       
   970 
       
   971 	r=aCam.ReleaseBuffer(retId);
       
   972 	aTest(r==KErrNone);
       
   973 
       
   974 	User::WaitForRequest(rs2);
       
   975 	retId=rs2.Int();
       
   976 	aTest(retId>=0);
       
   977 	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
   978 	aTest.Printf(_L("Buffer1 offset: %d(%xH)\r\n"),retOffset,retOffset);
       
   979 	aTest(retOffset>=0);
       
   980 
       
   981 	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
   982 		{
       
   983 		// Display the image received for 1s
       
   984 		imgBase=chunkImage.Base()+retOffset;
       
   985 		r=dispHand.Process(imgBase);
       
   986 		
       
   987 #ifdef __WINSCW__
       
   988         aTest(r==KErrNotSupported);
       
   989 #else
       
   990         aTest(r==KErrNone);
       
   991 #endif
       
   992         
       
   993 		User::After(1000000);	// 1 sec
       
   994 		}
       
   995 
       
   996 	r=aCam.ReleaseBuffer(retId);
       
   997 	aTest(r==KErrNone);
       
   998 
       
   999 	aTest.Next(_L("Issue four more separate capture requests"));
       
  1000 	for (TInt i=0 ; i<4 ; i++)
       
  1001 		{
       
  1002 		aCam.NotifyNewImage(rs1);
       
  1003 		User::WaitForRequest(rs1);
       
  1004 		retId=rs1.Int();
       
  1005 		aTest(retId>=0);
       
  1006 		aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
  1007 		aTest.Printf(_L("Buffer%d offset: %d(%xH)\r\n"),i,retOffset,retOffset);
       
  1008 		aTest(retOffset>=0);
       
  1009 
       
  1010 		if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
       
  1011 			{
       
  1012 			// Display the image received for 1s
       
  1013 			imgBase=chunkImage.Base()+retOffset;
       
  1014 			r=dispHand.Process(imgBase);
       
  1015 			
       
  1016 #ifdef __WINSCW__
       
  1017             aTest(r==KErrNotSupported);
       
  1018 #else
       
  1019             aTest(r==KErrNone);
       
  1020 #endif
       
  1021             
       
  1022 			User::After(1000000);	// 1 sec
       
  1023 			}
       
  1024 		}
       
  1025 
       
  1026 	r=aCam.ReleaseBuffer(retId);
       
  1027 	aTest(r==KErrNone);
       
  1028 
       
  1029 	aTest.Next(_L("Stop the camera."));
       
  1030 	r=aCam.Stop();
       
  1031 	aTest(r==KErrNone);
       
  1032 
       
  1033 	aTest.Next(_L("Close the chunk"));
       
  1034 	r=aCam.ChunkClose(ECamCaptureModeImage);
       
  1035 	aTest(r==KErrNone);
       
  1036 	}
       
  1037 
       
  1038 LOCAL_C void DoCamCancelTests(RTest& aTest, TInt aCameraSensorIndex)
       
  1039 	{
       
  1040 	TInt bufferSize, r;
       
  1041 	SDevCamFrameSize* frameSizes;
       
  1042 	TCameraConfigV02Buf camConfBuf;
       
  1043 
       
  1044 	aTest.Next(_L("CAPTURE CANCEL TESTS"));
       
  1045 
       
  1046 	RDevCameraSc cam;
       
  1047 	aTest.Next(_L("Open a channel on the camera driver"));
       
  1048 	r=cam.Open(aCameraSensorIndex);
       
  1049 	aTest(r==KErrNone);
       
  1050 
       
  1051 	TInt numBuffers=KNumVideoFramesToAllocate;
       
  1052 	SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
       
  1053 
       
  1054 	// Test Image Capture, if supported
       
  1055 	if (CameraCaps->iNumImagePixelFormats)
       
  1056 		{
       
  1057 		// If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1058 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1059 		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1060 		Test(frameSizes != NULL);
       
  1061 		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1062 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1063 		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1064 		Test(r == KErrNone);
       
  1065 
       
  1066 		cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
  1067 
       
  1068 		camConfBuf().iFrameSize=frameSizes[0];
       
  1069 		camConfBuf().iPixelFormat=*pixelFormat;
       
  1070 		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
       
  1071 
       
  1072 		// Set the camera configuration.
       
  1073 		r=cam.SetCamConfig(ECamCaptureModeImage, camConfBuf);
       
  1074 		aTest(r==KErrNone);
       
  1075 		cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
       
  1076 		PrintCamConf(camConfBuf(), aTest);
       
  1077 
       
  1078 		// Create a chunk handle and trigger the buffer creation.
       
  1079 		RChunk chunkImage;
       
  1080 		aTest.Next(_L("Setup the config - creating a chunk for image capture"));
       
  1081 		r=cam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
       
  1082 		aTest(r==KErrNone);
       
  1083 
       
  1084 		aTest.Next(_L("Read and display the resulting buffer config"));
       
  1085 		TMmSharedChunkBufConfig bufferConfig;
       
  1086 		TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
       
  1087 		cam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
       
  1088 		PrintBufferConf(bufferConfig,aTest);
       
  1089 
       
  1090 		// Set the current capture mode
       
  1091 		r=cam.SetCaptureMode(ECamCaptureModeImage);
       
  1092 		aTest(r==KErrNone);
       
  1093 
       
  1094 		aTest.Next(_L("Start the camera in image capture mode."));
       
  1095 		r=cam.Start();
       
  1096 		aTest(r==KErrNone);
       
  1097 
       
  1098 		TRequestStatus rs[KNumVideoFramesToCapture];
       
  1099 		TInt retId, retOffset;
       
  1100 
       
  1101 		aTest.Next(_L("Issue a request and then cancel it"));
       
  1102 		cam.NotifyNewImage(rs[0]);
       
  1103 		cam.NotifyNewImageCancel();
       
  1104 		User::WaitForRequest(rs[0]);
       
  1105 		retId=rs[0].Int();
       
  1106 		aTest(retId==KErrCancel || retId>=0);
       
  1107 		if (retId>=0)
       
  1108 			{
       
  1109 			cam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
       
  1110 			aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
       
  1111 			aTest(retOffset>=0);
       
  1112 			cam.ReleaseBuffer(retId);
       
  1113 			}
       
  1114 
       
  1115 		aTest.Next(_L("Stop the camera."));
       
  1116 		r=cam.Stop();
       
  1117 		aTest(r==KErrNone);
       
  1118 
       
  1119 		aTest.Next(_L("Close the Image chunk"));
       
  1120 		chunkImage.Close();
       
  1121 
       
  1122 		delete [] frameSizes;
       
  1123 		}
       
  1124 
       
  1125 	// Skip past the image pixel formats
       
  1126 	pixelFormat += CameraCaps->iNumImagePixelFormats;
       
  1127 
       
  1128 	// Test Video Capture, if supported
       
  1129 	if (CameraCaps->iNumVideoPixelFormats)
       
  1130 		{
       
  1131 		// If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1132 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1133 		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1134 		Test(frameSizes != NULL);
       
  1135 		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1136 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1137 		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1138 		Test(r == KErrNone);
       
  1139 
       
  1140 		cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
  1141 
       
  1142 		camConfBuf().iFrameSize=frameSizes[0];
       
  1143 		camConfBuf().iPixelFormat=*pixelFormat;
       
  1144 		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
       
  1145 
       
  1146 		// Set the camera configuration.
       
  1147 		r=cam.SetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
  1148 		aTest(r==KErrNone);
       
  1149 		cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
       
  1150 		PrintCamConf(camConfBuf(), aTest);
       
  1151 
       
  1152 		// Create a chunk handle and trigger the buffer creation.
       
  1153 		RChunk chunkVideo;
       
  1154 		aTest.Next(_L("Setup the config - creating a chunk for video capture"));
       
  1155 		r=cam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
       
  1156 		aTest(r==KErrNone);
       
  1157 
       
  1158 		aTest.Next(_L("Read and display the resulting buffer config"));
       
  1159 		TMmSharedChunkBufConfig bufferConfig;
       
  1160 		TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
       
  1161 		cam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBufVideo);
       
  1162 		PrintBufferConf(bufferConfig,aTest);
       
  1163 
       
  1164 		// Set the current capture mode
       
  1165 		r=cam.SetCaptureMode(ECamCaptureModeVideo);
       
  1166 		aTest(r==KErrNone);
       
  1167 
       
  1168 		aTest.Next(_L("Start the camera in video mode"));
       
  1169 		r=cam.Start();
       
  1170 		aTest(r==KErrNone);
       
  1171 
       
  1172 		aTest.Next(_L("Issue capture requests and globally cancel them all"));
       
  1173 		aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
       
  1174 		TRequestStatus rs[KNumVideoFramesToCapture];
       
  1175 		TInt i;
       
  1176 		for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
  1177 			cam.NotifyNewImage(rs[i]);
       
  1178 
       
  1179 		cam.NotifyNewImageCancel();
       
  1180 
       
  1181 		TInt retOffset = -2;
       
  1182 		TInt retId = -2;
       
  1183 		for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
  1184 			{
       
  1185 			User::WaitForRequest(rs[i]);
       
  1186 			retId=rs[i].Int();
       
  1187 			aTest(retId==KErrCancel || retId>=0);
       
  1188 			if (retId>=0)
       
  1189 				{
       
  1190 				cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
       
  1191 				aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
       
  1192 				aTest(retOffset>=0);
       
  1193 				cam.ReleaseBuffer(retId);
       
  1194 				}
       
  1195 			}
       
  1196 
       
  1197 		aTest.Next(_L("Issue capture requests and individually cancel them all"));
       
  1198 		aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
       
  1199 
       
  1200 		for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
  1201 			cam.NotifyNewImage(rs[i]);
       
  1202 
       
  1203 		for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
  1204 			cam.NotifyNewImageCancel(rs[i]);
       
  1205 
       
  1206 		for (i=0 ; i<KNumVideoFramesToCapture; i++)
       
  1207 			{
       
  1208 			User::WaitForRequest(rs[i]);
       
  1209 			retId=rs[i].Int();
       
  1210 			aTest(retId==KErrCancel || retId>=0);
       
  1211 			if (retId>=0)
       
  1212 				{
       
  1213 				cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
       
  1214 				aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
       
  1215 				aTest(retOffset>=0);
       
  1216 				cam.ReleaseBuffer(retId);
       
  1217 				}
       
  1218 			}
       
  1219 
       
  1220 		aTest.Next(_L("Stop the camera."));
       
  1221 		r=cam.Stop();
       
  1222 		aTest(r==KErrNone);
       
  1223 
       
  1224 		aTest.Next(_L("Close the Video chunk"));
       
  1225 		chunkVideo.Close();
       
  1226 
       
  1227 		delete [] frameSizes;
       
  1228 		}
       
  1229 
       
  1230 	// Skip past the video pixel formats
       
  1231 	pixelFormat += CameraCaps->iNumVideoPixelFormats;
       
  1232 
       
  1233 	// Test Viewfinder Capture, if supported
       
  1234 	if (CameraCaps->iNumViewFinderPixelFormats)
       
  1235 		{
       
  1236 		// If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1237 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1238 		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1239 		Test(frameSizes != NULL);
       
  1240 		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1241 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1242 		r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1243 		Test(r == KErrNone);
       
  1244 
       
  1245 		cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
       
  1246 
       
  1247 		camConfBuf().iFrameSize=frameSizes[0];
       
  1248 		camConfBuf().iPixelFormat=*pixelFormat;
       
  1249 		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
       
  1250 
       
  1251 		// Set the camera configuration.
       
  1252 		r=cam.SetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
       
  1253 		aTest(r==KErrNone);
       
  1254 		cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
       
  1255 		PrintCamConf(camConfBuf(), aTest);
       
  1256 
       
  1257 		// Create a chunk handle and trigger the buffer creation.
       
  1258 		RChunk chunkViewFinder;
       
  1259 		aTest.Next(_L("Setup the config - creating a chunk for viewfinder capture"));
       
  1260 		r=cam.SetBufConfigChunkCreate(ECamCaptureModeViewFinder,numBuffers,chunkViewFinder);
       
  1261 		aTest(r==KErrNone);
       
  1262 
       
  1263 		aTest.Next(_L("Read and display the resulting buffer config"));
       
  1264 		TMmSharedChunkBufConfig bufferConfig;
       
  1265 		TPckg<TMmSharedChunkBufConfig> bufferConfigBufViewFinder(bufferConfig);
       
  1266 		cam.GetBufferConfig(ECamCaptureModeViewFinder, bufferConfigBufViewFinder);
       
  1267 		PrintBufferConf(bufferConfig,aTest);
       
  1268 
       
  1269 		aTest.Next(_L("Close the Viewfinder chunk"));
       
  1270 		chunkViewFinder.Close();
       
  1271 
       
  1272 		delete [] frameSizes;
       
  1273 		}
       
  1274 
       
  1275 	aTest.Next(_L("Close the drivers"));
       
  1276 	cam.Close();
       
  1277 	}
       
  1278 
       
  1279 void CameraTests(TInt aCameraSensorIndex)
       
  1280 	{
       
  1281 	TUint index, size;
       
  1282 	Test.Printf(_L("Testing unit number: %d\r\n"),aCameraSensorIndex);
       
  1283 
       
  1284 	// Perform some basic opening and multithreaded tests.  We don't want just in time debugging during
       
  1285 	// these tests
       
  1286 	TBool justInTime=User::JustInTime();
       
  1287 	User::SetJustInTime(EFalse);
       
  1288 	DoCamOpenCapTests(Test,aCameraSensorIndex);
       
  1289 	User::SetJustInTime(justInTime);
       
  1290 
       
  1291 	// Test request handling
       
  1292 	DoCamCancelTests(Test, aCameraSensorIndex);
       
  1293 
       
  1294 	// Re-open the camera driver for use below and to ensure that it can deal with being re-opened (it
       
  1295 	// has already been opened and closed by DoCamOpenCapTests())
       
  1296 	RDevCameraSc cam;
       
  1297 	Test.Next(_L("Open a channel on the camera driver"));
       
  1298 	TInt r=cam.Open(aCameraSensorIndex);
       
  1299 	Test(r==KErrNone);
       
  1300 
       
  1301 	// Test Dynamic Settings, e.g. Brightness, Contrast, etc.
       
  1302 	DoCamDynamicSettingsTests(cam, Test);
       
  1303 	
       
  1304 	// Go through all supported image, video and viewfinder pixel formats and perform configuration
       
  1305 	// and capture tests on them all, for all supported frame sizes and frame rates
       
  1306 	TInt bufferSize;
       
  1307 	SDevCamFrameSize* frameSizes;
       
  1308 	TBool imageConfigTestsDone=EFalse, videoConfigTestsDone=EFalse, viewFinderConfigTestsDone=EFalse;
       
  1309 	SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
       
  1310 
       
  1311 	for (index = 0; index < CameraCaps->iNumImagePixelFormats; ++index)
       
  1312 		{
       
  1313 		// If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1314 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1315 		Test.Printf(_L("Image pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
       
  1316 		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1317 		Test(frameSizes!=NULL);
       
  1318 		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1319 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1320 		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1321 		Test(r == KErrNone);
       
  1322 
       
  1323 		// Test camera configuration for image capture.  This is only done once for the sake of
       
  1324 		// test expediency
       
  1325 		if (!imageConfigTestsDone)
       
  1326 			{
       
  1327 			imageConfigTestsDone = ETrue;
       
  1328 			DoCamConfigTests(cam, Test, ECamCaptureModeImage, *pixelFormat, frameSizes[0]);
       
  1329 			}
       
  1330 
       
  1331 		// Test image capture mode
       
  1332 		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
       
  1333 			{
       
  1334 			DoCamImageCaptureTests(cam, Test, aCameraSensorIndex, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
       
  1335 			}
       
  1336 
       
  1337 		// Test buffer offset
       
  1338 		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
       
  1339 			{
       
  1340 			DoCamBufferOffsetTests(cam, Test, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
       
  1341 			}
       
  1342 
       
  1343 		delete [] frameSizes;
       
  1344 		++pixelFormat;
       
  1345 		}
       
  1346 
       
  1347 	for (index = 0; index < CameraCaps->iNumVideoPixelFormats; ++index)
       
  1348 		{
       
  1349 		// If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1350 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1351 		Test.Printf(_L("Video pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
       
  1352 		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1353 		Test(frameSizes!=NULL);
       
  1354 		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1355 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1356 		r = cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1357 		Test(r == KErrNone);
       
  1358 
       
  1359 		// Test camera configuration for video capture.  This is only done once for the sake of
       
  1360 		// test expediency
       
  1361 		if (!videoConfigTestsDone)
       
  1362 			{
       
  1363 			videoConfigTestsDone=ETrue;
       
  1364 			DoCamConfigTests(cam, Test, ECamCaptureModeVideo, *pixelFormat, frameSizes[0]);
       
  1365 			}
       
  1366 
       
  1367 		// Test video capture mode
       
  1368 		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
       
  1369 			{
       
  1370 			DoCamVideoCaptureTests(cam, Test, ECamCaptureModeVideo, *pixelFormat,frameSizes[size], frameSizes[size].iMaxFrameRate);
       
  1371 			}
       
  1372 		delete [] frameSizes;
       
  1373 		++pixelFormat;
       
  1374 		}
       
  1375 
       
  1376 	for (index = 0; index < CameraCaps->iNumViewFinderPixelFormats; ++index)
       
  1377 		{
       
  1378 		// If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
       
  1379 		Test(pixelFormat->iNumFrameSizes > 0);
       
  1380 		Test.Printf(_L("Viewfinder pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
       
  1381 		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
       
  1382 		Test(frameSizes!=NULL);
       
  1383 		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
       
  1384 		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
       
  1385 		r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
       
  1386 		Test(r == KErrNone);
       
  1387 
       
  1388 		// Test camera configuration for view finder capture.  This is only done once for the sake of
       
  1389 		// test expediency
       
  1390 		if (!viewFinderConfigTestsDone)
       
  1391 			{
       
  1392 			viewFinderConfigTestsDone=ETrue;
       
  1393 			DoCamConfigTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[0]);
       
  1394 			}
       
  1395 
       
  1396 		// Test view finder capture mode
       
  1397 		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
       
  1398 			{
       
  1399 			DoCamVideoCaptureTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
       
  1400 			}
       
  1401 		delete [] frameSizes;
       
  1402 		++pixelFormat;
       
  1403 		}
       
  1404 	cam.Close();
       
  1405 
       
  1406 	// And free the global capabilities buffer that was allocated in DoCamOpenCapTests()
       
  1407 	User::Free(CapsBufPtr);
       
  1408 	}
       
  1409 
       
  1410 GLDEF_C TInt E32Main()
       
  1411 	{
       
  1412 	__UHEAP_MARK;
       
  1413 
       
  1414 	Test.Title();
       
  1415 	Test.Start(_L("Camera module API test"));
       
  1416 
       
  1417 	Test.Next(_L("Loading CAMERA PDD"));
       
  1418 	TInt r=User::LoadPhysicalDevice(KCamPddFileName);
       
  1419 	Test.Printf(_L("Returned %d\r\n"),r);
       
  1420 
       
  1421 	if (r==KErrNotFound)
       
  1422 		{
       
  1423 		Test.Printf(_L("Shared chunk camera driver not supported - test skipped\r\n"));
       
  1424 		Test.End();
       
  1425 		Test.Close();
       
  1426 		__UHEAP_MARKEND;
       
  1427 		return(KErrNone);
       
  1428 		}
       
  1429 
       
  1430 	Test(r==KErrNone || r==KErrAlreadyExists);
       
  1431 
       
  1432 	Test.Next(_L("Loading CAMERA LDD"));
       
  1433 	r=User::LoadLogicalDevice(KCamLddFileName);
       
  1434 	Test.Printf(_L("Returned %d\r\n"),r);
       
  1435 	Test(r==KErrNone || r==KErrAlreadyExists);
       
  1436 
       
  1437 	Test.Next(_L("Loading D_MMCSC LDD"));
       
  1438 	r=User::LoadLogicalDevice(KTstLddFileName);
       
  1439 	Test.Printf(_L("Returned %d\r\n"),r);
       
  1440 	Test(r==KErrNone||r==KErrAlreadyExists);
       
  1441 
       
  1442 	__KHEAP_MARK;
       
  1443 
       
  1444 	if (User::CommandLineLength()>0)
       
  1445 		{
       
  1446 		TBuf<0x100> cmd;
       
  1447 		TInt moduleIndex = KUnit0;
       
  1448 		User::CommandLine(cmd);
       
  1449 		Test(cmd.Length()>0);
       
  1450 		if (cmd[0]>='0' && cmd[0]<='9')
       
  1451 			moduleIndex=(TInt)(cmd[0]-'0');
       
  1452 		CameraTests(moduleIndex);
       
  1453 		}
       
  1454 	else // If no command line arguments are passed we perform tests on the module 0 and 1
       
  1455 		{
       
  1456 		CameraTests(0);
       
  1457 		}
       
  1458 
       
  1459 	__KHEAP_MARKEND;
       
  1460 
       
  1461 	// Free the PDDs and LDDs
       
  1462 	Test.Next(_L("Freeing ECAMERASC LDD"));
       
  1463 	r=User::FreeLogicalDevice(KDevCameraScName);
       
  1464 	Test(r==KErrNone);
       
  1465 
       
  1466 	Test.Next(_L("Freeing CAMERASC PDD"));
       
  1467 	TFindPhysicalDevice fDr;
       
  1468 	TFullName drivName;
       
  1469 	TName searchName;
       
  1470 	searchName.Append(KDevCameraScName);
       
  1471 	searchName.Append(KCamFreePddExtension);
       
  1472 	fDr.Find(searchName);
       
  1473 	r=fDr.Next(drivName);
       
  1474 	Test(r==KErrNone);
       
  1475 	r=User::FreePhysicalDevice(drivName);
       
  1476 	Test(r==KErrNone);
       
  1477 
       
  1478 	Test.Next(_L("Freeing D_MMCSC LDD"));
       
  1479 	r=User::FreeLogicalDevice(KDevMmCScName);
       
  1480 	Test(r==KErrNone);
       
  1481 
       
  1482 	Test.End();
       
  1483 	Test.Close();
       
  1484 
       
  1485 	__UHEAP_MARKEND;
       
  1486 	return(KErrNone);
       
  1487 	}