lbstest/lbstestproduct/common/src/ctlbsstepclearlog.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // @file ctlbsstepclearlog.cpp
       
    15 // This is the class implementation to clear the log file
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22  @test
       
    23 */
       
    24 		  
       
    25 #include "ctlbsstepclearlog.h"
       
    26 
       
    27 
       
    28 CT_LbsStep_ClearLog::CT_LbsStep_ClearLog(CT_LbsServer& aParent) : CT_LbsStep(aParent)
       
    29 	{
       
    30 	SetTestStepName(KLbsStep_ClearLog);
       
    31 	}
       
    32 
       
    33 /**
       
    34 Static Constructor
       
    35 */
       
    36 CT_LbsStep_ClearLog* CT_LbsStep_ClearLog::New(CT_LbsServer& aParent)
       
    37 	{
       
    38 	return new CT_LbsStep_ClearLog(aParent);
       
    39 	// Note the lack of ELeave.
       
    40 	// This means that having insufficient memory will return NULL;
       
    41 	}
       
    42 
       
    43 
       
    44 /**
       
    45 @pre 	
       
    46 @return Test verdict
       
    47 @post	Log file cleared
       
    48 */
       
    49  
       
    50 TVerdict CT_LbsStep_ClearLog::doTestStepL()
       
    51 	{
       
    52 	SetTestStepResult(EPass);
       
    53 
       
    54 	// Create necessary variables for Log reading
       
    55 	RFs theFs;
       
    56 	CLogClient* client;
       
    57 	CLogViewEvent* view;
       
    58 	CT_LbsAsyncWaiter* activeWaiter;
       
    59 		
       
    60 	//	Initialise variables
       
    61 	TInt ErrorCode = theFs.Connect();
       
    62 	if(ErrorCode)
       
    63 		{
       
    64 		INFO_PRINTF1(_L("\t Error: Open FileServer failed."));
       
    65 		SetTestStepResult(EFail);
       
    66 		}
       
    67 		
       
    68 
       
    69     client = CLogClient::NewL(theFs, CActive::EPriorityStandard);
       
    70 	view = CLogViewEvent::NewL(*client, CActive::EPriorityStandard);
       
    71 	activeWaiter = CT_LbsAsyncWaiter::NewL();			// NEW activeWaiter
       
    72 	
       
    73 	
       
    74 	// Setup a time in the future, before which all events will be deleted
       
    75  	_LIT(KDateCorrect1,"20900101:"); 
       
    76  	TTime time;
       
    77 	TBuf <10> theDate(KDateCorrect1);
       
    78 	TInt err=time.Set(theDate); 
       
    79 	
       
    80 	// Ensure time has been set correctly
       
    81 	if(err != KErrNone)
       
    82 		{
       
    83 		INFO_PRINTF1(_L("Failed to set time"));
       
    84 		}
       
    85 		
       
    86 	if(err == KErrGeneral)
       
    87 		{
       
    88 		INFO_PRINTF1(_L("Time syntax is incorrect"));
       
    89 		}
       
    90 	
       
    91 	// Set the filter to view ALL logs
       
    92 	CLogFilter* filter = CLogFilter::NewL();			// NEW FILTER
       
    93 	CleanupStack::PushL(filter);
       
    94 	TBool res = view->SetFilterL(*filter, activeWaiter->iStatus);
       
    95 	if (res == EFalse)
       
    96 		{
       
    97 		INFO_PRINTF1(_L("\t No such events to filter in the view."));
       
    98 		client->Cancel();
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		// else If there are logs, flush them
       
   103 			
       
   104 		// Cancel outstanding requests
       
   105 		client->Cancel();	
       
   106 		activeWaiter->StartAndWait();
       
   107 		if (activeWaiter->iStatus != KErrNone)
       
   108 			{
       
   109 			INFO_PRINTF2(_L("\t Error: Cancel returned error %d."),activeWaiter->iStatus.Int());
       
   110 			SetTestStepResult(EFail);
       
   111 			}
       
   112 
       
   113 		// Clear ALL logs
       
   114 		client->ClearLog(time, activeWaiter->iStatus);
       
   115 		activeWaiter->StartAndWait();
       
   116 		if (activeWaiter->iStatus != KErrNone)
       
   117 			{
       
   118 			INFO_PRINTF2(_L("\t Error: Clear log returned error %d."),activeWaiter->iStatus.Int());
       
   119 			SetTestStepResult(EFail);
       
   120 			}	
       
   121 			
       
   122 		//Confirm log is cleared
       
   123 		if(view->CountL() != 0)
       
   124 			{
       
   125 			INFO_PRINTF2(_L("<FONT><B>ERROR: Log still has %d entries</B></FONT>"),view->CountL());
       
   126 			SetTestStepResult(EFail);
       
   127 			}
       
   128 				
       
   129 		}
       
   130 	
       
   131 	CleanupStack::PopAndDestroy(filter);	
       
   132 		
       
   133 	// Cleanup everything
       
   134 	view->Cancel();
       
   135 	client->Cancel();
       
   136 
       
   137 	delete view;
       
   138 	delete client;
       
   139 	theFs.Close();
       
   140 	delete activeWaiter;
       
   141 
       
   142 	return TestStepResult();
       
   143 	}
       
   144