os/security/cryptoservices/filebasedcertificateandkeystores/test/tfiletokens/CCheckServerHeapError.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/tfiletokens/CCheckServerHeapError.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "t_filetokens.h"
    1.23 +#include "t_input.h"
    1.24 +#include "t_output.h"
    1.25 +#include <e32base.h>
    1.26 +
    1.27 +/////////////////////////////////////////////////////////////////////////////////
    1.28 +// CCheckServerHeapError
    1.29 +/////////////////////////////////////////////////////////////////////////////////
    1.30 +
    1.31 +_LIT(KHeapErrorFile, "\\fsserver_heap_error");
    1.32 +
    1.33 +EXPORT_C CTestAction* CCheckServerHeapError::NewL(RFs& aFs, 
    1.34 +												  CConsoleBase& aConsole, 
    1.35 +												  Output& aOut,
    1.36 +												  const TTestActionSpec& aTestActionSpec)
    1.37 +	{
    1.38 +	CCheckServerHeapError* self = new (ELeave) CCheckServerHeapError(aFs, aConsole, aOut);
    1.39 +	CleanupStack::PushL(self);
    1.40 +	self->ConstructL(aTestActionSpec);
    1.41 +	CleanupStack::Pop(self);
    1.42 +	return self;
    1.43 +	}
    1.44 +
    1.45 +CCheckServerHeapError::CCheckServerHeapError(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
    1.46 +	CTestAction(aConsole, aOut), iFs(aFs)
    1.47 +	{
    1.48 +	}
    1.49 +
    1.50 +void CCheckServerHeapError::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.51 +	{
    1.52 +	CTestAction::ConstructL(aTestActionSpec);
    1.53 +	TDriveUnit sysDrive (RFs::GetSystemDrive());
    1.54 +	TDriveName driveName(sysDrive.Name());	
    1.55 +	TBuf<128> heapErrFile (driveName);
    1.56 +	heapErrFile.Append(KHeapErrorFile);
    1.57 +	TInt err = iFs.Delete(heapErrFile);
    1.58 +	if (err != KErrNone && err != KErrNotFound)
    1.59 +		{
    1.60 +		User::Leave(err);
    1.61 +		}
    1.62 +	}
    1.63 +
    1.64 +CCheckServerHeapError::~CCheckServerHeapError()
    1.65 +	{
    1.66 +	}
    1.67 +
    1.68 +void CCheckServerHeapError::DoPerformPrerequisite(TRequestStatus& aStatus)
    1.69 +	{
    1.70 +	iActionState = EAction;
    1.71 +	TRequestStatus* status = &aStatus;
    1.72 +	User::RequestComplete(status, KErrNone);
    1.73 +	}
    1.74 +
    1.75 +void CCheckServerHeapError::PerformAction(TRequestStatus& aStatus)
    1.76 +	{
    1.77 +	TRequestStatus* status = &aStatus;
    1.78 +
    1.79 +	RFile file;
    1.80 +	TDriveUnit sysDrive (RFs::GetSystemDrive());
    1.81 +	TDriveName driveName(sysDrive.Name());
    1.82 +	TBuf<128> heapErrFile (driveName);
    1.83 +	heapErrFile.Append(KHeapErrorFile);
    1.84 +	
    1.85 +	TInt err = file.Open(iFs, heapErrFile, EFileRead | EFileShareExclusive);
    1.86 +
    1.87 +	if (err != KErrNone && err != KErrNotFound)
    1.88 +		{
    1.89 +		iResult = EFalse;
    1.90 +		iFinished = ETrue;			
    1.91 +		User::RequestComplete(status, err);
    1.92 +		return;
    1.93 +		}
    1.94 +
    1.95 +	file.Close();
    1.96 +	
    1.97 +	iResult = (err == KErrNotFound);
    1.98 +	iFinished = ETrue;			
    1.99 +	User::RequestComplete(status, KErrNone);
   1.100 +	}
   1.101 +
   1.102 +void CCheckServerHeapError::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.103 +	{	
   1.104 +	TRequestStatus* status = &aStatus;
   1.105 +	User::RequestComplete(status, KErrNone);
   1.106 +	}
   1.107 +
   1.108 +void CCheckServerHeapError::PerformCancel()
   1.109 +	{
   1.110 +    // nothing to cancel
   1.111 +	}
   1.112 +
   1.113 +void CCheckServerHeapError::Reset()
   1.114 +	{
   1.115 +	}
   1.116 +
   1.117 +void CCheckServerHeapError::DoReportAction()
   1.118 +	{
   1.119 +	iOut.writeString(_L("Checking for server heap error..."));
   1.120 +	iOut.writeNewLine();
   1.121 +	}
   1.122 +
   1.123 +void CCheckServerHeapError::DoCheckResult(TInt /*aError*/)
   1.124 +	{
   1.125 +	if (iFinished)
   1.126 +		{
   1.127 +		if (iResult)
   1.128 +			{
   1.129 +			_LIT(KSuccessful, "No heap error\n");
   1.130 +			iConsole.Write(KSuccessful);
   1.131 +			iOut.writeString(KSuccessful);
   1.132 +			iOut.writeNewLine();
   1.133 +			iOut.writeNewLine();
   1.134 +			}
   1.135 +		else
   1.136 +			{
   1.137 +			_LIT(KFailed, "!!!Server heap error detected!!!\n");
   1.138 +			iConsole.Write(KFailed);
   1.139 +			iOut.writeString(KFailed);
   1.140 +			iOut.writeNewLine();
   1.141 +			iOut.writeNewLine();
   1.142 +			}
   1.143 +		}
   1.144 +	}