loc_plat/location_centre_api/tsrc/src/testlcservice.cpp
branchRCL_3
changeset 16 4721bd00d3da
parent 14 3a25f69541ff
child 21 e15b7f06eba6
equal deleted inserted replaced
14:3a25f69541ff 16:4721bd00d3da
     1 /*
       
     2 * Copyright (c) 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 "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:  Test Class which has the list of test cases for CLcService
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Includes
       
    20 #include <lcservice.h>
       
    21 
       
    22 // User Includes
       
    23 #include "testlcservice.h"
       
    24 
       
    25 
       
    26 // Constant Declarations
       
    27 
       
    28     
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // C++ Default Constructor
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CTestLcService::CTestLcService(CStifLogger* aLog)
       
    36     :CActive(0),iLog(aLog)
       
    37     {
       
    38     CActiveScheduler::Add(this);
       
    39     }
       
    40     
       
    41 // ---------------------------------------------------------------------------
       
    42 // C++ Destructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CTestLcService::~CTestLcService()
       
    46     {
       
    47       if( IsActive() )
       
    48 	      {
       
    49 	      Cancel(); 	
       
    50 	      }
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CTestLcService::RunL 
       
    55 //
       
    56 // RunL to Handle Completed Request
       
    57 // ---------------------------------------------------------
       
    58 //	
       
    59 void CTestLcService::RunL()
       
    60 	{
       
    61 	if(iStatus != KErrCancel)	
       
    62 		{
       
    63 		iLog->Log(_L("RunL %d"),iStatus.Int());		
       
    64 		CActiveScheduler::Stop();				
       
    65 		}
       
    66 	}
       
    67 	
       
    68 // ---------------------------------------------------------
       
    69 // CTestLcService::DoCancel 
       
    70 //
       
    71 // To Handle Cancel Request
       
    72 // ---------------------------------------------------------
       
    73 //	
       
    74 void CTestLcService::DoCancel()
       
    75 	{
       
    76 	iLcService->CancelGetLocationApplications();
       
    77 	iLog->Log(_L("CancelL Done"));
       
    78 
       
    79 	}
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CTestLcService::RunError 
       
    83 //
       
    84 // To Handle Error in RunL
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 TInt CTestLcService::RunError(TInt aError)
       
    88 	{
       
    89 	iLog->Log(_L("Leave in RunError %d"),aError);
       
    90 	CActiveScheduler::Stop();
       
    91 	return KErrNone;
       
    92 	}
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CTestLcService::LcStatusChangedL 
       
    96 //
       
    97 // ---------------------------------------------------------
       
    98 //
       
    99 void  CTestLcService::LcStatusChangedL( TInt /*aErrorCode*/ )
       
   100 	{
       
   101 	// No implementation
       
   102 	}
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CTestLcService::HandleChainedLocationAppExitL 
       
   106 //
       
   107 // ---------------------------------------------------------
       
   108 //
       
   109 void  CTestLcService::HandleChainedLocationAppExitL( TInt aReason )
       
   110 	{
       
   111 	iLog->Log(_L("In HandleChainedLocationAppExitL returned with : %d"), aReason);
       
   112 	}
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CTestLcService::CheckServiceNewL
       
   116 //
       
   117 // (other items are commented in a header).
       
   118 // ---------------------------------------------------------
       
   119 //
       
   120 TInt CTestLcService::CheckServiceNewL()
       
   121 	{
       
   122 	TInt err = KErrNone;
       
   123 	TRAP(err, iLcService = CLcService::NewL());
       
   124 	iLog->Log(_L("CheckServiceNewL return - %d"),err);
       
   125 	delete iLcService;
       
   126 	return err;
       
   127 	}	
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CTestLcService::CheckServiceNewLC
       
   131 //
       
   132 // (other items are commented in a header).
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 TInt CTestLcService::CheckServiceNewLC()
       
   136 	{
       
   137 	TInt err = KErrNone;
       
   138 	TRAP(err, iLcService = CLcService::NewLC();
       
   139 		CleanupStack::Pop(iLcService));
       
   140 	iLog->Log(_L("CheckServiceNewLC return - %d"),err);
       
   141 	delete iLcService;
       
   142 	return err;
       
   143 	}	  
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CTestLcService::TestGetLocationApplicationsL
       
   147 //
       
   148 // (other items are commented in a header).
       
   149 // ---------------------------------------------------------
       
   150 //
       
   151 TInt CTestLcService::TestGetLocationApplicationsL()
       
   152 	{
       
   153 	TInt err = KErrNone;
       
   154 	iLcService = CLcService::NewL();
       
   155 	CLcLocationAppInfoArray* array = iLcService->GetLocationApplicationsL( );
       
   156 	TInt countItems = array->Count( );
       
   157 	CLcLocationAppInfo& info1 =(*array)[countItems - 1];
       
   158 
       
   159 	TPtrC name1 = info1.Name( );
       
   160 	TPtrC id1 = info1.Id( );
       
   161 		
       
   162 	if( 0 == name1.Compare(_L("Positioning settings")) &&
       
   163 		0 == id1.Compare(_L("1028313B")) &&
       
   164 		CLcLocationAppInfo::EChainedMode == info1.LaunchMode() &&
       
   165 		CLcLocationAppInfo::ESysCharRomBased == info1.SystemCharacteristics() &&
       
   166 		CLcLocationAppInfo::EAppCharSettings == info1.ApplicationCharacteristics() )
       
   167 		{
       
   168 		iLog->Log(_L("TestGetLocationApplicationsL Passed"));
       
   169 		}
       
   170 	else
       
   171 		{
       
   172 		err = KErrGeneral;
       
   173 		iLog->Log(_L("TestGetLocationApplicationsL Failed"));
       
   174 		}
       
   175 	
       
   176 	array->Remove(countItems - 1);
       
   177 	array->Reset();
       
   178 	
       
   179     delete array;
       
   180 	delete iLcService;
       
   181 	return err;
       
   182 	}	
       
   183 
       
   184 // ---------------------------------------------------------
       
   185 // CTestLcService::TestGetLocationApplicationsAsynL
       
   186 //
       
   187 // (other items are commented in a header).
       
   188 // ---------------------------------------------------------
       
   189 //
       
   190 TInt CTestLcService::TestGetLocationApplicationsAsynL()
       
   191 	{
       
   192 	TInt err = KErrNone;
       
   193 	iLcService = CLcService::NewL();
       
   194 	CLcLocationAppInfoArray* array;
       
   195 	iLcService->GetLocationApplications( iStatus, array );
       
   196 	SetActive();
       
   197 	CActiveScheduler::Start();
       
   198 
       
   199 	TInt countItems = array->Count( );
       
   200 	CLcLocationAppInfo& info1 =(*array)[countItems - 1];
       
   201 
       
   202 	TPtrC name1 = info1.Name( );
       
   203 	TPtrC id1 = info1.Id( );
       
   204 		
       
   205 	if( 0 == name1.Compare(_L("Positioning settings")) &&
       
   206 		0 == id1.Compare(_L("1028313B")) &&
       
   207 		CLcLocationAppInfo::EChainedMode == info1.LaunchMode() &&
       
   208 		CLcLocationAppInfo::ESysCharRomBased == info1.SystemCharacteristics() &&
       
   209 		CLcLocationAppInfo::EAppCharSettings == info1.ApplicationCharacteristics() )
       
   210 		{
       
   211 		iLog->Log(_L("TestGetLocationApplicationsL Passed"));
       
   212 		}
       
   213 	else
       
   214 		{
       
   215 		err = KErrGeneral;
       
   216 		iLog->Log(_L("TestGetLocationApplicationsL Failed"));
       
   217 		}
       
   218 	
       
   219     delete array;
       
   220 	delete iLcService;
       
   221 	return err;
       
   222 	}
       
   223 
       
   224 // ---------------------------------------------------------
       
   225 // CTestLcService::TestGetLocationApplicationsFilterL
       
   226 //
       
   227 // (other items are commented in a header).
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 TInt CTestLcService::TestGetLocationApplicationsFilterL()
       
   231 	{
       
   232 	TInt err = KErrNone;
       
   233 	iLcService = CLcService::NewL();
       
   234 	TLcLocationAppFilter filter;
       
   235     filter.SetApplicationCharacteristics( CLcLocationAppInfo::EAppCharSettings );
       
   236     filter.SetSystemCharacteristic( CLcLocationAppInfo::ESysCharRomBased  );
       
   237     filter.SetAppCharFilterConfiguration( TLcLocationAppFilter::EFilterStrict );
       
   238     filter.SetSysCharFilterConfiguration( TLcLocationAppFilter::EFilterStrict );
       
   239         
       
   240     CLcLocationAppInfoArray* array=iLcService->GetLocationApplicationsL(filter);
       
   241     
       
   242 	TInt countItems = array->Count( );
       
   243 	CLcLocationAppInfo& info1 =(*array)[countItems - 1];
       
   244 
       
   245 	TPtrC name1 = info1.Name( );
       
   246 	TPtrC id1 = info1.Id( );
       
   247 		
       
   248 	if( 0 == name1.Compare(_L("Positioning settings")) &&
       
   249 		0 == id1.Compare(_L("1028313B")) )
       
   250 		{
       
   251 		iLog->Log(_L("TestGetLocationApplicationsFilterL Passed"));
       
   252 		}
       
   253 	else
       
   254 		{
       
   255 		err = KErrGeneral;
       
   256 		iLog->Log(_L("TestGetLocationApplicationsFilterL Failed"));
       
   257 		}
       
   258 	
       
   259     delete array;
       
   260 	delete iLcService;
       
   261 	return err;
       
   262 	}	
       
   263 
       
   264 // ---------------------------------------------------------
       
   265 // CTestLcService::TestGetLocationApplicationsFilterAsynL
       
   266 //
       
   267 // (other items are commented in a header).
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 TInt CTestLcService::TestGetLocationApplicationsFilterAsynL()
       
   271 	{
       
   272 	TInt err = KErrNone;
       
   273 	iLcService = CLcService::NewL();
       
   274 	TLcLocationAppFilter filter;
       
   275     filter.SetApplicationCharacteristics( CLcLocationAppInfo::EAppCharSettings );
       
   276     filter.SetSystemCharacteristic( CLcLocationAppInfo::ESysCharRomBased  );
       
   277     filter.SetAppCharFilterConfiguration( TLcLocationAppFilter::EFilterStrict );
       
   278     filter.SetSysCharFilterConfiguration( TLcLocationAppFilter::EFilterStrict );
       
   279         
       
   280     CLcLocationAppInfoArray* array;
       
   281     iLcService->GetLocationApplications(iStatus, filter, array);
       
   282 
       
   283 	SetActive();
       
   284 	CActiveScheduler::Start();
       
   285 
       
   286 	TInt countItems = array->Count( );
       
   287 	CLcLocationAppInfo& info1 =(*array)[countItems - 1];
       
   288 
       
   289 	TPtrC name1 = info1.Name( );
       
   290 	TPtrC id1 = info1.Id( );
       
   291 		
       
   292 		iLog->Log(_L("countItems = %d"), countItems);
       
   293 		
       
   294 	if( 0 == name1.Compare(_L("Positioning settings")) &&
       
   295 		0 == id1.Compare(_L("1028313B")) )
       
   296 		{
       
   297 		iLog->Log(_L("TestGetLocationApplicationsFilterL Passed"));
       
   298 		}
       
   299 	else
       
   300 		{
       
   301 		err = KErrGeneral;
       
   302 		iLog->Log(_L("TestGetLocationApplicationsFilterL Failed"));
       
   303 		}
       
   304 	
       
   305     delete array;
       
   306 	delete iLcService;
       
   307 	return err;
       
   308 	}
       
   309 
       
   310 // ---------------------------------------------------------
       
   311 // CTestLcService::TestSetRemoveObserverL
       
   312 //
       
   313 // (other items are commented in a header).
       
   314 // ---------------------------------------------------------
       
   315 //
       
   316 TInt CTestLcService::TestSetRemoveObserverL(TInt aObserverState)
       
   317 	{
       
   318 	TInt err = KErrNone;
       
   319 	iLcService = CLcService::NewL();
       
   320 
       
   321 	if( 1 == aObserverState )
       
   322 		iLcService->SetObserverL(*this);
       
   323 	
       
   324 	err = iLcService->RemoveObserver();
       
   325 
       
   326 	if( KErrNone == err )
       
   327 		{
       
   328 		iLog->Log(_L("TestSetRemoveObserverL Passed with %d"), err);
       
   329 		}
       
   330 	else
       
   331 		{
       
   332 		iLog->Log(_L("TestSetRemoveObserverL Failed with %d"), err);
       
   333 		}
       
   334 
       
   335 	delete iLcService;
       
   336 	return err;
       
   337 	}
       
   338 
       
   339 // ---------------------------------------------------------
       
   340 // CTestLcService::TestCancelGetLocationApplications
       
   341 //
       
   342 // (other items are commented in a header).
       
   343 // ---------------------------------------------------------
       
   344 //
       
   345 TInt CTestLcService::TestCancelGetLocationApplications()
       
   346 	{
       
   347 	iLcService = CLcService::NewL();
       
   348 	CLcLocationAppInfoArray* array;
       
   349 	iLcService->GetLocationApplications( iStatus, array );
       
   350 	SetActive();
       
   351 	
       
   352 	Cancel();
       
   353 	
       
   354     iLog->Log(_L("In TestCancelGetLocationApplications: returned with : %d"), iStatus.Int());
       
   355 
       
   356 	delete iLcService;
       
   357 	return iStatus.Int();
       
   358 	}
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CTestLcService::TestCLcLaunchParamNewL
       
   362 //
       
   363 // (other items are commented in a header).
       
   364 // ---------------------------------------------------------
       
   365 //
       
   366 TInt CTestLcService::TestCLcLaunchParamNewL()
       
   367 	{
       
   368 	TInt err = KErrNone;
       
   369 	CLcService::CLcLaunchParam* lcLaunchParam;
       
   370 	TBuf<128> buf;
       
   371 	
       
   372 	TRAP(err, lcLaunchParam = CLcService::CLcLaunchParam::NewL(buf));
       
   373 
       
   374 	iLog->Log(_L("CheckNewL return with %d"), err);
       
   375 
       
   376 	delete lcLaunchParam;
       
   377 	return err;
       
   378 	}
       
   379 	
       
   380 // ---------------------------------------------------------
       
   381 // CTestLcService::TestCLcLaunchParamNewLC
       
   382 //
       
   383 // (other items are commented in a header).
       
   384 // ---------------------------------------------------------
       
   385 //
       
   386 TInt CTestLcService::TestCLcLaunchParamNewLC()
       
   387 	{
       
   388 	TInt err = KErrNone;
       
   389 	CLcService::CLcLaunchParam* lcLaunchParam;
       
   390 	TBuf<128> buf;
       
   391 	
       
   392 	TRAP(err, lcLaunchParam = CLcService::CLcLaunchParam::NewLC(buf);
       
   393 		CleanupStack::Pop(lcLaunchParam));
       
   394 
       
   395 	iLog->Log(_L("CheckNewLC return with %d"), err);
       
   396 
       
   397 	delete lcLaunchParam;
       
   398 	return err;
       
   399 	}
       
   400