|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of the T_MProfileEngine test class. |
|
15 * |
|
16 */ |
|
17 |
|
18 //////////////////////////////////////////////////////////////////////// |
|
19 // T_MProfileEngine.cpp |
|
20 // |
|
21 |
|
22 // INCLUDES |
|
23 #include <centralrepository.h> |
|
24 #include <ProfileEngineSDKCRKeys.h> |
|
25 #include <e32math.h> |
|
26 #include <e32svr.h> |
|
27 #include <bautils.h> |
|
28 |
|
29 #include <EUnitMacros.h> |
|
30 #include <TEUnitAssertionInfo.h> |
|
31 |
|
32 #include <BAMDESCA.H> |
|
33 #include <MProfileEngine.h> |
|
34 #include <MProfile.h> |
|
35 #include <MProfilesNamesArray.h> |
|
36 #include <MProfileTones.h> |
|
37 #include <MProfileExtraTones.h> |
|
38 #include "MProfilesLocalFeatures.h" |
|
39 #include "ProfilesVariant.hrh" |
|
40 #include "MProfileExtended.h" |
|
41 #include "MProfileSetName.h" |
|
42 #include "MProfileEngineExtended.h" |
|
43 #include <TProfileToneSettings.h> |
|
44 //#include "T_ProfileTestTools.h" |
|
45 //#include "T_ProfileTestHelper.h" |
|
46 |
|
47 // the header for the tested class |
|
48 #include "T_MProfileEngine.h" |
|
49 |
|
50 //CONSTS |
|
51 const TProfileRingingVolume |
|
52 KProfileTestExpectedVolume( EProfileRingingVolumeLevel3 ); |
|
53 |
|
54 // Redefined from RSSSettings.h (which includes shareddatakeys.h and thus cannot |
|
55 // be included here): |
|
56 namespace |
|
57 { |
|
58 enum TSSSettingsAlsValue |
|
59 { |
|
60 ESSSettingsAlsNotSupported = 0, |
|
61 ESSSettingsAlsPrimary = 1, |
|
62 ESSSettingsAlsAlternate = 2 |
|
63 }; |
|
64 } |
|
65 |
|
66 // create the testing class |
|
67 T_MProfileEngine* T_MProfileEngine::NewLC() |
|
68 { |
|
69 T_MProfileEngine* self = new(ELeave) T_MProfileEngine; |
|
70 |
|
71 CleanupStack::PushL( self ); |
|
72 // need to generate the table, so call base classes |
|
73 // second phase constructor |
|
74 self->ConstructL(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 T_MProfileEngine::~T_MProfileEngine() |
|
79 { |
|
80 iFs.Close(); |
|
81 if( iProfileEngine ) |
|
82 { |
|
83 iProfileEngine->Release(); |
|
84 } |
|
85 iArray.Close(); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Setup |
|
90 */ |
|
91 void T_MProfileEngine::EmptySetupL() |
|
92 { |
|
93 iFs.Connect(); |
|
94 } |
|
95 |
|
96 |
|
97 |
|
98 void T_MProfileEngine::SetupL() |
|
99 { |
|
100 iFs.Connect(); |
|
101 iCenRep = CRepository::NewL( KCRUidProfileEngine ); |
|
102 iCenRep->Reset(); |
|
103 |
|
104 iProfileEngine = CreateProfileEngineL( &iFs ); |
|
105 iArray.Reset(); |
|
106 iProfileEngine->SetActiveProfileL( iActiveId ); |
|
107 iTimed = EFalse; |
|
108 } |
|
109 |
|
110 void T_MProfileEngine::Setup0L() |
|
111 { |
|
112 iActiveId = 0; |
|
113 SetupL(); |
|
114 } |
|
115 |
|
116 void T_MProfileEngine::SetupGetRingingVolumeL() |
|
117 { |
|
118 Setup0L(); |
|
119 |
|
120 User::LeaveIfError( iCenRep->Get( KProEngActiveRingingVolume, |
|
121 iOrigRingingVolume ) ); |
|
122 User::LeaveIfError( iCenRep->Set( KProEngActiveRingingVolume, |
|
123 KProfileTestExpectedVolume ) ); |
|
124 } |
|
125 |
|
126 void T_MProfileEngine::SetupGetMediaVolumeL() |
|
127 { |
|
128 Setup0L(); |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 * Teardown |
|
134 */ |
|
135 void T_MProfileEngine::EmptyTeardown() |
|
136 { |
|
137 iFs.Close(); |
|
138 } |
|
139 |
|
140 void T_MProfileEngine::Teardown() |
|
141 { |
|
142 iFs.Close(); |
|
143 delete iCenRep; |
|
144 if( iProfileEngine ) |
|
145 { |
|
146 iProfileEngine->Release(); |
|
147 iProfileEngine = NULL; |
|
148 } |
|
149 iArray.Reset(); |
|
150 } |
|
151 |
|
152 |
|
153 /** |
|
154 * Tests |
|
155 */ |
|
156 void T_MProfileEngine::EmptyTestL() |
|
157 { |
|
158 //EUNIT_ASSERT( ETrue ); |
|
159 } |
|
160 |
|
161 void T_MProfileEngine::CreateTestL() |
|
162 { |
|
163 MProfileEngine* tmp = NULL; |
|
164 tmp = CreateProfileEngineL(); |
|
165 EUNIT_ASSERT( tmp ); |
|
166 if( tmp ) |
|
167 { |
|
168 tmp->Release(); |
|
169 } |
|
170 |
|
171 tmp = NULL; |
|
172 tmp = CreateProfileEngineL(); |
|
173 CleanupReleasePushL( *tmp ); |
|
174 EUNIT_ASSERT( tmp ); |
|
175 CleanupStack::PopAndDestroy(); |
|
176 |
|
177 tmp = NULL; |
|
178 tmp = CreateProfileEngineL( &iFs ); |
|
179 EUNIT_ASSERT( tmp ); |
|
180 if( tmp ) |
|
181 { |
|
182 tmp->Release(); |
|
183 } |
|
184 |
|
185 tmp = NULL; |
|
186 tmp = CreateProfileEngineL( &iFs ); |
|
187 CleanupReleasePushL( *tmp ); |
|
188 EUNIT_ASSERT( tmp ); |
|
189 CleanupStack::PopAndDestroy(); |
|
190 } |
|
191 |
|
192 void T_MProfileEngine::GetActiveProfileTestL() |
|
193 { |
|
194 MProfile* profile = NULL; |
|
195 profile = iProfileEngine->ActiveProfileL(); |
|
196 EUNIT_ASSERT( profile ); |
|
197 profile->Release(); |
|
198 |
|
199 profile = NULL; |
|
200 profile = iProfileEngine->ActiveProfileLC(); |
|
201 CleanupStack::Pop(); // profile |
|
202 EUNIT_ASSERT( profile ); |
|
203 profile->Release(); |
|
204 } |
|
205 |
|
206 void T_MProfileEngine::GetActiveProfileIdTestL() |
|
207 { |
|
208 TInt id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
209 EUNIT_ASSERT( iActiveId == id ); |
|
210 } |
|
211 |
|
212 void T_MProfileEngine::SetActiveProfileTestL() |
|
213 { |
|
214 TInt id(0); |
|
215 iProfileEngine->SetActiveProfileL( 0 ); |
|
216 id = iProfileEngine->ActiveProfileId(); |
|
217 User::LeaveIfError( id ); |
|
218 EUNIT_ASSERT( id == 0 ); |
|
219 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 0 ) ); |
|
220 |
|
221 iProfileEngine->SetActiveProfileL( 1 ); |
|
222 id = iProfileEngine->ActiveProfileId(); |
|
223 User::LeaveIfError( id ); |
|
224 EUNIT_ASSERT( id == 1 ); |
|
225 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 1 ) ); |
|
226 |
|
227 iProfileEngine->SetActiveProfileL( 2 ); |
|
228 id = iProfileEngine->ActiveProfileId(); |
|
229 User::LeaveIfError( id ); |
|
230 EUNIT_ASSERT( id == 2 ); |
|
231 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 2 ) ); |
|
232 |
|
233 iProfileEngine->SetActiveProfileL( 3 ); |
|
234 id = iProfileEngine->ActiveProfileId(); |
|
235 User::LeaveIfError( id ); |
|
236 EUNIT_ASSERT( id == 3 ); |
|
237 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 3 ) ); |
|
238 |
|
239 iProfileEngine->SetActiveProfileL( 4 ); |
|
240 id = iProfileEngine->ActiveProfileId(); |
|
241 User::LeaveIfError( id ); |
|
242 EUNIT_ASSERT( id == 4 ); |
|
243 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 4 ) ); |
|
244 |
|
245 iProfileEngine->SetActiveProfileL( 0 ); |
|
246 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
247 EUNIT_ASSERT( id == 0 ); |
|
248 |
|
249 TRAPD( err, iProfileEngine->SetActiveProfileL( -1 ) ); |
|
250 EUNIT_ASSERT( err != KErrNone ); |
|
251 if( ( err != KErrNotFound ) && ( err != KErrPathNotFound ) ) |
|
252 { |
|
253 User::LeaveIfError( err ); |
|
254 } |
|
255 EUNIT_ASSERT( ( err == KErrNotFound ) || ( err == KErrPathNotFound ) ); |
|
256 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
257 EUNIT_ASSERT( id == 0 ); |
|
258 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 0 ) ); |
|
259 |
|
260 #ifdef __OFFLINE_MODE |
|
261 iProfileEngine->SetActiveProfileL( 5 ); |
|
262 id = iProfileEngine->ActiveProfileId(); |
|
263 User::LeaveIfError( id ); |
|
264 EUNIT_ASSERT( id == 5 ); |
|
265 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 5 ) ); |
|
266 |
|
267 iProfileEngine->SetActiveProfileL( 0 ); |
|
268 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
269 EUNIT_ASSERT( id == 0 ); |
|
270 #endif |
|
271 |
|
272 #ifdef __DRIVE_MODE |
|
273 iProfileEngine->SetActiveProfileL( 6 ); |
|
274 id = iProfileEngine->ActiveProfileId(); |
|
275 User::LeaveIfError( id ); |
|
276 EUNIT_ASSERT( id == 6 ); |
|
277 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 6 ) ); |
|
278 |
|
279 iProfileEngine->SetActiveProfileL( 0 ); |
|
280 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
281 EUNIT_ASSERT( id == 0 ); |
|
282 #endif |
|
283 TRAP( err, iProfileEngine->SetActiveProfileL( 7 ) ); |
|
284 EUNIT_ASSERT( err != KErrNone ); |
|
285 if( ( err != KErrNotFound ) && ( err != KErrPathNotFound ) ) |
|
286 { |
|
287 User::LeaveIfError( err ); |
|
288 } |
|
289 EUNIT_ASSERT( ( err == KErrNotFound ) || ( err == KErrPathNotFound ) ); |
|
290 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
291 EUNIT_ASSERT( id == 0 ); |
|
292 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 0 ) ); |
|
293 |
|
294 TRAP( err, iProfileEngine->SetActiveProfileL( 1232131 ) ); |
|
295 EUNIT_ASSERT( err != KErrNone ); |
|
296 if( ( err != KErrNotFound ) && ( err != KErrPathNotFound ) ) |
|
297 { |
|
298 User::LeaveIfError( err ); |
|
299 } |
|
300 EUNIT_ASSERT( ( err == KErrNotFound ) || ( err == KErrPathNotFound ) ); |
|
301 id = User::LeaveIfError( iProfileEngine->ActiveProfileId() ); |
|
302 EUNIT_ASSERT( id == 0 ); |
|
303 //EUNIT_ASSERT( T_ProfileTestTools::CheckSharedDataSettingsL( 0 ) ); |
|
304 } |
|
305 |
|
306 void T_MProfileEngine::GetProfilesNamesArrayTestL() |
|
307 { |
|
308 MProfilesNamesArray* array = iProfileEngine->ProfilesNamesArrayLC(); |
|
309 EUNIT_ASSERT( array ); |
|
310 //EUNIT_ASSERT( T_ProfileTestTools::CheckArray( *array ) ); |
|
311 CleanupStack::PopAndDestroy(); |
|
312 array = NULL; |
|
313 |
|
314 array = iProfileEngine->ProfilesNamesArrayLC(); |
|
315 EUNIT_ASSERT( array ); |
|
316 //EUNIT_ASSERT( T_ProfileTestTools::CheckArray( *array ) ); |
|
317 CleanupStack::Pop(); |
|
318 delete array; |
|
319 } |
|
320 |
|
321 void T_MProfileEngine::SetTempRingingVolumeTestL() |
|
322 { |
|
323 iProfileEngine->SetTempRingingVolumeL( EProfileRingingVolumeLevel5 ); |
|
324 TInt volume( 0 ); |
|
325 User::LeaveIfError( iCenRep->Get( KProEngActiveRingingVolume, volume ) ); |
|
326 EUNIT_ASSERT( volume == 5 ); |
|
327 TRAPD( err, |
|
328 iProfileEngine->SetTempRingingVolumeL( |
|
329 EProfileRingingVolumeLevel1 ) ); |
|
330 if( err ) |
|
331 { |
|
332 } |
|
333 #ifdef __PROTOCOL_CDMA |
|
334 //EUNIT_ASSERT( err == KErrNone ); |
|
335 #else |
|
336 //EUNIT_ASSERT( err == KErrNotSupported ); |
|
337 #endif |
|
338 |
|
339 iProfileEngine->SetTempRingingVolumeL( EProfileRingingVolumeLevel7 ); |
|
340 } |
|
341 |
|
342 void T_MProfileEngine::SetTempMediaVolumeTestL() |
|
343 { |
|
344 iProfileEngine->SetTempMediaVolumeL( EProfileRingingVolumeLevel2 ); |
|
345 } |
|
346 |
|
347 void T_MProfileEngine::GetTempRingingVolumeTestL() |
|
348 { |
|
349 TProfileRingingVolume vol( iProfileEngine->TempRingingVolumeL() ); |
|
350 EUNIT_ASSERT( vol == KProfileTestExpectedVolume ); |
|
351 } |
|
352 |
|
353 void T_MProfileEngine::GetTempMediaVolumeTestL() |
|
354 { |
|
355 TProfileRingingVolume vol( iProfileEngine->TempMediaVolumeL() ); |
|
356 } |
|
357 |
|
358 void T_MProfileEngine::IsActiveProfileTimedLTestL() |
|
359 { |
|
360 MProfileEngineExtended* engineExt = CreateProfileEngineExtendedL( &iFs ); |
|
361 CleanupReleasePushL( *engineExt ); |
|
362 MProfilesLocalFeatures& features = engineExt->LocalFeatures(); |
|
363 if( features.IsFeatureSupported( KProEngFeatureIdTimedProfiles ) ) |
|
364 { |
|
365 TBool result( iProfileEngine->IsActiveProfileTimedL() ); |
|
366 EUNIT_ASSERT( result == iTimed ); |
|
367 } |
|
368 CleanupStack::PopAndDestroy(); //engineExt |
|
369 } |
|
370 |
|
371 // Test case table for this test suite class |
|
372 EUNIT_BEGIN_TEST_TABLE( T_MProfileEngine, "T_MProfileEngine test suite", "MODULE" ) |
|
373 |
|
374 EUNIT_TESTCASE("Create test ", EmptySetupL, CreateTestL, EmptyTeardown) |
|
375 // |
|
376 EUNIT_TESTCASE("Get active profile test", Setup0L, GetActiveProfileTestL, Teardown ) |
|
377 EUNIT_TESTCASE("Get active profile id test ", Setup0L, GetActiveProfileIdTestL, Teardown ) |
|
378 EUNIT_TESTCASE("Set active profile test ", Setup0L, SetActiveProfileTestL, Teardown ) |
|
379 EUNIT_TESTCASE("Get profiles names array test ", Setup0L, GetProfilesNamesArrayTestL, Teardown ) |
|
380 |
|
381 EUNIT_TESTCASE("Set temporary ringing volume ", Setup0L, SetTempRingingVolumeTestL, Teardown ) |
|
382 EUNIT_TESTCASE("Set temporary media volume ", Setup0L, SetTempMediaVolumeTestL, Teardown ) |
|
383 EUNIT_TESTCASE("Get temporary ringing volume ", SetupGetRingingVolumeL, GetTempRingingVolumeTestL, Teardown ) |
|
384 EUNIT_TESTCASE("Get temporary media volume ", SetupGetMediaVolumeL, GetTempMediaVolumeTestL, Teardown ) |
|
385 EUNIT_TESTCASE("Is Active Profile Timed test", Setup0L, IsActiveProfileTimedLTestL, Teardown ) |
|
386 |
|
387 EUNIT_END_TESTCASE_TABLE |
|
388 |
|
389 // End of File |