os/persistentdata/persistentstorage/dbms/tdbms/t_dbindex.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <d32dbms.h>
sl@0
    17
#include <s32file.h>
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <e32math.h>
sl@0
    20
#include "D32TABLE.H"
sl@0
    21
sl@0
    22
// MSVC++ up to 5.0 has problems with expanding inline functions
sl@0
    23
// This disables the mad warnings for the whole project
sl@0
    24
#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
sl@0
    25
#pragma warning(disable : 4710)			// function not expanded. MSVC 5.0 is stupid
sl@0
    26
#endif
sl@0
    27
sl@0
    28
LOCAL_D RTest test(_L("t_dbindex - Test DBMS indexing and ordering"));
sl@0
    29
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    30
LOCAL_D RDbs TheDbs;
sl@0
    31
LOCAL_D RDbNamedDatabase TheDatabase;
sl@0
    32
LOCAL_D RDbTable TheTable;
sl@0
    33
LOCAL_D RDbView TheView;
sl@0
    34
LOCAL_D RFs TheFs;
sl@0
    35
LOCAL_D TBuf<0x200> TheBuf;
sl@0
    36
sl@0
    37
const TInt KTestCleanupStack=0x20;
sl@0
    38
const TPtrC KTestDatabase=_L("C:\\DBMS-TST\\T_INDEX.DB");
sl@0
    39
const TPtrC KTableName(_S("Table"));
sl@0
    40
const TPtrC KIndexName(_S("index"));
sl@0
    41
const TPtrC KIndexTwo(_S("index_two"));
sl@0
    42
const TPtrC KColumnName(_S("column"));
sl@0
    43
const TPtrC KColumnTwo(_S("column2"));
sl@0
    44
sl@0
    45
const TPtrC KTableName1(_S("Table1"));
sl@0
    46
const TPtrC KColumnName1(_S("column1"));
sl@0
    47
const TPtrC KIndexName1(_S("index1"));
sl@0
    48
sl@0
    49
const TPtrC KSelectOrdered(_L("select column from table order by column"));
sl@0
    50
sl@0
    51
#define elementsof(array) (sizeof(array)/sizeof(array[0]))
sl@0
    52
sl@0
    53
void Check(TInt aValue,TInt aExpected,TInt aLine)
sl@0
    54
	{
sl@0
    55
	if (aValue!=aExpected)
sl@0
    56
		{
sl@0
    57
		test.Printf(_L("*** Expected %d: got %d\r\n"),aExpected,aValue);
sl@0
    58
		test.operator()(EFalse,aLine);
sl@0
    59
		}
sl@0
    60
	}
sl@0
    61
#define test2(a,b) Check(a,b,__LINE__)
sl@0
    62
sl@0
    63
//
sl@0
    64
// Open the database (shared access) (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
sl@0
    65
//
sl@0
    66
LOCAL_C void OpenDatabase()
sl@0
    67
	{
sl@0
    68
	TInt r=TheDatabase.Open(TheDbs,KTestDatabase);
sl@0
    69
	test (r==KErrNone);
sl@0
    70
	}
sl@0
    71
sl@0
    72
//
sl@0
    73
// Create the database (SYMBIAN_REMOVE_TRIVIAL_ENCRYPTION version)
sl@0
    74
//
sl@0
    75
LOCAL_C void CreateDatabase()
sl@0
    76
	{
sl@0
    77
	TInt r=TheDatabase.Replace(TheFs,KTestDatabase);
sl@0
    78
	test (r==KErrNone);
sl@0
    79
	TheDatabase.Close();
sl@0
    80
	OpenDatabase();
sl@0
    81
	}
sl@0
    82
sl@0
    83
sl@0
    84
LOCAL_C void CloseDatabase()
sl@0
    85
	{
sl@0
    86
	TheDatabase.Close();
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
@SYMTestCaseID          SYSLIB-DBMS-CT-0618
sl@0
    91
@SYMTestCaseDesc        Tests for RDbNamedDatabase functionality
sl@0
    92
@SYMTestPriority        Medium
sl@0
    93
@SYMTestActions         Tests for RDbNamedDatabase::CreateIndex()
sl@0
    94
@SYMTestExpectedResults Test must not fail
sl@0
    95
@SYMREQ                 REQ0000
sl@0
    96
*/
sl@0
    97
LOCAL_C void TestIndexBuildL()
sl@0
    98
	{
sl@0
    99
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0618 Create table "));
sl@0
   100
	TheDatabase.Begin();
sl@0
   101
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   102
	cs->AddL(TDbCol(KColumnName,EDbColInt32));
sl@0
   103
	cs->AddL(TDbCol(KColumnTwo,EDbColInt32));
sl@0
   104
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
   105
	CleanupStack::PopAndDestroy();
sl@0
   106
	test.Next(_L("create indices"));
sl@0
   107
	CDbKey *key=CDbKey::NewLC();
sl@0
   108
	key->AddL(TDbKeyCol(KColumnName));
sl@0
   109
	key->MakeUnique();
sl@0
   110
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
   111
	key->Clear();
sl@0
   112
	key->AddL(TDbKeyCol(KColumnTwo));
sl@0
   113
	key->MakeUnique();
sl@0
   114
	test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
sl@0
   115
	CleanupStack::PopAndDestroy();
sl@0
   116
	test.Next(_L("Populate table"));
sl@0
   117
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   118
	TheTable.InsertL();
sl@0
   119
	TheTable.SetColL(1,1);
sl@0
   120
	TheTable.SetColL(2,-1);
sl@0
   121
	TheTable.PutL();
sl@0
   122
	TheTable.InsertL();
sl@0
   123
	TheTable.SetColL(1,2);
sl@0
   124
	TheTable.SetColL(2,-2);
sl@0
   125
	TheTable.PutL();
sl@0
   126
	test(TheDatabase.Commit()==KErrNone);
sl@0
   127
	test.Next(_L("Check order"));
sl@0
   128
	test(TheTable.SetNoIndex()==KErrNone);
sl@0
   129
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   130
	test(TheTable.CountL()==2);
sl@0
   131
	test(TheTable.NextL());
sl@0
   132
	TheTable.GetL();
sl@0
   133
	test(TheTable.ColInt(1)==1);
sl@0
   134
	test(TheTable.NextL());
sl@0
   135
	TheTable.GetL();
sl@0
   136
	test(TheTable.ColInt(1)==2);
sl@0
   137
	test(!TheTable.NextL());
sl@0
   138
	test(TheTable.SetIndex(KIndexTwo)==KErrNone);
sl@0
   139
	test(TheTable.CountL()==2);
sl@0
   140
	test(TheTable.NextL());
sl@0
   141
	TheTable.GetL();
sl@0
   142
	test(TheTable.ColInt(1)==2);
sl@0
   143
	test(TheTable.NextL());
sl@0
   144
	TheTable.GetL();
sl@0
   145
	test(TheTable.ColInt(1)==1);
sl@0
   146
	test(!TheTable.NextL());
sl@0
   147
 	test(TheTable.SetNoIndex()==KErrNone);
sl@0
   148
	test(TheTable.CountL()==2);
sl@0
   149
	test(TheTable.NextL());
sl@0
   150
	test(TheTable.NextL());
sl@0
   151
	test(!TheTable.NextL());
sl@0
   152
	TheTable.Close();
sl@0
   153
	test.Next(_L("Drop indices"));
sl@0
   154
	test(TheDatabase.DropIndex(KIndexTwo,KTableName)==KErrNone);
sl@0
   155
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   156
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   157
	test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
sl@0
   158
	TheTable.Close();
sl@0
   159
	test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
sl@0
   160
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   161
	test(TheTable.SetIndex(KIndexName)!=KErrNone);
sl@0
   162
	test(TheTable.SetIndex(KIndexTwo)!=KErrNone);
sl@0
   163
	TheTable.Close();
sl@0
   164
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   165
	test.End();
sl@0
   166
	}
sl@0
   167
sl@0
   168
LOCAL_C TInt CountRowsL()
sl@0
   169
	{
sl@0
   170
	TInt count=0;
sl@0
   171
	while (TheTable.NextL())
sl@0
   172
		++count;
sl@0
   173
	return count;
sl@0
   174
	}
sl@0
   175
sl@0
   176
/**
sl@0
   177
@SYMTestCaseID          SYSLIB-DBMS-CT-0619
sl@0
   178
@SYMTestCaseDesc        RDbNamedDatabase::Execute() function test
sl@0
   179
@SYMTestPriority        Medium
sl@0
   180
@SYMTestActions         Tests for CREATE TABLE,CREATE INDEX and CREATE UNIQUE INDEX query
sl@0
   181
@SYMTestExpectedResults Test must not fail
sl@0
   182
@SYMREQ                 REQ0000
sl@0
   183
*/
sl@0
   184
LOCAL_C void TestPersistenceL()
sl@0
   185
	{
sl@0
   186
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0619 Create table "));
sl@0
   187
	TheDatabase.Begin();
sl@0
   188
	test(TheDatabase.Execute(_L("CREATE TABLE Table (column CHAR(120) NOT NULL)"))==KErrNone);
sl@0
   189
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   190
	TheTable.InsertL();
sl@0
   191
	TheTable.SetColL(1,_L("a"));
sl@0
   192
	TheTable.PutL();
sl@0
   193
	TheTable.InsertL();
sl@0
   194
	TheTable.SetColL(1,_L("b"));
sl@0
   195
	TheTable.PutL();
sl@0
   196
	TheTable.InsertL();
sl@0
   197
	TheTable.SetColL(1,_L("c"));
sl@0
   198
	TheTable.PutL();
sl@0
   199
	TheTable.InsertL();
sl@0
   200
	TheTable.SetColL(1,_L("d"));
sl@0
   201
	TheTable.PutL();
sl@0
   202
	TheTable.InsertL();
sl@0
   203
	TheTable.SetColL(1,_L("e"));
sl@0
   204
	TheTable.PutL();
sl@0
   205
	TheTable.Close();
sl@0
   206
	test(TheDatabase.Commit()==KErrNone);
sl@0
   207
	test.Next(_L("Build indices"));
sl@0
   208
	test (TheDatabase.Execute(_L("CREATE INDEX index ON table (column ASC)"))==KErrNone);
sl@0
   209
	test (TheDatabase.Execute(_L("CREATE UNIQUE INDEX index_two ON table (column DESC)"))==KErrNone);
sl@0
   210
	test.Next(_L("Close and re-open database"));
sl@0
   211
	CloseDatabase();
sl@0
   212
	OpenDatabase();
sl@0
   213
	test.Next(_L("Check indices"));
sl@0
   214
	CDbKey* key=TheDatabase.KeyL(KIndexName,KTableName);
sl@0
   215
	test (key->Count()==1);
sl@0
   216
	test (key->Comparison()==EDbCompareNormal);
sl@0
   217
	test (!key->IsUnique());
sl@0
   218
	test ((*key)[0].iName.CompareF(KColumnName)==0);
sl@0
   219
	test ((*key)[0].iOrder==TDbKeyCol::EAsc);
sl@0
   220
	delete key;
sl@0
   221
	key=TheDatabase.KeyL(KIndexTwo,KTableName);
sl@0
   222
	test (key->Count()==1);
sl@0
   223
	test (key->Comparison()==EDbCompareNormal);
sl@0
   224
	test (key->IsUnique());
sl@0
   225
	test ((*key)[0].iName.CompareF(KColumnName)==0);
sl@0
   226
	test ((*key)[0].iOrder==TDbKeyCol::EDesc);
sl@0
   227
	delete key;
sl@0
   228
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   229
	test(TheTable.SetNoIndex()==KErrNone);
sl@0
   230
	test(CountRowsL()==5);
sl@0
   231
	test(TheTable.CountL()==5);
sl@0
   232
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   233
	test(TheTable.CountL()==5);
sl@0
   234
	test(CountRowsL()==5);
sl@0
   235
	test(TheTable.SetIndex(KIndexTwo)==KErrNone);
sl@0
   236
	test(TheTable.CountL()==5);
sl@0
   237
	test(CountRowsL()==5);
sl@0
   238
	TheTable.Close();
sl@0
   239
	test.Next(_L("Drop indices"));
sl@0
   240
	TheDatabase.Begin();
sl@0
   241
	test (TheDatabase.Execute(_L("DROP INDEX index_two FROM table"))==KErrNone);
sl@0
   242
	test (TheDatabase.Execute(_L("DROP INDEX index FROM table"))==KErrNone);
sl@0
   243
	test (TheDatabase.Execute(_L("DROP TABLE table"))==KErrNone);
sl@0
   244
	test(TheDatabase.Commit()==KErrNone);
sl@0
   245
	test.End();
sl@0
   246
	}
sl@0
   247
sl@0
   248
LOCAL_C void BuildTablePrologL(TDbColType aType,TInt aAttribs=0)
sl@0
   249
	{
sl@0
   250
	TheDatabase.Begin();
sl@0
   251
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   252
	TDbCol col(KColumnName,aType);
sl@0
   253
	col.iAttributes=aAttribs;
sl@0
   254
	cs->AddL(col);
sl@0
   255
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
   256
	CleanupStack::PopAndDestroy();
sl@0
   257
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   258
	}
sl@0
   259
sl@0
   260
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt& aValue)
sl@0
   261
	{aSet.SetColL(col,aValue);}
