|
1 /* |
|
2 * Copyright (c) 2010 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: unit test for the sapidataobserver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS HEADER |
|
20 #include "ut_sapidataobserver.h" |
|
21 |
|
22 // EXTERNAL INCLUDES |
|
23 #include <digia/eunit/eunitmacros.h> |
|
24 #include <e32cmn.h> |
|
25 |
|
26 // INTERNAL INCLUDES |
|
27 #include "sapidata.h" |
|
28 #include "sapidataobserver.h" |
|
29 #include "sapidataplugin.h" |
|
30 #include "sapidatapluginconst.h" |
|
31 |
|
32 // CONSTRUCTION |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // UT_SapiDataObserver* UT_SapiDataObserver::NewL() |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 UT_SapiDataObserver* UT_SapiDataObserver::NewL() |
|
39 { |
|
40 UT_SapiDataObserver* self = UT_SapiDataObserver::NewLC(); |
|
41 CleanupStack::Pop(); |
|
42 |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // UT_SapiDataObserver* UT_SapiDataObserver::NewLC() |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 UT_SapiDataObserver* UT_SapiDataObserver::NewLC() |
|
51 { |
|
52 UT_SapiDataObserver* self = new(ELeave) UT_SapiDataObserver(); |
|
53 CleanupStack::PushL(self); |
|
54 |
|
55 self->ConstructL(); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Destructor (virtual by CBase) |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 UT_SapiDataObserver::~UT_SapiDataObserver() |
|
65 { |
|
66 |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Default constructor |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 UT_SapiDataObserver::UT_SapiDataObserver() |
|
74 { |
|
75 |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Second phase construct |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void UT_SapiDataObserver::ConstructL() |
|
83 { |
|
84 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
85 // It generates the test case table. |
|
86 CEUnitTestSuiteClass::ConstructL(); |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Auxiliary method for the obtaining of the MLiwInterface |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 MLiwInterface* UT_SapiDataObserver::GetMessagingInterfaceL() |
|
94 { |
|
95 if( !iServiceHandler ) |
|
96 { |
|
97 iServiceHandler = CLiwServiceHandler::NewL(); |
|
98 } |
|
99 |
|
100 CLiwGenericParamList* inParam = CLiwGenericParamList::NewL(); |
|
101 CleanupStack::PushL( inParam ); |
|
102 CLiwGenericParamList* outParam = CLiwGenericParamList::NewL(); |
|
103 CleanupStack::PushL( outParam ); |
|
104 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewL( KLiwCmdAsStr, KCPInterface, |
|
105 KCPService ); |
|
106 crit->SetServiceClass( TUid::Uid(KLiwClassBase) ); |
|
107 |
|
108 RCriteriaArray a; |
|
109 a.AppendL(crit); |
|
110 |
|
111 iServiceHandler->AttachL(a); |
|
112 iServiceHandler->ExecuteServiceCmdL( *crit, *inParam, *outParam ); |
|
113 |
|
114 delete crit; |
|
115 a.Reset(); |
|
116 |
|
117 // find service interface |
|
118 TInt pos = 0; |
|
119 MLiwInterface* msgInterface = NULL; |
|
120 outParam->FindFirst( pos, KCPInterface ); |
|
121 if ( pos != KErrNotFound ) |
|
122 { |
|
123 msgInterface = (*outParam)[pos].Value().AsInterface(); |
|
124 } |
|
125 |
|
126 outParam->Reset(); |
|
127 inParam->Reset(); |
|
128 CleanupStack::PopAndDestroy( outParam ); |
|
129 CleanupStack::PopAndDestroy( inParam ); |
|
130 |
|
131 return msgInterface; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // void UT_SapiDataObserver::SetupL() |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void UT_SapiDataObserver::SetupL() |
|
139 { |
|
140 iInterface = GetMessagingInterfaceL(); |
|
141 iPlugin = CSapiDataPlugin::NewL(); |
|
142 iData = CSapiData::NewL( iPlugin ); |
|
143 iObserver = CSapiDataObserver::NewL( iInterface, iData ); |
|
144 |
|
145 CLiwDefaultMap* filter = CLiwDefaultMap::NewLC(); |
|
146 filter->InsertL( KPublisherId, TLiwVariant( KPublisherId )); |
|
147 filter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) ); |
|
148 iObserver->RegisterL( filter, KCpData(), |
|
149 KExtendedNotifications ); |
|
150 CleanupStack::PopAndDestroy( filter ); |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // void UT_SapiDataObserver::Teardown() |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void UT_SapiDataObserver::Teardown() |
|
158 { |
|
159 if ( iObserver ) |
|
160 { |
|
161 iObserver->ReleaseL(); |
|
162 delete iObserver; |
|
163 iObserver = NULL; |
|
164 } |
|
165 if( iInterface ) |
|
166 { |
|
167 iInterface->Close(); |
|
168 iInterface = NULL; |
|
169 } |
|
170 if( iServiceHandler ) |
|
171 { |
|
172 iServiceHandler->Reset(); |
|
173 delete iServiceHandler; |
|
174 iServiceHandler = NULL; |
|
175 } |
|
176 if ( iData ) |
|
177 { |
|
178 delete iData; |
|
179 iData = NULL; |
|
180 } |
|
181 if ( iPlugin ) |
|
182 { |
|
183 delete iPlugin; |
|
184 iPlugin = NULL; |
|
185 } |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // void UT_SapiDataObserver::HandleSessionEventL() |
|
190 // --------------------------------------------------------------------------- |
|
191 // |
|
192 void UT_SapiDataObserver::ConstructTestL() |
|
193 { |
|
194 if ( iObserver ) |
|
195 EUNIT_ASSERT( ETrue ) |
|
196 else |
|
197 EUNIT_ASSERT( EFalse ); |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // void UT_SapiDataObserver::RegisterTestL() |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void UT_SapiDataObserver::RegisterTestL() |
|
205 { |
|
206 CLiwDefaultMap* conRegFilter = iData->CreateFilterLC(); |
|
207 conRegFilter->InsertL( KOperation, TLiwVariant( KAddUpdateDelete ) ); |
|
208 |
|
209 EUNIT_ASSERT_NO_LEAVE( iObserver->RegisterL( conRegFilter, KCpData(), KExtendedNotifications )); |
|
210 |
|
211 CleanupStack::PopAndDestroy( conRegFilter ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // void UT_SapiDataObserver::ReleaseTestL() |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void UT_SapiDataObserver::ReleaseTestL() |
|
219 { |
|
220 EUNIT_ASSERT_NO_LEAVE( iObserver->ReleaseL() ); |
|
221 |
|
222 delete iObserver; |
|
223 iObserver = NULL; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // void UT_SapiDataObserver::HandleNotifyTestL() |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void UT_SapiDataObserver::HandleNotifyTestL() |
|
231 { |
|
232 CLiwGenericParamList* paramList = CLiwGenericParamList::NewL(); |
|
233 TInt id = 999; |
|
234 TInt retValue = 0; |
|
235 |
|
236 retValue = iObserver->HandleNotifyL( id, 0, *paramList, *paramList ); |
|
237 |
|
238 if ( retValue == id ) |
|
239 EUNIT_ASSERT( ETrue ) |
|
240 else |
|
241 EUNIT_ASSERT( EFalse ); |
|
242 } |
|
243 |
|
244 // TEST TABLE |
|
245 |
|
246 EUNIT_BEGIN_TEST_TABLE |
|
247 ( |
|
248 UT_SapiDataObserver, |
|
249 "Sapidata Observer tests", |
|
250 "UNIT" |
|
251 ) |
|
252 |
|
253 EUNIT_TEST |
|
254 ( |
|
255 "Tests ConstructL()", |
|
256 "CSapiDataObserver", |
|
257 "ConstructL", |
|
258 "FUNCTIONALITY", |
|
259 SetupL, ConstructTestL, Teardown |
|
260 ) |
|
261 |
|
262 EUNIT_TEST |
|
263 ( |
|
264 "Tests RegisterL()", |
|
265 "CSapiDataObserver", |
|
266 "RegisterL", |
|
267 "FUNCTIONALITY", |
|
268 SetupL, RegisterTestL, Teardown |
|
269 ) |
|
270 |
|
271 EUNIT_TEST |
|
272 ( |
|
273 "Tests ReleaseL()", |
|
274 "CSapiDataObserver", |
|
275 "ReleaseL", |
|
276 "FUNCTIONALITY", |
|
277 SetupL, ReleaseTestL, Teardown |
|
278 ) |
|
279 |
|
280 EUNIT_TEST |
|
281 ( |
|
282 "Tests HandleNotify()", |
|
283 "CSapiDataObserver", |
|
284 "HandleNotifyL", |
|
285 "FUNCTIONALITY", |
|
286 SetupL, HandleNotifyTestL, Teardown |
|
287 ) |
|
288 |
|
289 EUNIT_END_TEST_TABLE |
|
290 |
|
291 // END OF FILE |