os/persistentdata/persistentstorage/dbms/tdbms/t_dbperf2.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) 2006-2010 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 <s32mem.h>
sl@0
    21
#include <hal.h>
sl@0
    22
sl@0
    23
static RTest TheTest(_L("t_dbperf2"));
sl@0
    24
static CTrapCleanup* TheTrapCleanup;
sl@0
    25
static RFs TheFs;
sl@0
    26
static RDbs TheDbs;
sl@0
    27
static RDbNamedDatabase TheDatabase;
sl@0
    28
static RDbRowSet TheRowSet;
sl@0
    29
static RFile TheTestFile;
sl@0
    30
static TFileName TheDatabaseFileName;
sl@0
    31
static TFileName TheLogFileName;
sl@0
    32
static TFileName TheTestFileName;
sl@0
    33
static TParse TheParse;
sl@0
    34
sl@0
    35
#define COUNT_OF(array) (sizeof(array)/sizeof(array[0]))
sl@0
    36
sl@0
    37
const TInt KTestRecordCount = 400;
sl@0
    38
sl@0
    39
const TInt KTextColSize = 200;//Change KCreateTestTableSql string too!
sl@0
    40
sl@0
    41
_LIT(KCreateTestTableSql, "CREATE TABLE A(I1 INTEGER, I2 DOUBLE, I3 VARCHAR(200))");
sl@0
    42
_LIT(KCreateIndexSql, "CREATE UNIQUE INDEX IDX ON A(I1)");
sl@0
    43
sl@0
    44
const TInt KColSize2 = 500;
sl@0
    45
_LIT(KCreateTestTableSql2, "CREATE TABLE A(I1 INTEGER, I2 LONG VARCHAR, I3 LONG VARBINARY)");
sl@0
    46
sl@0
    47
const TChar KBufChar('O');
sl@0
    48
TBuf8<KColSize2> TheBinRndData;
sl@0
    49
TBuf16<KColSize2> TheTextRndData;
sl@0
    50
sl@0
    51
//////////////////////////////////////////////////////
sl@0
    52
sl@0
    53
static TInt TheCounterFreq = -10000000;
sl@0
    54
const TInt KMicroSecIn1Sec = 1000000;
sl@0
    55
sl@0
    56
TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks)
sl@0
    57
	{
sl@0
    58
	TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
sl@0
    59
	if(diffTicks < 0)
sl@0
    60
		{
sl@0
    61
		diffTicks = KMaxTUint32 + diffTicks + 1;
sl@0
    62
		}
sl@0
    63
	return (TUint32)diffTicks;
sl@0
    64
	}
sl@0
    65
sl@0
    66
//Prints aFastCount parameter (converted to us)
sl@0
    67
void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount)
sl@0
    68
	{
sl@0
    69
	double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
sl@0
    70
	TInt v2 = (TInt)v;
sl@0
    71
	TheTest.Printf(aFormatStr, v2);
sl@0
    72
	}
sl@0
    73
sl@0
    74
//Prints aFastCount parameter (converted to us) and the records count
sl@0
    75
void PrintFcDiffAsUs2(const TDesC& aFormatStr, TInt aRecCnt, TUint32 aFastCount)
sl@0
    76
	{
sl@0
    77
	double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
sl@0
    78
	TInt v2 = (TInt)v;
sl@0
    79
	TheTest.Printf(aFormatStr, aRecCnt, v2);
sl@0
    80
	}
sl@0
    81
sl@0
    82
//////////////////////////////////////////////////////
sl@0
    83
sl@0
    84
enum TRowSetType {EViewRowSet, ETableRowSet};
sl@0
    85
const TRowSetType KRowSetTypes[] = {EViewRowSet/*, ETableRowSet*/}; //Excluding ETableRowSet means that the test requires less time.
sl@0
    86
const TPtrC KRowSetTypeStr[] = {_L("RDbView.")/*, _L("RDbTable.")*/};//The coverage is not affected that much.
sl@0
    87
sl@0
    88
//////////////////////////////////////////////////////
sl@0
    89
sl@0
    90
const RDbRowSet::TAccess KAccessModes[] = {RDbRowSet::EInsertOnly, RDbRowSet::EUpdatable};
sl@0
    91
const TPtrC KAccessModeStr[] = {_L("Insert only."), _L("Updatable.")};
sl@0
    92
sl@0
    93
//////////////////////////////////////////////////////
sl@0
    94
sl@0
    95
enum TUpdDirection {EUpdBackward, EUpdForward};
sl@0
    96
const TUpdDirection KUpdDirectionTypes[] = {EUpdBackward, EUpdForward};
sl@0
    97
const TPtrC KUpdDirectionTypeStr[] = {_L("Backward."), _L("Forward.")};
sl@0
    98
sl@0
    99
//////////////////////////////////////////////////////
sl@0
   100
sl@0
   101
enum TCommitRecCnt {ECommit_1_Rec = 1, ECommit_Cnt_Rec = 20, ECommit_All_Rec = KTestRecordCount};
sl@0
   102
const TCommitRecCnt KCommitTypes[] = {ECommit_1_Rec, ECommit_Cnt_Rec, ECommit_All_Rec};
sl@0
   103
const TPtrC KCommitTypeStr[] = {_L("Commit after 1 op."), _L("Commit after 20 ops."), _L("Commit at end.")};
sl@0
   104
sl@0
   105
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   106
sl@0
   107
//Delete "aFullName" file.
sl@0
   108
static void DeleteFile(const TDesC& aFullName)
sl@0
   109
	{
sl@0
   110
	RFs fsSession;
sl@0
   111
	TInt err = fsSession.Connect();
sl@0
   112
	if(err == KErrNone)
sl@0
   113
		{
sl@0
   114
		TEntry entry;
sl@0
   115
		if(fsSession.Entry(aFullName, entry) == KErrNone)
sl@0
   116
			{
sl@0
   117
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
sl@0
   118
			if(err != KErrNone) 
sl@0
   119
				{
sl@0
   120
				TheTest.Printf(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
sl@0
   121
				}
sl@0
   122
			err = fsSession.Delete(aFullName);
sl@0
   123
			if(err != KErrNone) 
sl@0
   124
				{
sl@0
   125
				TheTest.Printf(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
sl@0
   126
				}
sl@0
   127
			}
sl@0
   128
		fsSession.Close();
sl@0
   129
		}
sl@0
   130
	else
sl@0
   131
		{
sl@0
   132
		TheTest.Printf(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
sl@0
   133
		}
sl@0
   134
	}
sl@0
   135
sl@0
   136
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   137
sl@0
   138
static void CloseAll()
sl@0
   139
	{
sl@0
   140
	TheRowSet.Close();
sl@0
   141
	TheDatabase.Close();
sl@0
   142
	TheDbs.Close();
sl@0
   143
	TheTestFile.Close();
sl@0
   144
	TheFs.Close();
sl@0
   145
	}
sl@0
   146
sl@0
   147
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   148
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   149
//Tests macros and functions.
sl@0
   150
//If (!aValue) then the test will be panicked, the test data files will be deleted.
sl@0
   151
static void Check(TInt aValue, TInt aLine)
sl@0
   152
	{
sl@0
   153
	if(!aValue)
sl@0
   154
		{
sl@0
   155
		CloseAll();
sl@0
   156
		DeleteFile(TheDatabaseFileName);
sl@0
   157
		DeleteFile(TheTestFileName);
sl@0
   158
		TheTest(EFalse, aLine);
sl@0
   159
		}
sl@0
   160
	}
sl@0
   161
//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
sl@0
   162
static void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
   163
	{
sl@0
   164
	if(aValue != aExpected)
sl@0
   165
		{
sl@0
   166
		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
   167
		CloseAll();
sl@0
   168
		DeleteFile(TheDatabaseFileName);
sl@0
   169
		DeleteFile(TheTestFileName);
sl@0
   170
		TheTest(EFalse, aLine);
sl@0
   171
		}
sl@0
   172
	}
sl@0
   173
//Use these to test conditions.
sl@0
   174
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
   175
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
   176
sl@0
   177
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   178
sl@0
   179
void PrintFileSize()
sl@0
   180
	{
sl@0
   181
	RDbDatabase::TSize s = TheDatabase.Size();
sl@0
   182
	TheTest.Printf(_L("####FileSize: %d\r\n"), s.iSize);
sl@0
   183
	}
sl@0
   184
sl@0
   185
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   186
sl@0
   187
void DbRowSetInsertTestL(TRowSetType aRowSetType, RDbRowSet::TAccess aAccessMode, TCommitRecCnt aCommitRecCnt)
sl@0
   188
	{
sl@0
   189
	TBuf<KTextColSize> textColVal;
sl@0
   190
	for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
sl@0
   191
		{
sl@0
   192
		textColVal.Append(TChar(ii));
sl@0
   193
		}
sl@0
   194
	for(TInt compaction=0;compaction<2;++compaction)
sl@0
   195
		{
sl@0
   196
		TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n"));
sl@0
   197
		TheRowSet.Close();
sl@0
   198
		TInt err;
sl@0
   199
		err = TheDatabase.Execute(_L("DELETE FROM A"));
sl@0
   200
		TEST(err >= 0);
sl@0
   201
		TUint32 fc = User::FastCounter();
sl@0
   202
		if(aRowSetType == EViewRowSet)
sl@0
   203
			{
sl@0
   204
			RDbView view;
sl@0
   205
			err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode);
sl@0
   206
			TEST2(err, KErrNone);
sl@0
   207
			err = view.EvaluateAll();
sl@0
   208
			TEST2(err, KErrNone);
sl@0
   209
			TheRowSet = view;
sl@0
   210
			}
sl@0
   211
		else
sl@0
   212
			{
sl@0
   213
			RDbTable tbl;
sl@0
   214
			err = tbl.Open(TheDatabase, _L("A"), aAccessMode);
sl@0
   215
			TEST2(err, KErrNone);
sl@0
   216
			TheRowSet = tbl;
sl@0
   217
			}
sl@0
   218
		TUint32 prepFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   219
		TUint32 insFc = 0;
sl@0
   220
		TUint32 setcolFc = 0;
sl@0
   221
		TUint32 putFc = 0;
sl@0
   222
		TUint32 commitFc = 0;
sl@0
   223
		TUint32 totalFc = 0;
sl@0
   224
		fc = User::FastCounter();
sl@0
   225
		for(TInt i=0,count=0;i<KTestRecordCount;++i)
sl@0
   226
			{
sl@0
   227
			TUint32 tmpFc;
sl@0
   228
			if(aCommitRecCnt != ECommit_1_Rec && count == 0)
sl@0
   229
				{
sl@0
   230
				tmpFc = User::FastCounter();
sl@0
   231
				err = TheDatabase.Begin();	
sl@0
   232
				TEST2(err, KErrNone);
sl@0
   233
				commitFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   234
				}
sl@0
   235
			tmpFc = User::FastCounter();
sl@0
   236
			TheRowSet.InsertL();
sl@0
   237
			insFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   238
			tmpFc = User::FastCounter();
sl@0
   239
			TheRowSet.SetColL(1, i);
sl@0
   240
			TheRowSet.SetColL(2, i * 10.1234);
sl@0
   241
			TheRowSet.SetColL(3, textColVal);
sl@0
   242
			setcolFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   243
			tmpFc = User::FastCounter();
sl@0
   244
			TheRowSet.PutL();
sl@0
   245
			putFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   246
			if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt)
sl@0
   247
				{
sl@0
   248
				tmpFc = User::FastCounter();
sl@0
   249
				count = 0;
sl@0
   250
				err = TheDatabase.Commit();	
sl@0
   251
				TEST2(err, KErrNone);
sl@0
   252
				commitFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   253
				if(compaction)
sl@0
   254
					{
sl@0
   255
					err = TheDatabase.Compact();
sl@0
   256
					TEST2(err, KErrNone);
sl@0
   257
					}
sl@0
   258
				}
sl@0
   259
			}
sl@0
   260
		totalFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   261
		PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc);
sl@0
   262
		PrintFcDiffAsUs(_L("###InsertL,time=%d us\r\n"), insFc);
sl@0
   263
		PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc);
sl@0
   264
		PrintFcDiffAsUs(_L("###PutL,   time=%d us\r\n"), putFc);
sl@0
   265
		PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc);
