os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest3step.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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 /**
    17  @file UloggerServerTest3Step.cpp
    18  @internalTechnology
    19 */
    20 
    21 
    22 #include "uloggerservertest3step.h"
    23 #include "te_uloggerservertestsuitedefs.h"
    24 #include "uloggerwatcher.h"
    25 #include "pluginallocator.h"
    26 
    27 
    28 CUloggerServerTest3Step::~CUloggerServerTest3Step()
    29 /**
    30  * Destructor
    31  */
    32 	{
    33 	}
    34 
    35 CUloggerServerTest3Step::CUloggerServerTest3Step()
    36 /**
    37  * Constructor
    38  */
    39 	{
    40 	SetTestStepName(KUloggerServerTest3Step);
    41 	}
    42 
    43 TVerdict CUloggerServerTest3Step::doTestStepPreambleL()
    44 /**
    45  * @return - TVerdict code
    46  * Override of base class virtual
    47  */
    48 	{
    49 	INFO_PRINTF1(_L("****This is unit test for CPluginAllocator class****"));	
    50 	
    51 	
    52 	iScheduler = new (ELeave) CActiveScheduler();
    53 	CActiveScheduler::Install(iScheduler);
    54 	
    55 	SetTestStepResult(EPass);
    56 	return TestStepResult();
    57 	}
    58 
    59 
    60 TVerdict CUloggerServerTest3Step::doTestStepL()
    61 /**
    62  * @return - TVerdict code
    63  * Override of base class pure virtual
    64  * Our implementation only gets called if the base class doTestStepPreambleL() did
    65  * not leave. That being the case, the current test result value will be EPass.
    66  */
    67 	{
    68 	  iErrors = 0;
    69 	  if (TestStepResult()==EPass)
    70 	  {
    71 	  
    72 		iErrors += this->Test1L();//CPluginAllocator::NewL, GetOutputPlugin, GetControlPlugin
    73 		iErrors += this->Test1_2L();//CPluginAllocator::NewL.... - condition 2
    74 		iErrors += this->Test2L();//CPluginAllocator::NewLC
    75 		iErrors += this->Test1_3L(); //CPluginAllocator::NewL - condition 3
    76 		iErrors += this->Test1_4L(); //CPluginAllocator::NewL - condition 4
    77 
    78 		//display results
    79 		TBuf<128> res;
    80 		res.AppendFormat(_L("%d errors"), iErrors);
    81 		INFO_PRINTF1(_L("****Results****"));
    82 		INFO_PRINTF1(res);
    83 		if(iErrors == 0)  
    84 			SetTestStepResult(EPass);
    85 			else
    86 				SetTestStepResult(EFail);
    87 	  }
    88 	  
    89 	  return TestStepResult();
    90 	}
    91 
    92 
    93 
    94 TVerdict CUloggerServerTest3Step::doTestStepPostambleL()
    95 /**
    96  * @return - TVerdict code
    97  * Override of base class virtual
    98  */
    99 	{
   100 	delete iScheduler;
   101 	iScheduler = NULL;
   102 	return TestStepResult();
   103 	}
   104 
   105 
   106 TInt CUloggerServerTest3Step::Test1L()
   107 	{
   108 	TInt errors = 0;
   109 	
   110 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 1"));
   111 	CPluginAllocator *obj = CPluginAllocator::NewL(KFileTestPlugin(), KNullTestPlugin());
   112 	if(obj == NULL)
   113 	  {
   114 	  INFO_PRINTF1(_L("error"));
   115 	  errors++;
   116 	  }
   117 	  else
   118 		{
   119 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   120 		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
   121 		if(!output || input)
   122 			errors++;
   123 		
   124 		//cleanup
   125 		delete obj;
   126 		obj = NULL;
   127 		}
   128 		
   129 	return errors;
   130 	}
   131 
   132 TInt CUloggerServerTest3Step::Test1_2L()
   133 	{
   134 	TInt errors = 0;
   135 	
   136 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 2"));
   137 	CPluginAllocator *obj = NULL;
   138 	obj = CPluginAllocator::NewL(KNullTestPlugin(), KNullTestPlugin());
   139 	if(obj)
   140 		{
   141 		delete obj;
   142 		obj = NULL;
   143 		}
   144 	else
   145 		{
   146 		errors++;
   147 		INFO_PRINTF1(_L("error - obj not exists!"));
   148 		}
   149 		
   150 	return errors;
   151 	}
   152 
   153 
   154 TInt CUloggerServerTest3Step::Test1_3L()
   155 	{
   156 	TInt errors = 0;
   157 	
   158 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 3"));
   159 	CPluginAllocator *obj = NULL;
   160 	TRAPD(err, obj = CPluginAllocator::NewL(KFileTestPlugin(), KUsbTestPlugin()));
   161 	if(obj && err==KErrNone)
   162 		{
   163 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   164 		MInputPlugin* input = obj->GetInputPlugin(); //does not matter
   165 		if(!output)
   166 			errors++;
   167 		
   168 		delete obj;
   169 		obj = NULL;
   170 		}
   171 	else
   172 		{
   173 		INFO_PRINTF1(_L("plugin allocator not create. probably there is no usb plugin."));
   174 		}
   175 		
   176 	return errors;
   177 	}
   178 
   179 
   180 TInt CUloggerServerTest3Step::Test1_4L()
   181 	{
   182 	TInt errors = 0;
   183 	
   184 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewL method - condition 4"));
   185 	CPluginAllocator *obj = NULL;
   186 	//should leave
   187 	TRAPD(errCode, obj=CPluginAllocator::NewL(KFileTestPlugin(), KBadNameTestPlugin()));
   188 	if(errCode == KErrNone)
   189 		{
   190 		errors++;
   191 		INFO_PRINTF1(_L("error - method should leave!"));		
   192 		}
   193 	if(obj)
   194 		{
   195 		errors++;
   196 		INFO_PRINTF1(_L("error - obj should not exist!"));		
   197 		delete obj;
   198 		obj = NULL;
   199 		}
   200 		
   201 	return errors;
   202 	}
   203 
   204 
   205 TInt CUloggerServerTest3Step::Test2L()
   206 	{
   207 	TInt errors = 0;
   208 	
   209 	INFO_PRINTF1(_L("Testing - CPluginAllocator::NewLC method"));
   210 	CPluginAllocator *obj = CPluginAllocator::NewLC(KFileTestPlugin(), KNullTestPlugin());
   211 	if(obj == NULL)
   212 	  {
   213 	  INFO_PRINTF1(_L("error"));
   214 	  errors++;
   215 	  }
   216 	  else
   217 		{
   218 		MOutputPlugin* output = obj->GetOutputPlugin(); //should exists
   219 		MInputPlugin* input = obj->GetInputPlugin(); //should not exists
   220 		if(!output || input)
   221 			{
   222 			INFO_PRINTF1(_L("error"));
   223 			errors++;
   224 			}
   225 		
   226 		//cleanup
   227 		CleanupStack::PopAndDestroy(); //obj
   228 		}
   229 		
   230 	return errors;
   231 	}