sl@0
   262
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TUint& aValue)
sl@0
   263
	{aSet.SetColL(col,aValue);}
sl@0
   264
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TInt64& aValue)
sl@0
   265
	{aSet.SetColL(col,aValue);}
sl@0
   266
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal32& aValue)
sl@0
   267
	{aSet.SetColL(col,aValue);}
sl@0
   268
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TReal64& aValue)
sl@0
   269
	{aSet.SetColL(col,aValue);}
sl@0
   270
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TTime& aValue)
sl@0
   271
	{aSet.SetColL(col,aValue);}
sl@0
   272
inline void SetColL(RDbRowSet& aSet,TDbColNo col,const TPtrC& aValue)
sl@0
   273
	{aSet.SetColL(col,aValue);}
sl@0
   274
sl@0
   275
template <class T>
sl@0
   276
void BuildTableL(TDbColType aType,TInt aAttribs,T aValues[],TInt aCount)
sl@0
   277
	{
sl@0
   278
	BuildTablePrologL(aType,aAttribs);
sl@0
   279
	for (TInt ii=0;ii<aCount;++ii)
sl@0
   280
		{
sl@0
   281
		TheTable.InsertL();
sl@0
   282
		SetColL(TheTable,1,aValues[ii]);
sl@0
   283
		TheTable.PutL();
sl@0
   284
		}
sl@0
   285
	test(TheDatabase.Commit()==KErrNone);
sl@0
   286
	test (TheTable.CountL()==aCount);
sl@0
   287
	TheTable.Close();
sl@0
   288
	}
sl@0
   289
sl@0
   290
/**
sl@0
   291
@SYMTestCaseID          SYSLIB-DBMS-CT-0620
sl@0
   292
@SYMTestCaseDesc        Setting the specified index as the active index for a table test
sl@0
   293
@SYMTestPriority        Medium
sl@0
   294
@SYMTestActions         Create an index and set as active index for the table.
sl@0
   295
                        Tests for RDbNamedDatabase::CreateIndex(),RDbNamedDatabase::Commit()
sl@0
   296
						RDbTable::Open(),RDbTable::SetIndex() functions.
sl@0
   297
@SYMTestExpectedResults Test must not fail
sl@0
   298
@SYMREQ                 REQ0000
sl@0
   299
*/
sl@0
   300
LOCAL_C void BuildIndexL(TDbTextComparison aComparison=EDbCompareNormal,TInt aLength=KDbUndefinedLength)
sl@0
   301
	{
sl@0
   302
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0620 Test index order "));
sl@0
   303
	TheDatabase.Begin();
sl@0
   304
	CDbKey *key=CDbKey::NewLC();
sl@0
   305
	key->AddL(TDbKeyCol(KColumnName,aLength));
sl@0
   306
	key->MakeUnique();
sl@0
   307
	key->SetComparison(aComparison);
sl@0
   308
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
   309
	CleanupStack::PopAndDestroy();
sl@0
   310
	test (TheDatabase.Commit()==KErrNone);
sl@0
   311
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   312
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   313
	}
sl@0
   314
sl@0
   315
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt& aValue)
sl@0
   316
	{aValue=aSet.ColInt(col);}
sl@0
   317
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TUint& aValue)
sl@0
   318
	{aValue=aSet.ColUint(col);}
sl@0
   319
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TInt64& aValue)
sl@0
   320
	{aValue=aSet.ColInt64(col);}
sl@0
   321
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal32& aValue)
sl@0
   322
	{aValue=aSet.ColReal32(col);}
sl@0
   323
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TReal64& aValue)
sl@0
   324
	{aValue=aSet.ColReal64(col);}
sl@0
   325
inline void GetCol(RDbRowSet& aSet,TDbColNo col,TTime& aValue)
sl@0
   326
	{aValue=aSet.ColTime(col);}
sl@0
   327
sl@0
   328
/**
sl@0
   329
@SYMTestCaseID          SYSLIB-DBMS-CT-0621
sl@0
   330
@SYMTestCaseDesc        RDbRowSet ordering test
sl@0
   331
@SYMTestPriority        Medium
sl@0
   332
@SYMTestActions         Reorder the row set data with RDbRowSet::GetL(),SetL() functions.
sl@0
   333
@SYMTestExpectedResults Test must not fail
sl@0
   334
@SYMREQ                 REQ0000
sl@0
   335
*/
sl@0
   336
template <class T>
sl@0
   337
