Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Test code for bugs that have been fixed, to help prevent regression
25 #undef __UHEAP_MARKEND
27 #define __UHEAP_MARKEND
29 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
31 #ifndef __linux__ //No CRC test on LINUX
33 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_BUG.CRC");
35 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_BUG.CRC");
39 LOCAL_D RTest test(_L("T_BUG"));
40 LOCAL_D CTrapCleanup* TheTrapCleanup;
42 LOCAL_D RDbNamedDatabase TheDatabase;
44 const TInt KTestCleanupStack=0x40;
46 void Check(TInt aValue,TInt aExpected,TInt aLine)
48 if (aValue!=aExpected)
50 test.Printf(_L("*** Expected %d: got %d\r\n"),aExpected,aValue);
51 test.operator()(EFalse,aLine);
54 #define test2(a,b) Check(a,b,__LINE__)
56 static void Print(const TText* aString)
58 test.Printf(_L("%s\n"),aString);
61 ////////////////////////////////////////////
65 const TPtrC KTestDatabase=_L(".\\dbms-tst\\t_bug.db");
67 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\t_bug.db");
78 static const TDesC& Name();
82 const TDesC& Defect_590829::Name()
88 /////////////////////////////////////////////////
90 // Length of text data used for each entry. This will be
91 // equivalent to 400 bytes for ansi characters. The number of
92 // bytes must not be less than 256 (or 128 for this const).
93 // If it is a stream will not be used for transfer of data.
94 const TInt KTextDataLength = 200;
97 const TInt KMaxColLength = 1000;
99 // Buffer size to cause HDbsBuf::DoReadL() ipc check to be executed
100 const TInt KBufSizeDoReadL = 1000;
102 // Buffer size to cause HDbsBuf::UnderflowL() ipc check to be executed
103 const TInt KBufSizeUnderflowL = 500;
109 static const TDesC& Name();
113 const TDesC& Defect_071149::Name()
115 _LIT(KName,"071149");
120 HDbsBuf did not handle case when iIpc.iHandle is 0 causing IPC calls to panic.
121 The handle is 0 when opening a stream and all data is retrieved in this request.
123 @SYMTestCaseID SYSLIB-DBMS-CT-1491
124 @SYMTestCaseDesc Tests for defect number 590829
125 @SYMTestPriority High
126 @SYMTestActions Tests by setting up failure conditions.
127 @SYMTestExpectedResults Test must not fail
130 void Defect_071149::TestL()
132 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1491 "));
133 Print(_S("Creating test database"));
135 // Connect to dbms and open db
138 test2 (db.Replace(TheFs,KTestDatabase),KErrNone);
140 TheCrcChecker.GenerateCrcL(KTestDatabase);
143 test2(dbs.Connect(), KErrNone);
145 test2(db.Open(dbs,KTestDatabase), KErrNone);
147 // creating column to hold LongText
148 CDbColSet *colSet = CDbColSet::NewL();
149 CleanupStack::PushL(colSet);
150 colSet->AddL(TDbCol(_L("Id"), EDbColLongText, KMaxColLength));
153 test2(db.CreateTable(KTableA, *colSet), KErrNone);
154 CleanupStack::PopAndDestroy(colSet);
156 // create text data to add to table
157 HBufC* testText = HBufC::New(KTextDataLength);
158 test(testText !=NULL );
159 TPtr ptr = testText->Des();
160 for(TInt y=0;y<KTextDataLength;++y)
162 ptr.Append(TChar('A'));
167 test2 (newTable.Open(db,KTableA),KErrNone);
170 newTable.SetColL(1, ptr);
173 test2 (db.Commit(),KErrNone);
174 test2 (newTable.CountL(), 1);
180 // disconnect from db and dbms
182 TheCrcChecker.GenerateCrcL(KTestDatabase);
188 // Connect to dbms and open db
190 test2(dbs.Connect(), KErrNone);
192 test2(db.Open(dbs,KTestDatabase), KErrNone);
194 // Test handle check in HDbsBuf::DoReadL() - See defect
195 // If the handle check did not exist in the production code then
200 test2 (testTable.Open(db,KTableA),KErrNone);
207 rs.OpenLC( testTable, 1);
210 TBuf<KBufSizeDoReadL> buf;
211 TRAPD(err, rs.ReadL( buf, buf.MaxLength()));
216 CleanupStack::PopAndDestroy(); // Close rs
220 // Test handle check in HDbsBuf::UnderflowL() - additional error not in defect
221 // If the handle check did not exist in the production code then
225 test2 (testTable.Open(db,KTableA),KErrNone);
230 RDbColReadStream rs2;
231 rs2.OpenLC( testTable, 1);
234 TBuf<KBufSizeUnderflowL> buf2;
235 TRAP(err, rs2.ReadL( buf2, buf2.MaxLength()));
240 CleanupStack::PopAndDestroy(); // Close rs
250 /////////////////////////////////////////////////
253 Cached, unused tables were breaking the iterator in CDbTableDatabase::CheckIdle
254 The latter function has been re-written to restart the iteration when tables are Idle()'d
256 @SYMTestCaseID SYSLIB-DBMS-CT-0582
257 @SYMTestCaseDesc Tests for defect number 590829
258 @SYMTestPriority Medium
259 @SYMTestActions Tests by setting up failure conditions.
260 @SYMTestExpectedResults Test must not fail
263 void Defect_590829::TestL()
265 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0582 "));
266 Print(_S("Creating test database"));
267 test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
269 test2 (TheDatabase.Execute(_L("create table A (id counter)")),KErrNone);
270 test2 (TheDatabase.Execute(_L("create table B (id counter)")),KErrNone);
271 test2 (TheDatabase.Execute(_L("create table C (id counter)")),KErrNone);
272 test2 (TheDatabase.Commit(),KErrNone);
274 Print(_S("Setting up failure"));
276 test2 (tA.Open(TheDatabase,KTableA),KErrNone);
277 test2 (tB.Open(TheDatabase,KTableB),KErrNone);
279 test2 (tC.Open(TheDatabase,KTableC),KErrNone);
284 Print(_S("Testing fix"));
285 test2 (TheDatabase.Commit(),KErrNone);
286 TheDatabase.Destroy();
289 /////////////////////////////////////////////////
291 #ifndef TOOLS2_VARIANT
296 static const TDesC& Name();
298 static TInt Thread(TAny*);
299 static void ThreadL();
303 const TDesC& Defect_394751::Name()
305 _LIT(KName,"394751");
309 void Defect_394751::ThreadL()
313 User::LeaveIfError(dbs.Connect());
314 User::LeaveIfError(db.Open(dbs,KTestDatabase));
316 db.Begin(); /// panic now
317 User::Panic(_L("T_BUG failure"),0);
320 TInt Defect_394751::Thread(TAny*)
322 User::SetJustInTime(EFalse); // disable debugger panic handling
323 CTrapCleanup* cleanup=CTrapCleanup::New();
332 @SYMTestCaseID SYSLIB-DBMS-CT-0583
333 @SYMTestCaseDesc Tests for defect number 394751
334 @SYMTestPriority Medium
335 @SYMTestActions Tests for thread exit status.
336 @SYMTestExpectedResults Test must not fail
339 void Defect_394751::TestL()
343 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0583 "));
344 Print(_S("Creating test database"));
345 test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
347 TheCrcChecker.GenerateCrcL(KTestDatabase);
350 test2 (dbs.Connect(),KErrNone);
352 Print(_S("Running test thread"));
354 _LIT(KTestThread,"Defect Fix 394751");
355 test2 (t.Create(KTestThread,&Thread,0x2000,0x1000,0x10000,0,EOwnerThread),KErrNone);
358 test2 (s.Int(),KRequestPending);
360 Print(_S("Awaiting completion"));
361 User::WaitForRequest(s);
362 _LIT(KCategory,"DBMS-Table");
363 test2 (t.ExitType(),EExitPanic);
364 test (t.ExitCategory()==KCategory);
365 test2 (t.ExitReason(),11); // begin nested transaction
366 User::SetJustInTime(ETrue); // enable debugger panic handling
369 test2 (dbs.ResourceCount(),0);
374 ///////////////////////////////////////////////////////////
376 #ifndef TOOLS2_VARIANT
377 class Defect_COMBBAR_463J5D
381 static const TDesC& Name();
383 static void WaitForServerExit();
384 static TInt Thread(TAny*);
387 const TDesC& Defect_COMBBAR_463J5D::Name()
389 _LIT(KName,"COMBBAR_463J5D");
393 void Defect_COMBBAR_463J5D::WaitForServerExit()
395 _LIT(KDbmsServer,"*!DBMS server");
397 TFindThread ft(KDbmsServer);
398 if (ft.Next(n)==KErrNone)
401 if (t.Open(ft)==KErrNone)
405 User::WaitForRequest(s);
411 TInt Defect_COMBBAR_463J5D::Thread(TAny*)
413 // Just try to start the server
417 return dbs.Connect();
421 @SYMTestCaseID SYSLIB-DBMS-CT-0584
422 @SYMTestCaseDesc Tests for defect number COMBBAR_463J5D
423 @SYMTestPriority Medium
424 @SYMTestActions Testing that defect COMBBAR_463J5D in ER5 Defects database has been fixed
425 @SYMTestExpectedResults Test must not fail
428 void Defect_COMBBAR_463J5D::TestL()
430 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0584 "));
431 Print(_S("Wait for the server to exit"));
434 Print(_S("Create the launching threads"));
436 TRequestStatus s1,s2;
438 test2 (t1.Create(KThread1,&Thread,0x2000,0,0,EOwnerThread),KErrNone);
439 t1.SetPriority(EPriorityLess);
442 test2 (t2.Create(KThread2,&Thread,0x2000,0,0,EOwnerThread),KErrNone);
443 t2.SetPriority(EPriorityLess);
446 Print(_S("Run the threads and wait"));
449 User::WaitForRequest(s1,s2);
450 if (s1==KRequestPending)
451 User::WaitForRequest(s1);
453 User::WaitForRequest(s2);
455 test2 (t1.ExitType(),EExitKill);
456 if (s1.Int()!=KErrNotFound)
457 test2 (s1.Int(),KErrNone);
458 test2 (t2.ExitType(),EExitKill);
459 if (s2.Int()!=KErrNotFound)
460 test2 (s2.Int(),KErrNone);
466 /////////////////////////////////////////////////////////
468 class Defect_EDNATHE_48AEZW
472 static const TDesC& Name();
475 const TDesC& Defect_EDNATHE_48AEZW::Name()
477 _LIT(KName,"EDNATHE_48AEZW");
481 @SYMTestCaseID SYSLIB-DBMS-CT-0585
482 @SYMTestCaseDesc Tests for defect number EDNATHE_48AEZW
483 @SYMTestPriority Medium
484 @SYMTestActions Tests for navigation and deletion
485 @SYMTestExpectedResults Test must not fail
488 void Defect_EDNATHE_48AEZW::TestL()
490 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0585 "));
491 Print(_S("Set up database"));
492 test2 (TheDatabase.Replace(TheFs,KTestDatabase),KErrNone);
493 test2 (TheDatabase.Begin(),KErrNone);
494 test2 (TheDatabase.Execute(_L("create table A (id counter)")),KErrNone);
496 test2 (v1.Prepare(TheDatabase,_L("select * from A"),v1.EInsertOnly),KErrNone);
497 test2 (v1.EvaluateAll(),KErrNone);
498 for (TInt ii=0;ii<4;++ii)
503 test2 (TheDatabase.Commit(),KErrNone);
506 Print(_S("test navigation"));
507 test2 (v1.Prepare(TheDatabase,_L("select * from A where id=0")),KErrNone);
508 test2 (v1.EvaluateAll(),KErrNone);
511 test2 (v2.Prepare(TheDatabase,_L("select * from A where id=1")),KErrNone);
512 test2 (v2.EvaluateAll(),KErrNone);
515 TRAPD(r, v1.NextL());
520 Print(_S("test deletion"));
522 test2 (v2.Prepare(TheDatabase,_L("select * from A where id=2")),KErrNone);
523 test2 (v2.EvaluateAll(),KErrNone);
526 TRAP(r,v1.DeleteL());
535 TheCrcChecker.GenerateCrcL(KTestDatabase);
538 /////////////////////////////////////////////////////////
540 static void NextTest(const TDesC& aName)
543 buf=_S("Checking Defect ");
548 template <typename T>
553 const TDesC& name = T::Name();
557 Print(_S("Defect fixed"));
561 LOCAL_C void setupTestDirectory()
563 // Prepare the test directory.
566 TInt r=TheFs.Connect();
569 r=TheFs.MkDir(KTestDatabase);
570 test(r==KErrNone || r==KErrAlreadyExists);
573 LOCAL_C void setupCleanup()
575 // Initialise the cleanup stack.
578 TheTrapCleanup=CTrapCleanup::New();
579 test(TheTrapCleanup!=NULL);
582 for (TInt i=KTestCleanupStack;i>0;i--)\
583 CleanupStack::PushL((TAny*)0);\
584 CleanupStack::Pop(KTestCleanupStack);\
589 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
592 TInt err = fsSession.Connect();
596 if(fsSession.Entry(aFullName, entry) == KErrNone)
598 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
599 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
602 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
604 err = fsSession.Delete(aFullName);
607 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
614 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
619 GLDEF_C TInt E32Main()
623 setupTestDirectory();
626 test.Start(_L("Verifying defect fixes"));
627 #ifndef TOOLS2_VARIANT
628 RunTest<Defect_COMBBAR_463J5D>();
630 test.Printf(_L("Skipping defect test Defect_COMBBAR_463J5D\n"));
632 // The following short delay is needed for ccover builds only.
633 // Without the pause, the kernel scheduler would intermittently
634 // crash 0.3s after the last test ended.
636 test.Printf(_L("Resume test after delay.\n"));
638 #ifndef TOOLS2_VARIANT
639 RunTest<Defect_394751>();
641 test.Printf(_L("Resume test after delay.\n"));
643 test.Printf(_L("Skipping defect test of Defect_394751\n"));
646 RunTest<Defect_590829>();
648 test.Printf(_L("Resume test after delay.\n"));
650 RunTest<Defect_071149>();
652 test.Printf(_L("Resume test after delay.\n"));
654 RunTest<Defect_EDNATHE_48AEZW>();
655 test.Next(_L("Waiting for server exit"));
656 const TUint KExitDelay=6*0x100000; // ~6 seconds
657 User::After(KExitDelay);
659 // clean up data files used by this test - must be done before call to End() - DEF047652
660 ::DeleteDataFile(KTestDatabase);
665 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
669 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
671 TheCrcChecker.ErrorReportL(err, errmsg);
672 RDebug::Print(errmsg);
673 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
679 delete TheTrapCleanup;