Update contrib.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Tests resource reader
23 #include <barsread2.h>
28 RTest TheTest(_L("T_RSREAD2"));
30 CResourceFile* TheResourceFile = NULL;
34 //Test macroses and functions
35 LOCAL_C void Check(TInt aValue, TInt aLine)
39 TheTest(EFalse, aLine);
42 LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
44 if(aValue != aExpected)
46 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
47 TheTest(EFalse, aLine);
50 #define TEST(arg) ::Check((arg), __LINE__)
51 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
56 //Opens aReader using RResourceReader::OpenLC(CResourceFile*, TInt)
57 static void OpenResourceReaderLC(RResourceReader& aReader, TInt aResourceId)
59 TEST(TheResourceFile != NULL);
60 aReader.OpenLC(TheResourceFile, aResourceId);
63 //Opens aReader using RResourceReader::OpenL(const TDesC8&)
64 static void OpenResourceReader2LC(RResourceReader& aReader, TInt aResourceId)
66 TEST(TheResourceFile != NULL);
67 HBufC8* rscData = TheResourceFile->AllocReadLC(aResourceId);
68 aReader.OpenL(rscData->Des());
69 CleanupStack::PopAndDestroy(rscData);
70 CleanupClosePushL(aReader);
73 //This enum describes how to obtain the resource buffer for
74 //RResourceReader objects: from the resource file or from a buffer
75 enum TRscBufAllocation
82 typedef void (*FTOpenResourceReaderLC)(RResourceReader& aReader, TInt aResourceId);
84 static FTOpenResourceReaderLC OpenResourceReaderFuncLC[ERscBufLast] =
86 &OpenResourceReaderLC,
87 &OpenResourceReader2LC
90 //Opens aReader either from a resource file ot from a resource buffer
91 static void OpenResourceReaderLC(RResourceReader& aReader, TInt aResourceId, TRscBufAllocation aRscBufAllocation)
93 OpenResourceReaderFuncLC[aRscBufAllocation](aReader, aResourceId);
99 void TestButtonL(RResourceReader& aReader);
100 void TestArrayL(RResourceReader& aReader);
101 void TestFlPtEdL(RResourceReader& aReader);
102 void TestMenuBarL(RResourceReader& aReader);
103 void TestAlignment1L(RResourceReader& aReader, TInt aIndex);
104 void TestAlignment2L(RResourceReader& aReader);
105 void TimingTestsL(TRscBufAllocation aRscBufAllocation);
107 void DumpBytes(const TAny* aPtr,TInt aLen);
108 TUint8 DumpByte(TUint aVal);
112 @SYMTestCaseID SYSLIB-BAFL-CT-1289
113 @SYMTestCaseDesc Tests for reading data from a BUTTON resource file
114 @SYMTestPriority High
115 @SYMTestActions Tests for RResourceReader::ReadInt16L(),RResourceReader::ReadUInt16L(),
116 RResourceReader::ReadTPtrCL() functions
117 @SYMTestExpectedResults Tests must not fail
120 void TRsReadTester::TestButtonL(RResourceReader& aReader)
122 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1289 Test reading BUTTON resource "));
123 TEST(aReader.ReadInt16L()==3);
124 TEST(aReader.ReadUint16L()==5);
125 TPtrC ptr=aReader.ReadTPtrCL();
126 TEST(ptr==_L("Text"));
127 ptr.Set(aReader.ReadTPtrCL());
128 TEST(ptr.Length()==0);
129 HBufC* hBuf=aReader.ReadHBufCL();
130 TEST(*hBuf==_L("Bitmap placeholder"));
135 @SYMTestCaseID SYSLIB-BAFL-CT-1290
136 @SYMTestCaseDesc Tests for RResourceReader::ReadDesCArrayL() function
137 @SYMTestPriority High
138 @SYMTestActions Attempt to interpret data from an ARRAY resource file
139 @SYMTestExpectedResults Tests must not fail
142 void TRsReadTester::TestArrayL(RResourceReader& aReader)
144 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1290 Test reading ARRAY resource "));
145 CDesCArray* desArray=aReader.ReadDesCArrayL();
146 TEST(desArray->Count()==5);
148 TEST((*desArray)[0]==_L("Esc"));
149 TEST((*desArray)[1]==_L("Enter"));
150 TEST((*desArray)[2]==_L("Tab"));
151 TEST((*desArray)[3]==_L("Del"));
152 TEST((*desArray)[4]==_L("Space"));
158 @SYMTestCaseID SYSLIB-BAFL-CT-1291
159 @SYMTestCaseDesc Tests for reading FLPTED resource
160 @SYMTestPriority High
161 @SYMTestActions Tests for RResourceReader::ReadReal64L() function
162 @SYMTestExpectedResults Tests must not fail
165 void TRsReadTester::TestFlPtEdL(RResourceReader& aReader)
167 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1291 Test reading FLPTED resource "));
168 TEST(aReader.ReadInt16L()==18);
169 TReal little=aReader.ReadReal64L();
171 TReal big=aReader.ReadReal64L();
177 @SYMTestCaseID SYSLIB-BAFL-CT-1292
178 @SYMTestCaseDesc Tests for reading MENU_BAR resource
179 @SYMTestPriority High
180 @SYMTestActions Tests for RResourceReader::ReadInt16L() function
181 @SYMTestExpectedResults Tests must not fail
184 void TRsReadTester::TestMenuBarL(RResourceReader& aReader)
186 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1292 Test reading MENU_BAR resource "));
187 TEST(aReader.ReadInt16L()==8); // how many items following
188 TPtrC ref=_L("abcdefgh");
189 for (TInt ii=1; ii<=8; ii++)
191 TEST(aReader.ReadInt32L()==ii);
192 TEST(aReader.ReadTPtrCL()==ref.Left(ii));
197 @SYMTestCaseID SYSLIB-BAFL-CT-1293
198 @SYMTestCaseDesc Tests for reading ALIGNMENT_HORROR resources
199 @SYMTestPriority High
200 @SYMTestActions Tests for RResourceReader::ReadTPtrC8L(),RResourceReader::ReadTPtrC16L() functions
201 @SYMTestExpectedResults Tests must not fail
204 void TRsReadTester::TestAlignment1L(RResourceReader& aReader, TInt aIndex)
206 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1293 Test reading ALIGNMENT_HORROR resources "));
207 TPtrC8 ref8 =_L8("xyz");
208 TPtrC16 ref16=_L16("xyz");
209 TEST(aReader.ReadTPtrC8L() == ref8.Left(aIndex));
210 TEST(aReader.ReadTPtrC16L()== ref16.Left(aIndex));
214 @SYMTestCaseID SYSLIB-BAFL-CT-1294
215 @SYMTestCaseDesc Tests for reading ALIGNMENT_HORROR_ARRAY resource
216 @SYMTestPriority High
217 @SYMTestActions Tests for RResourceReader::ReadTPtrC8L(),RResourceReader::ReadTPtrC16L() functions
218 @SYMTestExpectedResults Tests must not fail
221 void TRsReadTester::TestAlignment2L(RResourceReader& aReader)
223 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1294 Test reading ALIGNMENT_HORROR_ARRAY resource "));
224 TEST(aReader.ReadInt16L()==7); // how many items following
225 TPtrC8 ref8 =_L8("abcdef");
226 TPtrC16 ref16=_L16("abcdef");
227 for (TInt ii=0; ii<=6; ii++)
229 TEST(aReader.ReadTPtrC8L() ==ref8.Left(ii));
230 TEST(aReader.ReadTPtrC16L()==ref16.Mid(ii));
235 @SYMTestCaseID SYSLIB-BAFL-CT-1295
236 @SYMTestCaseDesc Tests for time required to load a resource file around 100 times
237 @SYMTestPriority High
238 @SYMTestActions Tests for time taken to load resource files repeatedly
239 @SYMTestExpectedResults Tests must not fail
242 void TRsReadTester::TimingTestsL(TRscBufAllocation aRscBufAllocation)
244 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1295 Timing tests "));
245 TheTest.Next(_L("BUTTON and FLPTED"));
246 TUint time = User::TickCount();
247 for (TInt ii=0; ii<100; ii++)
249 RResourceReader reader;
250 ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
251 CleanupStack::PopAndDestroy(&reader);
252 ::OpenResourceReaderLC(reader, SYS_FLPTED_ONE, aRscBufAllocation);
253 CleanupStack::PopAndDestroy(&reader);
255 time = User::TickCount() - time;
256 TheTest.Printf(_L("Time to load 100 times: %d\n"),time);
258 TheTest.Next(_L("BUTTON and ARRAY"));
259 time = User::TickCount();
260 for (TInt jj=0; jj<100; jj++)
262 RResourceReader reader;
263 ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
264 CleanupStack::PopAndDestroy(&reader);
265 ::OpenResourceReaderLC(reader, SYS_ARRAY_ONE, aRscBufAllocation);
266 CleanupStack::PopAndDestroy(&reader);
268 time = User::TickCount() - time;
269 TheTest.Printf(_L("Time to load 100 times: %d\n"),time);
273 TUint8 TRsReadTester::DumpByte(TUint aVal)
275 return(aVal>9? TUint8(aVal-10+'a'): TUint8(aVal+'0'));
278 void TRsReadTester::DumpBytes(const TAny* aPtr,TInt aLen)
280 TUint8* src=(TUint8*)aPtr;
282 TUint8* tar=(TUint8*)whole.Ptr();
289 *tar++=DumpByte(top);
290 *tar++=DumpByte(bottom);
294 whole.SetLength(len);
295 TheTest.Printf(whole);
296 TheTest.Printf(_L("\r\n"));
300 @SYMTestCaseID SYSLIB-BAFL-CT-0474
301 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
302 @SYMTestPriority High
303 @SYMTestActions Open a resource file and test for the reading the data
304 @SYMTestExpectedResults Tests must not fail
307 static void TestButtonL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
309 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0474 "));
310 RResourceReader reader;
311 ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
312 TRAPD(errCode, aTest.TestButtonL(reader));
313 CleanupStack::PopAndDestroy(&reader);
314 TEST2(errCode, KErrNone);
318 @SYMTestCaseID SYSLIB-BAFL-CT-0475
319 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
320 @SYMTestPriority High
321 @SYMTestActions Tests for reading descriptor array.
322 @SYMTestExpectedResults Tests must not fail
325 static void TestArrayL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
327 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0475 "));
328 RResourceReader reader;
329 ::OpenResourceReaderLC(reader, SYS_ARRAY_ONE, aRscBufAllocation);
330 TRAPD(errCode, aTest.TestArrayL(reader));
331 CleanupStack::PopAndDestroy(&reader);
332 TEST2(errCode, KErrNone);
336 @SYMTestCaseID SYSLIB-BAFL-CT-0476
337 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
338 @SYMTestPriority High
339 @SYMTestActions Tests for reading real values
340 @SYMTestExpectedResults Tests must not fail
343 static void TestFlPtEdL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
345 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0476 "));
346 RResourceReader reader;
347 ::OpenResourceReaderLC(reader, SYS_FLPTED_ONE, aRscBufAllocation);
348 TRAPD(errCode, aTest.TestFlPtEdL(reader));
349 CleanupStack::PopAndDestroy(&reader);
350 TEST2(errCode, KErrNone);
354 @SYMTestCaseID SYSLIB-BAFL-CT-0477
355 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
356 @SYMTestPriority High
357 @SYMTestActions Tests for reading menu_bar resource
358 @SYMTestExpectedResults Tests must not fail
361 static void TestMenuBarL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
363 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0477 "));
364 RResourceReader reader;
365 ::OpenResourceReaderLC(reader, SYS_MENUBAR_ONE, aRscBufAllocation);
366 TRAPD(errCode, aTest.TestMenuBarL(reader));
367 CleanupStack::PopAndDestroy(&reader);
368 TEST2(errCode, KErrNone);
372 @SYMTestCaseID SYSLIB-BAFL-CT-0478
373 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
374 @SYMTestPriority High
375 @SYMTestActions Tests for reading descriptors and checks for alignment
376 @SYMTestExpectedResults Tests must not fail
379 static void TestAlignment1L(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
381 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0478 "));
382 const TInt TheHorrors[] =
384 SYS_ALIGNMENT_HORROR0, SYS_ALIGNMENT_HORROR1,
385 SYS_ALIGNMENT_HORROR2, SYS_ALIGNMENT_HORROR3,
389 for(TInt i=0;TheHorrors[i]!=0;++i)
391 RResourceReader reader;
392 ::OpenResourceReaderLC(reader, TheHorrors[i], aRscBufAllocation);
393 TRAPD(errCode, aTest.TestAlignment1L(reader, i));
394 CleanupStack::PopAndDestroy(&reader);
395 TEST2(errCode, KErrNone);
400 @SYMTestCaseID SYSLIB-BAFL-CT-0479
401 @SYMTestCaseDesc Tests for the functionality of RResourceReader class
402 @SYMTestPriority High
403 @SYMTestActions Tests for reading descriptors and checks for alignment
404 @SYMTestExpectedResults Tests must not fail
407 static void TestAlignment2L(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
409 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0479 "));
410 RResourceReader reader;
411 ::OpenResourceReaderLC(reader, SYS_ALIGNMENT_HORROR_ARRAY, aRscBufAllocation);
412 TRAPD(errCode, aTest.TestAlignment2L(reader));
413 CleanupStack::PopAndDestroy(&reader);
414 TEST2(errCode, KErrNone);
417 static void RunTestsL()
419 TheTest.Start(_L("Resource reader"));
420 CleanupClosePushL(TheFs);
421 User::LeaveIfError(TheFs.Connect());
422 TheResourceFile = CResourceFile::NewLC(TheFs,KRomResourceFile, 0, 0);
426 ::TestButtonL(lt, EFromRscFile);
427 ::TestButtonL(lt, EFromRscBuf);
429 ::TestArrayL(lt, EFromRscFile);
430 ::TestArrayL(lt, EFromRscBuf);
432 ::TestFlPtEdL(lt, EFromRscFile);
433 ::TestFlPtEdL(lt, EFromRscBuf);
435 ::TestMenuBarL(lt, EFromRscFile);
436 ::TestMenuBarL(lt, EFromRscBuf);
438 ::TestAlignment1L(lt, EFromRscFile);
439 ::TestAlignment1L(lt, EFromRscBuf);
441 ::TestAlignment2L(lt, EFromRscFile);
442 ::TestAlignment2L(lt, EFromRscBuf);
444 TRAPD(errCode, lt.TimingTestsL(EFromRscFile));
445 TEST2(errCode, KErrNone);
447 TRAP(errCode, lt.TimingTestsL(EFromRscBuf));
448 TEST2(errCode, KErrNone);
450 CleanupStack::PopAndDestroy(TheResourceFile);
451 CleanupStack::PopAndDestroy(1, &TheFs);
457 CTrapCleanup *cleanup=CTrapCleanup::New();
459 TRAPD(err,::RunTestsL());
460 TEST2(err, KErrNone);
461 TheTest.Next(_L("/n"));