sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file UloggerServerTest3Step.cpp
sl@0:  @internalTechnology
sl@0: */
sl@0: 
sl@0: 
sl@0: #include "uloggerservertest3step.h"
sl@0: #include "te_uloggerservertestsuitedefs.h"
sl@0: #include "uloggerwatcher.h"
sl@0: #include "pluginallocator.h"
sl@0: 
sl@0: 
sl@0: CUloggerServerTest3Step::~CUloggerServerTest3Step()
sl@0: /**
sl@0:  * Destructor
sl@0:  */
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: CUloggerServerTest3Step::CUloggerServerTest3Step()
sl@0: /**
sl@0:  * Constructor
sl@0:  */
sl@0: 	{
sl@0: 	SetTestStepName(KUloggerServerTest3Step);
sl@0: 	}
sl@0: 
sl@0: TVerdict CUloggerServerTest3Step::doTestStepPreambleL()
sl@0: /**
sl@0:  * @return - TVerdict code
sl@0:  * Override of base class virtual
sl@0:  */
sl@0: 	{
sl@0: 	INFO_PRINTF1(_L("****This is unit test for CPluginAllocator class****"));	
sl@0: 	
sl@0: 	
sl@0: 	iScheduler = new (ELeave) CActiveScheduler();
sl@0: 	CActiveScheduler::Install(iScheduler);
sl@0: 	
sl@0: 	SetTestStepResult(EPass);
sl@0: 	return TestStepResult();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TVerdict CUloggerServerTest3Step::doTestStepL()
sl@0: /**
sl@0:  * @return - TVerdict code
sl@0:  * Override of base class pure virtual
sl@0:  * Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0:  * not leave. That being the case, the current test result value will be EPass.
sl@0:  */
sl@0: 	{
sl@0: 	  iErrors = 0;
sl@0: 	  if (TestStepResult()==EPass)
sl@0: 	  {
sl@0: 	  
sl@0: 		iErrors += this->Test1L();//CPluginAllocator::NewL, GetOutputPlugin, GetControlPlugin
sl@0: 		iErrors += this->Test1_2L();//CPluginAllocator::NewL.... - condition 2
sl@0: 		iErrors += this->Test2L();//CPluginAllocator::NewLC
sl@0: 		iErrors += this->Test1_3L(); //CPluginAllocator::NewL - condition 3
sl@0: 		iErrors += this->Test1_4L(); //CPluginAllocator::NewL - condition 4
sl@0: 
sl@0: 		//display results
sl@0: 		TBuf<128> res;
sl@0: 		res.AppendFormat(_L("%d errors"), iErrors);
sl@0: 		INFO_PRINTF1(_L("****Results****"));
sl@0: 		INFO_PRINTF1(res);
sl@0: 		if(iErrors == 0)  
sl@0: 			SetTestStepResult(EPass);
sl@0: 			else
sl@0: 				SetTestStepResult(EFail);
sl@0: 	  }
sl@0: 	  
sl@0: 	  return TestStepResult();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: 
sl@0: TVerdict CUloggerServerTest3Step::doTestStepPostambleL()
sl@0: /**
sl@0:  * @return - TVerdict code
sl@0:  * Override of base class virtual
sl@0:  */
sl@0: 	{
sl@0: 	delete iScheduler;
sl@0: 	iScheduler = NULL;
sl@0: 	return TestStepResult();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt CUloggerServerTest3Step::Test1L()
sl@0: 	{
sl@0: 	TInt errors = 0;
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 1"));
sl@0: 	CPluginAllocator *obj = CPluginAllocator::NewL(KFileTestPlugin(), KNullTestPlugin());
sl@0: 	if(obj == NULL)
sl@0: 	  {
sl@0: 	  INFO_PRINTF1(_L("error"));
sl@0: 	  errors++;
sl@0: 	  }
sl@0: 	  else
sl@0: 		{
sl@0: 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
sl@0: 		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
sl@0: 		if(!output || input)
sl@0: 			errors++;
sl@0: 		
sl@0: 		//cleanup
sl@0: 		delete obj;
sl@0: 		obj = NULL;
sl@0: 		}
sl@0: 		
sl@0: 	return errors;
sl@0: 	}
sl@0: 
sl@0: TInt CUloggerServerTest3Step::Test1_2L()
sl@0: 	{
sl@0: 	TInt errors = 0;
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 2"));
sl@0: 	CPluginAllocator *obj = NULL;
sl@0: 	obj = CPluginAllocator::NewL(KNullTestPlugin(), KNullTestPlugin());
sl@0: 	if(obj)
sl@0: 		{
sl@0: 		delete obj;
sl@0: 		obj = NULL;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		errors++;
sl@0: 		INFO_PRINTF1(_L("error - obj not exists!"));
sl@0: 		}
sl@0: 		
sl@0: 	return errors;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt CUloggerServerTest3Step::Test1_3L()
sl@0: 	{
sl@0: 	TInt errors = 0;
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 3"));
sl@0: 	CPluginAllocator *obj = NULL;
sl@0: 	TRAPD(err, obj = CPluginAllocator::NewL(KFileTestPlugin(), KUsbTestPlugin()));
sl@0: 	if(obj && err==KErrNone)
sl@0: 		{
sl@0: 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
sl@0: 		MInputPlugin* input = obj->GetInputPlugin(); //does not matter
sl@0: 		if(!output)
sl@0: 			errors++;
sl@0: 		
sl@0: 		delete obj;
sl@0: 		obj = NULL;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		INFO_PRINTF1(_L("plugin allocator not create. probably there is no usb plugin."));
sl@0: 		}
sl@0: 		
sl@0: 	return errors;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt CUloggerServerTest3Step::Test1_4L()
sl@0: 	{
sl@0: 	TInt errors = 0;
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 4"));
sl@0: 	CPluginAllocator *obj = NULL;
sl@0: 	//should leave
sl@0: 	TRAPD(errCode, obj=CPluginAllocator::NewL(KFileTestPlugin(), KBadNameTestPlugin()));
sl@0: 	if(errCode == KErrNone)
sl@0: 		{
sl@0: 		errors++;
sl@0: 		INFO_PRINTF1(_L("error - method should leave!"));		
sl@0: 		}
sl@0: 	if(obj)
sl@0: 		{
sl@0: 		errors++;
sl@0: 		INFO_PRINTF1(_L("error - obj should not exist!"));		
sl@0: 		delete obj;
sl@0: 		obj = NULL;
sl@0: 		}
sl@0: 		
sl@0: 	return errors;
sl@0: 	}
sl@0: 
sl@0: 
sl@0: TInt CUloggerServerTest3Step::Test2L()
sl@0: 	{
sl@0: 	TInt errors = 0;
sl@0: 	
sl@0: 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewLC method"));
sl@0: 	CPluginAllocator *obj = CPluginAllocator::NewLC(KFileTestPlugin(), KNullTestPlugin());
sl@0: 	if(obj == NULL)
sl@0: 	  {
sl@0: 	  INFO_PRINTF1(_L("error"));
sl@0: 	  errors++;
sl@0: 	  }
sl@0: 	  else
sl@0: 		{
sl@0: 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
sl@0: 		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
sl@0: 		if(!output || input)
sl@0: 			{
sl@0: 			INFO_PRINTF1(_L("error"));
sl@0: 			errors++;
sl@0: 			}
sl@0: 		
sl@0: 		//cleanup
sl@0: 		CleanupStack::PopAndDestroy(); //obj
sl@0: 		}
sl@0: 		
sl@0: 	return errors;
sl@0: 	}