commsconfig/commsdatabaseshim/TE_commdb/src/Step_013_xx.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 CommDb Unit Test Cases 013.XX
       
    19 
       
    20 // EPOC includes
       
    21 #include <e32base.h>
       
    22 #include <commdb.h>
       
    23 
       
    24 
       
    25 // Test system includes
       
    26 #include "Teststepcommdb.h"
       
    27 #include "Step_013_xx.h"
       
    28 
       
    29 
       
    30 
       
    31 /////////////////////
       
    32 //	Test step 013.001
       
    33 /////////////////////
       
    34 
       
    35 // constructor
       
    36 CCommDbTest013_01::CCommDbTest013_01()
       
    37 	{
       
    38 	// store the name of this test case
       
    39 	SetTestStepName(_L("step_013_01"));
       
    40 	}
       
    41 
       
    42 // destructor
       
    43 CCommDbTest013_01::~CCommDbTest013_01()
       
    44 	{
       
    45 	}
       
    46 
       
    47 
       
    48 TVerdict CCommDbTest013_01::doTestStepPreambleL()
       
    49 	{	
       
    50 	openDbAndViewL(TPtrC(DIAL_IN_ISP));
       
    51         SetTestStepResult(EPass);	return TestStepResult();
       
    52 	}
       
    53 
       
    54 
       
    55 TInt CCommDbTest013_01::executeStepL()
       
    56 	{
       
    57 	TInt ret=KErrGeneral;
       
    58 
       
    59 
       
    60 	//Update an existing record
       
    61 
       
    62 	CDBLEAVE( iTheView->GotoFirstRecord(), KErrNone );
       
    63 	
       
    64 	//Check the value is what we expect 
       
    65 	TBuf<KCommsDbSvrMaxFieldLength> value;
       
    66 	iTheView->ReadTextL( TPtrC(COMMDB_NAME), value );
       
    67 	TEST( !value.Compare(_L("Record #1")) );
       
    68 
       
    69 	//Update the value in the field
       
    70 	TRAPD(r, iTheView->UpdateRecord() );
       
    71 	iTheView->WriteTextL( TPtrC(COMMDB_NAME), _L("Updated Record #1") );
       
    72 	CDBLEAVE( iTheView->PutRecordChanges(), KErrNone );
       
    73 
       
    74 	delete iTheView;
       
    75 	iTheView = 0;
       
    76 
       
    77 	//Open the view again and check for the updated value
       
    78 	iTheView = iTheDb->OpenTableLC(TPtrC(DIAL_IN_ISP) );
       
    79 	CleanupStack::Pop();
       
    80 
       
    81 	CDBLEAVE( iTheView->GotoFirstRecord(), KErrNone );
       
    82 	iTheView->ReadTextL( TPtrC(COMMDB_NAME), value );
       
    83 	
       
    84 	if ( !value.Compare(_L("Updated Record #1")) )
       
    85 		{
       
    86 		//Found the record, even though it is hidden
       
    87 		ret = KErrNone;
       
    88 		}
       
    89 
       
    90 	if ( r!= KErrNone )
       
    91 		{
       
    92 		ret = r;
       
    93 		}
       
    94 
       
    95 
       
    96 	if ( iLocalObjects )
       
    97 		popAndDestroyDatabaseObjects();
       
    98 
       
    99 	return ret;
       
   100 	}
       
   101 
       
   102 
       
   103 
       
   104 TVerdict CCommDbTest013_01::doTestStepL( )
       
   105 	{
       
   106 	INFO_PRINTF1(_L("Step 013.01 called "));
       
   107 
       
   108 	
       
   109 	if ( executeStepL() == KErrNone )
       
   110 		SetTestStepResult(EPass);	else
       
   111 		SetTestStepResult(EFail);
       
   112 	return TestStepResult();
       
   113 	}
       
   114 
       
   115 
       
   116 /////////////////////
       
   117 //	Test step 013.02
       
   118 /////////////////////
       
   119 
       
   120 // constructor
       
   121 CCommDbTest013_02::CCommDbTest013_02()
       
   122 	{
       
   123 	// store the name of this test case
       
   124 	SetTestStepName(_L("step_013_02"));
       
   125 	}
       
   126 
       
   127 // destructor
       
   128 CCommDbTest013_02::~CCommDbTest013_02()
       
   129 	{
       
   130 	}
       
   131 
       
   132 
       
   133 TVerdict CCommDbTest013_02::doTestStepPreambleL()
       
   134 	{	
       
   135 	openDbL();
       
   136         SetTestStepResult(EPass);	return TestStepResult();
       
   137 	}
       
   138 
       
   139 TInt CCommDbTest013_02::executeStepL()
       
   140 	{
       
   141 	TInt ret=KErrGeneral;
       
   142 	//This view must contain zero records
       
   143 	//NB. This test will crash the server
       
   144 
       
   145 	iTheView = iTheDb->OpenViewLC(TPtrC(DIAL_IN_ISP), _L("Select * from DialInISP where IfNetworks='xxx'") );
       
   146 	CleanupStack::Pop();
       
   147 
       
   148 	CDBLEAVE( iTheView->GotoFirstRecord(), KErrNotFound );
       
   149 	
       
   150 	TRAPD(r, ret = iTheView->UpdateRecord() );
       
   151 
       
   152 	if ( r!= KErrNone )
       
   153 		{
       
   154 		ret = r;
       
   155 		}
       
   156 
       
   157 	return ret;
       
   158 	}
       
   159 
       
   160 
       
   161 
       
   162 TVerdict CCommDbTest013_02::doTestStepL( )
       
   163 	{
       
   164 	TRAPD(ret, executeStepL());
       
   165 	if( ret == KErrNotSupported )
       
   166 		SetTestStepResult(EPass);
       
   167 	else
       
   168 		SetTestStepResult(EFail);
       
   169 	return TestStepResult();
       
   170 	}
       
   171 
       
   172 
       
   173 
       
   174 /////////////////////
       
   175 //	Test step 013.03
       
   176 /////////////////////
       
   177 
       
   178 // constructor
       
   179 CCommDbTest013_03::CCommDbTest013_03()
       
   180 	{
       
   181 	// store the name of this test case
       
   182 	SetTestStepName(_L("step_013_03"));
       
   183 	}
       
   184 
       
   185 // destructor
       
   186 CCommDbTest013_03::~CCommDbTest013_03()
       
   187 	{
       
   188 	}
       
   189 
       
   190 TVerdict CCommDbTest013_03::doTestStepPreambleL()
       
   191 	{	
       
   192 	openDbAndViewL(TPtrC(DIAL_IN_ISP));
       
   193         SetTestStepResult(EPass);	return TestStepResult();
       
   194 	}
       
   195 
       
   196 
       
   197 TInt CCommDbTest013_03::executeStepL()
       
   198 	{
       
   199 	TInt ret=KErrGeneral;
       
   200 	TUint32 id;
       
   201 
       
   202 	//Try to insert a read only record
       
   203 	CDBLEAVE( iTheView->InsertRecord( id ), KErrNone );
       
   204 
       
   205 	//Insert some text
       
   206 	iTheView->WriteTextL( TPtrC(COMMDB_NAME), _L("Example record name") ) ;
       
   207 
       
   208 	//Must write to these columns as they cannot hold null values
       
   209 //	iTheView->WriteTextL(TPtrC(ISP_IF_NAME), _L("PPP") );
       
   210 	iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue);
       
   211 	iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue);
       
   212 	iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue);
       
   213 
       
   214 	//Store the record as hidden
       
   215 	CDBLEAVE( iTheView->PutRecordChanges(EFalse, ETrue), KErrNone );
       
   216 
       
   217 	delete iTheView;
       
   218 	iTheView = 0;
       
   219 
       
   220     iTheView = iTheDb->OpenViewMatchingTextLC(TPtrC(DIAL_IN_ISP), TPtrC(COMMDB_NAME),  _L("Example record name") );
       
   221 	CleanupStack::Pop();
       
   222 	CDBLEAVE( iTheView->GotoFirstRecord(), KErrNone );
       
   223 	TRAPD(r, ret = iTheView->UpdateRecord() );
       
   224 
       
   225 	delete iTheView;
       
   226 	iTheView = 0;
       
   227 
       
   228 
       
   229 	if ( r!= KErrNone )
       
   230 		{
       
   231 		ret = r;
       
   232 		}
       
   233 
       
   234 	return ret;
       
   235 	}
       
   236 
       
   237 
       
   238 
       
   239 TVerdict CCommDbTest013_03::doTestStepL( )
       
   240 	{
       
   241 	INFO_PRINTF1(_L("Step 013.03 called "));
       
   242 
       
   243 	if ( executeStepL() == KErrAccessDenied )
       
   244 		SetTestStepResult(EPass);	else
       
   245 		SetTestStepResult(EFail);
       
   246 	return TestStepResult();
       
   247 	}
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 	
       
   255 /////////////////////
       
   256 //	Test step 013.04
       
   257 /////////////////////
       
   258 
       
   259 // constructor
       
   260 CCommDbTest013_04::CCommDbTest013_04()
       
   261 	{
       
   262 	// store the name of this test case
       
   263 	SetTestStepName(_L("step_013_04"));
       
   264 	}
       
   265 
       
   266 // destructor
       
   267 CCommDbTest013_04::~CCommDbTest013_04()
       
   268 	{
       
   269 	}
       
   270 
       
   271 TVerdict CCommDbTest013_04::doTestStepL( )
       
   272 	{
       
   273 	INFO_PRINTF1(_L("Step 013.04 called "));
       
   274 
       
   275 	SetTestStepResult(EPass);
       
   276 	// Heap test for 013.01
       
   277 
       
   278 	CCommDbTest013_01* step013_01 = new CCommDbTest013_01;
       
   279 	CleanupStack::PushL(step013_01);
       
   280 	if ( doTestStepWithHeapFailureL( *step013_01, KErrNone) == EFail )
       
   281 		SetTestStepResult(EFail);	CleanupStack::PopAndDestroy(step013_01);
       
   282 
       
   283 	// Heap test for 013.02
       
   284 	// SQl interface is deprecated from 9.1
       
   285 
       
   286 	CCommDbTest013_02* step013_02 = new CCommDbTest013_02;
       
   287 	CleanupStack::PushL(step013_02);
       
   288 	if ( doTestStepWithHeapFailureL( *step013_02, KErrNotSupported) == EFail )
       
   289 		SetTestStepResult(EFail);	CleanupStack::PopAndDestroy(step013_02);
       
   290 
       
   291 	// Heap test for 013.03
       
   292 
       
   293 	CCommDbTest013_03* step013_03 = new CCommDbTest013_03;
       
   294 	CleanupStack::PushL(step013_03);
       
   295 	doTestStepWithHeapFailureL( *step013_03, KErrAccessDenied);
       
   296 	if ( step013_03->TestStepResult() == EFail )
       
   297 		SetTestStepResult(EFail);	CleanupStack::PopAndDestroy(step013_03);
       
   298 
       
   299 	return TestStepResult();	
       
   300 
       
   301 }