|
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 "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 "csocketconnectordriver.h" |
|
17 |
|
18 #include <msocketfactory.h> |
|
19 #include <msocketconnector.h> |
|
20 |
|
21 #include "cclientsocketdriver.h" |
|
22 #include "thttptrhndtestpanic.h" |
|
23 |
|
24 const TInt KPortNumber = 80; |
|
25 const TInt KSecurePortNumber = 443; |
|
26 |
|
27 GLREF_D TBool gLongHostName; |
|
28 GLREF_D TBool gInvalidConnectPort; |
|
29 |
|
30 CSocketConnectorDriver* CSocketConnectorDriver::NewL(MDriverObserver& aObserver, MSocketFactory& aSocketFactory) |
|
31 /** |
|
32 @componentInternal |
|
33 @param aObserver The driver observer. |
|
34 @param aSocketFactory The socket factory. |
|
35 @return A pointer to a fully initialised object. |
|
36 */ |
|
37 { |
|
38 return new (ELeave) CSocketConnectorDriver(aObserver, aSocketFactory); |
|
39 } |
|
40 |
|
41 CSocketConnectorDriver::~CSocketConnectorDriver() |
|
42 /** |
|
43 Destructor |
|
44 @componentInternal |
|
45 */ |
|
46 { |
|
47 delete iClientSocketDriver; |
|
48 } |
|
49 |
|
50 CSocketConnectorDriver::CSocketConnectorDriver(MDriverObserver& aObserver, MSocketFactory& aSocketFactory) |
|
51 : CDriverBase(aObserver), iSocketFactory(aSocketFactory) |
|
52 /** |
|
53 Constructor |
|
54 @componentInternal |
|
55 @param aObserver The driver observer. |
|
56 @param aSocketFactory The socket factory. |
|
57 */ |
|
58 { |
|
59 } |
|
60 |
|
61 void CSocketConnectorDriver::SetDoubleConnectL() |
|
62 /** |
|
63 Sets the command stack to have the following behaviour. |
|
64 |
|
65 It initiates a connect service in the provided socket factory. It expects a |
|
66 connection to be made - it creates a client socket driver to control the |
|
67 connected socket. The client socket driver is expected to close. |
|
68 |
|
69 Then a second connection is initiated and then immediately stopped. A wait |
|
70 delay is started and the test driver terminates once the wait has completed. |
|
71 @componentInternal |
|
72 */ |
|
73 { |
|
74 // Create cmd stack |
|
75 AppendDoCmdL(EDoConnect); |
|
76 AppendExpectCmdL(EExpectConnected); |
|
77 AppendDoCmdL(EDoStartClientDriver); |
|
78 AppendExpectCmdL(EExpectClientClosed); |
|
79 AppendDoCmdL(EDoConnect); |
|
80 AppendDoCmdL(EDoStopConnect); |
|
81 AppendExpectCmdL(EExpectConnectError); |
|
82 } |
|
83 |
|
84 void CSocketConnectorDriver::SetSingleConnectL() |
|
85 /** |
|
86 Sets the command stack to have the following behaviour. |
|
87 |
|
88 It initiates a connect service in the provided socket factory. It expects a |
|
89 connection to be made - it creates a client socket driver to control the |
|
90 connected socket. The client socket driver is expected to close. |
|
91 @componentInternal |
|
92 */ |
|
93 { |
|
94 // Create cmd stack |
|
95 AppendDoCmdL(EDoConnect); |
|
96 AppendExpectCmdL(EExpectConnected); |
|
97 AppendDoCmdL(EDoStartClientDriver); |
|
98 AppendExpectCmdL(EExpectClientClosed); |
|
99 } |
|
100 |
|
101 void CSocketConnectorDriver::SetSingleSecureConnectL() |
|
102 /** |
|
103 Sets the command stack to have the following behaviour. |
|
104 |
|
105 It initiates a secure connect service in the provided socket factory. It expects a |
|
106 connection to be made - it creates a client socket driver to control the |
|
107 connected socket. The client socket driver is expected to close. |
|
108 @componentInternal |
|
109 */ |
|
110 { |
|
111 // Create cmd stack |
|
112 AppendDoCmdL(EDoSecureConnect); |
|
113 AppendExpectCmdL(EExpectConnected); |
|
114 AppendDoCmdL(EDoStartClientDriver); |
|
115 AppendExpectCmdL(EExpectClientClosed); |
|
116 } |
|
117 |
|
118 /* |
|
119 * Methods from CDriverBase |
|
120 */ |
|
121 |
|
122 void CSocketConnectorDriver::RunCmdL(TInt aCmd) |
|
123 /** |
|
124 @see CDriverBase |
|
125 @componentInternal |
|
126 */ |
|
127 { |
|
128 // Check the step number |
|
129 switch( aCmd ) |
|
130 { |
|
131 case EDoConnect: |
|
132 { |
|
133 DoLog(_L("Socket Connector Driver - initiate connection")); |
|
134 |
|
135 if(gLongHostName) |
|
136 { |
|
137 iSocketConnector = &iSocketFactory.ConnectL(*this, _L8(": This is a long Invalid address to which connection cannot be established "), KPortNumber); |
|
138 } |
|
139 else |
|
140 { |
|
141 iSocketConnector = &iSocketFactory.ConnectL(*this, _L8("127.0.0.1"), KPortNumber); |
|
142 } |
|
143 } break; |
|
144 case EDoSecureConnect: |
|
145 { |
|
146 DoLog(_L("Socket Connector Driver - initiate secure connection")); |
|
147 iSecure = ETrue; |
|
148 if (!gInvalidConnectPort) |
|
149 { |
|
150 iSocketConnector = &iSocketFactory.ConnectL(*this, _L8("lon-cn-lxwaptest2.closedtest.intra"), KSecurePortNumber); |
|
151 } |
|
152 else |
|
153 { |
|
154 iSocketConnector = &iSocketFactory.ConnectL(*this, _L8("lon-cn-lxwaptest2.closedtest.intra"), KPortNumber); |
|
155 } |
|
156 } break; |
|
157 case EDoStartClientDriver: |
|
158 { |
|
159 __ASSERT_DEBUG( iClientSocketDriver, User::Invariant() ); |
|
160 |
|
161 DoLog(_L("Socket Connector Driver - start client socket driver")); |
|
162 |
|
163 iClientSocketDriver->Start(); |
|
164 } break; |
|
165 case EDoStopConnect: |
|
166 { |
|
167 DoLog(_L("Socket Connector Driver - stop connection")); |
|
168 |
|
169 iSocketConnector->StopConnect(); |
|
170 } break; |
|
171 default: |
|
172 __ASSERT_DEBUG( 0, THttpTrHndTestPanic::Panic(THttpTrHndTestPanic::EBadCommandId) ); |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 /* |
|
178 * Methods from MSocketConnectObserver |
|
179 */ |
|
180 |
|
181 void CSocketConnectorDriver::ConnectionMadeL(MInputStream& aInputStream, MOutputStream& aOutputStream) |
|
182 /** |
|
183 @see MSocketConnectObserver |
|
184 @componentInternal |
|
185 */ |
|
186 { |
|
187 DoLog(_L("Socket Connector Driver - connection made")); |
|
188 |
|
189 if( TestExpectedCmd(EExpectConnected, KErrNone) ) |
|
190 { |
|
191 iClientSocketDriver = CClientSocketDriver::NewL(*this, *this, aInputStream, aOutputStream, iSecure); |
|
192 } |
|
193 } |
|
194 |
|
195 TInt CSocketConnectorDriver::HandleConnectError(TInt aError) |
|
196 /** |
|
197 @see MSocketConnectObserver |
|
198 @componentInternal |
|
199 */ |
|
200 { |
|
201 DoLog(_L("Socket Connector Driver - connect error")); |
|
202 |
|
203 TestExpectedCmd(EExpectConnectError, aError); |
|
204 return KErrNone; |
|
205 } |
|
206 |
|
207 void CSocketConnectorDriver::MSocketConnectObserver_Reserved() |
|
208 /** |
|
209 @see MSocketConnectObserver |
|
210 @componentInternal |
|
211 */ |
|
212 { |
|
213 User::Invariant(); |
|
214 } |
|
215 |
|
216 /* |
|
217 * Methods from MClientDriverObserver |
|
218 */ |
|
219 |
|
220 void CSocketConnectorDriver::ClientClosed() |
|
221 /** |
|
222 @see MClientDriverObserver |
|
223 @componentInternal |
|
224 */ |
|
225 { |
|
226 DoLog(_L("Socket Connector Driver - client driver closed")); |
|
227 |
|
228 TestExpectedCmd(EExpectClientClosed, KErrNone); |
|
229 } |