|
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_cnatfwunsaftlssender.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include <CommDbConnPref.h> |
|
27 |
|
28 // INTERNAL INCLUDES |
|
29 #include "natfwunsaftransporttestutils.h" |
|
30 #include "cnatfwunsaftlssender.h" |
|
31 #include "natfwunsafmessage.h" |
|
32 |
|
33 // CONSTRUCTION |
|
34 UT_CNATFWUNSAFTlsSender* UT_CNATFWUNSAFTlsSender::NewL() |
|
35 { |
|
36 UT_CNATFWUNSAFTlsSender* self = UT_CNATFWUNSAFTlsSender::NewLC(); |
|
37 CleanupStack::Pop(); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 UT_CNATFWUNSAFTlsSender* UT_CNATFWUNSAFTlsSender::NewLC() |
|
43 { |
|
44 UT_CNATFWUNSAFTlsSender* self = new( ELeave ) UT_CNATFWUNSAFTlsSender(); |
|
45 CleanupStack::PushL( self ); |
|
46 |
|
47 self->ConstructL(); |
|
48 |
|
49 return self; |
|
50 } |
|
51 |
|
52 // Destructor (virtual by CBase) |
|
53 UT_CNATFWUNSAFTlsSender::~UT_CNATFWUNSAFTlsSender() |
|
54 { |
|
55 } |
|
56 |
|
57 // Default constructor |
|
58 UT_CNATFWUNSAFTlsSender::UT_CNATFWUNSAFTlsSender() |
|
59 { |
|
60 } |
|
61 |
|
62 // Second phase construct |
|
63 void UT_CNATFWUNSAFTlsSender::ConstructL() |
|
64 { |
|
65 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
66 // It generates the test case table. |
|
67 CEUnitTestSuiteClass::ConstructL(); |
|
68 } |
|
69 |
|
70 // METHODS |
|
71 |
|
72 void UT_CNATFWUNSAFTlsSender::SetupL() |
|
73 { |
|
74 User::LeaveIfError( iServer.Connect( 8 ) ); |
|
75 User::LeaveIfError( iConn.Open( iServer, KConnectionTypeDefault ) ); |
|
76 |
|
77 TCommDbConnPref prefs; |
|
78 prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
79 prefs.SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
80 prefs.SetIapId(10); |
|
81 User::LeaveIfError( iConn.Start( prefs ) ); |
|
82 |
|
83 User::LeaveIfError( iSocket.Open( iServer, |
|
84 KAfInet, |
|
85 KSockStream, |
|
86 KProtocolInetTcp, |
|
87 iConn ) ); |
|
88 |
|
89 _LIT( KTLS1,"TLS1.0" ); |
|
90 iSecureSocket = CSecureSocket::NewL( iSocket, KTLS1 ); |
|
91 |
|
92 iSender = CNATFWUNSAFTlsSender::NewL( *iSecureSocket, *this ); |
|
93 |
|
94 iMsg = NATFWUNSAFTransportTestUtils::CreateUNSAFBindingRequestL(); |
|
95 } |
|
96 |
|
97 |
|
98 void UT_CNATFWUNSAFTlsSender::Teardown() |
|
99 { |
|
100 delete iMsg; |
|
101 delete iSender; |
|
102 |
|
103 delete iSecureSocket; |
|
104 iSocket.Close(); |
|
105 iConn.Close(); |
|
106 iServer.Close(); |
|
107 } |
|
108 |
|
109 |
|
110 // From MNATFWUNSAFTlsTransportObserver: |
|
111 void UT_CNATFWUNSAFTlsSender::TlsConnectedL() |
|
112 { |
|
113 // Allocate some memory, so that this function leaves |
|
114 // in memory allocation failure simulation. |
|
115 HBufC8* temp = HBufC8::NewL( 100 ); |
|
116 delete temp; |
|
117 } |
|
118 |
|
119 // From MNATFWUNSAFTlsTransportObserver: |
|
120 void UT_CNATFWUNSAFTlsSender::IncomingMessageL( CNATFWUNSAFMessage* /*aMessage*/ ) |
|
121 { |
|
122 // Allocate some memory, so that this function leaves |
|
123 // in memory allocation failure simulation. |
|
124 HBufC8* temp = HBufC8::NewL( 100 ); |
|
125 delete temp; |
|
126 // TODO: delete aMessage |
|
127 } |
|
128 |
|
129 // From MNATFWUNSAFTlsTransportObserver: |
|
130 void UT_CNATFWUNSAFTlsSender::ErrorOccured( TInt aError ) |
|
131 { |
|
132 iLastError = aError; |
|
133 } |
|
134 |
|
135 void UT_CNATFWUNSAFTlsSender::SendTestL() |
|
136 { |
|
137 iSender->SendL( *iMsg, KNullDesC8 ); |
|
138 |
|
139 EUNIT_ASSERT( iSender->iEncoded != 0 ); |
|
140 |
|
141 CompleteSendL( KErrNone ); |
|
142 |
|
143 EUNIT_ASSERT( iSender->iEncoded == 0 ); |
|
144 } |
|
145 |
|
146 void UT_CNATFWUNSAFTlsSender::SendFailedTestL() |
|
147 { |
|
148 iSender->SendL( *iMsg, KNullDesC8 ); |
|
149 |
|
150 TInt error( KErrGeneral ); |
|
151 CompleteSendL( error ); |
|
152 |
|
153 EUNIT_ASSERT( iLastError == error ); |
|
154 EUNIT_ASSERT( iSender->iEncoded == 0 ); |
|
155 } |
|
156 |
|
157 void UT_CNATFWUNSAFTlsSender::CancelSendTestL() |
|
158 { |
|
159 iSender->SendL( *iMsg, KNullDesC8 ); |
|
160 |
|
161 iSender->Cancel(); |
|
162 |
|
163 EUNIT_ASSERT( !iSender->IsActive() ); |
|
164 } |
|
165 |
|
166 void UT_CNATFWUNSAFTlsSender::QueueTestL() |
|
167 { |
|
168 iSender->SendL( *iMsg, KNullDesC8 ); |
|
169 EUNIT_ASSERT( iSender->iEncoded != 0 ); |
|
170 |
|
171 TRAPD( err, iSender->SendL( *iMsg, KNullDesC8 ) ); |
|
172 if ( err == KErrNoMemory ) |
|
173 { |
|
174 User::Leave( err ); |
|
175 } |
|
176 EUNIT_ASSERT( err == KErrInUse ); |
|
177 EUNIT_ASSERT( iSender->iEncoded != 0 ); |
|
178 |
|
179 CompleteSendL( KErrNone ); |
|
180 EUNIT_ASSERT( iSender->iEncoded == 0 ); |
|
181 } |
|
182 |
|
183 void UT_CNATFWUNSAFTlsSender::RunErrorTestL() |
|
184 { |
|
185 // Currently there's nothing in TLS sender's RunL which could leave |
|
186 // and cause RunError. Test the method anyway. |
|
187 |
|
188 TInt err = iSender->RunError( KErrGeneral ); |
|
189 EUNIT_ASSERT( iLastError == KErrGeneral ); |
|
190 EUNIT_ASSERT( err == KErrNone ); |
|
191 |
|
192 err = iSender->RunError( KErrNoMemory ); |
|
193 EUNIT_ASSERT( iLastError == KErrNoMemory ); |
|
194 EUNIT_ASSERT( err == KErrNoMemory ); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // Helpers |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void UT_CNATFWUNSAFTlsSender::CompleteSendL( TInt aStatus ) |
|
202 { |
|
203 // Complete send request |
|
204 |
|
205 // Canceling CSecureSocket will distract cppunit leave failure simulation |
|
206 // becuase of trap inside CSecureSocket |
|
207 iSender->Cancel(); |
|
208 |
|
209 iSender->iStatus = aStatus; |
|
210 |
|
211 TRAPD( err, iSender->RunL() ); |
|
212 if ( err ) |
|
213 { |
|
214 // Simulate active scheduler behavior |
|
215 err = iSender->RunError( err ); |
|
216 User::LeaveIfError( err ); |
|
217 } |
|
218 } |
|
219 |
|
220 // TEST TABLE |
|
221 |
|
222 EUNIT_BEGIN_TEST_TABLE( |
|
223 UT_CNATFWUNSAFTlsSender, |
|
224 "Add test suite description here.", |
|
225 "UNIT" ) |
|
226 |
|
227 EUNIT_TEST( |
|
228 "SendTestL - test ", |
|
229 "CNATFWUNSAFTlsSender", |
|
230 "SendTestL", |
|
231 "FUNCTIONALITY", |
|
232 SetupL, SendTestL, Teardown) |
|
233 |
|
234 EUNIT_TEST( |
|
235 "SendFailedTestL - test ", |
|
236 "CNATFWUNSAFTlsSender", |
|
237 "SendFailedTestL", |
|
238 "FUNCTIONALITY", |
|
239 SetupL, SendFailedTestL, Teardown) |
|
240 |
|
241 EUNIT_TEST( |
|
242 "CancelSendTestL - test ", |
|
243 "CNATFWUNSAFTlsSender", |
|
244 "CancelSendTestL", |
|
245 "FUNCTIONALITY", |
|
246 SetupL, CancelSendTestL, Teardown) |
|
247 |
|
248 EUNIT_TEST( |
|
249 "QueueTestL - test ", |
|
250 "CNATFWUNSAFTlsSender", |
|
251 "QueueTestL", |
|
252 "FUNCTIONALITY", |
|
253 SetupL, QueueTestL, Teardown) |
|
254 |
|
255 EUNIT_TEST( |
|
256 "RunErrorTestL - test ", |
|
257 "CNATFWUNSAFTlsSender", |
|
258 "RunErrorTestL", |
|
259 "FUNCTIONALITY", |
|
260 SetupL, RunErrorTestL, Teardown) |
|
261 |
|
262 EUNIT_END_TEST_TABLE |
|
263 |
|
264 // END OF FILE |