applayerprotocols/httpservice/test/httpservicetest/ctesthttpclientstep.cpp
branchGCC_SURGE
changeset 32 0713fb089b10
parent 23 ea9c9681bbaf
equal deleted inserted replaced
24:2af57effcf41 32:0713fb089b10
     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     {
    51     iActiveScheduler = new (ELeave) CActiveScheduler();
    55     iActiveScheduler = new (ELeave) CActiveScheduler();
    52     CActiveScheduler::Install(iActiveScheduler);
    56     CActiveScheduler::Install(iActiveScheduler);
    53     iTestParamArray = new(ELeave) CHttpClientTestParamArray;
    57     iTestParamArray = new(ELeave) CHttpClientTestParamArray;
    54     iTestUtils = CHTTPTestUtils::NewL(KTestHttpClientAPITestTitle());
    58     iTestUtils = CHTTPTestUtils::NewL(KTestHttpClientAPITestTitle());
    55     iTestUtils->InitCommsL();
    59     
    56     
    60     
    57     iTestServer = CLocalTestServer::NewL(*iTestUtils, *this, *iTestParamArray);
    61     iTestServer = CLocalTestServer::NewL(*iTestUtils, *this, *iTestParamArray);
    58     iHttpClient = CHttpService::NewL();
    62     iHttpClient = CHttpService::NewL();
       
    63     TCommDbConnPref connPref;
       
    64     connPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
    65     connPref.SetIapId(1);
       
    66     connPref.SetNetId(0);
       
    67     iHttpConnInfo = iHttpClient->HttpNetworkConnection();
       
    68     User::LeaveIfError(iHttpConnInfo->Start());
    59     THttpHeaderValueVariant variant(KUserAgent());
    69     THttpHeaderValueVariant variant(KUserAgent());
    60     if(iHttpClient->AddRequestHeader(HTTP::EUserAgent, variant))
    70     if(iHttpClient->AddRequestHeader(HTTP::EUserAgent, variant))
    61         {
    71         {
    62         SetTestStepResult(EFail);
    72         SetTestStepResult(EFail);
    63         return TestStepResult();
    73         return TestStepResult();
    97             {
   107             {
    98             User::Leave(KErrCorrupt);
   108             User::Leave(KErrCorrupt);
    99             }
   109             }
   100         }
   110         }
   101     
   111     
       
   112     if(param->IsAuthenticationReqd())
       
   113         {
       
   114         iTestHttpServiceAuthentication = new CTestHttpServiceAuthentication();
       
   115         User::LeaveIfError(iHttpClient->SetAuthentication(iTestHttpServiceAuthentication));
       
   116         }
       
   117   
   102     if(param->Method().CompareF(KGetMethod) == 0)
   118     if(param->Method().CompareF(KGetMethod) == 0)
   103         {
   119         {
   104         if(param->OnlineTest())
   120         if(param->OnlineTest())
   105             {
   121             {
   106             iHttpTrans = CTestClientHttpOnlineGet::NewL(*param, *this, *iHttpClient, param->Uri(), iTestUtils);
   122             iHttpTrans = CTestClientHttpOnlineGet::NewL(*param, *this, *iHttpClient, param->Uri(), iTestUtils);
   124    
   140    
   125     if(param->NoRetryOnDisconnect())
   141     if(param->NoRetryOnDisconnect())
   126         {
   142         {
   127         iHttpTrans->SetNoRetry();
   143         iHttpTrans->SetNoRetry();
   128         }
   144         }
   129     
       
   130     if(param->ResponseTimeoutEnable())
   145     if(param->ResponseTimeoutEnable())
   131         {
   146         {
   132         iHttpTrans->SetResponseTimeout(10);
   147         iHttpTrans->SetResponseTimeout(10);
   133         }
   148         }
   134     
       
   135     const RPointerArray<CHeaderInfo>& info = param->RequestHeaderInfos();
   149     const RPointerArray<CHeaderInfo>& info = param->RequestHeaderInfos();
   136     for(TInt i = 0; i < info.Count(); ++i)
   150     for(TInt i = 0; i < info.Count(); ++i)
   137         {
   151         {
   138         CHeaderInfo* headerInfo = info[i];
   152         CHeaderInfo* headerInfo = info[i];
   139         const TDesC8& headerName = *headerInfo->iFieldName;
   153         const TDesC8& headerName = *headerInfo->iFieldName;
   159                     TReal64 value = 0.;
   173                     TReal64 value = 0.;
   160                     lex.Val(value);             
   174                     lex.Val(value);             
   161                     THTTPHdrVal::TQConv q(value);
   175                     THTTPHdrVal::TQConv q(value);
   162                     TInt val2 = q;
   176                     TInt val2 = q;
   163                     THttpHeaderValueVariant variant2(val2);
   177                     THttpHeaderValueVariant variant2(val2);
   164                     // Set the header with the param
   178                     /// Set the header with the param
   165                     iHttpTrans->AddRequestHeader(headerName, variant, paramName, variant2);
   179                     iHttpTrans->AddRequestHeader(headerName, variant, paramName, variant2);
   166                     }
   180                     }
   167                 }
   181                 }
   168             }
   182             }
   169         }
   183         }