|
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_056_xx.h" |
|
33 |
|
34 ///////////////////// |
|
35 // Test step 056.01 |
|
36 ///////////////////// |
|
37 |
|
38 //TestProtectRecords |
|
39 CCommDbTest056_01::CCommDbTest056_01() |
|
40 { |
|
41 // store the name of this test case |
|
42 SetTestStepName(_L("step_056_01")); |
|
43 } |
|
44 |
|
45 CCommDbTest056_01::~CCommDbTest056_01() |
|
46 { |
|
47 delete iTheDb; |
|
48 } |
|
49 |
|
50 TVerdict CCommDbTest056_01::doTestStepPreambleL() |
|
51 { |
|
52 iTheDb = CCommsDatabase::NewL(EDatabaseTypeIAP); |
|
53 SetTestStepResult(EPass); return TestStepResult(); |
|
54 } |
|
55 |
|
56 enum TVerdict CCommDbTest056_01::doTestStepL( void ) |
|
57 { |
|
58 |
|
59 INFO_PRINTF1(_L("Test Normal Records : Protection ..")); |
|
60 SetTestStepResult(EPass); |
|
61 CCommsDbProtectTableView* table = (CCommsDbProtectTableView *)iTheDb->OpenTableLC(TPtrC(DIAL_OUT_ISP)); |
|
62 TESTL(iTheDb->BeginTransaction()==KErrNone); |
|
63 |
|
64 TESTL(table->GotoFirstRecord()==KErrNone); |
|
65 |
|
66 // Check record security level is writable |
|
67 TInt recordAccess = 1; |
|
68 TESTL(table->GetRecordAccess(recordAccess) == KErrNone); |
|
69 TESTL(recordAccess == 0); |
|
70 |
|
71 // Modify and test the first record |
|
72 TRAPD(ret,UpdateRecordL(table,KErrNone)); |
|
73 TESTL(ret == KErrNone); |
|
74 |
|
75 TRAP(ret,ProtectRecordL(table,KErrNone)); |
|
76 TESTL(ret == KErrNone); |
|
77 |
|
78 // Test that protection is effective |
|
79 TRAP(ret,UpdateRecordL(table,KErrAccessDenied)); |
|
80 TESTL(ret == KErrNone); |
|
81 TRAP(ret,DeleteRecordL(table,KErrAccessDenied)); |
|
82 TESTL(ret == KErrNone); |
|
83 |
|
84 // Check record security level is read only |
|
85 TESTL(table->GetRecordAccess(recordAccess) == KErrNone); |
|
86 TESTL(recordAccess == 1); |
|
87 |
|
88 table->GotoFirstRecord(); |
|
89 |
|
90 TESTL(iTheDb->CommitTransaction()==KErrNone); |
|
91 |
|
92 |
|
93 SetTestStepResult(EPass); INFO_PRINTF1(_L("\t\tSUCCESS")); |
|
94 |
|
95 CleanupStack::PopAndDestroy(); |
|
96 return TestStepResult(); |
|
97 } |
|
98 |
|
99 |
|
100 ///////////////////// |
|
101 // Test step 056.02 |
|
102 ///////////////////// |
|
103 |
|
104 //TestUnprotectRecords |
|
105 CCommDbTest056_02::CCommDbTest056_02() |
|
106 { |
|
107 // store the name of this test case |
|
108 SetTestStepName(_L("step_056_02")); |
|
109 } |
|
110 |
|
111 CCommDbTest056_02::~CCommDbTest056_02() |
|
112 { |
|
113 delete iTheDb; |
|
114 } |
|
115 |
|
116 TVerdict CCommDbTest056_02::doTestStepPreambleL() |
|
117 { |
|
118 iTheDb = CCommsDatabase::NewL(EDatabaseTypeIAP); |
|
119 SetTestStepResult(EPass); return TestStepResult(); |
|
120 } |
|
121 |
|
122 enum TVerdict CCommDbTest056_02::doTestStepL( void ) |
|
123 { |
|
124 |
|
125 INFO_PRINTF1(_L("Test Normal Records : unprotection ..")); |
|
126 SetTestStepResult(EPass); |
|
127 CCommsDbProtectTableView* table = (CCommsDbProtectTableView *)iTheDb->OpenTableLC(TPtrC(DIAL_OUT_ISP)); |
|
128 TESTL(iTheDb->BeginTransaction()==KErrNone); |
|
129 |
|
130 if(table->GotoFirstRecord()==KErrNone) |
|
131 { |
|
132 // Check record state is read only |
|
133 TInt recordAccess = 0; |
|
134 TESTL(table->GetRecordAccess(recordAccess) == KErrNone); |
|
135 TESTL(recordAccess == 1); |
|
136 |
|
137 // Check record cannot be updated |
|
138 TRAPD(ret, UpdateRecordL(table,KErrAccessDenied)); |
|
139 TESTL(ret == KErrNone); |
|
140 |
|
141 // Unprotect record |
|
142 table->GotoFirstRecord(); |
|
143 TRAP(ret,UnprotectRecordL(table,KErrNone)); |
|
144 TESTL(ret == KErrNone); |
|
145 |
|
146 // Check record state is now writable |
|
147 TESTL(table->GetRecordAccess(recordAccess) == KErrNone); |
|
148 TESTL(recordAccess == 0); |
|
149 |
|
150 // Test record can now be updated |
|
151 TRAP(ret,UpdateRecordL(table,KErrNone)); |
|
152 TESTL(ret == KErrNone); |
|
153 } |
|
154 |
|
155 TESTL(iTheDb->CommitTransaction()==KErrNone); |
|
156 |
|
157 // Do separate transaction to check deletion is |
|
158 // allowed as want to be able to roll this back |
|
159 TESTL(iTheDb->BeginTransaction()==KErrNone); |
|
160 |
|
161 if(table->GotoFirstRecord()==KErrNone) |
|
162 { |
|
163 // Check can delete record |
|
164 TRAPD(ret,DeleteRecordL(table,KErrNone)); |
|
165 TESTL(ret == KErrNone); |
|
166 } |
|
167 |
|
168 //don't commit as don't want to risk making db empty. |
|
169 iTheDb->RollbackTransaction(); |
|
170 |
|
171 |
|
172 SetTestStepResult(EPass); INFO_PRINTF1(_L("\t\tSUCCESS")); |
|
173 |
|
174 CleanupStack::PopAndDestroy(); |
|
175 return TestStepResult(); |
|
176 } |
|
177 |