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