|
1 // Copyright (c) 2007-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 "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Test for CApaDoor and CApaModelDoor Apis\n |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @test |
|
23 @internalComponent - Internal Symbian test code |
|
24 */ |
|
25 |
|
26 |
|
27 #include <f32file.h> |
|
28 #include <s32std.h> |
|
29 #include <s32stor.h> |
|
30 #include <s32file.h> |
|
31 #include <s32mem.h> |
|
32 #include <fbs.h> |
|
33 // |
|
34 #include <apamdr.h> |
|
35 #include <apgdoor.h> |
|
36 #include "tstapp.h" |
|
37 #include "T_MdrStep.h" |
|
38 // |
|
39 #include <e32test.h> |
|
40 |
|
41 /** |
|
42 Auxiliary Fn for Test Case ID T-MdrStep-testModelDoorL, |
|
43 T-MdrStep-testConversionL |
|
44 |
|
45 This method overrides CApaModelHeader::AppId(). It returns a |
|
46 TApaAppIdentifier object which identifies the application. |
|
47 |
|
48 */ |
|
49 TApaAppIdentifier CTestModelHeader::AppId()const |
|
50 { |
|
51 TFileName dllname=_L("tstapp.app"); |
|
52 #define KTestAppId TApaAppIdentifier(KUidTestApp,dllname) |
|
53 return KTestAppId; |
|
54 } |
|
55 |
|
56 |
|
57 /** |
|
58 Auxiliary Fn for Test Case ID T-MdrStep-testModelDoorL, |
|
59 T-MdrStep-testConversionL |
|
60 |
|
61 This method overrides CApaModelHeader::StoreL().It stores the |
|
62 data in the stream to a store. |
|
63 |
|
64 */ |
|
65 void CTestModelHeader::StoreL(CStreamStore& aStore,CStreamDictionary& aDict) const |
|
66 { |
|
67 // write out some data |
|
68 RStoreWriteStream stream; |
|
69 TStreamId id=stream.CreateLC(aStore); |
|
70 stream.WriteInt32L(iData); |
|
71 stream.WriteInt32L(0); // write testapp doc format - no subdocuments |
|
72 stream.CommitL(); |
|
73 aDict.AssignL(KUidTestAppHeadStream,id); |
|
74 CleanupStack::PopAndDestroy(); // stream |
|
75 } |
|
76 |
|
77 |
|
78 /** |
|
79 Auxiliary Fn for Test Case ID T-MdrStep-testModelDoorL, |
|
80 T-MdrStep-testConversionL |
|
81 |
|
82 This method reads the data stored in the store. |
|
83 |
|
84 */ |
|
85 void CTestModelHeader::RestoreL(const CStreamStore& aStore,const CStreamDictionary& aDict) |
|
86 { |
|
87 // read in some data |
|
88 RStoreReadStream stream; |
|
89 stream.OpenLC(aStore,aDict.At(KUidTestAppHeadStream)); |
|
90 iData = stream.ReadInt32L(); |
|
91 CleanupStack::PopAndDestroy(); // stream |
|
92 } |
|
93 |
|
94 |
|
95 void CTestModelHeader::DetachFromStoreL(CPicture::TDetach /*aDetach*/) |
|
96 {} |
|
97 |
|
98 |
|
99 /** |
|
100 Auxiliary Fn for Test Case ID T-MdrStep-testModelDoorL, |
|
101 T-MdrStep-testConversionL |
|
102 |
|
103 This method overrides MApaModelHeaderFactory::NewHeaderL().It creates and |
|
104 restores model header from the store. |
|
105 |
|
106 */ |
|
107 CApaModelHeader* TTestModelHeaderFactory::NewHeaderL(const CStreamStore& aStore,const CStreamDictionary& aDict, |
|
108 const TApaAppIdentifier& aAppId)const |
|
109 { |
|
110 TFileName dllname=_L("tstapp.app"); |
|
111 #define KTestAppId TApaAppIdentifier(KUidTestApp,dllname) |
|
112 if (aAppId.iAppUid!=KTestAppId.iAppUid) |
|
113 User::Leave(KErrNotSupported); |
|
114 CTestModelHeader* header = new(ELeave) CTestModelHeader(); |
|
115 CleanupStack::PushL(header); |
|
116 header->RestoreL(aStore,aDict); |
|
117 CleanupStack::Pop(); // header |
|
118 return header; |
|
119 } |
|
120 |
|
121 |
|
122 /** |
|
123 @SYMTestCaseID T-MdrStep-testModelDoorL |
|
124 |
|
125 @SYMPREQ |
|
126 |
|
127 @SYMTestCaseDesc Tests storing and restoring of Model door. |
|
128 |
|
129 @SYMTestPriority High |
|
130 |
|
131 @SYMTestStatus Implemented |
|
132 |
|
133 @SYMTestActions The test creates a test model header and initializes its |
|
134 member variable iData. A model door object is created by passing |
|
135 application model wrapper object to be embedded to CApaModelDoor::NewL(). |
|
136 A temporary store is created and CTestModelHeader::StoreL() is called to |
|
137 store the model door. Call CApaModelDoor::NewL() specifying the store and |
|
138 stream to restore the stored model door. Test values from the restored |
|
139 model door.\n |
|
140 API Calls:\n |
|
141 CApaModelDoor::NewL(CApaModelHeader* aHeader)\n |
|
142 CApaModelDoor::StoreL(CStreamStore& aStore) const\n |
|
143 CApaModelDoor::NewL(const CStreamStore& aStore,TStreamId aHeadStreamId,const MApaModelHeaderFactory* aFactory)\n |
|
144 CApaModelDoor::ModelHeader()\n |
|
145 |
|
146 @SYMTestExpectedResults Test completes restoration of model door successfully. |
|
147 |
|
148 */ |
|
149 void CT_MdrStep::testModelDoorL() |
|
150 { |
|
151 const TUid KTestSourceId={458}; |
|
152 INFO_PRINTF1(_L("Creating a model door")); |
|
153 |
|
154 // create a model header |
|
155 CTestModelHeader* header = new CTestModelHeader(); |
|
156 TEST(header!=NULL); |
|
157 header->iData = 7; |
|
158 |
|
159 // embed the header in a door |
|
160 CApaModelDoor* door=NULL; |
|
161 TRAPD(ret, door=CApaModelDoor::NewL(header) ); |
|
162 TEST(ret==KErrNone); |
|
163 |
|
164 // set the source |
|
165 door->SetSource(KTestSourceId); |
|
166 |
|
167 // create an in-memory store |
|
168 CBufStore* store=NULL; |
|
169 TRAP(ret, store=CBufStore::NewL(2) ); |
|
170 TEST(ret==KErrNone); |
|
171 |
|
172 // store the door |
|
173 INFO_PRINTF1(_L("Storing the model door")); |
|
174 TStreamId id = TStreamId(NULL); |
|
175 TRAP(ret, id=door->StoreL(*store) ); |
|
176 TEST(ret==KErrNone); |
|
177 delete door; // deletes header also |
|
178 |
|
179 // restore the door |
|
180 INFO_PRINTF1(_L("Restoring the model door")); |
|
181 TTestModelHeaderFactory factory; |
|
182 TRAP(ret, door=CApaModelDoor::NewL(*store,id,&factory) ); |
|
183 TEST(ret==KErrNone); |
|
184 TEST( ((CTestModelHeader*)door->ModelHeader())->iData==7 ); |
|
185 TEST((door->Source()==KTestSourceId)); |
|
186 delete door; |
|
187 delete store; |
|
188 } |
|
189 |
|
190 |
|
191 /** |
|
192 @SYMTestCaseID T-MdrStep-testConversionL |
|
193 |
|
194 @SYMPREQ |
|
195 |
|
196 @SYMTestCaseDesc Tests conversion of door format to model door format and back. |
|
197 |
|
198 @SYMTestPriority High |
|
199 |
|
200 @SYMTestStatus Implemented |
|
201 |
|
202 @SYMTestActions Create a new document for the tstapp and create a door for the |
|
203 document by calling CApaDoor::NewL(). Create a temporary store to store |
|
204 the door format by calling CTestModelHeader::StoreL(). Restore the door |
|
205 to a model door from the temporary store by calling CApaModelDoor::NewL(). |
|
206 Delete the store and store the model door format to a newly created store. |
|
207 Change the format and size of the model door by calling CApaModelDoor::SetFormat() |
|
208 and CApaModelDoor::SetSizeInTwips(). Store the new model door format to |
|
209 the temporary store. Restore the saved model door format to a new door. |
|
210 Observe the conversion of format & size from the saved format to default |
|
211 while it is restored as door.\n |
|
212 API Calls:\n |
|
213 CApaDoor::NewL(RFs& aFs,CApaDocument& aDoc,const TSize& aDefaultIconSizeInTwips)\n |
|
214 CApaDoor::StoreL(CStreamStore& aStore) const\n |
|
215 CApaModelDoor::NewL(const CStreamStore& aStore,TStreamId aHeadStreamId,const MApaModelHeaderFactory* aFactory)\n |
|
216 CApaModelDoor::StoreL(CStreamStore& aStore) const\n |
|
217 CApaModelDoor::SetFormat(TFormat aFormat)\n |
|
218 CApaModelDoor::SetSizeInTwips(const TSize& aSize)\n |
|
219 |
|
220 @SYMTestExpectedResults Test confirms that there is a conversion from the saved model format to |
|
221 default format while it is restored as a door. |
|
222 |
|
223 */ |
|
224 void CT_MdrStep::testConversionL() |
|
225 { |
|
226 INFO_PRINTF1(_L("Testing Conversions")); |
|
227 const TUid KTestSourceId={458}; |
|
228 |
|
229 // set things up |
|
230 TRAPD(ret,iProcess = CApaProcess::NewL(iFs)); |
|
231 TEST(ret==KErrNone); |
|
232 CBufStore* store=NULL; |
|
233 // |
|
234 // create a door |
|
235 INFO_PRINTF1(_L("Restoring a full door as a model door")); |
|
236 CApaDocument* doc=NULL; |
|
237 TRAP(ret,doc=iProcess->AddNewDocumentL(KUidTestApp)); |
|
238 |
|
239 TEST(ret==KErrNone); |
|
240 doc->EditL(NULL); // increments value to 1 |
|
241 CApaDoor* door=NULL; |
|
242 TRAP(ret, door=CApaDoor::NewL(iFs,*doc,TSize(1000,1000)) ); |
|
243 TEST(ret==KErrNone); |
|
244 |
|
245 // set the source |
|
246 door->SetSource(KTestSourceId); |
|
247 |
|
248 // create an in-memory store |
|
249 TRAP(ret, store=CBufStore::NewL(2) ); |
|
250 TEST(ret==KErrNone); |
|
251 |
|
252 // store the door |
|
253 TStreamId id = TStreamId(NULL); |
|
254 TRAP(ret, id=door->StoreL(*store) ); |
|
255 TEST(ret==KErrNone); |
|
256 delete door; // deletes doc also |
|
257 door = NULL; |
|
258 doc = NULL; |
|
259 |
|
260 // restore the door into a model door |
|
261 TTestModelHeaderFactory factory; |
|
262 CApaModelDoor* modelDoor=NULL; |
|
263 TRAP(ret, modelDoor=CApaModelDoor::NewL(*store,id,&factory) ); |
|
264 TEST(ret==KErrNone); |
|
265 TEST( ((CTestModelHeader*)modelDoor->ModelHeader())->iData==1 ); |
|
266 TEST(modelDoor->Format()==CApaDoorBase::EIconic); |
|
267 TEST(modelDoor->Source()==KTestSourceId); |
|
268 TSize size; |
|
269 modelDoor->GetSizeInTwips(size); |
|
270 TEST(size==TSize(1000,1000)); |
|
271 |
|
272 // store the model door |
|
273 INFO_PRINTF1(_L("Restoring a model door as a full door")); |
|
274 delete store; |
|
275 store = NULL; |
|
276 TRAP(ret, store=CBufStore::NewL(2) ); |
|
277 TEST(ret==KErrNone); |
|
278 TRAP(ret, id=modelDoor->StoreL(*store) ); |
|
279 TEST(ret==KErrNone); |
|
280 |
|
281 // restore the model door into a full door |
|
282 TRAP(ret, door=CApaDoor::NewL(iFs,*store,id,*iProcess) ); |
|
283 TEST(ret==KErrNone); |
|
284 delete door; |
|
285 door = NULL; |
|
286 delete store; |
|
287 store = NULL; |
|
288 |
|
289 // change the model door format to glass & store it |
|
290 TRAP(ret, store=CBufStore::NewL(2) ); |
|
291 TEST(ret==KErrNone); |
|
292 modelDoor->SetFormat(CApaDoorBase::EGlassDoor); |
|
293 modelDoor->SetSizeInTwips(TSize(2500,27)); |
|
294 TRAP(ret, id=modelDoor->StoreL(*store) ); |
|
295 TEST(ret==KErrNone); |
|
296 |
|
297 delete modelDoor; // deletes header also |
|
298 modelDoor = NULL; |
|
299 |
|
300 // restore into a full door - this should switch the format to iconic and use the default icon size |
|
301 TRAP(ret, door=CApaDoor::NewL(iFs,*store,id,*iProcess) ); |
|
302 TEST(ret==KErrNone); |
|
303 TEST(door->Format()==CApaDoorBase::EIconic); |
|
304 TEST(door->Source()==KTestSourceId); |
|
305 door->GetSizeInTwips(size); |
|
306 TEST(size==TSize(500,500)); |
|
307 delete door; |
|
308 door = NULL; |
|
309 delete store; |
|
310 store = NULL; |
|
311 |
|
312 delete iProcess; |
|
313 } |
|
314 |
|
315 |
|
316 // Tests various functions to increase API test coverage |
|
317 |
|
318 /** |
|
319 @SYMTestCaseID T-MdrStep-testMiscellaneousL |
|
320 |
|
321 @SYMPREQ |
|
322 |
|
323 @SYMTestCaseDesc Tests capabalities of CApaDoor Apis. |
|
324 |
|
325 @SYMTestPriority High |
|
326 |
|
327 @SYMTestStatus Implemented |
|
328 |
|
329 @SYMTestActions Create a document for tstapp. Create a door to this document.\n |
|
330 Test the following APIs:\n |
|
331 CApaDoor::Capability() const\n |
|
332 CApaDoor::AppUidL() const\n |
|
333 CApaDoor::SetFormatToTemporaryIconL()\n |
|
334 CApaDoor::SetCropInTwips()\n |
|
335 CApaDoor::SetScaleFactor()\n |
|
336 API Calls:\n |
|
337 CApaDoor::Capability() const\n |
|
338 CApaDoor::AppUidL() const\n |
|
339 CApaDoor::SetFormatToTemporaryIconL(TBool aEnabled=ETrue)\n |
|
340 CApaDoor::SetCropInTwips(const TMargins& aMargins)\n |
|
341 CApaDoor::SetScaleFactor(TInt aScaleFactorWidth,TInt aScaleFactorHeight)\n |
|
342 |
|
343 @SYMTestExpectedResults Test checks results against expected values. |
|
344 |
|
345 */ |
|
346 void CT_MdrStep::testMiscellaneousL() |
|
347 { |
|
348 INFO_PRINTF1(_L("Testing Misc.")); |
|
349 const TUid KTestSourceId={458}; |
|
350 |
|
351 // set things up |
|
352 TRAPD(ret,iProcess = CApaProcess::NewL(iFs)); |
|
353 |
|
354 CApaDocument* doc=NULL; |
|
355 TApaApplicationFactory appFact(KUidTestApp); |
|
356 TRAP(ret,doc=iProcess->AddNewDocumentL(appFact)); |
|
357 |
|
358 TEST(ret==KErrNone); |
|
359 doc->EditL(NULL); // increments value to 1 |
|
360 CApaDoor* door=NULL; |
|
361 TRAP(ret, door=CApaDoor::NewL(iFs,*doc,TSize(1000,1000))); |
|
362 TEST(ret==KErrNone); |
|
363 |
|
364 // set the source |
|
365 door->SetSource(KTestSourceId); |
|
366 |
|
367 INFO_PRINTF1(_L("Testing CApaDoor's picture capability")); |
|
368 TPictureCapability pictCap = door->Capability(); |
|
369 TEST(ret==KErrNone); |
|
370 TEST(pictCap.iScalingType == TPictureCapability::ENotScaleable); |
|
371 TEST(pictCap.iIsCroppable == EFalse); |
|
372 |
|
373 INFO_PRINTF1(_L("Testing CApaDoor AppUidL")); |
|
374 TUid uid = door->AppUidL(); |
|
375 TEST(uid ==KUidTestApp); |
|
376 |
|
377 INFO_PRINTF1(_L("Testing SetFormatToTemporaryIconL")); |
|
378 TRAP(ret, door->SetFormatToTemporaryIconL(ETrue)); |
|
379 TEST(ret==KErrNone); |
|
380 |
|
381 INFO_PRINTF1(_L("Testing SetCropInTwips")); |
|
382 TMargins margins; |
|
383 TRAP(ret, door->SetCropInTwips(margins)); |
|
384 TEST(ret==KErrNone); |
|
385 |
|
386 INFO_PRINTF1(_L("Testing SetScaleFactor")); |
|
387 TRAP(ret, door->SetScaleFactor(500, 500)); |
|
388 TEST(ret==KErrNone); |
|
389 |
|
390 delete door; |
|
391 delete iProcess; |
|
392 } |
|
393 |
|
394 |
|
395 /** |
|
396 Auxiliary Fn for entire Test Step. |
|
397 |
|
398 This method creates and installs an active scheduler and puts the |
|
399 test code on the scheduler as a CIdle object. The method initiates all |
|
400 tests by calling the static method CT-MdrTestCallBackWrapper::CallBack(). |
|
401 |
|
402 */ |
|
403 void CT_MdrStep::DoTestsInScheldulerLoopL() |
|
404 { |
|
405 // create an active scheduler |
|
406 CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
407 CActiveScheduler::Install(scheduler); |
|
408 CleanupStack::PushL(scheduler); |
|
409 |
|
410 // put the test code onto the scheduler as an idle object |
|
411 CIdle* idle=CIdle::NewL(-20); |
|
412 CleanupStack::PushL(idle); |
|
413 |
|
414 CT_MdrTestCallBackWrapper* callBack = new(ELeave) CT_MdrTestCallBackWrapper(this); |
|
415 CleanupStack::PushL(callBack); |
|
416 |
|
417 idle->Start(TCallBack(CT_MdrTestCallBackWrapper::CallBack,callBack)); |
|
418 // start the test code |
|
419 CActiveScheduler::Start(); |
|
420 |
|
421 // all outstanding requests complete - kill the scheduler |
|
422 CleanupStack::PopAndDestroy(3); //scheduler, callBack, idle |
|
423 } |
|
424 |
|
425 |
|
426 |
|
427 CT_MdrTestCallBackWrapper::CT_MdrTestCallBackWrapper(CT_MdrStep* aTestStep) |
|
428 /** |
|
429 Constructor |
|
430 */ |
|
431 { |
|
432 iTestStep=aTestStep; |
|
433 } |
|
434 |
|
435 |
|
436 CT_MdrTestCallBackWrapper::~CT_MdrTestCallBackWrapper() |
|
437 /** |
|
438 Destructor |
|
439 */ |
|
440 { |
|
441 } |
|
442 |
|
443 TInt CT_MdrTestCallBackWrapper::CallBack(TAny* aPtr) |
|
444 /** |
|
445 This static method is the callback function of CIdle object. The method |
|
446 calls the non-static method DoStepTests() which initiates all the tests. |
|
447 */ |
|
448 { |
|
449 ((CT_MdrTestCallBackWrapper *)aPtr)->iTestStep->DoStepTests(); |
|
450 |
|
451 CActiveScheduler::Stop(); |
|
452 return EFalse; // don't call back again |
|
453 } |
|
454 |
|
455 CT_MdrStep::~CT_MdrStep() |
|
456 /** |
|
457 Destructor |
|
458 */ |
|
459 { |
|
460 } |
|
461 |
|
462 CT_MdrStep::CT_MdrStep() |
|
463 /** |
|
464 Constructor |
|
465 */ |
|
466 { |
|
467 // Call base class method to set up the human readable name for logging |
|
468 SetTestStepName(KT_MdrStep); |
|
469 } |
|
470 |
|
471 TVerdict CT_MdrStep::doTestStepPreambleL() |
|
472 /** |
|
473 @return - TVerdict code |
|
474 Override of base class virtual |
|
475 */ |
|
476 { |
|
477 SetTestStepResult(EPass); |
|
478 return TestStepResult(); |
|
479 } |
|
480 |
|
481 TVerdict CT_MdrStep::doTestStepPostambleL() |
|
482 /** |
|
483 @return - TVerdict code |
|
484 Override of base class virtual |
|
485 */ |
|
486 { |
|
487 return TestStepResult(); |
|
488 } |
|
489 |
|
490 |
|
491 TVerdict CT_MdrStep::doTestStepL() |
|
492 { |
|
493 INFO_PRINTF1(_L("Testing model doors...")); |
|
494 |
|
495 // set up an fbs |
|
496 FbsStartup(); |
|
497 |
|
498 // set up the directory structure |
|
499 iFs.Connect(); |
|
500 |
|
501 // run the testcode |
|
502 TRAPD(ret,DoTestsInScheldulerLoopL()) |
|
503 TEST(ret==KErrNone); |
|
504 |
|
505 iFs.Close(); |
|
506 //delete TheTrapCleanup; |
|
507 return TestStepResult(); |
|
508 } |
|
509 |
|
510 /** |
|
511 Auxiliary Fn for entire Test Step. |
|
512 |
|
513 The method initiates all tests to be performed. |
|
514 |
|
515 */ |
|
516 void CT_MdrStep::DoStepTests() |
|
517 { |
|
518 __UHEAP_MARK; |
|
519 TRAPD(r,testModelDoorL()); |
|
520 TEST(r==KErrNone); |
|
521 __UHEAP_MARKEND; |
|
522 |
|
523 __UHEAP_MARK; |
|
524 TInt ret=RFbsSession::Connect(); |
|
525 TEST(ret==KErrNone); |
|
526 TRAP(r,testConversionL()); |
|
527 |
|
528 TEST(r==KErrNone); |
|
529 /** The memory that is allocated in AllocScanLineBuffer() is shared |
|
530 between all bitmaps using the same session and is only released when |
|
531 RFbsSession::Disconnect(); is called. */ |
|
532 RFbsSession::Disconnect(); |
|
533 REComSession::FinalClose(); |
|
534 __UHEAP_MARKEND; |
|
535 |
|
536 __UHEAP_MARK; |
|
537 ret=RFbsSession::Connect(); |
|
538 TEST(ret==KErrNone); |
|
539 TRAP(r,testMiscellaneousL()); |
|
540 TEST(r==KErrNone); |
|
541 RFbsSession::Disconnect(); |
|
542 REComSession::FinalClose(); |
|
543 __UHEAP_MARKEND; |
|
544 } |