os/kernelhwsrv/kerneltest/e32test/multimedia/t_camera_api.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/multimedia/t_camera_api.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1487 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\multimedia\t_camera_api.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +#include <d32camerasc.h>
    1.23 +#include <e32def.h>
    1.24 +#include <e32def_private.h>
    1.25 +#include "t_camera_display.h"
    1.26 +#include "t_camera_bitmap.h"
    1.27 +#include "d_mmcsc.h"
    1.28 +
    1.29 +_LIT(KTstLddFileName,"D_MMCSC.LDD");
    1.30 +_LIT(KCamLddFileName,"ECAMERASC.LDD");
    1.31 +
    1.32 +#ifdef __WINSCW__
    1.33 +_LIT(KCamPddFileName,"_TEMPLATE_CAMERASC.PDD");
    1.34 +#else
    1.35 +_LIT(KCamPddFileName,"CAMERASC.PDD");
    1.36 +#endif
    1.37 +
    1.38 +
    1.39 +_LIT(KCamFreePddExtension,".*");
    1.40 +
    1.41 +_LIT(KFrameSize, "%dx%d");
    1.42 +_LIT(KSensor, "d:\\Sensor_");
    1.43 +_LIT(KUnderscore, "_");
    1.44 +_LIT(KBmp, ".bmp");
    1.45 +_LIT(KJpeg, ".jpg");
    1.46 +_LIT(KSpeedTaggedJpeg, ".stj");
    1.47 +
    1.48 +LOCAL_D TCameraCapsV02* CameraCaps;
    1.49 +LOCAL_D TInt CapsSize;
    1.50 +LOCAL_D TAny* CapsBufPtr;
    1.51 +RTest Test(_L("T_CAMERA_API"));
    1.52 +
    1.53 +const TInt KNumVideoFramesToAllocate=6;
    1.54 +const TInt KNumVideoFramesToCapture=(KNumVideoFramesToAllocate-2);
    1.55 +const TInt KHeapSize=0x4000;
    1.56 +const TInt KUnit0=0;
    1.57 +
    1.58 +enum TSecThreadTestId
    1.59 +	{
    1.60 +	ESecThreadTestOpen,
    1.61 +	ESecThreadTestDuplicateHandle,
    1.62 +	ESecThreadReuseHandle
    1.63 +	};
    1.64 +
    1.65 +struct SSecondaryThreadInfo
    1.66 +	{
    1.67 +	TSecThreadTestId iTestId;
    1.68 +	TInt iExpectedRetVal;
    1.69 +	TThreadId iThreadId;
    1.70 +	TInt iDrvHandle;
    1.71 +	TInt iCameraModuleIndex;
    1.72 +	};
    1.73 +
    1.74 +LOCAL_C TInt secondaryThread(TAny* aTestInfo)
    1.75 +	{
    1.76 +	RTest stest(_L("Secondary test camera thread"));
    1.77 +	stest.Title();
    1.78 +
    1.79 +	stest.Start(_L("Check which test to perform"));
    1.80 +	SSecondaryThreadInfo sti =*((SSecondaryThreadInfo*)aTestInfo);
    1.81 +	
    1.82 +	TInt r;
    1.83 +	switch(sti.iTestId)
    1.84 +		{
    1.85 +		case ESecThreadTestOpen:
    1.86 +			{
    1.87 +			stest.Next(_L("Open channel test"));
    1.88 +			RDevCameraSc cam;
    1.89 +			r=cam.Open(sti.iCameraModuleIndex);
    1.90 +			stest(r==sti.iExpectedRetVal);
    1.91 +			cam.Close();
    1.92 +			break;
    1.93 +			}
    1.94 +		case ESecThreadTestDuplicateHandle:
    1.95 +			{
    1.96 +			stest.Next(_L("Duplicate channel handle test"));
    1.97 +
    1.98 +			// Get a reference to the main thread - which created the handle
    1.99 +			RThread thread;
   1.100 +			r=thread.Open(sti.iThreadId);
   1.101 +			stest(r==KErrNone);
   1.102 +
   1.103 +			// Duplicate the driver handle passed from the other thread - for this thread
   1.104 +			RDevCameraSc cam;
   1.105 +			cam.SetHandle(sti.iDrvHandle);
   1.106 +			r=cam.Duplicate(thread);
   1.107 +			stest(r==sti.iExpectedRetVal);
   1.108 +			cam.Close();
   1.109 +			thread.Close();
   1.110 +			break;
   1.111 +			}
   1.112 +		case ESecThreadReuseHandle:
   1.113 +			{
   1.114 +			stest.Next(_L("Re-use channel test"));
   1.115 +			RDevCameraSc* camPtr=(RDevCameraSc*)sti.iDrvHandle;
   1.116 +			TCameraConfigV02Buf camConfBuf;
   1.117 +			camPtr->GetCamConfig(ECamCaptureModeImage, camConfBuf);	// This should cause a panic.
   1.118 +			break;
   1.119 +			}
   1.120 +		default:
   1.121 +			break;
   1.122 +		}
   1.123 +
   1.124 +	stest.End();
   1.125 +	return(KErrNone);
   1.126 +	}
   1.127 +
   1.128 +/** Test for defect DEF135950. */
   1.129 +LOCAL_C void DoCamDynamicSettingsTests(RDevCameraSc& aCam, RTest& aTest)
   1.130 +	{
   1.131 +	aTest.Next(_L("DYNAMIC SETTINGS TESTS"));
   1.132 +	
   1.133 +	aTest.Next(_L("Get the Caps size. Should be non-zero"));
   1.134 +	TInt capsSize = aCam.CapsSize();
   1.135 +	aTest(capsSize>0);
   1.136 +
   1.137 +	aTest.Next(_L("Get the Capabilities (driver owned copy)."));
   1.138 +	TPtrC8 driverCopy = aCam.Caps();
   1.139 +	aTest(driverCopy.Ptr() != NULL);
   1.140 +	aTest(driverCopy.Length()>0);
   1.141 +
   1.142 +	aTest.Next(_L("Test failure (buffer too small)."));
   1.143 +	TAny* capsBufPtr = User::Alloc(capsSize-1);
   1.144 +	aTest(capsBufPtr != NULL);
   1.145 +	TPtr8 smallBuf((TUint8*) capsBufPtr, capsSize-1, capsSize-1);
   1.146 +	aTest(KErrArgument==aCam.Caps(smallBuf));
   1.147 +	User::Free(capsBufPtr);
   1.148 +
   1.149 +	aTest.Next(_L("Get the Capabilities (client owned copy)."));
   1.150 +	capsBufPtr = User::Alloc(capsSize);
   1.151 +	aTest(capsBufPtr != NULL);
   1.152 +	TPtr8 clientCopy((TUint8*) capsBufPtr, capsSize, capsSize);
   1.153 +	aTest(KErrNone==aCam.Caps(clientCopy));
   1.154 +	aTest(clientCopy.Ptr() != NULL);
   1.155 +	aTest(clientCopy.Length()>0);
   1.156 +
   1.157 +	aTest.Next(_L("Obtain the range for Dynamic Settings from both copies (should be the same)."));
   1.158 +	
   1.159 +	TDynamicRange &driverRangeBrightness = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
   1.160 +	TDynamicRange &clientRangeBrightness = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeBrightness];
   1.161 +	
   1.162 +	aTest(driverRangeBrightness.iMin == 0);
   1.163 +	aTest(driverRangeBrightness.iMax == 6);
   1.164 +	aTest(driverRangeBrightness.iMin == clientRangeBrightness.iMin);
   1.165 +	aTest(driverRangeBrightness.iMax == clientRangeBrightness.iMax);
   1.166 +
   1.167 +	TDynamicRange &driverRangeContrast = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
   1.168 +	TDynamicRange &clientRangeContrast = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeContrast];
   1.169 +
   1.170 +	aTest(driverRangeContrast.iMin == 0);
   1.171 +	aTest(driverRangeContrast.iMax == 6);
   1.172 +	aTest(driverRangeContrast.iMin == clientRangeContrast.iMin);
   1.173 +	aTest(driverRangeContrast.iMax == clientRangeContrast.iMax);
   1.174 +	
   1.175 +	TDynamicRange &driverRangeColorEffect = ((TCameraCapsV02*)(driverCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
   1.176 +	TDynamicRange &clientRangeColorEffect = ((TCameraCapsV02*)(clientCopy.Ptr()))->iDynamicRange[ECamAttributeColorEffect];
   1.177 +
   1.178 +	aTest(driverRangeColorEffect.iMin == 0);
   1.179 +	aTest(driverRangeColorEffect.iMax == 7); // TBC::OV3640 set to 7, template driver set to 0x0040 (enum)
   1.180 +	aTest(driverRangeColorEffect.iMin == clientRangeColorEffect.iMin);
   1.181 +	aTest(driverRangeColorEffect.iMax == clientRangeColorEffect.iMax);
   1.182 +
   1.183 +	aTest.Next(_L("Test for invalid Min range."));
   1.184 +	aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMin-1)==KErrArgument);
   1.185 +	aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMin-1)==KErrArgument);
   1.186 +	aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMin-1)==KErrArgument);
   1.187 +
   1.188 +	aTest.Next(_L("Test for invalid Max range."));
   1.189 +	aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, driverRangeBrightness.iMax+1)==KErrArgument);
   1.190 +	aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, driverRangeContrast.iMax+1)==KErrArgument);
   1.191 +	aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, driverRangeColorEffect.iMax+1)==KErrArgument);
   1.192 +
   1.193 +	aTest.Next(_L("Test all valid settings as reported by range - Brightness"));
   1.194 +	for (TUint i=driverRangeBrightness.iMin; i <= driverRangeBrightness.iMax; ++i)
   1.195 +		{
   1.196 +		aTest(aCam.SetDynamicAttribute(ECamAttributeBrightness, i)==KErrNone);
   1.197 +		}
   1.198 +
   1.199 +	aTest.Next(_L("Test all valid settings as reported by range - Contrast"));
   1.200 +	for (TUint j=driverRangeContrast.iMin; j <= driverRangeContrast.iMax; ++j)
   1.201 +		{
   1.202 +		aTest(aCam.SetDynamicAttribute(ECamAttributeContrast, j)==KErrNone);
   1.203 +		}
   1.204 +
   1.205 +	aTest.Next(_L("Test all valid settings as reported by range - ColorEffect"));
   1.206 +	for (TUint k=driverRangeColorEffect.iMin; k <= driverRangeColorEffect.iMax; ++k)
   1.207 +		{
   1.208 +		aTest(aCam.SetDynamicAttribute(ECamAttributeColorEffect, k)==KErrNone);
   1.209 +		}
   1.210 +
   1.211 +	User::Free(capsBufPtr);
   1.212 +	}
   1.213 +
   1.214 +/** Test for defect DEF135949. */
   1.215 +LOCAL_C void DoCamBufferOffsetTests(RDevCameraSc& aCam, RTest& aTest, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
   1.216 +	{
   1.217 +	TInt r;
   1.218 +
   1.219 +	aTest.Next(_L("BUFFER ID OFFSET TESTS"));
   1.220 +	aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
   1.221 +
   1.222 +	// Configure Image Capture
   1.223 +	aTest.Next(_L("Get the camera config of Image mode"));
   1.224 +	TCameraConfigV02Buf camConfBuf;
   1.225 +	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
   1.226 +	TCameraConfigV02 &camConf=camConfBuf();
   1.227 +
   1.228 +	camConf.iFrameSize=aFrameSize;
   1.229 +	camConf.iPixelFormat=aPixelFormat;
   1.230 +	camConf.iFrameRate=aFrameRate;
   1.231 +
   1.232 +	// Set the Image configuration.
   1.233 +	aTest.Next(_L("Set the Get the camera config of Image mode"));
   1.234 +	r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
   1.235 +	aTest(r==KErrNone);
   1.236 +	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
   1.237 +	PrintCamConf(camConf,aTest);
   1.238 +
   1.239 +	// Create an Image chunk handle.
   1.240 +	aTest.Next(_L("Create the Image chunk"));
   1.241 +	RChunk imgChunkImage;
   1.242 +	TInt numBuffers=KNumVideoFramesToAllocate;
   1.243 +	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,imgChunkImage);
   1.244 +	aTest(r==KErrNone);
   1.245 +
   1.246 +	aTest.Next(_L("Read and display the Image buffer config"));
   1.247 +	TMmSharedChunkBufConfig bufferConfig;
   1.248 +	TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   1.249 +	aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBuf);
   1.250 +	PrintBufferConf(bufferConfig,aTest);
   1.251 +
   1.252 +	// Configure Video Capture
   1.253 +	aTest.Next(_L("Get the camera config of Video mode"));
   1.254 +	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
   1.255 +	camConf=camConfBuf();
   1.256 +
   1.257 +	camConf.iFrameSize=aFrameSize;
   1.258 +	camConf.iPixelFormat=aPixelFormat;
   1.259 +	camConf.iFrameRate=aFrameRate;
   1.260 +
   1.261 +	// Set the video configuration.
   1.262 +	aTest.Next(_L("Set the Get the camera config of Video mode"));
   1.263 +	r=aCam.SetCamConfig(ECamCaptureModeVideo,camConfBuf);
   1.264 +	aTest(r==KErrNone);
   1.265 +	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
   1.266 +	PrintCamConf(camConf,aTest);
   1.267 +
   1.268 +	// Create an Video chunk handle.
   1.269 +	aTest.Next(_L("Create the Video chunk"));
   1.270 +	RChunk chunkVideo;
   1.271 +	numBuffers=KNumVideoFramesToAllocate;
   1.272 +	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
   1.273 +	aTest(r==KErrNone);
   1.274 +
   1.275 +	aTest.Next(_L("Read and display the Video buffer config"));
   1.276 +	aCam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBuf);
   1.277 +	PrintBufferConf(bufferConfig,aTest);
   1.278 +
   1.279 +	// Test that stop still returns an error.
   1.280 +	r=aCam.Stop();
   1.281 +	aTest(r==KErrGeneral);
   1.282 +
   1.283 +	// Set the current capture mode to image
   1.284 +	aTest.Next(_L("Set the camera in Image mode and capture a buffer, then requesting the buffer offset."));
   1.285 +	r=aCam.SetCaptureMode(ECamCaptureModeImage);
   1.286 +	aTest(r==KErrNone);
   1.287 +
   1.288 +	// Start the camera
   1.289 +	r=aCam.Start();
   1.290 +	aTest(r==KErrNone);
   1.291 +
   1.292 +	aTest.Next(_L("Issue a capture request"));
   1.293 +	TRequestStatus rs1;
   1.294 +	aCam.NotifyNewImage(rs1);
   1.295 +	User::WaitForRequest(rs1);
   1.296 +	TInt retId=rs1.Int();
   1.297 +	TInt retOffset=-1;
   1.298 +	aTest(retId>=0);
   1.299 +	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
   1.300 +	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
   1.301 +	aTest(retOffset>=0);
   1.302 +
   1.303 +	// Change capture mode
   1.304 +	aTest.Next(_L("Set the capture mode to Video."));
   1.305 +	r=aCam.SetCaptureMode(ECamCaptureModeVideo);
   1.306 +	aTest(r==KErrNone);
   1.307 +
   1.308 +	aTest.Next(_L("Request again the offset for the buffer in Image mode."));
   1.309 +	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
   1.310 +	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
   1.311 +	aTest(retOffset>=0);
   1.312 +
   1.313 +	// Stop the camera.
   1.314 +	r=aCam.Stop();
   1.315 +	aTest(r==KErrNone);
   1.316 +
   1.317 +	aTest.Next(_L("Close the chunk"));
   1.318 +	r=aCam.ChunkClose(ECamCaptureModeImage);
   1.319 +	aTest(r==KErrNone);
   1.320 +	r=aCam.ChunkClose(ECamCaptureModeVideo);
   1.321 +	aTest(r==KErrNone);
   1.322 +	}
   1.323 +
   1.324 +
   1.325 +LOCAL_C void DoCamOpenCapTests(RTest& aTest,TInt aCameraSensorIndex)
   1.326 +	{
   1.327 +	TInt r;
   1.328 +
   1.329 +	// Open the camera driver to obtain the basic capabilities for use throughout the tests and
   1.330 +	// then close it again so that it may be confirmed that opening multiple times is ok
   1.331 +	aTest.Next(_L("CHANNEL OPEN AND CAPABILITIES TESTS"));
   1.332 +	RDevCameraSc cam;
   1.333 +	aTest.Next(_L("Open a channel on the camera driver"));
   1.334 +	r=cam.Open(aCameraSensorIndex);
   1.335 +	aTest(r==KErrNone);
   1.336 +
   1.337 +	// Make sure that the driver can handle attempts to start it before it has been configured
   1.338 +	aTest.Next(_L("Try to start/stop camera before its configured"));
   1.339 +	r=cam.Start();
   1.340 +	aTest(r==KErrNotReady);
   1.341 +	r=cam.Stop();
   1.342 +	aTest(r==KErrGeneral);
   1.343 +
   1.344 +	aTest.Next(_L("Read the capabilities structure size of this device"));
   1.345 +	CapsSize=cam.CapsSize();
   1.346 +	aTest.Next(_L("Read and display the capabilities of this device"));
   1.347 +	CapsBufPtr = User::Alloc(CapsSize);
   1.348 +	TPtr8 capsPtr( (TUint8*)CapsBufPtr, CapsSize, CapsSize );
   1.349 +	r=cam.Caps(capsPtr);
   1.350 +	aTest(r==KErrNone);
   1.351 +	CameraCaps = (TCameraCapsV02*) capsPtr.Ptr();
   1.352 +	PrintCamModes(CameraCaps,aTest);
   1.353 +
   1.354 +	TAny* frameSizeCapsBuf;
   1.355 +	SDevCamPixelFormat* pixelFormat;
   1.356 +	TBuf<80> buf;
   1.357 +	SDevCamFrameSize* frameSize;
   1.358 +	TPtr8 frameSizeCapsPtr(0,0,0);
   1.359 +	TUint fsCount, pfCount, theCount = 0;
   1.360 +
   1.361 +	/* IMAGE */
   1.362 +	/* Use pixel formats from 0 to CapsBuf->iNumImagePixelFormats */
   1.363 +	buf.Zero();
   1.364 +	buf.Append(KCaptureModeImage);
   1.365 +	buf.Append(_L("\r\n"));
   1.366 +	aTest.Printf(buf);
   1.367 +	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
   1.368 +	for (pfCount = theCount; pfCount < CameraCaps->iNumImagePixelFormats; pfCount++)
   1.369 +		{
   1.370 +		buf.Zero();
   1.371 +		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
   1.372 +		aTest.Printf(buf);
   1.373 +		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.374 +		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.375 +		r=cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizeCapsPtr);
   1.376 +		aTest(r==KErrNone);
   1.377 +		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
   1.378 +		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
   1.379 +			{
   1.380 +			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
   1.381 +			frameSize++;
   1.382 +			}
   1.383 +		aTest.Printf(_L("\n"));
   1.384 +		User::Free(frameSizeCapsBuf);
   1.385 +		pixelFormat++;
   1.386 +		}
   1.387 +
   1.388 +	/* VIDEO */
   1.389 +	buf.Zero();
   1.390 +	buf.Append(KCaptureModeVideo);
   1.391 +	buf.Append(_L("\r\n"));
   1.392 +	aTest.Printf(buf);
   1.393 +	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
   1.394 +	pixelFormat += CameraCaps->iNumImagePixelFormats;
   1.395 +	theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats;
   1.396 +	for (pfCount = CameraCaps->iNumImagePixelFormats; pfCount < theCount; pfCount++)
   1.397 +		{
   1.398 +		buf.Zero();
   1.399 +		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
   1.400 +		aTest.Printf(buf);
   1.401 +		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.402 +		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.403 +		r=cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizeCapsPtr);
   1.404 +		aTest(r==KErrNone);
   1.405 +		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
   1.406 +		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
   1.407 +			{
   1.408 +			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
   1.409 +			frameSize++;
   1.410 +			}
   1.411 +		aTest.Printf(_L("\n"));
   1.412 +		User::Free(frameSizeCapsBuf);
   1.413 +		pixelFormat++;
   1.414 +		}
   1.415 +
   1.416 +	/* VIEW FINDER */
   1.417 +	buf.Zero();
   1.418 +	buf.Append(KCaptureModeViewFinder);
   1.419 +	buf.Append(_L("\r\n"));
   1.420 +	aTest.Printf(buf);
   1.421 +	pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
   1.422 +	pixelFormat += (CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats);
   1.423 +	theCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats + CameraCaps->iNumViewFinderPixelFormats;
   1.424 +	for (pfCount = CameraCaps->iNumImagePixelFormats + CameraCaps->iNumVideoPixelFormats; pfCount < theCount; pfCount++)
   1.425 +		{
   1.426 +		buf.Zero();
   1.427 +		AppendPixelFormat(buf, pixelFormat->iPixelFormat);
   1.428 +		aTest.Printf(buf);
   1.429 +		frameSizeCapsBuf = User::Alloc(pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.430 +		new (&frameSizeCapsPtr) TPtr8((TUint8*)frameSizeCapsBuf, pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize), pixelFormat->iNumFrameSizes*sizeof(SDevCamFrameSize));
   1.431 +		r=cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizeCapsPtr);
   1.432 +		aTest(r==KErrNone);
   1.433 +		frameSize = (SDevCamFrameSize*) frameSizeCapsPtr.Ptr();
   1.434 +		for (fsCount = 0; fsCount < pixelFormat->iNumFrameSizes; fsCount++)
   1.435 +			{
   1.436 +			aTest.Printf(_L("%dx%d "),frameSize->iWidth,frameSize->iHeight);
   1.437 +			frameSize++;
   1.438 +			}
   1.439 +		aTest.Printf(_L("\n"));
   1.440 +		User::Free(frameSizeCapsBuf);
   1.441 +		pixelFormat++;
   1.442 +		}
   1.443 +
   1.444 +	aTest.Next(_L("Try opening the same unit a second time."));
   1.445 +	RDevCameraSc cam2;
   1.446 +	r=cam2.Open(aCameraSensorIndex);
   1.447 +	aTest(r==KErrInUse);
   1.448 +
   1.449 +	aTest.Next(_L("Open a channel from the 2nd thread without closing the 1st"));
   1.450 +	RThread thread;
   1.451 +	TRequestStatus stat;
   1.452 +	SSecondaryThreadInfo sti;
   1.453 +
   1.454 +	// Setup the 2nd thread to open a channel on the same unit
   1.455 +	sti.iTestId=ESecThreadTestOpen;
   1.456 +	sti.iExpectedRetVal=KErrInUse;
   1.457 +	sti.iCameraModuleIndex=aCameraSensorIndex;
   1.458 +	r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
   1.459 +	Test(r==KErrNone);
   1.460 +	thread.Logon(stat);
   1.461 +	thread.Resume();
   1.462 +	User::WaitForRequest(stat);
   1.463 +	Test(stat.Int()==KErrNone);
   1.464 +	Test(thread.ExitType()==EExitKill);
   1.465 +	thread.Close();
   1.466 +	User::After(10000);	// Wait 10ms
   1.467 +
   1.468 +	aTest.Next(_L("Open a channel from the 2nd thread having closed the 1st"));
   1.469 +	cam.Close();		// Close the 1st channel
   1.470 +	sti.iTestId=ESecThreadTestOpen;
   1.471 +	sti.iExpectedRetVal=KErrNone;
   1.472 +	r=thread.Create(_L("Thread02"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti);
   1.473 +	Test(r==KErrNone);
   1.474 +	thread.Logon(stat);
   1.475 +	thread.Resume();
   1.476 +	User::WaitForRequest(stat);
   1.477 +	Test(stat.Int()==KErrNone);
   1.478 +	Test(thread.ExitType()==EExitKill);
   1.479 +	thread.Close();
   1.480 +	User::After(10000);	// Wait 10ms
   1.481 +
   1.482 +	aTest.Next(_L("Re-open channel and duplicate it from 2nd thread"));
   1.483 +	r=cam.Open(aCameraSensorIndex);		// Re-open the channel
   1.484 +	aTest(r==KErrNone);
   1.485 +	sti.iTestId=ESecThreadTestDuplicateHandle;
   1.486 +	sti.iExpectedRetVal=KErrAccessDenied;
   1.487 +	sti.iThreadId=RThread().Id();	// Get the ID of this thread
   1.488 +	sti.iDrvHandle=cam.Handle();	// Pass the channel handle
   1.489 +
   1.490 +	r=thread.Create(_L("Thread03"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
   1.491 +	Test(r==KErrNone);
   1.492 +	thread.Logon(stat);
   1.493 +	thread.Resume();
   1.494 +	User::WaitForRequest(stat);
   1.495 +	Test(stat.Int()==KErrNone);
   1.496 +	Test(thread.ExitType()==EExitKill);
   1.497 +	thread.Close();
   1.498 +	User::After(10000);	// Wait 10ms
   1.499 +
   1.500 +	aTest.Next(_L("Re-use the same channel from 2nd thread"));
   1.501 +	sti.iTestId=ESecThreadReuseHandle;
   1.502 +	sti.iDrvHandle=(TInt)&cam;	// Pass a pointer to the channel
   1.503 +	r=thread.Create(_L("Thread04"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
   1.504 +	Test(r==KErrNone);
   1.505 +	thread.Logon(stat);
   1.506 +	thread.Resume();
   1.507 +	User::WaitForRequest(stat);
   1.508 +	TExitCategoryName exitCategoryName = thread.ExitCategory();
   1.509 +	Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&exitCategoryName,thread.ExitReason(),thread.ExitType());
   1.510 +	Test(thread.ExitType()==EExitPanic);	// Secondary thread is expected to panic
   1.511 +	Test(stat.Int()==KErrNone);
   1.512 +	thread.Close();
   1.513 +	User::After(10000);	// Wait 10ms
   1.514 +
   1.515 +	cam.Close();
   1.516 +	}
   1.517 +
   1.518 +LOCAL_C void DoCamConfigTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize)
   1.519 +	{
   1.520 +	TInt r;
   1.521 +
   1.522 +	aTest.Next(_L("GETTING & SETTING CONFIG TESTS"));
   1.523 +	aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
   1.524 +
   1.525 +	aTest.Next(_L("Read and display the default camera config for requested capture mode"));
   1.526 +	TCameraConfigV02Buf camConfBuf;
   1.527 +	aCam.GetCamConfig(aCaptureMode, camConfBuf);
   1.528 +	TCameraConfigV02 &camConf=camConfBuf();
   1.529 +	PrintCamConf(camConf,aTest);
   1.530 +
   1.531 +	aTest.Next(_L("Read and display the default buffer config for requested capture mode"));
   1.532 +	TMmSharedChunkBufConfig bufferConfig;
   1.533 +	TPckg<TMmSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
   1.534 +	aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
   1.535 +	PrintBufferConf(bufferConfig,aTest);
   1.536 +
   1.537 +	aTest.Next(_L("Setup the config - creating a chunk"));
   1.538 +	camConf.iFrameSize=aFrameSize;
   1.539 +	camConf.iPixelFormat=aPixelFormat;
   1.540 +	camConf.iFrameRate=aFrameSize.iMaxFrameRate;
   1.541 +	r=aCam.SetCamConfig(aCaptureMode, camConfBuf);
   1.542 +	aTest(r==KErrNone);
   1.543 +	RChunk chunk;
   1.544 +	r=aCam.SetBufConfigChunkCreate(aCaptureMode, KNumVideoFramesToAllocate, chunk);
   1.545 +	aTest(r==KErrNone);
   1.546 +	aCam.GetCamConfig(aCaptureMode, camConfBuf);
   1.547 +	PrintCamConf(camConf,aTest);
   1.548 +
   1.549 +	aTest.Next(_L("Read and display the resulting buffer config"));
   1.550 +	aCam.GetBufferConfig(aCaptureMode, bufferConfigBuf);
   1.551 +	PrintBufferConf(bufferConfig,aTest);
   1.552 +
   1.553 +	aTest.Next(_L("Close the chunk created"));
   1.554 +	chunk.Close();
   1.555 +
   1.556 +	aTest.Next(_L("Open a channel on the test driver"));
   1.557 +	RMmCreateSc tstDrv;
   1.558 +	r=tstDrv.Open();		// Opening the channel results in the creation of a shared chunk.
   1.559 +	aTest(r==KErrNone);
   1.560 +
   1.561 +	aTest.Next(_L("Get a handle on its shared chunk"));
   1.562 +	r=tstDrv.GetChunkHandle(chunk);	// Get a handle on the shared chunk created by the test driver
   1.563 +	aTest(r==KErrNone);
   1.564 +
   1.565 +	aTest.Next(_L("Read and display the buffer config"));
   1.566 +	TMmSharedChunkBufConfig bufferConfigTest;
   1.567 +	TPckg<TMmSharedChunkBufConfig> bufferConfigBufTest(bufferConfigTest);
   1.568 +
   1.569 +	// Get info on the buffers within the shared chunk
   1.570 +	aTest.Next(_L("Get info. on the shared chunk"));
   1.571 +	r=tstDrv.GetBufInfo(bufferConfigBufTest);
   1.572 +	aTest(r==KErrNone);
   1.573 +
   1.574 +	PrintBufferConf(bufferConfigTest,aTest);
   1.575 +	aTest.Next(_L("Setup the config - supplying a chunk"));
   1.576 +	r=aCam.SetBufConfigChunkOpen(aCaptureMode, bufferConfigBufTest, chunk);
   1.577 +	aTest(r==KErrNone);
   1.578 +	aCam.GetCamConfig(aCaptureMode, camConfBuf);
   1.579 +	PrintCamConf(camConf,aTest);
   1.580 +	aCam.GetBufferConfig(aCaptureMode, bufferConfigBufTest);
   1.581 +	PrintBufferConf(bufferConfigTest,aTest);
   1.582 +
   1.583 +	aTest.Next(_L("Close the chunk driver and the 2nd chunk"));
   1.584 +	tstDrv.Close();
   1.585 +	chunk.Close();
   1.586 +	}
   1.587 +
   1.588 +LOCAL_C void DoCamVideoCaptureTests(RDevCameraSc& aCam, RTest& aTest, TDevCamCaptureMode aCaptureMode, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
   1.589 +	{
   1.590 +	TInt r;
   1.591 +
   1.592 +	aTest.Next(_L("VIDEO CAPTURE TESTS"));
   1.593 +	aTest.Printf(_L("CaptureMode = %d, PixelFormat = %x, FrameSize = %d x %d\n"),aCaptureMode,aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
   1.594 +
   1.595 +	// Configure Video or Viewfinder Capture
   1.596 +	TCameraConfigV02Buf camConfBuf;
   1.597 +	aCam.GetCamConfig(aCaptureMode, camConfBuf);
   1.598 +	TCameraConfigV02 &camConf=camConfBuf();
   1.599 +
   1.600 +	camConf.iFrameSize=aFrameSize;
   1.601 +	camConf.iPixelFormat=aPixelFormat;
   1.602 +	camConf.iFrameRate=aFrameRate;
   1.603 +
   1.604 +	// Set the camera configuration.
   1.605 +	r=aCam.SetCamConfig(aCaptureMode,camConfBuf);
   1.606 +	aTest(r==KErrNone);
   1.607 +	aCam.GetCamConfig(aCaptureMode, camConfBuf);
   1.608 +	PrintCamConf(camConf,aTest);
   1.609 +
   1.610 +	// Create a chunk handle and trigger the buffer creation.
   1.611 +	aTest.Next(_L("Setup the config - creating a chunk"));
   1.612 +	RChunk chunkVideo;
   1.613 +	TInt numBuffers=KNumVideoFramesToAllocate;
   1.614 +	r=aCam.SetBufConfigChunkCreate(aCaptureMode,numBuffers,chunkVideo);
   1.615 +	aTest(r==KErrNone);
   1.616 +
   1.617 +	aTest.Next(_L("Read and display the resulting buffer config"));
   1.618 +	TMmSharedChunkBufConfig bufferConfig;
   1.619 +	TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
   1.620 +	aCam.GetBufferConfig(aCaptureMode, bufferConfigBufVideo);
   1.621 +	PrintBufferConf(bufferConfig,aTest);
   1.622 +
   1.623 +	// Request and print the camera and buffer configurations for all three capture modes
   1.624 +	aTest.Next(_L("Read and display the camera configs"));
   1.625 +	aCam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
   1.626 +	PrintCamConf(camConf,aTest);
   1.627 +	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
   1.628 +	PrintCamConf(camConf,aTest);
   1.629 +	aCam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
   1.630 +	PrintCamConf(camConf,aTest);
   1.631 +
   1.632 +	// Create and configure a display handler
   1.633 +	TCamDisplayHandler dispHand;
   1.634 +	r=dispHand.Init();
   1.635 +	aTest(r==KErrNone);
   1.636 +
   1.637 +	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.638 +		{
   1.639 +		r=dispHand.SetConfig(aFrameSize,aPixelFormat);
   1.640 +		aTest(r==KErrNone);
   1.641 +		}
   1.642 +
   1.643 +	// Test that stop still returns an error.
   1.644 +	r=aCam.Stop();
   1.645 +	aTest(r==KErrGeneral);
   1.646 +
   1.647 +	// Set the current capture mode
   1.648 +	r=aCam.SetCaptureMode(aCaptureMode);
   1.649 +	aTest(r==KErrNone);
   1.650 +
   1.651 +	aTest.Next(_L("Start the camera in video mode"));
   1.652 +	r=aCam.Start();
   1.653 +	aTest(r==KErrNone);
   1.654 +
   1.655 +	aTest.Next(_L("Issue capture requests"));
   1.656 +	aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
   1.657 +	// Issue new image requests immediately. We'll have to wait while the
   1.658 +	// camera captures the images.
   1.659 +	TRequestStatus rs[KNumVideoFramesToCapture];
   1.660 +	TInt i;
   1.661 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.662 +		{
   1.663 +		aTest.Printf(_L("Requesting new image... %d\n"), i);
   1.664 +		aCam.NotifyNewImage(rs[i]);
   1.665 +		aTest.Printf(_L("Requested new image... %d\n"), i);
   1.666 +		}
   1.667 +
   1.668 +	TInt retId=-1;
   1.669 +	TInt retOffset=-1;
   1.670 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.671 +		{
   1.672 +		aTest.Printf(_L("Waiting for... %d\n"), i);
   1.673 +		User::WaitForRequest(rs[i]);
   1.674 +		retId=rs[i].Int();
   1.675 +		aTest(retId>=0);
   1.676 +		aTest.Printf(_L("Getting buffer offset for... %d\n"), i);
   1.677 +		aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
   1.678 +		aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
   1.679 +		aTest(retOffset>=0);
   1.680 +		}
   1.681 +
   1.682 +	TUint8* imgBase;
   1.683 +
   1.684 +	// Display each image received for 333ms
   1.685 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.686 +		{
   1.687 +		if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.688 +			{
   1.689 +			retId=rs[i].Int();
   1.690 +			aTest(retId>=0);
   1.691 +			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
   1.692 +			aTest(retOffset>=0);
   1.693 +			imgBase=chunkVideo.Base()+retOffset;
   1.694 +			r=dispHand.Process(imgBase);
   1.695 +			
   1.696 +#ifdef __WINSCW__
   1.697 +			aTest(r==KErrNotSupported);
   1.698 +#else
   1.699 +			aTest(r==KErrNone);
   1.700 +#endif
   1.701 +
   1.702 +			User::After(333000);	// 0.33sec
   1.703 +			}
   1.704 +		}
   1.705 +
   1.706 +	aTest.Next(_L("Free the buffers"));
   1.707 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.708 +		{
   1.709 +		aTest.Printf(_L("Releasing %d(i:%d) "),rs[i].Int(), i);
   1.710 +		r=aCam.ReleaseBuffer(rs[i].Int());
   1.711 +		aTest.Printf(_L("buffer(%d), r=%d\n"),rs[i].Int(),r);
   1.712 +		aTest(r==KErrNone);
   1.713 +		}
   1.714 +
   1.715 +	aTest.Next(_L("Issue more capture requests"));
   1.716 +	// Wait a bit more so camera has images ready as soon as we issue the requests
   1.717 +	User::After(500000);	// 0.5sec
   1.718 +
   1.719 +	aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
   1.720 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.721 +		aCam.NotifyNewImage(rs[i]);
   1.722 +
   1.723 +	for (i=0 ; i<KNumVideoFramesToCapture; i++)
   1.724 +		{
   1.725 +		User::WaitForRequest(rs[i]);
   1.726 +		retId=rs[i].Int();
   1.727 +		aTest(retId>=0);
   1.728 +		aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
   1.729 +		aTest.Printf(_L("Buffer%d(id:%d) offset: %d(%xH)\r\n"),i,retId,retOffset,retOffset);
   1.730 +		aTest(retOffset>=0);
   1.731 +		}
   1.732 +
   1.733 +	aTest.Next(_L("Stop the camera."));
   1.734 +	r=aCam.Stop();
   1.735 +	aTest(r==KErrNone);
   1.736 +
   1.737 +	aTest.Next(_L("Start it again."));
   1.738 +	r=aCam.Start();
   1.739 +	aTest(r==KErrNone);
   1.740 +
   1.741 +	aTest.Next(_L("Continuously display for 10 secs"));
   1.742 +	RTimer tim;
   1.743 +	tim.CreateLocal();
   1.744 +	TRequestStatus timStatus;
   1.745 +	const TUint KTimeOut=10000000;	// 10 seconds
   1.746 +	tim.After(timStatus,KTimeOut);
   1.747 +	aTest(timStatus==KRequestPending);
   1.748 +	aCam.NotifyNewImage(rs[0]);
   1.749 +	aCam.NotifyNewImage(rs[1]);
   1.750 +	FOREVER
   1.751 +		{
   1.752 +		User::WaitForAnyRequest();
   1.753 +		if (timStatus!=KRequestPending)
   1.754 +			{
   1.755 +			aCam.NotifyNewImageCancel();
   1.756 +			User::WaitForRequest(rs[0]);
   1.757 +			User::WaitForRequest(rs[1]);
   1.758 +			break;
   1.759 +			}
   1.760 +		else if (rs[0]!=KRequestPending)
   1.761 +			{
   1.762 +			retId=rs[0].Int();
   1.763 +			aTest(retId>=0);
   1.764 +			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
   1.765 +			aTest(retOffset>=0);
   1.766 +			imgBase=chunkVideo.Base()+retOffset;
   1.767 +			if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.768 +				{
   1.769 +				r=dispHand.Process(imgBase);
   1.770 +				
   1.771 +#ifdef __WINSCW__
   1.772 +				aTest(r==KErrNotSupported);
   1.773 +#else
   1.774 +				aTest(r==KErrNone);
   1.775 +#endif
   1.776 +				
   1.777 +				}
   1.778 +			r=aCam.ReleaseBuffer(retId);
   1.779 +			aTest(r==KErrNone);
   1.780 +			aCam.NotifyNewImage(rs[0]);
   1.781 +			}
   1.782 +		else if (rs[1]!=KRequestPending)
   1.783 +			{
   1.784 +			retId=rs[1].Int();
   1.785 +			aTest(retId>=0);
   1.786 +			aCam.BufferIdToOffset(aCaptureMode,retId,retOffset);
   1.787 +			aTest(retOffset>=0);
   1.788 +			imgBase=chunkVideo.Base()+retOffset;
   1.789 +			if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.790 +				{
   1.791 +				r=dispHand.Process(imgBase);
   1.792 +				
   1.793 +#ifdef __WINSCW__
   1.794 +				aTest(r==KErrNotSupported);
   1.795 +#else
   1.796 +				aTest(r==KErrNone);
   1.797 +#endif
   1.798 +				
   1.799 +				}
   1.800 +			r=aCam.ReleaseBuffer(retId);
   1.801 +			aTest(r==KErrNone);
   1.802 +			aCam.NotifyNewImage(rs[1]);
   1.803 +			}
   1.804 +		else
   1.805 +			aTest(0);
   1.806 +		}
   1.807 +
   1.808 +	tim.Close();
   1.809 +
   1.810 +	aTest.Next(_L("Stop the camera."));
   1.811 +	r=aCam.Stop();
   1.812 +	aTest(r==KErrNone);
   1.813 +
   1.814 +	aTest.Next(_L("Close the chunk"));
   1.815 +	r=aCam.ChunkClose(aCaptureMode);
   1.816 +	}
   1.817 +
   1.818 +LOCAL_C void DoCamImageCaptureTests(RDevCameraSc& aCam, RTest& aTest, TInt aCameraSensorIndex, const SDevCamPixelFormat& aPixelFormat, const SDevCamFrameSize& aFrameSize, TUint aFrameRate)
   1.819 +	{
   1.820 +	TInt r;
   1.821 +
   1.822 +	aTest.Next(_L("IMAGE CAPTURE TESTS"));
   1.823 +	aTest.Printf(_L("PixelFormat = %d, FrameSize = %d x %d\n"),aPixelFormat.iPixelFormat,aFrameSize.iWidth,aFrameSize.iHeight);
   1.824 +
   1.825 +	// Configure Image Capture
   1.826 +	TCameraConfigV02Buf camConfBuf;
   1.827 +	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
   1.828 +	TCameraConfigV02 &camConf=camConfBuf();
   1.829 +
   1.830 +	camConf.iFrameSize=aFrameSize;
   1.831 +	camConf.iPixelFormat=aPixelFormat;
   1.832 +	camConf.iFrameRate=aFrameRate;
   1.833 +
   1.834 +	// Set the camera configuration.
   1.835 +	r=aCam.SetCamConfig(ECamCaptureModeImage,camConfBuf);
   1.836 +	aTest(r==KErrNone);
   1.837 +	aCam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
   1.838 +	PrintCamConf(camConf,aTest);
   1.839 +
   1.840 +	// Create a chunk handle and trigger the buffer creation.
   1.841 +	aTest.Next(_L("Setup the config - creating a chunk"));
   1.842 +	RChunk chunkImage;
   1.843 +	TInt numBuffers=KNumVideoFramesToAllocate;
   1.844 +	r=aCam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
   1.845 +	aTest(r==KErrNone);
   1.846 +
   1.847 +	aTest.Next(_L("Read and display the resulting buffer config"));
   1.848 +	TMmSharedChunkBufConfig bufferConfig;
   1.849 +	TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
   1.850 +	aCam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
   1.851 +	PrintBufferConf(bufferConfig,aTest);
   1.852 +
   1.853 +	// Create and configure a display handler
   1.854 +	TCamDisplayHandler dispHand;
   1.855 +	r=dispHand.Init();
   1.856 +	aTest(r==KErrNone);
   1.857 +
   1.858 +	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.859 +		{
   1.860 +		r=dispHand.SetConfig(aFrameSize,aPixelFormat);
   1.861 +		aTest(r==KErrNone);
   1.862 +		}
   1.863 +
   1.864 +	// Test that stop still returns an error.
   1.865 +	r=aCam.Stop();
   1.866 +	aTest(r==KErrGeneral);
   1.867 +
   1.868 +	// Set the current capture mode
   1.869 +	r=aCam.SetCaptureMode(ECamCaptureModeImage);
   1.870 +	aTest(r==KErrNone);
   1.871 +
   1.872 +	aTest.Next(_L("Start the camera in image capture mode"));
   1.873 +	r=aCam.Start();
   1.874 +	aTest(r==KErrNone);
   1.875 +
   1.876 +	aTest.Next(_L("Issue a capture request"));
   1.877 +	TRequestStatus rs1;
   1.878 +	aCam.NotifyNewImage(rs1);
   1.879 +	User::WaitForRequest(rs1);
   1.880 +	TInt retId=rs1.Int();
   1.881 +	TInt retOffset=-1;
   1.882 +	aTest(retId>=0);
   1.883 +	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
   1.884 +	aTest.Printf(_L("Buffer offset: %d(%xH)\r\n"),retId,retOffset);
   1.885 +	aTest(retOffset>=0);
   1.886 +
   1.887 +	TUint8* imgBase;
   1.888 +	imgBase=chunkImage.Base()+retOffset;
   1.889 +
   1.890 +	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.891 +		{
   1.892 +		// Display the image received for 1s
   1.893 +		r=dispHand.Process(imgBase);
   1.894 +		
   1.895 +#ifdef __WINSCW__
   1.896 +        aTest(r==KErrNotSupported);
   1.897 +#else
   1.898 +        aTest(r==KErrNone);
   1.899 +#endif
   1.900 +        
   1.901 +		User::After(1000000);	// 1 sec
   1.902 +		}
   1.903 +
   1.904 +	// Save the to do MMC card with a filename to indicate its size.  If no MMC card is present
   1.905 +	// then we will just display a warning rather than fail as this is an optional manual step
   1.906 +	TBuf<100> fileName(KSensor);
   1.907 +	fileName.AppendNum(aCameraSensorIndex);
   1.908 +	fileName.Append(KUnderscore);
   1.909 +	fileName.AppendFormat(KFrameSize, aFrameSize.iWidth, aFrameSize.iHeight);
   1.910 +	fileName.Append(KUnderscore);
   1.911 +	AppendPixelFormat(fileName, aPixelFormat.iPixelFormat);
   1.912 +
   1.913 +	TBool wrote = ETrue;
   1.914 +	RBitmap bitmap;
   1.915 +
   1.916 +	if ((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) || (aPixelFormat.iPixelFormat == EUidPixelFormatSpeedTaggedJPEG))
   1.917 +		{
   1.918 +		fileName.Append((aPixelFormat.iPixelFormat == EUidPixelFormatJPEG) ? KJpeg : KSpeedTaggedJpeg);
   1.919 +		r=bitmap.WriteBuffer(fileName, imgBase, (aFrameSize.iWidth * aFrameSize.iHeight * aPixelFormat.iPixelWidthInBytes));
   1.920 +		}
   1.921 +	else if ((aPixelFormat.iPixelFormat == EUidPixelFormatYUV_422Interleaved) || (aPixelFormat.iPixelFormat == EUidPixelFormatRGB_565))
   1.922 +		{
   1.923 +		fileName.Append(KBmp);
   1.924 +		r=bitmap.WriteBMP(fileName, imgBase, aPixelFormat, aFrameSize.iWidth, aFrameSize.iHeight);
   1.925 +		}
   1.926 +	else
   1.927 +		{
   1.928 +		wrote = EFalse;
   1.929 +		}
   1.930 +
   1.931 +	if (wrote)
   1.932 +		{
   1.933 +		if (r==KErrNone)
   1.934 +			{
   1.935 +			aTest.Printf(_L("Wrote image to %S\n"),&fileName);
   1.936 +			}
   1.937 +		else
   1.938 +			{
   1.939 +			aTest.Printf(_L("Warning: Unable to write %S (error = %d)\r\n"),&fileName,r);
   1.940 +			}
   1.941 +		}
   1.942 +
   1.943 +	aTest.Next(_L("Free the buffer"));
   1.944 +	r=aCam.ReleaseBuffer(retId);
   1.945 +	aTest(r==KErrNone);
   1.946 +
   1.947 +	aTest.Next(_L("Issue two consecutive capture requests"));
   1.948 +	TRequestStatus rs2;
   1.949 +	aCam.NotifyNewImage(rs1);
   1.950 +	aCam.NotifyNewImage(rs2);
   1.951 +
   1.952 +	User::WaitForRequest(rs1);
   1.953 +	retId=rs1.Int();
   1.954 +	aTest(retId>=0);
   1.955 +	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
   1.956 +	aTest.Printf(_L("Buffer0 offset: %d(%xH)\r\n"),retOffset,retOffset);
   1.957 +	aTest(retOffset>=0);
   1.958 +
   1.959 +	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.960 +		{
   1.961 +		// Display the image received for 1s
   1.962 +		imgBase=chunkImage.Base()+retOffset;
   1.963 +		r=dispHand.Process(imgBase);
   1.964 +		
   1.965 +#ifdef __WINSCW__
   1.966 +        aTest(r==KErrNotSupported);
   1.967 +#else
   1.968 +        aTest(r==KErrNone);
   1.969 +#endif
   1.970 +        
   1.971 +		User::After(1000000);	// 1 sec
   1.972 +		}
   1.973 +
   1.974 +	r=aCam.ReleaseBuffer(retId);
   1.975 +	aTest(r==KErrNone);
   1.976 +
   1.977 +	User::WaitForRequest(rs2);
   1.978 +	retId=rs2.Int();
   1.979 +	aTest(retId>=0);
   1.980 +	aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
   1.981 +	aTest.Printf(_L("Buffer1 offset: %d(%xH)\r\n"),retOffset,retOffset);
   1.982 +	aTest(retOffset>=0);
   1.983 +
   1.984 +	if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
   1.985 +		{
   1.986 +		// Display the image received for 1s
   1.987 +		imgBase=chunkImage.Base()+retOffset;
   1.988 +		r=dispHand.Process(imgBase);
   1.989 +		
   1.990 +#ifdef __WINSCW__
   1.991 +        aTest(r==KErrNotSupported);
   1.992 +#else
   1.993 +        aTest(r==KErrNone);
   1.994 +#endif
   1.995 +        
   1.996 +		User::After(1000000);	// 1 sec
   1.997 +		}
   1.998 +
   1.999 +	r=aCam.ReleaseBuffer(retId);
  1.1000 +	aTest(r==KErrNone);
  1.1001 +
  1.1002 +	aTest.Next(_L("Issue four more separate capture requests"));
  1.1003 +	for (TInt i=0 ; i<4 ; i++)
  1.1004 +		{
  1.1005 +		aCam.NotifyNewImage(rs1);
  1.1006 +		User::WaitForRequest(rs1);
  1.1007 +		retId=rs1.Int();
  1.1008 +		aTest(retId>=0);
  1.1009 +		aCam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
  1.1010 +		aTest.Printf(_L("Buffer%d offset: %d(%xH)\r\n"),i,retOffset,retOffset);
  1.1011 +		aTest(retOffset>=0);
  1.1012 +
  1.1013 +		if (aPixelFormat.iPixelFormat!=EUidPixelFormatJPEG && aPixelFormat.iPixelFormat!=EUidPixelFormatSpeedTaggedJPEG)
  1.1014 +			{
  1.1015 +			// Display the image received for 1s
  1.1016 +			imgBase=chunkImage.Base()+retOffset;
  1.1017 +			r=dispHand.Process(imgBase);
  1.1018 +			
  1.1019 +#ifdef __WINSCW__
  1.1020 +            aTest(r==KErrNotSupported);
  1.1021 +#else
  1.1022 +            aTest(r==KErrNone);
  1.1023 +#endif
  1.1024 +            
  1.1025 +			User::After(1000000);	// 1 sec
  1.1026 +			}
  1.1027 +		}
  1.1028 +
  1.1029 +	r=aCam.ReleaseBuffer(retId);
  1.1030 +	aTest(r==KErrNone);
  1.1031 +
  1.1032 +	aTest.Next(_L("Stop the camera."));
  1.1033 +	r=aCam.Stop();
  1.1034 +	aTest(r==KErrNone);
  1.1035 +
  1.1036 +	aTest.Next(_L("Close the chunk"));
  1.1037 +	r=aCam.ChunkClose(ECamCaptureModeImage);
  1.1038 +	aTest(r==KErrNone);
  1.1039 +	}
  1.1040 +
  1.1041 +LOCAL_C void DoCamCancelTests(RTest& aTest, TInt aCameraSensorIndex)
  1.1042 +	{
  1.1043 +	TInt bufferSize, r;
  1.1044 +	SDevCamFrameSize* frameSizes;
  1.1045 +	TCameraConfigV02Buf camConfBuf;
  1.1046 +
  1.1047 +	aTest.Next(_L("CAPTURE CANCEL TESTS"));
  1.1048 +
  1.1049 +	RDevCameraSc cam;
  1.1050 +	aTest.Next(_L("Open a channel on the camera driver"));
  1.1051 +	r=cam.Open(aCameraSensorIndex);
  1.1052 +	aTest(r==KErrNone);
  1.1053 +
  1.1054 +	TInt numBuffers=KNumVideoFramesToAllocate;
  1.1055 +	SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
  1.1056 +
  1.1057 +	// Test Image Capture, if supported
  1.1058 +	if (CameraCaps->iNumImagePixelFormats)
  1.1059 +		{
  1.1060 +		// If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1061 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1062 +		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1063 +		Test(frameSizes != NULL);
  1.1064 +		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1065 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1066 +		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1067 +		Test(r == KErrNone);
  1.1068 +
  1.1069 +		cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
  1.1070 +
  1.1071 +		camConfBuf().iFrameSize=frameSizes[0];
  1.1072 +		camConfBuf().iPixelFormat=*pixelFormat;
  1.1073 +		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
  1.1074 +
  1.1075 +		// Set the camera configuration.
  1.1076 +		r=cam.SetCamConfig(ECamCaptureModeImage, camConfBuf);
  1.1077 +		aTest(r==KErrNone);
  1.1078 +		cam.GetCamConfig(ECamCaptureModeImage, camConfBuf);
  1.1079 +		PrintCamConf(camConfBuf(), aTest);
  1.1080 +
  1.1081 +		// Create a chunk handle and trigger the buffer creation.
  1.1082 +		RChunk chunkImage;
  1.1083 +		aTest.Next(_L("Setup the config - creating a chunk for image capture"));
  1.1084 +		r=cam.SetBufConfigChunkCreate(ECamCaptureModeImage,numBuffers,chunkImage);
  1.1085 +		aTest(r==KErrNone);
  1.1086 +
  1.1087 +		aTest.Next(_L("Read and display the resulting buffer config"));
  1.1088 +		TMmSharedChunkBufConfig bufferConfig;
  1.1089 +		TPckg<TMmSharedChunkBufConfig> bufferConfigBufImage(bufferConfig);
  1.1090 +		cam.GetBufferConfig(ECamCaptureModeImage, bufferConfigBufImage);
  1.1091 +		PrintBufferConf(bufferConfig,aTest);
  1.1092 +
  1.1093 +		// Set the current capture mode
  1.1094 +		r=cam.SetCaptureMode(ECamCaptureModeImage);
  1.1095 +		aTest(r==KErrNone);
  1.1096 +
  1.1097 +		aTest.Next(_L("Start the camera in image capture mode."));
  1.1098 +		r=cam.Start();
  1.1099 +		aTest(r==KErrNone);
  1.1100 +
  1.1101 +		TRequestStatus rs[KNumVideoFramesToCapture];
  1.1102 +		TInt retId, retOffset;
  1.1103 +
  1.1104 +		aTest.Next(_L("Issue a request and then cancel it"));
  1.1105 +		cam.NotifyNewImage(rs[0]);
  1.1106 +		cam.NotifyNewImageCancel();
  1.1107 +		User::WaitForRequest(rs[0]);
  1.1108 +		retId=rs[0].Int();
  1.1109 +		aTest(retId==KErrCancel || retId>=0);
  1.1110 +		if (retId>=0)
  1.1111 +			{
  1.1112 +			cam.BufferIdToOffset(ECamCaptureModeImage,retId,retOffset);
  1.1113 +			aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
  1.1114 +			aTest(retOffset>=0);
  1.1115 +			cam.ReleaseBuffer(retId);
  1.1116 +			}
  1.1117 +
  1.1118 +		aTest.Next(_L("Stop the camera."));
  1.1119 +		r=cam.Stop();
  1.1120 +		aTest(r==KErrNone);
  1.1121 +
  1.1122 +		aTest.Next(_L("Close the Image chunk"));
  1.1123 +		chunkImage.Close();
  1.1124 +
  1.1125 +		delete [] frameSizes;
  1.1126 +		}
  1.1127 +
  1.1128 +	// Skip past the image pixel formats
  1.1129 +	pixelFormat += CameraCaps->iNumImagePixelFormats;
  1.1130 +
  1.1131 +	// Test Video Capture, if supported
  1.1132 +	if (CameraCaps->iNumVideoPixelFormats)
  1.1133 +		{
  1.1134 +		// If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1135 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1136 +		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1137 +		Test(frameSizes != NULL);
  1.1138 +		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1139 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1140 +		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1141 +		Test(r == KErrNone);
  1.1142 +
  1.1143 +		cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
  1.1144 +
  1.1145 +		camConfBuf().iFrameSize=frameSizes[0];
  1.1146 +		camConfBuf().iPixelFormat=*pixelFormat;
  1.1147 +		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
  1.1148 +
  1.1149 +		// Set the camera configuration.
  1.1150 +		r=cam.SetCamConfig(ECamCaptureModeVideo, camConfBuf);
  1.1151 +		aTest(r==KErrNone);
  1.1152 +		cam.GetCamConfig(ECamCaptureModeVideo, camConfBuf);
  1.1153 +		PrintCamConf(camConfBuf(), aTest);
  1.1154 +
  1.1155 +		// Create a chunk handle and trigger the buffer creation.
  1.1156 +		RChunk chunkVideo;
  1.1157 +		aTest.Next(_L("Setup the config - creating a chunk for video capture"));
  1.1158 +		r=cam.SetBufConfigChunkCreate(ECamCaptureModeVideo,numBuffers,chunkVideo);
  1.1159 +		aTest(r==KErrNone);
  1.1160 +
  1.1161 +		aTest.Next(_L("Read and display the resulting buffer config"));
  1.1162 +		TMmSharedChunkBufConfig bufferConfig;
  1.1163 +		TPckg<TMmSharedChunkBufConfig> bufferConfigBufVideo(bufferConfig);
  1.1164 +		cam.GetBufferConfig(ECamCaptureModeVideo, bufferConfigBufVideo);
  1.1165 +		PrintBufferConf(bufferConfig,aTest);
  1.1166 +
  1.1167 +		// Set the current capture mode
  1.1168 +		r=cam.SetCaptureMode(ECamCaptureModeVideo);
  1.1169 +		aTest(r==KErrNone);
  1.1170 +
  1.1171 +		aTest.Next(_L("Start the camera in video mode"));
  1.1172 +		r=cam.Start();
  1.1173 +		aTest(r==KErrNone);
  1.1174 +
  1.1175 +		aTest.Next(_L("Issue capture requests and globally cancel them all"));
  1.1176 +		aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
  1.1177 +		TRequestStatus rs[KNumVideoFramesToCapture];
  1.1178 +		TInt i;
  1.1179 +		for (i=0 ; i<KNumVideoFramesToCapture; i++)
  1.1180 +			cam.NotifyNewImage(rs[i]);
  1.1181 +
  1.1182 +		cam.NotifyNewImageCancel();
  1.1183 +
  1.1184 +		TInt retOffset = -2;
  1.1185 +		TInt retId = -2;
  1.1186 +		for (i=0 ; i<KNumVideoFramesToCapture; i++)
  1.1187 +			{
  1.1188 +			User::WaitForRequest(rs[i]);
  1.1189 +			retId=rs[i].Int();
  1.1190 +			aTest(retId==KErrCancel || retId>=0);
  1.1191 +			if (retId>=0)
  1.1192 +				{
  1.1193 +				cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
  1.1194 +				aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
  1.1195 +				aTest(retOffset>=0);
  1.1196 +				cam.ReleaseBuffer(retId);
  1.1197 +				}
  1.1198 +			}
  1.1199 +
  1.1200 +		aTest.Next(_L("Issue capture requests and individually cancel them all"));
  1.1201 +		aTest.Printf(_L("Request %d frames\r\n"),KNumVideoFramesToCapture);
  1.1202 +
  1.1203 +		for (i=0 ; i<KNumVideoFramesToCapture; i++)
  1.1204 +			cam.NotifyNewImage(rs[i]);
  1.1205 +
  1.1206 +		for (i=0 ; i<KNumVideoFramesToCapture; i++)
  1.1207 +			cam.NotifyNewImageCancel(rs[i]);
  1.1208 +
  1.1209 +		for (i=0 ; i<KNumVideoFramesToCapture; i++)
  1.1210 +			{
  1.1211 +			User::WaitForRequest(rs[i]);
  1.1212 +			retId=rs[i].Int();
  1.1213 +			aTest(retId==KErrCancel || retId>=0);
  1.1214 +			if (retId>=0)
  1.1215 +				{
  1.1216 +				cam.BufferIdToOffset(ECamCaptureModeVideo,retId,retOffset);
  1.1217 +				aTest.Printf(_L("Buffer%d : %d\r\n"),retId,retOffset);
  1.1218 +				aTest(retOffset>=0);
  1.1219 +				cam.ReleaseBuffer(retId);
  1.1220 +				}
  1.1221 +			}
  1.1222 +
  1.1223 +		aTest.Next(_L("Stop the camera."));
  1.1224 +		r=cam.Stop();
  1.1225 +		aTest(r==KErrNone);
  1.1226 +
  1.1227 +		aTest.Next(_L("Close the Video chunk"));
  1.1228 +		chunkVideo.Close();
  1.1229 +
  1.1230 +		delete [] frameSizes;
  1.1231 +		}
  1.1232 +
  1.1233 +	// Skip past the video pixel formats
  1.1234 +	pixelFormat += CameraCaps->iNumVideoPixelFormats;
  1.1235 +
  1.1236 +	// Test Viewfinder Capture, if supported
  1.1237 +	if (CameraCaps->iNumViewFinderPixelFormats)
  1.1238 +		{
  1.1239 +		// If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1240 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1241 +		frameSizes = new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1242 +		Test(frameSizes != NULL);
  1.1243 +		bufferSize = (sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1244 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1245 +		r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1246 +		Test(r == KErrNone);
  1.1247 +
  1.1248 +		cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
  1.1249 +
  1.1250 +		camConfBuf().iFrameSize=frameSizes[0];
  1.1251 +		camConfBuf().iPixelFormat=*pixelFormat;
  1.1252 +		camConfBuf().iFrameRate=frameSizes[0].iMaxFrameRate;
  1.1253 +
  1.1254 +		// Set the camera configuration.
  1.1255 +		r=cam.SetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
  1.1256 +		aTest(r==KErrNone);
  1.1257 +		cam.GetCamConfig(ECamCaptureModeViewFinder, camConfBuf);
  1.1258 +		PrintCamConf(camConfBuf(), aTest);
  1.1259 +
  1.1260 +		// Create a chunk handle and trigger the buffer creation.
  1.1261 +		RChunk chunkViewFinder;
  1.1262 +		aTest.Next(_L("Setup the config - creating a chunk for viewfinder capture"));
  1.1263 +		r=cam.SetBufConfigChunkCreate(ECamCaptureModeViewFinder,numBuffers,chunkViewFinder);
  1.1264 +		aTest(r==KErrNone);
  1.1265 +
  1.1266 +		aTest.Next(_L("Read and display the resulting buffer config"));
  1.1267 +		TMmSharedChunkBufConfig bufferConfig;
  1.1268 +		TPckg<TMmSharedChunkBufConfig> bufferConfigBufViewFinder(bufferConfig);
  1.1269 +		cam.GetBufferConfig(ECamCaptureModeViewFinder, bufferConfigBufViewFinder);
  1.1270 +		PrintBufferConf(bufferConfig,aTest);
  1.1271 +
  1.1272 +		aTest.Next(_L("Close the Viewfinder chunk"));
  1.1273 +		chunkViewFinder.Close();
  1.1274 +
  1.1275 +		delete [] frameSizes;
  1.1276 +		}
  1.1277 +
  1.1278 +	aTest.Next(_L("Close the drivers"));
  1.1279 +	cam.Close();
  1.1280 +	}
  1.1281 +
  1.1282 +void CameraTests(TInt aCameraSensorIndex)
  1.1283 +	{
  1.1284 +	TUint index, size;
  1.1285 +	Test.Printf(_L("Testing unit number: %d\r\n"),aCameraSensorIndex);
  1.1286 +
  1.1287 +	// Perform some basic opening and multithreaded tests.  We don't want just in time debugging during
  1.1288 +	// these tests
  1.1289 +	TBool justInTime=User::JustInTime();
  1.1290 +	User::SetJustInTime(EFalse);
  1.1291 +	DoCamOpenCapTests(Test,aCameraSensorIndex);
  1.1292 +	User::SetJustInTime(justInTime);
  1.1293 +
  1.1294 +	// Test request handling
  1.1295 +	DoCamCancelTests(Test, aCameraSensorIndex);
  1.1296 +
  1.1297 +	// Re-open the camera driver for use below and to ensure that it can deal with being re-opened (it
  1.1298 +	// has already been opened and closed by DoCamOpenCapTests())
  1.1299 +	RDevCameraSc cam;
  1.1300 +	Test.Next(_L("Open a channel on the camera driver"));
  1.1301 +	TInt r=cam.Open(aCameraSensorIndex);
  1.1302 +	Test(r==KErrNone);
  1.1303 +
  1.1304 +	// Test Dynamic Settings, e.g. Brightness, Contrast, etc.
  1.1305 +	DoCamDynamicSettingsTests(cam, Test);
  1.1306 +	
  1.1307 +	// Go through all supported image, video and viewfinder pixel formats and perform configuration
  1.1308 +	// and capture tests on them all, for all supported frame sizes and frame rates
  1.1309 +	TInt bufferSize;
  1.1310 +	SDevCamFrameSize* frameSizes;
  1.1311 +	TBool imageConfigTestsDone=EFalse, videoConfigTestsDone=EFalse, viewFinderConfigTestsDone=EFalse;
  1.1312 +	SDevCamPixelFormat* pixelFormat = (SDevCamPixelFormat*) (CameraCaps + 1);
  1.1313 +
  1.1314 +	for (index = 0; index < CameraCaps->iNumImagePixelFormats; ++index)
  1.1315 +		{
  1.1316 +		// If iNumImagePixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1317 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1318 +		Test.Printf(_L("Image pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
  1.1319 +		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1320 +		Test(frameSizes!=NULL);
  1.1321 +		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1322 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1323 +		r = cam.FrameSizeCaps(ECamCaptureModeImage, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1324 +		Test(r == KErrNone);
  1.1325 +
  1.1326 +		// Test camera configuration for image capture.  This is only done once for the sake of
  1.1327 +		// test expediency
  1.1328 +		if (!imageConfigTestsDone)
  1.1329 +			{
  1.1330 +			imageConfigTestsDone = ETrue;
  1.1331 +			DoCamConfigTests(cam, Test, ECamCaptureModeImage, *pixelFormat, frameSizes[0]);
  1.1332 +			}
  1.1333 +
  1.1334 +		// Test image capture mode
  1.1335 +		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
  1.1336 +			{
  1.1337 +			DoCamImageCaptureTests(cam, Test, aCameraSensorIndex, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
  1.1338 +			}
  1.1339 +
  1.1340 +		// Test buffer offset
  1.1341 +		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
  1.1342 +			{
  1.1343 +			DoCamBufferOffsetTests(cam, Test, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
  1.1344 +			}
  1.1345 +
  1.1346 +		delete [] frameSizes;
  1.1347 +		++pixelFormat;
  1.1348 +		}
  1.1349 +
  1.1350 +	for (index = 0; index < CameraCaps->iNumVideoPixelFormats; ++index)
  1.1351 +		{
  1.1352 +		// If iNumVideoPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1353 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1354 +		Test.Printf(_L("Video pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
  1.1355 +		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1356 +		Test(frameSizes!=NULL);
  1.1357 +		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1358 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1359 +		r = cam.FrameSizeCaps(ECamCaptureModeVideo, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1360 +		Test(r == KErrNone);
  1.1361 +
  1.1362 +		// Test camera configuration for video capture.  This is only done once for the sake of
  1.1363 +		// test expediency
  1.1364 +		if (!videoConfigTestsDone)
  1.1365 +			{
  1.1366 +			videoConfigTestsDone=ETrue;
  1.1367 +			DoCamConfigTests(cam, Test, ECamCaptureModeVideo, *pixelFormat, frameSizes[0]);
  1.1368 +			}
  1.1369 +
  1.1370 +		// Test video capture mode
  1.1371 +		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
  1.1372 +			{
  1.1373 +			DoCamVideoCaptureTests(cam, Test, ECamCaptureModeVideo, *pixelFormat,frameSizes[size], frameSizes[size].iMaxFrameRate);
  1.1374 +			}
  1.1375 +		delete [] frameSizes;
  1.1376 +		++pixelFormat;
  1.1377 +		}
  1.1378 +
  1.1379 +	for (index = 0; index < CameraCaps->iNumViewFinderPixelFormats; ++index)
  1.1380 +		{
  1.1381 +		// If iNumViewFinderPixelFormats is > 0 then the matching iNumFrameSizes should also be > 0
  1.1382 +		Test(pixelFormat->iNumFrameSizes > 0);
  1.1383 +		Test.Printf(_L("Viewfinder pixel format %x, number of frame sizes = %d\n"), pixelFormat->iPixelFormat, pixelFormat->iNumFrameSizes);
  1.1384 +		frameSizes=new SDevCamFrameSize[pixelFormat->iNumFrameSizes];
  1.1385 +		Test(frameSizes!=NULL);
  1.1386 +		bufferSize=(sizeof(SDevCamFrameSize) * pixelFormat->iNumFrameSizes);
  1.1387 +		TPtr8 frameSizesBuf((TUint8*) frameSizes, bufferSize, bufferSize);
  1.1388 +		r = cam.FrameSizeCaps(ECamCaptureModeViewFinder, pixelFormat->iPixelFormat, frameSizesBuf);
  1.1389 +		Test(r == KErrNone);
  1.1390 +
  1.1391 +		// Test camera configuration for view finder capture.  This is only done once for the sake of
  1.1392 +		// test expediency
  1.1393 +		if (!viewFinderConfigTestsDone)
  1.1394 +			{
  1.1395 +			viewFinderConfigTestsDone=ETrue;
  1.1396 +			DoCamConfigTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[0]);
  1.1397 +			}
  1.1398 +
  1.1399 +		// Test view finder capture mode
  1.1400 +		for (size = 0; size < pixelFormat->iNumFrameSizes; ++size)
  1.1401 +			{
  1.1402 +			DoCamVideoCaptureTests(cam, Test, ECamCaptureModeViewFinder, *pixelFormat, frameSizes[size], frameSizes[size].iMaxFrameRate);
  1.1403 +			}
  1.1404 +		delete [] frameSizes;
  1.1405 +		++pixelFormat;
  1.1406 +		}
  1.1407 +	cam.Close();
  1.1408 +
  1.1409 +	// And free the global capabilities buffer that was allocated in DoCamOpenCapTests()
  1.1410 +	User::Free(CapsBufPtr);
  1.1411 +	}
  1.1412 +
  1.1413 +GLDEF_C TInt E32Main()
  1.1414 +	{
  1.1415 +	__UHEAP_MARK;
  1.1416 +
  1.1417 +	Test.Title();
  1.1418 +	Test.Start(_L("Camera module API test"));
  1.1419 +
  1.1420 +	Test.Next(_L("Loading CAMERA PDD"));
  1.1421 +	TInt r=User::LoadPhysicalDevice(KCamPddFileName);
  1.1422 +	Test.Printf(_L("Returned %d\r\n"),r);
  1.1423 +
  1.1424 +	if (r==KErrNotFound)
  1.1425 +		{
  1.1426 +		Test.Printf(_L("Shared chunk camera driver not supported - test skipped\r\n"));
  1.1427 +		Test.End();
  1.1428 +		Test.Close();
  1.1429 +		__UHEAP_MARKEND;
  1.1430 +		return(KErrNone);
  1.1431 +		}
  1.1432 +
  1.1433 +	Test(r==KErrNone || r==KErrAlreadyExists);
  1.1434 +
  1.1435 +	Test.Next(_L("Loading CAMERA LDD"));
  1.1436 +	r=User::LoadLogicalDevice(KCamLddFileName);
  1.1437 +	Test.Printf(_L("Returned %d\r\n"),r);
  1.1438 +	Test(r==KErrNone || r==KErrAlreadyExists);
  1.1439 +
  1.1440 +	Test.Next(_L("Loading D_MMCSC LDD"));
  1.1441 +	r=User::LoadLogicalDevice(KTstLddFileName);
  1.1442 +	Test.Printf(_L("Returned %d\r\n"),r);
  1.1443 +	Test(r==KErrNone||r==KErrAlreadyExists);
  1.1444 +
  1.1445 +	__KHEAP_MARK;
  1.1446 +
  1.1447 +	if (User::CommandLineLength()>0)
  1.1448 +		{
  1.1449 +		TBuf<0x100> cmd;
  1.1450 +		TInt moduleIndex = KUnit0;
  1.1451 +		User::CommandLine(cmd);
  1.1452 +		Test(cmd.Length()>0);
  1.1453 +		if (cmd[0]>='0' && cmd[0]<='9')
  1.1454 +			moduleIndex=(TInt)(cmd[0]-'0');
  1.1455 +		CameraTests(moduleIndex);
  1.1456 +		}
  1.1457 +	else // If no command line arguments are passed we perform tests on the module 0 and 1
  1.1458 +		{
  1.1459 +		CameraTests(0);
  1.1460 +		}
  1.1461 +
  1.1462 +	__KHEAP_MARKEND;
  1.1463 +
  1.1464 +	// Free the PDDs and LDDs
  1.1465 +	Test.Next(_L("Freeing ECAMERASC LDD"));
  1.1466 +	r=User::FreeLogicalDevice(KDevCameraScName);
  1.1467 +	Test(r==KErrNone);
  1.1468 +
  1.1469 +	Test.Next(_L("Freeing CAMERASC PDD"));
  1.1470 +	TFindPhysicalDevice fDr;
  1.1471 +	TFullName drivName;
  1.1472 +	TName searchName;
  1.1473 +	searchName.Append(KDevCameraScName);
  1.1474 +	searchName.Append(KCamFreePddExtension);
  1.1475 +	fDr.Find(searchName);
  1.1476 +	r=fDr.Next(drivName);
  1.1477 +	Test(r==KErrNone);
  1.1478 +	r=User::FreePhysicalDevice(drivName);
  1.1479 +	Test(r==KErrNone);
  1.1480 +
  1.1481 +	Test.Next(_L("Freeing D_MMCSC LDD"));
  1.1482 +	r=User::FreeLogicalDevice(KDevMmCScName);
  1.1483 +	Test(r==KErrNone);
  1.1484 +
  1.1485 +	Test.End();
  1.1486 +	Test.Close();
  1.1487 +
  1.1488 +	__UHEAP_MARKEND;
  1.1489 +	return(KErrNone);
  1.1490 +	}