void TestOrderingL(RDbRowSet& aSet,T,TInt aCount)
sl@0
   338
	{
sl@0
   339
	test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0621 " ) );
sl@0
   340
	test(aSet.CountL()==aCount);
sl@0
   341
	TInt count=0;
sl@0
   342
	if (aSet.FirstL())
sl@0
   343
		{
sl@0
   344
		++count;
sl@0
   345
		aSet.GetL();
sl@0
   346
		T last;
sl@0
   347
		GetCol(aSet,1,last);
sl@0
   348
		while (aSet.NextL())
sl@0
   349
			{
sl@0
   350
			++count;
sl@0
   351
			aSet.GetL();
sl@0
   352
			T current;
sl@0
   353
			GetCol(aSet,1,current);
sl@0
   354
			test(last<current);
sl@0
   355
			last=current;
sl@0
   356
			}
sl@0
   357
		}
sl@0
   358
	test(count==aCount);
sl@0
   359
	}
sl@0
   360
sl@0
   361
/**
sl@0
   362
@SYMTestCaseID          SYSLIB-DBMS-CT-0622
sl@0
   363
@SYMTestCaseDesc        RDbTable::SeekL() function test
sl@0
   364
@SYMTestPriority        Medium
sl@0
   365
@SYMTestActions         Tests for the retrieved column value
sl@0
   366
@SYMTestExpectedResults Test must not fail
sl@0
   367
@SYMREQ                 REQ0000
sl@0
   368
*/
sl@0
   369
template <class T>
sl@0
   370
