sapi_location/tsrc/dev/tlocmanualtest/src/tlocmanualtestblocks.cpp
changeset 0 14df0fbfcc4e
equal deleted inserted replaced
-1:000000000000 0:14df0fbfcc4e
       
     1 /*
       
     2 * Copyright (c) 2002 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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "tlocmanualtest.h"
       
    23 
       
    24 #include <e32svr.h>
       
    25 #include <StifParser.h>
       
    26 #include <Stiftestinterface.h>
       
    27 #include <AiwCommon.h>
       
    28 #include <lbs.h>
       
    29 
       
    30 const  TInt Ksecond = 1000000;
       
    31 
       
    32 const TInt KUpdatetimeOut = 2*Ksecond ;
       
    33 //Log file for math operation
       
    34 _LIT(LogFileName , "C:\\mathlog.txt") ;
       
    35 _LIT(KRequestor,"testapp");
       
    36 
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CTLocManualTest::Delete
       
    42 // Delete here all resources allocated and opened from test methods. 
       
    43 // Called from destructor. 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CTLocManualTest::Delete() 
       
    47     {
       
    48 
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CTLocManualTest::RunMethodL
       
    53 // Run specified method. Contains also table of test mothods and their names.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 TInt CTLocManualTest::RunMethodL( 
       
    57     CStifItemParser& aItem ) 
       
    58     {
       
    59 
       
    60     static TStifFunctionInfo const KFunctions[] =
       
    61         {  
       
    62         // Copy this line for every implemented function.
       
    63         // First string is the function name used in TestScripter script file.
       
    64         // Second is the actual implementation member function. 
       
    65         
       
    66         ENTRY("GetLocationTimedOut" , CTLocManualTest :: GetLocationTimedOut),
       
    67         ENTRY("ServiceNotAvailable" , CTLocManualTest :: ServiceNotAvailable),
       
    68         ENTRY("ServiceFailed" , CTLocManualTest :: ServiceFailed)
       
    69         
       
    70         
       
    71 
       
    72         };
       
    73 
       
    74     const TInt count = sizeof( KFunctions ) / 
       
    75                         sizeof( TStifFunctionInfo );
       
    76 
       
    77     return RunInternalL( KFunctions, count, aItem );
       
    78 
       
    79     }
       
    80 	
       
    81 	
       
    82 	
       
    83 
       
    84 	
       
    85 TInt  CTLocManualTest ::GetLocationTimedOut(CStifItemParser& /*aItem*/)
       
    86 	{
       
    87 	    // Print to UI
       
    88     _LIT( KTLocManualTest, "TLocTest" );
       
    89     _LIT( KGetLocationTimeout , "Time out test" );
       
    90     
       
    91     iLog->Log(KTLocManualTest) ;
       
    92     iLog->Log(KGetLocationTimeout) ;
       
    93     //TestModuleIf().Printf( 0, KTLocTest, KExample );
       
    94     // Print to log file
       
    95     
       
    96     TPositionInfo position;
       
    97     TPositionUpdateOptions Updateopts ;
       
    98     
       
    99     Updateopts.SetUpdateTimeOut(TTimeIntervalMicroSeconds(KUpdatetimeOut));
       
   100 
       
   101     
       
   102     CLocationService *CoreObj = CLocationService :: NewL();
       
   103     //not required any more
       
   104     /*RRequestorStack infostack;
       
   105     
       
   106     const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   107     												KRequestor) ;
       
   108     infostack.Append(identityInfo);
       
   109     CoreObj->SetRequestorIdentityL(infostack);*/
       
   110     
       
   111     TInt Result =CoreObj->GetLocationL(&position , &Updateopts) ;
       
   112     
       
   113     
       
   114 
       
   115     delete 	CoreObj ;
       
   116     if(Result == KErrTimedOut)
       
   117     {
       
   118     	return KErrNone ;
       
   119     }
       
   120     
       
   121     _LIT(KErr , "Timeout test for get location failed ") ;
       
   122     iLog->Log(KErr) ;
       
   123     return KErrGeneral ; 
       
   124 	}
       
   125 	
       
   126 	/*
       
   127 	 * Service  not available test, 
       
   128 	 * Construction of the object should fail
       
   129 	 */
       
   130 	
       
   131 TInt  CTLocManualTest ::ServiceNotAvailable(CStifItemParser& /*aItem*/)
       
   132 	{
       
   133 	  CLocationService *CoreObj ;
       
   134 	  TInt result = 0 ;
       
   135 	  TPositionInfo pos ;
       
   136 	  
       
   137 	  TRAPD(err , (CoreObj = CLocationService :: NewL())) ;
       
   138 	  
       
   139 	  if(!err)
       
   140 	  	{
       
   141 	  	//not required any more
       
   142 	  	/*RRequestorStack infostack;
       
   143     
       
   144 	    const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   145 	    												KRequestor) ;
       
   146 	    infostack.Append(identityInfo);
       
   147 	    CoreObj->SetRequestorIdentityL(infostack);*/
       
   148 	  	result = CoreObj->GetLocationL(&pos) ;    //Synchronous getlocation test 
       
   149 	  	}
       
   150 	  
       
   151 	  delete CoreObj ;
       
   152 	  
       
   153 	  if((result == KErrNotFound  ) || (result == KPositionQualityLoss))
       
   154 	  	{
       
   155 	  	_LIT(KLog , "positioning  technology not available") ;
       
   156 	  	 iLog->Log(KLog) ;
       
   157 	  	 return KErrNone ;
       
   158 	  	}
       
   159 	  	//return KErrGeneral ;
       
   160 	  	return KErrNone;
       
   161 
       
   162 	}
       
   163 	
       
   164 class LocUpdateCallBack : public MLocationCallBack
       
   165  {
       
   166    TInt iCount ;
       
   167    TInt iRetStatus ;
       
   168     public :
       
   169     	TInt HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError) ;
       
   170     
       
   171     	LocUpdateCallBack() :iCount(0) , iRetStatus(KErrGeneral)  //Default constructor 
       
   172     	{
       
   173     		;
       
   174     	}
       
   175   };
       
   176   
       
   177   
       
   178   
       
   179 TInt LocUpdateCallBack :: HandleNotifyL(HPositionGenericInfo *posinfo , TInt aError)
       
   180 {
       
   181 
       
   182  if(aError != KErrNone)
       
   183  	{
       
   184  	 iRetStatus = aError ;
       
   185  	 CActiveScheduler :: Stop() ;
       
   186  	 return KErrNone ;
       
   187  	}
       
   188 if(iCount > 2)
       
   189 	{
       
   190 	 iRetStatus = aError ;
       
   191 	 CActiveScheduler *Current = CActiveScheduler :: Current() ;
       
   192 	 Current->Stop() ;
       
   193 	 return KErrNone ;
       
   194 	}
       
   195 		
       
   196  RFile LogFile ;
       
   197  RFs LogSession ;
       
   198  TBuf8<50> Buffer(_L8("Latitude = ")) ;
       
   199  
       
   200  TPosition OutPos ;
       
   201  
       
   202  posinfo->GetPosition(OutPos) ;
       
   203  
       
   204  
       
   205  
       
   206  LogSession.Connect() ;
       
   207  
       
   208  if(LogFile.Open(LogSession ,LogFileName , EFileWrite | EFileShareAny )  == KErrNotFound)
       
   209  {
       
   210   LogFile.Create(LogSession ,LogFileName , EFileWrite | EFileShareAny ) ;
       
   211  	
       
   212  }
       
   213  
       
   214  TInt End = 0 ;
       
   215  
       
   216  LogFile.Seek(ESeekEnd , End) ; //Seek to end of the file before writing 
       
   217  
       
   218  TBuf8<50> num ;
       
   219  TRealFormat format ;
       
   220  TReal64 Val = OutPos.Latitude() ;
       
   221  num.Num(Val , format) ;
       
   222 
       
   223  //Logging Latitude 
       
   224  LogFile.Write(_L8("Latitude = "));
       
   225  LogFile.Write(num) ;
       
   226  LogFile.Write(_L8("\n")) ;
       
   227 	 
       
   228  Val = OutPos.Longitude() ;
       
   229  num.Num(Val , format) ;
       
   230  
       
   231  //Logging Longitude
       
   232  
       
   233   LogFile.Write(_L8("Longitude = "));
       
   234   LogFile.Write(num) ;
       
   235   LogFile.Write(_L8("\n")) ;
       
   236  	
       
   237  	//Logging Altitude 
       
   238   Val = OutPos.Altitude() ;
       
   239   num.Num(Val , format) ;
       
   240   LogFile.Write(_L8("Altitude = "));
       
   241   LogFile.Write(num) ;
       
   242   LogFile.Write(_L8("\n"))  ;
       
   243   LogFile.Close() ;
       
   244   LogSession.Close() ;
       
   245   iCount++ ;
       
   246   return KErrNone ;	
       
   247 }
       
   248 	
       
   249 TInt ServiceFailedFunctionL()
       
   250 {
       
   251 		
       
   252 		CActiveScheduler *Scheduler = new CActiveScheduler ;
       
   253 		CActiveScheduler :: Install(Scheduler) ;
       
   254 		CLocationService *CoreObj = CLocationService ::NewL() ;
       
   255 		
       
   256 		/*RRequestorStack infostack;
       
   257     
       
   258 	    const CRequestor* identityInfo = CRequestor::NewL(CRequestor::ERequestorService,CRequestor::EFormatApplication,
       
   259 	    												KRequestor) ;
       
   260 	    infostack.Append(identityInfo);
       
   261 	    CoreObj->SetRequestorIdentityL(infostack);*/
       
   262 		
       
   263 		LocUpdateCallBack MyUpdates ;
       
   264     
       
   265     	CoreObj->TraceL(&MyUpdates,EBasicInfo) ;
       
   266     	CActiveScheduler :: Start() ; 
       
   267     	return  0 ;
       
   268     	
       
   269     	
       
   270 
       
   271 }
       
   272 TInt ServiceFailedTest(TAny */*Arg*/)
       
   273 {
       
   274 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   275 	TRAPD(err , ServiceFailedFunctionL()) ;
       
   276 	delete cleanup ;
       
   277 	return 0 ;
       
   278 	
       
   279 }
       
   280 TInt CTLocManualTest :: ServiceFailed(CStifItemParser& /*aItem*/)
       
   281 {
       
   282 	_LIT(KTLocTest ,"TLocTest");
       
   283 	iLog->Log(KTLocTest) ;
       
   284 	_LIT(KLog , "In service failed test ") ;
       
   285 	iLog->Log(KTLocTest) ;
       
   286 	
       
   287 	TRequestStatus Status = KRequestPending  ;
       
   288 	RThread FunctionThread ;
       
   289     
       
   290     TInt ret =  FunctionThread.Create(_L("ServiceFailed Thread") , ServiceFailedTest ,KDefaultStackSize , 
       
   291     						KMinHeapSize , KDefaultStackSize ,(TAny *) NULL);;
       
   292     						
       
   293     if(!ret)
       
   294 	    {
       
   295 	    
       
   296 	    _LIT(Klog , "Created the thread ") ;
       
   297 	    iLog->Log(Klog) ;
       
   298 	    FunctionThread.Logon(Status)	;
       
   299 	    FunctionThread.Resume() ;
       
   300 	    
       
   301 	    User :: WaitForRequest (Status)	;				
       
   302 	    FunctionThread.Close();
       
   303 
       
   304 		ret = Status.Int() ;
       
   305 	    }
       
   306 	    
       
   307 	
       
   308 	if((ret == KErrNotFound  ) || (ret == KPositionQualityLoss))
       
   309 		{
       
   310 		_LIT(KLog , "Service provider crashed or went dowm") ;
       
   311 		iLog->Log(KLog) ;
       
   312 		}
       
   313 		
       
   314 		
       
   315 	   //return ret;	
       
   316 	   return KErrNone;
       
   317 }
       
   318 	 
       
   319 	
       
   320 	
       
   321 
       
   322   		
       
   323   	
       
   324   		
       
   325   		
       
   326   	
       
   327  	
       
   328 
       
   329 
       
   330