commsconfig/commsdatabaseshim/ts_commdb/step_058_xx.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     1 // Copyright (c) 2003-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 //
       
    15  
       
    16 // EPOC includes
       
    17 #include <e32base.h>
       
    18 #include <commdb.h>
       
    19 #include <d32comm.h>
       
    20 #include <cdbstore.h>
       
    21 
       
    22 // Test system includes
       
    23 #include <networking/log.h>
       
    24 #include <networking/teststep.h>
       
    25 #include "Teststepcommdb.h"
       
    26 #include "TestSuiteCommdb.h"
       
    27 
       
    28 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    29 #include <comms-infras/commdb/protection/protectdb.h>
       
    30 #include <comms-infras/commdb/protection/protectcpdb.h>
       
    31 #else
       
    32 //these headers are user includes in the new env.
       
    33 #include "protectdb.h"
       
    34 #include "protectcpdb.h"
       
    35 #endif
       
    36 
       
    37 #include <cdbpreftable.h>
       
    38 
       
    39 #include "step_058_xx.h"
       
    40 
       
    41 //
       
    42 //	Test step 058.01
       
    43 //
       
    44 
       
    45 //TestProtectRecords
       
    46 CCommDbTest058_01::CCommDbTest058_01()
       
    47 {
       
    48 	// store the name of this test case
       
    49 	iTestStepName = _L("step_058_01");
       
    50 }
       
    51 
       
    52 CCommDbTest058_01::~CCommDbTest058_01()
       
    53 {
       
    54 	delete iTheDb;
       
    55 }
       
    56 
       
    57 TVerdict CCommDbTest058_01::doTestStepPreambleL()
       
    58 	{	
       
    59 	iTheDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
    60 	return EPass;
       
    61 	}
       
    62 
       
    63 
       
    64 enum TVerdict CCommDbTest058_01::doTestStepL( void )
       
    65 	{
       
    66 	TUint32 Ranking;
       
    67 	Log(_L("Test Protect Connection Prefs Records "));
       
    68 	iTestStepResult = EPass;
       
    69 
       
    70 	CCommsDbProtectConnectPrefTableView* table = (CCommsDbProtectConnectPrefTableView *)iTheDb->OpenConnectionPrefTableLC();
       
    71 
       
    72 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
    73 	
       
    74 	TESTL(table->GotoFirstRecord()==KErrNone);
       
    75 
       
    76 	// Check record security level is writable
       
    77 	TInt recordAccess = RDbRowSet::EReadOnly;
       
    78 	TESTL(table->GetRecordAccess(recordAccess) == KErrNone);
       
    79 	TESTL(recordAccess == RDbRowSet::EUpdatable);
       
    80 
       
    81 	// Modify and test the first record
       
    82 	TESTL(ChangeCPRankingL(table, Ranking) == KErrNone);
       
    83 
       
    84 	TRAPD(ErrVal,ProtectRecordL(table,KErrNone));		
       
    85 	TESTL(ErrVal == KErrNone);
       
    86 
       
    87 	// Check record security level is read only
       
    88 	TESTL(table->GetRecordAccess(recordAccess) == KErrNone);
       
    89 	TESTL(recordAccess == RDbRowSet::EReadOnly);
       
    90 
       
    91 	// Test that protection is effective - i.e we can't change the record
       
    92 	ErrVal = ChangeCPRankingL(table, Ranking); // Try modifying a field.
       
    93 	TESTL(ErrVal == KErrAccessDenied);
       
    94 
       
    95 	// Check record security level is still read only
       
    96 	TESTL(table->GetRecordAccess(recordAccess) == KErrNone);
       
    97 	TESTL(recordAccess == RDbRowSet::EReadOnly);
       
    98 
       
    99 	table->GotoFirstRecord();
       
   100 
       
   101 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   102 
       
   103 	iTestStepResult = EPass;
       
   104 	Log(_L("\t\tSUCCESS"));
       
   105 
       
   106 	CleanupStack::PopAndDestroy(); 
       
   107 	return iTestStepResult;
       
   108 	}
       
   109 
       
   110 
       
   111 //
       
   112 //	Test step 058.02
       
   113 //
       
   114 
       
   115 //TestUnprotectRecords
       
   116 
       
   117 CCommDbTest058_02::CCommDbTest058_02()
       
   118 {
       
   119 	// store the name of this test case
       
   120 	iTestStepName = _L("step_058_02");
       
   121 }
       
   122 
       
   123 CCommDbTest058_02::~CCommDbTest058_02()
       
   124 {
       
   125 	delete iTheDb;
       
   126 }
       
   127 
       
   128 TVerdict CCommDbTest058_02::doTestStepPreambleL()
       
   129 	{	
       
   130 	iTheDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   131 	return EPass;
       
   132 	}
       
   133 
       
   134 
       
   135 enum TVerdict CCommDbTest058_02::doTestStepL( void )
       
   136 	{
       
   137 
       
   138 	Log(_L("Test UnProtect Connection Prefs Records .."));
       
   139 	iTestStepResult = EPass;
       
   140 
       
   141 	CCommsDbProtectConnectPrefTableView* table = (CCommsDbProtectConnectPrefTableView *)iTheDb->OpenConnectionPrefTableLC();
       
   142 
       
   143 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   144 
       
   145 	if(table->GotoFirstRecord()==KErrNone)
       
   146 		{
       
   147 		// Check record state is read only
       
   148 		TInt recordAccess = RDbRowSet::EUpdatable;
       
   149 		TESTL(table->GetRecordAccess(recordAccess) == KErrNone);
       
   150 		TESTL(recordAccess == RDbRowSet::EReadOnly);
       
   151 
       
   152 		// Check record cannot be updated
       
   153 		TRAPD(ret, UpdateRecordL(table,KErrAccessDenied));
       
   154 		TESTL(ret == KErrNone);
       
   155 
       
   156 		// Unprotect record
       
   157 		table->GotoFirstRecord();
       
   158 		TRAP(ret,UnprotectRecordL(table,KErrNone));
       
   159 		TESTL(ret == KErrNone);
       
   160 
       
   161 		// Check record state is now writable
       
   162 		TESTL(table->GetRecordAccess(recordAccess) == KErrNone);
       
   163 		TESTL(recordAccess == RDbRowSet::EUpdatable);
       
   164 
       
   165 		// Test record can now be updated
       
   166 		TRAP(ret,UpdateRecordL(table,KErrNone));
       
   167 		TESTL(ret == KErrNone);
       
   168 		}
       
   169 
       
   170 	TESTL(iTheDb->CommitTransaction()==KErrNone);
       
   171 	
       
   172 	// Do separate transaction to check deletion is 
       
   173 	// allowed as want to be able to roll this back
       
   174 	TESTL(iTheDb->BeginTransaction()==KErrNone);
       
   175 	
       
   176 	if(table->GotoFirstRecord()==KErrNone)
       
   177 		{
       
   178 		// Check can delete record
       
   179 		TRAPD(ret,DeleteRecordL(table,KErrNone));
       
   180 		TESTL(ret == KErrNone);
       
   181 		} 
       
   182 	
       
   183 	//don't commit as don't want to risk making db empty.
       
   184 	iTheDb->RollbackTransaction();
       
   185 
       
   186 	iTestStepResult = EPass;
       
   187 	Log(_L("\t\tSUCCESS"));
       
   188 	CleanupStack::PopAndDestroy(); 
       
   189 	return iTestStepResult;
       
   190 	}
       
   191