sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include "t_keystore_actions.h" sl@0: #include "t_keystore_defs.h" sl@0: #include "t_input.h" sl@0: sl@0: const int KErrDifferent = -99999; sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: // CCompare sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CTestAction* CCompare::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CCompare::NewLC(aFs, aConsole, aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CCompare::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCompare* self = new (ELeave) CCompare(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CCompare::~CCompare() sl@0: { sl@0: } sl@0: sl@0: CCompare::CCompare(RFs& aFs, CConsoleBase& aConsole, Output& aOut) sl@0: : CKeyStoreTestAction(aFs, aConsole, aOut) sl@0: { sl@0: iState = EComparing; sl@0: } sl@0: sl@0: sl@0: void CCompare::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CKeyStoreTestAction::ConstructL(aTestActionSpec); sl@0: sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: sl@0: TDriveUnit sysDrive (RFs::GetSystemDrive()); sl@0: TBuf<128> ramDrive (sysDrive.Name()); sl@0: ramDrive.Append(_L("\\tkeystore\\data\\")); sl@0: sl@0: iOriginalFile = ramDrive; sl@0: iNewFile = ramDrive; sl@0: sl@0: TFileName buf; sl@0: buf.FillZ(); sl@0: sl@0: buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody, sl@0: KOriginalFile, sl@0: KOriginalFileEnd, pos, err)); sl@0: // Now the filename itself sl@0: iOriginalFile.Append(buf); sl@0: sl@0: buf.Copy(Input::ParseElement(aTestActionSpec.iActionBody, sl@0: KNewFile, sl@0: KNewFileEnd, pos, err)); sl@0: // Now the filename itself sl@0: iNewFile.Append(buf); sl@0: sl@0: // iExpectedResult = SetExpectedResultL(Input::ParseElement(aTestActionSpec.iActionResult, sl@0: // KReturnStart, sl@0: // KReturnEnd, pos, err)); sl@0: } sl@0: sl@0: sl@0: void CCompare::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EComparing: sl@0: { sl@0: TInt res = KErrNone; sl@0: TRAPD(err, res = CompareFilesL()); sl@0: if (KErrNone != err) sl@0: { sl@0: res = err; sl@0: } sl@0: iState = EFinished; sl@0: TRequestStatus *status = &aStatus; sl@0: User::RequestComplete(status, res); sl@0: } sl@0: break; sl@0: case EFinished: sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: iFinished = ETrue; sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CCompare::PerformCancel() sl@0: { sl@0: // nothing to cancel sl@0: } sl@0: sl@0: sl@0: void CCompare::Reset() sl@0: {} sl@0: sl@0: sl@0: void CCompare::DoReportAction() sl@0: { sl@0: _LIT(KComparing, "Comparison in progress..."); sl@0: iOut.writeString(KComparing); sl@0: TPtr theLabel(iLabel->Des()); sl@0: iOut.writeString(theLabel); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: // Bitwise comparison of iOriginalFile and iNewFile sl@0: TInt CCompare::CompareFilesL() sl@0: { sl@0: TInt res = KErrNone; sl@0: sl@0: RFs theFs; sl@0: CleanupClosePushL(theFs); sl@0: User::LeaveIfError(theFs.Connect()); sl@0: sl@0: RFile original; sl@0: TInt r = original.Open(theFs, iOriginalFile, EFileRead); sl@0: User::LeaveIfError(r); sl@0: CleanupClosePushL(original); sl@0: sl@0: RFile generated; sl@0: r = generated.Open(theFs, iNewFile, EFileRead); sl@0: User::LeaveIfError(r); sl@0: CleanupClosePushL(generated); sl@0: sl@0: TInt pos1 = 0; sl@0: TInt pos2 = 0; sl@0: sl@0: TBuf8<1> ptr1; sl@0: TBuf8<1> ptr2; sl@0: sl@0: original.Read(pos1, ptr1); sl@0: generated.Read(pos2, ptr2); sl@0: sl@0: while (ptr1.Length()!=0) sl@0: { sl@0: if (ptr1.Compare(ptr2) != 0) sl@0: { sl@0: res = KErrDifferent; sl@0: pos = pos1; sl@0: break; sl@0: } sl@0: pos1++; sl@0: pos2++; sl@0: original.Read(pos1, ptr1); sl@0: generated.Read(pos2, ptr2); sl@0: } sl@0: if ((res != KErrDifferent)&& (ptr2.Length()!=0)) sl@0: { sl@0: res = KErrDifferent; sl@0: pos = pos1; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, &theFs); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: void CCompare::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (aError == KErrNone) sl@0: { sl@0: _LIT(KSuccessful, "Key comparison successfully\n"); sl@0: iConsole.Write(KSuccessful); sl@0: iOut.writeString(KSuccessful); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: TBuf<256> msg; sl@0: _LIT(KFailedDetails, "First difference at offset %d \n"); sl@0: msg.Format(KFailedDetails, pos); sl@0: if (aError!=iExpectedResult) sl@0: { sl@0: _LIT(KFailed, "!!!Key comparison failure!!! Import or export problem...\n"); sl@0: iConsole.Write(KFailed); sl@0: iOut.writeString(KFailed); sl@0: iOut.writeNewLine(); sl@0: iConsole.Write(msg); sl@0: iOut.writeString(msg); sl@0: } sl@0: else sl@0: { sl@0: _LIT(KFailed, "Key comparison failed, but expected\n"); sl@0: iConsole.Write(KFailed); sl@0: iOut.writeString(KFailed); sl@0: iOut.writeNewLine(); sl@0: iConsole.Write(msg); sl@0: iOut.writeString(msg); sl@0: } sl@0: sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: }