commsconfig/commsdatabaseshim/ts_commdb/Step_034_xx.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     1 // Copyright (c) 2001-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 // This contains CommDb Unit Test Cases 034.XX
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 #include <commdb.h>
       
    21 #include <d32comm.h>
       
    22 
       
    23 // Test system includes
       
    24 #include <networking/log.h>
       
    25 #include <networking/teststep.h>
       
    26 #include "Teststepcommdb.h"
       
    27 #include "TestSuiteCommdb.h"
       
    28 #include "Step_034_xx.h"
       
    29 
       
    30 
       
    31 CCommDbTest034_01::CCommDbTest034_01()
       
    32 	{
       
    33 	// store the name of this test case
       
    34 	iTestStepName = _L("step_034_01");
       
    35 	}
       
    36 
       
    37 CCommDbTest034_01::~CCommDbTest034_01()
       
    38 	{}
       
    39 
       
    40 TVerdict CCommDbTest034_01::doTestStepL( void )
       
    41 	{
       
    42 	executeStepL();
       
    43 	return EPass;	//If we've got this far we've passed
       
    44 	}
       
    45 
       
    46 TVerdict CCommDbTest034_01::doTestStepPreambleL()
       
    47 	{
       
    48 	iTheDb=CCommsDatabase::NewL();
       
    49 
       
    50 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
    51 	CleanupStack::Pop();
       
    52 
       
    53 	return EPass;
       
    54 	}
       
    55 
       
    56 TInt CCommDbTest034_01::executeStepL()
       
    57 	{
       
    58 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref1;
       
    59 	pref1.iRanking = 1;
       
    60 	pref1.iDirection = ECommDbConnectionDirectionOutgoing;
       
    61 	pref1.iDialogPref = ECommDbDialogPrefPrompt;
       
    62 	pref1.iBearer.iBearerSet = KCommDbBearerCSD;
       
    63 	pref1.iBearer.iIapId = 1;
       
    64 
       
    65 	iPrefView->InsertConnectionPreferenceL(pref1, EFalse);
       
    66 
       
    67 	User::LeaveIfError(iPrefView->GotoFirstRecord());
       
    68 	iPrefView->ChangeConnectionPreferenceRankL(2);
       
    69 
       
    70 	return KErrNone;
       
    71 	}
       
    72 	
       
    73 TVerdict CCommDbTest034_01::doTestStepPostambleL()
       
    74 	{
       
    75 		//Get rid of our view
       
    76 	if(iPrefView)
       
    77 		{
       
    78 		delete iPrefView;
       
    79 		}
       
    80 	iPrefView=0;
       
    81 
       
    82 	//Create a new view that should have the record that was added in executeStepL and
       
    83 	// may have been left in by a leave condition
       
    84 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
    85 	CleanupStack::Pop();
       
    86 
       
    87 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
    88 		{
       
    89 		iPrefView->DeleteConnectionPreferenceL();
       
    90 		}
       
    91 	
       
    92 	// Cleanup after test run
       
    93 	CTestStepCommDb::doTestStepPostambleL();	
       
    94 	return EPass;
       
    95 	}
       
    96 
       
    97 //
       
    98 
       
    99 CCommDbTest034_02::CCommDbTest034_02()
       
   100 	{
       
   101 	// store the name of this test case
       
   102 	iTestStepName = _L("step_034_02");
       
   103 	}
       
   104 
       
   105 CCommDbTest034_02::~CCommDbTest034_02()
       
   106 	{}
       
   107 
       
   108 TVerdict CCommDbTest034_02::doTestStepL( void )
       
   109 	{
       
   110 	if(executeStepL()!=KErrNone)
       
   111 		return EFail;
       
   112 	return EPass;
       
   113 	}
       
   114 
       
   115 TVerdict CCommDbTest034_02::doTestStepPreambleL()
       
   116 	{
       
   117 	iTheDb=CCommsDatabase::NewL();
       
   118 
       
   119 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   120 	CleanupStack::Pop();
       
   121 
       
   122 	return EPass;
       
   123 	}
       
   124 
       
   125 TInt CCommDbTest034_02::executeStepL()
       
   126 	{
       
   127 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref1;
       
   128 	pref1.iRanking = 1;
       
   129 	pref1.iDirection = ECommDbConnectionDirectionOutgoing;
       
   130 	pref1.iDialogPref = ECommDbDialogPrefPrompt;
       
   131 	pref1.iBearer.iBearerSet = KCommDbBearerCSD;
       
   132 	pref1.iBearer.iIapId = 1;
       
   133 
       
   134 	iPrefView->InsertConnectionPreferenceL(pref1, EFalse);
       
   135 
       
   136 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref2;
       
   137 	pref2.iRanking = 2;
       
   138 	pref2.iDirection = ECommDbConnectionDirectionOutgoing;
       
   139 	pref2.iDialogPref = ECommDbDialogPrefPrompt;
       
   140 	pref2.iBearer.iBearerSet = KCommDbBearerCSD;
       
   141 	pref2.iBearer.iIapId = 2;
       
   142 	
       
   143 	iPrefView->InsertConnectionPreferenceL(pref2, EFalse);
       
   144 
       
   145 	User::LeaveIfError(iPrefView->GotoFirstRecord());
       
   146 	iPrefView->ChangeConnectionPreferenceRankL(2);
       
   147 
       
   148 	User::LeaveIfError(iPrefView->GotoNextRecord());
       
   149 
       
   150 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref retrievedPref;
       
   151 	iPrefView->ReadConnectionPreferenceL(retrievedPref);
       
   152 
       
   153 	if(retrievedPref.iRanking!=0)
       
   154 		return KErrGeneral;		//pref2 should have it's ranking displaced to 0 by ChangeConnectionPreferenceRankL
       
   155 
       
   156 	return KErrNone;
       
   157 	}
       
   158 	
       
   159 TVerdict CCommDbTest034_02::doTestStepPostambleL()
       
   160 	{
       
   161 		//Get rid of our view
       
   162 	if(iPrefView)
       
   163 		{
       
   164 		delete iPrefView;
       
   165 		}
       
   166 	iPrefView=0;
       
   167 
       
   168 	//Create a new view that should have the record that was added in executeStepL and
       
   169 	// may have been left in by a leave condition
       
   170 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   171 	CleanupStack::Pop();
       
   172 
       
   173 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   174 		{
       
   175 		iPrefView->DeleteConnectionPreferenceL();
       
   176 		}
       
   177 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   178 		{
       
   179 		iPrefView->DeleteConnectionPreferenceL();
       
   180 		}
       
   181 	
       
   182 	// Cleanup after test run
       
   183 	CTestStepCommDb::doTestStepPostambleL();	
       
   184 	return EPass;
       
   185 	}
       
   186 
       
   187 //
       
   188 
       
   189 CCommDbTest034_03::CCommDbTest034_03()
       
   190 	{
       
   191 	// store the name of this test case
       
   192 	iTestStepName = _L("step_034_03");
       
   193 	}
       
   194 
       
   195 CCommDbTest034_03::~CCommDbTest034_03()
       
   196 	{}
       
   197 
       
   198 TVerdict CCommDbTest034_03::doTestStepL( void )
       
   199 	{
       
   200 	if(executeStepL()!=KErrNone)
       
   201 		return EFail;
       
   202 	return EPass;
       
   203 	}
       
   204 
       
   205 TVerdict CCommDbTest034_03::doTestStepPreambleL()
       
   206 	{
       
   207 	iTheDb=CCommsDatabase::NewL();
       
   208 
       
   209 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   210 	CleanupStack::Pop();
       
   211 
       
   212 	return EPass;
       
   213 	}
       
   214 
       
   215 TInt CCommDbTest034_03::executeStepL()
       
   216 	{
       
   217 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref1;
       
   218 	pref1.iRanking = 1;
       
   219 	pref1.iDirection = ECommDbConnectionDirectionOutgoing;
       
   220 	pref1.iDialogPref = ECommDbDialogPrefPrompt;
       
   221 	pref1.iBearer.iBearerSet = KCommDbBearerCSD;
       
   222 	pref1.iBearer.iIapId = 1;
       
   223 
       
   224 	iPrefView->InsertConnectionPreferenceL(pref1, EFalse);
       
   225 
       
   226 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref2;
       
   227 	pref2.iRanking = 2;
       
   228 	pref2.iDirection = ECommDbConnectionDirectionOutgoing;
       
   229 	pref2.iDialogPref = ECommDbDialogPrefPrompt;
       
   230 	pref2.iBearer.iBearerSet = KCommDbBearerCSD;
       
   231 	pref2.iBearer.iIapId = 2;
       
   232 	
       
   233 	iPrefView->InsertConnectionPreferenceL(pref2, EFalse);
       
   234 
       
   235 	User::LeaveIfError(iPrefView->GotoFirstRecord());
       
   236 	TRAPD(err, iPrefView->ChangeConnectionPreferenceRankL(5));
       
   237 	if (err!=KErrOverflow)
       
   238 		{
       
   239 		if(err==KErrNone)		//This is horrible, but need to make sure that if this returns with KErrNone we catch it.
       
   240 			err=KErrGeneral;
       
   241 		return err;
       
   242 		}
       
   243 
       
   244 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref retrievedPref;
       
   245 	iPrefView->ReadConnectionPreferenceL(retrievedPref);
       
   246 
       
   247 	if(retrievedPref.iRanking!=1)
       
   248 		return KErrGeneral;		//pref1 should still have ranking 1
       
   249 
       
   250 	return KErrNone;
       
   251 	}
       
   252 	
       
   253 TVerdict CCommDbTest034_03::doTestStepPostambleL()
       
   254 	{
       
   255 		//Get rid of our view
       
   256 	if(iPrefView)
       
   257 		{
       
   258 		delete iPrefView;
       
   259 		}
       
   260 	iPrefView=0;
       
   261 
       
   262 	//Create a new view that should have the record that was added in executeStepL and
       
   263 	// may have been left in by a leave condition
       
   264 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   265 	CleanupStack::Pop();
       
   266 
       
   267 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   268 		{
       
   269 		iPrefView->DeleteConnectionPreferenceL();
       
   270 		}
       
   271 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   272 		{
       
   273 		iPrefView->DeleteConnectionPreferenceL();
       
   274 		}
       
   275 	
       
   276 	// Cleanup after test run
       
   277 	CTestStepCommDb::doTestStepPostambleL();	
       
   278 	return EPass;
       
   279 	}
       
   280 
       
   281 //
       
   282 
       
   283 CCommDbTest034_04::CCommDbTest034_04()
       
   284 	{
       
   285 	// store the name of this test case
       
   286 	iTestStepName = _L("step_034_04");
       
   287 	}
       
   288 
       
   289 CCommDbTest034_04::~CCommDbTest034_04()
       
   290 	{}
       
   291 
       
   292 TVerdict CCommDbTest034_04::doTestStepL( void )
       
   293 	{
       
   294 	if (executeStepL() != KErrNotFound)
       
   295 		{
       
   296 		iTestStepResult = EFail;
       
   297 		}
       
   298 
       
   299 	return iTestStepResult;
       
   300 	}
       
   301 
       
   302 TVerdict CCommDbTest034_04::doTestStepPreambleL()
       
   303 	{
       
   304 	iTheDb=CCommsDatabase::NewL();
       
   305 
       
   306 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   307 	CleanupStack::Pop();
       
   308 
       
   309 	return EPass;
       
   310 	}
       
   311 
       
   312 TInt CCommDbTest034_04::executeStepL()
       
   313 	{
       
   314 	//
       
   315 	// Previously (I guess) CommDB would have been able to create two
       
   316 	// Conn Pref entries and then the fresh view would not have seen them
       
   317 	// and it would panic. Now CommsDAT does see them and returns
       
   318 	// KErrNotFound, so now we no longer inserted in this test allowing
       
   319 	// the test to actually test the expected scenario.
       
   320 	//
       
   321 	delete iPrefView;		//Create a fresh view
       
   322 	iPrefView=NULL;
       
   323 	iPrefView=iTheDb->OpenConnectionPrefTableLC();
       
   324 	CleanupStack::Pop();
       
   325 	TRAPD(err, iPrefView->ChangeConnectionPreferenceRankL(2));
       
   326 
       
   327 	return err;
       
   328 	}
       
   329 	
       
   330 TVerdict CCommDbTest034_04::doTestStepPostambleL()
       
   331 	{
       
   332 		//Get rid of our view
       
   333 	if(iPrefView)
       
   334 		{
       
   335 		delete iPrefView;
       
   336 		}
       
   337 	iPrefView=0;
       
   338 
       
   339 	//Create a new view that should have the record that was added in executeStepL and
       
   340 	// may have been left in by a leave condition
       
   341 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   342 	CleanupStack::Pop();
       
   343 
       
   344 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   345 		{
       
   346 		iPrefView->DeleteConnectionPreferenceL();
       
   347 		}
       
   348 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   349 		{
       
   350 		iPrefView->DeleteConnectionPreferenceL();
       
   351 		}
       
   352 	
       
   353 	// Cleanup after test run
       
   354 	CTestStepCommDb::doTestStepPostambleL();	
       
   355 	return EPass;
       
   356 	}
       
   357 
       
   358 //
       
   359 
       
   360 CCommDbTest034_05::CCommDbTest034_05()
       
   361 	{
       
   362 	// store the name of this test case
       
   363 	iTestStepName = _L("step_034_05");
       
   364 	}
       
   365 
       
   366 CCommDbTest034_05::~CCommDbTest034_05()
       
   367 	{}
       
   368 
       
   369 TVerdict CCommDbTest034_05::doTestStepL( void )
       
   370 	{
       
   371 	if(executeStepL()!=KErrNone)
       
   372 		return EFail;
       
   373 	return EPass;
       
   374 	}
       
   375 
       
   376 TVerdict CCommDbTest034_05::doTestStepPreambleL()
       
   377 	{
       
   378 	iTheDb=CCommsDatabase::NewL();
       
   379 
       
   380 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   381 	CleanupStack::Pop();
       
   382 
       
   383 	return EPass;
       
   384 	}
       
   385 
       
   386 TInt CCommDbTest034_05::executeStepL()
       
   387 	{
       
   388 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref1;
       
   389 	pref1.iRanking = 1;
       
   390 	pref1.iDirection = ECommDbConnectionDirectionOutgoing;
       
   391 	pref1.iDialogPref = ECommDbDialogPrefPrompt;
       
   392 	pref1.iBearer.iBearerSet = KCommDbBearerCSD;
       
   393 	pref1.iBearer.iIapId = 1;
       
   394 
       
   395 	iPrefView->InsertConnectionPreferenceL(pref1, ETrue);
       
   396 
       
   397 	User::LeaveIfError(iPrefView->GotoFirstRecord());
       
   398 
       
   399 	TRAPD(err, iPrefView->ChangeConnectionPreferenceRankL(2));
       
   400 	if(err!=KErrAccessDenied)
       
   401 		{
       
   402 		if(err==KErrNone)		//Need to do some maping here otherwise if this returns KErrNone the test will pass!!
       
   403 			err=KErrGeneral;
       
   404 		return err;
       
   405 		}
       
   406 
       
   407 	CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref retrievedPref;
       
   408 	iPrefView->ReadConnectionPreferenceL(retrievedPref);
       
   409 	
       
   410 	if(retrievedPref.iRanking!=1)		//The ranking has been changed for a read only entry
       
   411 		return KErrGeneral;
       
   412 
       
   413 	return KErrNone;
       
   414 	}
       
   415 	
       
   416 TVerdict CCommDbTest034_05::doTestStepPostambleL()
       
   417 	{
       
   418 		//Get rid of our view
       
   419 	if(iPrefView)
       
   420 		{
       
   421 		delete iPrefView;
       
   422 		}
       
   423 	iPrefView=0;
       
   424 
       
   425 	//Create a new view that should have the record that was added in executeStepL and
       
   426 	// may have been left in by a leave condition
       
   427 	iPrefView = iTheDb->OpenConnectionPrefTableLC();
       
   428 	CleanupStack::Pop();
       
   429 
       
   430 	if(iPrefView->GotoFirstRecord() == KErrNone)
       
   431 		{
       
   432 		iPrefView->DeleteConnectionPreferenceL();
       
   433 		}
       
   434 	
       
   435 	// Cleanup after test run
       
   436 	CTestStepCommDb::doTestStepPostambleL();	
       
   437 	return EPass;
       
   438 	}
       
   439 
       
   440 //
       
   441 
       
   442 CCommDbTest034_06::CCommDbTest034_06()
       
   443 	{
       
   444 	// store the name of this test case
       
   445 	iTestStepName = _L("step_034_06");
       
   446 	}
       
   447 
       
   448 CCommDbTest034_06::~CCommDbTest034_06()
       
   449 	{}
       
   450 
       
   451 TVerdict CCommDbTest034_06::doTestStepL( void )
       
   452 	{
       
   453 	Log(_L("Step 034.06 called "));
       
   454 
       
   455 	iTestStepResult = EPass;
       
   456 
       
   457 	CCommDbTest034_01* step034_01 = new(ELeave) CCommDbTest034_01;
       
   458 	CleanupStack::PushL(step034_01);
       
   459 	step034_01->iSuite = iSuite;
       
   460 	doTestStepWithHeapFailureL( *step034_01, KErrNone);
       
   461 	CleanupStack::PopAndDestroy(step034_01);
       
   462 
       
   463 	CCommDbTest034_02* step034_02 = new(ELeave) CCommDbTest034_02;
       
   464 	CleanupStack::PushL(step034_02);
       
   465 	step034_02->iSuite = iSuite;
       
   466 	doTestStepWithHeapFailureL( *step034_02, KErrNone);
       
   467 	CleanupStack::PopAndDestroy(step034_02);
       
   468 
       
   469 	CCommDbTest034_03* step034_03 = new(ELeave) CCommDbTest034_03;
       
   470 	CleanupStack::PushL(step034_03);
       
   471 	step034_03->iSuite = iSuite;
       
   472 	doTestStepWithHeapFailureL( *step034_03, KErrNone);
       
   473 	CleanupStack::PopAndDestroy(step034_03);
       
   474 
       
   475 	CCommDbTest034_04* step034_04 = new(ELeave) CCommDbTest034_04;
       
   476 	CleanupStack::PushL(step034_04);
       
   477 	step034_04->iSuite = iSuite;
       
   478 	doTestStepWithHeapFailureL( *step034_04, KErrNotFound);
       
   479 	CleanupStack::PopAndDestroy(step034_04);
       
   480 
       
   481 	CCommDbTest034_05* step034_05 = new(ELeave) CCommDbTest034_05;
       
   482 	CleanupStack::PushL(step034_05);
       
   483 	step034_05->iSuite = iSuite;
       
   484 	doTestStepWithHeapFailureL( *step034_05, KErrNone);
       
   485 	CleanupStack::PopAndDestroy(step034_05);
       
   486 	
       
   487 	return iTestStepResult;
       
   488 	}