|
1 // Copyright (c) 1998-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 // |
|
15 |
|
16 #include <d32dbms.h> |
|
17 #include <s32file.h> |
|
18 #include <e32test.h> |
|
19 #include <e32math.h> |
|
20 #include <hal.h> |
|
21 #include "D32DBAS.H" |
|
22 |
|
23 LOCAL_D RTest test(_L("t_dbsrv: Test DBMS server")); |
|
24 LOCAL_D CTrapCleanup* TheTrapCleanup; |
|
25 LOCAL_D RFs TheFs; |
|
26 LOCAL_D RDbs TheDbs; |
|
27 LOCAL_D RDbNamedDatabase TheDatabase; |
|
28 LOCAL_D RDbTable TheTable; |
|
29 LOCAL_D RDbView TheView; |
|
30 |
|
31 const TInt KTestCleanupStack=0x40; |
|
32 const TPtrC KTestDatabase(_S("c:\\dbms-tst\\share.db")); |
|
33 const TPtrC KTestFormat(_S("")); |
|
34 const TPtrC KTable1(_S("Table1")); |
|
35 const TPtrC KTable2(_S("Table2")); |
|
36 const TInt KRowCount=1000; |
|
37 const TUint KExitDelay=6*0x100000; // ~6 seconds |
|
38 |
|
39 const TPtrC KCreateTable1=_S("CREATE TABLE Table1 (Id INTEGER,Name CHAR(200),Memo LONG VARCHAR,Memo2 LONG VARBINARY)"); |
|
40 const TPtrC KCreateTable2=_S("CREATE TABLE Table2 (Id INTEGER,Name CHAR(200),Memo LONG VARCHAR)"); |
|
41 const TPtrC KDropTable1=_S("DROP TABLE Table1"); |
|
42 const TPtrC KDropTable2=_S("DROP TABLE Table2"); |
|
43 |
|
44 _LIT(KTestSpdFile1, "c:\\dbms-tst\\11335577.spd"); |
|
45 _LIT(KTestSpdFile2, "c:\\dbms-tst\\11335578.spd"); |
|
46 _LIT(KTestSpdFile3, "c:\\dbms-tst\\11335579.spd"); |
|
47 _LIT(KTestSpdFile4, "c:\\dbms-tst\\1133557A.spd"); |
|
48 |
|
49 const TInt KReturnValueForCompare = 10; |
|
50 const TInt KReturnValueForFind = 20; |
|
51 |
|
52 class TTimer |
|
53 { |
|
54 public: |
|
55 void Start(const TDesC& aDes); |
|
56 void Stop(); |
|
57 private: |
|
58 TUint iTicks; |
|
59 }; |
|
60 |
|
61 static TTimer TheTimer; |
|
62 |
|
63 void TTimer::Start(const TDesC& aDes) |
|
64 { |
|
65 test.Printf(_L(" %S: "),&aDes); |
|
66 iTicks=User::FastCounter(); |
|
67 } |
|
68 |
|
69 void TTimer::Stop() |
|
70 { |
|
71 TUint ticks = User::FastCounter() - iTicks; |
|
72 TInt freq = 0; |
|
73 test(HAL::Get(HAL::EFastCounterFrequency, freq) == KErrNone); |
|
74 const TInt KMicroSecIn1Sec = 1000000; |
|
75 const TInt KMsIn1Sec = 1000; |
|
76 double v = ((double)ticks * KMicroSecIn1Sec) / (double)freq; TInt v2 = (TInt)v; |
|
77 test.Printf(_L("%d ms\r\n"),v2/KMsIn1Sec); |
|
78 } |
|
79 |
|
80 void DeleteTestFiles() |
|
81 { |
|
82 (void)TheFs.Delete(KTestDatabase); |
|
83 (void)TheFs.Delete(KTestSpdFile1); |
|
84 (void)TheFs.Delete(KTestSpdFile2); |
|
85 (void)TheFs.Delete(KTestSpdFile3); |
|
86 (void)TheFs.Delete(KTestSpdFile4); |
|
87 } |
|
88 |
|
89 void Check(TInt aValue,TInt aExpected,TInt aLine) |
|
90 { |
|
91 if (aValue!=aExpected) |
|
92 { |
|
93 DeleteTestFiles(); |
|
94 test.Printf(_L("*** Expected %d: got %d\r\n"),aExpected,aValue); |
|
95 test.operator()(EFalse,aLine); |
|
96 } |
|
97 } |
|
98 #define test2(a,b) Check(a,b,__LINE__) |
|
99 |
|
100 LOCAL_C void Connect() |
|
101 { |
|
102 test2(TheDbs.Connect(),KErrNone); |
|
103 TheDbs.ResourceMark(); |
|
104 } |
|
105 |
|
106 LOCAL_C void Disconnect() |
|
107 { |
|
108 TheDbs.ResourceCheck(); |
|
109 TheDbs.Close(); |
|
110 } |
|
111 |
|
112 LOCAL_C void Execute(const TDesC& aSql) |
|
113 { |
|
114 test2 (TheDatabase.Execute(aSql),KErrNone); |
|
115 } |
|
116 |
|
117 LOCAL_C void WriteRecordsL(TInt aCount) |
|
118 { |
|
119 TheTimer.Start(_L("writing")); |
|
120 TheDatabase.Begin(); |
|
121 TBuf<10> text; |
|
122 TInt jj=0; |
|
123 for (TInt ii=0;ii<aCount;++ii) |
|
124 { |
|
125 TheTable.InsertL(); |
|
126 jj=(jj+23); |
|
127 if (jj>=aCount) |
|
128 jj-=aCount; |
|
129 TheTable.SetColL(1,jj); |
|
130 text.Num(jj); |
|
131 TheTable.SetColL(2,text); |
|
132 TheTable.PutL(); |
|
133 } |
|
134 test2 (TheDatabase.Commit(),KErrNone); |
|
135 TheTimer.Stop(); |
|
136 } |
|
137 |
|
138 LOCAL_C void Ipc(TInt aCount) |
|
139 { |
|
140 TheTimer.Start(_L("ipc")); |
|
141 while (--aCount>=0) |
|
142 TheDatabase.InTransaction(); |
|
143 TheTimer.Stop(); |
|
144 } |
|
145 |
|
146 LOCAL_C void LoopL(RDbTable::TPosition aDirection) |
|
147 { |
|
148 TheTimer.Start(_L("loop")); |
|
149 TInt cc=0; |
|
150 while (TheTable.GotoL(aDirection)) |
|
151 ++cc; |
|
152 test2 (cc,TheTable.CountL()); |
|
153 TheTimer.Stop(); |
|
154 } |
|
155 |
|
156 LOCAL_C void IterateL(RDbTable::TPosition aDirection) |
|
157 { |
|
158 TheTimer.Start(_L("iterate")); |
|
159 TInt cc=0; |
|
160 while (TheTable.GotoL(aDirection)) |
|
161 { |
|
162 ++cc; |
|
163 TheTable.GetL(); |
|
164 TBuf<10> text; |
|
165 text.Num(TheTable.ColInt(1)); |
|
166 test (text==TheTable.ColDes(2)); |
|
167 } |
|
168 test2 (cc,TheTable.CountL()); |
|
169 TheTimer.Stop(); |
|
170 } |
|
171 |
|
172 LOCAL_C void LocateL(const TDesC& aSql) |
|
173 { |
|
174 test2 (TheView.Prepare(TheDatabase,aSql),KErrNone); |
|
175 test2 (TheView.EvaluateAll(),KErrNone); |
|
176 TheTimer.Start(_L("locate")); |
|
177 test (!TheView.NextL()); |
|
178 TheTimer.Stop(); |
|
179 TheView.Close(); |
|
180 } |
|
181 |
|
182 LOCAL_C void Locate1L() |
|
183 { |
|
184 LocateL(_L("select * from Table1 where id is null")); |
|
185 } |
|
186 |
|
187 LOCAL_C void Locate2L() |
|
188 { |
|
189 LocateL(_L("select * from Table1 where id = -12345")); |
|
190 } |
|
191 |
|
192 LOCAL_C TInt DeleteL() |
|
193 { |
|
194 TheTimer.Start(_L("deleting")); |
|
195 TheDatabase.Begin(); |
|
196 TInt cc=0; |
|
197 TheTable.BeginningL(); |
|
198 while (TheTable.NextL()) |
|
199 { |
|
200 ++cc; |
|
201 TheTable.DeleteL(); |
|
202 } |
|
203 test (TheTable.CountL()==0); |
|
204 test (TheDatabase.Commit()==KErrNone); |
|
205 TheTimer.Stop(); |
|
206 return cc; |
|
207 } |
|
208 |
|
209 LOCAL_C TInt DeleteSQL() |
|
210 { |
|
211 TheTimer.Start(_L("deleting [SQL]")); |
|
212 TInt cc=TheDatabase.Execute(_L("delete from Table1")); |
|
213 test (cc>=KErrNone); |
|
214 test (TheTable.CountL()==0); |
|
215 TheTimer.Stop(); |
|
216 return cc; |
|
217 } |
|
218 |
|
219 LOCAL_C void BenchmarkL() |
|
220 { |
|
221 TInt r=TheTable.Open(TheDatabase,KTable1); |
|
222 TheTable.LastL(); |
|
223 test (r==KErrNone); |
|
224 Ipc(KRowCount); |
|
225 TheTable.Reset(); |
|
226 LoopL(TheTable.ENext); |
|
227 TheTable.Reset(); |
|
228 IterateL(TheTable.ENext); |
|
229 Locate1L(); |
|
230 Locate2L(); |
|
231 TheTable.Close(); |
|
232 } |
|
233 |
|
234 const TPtrC KSemaphore(_S("Connect-test")); |
|
235 |
|
236 LOCAL_C TInt ConnectThread(TAny*) |
|
237 { |
|
238 RSemaphore s; |
|
239 s.OpenGlobal(KSemaphore,EOwnerThread); |
|
240 RDbs dbs; |
|
241 dbs.Connect(); |
|
242 s.Signal(); |
|
243 User::After(0x100000); |
|
244 s.Wait(); |
|
245 dbs.Close(); |
|
246 s.Signal(); |
|
247 s.Close(); |
|
248 return KErrNone; |
|
249 } |
|
250 |
|
251 /** |
|
252 @SYMTestCaseID SYSLIB-DBMS-CT-0605 |
|
253 @SYMTestCaseDesc Single and multiple database connection tests |
|
254 @SYMTestPriority Medium |
|
255 @SYMTestActions Setup a DBMS server session Search the server for pattern matching |
|
256 @SYMTestExpectedResults Test must not fail |
|
257 @SYMREQ REQ0000 |
|
258 */ |
|
259 LOCAL_C void TestConnect() |
|
260 { |
|
261 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0605 Single connection ")); |
|
262 test (TheDbs.Connect()==KErrNone); |
|
263 TheDbs.Close(); |
|
264 test.Next(_L("Deferred exit")); |
|
265 TFindServer find(_L("!DBMS server")); |
|
266 TFullName result; |
|
267 test2 (find.Next(result),KErrNone); |
|
268 test.Next(_L("Multiple connection")); |
|
269 Connect(); |
|
270 RDbs dbs; |
|
271 test2 (dbs.Connect(),KErrNone); |
|
272 Disconnect(); |
|
273 dbs.Close(); |
|
274 test.Next(_L("Deferred exit")); |
|
275 find.Find(_L("!DBMS server")); |
|
276 test2 (find.Next(result),KErrNone); |
|
277 User::After(KExitDelay); |
|
278 find.Find(_L("!DBMS server")); |
|
279 test2 (find.Next(result),KErrNotFound); |
|
280 test.Next(_L("multiple thread connections")); |
|
281 RSemaphore s; |
|
282 test2 (s.CreateGlobal(KSemaphore,0,EOwnerThread),KErrNone); |
|
283 RThread t; |
|
284 test2 (t.Create(KSemaphore,ConnectThread,0x2000,0x1000,0x10000,0,EOwnerThread),KErrNone); |
|
285 t.Resume(); |
|
286 TRequestStatus st; |
|
287 t.Logon(st); |
|
288 t.Close(); |
|
289 s.Wait(); |
|
290 Connect(); |
|
291 s.Signal(); |
|
292 s.Close(); |
|
293 User::WaitForRequest(st); |
|
294 test2 (TheDbs.ResourceCount(),0); |
|
295 Disconnect(); |
|
296 test.Next(_L("Deferred exit")); |
|
297 find.Find(_L("!DBMS server")); |
|
298 test2 (find.Next(result),KErrNone); |
|
299 User::After(KExitDelay); |
|
300 find.Find(_L("!DBMS server")); |
|
301 test2 (find.Next(result),KErrNotFound); |
|
302 test.End(); |
|
303 } |
|
304 |
|
305 /** |
|
306 @SYMTestCaseID SYSLIB-DBMS-CT-0606 |
|
307 @SYMTestCaseDesc Tests for benchmark |
|
308 @SYMTestPriority Medium |
|
309 @SYMTestActions Tests for creating database and writing a table.Test for no error conditions. |
|
310 @SYMTestExpectedResults Test must not fail |
|
311 @SYMREQ REQ0000 |
|
312 */ |
|
313 LOCAL_C void TestBenchL() |
|
314 { |
|
315 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0606 Create database ")); |
|
316 TInt r=TheDatabase.Replace(TheFs,KTestDatabase,KTestFormat); |
|
317 test (r==KErrNone); |
|
318 Execute(KCreateTable1); |
|
319 test.Next(_L("write table")); |
|
320 r=TheTable.Open(TheDatabase,KTable1); |
|
321 test (r==KErrNone); |
|
322 WriteRecordsL(KRowCount); |
|
323 TheTable.Close(); |
|
324 test.Next(_L("BenchmarkL")); |
|
325 TRAPD(errCode, BenchmarkL()); |
|
326 test(errCode == KErrNone); |
|
327 test.Next(_L("Open server-side")); |
|
328 TheDatabase.Close(); |
|
329 Connect(); |
|
330 r=TheDatabase.Open(TheDbs,KTestDatabase); |
|
331 test (r==KErrNone); |
|
332 test.Next(_L("BenchmarkL")); |
|
333 TRAP(errCode, BenchmarkL()); |
|
334 test(errCode == KErrNone); |
|
335 test.Next(_L("Wrap up")); |
|
336 TheDatabase.Close(); |
|
337 Disconnect(); |
|
338 test.End(); |
|
339 } |
|
340 |
|
341 /** |
|
342 @SYMTestCaseID SYSLIB-DBMS-CT-0607 |
|
343 @SYMTestCaseDesc Tests for opening a shared database |
|
344 @SYMTestPriority Medium |
|
345 @SYMTestActions Tests for database open,column type,write and drop table |
|
346 @SYMTestExpectedResults Test must not fail |
|
347 @SYMREQ REQ0000 |
|
348 */ |
|
349 LOCAL_C void TestOpenL() |
|
350 { |
|
351 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0607 Create database ")); |
|
352 test2 (TheDatabase.Replace(TheFs,KTestDatabase,KTestFormat),KErrNone); |
|
353 TheDatabase.Close(); |
|
354 test.Next(_L("Open as shared")); |
|
355 Connect(); |
|
356 test2 (TheDatabase.Open(TheDbs,KTestDatabase),KErrNone); |
|
357 Execute(KCreateTable1); |
|
358 test2 (TheTable.Open(TheDatabase,KTable1),KErrNone); |
|
359 test2 (TheTable.ColCount(),4); |
|
360 test2 (TheTable.ColType(1),EDbColInt32); |
|
361 test2 (TheTable.ColType(2),EDbColText); |
|
362 test2 (TheTable.ColType(3),EDbColLongText); |
|
363 test2 (TheTable.ColType(4),EDbColLongBinary); |
|
364 delete TheTable.ColSetL(); |
|
365 test.Next(_L("write table")); |
|
366 WriteRecordsL(KRowCount); |
|
367 test.Next(_L("Check table")); |
|
368 TheTable.Reset(); |
|
369 test (TheTable.AtBeginning()); |
|
370 test (!TheTable.AtRow()); |
|
371 test (!TheTable.AtEnd()); |
|
372 test2 (TheTable.CountL(),KRowCount); |
|
373 IterateL(TheTable.ENext); |
|
374 test (!TheTable.AtBeginning()); |
|
375 test (!TheTable.AtRow()); |
|
376 test (TheTable.AtEnd()); |
|
377 test.Next(_L("Delete rows")); |
|
378 test2 (DeleteL(),KRowCount); |
|
379 TheTable.Close(); |
|
380 test.Next(_L("Drop table")); |
|
381 Execute(KDropTable1); |
|
382 TheDatabase.Close(); |
|
383 Disconnect(); |
|
384 test.End(); |
|
385 } |
|
386 |
|
387 /** |
|
388 @SYMTestCaseID SYSLIB-DBMS-CT-0608 |
|
389 @SYMTestCaseDesc Tests for database locking |
|
390 @SYMTestPriority Medium |
|
391 @SYMTestActions Tests for shared,exclusive locks on database |
|
392 @SYMTestExpectedResults Test must not fail |
|
393 @SYMREQ REQ0000 |
|
394 */ |
|
395 LOCAL_C void TestLocking() |
|
396 { |
|
397 TInt r; |
|
398 RDbNamedDatabase db; |
|
399 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0608 Open databases ")); |
|
400 Connect(); |
|
401 test2 (TheDatabase.Open(TheDbs,KTestDatabase),KErrNone); |
|
402 test2 (db.Open(TheDbs,KTestDatabase,KTestFormat),KErrNone); |
|
403 RDbNotifier ob; |
|
404 test2 (ob.Open(TheDatabase),KErrNone); |
|
405 // |
|
406 test.Next(_L("Shared locks")); |
|
407 TRequestStatus stat; |
|
408 ob.NotifyUnlock(stat); |
|
409 test2 (TheDatabase.Begin(),KErrNone); |
|
410 test2 (db.Begin(),KErrNone); |
|
411 test2 (TheDatabase.Commit(),KErrNone); |
|
412 User::After(1); |
|
413 test2 (stat.Int(),KRequestPending); // should not report yet |
|
414 test2 (db.Commit(),KErrNone); |
|
415 User::WaitForRequest(stat); |
|
416 test2 (stat.Int(),ob.EUnlock); |
|
417 // |
|
418 test.Next(_L("Exclusive locks")); |
|
419 ob.NotifyUnlock(stat); |
|
420 test2 (TheDatabase.Begin(),KErrNone); |
|
421 test2 (db.Begin(),KErrNone); |
|
422 test2 (TheDatabase.Execute(KCreateTable1),KErrLocked); // cannot acquire |
|
423 test2 (db.Commit(),KErrNone); // release lock |
|
424 test2 (TheDatabase.Execute(KCreateTable1),KErrNone); // upgrade to X-lock |
|
425 test2 (db.Begin(),KErrLocked); // cannot share |
|
426 test2 (TheTable.Open(db,KTable1),KErrNone); |
|
427 TRAP(r,TheTable.InsertL()); // cannot lock |
|
428 test2 (r,KErrLocked); |
|
429 TheTable.Close(); |
|
430 test2 (db.Execute(KDropTable1),KErrLocked); // cannot lock |
|
431 test2 (TheTable.Open(TheDatabase,KTable1),KErrNone); |
|
432 TRAP(r,TheTable.InsertL()); // we own the lock |
|
433 test2 (r,KErrNone); |
|
434 TheTable.Cancel(); |
|
435 TheTable.Close(); |
|
436 test2 (TheDatabase.Execute(KDropTable1),KErrNone); |
|
437 test2 (stat.Int(),KRequestPending); // no NotifyUnlock yet |
|
438 test2 (TheDatabase.Commit(),KErrNone); |
|
439 User::WaitForRequest(stat); |
|
440 test2 (stat.Int(),ob.ECommit); |
|
441 // |
|
442 ob.Close(); |
|
443 db.Close(); |
|
444 TheDatabase.Close(); |
|
445 Disconnect(); |
|
446 test.End(); |
|
447 } |
|
448 |
|
449 /** |
|
450 @SYMTestCaseID SYSLIB-DBMS-CT-0609 |
|
451 @SYMTestCaseDesc Tests for sharing a database |
|
452 @SYMTestPriority Medium |
|
453 @SYMTestActions Tests for opening a database more than once. |
|
454 Tests the integrity of the table data |
|
455 @SYMTestExpectedResults Test must not fail |
|
456 @SYMREQ REQ0000 |
|
457 */ |
|
458 LOCAL_C void TestShareL() |
|
459 { |
|
460 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0609 Open database ")); |
|
461 Connect(); |
|
462 TInt r=TheDatabase.Open(TheDbs,KTestDatabase); |
|
463 test (r==KErrNone); |
|
464 Execute(KCreateTable1); |
|
465 test.Next(_L("Open it again")); |
|
466 RDbNamedDatabase db; |
|
467 test (db.Open(TheDbs,KTestDatabase,KTestFormat)==KErrNone); |
|
468 test (TheTable.Open(db,KTable1)==KErrNone); |
|
469 test2 (TheTable.ColCount(),4); |
|
470 test2 (TheTable.ColType(1),EDbColInt32); |
|
471 test2 (TheTable.ColType(2),EDbColText); |
|
472 test2 (TheTable.ColType(3),EDbColLongText); |
|
473 test2 (TheTable.ColType(4),EDbColLongBinary); |
|
474 delete TheTable.ColSetL(); |
|
475 TheTable.Close(); |
|
476 // |
|
477 test.Next(_L("write table")); |
|
478 test (TheTable.Open(TheDatabase,KTable1)==KErrNone); |
|
479 WriteRecordsL(KRowCount); |
|
480 TheTable.Close(); |
|
481 test.Next(_L("Check table")); |
|
482 TheDatabase.Close(); |
|
483 TheDatabase=db; |
|
484 test (TheTable.Open(TheDatabase,KTable1)==KErrNone); |
|
485 test (TheTable.AtBeginning()); |
|
486 test (!TheTable.AtRow()); |
|
487 test (!TheTable.AtEnd()); |
|
488 test (TheTable.CountL()==KRowCount); |
|
489 IterateL(TheTable.ENext); |
|
490 test (!TheTable.AtBeginning()); |
|
491 test (!TheTable.AtRow()); |
|
492 test (TheTable.AtEnd()); |
|
493 test.Next(_L("Delete rows")); |
|
494 test (DeleteSQL()==KRowCount); |
|
495 TheTable.Close(); |
|
496 test.Next(_L("Drop table")); |
|
497 Execute(KDropTable1); |
|
498 TheDatabase.Close(); |
|
499 Disconnect(); |
|
500 test.End(); |
|
501 } |
|
502 |
|
503 LOCAL_C void TestScenario1L() |
|
504 { |
|
505 test.Start(_L("Take stream-lock on client 2")); |
|
506 test (TheView.FirstL()); |
|
507 TheView.GetL(); |
|
508 RDbColReadStream rcol; |
|
509 rcol.OpenLC(TheView,3); |
|
510 test2 (rcol.ReadUint16L(),0); |
|
511 test.Next(_L("Take a [shared] transaction-lock on client 1")); |
|
512 test2 (TheDatabase.Begin(),KErrNone); |
|
513 test.Next(_L("Attempt a write-lock on client 1")); |
|
514 TRAPD(r,TheTable.InsertL()); |
|
515 test2 (r,KErrLocked); |
|
516 test2 (rcol.ReadUint16L(),1); |
|
517 test.Next(_L("Release locks on client 1 and then 2")); |
|
518 TheDatabase.Rollback(); |
|
519 CleanupStack::PopAndDestroy(); // rcol |
|
520 test.End(); |
|
521 } |
|
522 |
|
523 LOCAL_C void TestScenario2L() |
|
524 { |
|
525 test.Start(_L("Take stream-lock on client 2")); |
|
526 test (TheView.FirstL()); |
|
527 TheView.GetL(); |
|
528 RDbColReadStream rcol; |
|
529 rcol.OpenLC(TheView,3); |
|
530 test2 (rcol.ReadUint16L(),0); |
|
531 test.Next(_L("Take a [shared] transaction-lock on client 1")); |
|
532 test2 (TheDatabase.Begin(),KErrNone); |
|
533 test.Next(_L("Attempt a write-lock on client 1")); |
|
534 TRAPD(r,TheTable.InsertL()); |
|
535 test2 (r,KErrLocked); |
|
536 test2 (rcol.ReadUint16L(),1); |
|
537 test.Next(_L("Release client 2 stream-lock")); |
|
538 CleanupStack::PopAndDestroy(); // rcol |
|
539 test.Next(_L("Take write-lock on client 1")); |
|
540 TheTable.InsertL(); // read-lock removed |
|
541 test.Next(_L("release client 1 locks")); |
|
542 TheTable.Cancel(); |
|
543 TheDatabase.Rollback(); |
|
544 test.End(); |
|
545 } |
|
546 |
|
547 LOCAL_C void TestScenario3L(RDbDatabase& aClient2) |
|
548 { |
|
549 test.Start(_L("Take transaction-lock on client 1")); |
|
550 test2 (TheDatabase.Begin(),KErrNone); |
|
551 test.Next(_L("Take stream-lock on client 2")); |
|
552 test (TheView.FirstL()); |
|
553 TheView.GetL(); |
|
554 RDbColReadStream rcol; |
|
555 rcol.OpenLC(TheView,3); |
|
556 test2 (rcol.ReadUint16L(),0); |
|
557 test.Next(_L("Release client 1 lock")); |
|
558 TheDatabase.Rollback(); |
|
559 test.Next(_L("Take write-lock on client 2")); |
|
560 RDbTable table2; // need a second cursor (cannot do insert with open streams) |
|
561 test2 (table2.Open(aClient2,KTable1,table2.EInsertOnly),KErrNone); |
|
562 TRAPD(r,table2.InsertL()); |
|
563 test2 (r,KErrNone); |
|
564 test.Next(_L("Release stream-lock")); |
|
565 CleanupStack::PopAndDestroy(); |
|
566 test.Next(_L("Release write-lock")); |
|
567 table2.PutL(); |
|
568 table2.Close(); |
|
569 test.Next(_L("check the system is unlocked")); |
|
570 test2 (TheDatabase.Begin(),KErrNone); |
|
571 test2 (TheDatabase.Commit(),KErrNone); |
|
572 test.End(); |
|
573 } |
|
574 |
|
575 LOCAL_C void TestScenario4L() |
|
576 { |
|
577 test.Start(_L("Take transaction-lock on client 1")); |
|
578 test2 (TheDatabase.Begin(),KErrNone); |
|
579 test.Next(_L("Take stream-lock on client 1")); |
|
580 test (TheTable.FirstL()); |
|
581 TheTable.GetL(); |
|
582 RDbColReadStream rcol; |
|
583 rcol.OpenLC(TheTable,3); |
|
584 test2 (rcol.ReadUint16L(),0); |
|
585 test.Next(_L("Take write-lock on client 1")); |
|
586 RDbTable table2; // need a second cursor (cannot do insert with open streams) |
|
587 test2 (table2.Open(TheDatabase,KTable1,table2.EInsertOnly),KErrNone); |
|
588 TRAPD(r,table2.InsertL()); |
|
589 test2 (r,KErrNone); |
|
590 test.Next(_L("Release write-lock")); |
|
591 table2.PutL(); |
|
592 table2.Close(); |
|
593 test.Next(_L("Release stream-lock")); |
|
594 CleanupStack::PopAndDestroy(); |
|
595 test.Next(_L("release transaction-lock")); |
|
596 test2 (TheDatabase.Commit(),KErrNone); |
|
597 test.End(); |
|
598 } |
|
599 |
|
600 LOCAL_C void TestScenario5L() |
|
601 { |
|
602 test.Start(_L("Begin compaction on client 1")); |
|
603 RDbIncremental inc; |
|
604 TInt s; |
|
605 test2 (inc.Compact(TheDatabase,s),KErrNone); |
|
606 test.Next(_L("Attempt a stream-lock on client 2")); |
|
607 test (TheView.FirstL()); |
|
608 TheView.GetL(); |
|
609 RDbColReadStream rcol; |
|
610 TRAPD(r,rcol.OpenL(TheView,3)); |
|
611 test (r==KErrLocked); |
|
612 test.Next(_L("Attempt a stream-lock on client 1")); |
|
613 TRAP(r,rcol.OpenL(TheTable,3)); |
|
614 test (r==KErrAccessDenied); |
|
615 test.Next(_L("Release compaction lock")); |
|
616 inc.Close(); |
|
617 test.End(); |
|
618 } |
|
619 |
|
620 LOCAL_C void TestScenario6L() |
|
621 { |
|
622 test.Start(_L("Begin compaction on client 1 - open and read columns")); |
|
623 TheTable.Close(); |
|
624 |
|
625 RDbIncremental inc; |
|
626 TInt s; |
|
627 test2 (inc.Compact(TheDatabase,s),KErrNone); |
|
628 |
|
629 test.Next(_L("Attempt to open a table on client 1")); |
|
630 TInt r=TheTable.Open(TheDatabase,KTable1); |
|
631 test (r==KErrNone); |
|
632 |
|
633 //read short column data |
|
634 TheTable.FirstL(); |
|
635 TheTable.GetL(); |
|
636 TheTable.ColInt32(1); |
|
637 |
|
638 // We cant write to tables |
|
639 TRAP(r,TheTable.InsertL()); |
|
640 test (r==KErrAccessDenied); |
|
641 |
|
642 RDbColReadStream rcol; |
|
643 // We can't read long columns |
|
644 TheTable.FirstL(); |
|
645 TheTable.GetL(); |
|
646 TRAP(r, rcol.OpenL(TheTable,3)); |
|
647 test2 (r,KErrAccessDenied); |
|
648 |
|
649 // can read other columns |
|
650 TRAP(r, rcol.OpenL(TheTable,4)); |
|
651 test2 (r,KErrNone); |
|
652 rcol.Close(); |
|
653 |
|
654 test.Next(_L("Release compaction lock")); |
|
655 inc.Close(); |
|
656 test.End(); |
|
657 } |
|
658 |
|
659 LOCAL_C void TestScenario7L() |
|
660 { |
|
661 test.Start(_L("Open tables on client 1 - Begin compaction on client 1")); |
|
662 |
|
663 TheTable.Close(); |
|
664 test.Next(_L("Attempt to open a table on client 1")); |
|
665 TInt r=TheTable.Open(TheDatabase,KTable1); |
|
666 test (r==KErrNone); |
|
667 |
|
668 test.Next(_L("Begin compaction on client 1")); |
|
669 RDbIncremental inc; |
|
670 TInt s; |
|
671 test2 (inc.Compact(TheDatabase,s),KErrNone); |
|
672 |
|
673 //read short column data |
|
674 TheTable.FirstL(); |
|
675 TheTable.GetL(); |
|
676 TheTable.ColInt32(1); |
|
677 |
|
678 // We cant write to tables |
|
679 TRAP(r,TheTable.InsertL()); |
|
680 test (r==KErrAccessDenied); |
|
681 |
|
682 RDbColReadStream rcol; |
|
683 // cant read 4K text |
|
684 TheTable.FirstL(); |
|
685 TheTable.GetL(); |
|
686 TRAP(r, rcol.OpenL(TheTable,3)); |
|
687 test2 (r,KErrAccessDenied); |
|
688 |
|
689 // can read 1K blob |
|
690 TRAP(r, rcol.OpenL(TheTable,4)); |
|
691 test2 (r,KErrNone); |
|
692 rcol.Close(); |
|
693 |
|
694 test.Next(_L("Release compaction lock")); |
|
695 inc.Close(); |
|
696 test.End(); |
|
697 } |
|
698 |
|
699 LOCAL_C void TestScenario8L() |
|
700 { |
|
701 test.Start(_L("Take update-lock on client 1")); |
|
702 test2 (TheDatabase.Begin(),KErrNone); |
|
703 TheTable.InsertL(); |
|
704 test.Next(_L("Read blob without locking on client 2")); |
|
705 test (TheView.FirstL()); |
|
706 TheView.GetL(); |
|
707 RDbColReadStream rcol; |
|
708 rcol.OpenLC(TheView,4); // 1K blob |
|
709 test2 (rcol.ReadInt32L(),0); |
|
710 CleanupStack::PopAndDestroy(); |
|
711 TRAPD(r,rcol.OpenL(TheView,3)); // 4K text blob |
|
712 test2 (r,KErrLocked); |
|
713 test.Next(_L("Release client 1 lock")); |
|
714 TheTable.Cancel(); |
|
715 TheDatabase.Rollback(); |
|
716 test.End(); |
|
717 } |
|
718 |
|
719 /** |
|
720 @SYMTestCaseID SYSLIB-DBMS-CT-0610 |
|
721 @SYMTestCaseDesc Tests for a defect on database |
|
722 @SYMTestPriority Medium |
|
723 @SYMTestActions Tests for database connection |
|
724 @SYMTestExpectedResults Test must not fail |
|
725 @SYMREQ REQ0000 |
|
726 */ |
|
727 LOCAL_C void TestDefectL() |
|
728 { |
|
729 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0610 Build test database ")); |
|
730 Connect(); |
|
731 TInt r=TheDatabase.Open(TheDbs,KTestDatabase); |
|
732 test (r==KErrNone); |
|
733 Execute(KCreateTable1); |
|
734 test2 (TheTable.Open(TheDatabase,KTable1),KErrNone); |
|
735 TheTable.InsertL(); |
|
736 RDbColWriteStream wcol; |
|
737 wcol.OpenLC(TheTable,3); |
|
738 TInt ii; |
|
739 for (ii=0;ii<2048;++ii) |
|
740 wcol.WriteUint16L(ii); |
|
741 wcol.CommitL(); |
|
742 CleanupStack::PopAndDestroy(); |
|
743 wcol.OpenLC(TheTable,4); |
|
744 for (ii=0;ii<256;++ii) |
|
745 wcol.WriteInt32L(ii); |
|
746 wcol.CommitL(); |
|
747 CleanupStack::PopAndDestroy(); |
|
748 TheTable.PutL(); |
|
749 // |
|
750 test.Next(_L("open client 2 connection")); |
|
751 RDbNamedDatabase db; |
|
752 test2 (db.Open(TheDbs,KTestDatabase,KTestFormat),KErrNone); |
|
753 test2 (TheView.Prepare(db,_L("select * from Table1")),KErrNone); |
|
754 test2 (TheView.EvaluateAll(),KErrNone); |
|
755 // |
|
756 test.Next(_L("Scenario 1")); |
|
757 TestScenario1L(); |
|
758 // |
|
759 test.Next(_L("Scenario 2")); |
|
760 TestScenario2L(); |
|
761 // |
|
762 test.Next(_L("Scenario 3")); |
|
763 TestScenario3L(db); |
|
764 // |
|
765 test.Next(_L("Scenario 4")); |
|
766 TestScenario4L(); |
|
767 // |
|
768 test.Next(_L("Scenario 5")); |
|
769 TestScenario5L(); |
|
770 // |
|
771 test.Next(_L("Scenario 6")); |
|
772 TestScenario6L(); |
|
773 // |
|
774 test.Next(_L("Scenario 7")); |
|
775 TestScenario7L(); |
|
776 // |
|
777 test.Next(_L("Scenario 8")); |
|
778 TestScenario8L(); |
|
779 // |
|
780 |
|
781 test.Next(_L("tidy up")); |
|
782 test2 (TheDatabase.Begin(),KErrNone); |
|
783 TheView.Close(); |
|
784 TheTable.Close(); |
|
785 db.Close(); |
|
786 Execute(KDropTable1); |
|
787 test2 (TheDatabase.Commit(),KErrNone); |
|
788 TheDatabase.Close(); |
|
789 Disconnect(); |
|
790 test.End(); |
|
791 } |
|
792 |
|
793 /** |
|
794 @SYMTestCaseID PDS-DBMS-CT-4002 |
|
795 @SYMTestCaseDesc Testing RDbIncremental API |
|
796 @SYMTestPriority High |
|
797 @SYMTestActions Executing SQL using RDbIncremental, Altering tables, creating and droping indexes |
|
798 @SYMTestExpectedResults After execution Table should exist in DB, after altering, table colums should change, |
|
799 creation of index should create index column in table, dropping index should remove |
|
800 it from table |
|
801 @SYMDEF DEF135710 |
|
802 */ |
|
803 LOCAL_C void TestRDbIncrementalAPIL() |
|
804 { |
|
805 test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4002 Testing RDbIncremental API")); |
|
806 |
|
807 Connect(); |
|
808 TInt err = TheDatabase.Open(TheDbs,KTestDatabase); |
|
809 test2(err, KErrNone); |
|
810 |
|
811 test.Next(_L("RDbIncremental API")); |
|
812 RDbIncremental inc; |
|
813 TInt step; |
|
814 |
|
815 test2(TheDatabase.Begin(), KErrNone); |
|
816 err = inc.Execute(TheDatabase, KCreateTable2, step); |
|
817 test2(err, KErrNone); |
|
818 while(step > 0) |
|
819 { |
|
820 err = inc.Next(step); |
|
821 test2(err, KErrNone); |
|
822 } |
|
823 inc.Close(); |
|
824 |
|
825 test.Next(_L("AlterTable")); |
|
826 CDbColSet* colSet = CDbColSet::NewLC(); |
|
827 colSet->AddL(TDbCol(_L("Id2"), EDbColUint32)); |
|
828 colSet->AddL(TDbCol(_L("Memo2"), EDbColText)); |
|
829 test2(colSet->Count(), 2); |
|
830 err = inc.AlterTable(TheDatabase, KTable2, *colSet, step); |
|
831 test2(err, KErrNone); |
|
832 while(step > 0) |
|
833 { |
|
834 err = inc.Next(step); |
|
835 test2(err, KErrNone); |
|
836 } |
|
837 inc.Close(); |
|
838 err = TheDatabase.Commit(); |
|
839 test2(err, KErrNone); |
|
840 |
|
841 test.Next(_L("CreateIndex")); |
|
842 TDbKeyCol kcol(_L("Id2"), TDbKeyCol::EAsc); |
|
843 CDbKey* key = CDbKey::NewLC(); |
|
844 test2(TheDatabase.Begin(), KErrNone); |
|
845 key->AddL(kcol); |
|
846 err = inc.CreateIndex(TheDatabase, _L("Id2"), KTable2, *key, step); |
|
847 test2(err, KErrNone); |
|
848 while(step > 0) |
|
849 { |
|
850 err = inc.Next(step); |
|
851 test2(err, KErrNone); |
|
852 } |
|
853 inc.Close(); |
|
854 |
|
855 test.Next(_L("DropIndex")); |
|
856 err = inc.DropIndex(TheDatabase, _L("Id2"), KTable2, step); |
|
857 test2(err, KErrNone); |
|
858 while(step > 0) |
|
859 { |
|
860 err = inc.Next(step); |
|
861 test2(err, KErrNone); |
|
862 } |
|
863 inc.Close(); |
|
864 err = inc.Execute(TheDatabase, KDropTable2, step); |
|
865 test2(err, KErrNone); |
|
866 while(step > 0) |
|
867 { |
|
868 err = inc.Next(step); |
|
869 test2(err, KErrNone); |
|
870 } |
|
871 err = TheDatabase.Commit(); |
|
872 test2(err, KErrNone); |
|
873 inc.Close(); |
|
874 |
|
875 CleanupStack::PopAndDestroy(2); |
|
876 |
|
877 TheDatabase.Close(); |
|
878 Disconnect(); |
|
879 test.End(); |
|
880 } |
|
881 |
|
882 /** |
|
883 @SYMTestCaseID PDS-DBMS-CT-4003 |
|
884 @SYMTestCaseDesc Testing RDbUpdate API |
|
885 @SYMTestPriority High |
|
886 @SYMTestActions Executing DML command using RDbUpdate, checking if rowCount working properly |
|
887 @SYMTestExpectedResults After DML execution, rowCount should return proper number of afected rows. |
|
888 @SYMDEF DEF135710 |
|
889 */ |
|
890 LOCAL_C void TestRDbUpdate() |
|
891 { |
|
892 test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4003 Testing RDbUpdate API")); |
|
893 _LIT(DMLinsert, "INSERT INTO Table2 VALUES (2,'Mietek', 'Mietek ma kota')"); |
|
894 |
|
895 Connect(); |
|
896 TInt err = TheDatabase.Open(TheDbs,KTestDatabase); |
|
897 test2(err, KErrNone); |
|
898 |
|
899 err = TheDatabase.Begin(); |
|
900 test2(err, KErrNone); |
|
901 |
|
902 err = TheDatabase.Execute(KCreateTable2, EDbCompareNormal); |
|
903 test(err >= KErrNone); |
|
904 |
|
905 RDbUpdate update; |
|
906 err = update.Execute(TheDatabase, DMLinsert, EDbCompareNormal ); |
|
907 if(err != KErrNone) |
|
908 RDebug::Printf("Error on Execute %d",err); |
|
909 test2(err, KErrNone); |
|
910 |
|
911 TInt rows = update.RowCount(); |
|
912 RDebug::Printf("Afected rows %d",rows); |
|
913 test2(rows, 1); |
|
914 update.Close(); |
|
915 |
|
916 err = TheDatabase.Commit(); |
|
917 test2(err, KErrNone); |
|
918 |
|
919 TheDatabase.Close(); |
|
920 Disconnect(); |
|
921 test.End(); |
|
922 } |
|
923 |
|
924 /** |
|
925 @SYMTestCaseID PDS-DBMS-CT-4004 |
|
926 @SYMTestCaseDesc Testing RDbRow API |
|
927 @SYMTestPriority High |
|
928 @SYMTestActions Test for construction functions for RDbRow |
|
929 @SYMTestExpectedResults After Creation/Opening row should be a valid object. |
|
930 @SYMDEF DEF135710 |
|
931 */ |
|
932 LOCAL_C void TestRDbRowL() |
|
933 { |
|
934 test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4004 Testing RDbRow API")); |
|
935 const TInt KRowSize = 300; |
|
936 const TInt KRealRowSize = 512; |
|
937 |
|
938 RDbRow row; |
|
939 row.CreateL(KRowSize); |
|
940 RDebug::Printf("Rows %d %d",row.Size(), row.MaxSize() ); |
|
941 test2(row.MaxSize(), KRealRowSize); |
|
942 TAny* rptr = row.First(); |
|
943 |
|
944 RDbRow row2; |
|
945 row2.Open(rptr, KRowSize, 2*KRowSize); |
|
946 RDebug::Printf("Row2s %d %d", KRowSize, row2.MaxSize()); |
|
947 test2(row2.Size(), KRowSize); |
|
948 test2(row2.MaxSize(), 2*KRowSize); |
|
949 |
|
950 row.Close(); |
|
951 row2.Close(); |
|
952 test.End(); |
|
953 } |
|
954 /* |
|
955 * Helper function for SYSLIB-DBMS-CT-4005 Testing TTextOps API |
|
956 */ |
|
957 LOCAL_C TInt HelperCompareForTestTTextOps(const TText8*,TInt,const TText8*,TInt) |
|
958 { |
|
959 return KReturnValueForCompare; |
|
960 } |
|
961 /* |
|
962 * Helper function for SYSLIB-DBMS-CT-4005 Testing TTextOps API |
|
963 */ |
|
964 LOCAL_C TInt HelperFindForTestTTextOps(const TDesC8&,const TText8*,TInt) |
|
965 { |
|
966 return KReturnValueForFind; |
|
967 } |
|
968 /** |
|
969 @SYMTestCaseID PDS-DBMS-CT-4005 |
|
970 @SYMTestCaseDesc Testing TTextOps API |
|
971 @SYMTestPriority High |
|
972 @SYMTestActions Test for Compare and Find functions for TTextOps |
|
973 @SYMTestExpectedResults Test if those functions really calling proper targets. |
|
974 @SYMDEF DEF135710 |
|
975 */ |
|
976 LOCAL_C void TestTTextOps() |
|
977 { |
|
978 test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4005 Testing TTextOps API")); |
|
979 TTextOps text; |
|
980 |
|
981 text.iCompare8 = HelperCompareForTestTTextOps; |
|
982 text.iFind8 = HelperFindForTestTTextOps; |
|
983 TInt ret = text.Compare(_L8("Ala ma kota"), _L8("Ala ma konia")); |
|
984 test2(ret, KReturnValueForCompare); |
|
985 ret = text.Find(_L8("Ala ma kota"), _L8("ma ko")); |
|
986 test2(ret, KReturnValueForFind); |
|
987 |
|
988 test.End(); |
|
989 } |
|
990 |
|
991 #if defined __WINS__ || defined __WINSCW__ |
|
992 |
|
993 LOCAL_C TInt ExecuteRemoteL(const TDesC& aCommand, const TDesC& aCommandLineArg) |
|
994 { |
|
995 RProcess process; |
|
996 User::LeaveIfError(process.Create(aCommand, aCommandLineArg)); |
|
997 |
|
998 TRequestStatus status; |
|
999 process.Logon(status); |
|
1000 process.Resume(); |
|
1001 |
|
1002 User::WaitForRequest(status); |
|
1003 TInt exitReason = process.ExitReason(); |
|
1004 |
|
1005 process.Close(); |
|
1006 User::LeaveIfError(exitReason); |
|
1007 |
|
1008 return exitReason; |
|
1009 } |
|
1010 |
|
1011 #endif //defined __WINS__ || defined __WINSCW__ |
|
1012 |
|
1013 /** |
|
1014 @SYMTestCaseID PDS-DBMS-CT-4007 |
|
1015 @SYMTestCaseDesc Testing SPConv - This test case uses the Edbsconv tool |
|
1016 so therefore only runs on WINSCW builds |
|
1017 @SYMTestPriority High |
|
1018 @SYMTestActions Launch the external tool to generate SPD files |
|
1019 @SYMTestExpectedResults Should produce SPD files and report no errors |
|
1020 @SYMDEF DEF135710 |
|
1021 */ |
|
1022 LOCAL_C void TestSPConvL() |
|
1023 { |
|
1024 test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4007 Testing SPConv")); |
|
1025 |
|
1026 #if defined __WINS__ || defined __WINSCW__ |
|
1027 |
|
1028 _LIT(KRomTxtFile1, "z:\\test\\11335577.txt"); |
|
1029 _LIT(KRomTxtFile2, "z:\\test\\11335578.txt"); |
|
1030 _LIT(KRomTxtFile3, "z:\\test\\11335579.txt"); |
|
1031 _LIT(KRomTxtFile4, "z:\\test\\1133557A.txt"); |
|
1032 _LIT(KCommand,"Edbspconv"); |
|
1033 _LIT(KCommandParameter, " /f=%S /b=%S /s"); |
|
1034 |
|
1035 TBuf<200> commandParameter; |
|
1036 |
|
1037 test.Next(_L("Create SPD File from \"11335577.txt\"")); |
|
1038 commandParameter.Format(KCommandParameter, &KRomTxtFile1, &KTestSpdFile1); |
|
1039 ExecuteRemoteL(KCommand, commandParameter); |
|
1040 |
|
1041 test.Next(_L("Create SPD File from \"11335578.txt\"")); |
|
1042 commandParameter.Format(KCommandParameter, &KRomTxtFile2, &KTestSpdFile2); |
|
1043 ExecuteRemoteL(KCommand, commandParameter); |
|
1044 |
|
1045 test.Next(_L("Create SPD File from \"11335579.txt\"")); |
|
1046 commandParameter.Format(KCommandParameter, &KRomTxtFile3, &KTestSpdFile3); |
|
1047 ExecuteRemoteL(KCommand, commandParameter); |
|
1048 |
|
1049 test.Next(_L("Create SPD File from \"1133557A.txt\"")); |
|
1050 commandParameter.Format(KCommandParameter, &KRomTxtFile4, &KTestSpdFile4); |
|
1051 ExecuteRemoteL(KCommand, commandParameter); |
|
1052 |
|
1053 #else |
|
1054 RDebug::Print(_L("Testing SPConv - This test case cannot run on hardware")); |
|
1055 #endif |
|
1056 |
|
1057 test.Next(_L("End")); |
|
1058 test.End(); |
|
1059 } |
|
1060 |
|
1061 |
|
1062 /** |
|
1063 @SYMTestCaseID SYSLIB-DBMS-CT-0611 |
|
1064 @SYMTestCaseDesc Tests the behaviour of observers |
|
1065 @SYMTestPriority Medium |
|
1066 @SYMTestActions Tests for DDL,DML |
|
1067 @SYMTestExpectedResults Test must not fail |
|
1068 @SYMREQ REQ0000 |
|
1069 */ |
|
1070 LOCAL_C void TestObserverL() |
|
1071 { |
|
1072 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0611 Single connection/observer ")); |
|
1073 Connect(); |
|
1074 TInt r=TheDatabase.Open(TheDbs,KTestDatabase); |
|
1075 test (r==KErrNone); |
|
1076 RDbNotifier ob; |
|
1077 r=ob.Open(TheDatabase); |
|
1078 test (r==KErrNone); |
|
1079 // |
|
1080 test.Next(_L("Cancel")); |
|
1081 TRequestStatus stat; |
|
1082 ob.NotifyUnlock(stat); |
|
1083 test (stat==KRequestPending); |
|
1084 ob.Cancel(); |
|
1085 User::WaitForRequest(stat); |
|
1086 test (stat==KErrCancel); |
|
1087 // |
|
1088 test.Next(_L("Close")); |
|
1089 ob.NotifyUnlock(stat); |
|
1090 test (stat==KRequestPending); |
|
1091 ob.Close(); |
|
1092 User::WaitForRequest(stat); |
|
1093 test (stat==KErrCancel); |
|
1094 // |
|
1095 test.Next(_L("DDL")); |
|
1096 r=ob.Open(TheDatabase); |
|
1097 test (r==KErrNone); |
|
1098 ob.NotifyUnlock(stat); |
|
1099 test (stat==KRequestPending); |
|
1100 Execute(KCreateTable1); |
|
1101 User::WaitForRequest(stat); |
|
1102 test (stat==ob.ECommit); |
|
1103 // |
|
1104 test.Next(_L("DML")); |
|
1105 ob.NotifyUnlock(stat); |
|
1106 test (stat==KRequestPending); |
|
1107 r=TheTable.Open(TheDatabase,KTable1); |
|
1108 test (r==KErrNone); |
|
1109 WriteRecordsL(50); |
|
1110 User::WaitForRequest(stat); |
|
1111 test (stat==ob.ECommit); |
|
1112 // |
|
1113 test.Next(_L("Locked read")); |
|
1114 ob.NotifyUnlock(stat); |
|
1115 TheDatabase.Begin(); |
|
1116 test (stat==KRequestPending); |
|
1117 TheDatabase.Commit(); |
|
1118 User::WaitForRequest(stat); |
|
1119 test (stat==ob.EUnlock); |
|
1120 // |
|
1121 test.Next(_L("Database closed")); |
|
1122 ob.NotifyUnlock(stat); |
|
1123 TheTable.Close(); |
|
1124 TheDatabase.Close(); |
|
1125 User::WaitForRequest(stat); |
|
1126 test (stat==ob.EClose); |
|
1127 ob.NotifyUnlock(stat); |
|
1128 User::WaitForRequest(stat); |
|
1129 test (stat==ob.EClose); |
|
1130 // |
|
1131 test.Next(_L("Re-open database")); |
|
1132 r=TheDatabase.Open(TheDbs,KTestDatabase); |
|
1133 test (r==KErrNone); |
|
1134 ob.NotifyUnlock(stat); |
|
1135 User::WaitForRequest(stat); |
|
1136 test (stat==ob.EClose); |
|
1137 ob.Close(); |
|
1138 // |
|
1139 test.Next(_L("Multiple connections and observers")); |
|
1140 r=ob.Open(TheDatabase); |
|
1141 test (r==KErrNone); |
|
1142 RDbNamedDatabase db2; |
|
1143 r=db2.Open(TheDbs,KTestDatabase); |
|
1144 test (r==KErrNone); |
|
1145 RDbNotifier ob2; |
|
1146 r=ob2.Open(db2); |
|
1147 test (r==KErrNone); |
|
1148 // |
|
1149 test.Next(_L("Cancel")); |
|
1150 ob.NotifyUnlock(stat); |
|
1151 TRequestStatus stat2; |
|
1152 ob2.NotifyUnlock(stat2); |
|
1153 test (stat==KRequestPending); |
|
1154 ob.Cancel(); |
|
1155 User::WaitForRequest(stat); |
|
1156 test (stat==KErrCancel); |
|
1157 test (stat2==KRequestPending); |
|
1158 ob2.Cancel(); |
|
1159 User::WaitForRequest(stat2); |
|
1160 test (stat2==KErrCancel); |
|
1161 // |
|
1162 test.Next(_L("Close")); |
|
1163 ob.NotifyUnlock(stat); |
|
1164 ob2.NotifyUnlock(stat2); |
|
1165 test (stat2==KRequestPending); |
|
1166 ob2.Close(); |
|
1167 User::WaitForRequest(stat2); |
|
1168 test (stat2==KErrCancel); |
|
1169 test (stat==KRequestPending); |
|
1170 ob.Close(); |
|
1171 User::WaitForRequest(stat); |
|
1172 test (stat==KErrCancel); |
|
1173 // |
|
1174 test.Next(_L("NotifyChange")); |
|
1175 r=ob.Open(TheDatabase); |
|
1176 test (r==KErrNone); |
|
1177 r=ob2.Open(db2); |
|
1178 test (r==KErrNone); |
|
1179 ob.NotifyUnlock(stat); |
|
1180 ob2.NotifyChange(stat2); |
|
1181 TheDatabase.Begin(); |
|
1182 r=TheDatabase.Commit(); |
|
1183 test (r==KErrNone); |
|
1184 User::WaitForRequest(stat); |
|
1185 test (stat==ob.EUnlock); |
|
1186 test (stat2==KRequestPending); |
|
1187 ob.NotifyUnlock(stat); |
|
1188 db2.Begin(); |
|
1189 r=db2.Commit(); |
|
1190 test (r==KErrNone); |
|
1191 User::WaitForRequest(stat); |
|
1192 test (stat==ob.EUnlock); |
|
1193 test (stat2==KRequestPending); |
|
1194 Execute(KDropTable1); |
|
1195 User::WaitForRequest(stat2); |
|
1196 test (stat2==ob.ECommit); |
|
1197 // |
|
1198 test.Next(_L("missed event")); |
|
1199 ob.NotifyUnlock(stat); |
|
1200 User::WaitForRequest(stat); |
|
1201 test (stat==ob.ECommit); |
|
1202 // |
|
1203 test.Next(_L("database close")); |
|
1204 ob.NotifyUnlock(stat); |
|
1205 test (stat==KRequestPending); |
|
1206 ob2.NotifyUnlock(stat2); |
|
1207 test (stat2==KRequestPending); |
|
1208 TheDatabase.Close(); |
|
1209 User::After(0x20000); // ~.1s |
|
1210 test (stat==KRequestPending); |
|
1211 test (stat2==KRequestPending); |
|
1212 db2.Close(); |
|
1213 User::WaitForRequest(stat); |
|
1214 test (stat==ob.EClose); |
|
1215 User::WaitForRequest(stat2); |
|
1216 test (stat2==ob.EClose); |
|
1217 ob.NotifyUnlock(stat); |
|
1218 User::WaitForRequest(stat); |
|
1219 test (stat==ob.EClose); |
|
1220 ob.Cancel(); |
|
1221 ob.Close(); |
|
1222 ob2.NotifyUnlock(stat2); |
|
1223 User::WaitForRequest(stat2); |
|
1224 test (stat2==ob.EClose); |
|
1225 ob2.Cancel(); |
|
1226 ob2.Close(); |
|
1227 // |
|
1228 Disconnect(); |
|
1229 test.End(); |
|
1230 } |
|
1231 |
|
1232 LOCAL_C void setupTestDirectory() |
|
1233 // |
|
1234 // Prepare the test directory. |
|
1235 // |
|
1236 { |
|
1237 TInt r=TheFs.Connect(); |
|
1238 test(r==KErrNone); |
|
1239 // |
|
1240 r=TheFs.MkDir(KTestDatabase); |
|
1241 test(r==KErrNone || r==KErrAlreadyExists); |
|
1242 } |
|
1243 |
|
1244 LOCAL_C void setupCleanup() |
|
1245 // |
|
1246 // Initialise the cleanup stack. |
|
1247 // |
|
1248 { |
|
1249 TheTrapCleanup=CTrapCleanup::New(); |
|
1250 test(TheTrapCleanup!=NULL); |
|
1251 TRAPD(r,\ |
|
1252 {\ |
|
1253 for (TInt i=KTestCleanupStack;i>0;i--)\ |
|
1254 CleanupStack::PushL((TAny*)0);\ |
|
1255 CleanupStack::Pop(KTestCleanupStack);\ |
|
1256 }); |
|
1257 test(r==KErrNone); |
|
1258 } |
|
1259 |
|
1260 void DoTests() |
|
1261 { |
|
1262 TVersionName n=RDbs::Version().Name(); |
|
1263 test.Printf(_L("DBMS server v%S\n"),&n); |
|
1264 TInt r; |
|
1265 test.Start(_L("Connection")); |
|
1266 TestConnect(); |
|
1267 |
|
1268 test.Next(_L("Open Database")); |
|
1269 TRAP(r,TestOpenL()); |
|
1270 test2 (r,KErrNone); |
|
1271 |
|
1272 test.Next(_L("test defect")); |
|
1273 TRAP(r,TestDefectL()); |
|
1274 test2 (r,KErrNone); |
|
1275 |
|
1276 test.Next(_L("Share Database")); |
|
1277 TRAP(r,TestShareL()); |
|
1278 test2 (r,KErrNone); |
|
1279 |
|
1280 test.Next(_L("Locking")); |
|
1281 TRAP(r,TestLocking()); |
|
1282 test2 (r,KErrNone); |
|
1283 |
|
1284 test.Next(_L("Observers")); |
|
1285 TRAP(r,TestObserverL()); |
|
1286 test2 (r,KErrNone); |
|
1287 |
|
1288 test.Next(_L("Benchmarks")); |
|
1289 TRAP(r,TestBenchL()); |
|
1290 test2 (r,KErrNone); |
|
1291 |
|
1292 test.Next(_L("RDbIncremental")); |
|
1293 TRAP(r, TestRDbIncrementalAPIL() ); |
|
1294 test2 (r,KErrNone); |
|
1295 |
|
1296 test.Next(_L("RDbUpdate")); |
|
1297 TestRDbUpdate(); |
|
1298 |
|
1299 test.Next(_L("RDbRow")); |
|
1300 TRAP(r, TestRDbRowL() ); |
|
1301 test2 (r,KErrNone); |
|
1302 |
|
1303 test.Next(_L("TTextOpsL")); |
|
1304 TestTTextOps(); |
|
1305 |
|
1306 test.Next(_L("TestSPConvL")); |
|
1307 TRAP(r, TestSPConvL() ); |
|
1308 test2 (r, KErrNone); |
|
1309 |
|
1310 test.Next(_L("Waiting for server exit")); |
|
1311 } |
|
1312 |
|
1313 |
|
1314 GLDEF_C TInt E32Main() |
|
1315 // |
|
1316 // Test streaming conversions. |
|
1317 // |
|
1318 { |
|
1319 __UHEAP_MARK; |
|
1320 |
|
1321 test.Title(); |
|
1322 setupTestDirectory(); |
|
1323 DeleteTestFiles(); |
|
1324 setupCleanup(); |
|
1325 DoTests(); |
|
1326 delete TheTrapCleanup; |
|
1327 DeleteTestFiles(); |
|
1328 |
|
1329 test.End(); |
|
1330 TheFs.Close(); |
|
1331 test.Close(); |
|
1332 __UHEAP_MARKEND; |
|
1333 return 0; |
|
1334 } |