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