|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // in its implementation. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file Test code for example camera device driver which uses Shared Chunks |
|
20 @publishedPartner |
|
21 @prototype 9.1 |
|
22 */ |
|
23 |
|
24 #include <e32test.h> |
|
25 #include <e32svr.h> |
|
26 #include <e32def.h> |
|
27 #include <e32def_private.h> |
|
28 #include "camera1.h" |
|
29 |
|
30 LOCAL_D RTest test(_L("CAMERA1_TEST")); |
|
31 |
|
32 RCamera1 Camera; |
|
33 |
|
34 RCamera1::TConfigBuf ConfigBuf; |
|
35 |
|
36 const TInt KMaxBuffers = 8; |
|
37 |
|
38 _LIT(KCamera1FileName,"camera1_ldd"); |
|
39 |
|
40 enum TBufferMode |
|
41 { |
|
42 EReleaseOnCapture, |
|
43 EReleaseInBlocks, |
|
44 }; |
|
45 |
|
46 void Capture(TInt aNumBuffers, TBufferMode aMode) |
|
47 { |
|
48 TInt r; |
|
49 |
|
50 test(aNumBuffers<=KMaxBuffers); |
|
51 |
|
52 test.Start(_L("SetConfig")); |
|
53 ConfigBuf().iNumImageBuffers = aNumBuffers; |
|
54 ConfigBuf().iFrameRate=10; |
|
55 r=Camera.SetConfig(ConfigBuf); |
|
56 test(r==KErrNone); |
|
57 |
|
58 // Base address of chunk which contains images |
|
59 TUint8* chunkBase=Camera.ImageChunk().Base(); |
|
60 |
|
61 test.Next(_L("StartCapture")); |
|
62 r=Camera.StartCapture(); |
|
63 test(r==KErrNone); |
|
64 |
|
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; |
|
69 TInt bufNum = 0; |
|
70 |
|
71 // Stream load of images... |
|
72 for(TInt i=0; i<20*aNumBuffers; i++) |
|
73 { |
|
74 // Stall half way through streaming test... |
|
75 if(i==10+aNumBuffers-1) |
|
76 { |
|
77 test.Next(_L("Stall during image capture")); |
|
78 User::After(500000); |
|
79 } |
|
80 |
|
81 // Get an image... |
|
82 TRequestStatus s; |
|
83 if(aMode==EReleaseInBlocks) |
|
84 Camera.CaptureImage(s); |
|
85 else |
|
86 Camera.CaptureImage(s,imageBuffer[bufNum]); |
|
87 User::WaitForRequest(s); |
|
88 |
|
89 // imageOffset = capture result |
|
90 TInt imageOffset=s.Int(); |
|
91 imageBuffer[bufNum] = imageOffset; |
|
92 |
|
93 // Error? |
|
94 if(imageOffset<0) |
|
95 { |
|
96 test.Printf(_L("Error = %d\n"),imageOffset); |
|
97 test(0); |
|
98 } |
|
99 |
|
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); |
|
104 |
|
105 // Move on to next buffer... |
|
106 if(++bufNum>=aNumBuffers) |
|
107 { |
|
108 if(aMode==EReleaseInBlocks) |
|
109 { |
|
110 // Release all the image buffers we have... |
|
111 for(bufNum=0; bufNum<aNumBuffers; bufNum++) |
|
112 { |
|
113 RDebug::Print(_L("Release %08x\n"),imageBuffer[bufNum]); |
|
114 r=Camera.ReleaseImage(imageBuffer[bufNum]); |
|
115 imageBuffer[bufNum] = -1; |
|
116 test(r==KErrNone); |
|
117 } |
|
118 } |
|
119 bufNum = 0; |
|
120 } |
|
121 } |
|
122 |
|
123 test.Next(_L("EndCapture")); |
|
124 r=Camera.EndCapture(); |
|
125 test(r==KErrNone); |
|
126 |
|
127 test.End(); |
|
128 } |
|
129 |
|
130 |
|
131 GLDEF_C TInt E32Main() |
|
132 { |
|
133 test.Title(); |
|
134 |
|
135 TInt r; |
|
136 |
|
137 test.Start(_L("Loading CAMERA1 Device")); |
|
138 r=User::LoadLogicalDevice(KCamera1FileName); |
|
139 test(r==KErrNone || r==KErrAlreadyExists); |
|
140 |
|
141 __KHEAP_MARK; |
|
142 |
|
143 test.Next(_L("Open Device")); |
|
144 RDevice device; |
|
145 r=device.Open(RCamera1::Name()); |
|
146 test(r==KErrNone); |
|
147 |
|
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); |
|
157 |
|
158 test.Next(_L("Close Device")); |
|
159 device.Close(); |
|
160 |
|
161 test.Next(_L("Open Logical Channel")); |
|
162 r=Camera.Open(); |
|
163 test(r==KErrNone); |
|
164 |
|
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); |
|
169 test(r==KErrNone); |
|
170 |
|
171 const TSize KDefaultImageSize(config.iImageSize); |
|
172 test(KDefaultImageSize.iWidth!=0); |
|
173 test(KDefaultImageSize.iHeight!=0); |
|
174 test(config.iImageBytesPerPixel!=0); |
|
175 |
|
176 test.Next(_L("StartCapture (before SetConfig has been called)")); |
|
177 r=Camera.StartCapture(); |
|
178 test(r==KErrNotReady); |
|
179 |
|
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); |
|
186 test(r==KErrNone); |
|
187 |
|
188 test.Next(_L("Check handle duplication")); |
|
189 RCamera1 Camera2=Camera; |
|
190 r=Camera2.Duplicate(RThread(),EOwnerProcess); |
|
191 test(r==KErrNone); |
|
192 Camera2.Close(); |
|
193 |
|
194 test.Next(_L("Check config set")); |
|
195 ConfigBuf.FillZ(); |
|
196 r=Camera.GetConfig(ConfigBuf); |
|
197 test(r==KErrNone); |
|
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); |
|
202 |
|
203 test.Next(_L("Check image chunk handle")); |
|
204 test(Camera.ImageChunk().Handle()!=KNullHandle); |
|
205 Camera.ImageChunk().Base(); |
|
206 |
|
207 test.Next(_L("CaptureImage (before StartCapture has been called)")); |
|
208 TRequestStatus s; |
|
209 Camera.CaptureImage(s); |
|
210 User::WaitForRequest(s); |
|
211 test(s.Int()==KErrNotReady); |
|
212 |
|
213 test.Next(_L("StartCapture")); |
|
214 r=Camera.StartCapture(); |
|
215 test(r==KErrNone); |
|
216 |
|
217 test.Next(_L("StartCapture again")); |
|
218 r=Camera.StartCapture(); |
|
219 test(r==KErrInUse); |
|
220 |
|
221 test.Next(_L("SetConfig whilst capturing")); |
|
222 r=Camera.SetConfig(ConfigBuf); |
|
223 test(r==KErrInUse); |
|
224 |
|
225 test.Next(_L("CaptureImage")); |
|
226 Camera.CaptureImage(s); |
|
227 |
|
228 test.Next(_L("CaptureImage again (before last has completed)")); |
|
229 TRequestStatus s2; |
|
230 Camera.CaptureImage(s2); |
|
231 User::WaitForRequest(s2); |
|
232 test(s2.Int()==KErrInUse); |
|
233 |
|
234 test.Next(_L("CaptureCancel")); |
|
235 Camera.CaptureImageCancel(); |
|
236 User::WaitForRequest(s); |
|
237 test(s.Int()==KErrCancel); |
|
238 |
|
239 test.Next(_L("CaptureCancel again")); |
|
240 Camera.CaptureImageCancel(); |
|
241 |
|
242 test.Next(_L("CaptureImage")); |
|
243 Camera.CaptureImage(s); |
|
244 User::WaitForRequest(s); |
|
245 test(s.Int()>=0); |
|
246 |
|
247 test.Next(_L("CaptureImage again (before releasing previous image)")); |
|
248 Camera.CaptureImage(s2); |
|
249 User::WaitForRequest(s2); |
|
250 test(s2.Int()==KErrOverflow); |
|
251 |
|
252 test.Next(_L("ReleaseImage")); |
|
253 r=Camera.ReleaseImage(s.Int()); |
|
254 test(r==KErrNone); |
|
255 |
|
256 test.Next(_L("ReleaseImage again")); |
|
257 r=Camera.ReleaseImage(s.Int()); |
|
258 test(r==KErrNotFound); |
|
259 |
|
260 test.Next(_L("CaptureImage")); |
|
261 Camera.CaptureImage(s); |
|
262 |
|
263 test.Next(_L("EndCapture")); |
|
264 r=Camera.EndCapture(); |
|
265 test(r==KErrNone); |
|
266 User::WaitForRequest(s); |
|
267 test(s.Int()==KErrCancel); |
|
268 |
|
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); |
|
273 |
|
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); |
|
278 |
|
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); |
|
283 |
|
284 test.Next(_L("Close Logical Channel")); |
|
285 Camera.Close(); |
|
286 |
|
287 test.Next(_L("Test cleanup 1")); |
|
288 |
|
289 test.Start(_L("Open Logical Channel")); |
|
290 r=Camera.Open(); |
|
291 test(r==KErrNone); |
|
292 |
|
293 test.Next(_L("Close Logical Channel")); |
|
294 Camera.Close(); |
|
295 |
|
296 test.End(); |
|
297 |
|
298 test.Next(_L("Test cleanup 2")); |
|
299 |
|
300 test.Start(_L("Open Logical Channel")); |
|
301 r=Camera.Open(); |
|
302 test(r==KErrNone); |
|
303 |
|
304 test.Next(_L("SetConfig")); |
|
305 r=Camera.SetConfig(ConfigBuf); |
|
306 test(r==KErrNone); |
|
307 |
|
308 test.Next(_L("Close Logical Channel")); |
|
309 Camera.Close(); |
|
310 |
|
311 test.End(); |
|
312 |
|
313 test.Next(_L("Test cleanup 2")); |
|
314 |
|
315 test.Start(_L("Open Logical Channel")); |
|
316 r=Camera.Open(); |
|
317 test(r==KErrNone); |
|
318 |
|
319 test.Next(_L("SetConfig")); |
|
320 r=Camera.SetConfig(ConfigBuf); |
|
321 test(r==KErrNone); |
|
322 |
|
323 test.Next(_L("StartCapture")); |
|
324 r=Camera.StartCapture(); |
|
325 test(r==KErrNone); |
|
326 |
|
327 test.Next(_L("Close Logical Channel")); |
|
328 Camera.Close(); |
|
329 |
|
330 test.End(); |
|
331 |
|
332 test.Next(_L("Test cleanup 3")); |
|
333 |
|
334 test.Start(_L("Open Logical Channel")); |
|
335 r=Camera.Open(); |
|
336 test(r==KErrNone); |
|
337 |
|
338 test.Next(_L("SetConfig")); |
|
339 r=Camera.SetConfig(ConfigBuf); |
|
340 test(r==KErrNone); |
|
341 |
|
342 test.Next(_L("StartCapture")); |
|
343 r=Camera.StartCapture(); |
|
344 test(r==KErrNone); |
|
345 |
|
346 test.Next(_L("CaptureImage")); |
|
347 Camera.CaptureImage(s); |
|
348 User::WaitForRequest(s); |
|
349 |
|
350 test.Next(_L("Close Logical Channel")); |
|
351 Camera.Close(); |
|
352 |
|
353 test.End(); |
|
354 |
|
355 test.End(); |
|
356 |
|
357 User::After(500000); // allow any async close operations to complete |
|
358 |
|
359 __KHEAP_MARKEND; |
|
360 |
|
361 return(0); |
|
362 } |
|
363 |
|
364 |