lbs/lbsclient/src/ctlbsclientpostp27.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 //  INCLUDES
       
    19 #include "ctlbsclientpostp27.h"
       
    20 #include "ctlbsposclientholder.h"
       
    21 #include <EPos_CPosModules.h>
       
    22 #include <EPos_CPosModuleUpdate.h>
       
    23 #include <EPos_CPosModuleIdList.h>
       
    24 #include <e32keys.h>
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // Constructor.
       
    32 // ---------------------------------------------------------
       
    33 CT_LbsClientPosTp27::CT_LbsClientPosTp27(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    34 	{  
       
    35 	_LIT(KTestName,"TP27 - Cancel Request");
       
    36 	SetTestStepName(KTestName); 
       
    37 	}
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // Destructor.
       
    41 // ---------------------------------------------------------
       
    42 CT_LbsClientPosTp27::~CT_LbsClientPosTp27()
       
    43 	{
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------
       
    47 // CT_LbsClientPosTp27::CloseTest
       
    48 // Always called after the test, even if the test leaves
       
    49 // (other items were commented in a header).
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 void CT_LbsClientPosTp27::CloseTest()
       
    53     {
       
    54     ClosePositioner();
       
    55 	Disconnect();
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CT_LbsClientPosTp27::StartL
       
    60 //
       
    61 // (other items were commented in a header).
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 void CT_LbsClientPosTp27::StartL()
       
    65     {
       
    66     SetupPsyL(iUidDynDbTestPsy);
       
    67     TTimeIntervalMicroSeconds timeLimit(5000000);
       
    68     ConnectL();
       
    69     User::LeaveIfError(OpenPositioner());
       
    70 
       
    71     TPositionInfo posInfo = TPositionInfo();
       
    72     _LIT(KService, "service");
       
    73     TInt err = PerformSyncRequest(KService, &posInfo);
       
    74 
       
    75     if (err != KErrNone)
       
    76         {
       
    77         _LIT(KErrorRequest, "The request was not completed with KErrorNone");
       
    78         LogErrorAndLeaveL(KErrorRequest);
       
    79         }
       
    80 	ClosePositioner();
       
    81 	Disconnect();
       
    82 	//Cancel quick (most likely before the PSY gets involved
       
    83 	MakeCancelRequestL(TTimeIntervalMicroSeconds32(100), timeLimit );
       
    84 	//Cancel after 1 second so that the PSY gets involved.
       
    85 	MakeCancelRequestL(TTimeIntervalMicroSeconds32(1000000), timeLimit);
       
    86 
       
    87 	CheckCancelRequestL();
       
    88 
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CT_LbsClientPosTp27::MakeCancelRequestL
       
    93 //
       
    94 // (other items were commented in a header).
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 void CT_LbsClientPosTp27::MakeCancelRequestL(TTimeIntervalMicroSeconds32 aCancelTime, TTimeIntervalMicroSeconds aTimeLimit)
       
    98 	{	
       
    99 	const TInt KNrOfClients = 1;
       
   100     CT_LbsPosClientHolder* clients = CT_LbsPosClientHolder::NewLC(KNrOfClients);
       
   101 
       
   102     clients->SetRequesterWillCancelL();
       
   103 	clients ->SetCancelTime(aCancelTime);
       
   104     clients->MakeRequests();
       
   105 
       
   106     TInt status;
       
   107 
       
   108     TPositionInfo myModuleInfo;
       
   109     TTimeIntervalMicroSeconds reqTime;
       
   110     clients->GetResult(status, myModuleInfo, reqTime);
       
   111 
       
   112     if (status != KErrCancel)
       
   113         {
       
   114         _LIT(KReqWasNotCancelled, "The request was not cancelled, return code %d");
       
   115         TBuf<100> buf;
       
   116         buf.Format(KReqWasNotCancelled, status);
       
   117         LogErrorAndLeaveL(buf);
       
   118         }
       
   119    
       
   120     if (reqTime > aTimeLimit)
       
   121         {
       
   122         _LIT(KError, "The request took too long, %d microsecs. It was probably never cancelled");
       
   123         TBuf<100> buf;
       
   124         buf.Format(KError, reqTime.Int64());
       
   125         LogErrorAndLeaveL(buf);
       
   126         }
       
   127 
       
   128     _LIT(KMsg, "The request was cancelled after %d microsecs.");
       
   129     TBuf<100> buf;
       
   130     buf.Format(KMsg, reqTime.Int64());
       
   131     INFO_PRINTF1(buf);
       
   132     CleanupStack::PopAndDestroy(clients); //clients
       
   133 	}
       
   134 
       
   135 // ---------------------------------------------------------
       
   136 // CT_LbsClientPosTp27::MakeCancelRequest2L
       
   137 //
       
   138 // (other items were commented in a header).
       
   139 // ---------------------------------------------------------
       
   140 //
       
   141 void CT_LbsClientPosTp27::MakeCancelRequest2L(TTimeIntervalMicroSeconds32 aCancelTime, TTimeIntervalMicroSeconds aTimeLimit)
       
   142 	{	
       
   143 	_LIT(KCancelRequest,"MakeCancelRequest2L");
       
   144 	INFO_PRINTF1(KCancelRequest);
       
   145 
       
   146 	RFs fs;
       
   147 	TInt err = fs.Connect();
       
   148     CleanupClosePushL(fs);
       
   149 
       
   150     DisableAllPsyL();
       
   151 	ConnectL();
       
   152 	// TestPsy9 waits for 6 sec before returning a position
       
   153     EnablePsyL(iUidTestPsy9);
       
   154     err = OpenPositionerByName(iUidTestPsy9);
       
   155 	if (err != KErrNone)
       
   156 		{
       
   157 		TBuf<150> buf;
       
   158 		_LIT(KErr, "OpenPositionerByName failed with %d");
       
   159 		buf.Format(KErr, err);
       
   160 		LogErrorAndLeaveL(buf);
       
   161 		}
       
   162 	
       
   163 	_LIT(KPerformRequest,"The request info");
       
   164 	PerformRequestL(KPerformRequest, CRequestor::ERequestorService, CRequestor::EFormatApplication);
       
   165 
       
   166 	const TInt KNrOfClients = 2;
       
   167 	// TestPsy6 waits for 5 sec before returning a position
       
   168     EnablePsyL(iUidTestPsy6);
       
   169     CT_LbsPosClientHolder* clients = CT_LbsPosClientHolder::NewLC(KNrOfClients, iUidTestPsy6, ETrue);
       
   170 
       
   171 	clients->SetRequesterWillCancelL();
       
   172 	clients->SetCancelTime(aCancelTime);
       
   173 
       
   174     clients->MakeRequests();
       
   175 	CheckRequestResultL(KErrNone);
       
   176 
       
   177     TInt status;
       
   178     TPositionInfo myModuleInfo;
       
   179     TTimeIntervalMicroSeconds reqTime;
       
   180     clients->GetResult(status, myModuleInfo, reqTime);
       
   181 
       
   182     if (status != KErrCancel)
       
   183         {
       
   184         _LIT(KReqWasNotCancelled, "The request was not cancelled, return code %d");
       
   185         TBuf<100> buf;
       
   186         buf.Format(KReqWasNotCancelled, status);
       
   187         LogErrorAndLeaveL(buf);
       
   188         }
       
   189 
       
   190     if (reqTime > aTimeLimit)
       
   191         {
       
   192         _LIT(KError, "The request took too long, %d microsecs. It was probably never cancelled");
       
   193         TBuf<100> buf;
       
   194         buf.Format(KError, reqTime.Int64());
       
   195         LogErrorAndLeaveL(buf);
       
   196         }
       
   197 
       
   198     _LIT(KMsg, "The request was cancelled after %d microsecs.");
       
   199     TBuf<100> buf;
       
   200     buf.Format(KMsg, reqTime.Int64());
       
   201     INFO_PRINTF1(buf);
       
   202     
       
   203 	ClosePositioner();
       
   204 	Disconnect();
       
   205 
       
   206 	//Check request log
       
   207 	RArray<TInt> arrayId;
       
   208 	CleanupClosePushL(arrayId);
       
   209 	err = KErrNone;
       
   210 
       
   211 	if (err != KErrNone)
       
   212 		{
       
   213 		TBuf<150> buf;
       
   214 		_LIT(KErr, "GetLogEntryListL() returned error, %d");
       
   215 		buf.Format(KErr, err);
       
   216 		LogErrorAndLeaveL(buf);
       
   217 		}
       
   218 
       
   219 	// All requests should have been logged, including the cancelled requests
       
   220 	TInt numberOfElements = arrayId. Count();
       
   221 
       
   222 	if (numberOfElements != 3)
       
   223 	{
       
   224 	buf.Zero();
       
   225 	_LIT(KErrLog,"ERROR: The log contains wrong number of entries, was %d");
       
   226 	buf.Format(KErrLog, numberOfElements);
       
   227 	INFO_PRINTF1(buf);
       
   228 	_LIT(KErrAndLeave, "Cancelled request has not been logged!!!");
       
   229 	LogErrorAndLeaveL(KErrAndLeave);
       
   230 	}
       
   231 
       
   232 	CleanupStack::PopAndDestroy(&arrayId);
       
   233 	CleanupStack::PopAndDestroy(clients); //clients
       
   234 	CleanupStack::PopAndDestroy(1); // privCtrl
       
   235 	CleanupStack::PopAndDestroy(1); //fs
       
   236 	}
       
   237 
       
   238 // ---------------------------------------------------------
       
   239 // CT_LbsClientPosTp27::CheckCancelRequestL
       
   240 //
       
   241 // (other items were commented in a header).
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CT_LbsClientPosTp27::CheckCancelRequestL()
       
   245 	{
       
   246 	_LIT(KFunctionName, "We are inside CheckCancelRequestL");
       
   247 	INFO_PRINTF1(KFunctionName);
       
   248 
       
   249 	RFs fs;
       
   250     User::LeaveIfError(fs.Connect());
       
   251     CleanupClosePushL(fs);
       
   252 
       
   253 	// TestPsy9 waits for 6 sec before returning a position
       
   254 	SetupPsyL(iUidTestPsy9);
       
   255 	TTimeIntervalMicroSeconds32 cancelTime(2000000); // 2 sec
       
   256 	const TInt KNrOfClients = 1;
       
   257     CT_LbsPosClientHolder* clients = CT_LbsPosClientHolder::NewLC(KNrOfClients, iUidTestPsy9);
       
   258 
       
   259     clients->SetRequesterWillCancelL();
       
   260 	clients->SetCancelTime(cancelTime);
       
   261     clients->MakeRequests();
       
   262 
       
   263     TInt status;
       
   264 
       
   265     TPositionInfo myModuleInfo;
       
   266     TTimeIntervalMicroSeconds reqTime;
       
   267     clients->GetResult(status, myModuleInfo, reqTime);
       
   268 
       
   269     if (status != KErrCancel)
       
   270         {
       
   271         _LIT(KReqWasNotCancelled, "The request was not cancelled, return code %d");
       
   272         TBuf<100> buf;
       
   273         buf.Format(KReqWasNotCancelled, status);
       
   274         LogErrorAndLeaveL(buf);
       
   275         }
       
   276 
       
   277     _LIT(KMsg, "The request was cancelled after %d microsecs.");
       
   278     TBuf<100> buf;
       
   279     buf.Format(KMsg, reqTime.Int64());
       
   280     INFO_PRINTF1(buf);
       
   281 
       
   282 	//Check request log
       
   283 	RArray<TInt> arrayId;
       
   284 	CleanupClosePushL(arrayId);
       
   285 	
       
   286 	CleanupStack::PopAndDestroy(&arrayId);
       
   287 	CleanupStack::PopAndDestroy(clients); //clients
       
   288 	CleanupStack::PopAndDestroy(1); // privCtrl
       
   289 	}
       
   290 
       
   291 // ---------------------------------------------------------
       
   292 // CT_LbsClientPosTp27::DisableAllPsyL
       
   293 //
       
   294 // (other items were commented in a header).
       
   295 // ---------------------------------------------------------
       
   296 //
       
   297 void CT_LbsClientPosTp27::DisableAllPsyL()
       
   298     {
       
   299     CPosModules* db = CPosModules::OpenL();
       
   300     CleanupStack::PushL(db);
       
   301     CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
       
   302 
       
   303     // Disable PSY
       
   304     moduleUpdate->SetUpdateAvailability(EFalse);
       
   305     CPosModuleIdList* prioList = db->ModuleIdListLC();
       
   306 
       
   307     // Disable all PSY:s
       
   308     for (TInt i = 0 ; i < prioList->Count(); i++)
       
   309         {
       
   310         db->UpdateModuleL((*prioList)[i], *moduleUpdate);
       
   311         }
       
   312 
       
   313     CleanupStack::PopAndDestroy(prioList);
       
   314     CleanupStack::PopAndDestroy(moduleUpdate);
       
   315     CleanupStack::PopAndDestroy(db);
       
   316     }
       
   317 
       
   318 // ---------------------------------------------------------
       
   319 // CT_LbsClientPosTp27::DisableAllPsyL
       
   320 //
       
   321 // (other items were commented in a header).
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void CT_LbsClientPosTp27::EnablePsyL(const TUid aPsyUid)
       
   325     {
       
   326     CPosModules* db = CPosModules::OpenL();
       
   327     CleanupStack::PushL(db);
       
   328     CPosModuleUpdate* moduleUpdate = CPosModuleUpdate::NewLC();
       
   329 
       
   330     // Enable the PSY that came as an in parameter
       
   331     moduleUpdate->SetUpdateAvailability(ETrue);
       
   332     db->UpdateModuleL(aPsyUid, *moduleUpdate);
       
   333 
       
   334     CleanupStack::PopAndDestroy(moduleUpdate);
       
   335     CleanupStack::PopAndDestroy(db);
       
   336     }