persistentstorage/sql/TEST/t_sqlperformance3.cpp
branchRCL_3
changeset 15 fcc16690f446
parent 0 08ec8eefde2f
equal deleted inserted replaced
14:04ec7606545c 15:fcc16690f446
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15 #include <e32test.h>
    15 #include <e32test.h>
    16 #include <e32math.h>
    16 #include <e32math.h>
    17 #include <bautils.h>
    17 #include <bautils.h>
    18 #include <hal.h>
    18 #include <hal.h>
    19 #include <sqldb.h>
    19 #include <sqldb.h>
       
    20 #include "t_sqlcmdlineutil.h"
    20 
    21 
    21 RTest 			TheTest(_L("t_sqlperformance3 test"));
    22 RTest 			TheTest(_L("t_sqlperformance3 test"));
    22 RSqlDatabase 	TheDb;
    23 RSqlDatabase 	TheDb;
    23 
    24 
    24 _LIT(KDbName, 	"c:\\test\\t_sqlperformance3.db");
    25 _LIT(KDbName, 	"c:\\test\\t_sqlperformance3.db");
    25 
    26 
    26 TFileName		TheDbFileName;
    27 TFileName		TheDbFileName;
    27 TBuf<256>  		TheCmd;
    28 TBuf<200> 		TheTestTitle;
    28 TDriveName 		TheDriveName;
    29 TCmdLineParams 	TheCmdLineParams(TCmdLineParams::EDbUtf16, 4096, 10000);
    29 TParse     		TheParse;
    30 TBuf8<200> 		TheSqlConfigString;
       
    31 
       
    32 _LIT(KUtf8,  "UTF8 ");
       
    33 _LIT(KUtf16, "UTF16");
    30 
    34 
    31 TInt TheFastCounterFreq = 0;
    35 TInt TheFastCounterFreq = 0;
    32 
    36 
    33 const TInt KItemCnt = 1000;
    37 const TInt KItemCnt = 1000;
    34 const TInt KItemBlockSize = 100;
    38 const TInt KItemBlockSize = 100;
   154 TInt TheHarvestUpdateObjTime = 0;
   158 TInt TheHarvestUpdateObjTime = 0;
   155 //=============================================================================
   159 //=============================================================================
   156 
   160 
   157 void DoCreateDbFile()
   161 void DoCreateDbFile()
   158 	{
   162 	{
   159 	_LIT8(KConfig, "page_size=4096;cache_size=10000;");
   163 	TUint32 fc1 = User::FastCounter();
   160 	TUint32 fc1 = User::FastCounter();
   164     TInt err = TheDb.Create(TheDbFileName, &TheSqlConfigString);
   161     TInt err = TheDb.Create(TheDbFileName, &KConfig);
       
   162     if(err != KErrNone)
   165     if(err != KErrNone)
   163     	{
   166     	{
   164     	if(err == KErrAlreadyExists)
   167     	if(err == KErrAlreadyExists)
   165     		{
   168     		{
   166     		err = TheDb.Open(TheDbFileName, &KConfig);
   169     		err = TheDb.Open(TheDbFileName, &TheSqlConfigString);
   167     		if(err == KErrNone)
   170     		if(err == KErrNone)
   168     			{
   171     			{
   169     			TUint32 fc2 = User::FastCounter();
   172     			TUint32 fc2 = User::FastCounter();
   170     			TheCreateDbCreateConnTime += TimeDiffUs(fc1, fc2);
   173     			TheCreateDbCreateConnTime += TimeDiffUs(fc1, fc2);
   171     			}
   174     			}
  1078 
  1081 
  1079 void DoTestsL()
  1082 void DoTestsL()
  1080 	{
  1083 	{
  1081 	CalcIterationsCount();
  1084 	CalcIterationsCount();
  1082 	
  1085 	
  1083 	TheTest.Start(_L("@SYMTestCaseID:PDS-SQL-UT-4149 Create database"));
  1086 	TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-UT-4149 Create database, encoding: \"%S\", page size: %d\r\n"), 
       
  1087 			TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
       
  1088 	TheTest.Start(TheTestTitle);
  1084 	CreateDb();
  1089 	CreateDb();
  1085 
  1090 
  1086 	TBuf<80> buf;
  1091 	TheTestTitle.Format(_L("@SYMTestCaseID:PDS-SQL-UT-4150 Harvest %d items, encoding: \"%S\", page size: %d\r\n"), 
  1087 	buf.Format(_L("@SYMTestCaseID:PDS-SQL-UT-4150 Harvest %d items"), KItemCnt);
  1092 			KItemCnt, TheCmdLineParams.iDbEncoding == TCmdLineParams::EDbUtf16 ? &KUtf16 : &KUtf8, TheCmdLineParams.iPageSize);
  1088 	TheTest.Next(buf);
  1093 	TheTest.Next(TheTestTitle);
  1089 	Harvest();
  1094 	Harvest();
  1090 	
  1095 	
  1091 	PrintResults();
  1096 	PrintResults();
  1092 	}
  1097 	}
  1093 
       
  1094 //Usage: "t_sqlperformance3 [<drive letter>:]"
       
  1095 
  1098 
  1096 TInt E32Main()
  1099 TInt E32Main()
  1097 	{
  1100 	{
  1098 	TheTest.Title();
  1101 	TheTest.Title();
  1099 
  1102 
  1100 	CTrapCleanup* tc = CTrapCleanup::New();
  1103 	CTrapCleanup* tc = CTrapCleanup::New();
  1101 	TheTest(tc != NULL);
  1104 	TheTest(tc != NULL);
  1102 	
  1105 	
  1103 	__UHEAP_MARK;
  1106 	__UHEAP_MARK;
  1104 	
  1107 
  1105 	User::CommandLine(TheCmd);
  1108 	GetCmdLineParamsAndSqlConfigString(TheTest, _L("t_sqlperformance3"), TheCmdLineParams, TheSqlConfigString);
  1106 	TheCmd.TrimAll();
  1109 	PrepareDbName(KDbName, TheCmdLineParams.iDriveName, TheDbFileName);
  1107 	if(TheCmd.Length() > 0)
  1110 
  1108 		{
  1111 	TheTest.Printf(_L("==Databases: %S\r\n"), &TheDbFileName); 
  1109 		TheDriveName.Copy(TheCmd);
       
  1110 		}
       
  1111 	TheParse.Set(TheDriveName, &KDbName, 0);
       
  1112 	const TDesC& dbFilePath = TheParse.FullName();
       
  1113 	TheDbFileName.Copy(dbFilePath);
       
  1114 	TheTest.Printf(_L("==Database file name: %S\r\n"), &TheDbFileName);
       
  1115 	
  1112 	
  1116 	TestEnvDestroy();
  1113 	TestEnvDestroy();
  1117 	TestEnvInit();
  1114 	TestEnvInit();
  1118 	TRAPD(err, DoTestsL());
  1115 	TRAPD(err, DoTestsL());
  1119 	TestEnvDestroy();
  1116 	TestEnvDestroy();