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