os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_compare.cpp
First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
24 #include "t_keystore_actions.h"
25 #include "t_keystore_defs.h"
28 const int KErrDifferent = -99999;
30 /////////////////////////////////////////////////////////////////////////////////
32 /////////////////////////////////////////////////////////////////////////////////
34 CTestAction* CCompare::NewL(RFs& aFs,
35 CConsoleBase& aConsole,
37 const TTestActionSpec& aTestActionSpec)
39 CTestAction* self = CCompare::NewLC(aFs, aConsole, aOut, aTestActionSpec);
40 CleanupStack::Pop(self);
44 CTestAction* CCompare::NewLC(RFs& aFs,
45 CConsoleBase& aConsole,
47 const TTestActionSpec& aTestActionSpec)
49 CCompare* self = new (ELeave) CCompare(aFs, aConsole, aOut);
50 CleanupStack::PushL(self);
51 self->ConstructL(aTestActionSpec);
59 CCompare::CCompare(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
60 : CKeyStoreTestAction(aFs, aConsole, aOut)
66 void CCompare::ConstructL(const TTestActionSpec& aTestActionSpec)
68 CKeyStoreTestAction::ConstructL(aTestActionSpec);
73 TDriveUnit sysDrive (RFs::GetSystemDrive());
74 TBuf<128> ramDrive (sysDrive.Name());
75 ramDrive.Append(_L("\\tkeystore\\data\\"));
77 iOriginalFile = ramDrive;
83 buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody,
85 KOriginalFileEnd, pos, err));
86 // Now the filename itself
87 iOriginalFile.Append(buf);
89 buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody,
91 KNewFileEnd, pos, err));
92 // Now the filename itself
95 // iExpectedResult = SetExpectedResultL(Input::ParseElement(aTestActionSpec.iActionResult,
97 // KReturnEnd, pos, err));
101 void CCompare::PerformAction(TRequestStatus& aStatus)
108 TRAPD(err, res = CompareFilesL());
114 TRequestStatus *status = &aStatus;
115 User::RequestComplete(status, res);
120 TRequestStatus* status = &aStatus;
121 User::RequestComplete(status, aStatus.Int());
122 if (aStatus == iExpectedResult)
137 void CCompare::PerformCancel()
143 void CCompare::Reset()
147 void CCompare::DoReportAction()
149 _LIT(KComparing, "Comparison in progress...");
150 iOut.writeString(KComparing);
151 TPtr theLabel(iLabel->Des());
152 iOut.writeString(theLabel);
156 // Bitwise comparison of iOriginalFile and iNewFile
157 TInt CCompare::CompareFilesL()
162 CleanupClosePushL(theFs);
163 User::LeaveIfError(theFs.Connect());
166 TInt r = original.Open(theFs, iOriginalFile, EFileRead);
167 User::LeaveIfError(r);
168 CleanupClosePushL(original);
171 r = generated.Open(theFs, iNewFile, EFileRead);
172 User::LeaveIfError(r);
173 CleanupClosePushL(generated);
181 original.Read(pos1, ptr1);
182 generated.Read(pos2, ptr2);
184 while (ptr1.Length()!=0)
186 if (ptr1.Compare(ptr2) != 0)
194 original.Read(pos1, ptr1);
195 generated.Read(pos2, ptr2);
197 if ((res != KErrDifferent)&& (ptr2.Length()!=0))
203 CleanupStack::PopAndDestroy(3, &theFs);
208 void CCompare::DoCheckResult(TInt aError)
212 if (aError == KErrNone)
214 _LIT(KSuccessful, "Key comparison successfully\n");
215 iConsole.Write(KSuccessful);
216 iOut.writeString(KSuccessful);
223 _LIT(KFailedDetails, "First difference at offset %d \n");
224 msg.Format(KFailedDetails, pos);
225 if (aError!=iExpectedResult)
227 _LIT(KFailed, "!!!Key comparison failure!!! Import or export problem...\n");
228 iConsole.Write(KFailed);
229 iOut.writeString(KFailed);
232 iOut.writeString(msg);
236 _LIT(KFailed, "Key comparison failed, but expected\n");
237 iConsole.Write(KFailed);
238 iOut.writeString(KFailed);
241 iOut.writeString(msg);