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