sysstatemgmt/systemstatereferenceplugins/test/tintcustcmd/src/tcustcmd_step_simsecuritypincheck.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 #include <ssm/startupdomainpskeys.h>
    18 #include <ssm/startupdomainpskeys.h>
    19 #include <w32std.h>
    19 #include <w32std.h>
    20 #include <s32file.h>
    20 #include <s32file.h>
    21 
    21 
    22 const TInt KNumOfTestCases = 8;
    22 const TInt KNumOfTestCases = 8;
       
    23 const TUint32 KMiscPluginPropertyKey = 0x2000E658;
    23 
    24 
    24 static TInt CustomCmdTestSecurityCheckCallBackL(TAny* aCustomCmdTestSecurityPinCheck)
    25 static TInt CustomCmdTestSecurityCheckCallBackL(TAny* aCustomCmdTestSecurityPinCheck)
    25 	{
    26 	{
    26 	CCustomCmdTestSecurityPinCheck* test = reinterpret_cast<CCustomCmdTestSecurityPinCheck*>(aCustomCmdTestSecurityPinCheck);
    27 	CCustomCmdTestSecurityPinCheck* test = reinterpret_cast<CCustomCmdTestSecurityPinCheck*>(aCustomCmdTestSecurityPinCheck);
    27 	CleanupStack::PushL(test);
    28 	CleanupStack::PushL(test);
    33 /*
    34 /*
    34 Call back function to enter a PIN 
    35 Call back function to enter a PIN 
    35 */
    36 */
    36 void CCustomCmdTestSecurityPinCheck::CallBackForEnterPin()
    37 void CCustomCmdTestSecurityPinCheck::CallBackForEnterPin()
    37 	{
    38 	{
       
    39 	const TInt okButtonPos1 = 60; //the position of ok button
       
    40 	const TInt okButtonPos2 = 600; //the position of ok button
    38 	iAsyncStopScheduler->CallBack();
    41 	iAsyncStopScheduler->CallBack();
    39 	
    42 	
    40 	RWsSession wsSession;
    43 	RWsSession wsSession;
    41 	wsSession.Connect();
    44 	wsSession.Connect();
    42 
    45 
    50 		eventUp.Set(TRawEvent::EKeyUp, EStdKeyComma);
    53 		eventUp.Set(TRawEvent::EKeyUp, EStdKeyComma);
    51 		UserSvr::AddEvent(eventUp);
    54 		UserSvr::AddEvent(eventUp);
    52 		User::After(100000);
    55 		User::After(100000);
    53 		}
    56 		}
    54 	
    57 	
    55 	eventDown.Set(TRawEvent::EKeyDown, EStdKeyEnter);
    58 	eventDown.Set(TRawEvent::EButton1Down, okButtonPos1,okButtonPos2);
    56 	UserSvr::AddEvent(eventDown);
    59 	UserSvr::AddEvent(eventDown);
    57 	eventUp.Set(TRawEvent::EKeyUp, EStdKeyEnter);
    60 	eventUp.Set(TRawEvent::EButton1Up, okButtonPos1,okButtonPos2);
    58 	UserSvr::AddEvent(eventUp);
    61 	UserSvr::AddEvent(eventUp);
    59 	User::After(100000);
    62 	User::After(100000);
    60 		
    63 		
    61 	wsSession.Flush();
    64 	wsSession.Flush();
    62 	wsSession.Close();
    65 	wsSession.Close();
    89 
    92 
    90 	iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait;
    93 	iActiveSchedulerWait = new(ELeave) CActiveSchedulerWait;
    91 
    94 
    92 	iAsyncStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
    95 	iAsyncStopScheduler = new(ELeave) CAsyncCallBack(CActive::EPriorityIdle);
    93 	
    96 	
       
    97 	TInt err = RProperty::Define(KPropertyCategory, KMiscPluginPropertyKey, RProperty::EInt);
       
    98 	TEST ((KErrNone == err) || (KErrAlreadyExists == err));
       
    99 	err = RProperty::Set(KPropertyCategory, KMiscPluginPropertyKey, 1);
       
   100 	TEST (KErrNone == err);
       
   101 	
    94 	//Start the test exe which defines startup related property keys
   102 	//Start the test exe which defines startup related property keys
    95 	RProcess processHandle;
   103 	RProcess processHandle;
    96 	CleanupClosePushL(processHandle);
   104 	CleanupClosePushL(processHandle);
    97 	processHandle.Create(KExeToDefineStartUpPS, KNullDesC);
   105 	processHandle.Create(KExeToDefineStartUpPS, KNullDesC);
    98 	processHandle.Resume();
   106 	processHandle.Resume();
   106 	TEST(KErrNone == retVal);
   114 	TEST(KErrNone == retVal);
   107 	// leave if the process has not started properly
   115 	// leave if the process has not started properly
   108 	User::LeaveIfError(retVal);
   116 	User::LeaveIfError(retVal);
   109 	CleanupStack::PopAndDestroy();
   117 	CleanupStack::PopAndDestroy();
   110 	
   118 	
       
   119 	//Start the test exe which defines startup state related property keys
   111 	RProcess processHandle1;
   120 	RProcess processHandle1;
   112 	TInt err1 = processHandle1.Create(KExeToDefineStartUpStatePS, KNullDesC);
   121 	CleanupClosePushL(processHandle1);
   113 	INFO_PRINTF2(_L("KExeToDefineStartUpStatePS ret is %d"), err1);
   122 	err = processHandle1.Create(KExeToDefineStartUpStatePS, KNullDesC);
       
   123 	INFO_PRINTF2(_L("KExeToDefineStartUpStatePS ret is %d"), err);
       
   124 	User::LeaveIfError(err);
   114 	processHandle1.Resume();
   125 	processHandle1.Resume();
   115 	processHandle1.Close();
   126 	
       
   127 	// wait for the newly created process to rendezvous
       
   128 	processHandle1.Rendezvous(status);
       
   129 	User::WaitForRequest(status);
       
   130 	retVal = status.Int();
       
   131 	//leave if the process has not started properly
       
   132 	INFO_PRINTF2(_L("KExeToDefineStartUpStatePS rendezvous returns %d"), retVal);
       
   133     User::LeaveIfError(retVal);
       
   134     CleanupStack::PopAndDestroy();
   116 
   135 
   117 	//there are 8 different scenarios to test the custom command. Check the test spec for the scenarios.
   136 	//there are 8 different scenarios to test the custom command. Check the test spec for the scenarios.
   118  	//CMiscAdaptationRef::SecurityStateChange() has been changed to simulate the scenarios.
   137  	//CMiscAdaptationRef::SecurityStateChange() has been changed to simulate the scenarios.
   119 	//CMiscAdaptationRef::SecurityStateChange() uses KTestCmdSecurityCheckTestFile to get the scenario number
   138 	//CMiscAdaptationRef::SecurityStateChange() uses KTestCmdSecurityCheckTestFile to get the scenario number
   120 	//connect to file server
   139 	//connect to file server
       
   140 
   121     User::LeaveIfError(iFs.Connect());
   141     User::LeaveIfError(iFs.Connect());
   122 	TInt err = iFs.MkDirAll(KDirNameOfTestCasesNumFile);
   142 	err = iFs.MkDirAll(KDirNameOfTestCasesNumFile);
   123 	if (KErrAlreadyExists != err && KErrNone != err)
   143 	if (KErrAlreadyExists != err && KErrNone != err)
   124 		{
   144 		{
   125 		User::Leave(err);
   145 		User::Leave(err);
   126 		}
   146 		}
   127 	err = iFile.Replace(iFs, KTestCmdSecurityCheckTestFile, EFileWrite | EFileStream);
   147 	err = iFile.Replace(iFs, KTestCmdSecurityCheckTestFile, EFileWrite | EFileStream);
       
   148 	TEST(KErrNone == err);
   128 	iFile.Close();
   149 	iFile.Close();
   129 	
   150 	
   130 	//For stopping the key simulation when execution behaviour is deferredwaitforsignal and fireandforget
   151 	//For stopping the key simulation when execution behaviour is deferredwaitforsignal and fireandforget
   131 	iStopSimulatekey = CStopSimulatekey::NewL(this);
   152 	iStopSimulatekey = CStopSimulatekey::NewL(this);
   132  	
   153  	
   133  	//Connect to SsmStateManager
   154  	//Connect to SsmStateManager
   134  	const TInt connect = iClient.Connect();
   155  	const TInt connect = iClient.Connect();
   135 	TEST(KErrNone == connect);
   156 	TEST(KErrNone == connect);
   136 	
   157 	
   137 	//RProperty property;
   158 	//RProperty property;
   138 	iProperty.Define(KCustomcmdServerSID, iSwp.Key(), RProperty::EInt);
   159 	err = iProperty.Define(KCustomcmdServerSID, iSwp.Key(), RProperty::EInt);
       
   160 	TEST ((KErrNone == err) || (KErrAlreadyExists == err));
   139 	
   161 	
   140 	// Register mapping between keys and swp policy DLL (done once per ssmserver)
   162 	// Register mapping between keys and swp policy DLL (done once per ssmserver)
   141 	INFO_PRINTF1(_L("Registering swp..."));
   163 	INFO_PRINTF1(_L("Registering swp..."));
   142 	iClient.RegisterSwpMapping(KTestSwp, KTestSwpPolicyCustomCmd);
   164 	iClient.RegisterSwpMapping(KTestSwp, KTestSwpPolicyCustomCmd);
   143 	
   165 	
   453 	}
   475 	}
   454 
   476 
   455 TVerdict CCustomCmdTestSecurityPinCheck::doTestStepPostambleL()
   477 TVerdict CCustomCmdTestSecurityPinCheck::doTestStepPostambleL()
   456 	{
   478 	{
   457 	TEST(KErrNone == iProperty.Delete(KCustomcmdServerSID, iSwp.Key()));
   479 	TEST(KErrNone == iProperty.Delete(KCustomcmdServerSID, iSwp.Key()));
       
   480 	TInt err = RProperty::Delete(KPropertyCategory, KMiscPluginPropertyKey);
       
   481 	TEST (KErrNone == err);
   458 	iProperty.Close();
   482 	iProperty.Close();
   459 	iClient.Close();
   483 	iClient.Close();
   460 	//delete the file		
   484 	//delete the file		
   461     iFs.Delete(KTestCmdSecurityCheckTestFile);
   485     iFs.Delete(KTestCmdSecurityCheckTestFile);
   462 	iFs.Close();
   486 	iFs.Close();