lowlevellibsandfws/apputils/tsrc/T_RscMem.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Tests CResourceFile class - memory allocation tests
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <barsc2.h>
       
    20 
       
    21 LOCAL_D RTest test(_L("T_RSCMEM"));
       
    22 LOCAL_D RFs TheFs;
       
    23 
       
    24 /**
       
    25 @SYMTestCaseID          SYSLIB-BAFL-CT-0484
       
    26 @SYMTestCaseDesc        CResourceFile class test
       
    27                         Memory allocation tests
       
    28 @SYMTestPriority        High
       
    29 @SYMTestActions         Tests for the out of memory conditions
       
    30 @SYMTestExpectedResults Tests must not fail
       
    31 @SYMREQ                 REQ0000
       
    32 */
       
    33 LOCAL_C void TestOpenL(const TDesC &aFileName, TUint aFileOffset, TUint aFileSize)
       
    34 	{
       
    35 	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0484 "));
       
    36 	__UHEAP_RESET;
       
    37 
       
    38 	for(TInt count = 1; ;count++)
       
    39 		{
       
    40 		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
       
    41 		__UHEAP_MARK;
       
    42 
       
    43 		CResourceFile* rsc_file = NULL;
       
    44 		TRAPD(err, rsc_file = CResourceFile::NewL(TheFs, aFileName, aFileOffset, aFileSize));
       
    45 		delete rsc_file;
       
    46 
       
    47 		if(err == KErrNoMemory)
       
    48 			{
       
    49 			__UHEAP_MARKEND;
       
    50 			}
       
    51 		else if(err == KErrNone)
       
    52 			{
       
    53 			__UHEAP_MARKEND;
       
    54 			break;
       
    55 			}
       
    56 		else
       
    57 			User::Panic(_L("CResourceFile::NewL(), error "), err);
       
    58 		}
       
    59 
       
    60 	__UHEAP_RESET;
       
    61 	}
       
    62 
       
    63 LOCAL_C void DoTestsL()
       
    64     {
       
    65 	CleanupClosePushL(TheFs);
       
    66 	User::LeaveIfError(TheFs.Connect());
       
    67 
       
    68 	::TestOpenL(_L("z:\\system\\data\\Trsc.rsc"), 0, 0);
       
    69 
       
    70 	CleanupStack::PopAndDestroy(1, &TheFs);
       
    71     }
       
    72 
       
    73 GLDEF_C TInt E32Main()
       
    74 	{
       
    75     __UHEAP_MARK;
       
    76     CTrapCleanup* cleanup = CTrapCleanup::New();
       
    77 	test.Title();
       
    78 	test.Start(_L("Testing CResourceFile::NewL()"));
       
    79     TRAPD(err, DoTestsL());
       
    80     test.Printf(_L("Error code is %d\n"), err);
       
    81     test(err == KErrNone);
       
    82     test.Next(_L("/n"));
       
    83 	test.End();
       
    84     test.Close();
       
    85     delete cleanup;
       
    86     __UHEAP_MARKEND;
       
    87 	return 0;
       
    88     }