sl@0
   266
		PrintFcDiffAsUs(_L("###Total,  time=%d us\r\n"), totalFc);
sl@0
   267
		TheRowSet.Close();
sl@0
   268
		PrintFileSize();
sl@0
   269
		//Check
sl@0
   270
		if(aAccessMode != RDbRowSet::EInsertOnly)
sl@0
   271
			{
sl@0
   272
			RDbView view;
sl@0
   273
			err = view.Prepare(TheDatabase, _L("SELECT * FROM A"), aAccessMode);
sl@0
   274
			TEST2(err, KErrNone);
sl@0
   275
			err = view.EvaluateAll();
sl@0
   276
			TEST2(err, KErrNone);
sl@0
   277
			TInt count = view.CountL();
sl@0
   278
			view.Close();
sl@0
   279
			TEST2(count, KTestRecordCount);
sl@0
   280
			}
sl@0
   281
		}//end of - for(TInt compaction=0;compaction<2;++compaction)
sl@0
   282
	}
sl@0
   283
sl@0
   284
void FirstRecL(TUpdDirection aUpdDirection)
sl@0
   285
	{
sl@0
   286
	TBool rc = EFalse;
sl@0
   287
	switch(aUpdDirection)
sl@0
   288
		{
sl@0
   289
		case EUpdBackward:
sl@0
   290
			rc = TheRowSet.LastL();
sl@0
   291
			break;
sl@0
   292
		case EUpdForward:
sl@0
   293
		default:
sl@0
   294
			rc = TheRowSet.FirstL();
sl@0
   295
			break;
sl@0
   296
		}
sl@0
   297
	TEST(rc);
sl@0
   298
	}
sl@0
   299
sl@0
   300
void NextRecL(TUpdDirection aUpdDirection)
sl@0
   301
	{
sl@0
   302
	TBool rc = EFalse;
sl@0
   303
	switch(aUpdDirection)
sl@0
   304
		{
sl@0
   305
		case EUpdBackward:
sl@0
   306
			rc = TheRowSet.PreviousL();
sl@0
   307
			break;
sl@0
   308
		case EUpdForward:
sl@0
   309
		default:
sl@0
   310
			rc = TheRowSet.NextL();
sl@0
   311
			break;
sl@0
   312
		}
sl@0
   313
	TEST(rc);
sl@0
   314
	}
sl@0
   315
sl@0
   316
void DbRowSetUpdateTestL(TRowSetType aRowSetType, TUpdDirection aUpdDirection, TCommitRecCnt aCommitRecCnt)
sl@0
   317
	{
sl@0
   318
	TBuf<KTextColSize> textColVal;
sl@0
   319
	for(TInt ii=33000;ii<(33000+KTextColSize);++ii)
sl@0
   320
		{
sl@0
   321
		textColVal.Append(TChar(ii));
sl@0
   322
		}
sl@0
   323
		
sl@0
   324
	for(TInt compaction=0;compaction<2;++compaction)
sl@0
   325
		{
sl@0
   326
		TheTest.Printf(compaction ? _L("Compaction:Yes.\r\n") : _L("Compaction:No.\r\n"));
sl@0
   327
		TheRowSet.Close();
sl@0
   328
		TInt err;
sl@0
   329
		TUint32 fc = User::FastCounter();
sl@0
   330
		if(aRowSetType == EViewRowSet)
sl@0
   331
			{
sl@0
   332
			RDbView view;
sl@0
   333
			err = view.Prepare(TheDatabase, _L("SELECT * FROM A WHERE I1 >= 0 AND I1 <= 1000000"), RDbRowSet::EUpdatable);
sl@0
   334
			TEST2(err, KErrNone);
sl@0
   335
			err = view.EvaluateAll();
sl@0
   336
			TEST2(err, KErrNone);
sl@0
   337
			TheRowSet = view;
sl@0
   338
			}
sl@0
   339
		else
sl@0
   340
			{
sl@0
   341
			RDbTable tbl;
sl@0
   342
			err = tbl.Open(TheDatabase, _L("A"), RDbRowSet::EUpdatable);
sl@0
   343
			TEST2(err, KErrNone);
sl@0
   344
			TheRowSet = tbl;
sl@0
   345
			}
sl@0
   346
		TInt cnt = TheRowSet.CountL();
sl@0
   347
		TEST2(cnt, KTestRecordCount);
sl@0
   348
		TUint32 prepFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   349
		TUint32 insFc = 0;
sl@0
   350
		TUint32 setcolFc = 0;
sl@0
   351
		TUint32 putFc = 0;
sl@0
   352
		TUint32 commitFc = 0;
sl@0
   353
		TUint32 totalFc = 0;
sl@0
   354
		fc = User::FastCounter();
sl@0
   355
		for(TInt i=0,count=0;i<KTestRecordCount;++i)
sl@0
   356
			{
sl@0
   357
			TRAP(err, (i == 0 ? FirstRecL(aUpdDirection) : NextRecL(aUpdDirection)));
sl@0
   358
			TEST2(err, KErrNone);
sl@0
   359
			TUint32 tmpFc;
sl@0
   360
			if(aCommitRecCnt != ECommit_1_Rec && count == 0)
sl@0
   361
				{
sl@0
   362
				tmpFc = User::FastCounter();
sl@0
   363
				err = TheDatabase.Begin();	
sl@0
   364
				TEST2(err, KErrNone);
sl@0
   365
				commitFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   366
				}
sl@0
   367
			tmpFc = User::FastCounter();
sl@0
   368
			TheRowSet.UpdateL();
sl@0
   369
			insFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   370
			tmpFc = User::FastCounter();
sl@0
   371
			TheRowSet.SetColL(2, i * 20.0);
sl@0
   372
			TheRowSet.SetColL(3, textColVal);
sl@0
   373
			setcolFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   374
			tmpFc = User::FastCounter();
sl@0
   375
			TheRowSet.PutL();
sl@0
   376
			putFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   377
			if(aCommitRecCnt != ECommit_1_Rec && ++count == aCommitRecCnt)
sl@0
   378
				{
sl@0
   379
				tmpFc = User::FastCounter();
sl@0
   380
				count = 0;
sl@0
   381
				err = TheDatabase.Commit();	
sl@0
   382
				TEST2(err, KErrNone);
sl@0
   383
				commitFc += CalcTickDiff(tmpFc, User::FastCounter());
sl@0
   384
				if(compaction)
sl@0
   385
					{
sl@0
   386
					err = TheDatabase.Compact();
sl@0
   387
					TEST2(err, KErrNone);
sl@0
   388
					}
sl@0
   389
				}
sl@0
   390
			}
sl@0
   391
		totalFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   392
		PrintFcDiffAsUs(_L("###Prepare,time=%d us\r\n"), prepFc);
sl@0
   393
		PrintFcDiffAsUs(_L("###UpdateL,time=%d us\r\n"), insFc);
sl@0
   394
		PrintFcDiffAsUs(_L("###SetColL,time=%d us\r\n"), setcolFc);
sl@0
   395
		PrintFcDiffAsUs(_L("###PutL,   time=%d us\r\n"), putFc);
sl@0
   396
		PrintFcDiffAsUs(_L("###Commit, time=%d us\r\n"), commitFc);
sl@0
   397
		PrintFcDiffAsUs(_L("###Total,  time=%d us\r\n"), totalFc);
sl@0
   398
		TheRowSet.Close();
sl@0
   399
		PrintFileSize();
sl@0
   400
		}//end of - for(TInt compaction=0;compaction<2;++compaction)
sl@0
   401
	}
