lafagnosticuifoundation/cone/tef/tconecoedatastoragestep.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 // The test step corrupts the system colorlist and colorlist is populated 
       
    15 // again using PopulateColorArrayL API and OOM tests are performed.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent - Internal Symbian test code.
       
    22 */
       
    23 
       
    24 
       
    25 #include "tconecoedatastoragestep.h"
       
    26 #include "coedatastorage.h"
       
    27 #include <centralrepository.h>
       
    28 #include <gulcolor.h>
       
    29 
       
    30 
       
    31 /**
       
    32 Constant Value KUidSystemColorRepository obtained from CoeDataStorage.cpp
       
    33 */
       
    34 const TUint KUidSystemColorRepository = 0x10272619;
       
    35 const TUint KSystemColorRepositoryKey = 0;
       
    36 
       
    37 CTConeCoeDataStorageStep::CTConeCoeDataStorageStep()
       
    38 /**
       
    39 Constructor
       
    40 */
       
    41 	{
       
    42 	SetTestStepName(KTConeCoeDataStorageStep);
       
    43 	}
       
    44 
       
    45 CTConeCoeDataStorageStep::~CTConeCoeDataStorageStep()
       
    46 /**
       
    47 Destructor
       
    48 */
       
    49 	{
       
    50 	}
       
    51 	
       
    52 /**
       
    53   @SYMTestCaseID UIF-TConeCoeDataStorageStep-TestPopulateColorArrayOOML
       
    54  
       
    55   @SYMPREQ
       
    56  
       
    57   @SYMTestCaseDesc Tests PopulateColorArrayL API with forced memory allocation failure.\n
       
    58  
       
    59   @SYMTestPriority High
       
    60  
       
    61   @SYMTestStatus Implemented
       
    62   
       
    63   @SYMTestActions : Creating the colorlist using PopulateColorArrayL API  .\n
       
    64   The system colorlist is corrupted and PopulateColorArrayL API is invoked to populate the colorlist.\n
       
    65       
       
    66   @SYMTestExpectedResults : PopulateColorArrayL method should report KErrNoMemory if it cannot allocate sufficient \n 
       
    67 	memory and recover gracefully from low memory situations and subsequently succeed in creating the colorlist when \n
       
    68 	sufficient memory is available.\n
       
    69  
       
    70   @SYMTestType : CIT
       
    71 */
       
    72 void CTConeCoeDataStorageStep::TestPopulateColorArrayOOML()
       
    73 	{
       
    74 	TInt err = KErrNoMemory;
       
    75 	TInt ii;
       
    76 	//The ideal loop condition is err==KErrNoMemory, it is changed
       
    77 	//because PopulateColorArrayL API invokes GetSystemColorListL() which has TRAP function,
       
    78 	//which captures the KErrNoMemory condition and the PopulateColorArrayL API doesn't leave
       
    79 	//with any memory allocation failure. In order to make sure that PopulateColorArrayL API 
       
    80 	//leaves with memory allocation failure and also to create successfully the colorlist 
       
    81 	//the loop has to run for 70 times. 
       
    82 	INFO_PRINTF1(_L("Tests After Corrupting the System Colorlist"));
       
    83 	for (ii=1; ii<70; ii++)
       
    84 		{
       
    85 		INFO_PRINTF2(_L("The value of the iteration number is %d"), ii);
       
    86 		__UHEAP_FAILNEXT(ii);
       
    87 		__UHEAP_MARK;
       
    88 		TRAP(err, DoOomTestsAfterCorruptingColorListL());
       
    89 		INFO_PRINTF2(_L("The value of the err is %d"), err);
       
    90 		__UHEAP_MARKEND;
       
    91 		}
       
    92 	__UHEAP_SETFAIL(RHeap::ENone,0); 
       
    93 	User::LeaveIfError(err);
       
    94 	}
       
    95 	
       
    96 /**
       
    97 This functions performs the OOM Tests.
       
    98 */	
       
    99 void CTConeCoeDataStorageStep::DoOomTestsAfterCorruptingColorListL()
       
   100 	{
       
   101 	SetSystemColorSchemeL(_L8("Some rubbish binary data\xab\xcd\xef"));
       
   102 	CColorList* colorlist = NULL;
       
   103 	CCoeDataStorage* dataStorage = CCoeDataStorage::NewL();
       
   104 	CleanupStack::PushL(dataStorage);
       
   105 	colorlist = dataStorage->PopulateColorArrayL();
       
   106 	TEST(colorlist != NULL);
       
   107 	delete colorlist;
       
   108     CleanupStack::PopAndDestroy(dataStorage);
       
   109 	}
       
   110 	
       
   111 /**
       
   112 This function corrupts the System Colorlist by corrupting the color scheme file. 
       
   113 */	
       
   114 void CTConeCoeDataStorageStep::SetSystemColorSchemeL(const TDesC8& aBuffer)
       
   115 	{ 
       
   116 	CRepository* const repository = CRepository::NewL(TUid::Uid(KUidSystemColorRepository));
       
   117 	CleanupStack::PushL(repository);
       
   118 	User::LeaveIfError(repository->Set(KSystemColorRepositoryKey, aBuffer));
       
   119 	CleanupStack::PopAndDestroy(repository);
       
   120 	}
       
   121 /**
       
   122   Entry function for CTConeCoeDataStorageStep Test Step.\n
       
   123   Invokes the TestPopulateColorArrayOOML function. \n
       
   124 */
       
   125 TVerdict CTConeCoeDataStorageStep::doTestStepL() // main function called by E32
       
   126 	{
       
   127 	SetTestStepID(_L("UIF-TConeCoeDataStorageStep-TestPopulateColorArrayOOML"));
       
   128 	INFO_PRINTF1(_L("Test Started"));
       
   129 	TestPopulateColorArrayOOML();
       
   130 	INFO_PRINTF1(_L("Test Finished"));
       
   131 	RecordTestResultL();
       
   132 	return TestStepResult();
       
   133 	}