Update contrib.
1 // Copyright (c) 2005-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // in its implementation.
19 @file Test code for example camera device driver which uses Shared Chunks
27 #include <e32def_private.h>
30 LOCAL_D RTest test(_L("CAMERA1_TEST"));
34 RCamera1::TConfigBuf ConfigBuf;
36 const TInt KMaxBuffers = 8;
38 _LIT(KCamera1FileName,"camera1_ldd");
46 void Capture(TInt aNumBuffers, TBufferMode aMode)
50 test(aNumBuffers<=KMaxBuffers);
52 test.Start(_L("SetConfig"));
53 ConfigBuf().iNumImageBuffers = aNumBuffers;
54 ConfigBuf().iFrameRate=10;
55 r=Camera.SetConfig(ConfigBuf);
58 // Base address of chunk which contains images
59 TUint8* chunkBase=Camera.ImageChunk().Base();
61 test.Next(_L("StartCapture"));
62 r=Camera.StartCapture();
65 test.Next(_L("Capture images..."));
66 TInt imageBuffer[KMaxBuffers]; // Array of image buffers we've received
67 memset(imageBuffer,~0,sizeof(imageBuffer)); // Initialise to 'empty' (-1)
68 TInt lastFrameCounter = -1;
71 // Stream load of images...
72 for(TInt i=0; i<20*aNumBuffers; i++)
74 // Stall half way through streaming test...
75 if(i==10+aNumBuffers-1)
77 test.Next(_L("Stall during image capture"));
83 if(aMode==EReleaseInBlocks)
84 Camera.CaptureImage(s);
86 Camera.CaptureImage(s,imageBuffer[bufNum]);
87 User::WaitForRequest(s);
89 // imageOffset = capture result
90 TInt imageOffset=s.Int();
91 imageBuffer[bufNum] = imageOffset;
96 test.Printf(_L("Error = %d\n"),imageOffset);
100 // Check image memory is accessable and get counter
101 TInt frameCounter = *(TInt*)(chunkBase+imageOffset); // Test driver puts frame counter at image start
102 RDebug::Print(_L("Capture %08x(%04d)\n"),imageOffset,frameCounter);
103 test(frameCounter>lastFrameCounter);
105 // Move on to next buffer...
106 if(++bufNum>=aNumBuffers)
108 if(aMode==EReleaseInBlocks)
110 // Release all the image buffers we have...
111 for(bufNum=0; bufNum<aNumBuffers; bufNum++)
113 RDebug::Print(_L("Release %08x\n"),imageBuffer[bufNum]);
114 r=Camera.ReleaseImage(imageBuffer[bufNum]);
115 imageBuffer[bufNum] = -1;
123 test.Next(_L("EndCapture"));
124 r=Camera.EndCapture();
131 GLDEF_C TInt E32Main()
137 test.Start(_L("Loading CAMERA1 Device"));
138 r=User::LoadLogicalDevice(KCamera1FileName);
139 test(r==KErrNone || r==KErrAlreadyExists);
143 test.Next(_L("Open Device"));
145 r=device.Open(RCamera1::Name());
148 test.Next(_L("Get Device Capabilities"));
149 RCamera1::TCaps caps;
150 TPckg<RCamera1::TCaps>capsPckg(caps);
151 capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
152 device.GetCaps(capsPckg);
153 TVersion expectedVer(RCamera1::VersionRequired());
154 test(caps.iVersion.iMajor==expectedVer.iMajor);
155 test(caps.iVersion.iMinor==expectedVer.iMinor);
156 test(caps.iVersion.iBuild==expectedVer.iBuild);
158 test.Next(_L("Close Device"));
161 test.Next(_L("Open Logical Channel"));
165 test.Next(_L("GetConfig"));
166 RCamera1::TConfig& config=ConfigBuf();
167 ConfigBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
168 r=Camera.GetConfig(ConfigBuf);
171 const TSize KDefaultImageSize(config.iImageSize);
172 test(KDefaultImageSize.iWidth!=0);
173 test(KDefaultImageSize.iHeight!=0);
174 test(config.iImageBytesPerPixel!=0);
176 test.Next(_L("StartCapture (before SetConfig has been called)"));
177 r=Camera.StartCapture();
178 test(r==KErrNotReady);
180 test.Next(_L("SetConfig"));
181 config.iImageSize.iWidth = KDefaultImageSize.iWidth/2;
182 config.iImageSize.iHeight = KDefaultImageSize.iHeight/2;
183 config.iFrameRate = 2; // Slow rate to give timing dependant tests a chance
184 config.iNumImageBuffers = 1;
185 r=Camera.SetConfig(ConfigBuf);
188 test.Next(_L("Check handle duplication"));
189 RCamera1 Camera2=Camera;
190 r=Camera2.Duplicate(RThread(),EOwnerProcess);
194 test.Next(_L("Check config set"));
196 r=Camera.GetConfig(ConfigBuf);
198 test(config.iImageSize.iWidth==KDefaultImageSize.iWidth/2);
199 test(config.iImageSize.iHeight==KDefaultImageSize.iHeight/2);
200 test(ConfigBuf().iFrameRate==2);
201 test(ConfigBuf().iNumImageBuffers==1);
203 test.Next(_L("Check image chunk handle"));
204 test(Camera.ImageChunk().Handle()!=KNullHandle);
205 Camera.ImageChunk().Base();
207 test.Next(_L("CaptureImage (before StartCapture has been called)"));
209 Camera.CaptureImage(s);
210 User::WaitForRequest(s);
211 test(s.Int()==KErrNotReady);
213 test.Next(_L("StartCapture"));
214 r=Camera.StartCapture();
217 test.Next(_L("StartCapture again"));
218 r=Camera.StartCapture();
221 test.Next(_L("SetConfig whilst capturing"));
222 r=Camera.SetConfig(ConfigBuf);
225 test.Next(_L("CaptureImage"));
226 Camera.CaptureImage(s);
228 test.Next(_L("CaptureImage again (before last has completed)"));
230 Camera.CaptureImage(s2);
231 User::WaitForRequest(s2);
232 test(s2.Int()==KErrInUse);
234 test.Next(_L("CaptureCancel"));
235 Camera.CaptureImageCancel();
236 User::WaitForRequest(s);
237 test(s.Int()==KErrCancel);
239 test.Next(_L("CaptureCancel again"));
240 Camera.CaptureImageCancel();
242 test.Next(_L("CaptureImage"));
243 Camera.CaptureImage(s);
244 User::WaitForRequest(s);
247 test.Next(_L("CaptureImage again (before releasing previous image)"));
248 Camera.CaptureImage(s2);
249 User::WaitForRequest(s2);
250 test(s2.Int()==KErrOverflow);
252 test.Next(_L("ReleaseImage"));
253 r=Camera.ReleaseImage(s.Int());
256 test.Next(_L("ReleaseImage again"));
257 r=Camera.ReleaseImage(s.Int());
258 test(r==KErrNotFound);
260 test.Next(_L("CaptureImage"));
261 Camera.CaptureImage(s);
263 test.Next(_L("EndCapture"));
264 r=Camera.EndCapture();
266 User::WaitForRequest(s);
267 test(s.Int()==KErrCancel);
269 test.Next(_L("CaptureImage streaming with 1 buffer and ReleaseOnCapture"));
270 Capture(1,EReleaseOnCapture);
271 test.Next(_L("CaptureImage streaming with 1 buffer and EReleaseInBlocks"));
272 Capture(1,EReleaseInBlocks);
274 test.Next(_L("CaptureImage streaming with 2 buffers and ReleaseOnCapture"));
275 Capture(2,EReleaseOnCapture);
276 test.Next(_L("CaptureImage streaming with 2 buffers and EReleaseInBlocks"));
277 Capture(2,EReleaseInBlocks);
279 test.Next(_L("CaptureImage streaming with 3 buffers and ReleaseOnCapture"));
280 Capture(3,EReleaseOnCapture);
281 test.Next(_L("CaptureImage streaming with 3 buffers and EReleaseInBlocks"));
282 Capture(3,EReleaseInBlocks);
284 test.Next(_L("Close Logical Channel"));
287 test.Next(_L("Test cleanup 1"));
289 test.Start(_L("Open Logical Channel"));
293 test.Next(_L("Close Logical Channel"));
298 test.Next(_L("Test cleanup 2"));
300 test.Start(_L("Open Logical Channel"));
304 test.Next(_L("SetConfig"));
305 r=Camera.SetConfig(ConfigBuf);
308 test.Next(_L("Close Logical Channel"));
313 test.Next(_L("Test cleanup 2"));
315 test.Start(_L("Open Logical Channel"));
319 test.Next(_L("SetConfig"));
320 r=Camera.SetConfig(ConfigBuf);
323 test.Next(_L("StartCapture"));
324 r=Camera.StartCapture();
327 test.Next(_L("Close Logical Channel"));
332 test.Next(_L("Test cleanup 3"));
334 test.Start(_L("Open Logical Channel"));
338 test.Next(_L("SetConfig"));
339 r=Camera.SetConfig(ConfigBuf);
342 test.Next(_L("StartCapture"));
343 r=Camera.StartCapture();
346 test.Next(_L("CaptureImage"));
347 Camera.CaptureImage(s);
348 User::WaitForRequest(s);
350 test.Next(_L("Close Logical Channel"));
357 User::After(500000); // allow any async close operations to complete