sl@0
   402
sl@0
   403
///////////////////////////////////////////////////////////////////////////////////////
sl@0
   404
sl@0
   405
void CreateDatabase()
sl@0
   406
	{
sl@0
   407
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
   408
	TEST2(err, KErrNone);
sl@0
   409
	TheDatabase.Close();
sl@0
   410
	err = TheDbs.Connect();
sl@0
   411
	TEST2(err, KErrNone);
sl@0
   412
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
sl@0
   413
	TEST2(err, KErrNone);
sl@0
   414
	err = TheDatabase.Execute(KCreateTestTableSql);
sl@0
   415
	TEST2(err, KErrNone);
sl@0
   416
	err = TheDatabase.Execute(KCreateIndexSql);
sl@0
   417
	TEST2(err, KErrNone);
sl@0
   418
	}
sl@0
   419
sl@0
   420
void CreateAndFillDatabase()
sl@0
   421
	{
sl@0
   422
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
   423
	TEST2(err, KErrNone);
sl@0
   424
	TheDatabase.Close();
sl@0
   425
	err = TheDbs.Connect();
sl@0
   426
	TEST2(err, KErrNone);
sl@0
   427
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
sl@0
   428
	TEST2(err, KErrNone);
sl@0
   429
	err = TheDatabase.Execute(KCreateTestTableSql);
sl@0
   430
	TEST2(err, KErrNone);
sl@0
   431
	err = TheDatabase.Execute(KCreateIndexSql);
sl@0
   432
	TEST2(err, KErrNone);
sl@0
   433
	//	
sl@0
   434
	TBuf<KTextColSize> textColVal;
sl@0
   435
	for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
sl@0
   436
		{
sl@0
   437
		textColVal.Append(TChar(ii));
sl@0
   438
		}
sl@0
   439
	err = TheDatabase.Begin();	
sl@0
   440
	TEST2(err, KErrNone);
sl@0
   441
	for(TInt i=0;i<KTestRecordCount;++i)
sl@0
   442
		{
sl@0
   443
		TBuf<KTextColSize + 100> sql;
sl@0
   444
		sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal);
sl@0
   445
		err = TheDatabase.Execute(sql);
sl@0
   446
		TEST2(err, 1);
sl@0
   447
		}
sl@0
   448
	err = TheDatabase.Commit();	
sl@0
   449
	TEST2(err, KErrNone);
sl@0
   450
	}
sl@0
   451
sl@0
   452
void DestroyDatabase()
sl@0
   453
	{
sl@0
   454
	TheRowSet.Close();
sl@0
   455
	TheDatabase.Close();
sl@0
   456
	TheDbs.Close();
sl@0
   457
	TInt err = TheFs.Delete(TheDatabaseFileName);
sl@0
   458
	TEST2(err, KErrNone);
sl@0
   459
	}
sl@0
   460
sl@0
   461
void GetFastCounterFrequency()
sl@0
   462
	{
sl@0
   463
	TheTest.Start(_L("Get fast counter frequency"));
sl@0
   464
	TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone);
sl@0
   465
	TheTest.Printf(_L("Counter frequency=%d\r\n"), TheCounterFreq);
sl@0
   466
	}
sl@0
   467
	
sl@0
   468
void FileBlockSizeTestsL()
sl@0
   469
	{
sl@0
   470
	TheTest.Next(_L("File Block Size test"));
sl@0
   471
	
sl@0
   472
	const TInt KBlockSizeLow = 64, KBlockSizeHigh = 1024 * 64;
sl@0
   473
	for(TInt blockSize=KBlockSizeLow;blockSize<=KBlockSizeHigh;blockSize*=2)
sl@0
   474
		{
sl@0
   475
		for(TInt addSize=-4;addSize<=4;addSize+=4)
sl@0
   476
			{
sl@0
   477
			TInt currBlockSize = blockSize + addSize;
sl@0
   478
			TBuf<100> title;
sl@0
   479
			title.Copy(_L("File block size "));
sl@0
   480
			title.AppendNum((TInt64)currBlockSize);
sl@0
   481
			title.Append(_L(" bytes"));
sl@0
   482
			TheTest.Printf(title);
sl@0
   483
			
sl@0
   484
			HBufC8* data = HBufC8::New(currBlockSize);
sl@0
   485
			TEST(data != NULL);
sl@0
   486
			TPtr8 dataPtr = data->Des();
sl@0
   487
			dataPtr.SetLength(currBlockSize);
sl@0
   488
			
sl@0
   489
			TInt err = TheTestFile.Replace(TheFs, TheTestFileName, EFileRead | EFileWrite);
sl@0
   490
			TEST2(err, KErrNone);
sl@0
   491
			err = TheTestFile.Write(dataPtr);
sl@0
   492
			TEST2(err, KErrNone);
sl@0
   493
			err = TheTestFile.Flush();
sl@0
   494
			TEST2(err, KErrNone);
sl@0
   495
			TUint32 fc = User::FastCounter();
sl@0
   496
			err = TheTestFile.Write(0, dataPtr);
sl@0
   497
			fc = CalcTickDiff(fc, User::FastCounter());
sl@0
   498
			PrintFcDiffAsUs(_L("###Time=%d us\r\n"), fc);
sl@0
   499
			TEST2(err, KErrNone);
sl@0
   500
			TheTestFile.Close();
sl@0
   501
			
sl@0
   502
			delete data;
sl@0
   503
			}
sl@0
   504
		}
sl@0
   505
	DeleteFile(TheTestFileName);
sl@0
   506
	}
sl@0
   507
sl@0
   508
/**
sl@0
   509
@SYMTestCaseID          SYSLIB-DBMS-UT-3310
sl@0
   510
@SYMTestCaseDesc        DBMS, RDbView performance tests.
sl@0
   511
@SYMTestPriority        High
sl@0
   512
@SYMTestActions        	The test creates and fills a test table with integer, real and text column. Then
sl@0
   513
						executes 3 test subcases:
sl@0
   514
						- updates the integer column only in all records, using "SELECT I1,I2,I3" cursor;
sl@0
   515
						- updates the text column only in all records, using "SELECT I1,I2,I3" cursor;
sl@0
   516
						- updates all columns in all records, using "SELECT I1,I2,I3" cursor;
sl@0
   517
						The execution times are printed out.
sl@0
   518
@SYMTestExpectedResults Test must not fail
sl@0
   519
@SYMREQ                 REQ7141
sl@0
   520
*/
sl@0
   521
