sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// in its implementation.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file Test code for example camera device driver which uses Shared Chunks
|
sl@0
|
20 |
@publishedPartner
|
sl@0
|
21 |
@prototype 9.1
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <e32test.h>
|
sl@0
|
25 |
#include <e32svr.h>
|
sl@0
|
26 |
#include <e32def.h>
|
sl@0
|
27 |
#include <e32def_private.h>
|
sl@0
|
28 |
#include "camera1.h"
|
sl@0
|
29 |
|
sl@0
|
30 |
LOCAL_D RTest test(_L("CAMERA1_TEST"));
|
sl@0
|
31 |
|
sl@0
|
32 |
RCamera1 Camera;
|
sl@0
|
33 |
|
sl@0
|
34 |
RCamera1::TConfigBuf ConfigBuf;
|
sl@0
|
35 |
|
sl@0
|
36 |
const TInt KMaxBuffers = 8;
|
sl@0
|
37 |
|
sl@0
|
38 |
_LIT(KCamera1FileName,"camera1_ldd");
|
sl@0
|
39 |
|
sl@0
|
40 |
enum TBufferMode
|
sl@0
|
41 |
{
|
sl@0
|
42 |
EReleaseOnCapture,
|
sl@0
|
43 |
EReleaseInBlocks,
|
sl@0
|
44 |
};
|
sl@0
|
45 |
|
sl@0
|
46 |
void Capture(TInt aNumBuffers, TBufferMode aMode)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
TInt r;
|
sl@0
|
49 |
|
sl@0
|
50 |
test(aNumBuffers<=KMaxBuffers);
|
sl@0
|
51 |
|
sl@0
|
52 |
test.Start(_L("SetConfig"));
|
sl@0
|
53 |
ConfigBuf().iNumImageBuffers = aNumBuffers;
|
sl@0
|
54 |
ConfigBuf().iFrameRate=10;
|
sl@0
|
55 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
56 |
test(r==KErrNone);
|
sl@0
|
57 |
|
sl@0
|
58 |
// Base address of chunk which contains images
|
sl@0
|
59 |
TUint8* chunkBase=Camera.ImageChunk().Base();
|
sl@0
|
60 |
|
sl@0
|
61 |
test.Next(_L("StartCapture"));
|
sl@0
|
62 |
r=Camera.StartCapture();
|
sl@0
|
63 |
test(r==KErrNone);
|
sl@0
|
64 |
|
sl@0
|
65 |
test.Next(_L("Capture images..."));
|
sl@0
|
66 |
TInt imageBuffer[KMaxBuffers]; // Array of image buffers we've received
|
sl@0
|
67 |
memset(imageBuffer,~0,sizeof(imageBuffer)); // Initialise to 'empty' (-1)
|
sl@0
|
68 |
TInt lastFrameCounter = -1;
|
sl@0
|
69 |
TInt bufNum = 0;
|
sl@0
|
70 |
|
sl@0
|
71 |
// Stream load of images...
|
sl@0
|
72 |
for(TInt i=0; i<20*aNumBuffers; i++)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
// Stall half way through streaming test...
|
sl@0
|
75 |
if(i==10+aNumBuffers-1)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
test.Next(_L("Stall during image capture"));
|
sl@0
|
78 |
User::After(500000);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
// Get an image...
|
sl@0
|
82 |
TRequestStatus s;
|
sl@0
|
83 |
if(aMode==EReleaseInBlocks)
|
sl@0
|
84 |
Camera.CaptureImage(s);
|
sl@0
|
85 |
else
|
sl@0
|
86 |
Camera.CaptureImage(s,imageBuffer[bufNum]);
|
sl@0
|
87 |
User::WaitForRequest(s);
|
sl@0
|
88 |
|
sl@0
|
89 |
// imageOffset = capture result
|
sl@0
|
90 |
TInt imageOffset=s.Int();
|
sl@0
|
91 |
imageBuffer[bufNum] = imageOffset;
|
sl@0
|
92 |
|
sl@0
|
93 |
// Error?
|
sl@0
|
94 |
if(imageOffset<0)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
test.Printf(_L("Error = %d\n"),imageOffset);
|
sl@0
|
97 |
test(0);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
// Check image memory is accessable and get counter
|
sl@0
|
101 |
TInt frameCounter = *(TInt*)(chunkBase+imageOffset); // Test driver puts frame counter at image start
|
sl@0
|
102 |
RDebug::Print(_L("Capture %08x(%04d)\n"),imageOffset,frameCounter);
|
sl@0
|
103 |
test(frameCounter>lastFrameCounter);
|
sl@0
|
104 |
|
sl@0
|
105 |
// Move on to next buffer...
|
sl@0
|
106 |
if(++bufNum>=aNumBuffers)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
if(aMode==EReleaseInBlocks)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
// Release all the image buffers we have...
|
sl@0
|
111 |
for(bufNum=0; bufNum<aNumBuffers; bufNum++)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
RDebug::Print(_L("Release %08x\n"),imageBuffer[bufNum]);
|
sl@0
|
114 |
r=Camera.ReleaseImage(imageBuffer[bufNum]);
|
sl@0
|
115 |
imageBuffer[bufNum] = -1;
|
sl@0
|
116 |
test(r==KErrNone);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
}
|
sl@0
|
119 |
bufNum = 0;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
test.Next(_L("EndCapture"));
|
sl@0
|
124 |
r=Camera.EndCapture();
|
sl@0
|
125 |
test(r==KErrNone);
|
sl@0
|
126 |
|
sl@0
|
127 |
test.End();
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
GLDEF_C TInt E32Main()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
test.Title();
|
sl@0
|
134 |
|
sl@0
|
135 |
TInt r;
|
sl@0
|
136 |
|
sl@0
|
137 |
test.Start(_L("Loading CAMERA1 Device"));
|
sl@0
|
138 |
r=User::LoadLogicalDevice(KCamera1FileName);
|
sl@0
|
139 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
140 |
|
sl@0
|
141 |
__KHEAP_MARK;
|
sl@0
|
142 |
|
sl@0
|
143 |
test.Next(_L("Open Device"));
|
sl@0
|
144 |
RDevice device;
|
sl@0
|
145 |
r=device.Open(RCamera1::Name());
|
sl@0
|
146 |
test(r==KErrNone);
|
sl@0
|
147 |
|
sl@0
|
148 |
test.Next(_L("Get Device Capabilities"));
|
sl@0
|
149 |
RCamera1::TCaps caps;
|
sl@0
|
150 |
TPckg<RCamera1::TCaps>capsPckg(caps);
|
sl@0
|
151 |
capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
|
sl@0
|
152 |
device.GetCaps(capsPckg);
|
sl@0
|
153 |
TVersion expectedVer(RCamera1::VersionRequired());
|
sl@0
|
154 |
test(caps.iVersion.iMajor==expectedVer.iMajor);
|
sl@0
|
155 |
test(caps.iVersion.iMinor==expectedVer.iMinor);
|
sl@0
|
156 |
test(caps.iVersion.iBuild==expectedVer.iBuild);
|
sl@0
|
157 |
|
sl@0
|
158 |
test.Next(_L("Close Device"));
|
sl@0
|
159 |
device.Close();
|
sl@0
|
160 |
|
sl@0
|
161 |
test.Next(_L("Open Logical Channel"));
|
sl@0
|
162 |
r=Camera.Open();
|
sl@0
|
163 |
test(r==KErrNone);
|
sl@0
|
164 |
|
sl@0
|
165 |
test.Next(_L("GetConfig"));
|
sl@0
|
166 |
RCamera1::TConfig& config=ConfigBuf();
|
sl@0
|
167 |
ConfigBuf.FillZ(); // Zero 'config' so we can tell if GetConfig has really filled it
|
sl@0
|
168 |
r=Camera.GetConfig(ConfigBuf);
|
sl@0
|
169 |
test(r==KErrNone);
|
sl@0
|
170 |
|
sl@0
|
171 |
const TSize KDefaultImageSize(config.iImageSize);
|
sl@0
|
172 |
test(KDefaultImageSize.iWidth!=0);
|
sl@0
|
173 |
test(KDefaultImageSize.iHeight!=0);
|
sl@0
|
174 |
test(config.iImageBytesPerPixel!=0);
|
sl@0
|
175 |
|
sl@0
|
176 |
test.Next(_L("StartCapture (before SetConfig has been called)"));
|
sl@0
|
177 |
r=Camera.StartCapture();
|
sl@0
|
178 |
test(r==KErrNotReady);
|
sl@0
|
179 |
|
sl@0
|
180 |
test.Next(_L("SetConfig"));
|
sl@0
|
181 |
config.iImageSize.iWidth = KDefaultImageSize.iWidth/2;
|
sl@0
|
182 |
config.iImageSize.iHeight = KDefaultImageSize.iHeight/2;
|
sl@0
|
183 |
config.iFrameRate = 2; // Slow rate to give timing dependant tests a chance
|
sl@0
|
184 |
config.iNumImageBuffers = 1;
|
sl@0
|
185 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
186 |
test(r==KErrNone);
|
sl@0
|
187 |
|
sl@0
|
188 |
test.Next(_L("Check handle duplication"));
|
sl@0
|
189 |
RCamera1 Camera2=Camera;
|
sl@0
|
190 |
r=Camera2.Duplicate(RThread(),EOwnerProcess);
|
sl@0
|
191 |
test(r==KErrNone);
|
sl@0
|
192 |
Camera2.Close();
|
sl@0
|
193 |
|
sl@0
|
194 |
test.Next(_L("Check config set"));
|
sl@0
|
195 |
ConfigBuf.FillZ();
|
sl@0
|
196 |
r=Camera.GetConfig(ConfigBuf);
|
sl@0
|
197 |
test(r==KErrNone);
|
sl@0
|
198 |
test(config.iImageSize.iWidth==KDefaultImageSize.iWidth/2);
|
sl@0
|
199 |
test(config.iImageSize.iHeight==KDefaultImageSize.iHeight/2);
|
sl@0
|
200 |
test(ConfigBuf().iFrameRate==2);
|
sl@0
|
201 |
test(ConfigBuf().iNumImageBuffers==1);
|
sl@0
|
202 |
|
sl@0
|
203 |
test.Next(_L("Check image chunk handle"));
|
sl@0
|
204 |
test(Camera.ImageChunk().Handle()!=KNullHandle);
|
sl@0
|
205 |
Camera.ImageChunk().Base();
|
sl@0
|
206 |
|
sl@0
|
207 |
test.Next(_L("CaptureImage (before StartCapture has been called)"));
|
sl@0
|
208 |
TRequestStatus s;
|
sl@0
|
209 |
Camera.CaptureImage(s);
|
sl@0
|
210 |
User::WaitForRequest(s);
|
sl@0
|
211 |
test(s.Int()==KErrNotReady);
|
sl@0
|
212 |
|
sl@0
|
213 |
test.Next(_L("StartCapture"));
|
sl@0
|
214 |
r=Camera.StartCapture();
|
sl@0
|
215 |
test(r==KErrNone);
|
sl@0
|
216 |
|
sl@0
|
217 |
test.Next(_L("StartCapture again"));
|
sl@0
|
218 |
r=Camera.StartCapture();
|
sl@0
|
219 |
test(r==KErrInUse);
|
sl@0
|
220 |
|
sl@0
|
221 |
test.Next(_L("SetConfig whilst capturing"));
|
sl@0
|
222 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
223 |
test(r==KErrInUse);
|
sl@0
|
224 |
|
sl@0
|
225 |
test.Next(_L("CaptureImage"));
|
sl@0
|
226 |
Camera.CaptureImage(s);
|
sl@0
|
227 |
|
sl@0
|
228 |
test.Next(_L("CaptureImage again (before last has completed)"));
|
sl@0
|
229 |
TRequestStatus s2;
|
sl@0
|
230 |
Camera.CaptureImage(s2);
|
sl@0
|
231 |
User::WaitForRequest(s2);
|
sl@0
|
232 |
test(s2.Int()==KErrInUse);
|
sl@0
|
233 |
|
sl@0
|
234 |
test.Next(_L("CaptureCancel"));
|
sl@0
|
235 |
Camera.CaptureImageCancel();
|
sl@0
|
236 |
User::WaitForRequest(s);
|
sl@0
|
237 |
test(s.Int()==KErrCancel);
|
sl@0
|
238 |
|
sl@0
|
239 |
test.Next(_L("CaptureCancel again"));
|
sl@0
|
240 |
Camera.CaptureImageCancel();
|
sl@0
|
241 |
|
sl@0
|
242 |
test.Next(_L("CaptureImage"));
|
sl@0
|
243 |
Camera.CaptureImage(s);
|
sl@0
|
244 |
User::WaitForRequest(s);
|
sl@0
|
245 |
test(s.Int()>=0);
|
sl@0
|
246 |
|
sl@0
|
247 |
test.Next(_L("CaptureImage again (before releasing previous image)"));
|
sl@0
|
248 |
Camera.CaptureImage(s2);
|
sl@0
|
249 |
User::WaitForRequest(s2);
|
sl@0
|
250 |
test(s2.Int()==KErrOverflow);
|
sl@0
|
251 |
|
sl@0
|
252 |
test.Next(_L("ReleaseImage"));
|
sl@0
|
253 |
r=Camera.ReleaseImage(s.Int());
|
sl@0
|
254 |
test(r==KErrNone);
|
sl@0
|
255 |
|
sl@0
|
256 |
test.Next(_L("ReleaseImage again"));
|
sl@0
|
257 |
r=Camera.ReleaseImage(s.Int());
|
sl@0
|
258 |
test(r==KErrNotFound);
|
sl@0
|
259 |
|
sl@0
|
260 |
test.Next(_L("CaptureImage"));
|
sl@0
|
261 |
Camera.CaptureImage(s);
|
sl@0
|
262 |
|
sl@0
|
263 |
test.Next(_L("EndCapture"));
|
sl@0
|
264 |
r=Camera.EndCapture();
|
sl@0
|
265 |
test(r==KErrNone);
|
sl@0
|
266 |
User::WaitForRequest(s);
|
sl@0
|
267 |
test(s.Int()==KErrCancel);
|
sl@0
|
268 |
|
sl@0
|
269 |
test.Next(_L("CaptureImage streaming with 1 buffer and ReleaseOnCapture"));
|
sl@0
|
270 |
Capture(1,EReleaseOnCapture);
|
sl@0
|
271 |
test.Next(_L("CaptureImage streaming with 1 buffer and EReleaseInBlocks"));
|
sl@0
|
272 |
Capture(1,EReleaseInBlocks);
|
sl@0
|
273 |
|
sl@0
|
274 |
test.Next(_L("CaptureImage streaming with 2 buffers and ReleaseOnCapture"));
|
sl@0
|
275 |
Capture(2,EReleaseOnCapture);
|
sl@0
|
276 |
test.Next(_L("CaptureImage streaming with 2 buffers and EReleaseInBlocks"));
|
sl@0
|
277 |
Capture(2,EReleaseInBlocks);
|
sl@0
|
278 |
|
sl@0
|
279 |
test.Next(_L("CaptureImage streaming with 3 buffers and ReleaseOnCapture"));
|
sl@0
|
280 |
Capture(3,EReleaseOnCapture);
|
sl@0
|
281 |
test.Next(_L("CaptureImage streaming with 3 buffers and EReleaseInBlocks"));
|
sl@0
|
282 |
Capture(3,EReleaseInBlocks);
|
sl@0
|
283 |
|
sl@0
|
284 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
285 |
Camera.Close();
|
sl@0
|
286 |
|
sl@0
|
287 |
test.Next(_L("Test cleanup 1"));
|
sl@0
|
288 |
|
sl@0
|
289 |
test.Start(_L("Open Logical Channel"));
|
sl@0
|
290 |
r=Camera.Open();
|
sl@0
|
291 |
test(r==KErrNone);
|
sl@0
|
292 |
|
sl@0
|
293 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
294 |
Camera.Close();
|
sl@0
|
295 |
|
sl@0
|
296 |
test.End();
|
sl@0
|
297 |
|
sl@0
|
298 |
test.Next(_L("Test cleanup 2"));
|
sl@0
|
299 |
|
sl@0
|
300 |
test.Start(_L("Open Logical Channel"));
|
sl@0
|
301 |
r=Camera.Open();
|
sl@0
|
302 |
test(r==KErrNone);
|
sl@0
|
303 |
|
sl@0
|
304 |
test.Next(_L("SetConfig"));
|
sl@0
|
305 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
306 |
test(r==KErrNone);
|
sl@0
|
307 |
|
sl@0
|
308 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
309 |
Camera.Close();
|
sl@0
|
310 |
|
sl@0
|
311 |
test.End();
|
sl@0
|
312 |
|
sl@0
|
313 |
test.Next(_L("Test cleanup 2"));
|
sl@0
|
314 |
|
sl@0
|
315 |
test.Start(_L("Open Logical Channel"));
|
sl@0
|
316 |
r=Camera.Open();
|
sl@0
|
317 |
test(r==KErrNone);
|
sl@0
|
318 |
|
sl@0
|
319 |
test.Next(_L("SetConfig"));
|
sl@0
|
320 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
321 |
test(r==KErrNone);
|
sl@0
|
322 |
|
sl@0
|
323 |
test.Next(_L("StartCapture"));
|
sl@0
|
324 |
r=Camera.StartCapture();
|
sl@0
|
325 |
test(r==KErrNone);
|
sl@0
|
326 |
|
sl@0
|
327 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
328 |
Camera.Close();
|
sl@0
|
329 |
|
sl@0
|
330 |
test.End();
|
sl@0
|
331 |
|
sl@0
|
332 |
test.Next(_L("Test cleanup 3"));
|
sl@0
|
333 |
|
sl@0
|
334 |
test.Start(_L("Open Logical Channel"));
|
sl@0
|
335 |
r=Camera.Open();
|
sl@0
|
336 |
test(r==KErrNone);
|
sl@0
|
337 |
|
sl@0
|
338 |
test.Next(_L("SetConfig"));
|
sl@0
|
339 |
r=Camera.SetConfig(ConfigBuf);
|
sl@0
|
340 |
test(r==KErrNone);
|
sl@0
|
341 |
|
sl@0
|
342 |
test.Next(_L("StartCapture"));
|
sl@0
|
343 |
r=Camera.StartCapture();
|
sl@0
|
344 |
test(r==KErrNone);
|
sl@0
|
345 |
|
sl@0
|
346 |
test.Next(_L("CaptureImage"));
|
sl@0
|
347 |
Camera.CaptureImage(s);
|
sl@0
|
348 |
User::WaitForRequest(s);
|
sl@0
|
349 |
|
sl@0
|
350 |
test.Next(_L("Close Logical Channel"));
|
sl@0
|
351 |
Camera.Close();
|
sl@0
|
352 |
|
sl@0
|
353 |
test.End();
|
sl@0
|
354 |
|
sl@0
|
355 |
test.End();
|
sl@0
|
356 |
|
sl@0
|
357 |
User::After(500000); // allow any async close operations to complete
|
sl@0
|
358 |
|
sl@0
|
359 |
__KHEAP_MARKEND;
|
sl@0
|
360 |
|
sl@0
|
361 |
return(0);
|
sl@0
|
362 |
}
|
sl@0
|
363 |
|
sl@0
|
364 |
|