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.
25 #undef __UHEAP_MARKEND
26 #define __UHEAP_MARKEND
28 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
30 #ifndef __linux__ //No CRC test on LINUX
32 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_DBMS.CRC");
34 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_DBMS.CRC");
38 #if defined(__VC32__) && !defined(_DEBUG)
39 #pragma warning(disable : 4710) // function not expanded. MSVC 4.0 is stupid
42 LOCAL_D RTest test(_L("T_DBMS : Test DBMS API"));
43 LOCAL_D CTrapCleanup* TheTrapCleanup;
45 LOCAL_D RDbNamedDatabase TheDatabase;
46 LOCAL_D RDbTable TheTable;
47 LOCAL_D RDbView TheView;
49 LOCAL_D TBuf8<0x200> TheBuf8;
50 LOCAL_D TBuf16<0x100> TheBuf16;
52 const TInt KTestCleanupStack=0x40;
55 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_DBMS.DB");
57 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_DBMS.DB");
60 const TPtrC8 KTestText8(_S8("Text used for test columns when testing"));
61 const TPtrC8 KTestShortText8(_S8("a"));
62 const TPtrC8 KTestLongText8(_S8("Text which is used to set Long ASCII Text columns and ensure they are not inlined, and therefore needs to be very long indeed............." \
63 "Text which is used to set Long ASCII Text columns and ensure they are not inlined, and therefore needs to be very long indeed............."));
64 const TPtrC16 KTestText16(_S16("Text used for test columns when testing"));
65 const TPtrC16 KTestShortText16(_S16("a"));
66 const TPtrC16 KTestLongText16(_S16("Text which is used to set Long UNICODE Text columns and ensure they are not inlined, and therefore needs to be very long indeed............."));
67 const TPtrC KTableName(_S("TestTable"));
68 const TPtrC KTableName2(_S("TestTable2"));
69 const TPtrC KTestViewTable(_L("TestViewTable"));
70 const TPtrC KTestTypesTable(_L("TestTypesTable"));
71 const TPtrC KTestFindTable(_L("TestFindTable"));
72 const TPtrC KTestMultiTable(_L("TestMultiTable"));
73 const TPtrC KIndexName(_S("Index1"));
74 const TPtrC KIndexName2(_S("Index2"));
75 const TPtrC KIndexName3(_S("Index3"));
76 const TInt KBlobItems=1000;
78 const TPtrC KNull=TPtrC();
79 const TPtrC KPass1(_S("wibble"));
80 const TPtrC KPass2(_S("wobble"));
82 const TTime KMinTTime=Time::MinTTime();
83 const TTime KMaxTTime=Time::MaxTTime();
91 LOCAL_D SColDef const SingleColumn[]=
93 {_S("Column1"),EDbColInt32,0},
96 LOCAL_D SColDef const DoubleColumn[]=
98 {_S("Column1"),EDbColInt32,0},
99 {_S("c2"),EDbColInt64,0},
102 LOCAL_D SColDef const ViewTestColumns[]=
104 {_S("Int"),EDbColInt32,0},
105 {_S("Long1"),EDbColLongText8,0},
106 {_S("Long2"),EDbColLongText8,0},
107 {_S("Long3"),EDbColLongText8,0},
108 {_S("Long4"),EDbColLongText8,0},
109 {_S("Long5"),EDbColLongText8,0},
112 LOCAL_D SColDef const AllColumns[]=
114 {_S("counter"),EDbColInt32,TDbCol::ENotNull|TDbCol::EAutoIncrement},
115 {_S("bit"),EDbColBit,TDbCol::ENotNull},
116 {_S("int8"),EDbColInt8,TDbCol::ENotNull},
117 {_S("uint8"),EDbColUint8,TDbCol::ENotNull},
118 {_S("int16"),EDbColInt16,TDbCol::ENotNull},
119 {_S("uint16"),EDbColUint16,TDbCol::ENotNull},
120 {_S("int32"),EDbColInt32,TDbCol::ENotNull},
121 {_S("uint32"),EDbColUint32,TDbCol::ENotNull},
122 {_S("int64"),EDbColInt64,TDbCol::ENotNull},
123 {_S("real32"),EDbColReal32,TDbCol::ENotNull},
124 {_S("real64"),EDbColReal64,TDbCol::ENotNull},
125 {_S("date_time"),EDbColDateTime,TDbCol::ENotNull},
126 {_S("text8"),EDbColText8,TDbCol::ENotNull},
127 {_S("text16"),EDbColText16,TDbCol::ENotNull},
128 {_S("binary"),EDbColBinary,TDbCol::ENotNull},
129 {_S("longtext8"),EDbColLongText8,TDbCol::ENotNull},
130 {_S("longtext16"),EDbColLongText16,TDbCol::ENotNull},
131 {_S("longbinary"),EDbColLongBinary,TDbCol::ENotNull},
132 {_S("bit_null"),EDbColBit,0},
133 {_S("int8_null"),EDbColInt8,0},
134 {_S("uint8_null"),EDbColUint8,0},
135 {_S("int16_null"),EDbColInt16,0},
136 {_S("uint16_null"),EDbColUint16,0},
137 {_S("int32_null"),EDbColInt32,0},
138 {_S("uint32_null"),EDbColUint32,0},
139 {_S("int64_null"),EDbColInt64,0},
140 {_S("real32_null"),EDbColReal32,0},
141 {_S("real64_null"),EDbColReal64,0},
142 {_S("date_time_null"),EDbColDateTime,0},
143 {_S("text8_null"),EDbColText8,0},
144 {_S("text16_null"),EDbColText16,0},
145 {_S("binary_null"),EDbColBinary,0},
146 {_S("longtext8_null"),EDbColLongText8,0},
147 {_S("longtext16_null"),EDbColLongText16,0},
148 {_S("longbinary_null"),EDbColLongBinary,0},
149 {_S("force_null"),EDbColInt32,0},
152 const TInt KColumns=sizeof(AllColumns)/sizeof(AllColumns[0])-1;
156 EBit,EInt8,EUint8,EInt16,EUint16,EInt32,EUint32,EInt64,
157 EReal32,EReal64,ETime,EText8,EText16,ETBinary,
158 ELongText8,ELongText16,ELongBinary,
159 EBitNull,EInt8Null,EUint8Null,EInt16Null,EUint16Null,EInt32Null,EUint32Null,EInt64Null,
160 EReal32Null,EReal64Null,ETimeNull,EText8Null,EText16Null,ETBinaryNull,
161 ELongText8Null,ELongText16Null,ELongBinaryNull,EForceNull
163 LOCAL_D TDbColNo TheMap[KColumns];
165 CDbColSet* ColumnSetL(const SColDef* aDef)
167 CDbColSet *set=CDbColSet::NewLC();
168 for (;aDef->iName;++aDef)
170 TDbCol col(TPtrC(aDef->iName),aDef->iType);
171 col.iAttributes=aDef->iAttributes;
178 enum TColSet {EAllTypes,ESingleColumn,EDoubleColumn,EViewTestTable};
179 LOCAL_D const SColDef* const ColSetDef[]=
186 LOCAL_C CDbColSet* CreateColSetL(TColSet aType)
188 return ColumnSetL(ColSetDef[aType]);
191 inline TPtrC ColName(const SColDef* aSet,TInt aColumn)
192 {return TPtrC(aSet[aColumn].iName);}
194 enum TKeySet {EKeyAsc,EKeyDesc,EKeyMulti,EKeySingle};
195 LOCAL_C CDbKey* CreateKeyL(TKeySet aType)
197 CDbKey *k=CDbKey::NewLC();
201 k->AddL(ColName(AllColumns,EInt32));
204 k->AddL(TDbKeyCol(ColName(AllColumns,EInt32),TDbKeyCol::EDesc));
208 k->AddL(ColName(AllColumns,EInt32)).AddL(ColName(AllColumns,EText8));
209 k->SetComparison(EDbCompareFolded);
212 k->AddL(ColName(SingleColumn,0));
219 LOCAL_C void CloseDatabase()
222 TheCrcChecker.GenerateCrcL(KTestDatabase);
227 // Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
229 LOCAL_C TInt OpenSharedDatabase()
231 return TheDatabase.Open(TheDbs,KTestDatabase);
235 // Create a local database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
237 LOCAL_C void CreateClientDatabase()
239 TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
244 // Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
246 LOCAL_C void CreateSharedDatabase()
248 CreateClientDatabase();
250 TInt r=OpenSharedDatabase();
255 // Open a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
257 LOCAL_C void OpenDatabase()
259 TInt r=OpenSharedDatabase();
264 // Create a shared database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
266 LOCAL_C void CreateDatabase()
268 CreateSharedDatabase();
272 LOCAL_C void DestroyDatabase()
274 TInt r=TheDatabase.Destroy();
279 // Check the database has this many tables
281 LOCAL_C void CountTables(TInt aCount)
283 CDbNames* names=TheDatabase.TableNamesL();
284 test (names->Count()==aCount);
289 // Compare two column sets
291 LOCAL_C void Compare(const TDesC& aTable,const CDbColSet& aSet)
293 CDbColSet* set=TheDatabase.ColSetL(aTable);
294 test(set->Count()==aSet.Count());
295 for (TDbColSetIter iter(*set);iter;++iter)
297 const TDbCol* pRight=aSet.Col(iter->iName);
299 test(iter->iType==pRight->iType);
300 test(iter->iMaxLength==KDbUndefinedLength || pRight->iMaxLength==KDbUndefinedLength || iter->iMaxLength==pRight->iMaxLength);
301 test((iter->iAttributes&pRight->iAttributes)==iter->iAttributes);
307 // Check the database has this many tables
309 LOCAL_C void CountIndexes(const TDesC& aTable,TInt aCount)
311 CDbNames* names=TheDatabase.IndexNamesL(aTable);
312 test (names->Count()==aCount);
317 // Compare index definition
319 LOCAL_C void Compare(const TDesC& aIndex,const TDesC& aTable,const CDbKey& aKey)
321 CDbKey* key=TheDatabase.KeyL(aIndex,aTable);
322 test(key->Count()==aKey.Count());
323 test(key->Comparison()==aKey.Comparison());
324 test(key->IsUnique()==aKey.IsUnique());
325 for (TInt ii=aKey.Count();--ii>=0;)
327 const TDbKeyCol& left=(*key)[ii];
328 const TDbKeyCol& right=aKey[ii];
329 test (left.iName==right.iName);
330 test (left.iOrder==right.iOrder);
331 test (left.iLength==right.iLength || right.iLength==KDbUndefinedLength);
337 @SYMTestCaseID SYSLIB-DBMS-CT-0594
338 @SYMTestCaseDesc Tests the database definition and enquiry functions
339 @SYMTestPriority Medium
340 @SYMTestActions Tests for creation and opening of a database,creation of a table
341 Tests for comparing column and table column sets
342 Tests for altering a table and creation of an index.
343 @SYMTestExpectedResults Test must not fail
346 LOCAL_C void TestDDL()
348 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0594 Create Database "));
352 test.Next(_L("Open Database"));
355 test.Next(_L("CreateTable"));
356 CDbColSet* cs=CreateColSetL(EAllTypes);
357 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
359 test.Next(_L("Compare column sets"));
360 Compare(KTableName,*cs);
362 test.Next(_L("Re-open database"));
365 test.Next(_L("Compare table column sets"));
366 Compare(KTableName,*cs);
368 test.Next(_L("Add another table"));
369 cs=CreateColSetL(ESingleColumn);
370 test(TheDatabase.CreateTable(KTableName2,*cs)==KErrNone);
371 Compare(KTableName2,*cs);
375 test.Next(_L("Alter table"));
376 cs=CreateColSetL(EDoubleColumn);
377 test(TheDatabase.AlterTable(KTableName2,*cs)==KErrNone);
378 Compare(KTableName2,*cs);
382 test.Next(_L("Test index creation"));
383 CountIndexes(KTableName,0);
384 CountIndexes(KTableName2,0);
385 CDbKey* key=CreateKeyL(EKeyAsc);
386 test (TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
387 Compare(KIndexName,KTableName,*key);
389 key=CreateKeyL(EKeyDesc);
390 test (TheDatabase.CreateIndex(KIndexName2,KTableName,*key)==KErrNone);
391 Compare(KIndexName2,KTableName,*key);
393 key=CreateKeyL(EKeySingle);
394 test (TheDatabase.CreateIndex(KIndexName,KTableName2,*key)==KErrNone);
395 Compare(KIndexName,KTableName2,*key);
397 key=CreateKeyL(EKeyMulti);
398 test (TheDatabase.CreateIndex(KIndexName3,KTableName,*key)==KErrNone);
399 Compare(KIndexName3,KTableName,*key);
400 CountIndexes(KTableName,3);
401 CountIndexes(KTableName2,1);
404 CountIndexes(KTableName,3);
405 CountIndexes(KTableName2,1);
406 Compare(KIndexName3,KTableName,*key);
408 test.Next(_L("Drop indexes"));
409 test (TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
410 CountIndexes(KTableName,2);
411 test (TheDatabase.DropIndex(KIndexName2,KTableName)==KErrNone);
412 CountIndexes(KTableName,1);
413 test (TheDatabase.DropIndex(KIndexName,KTableName2)==KErrNone);
414 CountIndexes(KTableName2,0);
415 test.Next(_L("Drop table"));
416 test(TheDatabase.DropTable(KTableName)==KErrNone);
418 test(TheDatabase.DropTable(KTableName2)==KErrNone);
428 LOCAL_C void AddRow()
430 test(TheView.Prepare(TheDatabase,_L("select * from testviewtable"))==KErrNone);
431 test(TheView.EvaluateAll()==KErrNone);
433 TheView.SetColL(1,(TInt32)12345);
439 test(TheView.AtEnd()); // should be only 1 row as second insert was cancelled
444 @SYMTestCaseID SYSLIB-DBMS-CT-1318
445 @SYMTestCaseDesc Tests for RDbView class
446 @SYMTestPriority Medium
447 @SYMTestActions Tests for navigation of the cursor in the generated row sets.
448 @SYMTestExpectedResults Test must not fail
451 LOCAL_C void TestEmptyNavigation(const TDesC& aQuery)
453 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1318 Test navigation states "));
454 test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
455 test(TheView.EvaluateAll()==KErrNone);
457 test(!TheView.AtBeginning());
458 test(!TheView.AtRow());
459 test(TheView.AtEnd());
461 test(TheView.AtBeginning());
462 test(!TheView.AtRow());
463 test(!TheView.AtEnd());
465 test(!TheView.AtBeginning());
466 test(!TheView.AtRow());
467 test(TheView.AtEnd());
469 test(TheView.AtBeginning());
470 test(!TheView.AtRow());
471 test(!TheView.AtEnd());
473 test(TheView.AtEnd());
478 @SYMTestCaseID SYSLIB-DBMS-CT-1319
479 @SYMTestCaseDesc Tests for RDbView class
480 @SYMTestPriority Medium
481 @SYMTestActions Tests for navigation of the cursor in the generated row sets.
482 @SYMTestExpectedResults Test must not fail
485 LOCAL_C void TestNavigation(const TDesC& aQuery)
487 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1319 Test navigation states "));
488 test(TheView.Prepare(TheDatabase,aQuery,TheView.EReadOnly)==KErrNone);
489 test(TheView.EvaluateAll()==KErrNone);
491 test(!TheView.AtBeginning());
492 test(TheView.AtRow());
493 test(!TheView.AtEnd());
495 test(TheView.ColInt32(1)==12345);
497 test(TheView.AtBeginning());
498 test(!TheView.AtRow());
499 test(!TheView.AtEnd());
501 test(!TheView.AtBeginning());
502 test(TheView.AtRow());
503 test(!TheView.AtEnd());
505 test(!TheView.AtBeginning());
506 test(!TheView.AtRow());
507 test(TheView.AtEnd());
509 test(!TheView.AtBeginning());
510 test(TheView.AtRow());
511 test(!TheView.AtEnd());
513 test(!TheView.AtBeginning());
514 test(TheView.AtRow());
515 test(!TheView.AtEnd());
517 test(TheView.AtEnd());
522 @SYMTestCaseID SYSLIB-DBMS-CT-1320
523 @SYMTestCaseDesc RDbView updation test
524 @SYMTestPriority Medium
525 @SYMTestActions Tests for updation of row sets
526 @SYMTestExpectedResults Test must not fail
529 static void TestUpdate()
531 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1320 Update and delete the row "));
532 test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
533 test(TheView.EvaluateAll()==KErrNone);
536 TheView.SetColL(1,(TInt32)54321);
540 test(TheView.ColInt32(1)==54321);
542 TheView.SetColL(1,(TInt32)12345);
546 test(TheView.ColInt32(1)==54321);
549 test(TheView.AtBeginning());
551 test(TheView.AtEnd());
557 void writeBLOB(TDbColNo aCol,const TDesC8& aDes)
559 CBufSeg* buf=CBufSeg::NewL(128);
560 CleanupStack::PushL(buf);
561 buf->InsertL(0,aDes);
562 RBufReadStream read(*buf);
563 RDbColWriteStream blob;
564 blob.OpenLC(TheView,aCol);
565 // blob.WriteL(aDes);
566 blob.WriteL(read,aDes.Length());
568 CleanupStack::PopAndDestroy();
569 CleanupStack::PopAndDestroy(); // buf
570 test (TheView.ColLength(aCol)==aDes.Length());
571 test (TheView.ColSize(aCol)==aDes.Size());
574 void checkBLOB(TDbColNo aCol,const TDesC8& aDes)
576 RDbColReadStream blob;
577 blob.OpenLC(TheView,aCol);
578 blob.ReadL(TheBuf8,TheView.ColLength(aCol));
579 CleanupStack::PopAndDestroy();
584 @SYMTestCaseID SYSLIB-DBMS-CT-1321
585 @SYMTestCaseDesc BLOB tests
586 @SYMTestPriority Medium
587 @SYMTestActions Test long column tracking through insert/put/update/cancel
588 @SYMTestExpectedResults Test must not fail
593 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1321 Long column tracking "));
594 test(TheView.Prepare(TheDatabase,_L("select * from TestViewTable"))==KErrNone);
595 test(TheView.EvaluateAll()==KErrNone);
597 writeBLOB(2,KTestShortText8);
598 writeBLOB(3,KTestShortText8);
601 writeBLOB(4,KTestShortText8);
602 writeBLOB(5,KTestShortText8);
604 // change in behaviour--writing BLOBs forces a true rollback here. So reset
606 test(TheView.EvaluateAll()==KErrNone);
607 // check the one row we should have
610 checkBLOB(2,KTestShortText8);
611 checkBLOB(3,KTestShortText8);
612 test(TheView.IsColNull(4));
613 test(TheView.IsColNull(5));
614 test(TheView.IsColNull(6));
616 test(TheView.AtEnd());
617 // update/cancel the row
620 TheView.SetColNullL(3);
621 writeBLOB(4,KTestLongText8);
622 writeBLOB(5,KTestLongText8);
624 checkBLOB(2,KTestShortText8);
625 test(TheView.IsColNull(3));
626 checkBLOB(4,KTestLongText8);
627 checkBLOB(5,KTestLongText8);
628 test(TheView.IsColNull(6));
631 // change in behaviour--writing BLOBs forces a true rollback here. So reset
633 test(TheView.EvaluateAll()==KErrNone);
636 checkBLOB(2,KTestShortText8);
637 checkBLOB(3,KTestShortText8);
638 test(TheView.IsColNull(4));
639 test(TheView.IsColNull(5));
640 test(TheView.IsColNull(6));
642 test(TheView.AtEnd());
643 // update/put the row
646 TheView.SetColNullL(3);
647 writeBLOB(4,KTestLongText8);
648 writeBLOB(5,KTestLongText8);
650 checkBLOB(2,KTestShortText8);
651 test(TheView.IsColNull(3));
652 checkBLOB(4,KTestLongText8);
653 checkBLOB(5,KTestLongText8);
654 test(TheView.IsColNull(6));
659 checkBLOB(2,KTestShortText8);
660 test(TheView.IsColNull(3));
661 checkBLOB(4,KTestLongText8);
662 checkBLOB(5,KTestLongText8);
663 test(TheView.IsColNull(6));
665 test(TheView.AtEnd());
666 // update/put the row again
669 TheView.SetColNullL(2);
670 writeBLOB(3,KTestShortText8);
671 writeBLOB(4,KTestShortText8);
672 writeBLOB(5,KTestShortText8);
674 test(TheView.IsColNull(2));
675 checkBLOB(3,KTestShortText8);
676 checkBLOB(4,KTestShortText8);
677 checkBLOB(5,KTestShortText8);
678 test(TheView.IsColNull(6));
680 writeBLOB(2,KTestLongText8);
681 TheView.SetColNullL(3);
682 TheView.SetColNullL(4);
683 writeBLOB(5,KTestLongText8);
685 checkBLOB(2,KTestLongText8);
686 test(TheView.IsColNull(3));
687 test(TheView.IsColNull(4));
688 checkBLOB(5,KTestLongText8);
689 test(TheView.IsColNull(6));
694 checkBLOB(2,KTestLongText8);
695 test(TheView.IsColNull(3));
696 test(TheView.IsColNull(4));
697 checkBLOB(5,KTestLongText8);
698 test(TheView.IsColNull(6));
700 test(TheView.AtEnd());
703 TheView.InsertCopyL();
704 TheView.SetColNullL(2);
705 writeBLOB(3,KTestLongText8);
707 test(TheView.IsColNull(2));
708 checkBLOB(3,KTestLongText8);
709 test(TheView.IsColNull(4));
710 checkBLOB(5,KTestLongText8);
711 test(TheView.IsColNull(6));
716 test(TheView.IsColNull(2));
717 checkBLOB(3,KTestLongText8);
718 test(TheView.IsColNull(4));
719 checkBLOB(5,KTestLongText8);
720 test(TheView.IsColNull(6));
721 // delete previous one and check
726 test(TheView.IsColNull(2));
727 checkBLOB(3,KTestLongText8);
728 test(TheView.IsColNull(4));
729 checkBLOB(5,KTestLongText8);
730 test(TheView.IsColNull(6));
732 test(TheView.AtEnd());
741 @SYMTestCaseID SYSLIB-DBMS-CT-0596
742 @SYMTestCaseDesc Tests for navigation states
743 @SYMTestPriority Medium
744 @SYMTestActions Tests for view state cycle, navigation, Insert/Update/Delete
745 @SYMTestExpectedResults Test must not fail
750 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0596 Create the Test table "));
752 CDbColSet* cs=CreateColSetL(EViewTestTable);
753 test(TheDatabase.CreateTable(KTestViewTable,*cs)==KErrNone);
755 test.Next(_L("Test navigation states"));
756 TestEmptyNavigation(_L("select * from TestViewTable"));
757 test.Next(_L("Insert and Put/Cancel"));
759 test.Next(_L("Test navigation states"));
760 TestNavigation(_L("select * from TestViewTable"));
761 TestNavigation(_L("select * from TestViewTable where Int is not null"));
762 TestEmptyNavigation(_L("select * from TestViewTable where Int is null"));
763 test.Next(_L("Update and delete the row"));
765 test.Next(_L("Long column tracking"));
767 test.Next(_L("Close"));
773 // Check the integral set/get functions for different width types
775 LOCAL_C void CheckIntAccessors()
779 TDbColNo ord=TheMap[EBit];
780 TheView.SetColL(ord,TUint32(1));
781 test (TheView.ColUint(ord)==1);
782 TheView.SetColL(ord,TInt32(0));
783 test (TheView.ColUint(ord)==0);
784 TheView.SetColL(ord,TInt64(1));
785 test (TheView.ColUint(ord)==1);
786 test (TheView.ColUint8(ord)==1);
787 test (TheView.ColUint16(ord)==1);
788 test (TheView.ColUint32(ord)==1);
789 test (TheView.ColInt8(ord)==1);
790 test (TheView.ColInt16(ord)==1);
791 test (TheView.ColInt32(ord)==1);
792 test (TheView.ColInt64(ord)==1);
795 TheView.SetColL(ord,TUint32(255));
796 test (TheView.ColUint(ord)==255);
797 TheView.SetColL(ord,TInt32(0));
798 test (TheView.ColUint(ord)==0);
799 TheView.SetColL(ord,TInt64(1));
800 test (TheView.ColUint(ord)==1);
801 test (TheView.ColUint8(ord)==1);
802 test (TheView.ColUint16(ord)==1);
803 test (TheView.ColUint32(ord)==1);
804 test (TheView.ColInt16(ord)==1);
805 test (TheView.ColInt32(ord)==1);
806 test (TheView.ColInt64(ord)==1);
809 TheView.SetColL(ord,TUint32(65535));
810 test (TheView.ColUint(ord)==65535);
811 TheView.SetColL(ord,TInt32(0));
812 test (TheView.ColUint(ord)==0);
813 TheView.SetColL(ord,TInt64(1));
814 test (TheView.ColUint(ord)==1);
815 test (TheView.ColUint16(ord)==1);
816 test (TheView.ColUint32(ord)==1);
817 test (TheView.ColInt32(ord)==1);
818 test (TheView.ColInt64(ord)==1);
821 TheView.SetColL(ord,TUint32(0));
822 test (TheView.ColUint(ord)==0);
823 TheView.SetColL(ord,TInt32(KMaxTInt));
824 test (TInt(TheView.ColUint(ord))==KMaxTInt);
825 TheView.SetColL(ord,TInt64(KMaxTUint));
826 test (TheView.ColUint(ord)==KMaxTUint);
827 test (TheView.ColUint32(ord)==KMaxTUint);
828 test (TheView.ColInt64(ord)==KMaxTUint);
831 TheView.SetColL(ord,TUint32(127));
832 test (TheView.ColInt(ord)==127);
833 TheView.SetColL(ord,TInt32(0));
834 test (TheView.ColInt(ord)==0);
835 TheView.SetColL(ord,TInt64(-128));
836 test (TheView.ColInt(ord)==-128);
837 test (TheView.ColInt8(ord)==-128);
838 test (TheView.ColInt16(ord)==-128);
839 test (TheView.ColInt32(ord)==-128);
840 test (TheView.ColInt64(ord)==-128);
843 TheView.SetColL(ord,TUint32(32767));
844 test (TheView.ColInt(ord)==32767);
845 TheView.SetColL(ord,TInt32(0));
846 test (TheView.ColInt(ord)==0);
847 TheView.SetColL(ord,TInt64(-32768));
848 test (TheView.ColInt(ord)==-32768);
849 test (TheView.ColInt16(ord)==-32768);
850 test (TheView.ColInt32(ord)==-32768);
851 test (TheView.ColInt64(ord)==-32768);
854 TheView.SetColL(ord,TUint32(KMaxTInt));
855 test (TheView.ColInt(ord)==KMaxTInt);
856 TheView.SetColL(ord,TInt32(0));
857 test (TheView.ColInt(ord)==0);
858 TheView.SetColL(ord,TInt64(KMinTInt));
859 test (TheView.ColInt(ord)==KMinTInt);
860 test (TheView.ColInt32(ord)==KMinTInt);
861 test (TheView.ColInt64(ord)==KMinTInt);
867 // Write the values to nullable column types
869 LOCAL_C void WriteMinValues(TInt anOffset)
871 TheView.SetColL(TheMap[anOffset+EBit],TUint(0));
872 TheView.SetColL(TheMap[anOffset+EInt8],KMinTInt8);
873 TheView.SetColL(TheMap[anOffset+EUint8],TUint(0));
874 TheView.SetColL(TheMap[anOffset+EInt16],KMinTInt16);
875 TheView.SetColL(TheMap[anOffset+EUint16],TUint(0));
876 TheView.SetColL(TheMap[anOffset+EInt32],KMinTInt32);
877 TheView.SetColL(TheMap[anOffset+EUint32],TUint(0));
878 TheView.SetColL(TheMap[anOffset+EInt64],KMinTInt64);
879 TheView.SetColL(TheMap[anOffset+EReal32],KMinTReal32);
880 TheView.SetColL(TheMap[anOffset+EReal64],KMinTReal64);
881 TheView.SetColL(TheMap[anOffset+ETime],KMinTTime);
882 TheView.SetColL(TheMap[anOffset+EText8],KTestShortText8);
883 TheView.SetColL(TheMap[anOffset+EText16],KTestShortText16);
886 TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8(&val,sizeof(val)));
888 TheView.SetColL(TheMap[anOffset+ELongText8],KTestShortText8);
889 TheView.SetColL(TheMap[anOffset+ELongText16],KTestShortText16);
890 RDbColWriteStream out;
891 out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
894 CleanupStack::PopAndDestroy();
898 // Write a row with the minimum (or small) column values
899 // return the value in the counter column
901 LOCAL_C TInt WriteMinimum()
905 WriteMinValues(EBitNull-EBit);
906 test(!TheView.IsColNull(TheMap[ECounter]));
907 TInt cc=TheView.ColInt(TheMap[ECounter]);
912 LOCAL_C void CheckMinValues(TInt anOffset)
914 test(TheView.ColUint8(TheMap[anOffset+EBit])==0);
915 test(TheView.ColUint16(TheMap[anOffset+EBit])==0);
916 test(TheView.ColUint32(TheMap[anOffset+EBit])==0);
917 test(TheView.ColUint(TheMap[anOffset+EBit])==0);
918 test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMinTInt8);
919 test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMinTInt8);
920 test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMinTInt8);
921 test(TheView.ColInt(TheMap[anOffset+EInt8])==KMinTInt8);
922 test(TheView.ColUint8(TheMap[anOffset+EUint8])==0);
923 test(TheView.ColUint16(TheMap[anOffset+EUint8])==0);
924 test(TheView.ColUint32(TheMap[anOffset+EUint8])==0);
925 test(TheView.ColUint(TheMap[anOffset+EUint8])==0);
926 test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMinTInt16);
927 test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMinTInt16);
928 test(TheView.ColInt(TheMap[anOffset+EInt16])==KMinTInt16);
929 test(TheView.ColUint16(TheMap[anOffset+EUint16])==0);
930 test(TheView.ColUint32(TheMap[anOffset+EUint16])==0);
931 test(TheView.ColUint(TheMap[anOffset+EUint16])==0);
932 test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMinTInt32);
933 test(TheView.ColInt(TheMap[anOffset+EInt32])==KMinTInt32);
934 test(TheView.ColUint32(TheMap[anOffset+EUint32])==0);
935 test(TheView.ColUint(TheMap[anOffset+EUint32])==0);
936 test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMinTInt64);
937 test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMinTReal32);
938 test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMinTReal64);
939 test(TheView.ColReal(TheMap[anOffset+EReal64])==KMinTReal64);
940 test(TheView.ColTime(TheMap[anOffset+ETime])==KMinTTime);
941 test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestShortText8);
942 test(TheView.ColSize(TheMap[anOffset+EText8])==KTestShortText8.Size());
943 test(TheView.ColLength(TheMap[anOffset+EText8])==KTestShortText8.Length());
944 test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestShortText16);
945 test(TheView.ColSize(TheMap[anOffset+EText16])==KTestShortText16.Size());
946 test(TheView.ColLength(TheMap[anOffset+EText16])==KTestShortText16.Length());
949 test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8(&val,sizeof(val)));
951 test(TheView.ColSize(TheMap[anOffset+ETBinary])==1);
952 test(TheView.ColLength(TheMap[anOffset+ETBinary])==1);
954 test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestShortText8.Size());
955 test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestShortText8.Length());
957 in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
958 in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
959 CleanupStack::PopAndDestroy();
960 test(TheBuf8==KTestShortText8);
962 test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestShortText16.Size());
963 test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestShortText16.Length());
964 in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
965 in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
966 CleanupStack::PopAndDestroy();
967 test(TheBuf16==KTestShortText16);
969 test(TheView.ColSize(TheMap[anOffset+ELongBinary])==1);
970 test(TheView.ColLength(TheMap[anOffset+ELongBinary])==1);
971 in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
972 test(in.ReadUint8L()==0);
973 CleanupStack::PopAndDestroy();
977 // Check the row is the same as was written
979 LOCAL_C void CheckMinimum(TInt aCounter)
982 test(TheView.ColInt32(TheMap[ECounter])==aCounter);
984 CheckMinValues(EBitNull-EBit);
987 LOCAL_C void WriteMaxValues(TInt anOffset)
989 TheView.SetColL(TheMap[anOffset+EBit],TUint(1));
990 TheView.SetColL(TheMap[anOffset+EInt8],KMaxTInt8);
991 TheView.SetColL(TheMap[anOffset+EUint8],TUint(KMaxTUint8));
992 TheView.SetColL(TheMap[anOffset+EInt16],KMaxTInt16);
993 TheView.SetColL(TheMap[anOffset+EUint16],TUint(KMaxTUint16));
994 TheView.SetColL(TheMap[anOffset+EInt32],KMaxTInt32);
995 TheView.SetColL(TheMap[anOffset+EUint32],KMaxTUint32);
996 TheView.SetColL(TheMap[anOffset+EInt64],KMaxTInt64);
997 TheView.SetColL(TheMap[anOffset+EReal32],KMaxTReal32);
998 TheView.SetColL(TheMap[anOffset+EReal64],KMaxTReal64);
999 TheView.SetColL(TheMap[anOffset+ETime],KMaxTTime);
1000 TheView.SetColL(TheMap[anOffset+EText8],KTestText8);
1001 TheView.SetColL(TheMap[anOffset+EText16],KTestText16);
1002 TheView.SetColL(TheMap[anOffset+ETBinary],TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
1003 TheView.SetColL(TheMap[anOffset+ELongText8],KTestLongText8);
1004 TheView.SetColL(TheMap[anOffset+ELongText16],KTestLongText16);
1005 RDbColWriteStream out;
1006 out.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
1007 for (TInt ii=0;ii<KBlobItems;++ii)
1008 out.WriteInt32L(ii);
1010 CleanupStack::PopAndDestroy();
1014 // Write a row with the maximum (or longer) column values
1015 // return the value in the counter column
1017 LOCAL_C TInt WriteMaximum()
1021 WriteMaxValues(EBitNull-EBit);
1022 test(!TheView.IsColNull(TheMap[ECounter]));
1023 TInt cc=TheView.ColInt(TheMap[ECounter]);
1028 LOCAL_C void CheckMaxValues(TInt anOffset)
1030 test(TheView.ColUint8(TheMap[anOffset+EBit])==1);
1031 test(TheView.ColUint16(TheMap[anOffset+EBit])==1);
1032 test(TheView.ColUint32(TheMap[anOffset+EBit])==1);
1033 test(TheView.ColUint(TheMap[anOffset+EBit])==1);
1034 test(TheView.ColInt8(TheMap[anOffset+EInt8])==KMaxTInt8);
1035 test(TheView.ColInt16(TheMap[anOffset+EInt8])==KMaxTInt8);
1036 test(TheView.ColInt32(TheMap[anOffset+EInt8])==KMaxTInt8);
1037 test(TheView.ColInt(TheMap[anOffset+EInt8])==KMaxTInt8);
1038 test(TheView.ColUint8(TheMap[anOffset+EUint8])==KMaxTUint8);
1039 test(TheView.ColUint16(TheMap[anOffset+EUint8])==KMaxTUint8);
1040 test(TheView.ColUint32(TheMap[anOffset+EUint8])==KMaxTUint8);
1041 test(TheView.ColUint(TheMap[anOffset+EUint8])==KMaxTUint8);
1042 test(TheView.ColInt16(TheMap[anOffset+EInt16])==KMaxTInt16);
1043 test(TheView.ColInt32(TheMap[anOffset+EInt16])==KMaxTInt16);
1044 test(TheView.ColInt(TheMap[anOffset+EInt16])==KMaxTInt16);
1045 test(TheView.ColUint16(TheMap[anOffset+EUint16])==KMaxTUint16);
1046 test(TheView.ColUint32(TheMap[anOffset+EUint16])==KMaxTUint16);
1047 test(TheView.ColUint(TheMap[anOffset+EUint16])==KMaxTUint16);
1048 test(TheView.ColInt32(TheMap[anOffset+EInt32])==KMaxTInt32);
1049 test(TheView.ColInt(TheMap[anOffset+EInt32])==KMaxTInt32);
1050 test(TheView.ColUint32(TheMap[anOffset+EUint32])==KMaxTUint32);
1051 test(TheView.ColUint(TheMap[anOffset+EUint32])==KMaxTUint32);
1052 test(TheView.ColInt64(TheMap[anOffset+EInt64])==KMaxTInt64);
1053 test(TheView.ColReal32(TheMap[anOffset+EReal32])==KMaxTReal32);
1054 test(TheView.ColReal64(TheMap[anOffset+EReal64])==KMaxTReal64);
1055 test(TheView.ColReal(TheMap[anOffset+EReal64])==KMaxTReal64);
1056 test(TheView.ColTime(TheMap[anOffset+ETime])==KMaxTTime);
1057 test(TheView.ColDes8(TheMap[anOffset+EText8])==KTestText8);
1058 test(TheView.ColSize(TheMap[anOffset+EText8])==KTestText8.Size());
1059 test(TheView.ColLength(TheMap[anOffset+EText8])==KTestText8.Length());
1060 test(TheView.ColDes16(TheMap[anOffset+EText16])==KTestText16);
1061 test(TheView.ColSize(TheMap[anOffset+EText16])==KTestText16.Size());
1062 test(TheView.ColLength(TheMap[anOffset+EText16])==KTestText16.Length());
1063 test(TheView.ColDes8(TheMap[anOffset+ETBinary])==TPtrC8((TUint8*)&TheMap[0],sizeof(TheMap)));
1064 test(TheView.ColSize(TheMap[anOffset+ETBinary])==sizeof(TheMap));
1065 test(TheView.ColLength(TheMap[anOffset+ETBinary])==sizeof(TheMap));
1067 test(TheView.ColSize(TheMap[anOffset+ELongText8])==KTestLongText8.Size());
1068 test(TheView.ColLength(TheMap[anOffset+ELongText8])==KTestLongText8.Length());
1069 RDbColReadStream in;
1070 in.OpenLC(TheView,TheMap[anOffset+ELongText8]);
1071 in.ReadL(TheBuf8,TheView.ColLength(TheMap[anOffset+ELongText8]));
1072 CleanupStack::PopAndDestroy();
1073 test(TheBuf8==KTestLongText8);
1075 test(TheView.ColSize(TheMap[anOffset+ELongText16])==KTestLongText16.Size());
1076 test(TheView.ColLength(TheMap[anOffset+ELongText16])==KTestLongText16.Length());
1077 in.OpenLC(TheView,TheMap[anOffset+ELongText16]);
1078 in.ReadL(TheBuf16,TheView.ColLength(TheMap[anOffset+ELongText16]));
1079 CleanupStack::PopAndDestroy();
1080 test(TheBuf16==KTestLongText16);
1082 test(TheView.ColSize(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
1083 test(TheView.ColLength(TheMap[anOffset+ELongBinary])==KBlobItems*sizeof(TUint32));
1084 in.OpenLC(TheView,TheMap[anOffset+ELongBinary]);
1085 for (TInt ii=0;ii<KBlobItems;++ii)
1086 test(in.ReadInt32L()==ii);
1087 CleanupStack::PopAndDestroy();
1091 // Check the row is the same as was written
1093 LOCAL_C void CheckMaximum(TInt aCounter)
1096 test(TheView.ColInt32(TheMap[ECounter])==aCounter);
1098 CheckMaxValues(EBitNull-EBit);
1102 // Write a row with null column values in the nullable columns
1103 // return the value in the counter column
1105 LOCAL_C TInt WriteNull()
1109 test(!TheView.IsColNull(TheMap[ECounter]));
1110 TInt cc=TheView.ColInt(TheMap[ECounter]);
1116 // Check the row is the same as was written
1118 LOCAL_C void CheckNull(TInt aCounter)
1121 test(TheView.ColInt32(TheMap[ECounter])==aCounter);
1123 for (ii=ECounter;ii<EBitNull;ii++)
1124 { // not null columns
1125 TDbColNo col=TheMap[ii];
1126 test(!TheView.IsColNull(col));
1127 test(TheView.ColSize(col)!=0);
1128 test(TheView.ColLength(col)!=0);
1130 test(TheView.ColDes8(col).Length()!=0);
1133 for (;ii<EForceNull-1;++ii)
1135 TDbColNo col=TheMap[ii];
1136 test(TheView.IsColNull(col));
1137 test(TheView.ColSize(col)==0);
1138 test(TheView.ColLength(col)==0);
1139 if (ii<ELongText8Null)
1140 test(TheView.ColDes8(col).Length()==0);
1142 test(TheView.ColUint(TheMap[EBitNull])==0);
1143 test(TheView.ColInt(TheMap[EInt8Null])==0);
1144 test(TheView.ColUint(TheMap[EUint8Null])==0);
1145 test(TheView.ColInt(TheMap[EInt16Null])==0);
1146 test(TheView.ColUint(TheMap[EUint16Null])==0);
1147 test(TheView.ColInt(TheMap[EInt32Null])==0);
1148 test(TheView.ColUint(TheMap[EUint32Null])==0);
1149 test(TheView.ColInt64(TheMap[EInt64Null])==0);
1150 test(TheView.ColReal32(TheMap[EReal32Null])==0);
1151 test(TheView.ColReal64(TheMap[EReal64Null])==0);
1152 test(TheView.ColTime(TheMap[ETimeNull])==TTime(0));
1156 // Copy the last row (should have a different auto-inc value)
1158 LOCAL_C TInt WriteCopy()
1161 TheView.InsertCopyL();
1162 TheView.SetColL(TheMap[EForceNull],1234567);
1163 test(!TheView.IsColNull(TheMap[ECounter]));
1164 TInt cc=TheView.ColInt(TheMap[ECounter]);
1170 void TestOverflow(TDbColNo aCol,const T& aValue)
1173 TheView.SetColL(aCol,aValue);
1174 TRAPD(r,TheView.PutL());
1175 test(r==KErrOverflow);
1179 LOCAL_C void TestWriteNull(TDbColNo aCol)
1182 TheView.SetColNullL(aCol);
1183 TRAPD(r,TheView.PutL());
1184 test(r==KErrNotFound);
1188 LOCAL_C void TestValidation()
1193 TestOverflow(TheMap[EBit],TUint(2));
1194 TestOverflow(TheMap[EBit],TUint(0xffffffffu));
1195 TestOverflow(TheMap[EInt8],TInt(-129));
1196 TestOverflow(TheMap[EInt8],TInt(128));
1197 TestOverflow(TheMap[EUint8],TUint(0xffffffffu));
1198 TestOverflow(TheMap[EUint8],TUint(256));
1199 TestOverflow(TheMap[EInt16],TInt(-32769));
1200 TestOverflow(TheMap[EInt16],TInt(32768));
1201 TestOverflow(TheMap[EUint16],TUint(0xffffffffu));
1202 TestOverflow(TheMap[EUint16],TUint(65536));
1204 TBuf8<KDbDefaultTextColLength+1> buf;
1207 TestOverflow(TheMap[EText8],buf);
1210 TBuf16<KDbDefaultTextColLength+1> buf;
1213 TestOverflow(TheMap[EText16],buf);
1215 for (TInt ii=EBit;ii<EBitNull;++ii)
1216 TestWriteNull(TheMap[ii]);
1220 @SYMTestCaseID SYSLIB-DBMS-CT-0597
1221 @SYMTestCaseDesc Tests the range and values of all columns types
1222 @SYMTestPriority Medium
1223 @SYMTestActions Tests for integral accessors
1224 @SYMTestExpectedResults Test must not fail
1227 LOCAL_C void TestTypes()
1229 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0597 Create table of all types "));
1231 CDbColSet* cs=CreateColSetL(EAllTypes);
1232 test(TheDatabase.CreateTable(KTestTypesTable,*cs)==KErrNone);
1234 test(TheView.Prepare(TheDatabase,_L("select * from TestTypesTable"))==KErrNone);
1235 test(TheView.EvaluateAll()==KErrNone);
1236 cs=TheView.ColSetL();
1237 for (TInt ii=0;ii<KColumns;ii++)
1238 TheMap[ii]=cs->ColNo(TPtrC(AllColumns[ii].iName));
1240 test.Next(_L("Test integral accessors"));
1241 CheckIntAccessors();
1242 test.Next(_L("Add row of minimum values"));
1243 TInt c1=WriteMinimum();
1244 test.Next(_L("Add row of maximum values"));
1245 TInt c2=WriteMaximum();
1247 test.Next(_L("Add row of Null values"));
1248 TInt c3=WriteNull();
1250 test.Next(_L("Add a copy of the last row"));
1251 TInt c4=WriteCopy();
1253 test.Next(_L("Check minimum values"));
1256 test.Next(_L("Check maximum values"));
1259 test.Next(_L("Check Null values"));
1264 test.Next(_L("Test column value Validation"));
1271 const TPtrC KColumnID(_S("id"));
1272 const TPtrC KColumnText(_S("txt"));
1273 const TPtrC KColumnOther(_S("other"));
1274 const TPtrC KBlobText(_S("text"));
1275 const TPtrC KFind1(_S("id=1"));
1276 const TPtrC KFind2(_S("id is null"));
1280 // 1: "aaa...aaatext"
1281 // 2: "textaaa...aaa"
1283 // 4: "aaa...aaatextaaa...aaa"
1292 LOCAL_D STest const Tests[]=
1294 {_S("txt like 'a*'"),0x010110},
1295 {_S("txt like 'a*' or other like 'a*'"),0x111111},
1296 {_S("txt like 'a*' and other like 'a*'"),0x010110},
1297 {_S("txt < 'text'"),0x010111},
1298 {_S("txt > 'text'"),0x001000},
1299 {_S("txt > ''"),0x111110},
1300 {_S("txt like 'text'"),0x100000},
1301 {_S("txt like '*TEXT'"),0x110000},
1302 {_S("txt like 'text*'"),0x101000},
1303 {_S("txt like '*text*'"),0x111010},
1304 {_S("txt like '*'"),0x111111},
1305 {_S("txt like '?*'"),0x111110},
1306 {_S("txt like '*t*t*'"),0x111010},
1307 {_S("txt like '*a??t*'"),0x010010},
1308 {_S("txt like 'aA*aa'"),0x000110},
1309 {_S("txt like 'teXT'"),0x100000},
1310 {_S("txt like '*text'"),0x110000},
1311 {_S("txt like '*tExt*'"),0x111010},
1312 {_S("txt like ''"),0x000001},
1313 {_S("txt is null"),0x000001}
1316 LOCAL_C void CreateFindTable()
1318 CDbColSet *pC=CDbColSet::NewL();
1319 CleanupStack::PushL(pC);
1320 pC->AddL(TDbCol(KColumnID,EDbColUint32));
1321 pC->AddL(TDbCol(KColumnText,EDbColLongText,200));
1322 pC->AddL(TDbCol(KColumnOther,EDbColText,200));
1323 test(TheDatabase.CreateTable(KTestFindTable,*pC)==KErrNone);
1324 CleanupStack::PopAndDestroy();
1325 test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EInsertOnly)==KErrNone);
1330 for (TUint ii=0;ii<6;++ii)
1333 TheTable.SetColL(1,ii);
1334 TheTable.SetColL(3,_L("abcdef"));
1339 TheTable.SetColL(2,KBlobText);
1344 TheTable.SetColL(2,col);
1349 TheTable.SetColL(2,col);
1352 TheTable.SetColL(2,garbage);
1358 TheTable.SetColL(2,col);
1366 CDbKey* key=CDbKey::NewLC();
1367 key->AddL(KColumnID);
1369 test(TheDatabase.CreateIndex(KIndexName,KTestFindTable,*key)==KErrNone);
1371 key->AddL(TDbKeyCol(KColumnText,100));
1373 key->SetComparison(EDbCompareFolded);
1374 test(TheDatabase.CreateIndex(KIndexName2,KTestFindTable,*key)==KErrNone);
1375 CleanupStack::PopAndDestroy(); //key
1379 @SYMTestCaseID SYSLIB-DBMS-CT-0598
1380 @SYMTestCaseDesc Tests for RDbRowConstraint::Open() function
1381 @SYMTestPriority Medium
1382 @SYMTestActions Tests for the specified SQL search-condition for matching against rows in the specified rowset
1383 @SYMTestExpectedResults Test must not fail
1386 LOCAL_C void TestMatch()
1388 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0598 Match "));
1389 test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
1390 for (TInt ii=0;ii<TInt(sizeof(Tests)/sizeof(Tests[0]));++ii)
1392 RDbRowConstraint match;
1393 test(match.Open(TheTable,TDbQuery(TPtrC(Tests[ii].iText),EDbCompareFolded))==KErrNone);
1395 TheTable.BeginningL();
1396 while (TheTable.NextL())
1398 if (TheTable.MatchL(match))
1401 TUint bit=0x100000>>(TheTable.ColUint32(1)*4);
1402 test((bit&mask)==0);
1407 test(mask==Tests[ii].iRecs);
1413 @SYMTestCaseID SYSLIB-DBMS-CT-0599
1414 @SYMTestCaseDesc Tests for RDbRowSet::FindL(),RDbRowSet::GetL() functions
1415 @SYMTestPriority Medium
1416 @SYMTestActions Tests for finding a match through a rowset
1417 @SYMTestExpectedResults Test must not fail
1420 LOCAL_C void TestFind(RDbRowSet& aSet)
1422 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0599 "));
1423 CDbColSet* cs=aSet.ColSetL();
1425 TDbColNo col=cs->ColNo(KColumnID);
1426 test(col!=KDbNullColNo);
1429 TInt p1=aSet.FindL(aSet.EForwards,KFind1);
1432 test(aSet.ColUint(col)==1);
1433 test(aSet.FindL(aSet.EForwards,KFind1)==0);
1435 test(aSet.ColUint(col)==1);
1437 test(aSet.FindL(aSet.EForwards,KFind1)==KErrNotFound);
1439 test(aSet.FindL(aSet.EForwards,KFind2)==KErrNotFound);
1441 TInt p2=aSet.FindL(aSet.EBackwards,KFind1);
1444 test(aSet.ColUint(col)==1);
1445 test(aSet.FindL(aSet.EBackwards,KFind1)==0);
1447 test(aSet.ColUint(col)==1);
1448 if (aSet.PreviousL())
1449 test(aSet.FindL(aSet.EBackwards,KFind1)==KErrNotFound);
1451 test(aSet.FindL(aSet.EBackwards,KFind2)==KErrNotFound);
1452 test(p1+p2+1==aSet.CountL());
1456 @SYMTestCaseID SYSLIB-DBMS-CT-0600
1457 @SYMTestCaseDesc Tests for SQL find
1458 @SYMTestPriority Medium
1459 @SYMTestActions Tests for SQL querying a table
1460 @SYMTestExpectedResults Test must not fail
1463 LOCAL_C void TestSQLFind(const TText* aSql)
1465 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0600 "));
1466 test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
1467 test(TheView.EvaluateAll()==KErrNone);
1473 @SYMTestCaseID SYSLIB-DBMS-CT-0601
1474 @SYMTestCaseDesc Tests for DBMS limits
1475 @SYMTestPriority Medium
1476 @SYMTestActions Tests for maximum length boundaries
1477 @SYMTestExpectedResults Test must not fail
1480 LOCAL_C void TestDbmsBoundaries()
1482 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0601 "));
1483 // Test KMaxSegmentLength boundary
1485 _LIT(KMaxSegmentLengthMinusOne,"txt like \
1486 '*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*' \
1488 '*01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567@0.com*'");
1489 _LIT(KMaxSegmentLengthExact,"txt like \
1490 '*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*' \
1492 '*012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678@0.com*'");
1493 _LIT(KMaxSegmentLengthPlusOne,"txt like \
1494 '*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*' \
1496 '*0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@0.com*'");
1499 RDbRowConstraint match;
1501 test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
1503 // Test one less than the boundary
1504 ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthMinusOne,EDbCompareFolded));
1506 test(ret==KErrNone);
1508 // Test the boundary
1509 ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthExact,EDbCompareFolded));
1511 test(ret==KErrNone);
1513 // Test one more than the boundary
1514 ret = match.Open(TheTable,TDbQuery(KMaxSegmentLengthPlusOne,EDbCompareFolded));
1516 test(ret==KErrArgument);
1522 @SYMTestCaseID SYSLIB-DBMS-CT-0602
1523 @SYMTestCaseDesc Tests for table order,SQL query,
1524 @SYMTestPriority Medium
1525 @SYMTestActions Tests for finding a row in a rowset,dbms boundaries,SQL querying
1526 @SYMTestExpectedResults Test must not fail
1529 LOCAL_C void TestFind()
1531 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0602 Table order "));
1532 test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
1534 test.Next(_L("Index order"));
1535 test(TheTable.SetIndex(KIndexName)==KErrNone);
1537 test(TheTable.SetIndex(KIndexName2)==KErrNone);
1541 test.Next(_L("SQL query test boundary"));
1542 TestDbmsBoundaries();
1544 test.Next(_L("SQL query"));
1545 TestSQLFind(_S("select id from TestFindTable where id=1"));
1546 TestSQLFind(_S("select * from TestFindTable where id<=2"));
1547 TestSQLFind(_S("select txt,id from TestFindTable order by id desc"));
1548 TestSQLFind(_S("select id,txt from TestFindTable where id=1 or txt like '*text*'"));
1549 TestSQLFind(_S("select * from TestFindTable where id=1 or txt is not null order by id"));
1550 TestSQLFind(_S("select id from TestFindTable where id<>3 order by txt"));
1554 LOCAL_C void TestBookmark(RDbRowSet& aSet)
1557 while (aSet.NextL())
1560 TUint id=aSet.ColUint(1);
1561 TDbBookmark mark=aSet.Bookmark();
1565 test(aSet.ColUint(1)==id);
1571 test(aSet.ColUint(1)==id);
1576 LOCAL_C void TestSQLBookmark(const TText* aSql)
1578 test(TheView.Prepare(TheDatabase,TDbQuery(TPtrC(aSql),EDbCompareFolded),TheView.EReadOnly)==KErrNone);
1579 test(TheView.EvaluateAll()==KErrNone);
1580 TestBookmark(TheView);
1584 LOCAL_C void TestBookmark()
1586 test.Start(_L("Table order"));
1587 test(TheTable.Open(TheDatabase,KTestFindTable,TheTable.EReadOnly)==KErrNone);
1588 TestBookmark(TheTable);
1589 test.Next(_L("Index order"));
1590 test(TheTable.SetIndex(KIndexName)==KErrNone);
1591 TestBookmark(TheTable);
1592 test(TheTable.SetIndex(KIndexName2)==KErrNone);
1593 TestBookmark(TheTable);
1595 test.Next(_L("SQL query"));
1596 TestSQLBookmark(_S("select * from TestFindTable where id=1"));
1597 TestSQLBookmark(_S("select * from TestFindTable where id>2"));
1598 TestSQLBookmark(_S("select * from TestFindTable order by id desc"));
1599 TestSQLBookmark(_S("select * from TestFindTable where txt like '*text*'"));
1600 TestSQLBookmark(_S("select * from TestFindTable where txt is not null order by id"));
1601 TestSQLBookmark(_S("select * from TestFindTable where id <> 3 order by txt"));
1606 @SYMTestCaseID SYSLIB-DBMS-CT-0603
1607 @SYMTestCaseDesc Tests for find and bookmark
1608 @SYMTestPriority Medium
1609 @SYMTestActions Executes Match,Find,Bookmarks tests
1610 @SYMTestExpectedResults Test must not fail
1613 LOCAL_C void TestFindAndBookmark()
1615 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0603 Create Table "));
1618 test.Next(_L("Match"));
1620 test.Next(_L("Find"));
1622 test.Next(_L("Bookmarks"));
1624 test.Next(_L("Close"));
1630 @SYMTestCaseID SYSLIB-DBMS-CT-0604
1631 @SYMTestCaseDesc Tests for multi view
1632 @SYMTestPriority Medium
1633 @SYMTestActions Tests for adding and deleting rows
1634 @SYMTestExpectedResults Test must not fail
1637 LOCAL_C void TestMultiView()
1639 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0604 Create Table "));
1641 CDbColSet* set=CreateColSetL(ESingleColumn);
1642 test(TheDatabase.CreateTable(KTestMultiTable,*set)==KErrNone);
1644 test.Next(_L("Add and modify rows"));
1645 test(TheTable.Open(TheDatabase,KTestMultiTable)==KErrNone);
1646 test(TheView.Prepare(TheDatabase,_L("select * from TestMultiTable"))==KErrNone);
1647 test(TheView.EvaluateAll()==KErrNone);
1648 for (TInt ii=1;ii<=10;++ii)
1651 TheTable.SetColL(1,ii);
1655 test(TheView.ColInt(1)==ii);
1657 TheView.SetColL(1,ii+100);
1659 test(TheTable.ColInt(1)==ii);
1661 test(TheTable.ColInt(1)==ii+100);
1663 test.Next(_L("delete rows"));
1667 test (TheView.ColInt(1)==1+100);
1669 TRAPD(r,TheView.GetL());
1673 test (TheView.ColInt(1)==2+100);
1675 test(!TheView.PreviousL());
1677 test(!TheTable.PreviousL());
1684 LOCAL_C void ValidateUID3(const TDesC& aDbName, const TUid& aUid)
1686 test.Next(_L("Read DB header"));
1688 TInt err = dbFile.Open(TheFs, aDbName, EFileRead);
1689 test(err==KErrNone);
1690 TBuf8<100> contents; // header of a new DB is approx 77 bytes
1691 err = dbFile.Read(contents);
1693 test(err==KErrNone);
1695 test.Next(_L("Check UID3"));
1696 const TPtrC8 ptr((const TUint8*) &aUid.iUid, sizeof(aUid.iUid));
1697 TInt pos = contents.Find(ptr);
1698 test(pos==8); // UID3 begins at byte pos 8
1702 @SYMTestCaseID SYSLIB-DBMS-CT-1372
1703 @SYMTestCaseDesc Tests for UID3 being set in DB header
1704 @SYMTestPriority Medium
1705 @SYMTestActions Creates a new DB and checks UID3
1706 @SYMTestExpectedResults Test must not fail
1709 LOCAL_C void TestDbUID3()
1711 const TUid KOrigUid = {0x19768253}; // random UID
1712 const TUid KReplaceUid = {0x24731264}; // different random UID
1714 const TPtrC KTempDbName(_S("C:\\dbms-tst\\T_DBMS_UID3.DB"));
1716 const TPtrC KTempDbName(_S(".\\dbms-tst\\T_DBMS_UID3.DB"));
1719 (void)TheFs.Delete(KTempDbName);
1721 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1372 Create Database "));
1722 RDbNamedDatabase tempDb;
1723 TInt err = tempDb.Create(TheFs, KTempDbName, KOrigUid.Name());
1724 test(err==KErrNone);
1727 ValidateUID3(KTempDbName, KOrigUid);
1729 test.Next(_L("Replace Database"));
1730 err = tempDb.Replace(TheFs, KTempDbName, KReplaceUid.Name());
1731 test(err==KErrNone);
1734 ValidateUID3(KTempDbName, KReplaceUid);
1736 test.Next(_L("Replace Database using default UID3"));
1737 err = tempDb.Replace(TheFs, KTempDbName);
1738 test(err==KErrNone);
1741 ValidateUID3(KTempDbName, KNullUid);
1743 (void)TheFs.Delete(KTempDbName);
1750 test.Start(_L("DDL"));
1755 test.Next(_L("Navigation/Edit"));
1760 test.Next(_L("Column Types"));
1761 TRAP(r,TestTypes();)
1765 test.Next(_L("Find, Match & Bookmarks"));
1766 TRAP(r,TestFindAndBookmark();)
1770 test.Next(_L("Multiple view updates"));
1771 TRAP(r,TestMultiView();)
1775 test.Next(_L("Database UID3"));
1776 TRAP(r,TestDbUID3();)
1783 // Prepare the test directory.
1785 LOCAL_C void setupTestDirectory()
1787 TInt r=TheFs.Connect();
1790 r=TheFs.MkDir(KTestDatabase);
1791 test(r==KErrNone || r==KErrAlreadyExists);
1795 // Initialise the cleanup stack.
1797 LOCAL_C void setupCleanup()
1799 TheTrapCleanup=CTrapCleanup::New();
1800 test(TheTrapCleanup!=NULL);
1803 for (TInt i=KTestCleanupStack;i>0;i--)\
1804 CleanupStack::PushL((TAny*)0);\
1805 CleanupStack::Pop(KTestCleanupStack);\
1810 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
1813 TInt err = fsSession.Connect();
1817 if(fsSession.Entry(aFullName, entry) == KErrNone)
1819 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1820 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1823 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1825 err = fsSession.Delete(aFullName);
1828 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1835 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1840 // Test streaming conversions.
1842 GLDEF_C TInt E32Main()
1845 setupTestDirectory();
1850 TInt r=TheDbs.Connect();
1853 test.Start(_L("Standard database"));
1855 test.Next(_L("Secure database"));
1864 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1865 test(err==KErrNone);
1868 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1870 TheCrcChecker.ErrorReportL(err, errmsg);
1871 RDebug::Print(errmsg);
1872 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1876 test.Next(_L("Waiting for server exit"));
1877 const TUint KExitDelay=6*0x100000; // ~6 seconds
1878 User::After(KExitDelay);
1882 delete TheTrapCleanup;
1884 ::DeleteDataFile(KTestDatabase);