void RecordLenTestL()
sl@0
   522
	{
sl@0
   523
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3310 Record length test - create database"));
sl@0
   524
	CreateAndFillDatabase();
sl@0
   525
	////////////////////////////////////////////////////////////////////////////////////////////////////////////	
sl@0
   526
	TheTest.Printf(_L("Record length test - update the integer column only"));
sl@0
   527
	TUint32 fc = User::FastCounter();
sl@0
   528
	RDbView view;
sl@0
   529
	TInt err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
sl@0
   530
	TEST2(err, KErrNone);
sl@0
   531
	err = view.EvaluateAll();
sl@0
   532
	TEST2(err, KErrNone);
sl@0
   533
	TheRowSet = view;
sl@0
   534
	err = TheDatabase.Begin();
sl@0
   535
	TEST2(err, KErrNone);
sl@0
   536
	TInt recCnt = 0;
sl@0
   537
	TheRowSet.FirstL();
sl@0
   538
	do
sl@0
   539
		{
sl@0
   540
		TheRowSet.UpdateL();
sl@0
   541
		TheRowSet.SetColL(1, 60000 + recCnt);
sl@0
   542
		TheRowSet.PutL();
sl@0
   543
		++recCnt;
sl@0
   544
		}
sl@0
   545
	while(TheRowSet.NextL());
sl@0
   546
	TEST2(recCnt, KTestRecordCount);
sl@0
   547
	err = TheDatabase.Commit();
sl@0
   548
	TEST2(err, KErrNone);
sl@0
   549
	PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   550
	TheRowSet.Close();
sl@0
   551
	////////////////////////////////////////////////////////////////////////////////////////////////////////////	
sl@0
   552
	TheTest.Printf(_L("Record length test - update the text column only"));
sl@0
   553
	fc = User::FastCounter();
sl@0
   554
	err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
sl@0
   555
	TEST2(err, KErrNone);
sl@0
   556
	err = view.EvaluateAll();
sl@0
   557
	TEST2(err, KErrNone);
sl@0
   558
	TheRowSet = view;
sl@0
   559
	err = TheDatabase.Begin();
sl@0
   560
	TEST2(err, KErrNone);
sl@0
   561
	recCnt = 0;
sl@0
   562
	TheRowSet.FirstL();
sl@0
   563
	do
sl@0
   564
		{
sl@0
   565
		TheRowSet.UpdateL();
sl@0
   566
		TheRowSet.SetColL(3, _L("0123456789"));
sl@0
   567
		TheRowSet.PutL();
sl@0
   568
		++recCnt;
sl@0
   569
		}
sl@0
   570
	while(TheRowSet.NextL());
sl@0
   571
	TEST2(recCnt, KTestRecordCount);
sl@0
   572
	err = TheDatabase.Commit();
sl@0
   573
	TEST2(err, KErrNone);
sl@0
   574
	PrintFcDiffAsUs(_L("###Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   575
	TheRowSet.Close();
sl@0
   576
	////////////////////////////////////////////////////////////////////////////////////////////////////////////	
sl@0
   577
	TheTest.Printf(_L("Record length test - update all columns"));
sl@0
   578
	fc = User::FastCounter();
sl@0
   579
	err = view.Prepare(TheDatabase, _L("SELECT * FROM A"));
sl@0
   580
	TEST2(err, KErrNone);
sl@0
   581
	err = view.EvaluateAll();
sl@0
   582
	TEST2(err, KErrNone);
sl@0
   583
	TheRowSet = view;
sl@0
   584
	err = TheDatabase.Begin();
sl@0
   585
	TEST2(err, KErrNone);
sl@0
   586
	recCnt = 0;
sl@0
   587
	TheRowSet.FirstL();
sl@0
   588
	do
sl@0
   589
		{
sl@0
   590
		TheRowSet.UpdateL();
sl@0
   591
		TheRowSet.SetColL(1, 34567 - recCnt);
sl@0
   592
		TheRowSet.SetColL(2, 888.111);
sl@0
   593
		TheRowSet.SetColL(3, _L("QWETYUIOPASDF"));
sl@0
   594
		TheRowSet.PutL();
sl@0
   595
		++recCnt;
sl@0
   596
		}
sl@0
   597
	while(TheRowSet.NextL());
sl@0
   598
	TEST2(recCnt, KTestRecordCount);
sl@0
   599
	err = TheDatabase.Commit();
sl@0
   600
	TEST2(err, KErrNone);
sl@0
   601
	PrintFcDiffAsUs(_L("###Time=%d ms\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   602
	////////////////////////////////////////////////////////////////////////////////////////////////////////////	
sl@0
   603
	DestroyDatabase();//This will destroy TheRowSet object too.
sl@0
   604
	}
sl@0
   605
sl@0
   606
/**
sl@0
   607
@SYMTestCaseID          SYSLIB-DBMS-UT-3311
sl@0
   608
@SYMTestCaseDesc        DBMS, RDbView performance tests.
sl@0
   609
@SYMTestPriority        High
sl@0
   610
@SYMTestActions        	The test measures the time used by insert-only or updatable cursor to:
sl@0
   611
						- insert certain amount of records, comitting after each insert;
sl@0
   612
						- insert certain amount of records, comitting after 20 inserts;
sl@0
   613
						- insert certain amount of records, comitting at the end;
sl@0
   614
						All cases repeated with and without compaction (except the first one).
sl@0
   615
						The execution times are printed out.
sl@0
   616
@SYMTestExpectedResults Test must not fail
sl@0
   617
@SYMREQ                 REQ7141
sl@0
   618
*/
sl@0
   619
void InsertTestsL()
sl@0
   620
	{
sl@0
   621
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3311 RDbView \"insert\" performance tests")); 	
sl@0
   622
	for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1)
sl@0
   623
		{
sl@0
   624
		for(TInt i2=0;i2<COUNT_OF(KAccessModes);++i2)
sl@0
   625
			{
sl@0
   626
			for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
sl@0
   627
				{
sl@0
   628
				CreateDatabase();
sl@0
   629
				TBuf<200> title;
sl@0
   630
				title.Copy(_L("Insert."));
sl@0
   631
				title.Append(KRowSetTypeStr[i1]);
sl@0
   632
				title.Append(KAccessModeStr[i2]);
sl@0
   633
				title.Append(KCommitTypeStr[i3]);
sl@0
   634
				TheTest.Printf(title);
sl@0
   635
				DbRowSetInsertTestL(KRowSetTypes[i1], KAccessModes[i2], KCommitTypes[i3]);
sl@0
   636
				DestroyDatabase();
sl@0
   637
				}
sl@0
   638
			}
sl@0
   639
		}
sl@0
   640
	}
sl@0
   641
sl@0
   642
/**
sl@0
   643
@SYMTestCaseID          SYSLIB-DBMS-UT-3312
sl@0
   644
@SYMTestCaseDesc        DBMS, RDbView performance tests.
sl@0
   645
@SYMTestPriority        High
sl@0
   646
@SYMTestActions        	The test measures the time used by updatable cursor to:
sl@0
   647
						- update (moving forward/backward) certain amount of records, comitting after each update;
sl@0
   648
						- update (moving forward/backward) certain amount of records, comitting after 20 update;
sl@0
   649
						- update (moving forward/backward) certain amount of records, comitting at the end;
sl@0
   650
						All cases repeated with and without compaction (except the first one).
sl@0
   651
						The execution times are printed out.
sl@0
   652
@SYMTestExpectedResults Test must not fail
sl@0
   653
@SYMREQ                 REQ7141
sl@0
   654
*/
sl@0
   655
void UpdateTestsL()
sl@0
   656
	{
sl@0
   657
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3312 RDbView \"update\" performance tests")); 	
sl@0
   658
	for(TInt i1=0;i1<COUNT_OF(KRowSetTypes);++i1)
sl@0
   659
		{
sl@0
   660
		for(TInt i2=0;i2<COUNT_OF(KUpdDirectionTypes);++i2)
sl@0
   661
			{
sl@0
   662
			for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
sl@0
   663
				{
sl@0
   664
				CreateAndFillDatabase();
sl@0
   665
				TBuf<200> title;
sl@0
   666
				title.Copy(_L("Update."));
sl@0
   667
				title.Append(KRowSetTypeStr[i1]);
sl@0
   668
				title.Append(KUpdDirectionTypeStr[i2]);
sl@0
   669
				title.Append(KCommitTypeStr[i3]);
sl@0
   670
				TheTest.Printf(title);
sl@0
   671
				DbRowSetUpdateTestL(KRowSetTypes[i1], KUpdDirectionTypes[i2], KCommitTypes[i3]);
sl@0
   672
				DestroyDatabase();
sl@0
   673
				}
sl@0
   674
			}
sl@0
   675
		}
sl@0
   676
	}
sl@0
   677
sl@0
   678
/**
sl@0
   679
@SYMTestCaseID          SYSLIB-DBMS-UT-3313
sl@0
   680
@SYMTestCaseDesc        DBMS, RDbDatabase::Execute() performance tests.
sl@0
   681
@SYMTestPriority        High
sl@0
   682
@SYMTestActions        	The test measures the time used by RDbDatabase::Execute() to:
sl@0
   683
						- insert certain amount of records, comitting after each insert;
sl@0
   684
						- insert certain amount of records, comitting after 20 inserts;
sl@0
   685
						- insert certain amount of records, comitting at the end;
sl@0
   686
						All cases repeated with and without compaction (except the first one).
sl@0
   687
						The execution times are printed out.
sl@0
   688
@SYMTestExpectedResults Test must not fail
sl@0
   689
@SYMREQ                 REQ7141
sl@0
   690
*/
sl@0
   691
void DbInsertTestsL()
sl@0
   692
	{
sl@0
   693
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3313 RDbDatabase::Execute() \"insert\" performance tests")); 	
sl@0
   694
	TBuf<KTextColSize> textColVal;
sl@0
   695
	for(TInt ii=23000;ii<(23000+KTextColSize);++ii)
sl@0
   696
		{
sl@0
   697
		textColVal.Append(TChar(ii));
sl@0
   698
		}
sl@0
   699
	for(TInt compaction=0;compaction<2;++compaction)
sl@0
   700
		{
sl@0
   701
		for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
sl@0
   702
			{
sl@0
   703
			CreateDatabase();
sl@0
   704
			TBuf<200> title;
sl@0
   705
			title.Copy(_L("RDbDatabase::Execute().Insert."));
sl@0
   706
			title.Append(KCommitTypeStr[i3]);
sl@0
   707
			title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No."));
sl@0
   708
			TheTest.Printf(title);
sl@0
   709
			TInt count = 0, err = KErrNone;
sl@0
   710
			TUint32 fc = User::FastCounter();
sl@0
   711
			for(TInt i=0;i<KTestRecordCount;++i)
sl@0
   712
				{
sl@0
   713
				if(KCommitTypes[i3] != ECommit_1_Rec && count == 0)
sl@0
   714
					{
sl@0
   715
					err = TheDatabase.Begin();	
sl@0
   716
					TEST2(err, KErrNone);
sl@0
   717
					}
sl@0
   718
				TBuf<KTextColSize + 100> sql;
sl@0
   719
				sql.Format(_L("INSERT INTO A(I1,I2,I3) VALUES(%d,%d,'%S')"), i, i + 100000, &textColVal);
sl@0
   720
				err = TheDatabase.Execute(sql);
sl@0
   721
				TEST2(err, 1);
sl@0
   722
				if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3])
sl@0
   723
					{
sl@0
   724
					count = 0;
sl@0
   725
					err = TheDatabase.Commit();	
sl@0
   726
					TEST2(err, KErrNone);
sl@0
   727
					if(compaction)
sl@0
   728
						{
sl@0
   729
						err = TheDatabase.Compact();
sl@0
   730
						TEST2(err, KErrNone);
sl@0
   731
						}
sl@0
   732
					}
sl@0
   733
				}
sl@0
   734
			PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   735
			PrintFileSize();
sl@0
   736
			DestroyDatabase();
sl@0
   737
			}
sl@0
   738
		}
sl@0
   739
	}
sl@0
   740
sl@0
   741
/**
sl@0
   742
@SYMTestCaseID          SYSLIB-DBMS-UT-3314
sl@0
   743
@SYMTestCaseDesc        DBMS, RDbDatabase::Execute() performance tests.
sl@0
   744
@SYMTestPriority        High
sl@0
   745
@SYMTestActions        	The test measures the time used by RDbDatabase::Execute() to:
sl@0
   746
						- update certain amount of records, comitting after each update;
sl@0
   747
						- update certain amount of records, comitting after 20 updates;
sl@0
   748
						- update certain amount of records, comitting at the end;
sl@0
   749
						All cases repeated with and without compaction (except the first one).
sl@0
   750
						The execution times are printed out.
sl@0
   751
@SYMTestExpectedResults Test must not fail
sl@0
   752
@SYMREQ                 REQ7141
sl@0
   753
*/
sl@0
   754
