|
1 /* |
|
2 * Copyright (c) 2004 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 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "ut_cnatfwsockethandler.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include "natfwconnectivityapidefs.h" |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include "natfwsockethandler.h" |
|
30 #include "socketmediaconnwrappertestdefs.h" |
|
31 #include "natfwunittestmacros.h" |
|
32 |
|
33 _LIT8(KData,"qwerty"); |
|
34 const TUint KTestPortUdp = 5000; |
|
35 const TUint KTestPortTcp = 5001; |
|
36 const TUint KTestPort2 = 5010; |
|
37 |
|
38 // CONSTRUCTION |
|
39 ut_cnatfwsockethandler* ut_cnatfwsockethandler::NewL() |
|
40 { |
|
41 ut_cnatfwsockethandler* self = ut_cnatfwsockethandler::NewLC(); |
|
42 CleanupStack::Pop(); |
|
43 |
|
44 return self; |
|
45 } |
|
46 |
|
47 ut_cnatfwsockethandler* ut_cnatfwsockethandler::NewLC() |
|
48 { |
|
49 ut_cnatfwsockethandler* self = new( ELeave ) ut_cnatfwsockethandler(); |
|
50 CleanupStack::PushL( self ); |
|
51 |
|
52 self->ConstructL(); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 // Destructor (virtual by CBase) |
|
58 ut_cnatfwsockethandler::~ut_cnatfwsockethandler() |
|
59 { |
|
60 } |
|
61 |
|
62 // Default constructor |
|
63 ut_cnatfwsockethandler::ut_cnatfwsockethandler() |
|
64 { |
|
65 } |
|
66 |
|
67 // Second phase construct |
|
68 void ut_cnatfwsockethandler::ConstructL() |
|
69 { |
|
70 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
71 // It generates the test case table. |
|
72 CEUnitTestSuiteClass::ConstructL(); |
|
73 } |
|
74 |
|
75 // From observer interface |
|
76 void ut_cnatfwsockethandler::GetNewFreePort( TUint& aPort ) |
|
77 { |
|
78 aPort = KTestPort2; |
|
79 } |
|
80 |
|
81 // METHODS |
|
82 void ut_cnatfwsockethandler::SetupL( ) |
|
83 { |
|
84 iHandler = CNATFWSocketHandler::NewL( *this, *this, KProtocolInetUdp, KTestPortUdp ); |
|
85 User::LeaveIfError( iSocketServer.Connect() ); |
|
86 } |
|
87 |
|
88 void ut_cnatfwsockethandler::Setup2L( ) |
|
89 { |
|
90 iHandler = CNATFWSocketHandler::NewL( *this, *this, KProtocolInetTcp, KTestPortTcp ); |
|
91 User::LeaveIfError( iSocketServer.Connect() ); |
|
92 } |
|
93 |
|
94 void ut_cnatfwsockethandler::Teardown( ) |
|
95 { |
|
96 delete iHandler; |
|
97 iSocketServer.Close(); |
|
98 } |
|
99 |
|
100 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_NewLL( ) |
|
101 { |
|
102 TUint port = 0; |
|
103 CNATFWSocketHandler* handler = NULL; |
|
104 |
|
105 NATFW_EUNIT_ASSERT_SPECIFIC_LEAVE( |
|
106 handler = CNATFWSocketHandler::NewL( *this, *this, 0, port ), KErrArgument ); |
|
107 |
|
108 delete handler; |
|
109 } |
|
110 |
|
111 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_LocalAddressL( ) |
|
112 { |
|
113 iHandler->LocalAddress( iAddr ); |
|
114 } |
|
115 |
|
116 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SetAddrLL( ) |
|
117 { |
|
118 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
119 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
120 |
|
121 NATFW_EUNIT_ASSERT_SPECIFIC_LEAVE( iHandler->SetAddrL( iAddr ), KErrArgument ); |
|
122 |
|
123 delete iHandler; |
|
124 iHandler = NULL; |
|
125 iHandler = CNATFWSocketHandler::NewL( *this, *this, KProtocolInetTcp, KTestPortTcp ); |
|
126 |
|
127 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
128 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
129 } |
|
130 |
|
131 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SetAddrL2L( ) |
|
132 { |
|
133 TSockAddr addr; |
|
134 RSocket socket; |
|
135 |
|
136 User::LeaveIfError( socket.Open( iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp ) ); |
|
137 socket.SetLocalPort( KTestPortUdp ); |
|
138 |
|
139 // RSocket is stubbed and currently the used ports are not stored |
|
140 // so we can make the next localportcall fail with this |
|
141 TBool shouldItFail = ETrue; |
|
142 socket.NextSetLocalPortShouldFail(ETrue, shouldItFail); // fails |
|
143 |
|
144 iHandler->SetMediaObserverL( this ); |
|
145 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
146 // Will try to use same port as KTestPortUdp, but |
|
147 // since it's reserved, should switch to KTestPort2 |
|
148 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
149 |
|
150 iHandler->LocalAddress( addr ); |
|
151 EUNIT_ASSERT_EQUALS( KTestPort2, addr.Port() ); |
|
152 } |
|
153 |
|
154 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_ConnectLL( ) |
|
155 { |
|
156 iHandler->iSendState = iHandler->EConnected; |
|
157 } |
|
158 |
|
159 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_StartListeningLL( ) |
|
160 { |
|
161 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
162 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
163 } |
|
164 |
|
165 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SendLL( ) |
|
166 { |
|
167 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
168 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
169 iHandler->iSendState = iHandler->EConnected; |
|
170 iHandler->SetSendingStateL(); |
|
171 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SendL( KData ) ); |
|
172 } |
|
173 |
|
174 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SetLocalAddressL( ) |
|
175 { |
|
176 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
177 } |
|
178 |
|
179 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_DeactivateSendingL( ) |
|
180 { |
|
181 iHandler->DeactivateSending(); |
|
182 } |
|
183 |
|
184 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_DeactivateReceivingL( ) |
|
185 { |
|
186 iHandler->DeactivateReceiving(); |
|
187 } |
|
188 |
|
189 void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SetupTcpConnectionL( ) |
|
190 { |
|
191 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
192 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
193 iHandler->OpenTcpConnectionL( ETcpSetupActive, *this ); |
|
194 |
|
195 delete iHandler; |
|
196 iHandler = NULL; |
|
197 iHandler = CNATFWSocketHandler::NewL( *this, *this, KProtocolInetTcp, KTestPortTcp ); |
|
198 |
|
199 iHandler->SetLocalAddress( iSocketServer, iAddr ); |
|
200 NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) ); |
|
201 iHandler->OpenTcpConnectionL( ETcpSetupPassive, *this ); |
|
202 |
|
203 iHandler->iSendState = iHandler->EConnected; |
|
204 NATFW_EUNIT_ASSERT_SPECIFIC_LEAVE( iHandler->OpenTcpConnectionL( ETcpSetupPassive, *this ), KErrInUse ); |
|
205 } |
|
206 |
|
207 |
|
208 // TEST TABLE |
|
209 |
|
210 EUNIT_BEGIN_TEST_TABLE( |
|
211 ut_cnatfwsockethandler, |
|
212 "Add test suite description here.", |
|
213 "UNIT" ) |
|
214 |
|
215 EUNIT_TEST( |
|
216 "NewL - test ", |
|
217 "CNATFWSocketHandler", |
|
218 "NewL", |
|
219 "FUNCTIONALITY", |
|
220 SetupL, ut_cnatfwsockethandler_NewLL, Teardown) |
|
221 |
|
222 EUNIT_TEST( |
|
223 "LocalAddress - test ", |
|
224 "CNATFWSocketHandler", |
|
225 "LocalAddress", |
|
226 "FUNCTIONALITY", |
|
227 SetupL, ut_cnatfwsockethandler_LocalAddressL, Teardown) |
|
228 |
|
229 EUNIT_TEST( |
|
230 "SetAddrL - test ", |
|
231 "CNATFWSocketHandler", |
|
232 "SetAddrL", |
|
233 "FUNCTIONALITY", |
|
234 SetupL, ut_cnatfwsockethandler_SetAddrLL, Teardown) |
|
235 |
|
236 EUNIT_TEST( |
|
237 "SetAddrL2 - port in use test ", |
|
238 "CNATFWSocketHandler", |
|
239 "SetAddrL", |
|
240 "FUNCTIONALITY", |
|
241 SetupL, ut_cnatfwsockethandler_SetAddrL2L, Teardown) |
|
242 |
|
243 EUNIT_TEST( |
|
244 "ConnectL - test ", |
|
245 "CNATFWSocketHandler", |
|
246 "ConnectL", |
|
247 "FUNCTIONALITY", |
|
248 SetupL, ut_cnatfwsockethandler_ConnectLL, Teardown) |
|
249 |
|
250 EUNIT_TEST( |
|
251 "StartListeningL - test ", |
|
252 "CNATFWSocketHandler", |
|
253 "StartListeningL", |
|
254 "FUNCTIONALITY", |
|
255 SetupL, ut_cnatfwsockethandler_StartListeningLL, Teardown) |
|
256 |
|
257 EUNIT_TEST( |
|
258 "SendL - test ", |
|
259 "CNATFWSocketHandler", |
|
260 "SendL", |
|
261 "FUNCTIONALITY", |
|
262 SetupL, ut_cnatfwsockethandler_SendLL, Teardown) |
|
263 |
|
264 EUNIT_TEST( |
|
265 "SetLocalAddress - test ", |
|
266 "CNATFWSocketHandler", |
|
267 "SetLocalAddress", |
|
268 "FUNCTIONALITY", |
|
269 SetupL, ut_cnatfwsockethandler_SetLocalAddressL, Teardown) |
|
270 |
|
271 EUNIT_TEST( |
|
272 "DeactivateSending - test ", |
|
273 "CNATFWSocketHandler", |
|
274 "DeactivateSending", |
|
275 "FUNCTIONALITY", |
|
276 SetupL, ut_cnatfwsockethandler_DeactivateSendingL, Teardown) |
|
277 |
|
278 EUNIT_TEST( |
|
279 "DeactivateReceiving - test ", |
|
280 "CNATFWSocketHandler", |
|
281 "DeactivateReceiving", |
|
282 "FUNCTIONALITY", |
|
283 SetupL, ut_cnatfwsockethandler_DeactivateReceivingL, Teardown) |
|
284 |
|
285 EUNIT_TEST( |
|
286 "SetupTcpConnection - test ", |
|
287 "CNATFWSocketHandler", |
|
288 "SetupTcpConnection", |
|
289 "FUNCTIONALITY", |
|
290 Setup2L, ut_cnatfwsockethandler_SetupTcpConnectionL, Teardown) |
|
291 |
|
292 |
|
293 EUNIT_END_TEST_TABLE |
|
294 |
|
295 // END OF FILE |