|
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 // CLASS HEADER |
|
20 #include "UT_CMusAvaInviteHandler.h" |
|
21 #include "musavaavailabilityobserver.h" |
|
22 #include "musavaavailabilityobserverimp.h" |
|
23 #include "musavasettingsimp.h" |
|
24 #include "musavaInviteresponderobserverimp.h" |
|
25 #include "musavainviteresponder.h" |
|
26 #include "muslogger.h" |
|
27 #include "musavaobserverimp.h" |
|
28 #include "musavacapabilitytesthelper.h" //remove compilation warning |
|
29 |
|
30 |
|
31 // EXTERNAL INCLUDES |
|
32 #include <digia/eunit/eunitmacros.h> |
|
33 #include <sipstrings.h> |
|
34 #include <sipstrconsts.h> |
|
35 #include <stringpool.h> |
|
36 #include <sipservertransaction.h> |
|
37 #include <siptransactionbase.h> |
|
38 #include <digia/eunit/eunitdecorators.h> |
|
39 // INTERNAL INCLUDES |
|
40 #include "musavainvitehandler.h" |
|
41 |
|
42 |
|
43 |
|
44 // CONSTRUCTION |
|
45 UT_CMusAvaInviteHandler* UT_CMusAvaInviteHandler::NewL() |
|
46 { |
|
47 UT_CMusAvaInviteHandler* self = UT_CMusAvaInviteHandler::NewLC(); |
|
48 CleanupStack::Pop(); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 UT_CMusAvaInviteHandler* UT_CMusAvaInviteHandler::NewLC() |
|
54 { |
|
55 UT_CMusAvaInviteHandler* self = new( ELeave ) UT_CMusAvaInviteHandler(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 |
|
59 return self; |
|
60 } |
|
61 |
|
62 // Destructor (virtual by CBase) |
|
63 UT_CMusAvaInviteHandler::~UT_CMusAvaInviteHandler() |
|
64 { |
|
65 } |
|
66 |
|
67 // Default constructor |
|
68 UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler() |
|
69 { |
|
70 } |
|
71 |
|
72 // Second phase construct |
|
73 void UT_CMusAvaInviteHandler::ConstructL() |
|
74 { |
|
75 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
76 // It generates the test case table. |
|
77 CEUnitTestSuiteClass::ConstructL(); |
|
78 } |
|
79 |
|
80 // METHODS |
|
81 |
|
82 void UT_CMusAvaInviteHandler::SetupL( ) |
|
83 { |
|
84 SIPStrings::OpenL(); |
|
85 iAvailabilityObserver = CMusAvaAvailabilityObserverImp::NewL(); |
|
86 iConcreteSettings = CMusAvaSettingsImp::NewL(); |
|
87 iInviteHandler = CMusAvaInviteHandler::NewL( *iAvailabilityObserver, |
|
88 *iConcreteSettings ); |
|
89 } |
|
90 |
|
91 void UT_CMusAvaInviteHandler::Teardown( ) |
|
92 { |
|
93 delete iAvailabilityObserver; |
|
94 delete iConcreteSettings; |
|
95 delete iInviteHandler; |
|
96 SIPStrings::Close(); |
|
97 } |
|
98 |
|
99 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_NewLL( ) |
|
100 { |
|
101 EUNIT_ASSERT( iInviteHandler ); |
|
102 } |
|
103 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_IncomingRequestL() |
|
104 { |
|
105 CSIPServerTransaction* transaction = |
|
106 CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
107 CleanupStack::PushL( transaction ); |
|
108 transaction->iIsClientTransaction = ETrue; |
|
109 transaction->iState = CSIPTransactionBase::ETrying; |
|
110 EUNIT_ASSERT( !iInviteHandler->IncomingRequest( transaction ) ); |
|
111 CleanupStack::Pop( transaction ); |
|
112 |
|
113 // Request not INVITE |
|
114 transaction = |
|
115 CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EOptions ) ); |
|
116 CleanupStack::PushL( transaction ); |
|
117 transaction->iIsClientTransaction = ETrue; |
|
118 transaction->iState = CSIPTransactionBase::ETrying; |
|
119 EUNIT_ASSERT( iInviteHandler->IncomingRequest( transaction ) == KErrNotFound ); |
|
120 CleanupStack::PopAndDestroy( transaction ); |
|
121 } |
|
122 |
|
123 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_DoExecuteLL() |
|
124 { |
|
125 TInt ret = 0; |
|
126 TRAPD( error, iInviteHandler->DoExecuteL() ); |
|
127 if ( error == KErrNoMemory ) User::Leave( error ); |
|
128 EUNIT_ASSERT ( error == KErrNone ); |
|
129 |
|
130 EUNIT_ASSERT( iInviteHandler->State() == MMusAvaObserver::EMusAvaStatusAvailable ); |
|
131 } |
|
132 |
|
133 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_NameL() |
|
134 { |
|
135 EUNIT_ASSERT( iInviteHandler->Name() == MMusAvaObserver::EMusAvaInviteHandler ); |
|
136 } |
|
137 |
|
138 |
|
139 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_StopL() |
|
140 { |
|
141 iInviteHandler->Stop(); |
|
142 EUNIT_ASSERT( iInviteHandler->iResponders.Count() == 0 ); |
|
143 } |
|
144 |
|
145 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_InvitationReceivedLL() |
|
146 { |
|
147 //Fails |
|
148 CSIPServerTransaction* transaction2 = |
|
149 CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
150 CleanupStack::PushL( transaction2 ); |
|
151 transaction2->iState = CSIPTransactionBase::ETerminated; |
|
152 iInviteHandler->InvitationReceivedL( transaction2 ); |
|
153 EUNIT_ASSERT( iInviteHandler->iResponders.Count() == 0 ); |
|
154 CleanupStack::Pop( transaction2 ); |
|
155 //Ok |
|
156 CSIPServerTransaction* transaction = |
|
157 CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
158 CleanupStack::PushL( transaction ); |
|
159 transaction->iIsClientTransaction = EFalse; |
|
160 transaction->iState = CSIPTransactionBase::ETrying; |
|
161 TRAPD( error, iInviteHandler->InvitationReceivedL( transaction ) ); |
|
162 if ( error == KErrNoMemory ) User::Leave( error ); |
|
163 CleanupStack::Pop( transaction ); |
|
164 TInt count = NULL; |
|
165 EUNIT_GET_ALLOC_DECORATOR_FAILCOUNT( count ); |
|
166 if ( count > 0 && iInviteHandler->iResponders.Count() == 0 ) |
|
167 { |
|
168 User::Leave( KErrNoMemory ); |
|
169 } |
|
170 EUNIT_ASSERT( iInviteHandler->iResponders.Count() > 0 ); |
|
171 } |
|
172 |
|
173 void UT_CMusAvaInviteHandler::UT_CMusAvaInviteHandler_InvitationAnsweredLDL() |
|
174 { |
|
175 //not removed, because response it not completed |
|
176 CMusAvaInviteResponderObserverImp* responderObserverImp = CMusAvaInviteResponderObserverImp::NewL(); |
|
177 CleanupStack::PushL( responderObserverImp ); |
|
178 CSIPServerTransaction* serverTransaction = CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
179 CleanupStack::PushL( serverTransaction ); |
|
180 CMusAvaInviteResponder* inviteResponder = CMusAvaInviteResponder::NewL( serverTransaction, |
|
181 *responderObserverImp ); |
|
182 CleanupStack::Pop( serverTransaction ); |
|
183 CleanupStack::PushL( inviteResponder ); |
|
184 User::LeaveIfError( iInviteHandler->iResponders.Append( inviteResponder ) ); |
|
185 CleanupStack::Pop( inviteResponder ); |
|
186 iInviteHandler->InvitationAnsweredLD( ); |
|
187 EUNIT_ASSERT( iInviteHandler->iResponders.Count() > 0 ); |
|
188 iInviteHandler->iResponders.ResetAndDestroy(); |
|
189 CleanupStack::PopAndDestroy( responderObserverImp ); |
|
190 //Ok |
|
191 CMusAvaInviteResponderObserverImp* responderObserverImp2 = CMusAvaInviteResponderObserverImp::NewL(); |
|
192 CleanupStack::PushL( responderObserverImp2 ); |
|
193 |
|
194 CSIPServerTransaction* serverTransaction2 = CSIPServerTransaction::NewL( SIPStrings::StringF( SipStrConsts::EInvite ) ); |
|
195 CleanupStack::PushL( serverTransaction2 ); |
|
196 CMusAvaInviteResponder* inviteResponder2 = CMusAvaInviteResponder::NewL( serverTransaction2, |
|
197 *responderObserverImp2 ); |
|
198 CleanupStack::Pop( serverTransaction2 ); |
|
199 CleanupStack::PushL( inviteResponder2 ); |
|
200 User::LeaveIfError( iInviteHandler->iResponders.Append( inviteResponder2 ) ); |
|
201 CleanupStack::Pop( inviteResponder2 ); |
|
202 serverTransaction2->iState = CSIPTransactionBase::ETerminated; |
|
203 iInviteHandler->InvitationAnsweredLD( ); |
|
204 EUNIT_ASSERT( iInviteHandler->iResponders.Count() == 0 ); |
|
205 CleanupStack::PopAndDestroy( responderObserverImp2 ); |
|
206 } |
|
207 |
|
208 |
|
209 // TEST TABLE |
|
210 |
|
211 EUNIT_BEGIN_TEST_TABLE( |
|
212 UT_CMusAvaInviteHandler, |
|
213 "CMusAvaInviteHandler", |
|
214 "UNIT" ) |
|
215 |
|
216 EUNIT_TEST( |
|
217 "NewL - test ", |
|
218 "CMusAvaInviteHandler", |
|
219 "NewL", |
|
220 "FUNCTIONALITY", |
|
221 SetupL,UT_CMusAvaInviteHandler_NewLL, Teardown) |
|
222 |
|
223 EUNIT_TEST( |
|
224 "IncomingRequest - test ", |
|
225 "CMusAvaInviteHandler", |
|
226 "IncomingRequest", |
|
227 "FUNCTIONALITY", |
|
228 SetupL,UT_CMusAvaInviteHandler_IncomingRequestL, Teardown) |
|
229 |
|
230 EUNIT_TEST( |
|
231 "DoExecuteL - test ", |
|
232 "CMusAvaInviteHandler", |
|
233 "DoExecuteL", |
|
234 "FUNCTIONALITY", |
|
235 SetupL,UT_CMusAvaInviteHandler_DoExecuteLL, Teardown) |
|
236 |
|
237 EUNIT_TEST( |
|
238 "Name - test ", |
|
239 "CMusAvaInviteHandler", |
|
240 "Name", |
|
241 "FUNCTIONALITY", |
|
242 SetupL,UT_CMusAvaInviteHandler_NameL, Teardown) |
|
243 |
|
244 |
|
245 EUNIT_TEST( |
|
246 "Stop - test ", |
|
247 "CMusAvaInviteHandler", |
|
248 "Stop", |
|
249 "FUNCTIONALITY", |
|
250 SetupL,UT_CMusAvaInviteHandler_StopL, Teardown) |
|
251 |
|
252 EUNIT_TEST( |
|
253 "InvitationReceivedL - test ", |
|
254 "CMusAvaInviteHandler", |
|
255 "InvitationReceivedL", |
|
256 "FUNCTIONALITY", |
|
257 SetupL,UT_CMusAvaInviteHandler_InvitationReceivedLL, Teardown) |
|
258 |
|
259 EUNIT_TEST( |
|
260 "InvitationAnsweredLD - test ", |
|
261 "CMusAvaInviteHandler", |
|
262 "InvitationAnsweredLD", |
|
263 "FUNCTIONALITY", |
|
264 SetupL,UT_CMusAvaInviteHandler_InvitationAnsweredLDL, Teardown) |
|
265 |
|
266 |
|
267 EUNIT_END_TEST_TABLE |
|
268 |
|
269 // END OF FILE |