void DbUpdateTestsL()
sl@0
   755
	{
sl@0
   756
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-DBMS-UT-3314 RDbDatabase::Execute() \"update\" performance tests")); 	
sl@0
   757
	TBuf<KTextColSize> textColVal;
sl@0
   758
	for(TInt ii=43000;ii<(43000+KTextColSize);++ii)
sl@0
   759
		{
sl@0
   760
		textColVal.Append(TChar(ii));
sl@0
   761
		}
sl@0
   762
	for(TInt compaction=0;compaction<2;++compaction)
sl@0
   763
		{
sl@0
   764
		for(TInt i3=0;i3<COUNT_OF(KCommitTypes);++i3)
sl@0
   765
			{
sl@0
   766
			CreateAndFillDatabase();
sl@0
   767
			TBuf<200> title;
sl@0
   768
			title.Copy(_L("RDbDatabase::Execute().Update."));
sl@0
   769
			title.Append(KCommitTypeStr[i3]);
sl@0
   770
			title.Append(compaction ? _L("Compaction:Yes.") : _L("Compaction:No."));
sl@0
   771
			TheTest.Printf(title);
sl@0
   772
			TInt count = 0, err = KErrNone;
sl@0
   773
			TUint32 fc = User::FastCounter();
sl@0
   774
			for(TInt i=0;i<KTestRecordCount;++i)
sl@0
   775
				{
sl@0
   776
				if(KCommitTypes[i3] != ECommit_1_Rec && count == 0)
sl@0
   777
					{
sl@0
   778
					err = TheDatabase.Begin();	
sl@0
   779
					TEST2(err, KErrNone);
sl@0
   780
					}
sl@0
   781
				TBuf<KTextColSize + 100> sql;
sl@0
   782
				sql.Format(_L("UPDATE A SET I2=%d,I3='%S' WHERE I1=%d"), i + 556622, &textColVal, i);
sl@0
   783
				err = TheDatabase.Execute(sql);
sl@0
   784
				TEST2(err, 1);
sl@0
   785
				if(KCommitTypes[i3] != ECommit_1_Rec && ++count == KCommitTypes[i3])
sl@0
   786
					{
sl@0
   787
					count = 0;
sl@0
   788
					err = TheDatabase.Commit();	
sl@0
   789
					TEST2(err, KErrNone);
sl@0
   790
					if(compaction)
sl@0
   791
						{
sl@0
   792
						err = TheDatabase.Compact();
sl@0
   793
						TEST2(err, KErrNone);
sl@0
   794
						}
sl@0
   795
					}
sl@0
   796
				}
sl@0
   797
			PrintFcDiffAsUs(_L("###RDbDatabase::Execute(), Time=%d us\r\n"), CalcTickDiff(fc, User::FastCounter()));
sl@0
   798
			PrintFileSize();
sl@0
   799
			DestroyDatabase();
sl@0
   800
			}
sl@0
   801
		}
sl@0
   802
	}
sl@0
   803
sl@0
   804
/**
sl@0
   805
@SYMTestCaseID			PDS-DBMS-UT-4010
sl@0
   806
@SYMTestCaseDesc		Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
   807
						Tests the performance of RDbColWriteStream::OpenLC() and RDbColWriteStream::OpenL(). 
sl@0
   808
@SYMTestPriority		High
sl@0
   809
@SYMTestActions			Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase
sl@0
   810
@SYMTestExpectedResults Test must not fail
sl@0
   811
@SYMDEF					DEF141419
sl@0
   812
*/
sl@0
   813
void DbColWriteStreamTestsL()
sl@0
   814
	{
sl@0
   815
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4010 RDbColWriteStream performance test")); 	
sl@0
   816
	
sl@0
   817
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
   818
	TEST2(err, KErrNone);
sl@0
   819
	err = TheDatabase.Execute(KCreateTestTableSql2);
sl@0
   820
	TEST(err >= 0);
sl@0
   821
sl@0
   822
	RDbView view;
sl@0
   823
	err = view.Prepare(TheDatabase, _L("select * from A"), view.EInsertOnly);
sl@0
   824
	TEST2(err, KErrNone);
sl@0
   825
	TheRowSet = view;	
sl@0
   826
sl@0
   827
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
   828
	const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
sl@0
   829
	const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
sl@0
   830
	const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
sl@0
   831
	delete colSet;
sl@0
   832
	
sl@0
   833
	TheTextRndData.SetLength(KColSize2);
sl@0
   834
	TheTextRndData.Fill(KBufChar);
sl@0
   835
	TheBinRndData.SetLength(KColSize2);
sl@0
   836
	TheBinRndData.Fill(KBufChar);
sl@0
   837
sl@0
   838
	err = TheDatabase.Begin();
sl@0
   839
	TEST2(err, KErrNone);
sl@0
   840
	
sl@0
   841
	TUint32 openLcFc = 0;
sl@0
   842
	TUint32 openLFc = 0;
sl@0
   843
	TUint32 fc = User::FastCounter();
sl@0
   844
	
sl@0
   845
	for(TInt i=0;i<KTestRecordCount;++i)
sl@0
   846
		{
sl@0
   847
		TheRowSet.InsertL();
sl@0
   848
		TheRowSet.SetColL(KIdx1, i + 1);
sl@0
   849
		
sl@0
   850
		RDbColWriteStream strm1;
sl@0
   851
		TUint32 tmp = User::FastCounter();
sl@0
   852
		strm1.OpenLC(TheRowSet, KIdx2);
sl@0
   853
		openLcFc += CalcTickDiff(tmp, User::FastCounter());
sl@0
   854
		strm1.WriteL(TheTextRndData, KColSize2);
sl@0
   855
		strm1.CommitL();
sl@0
   856
		CleanupStack::PopAndDestroy(&strm1);
sl@0
   857
sl@0
   858
		RDbColWriteStream strm2;
sl@0
   859
		CleanupClosePushL(strm2);
sl@0
   860
		tmp = User::FastCounter();
sl@0
   861
		strm2.OpenL(TheRowSet, KIdx3);
sl@0
   862
		openLFc += CalcTickDiff(tmp, User::FastCounter());
sl@0
   863
		strm2.WriteL(TheBinRndData, KColSize2);
sl@0
   864
		strm2.CommitL();
sl@0
   865
		CleanupStack::PopAndDestroy(&strm2);
sl@0
   866
		
sl@0
   867
		TheRowSet.PutL();
sl@0
   868
		}
sl@0
   869
	
sl@0
   870
	PrintFcDiffAsUs2(_L("###RDbColWriteStream, write %3d records, Time=%d us\r\n"), 
sl@0
   871
										KTestRecordCount, CalcTickDiff(fc, User::FastCounter()));
sl@0
   872
	PrintFcDiffAsUs (_L("###OpenLC()                            , Time=%d us\r\n"), openLcFc);
sl@0
   873
	PrintFcDiffAsUs (_L("###OpenL()                             , Time=%d us\r\n"), openLFc);
sl@0
   874
	
sl@0
   875
	TheRowSet.Close();
sl@0
   876
	
sl@0
   877
	err = TheDatabase.Commit();
sl@0
   878
	TEST2(err, KErrNone);
sl@0
   879
	
sl@0
   880
	TheDatabase.Close();
sl@0
   881
	}
sl@0
   882
sl@0
   883
/**
sl@0
   884
@SYMTestCaseID			PDS-DBMS-UT-4011
sl@0
   885
@SYMTestCaseDesc		Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
   886
						Tests the performance of RDbColReadStream::OpenLC() and RDbColReadStream::OpenL(). 
sl@0
   887
@SYMTestPriority		High
sl@0
   888
@SYMTestActions			Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
   889
@SYMTestExpectedResults Test must not fail
sl@0
   890
@SYMDEF					DEF141419
sl@0
   891
*/
sl@0
   892
void DbColReadStreamTestsL()
sl@0
   893
	{
sl@0
   894
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4011 RDbColReadStream performance test")); 	
sl@0
   895
	
sl@0
   896
	TInt err = TheDatabase.Open(TheFs, TheDatabaseFileName);
sl@0
   897
	TEST2(err, KErrNone);
sl@0
   898
sl@0
   899
	RDbView view;
sl@0
   900
	err = view.Prepare(TheDatabase, _L("select * from A"), view.EReadOnly);
sl@0
   901
	TEST2(err, KErrNone);
sl@0
   902
	TheRowSet = view;	
sl@0
   903
sl@0
   904
	err = view.EvaluateAll();
sl@0
   905
	TEST2(err, KErrNone);
sl@0
   906
	
sl@0
   907
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
   908
	const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
sl@0
   909
	const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
sl@0
   910
	const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
sl@0
   911
	delete colSet;
sl@0
   912
sl@0
   913
	TBuf8<KColSize2> binData;
sl@0
   914
	TBuf16<KColSize2> textData;
sl@0
   915
	
sl@0
   916
	TInt recCnt = 0;
sl@0
   917
	TUint32 openLcFc = 0;
sl@0
   918
	TUint32 openLFc = 0;
sl@0
   919
	TUint32 fc = User::FastCounter();
sl@0
   920
sl@0
   921
	if(TheRowSet.FirstL())
sl@0
   922
		{
sl@0
   923
		do
sl@0
   924
			{
sl@0
   925
			TheRowSet.GetL();
sl@0
   926
			++recCnt;
sl@0
   927
			
sl@0
   928
			TInt i1 = TheRowSet.ColInt(KIdx1);
sl@0
   929
			TEST2(recCnt, i1);
sl@0
   930
			
sl@0
   931
			RDbColReadStream strm1;
sl@0
   932
			TUint32 tmp = User::FastCounter();
sl@0
   933
			strm1.OpenLC(TheRowSet, KIdx2);
sl@0
   934
			openLcFc += CalcTickDiff(tmp, User::FastCounter());
sl@0
   935
			strm1.ReadL(textData, KColSize2);
sl@0
   936
			CleanupStack::PopAndDestroy(&strm1);
sl@0
   937
			TEST(textData == TheTextRndData);
sl@0
   938
				
sl@0
   939
			RDbColReadStream strm2;
sl@0
   940
			CleanupClosePushL(strm2);
sl@0
   941
			tmp = User::FastCounter();
sl@0
   942
			strm2.OpenL(TheRowSet, KIdx3);
sl@0
   943
			openLFc += CalcTickDiff(tmp, User::FastCounter());
sl@0
   944
			strm2.ReadL(binData, KColSize2);
sl@0
   945
			CleanupStack::PopAndDestroy(&strm2);
sl@0
   946
			TEST(binData == TheBinRndData);
sl@0
   947
			} while(TheRowSet.NextL());
sl@0
   948
		}
sl@0
   949
	TEST2(recCnt, KTestRecordCount);
sl@0
   950
	
sl@0
   951
	PrintFcDiffAsUs2(_L("###RDbColReadStream, read %3d records, Time=%d us\r\n"), 
sl@0
   952
			                                 recCnt, CalcTickDiff(fc, User::FastCounter()));
sl@0
   953
	PrintFcDiffAsUs (_L("###OpenLC()                          , Time=%d us\r\n"), openLcFc);
sl@0
   954
	PrintFcDiffAsUs (_L("###OpenL()                           , Time=%d us\r\n"), openLFc);
sl@0
   955
	
sl@0
   956
	TheRowSet.Close();
sl@0
   957
	
sl@0
   958
	TheDatabase.Close();
sl@0
   959
	}
