os/persistentdata/persistentstorage/dbms/tdbms/t_dbbig.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// MSVC++ up to 5.0 has problems with expanding inline functions
sl@0
    17
// This disables the mad warnings for the whole project
sl@0
    18
#if defined(NDEBUG) && defined(__VC32__) && _MSC_VER<=1100
sl@0
    19
#pragma warning(disable : 4710)			// function not expanded. MSVC 5.0 is stupid
sl@0
    20
#endif
sl@0
    21
sl@0
    22
#include <d32dbms.h>
sl@0
    23
#include <s32file.h>
sl@0
    24
#include <e32test.h>
sl@0
    25
#include <e32math.h>
sl@0
    26
#include <hal.h>
sl@0
    27
sl@0
    28
class TTimer
sl@0
    29
	{
sl@0
    30
public:
sl@0
    31
	void Start(const TDesC& aDes);
sl@0
    32
	void Stop();
sl@0
    33
private:
sl@0
    34
	TUint iTicks;
sl@0
    35
	};
sl@0
    36
sl@0
    37
LOCAL_D RTest test(_L("t_dbbig - Test Large DBMS objects"));
sl@0
    38
LOCAL_D CTrapCleanup* TheTrapCleanup;
sl@0
    39
LOCAL_D CFileStore* TheStore;
sl@0
    40
LOCAL_D RDbStoreDatabase TheDatabase;
sl@0
    41
LOCAL_D RDbTable TheTable;
sl@0
    42
LOCAL_D RFs TheFs;
sl@0
    43
sl@0
    44
const TInt KTestCleanupStack=0x20;
sl@0
    45
const TPtrC KTestDir=_L("C:\\DBMS-TST\\");
sl@0
    46
const TPtrC KTestFile=_L("T_BIG.DB");
sl@0
    47
const TPtrC KTableName(_S("table"));
sl@0
    48
const TPtrC KIndexText=_S("text");
sl@0
    49
const TPtrC KIndexInt=_S("int");
sl@0
    50
const TPtrC KColumnText=_S("text");
sl@0
    51
const TPtrC KColumnInt=_S("int");
sl@0
    52
const TPtrC KIncFormat=_S("%5d\r");
sl@0
    53
const TInt KRecords=1000;
sl@0
    54
const TPtrC KOtherTable=_S("extra");
sl@0
    55
sl@0
    56
static TTimer TheTimer;
sl@0
    57
sl@0
    58
void TTimer::Start(const TDesC& aDes)
sl@0
    59
	{
sl@0
    60
	test.Printf(_L("  %S: "),&aDes);
sl@0
    61
	iTicks=User::FastCounter();
sl@0
    62
	}
sl@0
    63
sl@0
    64
void TTimer::Stop()
sl@0
    65
	{
sl@0
    66
	TUint ticks = User::FastCounter() - iTicks;
sl@0
    67
	TInt freq = 0;
sl@0
    68
	test(HAL::Get(HAL::EFastCounterFrequency, freq) == KErrNone);
sl@0
    69
	const TInt KMicroSecIn1Sec = 1000000;
sl@0
    70
	const TInt KMsIn1Sec = 1000;
sl@0
    71
	double v = ((double)ticks * KMicroSecIn1Sec) / (double)freq; TInt v2 = (TInt)v;
sl@0
    72
	test.Printf(_L("%d ms\r\n"),v2/KMsIn1Sec);
sl@0
    73
	}
sl@0
    74
sl@0
    75
/**
sl@0
    76
@SYMTestCaseID          SYSLIB-DBMS-CT-1309
sl@0
    77
@SYMTestCaseDesc        Create the database-in-a-store
sl@0
    78
@SYMTestPriority        Medium
sl@0
    79
@SYMTestActions        	Calls up RDbStoreDatabase::CreateL() function
sl@0
    80
@SYMTestExpectedResults Test must not fail
sl@0
    81
@SYMREQ                 REQ0000
sl@0
    82
*/
sl@0
    83
