sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include <e32base.h>
|
sl@0
|
24 |
#include "t_keystore_actions.h"
|
sl@0
|
25 |
#include "t_keystore_defs.h"
|
sl@0
|
26 |
#include "t_input.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
const int KErrDifferent = -99999;
|
sl@0
|
29 |
|
sl@0
|
30 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
31 |
// CCompare
|
sl@0
|
32 |
/////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
33 |
|
sl@0
|
34 |
CTestAction* CCompare::NewL(RFs& aFs,
|
sl@0
|
35 |
CConsoleBase& aConsole,
|
sl@0
|
36 |
Output& aOut,
|
sl@0
|
37 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
CTestAction* self = CCompare::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
40 |
CleanupStack::Pop(self);
|
sl@0
|
41 |
return self;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
CTestAction* CCompare::NewLC(RFs& aFs,
|
sl@0
|
45 |
CConsoleBase& aConsole,
|
sl@0
|
46 |
Output& aOut,
|
sl@0
|
47 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
CCompare* self = new (ELeave) CCompare(aFs, aConsole, aOut);
|
sl@0
|
50 |
CleanupStack::PushL(self);
|
sl@0
|
51 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
52 |
return self;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
CCompare::~CCompare()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
CCompare::CCompare(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
|
sl@0
|
60 |
: CKeyStoreTestAction(aFs, aConsole, aOut)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
iState = EComparing;
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
|
sl@0
|
66 |
void CCompare::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
CKeyStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
69 |
|
sl@0
|
70 |
TInt err = KErrNone;
|
sl@0
|
71 |
TInt pos = 0;
|
sl@0
|
72 |
|
sl@0
|
73 |
TDriveUnit sysDrive (RFs::GetSystemDrive());
|
sl@0
|
74 |
TBuf<128> ramDrive (sysDrive.Name());
|
sl@0
|
75 |
ramDrive.Append(_L("\\tkeystore\\data\\"));
|
sl@0
|
76 |
|
sl@0
|
77 |
iOriginalFile = ramDrive;
|
sl@0
|
78 |
iNewFile = ramDrive;
|
sl@0
|
79 |
|
sl@0
|
80 |
TFileName buf;
|
sl@0
|
81 |
buf.FillZ();
|
sl@0
|
82 |
|
sl@0
|
83 |
buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody,
|
sl@0
|
84 |
KOriginalFile,
|
sl@0
|
85 |
KOriginalFileEnd, pos, err));
|
sl@0
|
86 |
// Now the filename itself
|
sl@0
|
87 |
iOriginalFile.Append(buf);
|
sl@0
|
88 |
|
sl@0
|
89 |
buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody,
|
sl@0
|
90 |
KNewFile,
|
sl@0
|
91 |
KNewFileEnd, pos, err));
|
sl@0
|
92 |
// Now the filename itself
|
sl@0
|
93 |
iNewFile.Append(buf);
|
sl@0
|
94 |
|
sl@0
|
95 |
// iExpectedResult = SetExpectedResultL(Input::ParseElement(aTestActionSpec.iActionResult,
|
sl@0
|
96 |
// KReturnStart,
|
sl@0
|
97 |
// KReturnEnd, pos, err));
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
|
sl@0
|
101 |
void CCompare::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
switch (iState)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
case EComparing:
|
sl@0
|
106 |
{
|
sl@0
|
107 |
TInt res = KErrNone;
|
sl@0
|
108 |
TRAPD(err, res = CompareFilesL());
|
sl@0
|
109 |
if (KErrNone != err)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
res = err;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
iState = EFinished;
|
sl@0
|
114 |
TRequestStatus *status = &aStatus;
|
sl@0
|
115 |
User::RequestComplete(status, res);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
break;
|
sl@0
|
118 |
case EFinished:
|
sl@0
|
119 |
{
|
sl@0
|
120 |
TRequestStatus* status = &aStatus;
|
sl@0
|
121 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
122 |
if (aStatus == iExpectedResult)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
iResult = ETrue;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
else
|
sl@0
|
127 |
{
|
sl@0
|
128 |
iResult = EFalse;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
iFinished = ETrue;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
break;
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
|
sl@0
|
137 |
void CCompare::PerformCancel()
|
sl@0
|
138 |
{
|
sl@0
|
139 |
// nothing to cancel
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
void CCompare::Reset()
|
sl@0
|
144 |
{}
|
sl@0
|
145 |
|
sl@0
|
146 |
|
sl@0
|
147 |
void CCompare::DoReportAction()
|
sl@0
|
148 |
{
|
sl@0
|
149 |
_LIT(KComparing, "Comparison in progress...");
|
sl@0
|
150 |
iOut.writeString(KComparing);
|
sl@0
|
151 |
TPtr theLabel(iLabel->Des());
|
sl@0
|
152 |
iOut.writeString(theLabel);
|
sl@0
|
153 |
iOut.writeNewLine();
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
// Bitwise comparison of iOriginalFile and iNewFile
|
sl@0
|
157 |
TInt CCompare::CompareFilesL()
|
sl@0
|
158 |
{
|
sl@0
|
159 |
TInt res = KErrNone;
|
sl@0
|
160 |
|
sl@0
|
161 |
RFs theFs;
|
sl@0
|
162 |
CleanupClosePushL(theFs);
|
sl@0
|
163 |
User::LeaveIfError(theFs.Connect());
|
sl@0
|
164 |
|
sl@0
|
165 |
RFile original;
|
sl@0
|
166 |
TInt r = original.Open(theFs, iOriginalFile, EFileRead);
|
sl@0
|
167 |
User::LeaveIfError(r);
|
sl@0
|
168 |
CleanupClosePushL(original);
|
sl@0
|
169 |
|
sl@0
|
170 |
RFile generated;
|
sl@0
|
171 |
r = generated.Open(theFs, iNewFile, EFileRead);
|
sl@0
|
172 |
User::LeaveIfError(r);
|
sl@0
|
173 |
CleanupClosePushL(generated);
|
sl@0
|
174 |
|
sl@0
|
175 |
TInt pos1 = 0;
|
sl@0
|
176 |
TInt pos2 = 0;
|
sl@0
|
177 |
|
sl@0
|
178 |
TBuf8<1> ptr1;
|
sl@0
|
179 |
TBuf8<1> ptr2;
|
sl@0
|
180 |
|
sl@0
|
181 |
original.Read(pos1, ptr1);
|
sl@0
|
182 |
generated.Read(pos2, ptr2);
|
sl@0
|
183 |
|
sl@0
|
184 |
while (ptr1.Length()!=0)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
if (ptr1.Compare(ptr2) != 0)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
res = KErrDifferent;
|
sl@0
|
189 |
pos = pos1;
|
sl@0
|
190 |
break;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
pos1++;
|
sl@0
|
193 |
pos2++;
|
sl@0
|
194 |
original.Read(pos1, ptr1);
|
sl@0
|
195 |
generated.Read(pos2, ptr2);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
if ((res != KErrDifferent)&& (ptr2.Length()!=0))
|
sl@0
|
198 |
{
|
sl@0
|
199 |
res = KErrDifferent;
|
sl@0
|
200 |
pos = pos1;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
CleanupStack::PopAndDestroy(3, &theFs);
|
sl@0
|
204 |
|
sl@0
|
205 |
return res;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
void CCompare::DoCheckResult(TInt aError)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
if (iFinished)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
if (aError == KErrNone)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
_LIT(KSuccessful, "Key comparison successfully\n");
|
sl@0
|
215 |
iConsole.Write(KSuccessful);
|
sl@0
|
216 |
iOut.writeString(KSuccessful);
|
sl@0
|
217 |
iOut.writeNewLine();
|
sl@0
|
218 |
iOut.writeNewLine();
|
sl@0
|
219 |
}
|
sl@0
|
220 |
else
|
sl@0
|
221 |
{
|
sl@0
|
222 |
TBuf<256> msg;
|
sl@0
|
223 |
_LIT(KFailedDetails, "First difference at offset %d \n");
|
sl@0
|
224 |
msg.Format(KFailedDetails, pos);
|
sl@0
|
225 |
if (aError!=iExpectedResult)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
_LIT(KFailed, "!!!Key comparison failure!!! Import or export problem...\n");
|
sl@0
|
228 |
iConsole.Write(KFailed);
|
sl@0
|
229 |
iOut.writeString(KFailed);
|
sl@0
|
230 |
iOut.writeNewLine();
|
sl@0
|
231 |
iConsole.Write(msg);
|
sl@0
|
232 |
iOut.writeString(msg);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
else
|
sl@0
|
235 |
{
|
sl@0
|
236 |
_LIT(KFailed, "Key comparison failed, but expected\n");
|
sl@0
|
237 |
iConsole.Write(KFailed);
|
sl@0
|
238 |
iOut.writeString(KFailed);
|
sl@0
|
239 |
iOut.writeNewLine();
|
sl@0
|
240 |
iConsole.Write(msg);
|
sl@0
|
241 |
iOut.writeString(msg);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
iOut.writeNewLine();
|
sl@0
|
245 |
iOut.writeNewLine();
|
sl@0
|
246 |
}
|
sl@0
|
247 |
}
|
sl@0
|
248 |
}
|