1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/tsrc/T_RSREAD2.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,467 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Tests resource reader
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32base.h>
1.23 +#include <e32test.h>
1.24 +#include <f32file.h>
1.25 +#include <barsc2.h>
1.26 +#include <barsread2.h>
1.27 +#include <badesca.h>
1.28 +#include <trsc.rsg>
1.29 +#include "T_RSC.H"
1.30 +
1.31 +RTest TheTest(_L("T_RSREAD2"));
1.32 +RFs TheFs;
1.33 +CResourceFile* TheResourceFile = NULL;
1.34 +
1.35 +//
1.36 +//
1.37 +//Test macroses and functions
1.38 +LOCAL_C void Check(TInt aValue, TInt aLine)
1.39 + {
1.40 + if(!aValue)
1.41 + {
1.42 + TheTest(EFalse, aLine);
1.43 + }
1.44 + }
1.45 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
1.46 + {
1.47 + if(aValue != aExpected)
1.48 + {
1.49 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.50 + TheTest(EFalse, aLine);
1.51 + }
1.52 + }
1.53 +#define TEST(arg) ::Check((arg), __LINE__)
1.54 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.55 +
1.56 +//
1.57 +//
1.58 +
1.59 +//Opens aReader using RResourceReader::OpenLC(CResourceFile*, TInt)
1.60 +static void OpenResourceReaderLC(RResourceReader& aReader, TInt aResourceId)
1.61 + {
1.62 + TEST(TheResourceFile != NULL);
1.63 + aReader.OpenLC(TheResourceFile, aResourceId);
1.64 + }
1.65 +
1.66 +//Opens aReader using RResourceReader::OpenL(const TDesC8&)
1.67 +static void OpenResourceReader2LC(RResourceReader& aReader, TInt aResourceId)
1.68 + {
1.69 + TEST(TheResourceFile != NULL);
1.70 + HBufC8* rscData = TheResourceFile->AllocReadLC(aResourceId);
1.71 + aReader.OpenL(rscData->Des());
1.72 + CleanupStack::PopAndDestroy(rscData);
1.73 + CleanupClosePushL(aReader);
1.74 + }
1.75 +
1.76 +//This enum describes how to obtain the resource buffer for
1.77 +//RResourceReader objects: from the resource file or from a buffer
1.78 +enum TRscBufAllocation
1.79 + {
1.80 + EFromRscFile,
1.81 + EFromRscBuf,
1.82 + ERscBufLast
1.83 + };
1.84 +
1.85 +typedef void (*FTOpenResourceReaderLC)(RResourceReader& aReader, TInt aResourceId);
1.86 +
1.87 +static FTOpenResourceReaderLC OpenResourceReaderFuncLC[ERscBufLast] =
1.88 + {
1.89 + &OpenResourceReaderLC,
1.90 + &OpenResourceReader2LC
1.91 + };
1.92 +
1.93 +//Opens aReader either from a resource file ot from a resource buffer
1.94 +static void OpenResourceReaderLC(RResourceReader& aReader, TInt aResourceId, TRscBufAllocation aRscBufAllocation)
1.95 + {
1.96 + OpenResourceReaderFuncLC[aRscBufAllocation](aReader, aResourceId);
1.97 + }
1.98 +
1.99 +class TRsReadTester
1.100 + {
1.101 +public:
1.102 + void TestButtonL(RResourceReader& aReader);
1.103 + void TestArrayL(RResourceReader& aReader);
1.104 + void TestFlPtEdL(RResourceReader& aReader);
1.105 + void TestMenuBarL(RResourceReader& aReader);
1.106 + void TestAlignment1L(RResourceReader& aReader, TInt aIndex);
1.107 + void TestAlignment2L(RResourceReader& aReader);
1.108 + void TimingTestsL(TRscBufAllocation aRscBufAllocation);
1.109 +private:
1.110 + void DumpBytes(const TAny* aPtr,TInt aLen);
1.111 + TUint8 DumpByte(TUint aVal);
1.112 + };
1.113 +
1.114 +/**
1.115 +@SYMTestCaseID SYSLIB-BAFL-CT-1289
1.116 +@SYMTestCaseDesc Tests for reading data from a BUTTON resource file
1.117 +@SYMTestPriority High
1.118 +@SYMTestActions Tests for RResourceReader::ReadInt16L(),RResourceReader::ReadUInt16L(),
1.119 + RResourceReader::ReadTPtrCL() functions
1.120 +@SYMTestExpectedResults Tests must not fail
1.121 +@SYMREQ REQ0000
1.122 +*/
1.123 +void TRsReadTester::TestButtonL(RResourceReader& aReader)
1.124 + {
1.125 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1289 Test reading BUTTON resource "));
1.126 + TEST(aReader.ReadInt16L()==3);
1.127 + TEST(aReader.ReadUint16L()==5);
1.128 + TPtrC ptr=aReader.ReadTPtrCL();
1.129 + TEST(ptr==_L("Text"));
1.130 + ptr.Set(aReader.ReadTPtrCL());
1.131 + TEST(ptr.Length()==0);
1.132 + HBufC* hBuf=aReader.ReadHBufCL();
1.133 + TEST(*hBuf==_L("Bitmap placeholder"));
1.134 + delete(hBuf);
1.135 + }
1.136 +
1.137 +/**
1.138 +@SYMTestCaseID SYSLIB-BAFL-CT-1290
1.139 +@SYMTestCaseDesc Tests for RResourceReader::ReadDesCArrayL() function
1.140 +@SYMTestPriority High
1.141 +@SYMTestActions Attempt to interpret data from an ARRAY resource file
1.142 +@SYMTestExpectedResults Tests must not fail
1.143 +@SYMREQ REQ0000
1.144 +*/
1.145 +void TRsReadTester::TestArrayL(RResourceReader& aReader)
1.146 + {
1.147 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1290 Test reading ARRAY resource "));
1.148 + CDesCArray* desArray=aReader.ReadDesCArrayL();
1.149 + TEST(desArray->Count()==5);
1.150 +
1.151 + TEST((*desArray)[0]==_L("Esc"));
1.152 + TEST((*desArray)[1]==_L("Enter"));
1.153 + TEST((*desArray)[2]==_L("Tab"));
1.154 + TEST((*desArray)[3]==_L("Del"));
1.155 + TEST((*desArray)[4]==_L("Space"));
1.156 +
1.157 + delete(desArray);
1.158 + }
1.159 +
1.160 +/**
1.161 +@SYMTestCaseID SYSLIB-BAFL-CT-1291
1.162 +@SYMTestCaseDesc Tests for reading FLPTED resource
1.163 +@SYMTestPriority High
1.164 +@SYMTestActions Tests for RResourceReader::ReadReal64L() function
1.165 +@SYMTestExpectedResults Tests must not fail
1.166 +@SYMREQ REQ0000
1.167 +*/
1.168 +void TRsReadTester::TestFlPtEdL(RResourceReader& aReader)
1.169 + {
1.170 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1291 Test reading FLPTED resource "));
1.171 + TEST(aReader.ReadInt16L()==18);
1.172 + TReal little=aReader.ReadReal64L();
1.173 + TEST(little==0.0);
1.174 + TReal big=aReader.ReadReal64L();
1.175 + TEST(big>9.89e99);
1.176 + TEST(big<9.91e99);
1.177 + }
1.178 +
1.179 +/**
1.180 +@SYMTestCaseID SYSLIB-BAFL-CT-1292
1.181 +@SYMTestCaseDesc Tests for reading MENU_BAR resource
1.182 +@SYMTestPriority High
1.183 +@SYMTestActions Tests for RResourceReader::ReadInt16L() function
1.184 +@SYMTestExpectedResults Tests must not fail
1.185 +@SYMREQ REQ0000
1.186 +*/
1.187 +void TRsReadTester::TestMenuBarL(RResourceReader& aReader)
1.188 + {
1.189 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1292 Test reading MENU_BAR resource "));
1.190 + TEST(aReader.ReadInt16L()==8); // how many items following
1.191 + TPtrC ref=_L("abcdefgh");
1.192 + for (TInt ii=1; ii<=8; ii++)
1.193 + {
1.194 + TEST(aReader.ReadInt32L()==ii);
1.195 + TEST(aReader.ReadTPtrCL()==ref.Left(ii));
1.196 + }
1.197 + }
1.198 +
1.199 +/**
1.200 +@SYMTestCaseID SYSLIB-BAFL-CT-1293
1.201 +@SYMTestCaseDesc Tests for reading ALIGNMENT_HORROR resources
1.202 +@SYMTestPriority High
1.203 +@SYMTestActions Tests for RResourceReader::ReadTPtrC8L(),RResourceReader::ReadTPtrC16L() functions
1.204 +@SYMTestExpectedResults Tests must not fail
1.205 +@SYMREQ REQ0000
1.206 +*/
1.207 +void TRsReadTester::TestAlignment1L(RResourceReader& aReader, TInt aIndex)
1.208 + {
1.209 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1293 Test reading ALIGNMENT_HORROR resources "));
1.210 + TPtrC8 ref8 =_L8("xyz");
1.211 + TPtrC16 ref16=_L16("xyz");
1.212 + TEST(aReader.ReadTPtrC8L() == ref8.Left(aIndex));
1.213 + TEST(aReader.ReadTPtrC16L()== ref16.Left(aIndex));
1.214 + }
1.215 +
1.216 +/**
1.217 +@SYMTestCaseID SYSLIB-BAFL-CT-1294
1.218 +@SYMTestCaseDesc Tests for reading ALIGNMENT_HORROR_ARRAY resource
1.219 +@SYMTestPriority High
1.220 +@SYMTestActions Tests for RResourceReader::ReadTPtrC8L(),RResourceReader::ReadTPtrC16L() functions
1.221 +@SYMTestExpectedResults Tests must not fail
1.222 +@SYMREQ REQ0000
1.223 +*/
1.224 +void TRsReadTester::TestAlignment2L(RResourceReader& aReader)
1.225 + {
1.226 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1294 Test reading ALIGNMENT_HORROR_ARRAY resource "));
1.227 + TEST(aReader.ReadInt16L()==7); // how many items following
1.228 + TPtrC8 ref8 =_L8("abcdef");
1.229 + TPtrC16 ref16=_L16("abcdef");
1.230 + for (TInt ii=0; ii<=6; ii++)
1.231 + {
1.232 + TEST(aReader.ReadTPtrC8L() ==ref8.Left(ii));
1.233 + TEST(aReader.ReadTPtrC16L()==ref16.Mid(ii));
1.234 + }
1.235 + }
1.236 +
1.237 +/**
1.238 +@SYMTestCaseID SYSLIB-BAFL-CT-1295
1.239 +@SYMTestCaseDesc Tests for time required to load a resource file around 100 times
1.240 +@SYMTestPriority High
1.241 +@SYMTestActions Tests for time taken to load resource files repeatedly
1.242 +@SYMTestExpectedResults Tests must not fail
1.243 +@SYMREQ REQ0000
1.244 +*/
1.245 +void TRsReadTester::TimingTestsL(TRscBufAllocation aRscBufAllocation)
1.246 + {
1.247 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-1295 Timing tests "));
1.248 + TheTest.Next(_L("BUTTON and FLPTED"));
1.249 + TUint time = User::TickCount();
1.250 + for (TInt ii=0; ii<100; ii++)
1.251 + {
1.252 + RResourceReader reader;
1.253 + ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
1.254 + CleanupStack::PopAndDestroy(&reader);
1.255 + ::OpenResourceReaderLC(reader, SYS_FLPTED_ONE, aRscBufAllocation);
1.256 + CleanupStack::PopAndDestroy(&reader);
1.257 + }
1.258 + time = User::TickCount() - time;
1.259 + TheTest.Printf(_L("Time to load 100 times: %d\n"),time);
1.260 +
1.261 + TheTest.Next(_L("BUTTON and ARRAY"));
1.262 + time = User::TickCount();
1.263 + for (TInt jj=0; jj<100; jj++)
1.264 + {
1.265 + RResourceReader reader;
1.266 + ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
1.267 + CleanupStack::PopAndDestroy(&reader);
1.268 + ::OpenResourceReaderLC(reader, SYS_ARRAY_ONE, aRscBufAllocation);
1.269 + CleanupStack::PopAndDestroy(&reader);
1.270 + }
1.271 + time = User::TickCount() - time;
1.272 + TheTest.Printf(_L("Time to load 100 times: %d\n"),time);
1.273 + }
1.274 +
1.275 +
1.276 +TUint8 TRsReadTester::DumpByte(TUint aVal)
1.277 + {
1.278 + return(aVal>9? TUint8(aVal-10+'a'): TUint8(aVal+'0'));
1.279 + }
1.280 +
1.281 +void TRsReadTester::DumpBytes(const TAny* aPtr,TInt aLen)
1.282 + {
1.283 + TUint8* src=(TUint8*)aPtr;
1.284 + TBuf<100> whole;
1.285 + TUint8* tar=(TUint8*)whole.Ptr();
1.286 + TInt len=0;
1.287 + while (aLen--)
1.288 + {
1.289 + TUint val=(*src++);
1.290 + TUint top=val/16;
1.291 + TUint bottom=val%16;
1.292 + *tar++=DumpByte(top);
1.293 + *tar++=DumpByte(bottom);
1.294 + *tar++=' ';
1.295 + len+=3;
1.296 + }
1.297 + whole.SetLength(len);
1.298 + TheTest.Printf(whole);
1.299 + TheTest.Printf(_L("\r\n"));
1.300 + }
1.301 +
1.302 +/**
1.303 +@SYMTestCaseID SYSLIB-BAFL-CT-0474
1.304 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.305 +@SYMTestPriority High
1.306 +@SYMTestActions Open a resource file and test for the reading the data
1.307 +@SYMTestExpectedResults Tests must not fail
1.308 +@SYMREQ REQ0000
1.309 +*/
1.310 +static void TestButtonL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.311 + {
1.312 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0474 "));
1.313 + RResourceReader reader;
1.314 + ::OpenResourceReaderLC(reader, SYS_BUTTON_ONE, aRscBufAllocation);
1.315 + TRAPD(errCode, aTest.TestButtonL(reader));
1.316 + CleanupStack::PopAndDestroy(&reader);
1.317 + TEST2(errCode, KErrNone);
1.318 + }
1.319 +
1.320 +/**
1.321 +@SYMTestCaseID SYSLIB-BAFL-CT-0475
1.322 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.323 +@SYMTestPriority High
1.324 +@SYMTestActions Tests for reading descriptor array.
1.325 +@SYMTestExpectedResults Tests must not fail
1.326 +@SYMREQ REQ0000
1.327 +*/
1.328 +static void TestArrayL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.329 + {
1.330 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0475 "));
1.331 + RResourceReader reader;
1.332 + ::OpenResourceReaderLC(reader, SYS_ARRAY_ONE, aRscBufAllocation);
1.333 + TRAPD(errCode, aTest.TestArrayL(reader));
1.334 + CleanupStack::PopAndDestroy(&reader);
1.335 + TEST2(errCode, KErrNone);
1.336 + }
1.337 +
1.338 +/**
1.339 +@SYMTestCaseID SYSLIB-BAFL-CT-0476
1.340 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.341 +@SYMTestPriority High
1.342 +@SYMTestActions Tests for reading real values
1.343 +@SYMTestExpectedResults Tests must not fail
1.344 +@SYMREQ REQ0000
1.345 +*/
1.346 +static void TestFlPtEdL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.347 + {
1.348 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0476 "));
1.349 + RResourceReader reader;
1.350 + ::OpenResourceReaderLC(reader, SYS_FLPTED_ONE, aRscBufAllocation);
1.351 + TRAPD(errCode, aTest.TestFlPtEdL(reader));
1.352 + CleanupStack::PopAndDestroy(&reader);
1.353 + TEST2(errCode, KErrNone);
1.354 + }
1.355 +
1.356 +/**
1.357 +@SYMTestCaseID SYSLIB-BAFL-CT-0477
1.358 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.359 +@SYMTestPriority High
1.360 +@SYMTestActions Tests for reading menu_bar resource
1.361 +@SYMTestExpectedResults Tests must not fail
1.362 +@SYMREQ REQ0000
1.363 +*/
1.364 +static void TestMenuBarL(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.365 + {
1.366 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0477 "));
1.367 + RResourceReader reader;
1.368 + ::OpenResourceReaderLC(reader, SYS_MENUBAR_ONE, aRscBufAllocation);
1.369 + TRAPD(errCode, aTest.TestMenuBarL(reader));
1.370 + CleanupStack::PopAndDestroy(&reader);
1.371 + TEST2(errCode, KErrNone);
1.372 + }
1.373 +
1.374 +/**
1.375 +@SYMTestCaseID SYSLIB-BAFL-CT-0478
1.376 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.377 +@SYMTestPriority High
1.378 +@SYMTestActions Tests for reading descriptors and checks for alignment
1.379 +@SYMTestExpectedResults Tests must not fail
1.380 +@SYMREQ REQ0000
1.381 +*/
1.382 +static void TestAlignment1L(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.383 + {
1.384 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0478 "));
1.385 + const TInt TheHorrors[] =
1.386 + {
1.387 + SYS_ALIGNMENT_HORROR0, SYS_ALIGNMENT_HORROR1,
1.388 + SYS_ALIGNMENT_HORROR2, SYS_ALIGNMENT_HORROR3,
1.389 + 0
1.390 + };
1.391 +
1.392 + for(TInt i=0;TheHorrors[i]!=0;++i)
1.393 + {
1.394 + RResourceReader reader;
1.395 + ::OpenResourceReaderLC(reader, TheHorrors[i], aRscBufAllocation);
1.396 + TRAPD(errCode, aTest.TestAlignment1L(reader, i));
1.397 + CleanupStack::PopAndDestroy(&reader);
1.398 + TEST2(errCode, KErrNone);
1.399 + }
1.400 + }
1.401 +
1.402 +/**
1.403 +@SYMTestCaseID SYSLIB-BAFL-CT-0479
1.404 +@SYMTestCaseDesc Tests for the functionality of RResourceReader class
1.405 +@SYMTestPriority High
1.406 +@SYMTestActions Tests for reading descriptors and checks for alignment
1.407 +@SYMTestExpectedResults Tests must not fail
1.408 +@SYMREQ REQ0000
1.409 +*/
1.410 +static void TestAlignment2L(TRsReadTester& aTest, TRscBufAllocation aRscBufAllocation)
1.411 + {
1.412 + TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0479 "));
1.413 + RResourceReader reader;
1.414 + ::OpenResourceReaderLC(reader, SYS_ALIGNMENT_HORROR_ARRAY, aRscBufAllocation);
1.415 + TRAPD(errCode, aTest.TestAlignment2L(reader));
1.416 + CleanupStack::PopAndDestroy(&reader);
1.417 + TEST2(errCode, KErrNone);
1.418 + }
1.419 +
1.420 +static void RunTestsL()
1.421 + {
1.422 + TheTest.Start(_L("Resource reader"));
1.423 + CleanupClosePushL(TheFs);
1.424 + User::LeaveIfError(TheFs.Connect());
1.425 + TheResourceFile = CResourceFile::NewLC(TheFs,KRomResourceFile, 0, 0);
1.426 +
1.427 + TRsReadTester lt;
1.428 +
1.429 + ::TestButtonL(lt, EFromRscFile);
1.430 + ::TestButtonL(lt, EFromRscBuf);
1.431 +
1.432 + ::TestArrayL(lt, EFromRscFile);
1.433 + ::TestArrayL(lt, EFromRscBuf);
1.434 +
1.435 + ::TestFlPtEdL(lt, EFromRscFile);
1.436 + ::TestFlPtEdL(lt, EFromRscBuf);
1.437 +
1.438 + ::TestMenuBarL(lt, EFromRscFile);
1.439 + ::TestMenuBarL(lt, EFromRscBuf);
1.440 +
1.441 + ::TestAlignment1L(lt, EFromRscFile);
1.442 + ::TestAlignment1L(lt, EFromRscBuf);
1.443 +
1.444 + ::TestAlignment2L(lt, EFromRscFile);
1.445 + ::TestAlignment2L(lt, EFromRscBuf);
1.446 +
1.447 + TRAPD(errCode, lt.TimingTestsL(EFromRscFile));
1.448 + TEST2(errCode, KErrNone);
1.449 +
1.450 + TRAP(errCode, lt.TimingTestsL(EFromRscBuf));
1.451 + TEST2(errCode, KErrNone);
1.452 +
1.453 + CleanupStack::PopAndDestroy(TheResourceFile);
1.454 + CleanupStack::PopAndDestroy(1, &TheFs);
1.455 + }
1.456 +
1.457 +TInt E32Main()
1.458 + {
1.459 + __UHEAP_MARK;
1.460 + CTrapCleanup *cleanup=CTrapCleanup::New();
1.461 + TheTest.Title();
1.462 + TRAPD(err,::RunTestsL());
1.463 + TEST2(err, KErrNone);
1.464 + TheTest.Next(_L("/n"));
1.465 + TheTest.End();
1.466 + TheTest.Close();
1.467 + delete(cleanup);
1.468 + __UHEAP_MARKEND;
1.469 + return(0);
1.470 + }