LOCAL_C void CreateDatabaseL()
sl@0
    84
	{
sl@0
    85
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1309 "));
sl@0
    86
	CFileStore* store=CPermanentFileStore::ReplaceLC(TheFs,KTestFile,EFileRead|EFileWrite);
sl@0
    87
	store->SetTypeL(KPermanentFileStoreLayoutUid);
sl@0
    88
	TStreamId id;
sl@0
    89
		id=TheDatabase.CreateL(store);
sl@0
    90
	store->SetRootL(id);
sl@0
    91
	store->CommitL();
sl@0
    92
	CleanupStack::Pop();
sl@0
    93
	TheStore=store;
sl@0
    94
	}
sl@0
    95
sl@0
    96
/**
sl@0
    97
@SYMTestCaseID          SYSLIB-DBMS-CT-1310
sl@0
    98
@SYMTestCaseDesc        Open the database-in-a-store
sl@0
    99
@SYMTestPriority        Medium
sl@0
   100
@SYMTestActions        	Call up RDbStoreDatabase::OpenL()
sl@0
   101
@SYMTestExpectedResults Test must not fail
sl@0
   102
@SYMREQ                 REQ0000
sl@0
   103
*/
sl@0
   104
LOCAL_C void OpenDatabaseL()
sl@0
   105
	{
sl@0
   106
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1310 "));
sl@0
   107
	CFileStore* store=CPermanentFileStore::OpenLC(TheFs,KTestFile,EFileRead|EFileWrite);
sl@0
   108
		TheDatabase.OpenL(store,store->Root());
sl@0
   109
	CleanupStack::Pop();
sl@0
   110
	TheStore=store;
sl@0
   111
	}
sl@0
   112
sl@0
   113
/**
sl@0
   114
@SYMTestCaseID          SYSLIB-DBMS-CT-1311
sl@0
   115
@SYMTestCaseDesc        Close the database in store
sl@0
   116
@SYMTestPriority        Medium
sl@0
   117
@SYMTestActions        	Test for RDbStoreDatabase::Close() function
sl@0
   118
@SYMTestExpectedResults Test must not fail
sl@0
   119
@SYMREQ                 REQ0000
sl@0
   120
*/
sl@0
   121
LOCAL_C void CloseDatabase()
sl@0
   122
	{
sl@0
   123
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1311 "));
sl@0
   124
	TheDatabase.Close();
sl@0
   125
	delete TheStore;
sl@0
   126
	}
sl@0
   127
sl@0
   128
LOCAL_C void CreateTableL()
sl@0
   129
	{
sl@0
   130
	CDbColSet *cs=CDbColSet::NewLC();
sl@0
   131
	TDbCol col1(KColumnInt,EDbColInt32);
sl@0
   132
	col1.iAttributes=TDbCol::ENotNull;
sl@0
   133
	cs->AddL(col1);
sl@0
   134
	TDbCol col2(KColumnText,EDbColText,200/sizeof(TText));
sl@0
   135
	col2.iAttributes=TDbCol::ENotNull;
sl@0
   136
	cs->AddL(col2);
sl@0
   137
	test(TheDatabase.CreateTable(KTableName,*cs)==KErrNone);
sl@0
   138
	CleanupStack::PopAndDestroy();
sl@0
   139
	}
sl@0
   140
sl@0
   141
LOCAL_C void WriteRecordsL(TInt aCount)
sl@0
   142
	{
sl@0
   143
	TBuf<10> text;
sl@0
   144
	TInt jj=0;
sl@0
   145
	for (TInt ii=0;ii<aCount;++ii)
sl@0
   146
		{
sl@0
   147
		TheTable.InsertL();
sl@0
   148
		jj=(jj+23);
sl@0
   149
		if (jj>=aCount)
sl@0
   150
			jj-=aCount;
sl@0
   151
		TheTable.SetColL(1,jj);
sl@0
   152
		text.Num(jj);
sl@0
   153
		TheTable.SetColL(2,text);
sl@0
   154
		TheTable.PutL();
sl@0
   155
		}
sl@0
   156
	}
sl@0
   157
sl@0
   158
/**
sl@0
   159
@SYMTestCaseID          SYSLIB-DBMS-CT-1312
sl@0
   160
@SYMTestCaseDesc        Create a table in database
sl@0
   161
@SYMTestPriority        Medium
sl@0
   162
@SYMTestActions        	Build a table and write records into the table.Test for commiting the transactions.
sl@0
   163
@SYMTestExpectedResults Test must not fail
sl@0
   164
@SYMREQ                 REQ0000
sl@0
   165
*/
sl@0
   166
