lbs/lbsclient/src/ctlbsclientpostp256.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2002-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 <EPos_CPosModules.h>
       
    20 #include <EPos_CPosModuleIdList.h>
       
    21 #include "ctlbsclientpostp256.h"
       
    22 #include <e32std.h>
       
    23 
       
    24 // CONSTANTS
       
    25 const TInt KNoMultipleClients=2;
       
    26 const TUint KMaxHeapSize=0x80000;
       
    27 
       
    28 // Structure for passing parameters to threads
       
    29 struct MyThreadData
       
    30     {
       
    31     TBool iTestFlag;
       
    32     };
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // Constructor.
       
    38 // ---------------------------------------------------------
       
    39 CT_LbsClientPosTp256::CT_LbsClientPosTp256(CT_LbsServer& aParent): CT_LbsPortedStepBase(aParent)
       
    40 	{  
       
    41 	_LIT(KTestName, "Tp256 - Location Settings and Multiple Clients");
       
    42 	SetTestStepName(KTestName); 
       
    43 	}
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // Destructor.
       
    47 // ---------------------------------------------------------
       
    48 CT_LbsClientPosTp256::~CT_LbsClientPosTp256()
       
    49 	{
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CT_LbsClientPosTp256::StartL
       
    54 //
       
    55 // (other items were commented in a header).
       
    56 // ---------------------------------------------------------
       
    57 //
       
    58 void CT_LbsClientPosTp256::StartL()
       
    59     {
       
    60     _LIT(KMultipleErr, "Error %d when multiple clients access the CPosModules, err from client:%d");
       
    61     _LIT(KSuccess, "Client %d is successful");
       
    62     _LIT(KAllErr, "All clients gets error when multiple clients access the CPosModules");
       
    63     _LIT(KPanicErr, "Panic when multiple clients access the CPosModules,  Thread: %d panics");
       
    64     
       
    65     TFixedArray<TRequestStatus, KNoMultipleClients> statuses;
       
    66     //make a request just to make sure att all databases are created.
       
    67 
       
    68 	SetupPsyL(iUidMultiPsy);
       
    69 
       
    70     //synchronous request
       
    71     ConnectL();
       
    72 
       
    73     User::LeaveIfError(OpenPositionerByName(iUidMultiPsy));
       
    74 
       
    75     TPositionInfo info = TPositionInfo();
       
    76 
       
    77 	RequestL(info);
       
    78 
       
    79     //potenial memory leak if above function leav
       
    80     ClosePositioner();
       
    81     Disconnect();
       
    82 
       
    83     //End first request.
       
    84 
       
    85 
       
    86     TInt errorsFound = KErrNone;
       
    87     CreateThreadsL();
       
    88 
       
    89     for (TInt i=0; i<iThreads.Count(); i++)
       
    90         { 
       
    91         iThreads[i].Logon(statuses[i]);
       
    92         iThreads[i].Resume();
       
    93         }
       
    94     
       
    95     for (TInt t=0; t<iThreads.Count(); t++)
       
    96         {
       
    97         TInt exitReason = iThreads[t].ExitReason();
       
    98         
       
    99         TBuf<150> buf;
       
   100         if (exitReason != KErrNone) 
       
   101             {      
       
   102             buf.Format(KMultipleErr, exitReason, t);
       
   103             INFO_PRINTF1(buf);
       
   104 
       
   105             errorsFound++;
       
   106             }
       
   107         else
       
   108             {
       
   109             buf.Format(KSuccess, t);
       
   110             INFO_PRINTF1(buf);
       
   111             }
       
   112         AssertTrueL(iThreads[t].ExitType() != EExitPanic, KPanicErr, t);
       
   113         }
       
   114     
       
   115     AssertTrueL(errorsFound < KNoMultipleClients, KAllErr, KErrGeneral);   
       
   116     
       
   117     _LIT(KPass, "CT_LbsClientPosTp256 passed!!!");
       
   118     INFO_PRINTF1(KPass);
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CT_LbsClientPosTp256::CloseTest
       
   123 //
       
   124 // (other items were commented in a header).
       
   125 // ---------------------------------------------------------
       
   126 //
       
   127 void CT_LbsClientPosTp256::CloseTest()
       
   128     {
       
   129     for (TInt i=0; i<iThreads.Count(); i++)
       
   130         {
       
   131         iThreads[i].Close();
       
   132         }
       
   133 
       
   134     iThreads.Close();
       
   135     iNames.ResetAndDestroy();
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // void RunTestL
       
   140 //
       
   141 // (other items were commented in a header).
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 void RunTestL(TAny* aData)
       
   145     {
       
   146     const TInt KNrOfRounds = 50;
       
   147    
       
   148     CPosModules* db = CPosModules::OpenL();
       
   149     CleanupStack::PushL(db);
       
   150 
       
   151     TInt nrOfModules = 0;
       
   152 
       
   153     // Read parameters from TAny*
       
   154     MyThreadData* info = (MyThreadData*) aData;
       
   155     TInt i = 0;
       
   156     for (i=0;i<KNrOfRounds; i++)
       
   157         {
       
   158         //db->ResetAllModulesL();
       
   159         CPosModuleIdList* myDebugList = db->ModuleIdListLC();
       
   160         
       
   161         nrOfModules = myDebugList->Count();
       
   162         TPositionModuleInfo debugModuleInfo;
       
   163         TBuf<40> moduleName;
       
   164         TPositionQuality quality;
       
   165         
       
   166         for (TInt i=0;i<nrOfModules;i++)
       
   167             {
       
   168             db->GetModuleInfoL(myDebugList->At(i), debugModuleInfo);
       
   169             moduleName.Zero();
       
   170             debugModuleInfo.GetModuleName(moduleName);
       
   171             debugModuleInfo.GetPositionQuality(quality);
       
   172             }
       
   173             CleanupStack::PopAndDestroy(myDebugList);
       
   174         }
       
   175 
       
   176    for (i=0;i<KNrOfRounds; i++)
       
   177         {
       
   178         // The first thread does this
       
   179         if (info->iTestFlag)
       
   180             {
       
   181             for (TInt j=0;j<nrOfModules;j++)
       
   182                 {
       
   183                 // Just change priority
       
   184                 db->SetModulePriorityL(nrOfModules-j-1, j);
       
   185                 }
       
   186             }
       
   187         // And all the other thread does this
       
   188         else
       
   189             {
       
   190             CPosModuleIdList* myDebugList = db->ModuleIdListLC();
       
   191             
       
   192             TInt debugCount = myDebugList->Count();
       
   193             TPositionModuleInfo debugModuleInfo;
       
   194             TBuf<20> moduleName;
       
   195             TPositionQuality quality;
       
   196             
       
   197             for (TInt i=0;i<debugCount;i++)
       
   198                 {
       
   199                 db->GetModuleInfoL(myDebugList->At(i), debugModuleInfo);
       
   200                 moduleName.Zero();
       
   201                 debugModuleInfo.GetModuleName(moduleName);
       
   202                 debugModuleInfo.GetPositionQuality(quality);
       
   203                 }
       
   204             CleanupStack::PopAndDestroy(myDebugList);
       
   205             }
       
   206         }
       
   207         
       
   208 
       
   209     CleanupStack::PopAndDestroy(db);
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // LOCAL_C TInt ThreadFunction
       
   214 //
       
   215 // (other items were commented in a header).
       
   216 // ---------------------------------------------------------
       
   217 //
       
   218 LOCAL_C TInt ThreadFunction(TAny* aData)
       
   219     {
       
   220     __UHEAP_MARK;
       
   221     CTrapCleanup* cleanup=CTrapCleanup::New(); // get clean-up stack
       
   222     
       
   223     if (cleanup == NULL)
       
   224         {
       
   225         return KErrNoMemory;
       
   226         }
       
   227     // we need an ActiveScheduler 
       
   228     CActiveScheduler scheduler;
       
   229     CActiveScheduler::Install(&scheduler);   
       
   230 
       
   231     TRAPD(err, RunTestL(aData));
       
   232     
       
   233     delete cleanup; // destroy clean-up stack
       
   234     __UHEAP_MARKEND;
       
   235     return err;
       
   236     }
       
   237 
       
   238 // ---------------------------------------------------------
       
   239 // CT_LbsClientPosTp256::CreateThreadsL
       
   240 //
       
   241 // (other items were commented in a header).
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CT_LbsClientPosTp256::CreateThreadsL()
       
   245     {
       
   246     _LIT(KThreadName, "TP256 test thread%d");
       
   247     _LIT(KCreateThreadErr, "Create thread failed with %d");
       
   248 
       
   249     for (TInt i=0; i<KNoMultipleClients; i++)
       
   250         {
       
   251         // Introduce parameters for each thread.
       
   252         MyThreadData info;
       
   253         
       
   254         if (i == 0) info.iTestFlag = ETrue;
       
   255         else info.iTestFlag = EFalse;
       
   256 
       
   257         RThread thread;
       
   258         TBuf<32> name;
       
   259 	    name.Format(KThreadName, 1+iThreads.Count());
       
   260 
       
   261         TInt err;
       
   262         err = thread.Create(name, ThreadFunction, KDefaultStackSize, KMinHeapSize, KMaxHeapSize, reinterpret_cast<TAny*>(&info));
       
   263         AssertTrueL(err == KErrNone, KCreateThreadErr, err);                                                                  
       
   264         
       
   265         iThreads.Append(thread);
       
   266         }
       
   267     }
       
   268 
       
   269 
       
   270 void CT_LbsClientPosTp256::RequestL(TPositionInfoBase& aInfoBase)
       
   271 	{
       
   272 	_LIT(KService, "service");
       
   273     TInt err = PerformSyncRequest(KService, &aInfoBase);
       
   274 
       
   275     if (err != KErrNone)
       
   276         {
       
   277         _LIT(KErrorRequest, "The request was not completed with KErrorNone, errCode = %d");
       
   278 		TBuf<100> buf;
       
   279 		buf.Format(KErrorRequest, err);
       
   280         LogErrorAndLeaveL(buf);
       
   281         }
       
   282 
       
   283 	_LIT(KIncorrectPsySyncRequestError,
       
   284           "TP2. Position from wrong PSY received (sync request).");
       
   285     if (iUidMultiPsy != aInfoBase.ModuleId())
       
   286         {
       
   287         LogErrorAndLeaveL(KIncorrectPsySyncRequestError);
       
   288         }
       
   289 	}
       
   290     
       
   291 //  End of File