lbs/lbsclient/src/ctlbsclientpostp201.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2001-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "ctlbsclientpostp201.h"
       
    20 #include <LbsPositionInfo.h>
       
    21 #include <Lbs.h>
       
    22 #include <LbsCommon.h>
       
    23 #include <LbsRequestor.h>
       
    24 #include <s32file.h>
       
    25 #include "ctlbsclientobserver.h"
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KSecond = 1*1000*1000;
       
    29 const TInt KMaxSentenceLength = 60; //Max length of each line in EXEClient-logfile
       
    30 const TInt KNoOfEXCalls = 3; // Nr of calls to ExeClient
       
    31 _LIT(KExeClientPath, "ctlbsexeclient");
       
    32 _LIT(KExeResultPath, "c:\\logs\\execlientresult%d.txt");
       
    33 _LIT(KSucce, "Test %d was successful");
       
    34 _LIT(KFail, "Test %d failed");
       
    35 _LIT8(KSuccess, "SUCCESS"); //String to search for that indicates the test was succesful
       
    36 
       
    37 // ================= MEMBER FUNCTIONS =======================
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // Constructor.
       
    41 // ---------------------------------------------------------
       
    42 CT_LbsClientPosTp201::CT_LbsClientPosTp201(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    43 	{  
       
    44 	_LIT(KTestName, "TP201 - Exe Client");
       
    45 	SetTestStepName(KTestName); 
       
    46 	}
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // Destructor.
       
    50 // ---------------------------------------------------------
       
    51 CT_LbsClientPosTp201::~CT_LbsClientPosTp201()
       
    52 	{
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------
       
    56 // CT_LbsClientPosTp201::StartL
       
    57 //
       
    58 // (other items were commented in a header).
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 void CT_LbsClientPosTp201::StartL()
       
    62     {
       
    63 	
       
    64     //This test can be run on emulator now.
       
    65 	TInt result;
       
    66 	TInt i;
       
    67 	TInt foundsucces; 
       
    68 	RProcess execlient[KNoOfEXCalls];
       
    69 	RFile file;
       
    70 	RFileReadStream fstream;
       
    71 	RFs fileSession;
       
    72 	User::LeaveIfError(fileSession.Connect());
       
    73 	CleanupClosePushL(fileSession);
       
    74 	CleanupClosePushL(fstream);
       
    75 	CleanupClosePushL(file);
       
    76 	CFileMan* fileMan = CFileMan::NewL(fileSession);
       
    77 	CleanupStack::PushL(fileMan);
       
    78 
       
    79 	_LIT(KRemoveFiles, "Remove files");
       
    80 	INFO_PRINTF1(KRemoveFiles);
       
    81 
       
    82 	//1. First check for old ExeClientResult-files to remove.
       
    83 	TBuf<40> filepath;
       
    84     filepath.Append(KExeResultPath);
       
    85 	for ( i = 1; i<=KNoOfEXCalls; i++)
       
    86 		{
       
    87 		filepath.Format(KExeResultPath,i);
       
    88 		TInt err = fileMan->Delete(filepath, CFileMan::EOverWrite);
       
    89 		if (err != KErrNone && err != KErrNotFound)
       
    90 			{
       
    91 			_LIT(KErrRemoveDll, "Removal of a previous ExeClientResult-file failed!");
       
    92 			TBuf<50> buf;
       
    93 			buf.Format(KErrRemoveDll, err);
       
    94 			LogErrorAndLeaveL(buf);
       
    95 			}
       
    96 		}	
       
    97 	
       
    98 	_LIT(KStartClients, "Start clients");
       
    99 	INFO_PRINTF1(KStartClients);
       
   100 
       
   101 	//2. Make 3 calls to ExeClient.
       
   102 	for ( i = 1; i<= KNoOfEXCalls; i++)
       
   103 		{
       
   104 		//Start the execlient-process
       
   105 		result = execlient[i-1].Create(KExeClientPath, KNullDesC);
       
   106 		User::LeaveIfError(result);
       
   107 		execlient[i-1].Resume();	//make the execlient visible
       
   108 		User::After(6000000);
       
   109 		}
       
   110 	
       
   111 	CT_LbsClientObserver::WaitForEPosShutdown(); //Wait for Epos to complete
       
   112     User::After(KSecond); //Wait for completion of writing to files. 1 minute.
       
   113 	for ( i = 0; i < KNoOfEXCalls; i++)
       
   114 		{	
       
   115 		TRequestStatus closed;
       
   116 		execlient[i].Logon(closed);
       
   117 		User::WaitForRequest(closed);
       
   118 
       
   119 	    TBuf<100> exit;
       
   120 	    _LIT(KExitClient, "Client %d exited: Type %d, Reason %d");
       
   121 	    exit.Format(KExitClient, 
       
   122             	    i+1, execlient[i].ExitType(), execlient[i].ExitReason());
       
   123         INFO_PRINTF1(exit);
       
   124 
       
   125 		execlient[i].Close(); //Close handle to exe-client
       
   126 		}
       
   127 	_LIT(KCheckResults, "Check results");
       
   128 	INFO_PRINTF1(KCheckResults);
       
   129 
       
   130 	//3. See if all calls were successes
       
   131 	TBuf<40> successinfo;
       
   132 	successinfo.Append(KSucce);
       
   133 	TBuf<40> failinfo;
       
   134 	failinfo.Append(KFail);
       
   135 	for ( i = 1; i <= KNoOfEXCalls; i++)
       
   136 		{
       
   137 		filepath.Format(KExeResultPath,i);
       
   138 		User::LeaveIfError(file.Open(fileSession, filepath, EFileShareReadersOnly));//open read only
       
   139 		fstream.Attach(file);
       
   140 
       
   141 		TBuf8<KMaxSentenceLength> dbuffer; //Buffer to place read data from file
       
   142 		TBuf8<KMaxSentenceLength> prevbuffer; //Buffer to place previous read data from file
       
   143 		TBool search = ETrue;
       
   144 		const TChar eoline(';');
       
   145 		while (search) 
       
   146 			{ 
       
   147 			dbuffer.Delete(0, KMaxSentenceLength);
       
   148 			TRAPD(ferr, (fstream.ReadL(dbuffer,eoline)));
       
   149 			if ( ferr == KErrEof) 
       
   150 				{
       
   151 				search = EFalse; //stop searching
       
   152 				}
       
   153 			else if ( ferr == KErrNone)
       
   154 				{
       
   155 				prevbuffer.Delete(0, KMaxSentenceLength);
       
   156 				prevbuffer = dbuffer;
       
   157 				}
       
   158 			else 
       
   159 				{
       
   160 				_LIT(KReadError, "Error when reading from log-file.");
       
   161 				LogErrorAndLeaveL(KReadError);
       
   162 				}
       
   163 			}
       
   164 		//Check if success
       
   165 		foundsucces = prevbuffer.Find(KSuccess);
       
   166 		if ( foundsucces != KErrNotFound)
       
   167 			{
       
   168 			successinfo.Format(KSucce,i);
       
   169 			INFO_PRINTF1(successinfo);
       
   170 			}
       
   171 		else
       
   172 			{
       
   173 			failinfo.Format(KFail,i);
       
   174 			LogErrorAndLeaveL(failinfo);
       
   175 			}
       
   176 		} //for
       
   177 
       
   178 	_LIT(KDone, "Done.");
       
   179 	INFO_PRINTF1(KDone);
       
   180 
       
   181 	//4. Let's clean...
       
   182 	CleanupStack::PopAndDestroy(fileMan); //fileMan
       
   183 	CleanupStack::PopAndDestroy(&file); //file
       
   184 	CleanupStack::PopAndDestroy(&fstream); //fstream
       
   185 	CleanupStack::PopAndDestroy(&fileSession); //fileSession
       
   186 	}
       
   187 
       
   188 // End of File