|
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 * Mostly obsolete code to manage hash tests |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 */ |
|
25 |
|
26 #include "hashtestutils.h" |
|
27 |
|
28 |
|
29 CTestData* CTestData::NewL(const TDesC& aFilename) |
|
30 |
|
31 { |
|
32 CTestData* self; |
|
33 self=new (ELeave) CTestData; |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(aFilename); |
|
36 CleanupStack::Pop(); // self |
|
37 return self; |
|
38 } |
|
39 |
|
40 CTestData::CTestData(void):CBase() |
|
41 |
|
42 { |
|
43 } |
|
44 |
|
45 CTestData::~CTestData(void) |
|
46 |
|
47 { |
|
48 delete iFile; |
|
49 delete iLine; |
|
50 } |
|
51 |
|
52 void CTestData::ConstructL(const TDesC& aFilename) |
|
53 |
|
54 { |
|
55 RFs fs; |
|
56 RFile file; |
|
57 CleanupClosePushL(fs); |
|
58 User::LeaveIfError(fs.Connect()); |
|
59 TDriveUnit sysDrive(fs.GetSystemDrive()); |
|
60 TDriveName driveName(sysDrive.Name()); |
|
61 TBuf<24> filePath (driveName); |
|
62 filePath.Append(_L("\\thash\\")); |
|
63 User::LeaveIfError(fs.SetSessionPath(filePath)); |
|
64 CleanupClosePushL(file); |
|
65 User::LeaveIfError(file.Open(fs,aFilename,EFileShareAny|EFileRead)); |
|
66 // read into iFile |
|
67 TInt size=0; |
|
68 file.Size(size); |
|
69 iFile=HBufC8::NewMaxL(size); |
|
70 TPtr8 ptr=iFile->Des(); |
|
71 User::LeaveIfError(file.Read(ptr)); |
|
72 CleanupStack::PopAndDestroy(2, &fs); |
|
73 iCurrentPlace=0; |
|
74 iLine=HBufC8::NewMaxL(2000); |
|
75 } |
|
76 |
|
77 CTestData::TType CTestData::Type(void) |
|
78 |
|
79 { |
|
80 TPtr8 ptr=iLine->Des(); |
|
81 if (iCurrentPlace>=iFile->Length()) |
|
82 { |
|
83 return EFinished; |
|
84 } |
|
85 TInt8 ch=(*iFile)[iCurrentPlace++]; |
|
86 ptr.SetLength(0); |
|
87 while ((ch!='\r')&&(ch!='\n')&&(iCurrentPlace<=iFile->Length())) |
|
88 { |
|
89 ptr.Append(ch); |
|
90 ch=(*iFile)[iCurrentPlace++]; |
|
91 } |
|
92 if ((iCurrentPlace==iFile->Length())||(iLine->Length()==0)) |
|
93 { |
|
94 return EFinished; |
|
95 } |
|
96 if (((*iFile)[iCurrentPlace]=='\r')||((*iFile)[iCurrentPlace]=='\n')) |
|
97 { |
|
98 iCurrentPlace++; |
|
99 } |
|
100 if ((*iLine)[0]=='+') |
|
101 { |
|
102 switch ((*iLine)[1]) |
|
103 { |
|
104 case 'M': // Message |
|
105 return EMessage; |
|
106 case 'F': // File Name |
|
107 return EFileName; |
|
108 case 'C': // Comment |
|
109 return Type(); |
|
110 default: |
|
111 return EError; |
|
112 } |
|
113 } |
|
114 return EData; |
|
115 } |
|
116 |
|
117 HBufC8* CTestData::operator [] (TInt aIndex) |
|
118 |
|
119 { |
|
120 TInt i; |
|
121 TInt count=0; |
|
122 HBufC8* ret; |
|
123 ret=HBufC8::New(4000); |
|
124 for (i=0;(i<iLine->Length())&&(count<aIndex);i++) |
|
125 { |
|
126 if ((*iLine)[i]==' ') |
|
127 { |
|
128 count++; |
|
129 } |
|
130 } |
|
131 if(ret != NULL) |
|
132 { |
|
133 TPtr8 ptr=ret->Des(); |
|
134 for (;(i<iLine->Length()&&(*iLine)[i]!=' ');i++) |
|
135 { |
|
136 ptr.Append((*iLine)[i]); |
|
137 } |
|
138 } |
|
139 return ret; |
|
140 } |
|
141 |
|
142 HBufC* CTestData::Message(void) |
|
143 |
|
144 { |
|
145 HBufC* ret=HBufC::NewMax(iLine->Length()-3); |
|
146 TPtrC8 ptr=iLine->Right(iLine->Length()-3); |
|
147 if(ret != NULL) |
|
148 { |
|
149 TPtr dest=ret->Des(); |
|
150 dest.Copy(ptr); |
|
151 } |
|
152 return ret; |
|
153 } |
|
154 |
|
155 |
|
156 CTestConsole* CTestConsole::NewL(CConsoleBase* aCon) |
|
157 { |
|
158 CTestConsole* self; |
|
159 self=new (ELeave) CTestConsole; |
|
160 self->iCon=aCon; |
|
161 self->iFile=NULL; |
|
162 return self; |
|
163 } |
|
164 |
|
165 CTestConsole::CTestConsole(void):CConsoleBase() |
|
166 |
|
167 { |
|
168 } |
|
169 |
|
170 CTestConsole::~CTestConsole(void) |
|
171 |
|
172 { |
|
173 delete iCon; |
|
174 if (iFile) |
|
175 { |
|
176 iFile->Close(); |
|
177 } |
|
178 } |
|
179 |
|
180 void CTestConsole::Write(const TDesC16& aString) |
|
181 |
|
182 { |
|
183 iCon->Write(aString); |
|
184 if (iFile) |
|
185 { |
|
186 TUint8 space[200]; |
|
187 TPtr8 ptr(space,200); |
|
188 ptr.Copy(aString); |
|
189 iFile->Write(ptr); |
|
190 } |
|
191 } |
|
192 |
|
193 void CTestConsole::SetLogFile(RFile* aFile) |
|
194 |
|
195 { |
|
196 iFile=aFile; |
|
197 } |