os/kernelhwsrv/kerneltest/e32test/examples/camera1/camera1_test.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/examples/camera1/camera1_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,364 @@
     1.4 +// Copyright (c) 2005-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 +// in its implementation.
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +/**
    1.22 + @file Test code for example camera device driver which uses Shared Chunks
    1.23 + @publishedPartner
    1.24 + @prototype 9.1
    1.25 +*/
    1.26 +
    1.27 +#include <e32test.h>
    1.28 +#include <e32svr.h>
    1.29 +#include <e32def.h>
    1.30 +#include <e32def_private.h>
    1.31 +#include "camera1.h"
    1.32 +
    1.33 +LOCAL_D RTest test(_L("CAMERA1_TEST"));
    1.34 +
    1.35 +RCamera1 Camera;
    1.36 +
    1.37 +RCamera1::TConfigBuf ConfigBuf;
    1.38 +
    1.39 +const TInt KMaxBuffers = 8;
    1.40 +
    1.41 +_LIT(KCamera1FileName,"camera1_ldd");
    1.42 +
    1.43 +enum TBufferMode
    1.44 +	{
    1.45 +	EReleaseOnCapture,
    1.46 +	EReleaseInBlocks,
    1.47 +	};
    1.48 +
    1.49 +void Capture(TInt aNumBuffers, TBufferMode aMode)
    1.50 +	{
    1.51 +	TInt r;
    1.52 +
    1.53 +	test(aNumBuffers<=KMaxBuffers);
    1.54 +
    1.55 +	test.Start(_L("SetConfig"));
    1.56 +	ConfigBuf().iNumImageBuffers = aNumBuffers;
    1.57 +	ConfigBuf().iFrameRate=10;
    1.58 +	r=Camera.SetConfig(ConfigBuf);
    1.59 +	test(r==KErrNone);
    1.60 +
    1.61 +	// Base address of chunk which contains images
    1.62 +	TUint8* chunkBase=Camera.ImageChunk().Base();
    1.63 +
    1.64 +	test.Next(_L("StartCapture"));
    1.65 +	r=Camera.StartCapture();
    1.66 +	test(r==KErrNone);
    1.67 +
    1.68 +	test.Next(_L("Capture images..."));
    1.69 +	TInt imageBuffer[KMaxBuffers]; // Array of image buffers we've received
    1.70 +	memset(imageBuffer,~0,sizeof(imageBuffer)); // Initialise to 'empty' (-1)
    1.71 +	TInt lastFrameCounter = -1;
    1.72 +	TInt bufNum = 0;
    1.73 +
    1.74 +	// Stream load of images...
    1.75 +	for(TInt i=0; i<20*aNumBuffers; i++)
    1.76 +		{
    1.77 +		// Stall half way through streaming test...
    1.78 +		if(i==10+aNumBuffers-1)
    1.79 +			{
    1.80 +			test.Next(_L("Stall during image capture"));
    1.81 +			User::After(500000);
    1.82 +			}
    1.83 +
    1.84 +		// Get an image...
    1.85 +		TRequestStatus s;
    1.86 +		if(aMode==EReleaseInBlocks)
    1.87 +			Camera.CaptureImage(s);
    1.88 +		else
    1.89 +			Camera.CaptureImage(s,imageBuffer[bufNum]);
    1.90 +		User::WaitForRequest(s);
    1.91 +
    1.92 +		// imageOffset = capture result
    1.93 +		TInt imageOffset=s.Int();
    1.94 +		imageBuffer[bufNum] = imageOffset;
    1.95 +
    1.96 +		// Error?
    1.97 +		if(imageOffset<0)
    1.98 +			{
    1.99 +			test.Printf(_L("Error = %d\n"),imageOffset);
   1.100 +			test(0);
   1.101 +			}
   1.102 +
   1.103 +		// Check image memory is accessable and get counter
   1.104 +		TInt frameCounter = *(TInt*)(chunkBase+imageOffset);  // Test driver puts frame counter at image start
   1.105 +		RDebug::Print(_L("Capture %08x(%04d)\n"),imageOffset,frameCounter);
   1.106 +		test(frameCounter>lastFrameCounter);
   1.107 +
   1.108 +		// Move on to next buffer...
   1.109 +		if(++bufNum>=aNumBuffers)
   1.110 +			{
   1.111 +			if(aMode==EReleaseInBlocks)
   1.112 +				{
   1.113 +				// Release all the image buffers we have...
   1.114 +				for(bufNum=0; bufNum<aNumBuffers; bufNum++)
   1.115 +					{
   1.116 +					RDebug::Print(_L("Release %08x\n"),imageBuffer[bufNum]);
   1.117 +					r=Camera.ReleaseImage(imageBuffer[bufNum]);
   1.118 +					imageBuffer[bufNum] = -1;
   1.119 +					test(r==KErrNone);
   1.120 +					}
   1.121 +				}
   1.122 +			bufNum = 0;
   1.123 +			}
   1.124 +		}
   1.125 +
   1.126 +	test.Next(_L("EndCapture"));
   1.127 +	r=Camera.EndCapture();
   1.128 +	test(r==KErrNone);
   1.129 +
   1.130 +	test.End();
   1.131 +	}
   1.132 +
   1.133 +
   1.134 +GLDEF_C TInt E32Main()
   1.135 +    {
   1.136 +	test.Title();
   1.137 +
   1.138 +	TInt r;
   1.139 +
   1.140 +	test.Start(_L("Loading CAMERA1 Device"));
   1.141 +	r=User::LoadLogicalDevice(KCamera1FileName);
   1.142 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.143 +
   1.144 +	__KHEAP_MARK;
   1.145 +
   1.146 +	test.Next(_L("Open Device"));
   1.147 +	RDevice device;
   1.148 +	r=device.Open(RCamera1::Name());
   1.149 +	test(r==KErrNone);
   1.150 +
   1.151 +	test.Next(_L("Get Device Capabilities"));
   1.152 +	RCamera1::TCaps caps;
   1.153 +	TPckg<RCamera1::TCaps>capsPckg(caps);
   1.154 +	capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
   1.155 +	device.GetCaps(capsPckg);
   1.156 +	TVersion expectedVer(RCamera1::VersionRequired());
   1.157 +	test(caps.iVersion.iMajor==expectedVer.iMajor);
   1.158 +	test(caps.iVersion.iMinor==expectedVer.iMinor);
   1.159 +	test(caps.iVersion.iBuild==expectedVer.iBuild);
   1.160 +
   1.161 +	test.Next(_L("Close Device"));
   1.162 +	device.Close();
   1.163 +
   1.164 +	test.Next(_L("Open Logical Channel"));
   1.165 +	r=Camera.Open();
   1.166 +	test(r==KErrNone);
   1.167 +
   1.168 +	test.Next(_L("GetConfig"));
   1.169 +	RCamera1::TConfig& config=ConfigBuf();
   1.170 +	ConfigBuf.FillZ();   // Zero 'config' so we can tell if GetConfig has really filled it
   1.171 +	r=Camera.GetConfig(ConfigBuf);
   1.172 +	test(r==KErrNone);
   1.173 +
   1.174 +	const TSize KDefaultImageSize(config.iImageSize);
   1.175 +	test(KDefaultImageSize.iWidth!=0);
   1.176 +	test(KDefaultImageSize.iHeight!=0);
   1.177 +	test(config.iImageBytesPerPixel!=0);
   1.178 +
   1.179 +	test.Next(_L("StartCapture (before SetConfig has been called)"));
   1.180 +	r=Camera.StartCapture();
   1.181 +	test(r==KErrNotReady);
   1.182 +
   1.183 +	test.Next(_L("SetConfig"));
   1.184 +	config.iImageSize.iWidth = KDefaultImageSize.iWidth/2;
   1.185 +	config.iImageSize.iHeight = KDefaultImageSize.iHeight/2;
   1.186 +	config.iFrameRate = 2; // Slow rate to give timing dependant tests a chance
   1.187 +	config.iNumImageBuffers = 1;
   1.188 +	r=Camera.SetConfig(ConfigBuf);
   1.189 +	test(r==KErrNone);
   1.190 +
   1.191 +	test.Next(_L("Check handle duplication"));
   1.192 +	RCamera1 Camera2=Camera;
   1.193 +	r=Camera2.Duplicate(RThread(),EOwnerProcess);
   1.194 +	test(r==KErrNone);
   1.195 +	Camera2.Close();
   1.196 +
   1.197 +	test.Next(_L("Check config set"));
   1.198 +	ConfigBuf.FillZ();
   1.199 +	r=Camera.GetConfig(ConfigBuf);
   1.200 +	test(r==KErrNone);
   1.201 +	test(config.iImageSize.iWidth==KDefaultImageSize.iWidth/2);
   1.202 +	test(config.iImageSize.iHeight==KDefaultImageSize.iHeight/2);
   1.203 +	test(ConfigBuf().iFrameRate==2);
   1.204 +	test(ConfigBuf().iNumImageBuffers==1);
   1.205 +
   1.206 +	test.Next(_L("Check image chunk handle"));
   1.207 +	test(Camera.ImageChunk().Handle()!=KNullHandle);
   1.208 +	Camera.ImageChunk().Base();
   1.209 +
   1.210 +	test.Next(_L("CaptureImage (before StartCapture has been called)"));
   1.211 +	TRequestStatus s;
   1.212 +	Camera.CaptureImage(s);
   1.213 +	User::WaitForRequest(s);
   1.214 +	test(s.Int()==KErrNotReady);
   1.215 +
   1.216 +	test.Next(_L("StartCapture"));
   1.217 +	r=Camera.StartCapture();
   1.218 +	test(r==KErrNone);
   1.219 +
   1.220 +	test.Next(_L("StartCapture again"));
   1.221 +	r=Camera.StartCapture();
   1.222 +	test(r==KErrInUse);
   1.223 +
   1.224 +	test.Next(_L("SetConfig whilst capturing"));
   1.225 +	r=Camera.SetConfig(ConfigBuf);
   1.226 +	test(r==KErrInUse);
   1.227 +
   1.228 +	test.Next(_L("CaptureImage"));
   1.229 +	Camera.CaptureImage(s);
   1.230 +
   1.231 +	test.Next(_L("CaptureImage again (before last has completed)"));
   1.232 +	TRequestStatus s2;
   1.233 +	Camera.CaptureImage(s2);
   1.234 +	User::WaitForRequest(s2);
   1.235 +	test(s2.Int()==KErrInUse);
   1.236 +
   1.237 +	test.Next(_L("CaptureCancel"));
   1.238 +	Camera.CaptureImageCancel();
   1.239 +	User::WaitForRequest(s);
   1.240 +	test(s.Int()==KErrCancel);
   1.241 +
   1.242 +	test.Next(_L("CaptureCancel again"));
   1.243 +	Camera.CaptureImageCancel();
   1.244 +
   1.245 +	test.Next(_L("CaptureImage"));
   1.246 +	Camera.CaptureImage(s);
   1.247 +	User::WaitForRequest(s);
   1.248 +	test(s.Int()>=0);
   1.249 +
   1.250 +	test.Next(_L("CaptureImage again (before releasing previous image)"));
   1.251 +	Camera.CaptureImage(s2);
   1.252 +	User::WaitForRequest(s2);
   1.253 +	test(s2.Int()==KErrOverflow);
   1.254 +
   1.255 +	test.Next(_L("ReleaseImage"));
   1.256 +	r=Camera.ReleaseImage(s.Int());
   1.257 +	test(r==KErrNone);
   1.258 +
   1.259 +	test.Next(_L("ReleaseImage again"));
   1.260 +	r=Camera.ReleaseImage(s.Int());
   1.261 +	test(r==KErrNotFound);
   1.262 +
   1.263 +	test.Next(_L("CaptureImage"));
   1.264 +	Camera.CaptureImage(s);
   1.265 +
   1.266 +	test.Next(_L("EndCapture"));
   1.267 +	r=Camera.EndCapture();
   1.268 +	test(r==KErrNone);
   1.269 +	User::WaitForRequest(s);
   1.270 +	test(s.Int()==KErrCancel);
   1.271 +
   1.272 +	test.Next(_L("CaptureImage streaming with 1 buffer and ReleaseOnCapture"));
   1.273 +	Capture(1,EReleaseOnCapture);
   1.274 +	test.Next(_L("CaptureImage streaming with 1 buffer and EReleaseInBlocks"));
   1.275 +	Capture(1,EReleaseInBlocks);
   1.276 +
   1.277 +	test.Next(_L("CaptureImage streaming with 2 buffers and ReleaseOnCapture"));
   1.278 +	Capture(2,EReleaseOnCapture);
   1.279 +	test.Next(_L("CaptureImage streaming with 2 buffers and EReleaseInBlocks"));
   1.280 +	Capture(2,EReleaseInBlocks);
   1.281 +
   1.282 +	test.Next(_L("CaptureImage streaming with 3 buffers and ReleaseOnCapture"));
   1.283 +	Capture(3,EReleaseOnCapture);
   1.284 +	test.Next(_L("CaptureImage streaming with 3 buffers and EReleaseInBlocks"));
   1.285 +	Capture(3,EReleaseInBlocks);
   1.286 +
   1.287 +	test.Next(_L("Close Logical Channel"));
   1.288 +	Camera.Close();
   1.289 +
   1.290 +	test.Next(_L("Test cleanup 1"));
   1.291 +
   1.292 +		test.Start(_L("Open Logical Channel"));
   1.293 +		r=Camera.Open();
   1.294 +		test(r==KErrNone);
   1.295 +
   1.296 +		test.Next(_L("Close Logical Channel"));
   1.297 +		Camera.Close();
   1.298 +
   1.299 +		test.End();
   1.300 +
   1.301 +	test.Next(_L("Test cleanup 2"));
   1.302 +
   1.303 +		test.Start(_L("Open Logical Channel"));
   1.304 +		r=Camera.Open();
   1.305 +		test(r==KErrNone);
   1.306 +
   1.307 +		test.Next(_L("SetConfig"));
   1.308 +		r=Camera.SetConfig(ConfigBuf);
   1.309 +		test(r==KErrNone);
   1.310 +
   1.311 +		test.Next(_L("Close Logical Channel"));
   1.312 +		Camera.Close();
   1.313 +
   1.314 +		test.End();
   1.315 +
   1.316 +	test.Next(_L("Test cleanup 2"));
   1.317 +
   1.318 +		test.Start(_L("Open Logical Channel"));
   1.319 +		r=Camera.Open();
   1.320 +		test(r==KErrNone);
   1.321 +
   1.322 +		test.Next(_L("SetConfig"));
   1.323 +		r=Camera.SetConfig(ConfigBuf);
   1.324 +		test(r==KErrNone);
   1.325 +
   1.326 +		test.Next(_L("StartCapture"));
   1.327 +		r=Camera.StartCapture();
   1.328 +		test(r==KErrNone);
   1.329 +
   1.330 +		test.Next(_L("Close Logical Channel"));
   1.331 +		Camera.Close();
   1.332 +
   1.333 +		test.End();
   1.334 +
   1.335 +	test.Next(_L("Test cleanup 3"));
   1.336 +
   1.337 +		test.Start(_L("Open Logical Channel"));
   1.338 +		r=Camera.Open();
   1.339 +		test(r==KErrNone);
   1.340 +
   1.341 +		test.Next(_L("SetConfig"));
   1.342 +		r=Camera.SetConfig(ConfigBuf);
   1.343 +		test(r==KErrNone);
   1.344 +
   1.345 +		test.Next(_L("StartCapture"));
   1.346 +		r=Camera.StartCapture();
   1.347 +		test(r==KErrNone);
   1.348 +
   1.349 +		test.Next(_L("CaptureImage"));
   1.350 +		Camera.CaptureImage(s);
   1.351 +		User::WaitForRequest(s);
   1.352 +
   1.353 +		test.Next(_L("Close Logical Channel"));
   1.354 +		Camera.Close();
   1.355 +
   1.356 +		test.End();
   1.357 +
   1.358 +	test.End();
   1.359 +
   1.360 +	User::After(500000);	// allow any async close operations to complete
   1.361 +
   1.362 +	__KHEAP_MARKEND;
   1.363 +
   1.364 +	return(0);
   1.365 +    }
   1.366 +
   1.367 +