sapi_sysinfo/tsrc/testing/tsysgeneral/src/tasyncipandpredictivetext.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Tests input and predeictive text status
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "tsysgeneral.h"
       
    20 #include "sysinfoservice.h"
       
    21 #include "sysrequest.h"
       
    22 #include "tasyncipandpredictivetext.h"
       
    23 #include "watchtimer.h"
       
    24 #include "entitykeys.h"
       
    25 
       
    26 using namespace SysInfo;
       
    27 
       
    28 
       
    29 CTestIpAndPredTextNot* CTestIpAndPredTextNot::NewL(CStifLogger* aLog)
       
    30 	{
       
    31 	CTestIpAndPredTextNot* self = new(ELeave) CTestIpAndPredTextNot(aLog);
       
    32 	self->ConstructL();
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CTestIpAndPredTextNot::~CTestIpAndPredTextNot()
       
    37 	{
       
    38 	Cancel();
       
    39 	
       
    40 	if(iWaitScheduler->IsStarted())
       
    41 		iWaitScheduler->AsyncStop();
       
    42 	
       
    43 	if(iSysInfoService)
       
    44 		delete iSysInfoService;
       
    45 	
       
    46 	if(iWaitScheduler)
       
    47 		delete iWaitScheduler;
       
    48 	}
       
    49 
       
    50 void CTestIpAndPredTextNot::ConstructL()
       
    51 	{
       
    52 	CActiveScheduler::Add(this);
       
    53 	iSysInfoService = CSysInfoService::NewL();
       
    54 	iWaitScheduler = new(ELeave) CActiveSchedulerWait();
       
    55 	}
       
    56 
       
    57 CTestIpAndPredTextNot::CTestIpAndPredTextNot(CStifLogger* aLog) :
       
    58 CActive(EPriorityStandard),iResult(-1),iLog(aLog),iCount(0)
       
    59 	{
       
    60 	}
       
    61 
       
    62 void CTestIpAndPredTextNot::DoCancel()
       
    63 	{
       
    64 
       
    65 	}
       
    66 
       
    67 void CTestIpAndPredTextNot::RunL()
       
    68 	{
       
    69 	TestFunc();
       
    70 	}
       
    71 
       
    72 void CTestIpAndPredTextNot::Start()
       
    73 	{
       
    74 	
       
    75 	SetActive();
       
    76 	TRequestStatus* temp = &iStatus;
       
    77 	User::RequestComplete(temp, KErrNone);
       
    78 	iWaitScheduler->Start();	
       
    79 	}
       
    80 
       
    81 TInt CTestIpAndPredTextNot::Result()
       
    82 	{
       
    83 	return iResult;
       
    84 	}
       
    85 
       
    86 void CTestIpAndPredTextNot::TestSetup(TInt /*aLangIndex*/, TInt aPredTextStatus)
       
    87 	{
       
    88 	CStatus *predData = CStatus::NewL(aPredTextStatus) ;
       
    89     iSysInfoService->SetInfoL(KGeneral,KPridictiveText,predData) ;
       
    90     delete predData ;
       
    91 	}
       
    92 
       
    93 void CTestIpAndPredTextNot::TestFunc()
       
    94 	{
       
    95     TestSetup(0,0) ;	
       
    96 	TRAPD(err2,iSysInfoService->GetNotificationL(KGeneral,KPridictiveText,1001,this));
       
    97 	
       
    98 	if(KErrNone == err2)
       
    99 		{
       
   100 		TestSetup(58,1) ;	
       
   101        	}
       
   102 	else
       
   103 		{
       
   104 		iWaitScheduler->AsyncStop();
       
   105 		TestSetup(0,0) ;
       
   106 		}
       
   107 	return ;
       
   108 	}
       
   109 
       
   110 void CTestIpAndPredTextNot::HandleResponseL(const TDesC& /*aEntity*/,const TDesC& /*aKey*/, 
       
   111 									CSysData* aResponse, TInt32 aTransID, 
       
   112 									TSysRequest::TRequestType aType,
       
   113 									TInt aError)
       
   114 	{
       
   115 
       
   116 	if(aError == KErrNone) 
       
   117 		{
       
   118 		if(aTransID == 1000 && aType == 2)
       
   119 			{
       
   120 			TInt expIpLanguage = 58 ;
       
   121 			
       
   122 			const CStatus* data = (CStatus*)aResponse ;
       
   123 			TInt IpLang = data->Status() ;
       
   124 			
       
   125 			if(IpLang == expIpLanguage)
       
   126 				{
       
   127 				iResult = KErrNone ;
       
   128 				}
       
   129 			iLog->Log(_L8("IpLanguage : %d"),IpLang) ;
       
   130 			}
       
   131 		else if(aTransID == 1001 && aType == 2)
       
   132 			{
       
   133 			TInt expPredTextStatus = 1 ;
       
   134 			
       
   135 			const CStatus* data = (CStatus*)aResponse ;
       
   136 			TInt predTextStatus = data->Status() ;
       
   137 			
       
   138 			if(predTextStatus == expPredTextStatus)
       
   139 				{
       
   140 				iResult = KErrNone ;
       
   141 				}
       
   142 			iLog->Log(_L8("PredicitiveText statys : %d"),predTextStatus) ;
       
   143 			
       
   144 			}
       
   145 		iCount++ ;
       
   146 		delete aResponse ;
       
   147 		}
       
   148 
       
   149 	if(iCount == 1)
       
   150 		{
       
   151 		iWaitScheduler->AsyncStop();
       
   152 		TestSetup(0,0) ;	
       
   153 		}
       
   154 	
       
   155 	}
       
   156 
       
   157 
       
   158 int TestIpAndPredTextNot(CStifLogger* aLog)
       
   159 	{
       
   160 
       
   161 	__UHEAP_MARK ;
       
   162 	
       
   163 	CTestIpAndPredTextNot* test = CTestIpAndPredTextNot::NewL(aLog);
       
   164 	aLog->Log(_L8("InputLang and PredText Notification Test")) ;
       
   165 	test->Start();
       
   166 	TInt retval = test->Result();
       
   167 	delete test;
       
   168 	
       
   169 	__UHEAP_MARKEND ;
       
   170 	return retval;
       
   171 	}
       
   172