os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest3step.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest3step.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,231 @@
     1.4 +// Copyright (c) 2007-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 +//
    1.18 +
    1.19 +/**
    1.20 + @file UloggerServerTest3Step.cpp
    1.21 + @internalTechnology
    1.22 +*/
    1.23 +
    1.24 +
    1.25 +#include "uloggerservertest3step.h"
    1.26 +#include "te_uloggerservertestsuitedefs.h"
    1.27 +#include "uloggerwatcher.h"
    1.28 +#include "pluginallocator.h"
    1.29 +
    1.30 +
    1.31 +CUloggerServerTest3Step::~CUloggerServerTest3Step()
    1.32 +/**
    1.33 + * Destructor
    1.34 + */
    1.35 +	{
    1.36 +	}
    1.37 +
    1.38 +CUloggerServerTest3Step::CUloggerServerTest3Step()
    1.39 +/**
    1.40 + * Constructor
    1.41 + */
    1.42 +	{
    1.43 +	SetTestStepName(KUloggerServerTest3Step);
    1.44 +	}
    1.45 +
    1.46 +TVerdict CUloggerServerTest3Step::doTestStepPreambleL()
    1.47 +/**
    1.48 + * @return - TVerdict code
    1.49 + * Override of base class virtual
    1.50 + */
    1.51 +	{
    1.52 +	INFO_PRINTF1(_L("****This is unit test for CPluginAllocator class****"));	
    1.53 +	
    1.54 +	
    1.55 +	iScheduler = new (ELeave) CActiveScheduler();
    1.56 +	CActiveScheduler::Install(iScheduler);
    1.57 +	
    1.58 +	SetTestStepResult(EPass);
    1.59 +	return TestStepResult();
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +TVerdict CUloggerServerTest3Step::doTestStepL()
    1.64 +/**
    1.65 + * @return - TVerdict code
    1.66 + * Override of base class pure virtual
    1.67 + * Our implementation only gets called if the base class doTestStepPreambleL() did
    1.68 + * not leave. That being the case, the current test result value will be EPass.
    1.69 + */
    1.70 +	{
    1.71 +	  iErrors = 0;
    1.72 +	  if (TestStepResult()==EPass)
    1.73 +	  {
    1.74 +	  
    1.75 +		iErrors += this->Test1L();//CPluginAllocator::NewL, GetOutputPlugin, GetControlPlugin
    1.76 +		iErrors += this->Test1_2L();//CPluginAllocator::NewL.... - condition 2
    1.77 +		iErrors += this->Test2L();//CPluginAllocator::NewLC
    1.78 +		iErrors += this->Test1_3L(); //CPluginAllocator::NewL - condition 3
    1.79 +		iErrors += this->Test1_4L(); //CPluginAllocator::NewL - condition 4
    1.80 +
    1.81 +		//display results
    1.82 +		TBuf<128> res;
    1.83 +		res.AppendFormat(_L("%d errors"), iErrors);
    1.84 +		INFO_PRINTF1(_L("****Results****"));
    1.85 +		INFO_PRINTF1(res);
    1.86 +		if(iErrors == 0)  
    1.87 +			SetTestStepResult(EPass);
    1.88 +			else
    1.89 +				SetTestStepResult(EFail);
    1.90 +	  }
    1.91 +	  
    1.92 +	  return TestStepResult();
    1.93 +	}
    1.94 +
    1.95 +
    1.96 +
    1.97 +TVerdict CUloggerServerTest3Step::doTestStepPostambleL()
    1.98 +/**
    1.99 + * @return - TVerdict code
   1.100 + * Override of base class virtual
   1.101 + */
   1.102 +	{
   1.103 +	delete iScheduler;
   1.104 +	iScheduler = NULL;
   1.105 +	return TestStepResult();
   1.106 +	}
   1.107 +
   1.108 +
   1.109 +TInt CUloggerServerTest3Step::Test1L()
   1.110 +	{
   1.111 +	TInt errors = 0;
   1.112 +	
   1.113 +	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 1"));
   1.114 +	CPluginAllocator *obj = CPluginAllocator::NewL(KFileTestPlugin(), KNullTestPlugin());
   1.115 +	if(obj == NULL)
   1.116 +	  {
   1.117 +	  INFO_PRINTF1(_L("error"));
   1.118 +	  errors++;
   1.119 +	  }
   1.120 +	  else
   1.121 +		{
   1.122 +		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   1.123 +		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
   1.124 +		if(!output || input)
   1.125 +			errors++;
   1.126 +		
   1.127 +		//cleanup
   1.128 +		delete obj;
   1.129 +		obj = NULL;
   1.130 +		}
   1.131 +		
   1.132 +	return errors;
   1.133 +	}
   1.134 +
   1.135 +TInt CUloggerServerTest3Step::Test1_2L()
   1.136 +	{
   1.137 +	TInt errors = 0;
   1.138 +	
   1.139 +	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 2"));
   1.140 +	CPluginAllocator *obj = NULL;
   1.141 +	obj = CPluginAllocator::NewL(KNullTestPlugin(), KNullTestPlugin());
   1.142 +	if(obj)
   1.143 +		{
   1.144 +		delete obj;
   1.145 +		obj = NULL;
   1.146 +		}
   1.147 +	else
   1.148 +		{
   1.149 +		errors++;
   1.150 +		INFO_PRINTF1(_L("error - obj not exists!"));
   1.151 +		}
   1.152 +		
   1.153 +	return errors;
   1.154 +	}
   1.155 +
   1.156 +
   1.157 +TInt CUloggerServerTest3Step::Test1_3L()
   1.158 +	{
   1.159 +	TInt errors = 0;
   1.160 +	
   1.161 +	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 3"));
   1.162 +	CPluginAllocator *obj = NULL;
   1.163 +	TRAPD(err, obj = CPluginAllocator::NewL(KFileTestPlugin(), KUsbTestPlugin()));
   1.164 +	if(obj && err==KErrNone)
   1.165 +		{
   1.166 +		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   1.167 +		MInputPlugin* input = obj->GetInputPlugin(); //does not matter
   1.168 +		if(!output)
   1.169 +			errors++;
   1.170 +		
   1.171 +		delete obj;
   1.172 +		obj = NULL;
   1.173 +		}
   1.174 +	else
   1.175 +		{
   1.176 +		INFO_PRINTF1(_L("plugin allocator not create. probably there is no usb plugin."));
   1.177 +		}
   1.178 +		
   1.179 +	return errors;
   1.180 +	}
   1.181 +
   1.182 +
   1.183 +TInt CUloggerServerTest3Step::Test1_4L()
   1.184 +	{
   1.185 +	TInt errors = 0;
   1.186 +	
   1.187 +	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 4"));
   1.188 +	CPluginAllocator *obj = NULL;
   1.189 +	//should leave
   1.190 +	TRAPD(errCode, obj=CPluginAllocator::NewL(KFileTestPlugin(), KBadNameTestPlugin()));
   1.191 +	if(errCode == KErrNone)
   1.192 +		{
   1.193 +		errors++;
   1.194 +		INFO_PRINTF1(_L("error - method should leave!"));		
   1.195 +		}
   1.196 +	if(obj)
   1.197 +		{
   1.198 +		errors++;
   1.199 +		INFO_PRINTF1(_L("error - obj should not exist!"));		
   1.200 +		delete obj;
   1.201 +		obj = NULL;
   1.202 +		}
   1.203 +		
   1.204 +	return errors;
   1.205 +	}
   1.206 +
   1.207 +
   1.208 +TInt CUloggerServerTest3Step::Test2L()
   1.209 +	{
   1.210 +	TInt errors = 0;
   1.211 +	
   1.212 +	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewLC method"));
   1.213 +	CPluginAllocator *obj = CPluginAllocator::NewLC(KFileTestPlugin(), KNullTestPlugin());
   1.214 +	if(obj == NULL)
   1.215 +	  {
   1.216 +	  INFO_PRINTF1(_L("error"));
   1.217 +	  errors++;
   1.218 +	  }
   1.219 +	  else
   1.220 +		{
   1.221 +		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   1.222 +		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
   1.223 +		if(!output || input)
   1.224 +			{
   1.225 +			INFO_PRINTF1(_L("error"));
   1.226 +			errors++;
   1.227 +			}
   1.228 +		
   1.229 +		//cleanup
   1.230 +		CleanupStack::PopAndDestroy(); //obj
   1.231 +		}
   1.232 +		
   1.233 +	return errors;
   1.234 +	}