os/security/cryptoservices/filebasedcertificateandkeystores/test/tfiletokens/CCheckServerHeapError.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-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 *
    16 */
    17 
    18 
    19 #include "t_filetokens.h"
    20 #include "t_input.h"
    21 #include "t_output.h"
    22 #include <e32base.h>
    23 
    24 /////////////////////////////////////////////////////////////////////////////////
    25 // CCheckServerHeapError
    26 /////////////////////////////////////////////////////////////////////////////////
    27 
    28 _LIT(KHeapErrorFile, "\\fsserver_heap_error");
    29 
    30 EXPORT_C CTestAction* CCheckServerHeapError::NewL(RFs& aFs, 
    31 												  CConsoleBase& aConsole, 
    32 												  Output& aOut,
    33 												  const TTestActionSpec& aTestActionSpec)
    34 	{
    35 	CCheckServerHeapError* self = new (ELeave) CCheckServerHeapError(aFs, aConsole, aOut);
    36 	CleanupStack::PushL(self);
    37 	self->ConstructL(aTestActionSpec);
    38 	CleanupStack::Pop(self);
    39 	return self;
    40 	}
    41 
    42 CCheckServerHeapError::CCheckServerHeapError(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
    43 	CTestAction(aConsole, aOut), iFs(aFs)
    44 	{
    45 	}
    46 
    47 void CCheckServerHeapError::ConstructL(const TTestActionSpec& aTestActionSpec)
    48 	{
    49 	CTestAction::ConstructL(aTestActionSpec);
    50 	TDriveUnit sysDrive (RFs::GetSystemDrive());
    51 	TDriveName driveName(sysDrive.Name());	
    52 	TBuf<128> heapErrFile (driveName);
    53 	heapErrFile.Append(KHeapErrorFile);
    54 	TInt err = iFs.Delete(heapErrFile);
    55 	if (err != KErrNone && err != KErrNotFound)
    56 		{
    57 		User::Leave(err);
    58 		}
    59 	}
    60 
    61 CCheckServerHeapError::~CCheckServerHeapError()
    62 	{
    63 	}
    64 
    65 void CCheckServerHeapError::DoPerformPrerequisite(TRequestStatus& aStatus)
    66 	{
    67 	iActionState = EAction;
    68 	TRequestStatus* status = &aStatus;
    69 	User::RequestComplete(status, KErrNone);
    70 	}
    71 
    72 void CCheckServerHeapError::PerformAction(TRequestStatus& aStatus)
    73 	{
    74 	TRequestStatus* status = &aStatus;
    75 
    76 	RFile file;
    77 	TDriveUnit sysDrive (RFs::GetSystemDrive());
    78 	TDriveName driveName(sysDrive.Name());
    79 	TBuf<128> heapErrFile (driveName);
    80 	heapErrFile.Append(KHeapErrorFile);
    81 	
    82 	TInt err = file.Open(iFs, heapErrFile, EFileRead | EFileShareExclusive);
    83 
    84 	if (err != KErrNone && err != KErrNotFound)
    85 		{
    86 		iResult = EFalse;
    87 		iFinished = ETrue;			
    88 		User::RequestComplete(status, err);
    89 		return;
    90 		}
    91 
    92 	file.Close();
    93 	
    94 	iResult = (err == KErrNotFound);
    95 	iFinished = ETrue;			
    96 	User::RequestComplete(status, KErrNone);
    97 	}
    98 
    99 void CCheckServerHeapError::DoPerformPostrequisite(TRequestStatus& aStatus)
   100 	{	
   101 	TRequestStatus* status = &aStatus;
   102 	User::RequestComplete(status, KErrNone);
   103 	}
   104 
   105 void CCheckServerHeapError::PerformCancel()
   106 	{
   107     // nothing to cancel
   108 	}
   109 
   110 void CCheckServerHeapError::Reset()
   111 	{
   112 	}
   113 
   114 void CCheckServerHeapError::DoReportAction()
   115 	{
   116 	iOut.writeString(_L("Checking for server heap error..."));
   117 	iOut.writeNewLine();
   118 	}
   119 
   120 void CCheckServerHeapError::DoCheckResult(TInt /*aError*/)
   121 	{
   122 	if (iFinished)
   123 		{
   124 		if (iResult)
   125 			{
   126 			_LIT(KSuccessful, "No heap error\n");
   127 			iConsole.Write(KSuccessful);
   128 			iOut.writeString(KSuccessful);
   129 			iOut.writeNewLine();
   130 			iOut.writeNewLine();
   131 			}
   132 		else
   133 			{
   134 			_LIT(KFailed, "!!!Server heap error detected!!!\n");
   135 			iConsole.Write(KFailed);
   136 			iOut.writeString(KFailed);
   137 			iOut.writeNewLine();
   138 			iOut.writeNewLine();
   139 			}
   140 		}
   141 	}