0
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "UtilsSetupStep.h"
|
|
19 |
|
|
20 |
/*@{*/
|
|
21 |
// Literals Used
|
|
22 |
_LIT(KT_FileSize, "fileSize");
|
|
23 |
_LIT(KT_NumOfFiles, "numOfFiles");
|
|
24 |
_LIT(KT_DirTreeDepth, "dirTreeDepth");
|
|
25 |
_LIT(KT_BaseFileName, "fileBaseName");
|
|
26 |
_LIT(KT_SubDirName, "subDirName");
|
|
27 |
_LIT(KT_FileData, "fileData");
|
|
28 |
_LIT(KT_DotSeparator, ".");
|
|
29 |
_LIT(KT_DirSpearator, "\\");
|
|
30 |
/*@}*/
|
|
31 |
|
|
32 |
// Function : CT_SetupStep
|
|
33 |
// Description :CT_SetupStep:: class constructor
|
|
34 |
CT_SetupStep::CT_SetupStep()
|
|
35 |
: CT_UtilsStep()
|
|
36 |
, iFileSize(0)
|
|
37 |
, iDirTreeDepth(0)
|
|
38 |
, iNumOfFiles(0)
|
|
39 |
{
|
|
40 |
}
|
|
41 |
|
|
42 |
// Function : ~CT_SetupStep
|
|
43 |
// Description :CT_SetupStep class destructor
|
|
44 |
CT_SetupStep:: ~CT_SetupStep()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
//Function:doTestStepL
|
|
49 |
//Description :
|
|
50 |
//@return TVerdict pass / fail
|
|
51 |
TVerdict CT_SetupStep::doTestStepL()
|
|
52 |
{
|
|
53 |
INFO_PRINTF1(_L("Starting CT_SetupStepdoTestStepL"));
|
|
54 |
//create directory structure and contents
|
|
55 |
CreateDirTreeL();
|
|
56 |
INFO_PRINTF1(_L("CT_SetupStep Completed doTestStepL"));
|
|
57 |
return TestStepResult();
|
|
58 |
}
|
|
59 |
|
|
60 |
//Function:doTestStepPreambleL
|
|
61 |
//Description :
|
|
62 |
//@return TVerdict pass / fail
|
|
63 |
TVerdict CT_SetupStep::doTestStepPreambleL()
|
|
64 |
{
|
|
65 |
INFO_PRINTF1(_L("Test Step :Perf SetupStep Preamble setup"));
|
|
66 |
INFO_PRINTF1(_L("Initiating: :Perf Utils step Preamble setup"));
|
|
67 |
//call Utils base class doTestStepPreambleL
|
|
68 |
TVerdict result= CT_UtilsStep::doTestStepPreambleL();
|
|
69 |
CT_UtilsStep::DoFormatDriveL(); //format drive if requested
|
|
70 |
|
|
71 |
if (!GetIntFromConfig(ConfigSection(),KT_FileSize,iFileSize))
|
|
72 |
{
|
|
73 |
ERR_PRINTF2( _L("Invalid fileSize given, file size set to: (%d)"), iFileSize );
|
|
74 |
SetTestStepResult(EFail);
|
|
75 |
}
|
|
76 |
if (!GetIntFromConfig(ConfigSection(),KT_DirTreeDepth,iDirTreeDepth))
|
|
77 |
{
|
|
78 |
ERR_PRINTF2( _L("Invalid directory tree depth given, it is set to:...(%d)"),iDirTreeDepth);
|
|
79 |
SetTestStepResult(EFail);
|
|
80 |
}
|
|
81 |
if (!GetIntFromConfig(ConfigSection(),KT_NumOfFiles,iNumOfFiles))
|
|
82 |
{
|
|
83 |
ERR_PRINTF2( _L("Invalid number of files to create, it is set to: (%d) "), iNumOfFiles );
|
|
84 |
SetTestStepResult(EFail);
|
|
85 |
}
|
|
86 |
if(!GetStringFromConfig(ConfigSection(),KT_BaseFileName,iFileBaseName))
|
|
87 |
{
|
|
88 |
ERR_PRINTF1( _L("Unable to read file name to create, Will not be able to create file structure:!! ") );
|
|
89 |
SetTestStepResult(EFail);
|
|
90 |
}
|
|
91 |
if (!GetStringFromConfig(ConfigSection(),KT_SubDirName,iDirSubName))
|
|
92 |
{
|
|
93 |
ERR_PRINTF1( _L("Unable to read in sub directory name to use within test, Will not be able to create a directory structure! ") );
|
|
94 |
SetTestStepResult(EFail);
|
|
95 |
}
|
|
96 |
if (!GetStringFromConfig(ConfigSection(),KT_FileData,iFileData))
|
|
97 |
{
|
|
98 |
ERR_PRINTF1( _L("Unable to read file Data to use within test, Will not be able to create files with any data!") );
|
|
99 |
SetTestStepResult(EFail);
|
|
100 |
}
|
|
101 |
|
|
102 |
return result;
|
|
103 |
}
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
// Function CreateDirTreeL
|
|
109 |
// Description
|
|
110 |
// @return :void
|
|
111 |
void CT_SetupStep::CreateDirTreeL()
|
|
112 |
{
|
|
113 |
RDir dir;
|
|
114 |
TFileName pathDepth=iDirBaseName;
|
|
115 |
TInt err=dir.Open(iFsSession, pathDepth, KEntryAttNormal);
|
|
116 |
|
|
117 |
if (err!=KErrNone)
|
|
118 |
{
|
|
119 |
RemoveDirTreeL();
|
|
120 |
}
|
|
121 |
else
|
|
122 |
{
|
|
123 |
dir.Close();//close dir
|
|
124 |
}
|
|
125 |
|
|
126 |
// Create directory tree
|
|
127 |
for (TInt i=0;i<iDirTreeDepth ;i++)//offset due to parent dir
|
|
128 |
{
|
|
129 |
pathDepth+=iDirSubName;
|
|
130 |
pathDepth+=KT_DirSpearator;
|
|
131 |
}
|
|
132 |
User::LeaveIfError(iFsSession.MkDirAll(pathDepth));
|
|
133 |
|
|
134 |
// Create files in each directory
|
|
135 |
pathDepth=iDirBaseName;
|
|
136 |
for (TInt j=0;j<iDirTreeDepth ;j++)//offset due to parent dir
|
|
137 |
{
|
|
138 |
pathDepth+=iDirSubName;
|
|
139 |
pathDepth+=KT_DirSpearator;
|
|
140 |
CreateFileL(pathDepth);
|
|
141 |
}
|
|
142 |
}
|
|
143 |
|
|
144 |
|
|
145 |
// Function CreateFileL
|
|
146 |
// Description
|
|
147 |
// @return :void
|
|
148 |
// @param:TDesC& aPath
|
|
149 |
void CT_SetupStep:: CreateFileL(TDesC& aPath)
|
|
150 |
{
|
|
151 |
RFile file;
|
|
152 |
// File names are of the type filename1.ext, filename2.ext, etc, so create first file with "1" attached to it
|
|
153 |
TFileName extNum=_L("");//placeholder
|
|
154 |
extNum.AppendNum(1);
|
|
155 |
TFileName firstFilename=aPath;
|
|
156 |
firstFilename.Append(iFileBaseName);
|
|
157 |
firstFilename.Insert((firstFilename.Find(KT_DotSeparator)), extNum);
|
|
158 |
TInt opened=file.Open(iFsSession, firstFilename, EFileStream);
|
|
159 |
if ( opened!=KErrNone )
|
|
160 |
{
|
|
161 |
opened=file.Create(iFsSession, firstFilename, EFileStream);
|
|
162 |
}
|
|
163 |
|
|
164 |
if ( opened==KErrNone )
|
|
165 |
{
|
|
166 |
CleanupClosePushL(file);//make handle leave safe
|
|
167 |
CreateFileDataL(file);
|
|
168 |
CleanupStack::PopAndDestroy(&file);
|
|
169 |
|
|
170 |
// Copy first file to subsequent files
|
|
171 |
CFileMan* fileMan=CFileMan::NewL(iFsSession);
|
|
172 |
CleanupStack::PushL(fileMan);
|
|
173 |
for (TInt i=1;i<iNumOfFiles; i++)
|
|
174 |
{
|
|
175 |
extNum.Zero();
|
|
176 |
extNum.AppendNum(i+1);
|
|
177 |
TFileName newFilename=aPath;
|
|
178 |
newFilename.Append(iFileBaseName);
|
|
179 |
newFilename.Insert((newFilename.Find(KT_DotSeparator)), extNum);
|
|
180 |
fileMan->Copy(firstFilename, newFilename);
|
|
181 |
}
|
|
182 |
CleanupStack::PopAndDestroy(fileMan);
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
ERR_PRINTF2( _L("File not created failed with error (%d)"), opened);
|
|
187 |
SetTestStepResult(EFail);
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
|
|
192 |
// Function : CreateFileDataL
|
|
193 |
// Description
|
|
194 |
// @return :void
|
|
195 |
// @param:RFile& aFile
|
|
196 |
void CT_SetupStep::CreateFileDataL(RFile& aFile)
|
|
197 |
{
|
|
198 |
HBufC8* tempbuf=HBufC8::NewLC(iFileData.Length());
|
|
199 |
TPtr8 data(tempbuf->Des());
|
|
200 |
data.Copy(iFileData);
|
|
201 |
|
|
202 |
TInt filelength=iFileSize/iFileData.Length();
|
|
203 |
for (TInt i=0;i<filelength;i++)
|
|
204 |
{
|
|
205 |
TInt err= aFile.Write(data);//Write(const TDesC8 &aDes);
|
|
206 |
if(err!=KErrNone)
|
|
207 |
{
|
|
208 |
ERR_PRINTF2( _L("File data not successful failed with error: (%d)"),err);
|
|
209 |
SetTestStepResult(EFail);
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
CleanupStack::PopAndDestroy(1,tempbuf);
|
|
214 |
}
|