LOCAL_C void BuildTableL(TInt aCount)
sl@0
   167
	{
sl@0
   168
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1312 "));
sl@0
   169
	TheTimer.Start(_L("build"));
sl@0
   170
	CreateTableL();
sl@0
   171
	TheDatabase.Begin();
sl@0
   172
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   173
	WriteRecordsL(aCount);
sl@0
   174
	test(TheDatabase.Commit()==KErrNone);
sl@0
   175
	TheTable.Close();
sl@0
   176
	TheTimer.Stop();
sl@0
   177
	}
sl@0
   178
sl@0
   179
/**
sl@0
   180
@SYMTestCaseID          SYSLIB-DBMS-CT-1313
sl@0
   181
@SYMTestCaseDesc        Tests for total rows in the rowset
sl@0
   182
@SYMTestPriority        Medium
sl@0
   183
@SYMTestActions        	Iterate through the table.Test for the total numbers of rows available
sl@0
   184
@SYMTestExpectedResults Test must not fail
sl@0
   185
@SYMREQ                 REQ0000
sl@0
   186
*/
sl@0
   187
LOCAL_C void IterateL(RDbTable::TPosition aDirection)
sl@0
   188
	{
sl@0
   189
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1313 "));
sl@0
   190
	TheTimer.Start(_L("iterate"));
sl@0
   191
	TInt cc=0;
sl@0
   192
	while (TheTable.GotoL(aDirection))
sl@0
   193
		{
sl@0
   194
		++cc;
sl@0
   195
		TheTable.GetL();
sl@0
   196
		}
sl@0
   197
	TheTimer.Stop();
sl@0
   198
	test(cc=TheTable.CountL());
sl@0
   199
	}
sl@0
   200
sl@0
   201
/**
sl@0
   202
@SYMTestCaseID          SYSLIB-DBMS-CT-0580
sl@0
   203
@SYMTestCaseDesc        Tests the database definition and enquiry functions
sl@0
   204
@SYMTestPriority        Medium
sl@0
   205
@SYMTestActions        	Tests by setting an active index for the table.
sl@0
   206
@SYMTestExpectedResults Test must not fail
sl@0
   207
@SYMREQ                 REQ0000
sl@0
   208
*/
sl@0
   209
LOCAL_C void TestIndexL(const TDesC& aName,const CDbKey& aKey)
sl@0
   210
	{
sl@0
   211
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0580 "));
sl@0
   212
	TheTimer.Start(_L("build"));
sl@0
   213
	test(TheDatabase.CreateIndex(aName,KTableName,aKey)==KErrNone);
sl@0
   214
	TheTimer.Stop();
sl@0
   215
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   216
	test(TheTable.SetIndex(aName)==KErrNone);
sl@0
   217
	IterateL(TheTable.ENext);
sl@0
   218
	TheTable.Close();
sl@0
   219
	}
sl@0
   220
sl@0
   221
/**
sl@0
   222
@SYMTestCaseID          SYSLIB-DBMS-CT-0581
sl@0
   223
@SYMTestCaseDesc        Tests the database definition and enquiry functions
sl@0
   224
@SYMTestPriority        Medium
sl@0
   225
@SYMTestActions        	Tests for bookmark which saves the current location of a rowset.
sl@0
   226
@SYMTestExpectedResults Test must not fail
sl@0
   227
@SYMREQ                 REQ0000
sl@0
   228
*/
sl@0
   229
