|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <bautils.h> |
|
18 #include <barsread2.h> |
|
19 #include <barsc2.h> |
|
20 #include <baspi.h> |
|
21 |
|
22 LOCAL_D RTest TheTest(_L("T_SPI")); |
|
23 LOCAL_D RFs TheFs; |
|
24 |
|
25 //Test files |
|
26 _LIT(KTestDirectoryPath,"z:\\system\\data\\"); |
|
27 _LIT(KRscExtension,".rsc"); |
|
28 _LIT(KXipSpiFile,"z:\\system\\data\\Spi_ECom.SPI"); |
|
29 _LIT(KNonXipSpiFile, "c:\\system\\data\\Spi_ECom.SPI"); |
|
30 _LIT(KXipSpi_EcomRsc1,"z:\\system\\data\\Spi_EcomRsc1.rsc"); |
|
31 _LIT(KXipSpi_EcomRsc2,"z:\\system\\data\\Spi_EcomRsc2.rsc"); |
|
32 _LIT(KXipSpi_EcomRsc3,"z:\\system\\data\\Spi_EcomRsc3.rsc"); |
|
33 _LIT(KNonXipSpi_EcomRsc1,"c:\\system\\data\\Spi_EcomRsc1.rsc"); |
|
34 _LIT(KNonXipSpi_EcomRsc2,"c:\\system\\data\\Spi_EcomRsc2.rsc"); |
|
35 _LIT(KNonXipSpi_EcomRsc3,"c:\\system\\data\\Spi_EcomRsc3.rsc"); |
|
36 |
|
37 //----------------------UTILITY FUNCTIONS---------------------------------- |
|
38 LOCAL_C void CopyFileL(const TDesC& aFrom,const TDesC& aTo) |
|
39 { |
|
40 TheFs.Delete(aTo); |
|
41 CFileMan* man=CFileMan::NewL(TheFs); |
|
42 TInt r=man->Copy(aFrom,aTo, CFileMan::ERecurse); |
|
43 delete man; |
|
44 User::LeaveIfError(r); |
|
45 User::LeaveIfError(TheFs.SetAtt(aTo,0,KEntryAttReadOnly)); // clear RO |
|
46 } |
|
47 |
|
48 LOCAL_C void DeleteFile(const TDesC& aFileName) |
|
49 { |
|
50 // make sure the file is read/write |
|
51 TInt err = TheFs.SetAtt(aFileName, 0, KEntryAttReadOnly); |
|
52 if(err != KErrNone) |
|
53 { |
|
54 RDebug::Print(_L("error changing attributes file = %d"),err); |
|
55 } |
|
56 // delete the file |
|
57 err = BaflUtils::DeleteFile(TheFs, aFileName); |
|
58 if(err != KErrNone) |
|
59 { |
|
60 RDebug::Print(_L("error deleting file = %d"),err); |
|
61 } |
|
62 } |
|
63 |
|
64 LOCAL_C TInt FileSizeL(const TDesC& aFileName) |
|
65 { |
|
66 RFile file; |
|
67 CleanupClosePushL(file); |
|
68 User::LeaveIfError(file.Open(TheFs, aFileName, EFileRead)); |
|
69 TInt size = 0; |
|
70 User::LeaveIfError(file.Size(size)); |
|
71 CleanupStack::PopAndDestroy(&file); |
|
72 return size; |
|
73 } |
|
74 |
|
75 LOCAL_C void DeleteTestFile() |
|
76 { |
|
77 DeleteFile(KNonXipSpiFile); |
|
78 DeleteFile(KNonXipSpi_EcomRsc1); |
|
79 DeleteFile(KNonXipSpi_EcomRsc2); |
|
80 DeleteFile(KNonXipSpi_EcomRsc3); |
|
81 } |
|
82 |
|
83 //Test macroses and functions |
|
84 LOCAL_C void Check(TInt aValue, TInt aLine) |
|
85 { |
|
86 if(!aValue) |
|
87 { |
|
88 ::DeleteTestFile(); |
|
89 TheTest(EFalse, aLine); |
|
90 } |
|
91 } |
|
92 |
|
93 #define TEST(arg) ::Check((arg), __LINE__) |
|
94 |
|
95 //---------------------TEST CASE for RResoureArchive------------------ |
|
96 // Tests for RResourceArchive |
|
97 /* |
|
98 (1) Test Loading SPI file through RResourceArchive and retrieving the first rsc block |
|
99 from XIP media(e.g NOR flash) in basic and OOM environment. |
|
100 (2) Test Loading SPI file through RResourceArchive and retrieving the first rsc block |
|
101 from NON-XIP media(e.g NAND flash) in basic and OOM environment. |
|
102 (3) Test the Reset() functionality to ensure proper reset functionality by comparing the |
|
103 content of the rsc file |
|
104 (4) Test Loading some test SPI(with 2-3 random rsc file), interpret the content of rsc file |
|
105 through RResourceReader and compare it with the results when opening each rsc file |
|
106 separately. |
|
107 (5) Test Loading some non-spi file using RResourceArchive expecting a KErrCorrupt to be |
|
108 returned |
|
109 */ |
|
110 class RStaticPluginInfoTest |
|
111 { |
|
112 public: |
|
113 static void TestCase1L(); |
|
114 static void TestCase2L(); |
|
115 static void TestCase3L(); |
|
116 static void TestCase4L(); |
|
117 static void TestCase5L(); |
|
118 private: |
|
119 static void TestOpenNextL(const TDesC& aFileName); |
|
120 static void TestComparisonL(const TDesC& aFileName); |
|
121 }; |
|
122 |
|
123 void RStaticPluginInfoTest::TestCase1L() |
|
124 { |
|
125 TheTest.Next(_L("Test case 1 Loading/Reading SPI file from XIP media\n")); |
|
126 TestOpenNextL(KXipSpiFile); |
|
127 } |
|
128 |
|
129 void RStaticPluginInfoTest::TestCase2L() |
|
130 { |
|
131 TheTest.Next(_L("Test case 2 Loading/Reading SPI file from Non-XIP media\n")); |
|
132 TestOpenNextL(KNonXipSpiFile); |
|
133 } |
|
134 |
|
135 void RStaticPluginInfoTest::TestCase3L() |
|
136 { |
|
137 __UHEAP_MARK; |
|
138 TheTest.Next(_L("Test case 3 Testing functionality of the Reset() function\n")); |
|
139 RResourceArchive testArchiveIter; |
|
140 testArchiveIter.OpenL(TheFs,KXipSpiFile); |
|
141 |
|
142 RResourceReader theReader1; |
|
143 RResourceReader theReader3; |
|
144 |
|
145 HBufC* rscName1=NULL; |
|
146 HBufC* rscName2=NULL; |
|
147 HBufC* rscName3=NULL; |
|
148 |
|
149 CResourceFile* rscArchive1=testArchiveIter.NextL(rscName1); |
|
150 TEST(rscArchive1!=NULL); |
|
151 |
|
152 CResourceFile* rscArchive2=testArchiveIter.NextL(rscName2); |
|
153 TEST(rscArchive2!=NULL); |
|
154 |
|
155 testArchiveIter.Reset(); |
|
156 |
|
157 CResourceFile* rscArchive3=testArchiveIter.NextL(rscName3); |
|
158 TEST(rscArchive3!=NULL); |
|
159 |
|
160 //Check to ensure that rscArchive3 content is the same as rscArchive1 |
|
161 theReader1.OpenLC(rscArchive1,1); |
|
162 theReader3.OpenLC(rscArchive3,1); |
|
163 TEST(rscArchive1->UidType()==rscArchive3->UidType()); |
|
164 TEST(rscName1->CompareF(rscName3->Des())==0); |
|
165 TEST(theReader1.ReadInt32L()==theReader3.ReadInt32L()); |
|
166 |
|
167 delete rscName1; |
|
168 delete rscName2; |
|
169 delete rscName3; |
|
170 delete rscArchive1; |
|
171 delete rscArchive2; |
|
172 delete rscArchive3; |
|
173 |
|
174 testArchiveIter.Close(); |
|
175 |
|
176 CleanupStack::PopAndDestroy(&theReader3); |
|
177 CleanupStack::PopAndDestroy(&theReader1); |
|
178 __UHEAP_MARKEND; |
|
179 } |
|
180 |
|
181 void RStaticPluginInfoTest::TestCase4L() |
|
182 { |
|
183 TheTest.Next(_L("Test case 4 Testing comparison of spi and rsc read CResourceFiles\n")); |
|
184 TestComparisonL(KXipSpiFile); |
|
185 TestComparisonL(KNonXipSpiFile); |
|
186 } |
|
187 |
|
188 void RStaticPluginInfoTest::TestCase5L() |
|
189 { |
|
190 TheTest.Next(_L("Test case 5 Testing opening a non-spi file\n")); |
|
191 __UHEAP_MARK; |
|
192 RResourceArchive testArchiveIter; |
|
193 TRAPD(err,testArchiveIter.OpenL(TheFs,KXipSpi_EcomRsc1)); |
|
194 TEST(err==KErrCorrupt); |
|
195 |
|
196 __UHEAP_MARKEND; |
|
197 } |
|
198 |
|
199 void RStaticPluginInfoTest::TestComparisonL(const TDesC& aFileName) |
|
200 { |
|
201 __UHEAP_MARK; |
|
202 RResourceArchive testArchiveIter; |
|
203 testArchiveIter.OpenL(TheFs,aFileName); |
|
204 TUid spiType=testArchiveIter.Type(); |
|
205 TEST(spiType.iUid=0x10205C2C); |
|
206 |
|
207 CResourceFile* spiRscArchive=NULL; |
|
208 HBufC* rscName=NULL; |
|
209 spiRscArchive=testArchiveIter.NextL(rscName); |
|
210 while (spiRscArchive) |
|
211 { |
|
212 TFileName fullRscName; |
|
213 fullRscName.Append(KTestDirectoryPath); |
|
214 fullRscName.Append(rscName->Des()); |
|
215 fullRscName.Append(KRscExtension); |
|
216 TInt rscFileSize=FileSizeL(fullRscName); |
|
217 |
|
218 //Creating a CResourceFile by opening the individual rsc file |
|
219 CResourceFile* existingRscArchive=CResourceFile::NewL(TheFs,fullRscName,0,rscFileSize); |
|
220 //Now perform general comparison |
|
221 TEST(spiRscArchive->UidType()==existingRscArchive->UidType()); |
|
222 TEST(spiRscArchive->Offset()==existingRscArchive->Offset()); |
|
223 //Now perform interpreting and comparing the rsc content |
|
224 RResourceReader rscReader; |
|
225 RResourceReader spiRscReader; |
|
226 spiRscReader.OpenLC(spiRscArchive,1); |
|
227 rscReader.OpenLC(existingRscArchive,1); |
|
228 //Now perform all the read results and comparison between the two CResourceFile |
|
229 const TUid KUidEComResourceFormatV2 = {0x101FB0B9}; |
|
230 TInt resourceFormatVersion=0; |
|
231 resourceFormatVersion+=0; |
|
232 //Comparison of Rsc uid |
|
233 TUid rscUid = {rscReader.ReadInt32L()}; |
|
234 TEST(rscUid.iUid==spiRscReader.ReadInt32L()); |
|
235 if(rscUid==KUidEComResourceFormatV2) |
|
236 { |
|
237 resourceFormatVersion = 2; |
|
238 TUid dllUid={rscReader.ReadInt32L()}; |
|
239 TEST(dllUid.iUid==spiRscReader.ReadInt32L()); |
|
240 } |
|
241 //Comparison of number of interfaces |
|
242 TInt numberOfInterface=rscReader.ReadInt16L(); |
|
243 TEST(numberOfInterface==spiRscReader.ReadInt16L()); |
|
244 //Comparison of the each interface uid and implementations under this interface |
|
245 for(TInt iFace = 0; iFace < numberOfInterface; ++iFace) |
|
246 { |
|
247 //Comparison of each interface Uid |
|
248 const TUid interfaceUid = {rscReader.ReadInt32L()}; |
|
249 TEST(interfaceUid.iUid==spiRscReader.ReadInt32L()); |
|
250 //Comparison of number of implementations under this interface |
|
251 const TInt numImplementations = rscReader.ReadInt16L(); |
|
252 TEST(numImplementations==spiRscReader.ReadInt16L()); |
|
253 for(TInt impl = 0; impl < numImplementations; ++impl) |
|
254 { |
|
255 //Comparison of some of the implementation content |
|
256 const TUid impUid = {rscReader.ReadInt32L()}; |
|
257 TEST(impUid.iUid==spiRscReader.ReadInt32L()); |
|
258 const TInt version = rscReader.ReadInt8L(); |
|
259 TEST(version==spiRscReader.ReadInt8L()); |
|
260 } |
|
261 } |
|
262 delete existingRscArchive; |
|
263 existingRscArchive=NULL; |
|
264 delete spiRscArchive; |
|
265 spiRscArchive=NULL; |
|
266 delete rscName; |
|
267 rscName=NULL; |
|
268 CleanupStack::PopAndDestroy(&rscReader); |
|
269 CleanupStack::PopAndDestroy(&spiRscReader); |
|
270 spiRscArchive=testArchiveIter.NextL(rscName); |
|
271 } |
|
272 testArchiveIter.Close(); |
|
273 |
|
274 __UHEAP_MARKEND; |
|
275 } |
|
276 |
|
277 void RStaticPluginInfoTest::TestOpenNextL(const TDesC& aFileName) |
|
278 { |
|
279 //---------Basic testing------------------------------- |
|
280 __UHEAP_MARK; |
|
281 |
|
282 RResourceArchive testArchiveIter; |
|
283 testArchiveIter.OpenL(TheFs,aFileName); |
|
284 TUid spiType=testArchiveIter.Type(); |
|
285 TEST(spiType.iUid==0x10205C2C); |
|
286 HBufC* rscName=NULL; |
|
287 CResourceFile* rscArchive=testArchiveIter.NextL(rscName); |
|
288 |
|
289 delete rscArchive; |
|
290 rscArchive=NULL; |
|
291 delete rscName; |
|
292 rscName=NULL; |
|
293 testArchiveIter.Close(); |
|
294 |
|
295 __UHEAP_MARKEND; |
|
296 |
|
297 //-----------OOM testing-------------------------------- |
|
298 TInt err; |
|
299 TInt tryCount = 0; |
|
300 tryCount=tryCount; |
|
301 RResourceArchive testArchiveIter1; |
|
302 testArchiveIter1.OpenL(TheFs,aFileName); |
|
303 do |
|
304 { |
|
305 __UHEAP_MARK; |
|
306 // find out the number of open handles |
|
307 TInt startProcessHandleCount; |
|
308 TInt startThreadHandleCount; |
|
309 RThread().HandleCount(startProcessHandleCount, startThreadHandleCount); |
|
310 __UHEAP_SETFAIL(RHeap::EDeterministic, ++tryCount); |
|
311 TRAP(err,rscArchive=testArchiveIter1.NextL(rscName)); |
|
312 __UHEAP_SETFAIL(RHeap::ENone, 0); |
|
313 |
|
314 delete rscArchive; |
|
315 rscArchive=NULL; |
|
316 |
|
317 delete rscName; |
|
318 rscName=NULL; |
|
319 |
|
320 // check that no handles have leaked |
|
321 TInt endProcessHandleCount; |
|
322 TInt endThreadHandleCount; |
|
323 RThread().HandleCount(endProcessHandleCount, endThreadHandleCount); |
|
324 |
|
325 TEST(startProcessHandleCount == endProcessHandleCount); |
|
326 TEST(startThreadHandleCount == endThreadHandleCount); |
|
327 |
|
328 __UHEAP_MARKEND; |
|
329 } while(err == KErrNoMemory); |
|
330 testArchiveIter1.Close(); |
|
331 } |
|
332 |
|
333 /** |
|
334 @SYMTestCaseID SYSLIB-BAFL-CT-0094 |
|
335 @SYMTestCaseDesc Testing for the functionality of RResourceArchive |
|
336 @SYMTestPriority High |
|
337 @SYMTestActions Test loading and reading Spi file through Xip and Non-Xip media |
|
338 Test interpreting and comparing rsc content through read from |
|
339 spi file and from individual rsc file. |
|
340 Test all exported functionality of this class in general and |
|
341 OOM conditions. |
|
342 @SYMTestExpectedResults The test must not fail. |
|
343 @SYMPREQ 806 Eliminate scanning for plugins on startup |
|
344 */ |
|
345 LOCAL_C void DoAllTestsL() |
|
346 { |
|
347 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0094 ")); |
|
348 CleanupClosePushL(TheFs); |
|
349 User::LeaveIfError(TheFs.Connect()); |
|
350 |
|
351 TheTest.Printf(_L("Copying SPI files to RAM\r\n")); |
|
352 //Copying test spi file and individual rsc files that are included inside spi |
|
353 CopyFileL(KXipSpiFile,KNonXipSpiFile); |
|
354 CopyFileL(KXipSpi_EcomRsc1,KNonXipSpi_EcomRsc1); |
|
355 CopyFileL(KXipSpi_EcomRsc2,KNonXipSpi_EcomRsc2); |
|
356 CopyFileL(KXipSpi_EcomRsc3,KNonXipSpi_EcomRsc3); |
|
357 |
|
358 //Start running all the TestCase |
|
359 RStaticPluginInfoTest::TestCase1L(); |
|
360 RStaticPluginInfoTest::TestCase2L(); |
|
361 RStaticPluginInfoTest::TestCase3L(); |
|
362 RStaticPluginInfoTest::TestCase4L(); |
|
363 RStaticPluginInfoTest::TestCase5L(); |
|
364 |
|
365 //Clearing all the test files we have copied to C |
|
366 DeleteTestFile(); |
|
367 |
|
368 CleanupStack::PopAndDestroy(1, &TheFs); |
|
369 } |
|
370 |
|
371 GLDEF_C TInt E32Main() |
|
372 { |
|
373 __UHEAP_MARK; |
|
374 CTrapCleanup *cleanup=CTrapCleanup::New(); |
|
375 TheTest.Title(); |
|
376 TheTest.Start(_L("Testing RResourceArchive")); |
|
377 TRAPD(err,DoAllTestsL()); |
|
378 TheTest.Printf(_L("Error code is %d\n"),err); |
|
379 TEST(err==KErrNone); |
|
380 TheTest.End(); |
|
381 TheTest.Close(); |
|
382 delete cleanup; |
|
383 __UHEAP_MARKEND; |
|
384 return(0); |
|
385 } |
|
386 |