testexecmdw/tef/tef/test/regressiontest/scriptcommand/src/checklogfilestep.cpp
branchRCL_3
changeset 3 9397a16b6eb8
parent 1 6edeef394eb7
equal deleted inserted replaced
1:6edeef394eb7 3:9397a16b6eb8
     1 /*
       
     2 * Copyright (c) 2005-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 "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 * Example CTestStep derived implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file checkresultstep.cpp
       
    23 */
       
    24 #include "checklogfilestep.h"
       
    25 
       
    26 CCheckLogFileStep::~CCheckLogFileStep()
       
    27 /**
       
    28  * Destructor
       
    29  */
       
    30 	{
       
    31 	}
       
    32 
       
    33 CCheckLogFileStep::CCheckLogFileStep()
       
    34 /**
       
    35  * Constructor
       
    36  */
       
    37 	{
       
    38 	// Call base class method to set up the human readable name for logging
       
    39 	SetTestStepName(KCheckLogFileStep);
       
    40 	}
       
    41 
       
    42 TVerdict CCheckLogFileStep::doTestStepL()
       
    43 /**
       
    44  * @return - TVerdict code
       
    45  * Override of base class pure virtual
       
    46  * Demonstrates opening up a handle to the data saved at RChunk base using template class
       
    47  * Overwrite shared data with values and also demonstrates the locking mechanism
       
    48  */
       
    49 	{
       
    50 	INFO_PRINTF1(_L("Check log file."));
       
    51 	SetTestStepResult(EFail);
       
    52 	_LIT(KLogFilePath, "LogFilePath");
       
    53 	_LIT(KCheckString, "CheckString");
       
    54 	_LIT(KExpectedTimes, "ExpectedTimes");
       
    55 	
       
    56 	TPtrC logFilePath;
       
    57 	if (!GetStringFromConfig(ConfigSection(), KLogFilePath(), logFilePath))
       
    58 		{
       
    59 		ERR_PRINTF1(_L("Error occured when getting log file path"));
       
    60 		SetTestStepResult(EInconclusive);
       
    61 		return TestStepResult();
       
    62 		}
       
    63 	
       
    64 	TPtrC checkString;
       
    65 	if (!GetStringFromConfig(ConfigSection(), KCheckString(), checkString))
       
    66 		{
       
    67 		ERR_PRINTF1(_L("Error occured when getting check string"));
       
    68 		SetTestStepResult(EInconclusive);
       
    69 		return TestStepResult();
       
    70 		}
       
    71 	
       
    72 	RFs fs;
       
    73 	User::LeaveIfError(fs.Connect());
       
    74 	CleanupClosePushL(fs);
       
    75 	RFile file;
       
    76 	User::LeaveIfError(file.Open(fs, logFilePath, EFileRead|EFileShareAny));
       
    77 	CleanupClosePushL(file);
       
    78 	TInt fileSize;
       
    79 	User::LeaveIfError(file.Size(fileSize));
       
    80 	HBufC8* fileBuf8 = HBufC8::NewLC(fileSize);
       
    81 	TPtr8 fileBufPtr8 = fileBuf8->Des();
       
    82 	file.Read(fileBufPtr8);
       
    83 	TBuf<512> lineBuf;
       
    84 	TLex8 fileLex8(fileBufPtr8);
       
    85 	TInt times = 0;
       
    86 	
       
    87 	while (!fileLex8.Eos())
       
    88 		{
       
    89 		ReadLineL(fileLex8, lineBuf);
       
    90 		if (KErrNotFound != lineBuf.Find(checkString))
       
    91 			{
       
    92 			++times;
       
    93 			}
       
    94 		}
       
    95 	
       
    96 	TInt expectedTimes;
       
    97 	if (GetIntFromConfig(ConfigSection(), KExpectedTimes(), expectedTimes))
       
    98 		{
       
    99 		if (times == expectedTimes)
       
   100 			{
       
   101 			SetTestStepResult(EPass);
       
   102 			}
       
   103 		else
       
   104 			{
       
   105 			ERR_PRINTF3(_L("Test Failed! Expected Times: %d, Actual Times: %d"), expectedTimes, times);
       
   106 			}
       
   107 		}
       
   108 	
       
   109 	CleanupStack::PopAndDestroy(3, &fs);
       
   110 	return TestStepResult();
       
   111 	}
       
   112 
       
   113 void CCheckLogFileStep::ReadLineL(TLex8& aFileLex, TDes& aLineBuf)
       
   114 	{
       
   115 	aLineBuf.Zero();
       
   116 	TChar ch;
       
   117 	while ((ch=aFileLex.Get()) != '\n')
       
   118 		{
       
   119 		aLineBuf.Append(ch);
       
   120 		}
       
   121 	}