messagingappbase/obexmtms/TObexMTM/testutils/msgth/src/harness.cpp
changeset 80 8b14b30db193
parent 0 72b543305e3a
equal deleted inserted replaced
79:2981cb3aa489 80:8b14b30db193
       
     1 // Copyright (c) 2003-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 #include "testframeutils.h"
       
    17 #include "parsers.h"
       
    18 #include "commands.h"
       
    19 #include "msvtestutils.h"
       
    20 
       
    21 
       
    22 //
       
    23 //
       
    24 // DLL Entry
       
    25 //
       
    26 
       
    27 //
       
    28 //
       
    29 // CActiveTestState
       
    30 //
       
    31 
       
    32 EXPORT_C CActiveTestState::CActiveTestState(TInt aPriority) : CActive(aPriority)
       
    33 	{
       
    34 	}
       
    35 
       
    36 EXPORT_C TInt CActiveTestState::RunError(TInt aError)
       
    37 	{
       
    38 	User::RequestComplete(iReportStatus, aError);
       
    39 	return KErrNone;
       
    40 	}
       
    41 
       
    42 
       
    43 //
       
    44 //
       
    45 // CBaseTestHarness
       
    46 //
       
    47 
       
    48 EXPORT_C CBaseTestHarness::~CBaseTestHarness()
       
    49 	{
       
    50 	iStateList->ResetAndDestroy();
       
    51 	delete iStateList;
       
    52 	}
       
    53 
       
    54 EXPORT_C void CBaseTestHarness::StartL(TRequestStatus& aStatus)
       
    55 	{
       
    56 	TTestDebugInfo debugInfo = GetDebugInfo();
       
    57 	HBufC* startString = debugInfo.TestStartStringLC();
       
    58 	LogCommentL(*startString);
       
    59 	TestConsole().Printf(*startString);
       
    60 	TestConsole().Printf(_L("\n"));
       
    61 
       
    62 	CleanupStack::PopAndDestroy(startString);
       
    63 	iCurrentState = 0;
       
    64 	iReportStatus = &aStatus;
       
    65 	
       
    66 	if (iCurrentState < iStateList->Count())
       
    67 		{
       
    68 		TTestDebugInfo moreInfo=(*iStateList)[iCurrentState]->GetDebugInfo();
       
    69 		HBufC* debugString=moreInfo.TestStartStringLC();
       
    70 		TestConsole().Printf(*debugString);
       
    71 		TestConsole().Printf(_L("\r"));
       
    72 		CleanupStack::PopAndDestroy(debugString);
       
    73 
       
    74 		(*iStateList)[iCurrentState]->StartL(iStatus);
       
    75 		}
       
    76 
       
    77 	aStatus = KRequestPending;
       
    78 	SetActive();
       
    79 	}
       
    80 
       
    81 
       
    82 EXPORT_C void CBaseTestHarness::AddStateL(MBaseTestState* aTestState, TTestDebugInfo aDebugInfo)
       
    83 	{
       
    84 	aTestState->SetDebugInfo(aDebugInfo);
       
    85 	TRAPD(err, iStateList->AppendL(aTestState));
       
    86 	if (err != KErrNone)
       
    87 		// If the state can't be added then delete it.
       
    88 		// We do this because we have taken ownership of the state.
       
    89 		{
       
    90 		delete aTestState;
       
    91 		User::Leave(err);
       
    92 		}
       
    93 	}
       
    94 
       
    95 
       
    96 // From CActive
       
    97 EXPORT_C void CBaseTestHarness::RunL()
       
    98 	{
       
    99 	if (iStatus == KErrNone)
       
   100 		{
       
   101 		iCurrentState++;
       
   102 		if (iCurrentState < iStateList->Count())
       
   103 			{
       
   104 			TTestDebugInfo moreInfo=(*iStateList)[iCurrentState]->GetDebugInfo();
       
   105 			HBufC* debugString=moreInfo.TestCompleteStringLC();
       
   106 			TestConsole().Printf(*debugString);
       
   107 			TestConsole().Printf(_L("\r"));
       
   108 			CleanupStack::PopAndDestroy(debugString);
       
   109 
       
   110 			(*iStateList)[iCurrentState]->StartL(iStatus);
       
   111 			SetActive();
       
   112 			}
       
   113 		else
       
   114 			{
       
   115 			TTestDebugInfo debugInfo = GetDebugInfo();
       
   116 			HBufC* testCompleted = debugInfo.TestCompleteStringLC();
       
   117 			LogCommentL(*testCompleted);
       
   118 
       
   119 			CleanupStack::PopAndDestroy(testCompleted);
       
   120 			User::RequestComplete(iReportStatus, iStatus.Int());
       
   121 			}
       
   122 		}
       
   123 	else
       
   124 		{
       
   125 		// Pass the debug info back from the child state and log the error
       
   126 		TTestDebugInfo debugInfo = (*iStateList)[iCurrentState]->GetDebugInfo();
       
   127 		SetDebugInfo(debugInfo);
       
   128 		HBufC* errorText = debugInfo.TestFailedStringL(iStatus.Int());
       
   129 		CleanupStack::PushL(errorText);
       
   130 		LogCommentL(*errorText);
       
   131 		TestConsole().Printf(*errorText);
       
   132 		TestConsole().Printf(_L("\r"));
       
   133 							  
       
   134 		CleanupStack::PopAndDestroy(errorText);
       
   135 		User::RequestComplete(iReportStatus, iStatus.Int());
       
   136 		}
       
   137 	}
       
   138 
       
   139 EXPORT_C void CBaseTestHarness::DoCancel()
       
   140 	{
       
   141 	}
       
   142 
       
   143 EXPORT_C void CBaseTestHarness::LogCommentL(const TDesC& /* aError */)
       
   144 	{
       
   145 	}
       
   146 
       
   147 EXPORT_C TInt CBaseTestHarness::RunError(TInt aError)
       
   148 	{
       
   149 	// Pass the debug info back from the child state and log the error
       
   150 	TTestDebugInfo debugInfo = (*iStateList)[iCurrentState]->GetDebugInfo();
       
   151 	SetDebugInfo(debugInfo);
       
   152 	aError = KErrNone;
       
   153 	HBufC* errorText = NULL;
       
   154 	TRAP(aError,
       
   155 		{
       
   156 		errorText=debugInfo.TestFailedStringL(aError);
       
   157 		LogCommentL(*errorText);
       
   158 		});
       
   159 		
       
   160 	TestConsole().Printf(*errorText);
       
   161 	TestConsole().Printf(_L("\r"));
       
   162 
       
   163 	delete errorText;
       
   164 	User::RequestComplete(iReportStatus, aError);
       
   165 	return aError;
       
   166 	}
       
   167 
       
   168 EXPORT_C void CBaseTestHarness::ConstructL()
       
   169 	{
       
   170 	CActiveScheduler::Add(this);
       
   171 	iStateList = new (ELeave) CArrayPtrFlat<MBaseTestState>(10);
       
   172 	}
       
   173 
       
   174 EXPORT_C CBaseTestHarness::CBaseTestHarness(RTest& aTest) : CActive(EPriorityHigh), iTest(aTest)
       
   175 	{
       
   176 	}
       
   177 
       
   178 EXPORT_C RTest& CBaseTestHarness::TestConsole()
       
   179 	{
       
   180 	return iTest;
       
   181 	}
       
   182 
       
   183 EXPORT_C void CBaseTestHarness::SetHeapFailureTesting(TBool aTest)
       
   184 	{
       
   185 	iTestHeapFailure = aTest;
       
   186 	}
       
   187 
       
   188 //
       
   189 //
       
   190 // CMainTestHarness
       
   191 //
       
   192 
       
   193 EXPORT_C CMainTestHarness* CMainTestHarness::NewL(RTest& aTest)
       
   194 	{
       
   195 	CMainTestHarness* self = new (ELeave) CMainTestHarness(aTest);
       
   196 	CleanupStack::PushL(self);
       
   197 	self->ConstructL();
       
   198 	CleanupStack::Pop(self);
       
   199 	return self;
       
   200 	}
       
   201 
       
   202 EXPORT_C void CMainTestHarness::ConstructL()
       
   203 	{
       
   204 	CBaseTestHarness::ConstructL();
       
   205 	}
       
   206 
       
   207 EXPORT_C CMainTestHarness::CMainTestHarness(RTest& aTest) : CBaseTestHarness(aTest)
       
   208 	{
       
   209 	}
       
   210 
       
   211 EXPORT_C void CMainTestHarness::StartL(TRequestStatus& aStatus)
       
   212 	{
       
   213 	CBaseTestHarness::StartL(aStatus);
       
   214 	}
       
   215 
       
   216 
       
   217 //
       
   218 //
       
   219 // CMsvClientTest
       
   220 //
       
   221 
       
   222 
       
   223 EXPORT_C CMsvClientTest* CMsvClientTest::NewL(CMsvTestUtils& aTestUtils, RTest& aTest)
       
   224 	{
       
   225 	CMsvClientTest* self = new (ELeave) CMsvClientTest(aTestUtils, aTest);
       
   226 	CleanupStack::PushL(self);
       
   227 	self->ConstructL();
       
   228 	CleanupStack::Pop(self);
       
   229 	return self;
       
   230 	}
       
   231 
       
   232 EXPORT_C CMsvClientTest* CMsvClientTest::NewL(CMsvTestUtils* aTestUtils, RTest& aTest)
       
   233 	{
       
   234 	CMsvClientTest* self = new (ELeave) CMsvClientTest(aTestUtils, aTest);
       
   235 	CleanupStack::PushL(self);
       
   236 	self->ConstructL();
       
   237 	CleanupStack::Pop(self);
       
   238 	return self;
       
   239 	}
       
   240 
       
   241 EXPORT_C CMsvClientTest::~CMsvClientTest()
       
   242 	{
       
   243 	Cancel();
       
   244 	delete iCurrentSelection;
       
   245 	delete iOperation;
       
   246 	}
       
   247 
       
   248 EXPORT_C void CMsvClientTest::DoCancel()
       
   249 	{
       
   250 	if (iOperation)
       
   251 		{
       
   252 		iOperation->Cancel();
       
   253 		}
       
   254 	}
       
   255 
       
   256 EXPORT_C void CMsvClientTest::SetCurrentOperation(CMsvOperation* aOperation)
       
   257 	{
       
   258 	delete iOperation;
       
   259 	iOperation = aOperation;
       
   260 	}
       
   261 
       
   262 
       
   263 EXPORT_C CMsvOperation& CMsvClientTest::CurrentOperation()
       
   264 	{
       
   265 	return *iOperation;
       
   266 	}
       
   267 
       
   268 EXPORT_C void CMsvClientTest::ConstructL()
       
   269 	{
       
   270 	CBaseTestHarness::ConstructL();
       
   271 	iCurrentSelection = new (ELeave) CMsvEntrySelection;
       
   272 	}
       
   273 
       
   274 EXPORT_C CMsvClientTest::CMsvClientTest(CMsvTestUtils& aMsvTestUtils, RTest& aTest) 
       
   275 : CBaseTestHarness(aTest), 
       
   276   iMsvTestUtils(aMsvTestUtils)
       
   277 	{
       
   278 	iOperation = NULL;
       
   279 	}
       
   280 
       
   281 EXPORT_C CMsvClientTest::CMsvClientTest(CMsvTestUtils* aMsvTestUtils, RTest& aTest) 
       
   282 : CBaseTestHarness(aTest), 
       
   283   iMsvTestUtils(*aMsvTestUtils),
       
   284   iOwnedMsvTestUtils(aMsvTestUtils)  
       
   285 	{
       
   286 	iOperation = NULL;
       
   287 	}
       
   288 
       
   289 EXPORT_C CMsvTestUtils& CMsvClientTest::MsvTestUtils()
       
   290 	{
       
   291 	return iMsvTestUtils;
       
   292 	}
       
   293 
       
   294 // MMS Test Harness: added to enable derived classes to reset data
       
   295 EXPORT_C void CMsvClientTest::Reset()
       
   296 	{
       
   297 	iMsvTestUtils.Reset();
       
   298 	}
       
   299 	
       
   300 EXPORT_C void MBaseTestState::SetDebugInfo(const TTestDebugInfo& aDebugInfo) 
       
   301 {
       
   302 iDebugInfo = aDebugInfo;
       
   303 }
       
   304 
       
   305 EXPORT_C const TTestDebugInfo& MBaseTestState::GetDebugInfo() const 
       
   306 {
       
   307 return iDebugInfo;
       
   308 }
       
   309 
       
   310 EXPORT_C MBaseTestState::~MBaseTestState()
       
   311 {
       
   312 }