applayerprotocols/httpservice/test/httpservicetest/chttpclienttestparams.cpp
changeset 0 b16258d2340f
child 7 337070b4fa18
child 19 2f328ce1b263
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //  
       
    15 
       
    16 #include "chttpclienttestparams.h"
       
    17 #include <testexecuteserverbase.h>
       
    18 #include "thttpheadervaluevariant.h"
       
    19 #include <escapeutils.h>
       
    20 #include <tinternetdate.h>
       
    21 
       
    22 _LIT(KMethod, "Method");
       
    23 _LIT(KUri, "Uri");
       
    24 _LIT(KRawRequest, "RawRequest");
       
    25 _LIT(KRawResponse, "RawResponse");
       
    26 _LIT(KResponseBody, "ResponseBody");
       
    27 _LIT(KStatusCode, "StatusCode");
       
    28 _LIT(KResponseFieldCount, "ResponseFieldCount");
       
    29 _LIT(KHeader, "ResponseHeader%d");
       
    30 _LIT(KHeaderValue, "ResponseHeader%d.Value%d");
       
    31 _LIT(KHeaderValueCount, "ResponseHeader%dValueCount");
       
    32 _LIT(KFieldParamCount, "ResponseHeader%d.Field%dParamCount");
       
    33 _LIT(KFieldParamName, "ResponseHeader%d.Field%d.ParamName%d");
       
    34 _LIT(KFieldParamValue, "ResponseHeader%d.Field%d.ParamValue%d");
       
    35 _LIT(KHeaderParamCount, "ResponseHeader%dParamCount");
       
    36 _LIT(KHeaderParamName, "ResponseHeader%d.ParamName%d");
       
    37 _LIT(KHeaderParamValue, "ResponseHeader%d.ParamValue%d");
       
    38 _LIT(KResponseFileName, "ResponseFileName");
       
    39 _LIT(KResponseFileNameStore, "ResponseFileNameStore");
       
    40 _LIT(KRequestFileName, "RequestFileName");
       
    41 _LIT(KRequestFileNameStore, "RequestFileNameStore");
       
    42 
       
    43 
       
    44 _LIT(KRequestFieldCount, "RequestFieldCount");
       
    45 _LIT(KRequestHeader, "RequestHeader%d");
       
    46 _LIT(KRequestHeaderValueCount, "RequestHeader%dValueCount");
       
    47 _LIT(KRequestHeaderValue, "RequestHeader%d.Value%d");
       
    48 _LIT(KRequestHeaderValueParamCount, "RequestHeader%d.Value%dParamCount");
       
    49 _LIT(KRequestHeaderValueParamName, "RequestHeader%d.Value%d.ParamName%d");
       
    50 _LIT(KRequestHeaderValueParamValue, "RequestHeader%d.Value%d.ParamValue%d");
       
    51 
       
    52 _LIT(KRequestBody, "RequestBody");
       
    53 _LIT(KConnDisconnect, "ConnDisconnect");
       
    54 _LIT(KExpectedError, "ExpectedError");
       
    55 _LIT(KNoRetryOnDisconnect, "NoRetryOnDisconnect");
       
    56 _LIT(KResponseDynamicAndStatic, "ResponseDynamicAndStatic");
       
    57 _LIT(KOnlineTest, "OnlineTest");
       
    58 _LIT(KProxyAddress, "ProxyAddress");
       
    59 _LIT(KResponseTimeout, "ResponseTimeout");  
       
    60 _LIT(KRedirection, "Redirection"); 
       
    61 _LIT(KNotifyTransferProgress, "NotifyTransferProgress"); 
       
    62 
       
    63 _LIT8(KScriptLF8,   "\\n");
       
    64 _LIT8(KReplaceLF8,  "\n");
       
    65 _LIT8(KScriptCR8,   "\\r");
       
    66 _LIT8(KReplaceCR8,  "\r");
       
    67 
       
    68 
       
    69 void ParseAndReplaceCRLF(HBufC8* aHBufPtr)
       
    70     {
       
    71     TInt crPos = 0;
       
    72     TInt lfPos = 0;
       
    73     do
       
    74       {
       
    75       crPos = ((aHBufPtr->Des()).Find(KScriptCR8()));
       
    76       if (crPos != KErrNotFound)
       
    77         {
       
    78         (aHBufPtr->Des()).Replace(crPos,2, KReplaceCR8());
       
    79         }           
       
    80       }while (crPos != KErrNotFound );
       
    81 
       
    82 
       
    83     do
       
    84       {
       
    85       lfPos = ((aHBufPtr->Des()).Find(KScriptLF8()));
       
    86       if (lfPos != KErrNotFound)
       
    87         {
       
    88         (aHBufPtr->Des()).Replace(lfPos,2, KReplaceLF8());
       
    89         }            
       
    90       }while (lfPos != KErrNotFound );    
       
    91     }
       
    92 
       
    93 CHttpClientTestParams* CHttpClientTestParams::NewL(CTestStep& aTestCase)
       
    94     {
       
    95     CHttpClientTestParams* self = new(ELeave) CHttpClientTestParams;
       
    96     CleanupStack::PushL(self);
       
    97     self->ConstructL(aTestCase);
       
    98     CleanupStack::Pop();
       
    99     return self;
       
   100     } 
       
   101 
       
   102 
       
   103 
       
   104 void CHttpClientTestParams::ConstructL(CTestStep& aTestCase)
       
   105     {
       
   106     TPtrC method;
       
   107     TPtrC uri;
       
   108     TPtrC rawRequest;
       
   109     TPtrC rawResponse;
       
   110     if(!aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KMethod(), method) || 
       
   111             !aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KUri(), uri) ||
       
   112              !aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), KStatusCode(), iStatusCode))
       
   113         {
       
   114         User::Leave(KErrCorrupt);
       
   115         }
       
   116     aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KRawRequest(), rawRequest);
       
   117     aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KRawResponse(), rawResponse);
       
   118     
       
   119     iMethod = EscapeUtils::ConvertFromUnicodeToUtf8L(method);
       
   120     iUri = EscapeUtils::ConvertFromUnicodeToUtf8L(uri);
       
   121     iRawRequest = EscapeUtils::ConvertFromUnicodeToUtf8L(rawRequest);
       
   122     iRawResponse = EscapeUtils::ConvertFromUnicodeToUtf8L(rawResponse);
       
   123     ParseAndReplaceCRLF(iRawRequest);
       
   124     ParseAndReplaceCRLF(iRawResponse);
       
   125     
       
   126     
       
   127     TPtrC responseBody;
       
   128     if(aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KResponseBody(), responseBody))
       
   129         {
       
   130         iResponseBody = EscapeUtils::ConvertFromUnicodeToUtf8L(responseBody);
       
   131         }
       
   132     
       
   133     TPtrC requestBody;
       
   134     if(aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KRequestBody(), requestBody))
       
   135         {
       
   136         iRequestBody = EscapeUtils::ConvertFromUnicodeToUtf8L(requestBody);
       
   137         }
       
   138     
       
   139     
       
   140     // Now read the headers
       
   141     // Read the number of headers
       
   142     TInt responseHeaderCount = 0;
       
   143     aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), KResponseFieldCount(), responseHeaderCount);
       
   144     for(TInt i = 0; i < responseHeaderCount; ++i)
       
   145         {
       
   146         CHeaderInfo* headerInfo = new(ELeave) CHeaderInfo;
       
   147         CleanupStack::PushL(headerInfo);
       
   148         TBuf<32> headerFormat;
       
   149         headerFormat.Format(KHeader(), i + 1);
       
   150         TPtrC headerName;
       
   151         aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), headerFormat, headerName);
       
   152         headerInfo->iFieldName = EscapeUtils::ConvertFromUnicodeToUtf8L(headerName);
       
   153         TInt headerValueCount = 0;        
       
   154         TBuf<32> headerValueCountStr;
       
   155         headerValueCountStr.Format(KHeaderValueCount(), i + 1);        
       
   156         aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), headerValueCountStr, headerValueCount);        
       
   157         for(TInt j = 0; j < headerValueCount; ++j)
       
   158             {
       
   159             TBuf<32> headerValueFormat;
       
   160             headerValueFormat.Format(KHeaderValue(), i + 1, j+ 1);
       
   161             TPtrC headerValue;
       
   162             aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), headerValueFormat, headerValue);
       
   163             CHeaderFieldInfo* fieldInfo = new(ELeave) CHeaderFieldInfo;
       
   164             CleanupStack::PushL(fieldInfo);
       
   165             fieldInfo->iFieldValue = EscapeUtils::ConvertFromUnicodeToUtf8L(headerValue);
       
   166             
       
   167             // Check this field has params.
       
   168             TBuf<32> headerFieldParamCount;
       
   169             headerFieldParamCount.Format(KFieldParamCount(), i + 1, j + 1);
       
   170             TInt paramCount = 0;
       
   171             aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), headerFieldParamCount, paramCount);
       
   172             for(TInt k = 0; k < paramCount; ++k)
       
   173                 {
       
   174                 TBuf<48> fieldParamName;
       
   175                 TBuf<48> fieldParamValue;
       
   176                 fieldParamName.Format(KFieldParamName, i + 1, j + 1, k + 1);
       
   177                 fieldParamValue.Format(KFieldParamValue, i + 1, j + 1, k + 1);             
       
   178                 TPtrC paramName;
       
   179                 TPtrC paramValue;
       
   180                 aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), fieldParamName, paramName);
       
   181                 aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), fieldParamValue, paramValue);
       
   182                 CHeaderFieldParamInfo* paramInfo = new(ELeave) CHeaderFieldParamInfo;
       
   183                 CleanupStack::PushL(paramInfo);
       
   184                 paramInfo->iParamName = EscapeUtils::ConvertFromUnicodeToUtf8L(paramName);
       
   185                 paramInfo->iParamValue = EscapeUtils::ConvertFromUnicodeToUtf8L(paramValue);                
       
   186                 fieldInfo->iFieldParamInfos.AppendL(paramInfo);
       
   187                 CleanupStack::Pop(); // paramInfo                
       
   188                 }
       
   189             
       
   190             headerInfo->iFieldInfos.AppendL(fieldInfo); 
       
   191             CleanupStack::Pop(); // fieldInfo
       
   192             }        
       
   193         // Check if the header has some params
       
   194         TBuf<48> headerParamCount;
       
   195         headerParamCount.Format(KHeaderParamCount(), i + 1);
       
   196         TInt hdrParamCount = 0;
       
   197         aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), headerParamCount, hdrParamCount);   
       
   198         for(TInt x = 0; x < hdrParamCount; ++x)
       
   199             {
       
   200             TBuf<48> headerParamName;
       
   201             TBuf<48> headerParamValue;
       
   202             headerParamName.Format(KHeaderParamName(), i + 1, x + 1);
       
   203             headerParamValue.Format(KHeaderParamValue(), i + 1, x + 1);
       
   204             TPtrC paramName;
       
   205             TPtrC paramValue;
       
   206             aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), headerParamName, paramName);
       
   207             aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), headerParamValue, paramValue);
       
   208             CHeaderFieldParamInfo* paramInfo = new (ELeave) CHeaderFieldParamInfo;
       
   209             CleanupStack::PushL(paramInfo);
       
   210             paramInfo->iParamName = EscapeUtils::ConvertFromUnicodeToUtf8L(paramName);
       
   211             paramInfo->iParamValue = EscapeUtils::ConvertFromUnicodeToUtf8L(paramValue);
       
   212             headerInfo->iParamInfos.AppendL(paramInfo);
       
   213             CleanupStack::Pop(); // paramInfo
       
   214             }
       
   215         iResponseHeaderInfos.AppendL(headerInfo);
       
   216         CleanupStack::Pop(); // headerInfo
       
   217         }
       
   218 
       
   219     TPtrC fileName;
       
   220     aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KResponseFileName(), fileName);
       
   221     if(fileName.Length() > 0)
       
   222         {
       
   223         iFileSender = CFileSender::NewL(fileName);        
       
   224         aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KResponseFileNameStore(), fileName);
       
   225         if(fileName.Length() == 0)
       
   226             {
       
   227             User::Leave(KErrCorrupt);
       
   228             }
       
   229         iFileReceiver = CFileReceiver::NewL(fileName);
       
   230         }
       
   231 
       
   232     
       
   233     TPtrC ulFileName;
       
   234     aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KRequestFileName(), ulFileName);
       
   235     if(ulFileName.Length() > 0)
       
   236         {
       
   237         iFileSender = CFileSender::NewL(ulFileName);
       
   238         aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KRequestFileNameStore(), ulFileName);
       
   239         if(ulFileName.Length() == 0)
       
   240              {
       
   241              User::Leave(KErrCorrupt);
       
   242              }
       
   243          iFileReceiver = CFileReceiver::NewL(ulFileName);        
       
   244         }
       
   245     
       
   246     // Read request headers 
       
   247      TInt reqFieldCount = 0;
       
   248     aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), KRequestFieldCount(), reqFieldCount);
       
   249     
       
   250     for(TInt ii = 0; ii < reqFieldCount; ++ii)
       
   251         {
       
   252         // Read the request header
       
   253         TBuf<64> reqHeaderStr;
       
   254         reqHeaderStr.Format(KRequestHeader(), ii + 1);
       
   255         TPtrC reqHeaderName;
       
   256         aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), reqHeaderStr, reqHeaderName);
       
   257         CHeaderInfo* headerInfo = new(ELeave) CHeaderInfo;
       
   258         CleanupStack::PushL(headerInfo);
       
   259         headerInfo->iFieldName = EscapeUtils::ConvertFromUnicodeToUtf8L(reqHeaderName);
       
   260         
       
   261         // Now read how many fields are present
       
   262         reqHeaderStr.Format(KRequestHeaderValueCount(), ii + 1);
       
   263         TInt reqHdrValueCount = 0;
       
   264         aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), reqHeaderStr, reqHdrValueCount);
       
   265         for(TInt jj = 0; jj < reqHdrValueCount; ++jj)
       
   266             {
       
   267             TPtrC reqHeaderVal;
       
   268             reqHeaderStr.Format(KRequestHeaderValue(), ii + 1, jj + 1);
       
   269             aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), reqHeaderStr, reqHeaderVal);
       
   270             CHeaderFieldInfo* info = new (ELeave) CHeaderFieldInfo;
       
   271             CleanupStack::PushL(info);
       
   272             info->iFieldValue = EscapeUtils::ConvertFromUnicodeToUtf8L(reqHeaderVal);
       
   273             reqHeaderStr.Format(KRequestHeaderValueParamCount, ii + 1, jj + 1);
       
   274             TInt paramCount = 0;
       
   275             aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), reqHeaderStr, paramCount);
       
   276             for(TInt kk = 0; kk < paramCount; ++kk)
       
   277                 {
       
   278                 reqHeaderStr.Format(KRequestHeaderValueParamName(), ii + 1, jj + 1, kk + 1);
       
   279                 TPtrC name;
       
   280                 TPtrC value;
       
   281                 aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), reqHeaderStr, name);
       
   282                 reqHeaderStr.Format(KRequestHeaderValueParamValue(), ii + 1, jj + 1, kk + 1);
       
   283                 aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), reqHeaderStr, value);
       
   284                 
       
   285                 CHeaderFieldParamInfo* paramInfo = new (ELeave) CHeaderFieldParamInfo;
       
   286                 CleanupStack::PushL(paramInfo);
       
   287                 paramInfo->iParamName = EscapeUtils::ConvertFromUnicodeToUtf8L(name);
       
   288                 paramInfo->iParamValue = EscapeUtils::ConvertFromUnicodeToUtf8L(value);
       
   289                 info->iFieldParamInfos.AppendL(paramInfo);
       
   290                 CleanupStack::Pop(); // CHeaderFieldParamInfo
       
   291                 }
       
   292             headerInfo->iFieldInfos.AppendL(info);
       
   293             CleanupStack::Pop(); // info
       
   294             }
       
   295         
       
   296         iRequestHeaderInfos.AppendL(headerInfo);
       
   297         CleanupStack::Pop();      
       
   298         }         
       
   299     
       
   300     iConnDisconnect = EFalse;
       
   301     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KConnDisconnect(), iConnDisconnect);
       
   302     
       
   303     iExpectedError = KErrNone;    
       
   304     aTestCase.GetIntFromConfig(aTestCase.ConfigSection(), KExpectedError(), iExpectedError);
       
   305     
       
   306     iNoRetryOnDisconnect = EFalse;
       
   307     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KNoRetryOnDisconnect(), iNoRetryOnDisconnect);
       
   308     
       
   309     iResponseDynamicAndStatic = EFalse;
       
   310     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KResponseDynamicAndStatic(), iResponseDynamicAndStatic);
       
   311     
       
   312     iOnlineTest = EFalse;
       
   313     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KOnlineTest(), iOnlineTest);
       
   314         
       
   315     iRedirection = EFalse;
       
   316     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KRedirection(), iRedirection);
       
   317    
       
   318     iResponseTimeout = EFalse;
       
   319     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KResponseTimeout(), iResponseTimeout);
       
   320     
       
   321     iNotifyTransferProgress = EFalse;
       
   322     aTestCase.GetBoolFromConfig(aTestCase.ConfigSection(), KNotifyTransferProgress(), iNotifyTransferProgress);
       
   323     
       
   324     TPtrC proxyAddress;
       
   325     if(aTestCase.GetStringFromConfig(aTestCase.ConfigSection(), KProxyAddress, proxyAddress))
       
   326         {
       
   327         iProxyAddress = EscapeUtils::ConvertFromUnicodeToUtf8L(proxyAddress);
       
   328         }
       
   329     }
       
   330 
       
   331 
       
   332 CHttpClientTestParams::~CHttpClientTestParams()
       
   333     {
       
   334     delete iFileSender;
       
   335     delete iMethod;
       
   336     delete iUri;
       
   337     delete iRawRequest;
       
   338     delete iRawResponse;
       
   339     delete iResponseBody;
       
   340     iResponseHeaderInfos.ResetAndDestroy();
       
   341     }
       
   342 
       
   343 TInt CHttpClientTestParams::StatusCode() const
       
   344     {
       
   345     return iStatusCode;
       
   346     }
       
   347 
       
   348 const TDesC8& CHttpClientTestParams::Method() const
       
   349     {
       
   350     return *iMethod;
       
   351     }
       
   352 
       
   353 const TDesC8& CHttpClientTestParams::Uri() const
       
   354     {
       
   355     return *iUri;
       
   356     }
       
   357 
       
   358 const TDesC8& CHttpClientTestParams::RawRequest() const
       
   359     {
       
   360     return *iRawRequest;
       
   361     }
       
   362 
       
   363 const TDesC8& CHttpClientTestParams::RawResponse() const
       
   364     {
       
   365     return *iRawResponse;
       
   366     }
       
   367 
       
   368 const TDesC8& CHttpClientTestParams::ResponseBody() const
       
   369     {
       
   370     if(iResponseBody)
       
   371         return *iResponseBody;
       
   372     return KNullDesC8();
       
   373     }
       
   374 
       
   375 TBool   CHttpClientTestParams::IsFileSending() const
       
   376     {
       
   377     return (iFileSender != NULL);
       
   378     }
       
   379 
       
   380 const TDesC8& CHttpClientTestParams::ReadFromFile()
       
   381     {
       
   382     return iFileSender->Read();
       
   383     }
       
   384 
       
   385 TBool   CHttpClientTestParams::IsPendingRead() const
       
   386     {
       
   387     return iFileSender->MoreToRead();
       
   388     }
       
   389 
       
   390 TInt CHttpClientTestParams::WriteToFile(const TDesC8& aData)
       
   391     {
       
   392     return iFileReceiver->Write(aData);
       
   393     }
       
   394 
       
   395 RFile&  CHttpClientTestParams::SourceFile()
       
   396     {
       
   397     return iFileSender->iFile;
       
   398     }
       
   399 
       
   400 RFile&  CHttpClientTestParams::SinkFile()
       
   401     {
       
   402     return iFileReceiver->iFile;
       
   403     }
       
   404 
       
   405 TBool   CHttpClientTestParams::NeedDisconnection() const
       
   406     {
       
   407     return iConnDisconnect;
       
   408     }
       
   409 
       
   410 TInt CHttpClientTestParams::ExpectedError() const
       
   411     {
       
   412     return iExpectedError;
       
   413     }
       
   414 
       
   415 TBool CHttpClientTestParams::NoRetryOnDisconnect() const
       
   416     {
       
   417     return iNoRetryOnDisconnect;
       
   418     }
       
   419 
       
   420 TBool CHttpClientTestParams::ResponseTimeoutEnable() const
       
   421     {
       
   422     return iResponseTimeout;
       
   423     }
       
   424 
       
   425 TBool CHttpClientTestParams::IsRedirecting() const
       
   426     {
       
   427     return iRedirection;
       
   428     }
       
   429 
       
   430 TBool CHttpClientTestParams::TransferProgress() const
       
   431     {
       
   432     return iNotifyTransferProgress;
       
   433     }
       
   434 
       
   435 TBool CHttpClientTestParams::CheckVariantValue(const THttpHeaderValueVariant& aVariant, const TDesC8& aValueToMatch)
       
   436     {
       
   437     TBool ret = EFalse;
       
   438     switch(aVariant.Type())
       
   439         {
       
   440         case THttpHeaderValueVariant::EIntType:
       
   441             {
       
   442             _LIT8(KIntType, "%d");
       
   443             TBuf8<16>  buf;
       
   444             buf.Format(KIntType(), aVariant.Int());
       
   445             ret = (buf.CompareF(aValueToMatch) == 0);                    
       
   446             }
       
   447         break;
       
   448         
       
   449         case THttpHeaderValueVariant::EStrType:
       
   450             {
       
   451             ret = (aVariant.Str().CompareF(aValueToMatch) == 0);
       
   452             }
       
   453         break;
       
   454         
       
   455         case THttpHeaderValueVariant::EDateTimeType:
       
   456             {
       
   457             TInternetDate internetDate(aVariant.DateTime());
       
   458             HBufC8* dateTimeStr = internetDate.InternetDateTimeL(TInternetDate::ERfc1123Format);
       
   459             ret = aValueToMatch.CompareF(*dateTimeStr) == 0;
       
   460             delete dateTimeStr;
       
   461             }
       
   462         break;
       
   463         
       
   464         default:
       
   465         User::Invariant();
       
   466         }    
       
   467     return ret;
       
   468     }
       
   469 
       
   470 CHeaderInfo* CHttpClientTestParams::FindHeaderInfo(const TDesC8& aHeaderName)
       
   471     {
       
   472     const TUint count = iResponseHeaderInfos.Count();
       
   473     for(TInt i = 0; i < count; ++i)
       
   474         {
       
   475         if(aHeaderName.CompareF(*iResponseHeaderInfos[i]->iFieldName) == 0)
       
   476             {
       
   477             return iResponseHeaderInfos[i];
       
   478             }
       
   479         }
       
   480     return NULL;        
       
   481     }
       
   482 
       
   483 TBool CHttpClientTestParams::MatchPostFileContent()
       
   484     {
       
   485     CFileSender* sender = CFileSender::NewL(iFileSender->FileName());
       
   486     CleanupStack::PushL(sender);
       
   487     CFileSender* sender2 = CFileSender::NewL(iFileReceiver->FileName());
       
   488     CleanupStack::PushL(sender2);
       
   489     sender2->Read(RawRequest().Length());
       
   490     TBool ret = ETrue;
       
   491     while(sender->MoreToRead())
       
   492         {
       
   493         if(!sender2->MoreToRead())
       
   494             {
       
   495             ret = EFalse;
       
   496             break;
       
   497             }
       
   498         
       
   499         if(sender->Read().CompareF(sender2->Read()) != 0)
       
   500             {
       
   501             ret = EFalse;
       
   502             break;
       
   503             }
       
   504         }
       
   505     CleanupStack::Pop(2); // sender/sender2
       
   506     return ret;     
       
   507     }
       
   508 
       
   509 TBool   CHttpClientTestParams::MatchFileContent()
       
   510     {
       
   511     CFileSender* sender = CFileSender::NewL(iFileSender->FileName());
       
   512     CleanupStack::PushL(sender);
       
   513     CFileSender* sender2 = CFileSender::NewL(iFileReceiver->FileName());
       
   514     CleanupStack::PushL(sender2);
       
   515     TBool ret = ETrue;
       
   516     while(sender->MoreToRead())
       
   517         {
       
   518         if(!sender2->MoreToRead())
       
   519             {
       
   520             ret = EFalse;
       
   521             break;
       
   522             }
       
   523         
       
   524         if(sender->Read().CompareF(sender2->Read()) != 0)
       
   525             {
       
   526             ret = EFalse;
       
   527             break;
       
   528             }
       
   529         }
       
   530     CleanupStack::Pop(2); // sender/sender2
       
   531     return ret;    
       
   532     }
       
   533 
       
   534 CHttpClientTestParamArray::CHttpClientTestParamArray()
       
   535     {
       
   536     
       
   537     }
       
   538 
       
   539 CHttpClientTestParamArray::~CHttpClientTestParamArray()
       
   540     {
       
   541     iTestParamArray.ResetAndDestroy();
       
   542     }
       
   543 
       
   544 void CHttpClientTestParamArray::AddTestParams(CHttpClientTestParams* aParams)
       
   545     {
       
   546     iTestParamArray.Append(aParams);
       
   547     }
       
   548 
       
   549 CHttpClientTestParams* CHttpClientTestParamArray::MatchingParam(const TDesC8& aData)
       
   550     {
       
   551     CHttpClientTestParams* param = NULL;
       
   552     TInt count = iTestParamArray.Count();
       
   553     for(TUint i = 0; i < count; ++i)
       
   554         {
       
   555         TInt startPos = aData.Locate(' ');
       
   556         TInt reversePos = aData.LocateReverse(' ') - 1;
       
   557         TPtrC8 ptr = aData.Mid(startPos + 1, reversePos - startPos);         
       
   558          if (iTestParamArray[i]->Uri().FindF(ptr) != KErrNotFound)
       
   559              {
       
   560              param = iTestParamArray[i];             
       
   561              break;
       
   562              }
       
   563         }
       
   564     return param;            
       
   565     }
       
   566 
       
   567 //Parse Replace \n & \r
       
   568 void ParseReplaceCRLF(HBufC8* aHBufPtr)
       
   569     {
       
   570     TInt crPos = 0;
       
   571     TInt lfPos = 0;
       
   572     do
       
   573         {
       
   574 
       
   575         crPos = ((aHBufPtr->Des()).Find(KScriptCR8()));
       
   576         if (crPos != KErrNotFound)
       
   577             {
       
   578             (aHBufPtr->Des()).Replace(crPos,2, KReplaceCR8());
       
   579             }
       
   580             
       
   581         }
       
   582     while (crPos != KErrNotFound );
       
   583 
       
   584 
       
   585     do
       
   586         {
       
   587 
       
   588         lfPos = ((aHBufPtr->Des()).Find(KScriptLF8()));
       
   589         if (lfPos != KErrNotFound)
       
   590             {
       
   591             (aHBufPtr->Des()).Replace(lfPos,2, KReplaceLF8());
       
   592             }
       
   593             
       
   594         }
       
   595     while (lfPos != KErrNotFound );
       
   596     
       
   597     }
       
   598 
       
   599 
       
   600 CFileSender* CFileSender::NewL(const TDesC& aFileName)
       
   601     {
       
   602     CFileSender* self = new(ELeave) CFileSender;
       
   603     CleanupStack::PushL(self);
       
   604     self->ConstructL(aFileName);
       
   605     CleanupStack::Pop(); // self
       
   606     return self;
       
   607     }
       
   608 
       
   609 
       
   610 void CFileSender::ConstructL(const TDesC& aFileName)
       
   611     {
       
   612     iFileName = aFileName.AllocL();
       
   613     User::LeaveIfError(iFs.Connect());
       
   614     iBuffer.CreateL(16 * 1024);
       
   615     User::LeaveIfError(iFile.Open(iFs, aFileName, EFileShareReadersOnly));
       
   616     User::LeaveIfError(iFile.Size(iFileSize));
       
   617     }
       
   618 
       
   619 CFileSender::~CFileSender()
       
   620     {
       
   621     delete iFileName;
       
   622     iBuffer.Close();
       
   623     iFile.Close();
       
   624     iFs.Close();
       
   625     }
       
   626 
       
   627 const TDesC8& CFileSender::Read(TInt aSize)
       
   628     {
       
   629     iBuffer.Zero();
       
   630     iFile.Read(iBuffer, aSize);
       
   631     iFileSize -= iBuffer.Length();
       
   632     return iBuffer;    
       
   633     }
       
   634 
       
   635 const TDesC8& CFileSender::Read()
       
   636     {
       
   637     iBuffer.Zero();
       
   638     iFile.Read(iBuffer);
       
   639     iFileSize -= iBuffer.Length();
       
   640     return iBuffer;
       
   641     }
       
   642 
       
   643 TInt CFileSender::Size()
       
   644     {
       
   645     TInt size;
       
   646     iFile.Size(size);
       
   647     return size;
       
   648     }
       
   649 
       
   650 TBool   CFileSender::MoreToRead() const
       
   651     {
       
   652     return iFileSize > 0;
       
   653     }
       
   654 
       
   655 CFileSender::CFileSender()
       
   656     {
       
   657     
       
   658     }
       
   659 
       
   660 const TDesC& CFileSender::FileName() const
       
   661     {
       
   662     return *iFileName;
       
   663     }
       
   664 
       
   665 CFileReceiver* CFileReceiver::NewL(const TDesC& aFileName)
       
   666     {
       
   667     CFileReceiver* self = new(ELeave) CFileReceiver;
       
   668     CleanupStack::PushL(self);
       
   669     self->ConstructL(aFileName);
       
   670     CleanupStack::Pop(); // self
       
   671     return self;
       
   672     }
       
   673 
       
   674  TInt CFileReceiver::Write(const TDesC8& aData)
       
   675      {
       
   676      return iFile.Write(aData);
       
   677      }
       
   678  
       
   679  CFileReceiver::~CFileReceiver()
       
   680      {
       
   681      iFile.Close();
       
   682      iFs.Close();
       
   683      delete iFileName;
       
   684      }
       
   685  
       
   686  void CFileReceiver::ConstructL(const TDesC& aFileName)
       
   687      {
       
   688      iFileName = aFileName.AllocL();
       
   689      User::LeaveIfError(iFs.Connect());
       
   690      if(iFile.Open(iFs, aFileName, EFileWrite) != KErrNone)
       
   691          {
       
   692          User::LeaveIfError(iFile.Create(iFs, aFileName, EFileWrite));
       
   693          }
       
   694      }
       
   695  
       
   696  RFile& CFileReceiver::File()
       
   697      {
       
   698      return iFile;
       
   699      }
       
   700 
       
   701  const TDesC& CFileReceiver::FileName() const
       
   702      {
       
   703      return *iFileName;
       
   704      }