sysstatemgmt/systemstatemgr/test/testapps/src/ssmcletestapplication.cpp
changeset 0 4e1aa6a622a0
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 "ssmcletestapplication.h"
       
    25 #include "ssmcletestapp.h"
       
    26 #include "ssmtestapps.h"
       
    27 
       
    28 static void RunL()
       
    29 	{
       
    30 	TSsmCleTestAppArgs args;
       
    31 	XSsmCleTestApp::GetCommandLineArgsL(args);
       
    32 	RFs fs;
       
    33 	User::LeaveIfError(fs.Connect());
       
    34 	CleanupClosePushL(fs);
       
    35 	TInt count = XSsmCleTestApp::GetRunCountL(fs, args.iLogPrefix);
       
    36 	
       
    37 	if (0 == count)
       
    38 		{
       
    39 		XSsmCleTestApp::WriteStartTimeL(fs, args.iLogPrefix);
       
    40 		}
       
    41 	TInt newCount = XSsmCleTestApp::IncrementRunCountL(fs, args.iLogPrefix);
       
    42 	
       
    43 	if ((args.iSucceedOnRun == 0)  && (args.iWaitTime > 0))
       
    44 		{
       
    45 		User::After(args.iWaitTime * 1000); 
       
    46 		}
       
    47 	
       
    48 	if ((args.iSucceedOnRun != 0) && (args.iSucceedOnRun > count) && (args.iWaitTime > 0))
       
    49 		{
       
    50 		User::After(args.iWaitTime * 1000); 
       
    51 		}
       
    52 
       
    53 	XSsmCleTestApp::WriteResultL(fs, args.iLogPrefix,args.iFailHow);
       
    54 	CleanupStack::PopAndDestroy(&fs);
       
    55 	switch (args.iFailHow) //Other failure modes don't require special action
       
    56 		{
       
    57 		case EDontFail:
       
    58 			{
       
    59 			if ((args.iSucceedOnRun == 0) || ((args.iSucceedOnRun > 0) && (count >= args.iSucceedOnRun)))
       
    60 				{
       
    61 				RProcess::Rendezvous(KErrNone);
       
    62 				}
       
    63 			else
       
    64 				{
       
    65 				RProcess::Rendezvous(KErrGeneral);
       
    66 				}
       
    67 			break;
       
    68 			}
       
    69 		case EPanic:
       
    70 			{
       
    71 			User::Panic(_L("SSMTEST"), KSsmCleTestPanic);
       
    72 			break;
       
    73 			}
       
    74 		case EBadRendezvous:
       
    75 			{
       
    76 			RProcess::Rendezvous(KErrGeneral);
       
    77 			break;
       
    78 			}
       
    79 		case ENoRendezvous:
       
    80 		case EMultipleTimeout:
       
    81 			{
       
    82 			User::After(10000000); // 10 seconds
       
    83 			break;
       
    84 			}
       
    85 		}
       
    86 	
       
    87 	RSemaphore sem;
       
    88 	TInt err = sem.OpenGlobal(KStartAppSignalSemaphore);
       
    89 	RDebug::Print(_L("KStartAppSignalSemaphore Opened with %d"), err);
       
    90 	
       
    91 	if(err == KErrNone)
       
    92 		{
       
    93 		sem.Signal();
       
    94 		sem.Close();
       
    95 		}
       
    96 	}
       
    97 
       
    98 /**
       
    99 Standard DLL entry point function.
       
   100 Creates and returns an instance of the CApaApplication-derived class.
       
   101 @return an instance of the CApaApplication-derived class
       
   102 */
       
   103 TInt E32Main()
       
   104 	{
       
   105 	__UHEAP_MARK;
       
   106 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   107 	TInt r=KErrNoMemory;
       
   108 	if (cleanup)
       
   109 		{
       
   110 		TRAP(r,RunL());
       
   111 		delete cleanup;
       
   112 		}
       
   113 
       
   114 	if (KErrNone != r)
       
   115 		{
       
   116 		User::Panic(_L("CLETEST"),r);
       
   117 		}
       
   118 	__UHEAP_MARKEND;
       
   119 	
       
   120 	//This process will return to the user and thus be terminated without cleaning up properly
       
   121 	//To avoid this we give a wait for request so that we can explicitly clean it up
       
   122 	TRequestStatus status = KRequestPending;
       
   123 	User::WaitForRequest(status);
       
   124 	return EikStart::RunApplication( CTestApplication::NewApplication);
       
   125 	}
       
   126 	
       
   127 CTestApplication::CTestApplication()
       
   128 	{
       
   129 	}
       
   130 
       
   131 CTestApplication::~CTestApplication()
       
   132 	{
       
   133 	}
       
   134 		
       
   135 /**
       
   136 @return The application's UID 
       
   137 */
       
   138 TUid CTestApplication::AppDllUid() const
       
   139 	{
       
   140 	const TUid dll = {KSsmCleTestApplicationUid};
       
   141 	return dll;
       
   142 	}
       
   143 
       
   144 /**
       
   145 @return CTestApplication or NULL if KErrNoMemory
       
   146 */
       
   147 CApaApplication* CTestApplication::NewApplication()
       
   148 	{
       
   149 	// As the framework has at this point not started up enough, and therefore the TRAP-harness and 
       
   150 	// exception handlers aren’t available yet, this factory function is a non-leaving function and 
       
   151 	// can't use the new(Eleave) operator.
       
   152 	return new CTestApplication();
       
   153 	}
       
   154 	
       
   155 /**
       
   156 Called by the UI framework at application start-up to create an instance of the document class.
       
   157 @leave	KErrNoMemory
       
   158 @return A CTestDocument
       
   159 */
       
   160 CApaDocument* CTestApplication::CreateDocumentL()
       
   161 	{
       
   162 	return CTestDocument::NewL(*this);
       
   163 	}
       
   164 
       
   165 CTestDocument::CTestDocument(CEikApplication& aApp) : CEikDocument(aApp)
       
   166 	{
       
   167 	}
       
   168 
       
   169 CTestDocument::~CTestDocument()
       
   170 	{
       
   171 	}
       
   172 
       
   173 /**
       
   174 Factory function for this class
       
   175 @return a new CEndTaskTestDocument instance.
       
   176 */
       
   177 CTestDocument* CTestDocument::NewL(CEikApplication& aApp)
       
   178 	{
       
   179 	return new(ELeave) CTestDocument(aApp);
       
   180 	}
       
   181 
       
   182 
       
   183 /**
       
   184 Called by the UI framework to construct the application UI class. 
       
   185 Note that the app UI's ConstructL() is called by the UI framework.
       
   186 */
       
   187 CEikAppUi* CTestDocument::CreateAppUiL()
       
   188 	{
       
   189 	return new(ELeave) CTestAppUi();
       
   190 	}
       
   191 
       
   192 CTestAppUi::CTestAppUi()
       
   193 	{
       
   194 	}
       
   195 
       
   196 CTestAppUi::~CTestAppUi()
       
   197 	{
       
   198 	}
       
   199 
       
   200 void CTestAppUi::ConstructL()
       
   201 	{
       
   202 	// Complete the UI framework's construction of the App UI.
       
   203 	BaseConstructL(CEikAppUi::ENoAppResourceFile);
       
   204 	}
       
   205