sysstatemgmt/systemstarter/test/testapprvafterretry/testapprvafterretry.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 <eikstart.h> 
       
    23 #include <eikapp.h>
       
    24 #include "testapprvafterretry.h"
       
    25 #include "testapps.h"
       
    26 
       
    27 
       
    28 /**
       
    29 Standard DLL entry point function.
       
    30 Creates and returns an instance of the CApaApplication-derived class.
       
    31 @return an instance of the CApaApplication-derived class
       
    32 */
       
    33 TInt E32Main()
       
    34 	{
       
    35 	return EikStart::RunApplication( CTestApplication::NewApplication );
       
    36 	}
       
    37 
       
    38 CTestApplication::CTestApplication()
       
    39 	{
       
    40 	}
       
    41 
       
    42 CTestApplication::~CTestApplication()
       
    43 	{
       
    44 	}
       
    45 		
       
    46 /**
       
    47 @return The application's UID 
       
    48 */
       
    49 TUid CTestApplication::AppDllUid() const
       
    50 	{
       
    51 	const TUid dll = {KTestAppRvAfterRetryUid};
       
    52 	return dll;
       
    53 	}
       
    54 
       
    55 /**
       
    56 @return CTestApplication or NULL if KErrNoMemory
       
    57 */
       
    58 CApaApplication* CTestApplication::NewApplication()
       
    59 	{
       
    60 	// As the framework has at this point not started up enough, and therefore the TRAP-harness and 
       
    61 	// exception handlers aren’t available yet, this factory function is a non-leaving function and 
       
    62 	// can't use the new(Eleave) operator.
       
    63 	return new CTestApplication();
       
    64 	}
       
    65 	
       
    66 /**
       
    67 Called by the UI framework at application start-up to create an instance of the document class.
       
    68 @leave	KErrNoMemory
       
    69 @return A CTestDocument
       
    70 */
       
    71 CApaDocument* CTestApplication::CreateDocumentL()
       
    72 	{
       
    73 	return CTestDocument::NewL(*this);
       
    74 	}
       
    75 
       
    76 CTestDocument::CTestDocument(CEikApplication& aApp) : CEikDocument(aApp)
       
    77 	{
       
    78 	}
       
    79 
       
    80 CTestDocument::~CTestDocument()
       
    81 	{
       
    82 	}
       
    83 
       
    84 /**
       
    85 Factory function for this class
       
    86 @return a new CEndTaskTestDocument instance.
       
    87 */
       
    88 CTestDocument* CTestDocument::NewL(CEikApplication& aApp)
       
    89 	{
       
    90 	return new(ELeave) CTestDocument(aApp);
       
    91 	}
       
    92 
       
    93 
       
    94 
       
    95 /**
       
    96 Called by the UI framework to construct the application UI class. 
       
    97 Note that the app UI's ConstructL() is called by the UI framework.
       
    98 */
       
    99 CEikAppUi* CTestDocument::CreateAppUiL()
       
   100 	{
       
   101 	return new(ELeave) CTestAppUi();
       
   102 	}
       
   103 
       
   104 
       
   105 
       
   106 CTestAppUi::CTestAppUi()
       
   107 	{
       
   108 	}
       
   109 
       
   110 
       
   111 
       
   112 CTestAppUi::~CTestAppUi()
       
   113 	{
       
   114 	}
       
   115 
       
   116 
       
   117 
       
   118 void CTestAppUi::ConstructL()
       
   119 	{
       
   120 	// Complete the UI framework's construction of the App UI.
       
   121 	BaseConstructL(CEikAppUi::ENoAppResourceFile);
       
   122 	}
       
   123 
       
   124 
       
   125 
       
   126 /**
       
   127  Overload of the CCoeAppUi virtual method.
       
   128  The method in the base class merely returns ETrue. Overloads would normally just return EFalse.
       
   129  In this case however, we do some jiggery-pokery in order to invoke the StartSafe retry mechanism.
       
   130  ie we return EFalse on each of several invocations but don't do the Rendezvous, then 
       
   131  eventually ETrue, so the Framework Rendezvous for us. our final invocation therefore being successful.
       
   132  
       
   133  The count file is written from the test-step, and 
       
   134  if successful, deleted here.
       
   135  
       
   136  The code is nearly all parenthesised within a TRAP harness in order to preserve the integrity 
       
   137  of this function, which is called by the framework.
       
   138 
       
   139 */
       
   140 TBool CTestAppUi::FrameworkCallsRendezvous() const
       
   141 	{
       
   142 	
       
   143 	TBool frameworkRendezvous = EFalse;
       
   144 
       
   145 	TRAPD( err,
       
   146 		{			
       
   147 		RFs fs;
       
   148 		RFileReadStream readStream;
       
   149 		RFileWriteStream writeStream;
       
   150 						
       
   151 		CleanupClosePushL( fs );
       
   152 		CleanupClosePushL( readStream );
       
   153 		CleanupClosePushL( writeStream );
       
   154 		
       
   155 			
       
   156 		if( KErrNone != fs.Connect()
       
   157 		 || KErrNone != readStream.Open(fs, KDontRvCountFile, EFileRead) )
       
   158 			{
       
   159 			User::Leave( KErrCouldNotConnect );	
       
   160 			}
       
   161 		
       
   162 
       
   163 		TInt failCount = readStream.ReadInt8L();
       
   164 		readStream.Close();	
       
   165 		
       
   166 
       
   167 		if( 0 == failCount )
       
   168 			{
       
   169 			fs.Delete( KDontRvCountFile );
       
   170 			
       
   171 			// We've decided to be good this time. Let the framework do it for us.
       
   172 			frameworkRendezvous = ETrue;
       
   173 			}
       
   174 		else
       
   175 			{
       
   176 			// StartSafe will timeout while waiting for a Rendezvous()
       
   177 			User::LeaveIfError( writeStream.Open(fs, KDontRvCountFile, EFileWrite) );
       
   178 	
       
   179 			writeStream.WriteInt8L( --failCount );
       
   180 			writeStream.CommitL();
       
   181 			writeStream.Close();
       
   182 			}
       
   183 			
       
   184 		CleanupStack::PopAndDestroy( 3, &fs );
       
   185 		} );
       
   186 		
       
   187 		
       
   188 	// In the case of error, returning Efalse will mean that StartSafe 
       
   189 	// times out. The test will therefore fail.
       
   190 	return ( KErrNone == err ) ? frameworkRendezvous : EFalse;
       
   191 	}