sl@0
   960
sl@0
   961
/**
sl@0
   962
@SYMTestCaseID			PDS-DBMS-UT-4012
sl@0
   963
@SYMTestCaseDesc		Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
   964
						RDbUpdate performance tests.
sl@0
   965
@SYMTestPriority		High
sl@0
   966
@SYMTestActions			Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase
sl@0
   967
@SYMTestExpectedResults Test must not fail
sl@0
   968
@SYMDEF					DEF141419
sl@0
   969
*/
sl@0
   970
void DbUpdateTestL()
sl@0
   971
	{
sl@0
   972
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4012 RDbUpdate performance test")); 	
sl@0
   973
	
sl@0
   974
	TInt err = TheDbs.Connect();
sl@0
   975
	TEST2(err, KErrNone);
sl@0
   976
		
sl@0
   977
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
sl@0
   978
	TEST2(err, KErrNone);
sl@0
   979
	
sl@0
   980
	TUint32 execFc = 0;
sl@0
   981
	TUint32 nextFc = 0;
sl@0
   982
	TUint32 rowCntFc = 0;
sl@0
   983
	
sl@0
   984
	//Synchronous update
sl@0
   985
	TInt recCnt = 0;
sl@0
   986
	RDbUpdate upd1;
sl@0
   987
	TUint32 fc = User::FastCounter();
sl@0
   988
	err = upd1.Execute(TheDatabase, _L("UPDATE A SET I1=1000, I2='8888888888888888'"));
sl@0
   989
	execFc = CalcTickDiff(fc, User::FastCounter());
sl@0
   990
	TEST2(err, KErrNone);
sl@0
   991
	TUint32 tmp = User::FastCounter();
sl@0
   992
	while((err = upd1.Next()) > 0)
sl@0
   993
		{
sl@0
   994
		}
sl@0
   995
	nextFc = CalcTickDiff(tmp, User::FastCounter());
sl@0
   996
	tmp = User::FastCounter();
sl@0
   997
	recCnt = upd1.RowCount();
sl@0
   998
	rowCntFc = CalcTickDiff(tmp, User::FastCounter());
sl@0
   999
	upd1.Close();
sl@0
  1000
	fc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1001
	TEST2(err, 0);
sl@0
  1002
	TEST2(recCnt, KTestRecordCount);
sl@0
  1003
	
sl@0
  1004
	TheDatabase.Close();
sl@0
  1005
sl@0
  1006
	PrintFcDiffAsUs2(_L("###Sync RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc);
sl@0
  1007
	PrintFcDiffAsUs (_L("###Execute()                  , Time=%d us\r\n"), execFc);
sl@0
  1008
	PrintFcDiffAsUs (_L("###Next()                     , Time=%d us\r\n"), nextFc);
sl@0
  1009
	PrintFcDiffAsUs (_L("###RowCount()                 , Time=%d us\r\n"), rowCntFc);
sl@0
  1010
	
sl@0
  1011
	//Asynchronous update
sl@0
  1012
	err = TheDatabase.Open(TheDbs, TheDatabaseFileName);
sl@0
  1013
	TEST2(err, KErrNone);
sl@0
  1014
	
sl@0
  1015
	execFc = 0;
sl@0
  1016
	nextFc = 0;
sl@0
  1017
	rowCntFc = 0;
sl@0
  1018
	recCnt = 0;
sl@0
  1019
	
sl@0
  1020
	RDbUpdate upd2;
sl@0
  1021
	fc = User::FastCounter();
sl@0
  1022
	err = upd2.Execute(TheDatabase, _L("UPDATE A SET I1=5678, I2='9w27u22272252542r2242242424221'"));
sl@0
  1023
	execFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1024
	TEST2(err, KErrNone);
sl@0
  1025
	TRequestStatus stat;
sl@0
  1026
	tmp = User::FastCounter();
sl@0
  1027
	do
sl@0
  1028
		{
sl@0
  1029
		upd2.Next(stat);
sl@0
  1030
		User::WaitForRequest(stat);
sl@0
  1031
		} while(stat.Int() > 0);
sl@0
  1032
	nextFc = CalcTickDiff(tmp, User::FastCounter());
sl@0
  1033
	tmp = User::FastCounter();
sl@0
  1034
	recCnt = upd2.RowCount();
sl@0
  1035
	rowCntFc = CalcTickDiff(tmp, User::FastCounter());
sl@0
  1036
	upd2.Close();
sl@0
  1037
	fc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1038
	TEST2(stat.Int(), 0);
sl@0
  1039
	TEST2(recCnt, KTestRecordCount);
sl@0
  1040
sl@0
  1041
	TheDatabase.Close();
sl@0
  1042
	
sl@0
  1043
	PrintFcDiffAsUs2(_L("###Async RDbUpdate, %3d records, Time=%d us\r\n"), recCnt, fc);
sl@0
  1044
	PrintFcDiffAsUs (_L("###Execute()                   , Time=%d us\r\n"), execFc);
sl@0
  1045
	PrintFcDiffAsUs (_L("###Next()                      , Time=%d us\r\n"), nextFc);
sl@0
  1046
	PrintFcDiffAsUs (_L("###RowCount()                  , Time=%d us\r\n"), rowCntFc);
sl@0
  1047
	
sl@0
  1048
	TheDbs.Close();
sl@0
  1049
	err = TheFs.Delete(TheDatabaseFileName);
sl@0
  1050
	TEST2(err, KErrNone);
sl@0
  1051
	}
sl@0
  1052
sl@0
  1053
/**
sl@0
  1054
@SYMTestCaseID			PDS-DBMS-UT-4013
sl@0
  1055
@SYMTestCaseDesc		Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
  1056
						RDbStoreDatabase performance tests.
sl@0
  1057
@SYMTestPriority		High
sl@0
  1058
@SYMTestActions			Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
  1059
@SYMTestExpectedResults Test must not fail
sl@0
  1060
@SYMDEF					DEF141419
sl@0
  1061
*/
sl@0
  1062
void DbStoreDatabaseTestL()
sl@0
  1063
	{
sl@0
  1064
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4013 RDbStoreDatabase performance test")); 	
sl@0
  1065
	
sl@0
  1066
	CFileStore* fstore = CPermanentFileStore::ReplaceLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite);
sl@0
  1067
	fstore->SetTypeL(fstore->Layout());
sl@0
  1068
	
sl@0
  1069
	//Create the database, insert records, compress the store.
sl@0
  1070
	
sl@0
  1071
	RDbStoreDatabase db1;
sl@0
  1072
	CleanupClosePushL(db1);
sl@0
  1073
	TUint32 fc = User::FastCounter();
sl@0
  1074
	TStreamId strmId = db1.CreateL(fstore);
sl@0
  1075
	TUint32 createFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1076
	
sl@0
  1077
	TInt err = db1.Execute(KCreateTestTableSql2);
sl@0
  1078
	TEST(err >= 0);
sl@0
  1079
	err = db1.Begin();
sl@0
  1080
	TEST2(err, 0);
sl@0
  1081
	for(TInt i=0;i<KTestRecordCount;++i)
sl@0
  1082
		{
sl@0
  1083
		err = db1.Execute(_L("INSERT INTO A(I1, I2) VALUES(1, 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA')"));
sl@0
  1084
		TEST2(err, 1);
sl@0
  1085
		}
sl@0
  1086
	err = db1.Commit();
sl@0
  1087
	TEST2(err, 0);
sl@0
  1088
sl@0
  1089
	CleanupStack::PopAndDestroy(&db1);
sl@0
  1090
	TUint32 writeFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1091
	
sl@0
  1092
	TInt fsize1 = 0;
sl@0
  1093
	err = fstore->File().Size(fsize1);
sl@0
  1094
	TEST2(err, KErrNone);
sl@0
  1095
	
sl@0
  1096
	fc = User::FastCounter();
sl@0
  1097
	RDbStoreDatabase::CompressL(*fstore, strmId);
sl@0
  1098
	TUint32 compressFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1099
sl@0
  1100
	TInt fsize2 = 0;
sl@0
  1101
	err = fstore->File().Size(fsize2);
sl@0
  1102
	TEST2(err, KErrNone);
sl@0
  1103
	
sl@0
  1104
	CleanupStack::PopAndDestroy(fstore);
sl@0
  1105
	
sl@0
  1106
	PrintFcDiffAsUs2(_L("###RDbStoreDatabase, write %3d records, Time=%d us\r\n"), KTestRecordCount, writeFc);
sl@0
  1107
	PrintFcDiffAsUs (_L("###CreateL()                          , Time=%d us\r\n"), createFc);
sl@0
  1108
	PrintFcDiffAsUs (_L("###CompressL()                        , Time=%d us\r\n"), compressFc);
sl@0
  1109
	
sl@0
  1110
	//Decompress the store, open the database, read the records
sl@0
  1111
sl@0
  1112
	fstore = CPermanentFileStore::OpenLC(TheFs, TheDatabaseFileName, EFileRead | EFileWrite);
sl@0
  1113
	fstore->SetTypeL(fstore->Layout());
sl@0
  1114
	
sl@0
  1115
	fc = User::FastCounter();
sl@0
  1116
	RDbStoreDatabase::DecompressL(*fstore, strmId);
sl@0
  1117
	TUint32 decompressFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1118
sl@0
  1119
	TInt fsize3 = 0;
sl@0
  1120
	err = fstore->File().Size(fsize3);
sl@0
  1121
	TEST2(err, KErrNone);
sl@0
  1122
	
sl@0
  1123
	RDbStoreDatabase db2;
sl@0
  1124
	CleanupClosePushL(db2);
sl@0
  1125
	fc = User::FastCounter();
sl@0
  1126
	db2.OpenL(fstore, strmId);
sl@0
  1127
	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1128
	
sl@0
  1129
	RDbView view;
sl@0
  1130
	err = view.Prepare(db2, _L("SELECT * FROM A"));
sl@0
  1131
	TEST2(err, KErrNone);
sl@0
  1132
	err = view.EvaluateAll();
sl@0
  1133
	TEST2(err, KErrNone);	
sl@0
  1134
	TheRowSet = view;
sl@0
  1135
	
sl@0
  1136
	CDbColSet* colSet = TheRowSet.ColSetL();
sl@0
  1137
	const TDbColNo KIdx1 = colSet->ColNo(_L("I1"));
sl@0
  1138
	const TDbColNo KIdx2 = colSet->ColNo(_L("I2"));
sl@0
  1139
	const TDbColNo KIdx3 = colSet->ColNo(_L("I3"));
sl@0
  1140
	delete colSet;
sl@0
  1141
sl@0
  1142
	TInt recCnt = 0;
sl@0
  1143
	if(TheRowSet.FirstL())
sl@0
  1144
		{
sl@0
  1145
		do
sl@0
  1146
			{
sl@0
  1147
			TheRowSet.GetL();
sl@0
  1148
			++recCnt;
sl@0
  1149
			
sl@0
  1150
			RDbColReadStream strm1;
sl@0
  1151
			strm1.OpenLC(TheRowSet, KIdx2);
sl@0
  1152
			TBuf<KColSize2> buf;
sl@0
  1153
			_LIT(KText, "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAA");//the same as the used in the INSERT statement above
sl@0
  1154
			strm1.ReadL(buf, KText().Length());
sl@0
  1155
			CleanupStack::PopAndDestroy(&strm1);
sl@0
  1156
			TEST(KText() == buf);
sl@0
  1157
			} while(TheRowSet.NextL());
sl@0
  1158
		}
sl@0
  1159
	TEST2(recCnt, KTestRecordCount);
sl@0
  1160
	
sl@0
  1161
	TheRowSet.Close();
sl@0
  1162
	TUint32 readFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1163
	
sl@0
  1164
	CleanupStack::PopAndDestroy(&db2);
sl@0
  1165
	CleanupStack::PopAndDestroy(fstore);
sl@0
  1166
	
sl@0
  1167
	PrintFcDiffAsUs2(_L("###RDbStoreDatabase, read %3d records , Time=%d us\r\n"), recCnt, readFc);
sl@0
  1168
	PrintFcDiffAsUs (_L("###OpenL()                            , Time=%d us\r\n"), openFc);
sl@0
  1169
	PrintFcDiffAsUs (_L("###DecompressL()                      , Time=%d us\r\n"), decompressFc);
sl@0
  1170
	TheTest.Printf(_L("###File size. After write: %d. After Compress(): %d. After Decompress(): %d\r\n"), fsize1, fsize2, fsize3);
sl@0
  1171
	
sl@0
  1172
	err = TheFs.Delete(TheDatabaseFileName);
sl@0
  1173
	TEST2(err, KErrNone);
sl@0
  1174
	}
sl@0
  1175
sl@0
  1176
/**
sl@0
  1177
@SYMTestCaseID			PDS-DBMS-UT-4014
sl@0
  1178
@SYMTestCaseDesc		Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
  1179
						RDbDatabase performance tests.
sl@0
  1180
@SYMTestPriority		High
sl@0
  1181
@SYMTestActions			Test for DEF141419 - DBMS, new performance tests - RDbUpdate, RDbStoreDatabase.
sl@0
  1182
@SYMTestExpectedResults Test must not fail
sl@0
  1183
@SYMDEF					DEF141419
sl@0
  1184
*/
sl@0
  1185
void DbDatabaseTestL()
sl@0
  1186
	{
sl@0
  1187
	TheTest.Next(_L(" @SYMTestCaseID:PDS-DBMS-UT-4014 RDbDatabase performance test")); 	
sl@0
  1188
	
sl@0
  1189
	TInt err = TheDatabase.Replace(TheFs, TheDatabaseFileName);
sl@0
  1190
	TEST2(err, KErrNone);
sl@0
  1191
	
sl@0
  1192
	//CDbColSet
sl@0
  1193
	_LIT(KColName1, "Col1");
sl@0
  1194
	_LIT(KColName2, "Col2");
sl@0
  1195
	_LIT(KColName3, "Col3");
sl@0
  1196
	TUint32 fc = User::FastCounter();
sl@0
  1197
	CDbColSet* colset = CDbColSet::NewLC();
sl@0
  1198
	TDbCol col1(KColName1, EDbColInt32);
sl@0
  1199
	colset->AddL(col1);
sl@0
  1200
	TDbCol col2(KColName2, EDbColText16, 100);
sl@0
  1201
	colset->AddL(col2);
sl@0
  1202
	TDbCol col3(KColName3, EDbColBinary, 100);
sl@0
  1203
	colset->AddL(col3);
sl@0
  1204
	TUint32 colSetFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1205
	PrintFcDiffAsUs(_L("###CDbColSet::NewLC() & CDbColSet::AddL(), Time=%d us\r\n"), colSetFc);
sl@0
  1206
	
sl@0
  1207
	//RDbDatabase::CreateTable()
sl@0
  1208
	_LIT(KTblName, "ATbl");
sl@0
  1209
	fc = User::FastCounter();
sl@0
  1210
	err = TheDatabase.CreateTable(KTblName, *colset);
sl@0
  1211
	TUint32 createTblFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1212
	TEST2(err, KErrNone);
sl@0
  1213
	PrintFcDiffAsUs(_L("###RDbDatabase::CreateTable(), Time=%d us\r\n"), createTblFc);
sl@0
  1214
	
sl@0
  1215
	//RDbDatabase::AlterTable()
sl@0
  1216
	_LIT(KColName4, "Col4");
sl@0
  1217
	TDbCol col4(KColName4, EDbColReal64);
sl@0
  1218
	colset->AddL(col4);
sl@0
  1219
	fc = User::FastCounter();
sl@0
  1220
	err = TheDatabase.AlterTable(KTblName, *colset);
sl@0
  1221
	TUint32 alterTblFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1222
	TEST2(err, KErrNone);
sl@0
  1223
	PrintFcDiffAsUs(_L("###RDbDatabase::AlterTable(), Time=%d us\r\n"), alterTblFc);
sl@0
  1224
sl@0
  1225
	//CDbKey
sl@0
  1226
	fc = User::FastCounter();
sl@0
  1227
	CDbKey* dbKey = CDbKey::NewLC();
sl@0
  1228
	TDbKeyCol keyCol1(KColName1, TDbKeyCol::EAsc);
sl@0
  1229
	dbKey->AddL(keyCol1);
sl@0
  1230
	TDbKeyCol keyCol2(KColName4, TDbKeyCol::EDesc);
sl@0
  1231
	dbKey->AddL(keyCol2);
sl@0
  1232
	TUint32 dbKeyFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1233
	PrintFcDiffAsUs(_L("###CDbKey::NewLC() & CDbKey::AddL(), Time=%d us\r\n"), dbKeyFc);
sl@0
  1234
	
sl@0
  1235
	//RDbDatabase::CreateIndex()
sl@0
  1236
	_LIT(KKeyName, "AKey");
sl@0
  1237
	fc = User::FastCounter();
sl@0
  1238
	err = TheDatabase.CreateIndex(KKeyName, KTblName, *dbKey);
sl@0
  1239
	TUint32 createIndexFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1240
	TEST2(err, KErrNone);
sl@0
  1241
	PrintFcDiffAsUs(_L("###RDbDatabase::CreateIndex(), Time=%d us\r\n"), createIndexFc);
sl@0
  1242
	
sl@0
  1243
	CleanupStack::PopAndDestroy(dbKey);
sl@0
  1244
	CleanupStack::PopAndDestroy(colset);
sl@0
  1245
	
sl@0
  1246
	//RDbDatabase::TableNamesL()
sl@0
  1247
	fc = User::FastCounter();
sl@0
  1248
	CDbTableNames* tblNames = TheDatabase.TableNamesL();
sl@0
  1249
	TUint32 tblNamesFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1250
	delete tblNames;
sl@0
  1251
	PrintFcDiffAsUs(_L("###RDbDatabase::TableNamesL(), Time=%d us\r\n"), tblNamesFc);
sl@0
  1252
	
sl@0
  1253
	//RDbDatabase::IndexNamesL()
sl@0
  1254
	fc = User::FastCounter();
sl@0
  1255
	CDbIndexNames* idxNames = TheDatabase.IndexNamesL(KTblName);
sl@0
  1256
	TUint32 idxNamesFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1257
	delete idxNames;
sl@0
  1258
	PrintFcDiffAsUs(_L("###RDbDatabase::IndexNamesL(), Time=%d us\r\n"), idxNamesFc);
sl@0
  1259
sl@0
  1260
	//RDbDatabase::ColSetL()
sl@0
  1261
	fc = User::FastCounter();
sl@0
  1262
	colset = TheDatabase.ColSetL(KTblName);
sl@0
  1263
	colSetFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1264
	delete colset;
sl@0
  1265
	PrintFcDiffAsUs(_L("###RDbDatabase::ColSetL(), Time=%d us\r\n"), colSetFc);
sl@0
  1266
	
sl@0
  1267
	//RDbDatabase::KeyL()
sl@0
  1268
	fc = User::FastCounter();
sl@0
  1269
	dbKey =  TheDatabase.KeyL(KKeyName, KTblName);
sl@0
  1270
	dbKeyFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1271
	delete dbKey;
sl@0
  1272
	PrintFcDiffAsUs(_L("###RDbDatabase::KeyL(), Time=%d us\r\n"), dbKeyFc);
sl@0
  1273
sl@0
  1274
	//RDbDatabase::DropIndex()
sl@0
  1275
	fc = User::FastCounter();
sl@0
  1276
	err = TheDatabase.DropIndex(KKeyName, KTblName);
sl@0
  1277
	TUint32 dropIdxFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1278
	TEST2(err, KErrNone);
sl@0
  1279
	PrintFcDiffAsUs(_L("###RDbDatabase::DropIndex(), Time=%d us\r\n"), dropIdxFc);
sl@0
  1280
	
sl@0
  1281
	//RDbDatabase::DropTable()
sl@0
  1282
	fc = User::FastCounter();
sl@0
  1283
	err = TheDatabase.DropTable(KTblName);
sl@0
  1284
	TUint32 dropTblFc = CalcTickDiff(fc, User::FastCounter());
sl@0
  1285
	TEST2(err, KErrNone);
sl@0
  1286
	PrintFcDiffAsUs(_L("###RDbDatabase::DropTable(), Time=%d us\r\n"), dropTblFc);
sl@0
  1287
	
sl@0
  1288
	TheDatabase.Close();
sl@0
  1289
	}
sl@0
  1290
sl@0
  1291
void PrintDiskUsage(const TDesC& aPath, TInt aOffset = 0)
sl@0
  1292
	{
sl@0
  1293
	_LIT(KSpace, " ");
sl@0
  1294
	TheTest.Printf(_L("%*.*S%S\r\n"), aOffset, aOffset, &KSpace, &aPath);
sl@0
  1295
	TFindFile* findFile = new TFindFile(TheFs);//TFindFile has TParse data member. 
sl@0
  1296
											   //Since this function is called recoursively, on some platforms
sl@0
  1297
											   //the test might crash - "stack overflow" problem.
sl@0
  1298
	TEST(findFile != NULL);
sl@0
  1299
	CDir* fileNameCol = NULL;
sl@0
  1300
	TBuf<8> fileNameMask;
sl@0
  1301
	fileNameMask.Copy(_L("*.*"));
sl@0
  1302
	TInt err = findFile->FindWildByDir(fileNameMask, aPath, fileNameCol);
sl@0
  1303
	if(err == KErrNone)
sl@0
  1304
		{
sl@0
  1305
		do
sl@0
  1306
			{
sl@0
  1307
			const TDesC& file = findFile->File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case.
sl@0
  1308
			(void)TheParse.Set(file, NULL, NULL);
sl@0
  1309
			TPtrC driveName = TheParse.Drive();
sl@0
  1310
			if(aPath.FindF(driveName) >= 0)
sl@0
  1311
				{		
sl@0
  1312
                TInt cnt = fileNameCol->Count();
sl@0
  1313
                for(TInt i=0;i<cnt;++i)
sl@0
  1314
                    {
sl@0
  1315
                    const ::TEntry& entry = (*fileNameCol)[i];
sl@0
  1316
                    if(!entry.IsDir())
sl@0
  1317
                        {
sl@0
  1318
                        TheTest.Printf(_L("%*.*S    %S, size=%d\r\n"), aOffset, aOffset, &KSpace, &entry.iName, entry.iSize);
sl@0
  1319
                        }
sl@0
  1320
                    else
sl@0
  1321
                        {
sl@0
  1322
						TFileName* path = new TFileName;//allocated in heap to prevent "stack overflow" prolem
sl@0
  1323
						TEST(path != NULL);
sl@0
  1324
						path->Copy(aPath);
sl@0
  1325
						path->Append(entry.iName);
sl@0
  1326
						path->Append(_L("\\"));
sl@0
  1327
                        PrintDiskUsage(*path, aOffset + 4);
sl@0
  1328
                        delete path;
sl@0
  1329
                        }
sl@0
  1330
                    }
sl@0
  1331
				} // if(aPath.FindF(driveName) >= 0)
sl@0
  1332
			
sl@0
  1333
			delete fileNameCol;
sl@0
  1334
			fileNameCol = NULL;
sl@0
  1335
			} while((err = findFile->FindWild(fileNameCol)) == KErrNone);//Get the next set of files
sl@0
  1336
		}
sl@0
  1337
	else
sl@0
  1338
		{
sl@0
  1339
		TheTest.Printf(_L("  FindWildByDir() failed with err=%d\r\n"), err);
sl@0
  1340
		}
sl@0
  1341
	delete findFile;
sl@0
  1342
	}
sl@0
  1343
sl@0
  1344
void DoTestL()
sl@0
  1345
	{
sl@0
  1346
	GetFastCounterFrequency();
sl@0
  1347
sl@0
  1348
	FileBlockSizeTestsL();
sl@0
  1349
sl@0
  1350
	RecordLenTestL();
sl@0
  1351
sl@0
  1352
	InsertTestsL();
sl@0
  1353
sl@0
  1354
	UpdateTestsL();
sl@0
  1355
sl@0
  1356
	DbInsertTestsL();
sl@0
  1357
sl@0
  1358
	DbUpdateTestsL();
sl@0
  1359
sl@0
  1360
	DbColWriteStreamTestsL();
sl@0
  1361
sl@0
  1362
	DbColReadStreamTestsL();
sl@0
  1363
sl@0
  1364
	DbUpdateTestL();
sl@0
  1365
sl@0
  1366
	DbStoreDatabaseTestL();
sl@0
  1367
sl@0
  1368
	DbDatabaseTestL();
sl@0
  1369
	}
sl@0
  1370
sl@0
  1371
//Usage: "t_dbperf2 [<drive letter>:]"
sl@0
  1372
TInt E32Main()
sl@0
  1373
    {
sl@0
  1374
	TheTest.Title();
sl@0
  1375
	
sl@0
  1376
	TheTrapCleanup = CTrapCleanup::New();
sl@0
  1377
	TEST(TheTrapCleanup != NULL);
sl@0
  1378
	
sl@0
  1379
	//Construct test database file name
sl@0
  1380
	_LIT(KTestDatabase, "c:\\dbms-tst\\t_dbperf2.db");
sl@0
  1381
	TFileName fname;
sl@0
  1382
	User::CommandLine(fname);
sl@0
  1383
	TParse parse;
sl@0
  1384
	parse.Set(fname, &KTestDatabase, 0);
sl@0
  1385
	const TDesC& dbFilePath = parse.FullName();
sl@0
  1386
	TheDatabaseFileName.Copy(dbFilePath);
sl@0
  1387
	TheTest.Printf(_L("Test database: %S\r\n"), &TheDatabaseFileName);
sl@0
  1388
	//Construct test file name
sl@0
  1389
	_LIT(KTestFile, "c:\\dbms-tst\\t_dbperf2.dat");
sl@0
  1390
	parse.Set(fname, &KTestFile, 0);
sl@0
  1391
	const TDesC& testFilePath = parse.FullName();
sl@0
  1392
	TheTestFileName.Copy(testFilePath);
sl@0
  1393
sl@0
  1394
	__UHEAP_MARK;
sl@0
  1395
sl@0
  1396
	TInt err = TheFs.Connect();
sl@0
  1397
	TEST2(err, KErrNone);
sl@0
  1398
	err = TheFs.MkDir(TheDatabaseFileName);
sl@0
  1399
	TheTest.Printf(_L("MkDir(): err=%d\r\n"), err);
sl@0
  1400
	TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
  1401
sl@0
  1402
	DeleteFile(TheDatabaseFileName);
sl@0
  1403
	TRAP(err, DoTestL());
sl@0
  1404
	DeleteFile(TheDatabaseFileName);
sl@0
  1405
	DeleteFile(TheTestFileName);
sl@0
  1406
	TEST2(err, KErrNone);
sl@0
  1407
sl@0
  1408
	TheTest.Printf(_L("====================== Disk usage ==================\r\n"));
sl@0
  1409
	PrintDiskUsage(_L("c:\\"));
sl@0
  1410
	TheTest.Printf(_L("====================================================\r\n"));
sl@0
  1411
	
sl@0
  1412
	CloseAll();
sl@0
  1413
sl@0
  1414
	__UHEAP_MARKEND;
sl@0
  1415
sl@0
  1416
	TheTest.End();
sl@0
  1417
	TheTest.Close();
sl@0
  1418
	
sl@0
  1419
	delete TheTrapCleanup;
sl@0
  1420
	return KErrNone;
sl@0
  1421
    }