sysstatemgmt/systemstateplugins/test/tappgsapolicy/src/sspluginstest_tappgsapolicy.cpp
changeset 0 4e1aa6a622a0
child 70 653a8b91b95e
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2008-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 <bautils.h>
       
    25 #include "sspluginstest_tappgsapolicy.h"
       
    26 
       
    27 //Fail to execute this exe for KDontRvBootCount times
       
    28 const TInt KDontRvBootCount = 3;
       
    29 _LIT(KBootUpFolder, ":\\private\\2000d75b\\bootupinfo\\");
       
    30 _LIT(KBootUpFile, "bootupcount.bin");
       
    31 
       
    32 /**
       
    33 Standard DLL entry point function.
       
    34 Creates and returns an instance of the CApaApplication-derived class.
       
    35 @return an instance of the CApaApplication-derived class
       
    36 */
       
    37 TInt E32Main()
       
    38 	{
       
    39 	return EikStart::RunApplication( CTestApplication::NewApplication );
       
    40 	}
       
    41 
       
    42 CTestApplication::CTestApplication()
       
    43 	{
       
    44 	}
       
    45 
       
    46 CTestApplication::~CTestApplication()
       
    47 	{
       
    48 	}
       
    49 		
       
    50 /**
       
    51 @return The application's UID 
       
    52 */
       
    53 TUid CTestApplication::AppDllUid() const
       
    54 	{
       
    55 	const TUid dll = {KTestAppReboots};
       
    56 	return dll;
       
    57 	}
       
    58 
       
    59 /**
       
    60 @return CTestApplication or NULL if KErrNoMemory
       
    61 */
       
    62 CApaApplication* CTestApplication::NewApplication()
       
    63 	{
       
    64 	// As the framework has at this point not started up enough, and therefore the TRAP-harness and 
       
    65 	// exception handlers aren’t available yet, this factory function is a non-leaving function and 
       
    66 	// can't use the new(Eleave) operator.
       
    67 	return new CTestApplication();
       
    68 	}
       
    69 	
       
    70 /**
       
    71 Called by the UI framework at application start-up to create an instance of the document class.
       
    72 @leave	KErrNoMemory
       
    73 @return A CTestDocument
       
    74 */
       
    75 CApaDocument* CTestApplication::CreateDocumentL()
       
    76 	{
       
    77 	return CTestDocument::NewL(*this);
       
    78 	}
       
    79 
       
    80 CTestDocument::CTestDocument(CEikApplication& aApp) : CEikDocument(aApp)
       
    81 	{
       
    82 	}
       
    83 
       
    84 CTestDocument::~CTestDocument()
       
    85 	{
       
    86 	}
       
    87 
       
    88 /**
       
    89 Factory function for this class
       
    90 @return a new CEndTaskTestDocument instance.
       
    91 */
       
    92 CTestDocument* CTestDocument::NewL(CEikApplication& aApp)
       
    93 	{
       
    94 	return new(ELeave) CTestDocument(aApp);
       
    95 	}
       
    96 
       
    97 
       
    98 /**
       
    99 Called by the UI framework to construct the application UI class. 
       
   100 Note that the app UI's ConstructL() is called by the UI framework.
       
   101 */
       
   102 CEikAppUi* CTestDocument::CreateAppUiL()
       
   103 	{
       
   104 	return new(ELeave) CTestAppUi();
       
   105 	}
       
   106 
       
   107 CTestAppUi::CTestAppUi()
       
   108 	{
       
   109 	}
       
   110 
       
   111 CTestAppUi::~CTestAppUi()
       
   112 	{
       
   113 	}
       
   114 
       
   115 void CTestAppUi::ConstructL()
       
   116 	{
       
   117 	// Complete the UI framework's construction of the App UI.
       
   118 	BaseConstructL(CEikAppUi::ENoAppResourceFile);
       
   119 	}
       
   120 
       
   121 /**
       
   122  Overload of the CCoeAppUi virtual method.
       
   123  The method in the base class merely returns ETrue. Overloads would normally just return EFalse.
       
   124  In this case however, we do some jiggery-pokery in order to invoke the ssma retry mechanism.
       
   125  ie we panic for KDontRvBootCount invocations but don't do the Rendezvous, then  eventually ETrue, so the Framework 
       
   126  Rendezvous for us. our final invocation therefore being successful.
       
   127  
       
   128  This particular test case can be used to test following
       
   129  1.Transitions to fail 
       
   130  	To test above need to set KDontRvBootCount to KSsmMaxBootAttempts+1.
       
   131  2.Persisted number of consecutive failed device start-ups
       
   132  	To test above feature need set KDontRvBootCount to KSsmMaxBootAttempts
       
   133  3.Transitions to restart to infinite times.
       
   134  	To test above feature set KDontRvBootCount and KSsmMaxBootAttempts to 0xFFFFFFFF      	
       
   135 */
       
   136 void DoFrameworkCallsRendezvousL();
       
   137 
       
   138 TBool CTestAppUi::FrameworkCallsRendezvous() const
       
   139 	{	
       
   140 	TRAPD(err,DoFrameworkCallsRendezvousL());
       
   141 	return ( KErrNone == err ) ? ETrue : EFalse;
       
   142 	}
       
   143 
       
   144 void DoFrameworkCallsRendezvousL()
       
   145 	{
       
   146 	RFs fs;
       
   147 	User::LeaveIfError(fs.Connect());
       
   148 	CleanupClosePushL(fs);
       
   149 	RBuf bootupInfoPath;
       
   150 	CleanupClosePushL( bootupInfoPath );
       
   151 	const TChar drive = RFs::GetSystemDriveChar();
       
   152 	TInt length = KBootUpFolder().Length() + KBootUpFile().Length() + 1 /* for RFs::GetSystemDriveChar() */;
       
   153 	bootupInfoPath.CreateL(length);
       
   154 	bootupInfoPath.Append(drive);
       
   155 	bootupInfoPath.Append(KBootUpFolder());
       
   156 	bootupInfoPath.Append(KBootUpFile());
       
   157 	
       
   158 	TBool found = BaflUtils::FileExists(fs, bootupInfoPath);
       
   159 	TInt bootCount = 0;
       
   160 	if(found)
       
   161 		{
       
   162 		RFileReadStream file;
       
   163 		CleanupClosePushL(file);
       
   164 		User::LeaveIfError(file.Open(fs, bootupInfoPath, EFileRead));
       
   165 		bootCount = file.ReadUint8L();
       
   166 		RDebug::Printf("--- CTestAppUi::FrameworkCallsRendezvous() bootcount %d", bootCount);
       
   167 		CleanupStack::PopAndDestroy( &file );
       
   168 		}
       
   169 	CleanupStack::PopAndDestroy( &bootupInfoPath );
       
   170 	CleanupStack::PopAndDestroy( &fs );
       
   171 	if( bootCount < KDontRvBootCount )
       
   172 		{
       
   173 		_LIT(KMainErrorStatement, "*** Program error in Starting sspluginstest_tappgsapolicy.exe: %d");
       
   174 		RDebug::Print(KMainErrorStatement, KErrNone);
       
   175 	   	User::Panic(KMainErrorStatement,KErrNone);
       
   176 		}
       
   177 	}