void TestSeekL(RDbTable& aTable,T,const T aValues[],TInt aCount)
sl@0
   371
	{
sl@0
   372
	test.Next( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0622 Test index seeking " ) );
sl@0
   373
	for (TInt ii=0;ii<aCount;++ii)
sl@0
   374
		{
sl@0
   375
		test(aTable.SeekL(aValues[ii]));
sl@0
   376
		aTable.GetL();
sl@0
   377
		T val;
sl@0
   378
		GetCol(aTable,1,val);
sl@0
   379
		test(aValues[ii]==val);
sl@0
   380
		}
sl@0
   381
	}
sl@0
   382
sl@0
   383
/**
sl@0
   384
aVal argument is used in the test functions (TestType & TestOrdering) and has no meaning outside them.
sl@0
   385
It is used only to avoid some compiler varnings and to determine the correct template type
sl@0
   386
sl@0
   387
@SYMTestCaseID          SYSLIB-DBMS-CT-0623
sl@0
   388
@SYMTestCaseDesc        Tests for RDbTable,RDbRowSet classes
sl@0
   389
@SYMTestPriority        Medium
sl@0
   390
@SYMTestActions         Call up Test for table ordering and index seeking functions
sl@0
   391
@SYMTestExpectedResults Test must not fail
sl@0
   392
@SYMREQ                 REQ0000
sl@0
   393
*/
sl@0
   394
template <class T>
sl@0
   395
void TestTypeL( TDbColType aType, TInt aAttribs, const T aValues[], TInt aCount )
sl@0
   396
	{
sl@0
   397
	test.Start( _L( " @SYMTestCaseID:SYSLIB-DBMS-CT-0623 Build table " ) );
sl@0
   398
	BuildTableL( aType, aAttribs, aValues, aCount );
sl@0
   399
	T t(0);
sl@0
   400
//
sl@0
   401
	test.Next( _L( "Test ORDER BY ordering" ) );
sl@0
   402
	test( TheView.Prepare( TheDatabase, KSelectOrdered ) == KErrNone );
sl@0
   403
	test( TheView.EvaluateAll() == KErrNone );
sl@0
   404
	TestOrderingL( TheView, t, aCount );
sl@0
   405
	TheView.Close();
sl@0
   406
//
sl@0
   407
	BuildIndexL();
sl@0
   408
	TestOrderingL( TheTable, t, aCount );
sl@0
   409
//
sl@0
   410
	TestSeekL( TheTable, t, aValues, aCount );
sl@0
   411
	TheTable.Close();
sl@0
   412
//
sl@0
   413
	test( TheDatabase.DropTable( KTableName ) == KErrNone );
sl@0
   414
	test.End();
sl@0
   415
	}
sl@0
   416
/**
sl@0
   417
@SYMTestCaseID          SYSLIB-DBMS-CT-1322
sl@0
   418
@SYMTestCaseDesc        Text ordering test
sl@0
   419
@SYMTestPriority        Medium
sl@0
   420
@SYMTestActions         Tests for RDbRowSet::Next(),RDbRowSet::GetL(),RDbRowSet::ColDes() functions
sl@0
   421
@SYMTestExpectedResults Test must not fail
sl@0
   422
@SYMREQ                 REQ0000
sl@0
   423
*/
sl@0
   424
void TestTextOrderingL(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
sl@0
   425
	{
sl@0
   426
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1322 "));
sl@0
   427
	test(aSet.CountL()==aCount);
sl@0
   428
	TInt count=0;
sl@0
   429
	while (aSet.NextL())
sl@0
   430
		{
sl@0
   431
		aSet.GetL();
sl@0
   432
		TPtrC current=aSet.ColDes(1);
sl@0
   433
		if (count++>0)
sl@0
   434
			test(aComp.Compare(TheBuf,current)<0);
sl@0
   435
		TheBuf=current;
sl@0
   436
		}
sl@0
   437
	test(count==aCount);
sl@0
   438
	}
sl@0
   439
sl@0
   440
/**
sl@0
   441
@SYMTestCaseID          SYSLIB-DBMS-CT-1323
sl@0
   442
@SYMTestCaseDesc        Tests for RDbView,RDbTable classes
sl@0
   443
@SYMTestPriority        Medium
sl@0
   444
@SYMTestActions         Wrapper function to call up for text ordering and text indexing tests
sl@0
   445
@SYMTestExpectedResults Test must not fail
sl@0
   446
@SYMREQ                 REQ0000
sl@0
   447
*/
sl@0
   448
void TestTextL(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
sl@0
   449
	{
sl@0
   450
	const TTextOps& comp=TTextOps::Ops(aComparison);
sl@0
   451
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1323 Build table "));
sl@0
   452
	BuildTableL(EDbColText,0,aValues,aCount);
sl@0
   453
//
sl@0
   454
	test.Next(_L("Test ORDER BY ordering"));
sl@0
   455
	test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
sl@0
   456
	test (TheView.EvaluateAll()==KErrNone);
sl@0
   457
	TestTextOrderingL(TheView,aCount,comp);
sl@0
   458
	TheView.Close();
sl@0
   459
//
sl@0
   460
	BuildIndexL(aComparison,aLength);
sl@0
   461
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   462
	TestTextOrderingL(TheTable,aCount,comp);
sl@0
   463
//
sl@0
   464
	test.Next(_L("Test index seeking"));
sl@0
   465
	for (TInt ii=0;ii<aCount;++ii)
sl@0
   466
		{
sl@0
   467
		test(TheTable.SeekL(aValues[ii]));
sl@0
   468
		TheTable.GetL();
sl@0
   469
		test(comp.Compare(aValues[ii],TheTable.ColDes(1))==0);
sl@0
   470
		}
sl@0
   471
//
sl@0
   472
	TheTable.Close();
sl@0
   473
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   474
	test.End();
sl@0
   475
	}
sl@0
   476
sl@0
   477
void TestLongTextOrderingL(RDbRowSet& aSet,TInt aCount,const TTextOps& aComp)
sl@0
   478
	{
sl@0
   479
	test(aSet.CountL()==aCount);
sl@0
   480
	TInt count=0;
sl@0
   481
	HBufC* prev=0;
sl@0
   482
	while (aSet.NextL())
sl@0
   483
		{
sl@0
   484
		aSet.GetL();
sl@0
   485
		TInt len=aSet.ColLength(1);
sl@0
   486
		HBufC* buf=HBufC::NewL(len);
sl@0
   487
		RDbColReadStream s;
sl@0
   488
		s.OpenLC(aSet,1);
sl@0
   489
		TPtr des(buf->Des());
sl@0
   490
		s.ReadL(des,len);
sl@0
   491
		CleanupStack::PopAndDestroy();
sl@0
   492
		if (count++)
sl@0
   493
			test (aComp.Compare(*buf,*prev)>=0);
sl@0
   494
		delete prev;
sl@0
   495
		prev=buf;
sl@0
   496
		}
sl@0
   497
	delete prev;
sl@0
   498
	test(count==aCount);
sl@0
   499
	}
sl@0
   500
sl@0
   501
LOCAL_C void OrderByLongTextL(TInt aCount,TDbTextComparison aComparison)
sl@0
   502
	{
sl@0
   503
	test (TheView.Prepare(TheDatabase,TDbQuery(KSelectOrdered,aComparison))==KErrNone);
sl@0
   504
	test (TheView.EvaluateAll()==KErrNone);
sl@0
   505
	TestLongTextOrderingL(TheView,aCount,TTextOps::Ops(aComparison));
sl@0
   506
	TheView.Close();
sl@0
   507
	}
sl@0
   508
sl@0
   509
LOCAL_C void TestLongTextL(const TPtrC aValues[],TInt aCount,TDbTextComparison aComparison,TInt aLength=KDbUndefinedLength)
sl@0
   510
	{
sl@0
   511
	const TTextOps& comp=TTextOps::Ops(aComparison);
sl@0
   512
	test.Start(_L("Build table"));
sl@0
   513
	BuildTableL(EDbColLongText,0,aValues,aCount);
sl@0
   514
//
sl@0
   515
	test.Next(_L("Test ORDER BY ordering"));
sl@0
   516
	OrderByLongTextL(aCount,aComparison);
sl@0
   517
//
sl@0
   518
	BuildIndexL(aComparison,aLength);
sl@0
   519
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   520
	TestLongTextOrderingL(TheTable,aCount,comp);
sl@0
   521
//
sl@0
   522
	test.Next(_L("Test index seeking"));
sl@0
   523
	for (TInt ii=0;ii<aCount;++ii)
sl@0
   524
		{
sl@0
   525
		test(TheTable.SeekL(aValues[ii]));
sl@0
   526
		TheTable.GetL();
sl@0
   527
		RDbColReadStream strm;
sl@0
   528
		strm.OpenLC(TheTable,1);
sl@0
   529
		strm.ReadL(TheBuf,TheTable.ColLength(1));
sl@0
   530
		CleanupStack::PopAndDestroy();
sl@0
   531
		test(comp.Compare(aValues[ii],TheBuf)==0);
sl@0
   532
		}
sl@0
   533
	TheTable.Close();
sl@0
   534
//
sl@0
   535
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   536
	test.End();
sl@0
   537
	}
sl@0
   538
sl@0
   539
TUint const KBitValues[]={0,1};
sl@0
   540
TInt const KInt8Values[]={0,KMinTInt8+1,1,KMaxTInt8,2,-3,-1,KMaxTInt8-1,KMinTInt8,-40};
sl@0
   541
TInt const KInt16Values[]={0,KMinTInt16+1,1,KMaxTInt16,2,-3,-1,KMaxTInt16-1,KMinTInt16,-4000};
sl@0
   542
TInt const KInt32Values[]={0,KMinTInt32+1,1,KMaxTInt32,2,-3,-1,KMaxTInt32-1,KMinTInt32,-40000000};
sl@0
   543
TInt const KInt32Count=sizeof(KInt32Values)/sizeof(KInt32Values[0]);
sl@0
   544
TUint const KUint8Values[]={0,1,KMaxTUint8,2,(KMaxTUint8+1)/2,(KMaxTUint8-1)/2,KMaxTUint8-1,40};
sl@0
   545
TUint const KUint16Values[]={0,1,KMaxTUint16,2,(KMaxTUint16+1)/2,(KMaxTUint16-1)/2,KMaxTUint16-1,4000};
sl@0
   546
TUint const KUint32Values[]={0,1,KMaxTUint32,2,KMaxTUint32/2+1,KMaxTUint32/2,KMaxTUint32-1,40000000};
sl@0
   547
//TReal32 const KReal32Values[]={0.0f,1.0f,KMaxTReal32,KMinTReal32,-1.0f,-KMaxTReal32,-4e20f,-KMinTReal32};
sl@0
   548
//TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
sl@0
   549
TReal32 const KReal32Values[]={0.0f,1.0f,1e37f,1e-37f,-1.0f,-1e37f,-4e20f,-1e-37f};
sl@0
   550
TReal64 const KReal64Values[]={0.0,1.0,KMaxTReal64,KMinTReal64,-1.0,-KMaxTReal64,-4e200,-KMinTReal64};
sl@0
   551
TInt64 const KInt64Values[]=
sl@0
   552
	{
sl@0
   553
	0,
sl@0
   554
	MAKE_TINT64(0x80000000u,0x1u),
sl@0
   555
	1,
sl@0
   556
	MAKE_TINT64(0x7fffffffu,0xffffffffu),
sl@0
   557
	2,
sl@0
   558
	-3,
sl@0
   559
	-1,
sl@0
   560
	MAKE_TINT64(0x7fffffffu,0xfffffffeu),
sl@0
   561
	MAKE_TINT64(0x80000000u,0x0u),
sl@0
   562
	-40
sl@0
   563
	};
sl@0
   564
TTime const KTimeValues[]=
sl@0
   565
	{
sl@0
   566
	Time::MaxTTime(),
sl@0
   567
	TInt64(0),
sl@0
   568
	TDateTime(1970,EJanuary,0,0,0,0,0),
sl@0
   569
	Time::MinTTime(),
sl@0
   570
	TDateTime(2049,EDecember,30,23,59,59,999999),
sl@0
   571
	TDateTime(1996,EJuly,8,17,45,0,0)
sl@0
   572
	};
sl@0
   573
TPtrC const KTextValues[]=
sl@0
   574
	{
sl@0
   575
	_S(""),
sl@0
   576
	_S("10"),
sl@0
   577
	_S("zyx"),
sl@0
   578
	_S("0"),
sl@0
   579
	_S("abcd"),
sl@0
   580
	_S("abcdefg"),
sl@0
   581
	_S("ABCDE"),
sl@0
   582
	_S("Z")
sl@0
   583
	};
sl@0
   584
TPtrC const KLongTextValues[]=
sl@0
   585
	{
sl@0
   586
	_S("this blob will be inlined"),
sl@0
   587
	_S(""),
sl@0
   588
	_S("that blob was null"),
sl@0
   589
	_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")
sl@0
   590
	};
sl@0
   591
const TInt KLongTextLimit=30;
sl@0
   592
sl@0
   593
/**
sl@0
   594
@SYMTestCaseID          SYSLIB-DBMS-CT-0624
sl@0
   595
@SYMTestCaseDesc        Wrapper function testing for Indexing with different integer sizes and Text .
sl@0
   596
@SYMTestPriority        Medium
sl@0
   597
@SYMTestActions         Tests for indexing
sl@0
   598
@SYMTestExpectedResults Test must not fail
sl@0
   599
@SYMREQ                 REQ0000
sl@0
   600
*/
sl@0
   601
LOCAL_C void TestTypesL()
sl@0
   602
	{
sl@0
   603
	#define ARRAY_SIZE(a) TInt(sizeof(a)/sizeof(a[0]))
sl@0
   604
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0624 Indexing Bit "));
sl@0
   605
	TestTypeL(EDbColBit,TDbCol::ENotNull,KBitValues,ARRAY_SIZE(KBitValues));
sl@0
   606
	test.Next(_L("Indexing Int8"));
sl@0
   607
	TestTypeL(EDbColInt8,TDbCol::ENotNull,KInt8Values,ARRAY_SIZE(KInt8Values));
sl@0
   608
	test.Next(_L("Indexing Int16"));
sl@0
   609
	TestTypeL(EDbColInt16,TDbCol::ENotNull,KInt16Values,ARRAY_SIZE(KInt16Values));
sl@0
   610
	test.Next(_L("Indexing Int32"));
sl@0
   611
	TestTypeL(EDbColInt32,TDbCol::ENotNull,KInt32Values,ARRAY_SIZE(KInt32Values));
sl@0
   612
	test.Next(_L("Indexing Uint8"));
sl@0
   613
	TestTypeL(EDbColUint8,TDbCol::ENotNull,KUint8Values,ARRAY_SIZE(KUint8Values));
sl@0
   614
	test.Next(_L("Indexing Uint16"));
sl@0
   615
	TestTypeL(EDbColUint16,TDbCol::ENotNull,KUint16Values,ARRAY_SIZE(KUint16Values));
sl@0
   616
	test.Next(_L("Indexing Uint32"));
sl@0
   617
	TestTypeL(EDbColUint32,TDbCol::ENotNull,KUint32Values,ARRAY_SIZE(KUint32Values));
sl@0
   618
	test.Next(_L("Indexing Real32"));
sl@0
   619
	TestTypeL(EDbColReal32,TDbCol::ENotNull,KReal32Values,ARRAY_SIZE(KReal32Values));
sl@0
   620
	test.Next(_L("Indexing Real64"));
sl@0
   621
	TestTypeL(EDbColReal64,TDbCol::ENotNull,KReal64Values,ARRAY_SIZE(KReal64Values));
sl@0
   622
	test.Next(_L("Indexing Int64"));
sl@0
   623
	TestTypeL(EDbColInt64,TDbCol::ENotNull,KInt64Values,ARRAY_SIZE(KInt64Values));
sl@0
   624
	test.Next(_L("Indexing Time"));
sl@0
   625
	TestTypeL(EDbColDateTime,TDbCol::ENotNull,KTimeValues,ARRAY_SIZE(KTimeValues));
sl@0
   626
	test.Next(_L("Indexing Text (Normal)"));
sl@0
   627
	TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal);
sl@0
   628
	test.Next(_L("Indexing Text (Folded)"));
sl@0
   629
	TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareFolded);
sl@0
   630
	test.Next(_L("Indexing Text (Collated)"));
sl@0
   631
	TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareCollated);
sl@0
   632
	test.Next(_L("Indexing Text (Normal, truncated)"));
sl@0
   633
	TestTextL(KTextValues,ARRAY_SIZE(KTextValues),EDbCompareNormal,5);
sl@0
   634
	test.Next(_L("Indexing LongText (Normal)"));
sl@0
   635
	TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareNormal,KLongTextLimit);
