commsconfig/commsdatabaseshim/TE_commdb/src/Teststepcommdb.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     1 //
       
     2 // Copyright (c) 2009 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:
       
    15 //
       
    16 //
       
    17 //
       
    18 // This contains CTestCase which is the base class for all the TestCase DLLs
       
    19 
       
    20 // EPOC includes
       
    21 #include <e32base.h>
       
    22 #include <commdb.h>
       
    23 #include <f32file.h>
       
    24 // Test system includes
       
    25 #include "comms-infras/commdb/protection/protectdb.h"
       
    26 #include "comms-infras/commdb/protection/protectcpdb.h"
       
    27 #include <cdbpreftable.h>
       
    28 #include "CDBSTD.H"
       
    29 #include "Teststepcommdb.h"
       
    30 
       
    31 
       
    32 // constructor
       
    33 CTestStepCommDb::CTestStepCommDb()
       
    34 	{
       
    35 	iRemoteObjects = EFalse;
       
    36 	}
       
    37 
       
    38 // destructor
       
    39 CTestStepCommDb::~CTestStepCommDb()
       
    40 	{
       
    41 	popAndDestroyDatabaseObjects();
       
    42 	}
       
    43 
       
    44 // file copy
       
    45 void CTestStepCommDb::copyFileL(const TDesC& anOld,const TDesC& aNew)
       
    46 	{
       
    47 	// create a fileserver
       
    48 	RFs fileSystem;
       
    49 
       
    50 	// connect to file server
       
    51 	User::LeaveIfError(fileSystem.Connect());
       
    52 	CleanupClosePushL(fileSystem);
       
    53 
       
    54 	// create a file manager
       
    55 	CFileMan * fileMan = CFileMan::NewL(fileSystem);
       
    56 	CleanupStack::PushL(fileMan);
       
    57 
       
    58 	// parse the filenames
       
    59 	TParse source;
       
    60 	User::LeaveIfError(source.Set(anOld, NULL, NULL));
       
    61 
       
    62 	// parse the filenames
       
    63 	TParse target;
       
    64 	User::LeaveIfError(target.Set(aNew, NULL, NULL));
       
    65 
       
    66 	// do the copy
       
    67 	User::LeaveIfError(fileMan->Copy(source.FullName(), target.FullName(), CFileMan::EOverWrite));
       
    68 
       
    69 	// make read/write
       
    70 	User::LeaveIfError(fileSystem.SetAtt(source.FullName(),NULL, KEntryAttReadOnly));
       
    71 
       
    72 	// clean up
       
    73 	CleanupStack::PopAndDestroy(fileMan);
       
    74 	CleanupStack::PopAndDestroy(&fileSystem);
       
    75 	}
       
    76 
       
    77 void CTestStepCommDb::deleteFileL(const TDesC& aFileName)
       
    78 	{
       
    79 	// create a fileserver
       
    80 	RFs  fileSystem;
       
    81 
       
    82 	User::LeaveIfError(fileSystem.Connect());
       
    83 	CleanupClosePushL(fileSystem);
       
    84 
       
    85 	INFO_PRINTF1(_L("Set file to read-write in order to delete"));
       
    86 
       
    87 	// Remove read only flag
       
    88 	TInt ret = fileSystem.SetAtt(aFileName, 0, KEntryAttReadOnly);
       
    89 	if (ret == KErrNotFound)
       
    90 		{
       
    91 		// If file already removed then no need to delete it
       
    92 		INFO_PRINTF1(_L("File not found"));
       
    93 		CleanupStack::PopAndDestroy(&fileSystem);
       
    94 		return;
       
    95 		}
       
    96 	User::LeaveIfError(ret);
       
    97 
       
    98 	// Delete file
       
    99 	User::LeaveIfError(fileSystem.Delete(aFileName));
       
   100 	INFO_PRINTF1(_L("deleted file"));
       
   101 
       
   102 	// clean up
       
   103 	CleanupStack::PopAndDestroy(&fileSystem);
       
   104 	}
       
   105 
       
   106 void CTestStepCommDb::DeleteCurrentDatabaseL()
       
   107 	{
       
   108 	RDbs rDbs;
       
   109 
       
   110 //	User::LeaveIfError(rDbs.Connect());
       
   111 	TInt ret(KErrNone);
       
   112 	ret = rDbs.Connect();
       
   113 	if(ret!=KErrNone)
       
   114 		{
       
   115 		INFO_PRINTF2(_L("CTestStepCommDb::DeleteCurrentDatabaseL : rDbs.Connect FAILED with %d"),ret );
       
   116 		User::Leave(ret);
       
   117 		}
       
   118 
       
   119 	CleanupClosePushL(rDbs);
       
   120 	TName commDb(KCDrive);
       
   121 	commDb.Append(KDbBaseName);
       
   122 	TUid KCommsDbFileUid = { 0x10004e1d };
       
   123 	// May need to make several
       
   124 	// attempts if it is transiently locked; report these and if
       
   125 	// not successful after a number of attempts report this and abort
       
   126 	TInt remainingTries = 5;
       
   127 //	TInt ret (KErrNone);
       
   128 	while(remainingTries-- > 0)
       
   129 		{
       
   130 		ret = rDbs.DeleteDatabase(commDb, KCommsDbFileUid);
       
   131 		if(ret == KErrNone || ret == KErrPathNotFound || ret == KErrNotFound)
       
   132 			{
       
   133 			ret = KErrNone;
       
   134 			break;
       
   135 			}
       
   136 		else
       
   137 			{
       
   138 			INFO_PRINTF4(_L("CTestStepCommDb::DeleteCurrentDatabaseL : rDbs.DeleteDatabase FAILED to delete %S %S with %d"),&KCDrive,&KDbBaseName,ret);
       
   139 			}
       
   140 		}
       
   141 	User::LeaveIfError(ret);
       
   142 	CleanupStack::PopAndDestroy(&rDbs);
       
   143 	}
       
   144 
       
   145 void CTestStepCommDb::CopyDatabaseL(const TDesC& aSource)
       
   146 	{
       
   147 	RFs fs;
       
   148 	User::LeaveIfError(fs.Connect());
       
   149 	CleanupClosePushL(fs);
       
   150 
       
   151 	RDbs rDbs;
       
   152 	User::LeaveIfError(rDbs.Connect());
       
   153 	CleanupClosePushL(rDbs);
       
   154 	const TUid KCommsDbFileUid = {0x10004e1d};
       
   155 
       
   156 	TInt remainingTries = 5;
       
   157 	TInt ret (KErrNone);
       
   158 	DeleteCurrentDatabaseL();
       
   159 	while(remainingTries-- > 0)
       
   160 		{
       
   161 		ret = rDbs.CopyDatabase(aSource, KDbFileName, KCommsDbFileUid);
       
   162 		if(ret == KErrNone || ret == KErrPathNotFound || ret == KErrNotFound)
       
   163 			{
       
   164 			break;
       
   165 			}
       
   166 		}
       
   167 	User::LeaveIfError(ret);
       
   168 	CleanupStack::PopAndDestroy(&rDbs);
       
   169 	CleanupStack::PopAndDestroy(&fs);
       
   170 	}
       
   171 
       
   172 
       
   173 TInt CTestStepCommDb::copyTestDatabase( TDatabaseNumber aDbNumber )
       
   174 	{
       
   175 	(void)aDbNumber;
       
   176 	return KErrNone;
       
   177 	}
       
   178 
       
   179 TInt CTestStepCommDb::copyDatabaseToDefault( TDatabaseNumber aDbNumber )
       
   180 	{
       
   181 	(void)aDbNumber;
       
   182 	return KErrNone;
       
   183 	}
       
   184 
       
   185 TBool CTestStepCommDb::openDbAndViewL( const TDesC16& aTable )
       
   186 	{
       
   187 	TBool created = EFalse;
       
   188 
       
   189 	//Only create Db and view objects if they're not already created
       
   190 	if ( ! iTheDb )
       
   191 		{
       
   192 		iTheDb=CCommsDatabase::NewL();
       
   193 		created = ETrue;
       
   194 		}
       
   195 
       
   196 	if ( !iTheView )
       
   197 		{
       
   198 		iTheView=iTheDb->OpenTableLC( aTable );
       
   199 		CleanupStack::Pop(); //no need to put it on the cleanup stack
       
   200 		}
       
   201 
       
   202 	return created;
       
   203 	}
       
   204 
       
   205 TVerdict CTestStepCommDb::doTestStepPostambleL()
       
   206 	{
       
   207 	if ( iTheView )
       
   208 		{
       
   209 		delete iTheView;
       
   210 		iTheView = 0;
       
   211 		}
       
   212 
       
   213 	if ( iTheDb )
       
   214 		{
       
   215 		delete iTheDb;
       
   216 		iTheDb = 0;
       
   217 		}
       
   218 
       
   219         SetTestStepResult(EPass);	return TestStepResult();
       
   220 	}
       
   221 
       
   222 
       
   223 
       
   224 void CTestStepCommDb::popAndDestroyDatabaseObjects()
       
   225 	{
       
   226 		// doTestStepPostambleL();
       
   227 	}
       
   228 
       
   229 TBool CTestStepCommDb::openDbL()
       
   230 	{
       
   231 
       
   232 	TBool created = EFalse;
       
   233 
       
   234 	if ( !iTheDb )
       
   235 		{
       
   236 		//Only open the Db if its not already open
       
   237 		TRAPD(ret,iTheDb=CCommsDatabase::NewL());
       
   238 		if(ret!=KErrNone)
       
   239 			{
       
   240 			INFO_PRINTF2(_L("CTestStepCommDb::openDbL : CCommsDatabase::NewL LEFT with %d"),ret);
       
   241 			User::Leave(ret);
       
   242 			}
       
   243 		created = ETrue;
       
   244 		}
       
   245 	return created;
       
   246 
       
   247 	}
       
   248 
       
   249 void CTestStepCommDb::setRemoteDatabaseObjects( CCommsDatabase* aDb, CCommsDbTableView* aDbView )
       
   250 	{
       
   251 		if ( !iTheDb )
       
   252 			{
       
   253 			//make sure that no-one else has already set the objects
       
   254 			iTheDb = aDb;
       
   255 			iTheView = aDbView;
       
   256 			iRemoteObjects = ETrue;
       
   257 			}
       
   258 	}
       
   259 
       
   260 
       
   261 void CTestStepCommDb::clearRemoteDatabaseObjects()
       
   262 	{
       
   263 		if( iRemoteObjects )
       
   264 			{
       
   265 			//Only clear objects if they were previously set remotly
       
   266 			iTheDb = 0;
       
   267 			iTheView = 0;
       
   268 			}
       
   269 	}
       
   270 
       
   271 TInt CTestStepCommDb::executeStepL()
       
   272 	{
       
   273 		return KErrGeneral;
       
   274 	}
       
   275 
       
   276 
       
   277 TInt CTestStepCommDb::executeStep(CTestStepCommDb& aTestStep)
       
   278 	{
       
   279 	TInt r,ret= KErrNone;
       
   280 
       
   281 	TRAP( r, ret = aTestStep.executeStepL() );
       
   282 
       
   283 	if ( r != KErrNone )
       
   284 		ret = r;
       
   285 
       
   286 	return ret;
       
   287 	}
       
   288 
       
   289 TInt CTestStepCommDb::executeStep( )
       
   290 	{
       
   291 	TInt ret=0;
       
   292 
       
   293 	TRAPD( r, ret = executeStepL() );
       
   294 
       
   295 	if ( r != KErrNone )
       
   296 		ret = r;
       
   297 
       
   298 	return ret;
       
   299 	}
       
   300 
       
   301 //
       
   302 //This heap failure member function is used when a test step needs a Database and a View
       
   303 //object.
       
   304 //
       
   305 TInt CTestStepCommDb::doTestStepWithHeapFailureL( CTestStepCommDb& aTestStep, TInt aReturnValue)
       
   306 	{
       
   307 	TInt ret=0;
       
   308 
       
   309 	for (TInt i=1; i< KHeapFailure ; i++)
       
   310 		{
       
   311 		aTestStep.doTestStepPreambleL();
       
   312 
       
   313 		__UHEAP_FAILNEXT(i);
       
   314 
       
   315 		ret = aTestStep.executeStep();
       
   316 
       
   317 		__UHEAP_RESET;
       
   318 
       
   319 		aTestStep.doTestStepPostambleL();
       
   320 
       
   321 		if ( ret == KErrNoMemory )
       
   322 			{
       
   323 			//The heap failure has been trapped correctly
       
   324 			continue;
       
   325 			}
       
   326 		else if ( ret == aReturnValue )
       
   327 			{
       
   328 			//Test step normal behaviour
       
   329 			INFO_PRINTF4(_L("%S PASSED heap failure test, i = %d return code==%d"),
       
   330 				&aTestStep.TestStepName(), i, ret );
       
   331 
       
   332 			break;
       
   333 			}
       
   334 		else
       
   335 			{
       
   336 			// test step has not returned the exepected error value ( which was either KErrNoMemory or aReturnValue );
       
   337 			INFO_PRINTF5(_L("%S *FAILED* heap failure test, i=%d return code:%d expected:%d"),
       
   338 				&aTestStep.TestStepName(), i, ret, aReturnValue );
       
   339 			SetTestStepResult(EFail);			break;
       
   340 			}
       
   341 
       
   342 		}
       
   343 
       
   344 	return KErrNone;
       
   345 	}
       
   346 
       
   347 void CTestStepCommDb::CheckTableIsProtectedL(CCommsDbProtectTableView* aTable)
       
   348 	{
       
   349 
       
   350 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   351 
       
   352 	if(aTable->GotoFirstRecord()==KErrNone)
       
   353 		{
       
   354 		// Check settings on Record
       
   355 		RDbRowSet::TAccess tableAccess = RDbRowSet::EUpdatable;
       
   356 		TInt ret = aTable->GetTableAccess(tableAccess);
       
   357 		TESTL(ret == KErrNone);
       
   358 		TESTL(tableAccess == RDbRowSet::EReadOnly);
       
   359 
       
   360 		// Test that first record cannot be updated
       
   361 		TRAP(ret,UpdateRecordL(aTable,KErrAccessDenied));
       
   362 		TESTL(ret == KErrNone);
       
   363 
       
   364 		// Test that cannot delete first record
       
   365 		TRAP(ret,DeleteRecordL(aTable,KErrAccessDenied));
       
   366 		TESTL(ret == KErrNone);
       
   367 
       
   368 		// Test that cannot insert new record
       
   369 		TRAP(ret,InsertRecordL(aTable,KErrAccessDenied));
       
   370 		TESTL(ret == KErrNone);
       
   371 
       
   372 		aTable->GotoFirstRecord();
       
   373 		}
       
   374 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   375 	}
       
   376 
       
   377 
       
   378 void CTestStepCommDb::CheckTableIsProtectedL(CCommsDbProtectConnectPrefTableView* aTable)
       
   379 	{
       
   380 
       
   381 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   382 	if(aTable->GotoFirstRecord()==KErrNone)
       
   383 		{
       
   384 		// Check settings on Record
       
   385 		RDbRowSet::TAccess tableAccess = RDbRowSet::EUpdatable;
       
   386 		TInt ret = aTable->GetTableAccess(tableAccess);
       
   387 		TESTL(ret == KErrNone);
       
   388 		TESTL(tableAccess == RDbRowSet::EReadOnly);
       
   389 
       
   390 		// Test that first record cannot be updated
       
   391 		TRAP(ret,UpdateRecordL(aTable,KErrAccessDenied));
       
   392 		TESTL(ret == KErrNone);
       
   393 
       
   394 		// Test that cannot delete first record
       
   395 		TRAP(ret,DeleteRecordL(aTable,KErrAccessDenied));
       
   396 		TESTL(ret == KErrNone);
       
   397 
       
   398 		// Test that cannot insert new record
       
   399 		TRAP(ret,InsertRecordL(aTable,KErrAccessDenied));
       
   400 		TESTL(ret == KErrNone);
       
   401 
       
   402 		aTable->GotoFirstRecord();
       
   403 		}
       
   404 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   405 	}
       
   406 
       
   407 void CTestStepCommDb::CheckTableIsNotProtectedL(CCommsDbProtectTableView* aTable)
       
   408 	{
       
   409 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   410 	if(aTable->GotoFirstRecord()==KErrNone)
       
   411 		{
       
   412 		// Check settings on Table
       
   413 		RDbRowSet::TAccess tableAccess = RDbRowSet::EReadOnly;
       
   414 		TInt ret = aTable->GetTableAccess(tableAccess);
       
   415 		TESTL(ret == KErrNone);
       
   416 		TESTL(tableAccess == RDbRowSet::EUpdatable);
       
   417 
       
   418 		// Test can update first record
       
   419 		TRAP(ret,UpdateRecordL(aTable,KErrNone));
       
   420 		TESTL(ret == KErrNone);
       
   421 
       
   422 		// Test that can delete record
       
   423 		TRAP(ret,DeleteRecordL(aTable,KErrNone));
       
   424 		TESTL(ret == KErrNone);
       
   425 
       
   426 		// Test that can insert new record
       
   427 		TRAP(ret,InsertRecordL(aTable,KErrNone));
       
   428 		TESTL(ret == KErrNone);
       
   429 
       
   430 		aTable->GotoFirstRecord();
       
   431 		}
       
   432 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   433 	}
       
   434 
       
   435 void CTestStepCommDb::CheckTableIsNotProtectedL(CCommsDbProtectConnectPrefTableView* aTable)
       
   436 	{
       
   437 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   438 	if(aTable->GotoFirstRecord()==KErrNone)
       
   439 		{
       
   440 		// Check settings on Table
       
   441 		RDbRowSet::TAccess tableAccess = RDbRowSet::EReadOnly;
       
   442 		TInt ret = aTable->GetTableAccess(tableAccess);
       
   443 		TESTL(ret == KErrNone);
       
   444 		TESTL(tableAccess == RDbRowSet::EUpdatable);
       
   445 
       
   446 		// Test can update first record
       
   447 		TRAP(ret,UpdateRecordL(aTable,KErrNone));
       
   448 		TESTL(ret == KErrNone);
       
   449 
       
   450 		// Test that can delete record
       
   451 		TRAP(ret,DeleteRecordL(aTable,KErrNone));
       
   452 		TESTL(ret == KErrNone);
       
   453 
       
   454 		// Test that can insert new record
       
   455 		TRAP(ret,InsertRecordL(aTable,KErrNone));
       
   456 		TESTL(ret == KErrNone);
       
   457 
       
   458 		aTable->GotoFirstRecord();
       
   459 		}
       
   460 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   461 	}
       
   462 
       
   463 void CTestStepCommDb::GoToPositionL(CCommsDbProtectTableView* aTable,TInt aPos)
       
   464 	{
       
   465 	TESTL(aTable->GotoFirstRecord()==KErrNone);
       
   466 	for (TInt i = 0; i < aPos; i++)
       
   467 		{
       
   468 		TESTL(aTable->GotoNextRecord()==KErrNone);
       
   469 		}
       
   470 	}
       
   471 
       
   472 void CTestStepCommDb::ProtectRecordL(CCommsDbProtectTableView* aTable, TInt aResult)
       
   473 	{
       
   474 	TESTL(aTable->ProtectRecord()==aResult);
       
   475 	}
       
   476 
       
   477 void CTestStepCommDb::ProtectRecordL(CCommsDbProtectConnectPrefTableView* aTable, TInt aResult)
       
   478 	{
       
   479 	TESTL(aTable->ProtectRecord()==aResult);
       
   480 	}
       
   481 
       
   482 void CTestStepCommDb::UnprotectRecordL(CCommsDbProtectTableView* aTable, TInt aResult)
       
   483 	{
       
   484 	TESTL(aTable->UnprotectRecord()==aResult);
       
   485 	}
       
   486 
       
   487 void CTestStepCommDb::UnprotectRecordL(CCommsDbProtectConnectPrefTableView* aTable, TInt aResult)
       
   488 	{
       
   489 	TESTL(aTable->UnprotectRecord()==aResult);
       
   490 	}
       
   491 
       
   492 void CTestStepCommDb::UpdateRecordL(CCommsDbProtectTableView* aTable, TInt aResult)
       
   493 	{
       
   494 
       
   495 	TESTL(aTable->UpdateRecord()==aResult);
       
   496 	if (aResult == KErrNone)
       
   497 		{
       
   498 		ModifyRecordL(aTable);
       
   499 		TESTL(aTable->PutRecordChanges()==KErrNone);
       
   500 		}
       
   501 	}
       
   502 
       
   503 void CTestStepCommDb::UpdateRecordL(CCommsDbProtectConnectPrefTableView* aTable, TInt aExpectedResult)
       
   504 	{
       
   505 
       
   506 	TUint32 Ranking;
       
   507 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref RecordData;
       
   508 
       
   509 	TInt ErrVal = ChangeCPRankingL(aTable, Ranking); // Try modifying a field.
       
   510 
       
   511 	TESTL(ErrVal == aExpectedResult);
       
   512 
       
   513 	if (ErrVal == KErrNone)
       
   514 		{
       
   515 		// The change was allowed, so check it actually happened.
       
   516 		aTable->ReadConnectionPreferenceL(RecordData);
       
   517 		TESTL(Ranking == RecordData.iRanking);
       
   518 		}
       
   519 	}
       
   520 
       
   521 void CTestStepCommDb::DeleteRecordL(CCommsDbProtectTableView* aTable, TInt aResult)
       
   522 	{
       
   523 	TESTL(aTable->DeleteRecord()==aResult);
       
   524 	}
       
   525 
       
   526 void CTestStepCommDb::DeleteRecordL(CCommsDbProtectConnectPrefTableView* aTable, TInt aExpectedResult)
       
   527 	{
       
   528 	TRAPD(ErrVal, aTable->DeleteConnectionPreferenceL());
       
   529 	TESTL(ErrVal == aExpectedResult);
       
   530 	}
       
   531 
       
   532 void CTestStepCommDb::InsertRecordL(CCommsDbProtectTableView* aTable, TInt aExpectedResult)
       
   533 	{
       
   534 	TUint32 recordId;
       
   535 	TInt ret = aTable->InsertRecord(recordId);
       
   536 	TESTL(ret==aExpectedResult||ret==KErrAlreadyExists); //for some tables insertion fails
       
   537 											  //because they can only have
       
   538 											//one record (i.e. DEFAULT_GPRS)
       
   539 	if (ret == KErrNone)
       
   540 		{
       
   541 		PopulateInsertedRecordL(aTable);
       
   542 		TESTL(aTable->PutRecordChanges()==KErrNone);
       
   543 		}
       
   544 	}
       
   545 
       
   546 void CTestStepCommDb::InsertRecordL(CCommsDbProtectConnectPrefTableView* aTable, TInt aExpectedResult)
       
   547 	{
       
   548 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref PrefData1, PrefData2;
       
   549 
       
   550 	PrefData1.iRanking = 0;
       
   551 	PrefData1.iDirection = ECommDbConnectionDirectionOutgoing;
       
   552 	PrefData1.iDialogPref = ECommDbDialogPrefWarn;
       
   553 	PrefData1.iBearer.iBearerSet = ECommDbBearerCSD;
       
   554 	PrefData1.iBearer.iIapId = 1;
       
   555 
       
   556 	TRAPD(ErrVal, aTable->InsertConnectionPreferenceL(PrefData1));
       
   557 	TESTL(ErrVal==aExpectedResult); //for some tables insertion fails
       
   558 											  //because they can only have
       
   559 											//one record (i.e. DEFAULT_GPRS)
       
   560 	if (ErrVal == KErrNone)
       
   561 		{
       
   562 		aTable->ReadConnectionPreferenceL(PrefData2);
       
   563 		TESTL(PrefData1 == PrefData2);
       
   564 		}
       
   565 	}
       
   566 
       
   567 
       
   568 #define TEST_FCN(_F_)		{TRAPD(ret,_F_); TESTL(ret == KErrNone);}
       
   569 
       
   570 void CTestStepCommDb::ModifyRecordL(CCommsDbProtectTableView* aTable)
       
   571 //
       
   572 // Modify some field in current record
       
   573 //
       
   574 	{
       
   575 	TEST_FCN(aTable->WriteTextL(TPtrC(COMMDB_NAME),_L("test")));
       
   576 	}
       
   577 // Extract the protection state for the current record,
       
   578 // and leave if it's not the state expected
       
   579 void CTestStepCommDb::CheckRecordAccessL(CCommsDbProtectConnectPrefTableView* aTable, TInt aExpectedAccess)
       
   580 	{
       
   581 	TInt FoundAccess;
       
   582 	// Set the state to one not expected, so it will fail if not explicitly changed
       
   583 	if (aExpectedAccess == RDbRowSet::EUpdatable)
       
   584 		FoundAccess = RDbRowSet::EReadOnly;
       
   585 	else
       
   586 		FoundAccess = RDbRowSet::EUpdatable;
       
   587 
       
   588 	TESTL(aTable->GetRecordAccess(FoundAccess) == KErrNone);
       
   589 	TESTL(aExpectedAccess == FoundAccess);
       
   590 	}
       
   591 void CTestStepCommDb::PopulateInsertedRecordL(CCommsDbProtectTableView* aTable)
       
   592 //
       
   593 // Populate minimal set of fields in current newly inserted record.
       
   594 //
       
   595 	{
       
   596 	TBuf<50> tableName;
       
   597 	aTable->GetTableName(tableName);
       
   598 
       
   599 	if (tableName == TPtrC(DIAL_OUT_ISP))
       
   600 		{
       
   601 		TEST_FCN(aTable->WriteTextL(TPtrC(COMMDB_NAME),_L("Inserted Service")));
       
   602 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue));
       
   603 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse));
       
   604 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue));
       
   605 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue));
       
   606 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue));
       
   607 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue));
       
   608 		TEST_FCN(aTable->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue));
       
   609 		}
       
   610 
       
   611 	// EXTEND OR MODIFY this function if want to use different table
       
   612 	}
       
   613 // Just a utility function - for checking the protection of the Connection Preferences
       
   614 // table and its records, we just try changing the ranking field of the first one.
       
   615 TInt CTestStepCommDb::ChangeCPRankingL(CCommsDbProtectConnectPrefTableView* aTable, TUint32& Ranking)
       
   616 	{
       
   617 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref  RecordData;
       
   618 
       
   619 	aTable->ReadConnectionPreferenceL(RecordData);
       
   620 	if(RecordData.iRanking == 1)
       
   621 		Ranking = 0;
       
   622 	else
       
   623 		Ranking = 1;
       
   624 	TRAPD(ErrVal, aTable->ChangeConnectionPreferenceRankL(Ranking));
       
   625 	return(ErrVal);
       
   626 	}
       
   627 
       
   628 #undef TEST_FCN