fep/frontendprocessor/test/src/TFepGen.CPP
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 // Copyright (c) 2006-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 // Tests for the Combination of key controls which 
       
    15 // is used to Turn on and Off the Fep Using the CFepGenericGlobalSettings API.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @test 
       
    22  @internalComponent - Internal Symbian test code
       
    23 */
       
    24 
       
    25 #include <e32std.h>
       
    26 #include <coeaui.h>
       
    27 #include <fepbase.h>
       
    28 #include <coemain.h>
       
    29 #include "TFepGen.h"
       
    30 
       
    31 // global variables
       
    32 TBool gIsOn = ETrue;
       
    33 TFepOnOrOffKeyData	gOnKey(0,0,0);
       
    34 TFepOnOrOffKeyData	gOffKey(0,0,0);	
       
    35 
       
    36 
       
    37 /*************************************************************
       
    38  **  
       
    39  **  CFepGenAppUi
       
    40  **  
       
    41  *************************************************************/
       
    42 
       
    43 CFepGenAppUi::CFepGenAppUi(CTmsTestStep* aStep) :
       
    44   	CTestCoeAppUi(aStep)
       
    45 	{
       
    46   	}
       
    47 
       
    48 CFepGenAppUi::~CFepGenAppUi()
       
    49     {
       
    50     }
       
    51 
       
    52 void CFepGenAppUi::ConstructL()
       
    53     {
       
    54     CTestCoeAppUi::ConstructL();
       
    55     TRect rect(TPoint(40,40),TSize(560,160));
       
    56     AutoTestManager().StartAutoTest();
       
    57     }
       
    58 
       
    59 void CFepGenAppUi::RunTestStepL(TInt aStepNum)
       
    60 	{
       
    61 	switch(aStepNum)
       
    62 		{	 
       
    63 		case 1:
       
    64 			{
       
    65 			// Need to save original settings
       
    66 			TRAPD(err, StoreOriginalSettingsL());
       
    67 			TEST(err == KErrNone);
       
    68 			}
       
    69 			break;
       
    70 		case 2:
       
    71 			{
       
    72 			SetTestStepID(_L("UIF-FEPBASE-0001"));
       
    73 			TRAPD(err, CreateFepGenericL());
       
    74 			TEST(err == KErrNone);
       
    75 			RecordTestResultL();
       
    76 			}
       
    77 			break;
       
    78 		case 3:
       
    79 			{
       
    80 			SetTestStepID(_L("UIF-FEPBASE-0002"));
       
    81 			TRAPD(err, FepStoreAndBroadCastL());
       
    82 			TEST(err == KErrNone);
       
    83 			RecordTestResultL();
       
    84 			CloseTMSGraphicsStep();
       
    85 			}
       
    86 			break;
       
    87 		case 4:
       
    88 			{
       
    89 			// Need to get original settings
       
    90 			TRAPD(err, RetrieveOriginalSettingsL());
       
    91 			TEST(err == KErrNone);
       
    92 			}
       
    93 			break;
       
    94 		case 5:
       
    95 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
    96 			break;
       
    97 		}
       
    98 	}
       
    99 	
       
   100 
       
   101 void CFepGenAppUi::StoreOriginalSettingsL()
       
   102 	{
       
   103 	CFepGenericGlobalSettings *fep=CFepGenericGlobalSettings::NewL();
       
   104 	CleanupStack::PushL(fep);
       
   105 
       
   106 	gIsOn = fep->IsOn();
       
   107 	gOnKey = fep->OnKeyData();
       
   108 	gOffKey = fep->OffKeyData();
       
   109 
       
   110 	CleanupStack::PopAndDestroy(fep);	
       
   111 	}
       
   112 	
       
   113 	
       
   114 void CFepGenAppUi::RetrieveOriginalSettingsL()
       
   115 	{
       
   116 	CFepGenericGlobalSettings *fep=CFepGenericGlobalSettings::NewL();
       
   117 	CleanupStack::PushL(fep);
       
   118 
       
   119 	fep->SetIsOn(gIsOn);
       
   120 	fep->SetOnKeyData(gOnKey);
       
   121 	fep->SetOffKeyData(gOffKey);
       
   122 
       
   123 	fep->StoreChangesAndBroadcastL();
       
   124 
       
   125 	CleanupStack::PopAndDestroy(fep);		
       
   126 	}
       
   127 	
       
   128 /**
       
   129    @SYMTestCaseID UIF-FEPBASE-0001
       
   130   
       
   131    @SYMDEF    DEF083097
       
   132   
       
   133    @SYMTestCaseDesc   This Test case is used to test the functionality of the 
       
   134    CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) 
       
   135    and CFepGenericGlobalSettings::NewL () .The functionality of Set API s of the class CFepGenericGlobalSettings is also tested which is used to overide system parameters for fep.
       
   136    @SYMTestPriority High 
       
   137   
       
   138    @SYMTestStatus Implemented
       
   139   
       
   140        
       
   141    @SYMTestActions   This methods creates Objects of CFepGenericGlobalSettings using CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) and 
       
   142    CFepGenericGlobalSettings::NewL () . Checks whether the attributes of the two objects are same.It then calls the Set methods of CFepGenericGlobalSettings namely SetIsOn();SetOnkeyData(), SetOffkeyData(),with one of the objects created by   
       
   143    CFepGenericGlobalSettings using CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) method and checks that the attributes of the object created using 
       
   144    CFepGenericGlobalSettings::NewL () are not the same .
       
   145 
       
   146        
       
   147    @SYMTestExpectedResults   The test case fails when the attributes of the objects created using CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) and 
       
   148    CFepGenericGlobalSettings::NewL () are not the same.
       
   149    When the SET methods are called using the CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) method's object.The attributes get changed.
       
   150    And the attributes are not equal to the object created using the CFepGenericGlobalSettings::NewL ().The test case fails if they are identical.
       
   151 
       
   152 */
       
   153 void CFepGenAppUi::CreateFepGenericL()
       
   154     {
       
   155     INFO_PRINTF1(_L("Executing Test case UIF_FEPBASE_001"));
       
   156 
       
   157    	const TFepOnOrOffKeyData genKeyData1(EKeySpace,EModifierFunc|EModifierLeftShift ,EModifierFunc);
       
   158 	TEST(genKeyData1.ModifierMask()==(EModifierFunc|EModifierLeftShift));
       
   159 	TEST(genKeyData1.ModifierValues()==EModifierFunc);
       
   160 
       
   161 	const TFepOnOrOffKeyData genKeyData2(EKeyDelete,EModifierFunc|EModifierRightShift,EModifierFunc) ;
       
   162 	TEST(genKeyData2.ModifierMask()==(EModifierFunc|EModifierRightShift));
       
   163 	TEST(genKeyData2.ModifierValues()==EModifierFunc);
       
   164 
       
   165 	CCoeEnv* env = CCoeEnv::Static();
       
   166 	CFepGenericGlobalSettings *fepWithParam=CFepGenericGlobalSettings::NewL(*env,genKeyData1,genKeyData2,ETrue);
       
   167 	CleanupStack::PushL(fepWithParam);
       
   168 
       
   169 	CFepGenericGlobalSettings *fepNoParam=CFepGenericGlobalSettings::NewL();
       
   170 	CleanupStack::PushL(fepNoParam);
       
   171 
       
   172 
       
   173 	const TFepOnOrOffKeyData keyOnFepPar=fepWithParam->OnKeyData();
       
   174 	const TFepOnOrOffKeyData keyOnFepNoPar=fepNoParam->OnKeyData();
       
   175 	const TFepOnOrOffKeyData keyOffFepPar=fepWithParam->OffKeyData();
       
   176 	const TFepOnOrOffKeyData keyOffFepNoPar=fepNoParam->OffKeyData();
       
   177 	
       
   178 	INFO_PRINTF2(_L("val of keyOnFepPar.ModifierMask() '%d' "),keyOnFepPar.ModifierMask());
       
   179 	INFO_PRINTF2(_L("val of keyOnFepNoPar.ModifierMask() '%d' "),keyOnFepNoPar.ModifierMask());
       
   180 	INFO_PRINTF2(_L("val of keyOnFepPar.ModifierValues() '%d' "),keyOnFepPar.ModifierValues());
       
   181 	INFO_PRINTF2(_L("val of keyOnFepNoPar.ModifierValues() '%d' "),keyOnFepNoPar.ModifierValues());
       
   182 	INFO_PRINTF2(_L("val of keyOnFepPar.CharacterCodeForFoldedMatch() '%d' "),keyOnFepPar.CharacterCodeForFoldedMatch());
       
   183 	INFO_PRINTF2(_L("val of keyOnFepNoPar.CharacterCodeForFoldedMatch() '%d' "),keyOnFepNoPar.CharacterCodeForFoldedMatch());
       
   184 
       
   185 	
       
   186 	INFO_PRINTF2(_L("val of keyOffFepPar.ModifierMask() '%d' "),keyOffFepPar.ModifierMask());
       
   187 	INFO_PRINTF2(_L("val of keyOffFepNoPar.ModifierMask() '%d' "),keyOffFepNoPar.ModifierMask());
       
   188 	INFO_PRINTF2(_L("val of keyOffFepPar.ModifierValues() '%d' "),keyOffFepPar.ModifierValues());
       
   189 	INFO_PRINTF2(_L("val of keyOffFepNoPar.ModifierValues() '%d' "),keyOffFepNoPar.ModifierValues());
       
   190 	INFO_PRINTF2(_L("val of keyOffFepPar.CharacterCodeForFoldedMatch() '%d' "),keyOffFepPar.CharacterCodeForFoldedMatch());
       
   191 	INFO_PRINTF2(_L("val of keyOffFepNoPar.CharacterCodeForFoldedMatch() '%d' "),keyOffFepNoPar.CharacterCodeForFoldedMatch());
       
   192 	
       
   193 	TEST(fepWithParam->IsOn()==fepNoParam->IsOn());
       
   194 	
       
   195 	TEST(keyOnFepPar==keyOnFepNoPar);
       
   196 	TEST(genKeyData1!=keyOnFepPar);
       
   197 	TEST(genKeyData1!=keyOnFepNoPar);
       
   198 	
       
   199 	TEST(keyOffFepPar==keyOffFepNoPar);
       
   200 	TEST(genKeyData2!=keyOffFepPar);
       
   201 	TEST(genKeyData2!=keyOffFepNoPar);
       
   202 
       
   203 	if(fepWithParam->IsOn())
       
   204 	{
       
   205 	INFO_PRINTF2(_L("fepWithParam->IsOn() is ETRUE '%d' "),fepWithParam->IsOn());
       
   206 	fepWithParam->SetIsOn(EFalse);
       
   207 	TEST(!(fepWithParam->IsOn()));
       
   208 	INFO_PRINTF2(_L("fepWithParam->IsOn() Was ETRUE and Now It is changed to '%d' "),fepWithParam->IsOn());
       
   209 	}
       
   210 	else
       
   211 	{
       
   212 	INFO_PRINTF2(_L("fepWithParam->IsOn() is EFalse '%d' "),fepWithParam->IsOn());
       
   213 	fepWithParam->SetIsOn(ETrue);
       
   214 	TEST(fepWithParam->IsOn());
       
   215 	INFO_PRINTF2(_L("fepWithParam->IsOn() was EFalse and now changed to '%d' "),fepWithParam->IsOn());
       
   216 	}
       
   217 
       
   218 	fepWithParam->SetOnKeyData(genKeyData1);
       
   219 	fepWithParam->SetOffKeyData(genKeyData2);
       
   220 	
       
   221 	
       
   222 	TEST(genKeyData1==fepWithParam->OnKeyData());
       
   223 	TEST(genKeyData2==fepWithParam->OffKeyData());
       
   224 	TEST(fepNoParam->IsOn()!=fepWithParam->IsOn());
       
   225 	TEST(genKeyData1!=fepNoParam->OnKeyData());
       
   226 	TEST(genKeyData2!=fepNoParam->OffKeyData());
       
   227 	
       
   228 	// After the test, we should restore original values...
       
   229 	fepWithParam->SetOnKeyData(genKeyData1);
       
   230 	fepWithParam->SetOffKeyData(genKeyData2);
       
   231 	
       
   232 	
       
   233 	CleanupStack::PopAndDestroy(2,fepWithParam);
       
   234 	INFO_PRINTF1(_L("End of  Test case 1"));
       
   235     }
       
   236     
       
   237 /**
       
   238    @SYMTestCaseID UIF-FEPBASE-0002
       
   239   
       
   240    @SYMDEF    DEF083097
       
   241   
       
   242    @SYMTestCaseDesc		This test case tests the functionality of StoreAndBroadcastL() method of CFepGenericFlobalSettings().
       
   243 
       
   244    @SYMTestPriority High 
       
   245   
       
   246    @SYMTestStatus Implemented  
       
   247        
       
   248    @SYMTestActions 	This methods creates Objects of CFepGenericGlobalSettings using CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) and
       
   249    CFepGenericGlobalSettings::NewL () . It then calls the Set methods of CFepGenericGlobalSettings namely SetIsOn();SetOnkeyData(), SetOffkeyData(),with one of the objects created by   
       
   250    CFepGenericGlobalSettings using CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) method and ,Then it calls the StoreAndBroadcastL() and checks that the attributes of the object created using 
       
   251    CFepGenericGlobalSettings::NewL () are the same .
       
   252    	 
       
   253    @SYMTestExpectedResults 	When the SET methods are called using the CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment,const TFepOnOrOffKeyData& aDefaultOnKeyData,const TFepOnOrOffKeyData& aDefaultOffKeyData,TBool aDefaultIsOn) method's object.The attributes get changed.
       
   254    StoreAndBroadCastL(), Stores the local changes to the systemSettings and distributes the changes to all the instances of FEP.So when a new object is created Using the NewL() method , the attributes should be same as that of the previuosly created object 's attributes.
       
   255 */
       
   256     
       
   257 void CFepGenAppUi::FepStoreAndBroadCastL()
       
   258     {
       
   259     INFO_PRINTF1(_L("Executing Test case UIF_FEPBASE_0002"));
       
   260 	const  TFepOnOrOffKeyData onKeyData1(EKeySpace,EModifierFunc|EModifierLeftShift ,EModifierFunc);
       
   261 	TEST(onKeyData1.ModifierMask()==(EModifierFunc|EModifierLeftShift));
       
   262 	TEST(onKeyData1.ModifierValues()==EModifierFunc);
       
   263 	const TFepOnOrOffKeyData offKeyData1(EKeyDelete,EModifierFunc|EModifierRightShift,EModifierFunc) ;
       
   264 	TEST(offKeyData1.ModifierMask()==(EModifierFunc|EModifierRightShift));
       
   265 	TEST(offKeyData1.ModifierValues()==EModifierFunc);
       
   266 	
       
   267 	const  TFepOnOrOffKeyData testOnKeyData1(EKeyEnter,EModifierFunc|EModifierLeftShift ,EModifierFunc);
       
   268 	const  TFepOnOrOffKeyData testOffKeyData1(EKeyTab,EModifierFunc|EModifierLeftShift ,EModifierFunc);
       
   269 
       
   270 	CCoeEnv* env = CCoeEnv::Static();
       
   271 	CFepGenericGlobalSettings *fepGen1=	CFepGenericGlobalSettings::NewL(*env,onKeyData1,offKeyData1,ETrue);
       
   272 	CleanupStack::PushL(fepGen1);
       
   273 	
       
   274 	fepGen1->SetOffKeyData(testOffKeyData1);
       
   275 	fepGen1->SetOnKeyData(testOnKeyData1);
       
   276 	fepGen1->SetIsOn(EFalse);
       
   277 	fepGen1->StoreChangesAndBroadcastL();
       
   278 	CleanupStack::PopAndDestroy(fepGen1);
       
   279 	
       
   280 	CFepGenericGlobalSettings *fepGen2=CFepGenericGlobalSettings::NewL();
       
   281 	CleanupStack::PushL(fepGen2);
       
   282 	TFepOnOrOffKeyData testOnKeyData2=fepGen2->OnKeyData();
       
   283 	TFepOnOrOffKeyData testOffKeyData2=fepGen2->OffKeyData();
       
   284 	
       
   285 	TEST(!(fepGen2->IsOn()));
       
   286 	TEST(testOnKeyData2!=onKeyData1);
       
   287 	TEST(testOnKeyData2==testOnKeyData1);
       
   288 	TEST(testOffKeyData2!=offKeyData1);
       
   289 	TEST(testOffKeyData2==testOffKeyData1);
       
   290 	
       
   291 	CleanupStack::PopAndDestroy(fepGen2);
       
   292 	INFO_PRINTF1(_L("End of Test case 2")); 
       
   293     }
       
   294 
       
   295 
       
   296 /*************************************************************
       
   297  **  
       
   298  **  CTFepGenStep
       
   299  **  
       
   300  *************************************************************/
       
   301 
       
   302 /**
       
   303   Completes the construction of the Control Environment(CCoeEnv object).\n
       
   304   Instantiates the CFepGenAppUi class which serves as a AppUi class.\n
       
   305   Sets the CFepGenAppUi object as the application's user interface object.\n
       
   306   Invokes the second phase constructor of the application's UI.\n
       
   307 */
       
   308 void CTFepGenStep::ConstructFepGenAppL(CCoeEnv* aCoe)
       
   309 	{
       
   310 	aCoe->ConstructL();
       
   311 	CFepGenAppUi* appUi=new(ELeave) CFepGenAppUi(this);
       
   312 	aCoe->SetAppUi(appUi);
       
   313 	appUi->ConstructL();
       
   314 	}
       
   315 
       
   316 CTFepGenStep::CTFepGenStep()
       
   317 	{
       
   318 	SetTestStepName(KTFepGen);
       
   319 	}	
       
   320 
       
   321 CTFepGenStep::~CTFepGenStep()
       
   322 	{
       
   323 	}
       
   324 	
       
   325 TVerdict CTFepGenStep::doTestStepL()
       
   326 	{
       
   327     INFO_PRINTF1(_L("APPFWK_FEPBASE:FepGeneric Started"));
       
   328     
       
   329     __UHEAP_MARK;
       
   330     
       
   331 	CCoeEnv* coe=new(ELeave) CCoeEnv;
       
   332 	TEST(coe !=NULL);
       
   333 	if(coe==NULL)
       
   334 		{
       
   335 		INFO_PRINTF1(_L("Failed to create CCoeEnv "));
       
   336  		return TestStepResult();
       
   337 		}
       
   338 		
       
   339     TRAPD(err,ConstructFepGenAppL(coe));
       
   340     if (!err)
       
   341         coe->ExecuteD();
       
   342 	else
       
   343 		{
       
   344 		INFO_PRINTF2(_L("Failed to Construct CCoeEnv ,error %d"),err);
       
   345 		SetTestStepResult(EFail);
       
   346  		coe->PrepareToExit();
       
   347 		coe->DestroyEnvironment();
       
   348 		delete coe;
       
   349 		return TestStepResult();
       
   350 		}
       
   351 	
       
   352 	__UHEAP_MARKEND;
       
   353 
       
   354 	INFO_PRINTF1(_L("Test Finished"));
       
   355 
       
   356 	return TestStepResult();
       
   357 	}
       
   358 
       
   359 	
       
   360     
       
   361   
       
   362  
       
   363 
       
   364 
       
   365     
       
   366 
       
   367 
       
   368 
       
   369 
       
   370