|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "ctestclienthttppost.h" |
|
18 #include <httpstringconstants.h> |
|
19 #include "mlocaltestserverobserver.h" |
|
20 #include "chttpclienttestparams.h" |
|
21 _LIT(KTestHttpClientAPITestTitle, "HTTP client API Unit Test Harness"); |
|
22 _LIT(KTransferProgress, "File size: %d kb , Uploaded so far: %d kb"); |
|
23 |
|
24 CTestClientHttpSimplePost* CTestClientHttpSimplePost::NewL(CHttpClientTestParams& aParams, MLocalTestServerObserver& aObserver, CHttpService& aClient, const TDesC8& aUri, CHTTPTestUtils& aUtils) |
|
25 { |
|
26 CTestClientHttpSimplePost* self = new(ELeave) CTestClientHttpSimplePost(aParams, aObserver, aUtils); |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(aClient, aUri); |
|
29 CleanupStack::Pop(); // self |
|
30 return self; |
|
31 } |
|
32 |
|
33 CTestClientHttpSimplePost::~CTestClientHttpSimplePost() |
|
34 { |
|
35 |
|
36 } |
|
37 |
|
38 CTestClientHttpSimplePost::CTestClientHttpSimplePost(CHttpClientTestParams& aParams, MLocalTestServerObserver& aObserver, CHTTPTestUtils& aUtils) |
|
39 : iObserver(aObserver), |
|
40 iParams(aParams), |
|
41 iTestUtils(aUtils) |
|
42 { |
|
43 |
|
44 } |
|
45 |
|
46 void CTestClientHttpSimplePost::ConstructL(CHttpService& aClient, const TDesC8& aUri) |
|
47 { |
|
48 TPtrC8 method; |
|
49 aClient.String(HTTP::EPOST, method); |
|
50 CHttpClientTransaction::Create(aClient, method, aUri); |
|
51 if(iParams.IsFileSending()) |
|
52 CHttpClientTransaction::SetContentSource(iParams.SourceFile()); |
|
53 else |
|
54 CHttpClientTransaction::SetContentSource(*this); |
|
55 } |
|
56 |
|
57 // From CHTTPClientTransaction |
|
58 void CTestClientHttpSimplePost::OnResponseHeaders() |
|
59 { |
|
60 // Check whether the status code matches |
|
61 if(iParams.StatusCode() != StatusCode()) |
|
62 { |
|
63 iObserver.EndTest(KErrCorrupt); |
|
64 } |
|
65 } |
|
66 |
|
67 void CTestClientHttpSimplePost::OnCompletion() |
|
68 { |
|
69 if(iParams.RequestBody().Length() > 0) |
|
70 { |
|
71 iObserver.EndTest(KErrNone); |
|
72 return; |
|
73 } |
|
74 if(iParams.MatchPostFileContent()) |
|
75 iObserver.EndTest(KErrNone); |
|
76 else |
|
77 iObserver.EndTest(KErrCorrupt); |
|
78 } |
|
79 |
|
80 void CTestClientHttpSimplePost::OnError(TInt aError) |
|
81 { |
|
82 if(aError == iParams.ExpectedError()) |
|
83 iObserver.EndTest(KErrNone); |
|
84 else |
|
85 iObserver.EndTest(aError); |
|
86 } |
|
87 |
|
88 void CTestClientHttpSimplePost::OnTransferProgress(TInt aTotal, TInt aTransffered) |
|
89 { |
|
90 if(iParams.TransferProgress()) |
|
91 { |
|
92 iTestUtils.LogIt(KTransferProgress(),aTotal,aTransffered); |
|
93 } |
|
94 } |
|
95 |
|
96 void CTestClientHttpSimplePost::OnData(THttpContentSourceOp& aData) |
|
97 { |
|
98 aData.Notify(iParams.RequestBody(), ETrue); |
|
99 } |
|
100 |
|
101 |