mmtestenv/mmtestfwunittest/src/tsu_mmtsth20/TSU_MmTsth20.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2002-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 // This file contains the test steps for Unit Test Suite 20 : TestFrameworkServer.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // Test system includes
       
    22 #include <testframework.h>
       
    23 
       
    24 // Specific includes for this test suite
       
    25 #include "TSU_MmTsthSuite20.h"
       
    26 
       
    27 // Specific includes for these test steps
       
    28 #include "TSU_MmTsth20.h"
       
    29 #include "TestFrameworkServer/TestFrameworkServer.h"
       
    30 
       
    31 // --------------------------------------------
       
    32 
       
    33 // Unit Test Suite 20 : TestFrameworkServer.cpp
       
    34 // Depends on : TestFrameworkClient (running)
       
    35 // Needs : LogFile.cpp, ServerConsole.cpp
       
    36 
       
    37 // Tests :-
       
    38 
       
    39 //	1. verify that a CTestFrameworkServer is running
       
    40 //	2. verify that a CTestFrameworkServerSession is running
       
    41 
       
    42 // (CTestFrameworkServerShutdown is a private utility class)
       
    43 // (TWindow is private and obsolete; will be removed)
       
    44 
       
    45 // NB : to test within the TestFramework, we can't open a new server (it's already
       
    46 // running) - nor can we access the private API's of Server and ServerSession
       
    47 // The tests will validate that the server and session are already running.
       
    48 
       
    49 
       
    50 // --------------------------------------------
       
    51 // RTestMmTsthU2001
       
    52 
       
    53 RTestMmTsthU2001* RTestMmTsthU2001::NewL()
       
    54 	{
       
    55 	RTestMmTsthU2001* self = new(ELeave) RTestMmTsthU2001;
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 // Each test step initialises its own name.
       
    60 RTestMmTsthU2001::RTestMmTsthU2001()
       
    61 	{
       
    62 	iTestStepName = _L("MM-TSTH-U-2001");
       
    63 	}
       
    64 
       
    65 // Do the test step.
       
    66 TVerdict RTestMmTsthU2001::DoTestStepL()
       
    67 	{
       
    68 	INFO_PRINTF1(_L("Unit test for TestFrameworkServer - Server"));
       
    69 
       
    70 	// we can't construct a server - it's already running. Attempts to construct
       
    71 	// again will leave.
       
    72 	// Test :- Check it's running, by trying to construct it again. Trap the leave.
       
    73 
       
    74 	TVerdict currentVerdict = EPass;
       
    75 
       
    76 	// create and install the active scheduler we need
       
    77 	CActiveScheduler* theScheduler = new(ELeave) CActiveScheduler;
       
    78 	CleanupStack::PushL(theScheduler);
       
    79 	CActiveScheduler::Install(theScheduler);
       
    80 	//
       
    81 
       
    82 	CMmfIpcServer* theServer = NULL;
       
    83 	TRAPD(err, theServer = CTestFrameworkServer::NewL());
       
    84 	if(err != KErrAlreadyExists)
       
    85 		{
       
    86 		TPtrC errortxt = CLog::EpocErrorToText(err);
       
    87 		ERR_PRINTF2(_L("Server not already running, create returned %S"), &errortxt);
       
    88 		delete theServer;
       
    89 		currentVerdict = EFail;
       
    90 		}
       
    91 	else
       
    92 		{
       
    93 		TPtrC errortxt = CLog::EpocErrorToText(err);
       
    94 		INFO_PRINTF2(_L("Server already running, create returned %S"), &errortxt);
       
    95 		}
       
    96 
       
    97 	// Cleanup the scheduler
       
    98 	CleanupStack::PopAndDestroy(theScheduler);
       
    99 
       
   100 	return iTestStepResult = currentVerdict; // should be EPass if we've got here
       
   101 	}
       
   102 
       
   103 // ------------------------
       
   104 // RTestMmTsthU2002
       
   105 
       
   106 RTestMmTsthU2002* RTestMmTsthU2002::NewL()
       
   107 	{
       
   108 	RTestMmTsthU2002* self = new(ELeave) RTestMmTsthU2002;
       
   109 	return self;
       
   110 	}
       
   111 
       
   112 // Each test step initialises its own name.
       
   113 RTestMmTsthU2002::RTestMmTsthU2002()
       
   114 	{
       
   115 	// store the name of this test case
       
   116 	// this is the name that is used by the script file
       
   117 	iTestStepName = _L("MM-TSTH-U-2002");
       
   118 	}
       
   119 
       
   120 // Do the test step.
       
   121 TVerdict RTestMmTsthU2002::DoTestStepL()
       
   122 	{
       
   123 	INFO_PRINTF1(_L("Unit test for TestFrameworkServer - Server Session"));
       
   124 
       
   125 	TVerdict currentVerdict = EPass;
       
   126 
       
   127 	// create and install the active scheduler we need
       
   128 	CActiveScheduler* theScheduler = new(ELeave) CActiveScheduler;
       
   129 	CleanupStack::PushL(theScheduler);
       
   130 	CActiveScheduler::Install(theScheduler);
       
   131 	//
       
   132 
       
   133 	CMmfIpcServer* theServer = NULL;
       
   134 	TRAPD(err, theServer = CTestFrameworkServer::NewL());
       
   135 	if(err != KErrAlreadyExists)
       
   136 		{
       
   137 		TPtrC errortxt = CLog::EpocErrorToText(err);
       
   138 		ERR_PRINTF2(_L("Server not already running, create returned %S"), &errortxt);
       
   139 		delete theServer;
       
   140 		CleanupStack::PopAndDestroy(theScheduler);
       
   141 		return iTestStepResult = EInconclusive;
       
   142 		}
       
   143 
       
   144 	// setup local logger - this will cause a server session to be created
       
   145 	// (we can't get a handle to it!)
       
   146 	CLog* logClient	= CLog::NewLC();
       
   147 	logClient->OpenLogFileL();
       
   148 
       
   149 	TInt status = logClient->LogStatus();
       
   150 	// this will have retrieved log status from the server - the value is dependent on
       
   151 	// params passed into TestFramework, but in all cases will be nonzero. this demonstrates
       
   152 	// that a server session is running
       
   153 	if(status == 0)
       
   154 		{
       
   155 		ERR_PRINTF1(_L("Log status is zero - server session may not be running"));
       
   156 		currentVerdict = EFail;
       
   157 		}
       
   158 	else
       
   159 		{
       
   160 		INFO_PRINTF2(_L("Log status %d retrieved from server session"), status);
       
   161 		currentVerdict = EPass;
       
   162 		}
       
   163 
       
   164 	// cleanup the logger and the scheduler
       
   165 	CleanupStack::PopAndDestroy(2); // logClient, theScheduler
       
   166 
       
   167 	return iTestStepResult = currentVerdict;
       
   168 	}