1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmtestenv/mmtestfwunittest/src/tsu_mmtsth20/TSU_MmTsth20.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,168 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// This file contains the test steps for Unit Test Suite 20 : TestFrameworkServer.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +// EPOC includes
1.22 +#include <e32base.h>
1.23 +
1.24 +// Test system includes
1.25 +#include <testframework.h>
1.26 +
1.27 +// Specific includes for this test suite
1.28 +#include "TSU_MmTsthSuite20.h"
1.29 +
1.30 +// Specific includes for these test steps
1.31 +#include "TSU_MmTsth20.h"
1.32 +#include "TestFrameworkServer/TestFrameworkServer.h"
1.33 +
1.34 +// --------------------------------------------
1.35 +
1.36 +// Unit Test Suite 20 : TestFrameworkServer.cpp
1.37 +// Depends on : TestFrameworkClient (running)
1.38 +// Needs : LogFile.cpp, ServerConsole.cpp
1.39 +
1.40 +// Tests :-
1.41 +
1.42 +// 1. verify that a CTestFrameworkServer is running
1.43 +// 2. verify that a CTestFrameworkServerSession is running
1.44 +
1.45 +// (CTestFrameworkServerShutdown is a private utility class)
1.46 +// (TWindow is private and obsolete; will be removed)
1.47 +
1.48 +// NB : to test within the TestFramework, we can't open a new server (it's already
1.49 +// running) - nor can we access the private API's of Server and ServerSession
1.50 +// The tests will validate that the server and session are already running.
1.51 +
1.52 +
1.53 +// --------------------------------------------
1.54 +// RTestMmTsthU2001
1.55 +
1.56 +RTestMmTsthU2001* RTestMmTsthU2001::NewL()
1.57 + {
1.58 + RTestMmTsthU2001* self = new(ELeave) RTestMmTsthU2001;
1.59 + return self;
1.60 + }
1.61 +
1.62 +// Each test step initialises its own name.
1.63 +RTestMmTsthU2001::RTestMmTsthU2001()
1.64 + {
1.65 + iTestStepName = _L("MM-TSTH-U-2001");
1.66 + }
1.67 +
1.68 +// Do the test step.
1.69 +TVerdict RTestMmTsthU2001::DoTestStepL()
1.70 + {
1.71 + INFO_PRINTF1(_L("Unit test for TestFrameworkServer - Server"));
1.72 +
1.73 + // we can't construct a server - it's already running. Attempts to construct
1.74 + // again will leave.
1.75 + // Test :- Check it's running, by trying to construct it again. Trap the leave.
1.76 +
1.77 + TVerdict currentVerdict = EPass;
1.78 +
1.79 + // create and install the active scheduler we need
1.80 + CActiveScheduler* theScheduler = new(ELeave) CActiveScheduler;
1.81 + CleanupStack::PushL(theScheduler);
1.82 + CActiveScheduler::Install(theScheduler);
1.83 + //
1.84 +
1.85 + CMmfIpcServer* theServer = NULL;
1.86 + TRAPD(err, theServer = CTestFrameworkServer::NewL());
1.87 + if(err != KErrAlreadyExists)
1.88 + {
1.89 + TPtrC errortxt = CLog::EpocErrorToText(err);
1.90 + ERR_PRINTF2(_L("Server not already running, create returned %S"), &errortxt);
1.91 + delete theServer;
1.92 + currentVerdict = EFail;
1.93 + }
1.94 + else
1.95 + {
1.96 + TPtrC errortxt = CLog::EpocErrorToText(err);
1.97 + INFO_PRINTF2(_L("Server already running, create returned %S"), &errortxt);
1.98 + }
1.99 +
1.100 + // Cleanup the scheduler
1.101 + CleanupStack::PopAndDestroy(theScheduler);
1.102 +
1.103 + return iTestStepResult = currentVerdict; // should be EPass if we've got here
1.104 + }
1.105 +
1.106 +// ------------------------
1.107 +// RTestMmTsthU2002
1.108 +
1.109 +RTestMmTsthU2002* RTestMmTsthU2002::NewL()
1.110 + {
1.111 + RTestMmTsthU2002* self = new(ELeave) RTestMmTsthU2002;
1.112 + return self;
1.113 + }
1.114 +
1.115 +// Each test step initialises its own name.
1.116 +RTestMmTsthU2002::RTestMmTsthU2002()
1.117 + {
1.118 + // store the name of this test case
1.119 + // this is the name that is used by the script file
1.120 + iTestStepName = _L("MM-TSTH-U-2002");
1.121 + }
1.122 +
1.123 +// Do the test step.
1.124 +TVerdict RTestMmTsthU2002::DoTestStepL()
1.125 + {
1.126 + INFO_PRINTF1(_L("Unit test for TestFrameworkServer - Server Session"));
1.127 +
1.128 + TVerdict currentVerdict = EPass;
1.129 +
1.130 + // create and install the active scheduler we need
1.131 + CActiveScheduler* theScheduler = new(ELeave) CActiveScheduler;
1.132 + CleanupStack::PushL(theScheduler);
1.133 + CActiveScheduler::Install(theScheduler);
1.134 + //
1.135 +
1.136 + CMmfIpcServer* theServer = NULL;
1.137 + TRAPD(err, theServer = CTestFrameworkServer::NewL());
1.138 + if(err != KErrAlreadyExists)
1.139 + {
1.140 + TPtrC errortxt = CLog::EpocErrorToText(err);
1.141 + ERR_PRINTF2(_L("Server not already running, create returned %S"), &errortxt);
1.142 + delete theServer;
1.143 + CleanupStack::PopAndDestroy(theScheduler);
1.144 + return iTestStepResult = EInconclusive;
1.145 + }
1.146 +
1.147 + // setup local logger - this will cause a server session to be created
1.148 + // (we can't get a handle to it!)
1.149 + CLog* logClient = CLog::NewLC();
1.150 + logClient->OpenLogFileL();
1.151 +
1.152 + TInt status = logClient->LogStatus();
1.153 + // this will have retrieved log status from the server - the value is dependent on
1.154 + // params passed into TestFramework, but in all cases will be nonzero. this demonstrates
1.155 + // that a server session is running
1.156 + if(status == 0)
1.157 + {
1.158 + ERR_PRINTF1(_L("Log status is zero - server session may not be running"));
1.159 + currentVerdict = EFail;
1.160 + }
1.161 + else
1.162 + {
1.163 + INFO_PRINTF2(_L("Log status %d retrieved from server session"), status);
1.164 + currentVerdict = EPass;
1.165 + }
1.166 +
1.167 + // cleanup the logger and the scheduler
1.168 + CleanupStack::PopAndDestroy(2); // logClient, theScheduler
1.169 +
1.170 + return iTestStepResult = currentVerdict;
1.171 + }