filehandling/htmltorichtextconverter/tsrc/profilingtest.cpp
changeset 0 2e3d3ce01487
child 24 a72ff4214918
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // CHtmlToCrtConverter profiling test code
       
    15 // profiles conversion of files of size 0.1kb - 2kb in 0.1kb increments
       
    16 // and then 2kb - 20kb in 1kb increments
       
    17 // The results are written to the file results.csv
       
    18 // 
       
    19 //
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <e32test.h>
       
    23 #include <f32file.h>
       
    24 #include <e32math.h>
       
    25 #include "CHtmlToCrtConverter.h"
       
    26 #include "CHtmlToCrtConvActive.h"
       
    27 
       
    28 _LIT(KTestName,"CHtmlToCrtConverter");
       
    29 
       
    30 LOCAL_D RTest test(KTestName);
       
    31 
       
    32 //=================================================================================
       
    33 //synchronousConversionL
       
    34 //tests synchronous conversion
       
    35 //=================================================================================
       
    36 void synchronousConversionL(TDesC& aSourceFile, TDesC& aTargetFile)
       
    37 	{
       
    38 	CHtmlToCrtConverter* converter = new(ELeave) CHtmlToCrtConverter;
       
    39 	CleanupStack::PushL(converter);
       
    40 	converter->ConvertL(aSourceFile, aTargetFile);		
       
    41 
       
    42 	CleanupStack::PopAndDestroy(converter);
       
    43 	}
       
    44 //================================================================================
       
    45 //getPath
       
    46 //================================================================================
       
    47 TBool getPath(TDes& aPath, RFs& aFs)
       
    48 	{
       
    49 	// Generate the folder spec to search in
       
    50 	TFileName searchSpec;
       
    51 	TChar driveLetter = 'C';
       
    52 	searchSpec.Append(driveLetter);
       
    53 	searchSpec.Append(aPath);
       
    54 
       
    55 	CDir* entryList = NULL;
       
    56 	TFindFile finder(aFs);
       
    57 	TInt ret = finder.FindWildByPath(searchSpec, NULL, entryList);
       
    58 	if(ret<KErrNone)
       
    59 		{
       
    60 		//try z drive
       
    61 		driveLetter = 'Z';
       
    62 		searchSpec.Zero();
       
    63 		searchSpec.Append(driveLetter);
       
    64 		searchSpec.Append(aPath);
       
    65 		delete entryList;
       
    66 		entryList = NULL;
       
    67 
       
    68 		ret = finder.FindWildByPath(searchSpec, NULL, entryList);
       
    69 		if	(ret < KErrNone)
       
    70 			{
       
    71 			//path not found
       
    72 			delete entryList;
       
    73 			test.Printf(_L("files not found\n"));
       
    74 			return EFalse;
       
    75 			}
       
    76 		}
       
    77 
       
    78 	//set path
       
    79 	delete entryList;
       
    80 	aPath.Copy(searchSpec);
       
    81 	return ETrue;
       
    82 	}
       
    83 //=================================================================================
       
    84 //doProfilingL
       
    85 //=================================================================================
       
    86 void doProfilingL(TDesC& aPath, TDesC& aPathName, RFs& aFs, TDesC& aTargetFile, TDesC& aResultFile)
       
    87 	{
       
    88 	TBuf<24> sourceFile;
       
    89 
       
    90 	CDir* entryList = NULL;
       
    91 	TInt error = aFs.GetDir(aPath,KEntryAttMatchMask,ESortByName,entryList);
       
    92 	User::LeaveIfError(error);
       
    93 
       
    94 	TInt numberOfEntries = entryList->Count();
       
    95 	TBuf<11>sourceFileName;
       
    96 	_LIT8(KCSVHeadings,"size,time\r\n");
       
    97 	HBufC8* temp=HBufC8::NewLC(500);
       
    98 	TPtr8 resultBuffer(temp->Des());
       
    99 	resultBuffer.Append(KCSVHeadings);
       
   100 
       
   101 	for (TInt i=0; i<numberOfEntries; i++)
       
   102 		{
       
   103 		//get file name
       
   104 		sourceFileName = (*entryList)[i].iName;
       
   105 		sourceFile = aPathName;
       
   106 		sourceFile.Append(sourceFileName);
       
   107 		__PROFILE_RESET(1);
       
   108 		__PROFILE_START(0);
       
   109 		synchronousConversionL(sourceFile, aTargetFile);
       
   110 		__PROFILE_END(0);
       
   111 		__PROFILE_DISPLAY(1);
       
   112 		}
       
   113 
       
   114 	//write result to file
       
   115 	_LIT(KPath,"c:\\");
       
   116 	_LIT(KExtension,".csv");
       
   117 	TBuf<256> result(KPath);
       
   118 	result.Append(aResultFile);
       
   119 	result.Append(KExtension);
       
   120 
       
   121 	RFs theFs;
       
   122 	User::LeaveIfError(theFs.Connect());
       
   123 	CleanupClosePushL(theFs);
       
   124 	RFile file;
       
   125 	TInt err=file.Replace(theFs, result,
       
   126 	EFileWrite+EFileShareAny+EFileStreamText);
       
   127 	User::LeaveIfError(err);
       
   128 	CleanupClosePushL(file);
       
   129 	file.Write(resultBuffer);
       
   130 	CleanupStack::PopAndDestroy(3);
       
   131 
       
   132 	delete entryList;
       
   133 	}
       
   134 //=================================================================================
       
   135 	
       
   136 /**
       
   137 @SYMTestCaseID PIM-PROFILINGTEST-0001
       
   138 */
       
   139 void doMainL()
       
   140 	{
       
   141 	test.Start(_L("@SYMTestCaseID PIM-PROFILINGTEST-0001 CHtmlToCrtConverter profiling test"));
       
   142 
       
   143 	RFs		fs;
       
   144 	User::LeaveIfError(fs.Connect());
       
   145 	CleanupClosePushL(fs);
       
   146 
       
   147 	TBufC<11> targetFile(_L("target file"));
       
   148 
       
   149 //path to be profiled
       
   150 	TBuf<18> path(_L(":\\profiling\\*.*"));
       
   151 
       
   152 //file to write results to
       
   153 	_LIT(KResultFile,"results");
       
   154 	TBufC<7> resultFile(KResultFile);
       
   155 
       
   156 	if(getPath(path, fs))
       
   157 		{
       
   158 		TBuf<18> pathName(path);
       
   159 		pathName.SetLength(pathName.Length()-3);
       
   160 
       
   161 		doProfilingL(path, pathName, fs, targetFile, resultFile);
       
   162 		}
       
   163 
       
   164 	CleanupStack::PopAndDestroy(&fs);
       
   165 
       
   166 	test.End();
       
   167 	test.Close();
       
   168 	}
       
   169 
       
   170 GLDEF_C TInt E32Main()
       
   171 	{	
       
   172 	__UHEAP_MARK;
       
   173 
       
   174 	CTrapCleanup* theCleanup=CTrapCleanup::New();
       
   175 	TRAPD(ret,doMainL());		
       
   176 	test(ret==KErrNone);
       
   177 	delete theCleanup;	
       
   178 
       
   179 	__UHEAP_MARKEND;
       
   180 	return(KErrNone);
       
   181 	}