lbs/lbsclient/src/ctlbsclientstepmodinfo.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file ctlbsclientstepmodinfo.cpp
       
    15 // This is the class implementation for the Module Information Tests
       
    16 // 
       
    17 //
       
    18  
       
    19 #include "ctlbsclientstepmodinfo.h"
       
    20 
       
    21 #include <lbs.h>
       
    22 
       
    23 #include "tlbsutils.h"
       
    24 
       
    25 /** "num_of_mods" = the expected number (TUint) of modules returned from RPositionServer::GetNumModules().
       
    26 */
       
    27 _LIT(KNumOfMods, "num_of_mods");
       
    28 
       
    29 /** "default_mod_id" = the expected module id returned from RPositionServer::GetDefaultModuleId(),
       
    30 	value is decimal.
       
    31 */
       
    32 _LIT(KDefaultModId, "default_mod_id");
       
    33 
       
    34 
       
    35 
       
    36 /**
       
    37  * Destructor
       
    38  */
       
    39 CT_LbsClientStep_ModInfo::~CT_LbsClientStep_ModInfo()
       
    40 	{
       
    41 	}
       
    42 
       
    43 
       
    44 /**
       
    45  * Constructor
       
    46  */
       
    47 CT_LbsClientStep_ModInfo::CT_LbsClientStep_ModInfo(CT_LbsClientServer& aParent) : CT_LbsClientStep(aParent)
       
    48 	{
       
    49 	SetTestStepName(KLbsClientStep_ModInfo);
       
    50 	}
       
    51 
       
    52 
       
    53 /**
       
    54 Static Constructor
       
    55 */
       
    56 CT_LbsClientStep_ModInfo* CT_LbsClientStep_ModInfo::New(CT_LbsClientServer& aParent)
       
    57 	{
       
    58 	return new CT_LbsClientStep_ModInfo(aParent);
       
    59 	// Note the lack of ELeave.
       
    60 	// This means that having insufficient memory will return NULL;
       
    61 	}
       
    62 
       
    63 
       
    64 /**
       
    65  * @return - TVerdict code
       
    66  * Override of base class pure virtual
       
    67  * Our implementation only gets called if the base class doTestStepPreambleL() did
       
    68  * not leave. That being the case, the current test result value will be EPass.
       
    69  */
       
    70 TVerdict CT_LbsClientStep_ModInfo::doTestStepL()
       
    71 	{
       
    72 	// Generic test step used to test the LBS Client Notify position update API.
       
    73 	INFO_PRINTF1(_L("&gt;&gt;CT_LbsClientStep_ModInfo::doTestStepL()"));
       
    74 
       
    75 	if (TestStepResult() == EPass)
       
    76 		{
       
    77 		TInt err = KErrNone;
       
    78 		TUint 					numOfMods;
       
    79 		TInt 					modIndex;
       
    80 		TPositionModuleId		modId;
       
    81 		TPositionModuleInfo&	currentModInfo = iParent.iSharedData->iCurrentModuleInfo;
       
    82 							
       
    83 		// Connect to self locate server.
       
    84 		User::LeaveIfError(iServer.Connect());
       
    85 		CleanupClosePushL(iServer);
       
    86 		
       
    87 		// Carryout unique test actions.
       
    88 		TInt testCaseId;
       
    89 		if (GetIntFromConfig(ConfigSection(), KTestCaseId, testCaseId))
       
    90 			{
       
    91 			switch (testCaseId)
       
    92 				{
       
    93 				// Test case LBS-ModCnt-0001
       
    94 				case 1:
       
    95 					{
       
    96 					// Find the number of modules installed.
       
    97 					TUint verifyNumOfMods;
       
    98 
       
    99 					if (GetIntFromConfig(ConfigSection(), KNumOfMods, reinterpret_cast<TInt&>(verifyNumOfMods)))
       
   100 						{
       
   101 						err = iServer.GetNumModules(numOfMods);
       
   102 						if ((KErrNone != err) || (verifyNumOfMods != numOfMods))
       
   103 							{
       
   104 							INFO_PRINTF4(_L("Incorrect err = %d, or num of modules %d should be %d"), err, numOfMods, verifyNumOfMods);
       
   105 							SetTestStepResult(EFail);	
       
   106 							}
       
   107 						}
       
   108 						else
       
   109 						{
       
   110 							INFO_PRINTF1(_L("No num_of_mods variable set in .ini file"));
       
   111 							SetTestStepResult(EFail);
       
   112 						}
       
   113 						break;
       
   114 					}
       
   115 					
       
   116 				// Test case LBS-ModCnt-0002
       
   117 				case 2:
       
   118 					{
       
   119 				
       
   120 					// Call GetNumModules with no connection to server.
       
   121 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   122 
       
   123 					server.GetNumModules(numOfMods);	// No need to check err, call will panic.
       
   124 					break;
       
   125 					}
       
   126 
       
   127 				// Test case LBS-ModCnt-0003
       
   128 				// Test case LBS-ModCnt-0004
       
   129 				case 3:
       
   130 				case 4:
       
   131 					{
       
   132 					// Find the number of modules installed.
       
   133 					TUint verifyNumOfMods;
       
   134 
       
   135 					if (GetIntFromConfig(ConfigSection(), KNumOfMods, reinterpret_cast<TInt&>(verifyNumOfMods)))
       
   136 						{
       
   137 						err = iServer.GetNumModules(numOfMods);
       
   138 						if ((KErrNone != err) || (verifyNumOfMods != numOfMods))
       
   139 							{
       
   140 							INFO_PRINTF4(_L("Incorrect err = %d, or num of modules %d should be %d"), err, numOfMods, verifyNumOfMods);
       
   141 							SetTestStepResult(EFail);	
       
   142 							}
       
   143 						}
       
   144 						else
       
   145 						{
       
   146 							INFO_PRINTF1(_L("No num_of_mods variable set in .ini file"));
       
   147 							SetTestStepResult(EFail);
       
   148 						}
       
   149 
       
   150 					// Setup verification data
       
   151 					const TInt KNumModules = 3;
       
   152 					_LIT(KLitModName1, "OtherModule");
       
   153 					_LIT(KLitModName2, "SIRF_Loc_AGPS_Module");
       
   154 					_LIT(KLitModName2_C, "C_Drive_SIRF_Module");
       
   155 					_LIT(KLitModName3, "TEST_Loc_AGPS_Module");
       
   156 					TPositionModuleId modId;
       
   157 					TPositionModuleInfo modInfArray[KNumModules];
       
   158 					modId.iUid = 271064389;			// othermodule.ini
       
   159 					modInfArray[0].SetModuleId(modId);
       
   160 					modInfArray[0].SetModuleName(KLitModName1);
       
   161 					modInfArray[0].SetIsAvailable(ETrue);
       
   162 					modId.iUid = 271064388;			// sirfdatasource.ini
       
   163 					modInfArray[1].SetModuleId(modId);
       
   164 					if (testCaseId == 3)
       
   165 						modInfArray[1].SetModuleName(KLitModName2);
       
   166 					else
       
   167 						modInfArray[1].SetModuleName(KLitModName2_C);
       
   168 					modInfArray[1].SetIsAvailable(ETrue);
       
   169 					modId.iUid = 271064388;			// xtestmodule.ini
       
   170 					modInfArray[2].SetModuleId(modId);
       
   171 					modInfArray[2].SetModuleName(KLitModName3);
       
   172 					modInfArray[2].SetIsAvailable(ETrue);
       
   173 						
       
   174 					if (err == KErrNone)
       
   175 						{
       
   176 						// Verify the expected modules were returned
       
   177 						for (TInt i=0; i < numOfMods; i++)
       
   178 							{
       
   179 							TPositionModuleInfo modInfo;
       
   180 							err = iServer.GetModuleInfoByIndex(i, modInfo);
       
   181 							if (err == KErrNone)
       
   182 								{
       
   183 								// Check module info is as expected
       
   184 								for (TInt j=0; j < KNumModules; j++)
       
   185 									{
       
   186 									// Check module info
       
   187 									if (!modInfArray[j].IsAvailable())
       
   188 										continue;
       
   189 									// Check ID
       
   190 									if (modInfo.ModuleId() != modInfArray[j].ModuleId())
       
   191 										continue;
       
   192 									// Check name
       
   193 									TBuf<32> modName, verifyName;
       
   194 									modInfo.GetModuleName(modName);
       
   195 									modInfArray[j].GetModuleName(verifyName);
       
   196 									if (modName.Compare(verifyName) == 0)
       
   197 										{
       
   198 										// Use the available to flag module info already 
       
   199 										// seen in modInfArray.
       
   200 										modInfArray[j].SetIsAvailable(EFalse);
       
   201 										break;
       
   202 										}
       
   203 									}
       
   204 								}
       
   205 							else
       
   206 								{
       
   207 								INFO_PRINTF3(_L("Error getting module info %d (%d)"), i, err);
       
   208 								SetTestStepResult(EFail);
       
   209 								}
       
   210 							}
       
   211 							
       
   212 						// Check that all modules were seen
       
   213 						for (TInt k=0; k < KNumModules; k++)
       
   214 							{
       
   215 							if (modInfArray[k].IsAvailable())
       
   216 								{
       
   217 								INFO_PRINTF2(_L("Expected module %d not found"), k);
       
   218 								SetTestStepResult(EFail);
       
   219 								}
       
   220 							}
       
   221 						}
       
   222 					break;
       
   223 					}
       
   224 
       
   225 
       
   226 				// TODO:
       
   227 				// how do we compare the mod info items, will have to read the ini file ourselfs
       
   228 				// no point in having our own ini file type like we have for posinfo
       
   229 				// have a test step does the reading of the standard modinfo ini file
       
   230 				// have a test step to install the modinfo ini file
       
   231 
       
   232 
       
   233 				// Test case LBS-ModInfo-0001
       
   234 				case 11:
       
   235 					{
       
   236 					// Get mod info, normal functional test.
       
   237 					//iServer.GetNumModules(numOfMods);
       
   238 				    
       
   239 					//err = iServer.GetModuleInfoByIndex(numOfMods-1, currentModInfo);
       
   240 					err = iServer.GetModuleInfoByIndex(0, currentModInfo);
       
   241 					if (KErrNone != err)
       
   242 						{
       
   243 						INFO_PRINTF2(_L("Incorrect err = %d"), err);
       
   244 						SetTestStepResult(EFail);	
       
   245 						}
       
   246 					break;
       
   247 					}
       
   248 				
       
   249 				// Test case LBS-ModInfo-0002
       
   250 				case 12:
       
   251 					{
       
   252 					// Get mod info using a invalid index.
       
   253 					modIndex = -1;
       
   254 					
       
   255 					err = iServer.GetModuleInfoByIndex(modIndex, currentModInfo);
       
   256 					if (KErrNotFound != err)
       
   257 						{
       
   258 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   259 						SetTestStepResult(EFail);	
       
   260 						}
       
   261 					break;
       
   262 					}
       
   263 				
       
   264 				// Test case LBS-ModInfo-0003
       
   265 				case 13:
       
   266 					{
       
   267 					// Get mod info using a invalid index.
       
   268 					User::LeaveIfError(iServer.GetNumModules(numOfMods));
       
   269 					modIndex = numOfMods + 1; // This will give us a invalid index.
       
   270 					
       
   271 					err = iServer.GetModuleInfoByIndex(modIndex, currentModInfo);
       
   272 					if (KErrNotFound != err)
       
   273 						{
       
   274 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   275 						SetTestStepResult(EFail);	
       
   276 						}
       
   277 					break;
       
   278 					}
       
   279 
       
   280 				// Test case LBS-ModInfo-0004
       
   281 				case 14:
       
   282 					{
       
   283 					// Get mod info with no connection to the server.
       
   284 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   285 					
       
   286 					server.GetModuleInfoByIndex(0, currentModInfo);	// No need to check err, call will panic.
       
   287 					break;
       
   288 					}
       
   289 
       
   290 				// Test case LBS-ModInfo-0005
       
   291 				case 15:
       
   292 					{
       
   293 					// Get mod info using a valid id.
       
   294 					TPositionModuleInfo	modInfo;
       
   295 					
       
   296 					// Determine a valid module id, use get mod by index
       
   297 					User::LeaveIfError(iServer.GetModuleInfoByIndex(0, modInfo));
       
   298 					modId = modInfo.ModuleId();
       
   299 
       
   300 					// Carry out test of a valid id					
       
   301 					err = iServer.GetModuleInfoById(modId, currentModInfo);
       
   302 					if (KErrNone != err)
       
   303 						{
       
   304 						INFO_PRINTF2(_L("Incorrect err = %d"), err);
       
   305 						SetTestStepResult(EFail);	
       
   306 						}
       
   307 					break;
       
   308 					}
       
   309 				
       
   310 				// Test case LBS-ModInfo-0006
       
   311 				case 16:
       
   312 					{
       
   313 					// Get mod info with invalid id.
       
   314 					modId = KPositionNullModuleId;
       
   315 					
       
   316 					err = iServer.GetModuleInfoById(modId, currentModInfo);
       
   317 					if (KErrNotFound != err)
       
   318 						{
       
   319 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   320 						SetTestStepResult(EFail);	
       
   321 						}
       
   322 					break;
       
   323 					}
       
   324 				
       
   325 				// Test case LBS-ModInfo-0007
       
   326 				case 17:
       
   327 					{
       
   328 					// Get mod info with no connection to the server.
       
   329 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   330 					
       
   331 					server.GetModuleInfoById(KPositionNullModuleId, currentModInfo);	// No need to check err, call will panic.
       
   332 					break;
       
   333 					}
       
   334 
       
   335 				// Test case LBS-ModInfo-0008
       
   336 				case 18:
       
   337 					{
       
   338 					// Get default mod id.
       
   339 					TPositionModuleId verifyModId;
       
   340 					if (GetIntFromConfig(ConfigSection(), KDefaultModId, reinterpret_cast<TInt&>(verifyModId)))
       
   341 						{
       
   342 						err = iServer.GetDefaultModuleId(modId);
       
   343 						if ((KErrNone != err) || (verifyModId != modId))
       
   344 							{
       
   345 							INFO_PRINTF4(_L("Incorrect err = %d, or default module id %d should be %d"), err, modId, verifyModId);
       
   346 							SetTestStepResult(EFail);	
       
   347 							}
       
   348 						}
       
   349 						
       
   350 					else
       
   351 						{
       
   352 						INFO_PRINTF1(_L("No default_mod_id variable set in .ini file"));
       
   353 						SetTestStepResult(EFail);
       
   354 						}
       
   355 					break;		
       
   356 					}
       
   357 
       
   358 				// Test case LBS-ModInfo-0009
       
   359 				case 19:
       
   360 					{
       
   361 					// Get default mod id with no connection to server.
       
   362 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   363 					
       
   364 					server.GetDefaultModuleId(modId);	// No need to check err, call will panic.
       
   365 					break;
       
   366 					}
       
   367 				}
       
   368 			}
       
   369 			
       
   370 		// All done, clean up.
       
   371 		CleanupStack::PopAndDestroy(&iServer);		
       
   372 		}
       
   373 
       
   374 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_ModInfo::doTestStepL()"));
       
   375 
       
   376 	return TestStepResult();
       
   377 	}