LOCAL_C void TestBookmarkL()
sl@0
   230
	{
sl@0
   231
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0581 creating alien bookmark "));
sl@0
   232
	CDbColSet* cs=CDbColSet::NewLC();
sl@0
   233
	TDbCol col(_L("column"),EDbColUint8);
sl@0
   234
	col.iAttributes=TDbCol::ENotNull+TDbCol::EAutoIncrement;
sl@0
   235
	cs->AddL(col);
sl@0
   236
	test (TheDatabase.CreateTable(KOtherTable,*cs)==KErrNone);
sl@0
   237
	CleanupStack::PopAndDestroy();
sl@0
   238
	RDbTable extra;
sl@0
   239
	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
sl@0
   240
	extra.InsertL();
sl@0
   241
	extra.PutL();
sl@0
   242
	TDbBookmark alien=extra.Bookmark();
sl@0
   243
	extra.Close();
sl@0
   244
//
sl@0
   245
	test.Next(_L("Alien bookmark"));
sl@0
   246
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   247
	TRAPD(r,TheTable.GotoL(alien));
sl@0
   248
	test (r==KErrNotFound);
sl@0
   249
	test (TheTable.SetIndex(KIndexInt)==KErrNone);
sl@0
   250
	TRAP(r,TheTable.GotoL(alien));
sl@0
   251
	test (r==KErrNotFound);
sl@0
   252
	test (TheTable.SetIndex(KIndexText)==KErrNone);
sl@0
   253
	TRAP(r,TheTable.GotoL(alien));
sl@0
   254
	test (r==KErrNotFound);
sl@0
   255
//
sl@0
   256
	test.Next(_L("Cross-view bookmarks"));
sl@0
   257
	TheTable.LastL();	// indexed view
sl@0
   258
	TheTable.PreviousL();
sl@0
   259
	TDbBookmark mark=TheTable.Bookmark();
sl@0
   260
	test (extra.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   261
	TRAP(r,extra.GotoL(mark));
sl@0
   262
	test (r==KErrNone);
sl@0
   263
	test (extra.PreviousL());
sl@0
   264
	TRAP(r,TheTable.GotoL(extra.Bookmark()));
sl@0
   265
	test (r==KErrNone);
sl@0
   266
	extra.Close();
sl@0
   267
//
sl@0
   268
	test.Next(_L("Bookmark persistence"));
sl@0
   269
	TheTable.Close();
sl@0
   270
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   271
	TRAP(r,TheTable.GotoL(mark));
sl@0
   272
	test (r==KErrNone);
sl@0
   273
	TheTable.Close();
sl@0
   274
//
sl@0
   275
	test.Next(_L("Delete alien record"));
sl@0
   276
	test (extra.Open(TheDatabase,KOtherTable)==KErrNone);
sl@0
   277
	TRAP(r, extra.GotoL(mark));
sl@0
   278
	test (r==KErrNotFound);
sl@0
   279
	TRAP(r,extra.GotoL(alien));
sl@0
   280
	test (r==KErrNone);
sl@0
   281
	extra.DeleteL();
sl@0
   282
	TRAP(r,extra.GotoL(alien));
sl@0
   283
	test (r==KErrNotFound);
sl@0
   284
	extra.Close();
sl@0
   285
//
sl@0
   286
	test.Next(_L("Delete extra table"));
sl@0
   287
	test (TheDatabase.DropTable(KOtherTable)==KErrNone);
sl@0
   288
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   289
	TRAP(r,TheTable.GotoL(alien));
sl@0
   290
	test (r==KErrNotFound);
sl@0
   291
	TheTable.Close();
sl@0
   292
//
sl@0
   293
	test.End();
sl@0
   294
	}
sl@0
   295
sl@0
   296
/**
sl@0
   297
@SYMTestCaseID          SYSLIB-DBMS-CT-1314
sl@0
   298
@SYMTestCaseDesc        Discarding indexes belonging to the table on database
sl@0
   299
@SYMTestPriority        Medium
sl@0
   300
@SYMTestActions        	Tests for RDbIncremental::DropTable(),RDbIncremental::Next() function.
sl@0
   301
@SYMTestExpectedResults Test must not fail
sl@0
   302
@SYMREQ                 REQ0000
sl@0
   303
*/
sl@0
   304
LOCAL_C void BreakIndex()
sl@0
   305
	{
sl@0
   306
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1314 "));
sl@0
   307
	TheTimer.Start(_L("break"));
sl@0
   308
	TInt step;
sl@0
   309
	RDbIncremental drop;
sl@0
   310
	test(drop.DropTable(TheDatabase,KTableName,step)==KErrNone);
sl@0
   311
	test(drop.Next(step)==KErrNone);
sl@0
   312
	test(step>0);
sl@0
   313
	drop.Close();	// abort the drop
sl@0
   314
	test(TheDatabase.IsDamaged());
sl@0
   315
	TheTimer.Stop();
sl@0
   316
	}
sl@0
   317
sl@0
   318
/**
sl@0
   319
@SYMTestCaseID          SYSLIB-DBMS-CT-1315
sl@0
   320
@SYMTestCaseDesc        Database recovery test
sl@0
   321
@SYMTestPriority        Medium
sl@0
   322
@SYMTestActions        	Calls up RDbStoreDatabase::Recover() function
sl@0
   323
@SYMTestExpectedResults Test must not fail
sl@0
   324
@SYMREQ                 REQ0000
sl@0
   325
*/
sl@0
   326
LOCAL_C void Recover()
sl@0
   327
	{
sl@0
   328
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1315 "));
sl@0
   329
	TheTimer.Start(_L("recover"));
sl@0
   330
	test(TheDatabase.Recover()==KErrNone);
sl@0
   331
	TheTimer.Stop();
sl@0
   332
	test(!TheDatabase.IsDamaged());
sl@0
   333
	}
sl@0
   334
sl@0
   335
/**
sl@0
   336
@SYMTestCaseID          SYSLIB-DBMS-CT-1316
sl@0
   337
@SYMTestCaseDesc        Tests for dropping an index
sl@0
   338
@SYMTestPriority        Medium
sl@0
   339
@SYMTestActions        	Drop an integer and text index from the table. Test for damage of database
sl@0
   340
@SYMTestExpectedResults Test must not fail
sl@0
   341
@SYMREQ                 REQ0000
sl@0
   342
*/
sl@0
   343
LOCAL_C void DropIndexes()
sl@0
   344
	{
sl@0
   345
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1316 "));
sl@0
   346
	TheTimer.Start(_L("drop Int[32]"));
sl@0
   347
	test(TheDatabase.DropIndex(KIndexInt,KTableName)==KErrNone);
sl@0
   348
	TheTimer.Stop();
sl@0
   349
	TheTimer.Start(_L("drop Text[200]"));
sl@0
   350
	test(TheDatabase.DropIndex(KIndexText,KTableName)==KErrNone);
sl@0
   351
	TheTimer.Stop();
sl@0
   352
	test(!TheDatabase.IsDamaged());
sl@0
   353
	}
sl@0
   354
sl@0
   355
/**
sl@0
   356
@SYMTestCaseID          SYSLIB-DBMS-CT-1317
sl@0
   357
@SYMTestCaseDesc        Deleting a table from the database
sl@0
   358
@SYMTestPriority        Medium
sl@0
   359
@SYMTestActions        	Delete the rows from the rowset.Check for empty rows in the rowset.
sl@0
   360
@SYMTestExpectedResults Test must not fail
sl@0
   361
@SYMREQ                 REQ0000
sl@0
   362
*/
sl@0
   363
LOCAL_C void DeleteTableL()
sl@0
   364
	{
sl@0
   365
	test.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-1317 "));
sl@0
   366
	const TInt KTenthRecords=KRecords/10;
sl@0
   367
sl@0
   368
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   369
	TheDatabase.Begin();
sl@0
   370
	TInt ii;
sl@0
   371
	for (ii=0;ii<15;++ii)
sl@0
   372
		{
sl@0
   373
		TheTable.NextL();
sl@0
   374
		TheTable.DeleteL();
sl@0
   375
		}
sl@0
   376
	TheTable.NextL();
sl@0
   377
	TDbBookmark mark=TheTable.Bookmark();
sl@0
   378
	TheTable.Close();
sl@0
   379
	TheDatabase.Commit();
sl@0
   380
	CloseDatabase();
sl@0
   381
	OpenDatabaseL();
sl@0
   382
	TheTimer.Start(_L("delete table"));
sl@0
   383
	test (TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   384
	TheDatabase.Begin();
sl@0
   385
	TheTable.GotoL(mark);
sl@0
   386
	TheTable.DeleteL();
sl@0
   387
	for (ii=0;ii<KTenthRecords*2-16;++ii)
sl@0
   388
		{
sl@0
   389
		TheTable.NextL();
sl@0
   390
		TheTable.DeleteL();
sl@0
   391
		}
sl@0
   392
	TheTable.EndL();
sl@0
   393
	for (ii=0;ii<KTenthRecords*2;++ii)
sl@0
   394
		{
sl@0
   395
		TheTable.PreviousL();
sl@0
   396
		TheTable.DeleteL();
sl@0
   397
		}
sl@0
   398
	TheTable.BeginningL();
sl@0
   399
	for (ii=0;ii<KTenthRecords*3;++ii)
sl@0
   400
		TheTable.NextL();
sl@0
   401
	for (ii=0;ii<KTenthRecords*2;++ii)
sl@0
   402
		{
sl@0
   403
		TheTable.NextL();
sl@0
   404
		TheTable.DeleteL();
sl@0
   405
		}
sl@0
   406
	for (ii=0;ii<KTenthRecords*2;++ii)
sl@0
   407
		{
sl@0
   408
		TheTable.PreviousL();
sl@0
   409
		TheTable.DeleteL();
sl@0
   410
		}
sl@0
   411
	for (ii=0;ii<KTenthRecords;++ii)
sl@0
   412
		{
sl@0
   413
		TheTable.NextL();
sl@0
   414
		TheTable.DeleteL();
sl@0
   415
		}
sl@0
   416
	for (ii=0;ii<KTenthRecords;++ii)
sl@0
   417
		{
sl@0
   418
		TheTable.PreviousL();
sl@0
   419
		TheTable.DeleteL();
sl@0
   420
		}
sl@0
   421
	test (TheTable.CountL()==0);
sl@0
   422
	test (!TheTable.NextL());
sl@0
   423
	test (!TheTable.PreviousL());
sl@0
   424
	test (TheDatabase.Commit()==KErrNone);
sl@0
   425
	TheTable.Close();
sl@0
   426
	TheTimer.Stop();
sl@0
   427
	}
sl@0
   428
sl@0
   429
/**
sl@0
   430
@SYMTestCaseID          SYSLIB-DBMS-CT-0579
sl@0
   431
@SYMTestCaseDesc        Tests the database definition and enquiry functions
sl@0
   432
@SYMTestPriority        Medium
sl@0
   433
@SYMTestActions        	Executes the index and bookmark tests
sl@0
   434
@SYMTestExpectedResults Test must not fail
sl@0
   435
@SYMREQ                 REQ0000
sl@0
   436
*/
sl@0
   437
LOCAL_C void BigTestL()
sl@0
   438
	{
sl@0
   439
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0579 Table "));
sl@0
   440
	CreateDatabaseL();
sl@0
   441
	BuildTableL(KRecords);
sl@0
   442
	test(TheTable.Open(TheDatabase,KTableName)==KErrNone);
sl@0
   443
	TheTable.EndL();
sl@0
   444
	IterateL(TheTable.EPrevious);
sl@0
   445
	TheTable.BeginningL();
sl@0
   446
	IterateL(TheTable.ENext);
sl@0
   447
	TheTable.EndL();
sl@0
   448
	IterateL(TheTable.EPrevious);
sl@0
   449
	TheTable.Close();
sl@0
   450
	test.Next(_L("Int32 Index"));
sl@0
   451
	CDbKey *key=CDbKey::NewLC();
sl@0
   452
	key->AddL(KColumnInt);
sl@0
   453
	key->MakeUnique();
sl@0
   454
	TestIndexL(KIndexInt,*key);
sl@0
   455
	test.Next(_L("Text[200] Index"));
sl@0
   456
	key->Clear();
sl@0
   457
	key->AddL(KColumnText);
sl@0
   458
	key->MakeUnique();
sl@0
   459
	TestIndexL(KIndexText,*key);
sl@0
   460
	test.Next(_L("Bookmarks"));
sl@0
   461
	TestBookmarkL();
sl@0
   462
	test.Next(_L("Int32 Index"));
sl@0
   463
	TheTimer.Start(_L("drop"));
sl@0
   464
	test(TheDatabase.DropIndex(KIndexInt,KTableName)==KErrNone);
sl@0
   465
	TheTimer.Stop();
sl@0
   466
	key->Clear();
sl@0
   467
	key->AddL(KColumnInt);
sl@0
   468
	key->MakeUnique();
sl@0
   469
	TestIndexL(KIndexInt,*key);
sl@0
   470
	CleanupStack::PopAndDestroy();
sl@0
   471
	test.Next(_L("Break & Recover"));
sl@0
   472
	BreakIndex();
sl@0
   473
	Recover();
sl@0
   474
	test.Next(_L("Drop Indexes"));
sl@0
   475
	DropIndexes();
sl@0
   476
	test.Next(_L("Delete all records"));
sl@0
   477
	DeleteTableL();
sl@0
   478
	CloseDatabase();
sl@0
   479
	test.End();
sl@0
   480
	}
sl@0
   481
sl@0
   482
//
sl@0
   483
// Prepare the test directory.
sl@0
   484
//
sl@0
   485
LOCAL_C void setupTestDirectory()
sl@0
   486
    {
sl@0
   487
	TInt r=TheFs.Connect();
sl@0
   488
	test(r==KErrNone);
sl@0
   489
	r=TheFs.MkDir(KTestDir);
sl@0
   490
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   491
	r=TheFs.SetSessionPath(KTestDir);
sl@0
   492
	test(r==KErrNone);
sl@0
   493
	}
sl@0
   494
sl@0
   495
//
sl@0
   496
// Initialise the cleanup stack.
sl@0
   497
//
sl@0
   498
LOCAL_C void setupCleanup()
sl@0
   499
    {
sl@0
   500
	TheTrapCleanup=CTrapCleanup::New();
sl@0
   501
	test(TheTrapCleanup!=NULL);
sl@0
   502
	TRAPD(r,\
sl@0
   503
		{\
sl@0
   504
		for (TInt i=KTestCleanupStack;i>0;i--)\
sl@0
   505
			CleanupStack::PushL((TAny*)0);\
sl@0
   506
		CleanupStack::Pop(KTestCleanupStack);\
sl@0
   507
		});
sl@0
   508
	test(r==KErrNone);
sl@0
   509
	}
sl@0
   510
sl@0
   511
LOCAL_C void DeleteDataFile(const TDesC& aFullName)
sl@0
   512
	{
sl@0
   513
	RFs fsSession;
sl@0
   514
	TInt err = fsSession.Connect();
sl@0
   515
	if(err == KErrNone)
sl@0
   516
		{
sl@0
   517
		TEntry entry;
sl@0
   518
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   519
			{
sl@0
   520
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
sl@0
   521
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   522
			if(err != KErrNone)
sl@0
   523
				{
sl@0
   524
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   525
				}
sl@0
   526
			err = fsSession.Delete(aFullName);
sl@0
   527
			if(err != KErrNone)
sl@0
   528
				{
sl@0
   529
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   530
				}
sl@0
   531
			}
sl@0
   532
		fsSession.Close();
sl@0
   533
		}
sl@0
   534
	else
sl@0
   535
		{
sl@0
   536
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   537
		}
sl@0
   538
	}
sl@0
   539
sl@0
   540
//
sl@0
   541
// Test streaming conversions.
sl@0
   542
//
sl@0
   543
GLDEF_C TInt E32Main()
sl@0
   544
    {
sl@0
   545
	test.Title();
sl@0
   546
	setupTestDirectory();
sl@0
   547
	setupCleanup();
sl@0
   548
	__UHEAP_MARK;
sl@0
   549
//
sl@0
   550
	test.Start(_L("Standard database"));
sl@0
   551
	TRAPD(r,BigTestL();)
sl@0
   552
	test(r==KErrNone);
sl@0
   553
sl@0
   554
	// clean up data files used by this test - must be done before call to End() - DEF047652
sl@0
   555
	_LIT(KTestDbName, "C:\\DBMS-TST\\T_BIG.DB");
sl@0
   556
	::DeleteDataFile(KTestDbName);
sl@0
   557
sl@0
   558
	test.End();
sl@0
   559
//
sl@0
   560
	__UHEAP_MARKEND;
sl@0
   561
	delete TheTrapCleanup;
sl@0
   562
sl@0
   563
sl@0
   564
sl@0
   565
	TheFs.Close();
sl@0
   566
	test.Close();
sl@0
   567
	return 0;
sl@0
   568
    }