|
1 // Copyright (c) 2006-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 // Tests for CBaNamedPlugins class, which contains CParameters class |
|
15 // |
|
16 // |
|
17 |
|
18 #include <banamedplugins.h> |
|
19 #include <e32test.h> |
|
20 #include <basched.h> |
|
21 #include <f32file.h> |
|
22 #include <baflpan.h> |
|
23 |
|
24 RTest TheTest(_L("T_NamedPlugins")); |
|
25 RFs TheFs; |
|
26 |
|
27 //Test macros and functions |
|
28 |
|
29 LOCAL_C void Check(TInt aValue, TInt aLine) |
|
30 { |
|
31 if(!aValue) |
|
32 { |
|
33 TheTest(EFalse, aLine); |
|
34 } |
|
35 } |
|
36 |
|
37 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
38 { |
|
39 if(aValue != aExpected) |
|
40 { |
|
41 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
42 TheTest(EFalse, aLine); |
|
43 } |
|
44 } |
|
45 |
|
46 #define TEST(arg) Check((arg), __LINE__) |
|
47 #define TEST2(aValue, aExpected) Check(aValue, aExpected, __LINE__) |
|
48 |
|
49 |
|
50 TUid KUid1 = {0xE1A01753}; |
|
51 TUid KUid2 = {0xE1B01753}; |
|
52 |
|
53 _LIT(KRscFileName1, "\\resource\\plugins\\E1A01753.RSC"); |
|
54 _LIT(KRscFileName2, "\\resource\\plugins\\E1B01753.RSC"); |
|
55 _LIT(KIdentifier, "plugin"); |
|
56 _LIT(KBadIdentifier, "plugni"); |
|
57 _LIT(KMainPath, "\\system\\data\\"); |
|
58 _LIT(KLitWildCard, "*.RSC"); |
|
59 _LIT(KTextForNone, "NoPlugin"); |
|
60 |
|
61 class CImplementation: public CBaNamedPlugins::MFallBackName |
|
62 { |
|
63 public: |
|
64 |
|
65 HBufC* FallBackNameL(const TDesC& aFullResourceFileName) const; |
|
66 }; |
|
67 |
|
68 HBufC* CImplementation::FallBackNameL(const TDesC& aFullResourceFileName) const |
|
69 { |
|
70 return aFullResourceFileName.AllocL(); |
|
71 } |
|
72 |
|
73 TBool TestAlgorithmToCompareNames(const TDesC& aName1, const TDesC& aName2) |
|
74 { |
|
75 return( aName1.CompareC(aName2) == 0); // Function is supposed to return 1, when CompareC returns 0 |
|
76 } |
|
77 |
|
78 /* |
|
79 @SYMTestCaseID SYSLIB-BAFL-CT-1756 |
|
80 @SYMTestCaseDesc CBaNamedPlugins class test |
|
81 Tests for CBaNamedPlugins::IndexOfIdentifier(), CBaNamedPlugins::IndexOfUid(), CBaNamedPlugins::MdcaPoint(), CBaNamedPlugins::IdentifierAtIndex(), CBaNamedPlugins::UidAtIndex(),CBaNamedPlugins::MdcaCount() functions |
|
82 @SYMTestPriority Medium |
|
83 @SYMTestActions CBaNamedPlugins object is populated with resource file names and checking for identifier and Uid |
|
84 @SYMTestExpectedResults Test must not fail |
|
85 @SYMREQ REQ0000 |
|
86 */ |
|
87 |
|
88 void DoTests1() |
|
89 { |
|
90 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1756 Testing DoTests1... ")); |
|
91 TBuf<64> buf; |
|
92 |
|
93 CBaNamedPlugins* namedPlugins; |
|
94 RArray<CBaNamedPlugins::TResourceFile> arrayOfResourceFiles; |
|
95 CleanupClosePushL(arrayOfResourceFiles); |
|
96 |
|
97 buf = KRscFileName1; |
|
98 |
|
99 CBaNamedPlugins::TResourceFile resourceFile1; |
|
100 resourceFile1.iFullFileName = buf.AllocLC(); |
|
101 resourceFile1.iIdentifier = NULL; |
|
102 resourceFile1.iUid = KUid1; |
|
103 resourceFile1.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; |
|
104 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile1)); |
|
105 CleanupStack::Pop(resourceFile1.iFullFileName); |
|
106 |
|
107 buf = KRscFileName2; |
|
108 |
|
109 CBaNamedPlugins::TResourceFile resourceFile2; |
|
110 resourceFile2.iFullFileName = buf.AllocLC(); |
|
111 buf = KIdentifier; |
|
112 resourceFile2.iIdentifier = buf.AllocLC(); |
|
113 resourceFile2.iUid = KUid2; |
|
114 resourceFile2.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; |
|
115 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile2)); |
|
116 CleanupStack::Pop(resourceFile2.iIdentifier); |
|
117 |
|
118 CleanupStack::Pop(resourceFile2.iFullFileName); |
|
119 |
|
120 CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewLC(TheFs, arrayOfResourceFiles.Array()); |
|
121 HBufC* textForNone=KTextForNone().AllocL(); |
|
122 parameters->SetTextForNone(textForNone,CBaNamedPlugins::EArrayPositionLast); |
|
123 |
|
124 // This call to SetTextForNoneL will delete textForNone |
|
125 parameters->SetTextForNoneL(KTextForNone,CBaNamedPlugins::EArrayPositionLast); |
|
126 |
|
127 namedPlugins = CBaNamedPlugins::NewL(*parameters); |
|
128 |
|
129 CBaNamedPlugins::TEquivalentIdentifiers eqIdent = TestAlgorithmToCompareNames; |
|
130 TInt i = (*namedPlugins).IndexOfIdentifier(KIdentifier,eqIdent); |
|
131 // With the sorting algorithm and resource files benig used KIdentifier is at index 0 |
|
132 TEST2(i,0); |
|
133 i = (*namedPlugins).IndexOfIdentifier(KBadIdentifier,eqIdent); |
|
134 TEST2(i,KErrNotFound); |
|
135 |
|
136 TInt index = namedPlugins->IndexOfUid(KUid1); |
|
137 TEST(index>=0); |
|
138 TPtrC name; |
|
139 if( index >= 0 ) |
|
140 { |
|
141 name.Set((*namedPlugins).MdcaPoint(index)); |
|
142 } |
|
143 index = (namedPlugins)->IndexOfUid(TUid::Uid(0x123)); |
|
144 TEST2(index,-1); |
|
145 |
|
146 TEST((*namedPlugins).IdentifierAtIndex(1)!= &buf); |
|
147 TEST((*namedPlugins).UidAtIndex(0)==KUid2); |
|
148 TEST((*namedPlugins).UidAtIndex(1)==KUid1); |
|
149 |
|
150 TInt count = (*namedPlugins).MdcaCount(); |
|
151 TEST2(count,3); |
|
152 |
|
153 count = arrayOfResourceFiles.Count(); |
|
154 for(i = 0; i < count; i++ ) |
|
155 { |
|
156 const CBaNamedPlugins::TResourceFile& resourceFileData=arrayOfResourceFiles[i]; |
|
157 delete resourceFileData.iFullFileName; |
|
158 delete resourceFileData.iIdentifier; |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(2, &arrayOfResourceFiles); |
|
162 delete namedPlugins; |
|
163 |
|
164 // Test EFormatArrayOfUidNamePairs format |
|
165 buf = KRscFileName1; |
|
166 |
|
167 CleanupClosePushL(arrayOfResourceFiles); |
|
168 |
|
169 CBaNamedPlugins::TResourceFile resourceFile; |
|
170 resourceFile.iFullFileName = KRscFileName1().AllocLC(); |
|
171 resourceFile.iIdentifier = NULL; |
|
172 resourceFile.iUid = KNullUid; |
|
173 resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatArrayOfUidNamePairs; |
|
174 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); |
|
175 CleanupStack::Pop(resourceFile.iFullFileName); |
|
176 |
|
177 CBaNamedPlugins::CParameters* const parameters1 = CBaNamedPlugins::CParameters::NewL(TheFs, arrayOfResourceFiles.Array()); |
|
178 textForNone=KTextForNone().AllocL(); |
|
179 parameters1->SetTextForNone(textForNone,CBaNamedPlugins::EArrayPositionFirst); |
|
180 namedPlugins = CBaNamedPlugins::NewL(*parameters1); |
|
181 |
|
182 delete resourceFile.iFullFileName; |
|
183 |
|
184 CleanupStack::PopAndDestroy(&arrayOfResourceFiles); |
|
185 delete parameters1; |
|
186 delete namedPlugins; |
|
187 } |
|
188 |
|
189 /* |
|
190 @SYMTestCaseID SYSLIB-BAFL-CT-1757 |
|
191 @SYMTestCaseDesc CBaNamedPlugins::CParameters class test |
|
192 Tests for CParameters::SetFallBackName,CParameters::SetCompareNames,getting file names by searching file system |
|
193 @SYMTestPriority Medium |
|
194 @SYMTestActions Setting the algorithm to compare two plugin names |
|
195 @SYMTestExpectedResults Test must not fail |
|
196 @SYMREQ REQ0000 |
|
197 */ |
|
198 |
|
199 void DoTests2() |
|
200 { |
|
201 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1757 Testing DoTests2... ")); |
|
202 TBuf<64> buf; |
|
203 buf = KMainPath; |
|
204 |
|
205 CBaNamedPlugins* namedPlugins; |
|
206 RArray<CBaNamedPlugins::TResourceFile> arrayOfResourceFiles; |
|
207 CleanupClosePushL(arrayOfResourceFiles); |
|
208 |
|
209 TFindFile* findFile = new(ELeave) TFindFile(TheFs); |
|
210 CleanupStack::PushL(findFile); |
|
211 |
|
212 CDir* directory = NULL; |
|
213 |
|
214 TInt err = findFile->FindWildByDir(KLitWildCard, buf, directory); |
|
215 TInt mdcaCount=0; |
|
216 while(err==KErrNone) |
|
217 { |
|
218 CleanupStack::PushL(directory); |
|
219 for (TInt i=directory->Count()-1; i>=0; --i) |
|
220 { |
|
221 const TEntry& entry = (*directory)[i]; |
|
222 CBaNamedPlugins::TResourceFile resourceFile; |
|
223 resourceFile.iFullFileName = entry.iName.AllocLC(); |
|
224 resourceFile.iIdentifier = NULL; |
|
225 resourceFile.iUid = KNullUid; |
|
226 resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; |
|
227 ++mdcaCount; |
|
228 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); |
|
229 CleanupStack::Pop(resourceFile.iFullFileName); |
|
230 } |
|
231 CleanupStack::PopAndDestroy(); // directory |
|
232 directory = NULL; |
|
233 err=findFile->FindWild(directory); |
|
234 } |
|
235 CleanupStack::PopAndDestroy(); // findfile |
|
236 |
|
237 CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(TheFs, arrayOfResourceFiles.Array()); |
|
238 |
|
239 CBaNamedPlugins::TCompareNames compName = TestAlgorithmToCompareNames; |
|
240 (*parameters).SetCompareNames(compName); |
|
241 namedPlugins = CBaNamedPlugins::NewL(*parameters); |
|
242 |
|
243 // Test CBaNamedPlugins constructor when fall back name is set |
|
244 CImplementation obj; |
|
245 (*parameters).SetFallBackName(obj); |
|
246 delete namedPlugins; |
|
247 namedPlugins = CBaNamedPlugins::NewL(*parameters); |
|
248 |
|
249 TInt count = (*namedPlugins).MdcaCount(); |
|
250 TEST2(count,mdcaCount); |
|
251 |
|
252 count=arrayOfResourceFiles.Count(); |
|
253 for( TInt i = 0; i < count; i++ ) |
|
254 { |
|
255 const CBaNamedPlugins::TResourceFile& resourceFileData=arrayOfResourceFiles[i]; |
|
256 delete resourceFileData.iFullFileName; |
|
257 } |
|
258 CleanupStack::PopAndDestroy(&arrayOfResourceFiles); |
|
259 delete parameters; |
|
260 delete namedPlugins; |
|
261 } |
|
262 |
|
263 LOCAL_C void StartTestPanicBadArrayPositionL() |
|
264 { |
|
265 CBaNamedPlugins* namedPlugins; |
|
266 RArray<CBaNamedPlugins::TResourceFile> arrayOfResourceFiles; |
|
267 CleanupClosePushL(arrayOfResourceFiles); |
|
268 RFs fs; |
|
269 fs.Connect(); |
|
270 TBuf<64> buf; |
|
271 buf = KRscFileName2; |
|
272 |
|
273 // Test Panic |
|
274 CBaNamedPlugins::TResourceFile resourceFile; |
|
275 resourceFile.iFullFileName = buf.AllocLC(); |
|
276 resourceFile.iIdentifier = NULL; |
|
277 resourceFile.iUid = KNullUid; |
|
278 resourceFile.iFormat = CBaNamedPlugins::TResourceFile::EFormatTbuf; |
|
279 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); |
|
280 CleanupStack::Pop(resourceFile.iFullFileName); |
|
281 |
|
282 CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(fs, arrayOfResourceFiles.Array()); |
|
283 |
|
284 HBufC* textForNone=KTextForNone().AllocL(); |
|
285 parameters->SetTextForNone(textForNone,static_cast<CBaNamedPlugins::TArrayPosition>(255)); // Pick an illegal position |
|
286 |
|
287 // This should panic |
|
288 namedPlugins = CBaNamedPlugins::NewL(*parameters); |
|
289 |
|
290 delete resourceFile.iFullFileName; |
|
291 |
|
292 CleanupStack::PopAndDestroy(&arrayOfResourceFiles); |
|
293 delete parameters; |
|
294 delete namedPlugins; |
|
295 } |
|
296 |
|
297 LOCAL_C TInt TestPanicBadArrayPosition(TAny* /*aData*/) |
|
298 { |
|
299 __UHEAP_MARK; |
|
300 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
301 if(!cleanup) |
|
302 return KErrNoMemory; |
|
303 |
|
304 TRAPD(err, StartTestPanicBadArrayPositionL()); |
|
305 |
|
306 // Won't get here but add this line to get rid of ARMV5 warning |
|
307 TEST2(err, KErrNone); |
|
308 |
|
309 delete cleanup; |
|
310 __UHEAP_MARKEND; |
|
311 |
|
312 return (KErrNone); |
|
313 } |
|
314 |
|
315 LOCAL_C void StartTestPanicBadResourceFileFormatL() |
|
316 { |
|
317 CBaNamedPlugins* namedPlugins; |
|
318 RArray<CBaNamedPlugins::TResourceFile> arrayOfResourceFiles; |
|
319 CleanupClosePushL(arrayOfResourceFiles); |
|
320 RFs fs; |
|
321 fs.Connect(); |
|
322 TBuf<64> buf; |
|
323 buf = KRscFileName2; |
|
324 |
|
325 // Test Panic |
|
326 CBaNamedPlugins::TResourceFile resourceFile; |
|
327 resourceFile.iFullFileName = buf.AllocLC(); |
|
328 resourceFile.iIdentifier = NULL; |
|
329 resourceFile.iUid = KNullUid; |
|
330 resourceFile.iFormat = static_cast<CBaNamedPlugins::TResourceFile::TFormat>(255); // Pick an illegal format |
|
331 User::LeaveIfError(arrayOfResourceFiles.Append(resourceFile)); |
|
332 CleanupStack::Pop(resourceFile.iFullFileName); |
|
333 |
|
334 CBaNamedPlugins::CParameters* const parameters = CBaNamedPlugins::CParameters::NewL(fs, arrayOfResourceFiles.Array()); |
|
335 |
|
336 // This should panic |
|
337 namedPlugins = CBaNamedPlugins::NewL(*parameters); |
|
338 |
|
339 delete resourceFile.iFullFileName; |
|
340 |
|
341 CleanupStack::PopAndDestroy(&arrayOfResourceFiles); |
|
342 delete parameters; |
|
343 delete namedPlugins; |
|
344 } |
|
345 |
|
346 LOCAL_C TInt TestPanicBadResourceFileFormat(TAny* /*aData*/) |
|
347 { |
|
348 __UHEAP_MARK; |
|
349 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
350 if(!cleanup) |
|
351 return KErrNoMemory; |
|
352 |
|
353 TRAPD(err, StartTestPanicBadResourceFileFormatL()); |
|
354 |
|
355 // Won't get here but add this line to get rid of ARMV5 warning |
|
356 TEST2(err, KErrNone); |
|
357 |
|
358 delete cleanup; |
|
359 __UHEAP_MARKEND; |
|
360 |
|
361 return (KErrNone); |
|
362 } |
|
363 |
|
364 /* |
|
365 @SYMTestCaseID SYSLIB-BAFL-CT-3379 |
|
366 @SYMTestCaseDesc CBaNamedPlugins::CParameters class test |
|
367 Tests the class panic conditions |
|
368 @SYMTestPriority Medium |
|
369 @SYMTestActions Cause the class to panic by setting bad enums. |
|
370 @SYMTestExpectedResults Test must not fail |
|
371 @SYMREQ DEF101753 |
|
372 */ |
|
373 LOCAL_C void NamedPluginsPanicConditionsThread() |
|
374 { |
|
375 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-3379 Testing CBaNamedPlugins Panics... ")); |
|
376 TBool jitEnabled = User::JustInTime(); |
|
377 User::SetJustInTime(EFalse); |
|
378 |
|
379 TRequestStatus status; |
|
380 |
|
381 _LIT(KName, "NamedPlugins_Panic_Thread"); |
|
382 |
|
383 RThread thread; |
|
384 const TInt KThreadStackSize =0x2000; // 8k |
|
385 const TInt KThreadMinHeapSize =0x4000; // 16k |
|
386 const TInt KThreadMaxHeapSize =0xf000; // 60k |
|
387 |
|
388 // Test EBafPanicBadResourceFileFormat |
|
389 TInt rc = thread.Create(KName,TestPanicBadResourceFileFormat,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); |
|
390 |
|
391 TEST(rc==KErrNone); |
|
392 |
|
393 thread.Logon(status); |
|
394 thread.Resume(); |
|
395 |
|
396 User::WaitForRequest(status); |
|
397 |
|
398 // Should result in a EExitPanic exit type and an EBafPanicBadResourceFileFormat exit reason |
|
399 TEST(thread.ExitType() == EExitPanic); |
|
400 TEST(thread.ExitReason() == EBafPanicBadResourceFileFormat); |
|
401 |
|
402 CLOSE_AND_WAIT(thread); |
|
403 |
|
404 // Test EBafPanicBadArrayPosition |
|
405 rc = thread.Create(KName,TestPanicBadArrayPosition,KThreadStackSize,KThreadMinHeapSize,KThreadMaxHeapSize,NULL); |
|
406 |
|
407 TEST(rc==KErrNone); |
|
408 |
|
409 thread.Logon(status); |
|
410 thread.Resume(); |
|
411 |
|
412 User::WaitForRequest(status); |
|
413 |
|
414 // Should result in a EExitPanic exit type and an EBafPanicBadArrayPosition exit reason |
|
415 TEST(thread.ExitType() == EExitPanic); |
|
416 TEST(thread.ExitReason() == EBafPanicBadArrayPosition); |
|
417 |
|
418 thread.Close(); |
|
419 |
|
420 User::SetJustInTime(jitEnabled); |
|
421 } |
|
422 |
|
423 |
|
424 void DoTestsL() |
|
425 { |
|
426 TheTest.Next(_L("Calling the tests")); |
|
427 TheFs.Connect(); |
|
428 CleanupClosePushL(TheFs); |
|
429 |
|
430 DoTests1();//Getting the resource file names from literals |
|
431 DoTests2();//Getting the resource file names by performing a search on the file system |
|
432 NamedPluginsPanicConditionsThread(); // Test Panic condition |
|
433 |
|
434 CleanupStack::PopAndDestroy(); // TheFs |
|
435 } |
|
436 |
|
437 TInt E32Main() |
|
438 { |
|
439 __UHEAP_MARK; |
|
440 |
|
441 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
442 TheTest.Title(); |
|
443 TheTest.Start(_L("Testing CBaNamedPlugins Class")); |
|
444 TRAPD(err,DoTestsL()); |
|
445 TEST2(err,KErrNone); |
|
446 TheTest.End(); |
|
447 TheTest.Close(); |
|
448 delete cleanup; |
|
449 |
|
450 __UHEAP_MARKEND; |
|
451 return(0); |
|
452 } |