sl@0
   636
	test.Next(_L("Indexing LongText (Folded)"));
sl@0
   637
	TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareFolded,KLongTextLimit);
sl@0
   638
	test.Next(_L("Indexing LongText (Collated)"));
sl@0
   639
	TestLongTextL(KLongTextValues,ARRAY_SIZE(KLongTextValues),EDbCompareCollated,KLongTextLimit);
sl@0
   640
	test.End();
sl@0
   641
	}
sl@0
   642
sl@0
   643
const TInt KBlobKeyTruncated=32/sizeof(TText);
sl@0
   644
const TInt KBlobKeyMaxInline=255/sizeof(TText);
sl@0
   645
const TInt KBlobKeyCompare=512/sizeof(TText);
sl@0
   646
sl@0
   647
const TInt KMemoTestLengths[]=
sl@0
   648
	{
sl@0
   649
	0,
sl@0
   650
	1,
sl@0
   651
	KBlobKeyTruncated-1,
sl@0
   652
	KBlobKeyTruncated,
sl@0
   653
	KBlobKeyTruncated+1,
sl@0
   654
	KBlobKeyMaxInline,
sl@0
   655
	KBlobKeyMaxInline+1,
sl@0
   656
	KBlobKeyCompare-1,
sl@0
   657
	KBlobKeyCompare,
sl@0
   658
	KBlobKeyCompare+1,
sl@0
   659
	5000
sl@0
   660
	};
sl@0
   661
sl@0
   662
void TestMemoTableL(CDbColSet& aBaseSet)
sl@0
   663
	{
sl@0
   664
	test.Start(_L("create the table"));
sl@0
   665
	aBaseSet.AddL(TDbCol(KColumnName,EDbColLongText));
sl@0
   666
	TheDatabase.Begin();
sl@0
   667
	TInt r=TheDatabase.CreateTable(KTableName,aBaseSet);
sl@0
   668
	test (r==KErrNone);
sl@0
   669
//
sl@0
   670
	test.Next(_L("add the rows"));
sl@0
   671
	r=TheView.Prepare(TheDatabase,KSelectOrdered,RDbView::EInsertOnly);
sl@0
   672
	test (r==KErrNone);
sl@0
   673
	r=TheView.EvaluateAll();
sl@0
   674
	test (r==KErrNone);
sl@0
   675
	HBufC* prev=0;
sl@0
   676
	TInt count=0;
sl@0
   677
	for (TUint ii=0;ii<elementsof(KMemoTestLengths);++ii)
sl@0
   678
		{
sl@0
   679
		TInt size=KMemoTestLengths[ii];
sl@0
   680
		HBufC* buf=HBufC::NewL(size);
sl@0
   681
		if (size>0)
sl@0
   682
			{
sl@0
   683
			TPtr des(buf->Des());
sl@0
   684
			des.Copy(*prev);
sl@0
   685
			des.AppendFill('b',size-prev->Length());
sl@0
   686
			delete prev;
sl@0
   687
			TheView.InsertL();
sl@0
   688
			TheView.SetColL(1,*buf);
sl@0
   689
			TheView.PutL();
sl@0
   690
			++count;
sl@0
   691
			des[size-1]='a';
sl@0
   692
			}
sl@0
   693
		TheView.InsertL();
sl@0
   694
		TheView.SetColL(1,*buf);
sl@0
   695
		TheView.PutL();
sl@0
   696
		++count;
sl@0
   697
		prev=buf;
sl@0
   698
		}
sl@0
   699
	delete prev;
sl@0
   700
	TheView.Close();
sl@0
   701
	r=TheDatabase.Commit();
sl@0
   702
	test (r==KErrNone);
sl@0
   703
//
sl@0
   704
	test.Next(_L("Normal order"));
sl@0
   705
	OrderByLongTextL(count,EDbCompareNormal);
sl@0
   706
	test.Next(_L("Folded order"));
sl@0
   707
	OrderByLongTextL(count,EDbCompareFolded);
sl@0
   708
	test.Next(_L("Collated order"));
sl@0
   709
	OrderByLongTextL(count,EDbCompareCollated);
sl@0
   710
//
sl@0
   711
	r=TheDatabase.DropTable(KTableName);
sl@0
   712
	test (r==KErrNone);
sl@0
   713
	test.End();
sl@0
   714
	}
sl@0
   715
sl@0
   716
/**
sl@0
   717
@SYMTestCaseID          SYSLIB-DBMS-CT-0625
sl@0
   718
@SYMTestCaseDesc        Tests for ordering by longtext
sl@0
   719
@SYMTestPriority        Medium
sl@0
   720
@SYMTestActions         Tests for CDbColSet
sl@0
   721
@SYMTestExpectedResults Test must not fail
sl@0
   722
@SYMREQ                 REQ0000
sl@0
   723
*/
sl@0
   724
LOCAL_C void TestOrderByLongTextL()
sl@0
   725
	{
sl@0
   726
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0625 Maximum Inline Limit "));
sl@0
   727
	CDbColSet* set=CDbColSet::NewLC();
sl@0
   728
	TestMemoTableL(*set);
sl@0
   729
//
sl@0
   730
	test.Next(_L("Reduced Inline limit [<32]"));
sl@0
   731
	set->Clear();
sl@0
   732
	TDbCol col;
sl@0
   733
	col.iType=EDbColText8;
sl@0
   734
	col.iMaxLength=255;
sl@0
   735
	col.iAttributes=0;
sl@0
   736
	TDbColName name;
sl@0
   737
	for (TInt ii=0;ii<32;++ii)
sl@0
   738
		{
sl@0
   739
		name.Format(_L("col%d"),ii);
sl@0
   740
		col.iName=name;
sl@0
   741
		if (ii==31)
sl@0
   742
			col.iMaxLength=255-20;
sl@0
   743
		set->AddL(col);
sl@0
   744
		}
sl@0
   745
	TestMemoTableL(*set);
sl@0
   746
	CleanupStack::PopAndDestroy();
sl@0
   747
	test.End();
sl@0
   748
	}
sl@0
   749
sl@0
   750
/**
sl@0
   751
@SYMTestCaseID          SYSLIB-DBMS-CT-0626
sl@0
   752
@SYMTestCaseDesc        Tests for reverse ordering in indexes
sl@0
   753
@SYMTestPriority        Medium
sl@0
   754
@SYMTestActions         Tests for reversing the indexes
sl@0
   755
@SYMTestExpectedResults Test must not fail
sl@0
   756
@SYMREQ                 REQ0000
sl@0
   757
*/
sl@0
   758
LOCAL_C void TestReverseL()
sl@0
   759
	{
sl@0
   760
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0626 Create table and index "));
sl@0
   761
	TheDatabase.Begin();
sl@0
   762
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   763
	cs->AddL(TDbCol(KColumnName,EDbColInt32));
sl@0
   764
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
   765
	CleanupStack::PopAndDestroy();
sl@0
   766
	CDbKey *key=CDbKey::NewLC();
sl@0
   767
	key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
sl@0
   768
	key->MakeUnique();
sl@0
   769
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
   770
	CleanupStack::PopAndDestroy();
sl@0
   771
	test(TheDatabase.Commit()==KErrNone);
sl@0
   772
	test.Next(_L("Add records"));
sl@0
   773
	TheDatabase.Begin();
sl@0
   774
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   775
	for (TInt ii=0;ii<KInt32Count;++ii)
sl@0
   776
		{
sl@0
   777
		TheTable.InsertL();
sl@0
   778
		TheTable.SetColL(1,KInt32Values[ii]);
sl@0
   779
		TheTable.PutL();
sl@0
   780
		}
sl@0
   781
	test(TheDatabase.Commit()==KErrNone);
sl@0
   782
	test(TheTable.CountL()==KInt32Count);
sl@0
   783
	test.Next(_L("Check order"));
sl@0
   784
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   785
	test(TheTable.CountL()==KInt32Count);
sl@0
   786
	TInt count=0;
sl@0
   787
	if (TheTable.FirstL())
sl@0
   788
		{
sl@0
   789
		++count;
sl@0
   790
		TheTable.GetL();
sl@0
   791
		TInt32 last=TheTable.ColInt(1);
sl@0
   792
		while (TheTable.NextL())
sl@0
   793
			{
sl@0
   794
			++count;
sl@0
   795
			TheTable.GetL();
sl@0
   796
			TInt32 current=TheTable.ColInt(1);
sl@0
   797
			test(last>current);
sl@0
   798
			last=current;
sl@0
   799
			}
sl@0
   800
		}
sl@0
   801
	test(count==KInt32Count);
sl@0
   802
	TheTable.Close();
sl@0
   803
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   804
	test.End();
sl@0
   805
	}
