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.
17 #include <../include/d32dbms.h>
31 #undef __UHEAP_MARKEND
32 #define __UHEAP_MARKEND
34 LOCAL_D TDBMS_CRCChecks TheCrcChecker;
36 #ifndef __linux__ //No CRC test on LINUX
38 const TPtrC KCrcRecord=_L("\\epoc32\\winscw\\c\\dbms-tst\\T_INDEX.CRC");
40 const TPtrC KCrcRecord=_L("C:\\dbms-tst\\T_INDEX.CRC");
45 // MSVC++ up to 5.0 has problems with expanding inline functions
46 // This disables the mad warnings for the whole project
47 #if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
48 #pragma warning(disable : 4710) // function not expanded. MSVC 5.0 is stupid
51 LOCAL_D RTest test(_L("T_INDEX - Test DBMS indexing and ordering"));
52 LOCAL_D CTrapCleanup* TheTrapCleanup;
54 LOCAL_D RDbNamedDatabase TheDatabase;
55 LOCAL_D RDbTable TheTable;
56 LOCAL_D RDbView TheView;
58 LOCAL_D TBuf<0x200> TheBuf;
60 const TInt KTestCleanupStack=0x20;
63 const TPtrC KTestDatabase=_L(".\\dbms-tst\\T_INDEX.DB");
65 const TPtrC KTestDatabase=_L("C:\\dbms-tst\\T_INDEX.DB");
68 const TPtrC KTableName(_S("Table"));
69 const TPtrC KIndexName(_S("index"));
70 const TPtrC KIndexTwo(_S("index_two"));
71 const TPtrC KColumnName(_S("column"));
72 const TPtrC KColumnTwo(_S("column2"));
74 const TPtrC KSelectOrdered(_L("select column from table order by column"));
76 #define elementsof(array) (sizeof(array)/sizeof(array[0]))
80 // Open the database (shared access) (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
82 LOCAL_C void OpenDatabaseL()
84 TInt r=TheDatabase.Open(TheDbs,KTestDatabase);
89 // Create the database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
91 LOCAL_C void CreateDatabaseL()
93 TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
96 TheCrcChecker.GenerateCrcL(KTestDatabase);
101 LOCAL_C void CloseDatabaseL()
104 TheCrcChecker.GenerateCrcL(KTestDatabase);
108 @SYMTestCaseID SYSLIB-DBMS-CT-0618
109 @SYMTestCaseDesc Tests for RDbNamedDatabase functionality
110 @SYMTestPriority Medium
111 @SYMTestActions Tests for RDbNamedDatabase::CreateIndex()
112 @SYMTestExpectedResults Test must not fail
115 LOCAL_C void TestIndexBuild()
117 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0618 Create table "));
119 CDbColSet *cs=CDbColSet::NewLC();
120 cs->AddL(TDbCol(KColumnName,EDbColInt32));
121 cs->AddL(TDbCol(KColumnTwo,EDbColInt32));
122 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
123 CleanupStack::PopAndDestroy();
124 test.Next(_L("create indices"));
125 CDbKey *key=CDbKey::NewLC();
126 key->AddL(TDbKeyCol(KColumnName));
128 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
130 key->AddL(TDbKeyCol(KColumnTwo));
132 test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
133 CleanupStack::PopAndDestroy();
134 test.Next(_L("Populate table"));
135 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
137 TheTable.SetColL(1,1);
138 TheTable.SetColL(2,-1);
141 TheTable.SetColL(1,2);
142 TheTable.SetColL(2,-2);
144 test(TheDatabase.Commit()==KErrNone);
145 test.Next(_L("Check order"));
146 test(TheTable.SetNoIndex()==KErrNone);
147 test(TheTable.SetIndex(KIndexName)==KErrNone);
148 test(TheTable.CountL()==2);
149 test(TheTable.NextL());
151 test(TheTable.ColInt(1)==1);
152 test(TheTable.NextL());
154 test(TheTable.ColInt(1)==2);
155 test(!TheTable.NextL());
156 test(TheTable.SetIndex(KIndexTwo)==KErrNone);
157 test(TheTable.CountL()==2);
158 test(TheTable.NextL());
160 test(TheTable.ColInt(1)==2);
161 test(TheTable.NextL());
163 test(TheTable.ColInt(1)==1);
164 test(!TheTable.NextL());
165 test(TheTable.SetNoIndex()==KErrNone);
166 test(TheTable.CountL()==2);
167 test(TheTable.NextL());
168 test(TheTable.NextL());
169 test(!TheTable.NextL());
171 test.Next(_L("Drop indices"));
172 test(TheDatabase.DropIndex(KIndexTwo,KTableName)==KErrNone);
173 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
174 test(TheTable.SetIndex(KIndexName)==KErrNone);
175 test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
177 test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
178 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
179 test(TheTable.SetIndex(KIndexName)!=KErrNone);
180 test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
182 test(TheDatabase.DropTable(KTableName)==KErrNone);
186 LOCAL_C TInt CountRowsL()
189 while (TheTable.NextL())
195 @SYMTestCaseID SYSLIB-DBMS-CT-0619
196 @SYMTestCaseDesc RDbNamedDatabase::Execute() function test
197 @SYMTestPriority Medium
198 @SYMTestActions Tests for CREATE TABLE,CREATE INDEX and CREATE UNIQUE INDEX query
199 @SYMTestExpectedResults Test must not fail
202 LOCAL_C void TestPersistence()
204 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0619 Create table "));
206 test(TheDatabase.Execute(_L("CREATE TABLE Table (column CHAR(120) NOT NULL)"))==KErrNone);
207 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
209 TheTable.SetColL(1,_L("a"));
212 TheTable.SetColL(1,_L("b"));
215 TheTable.SetColL(1,_L("c"));
218 TheTable.SetColL(1,_L("d"));
221 TheTable.SetColL(1,_L("e"));
224 test(TheDatabase.Commit()==KErrNone);
225 test.Next(_L("Build indices"));
226 test (TheDatabase.Execute(_L("CREATE INDEX index ON table (column ASC)"))==KErrNone);
227 test (TheDatabase.Execute(_L("CREATE UNIQUE INDEX index_two ON table (column DESC)"))==KErrNone);
228 test.Next(_L("Close and re-open database"));
231 test.Next(_L("Check indices"));
232 CDbKey* key=TheDatabase.KeyL(KIndexName,KTableName);
233 test (key->Count()==1);
234 test (key->Comparison()==EDbCompareNormal);
235 test (!key->IsUnique());
236 test ((*key)[0].iName.CompareF(KColumnName)==0);
237 test ((*key)[0].iOrder==TDbKeyCol::EAsc);
239 key=TheDatabase.KeyL(KIndexTwo,KTableName);
240 test (key->Count()==1);
241 test (key->Comparison()==EDbCompareNormal);
242 test (key->IsUnique());
243 test ((*key)[0].iName.CompareF(KColumnName)==0);
244 test ((*key)[0].iOrder==TDbKeyCol::EDesc);
246 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
247 test(TheTable.SetNoIndex()==KErrNone);
248 test(CountRowsL()==5);
249 test(TheTable.CountL()==5);
250 test(TheTable.SetIndex(KIndexName)==KErrNone);
251 test(TheTable.CountL()==5);
252 test(CountRowsL()==5);
253 test(TheTable.SetIndex(KIndexTwo)==KErrNone);
254 test(TheTable.CountL()==5);
255 test(CountRowsL()==5);
257 test.Next(_L("Drop indices"));
259 test (TheDatabase.Execute(_L("DROP INDEX index_two FROM table"))==KErrNone);
260 test (TheDatabase.Execute(_L("DROP INDEX index FROM table"))==KErrNone);
261 test (TheDatabase.Execute(_L("DROP TABLE table"))==KErrNone);
262 test(TheDatabase.Commit()==KErrNone);
266 LOCAL_C void BuildTableProlog(TDbColType aType,TInt aAttribs=0)
269 CDbColSet *cs=CDbColSet::NewLC();
270 TDbCol col(KColumnName,aType);
271 col.iAttributes=aAttribs;
273 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
274 CleanupStack::PopAndDestroy();
275 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
278 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt& aValue)
279 {aSet.SetColL(col,aValue);}
280 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TUint& aValue)
281 {aSet.SetColL(col,aValue);}
282 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt64& aValue)
283 {aSet.SetColL(col,aValue);}
284 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal32& aValue)
285 {aSet.SetColL(col,aValue);}
286 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal64& aValue)
287 {aSet.SetColL(col,aValue);}
288 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TTime& aValue)
289 {aSet.SetColL(col,aValue);}
290 inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TPtrC& aValue)
291 {aSet.SetColL(col,aValue);}
294 void BuildTable(TDbColType aType,TInt aAttribs,T aValues[],TInt aCount)
296 BuildTableProlog(aType,aAttribs);
297 for (TInt ii=0;ii<aCount;++ii)
300 SetColL(TheTable,1,aValues[ii]);
303 test(TheDatabase.Commit()==KErrNone);
304 test (TheTable.CountL()==aCount);
309 @SYMTestCaseID SYSLIB-DBMS-CT-0620
310 @SYMTestCaseDesc Setting the specified index as the active index for a table test
311 @SYMTestPriority Medium
312 @SYMTestActions Create an index and set as active index for the table.
313 Tests for RDbNamedDatabase::CreateIndex(),RDbNamedDatabase::Commit()
314 RDbTable::Open(),RDbTable::SetIndex() functions.
315 @SYMTestExpectedResults Test must not fail
318 LOCAL_C void BuildIndex(TDbTextComparison aComparison=EDbCompareNormal,TInt aLength=KDbUndefinedLength)
320 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0620 Test index order "));
322 CDbKey *key=CDbKey::NewLC();
323 key->AddL(TDbKeyCol(KColumnName,aLength));
325 key->SetComparison(aComparison);
326 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
327 CleanupStack::PopAndDestroy();
328 test (TheDatabase.Commit()==KErrNone);
329 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
330 test(TheTable.SetIndex(KIndexName)==KErrNone);
333 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt& aValue)
334 {aValue=aSet.ColInt(col);}
335 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TUint& aValue)
336 {aValue=aSet.ColUint(col);}
337 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt64& aValue)
338 {aValue=aSet.ColInt64(col);}
339 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal32& aValue)
340 {aValue=aSet.ColReal32(col);}
341 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal64& aValue)
342 {aValue=aSet.ColReal64(col);}
343 inline void GetCol(RDbRowSet& aSet,TDbColNo col,TTime& aValue)
344 {aValue=aSet.ColTime(col);}
347 @SYMTestCaseID SYSLIB-DBMS-CT-0621
348 @SYMTestCaseDesc RDbRowSet ordering test
349 @SYMTestPriority Medium
350 @SYMTestActions Reorder the row set data with RDbRowSet::GetL(),SetL() functions.
351 @SYMTestExpectedResults Test must not fail
355 void TestOrdering(RDbRowSet& aSet,T,TInt aCount)
357 test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0621 " ) );
358 test(aSet.CountL()==aCount);
371 GetCol(aSet,1,current);
380 @SYMTestCaseID SYSLIB-DBMS-CT-0622
381 @SYMTestCaseDesc RDbTable::SeekL() function test
382 @SYMTestPriority Medium
383 @SYMTestActions Tests for the retrieved column value
384 @SYMTestExpectedResults Test must not fail
388 void TestSeek(RDbTable& aTable,T,const T aValues[],TInt aCount)
390 test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0622 Test index seeking " ) );
391 for (TInt ii=0;ii<aCount;++ii)
393 test(aTable.SeekL(aValues[ii]));
396 GetCol(aTable,1,val);
397 test(aValues[ii]==val);
402 aVal argument is used in the test functions (TestType & TestOrdering) and has no meaning outside them.
403 It is used only to avoid some compiler varnings and to determine the correct template type
405 @SYMTestCaseID SYSLIB-DBMS-CT-0623
406 @SYMTestCaseDesc Tests for RDbTable,RDbRowSet classes
407 @SYMTestPriority Medium
408 @SYMTestActions Call up Test for table ordering and index seeking functions
409 @SYMTestExpectedResults Test must not fail
413 void TestType( TDbColType aType, TInt aAttribs, const T aValues[], TInt aCount )
415 test.Start( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0623 Build table " ) );
416 BuildTable( aType, aAttribs, aValues, aCount );
419 test.Next( _L( "Test ORDER BY ordering" ) );
420 test( TheView.Prepare( TheDatabase, KSelectOrdered ) == KErrNone );
421 test( TheView.EvaluateAll() == KErrNone );
422 TestOrdering( TheView, t, aCount );
425 test.Next( _L( "Test index ordering" ) );
427 TestOrdering( TheTable, t, aCount );
429 test.Next( _L( "Test index seeking" ) );
430 TestSeek( TheTable, t, aValues, aCount );
433 test( TheDatabase.DropTable( KTableName ) == KErrNone );
437 @SYMTestCaseID SYSLIB-DBMS-CT-1322
438 @SYMTestCaseDesc Text ordering test
439 @SYMTestPriority Medium
440 @SYMTestActions Tests for RDbRowSet::Next(),RDbRowSet::GetL(),RDbRowSet::ColDes() functions
441 @SYMTestExpectedResults Test must not fail
444 void TestTextOrdering(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
446 test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1322 "));
447 test(aSet.CountL()==aCount);
452 TPtrC current=aSet.ColDes(1);
454 test(aComp.Compare(TheBuf,current)<0);
461 @SYMTestCaseID SYSLIB-DBMS-CT-1323
462 @SYMTestCaseDesc Tests for RDbView,RDbTable classes
463 @SYMTestPriority Medium
464 @SYMTestActions Wrapper function to call up for text ordering and text indexing tests
465 @SYMTestExpectedResults Test must not fail
468 void TestText(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
470 const TTextOps& comp=TTextOps::Ops(aComparison);
471 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1323 Build table "));
472 BuildTable(EDbColText,0,aValues,aCount);
474 test.Next(_L("Test ORDER BY ordering"));
475 test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
476 test (TheView.EvaluateAll()==KErrNone);
477 TestTextOrdering(TheView,aCount,comp);
480 test.Next(_L("Test index order"));
481 BuildIndex(aComparison,aLength);
482 test(TheTable.SetIndex(KIndexName)==KErrNone);
483 TestTextOrdering(TheTable,aCount,comp);
485 test.Next(_L("Test index seeking"));
486 for (TInt ii=0;ii<aCount;++ii)
488 test(TheTable.SeekL(aValues[ii]));
490 test(comp.Compare(aValues[ii],TheTable.ColDes(1))==0);
494 test(TheDatabase.DropTable(KTableName)==KErrNone);
498 void TestLongTextOrdering(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
500 test(aSet.CountL()==aCount);
506 TInt len=aSet.ColLength(1);
507 HBufC* buf=HBufC::NewL(len);
510 TPtr des(buf->Des());
512 CleanupStack::PopAndDestroy();
514 test (aComp.Compare(*buf,*prev)>=0);
522 LOCAL_C void OrderByLongText(TInt aCount,TDbTextComparison aComparison)
524 test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
525 test (TheView.EvaluateAll()==KErrNone);
526 TestLongTextOrdering(TheView,aCount,TTextOps::Ops(aComparison));
530 LOCAL_C void TestLongText(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
532 const TTextOps& comp=TTextOps::Ops(aComparison);
533 test.Start(_L("Build table"));
534 BuildTable(EDbColLongText,0,aValues,aCount);
536 test.Next(_L("Test ORDER BY ordering"));
537 OrderByLongText(aCount,aComparison);
539 test.Next(_L("Test index order"));
540 BuildIndex(aComparison,aLength);
541 test(TheTable.SetIndex(KIndexName)==KErrNone);
542 TestLongTextOrdering(TheTable,aCount,comp);
544 test.Next(_L("Test index seeking"));
545 for (TInt ii=0;ii<aCount;++ii)
547 test(TheTable.SeekL(aValues[ii]));
549 RDbColReadStream strm;
550 strm.OpenLC(TheTable,1);
551 strm.ReadL(TheBuf,TheTable.ColLength(1));
552 CleanupStack::PopAndDestroy();
553 test(comp.Compare(aValues[ii],TheBuf)==0);
557 test(TheDatabase.DropTable(KTableName)==KErrNone);
561 TUint const KBitValues[]={0,1};
562 TInt const KInt8Values[]={0,KMinTInt8+1,1,KMaxTInt8,2,-3,-1,KMaxTInt8-1,KMinTInt8,-40};
563 TInt const KInt16Values[]={0,KMinTInt16+1,1,KMaxTInt16,2,-3,-1,KMaxTInt16-1,KMinTInt16,-4000};
564 TInt const KInt32Values[]={0,KMinTInt32+1,1,KMaxTInt32,2,-3,-1,KMaxTInt32-1,KMinTInt32,-40000000};
565 TInt const KInt32Count=sizeof(KInt32Values)/sizeof(KInt32Values[0]);
566 TUint const KUint8Values[]={0,1,KMaxTUint8,2,(KMaxTUint8+1)/2,(KMaxTUint8-1)/2,KMaxTUint8-1,40};
567 TUint const KUint16Values[]={0,1,KMaxTUint16,2,(KMaxTUint16+1)/2,(KMaxTUint16-1)/2,KMaxTUint16-1,4000};
568 TUint const KUint32Values[]={0,1,KMaxTUint32,2,KMaxTUint32/2+1,KMaxTUint32/2,KMaxTUint32-1,40000000};
569 //TReal32 const KReal32Values[]={0.0f,1.0f,KMaxTReal32,KMinTReal32,-1.0f,-KMaxTReal32,-4e20f,-KMinTReal32};
570 //TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
571 TReal32 const KReal32Values[]={0.0f,1.0f,1e37f,1e-37f,-1.0f,-1e37f,-4e20f,-1e-37f};
572 TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
573 TInt64 const KInt64Values[]=
576 MAKE_TINT64(0x80000000u,0x1u),
578 MAKE_TINT64(0x7fffffffu,0xffffffffu),
582 MAKE_TINT64(0x7fffffffu,0xfffffffeu),
583 MAKE_TINT64(0x80000000u,0x0u),
586 TTime const KTimeValues[]=
590 TDateTime(1970,EJanuary,0,0,0,0,0),
592 TDateTime(2049,EDecember,30,23,59,59,999999),
593 TDateTime(1996,EJuly,8,17,45,0,0)
595 TPtrC const KTextValues[]=
606 TPtrC const KLongTextValues[]=
608 _S("this blob will be inlined"),
610 _S("that blob was null"),
611 _S("An example of an out-of-line blob in an index! LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8-LongText8")
613 const TInt KLongTextLimit=30;
616 @SYMTestCaseID SYSLIB-DBMS-CT-0624
617 @SYMTestCaseDesc Wrapper function testing for Indexing with different integer sizes and Text .
618 @SYMTestPriority Medium
619 @SYMTestActions Tests for indexing
620 @SYMTestExpectedResults Test must not fail
623 LOCAL_C void TestTypes()
625 #define ARRAY_SIZE(a) TInt(sizeof(a)/sizeof(a[0]))
626 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0624 Indexing Bit "));
627 TestType(EDbColBit,TDbCol::ENotNull,KBitValues,ARRAY_SIZE(KBitValues));
628 test.Next(_L("Indexing Int8"));
629 TestType(EDbColInt8,TDbCol::ENotNull,KInt8Values,ARRAY_SIZE(KInt8Values));
630 test.Next(_L("Indexing Int16"));
631 TestType(EDbColInt16,TDbCol::ENotNull,KInt16Values,ARRAY_SIZE(KInt16Values));
632 test.Next(_L("Indexing Int32"));
633 TestType(EDbColInt32,TDbCol::ENotNull,KInt32Values,ARRAY_SIZE(KInt32Values));
634 test.Next(_L("Indexing Uint8"));
635 TestType(EDbColUint8,TDbCol::ENotNull,KUint8Values,ARRAY_SIZE(KUint8Values));
636 test.Next(_L("Indexing Uint16"));
637 TestType(EDbColUint16,TDbCol::ENotNull,KUint16Values,ARRAY_SIZE(KUint16Values));
638 test.Next(_L("Indexing Uint32"));
639 TestType(EDbColUint32,TDbCol::ENotNull,KUint32Values,ARRAY_SIZE(KUint32Values));
640 test.Next(_L("Indexing Real32"));
641 TestType(EDbColReal32,TDbCol::ENotNull,KReal32Values,ARRAY_SIZE(KReal32Values));
642 test.Next(_L("Indexing Real64"));
643 TestType(EDbColReal64,TDbCol::ENotNull,KReal64Values,ARRAY_SIZE(KReal64Values));
644 test.Next(_L("Indexing Int64"));
645 TestType(EDbColInt64,TDbCol::ENotNull,KInt64Values,ARRAY_SIZE(KInt64Values));
646 test.Next(_L("Indexing Time"));
647 TestType(EDbColDateTime,TDbCol::ENotNull,KTimeValues,ARRAY_SIZE(KTimeValues));
648 test.Next(_L("Indexing Text (Normal)"));
649 TestText(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal);
650 test.Next(_L("Indexing Text (Folded)"));
651 TestText(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareFolded);
652 test.Next(_L("Indexing Text (Collated)"));
653 TestText(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareCollated);
654 test.Next(_L("Indexing Text (Normal, truncated)"));
655 TestText(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal,5);
656 test.Next(_L("Indexing LongText (Normal)"));
657 TestLongText(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareNormal,KLongTextLimit);
658 test.Next(_L("Indexing LongText (Folded)"));
659 TestLongText(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareFolded,KLongTextLimit);
660 test.Next(_L("Indexing LongText (Collated)"));
661 TestLongText(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareCollated,KLongTextLimit);
665 const TInt KBlobKeyTruncated=32/sizeof(TText);
666 const TInt KBlobKeyMaxInline=255/sizeof(TText);
667 const TInt KBlobKeyCompare=512/sizeof(TText);
669 const TInt KMemoTestLengths[]=
684 void TestMemoTable(CDbColSet& aBaseSet)
686 test.Start(_L("create the table"));
687 aBaseSet.AddL(TDbCol(KColumnName,EDbColLongText));
689 TInt r=TheDatabase.CreateTable(KTableName,aBaseSet);
692 test.Next(_L("add the rows"));
693 r=TheView.Prepare(TheDatabase,KSelectOrdered,RDbView::EInsertOnly);
695 r=TheView.EvaluateAll();
699 for (TUint ii=0;ii<elementsof(KMemoTestLengths);++ii)
701 TInt size=KMemoTestLengths[ii];
702 HBufC* buf=HBufC::NewL(size);
705 TPtr des(buf->Des());
707 des.AppendFill('b',size-prev->Length());
710 TheView.SetColL(1,*buf);
716 TheView.SetColL(1,*buf);
723 r=TheDatabase.Commit();
726 test.Next(_L("Normal order"));
727 OrderByLongText(count,EDbCompareNormal);
728 test.Next(_L("Folded order"));
729 OrderByLongText(count,EDbCompareFolded);
730 test.Next(_L("Collated order"));
731 OrderByLongText(count,EDbCompareCollated);
733 r=TheDatabase.DropTable(KTableName);
739 @SYMTestCaseID SYSLIB-DBMS-CT-0625
740 @SYMTestCaseDesc Tests for ordering by longtext
741 @SYMTestPriority Medium
742 @SYMTestActions Tests for CDbColSet
743 @SYMTestExpectedResults Test must not fail
746 LOCAL_C void TestOrderByLongText()
748 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0625 Maximum Inline Limit "));
749 CDbColSet* set=CDbColSet::NewLC();
752 test.Next(_L("Reduced Inline limit [<32]"));
755 col.iType=EDbColText8;
759 for (TInt ii=0;ii<32;++ii)
761 name.Format(_L("col%d"),ii);
764 col.iMaxLength=255-20;
768 CleanupStack::PopAndDestroy();
773 @SYMTestCaseID SYSLIB-DBMS-CT-0626
774 @SYMTestCaseDesc Tests for reverse ordering in indexes
775 @SYMTestPriority Medium
776 @SYMTestActions Tests for reversing the indexes
777 @SYMTestExpectedResults Test must not fail
780 LOCAL_C void TestReverse()
782 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0626 Create table and index "));
784 CDbColSet *cs=CDbColSet::NewLC();
785 cs->AddL(TDbCol(KColumnName,EDbColInt32));
786 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
787 CleanupStack::PopAndDestroy();
788 CDbKey *key=CDbKey::NewLC();
789 key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
791 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
792 CleanupStack::PopAndDestroy();
793 test(TheDatabase.Commit()==KErrNone);
794 test.Next(_L("Add records"));
796 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
797 for (TInt ii=0;ii<KInt32Count;++ii)
800 TheTable.SetColL(1,KInt32Values[ii]);
803 test(TheDatabase.Commit()==KErrNone);
804 test(TheTable.CountL()==KInt32Count);
805 test.Next(_L("Check order"));
806 test(TheTable.SetIndex(KIndexName)==KErrNone);
807 test(TheTable.CountL()==KInt32Count);
809 if (TheTable.FirstL())
813 TInt32 last=TheTable.ColInt(1);
814 while (TheTable.NextL())
818 TInt32 current=TheTable.ColInt(1);
823 test(count==KInt32Count);
825 test(TheDatabase.DropTable(KTableName)==KErrNone);
830 @SYMTestCaseID SYSLIB-DBMS-CT-0627
831 @SYMTestCaseDesc Tests for multi-column keys
832 @SYMTestPriority Medium
833 @SYMTestActions Tests for mutliple column keys
834 @SYMTestExpectedResults Test must not fail
837 LOCAL_C void TestMulti()
839 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0627 Create table and index "));
841 CDbColSet *cs=CDbColSet::NewLC();
842 TDbCol col(KColumnName,EDbColInt32);
843 col.iAttributes=TDbCol::ENotNull;
845 col.iName=KColumnTwo;
847 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
848 CleanupStack::PopAndDestroy();
849 CDbKey *key=CDbKey::NewLC();
850 key->AddL(TDbKeyCol(KColumnTwo));
851 key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
853 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
854 CleanupStack::PopAndDestroy();
855 test(TheDatabase.Commit()==KErrNone);
856 test.Next(_L("Add records"));
858 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
859 for (TInt ii=0;ii<KInt32Count;++ii)
861 for (TInt jj=0;jj<KInt32Count;++jj)
864 TheTable.SetColL(1,KInt32Values[ii]);
865 TheTable.SetColL(2,KInt32Values[jj]);
869 test(TheDatabase.Commit()==KErrNone);
870 test.Next(_L("Check order"));
871 test(TheTable.CountL()==KInt32Count*KInt32Count);
872 test(TheTable.SetIndex(KIndexName)==KErrNone);
873 test(TheTable.CountL()==KInt32Count*KInt32Count);
875 if (TheTable.FirstL())
879 TInt32 lastOne=TheTable.ColInt(1);
880 TInt32 lastTwo=TheTable.ColInt(2);
881 while (TheTable.NextL())
885 TInt32 currentOne=TheTable.ColInt(1);
886 TInt32 currentTwo=TheTable.ColInt(2);
887 test(lastTwo<currentTwo||(lastTwo==currentTwo&&lastOne>currentOne));
892 test(count==KInt32Count*KInt32Count);
894 test(TheDatabase.DropTable(KTableName)==KErrNone);
899 @SYMTestCaseID SYSLIB-DBMS-CT-0628
900 @SYMTestCaseDesc Tests duplicates/unique constraints
901 @SYMTestPriority Medium
902 @SYMTestActions Tests for adding duplicate entries
903 @SYMTestExpectedResults Test must not fail
906 LOCAL_C void TestDuplicates()
908 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0628 Create table and indices "));
909 BuildTable(EDbColInt32,TDbCol::ENotNull,KInt32Values,KInt32Count);
912 CDbKey* key=CDbKey::NewLC();
913 key->AddL(KColumnName);
914 test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
915 CleanupStack::PopAndDestroy();
916 test.Next(_L("Attempt to add/update duplicate entry"));
917 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
919 TheTable.SetColL(1,0);
920 TRAPD(r,TheTable.PutL());
925 TheTable.SetColL(1,0);
926 TRAP(r,TheTable.PutL());
929 test.Next(_L("Remove unique index"));
931 test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
932 test.Next(_L("Attempt to update/add duplicate entry"));
933 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
936 TheTable.SetColL(1,0);
937 TRAP(r,TheTable.PutL());
940 TheTable.SetColL(1,0);
941 TRAP(r,TheTable.PutL());
943 test.Next(_L("Check order"));
944 test(TheTable.CountL()==KInt32Count+1);
945 test(TheTable.SetIndex(KIndexTwo)==KErrNone);
946 test(TheTable.CountL()==KInt32Count+1);
948 if (TheTable.FirstL())
952 TInt32 last=TheTable.ColInt(1);
953 while (TheTable.NextL())
957 TInt32 current=TheTable.ColInt(1);
958 test(last<=current); // duplicates present
962 test(count==KInt32Count+1);
963 test.Next(_L("Try to create unique index"));
966 key->AddL(KColumnName);
968 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)!=KErrNone);
969 CleanupStack::PopAndDestroy();
970 test(TheDatabase.DropTable(KTableName)==KErrNone);
974 struct Pair { TInt i1,i2; };
981 // seek pair: results for <,<=,=,>=,>
982 static TSeekingTest const SeekingTests[]=
984 {{0,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
985 {{0,-1},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
986 {{100,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
987 {{100,10},{{-1,-1},{100,10},{100,10},{100,10},{100,20}}},
988 {{100,55},{{100,50},{100,50},{-1,-1},{100,60},{100,60}}},
989 {{100,60},{{100,50},{100,60},{100,60},{100,60},{100,70}}},
990 {{100,100},{{100,90},{100,100},{100,100},{100,100},{200,10}}},
991 {{100,110},{{100,100},{100,100},{-1,-1},{200,10},{200,10}}},
992 {{100,-1},{{-1,-1},{100,100},{100,10},{100,10},{200,10}}},
993 {{500,-1},{{400,100},{500,100},{500,10},{500,10},{600,10}}},
994 {{550,50},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
995 {{550,-1},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
996 {{1000,0},{{900,100},{900,100},{-1,-1},{1000,10},{1000,10}}},
997 {{1000,10},{{900,100},{1000,10},{1000,10},{1000,10},{1000,20}}},
998 {{1000,100},{{1000,90},{1000,100},{1000,100},{1000,100},{-1,-1}}},
999 {{1000,110},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
1000 {{1000,-1},{{900,100},{1000,100},{1000,10},{1000,10},{-1,-1}}},
1001 {{1100,0},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
1002 {{1100,-1},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}}
1006 @SYMTestCaseID SYSLIB-DBMS-CT-0629
1007 @SYMTestCaseDesc Tests for seeking on indexes
1008 @SYMTestPriority Medium
1009 @SYMTestActions Tests for SeekL and GetL functions
1010 @SYMTestExpectedResults Test must not fail
1013 LOCAL_C void TestSeeking()
1015 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0629 Create table and index "));
1016 TheDatabase.Begin();
1017 CDbColSet *cs=CDbColSet::NewLC();
1018 TDbCol col(KColumnName,EDbColInt32);
1019 col.iAttributes=TDbCol::ENotNull;
1021 col.iName=KColumnTwo;
1023 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1024 CleanupStack::PopAndDestroy();
1025 CDbKey *key=CDbKey::NewLC();
1026 key->AddL(KColumnName).AddL(KColumnTwo);
1028 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1029 CleanupStack::PopAndDestroy();
1030 test(TheDatabase.Commit()==KErrNone);
1031 test.Next(_L("Add records"));
1032 TheDatabase.Begin();
1033 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1034 for (TInt ii=100;ii<=1000;ii+=100)
1036 for (TInt jj=10;jj<=100;jj+=10)
1039 TheTable.SetColL(1,ii);
1040 TheTable.SetColL(2,jj);
1044 test(TheDatabase.Commit()==KErrNone);
1045 test(TheTable.CountL()==100);
1046 test(TheTable.SetIndex(KIndexName)==KErrNone);
1047 test(TheTable.CountL()==100);
1048 test.Next(_L("Seeking"));
1049 const TSeekingTest* stest=SeekingTests;
1050 const TSeekingTest* const end=stest+sizeof(SeekingTests)/sizeof(SeekingTests[0])-1;
1051 for (;stest<=end;++stest)
1053 TDbSeekMultiKey<2> key;
1054 key.Add(stest->iSeek.i1);
1055 if (stest->iSeek.i2>=0)
1056 key.Add(stest->iSeek.i2);
1057 const Pair* results=stest->iResults;
1058 for (TInt ii=RDbTable::ELessThan;ii<=RDbTable::EGreaterThan;++results,++ii)
1060 if (TheTable.SeekL(key,RDbTable::TComparison(ii)))
1062 test(results->i1>=0);
1063 TRAPD(errCode, TheTable.GetL());
1064 test(errCode==KErrNone);
1065 test(TheTable.ColInt(1)==results->i1);
1066 test(TheTable.ColInt(2)==results->i2);
1069 test(results->i1<0);
1073 test(TheDatabase.DropTable(KTableName)==KErrNone);
1078 @SYMTestCaseID SYSLIB-DBMS-CT-0630
1079 @SYMTestCaseDesc Tests for defect,index creation and set index operations
1080 @SYMTestPriority Medium
1081 @SYMTestActions Tests for creating and setting index operations
1082 @SYMTestExpectedResults Test must not fail
1085 LOCAL_C void TestInequalityError()
1087 test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0630 Create table "));
1088 TheDatabase.Begin();
1089 CDbColSet *cs=CDbColSet::NewLC();
1090 cs->AddL(TDbCol(KColumnName,EDbColInt32));
1091 test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
1092 CleanupStack::PopAndDestroy();
1094 test.Next(_L("create indices"));
1095 CDbKey *key=CDbKey::NewLC();
1096 key->AddL(TDbKeyCol(KColumnName));
1097 test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
1098 CleanupStack::PopAndDestroy();
1100 test.Next(_L("Populate table"));
1101 test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
1102 for(TInt ii=0; ii<=130;++ii)
1105 TheTable.SetColL(1,ii);
1109 test.Next(_L("Checks"));
1110 test(TheTable.SetIndex(KIndexName)==KErrNone);
1112 // We need to delete a row in this node to get to the correct inequality condition
1113 test.Next(_L("Delete row 90"));
1114 test(TheTable.SeekL(TDbSeekKey(90)));
1117 // Now delete last row on node which should be 94
1118 test.Next(_L("Delete row 94"));
1119 test(TheTable.SeekL(TDbSeekKey(94)));
1123 test(!TheTable.SeekL(TDbSeekKey(94)));
1125 test.Next(_L("Insert row 94"));
1127 TheTable.SetColL(1,94);
1130 test.Next(_L("now try and find it"));
1131 test(TheTable.SeekL(TDbSeekKey(94))); //prior to defect fix this line failed.
1134 test(TheDatabase.DropTable(KTableName)==KErrNone);
1139 // Test the database definition and enquiry functions
1141 LOCAL_C void TestIndexes()
1143 test.Start(_L("Create Database"));
1145 test.Next(_L("Test index build and drop"));
1147 test.Next(_L("Test index persistence"));
1149 test.Next(_L("Testing index key types"));
1151 test.Next(_L("Testing LongText ORDER BY"));
1152 TestOrderByLongText();
1153 test.Next(_L("Testing reverse ordering"));
1155 test.Next(_L("Testing multi column keys"));
1157 test.Next(_L("Testing duplicate/unqiue"));
1159 test.Next(_L("Testing seeking"));
1161 test.Next(_L("Testing incorrect inequaltiy condition in store btree"));
1162 TestInequalityError();
1168 // Prepare the test directory.
1170 LOCAL_C void setupTestDirectory()
1172 TInt r=TheFs.Connect();
1175 r=TheFs.MkDir(KTestDatabase);
1176 test(r==KErrNone || r==KErrAlreadyExists);
1180 // Initialise the cleanup stack.
1182 LOCAL_C void setupCleanup()
1184 TheTrapCleanup=CTrapCleanup::New();
1185 test(TheTrapCleanup!=NULL);
1188 for (TInt i=KTestCleanupStack;i>0;i--)\
1189 CleanupStack::PushL((TAny*)0);\
1190 CleanupStack::Pop(KTestCleanupStack);\
1195 LOCAL_C void DeleteDataFile(const TDesC& aFullName)
1198 TInt err = fsSession.Connect();
1202 if(fsSession.Entry(aFullName, entry) == KErrNone)
1204 RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
1205 err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
1208 RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
1210 err = fsSession.Delete(aFullName);
1213 RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
1220 RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
1225 // Test streaming conversions.
1227 GLDEF_C TInt E32Main()
1230 setupTestDirectory();
1235 TInt r=TheDbs.Connect();
1237 TheDbs.ResourceMark();
1241 test.Start(_L("Standard database"));
1242 TRAP(r,TestIndexes();)
1244 test.Next(_L("Secure database"));
1245 TRAP(r,TestIndexes();)
1248 ::DeleteDataFile(KTestDatabase); //deletion of data files must be before call to end - DEF047652
1253 TRAPD(lc, err = TheCrcChecker.DumpCrcRecordsL(KCrcRecord));
1254 test(err==KErrNone);
1257 TRAPD(lc, err = TheCrcChecker.ValidateCrcRecordsL(KCrcRecord));
1259 TheCrcChecker.ErrorReportL(err, errmsg);
1260 RDebug::Print(errmsg);
1261 test(err==KErrNone || err==TDBMS_CRCChecks::ECrcCheckOk);
1267 TheDbs.ResourceCheck();
1271 test.Printf(_L("Waiting for server exit\n"));
1272 const TUint KExitDelay=6*0x100000; // ~6 seconds
1273 User::After(KExitDelay);
1276 delete TheTrapCleanup;