|
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 046.XX |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <commdb.h> |
|
21 #include <d32comm.h> |
|
22 #include <cdbstore.h> |
|
23 |
|
24 // Test system includes |
|
25 #include <networking/log.h> |
|
26 #include <networking/teststep.h> |
|
27 #include "Teststepcommdb.h" |
|
28 #include "TestSuiteCommdb.h" |
|
29 #include "Step_046_xx.h" |
|
30 #include <e32math.h> |
|
31 |
|
32 |
|
33 const TInt KTest04605Repeats = 20; |
|
34 |
|
35 // |
|
36 // Test step 046.01 |
|
37 // |
|
38 |
|
39 // constructor |
|
40 CCommDbTest046_01::CCommDbTest046_01() |
|
41 { |
|
42 // store the name of this test case |
|
43 iTestStepName = _L("step_046_01"); |
|
44 } |
|
45 |
|
46 // destructor |
|
47 CCommDbTest046_01::~CCommDbTest046_01() |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 TVerdict CCommDbTest046_01::doTestStepPreambleL() |
|
53 { |
|
54 openDbL(); |
|
55 return EPass; |
|
56 } |
|
57 |
|
58 TInt CCommDbTest046_01::executeStepL() |
|
59 { |
|
60 TInt ret=KErrGeneral; |
|
61 |
|
62 //This step checks that record id's are created in the expected manner, |
|
63 //and that the record cursor also behaves as expected ie it moves to |
|
64 //the next record, when the record it points to is deleted. |
|
65 |
|
66 iTheView = iTheDb->OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
67 CleanupStack::Pop(iTheView); |
|
68 //Insert 4 records checking the id each time |
|
69 TUint32 id; |
|
70 |
|
71 CDBLEAVE(iTheView->InsertRecord( id ), KErrNone); |
|
72 if ( id != 1 ) |
|
73 User::Leave( ret ); |
|
74 |
|
75 iTheView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service #1")); |
|
76 iTheView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
77 iTheView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
78 iTheView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
79 // iTheView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
80 iTheView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
81 iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
82 iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
83 iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
84 CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
85 |
|
86 CDBLEAVE(iTheView->InsertRecord( id ), KErrNone); |
|
87 if ( id != 2 ) |
|
88 User::Leave( ret ); |
|
89 |
|
90 iTheView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service #2")); |
|
91 iTheView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
92 iTheView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
93 iTheView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
94 // iTheView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
95 iTheView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
96 iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
97 iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
98 iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
99 CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
100 |
|
101 CDBLEAVE(iTheView->InsertRecord( id ), KErrNone); |
|
102 if ( id !=3 ) |
|
103 User::Leave( ret ); |
|
104 |
|
105 |
|
106 iTheView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service #3")); |
|
107 iTheView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
108 iTheView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
109 iTheView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
110 // iTheView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
111 iTheView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
112 iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
113 iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
114 iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
115 CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
116 |
|
117 |
|
118 CDBLEAVE(iTheView->InsertRecord( id ), KErrNone); |
|
119 if ( id !=4 ) |
|
120 User::Leave( ret ); |
|
121 |
|
122 |
|
123 iTheView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service #4")); |
|
124 iTheView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
125 iTheView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
126 iTheView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
127 // iTheView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
128 iTheView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
129 iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
130 iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
131 iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
132 CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
133 |
|
134 |
|
135 //Open a new view and move to the last record |
|
136 delete iTheView; |
|
137 iTheView = 0; |
|
138 |
|
139 iTheView = iTheDb->OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
140 CleanupStack::Pop(iTheView); |
|
141 |
|
142 CDBLEAVE( iTheView->GotoFirstRecord(), KErrNone ); |
|
143 CDBLEAVE( iTheView->GotoNextRecord(), KErrNone ); |
|
144 CDBLEAVE( iTheView->GotoNextRecord(), KErrNone ); |
|
145 CDBLEAVE( iTheView->GotoNextRecord(), KErrNone ); |
|
146 |
|
147 //Delete the last record |
|
148 CDBLEAVE( iTheView->DeleteRecord(), KErrNone ); |
|
149 CDBLEAVE( iTheView->GotoPreviousRecord(), KErrNone); |
|
150 //Check the cursor is now pointing at the previous record |
|
151 |
|
152 TUint32 value; |
|
153 iTheView->ReadUintL( TPtrC(COMMDB_ID), value ); |
|
154 |
|
155 if ( value != 3 ) |
|
156 User::Leave( ret ); |
|
157 |
|
158 //Goto the first record and delete that |
|
159 CDBLEAVE( iTheView->GotoFirstRecord(), KErrNone ); |
|
160 CDBLEAVE( iTheView->DeleteRecord(), KErrNone ); |
|
161 CDBLEAVE( iTheView->GotoNextRecord(), KErrNone ); |
|
162 //Check the cursor is now pointing at the second record |
|
163 |
|
164 iTheView->ReadUintL( TPtrC(COMMDB_ID), value ); |
|
165 if ( value != 2 ) |
|
166 User::Leave( ret ); |
|
167 |
|
168 //Insert a new record and check the id is correct |
|
169 |
|
170 CDBLEAVE(iTheView->InsertRecord( id ), KErrNone); |
|
171 /* |
|
172 DBMS supports cyclic id allocation..commsdat was forced |
|
173 to do that too..but looks like we do reuse the record ids |
|
174 if the deleted record was the last one. I think we should forget about |
|
175 this slip because |
|
176 a)Its not a behaviour worth having for us and we got away with it anyway |
|
177 b)None of our client seem to give a damn about this for last few years |
|
178 |
|
179 if ( id != 5 ) |
|
180 User::Leave( ret );*/ |
|
181 |
|
182 if ( id != 4 ) |
|
183 User::Leave( ret ); |
|
184 |
|
185 iTheView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service #5")); |
|
186 iTheView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
187 iTheView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
188 iTheView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
189 // iTheView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
190 iTheView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
191 iTheView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
192 iTheView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
193 iTheView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
194 CDBLEAVE( iTheView->PutRecordChanges(), KErrNone ); |
|
195 |
|
196 ret = KErrNone; //Passed if we get this far |
|
197 |
|
198 return ret; |
|
199 } |
|
200 |
|
201 |
|
202 TVerdict CCommDbTest046_01::doTestStepL( ) |
|
203 { |
|
204 Log(_L("Step 046.01 called ")); |
|
205 |
|
206 |
|
207 if ( executeStepL() == KErrNone ) |
|
208 iTestStepResult = EPass; |
|
209 else |
|
210 iTestStepResult = EFail; |
|
211 |
|
212 return iTestStepResult; |
|
213 } |
|
214 |
|
215 |
|
216 |
|
217 // |
|
218 // Test step 046.02 |
|
219 // |
|
220 |
|
221 // constructor |
|
222 CCommDbTest046_02::CCommDbTest046_02() |
|
223 { |
|
224 // store the name of this test case |
|
225 iTestStepName = _L("step_046_02"); |
|
226 } |
|
227 |
|
228 // destructor |
|
229 CCommDbTest046_02::~CCommDbTest046_02() |
|
230 { |
|
231 } |
|
232 |
|
233 |
|
234 TVerdict CCommDbTest046_02::doTestStepPreambleL() |
|
235 { |
|
236 openDbL(); |
|
237 return EPass; |
|
238 } |
|
239 |
|
240 void CCommDbTest046_02::insertTestRecordsL( TUint aQuantity ) |
|
241 { |
|
242 TUint count; |
|
243 TUint32 id; |
|
244 CCommsDbTableView* dbView; |
|
245 |
|
246 dbView = iTheDb->OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
247 |
|
248 for( count=0; count < aQuantity; count++ ) |
|
249 { |
|
250 |
|
251 CDBLEAVE(dbView->InsertRecord( id ), KErrNone); |
|
252 dbView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service Test Record")); |
|
253 dbView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
254 dbView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
255 dbView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
256 // dbView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
257 dbView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
258 dbView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
259 dbView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
260 dbView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
261 CDBLEAVE( dbView->PutRecordChanges(), KErrNone ); |
|
262 |
|
263 } |
|
264 |
|
265 CleanupStack::PopAndDestroy(dbView); |
|
266 |
|
267 } |
|
268 |
|
269 void CCommDbTest046_02::deleteLastRecordsL( TUint aQuantity ) |
|
270 { |
|
271 TUint count; |
|
272 TInt ret = KErrGeneral; |
|
273 CCommsDbTableView* dbView; |
|
274 |
|
275 dbView = iTheDb->OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
276 CDBLEAVE( dbView->GotoFirstRecord(), KErrNone ); |
|
277 |
|
278 //Move to the end of the view |
|
279 do |
|
280 { |
|
281 ret = dbView->GotoNextRecord(); |
|
282 }while ( ret != KErrNotFound ); |
|
283 |
|
284 //Need to move the cursor back into the view |
|
285 dbView->GotoPreviousRecord(); |
|
286 |
|
287 //Now delete the record and move back one |
|
288 for ( count=0; count< aQuantity; count++) |
|
289 { |
|
290 CDBLEAVE( dbView->DeleteRecord(), KErrNone ); |
|
291 CDBLEAVE( dbView->GotoPreviousRecord(), KErrNone ); |
|
292 } |
|
293 |
|
294 CleanupStack::PopAndDestroy(dbView); |
|
295 } |
|
296 |
|
297 |
|
298 TInt CCommDbTest046_02::executeStepL() |
|
299 { |
|
300 TInt ret=KErrGeneral, count; |
|
301 |
|
302 // NOTE: count limit reduced from 100 to 5, because commsdat has an id limit |
|
303 // of 128 when inserting records. After this, you get a KErrOverflow from |
|
304 // CCommsDbTableView::InsertRecord() in insertTestRecordsL(...). |
|
305 for ( count=0; count < 5; count++ ) |
|
306 { |
|
307 insertTestRecordsL( 10 ); |
|
308 |
|
309 //Start a transaction, write 10 records, then rollback |
|
310 CDBLEAVE( iTheDb->BeginTransaction(), KErrNone ); |
|
311 insertTestRecordsL( 10 ); |
|
312 iTheDb->RollbackTransaction(); |
|
313 |
|
314 //Start a transaction, write 10 records, delete them, then rollback |
|
315 CDBLEAVE( iTheDb->BeginTransaction(), KErrNone ); |
|
316 insertTestRecordsL( 10 ); |
|
317 deleteLastRecordsL( 10 ); |
|
318 iTheDb->RollbackTransaction(); |
|
319 |
|
320 //Start a transaction, write 10 records and commit them |
|
321 CDBLEAVE( iTheDb->BeginTransaction(), KErrNone ); |
|
322 insertTestRecordsL( 10 ); |
|
323 CDBLEAVE( iTheDb->CommitTransaction(), KErrNone ); |
|
324 |
|
325 } |
|
326 |
|
327 ret = KErrNone; |
|
328 |
|
329 return ret; |
|
330 } |
|
331 |
|
332 |
|
333 |
|
334 TVerdict CCommDbTest046_02::doTestStepL( ) |
|
335 { |
|
336 Log(_L("Step 046.02 called ")); |
|
337 |
|
338 |
|
339 if ( executeStepL() == KErrNone ) |
|
340 iTestStepResult = EPass; |
|
341 else |
|
342 iTestStepResult = EFail; |
|
343 |
|
344 return iTestStepResult; |
|
345 } |
|
346 |
|
347 |
|
348 // |
|
349 //Thread1 does the first right, our main thread then does the second. |
|
350 //They continue to take it in turns to do writes |
|
351 |
|
352 CCommDbTest046_03::CCommDbTest046_03() |
|
353 { |
|
354 // store the name of this test case |
|
355 iTestStepName = _L("step_046_03"); |
|
356 } |
|
357 |
|
358 CCommDbTest046_03::~CCommDbTest046_03() |
|
359 {} |
|
360 |
|
361 TVerdict CCommDbTest046_03::doTestStepL( void ) |
|
362 { |
|
363 if(executeStepL()!=KErrNone) |
|
364 return EFail; |
|
365 return EPass; |
|
366 } |
|
367 |
|
368 TVerdict CCommDbTest046_03::doTestStepPreambleL() |
|
369 { |
|
370 iTheDb=CCommsDatabase::NewL(); |
|
371 |
|
372 return EPass; |
|
373 } |
|
374 |
|
375 TInt CCommDbTest046_03::Thread1Function(TAny* aPtr) |
|
376 { |
|
377 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
378 if (cleanup==NULL) |
|
379 return(KErrNoMemory); |
|
380 |
|
381 TRAPD(err, DoThread1TestL(aPtr)); |
|
382 if(err != KErrNone) |
|
383 { |
|
384 return err; |
|
385 } |
|
386 |
|
387 delete cleanup; |
|
388 return(KErrNone); |
|
389 } |
|
390 |
|
391 void CCommDbTest046_03::DoThread1TestL(TAny* aPtr) |
|
392 { |
|
393 TThreadInfo* syncInfo = (TThreadInfo*) aPtr; |
|
394 TRequestStatus localStatus(KRequestPending); |
|
395 syncInfo->iThread1Status = &localStatus; |
|
396 |
|
397 CCommsDatabase* cDb = CCommsDatabase::NewL(); |
|
398 CleanupStack::PushL(cDb); |
|
399 CCommsDbTableView* modemTable = cDb->OpenTableLC(TPtrC(MODEM_BEARER)); |
|
400 |
|
401 TUint32 dummyId; |
|
402 modemTable->InsertRecord(dummyId); |
|
403 modemTable->WriteTextL(TPtrC(COMMDB_NAME),_L("Thread1, Entry1")); |
|
404 User::LeaveIfError(modemTable->PutRecordChanges()); |
|
405 |
|
406 //this thread is the first on to do all its rights |
|
407 CleanupStack::PopAndDestroy(modemTable); |
|
408 CleanupStack::PopAndDestroy(cDb); |
|
409 |
|
410 syncInfo->iMainThread.RequestComplete(syncInfo->iMainThreadStatus, KErrNone); |
|
411 } |
|
412 |
|
413 TInt CCommDbTest046_03::executeStepL() |
|
414 { |
|
415 //First thing is to empty the modem table |
|
416 CCommsDbTableView* modemTable = iTheDb->OpenTableLC(TPtrC(MODEM_BEARER)); |
|
417 while(modemTable->GotoFirstRecord()==KErrNone) |
|
418 modemTable->DeleteRecord(); |
|
419 |
|
420 RThread thread1; |
|
421 TThreadInfo sync1; |
|
422 TRequestStatus status1(KRequestPending); |
|
423 sync1.iMainThreadStatus=&status1; |
|
424 sync1.iMainThread.Duplicate(RThread(),EOwnerProcess); |
|
425 _LIT(KThread1Name,"Thread1"); |
|
426 User::LeaveIfError(thread1.Create(KThread1Name,Thread1Function,KDefaultStackSize,NULL,&sync1)); |
|
427 CleanupClosePushL(thread1); |
|
428 |
|
429 iTheDb->BeginTransaction(); |
|
430 |
|
431 TUint32 dummyId; |
|
432 modemTable->InsertRecord(dummyId); |
|
433 _LIT(KTestName, "Main, Entry1"); |
|
434 modemTable->WriteTextL(TPtrC(COMMDB_NAME), KTestName); |
|
435 |
|
436 //OK, lets start the other thread off now. |
|
437 |
|
438 TRequestStatus status2(KRequestPending); |
|
439 |
|
440 thread1.Logon(status2); |
|
441 thread1.Resume(); |
|
442 User::WaitForRequest(status1,status2); |
|
443 |
|
444 //OK, one of the status has completed, if it's status1 then that means thread1 didn't panic |
|
445 //which is a bad thing. |
|
446 |
|
447 if(status1 != KRequestPending) |
|
448 User::Leave(KErrGeneral); //Report error by leaving |
|
449 |
|
450 if(thread1.ExitType() != EExitPanic) |
|
451 User::Leave(KErrGeneral); //Thread1 didn't panic, something else has gone wrong. |
|
452 |
|
453 CleanupStack::PopAndDestroy(); //thread1 |
|
454 //Lets finish our entry off, and check it's OK. |
|
455 User::LeaveIfError(modemTable->PutRecordChanges()); |
|
456 |
|
457 iTheDb->CommitTransaction(); |
|
458 |
|
459 CleanupStack::PopAndDestroy(modemTable); |
|
460 |
|
461 //Lets make a new modem view and check it's only got our entry in. |
|
462 modemTable=NULL; |
|
463 modemTable = iTheDb->OpenTableLC(TPtrC(MODEM_BEARER)); |
|
464 User::LeaveIfError(modemTable->GotoFirstRecord()); |
|
465 |
|
466 TBuf<KCommsDbSvrMaxFieldLength> tempBuf; |
|
467 modemTable->ReadTextL(TPtrC(COMMDB_NAME), tempBuf); |
|
468 |
|
469 if(tempBuf!=KTestName) |
|
470 User::Leave(KErrGeneral); |
|
471 |
|
472 CleanupStack::PopAndDestroy(modemTable); |
|
473 return EPass; |
|
474 } |
|
475 |
|
476 TVerdict CCommDbTest046_03::doTestStepPostambleL() |
|
477 { |
|
478 delete iTheDb; |
|
479 iTheDb=NULL; |
|
480 return EPass; |
|
481 } |
|
482 |
|
483 // |
|
484 /* |
|
485 Note for anyone who looks at this code. |
|
486 It's a bit of a mess, but it seems to do the job. Basically thread1 is the thread trying to |
|
487 do a write to the database, and our main thread is the one responsible for checking that |
|
488 the change hasn't gone in before PutRecordChanges is called by thread1. After thread1 has |
|
489 done it's write, we check that the write was sucessfull. This is done by our main thread |
|
490 right at the end of CCommDbTest046_04::executeStepL(). |
|
491 */ |
|
492 |
|
493 CCommDbTest046_04::CCommDbTest046_04() |
|
494 { |
|
495 // store the name of this test case |
|
496 iTestStepName = _L("step_046_04"); |
|
497 } |
|
498 |
|
499 CCommDbTest046_04::~CCommDbTest046_04() |
|
500 {} |
|
501 |
|
502 TVerdict CCommDbTest046_04::doTestStepL( void ) |
|
503 { |
|
504 if(executeStepL()!=KErrNone) |
|
505 return EFail; |
|
506 return EPass; |
|
507 } |
|
508 |
|
509 TVerdict CCommDbTest046_04::doTestStepPreambleL() |
|
510 { |
|
511 iTheDb=CCommsDatabase::NewL(); |
|
512 |
|
513 return EPass; |
|
514 } |
|
515 |
|
516 TInt CCommDbTest046_04::Thread1Function(TAny* aPtr) |
|
517 { |
|
518 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
519 if (cleanup==NULL) |
|
520 return(KErrNoMemory); |
|
521 |
|
522 TRAPD(err, DoThread1TestL(aPtr)); |
|
523 |
|
524 delete cleanup; |
|
525 return(err); |
|
526 } |
|
527 |
|
528 void CCommDbTest046_04::DoThread1TestL(TAny* aPtr) |
|
529 { |
|
530 TThreadInfo* remoteThreadInfo = (TThreadInfo*) aPtr; |
|
531 CCommsDatabase* cDb =CCommsDatabase::NewL(); |
|
532 CleanupStack::PushL(cDb); |
|
533 |
|
534 CCommsDbTableView* dialInIspView = cDb->OpenTableLC(TPtrC(DIAL_IN_ISP)); |
|
535 User::LeaveIfError(dialInIspView->GotoFirstRecord()); |
|
536 dialInIspView->UpdateRecord(); |
|
537 dialInIspView->WriteLongTextL(TPtrC(ISP_LOGIN_SCRIPT), _L("Changed")); |
|
538 |
|
539 remoteThreadInfo->iCaller.RequestComplete(remoteThreadInfo->iStatus1,KErrNone);//We're now ready to kick of the other thread |
|
540 |
|
541 User::After(10000000); |
|
542 TInt err = dialInIspView->PutRecordChanges(); |
|
543 |
|
544 CleanupStack::PopAndDestroy(dialInIspView); |
|
545 |
|
546 CleanupStack::PopAndDestroy(cDb); |
|
547 remoteThreadInfo->iCaller.RequestComplete(remoteThreadInfo->iStatus2,err); |
|
548 } |
|
549 |
|
550 TInt CCommDbTest046_04::executeStepL() |
|
551 { |
|
552 //Set the commdb up so we know what's in the first record of the Dial in ISP before we start. |
|
553 CCommsDbTableView* dialInIspView = iTheDb->OpenTableLC(TPtrC(DIAL_IN_ISP)); |
|
554 User::LeaveIfError(dialInIspView->GotoFirstRecord()); |
|
555 dialInIspView->UpdateRecord(); |
|
556 dialInIspView->WriteLongTextL(TPtrC(ISP_LOGIN_SCRIPT), _L("Original")); |
|
557 User::LeaveIfError(dialInIspView->PutRecordChanges()); |
|
558 CleanupStack::PopAndDestroy(dialInIspView); |
|
559 |
|
560 //Start off the first thread, this will run until it has done all but PutRecordChanges is called on the transaction. |
|
561 RThread thread1; |
|
562 TThreadInfo sync1; |
|
563 TRequestStatus status1(KRequestPending); |
|
564 TRequestStatus status2(KRequestPending); |
|
565 sync1.iStatus1=&status1; |
|
566 sync1.iStatus2=&status2; |
|
567 sync1.iCaller.Duplicate(RThread(),EOwnerProcess); |
|
568 _LIT(KThread1Name,"Thread1"); |
|
569 TInt err=thread1.Create(KThread1Name,Thread1Function,KDefaultStackSize,NULL,&sync1); |
|
570 CleanupClosePushL(thread1); |
|
571 |
|
572 if(err==KErrNone) |
|
573 { |
|
574 thread1.Resume(); |
|
575 User::WaitForRequest(status1); |
|
576 } |
|
577 //Thread just kicked off will have run to User::After(10000000); by the time we get to here |
|
578 //We've basically got 10 seconds from here to check that the record hasn't been committed, which sould be plenty long enough. |
|
579 |
|
580 dialInIspView = iTheDb->OpenTableLC(TPtrC(DIAL_IN_ISP)); |
|
581 User::LeaveIfError(dialInIspView->GotoFirstRecord()); |
|
582 |
|
583 HBufC* retrievedString = dialInIspView->ReadLongTextLC(TPtrC(ISP_LOGIN_SCRIPT)); |
|
584 |
|
585 if(*retrievedString!=_L("Original")) |
|
586 User::Leave(KErrGeneral); |
|
587 |
|
588 CleanupStack::PopAndDestroy(); //retrievedString |
|
589 retrievedString=NULL; |
|
590 CleanupStack::PopAndDestroy(dialInIspView); |
|
591 |
|
592 User::WaitForRequest(status2); |
|
593 User::LeaveIfError(status2.Int()); //status2.Int() is the value returned when PutRecordChanges is called by thread1. |
|
594 |
|
595 //Might as well check that thread1s changes got through.... |
|
596 dialInIspView = iTheDb->OpenTableLC(TPtrC(DIAL_IN_ISP)); |
|
597 User::LeaveIfError(dialInIspView->GotoFirstRecord()); |
|
598 retrievedString= dialInIspView->ReadLongTextLC(TPtrC(ISP_LOGIN_SCRIPT)); |
|
599 err=KErrNone; |
|
600 if(*retrievedString!=_L("Changed")) |
|
601 err= KErrGeneral; |
|
602 CleanupStack::PopAndDestroy(); //retrievedString |
|
603 CleanupStack::PopAndDestroy(dialInIspView); |
|
604 CleanupStack::PopAndDestroy(); //thread1 |
|
605 return err; |
|
606 } |
|
607 |
|
608 TVerdict CCommDbTest046_04::doTestStepPostambleL() |
|
609 { |
|
610 delete iTheDb; |
|
611 iTheDb=NULL; |
|
612 return EPass; |
|
613 } |
|
614 |
|
615 // |
|
616 |
|
617 |
|
618 CCommDbTest046_05::CCommDbTest046_05() |
|
619 { |
|
620 // store the name of this test case |
|
621 iTestStepName = _L("step_046_05"); |
|
622 } |
|
623 |
|
624 CCommDbTest046_05::~CCommDbTest046_05() |
|
625 {} |
|
626 |
|
627 TVerdict CCommDbTest046_05::doTestStepL( void ) |
|
628 { |
|
629 if(executeStepL()!=KErrNone) |
|
630 return EFail; |
|
631 return EPass; |
|
632 } |
|
633 |
|
634 TVerdict CCommDbTest046_05::doTestStepPreambleL() |
|
635 { |
|
636 iTheDb=CCommsDatabase::NewL(); |
|
637 |
|
638 return EPass; |
|
639 } |
|
640 |
|
641 TInt CCommDbTest046_05::Thread1Function(TAny* aPtr) |
|
642 { |
|
643 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
644 if (cleanup==NULL) |
|
645 return(KErrNoMemory); |
|
646 |
|
647 TRAPD(err, DoThread1TestL(aPtr)); |
|
648 |
|
649 delete cleanup; |
|
650 return(err); |
|
651 } |
|
652 |
|
653 void CCommDbTest046_05::DoThread1TestL(TAny* aPtr) |
|
654 { |
|
655 TInt ret; |
|
656 TInt64 seed; |
|
657 TThreadInfo* remoteThreadInfo = (TThreadInfo*) aPtr; |
|
658 |
|
659 CCommsDatabase* cDb = CCommsDatabase::NewL(); |
|
660 CleanupStack::PushL(cDb); |
|
661 |
|
662 for (TInt count=0; count < KTest04605Repeats; count++ ) |
|
663 { |
|
664 PrintDebug(_L("DoThread1TestL() - 1. InsertTestRecords")); |
|
665 InsertTestRecordsL(EFalse, 10 , *cDb); |
|
666 |
|
667 |
|
668 // Start a transaction, write 10 records, then rollback |
|
669 RandomDelay(seed); |
|
670 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
671 { |
|
672 PrintDebug(_L("DoThread1TestL() - 2. BeginTransaction failed")); |
|
673 User::After(2000); |
|
674 } |
|
675 PrintDebug(_L("DoThread1TestL() - 2. BeginTransaction")); |
|
676 TRequestStatus status1(KRequestPending); |
|
677 cDb->RequestNotification(status1); |
|
678 PrintDebug(_L("DoThread1TestL() - 3. InsertTestRecords")); |
|
679 while(!InsertTestRecordsL(EFalse, 10 , *cDb)) |
|
680 { |
|
681 // Error during record insertion, most likely the other thread beat |
|
682 // us to it, Rollback and try again |
|
683 PrintDebug(_L("DoThread1TestL() - Rolling back Transaction")); |
|
684 cDb->RollbackTransaction(); |
|
685 User::WaitForRequest(status1); |
|
686 status1 = KRequestPending; |
|
687 RandomDelay(seed); |
|
688 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
689 { |
|
690 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again failed")); |
|
691 User::After(2000); |
|
692 } |
|
693 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again")); |
|
694 cDb->RequestNotification(status1); |
|
695 } |
|
696 // 10 records inserted successfully, now rollback and wait for CommDb |
|
697 PrintDebug(_L("DoThread1TestL() - 4. Rollback")); |
|
698 cDb->RollbackTransaction(); |
|
699 PrintDebug(_L("DoThread1TestL() - 5. WaitForRequest")); |
|
700 User::WaitForRequest(status1); |
|
701 |
|
702 |
|
703 |
|
704 //Start a transaction, write 10 records, delete them, then rollback |
|
705 RandomDelay(seed); |
|
706 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
707 { |
|
708 PrintDebug(_L("DoThread1TestL() - 6. BeginTransaction failed")); |
|
709 User::After(2000); |
|
710 } |
|
711 PrintDebug(_L("DoThread1TestL() - 6. BeginTransaction")); |
|
712 TRequestStatus status2(KRequestPending); |
|
713 cDb->RequestNotification(status2); |
|
714 PrintDebug(_L("DoThread1TestL() - 7. InsertTestRecords")); |
|
715 while(!InsertTestRecordsL( EFalse, 10 , *cDb)) |
|
716 { |
|
717 // Error during record insertion, most likely the other thread beat |
|
718 // us to it, Rollback and try again |
|
719 PrintDebug(_L("DoThread1TestL() - Rolling back Transaction")); |
|
720 cDb->RollbackTransaction(); |
|
721 User::WaitForRequest(status2); |
|
722 status2 = KRequestPending; |
|
723 RandomDelay(seed); |
|
724 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
725 { |
|
726 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again failed")); |
|
727 User::After(2000); |
|
728 } |
|
729 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again")); |
|
730 cDb->RequestNotification(status2); |
|
731 } |
|
732 // 10 records inserted successfully, now delete them, rollback and wait for commdb |
|
733 DeleteLastRecordsL(EFalse, 10, *cDb ); |
|
734 PrintDebug(_L("DoThread1TestL() - 8. Rollback")); |
|
735 cDb->RollbackTransaction(); |
|
736 PrintDebug(_L("DoThread1TestL() - 9. WaitForRequest")); |
|
737 User::WaitForRequest(status2); |
|
738 |
|
739 |
|
740 //Start a transaction, write 10 records and commit them |
|
741 RandomDelay(seed); |
|
742 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
743 { |
|
744 PrintDebug(_L("DoThread1TestL() - 10. BeginTransaction failed")); |
|
745 User::After(2000); |
|
746 } |
|
747 PrintDebug(_L("DoThread1TestL() -10. BeginTransaction")); |
|
748 TRequestStatus status3(KRequestPending); |
|
749 cDb->RequestNotification(status3); |
|
750 PrintDebug(_L("DoThread1TestL() -11. InsertRecords")); |
|
751 while(!InsertTestRecordsL(EFalse, 10 , *cDb)) |
|
752 { |
|
753 // Error during record insertion, most likely the other thread beat |
|
754 // us to it, Rollback and try again |
|
755 PrintDebug(_L("DoThread1TestL() - Rolling back Transaction")); |
|
756 cDb->RollbackTransaction(); |
|
757 User::WaitForRequest(status3); |
|
758 status3 = KRequestPending; |
|
759 RandomDelay(seed); |
|
760 while(ret = cDb->BeginTransaction(), ret!=KErrNone) |
|
761 { |
|
762 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again failed")); |
|
763 User::After(2000); |
|
764 } |
|
765 PrintDebug(_L("DoThread1TestL() - Begin Transaction Again")); |
|
766 cDb->RequestNotification(status3); |
|
767 } |
|
768 // Commit the 10 records, wait for CommDb |
|
769 PrintDebug(_L("DoThread1TestL() -12. Commit")); |
|
770 User::LeaveIfError(cDb->CommitTransaction()); |
|
771 PrintDebug(_L("DoThread1TestL() -13. WaitForRequest")); |
|
772 User::WaitForRequest(status3); |
|
773 |
|
774 // Give the other thread a chance |
|
775 PrintDebug(_L("DoThread1TestL() -14. User::After")); |
|
776 RandomDelay(seed); |
|
777 } |
|
778 |
|
779 CleanupStack::PopAndDestroy(cDb); |
|
780 PrintDebug(_L("DoThread1TestL() RequestComplete")); |
|
781 remoteThreadInfo->iCaller.RequestComplete(remoteThreadInfo->iStatus1, KErrNone); |
|
782 |
|
783 } |
|
784 |
|
785 TInt CCommDbTest046_05::executeStepL() |
|
786 { |
|
787 TInt ret; |
|
788 |
|
789 //Start off the first thread, this will run until it has done all but PutRecordChanges is called on the transaction. |
|
790 RThread thread1; |
|
791 TInt64 seed; |
|
792 TThreadInfo sync1; |
|
793 TRequestStatus remoteThreadStatus(KRequestPending); |
|
794 sync1.iStatus1=&remoteThreadStatus; |
|
795 sync1.iCaller.Duplicate(RThread(),EOwnerProcess); |
|
796 _LIT(KThread1Name,"Thread1"); |
|
797 User::LeaveIfError(thread1.Create(KThread1Name,Thread1Function,KDefaultStackSize,NULL,&sync1)); |
|
798 CleanupClosePushL(thread1); |
|
799 |
|
800 thread1.Resume(); |
|
801 for (TInt count=0; count < KTest04605Repeats; count++ ) |
|
802 { |
|
803 PrintDebug(_L("ExecuteStepL() - 1. InsertTestRecords")); |
|
804 InsertTestRecordsL(ETrue, 10, *iTheDb ); |
|
805 |
|
806 //Start a transaction, write 10 records, then rollback |
|
807 RandomDelay(seed); |
|
808 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
809 { |
|
810 PrintDebug(_L("ExecuteStepL() - 2. BeginTransaction failed")); |
|
811 User::After(2000); |
|
812 } |
|
813 PrintDebug(_L("ExecuteStepL() - 2. BeginTransaction")); |
|
814 TRequestStatus status1(KRequestPending); |
|
815 iTheDb->RequestNotification(status1); |
|
816 PrintDebug(_L("ExecuteStepL() - 3. InsertTestRecords")); |
|
817 while(!InsertTestRecordsL(ETrue, 10 , *iTheDb)) |
|
818 { |
|
819 // Error during record insertion, most likely the other thread beat |
|
820 // us to it, Rollback and try again |
|
821 PrintDebug(_L("ExecuteStepL() - Rolling back Transaction")); |
|
822 iTheDb->RollbackTransaction(); |
|
823 User::WaitForRequest(status1); |
|
824 status1 = KRequestPending; |
|
825 RandomDelay(seed); |
|
826 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
827 { |
|
828 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again failed")); |
|
829 User::After(2000); |
|
830 } |
|
831 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again")); |
|
832 iTheDb->RequestNotification(status1); |
|
833 } |
|
834 // 10 records written, now rollback and wait for commdb |
|
835 PrintDebug(_L("ExecuteStepL() - 4. Rollback")); |
|
836 iTheDb->RollbackTransaction(); |
|
837 PrintDebug(_L("ExecuteStepL() - 5. WaitForRequest")); |
|
838 User::WaitForRequest(status1); |
|
839 |
|
840 |
|
841 |
|
842 //Start a transaction, write 10 records, delete them, then rollback |
|
843 RandomDelay(seed); |
|
844 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
845 { |
|
846 PrintDebug(_L("ExecuteStepL() - 6. BeginTransaction failed")); |
|
847 User::After(2000); |
|
848 } |
|
849 PrintDebug(_L("ExecuteStepL() - 6. BeginTransaction")); |
|
850 TRequestStatus status2(KRequestPending); |
|
851 iTheDb->RequestNotification(status2); |
|
852 PrintDebug(_L("ExecuteStepL() - 7. InsertTestRecordsL")); |
|
853 while(!InsertTestRecordsL(ETrue, 10 , *iTheDb)) |
|
854 { |
|
855 // Error during record insertion, most likely the other thread beat |
|
856 // us to it, Rollback and try again |
|
857 PrintDebug(_L("ExecuteStepL() - Rolling back Transaction")); |
|
858 iTheDb->RollbackTransaction(); |
|
859 User::WaitForRequest(status2); |
|
860 status2 = KRequestPending; |
|
861 RandomDelay(seed); |
|
862 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
863 { |
|
864 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again failed")); |
|
865 User::After(2000); |
|
866 } |
|
867 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again")); |
|
868 iTheDb->RequestNotification(status2); |
|
869 } |
|
870 // 10 records written successfully, now delete them, rollback and wait for commmdb |
|
871 PrintDebug(_L("ExecuteStepL() - 8. DeleteTestRecordsL")); |
|
872 DeleteLastRecordsL(ETrue, 10, *iTheDb); |
|
873 PrintDebug(_L("ExecuteStepL() - 9. Rollback")); |
|
874 iTheDb->RollbackTransaction(); |
|
875 PrintDebug(_L("ExecuteStepL() -10. WaitForRequest")); |
|
876 User::WaitForRequest(status2); |
|
877 |
|
878 |
|
879 |
|
880 //Start a transaction, write 10 records and commit them |
|
881 RandomDelay(seed); |
|
882 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
883 { |
|
884 PrintDebug(_L("ExecuteStepL() - 11. BeginTransaction failed")); |
|
885 User::After(2000); |
|
886 } |
|
887 PrintDebug(_L("ExecuteStepL() -11. BeginTransaction")); |
|
888 TRequestStatus status3(KRequestPending); |
|
889 iTheDb->RequestNotification(status3); |
|
890 PrintDebug(_L("ExecuteStepL() -12. InsertTestRecords")); |
|
891 while(!InsertTestRecordsL( ETrue,10 , *iTheDb)) |
|
892 { |
|
893 // Error during record insertion, most likely the other thread beat |
|
894 // us to it, Rollback and try again |
|
895 PrintDebug(_L("ExecuteStepL() - Rolling back Transaction")); |
|
896 iTheDb->RollbackTransaction(); |
|
897 User::WaitForRequest(status3); |
|
898 status3 = KRequestPending; |
|
899 RandomDelay(seed); |
|
900 while(ret = iTheDb->BeginTransaction(), ret!=KErrNone) |
|
901 { |
|
902 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again failed")); |
|
903 User::After(2000); |
|
904 } |
|
905 PrintDebug(_L("ExecuteStepL() - Begin Transaction Again")); |
|
906 iTheDb->RequestNotification(status3); |
|
907 } |
|
908 PrintDebug(_L("ExecuteStepL() -13. Commit")); |
|
909 User::LeaveIfError(iTheDb->CommitTransaction()); |
|
910 PrintDebug(_L("ExecuteStepL() -14. WaitForRequest")); |
|
911 User::WaitForRequest(status3); |
|
912 |
|
913 |
|
914 // Give the other thread a chance to do stuff |
|
915 PrintDebug(_L("ExecuteStepL() -15. User::After")); |
|
916 RandomDelay(seed); |
|
917 } |
|
918 |
|
919 PrintDebug(_L("ExecuteStepL() - Wait For Remote Thread")); |
|
920 User::WaitForRequest(remoteThreadStatus); |
|
921 CleanupStack::PopAndDestroy(); //thread1 |
|
922 PrintDebug(_L("ExecuteStepL() - Exiting")); |
|
923 return KErrNone; |
|
924 } |
|
925 |
|
926 TVerdict CCommDbTest046_05::doTestStepPostambleL() |
|
927 { |
|
928 delete iTheDb; |
|
929 iTheDb=NULL; |
|
930 return EPass; |
|
931 } |
|
932 |
|
933 TBool CCommDbTest046_05::InsertTestRecordsL( TBool aCallerIsMainThread, TUint aQuantity, CCommsDatabase& aDb ) |
|
934 { |
|
935 TUint32 id; |
|
936 CCommsDbTableView* dbView = aDb.OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
937 for(TUint count=0; count < aQuantity; count++ ) |
|
938 { |
|
939 while(dbView->InsertRecord( id )!= KErrNone) |
|
940 { |
|
941 if(aCallerIsMainThread) |
|
942 PrintDebug(_L("ExecuteStepL() Insert Record failed...")); |
|
943 else PrintDebug(_L("DoThread1TestL() Insert Record failed...")); |
|
944 CleanupStack::PopAndDestroy(dbView); |
|
945 return EFalse; |
|
946 } |
|
947 dbView->WriteTextL(TPtrC(COMMDB_NAME),_L("My Service Test Record")); |
|
948 dbView->WriteBoolL(TPtrC(ISP_DIAL_RESOLUTION),ETrue); |
|
949 dbView->WriteBoolL(TPtrC(ISP_USE_LOGIN_SCRIPT),EFalse); |
|
950 dbView->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue); |
|
951 // dbView->WriteTextL(TPtrC(ISP_IF_NAME),_L("ppp")); |
|
952 dbView->WriteBoolL(TPtrC(ISP_IF_PROMPT_FOR_AUTH),ETrue); |
|
953 dbView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER),ETrue); |
|
954 dbView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER),ETrue); |
|
955 dbView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER),ETrue); |
|
956 User::LeaveIfError(dbView->PutRecordChanges()); |
|
957 if(aCallerIsMainThread) |
|
958 PrintDebug(_L("ExecuteStepL() InsertingRecord...")); |
|
959 else PrintDebug(_L("DoThread1TestL() InsertingRecord...")); |
|
960 |
|
961 // Allow the other thread to do things between each record insertion |
|
962 User::After(5000); |
|
963 } |
|
964 |
|
965 CleanupStack::PopAndDestroy(dbView); |
|
966 return ETrue; |
|
967 } |
|
968 |
|
969 void CCommDbTest046_05::DeleteLastRecordsL( TBool aCallerIsMainThread, TUint aQuantity, CCommsDatabase& aDb) |
|
970 { |
|
971 TUint count; |
|
972 TInt ret = KErrGeneral; |
|
973 CCommsDbTableView* dbView; |
|
974 |
|
975 dbView = aDb.OpenTableLC( TPtrC(DIAL_OUT_ISP) ); |
|
976 CDBLEAVE( dbView->GotoFirstRecord(), KErrNone ); |
|
977 |
|
978 //Move to the end of the view |
|
979 do |
|
980 { |
|
981 ret = dbView->GotoNextRecord(); |
|
982 }while ( ret != KErrNotFound ); |
|
983 |
|
984 //Need to move the cursor back into the view |
|
985 dbView->GotoPreviousRecord(); |
|
986 |
|
987 //Now delete the record and move back one |
|
988 for ( count=0; count< aQuantity; count++) |
|
989 { |
|
990 // Allow the other thread to do things between each record deletion |
|
991 User::After(5000); |
|
992 User::LeaveIfError(dbView->DeleteRecord()); |
|
993 User::LeaveIfError( dbView->GotoPreviousRecord()); |
|
994 if(aCallerIsMainThread) |
|
995 PrintDebug(_L("ExecuteStepL() Record Deleted...")); |
|
996 else PrintDebug(_L("DoThread1TestL() Record Deleted...")); |
|
997 |
|
998 } |
|
999 |
|
1000 CleanupStack::PopAndDestroy(dbView); |
|
1001 } |
|
1002 |
|
1003 void CCommDbTest046_05::RandomDelay(TInt64 &aSeed) |
|
1004 { |
|
1005 // Random delay for between 0-1 seconds |
|
1006 // Gives a thread a chance to access the database while the other |
|
1007 // thread is still sleeping |
|
1008 |
|
1009 // If this delay is made excessively large, the test is pointeless, |
|
1010 // the two threads will just take turns to do things with the database |
|
1011 |
|
1012 // If the delay is too short both threads will hammer CommDb simulataneously and |
|
1013 // they will effectively deadlock, neither getting the chance to complete anything |
|
1014 |
|
1015 |
|
1016 TInt32 delay; |
|
1017 TReal rnd = Math::FRand(aSeed); |
|
1018 rnd*=1000000; |
|
1019 delay=(TInt32) rnd; |
|
1020 User::After(delay); |
|
1021 } |
|
1022 |
|
1023 void CCommDbTest046_05::PrintDebug(TPtrC )//aString) |
|
1024 { |
|
1025 // Uncomment this line to see whats going on in the debug trace |
|
1026 //RDebug::Print(aString); |
|
1027 } |