sl@0
   806
sl@0
   807
/**
sl@0
   808
@SYMTestCaseID          SYSLIB-DBMS-CT-0627
sl@0
   809
@SYMTestCaseDesc        Tests for multi-column keys
sl@0
   810
@SYMTestPriority        Medium
sl@0
   811
@SYMTestActions         Tests for mutliple column keys
sl@0
   812
@SYMTestExpectedResults Test must not fail
sl@0
   813
@SYMREQ                 REQ0000
sl@0
   814
*/
sl@0
   815
LOCAL_C void TestMultiL()
sl@0
   816
	{
sl@0
   817
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0627 Create table and index "));
sl@0
   818
	TheDatabase.Begin();
sl@0
   819
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   820
	TDbCol col(KColumnName,EDbColInt32);
sl@0
   821
	col.iAttributes=TDbCol::ENotNull;
sl@0
   822
	cs->AddL(col);
sl@0
   823
	col.iName=KColumnTwo;
sl@0
   824
	cs->AddL(col);
sl@0
   825
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
   826
	CleanupStack::PopAndDestroy();
sl@0
   827
	CDbKey *key=CDbKey::NewLC();
sl@0
   828
	key->AddL(TDbKeyCol(KColumnTwo));
sl@0
   829
	key->AddL(TDbKeyCol(KColumnName,TDbKeyCol::EDesc));
sl@0
   830
	key->MakeUnique();
sl@0
   831
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
   832
	CleanupStack::PopAndDestroy();
sl@0
   833
	test(TheDatabase.Commit()==KErrNone);
sl@0
   834
	test.Next(_L("Add records"));
sl@0
   835
	TheDatabase.Begin();
sl@0
   836
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   837
	for (TInt ii=0;ii<KInt32Count;++ii)
sl@0
   838
		{
sl@0
   839
		for (TInt jj=0;jj<KInt32Count;++jj)
sl@0
   840
			{
sl@0
   841
			TheTable.InsertL();
sl@0
   842
			TheTable.SetColL(1,KInt32Values[ii]);
sl@0
   843
			TheTable.SetColL(2,KInt32Values[jj]);
sl@0
   844
			TheTable.PutL();
sl@0
   845
			}
sl@0
   846
		}
sl@0
   847
	test(TheDatabase.Commit()==KErrNone);
sl@0
   848
	test.Next(_L("Check order"));
sl@0
   849
	test(TheTable.CountL()==KInt32Count*KInt32Count);
sl@0
   850
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
   851
	test(TheTable.CountL()==KInt32Count*KInt32Count);
sl@0
   852
	TInt count=0;
sl@0
   853
	if (TheTable.FirstL())
sl@0
   854
		{
sl@0
   855
		++count;
sl@0
   856
		TheTable.GetL();
sl@0
   857
		TInt32 lastOne=TheTable.ColInt(1);
sl@0
   858
		TInt32 lastTwo=TheTable.ColInt(2);
sl@0
   859
		while (TheTable.NextL())
sl@0
   860
			{
sl@0
   861
			++count;
sl@0
   862
			TheTable.GetL();
sl@0
   863
			TInt32 currentOne=TheTable.ColInt(1);
sl@0
   864
			TInt32 currentTwo=TheTable.ColInt(2);
sl@0
   865
			test(lastTwo<currentTwo||(lastTwo==currentTwo&&lastOne>currentOne));
sl@0
   866
			lastOne=currentOne;
sl@0
   867
			lastTwo=currentTwo;
sl@0
   868
			}
sl@0
   869
		}
sl@0
   870
	test(count==KInt32Count*KInt32Count);
sl@0
   871
	TheTable.Close();
sl@0
   872
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   873
	test.End();
sl@0
   874
	}
sl@0
   875
sl@0
   876
/**
sl@0
   877
@SYMTestCaseID          SYSLIB-DBMS-CT-0628
sl@0
   878
@SYMTestCaseDesc        Tests duplicates/unique constraints
sl@0
   879
@SYMTestPriority        Medium
sl@0
   880
@SYMTestActions         Tests for adding duplicate entries
sl@0
   881
@SYMTestExpectedResults Test must not fail
sl@0
   882
@SYMREQ                 REQ0000
sl@0
   883
*/
sl@0
   884
LOCAL_C void TestDuplicatesL()
sl@0
   885
	{
sl@0
   886
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0628 Create table and indices "));
sl@0
   887
	BuildTableL(EDbColInt32,TDbCol::ENotNull,KInt32Values,KInt32Count);
sl@0
   888
	BuildIndexL();
sl@0
   889
	TheTable.Close();
sl@0
   890
	CDbKey* key=CDbKey::NewLC();
sl@0
   891
	key->AddL(KColumnName);
sl@0
   892
	test(TheDatabase.CreateIndex(KIndexTwo,KTableName,*key)==KErrNone);
sl@0
   893
	CleanupStack::PopAndDestroy();
sl@0
   894
	test.Next(_L("Attempt to add/update duplicate entry"));
sl@0
   895
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   896
	TheTable.InsertL();
sl@0
   897
	TheTable.SetColL(1,0);
sl@0
   898
	TRAPD(r,TheTable.PutL());
sl@0
   899
	test(r!=KErrNone);
sl@0
   900
	TheTable.Cancel();
sl@0
   901
	TheTable.LastL();
sl@0
   902
	TheTable.UpdateL();
sl@0
   903
	TheTable.SetColL(1,0);
sl@0
   904
	TRAP(r,TheTable.PutL());
sl@0
   905
	test(r!=KErrNone);
sl@0
   906
	TheTable.Cancel();
sl@0
   907
	test.Next(_L("Remove unique index"));
sl@0
   908
	TheTable.Close();
sl@0
   909
	test(TheDatabase.DropIndex(KIndexName,KTableName)==KErrNone);
sl@0
   910
	test.Next(_L("Attempt to update/add duplicate entry"));
sl@0
   911
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   912
	TheTable.LastL();
sl@0
   913
	TheTable.UpdateL();
sl@0
   914
	TheTable.SetColL(1,0);
sl@0
   915
	TRAP(r,TheTable.PutL());
sl@0
   916
	test(r==KErrNone);
sl@0
   917
	TheTable.InsertL();
sl@0
   918
	TheTable.SetColL(1,0);
sl@0
   919
	TRAP(r,TheTable.PutL());
sl@0
   920
	test(r==KErrNone);
sl@0
   921
	test.Next(_L("Check order"));
sl@0
   922
	test(TheTable.CountL()==KInt32Count+1);
sl@0
   923
	test(TheTable.SetIndex(KIndexTwo)==KErrNone);
sl@0
   924
	test(TheTable.CountL()==KInt32Count+1);
sl@0
   925
	TInt count=0;
sl@0
   926
	if (TheTable.FirstL())
sl@0
   927
		{
sl@0
   928
		++count;
sl@0
   929
		TheTable.GetL();
sl@0
   930
		TInt32 last=TheTable.ColInt(1);
sl@0
   931
		while (TheTable.NextL())
sl@0
   932
			{
sl@0
   933
			++count;
sl@0
   934
			TheTable.GetL();
sl@0
   935
			TInt32 current=TheTable.ColInt(1);
sl@0
   936
			test(last<=current);	// duplicates present
sl@0
   937
			last=current;
sl@0
   938
			}
sl@0
   939
		}
sl@0
   940
	test(count==KInt32Count+1);
sl@0
   941
	test.Next(_L("Try to create unique index"));
sl@0
   942
	TheTable.Close();
sl@0
   943
	key=CDbKey::NewLC();
sl@0
   944
	key->AddL(KColumnName);
sl@0
   945
	key->MakeUnique();
sl@0
   946
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)!=KErrNone);
sl@0
   947
	CleanupStack::PopAndDestroy();
sl@0
   948
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
   949
	test.End();
sl@0
   950
	}
sl@0
   951
sl@0
   952
struct Pair { TInt i1,i2; };
sl@0
   953
struct TSeekingTest
sl@0
   954
	{
sl@0
   955
	Pair iSeek;
sl@0
   956
	Pair iResults[5];
sl@0
   957
	};
sl@0
   958
sl@0
   959
// seek pair: results for <,<=,=,>=,>
sl@0
   960
