|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // TA_ARRAY.CPP |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <basched.h> |
|
20 #include <f32file.h> |
|
21 #include <centralrepository.h> |
|
22 |
|
23 #include <bassnd.h> |
|
24 #include "BASSNDUID.h" |
|
25 #include "BASSNDPriorityDecoder.h" |
|
26 |
|
27 LOCAL_D RTest test(_L("T_SSND")); |
|
28 RFs TheFs; |
|
29 TBool TestingOOM = EFalse; |
|
30 |
|
31 const TUid KRing1={100}; |
|
32 const TUid KRing2={101}; |
|
33 const TUid KAlarm1={201}; |
|
34 const TUid KAlarm2={202}; |
|
35 const TUid KMessage1={203}; |
|
36 |
|
37 _LIT(KSndNameWarble,"c:\\system\\data\\warble.wav"); |
|
38 _LIT(KSndNameMozart,"c:\\system\\data\\mozart.wav"); |
|
39 _LIT(KSndNameBach,"c:\\system\\data\\bach.wav"); |
|
40 _LIT(KSndNameVivaldi,"c:\\system\\data\\vivaldi.wav"); |
|
41 |
|
42 #define TEST2(err, cond) \ |
|
43 {\ |
|
44 if (TestingOOM && err == KErrNoMemory) \ |
|
45 {\ |
|
46 User::LeaveNoMemory();\ |
|
47 }\ |
|
48 test(cond);\ |
|
49 } |
|
50 |
|
51 // Delete all entries in sound table |
|
52 LOCAL_C void ClearSoundTableL() |
|
53 { |
|
54 CRepository *repository = CRepository::NewLC(KSystemSoundRepositoryUID); |
|
55 repository->Reset(); |
|
56 CleanupStack::PopAndDestroy( repository ); |
|
57 } |
|
58 |
|
59 LOCAL_C void TestSetSounds1L() |
|
60 { |
|
61 TBaSystemSoundType sndType(KSystemSoundRingUID,KRing1); |
|
62 TBaSystemSoundInfo sndInfo(sndType,KSndNameWarble()); |
|
63 BaSystemSound::SetSoundL(TheFs,sndInfo); |
|
64 } |
|
65 |
|
66 LOCAL_C void TestSetSounds2L() |
|
67 { |
|
68 TBaSystemSoundType sndType(KSystemSoundRingUID,KRing2); |
|
69 TBaSystemSoundInfo sndInfo(sndType,KSndNameMozart()); |
|
70 BaSystemSound::SetSoundL(TheFs,sndInfo); |
|
71 } |
|
72 |
|
73 LOCAL_C void TestSetSounds3L() |
|
74 { |
|
75 TBaSystemSoundType sndType(KSystemSoundAlarmUID,KAlarm1); |
|
76 TBaSystemSoundInfo sndInfo(sndType,KSndNameBach()); |
|
77 sndInfo.iVolume=100; |
|
78 sndInfo.iPriority=TBaSoundPriorityEncoder(16).Int(); |
|
79 BaSystemSound::SetSoundL(TheFs,sndInfo); |
|
80 } |
|
81 |
|
82 LOCAL_C void TestSetSounds4L() |
|
83 { |
|
84 TBaSystemSoundType sndType(KSystemSoundAlarmUID,KAlarm2); |
|
85 TBaSystemSoundInfo sndInfo(sndType,KSndNameVivaldi()); |
|
86 sndInfo.iVolume=83; |
|
87 TBaSoundPriorityEncoder priority(-100,(TMdaPriorityPreference(0xFF030001))); |
|
88 sndInfo.iPriority=priority.Int(); |
|
89 BaSystemSound::SetSoundL(TheFs,sndInfo); |
|
90 } |
|
91 |
|
92 /** |
|
93 @SYMTestCaseID SYSLIB-BAFL-CT-1286 |
|
94 @SYMTestCaseDesc Tests for BaSystemSound::SetSoundL() function |
|
95 @SYMTestPriority High |
|
96 @SYMTestActions Tests for KErrArgument,when TSoundCategory is passed with out being set as a tone |
|
97 @SYMTestExpectedResults Test must not fail |
|
98 @SYMREQ REQ0000 |
|
99 */ |
|
100 LOCAL_C void TestSetSounds5L() |
|
101 { |
|
102 // Testing SetSoundL. |
|
103 // Should leave with KErrArgument when TSoundCategory of sndInfo |
|
104 // parameter is passed with out being set either as a tone, a file |
|
105 // or a sequence. |
|
106 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1286 ")); |
|
107 TBaSystemSoundInfo sndInfo; |
|
108 TRAPD(err,BaSystemSound::SetSoundL(TheFs,sndInfo)); |
|
109 TEST2(err, err==KErrArgument); |
|
110 } |
|
111 |
|
112 /** |
|
113 @SYMTestCaseID SYSLIB-BAFL-CT-3395 |
|
114 @SYMTestCaseDesc Tests for BaSystemSound::SetSound() function |
|
115 @SYMTestPriority High |
|
116 @SYMTestActions Set sounds of different types: file, tone and seq |
|
117 @SYMTestExpectedResults Test must not fail |
|
118 @SYMDEF DEF095280 |
|
119 */ |
|
120 LOCAL_C void TestSetSoundsL() |
|
121 { |
|
122 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3395 ")); |
|
123 // split into stupidly small chunks to avoid _chkstk errors |
|
124 |
|
125 //set sounds |
|
126 TestSetSounds1L(); |
|
127 TestSetSounds2L(); |
|
128 TestSetSounds3L(); |
|
129 TestSetSounds4L(); |
|
130 TestSetSounds5L(); |
|
131 } |
|
132 |
|
133 /** |
|
134 @SYMTestCaseID SYSLIB-BAFL-CT-1287 |
|
135 @SYMTestCaseDesc Tests for BaSystemSound::GetSound() function |
|
136 @SYMTestPriority High |
|
137 @SYMTestActions Attempt for getting back sounds |
|
138 @SYMTestExpectedResults Test must not fail |
|
139 @SYMDEF DEF095280 |
|
140 */ |
|
141 LOCAL_C void TestGetSoundsL() |
|
142 { |
|
143 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1287 ")); |
|
144 TBaSystemSoundInfo info; |
|
145 |
|
146 //get sounds |
|
147 //should return warble |
|
148 TBaSystemSoundType sndType(KSystemSoundRingUID,KRing1); |
|
149 TInt e=BaSystemSound::GetSound(TheFs,sndType,info); |
|
150 TEST2(e, e==KErrNone); |
|
151 test(info.FileName()==KSndNameWarble); |
|
152 //should return mozart |
|
153 sndType=TBaSystemSoundType(KSystemSoundRingUID,KRing2); |
|
154 e=BaSystemSound::GetSound(TheFs,sndType,info); |
|
155 TEST2(e, e==KErrNone); |
|
156 test(info.FileName()==KSndNameMozart); |
|
157 //should return bach |
|
158 sndType=TBaSystemSoundType(KSystemSoundAlarmUID,KAlarm1); |
|
159 e=BaSystemSound::GetSound(TheFs,sndType,info); |
|
160 TEST2(e, e==KErrNone); |
|
161 test(info.FileName()==KSndNameBach); |
|
162 test(info.iVolume=100); |
|
163 TBaSoundPriorityDecoder priorityDecode(info.iPriority); |
|
164 test(priorityDecode.Priority()==16); |
|
165 test(priorityDecode.PriorityPreference()==EMdaPriorityPreferenceTimeAndQuality); |
|
166 //should rturn vivaldi |
|
167 sndType=TBaSystemSoundType(KSystemSoundAlarmUID,KAlarm2); |
|
168 e=BaSystemSound::GetSound(TheFs,sndType,info); |
|
169 TEST2(e, e==KErrNone); |
|
170 test(info.FileName()==KSndNameVivaldi); |
|
171 test(info.iVolume=83); |
|
172 priorityDecode=TBaSoundPriorityDecoder(info.iPriority); |
|
173 test(priorityDecode.Priority()==-100); |
|
174 test(priorityDecode.PriorityPreference()==(TMdaPriorityPreference(0xFF030001))); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------- |
|
178 // OomTest |
|
179 // |
|
180 // Function to convert a test into an OOM test |
|
181 |
|
182 /** |
|
183 @SYMTestCaseID SYSLIB-BAFL-CT-1288 |
|
184 @SYMTestCaseDesc Out of memory tests |
|
185 @SYMTestPriority High |
|
186 @SYMTestActions Turns a basic test function into OOM test. |
|
187 @SYMTestExpectedResults Test must not fail |
|
188 @SYMDEF DEF095280 |
|
189 @SYMREQ REQ0000 |
|
190 */ |
|
191 LOCAL_C void OomTest( void (*testFuncL)() ) |
|
192 { |
|
193 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1288 ")); |
|
194 TInt error; |
|
195 TestingOOM = ETrue; |
|
196 TInt count = 0; |
|
197 |
|
198 do |
|
199 { |
|
200 User::__DbgMarkStart( RHeap::EUser ); |
|
201 |
|
202 // find out the number of open handles |
|
203 TInt startProcessHandleCount; |
|
204 TInt startThreadHandleCount; |
|
205 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
206 |
|
207 User::__DbgSetAllocFail( RHeap::EUser, RHeap::EFailNext, ++count ); |
|
208 |
|
209 TRAP( error, (testFuncL)() ); |
|
210 |
|
211 User::__DbgSetAllocFail( RHeap::EUser, RHeap::ENone, 1 ); |
|
212 |
|
213 // check that no handles have leaked |
|
214 TInt endProcessHandleCount; |
|
215 TInt endThreadHandleCount; |
|
216 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
217 |
|
218 test(startProcessHandleCount == endProcessHandleCount); |
|
219 test(startThreadHandleCount == endThreadHandleCount); |
|
220 |
|
221 User::__DbgMarkEnd( RHeap::EUser, 0 ); |
|
222 } while( error == KErrNoMemory ); |
|
223 |
|
224 TestingOOM = EFalse; |
|
225 |
|
226 _LIT( KTestFailed, "Out of memory test failure on iteration %d\n" ); |
|
227 __ASSERT_ALWAYS( error == KErrNone, test.Panic( error, KTestFailed, count ) ); |
|
228 |
|
229 test.Printf( _L( "Out of memory tests succeeded at heap failure rate of %i\n" ), count ); |
|
230 } |
|
231 |
|
232 /** |
|
233 @SYMTestCaseID SYSLIB-BAFL-CT-3397 |
|
234 @SYMTestCaseDesc When a client requests a non-existing sound |
|
235 which is in one of the system category, |
|
236 BaSystemSound returns the default sound for |
|
237 that system category. |
|
238 @SYMTestPriority High |
|
239 @SYMTestActions With the sound table empty, get sound in the |
|
240 alarm, message and ring categories. |
|
241 @SYMTestExpectedResults The default sound for the category is returned. |
|
242 @SYMDEF DEF095280 |
|
243 */ |
|
244 LOCAL_C void GetNonExistingSoundL() |
|
245 { |
|
246 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3397 ")); |
|
247 TBaSystemSoundInfo info; |
|
248 TInt ret(KErrNone); |
|
249 |
|
250 //get sound empty file |
|
251 TBaSystemSoundType sndType(KSystemSoundAlarmUID,KAlarm1); |
|
252 ret = BaSystemSound::GetSound(TheFs,sndType,info); |
|
253 TEST2(ret, ret==KErrNotFound); |
|
254 _LIT(KSystemSoundDefaultAlarm,"z:\\system\\SystemSounds\\alarm.wav"); |
|
255 test(info.FileName() == KSystemSoundDefaultAlarm); |
|
256 |
|
257 sndType.iMajor = KSystemSoundMessageUID; |
|
258 sndType.iMinor = KMessage1; |
|
259 ret = BaSystemSound::GetSound(TheFs,sndType,info); |
|
260 TEST2(ret, ret==KErrNotFound); |
|
261 _LIT(KSystemSoundDefaultMessage,"z:\\system\\SystemSounds\\message.wav"); |
|
262 test(info.FileName() == KSystemSoundDefaultMessage); |
|
263 |
|
264 sndType.iMajor = KSystemSoundRingUID; |
|
265 sndType.iMinor = KRing1; |
|
266 ret = BaSystemSound::GetSound(TheFs,sndType,info); |
|
267 TEST2(ret, ret==KErrNotFound); |
|
268 _LIT(KSystemSoundDefaultRing,"z:\\system\\SystemSounds\\ring.wav"); |
|
269 test(info.FileName() == KSystemSoundDefaultRing); |
|
270 } |
|
271 |
|
272 /** |
|
273 @SYMTestCaseID SYSLIB-BAFL-CT-3396 |
|
274 @SYMTestCaseDesc Test CBaSystemSoundArray APIs. |
|
275 @SYMTestPriority High |
|
276 @SYMTestActions Use CBaSystemSoundArray to retrieve an entire |
|
277 sound category and step through each sound in |
|
278 the array. |
|
279 @SYMTestExpectedResults Test must not fail |
|
280 @SYMDEF DEF095280 |
|
281 */ |
|
282 LOCAL_C void GetSoundArrayL() |
|
283 { |
|
284 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3396 ")); |
|
285 CBaSystemSoundArray* sa= CBaSystemSoundArray::NewLC(); |
|
286 sa->RestoreL(TheFs,KSystemSoundRingUID); |
|
287 |
|
288 TInt count = sa->Count(); |
|
289 test(count==2); |
|
290 TBaSystemSoundInfo i0 = sa->At(0); |
|
291 test(i0.iType.iMinor==KRing1); |
|
292 test(i0.FileName()==KSndNameWarble); |
|
293 TBaSystemSoundInfo i1 = sa->At(1); |
|
294 test(i1.iType.iMinor==KRing2); |
|
295 test(i1.FileName()==KSndNameMozart); |
|
296 |
|
297 CleanupStack::PopAndDestroy(); // sa |
|
298 } |
|
299 |
|
300 /** |
|
301 @SYMTestCaseID SYSLIB-BAFL-CT-0441 |
|
302 @SYMTestCaseDesc Tests for the functionality of TBaSystemSoundInfo |
|
303 @SYMTestPriority High |
|
304 @SYMTestActions Calls up BaSystemSound test functions |
|
305 @SYMTestExpectedResults Test must not fail |
|
306 @SYMREQ REQ0000 |
|
307 */ |
|
308 void DoTestsL() |
|
309 { |
|
310 test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0441 ")); |
|
311 //delete all sounds |
|
312 ClearSoundTableL(); |
|
313 |
|
314 test.Next(_L("Get non-existing sound")); |
|
315 GetNonExistingSoundL(); |
|
316 |
|
317 test.Next(_L("Setting sounds")); |
|
318 TestSetSoundsL(); |
|
319 |
|
320 test.Next(_L("Getting back sounds\n")); |
|
321 TestGetSoundsL(); |
|
322 |
|
323 test.Next(_L("CBaSystemSoundArray access")); |
|
324 GetSoundArrayL(); |
|
325 |
|
326 //delete all sounds |
|
327 ClearSoundTableL(); |
|
328 |
|
329 // OOM test |
|
330 test.Next(_L("OOM Test get non-existing sound")); |
|
331 OomTest(GetNonExistingSoundL); |
|
332 |
|
333 test.Next(_L("OOM Test Setting sounds")); |
|
334 OomTest(TestSetSoundsL); |
|
335 |
|
336 test.Next(_L("OOM Test Getting back sounds")); |
|
337 OomTest(TestGetSoundsL); |
|
338 |
|
339 test.Next(_L("OOM Test CBaSystemSoundArray access")); |
|
340 OomTest(GetSoundArrayL); |
|
341 |
|
342 // cleanup |
|
343 ClearSoundTableL(); |
|
344 } |
|
345 |
|
346 GLDEF_C TInt E32Main() |
|
347 { |
|
348 __UHEAP_MARK; |
|
349 CActiveScheduler::Install(new CActiveScheduler); |
|
350 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
351 test.Title(); |
|
352 // test.RunManual(); |
|
353 test.Start(_L("Testing system sounds")); |
|
354 TRAPD(err,DoTestsL()); |
|
355 test(err==KErrNone); |
|
356 test.End(); |
|
357 test.Close(); |
|
358 delete cleanup; |
|
359 delete CActiveScheduler::Current(); |
|
360 __UHEAP_MARKEND; |
|
361 return(0); |
|
362 } |