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