lbstest/lbstestproduct/lbsclient/src/ctlbsclientstepmodinfo.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-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 <lbs/test/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 					err = iServer.GetNumModules(numOfMods);
       
    98 					if ((KErrNone != err) || (numOfMods <=0))
       
    99                         {
       
   100                         INFO_PRINTF3(_L("Incorrect err = %d, or num of modules %d shouldn't be equal to zero "), err, numOfMods);
       
   101                         SetTestStepResult(EFail);	
       
   102                         }
       
   103 					break;
       
   104 					}
       
   105 				// Test case LBS-ModCnt-0002
       
   106 				case 2:
       
   107 					{
       
   108 				
       
   109 					// Call GetNumModules with no connection to server.
       
   110 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   111 
       
   112 					server.GetNumModules(numOfMods);	// No need to check err, call will panic.
       
   113 					break;
       
   114 					}
       
   115 
       
   116 				// Test case LBS-ModCnt-0003
       
   117 				// Test case LBS-ModCnt-0004
       
   118 				case 3:
       
   119 				case 4:
       
   120 					{
       
   121 					// Find the number of modules installed.
       
   122 					TUint verifyNumOfMods;
       
   123 
       
   124 					if (GetIntFromConfig(ConfigSection(), KNumOfMods, reinterpret_cast<TInt&>(verifyNumOfMods)))
       
   125 						{
       
   126 						err = iServer.GetNumModules(numOfMods);
       
   127 						if ((KErrNone != err) || (verifyNumOfMods != numOfMods))
       
   128 							{
       
   129 							INFO_PRINTF4(_L("Incorrect err = %d, or num of modules %d should be %d"), err, numOfMods, verifyNumOfMods);
       
   130 							SetTestStepResult(EFail);	
       
   131 							}
       
   132 						}
       
   133 						else
       
   134 						{
       
   135 							INFO_PRINTF1(_L("No num_of_mods variable set in .ini file"));
       
   136 							SetTestStepResult(EFail);
       
   137 						}
       
   138 
       
   139 					// Setup verification data
       
   140 					const TInt KNumModules = 3;
       
   141 					_LIT(KLitModName1, "OtherModule");
       
   142 					_LIT(KLitModName2, "SIRF_Loc_AGPS_Module");
       
   143 					_LIT(KLitModName2_C, "C_Drive_SIRF_Module");
       
   144 					_LIT(KLitModName3, "TEST_Loc_AGPS_Module");
       
   145 					TPositionModuleId modId;
       
   146 					TPositionModuleInfo modInfArray[KNumModules];
       
   147 					modId.iUid = 271064389;			// othermodule.ini
       
   148 					modInfArray[0].SetModuleId(modId);
       
   149 					modInfArray[0].SetModuleName(KLitModName1);
       
   150 					modInfArray[0].SetIsAvailable(ETrue);
       
   151 					modId.iUid = 271064388;			// sirfdatasource.ini
       
   152 					modInfArray[1].SetModuleId(modId);
       
   153 					if (testCaseId == 3)
       
   154 						modInfArray[1].SetModuleName(KLitModName2);
       
   155 					else
       
   156 						modInfArray[1].SetModuleName(KLitModName2_C);
       
   157 					modInfArray[1].SetIsAvailable(ETrue);
       
   158 					modId.iUid = 271064388;			// xtestmodule.ini
       
   159 					modInfArray[2].SetModuleId(modId);
       
   160 					modInfArray[2].SetModuleName(KLitModName3);
       
   161 					modInfArray[2].SetIsAvailable(ETrue);
       
   162 						
       
   163 					if (err == KErrNone)
       
   164 						{
       
   165 						// Verify the expected modules were returned
       
   166 						for (TInt i=0; i < numOfMods; i++)
       
   167 							{
       
   168 							TPositionModuleInfo modInfo;
       
   169 							err = iServer.GetModuleInfoByIndex(i, modInfo);
       
   170 							if (err == KErrNone)
       
   171 								{
       
   172 								// Check module info is as expected
       
   173 								for (TInt j=0; j < KNumModules; j++)
       
   174 									{
       
   175 									// Check module info
       
   176 									if (!modInfArray[j].IsAvailable())
       
   177 										continue;
       
   178 									// Check ID
       
   179 									if (modInfo.ModuleId() != modInfArray[j].ModuleId())
       
   180 										continue;
       
   181 									// Check name
       
   182 									TBuf<32> modName, verifyName;
       
   183 									modInfo.GetModuleName(modName);
       
   184 									modInfArray[j].GetModuleName(verifyName);
       
   185 									if (modName.Compare(verifyName) == 0)
       
   186 										{
       
   187 										// Use the available to flag module info already 
       
   188 										// seen in modInfArray.
       
   189 										modInfArray[j].SetIsAvailable(EFalse);
       
   190 										break;
       
   191 										}
       
   192 									}
       
   193 								}
       
   194 							else
       
   195 								{
       
   196 								INFO_PRINTF3(_L("Error getting module info %d (%d)"), i, err);
       
   197 								SetTestStepResult(EFail);
       
   198 								}
       
   199 							}
       
   200 							
       
   201 						// Check that all modules were seen
       
   202 						for (TInt k=0; k < KNumModules; k++)
       
   203 							{
       
   204 							if (modInfArray[k].IsAvailable())
       
   205 								{
       
   206 								INFO_PRINTF2(_L("Expected module %d not found"), k);
       
   207 								SetTestStepResult(EFail);
       
   208 								}
       
   209 							}
       
   210 						}
       
   211 					break;
       
   212 					}
       
   213 
       
   214 
       
   215 				// TODO:
       
   216 				// how do we compare the mod info items, will have to read the ini file ourselfs
       
   217 				// no point in having our own ini file type like we have for posinfo
       
   218 				// have a test step does the reading of the standard modinfo ini file
       
   219 				// have a test step to install the modinfo ini file
       
   220 
       
   221 
       
   222 				// Test case LBS-ModInfo-0001
       
   223 				case 11:
       
   224 					{
       
   225 					// Get mod info, normal functional test.
       
   226 					//iServer.GetNumModules(numOfMods);
       
   227 				    
       
   228 					//err = iServer.GetModuleInfoByIndex(numOfMods-1, currentModInfo);
       
   229 					err = iServer.GetModuleInfoByIndex(0, currentModInfo);
       
   230 					if (KErrNone != err)
       
   231 						{
       
   232 						INFO_PRINTF2(_L("Incorrect err = %d"), err);
       
   233 						SetTestStepResult(EFail);	
       
   234 						}
       
   235 					break;
       
   236 					}
       
   237 				
       
   238 				// Test case LBS-ModInfo-0002
       
   239 				case 12:
       
   240 					{
       
   241 					// Get mod info using a invalid index.
       
   242 					modIndex = -1;
       
   243 					
       
   244 					err = iServer.GetModuleInfoByIndex(modIndex, currentModInfo);
       
   245 					if (KErrNotFound != err)
       
   246 						{
       
   247 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   248 						SetTestStepResult(EFail);	
       
   249 						}
       
   250 					break;
       
   251 					}
       
   252 				
       
   253 				// Test case LBS-ModInfo-0003
       
   254 				case 13:
       
   255 					{
       
   256 					// Get mod info using a invalid index.
       
   257 					User::LeaveIfError(iServer.GetNumModules(numOfMods));
       
   258 					modIndex = numOfMods + 1; // This will give us a invalid index.
       
   259 					
       
   260 					err = iServer.GetModuleInfoByIndex(modIndex, currentModInfo);
       
   261 					if (KErrNotFound != err)
       
   262 						{
       
   263 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   264 						SetTestStepResult(EFail);	
       
   265 						}
       
   266 					break;
       
   267 					}
       
   268 
       
   269 				// Test case LBS-ModInfo-0004
       
   270 				case 14:
       
   271 					{
       
   272 					// Get mod info with no connection to the server.
       
   273 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   274 					
       
   275 					server.GetModuleInfoByIndex(0, currentModInfo);	// No need to check err, call will panic.
       
   276 					break;
       
   277 					}
       
   278 
       
   279 				// Test case LBS-ModInfo-0005
       
   280 				case 15:
       
   281 					{
       
   282 					// Get mod info using a valid id.
       
   283 					TPositionModuleInfo	modInfo;
       
   284 					
       
   285 					// Determine a valid module id, use get mod by index
       
   286 					User::LeaveIfError(iServer.GetModuleInfoByIndex(0, modInfo));
       
   287 					modId = modInfo.ModuleId();
       
   288 
       
   289 					// Carry out test of a valid id					
       
   290 					err = iServer.GetModuleInfoById(modId, currentModInfo);
       
   291 					if (KErrNone != err)
       
   292 						{
       
   293 						INFO_PRINTF2(_L("Incorrect err = %d"), err);
       
   294 						SetTestStepResult(EFail);	
       
   295 						}
       
   296 					break;
       
   297 					}
       
   298 				
       
   299 				// Test case LBS-ModInfo-0006
       
   300 				case 16:
       
   301 					{
       
   302 					// Get mod info with invalid id.
       
   303 					modId = KPositionNullModuleId;
       
   304 					
       
   305 					err = iServer.GetModuleInfoById(modId, currentModInfo);
       
   306 					if (KErrNotFound != err)
       
   307 						{
       
   308 						INFO_PRINTF3(_L("Incorrect err = %d, should be %d"), err, KErrNotFound);
       
   309 						SetTestStepResult(EFail);	
       
   310 						}
       
   311 					break;
       
   312 					}
       
   313 				
       
   314 				// Test case LBS-ModInfo-0007
       
   315 				case 17:
       
   316 					{
       
   317 					// Get mod info with no connection to the server.
       
   318 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   319 					
       
   320 					server.GetModuleInfoById(KPositionNullModuleId, currentModInfo);	// No need to check err, call will panic.
       
   321 					break;
       
   322 					}
       
   323 
       
   324 				// Test case LBS-ModInfo-0008
       
   325 				case 18:
       
   326 					{
       
   327 					// Get default mod id.
       
   328 					TPositionModuleId verifyModId;
       
   329 					if (GetIntFromConfig(ConfigSection(), KDefaultModId, reinterpret_cast<TInt&>(verifyModId)))
       
   330 						{
       
   331 						err = iServer.GetDefaultModuleId(modId);
       
   332 						if ((KErrNone != err) || (verifyModId != modId))
       
   333 							{
       
   334 							INFO_PRINTF4(_L("Incorrect err = %d, or default module id %d should be %d"), err, modId, verifyModId);
       
   335 							SetTestStepResult(EFail);	
       
   336 							}
       
   337 						}
       
   338 						
       
   339 					else
       
   340 						{
       
   341 						INFO_PRINTF1(_L("No default_mod_id variable set in .ini file"));
       
   342 						SetTestStepResult(EFail);
       
   343 						}
       
   344 					break;		
       
   345 					}
       
   346 
       
   347 				// Test case LBS-ModInfo-0009
       
   348 				case 19:
       
   349 					{
       
   350 					// Get default mod id with no connection to server.
       
   351 					RPositionServer server;	// Don't use iServer as it's open for every test.
       
   352 					
       
   353 					server.GetDefaultModuleId(modId);	// No need to check err, call will panic.
       
   354 					break;
       
   355 					}
       
   356 				}
       
   357 			}
       
   358 			
       
   359 		// All done, clean up.
       
   360 		CleanupStack::PopAndDestroy(&iServer);		
       
   361 		}
       
   362 
       
   363 	INFO_PRINTF1(_L("&lt;&lt;CT_LbsClientStep_ModInfo::doTestStepL()"));
       
   364 
       
   365 	return TestStepResult();
       
   366 	}
       
   367