applayerprotocols/httpservice/test/httpservicetest/ctesthttpclientstep.cpp
changeset 19 2f328ce1b263
parent 0 b16258d2340f
child 23 ea9c9681bbaf
equal deleted inserted replaced
16:cb0c8a2aff2d 19:2f328ce1b263
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 #include "chttpservice.h"
    17 #include "chttpservice.h"
    18 #include "ctestclienthttpget.h"
    18 #include "ctestclienthttpget.h"
    19 #include "ctestclienthttppost.h"
    19 #include "ctestclienthttppost.h"
    20 #include <escapeutils.h>
    20 #include <escapeutils.h>
    21 #include <thttphdrval.h>
    21 #include <thttphdrval.h>
       
    22 #include <commdbconnpref.h>
    22 #include "httptestutils.h"
    23 #include "httptestutils.h"
    23 #include "clocaltestserver.h"
    24 #include "clocaltestserver.h"
    24 #include "chttpclienttestparams.h"
    25 #include "chttpclienttestparams.h"
       
    26 #include "ctesthttpserviceauthentication.h"
       
    27 #include "chttpnetworkconnectioninfo.h"
    25 
    28 
    26 _LIT(KTestCaseName, "TestCaseName");
    29 _LIT(KTestCaseName, "TestCaseName");
    27 _LIT8(KUserAgent, "HTTP Client API Test");
    30 _LIT8(KUserAgent, "HTTP Client API Test");
    28 _LIT(KTestHttpClientAPITestTitle, "HTTP client API Unit Test Harness");
    31 _LIT(KTestHttpClientAPITestTitle, "HTTP client API Unit Test Harness");
    29 const TInt KMaxNoOfConnections = 6;
    32 const TInt KMaxNoOfConnections = 6;
    41     delete iHttpClient;
    44     delete iHttpClient;
    42     delete iTestServer;
    45     delete iTestServer;
    43     delete iTestUtils;    
    46     delete iTestUtils;    
    44     delete iTestParamArray;
    47     delete iTestParamArray;
    45     delete iActiveScheduler;
    48     delete iActiveScheduler;
       
    49     delete iTestHttpServiceAuthentication;
    46     }
    50     }
    47 
    51 
    48 // TEF virtuals
    52 // TEF virtuals
    49 TVerdict CTestHttpClientStep::doTestStepPreambleL()
    53 TVerdict CTestHttpClientStep::doTestStepPreambleL()
    50     {
    54     {
       
    55     TInt status;
    51     iActiveScheduler = new (ELeave) CActiveScheduler();
    56     iActiveScheduler = new (ELeave) CActiveScheduler();
    52     CActiveScheduler::Install(iActiveScheduler);
    57     CActiveScheduler::Install(iActiveScheduler);
    53     iTestParamArray = new(ELeave) CHttpClientTestParamArray;
    58     iTestParamArray = new(ELeave) CHttpClientTestParamArray;
    54     iTestUtils = CHTTPTestUtils::NewL(KTestHttpClientAPITestTitle());
    59     iTestUtils = CHTTPTestUtils::NewL(KTestHttpClientAPITestTitle());
    55     iTestUtils->InitCommsL();
    60     
    56     
    61     
    57     iTestServer = CLocalTestServer::NewL(*iTestUtils, *this, *iTestParamArray);
    62     iTestServer = CLocalTestServer::NewL(*iTestUtils, *this, *iTestParamArray);
    58     iHttpClient = CHttpService::NewL();
    63     iHttpClient = CHttpService::NewL();
       
    64     TCommDbConnPref connPref;
       
    65     connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
    66     connPref.SetIapId(1);
       
    67     connPref.SetNetId(0);
       
    68     iHttpConnInfo = iHttpClient->HttpNetworkConnection();
       
    69     status = iHttpConnInfo->Start();
    59     THttpHeaderValueVariant variant(KUserAgent());
    70     THttpHeaderValueVariant variant(KUserAgent());
    60     if(iHttpClient->AddRequestHeader(HTTP::EUserAgent, variant))
    71     if(iHttpClient->AddRequestHeader(HTTP::EUserAgent, variant))
    61         {
    72         {
    62         SetTestStepResult(EFail);
    73         SetTestStepResult(EFail);
    63         return TestStepResult();
    74         return TestStepResult();
    97             {
   108             {
    98             User::Leave(KErrCorrupt);
   109             User::Leave(KErrCorrupt);
    99             }
   110             }
   100         }
   111         }
   101     
   112     
       
   113     if(param->IsAuthenticationReqd())
       
   114         {
       
   115         iTestHttpServiceAuthentication = new CTestHttpServiceAuthentication();
       
   116         User::LeaveIfError(iHttpClient->SetAuthentication(iTestHttpServiceAuthentication));
       
   117         }
       
   118   
   102     if(param->Method().CompareF(KGetMethod) == 0)
   119     if(param->Method().CompareF(KGetMethod) == 0)
   103         {
   120         {
   104         if(param->OnlineTest())
   121         if(param->OnlineTest())
   105             {
   122             {
   106             iHttpTrans = CTestClientHttpOnlineGet::NewL(*param, *this, *iHttpClient, param->Uri(), iTestUtils);
   123             iHttpTrans = CTestClientHttpOnlineGet::NewL(*param, *this, *iHttpClient, param->Uri(), iTestUtils);
   124    
   141    
   125     if(param->NoRetryOnDisconnect())
   142     if(param->NoRetryOnDisconnect())
   126         {
   143         {
   127         iHttpTrans->SetNoRetry();
   144         iHttpTrans->SetNoRetry();
   128         }
   145         }
   129     
       
   130     if(param->ResponseTimeoutEnable())
   146     if(param->ResponseTimeoutEnable())
   131         {
   147         {
   132         iHttpTrans->SetResponseTimeout(10);
   148         iHttpTrans->SetResponseTimeout(10);
   133         }
   149         }
   134     
       
   135     const RPointerArray<CHeaderInfo>& info = param->RequestHeaderInfos();
   150     const RPointerArray<CHeaderInfo>& info = param->RequestHeaderInfos();
   136     for(TInt i = 0; i < info.Count(); ++i)
   151     for(TInt i = 0; i < info.Count(); ++i)
   137         {
   152         {
   138         CHeaderInfo* headerInfo = info[i];
   153         CHeaderInfo* headerInfo = info[i];
   139         const TDesC8& headerName = *headerInfo->iFieldName;
   154         const TDesC8& headerName = *headerInfo->iFieldName;
   159                     TReal64 value = 0.;
   174                     TReal64 value = 0.;
   160                     lex.Val(value);             
   175                     lex.Val(value);             
   161                     THTTPHdrVal::TQConv q(value);
   176                     THTTPHdrVal::TQConv q(value);
   162                     TInt val2 = q;
   177                     TInt val2 = q;
   163                     THttpHeaderValueVariant variant2(val2);
   178                     THttpHeaderValueVariant variant2(val2);
   164                     // Set the header with the param
   179                     /// Set the header with the param
   165                     iHttpTrans->AddRequestHeader(headerName, variant, paramName, variant2);
   180                     iHttpTrans->AddRequestHeader(headerName, variant, paramName, variant2);
   166                     }
   181                     }
   167                 }
   182                 }
   168             }
   183             }
   169         }
   184         }