static TSeekingTest const SeekingTests[]=
sl@0
   961
	{
sl@0
   962
	{{0,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
sl@0
   963
	{{0,-1},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
sl@0
   964
	{{100,0},{{-1,-1},{-1,-1},{-1,-1},{100,10},{100,10}}},
sl@0
   965
	{{100,10},{{-1,-1},{100,10},{100,10},{100,10},{100,20}}},
sl@0
   966
	{{100,55},{{100,50},{100,50},{-1,-1},{100,60},{100,60}}},
sl@0
   967
	{{100,60},{{100,50},{100,60},{100,60},{100,60},{100,70}}},
sl@0
   968
	{{100,100},{{100,90},{100,100},{100,100},{100,100},{200,10}}},
sl@0
   969
	{{100,110},{{100,100},{100,100},{-1,-1},{200,10},{200,10}}},
sl@0
   970
	{{100,-1},{{-1,-1},{100,100},{100,10},{100,10},{200,10}}},
sl@0
   971
	{{500,-1},{{400,100},{500,100},{500,10},{500,10},{600,10}}},
sl@0
   972
	{{550,50},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
sl@0
   973
	{{550,-1},{{500,100},{500,100},{-1,-1},{600,10},{600,10}}},
sl@0
   974
	{{1000,0},{{900,100},{900,100},{-1,-1},{1000,10},{1000,10}}},
sl@0
   975
	{{1000,10},{{900,100},{1000,10},{1000,10},{1000,10},{1000,20}}},
sl@0
   976
	{{1000,100},{{1000,90},{1000,100},{1000,100},{1000,100},{-1,-1}}},
sl@0
   977
	{{1000,110},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
sl@0
   978
	{{1000,-1},{{900,100},{1000,100},{1000,10},{1000,10},{-1,-1}}},
sl@0
   979
	{{1100,0},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}},
sl@0
   980
	{{1100,-1},{{1000,100},{1000,100},{-1,-1},{-1,-1},{-1,-1}}}
sl@0
   981
	};
sl@0
   982
sl@0
   983
/**
sl@0
   984
@SYMTestCaseID          SYSLIB-DBMS-CT-0629
sl@0
   985
@SYMTestCaseDesc        Tests for seeking on indexes
sl@0
   986
@SYMTestPriority        Medium
sl@0
   987
@SYMTestActions         Tests for SeekL and GetL functions
sl@0
   988
@SYMTestExpectedResults Test must not fail
sl@0
   989
@SYMREQ                 REQ0000
sl@0
   990
*/
sl@0
   991
LOCAL_C void TestSeekingL()
sl@0
   992
	{
sl@0
   993
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0629 Create table and index "));
sl@0
   994
	TheDatabase.Begin();
sl@0
   995
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   996
	TDbCol col(KColumnName,EDbColInt32);
sl@0
   997
	col.iAttributes=TDbCol::ENotNull;
sl@0
   998
	cs->AddL(col);
sl@0
   999
	col.iName=KColumnTwo;
sl@0
  1000
	cs->AddL(col);
sl@0
  1001
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
  1002
	CleanupStack::PopAndDestroy();
sl@0
  1003
	CDbKey *key=CDbKey::NewLC();
sl@0
  1004
	key->AddL(KColumnName).AddL(KColumnTwo);
sl@0
  1005
	key->MakeUnique();
sl@0
  1006
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
  1007
	CleanupStack::PopAndDestroy();
sl@0
  1008
	test(TheDatabase.Commit()==KErrNone);
sl@0
  1009
	test.Next(_L("Add records"));
sl@0
  1010
	TheDatabase.Begin();
sl@0
  1011
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
  1012
	for (TInt ii=100;ii<=1000;ii+=100)
sl@0
  1013
		{
sl@0
  1014
		for (TInt jj=10;jj<=100;jj+=10)
sl@0
  1015
			{
sl@0
  1016
			TheTable.InsertL();
sl@0
  1017
			TheTable.SetColL(1,ii);
sl@0
  1018
			TheTable.SetColL(2,jj);
sl@0
  1019
			TheTable.PutL();
sl@0
  1020
			}
sl@0
  1021
		}
sl@0
  1022
	test(TheDatabase.Commit()==KErrNone);
sl@0
  1023
	test(TheTable.CountL()==100);
sl@0
  1024
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
  1025
	test(TheTable.CountL()==100);
sl@0
  1026
	test.Next(_L("Seeking"));
sl@0
  1027
	const TSeekingTest* stest=SeekingTests;
sl@0
  1028
	const TSeekingTest* const end=stest+sizeof(SeekingTests)/sizeof(SeekingTests[0])-1;
sl@0
  1029
	for (;stest<=end;++stest)
sl@0
  1030
		{
sl@0
  1031
		TDbSeekMultiKey<2> key;
sl@0
  1032
		key.Add(stest->iSeek.i1);
sl@0
  1033
		if (stest->iSeek.i2>=0)
sl@0
  1034
			key.Add(stest->iSeek.i2);
sl@0
  1035
		const Pair* results=stest->iResults;
sl@0
  1036
		for (TInt ii=RDbTable::ELessThan;ii<=RDbTable::EGreaterThan;++results,++ii)
sl@0
  1037
			{
sl@0
  1038
			if (TheTable.SeekL(key,RDbTable::TComparison(ii)))
sl@0
  1039
				{
sl@0
  1040
				test(results->i1>=0);
sl@0
  1041
				TRAPD(errCode, TheTable.GetL());
sl@0
  1042
				test(errCode==KErrNone);
sl@0
  1043
				test(TheTable.ColInt(1)==results->i1);
sl@0
  1044
				test(TheTable.ColInt(2)==results->i2);
sl@0
  1045
				}
sl@0
  1046
			else
sl@0
  1047
				test(results->i1<0);
sl@0
  1048
			}
sl@0
  1049
		}
sl@0
  1050
	TheTable.Close();
sl@0
  1051
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
  1052
	test.End();
sl@0
  1053
	}
sl@0
  1054
sl@0
  1055
/**
sl@0
  1056
@SYMTestCaseID          SYSLIB-DBMS-CT-0630
sl@0
  1057
@SYMTestCaseDesc        Tests for defect,index creation and set index operations
sl@0
  1058
@SYMTestPriority        Medium
sl@0
  1059
@SYMTestActions         Tests for creating and setting index operations
sl@0
  1060
@SYMTestExpectedResults Test must not fail
sl@0
  1061
@SYMREQ                 REQ0000
sl@0
  1062
*/
sl@0
  1063
LOCAL_C void TestInequalityErrorL()
sl@0
  1064
	{
sl@0
  1065
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0630 Create table "));
sl@0
  1066
	TheDatabase.Begin();
sl@0
  1067
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
  1068
	cs->AddL(TDbCol(KColumnName,EDbColInt32));
sl@0
  1069
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
  1070
	CleanupStack::PopAndDestroy();
sl@0
  1071
//
sl@0
  1072
	test.Next(_L("create indices"));
sl@0
  1073
	CDbKey *key=CDbKey::NewLC();
sl@0
  1074
	key->AddL(TDbKeyCol(KColumnName));
sl@0
  1075
	test(TheDatabase.CreateIndex(KIndexName,KTableName,*key)==KErrNone);
sl@0
  1076
	CleanupStack::PopAndDestroy();
sl@0
  1077
//
sl@0
  1078
	test.Next(_L("Populate table"));
sl@0
  1079
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
  1080
	for(TInt ii=0; ii<=130;++ii)
sl@0
  1081
		{
sl@0
  1082
		TheTable.InsertL();
sl@0
  1083
		TheTable.SetColL(1,ii);
sl@0
  1084
		TheTable.PutL();
sl@0
  1085
		}
sl@0
  1086
//
sl@0
  1087
	test.Next(_L("Checks"));
sl@0
  1088
	test(TheTable.SetIndex(KIndexName)==KErrNone);
sl@0
  1089
//
sl@0
  1090
// We need to delete a row in this node to get to the correct inequality condition
sl@0
  1091
	test.Next(_L("Delete row 90"));
sl@0
  1092
	test(TheTable.SeekL(TDbSeekKey(90)));
sl@0
  1093
	TheTable.GetL();
sl@0
  1094
	TheTable.DeleteL();
sl@0
  1095
// Now delete last row on node which should be 94
sl@0
  1096
	test.Next(_L("Delete row 94"));
sl@0
  1097
	test(TheTable.SeekL(TDbSeekKey(94)));
sl@0
  1098
	TheTable.GetL();
sl@0
  1099
	TheTable.DeleteL();
sl@0
  1100
	TheTable.EndL();
sl@0
  1101
	test(!TheTable.SeekL(TDbSeekKey(94)));
sl@0
  1102
//
sl@0
  1103
	test.Next(_L("Insert row 94"));
sl@0
  1104
	TheTable.InsertL();
sl@0
  1105
	TheTable.SetColL(1,94);
sl@0
  1106
	TheTable.PutL();
sl@0
  1107
//
sl@0
  1108
	test.Next(_L("now try and find it"));
sl@0
  1109
	test(TheTable.SeekL(TDbSeekKey(94))); //prior to defect fix this line failed.
sl@0
  1110
//
sl@0
  1111
	TheDatabase.Commit();
sl@0
  1112
	TheTable.Close();
sl@0
  1113
	test(TheDatabase.DropTable(KTableName)==KErrNone);
sl@0
  1114
	test.End();
sl@0
  1115
	}
sl@0
  1116
sl@0
  1117
/**
sl@0
  1118
@SYMTestCaseID          PDS-DBMS-CT-4006
sl@0
  1119
@SYMTestCaseDesc        Tests for add dbseekkey operations
sl@0
  1120
@SYMTestPriority        High
sl@0
  1121
@SYMTestActions         Create a DbSeekKey then add an index to it
sl@0
  1122
@SYMTestExpectedResults Verify that seeking with key works
sl@0
  1123
@SYMDEF                 DEF135710
sl@0
  1124
*/
sl@0
  1125
LOCAL_C void TestAddSeekKeyL()
sl@0
  1126
	{
sl@0
  1127
	test.Start(_L(" @SYMTestCaseID:PDS-DBMS-CT-4006 Tests for add dbseekkey operations"));
sl@0
  1128
	
sl@0
  1129
	CreateDatabase();
sl@0
  1130
	TInt err = TheDatabase.Begin();
sl@0
  1131
	test2(err, KErrNone);
sl@0
  1132
	
sl@0
  1133
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
  1134
	cs->AddL(TDbCol(KColumnName1,EDbColText8));
sl@0
  1135
	err = TheDatabase.CreateTable(KTableName1,*cs);
sl@0
  1136
	test2(err , KErrNone);
sl@0
  1137
	CleanupStack::PopAndDestroy();
sl@0
  1138
sl@0
  1139
	test.Next(_L("Create Indices"));
sl@0
  1140
	CDbKey *key=CDbKey::NewLC();
sl@0
  1141
	key->AddL(TDbKeyCol(KColumnName1));
sl@0
  1142
	err = TheDatabase.CreateIndex(KIndexName1,KTableName1,*key);
sl@0
  1143
	test2(err, KErrNone);
sl@0
  1144
	CleanupStack::PopAndDestroy();
sl@0
  1145
sl@0
  1146
	test.Next(_L("Populate Table"));
sl@0
  1147
	TBuf8<7> buf(_L8("testKey"));
sl@0
  1148
	err = TheTable.Open(TheDatabase,KTableName1);
sl@0
  1149
	test2(err, KErrNone);
sl@0
  1150
	for(TInt i = 0; i <= 10; ++i)
sl@0
  1151
		{
sl@0
  1152
		TheTable.InsertL();
sl@0
  1153
		TheTable.SetColL(1,buf);
sl@0
  1154
		TheTable.PutL();
sl@0
  1155
		}
sl@0
  1156
	
sl@0
  1157
	test.Next(_L("Set Index"));
sl@0
  1158
	err = TheTable.SetIndex(KIndexName1);
sl@0
  1159
	test2(err, KErrNone);
sl@0
  1160
sl@0
  1161
	test.Next(_L("Testing Add Function"));
sl@0
  1162
	TDbSeekKey testkey;
sl@0
  1163
	testkey.Add(buf);
sl@0
  1164
	TBool r = TheTable.SeekL(testkey);
sl@0
  1165
	test2(r, ETrue);
sl@0
  1166
	
sl@0
  1167
	err = TheDatabase.Commit();
sl@0
  1168
	test2(err, KErrNone);
sl@0
  1169
	
sl@0
  1170
	TheTable.Close();
sl@0
  1171
	test.End();
sl@0
  1172
	}
sl@0
  1173
sl@0
  1174
//
sl@0
  1175
// Test the database definition and enquiry functions
sl@0
  1176
//
sl@0
  1177
LOCAL_C void TestIndexesL()
sl@0
  1178
	{
sl@0
  1179
	test.Start(_L("Create Database"));
sl@0
  1180
	CreateDatabase();
sl@0
  1181
	test.Next(_L("Test index build and drop"));
sl@0
  1182
	TestIndexBuildL();
sl@0
  1183
	test.Next(_L("Test index persistence"));
sl@0
  1184
	TestPersistenceL();
sl@0
  1185
	test.Next(_L("Testing index key types"));
sl@0
  1186
	TestTypesL();
sl@0
  1187
	test.Next(_L("Testing LongText ORDER BY"));
sl@0
  1188
	TestOrderByLongTextL();
sl@0
  1189
	test.Next(_L("Testing reverse ordering"));
sl@0
  1190
	TestReverseL();
sl@0
  1191
	test.Next(_L("Testing multi column keys"));
sl@0
  1192
	TestMultiL();
sl@0
  1193
	test.Next(_L("Testing duplicate/unqiue"));
sl@0
  1194
	TestDuplicatesL();
sl@0
  1195
	test.Next(_L("Testing seeking"));
sl@0
  1196
	TestSeekingL();
sl@0
  1197
	test.Next(_L("Testing incorrect inequaltiy condition in store btree"));
sl@0
  1198
	TestInequalityErrorL();
sl@0
  1199
	CloseDatabase();
sl@0
  1200
	test.End();
sl@0
  1201
	}
sl@0
  1202
sl@0
  1203
//
sl@0
  1204
// Prepare the test directory.
sl@0
  1205
//
sl@0
  1206
LOCAL_C void setupTestDirectory()
sl@0
  1207
    {
sl@0
  1208
	TInt r=TheFs.Connect();
sl@0
  1209
	test(r==KErrNone);
sl@0
  1210
//
sl@0
  1211
	r=TheFs.MkDir(KTestDatabase);
sl@0
  1212
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
  1213
	}
sl@0
  1214
sl@0
  1215
//
sl@0
  1216
// Initialise the cleanup stack.
sl@0
  1217
//
sl@0
  1218
LOCAL_C void setupCleanup()
sl@0
  1219
    {
sl@0
  1220
	TheTrapCleanup=CTrapCleanup::New();
sl@0
  1221
	test(TheTrapCleanup!=NULL);
sl@0
  1222
	TRAPD(r,\
sl@0
  1223
		{\
sl@0
  1224
		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0
  1225
			CleanupStack::PushL((TAny*)0);\
sl@0
  1226
		CleanupStack::Pop(KTestCleanupStack);\
sl@0
  1227
		});
sl@0
  1228
	test(r==KErrNone);
sl@0
  1229
	}
sl@0
  1230
sl@0
  1231
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
  1232
	{
sl@0
  1233
	RFs fsSession;
sl@0
  1234
	TInt err = fsSession.Connect();
sl@0
  1235
	if(err == KErrNone)
sl@0
  1236
		{
sl@0
  1237
		TEntry entry;
sl@0
  1238
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
  1239
			{
sl@0
  1240
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
  1241
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
  1242
			if(err != KErrNone)
sl@0
  1243
				{
sl@0
  1244
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
  1245
				}
sl@0
  1246
			err = fsSession.Delete(aFullName);
sl@0
  1247
			if(err != KErrNone)
sl@0
  1248
				{
sl@0
  1249
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
  1250
				}
sl@0
  1251
			}
sl@0
  1252
		fsSession.Close();
sl@0
  1253
		}
sl@0
  1254
	else
sl@0
  1255
		{
sl@0
  1256
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
  1257
		}
sl@0
  1258
	}
sl@0
  1259
sl@0
  1260
//
sl@0
  1261
// Test streaming conversions.
sl@0
  1262
//
sl@0
  1263
GLDEF_C TInt E32Main()
sl@0
  1264
    {
sl@0
  1265
	test.Title();
sl@0
  1266
	setupTestDirectory();
sl@0
  1267
	setupCleanup();
sl@0
  1268
	__UHEAP_MARK;
sl@0
  1269
//
sl@0
  1270
	TInt r=TheDbs.Connect();
sl@0
  1271
	test (r==KErrNone);
sl@0
  1272
	TheDbs.ResourceMark();
sl@0
  1273
	test.Start(_L("Standard database"));
sl@0
  1274
	TRAP(r,TestIndexesL();)
sl@0
  1275
	test(r==KErrNone);
sl@0
  1276
	test.Next(_L("Secure database"));
sl@0
  1277
	TRAP(r,TestIndexesL();)
sl@0
  1278
	test(r==KErrNone);
sl@0
  1279
	TRAP(r, TestAddSeekKeyL());
sl@0
  1280
	test(r==KErrNone);
sl@0
  1281
	CloseDatabase();
sl@0
  1282
sl@0
  1283
	::DeleteDataFile(KTestDatabase);	//deletion of data files must be before call to end - DEF047652
sl@0
  1284
sl@0
  1285
	test.End();
sl@0
  1286
	TheDbs.ResourceCheck();
sl@0
  1287
	TheDbs.Close();
sl@0
  1288
sl@0
  1289
	__UHEAP_MARKEND;
sl@0
  1290
	delete TheTrapCleanup;
sl@0
  1291
sl@0
  1292
	TheFs.Close();
sl@0
  1293
	test.Close();
sl@0
  1294
	return 0;
sl@0
  1295
    }