lafagnosticuifoundation/cone/tef/tconeresourceloader.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 2007-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 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "tconeresourceloader.h"
       
    23 #include <eikenv.h>
       
    24 
       
    25 _LIT(KConeResourceLoaderPath,"z:\\resource\\apps\\tconeresourceloader.rsc");
       
    26 
       
    27 CTConeResourceLoaderAppUi::CTConeResourceLoaderAppUi(CTConeResourceLoaderStep& aStep) 
       
    28 : CTestAppUi(&aStep, KConeResourceLoaderPath)
       
    29 	{
       
    30 	}
       
    31 
       
    32 void CTConeResourceLoaderAppUi::ConstructL()
       
    33 	{
       
    34 	CTestAppUi::ConstructL();
       
    35 	AutoTestManager().StartAutoTest();
       
    36 	}
       
    37 
       
    38 CTConeResourceLoaderAppUi::~CTConeResourceLoaderAppUi()
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CTConeResourceLoaderAppUi::RunTestStepL(TInt aStep)
       
    43 	{
       
    44 	switch (aStep)
       
    45 		{
       
    46 		case 1:
       
    47 			SetTestStepID(_L("UIF-CONE-0026"));			
       
    48 			INFO_PRINTF1(_L("Test Cone resource loader"));
       
    49 			TestConeResourceLoader();
       
    50 			INFO_PRINTF1(_L("Test Cone resource loader Completed"));
       
    51 			RecordTestResultL();			
       
    52 			break;
       
    53 		case 2:
       
    54 			SetTestStepID(_L("UIF-CONE-0027"));			
       
    55 	  		INFO_PRINTF1(_L("Start OOM test for Cone Resource Loader"));
       
    56 	  		TestOOMConeResourceLoader();
       
    57 			INFO_PRINTF1(_L("OOM test for Cone Resource Loader Completed"));
       
    58 			RecordTestResultL();
       
    59 			CloseTMSGraphicsStep();
       
    60 			break;	
       
    61 		case 3:
       
    62 			AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass);
       
    63 			break;
       
    64 		default:
       
    65 			break;
       
    66 		}
       
    67 	}
       
    68 
       
    69 /**
       
    70    @SYMTestCaseID UIF-CONE-0026
       
    71   
       
    72    @SYMREQ 7736
       
    73   
       
    74    @SYMTestCaseDesc Tests the RCoeResourceLoader::OpenL(), RCoeResourceLoader::Open() and RCoeResourceLoader::Close() methods.
       
    75   
       
    76    @SYMTestPriority High
       
    77   
       
    78    @SYMTestStatus Implemented
       
    79    
       
    80    @SYMTestActions The OpenL() and Open() methods opens the given resource file. 
       
    81    					Close() method closes the resource file if it is open.
       
    82    
       
    83    @SYMTestExpectedResults  1. OpenL() and Open() methods open the given resource file and leaves and returns 
       
    84    							   with KErrNone respectively.  
       
    85    							2. The OpenL() leaves with KErrNotSupported if the given resource file is already open.
       
    86    							3. Close() method closes the given resource file.
       
    87    							4. The OpenL() leaves with KErrNotFound if the given resource file is not found.
       
    88    							5. Close() method returns correctly if it called on resource file which not opened using resource loader.
       
    89    							
       
    90  */
       
    91 void CTConeResourceLoaderAppUi::TestConeResourceLoader()
       
    92 	{
       
    93 	TInt ret(KErrNone);
       
    94     TFileName fileName(KConeResourceLoaderPath);
       
    95     
       
    96     RCoeResourceLoader resourceLoader(*iCoeEnv);
       
    97         	
       
    98 	TRAP(ret, resourceLoader.OpenL(fileName));
       
    99 	TEST(ret == KErrNone);
       
   100 	
       
   101 	// Try to open an already open file.
       
   102 	INFO_PRINTF1(_L("Try to open a file which is already open, using Cone resource loader"));
       
   103 	TRAP(ret, resourceLoader.OpenL(fileName));
       
   104 	TEST(ret == KErrNotSupported);
       
   105 	resourceLoader.Close();
       
   106 
       
   107 	ret = resourceLoader.Open(fileName);
       
   108 	TEST(ret == KErrNone);
       
   109 	resourceLoader.Close();
       
   110 	
       
   111 	// Try to open an non-existing file.
       
   112 	INFO_PRINTF1(_L("Try to open a file which is not present, using Cone resource loader"));
       
   113 	fileName = _L("c:\\system\\data\\trial.rsc");
       
   114 	TRAP(ret, resourceLoader.OpenL(fileName));
       
   115 	TEST(ret==KErrNotFound || ret==KErrPathNotFound);
       
   116 	if (ret!=KErrNotFound)
       
   117 		{
       
   118 		if (ret==KErrPathNotFound)
       
   119 			{
       
   120 			_LIT(KLog,"WARNING!! Opening non existent resouce file %S gave error KErrPathNotFound (%d) expecting KErrNotFound");
       
   121 			INFO_PRINTF3(KLog,&fileName,ret);
       
   122 			}
       
   123 		else
       
   124 			{
       
   125 			_LIT(KLog,"Opening non existent resouce file %S gave unexpected error %d (should have been KErrNotFound: %d)");
       
   126 			INFO_PRINTF4(KLog,&fileName,ret,KErrNotFound);
       
   127 			}
       
   128 		}
       
   129 	INFO_PRINTF1(_L("Try to close a file which is not open using Cone resource loader"));
       
   130 	resourceLoader.Close();
       
   131 	}
       
   132 
       
   133 /**
       
   134    @SYMTestCaseID UIF-CONE-0027
       
   135   
       
   136    @SYMREQ 7736
       
   137   
       
   138    @SYMTestCaseDesc Tests RCoeResourceLoader::OpenL() method when device goes Out of Memory.
       
   139   
       
   140    @SYMTestPriority High
       
   141   
       
   142    @SYMTestStatus Implemented
       
   143    
       
   144    @SYMTestActions Calls OpenL() under OOM condition
       
   145    
       
   146    @SYMTestExpectedResults Tests should complete without any memory leaks.
       
   147  */
       
   148 void CTConeResourceLoaderAppUi::TestOOMConeResourceLoader()
       
   149 	{
       
   150     TFileName fileName(KConeResourceLoaderPath);
       
   151     
       
   152     RCoeResourceLoader resourceLoader(*iCoeEnv);
       
   153 	//OOM test for RCoeResourceLoader::OpenL() method.
       
   154 	for (TInt fail = 1;; fail++)
       
   155 		{
       
   156 		__UHEAP_SETFAIL(RHeap::EDeterministic, fail);
       
   157 		__UHEAP_MARK;
       
   158 		TRAPD(ret, resourceLoader.OpenL(fileName));
       
   159 		TEST((ret == KErrNone) || (ret == KErrNoMemory));
       
   160 		if (ret == KErrNone)
       
   161 			{
       
   162 			resourceLoader.Close();
       
   163 			__UHEAP_MARKEND;
       
   164 			break;
       
   165 			}
       
   166 		__UHEAP_MARKEND;
       
   167 		}
       
   168 	__UHEAP_RESET;	
       
   169 	}
       
   170 
       
   171 /**
       
   172    Destructor
       
   173  */
       
   174 CTConeResourceLoaderStep::~CTConeResourceLoaderStep()
       
   175 	{
       
   176 	}
       
   177 
       
   178 /**
       
   179    Constructor
       
   180  */	
       
   181 CTConeResourceLoaderStep::CTConeResourceLoaderStep()
       
   182 	{
       
   183 	// Call base class method to set up the human readable name for logging
       
   184 	SetTestStepName(KTConeResourceLoader);
       
   185 	}
       
   186 	
       
   187 void CTConeResourceLoaderStep::ConstructAppL(CEikonEnv* aEikEnv)
       
   188 	{
       
   189 	aEikEnv->ConstructL();
       
   190 	CTConeResourceLoaderAppUi* appUi=new(ELeave) CTConeResourceLoaderAppUi(*this);
       
   191 	appUi->ConstructL();
       
   192 	aEikEnv->SetAppUi(appUi);
       
   193 	}
       
   194 
       
   195 TVerdict CTConeResourceLoaderStep::doTestStepL()
       
   196 	{
       
   197 	INFO_PRINTF1(_L("Cone Resource Loader Test"));
       
   198 	__UHEAP_MARK;
       
   199 
       
   200 	CEikonEnv* coe = new(ELeave) CEikonEnv;
       
   201 	TRAPD(err, ConstructAppL(coe));
       
   202 	if (!err)
       
   203 		coe->ExecuteD();
       
   204 	else
       
   205 		{
       
   206 		SetTestStepResult(EFail);
       
   207 		delete coe;
       
   208 		}
       
   209 
       
   210 	INFO_PRINTF1(_L("Test Finished"));
       
   211 
       
   212 	__UHEAP_MARKEND;
       
   213 	return TestStepResult();
       
   214 	}