os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest0step.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 // Example CTestStep derived implementation
    15 // 
    16 //
    17 
    18 /**
    19  @file UloggerServerTest0Step.cpp
    20  @internalTechnology
    21 */
    22 #include "uloggerservertest0step.h"
    23 #include "te_uloggerservertestsuitedefs.h"
    24 #include "uloggerwatcher.h"
    25 
    26 
    27 
    28 CUloggerServerTest0Step::~CUloggerServerTest0Step()
    29 /**
    30  * Destructor
    31  */
    32 	{
    33 	}
    34 
    35 CUloggerServerTest0Step::CUloggerServerTest0Step()
    36 /**
    37  * Constructor
    38  */
    39 	{
    40 	// **MUST** call SetTestStepName in the constructor as the controlling
    41 	// framework uses the test step name immediately following construction to set
    42 	// up the step's unique logging ID.
    43 	SetTestStepName(KUloggerServerTest0Step);
    44 	}
    45 
    46 TVerdict CUloggerServerTest0Step::doTestStepPreambleL()
    47 /**
    48  * @return - TVerdict code
    49  * Override of base class virtual
    50  */
    51 	{
    52 	INFO_PRINTF1(_L("****This is unit test for CULoggerWatcher class****"));	
    53 	
    54 	INFO_PRINTF1(_L("************************************************"));
    55 	INFO_PRINTF1(_L("Note: To test CUloggerServer properly we must:"));
    56 	INFO_PRINTF1(_L("- change UID3 for our test unit as we need access to server private directory"));
    57 	INFO_PRINTF1(_L("************************************************"));
    58 
    59 	
    60 	iScheduler = new (ELeave) CActiveScheduler();
    61 	CActiveScheduler::Install(iScheduler);
    62 	
    63 	SetTestStepResult(EPass);
    64 	return TestStepResult();
    65 	}
    66 
    67 
    68 TVerdict CUloggerServerTest0Step::doTestStepL()
    69 /**
    70  * @return - TVerdict code
    71  * Override of base class pure virtual
    72  * Our implementation only gets called if the base class doTestStepPreambleL() did
    73  * not leave. That being the case, the current test result value will be EPass.
    74  */
    75 	{
    76 	  iErrors = 0;
    77 	  if (TestStepResult()==EPass)
    78 	  {
    79 		  iErrors += this->Test1L();//CULoggerWatcher::NewL
    80 		  iErrors += this->Test2L();//CULoggerWatcher::NewLC
    81 		  iErrors += this->Test3L();//CULoggerWatcher::StartWatching
    82 		  iErrors += this->Test4L();//CULoggerWatcher::StopWatching
    83 		  iErrors += this->Test5L();//CULoggerWatcher::RunL
    84 
    85 		  
    86 		//display results
    87 		TBuf<128> res;
    88 		res.AppendFormat(_L("%d errors"), iErrors);
    89 		INFO_PRINTF1(_L("****Results****"));
    90 		INFO_PRINTF1(res);
    91 		if(iErrors == 0)  
    92 			SetTestStepResult(EPass);
    93 			else
    94 				SetTestStepResult(EFail);
    95 	  }
    96 	  
    97 	  return TestStepResult();
    98 	}
    99 
   100 
   101 
   102 TVerdict CUloggerServerTest0Step::doTestStepPostambleL()
   103 /**
   104  * @return - TVerdict code
   105  * Override of base class virtual
   106  */
   107 	{
   108 	delete iScheduler;
   109 	iScheduler = NULL;
   110 	return TestStepResult();
   111 	}
   112 
   113 
   114 TInt CUloggerServerTest0Step::Test1L()
   115 	{
   116 	TInt errors = 0;
   117 	INFO_PRINTF1(_L("Testing - CULoggerWatcher::NewL method"));
   118 	CULoggerWatcher *obj = CULoggerWatcher::NewL();
   119 	if(obj == NULL)
   120 	  {
   121 	  INFO_PRINTF1(_L("error"));
   122 	  errors++;
   123 	  }
   124 	  else
   125 		{
   126 		delete obj;
   127 		obj = NULL;
   128 		}
   129 	return errors;
   130 	}
   131 
   132 TInt CUloggerServerTest0Step::Test2L()
   133 	{
   134 	TInt errors = 0;
   135 	  //CULoggerWatcher::NewLC
   136 	  INFO_PRINTF1(_L("Testing - CULoggerWatcher::NewLC method"));
   137 	  CULoggerWatcher *obj = CULoggerWatcher::NewLC();
   138 	  if(obj == NULL)
   139 	  	{
   140 		  INFO_PRINTF1(_L("error"));
   141 		  errors++;
   142 	  	}
   143 	  else
   144 		  CleanupStack::PopAndDestroy();
   145 	  return errors;
   146 	  } 
   147 
   148 TInt CUloggerServerTest0Step::Test3L()
   149 {
   150 	TInt errors = 0;
   151 	  //CULoggerWatcher::StartWatching
   152 	  INFO_PRINTF1(_L("Testing - CULoggerWatcher::StartWatching method"));
   153 	  CULoggerWatcher *obj = CULoggerWatcher::NewL();
   154 	  /*
   155 	   * We need to create service provider for active object (RTimer is good choice)
   156 	   * */
   157 	  RTimer timer;
   158 	  timer.CreateLocal();
   159 	  timer.After(obj->GetStatus(), 2*1000*1000);
   160 	  obj->StartWatching(this);
   161 	  obj->StopWatching();
   162 	  timer.Close();
   163 	  if(obj->GetStatus().Int() != KErrNone)
   164 		{
   165 		INFO_PRINTF1(_L("error"));
   166 		errors++;
   167 		} 
   168 	   delete obj;
   169 	   return errors;
   170 } 
   171 
   172 TInt CUloggerServerTest0Step::Test4L()
   173 {
   174 	TInt errors = 0;
   175 	   //CULoggerWatcher::StopWatching
   176 		INFO_PRINTF1(_L("Testing - CULoggerWatcher::StopWatching method"));
   177 	    CULoggerWatcher *obj = CULoggerWatcher::NewL();
   178 	    RTimer timer;
   179 	    timer.CreateLocal();
   180 	    timer.After(obj->GetStatus(), 2*1000*1000);
   181 	    obj->StartWatching(this);
   182 	    obj->StopWatching();
   183 	    timer.Close();
   184 	    TBuf<128> buf;
   185 	    buf.AppendFormat(_L("Result of Stopping: %d"), obj->GetStatus().Int());
   186 	    INFO_PRINTF1(buf);
   187 		if(obj->GetStatus().Int() != KErrNone)
   188 		 {
   189 		 INFO_PRINTF1(_L("error"));
   190 		 errors++;
   191 		 }
   192 		delete obj;
   193 		
   194 		return errors;
   195 } 
   196 
   197 TInt CUloggerServerTest0Step::Test5L()
   198 {
   199 	TInt errors = 0;
   200 	  //CULoggerWatcher::RunL
   201 	  INFO_PRINTF1(_L("Testing - CULoggerWatcher::RunL method"));
   202     CULoggerWatcher *obj = CULoggerWatcher::NewL();
   203     RTimer timer;
   204     timer.CreateLocal();
   205 	      timer.After(obj->GetStatus(), 2*1000*1000);
   206     obj->StartWatching(this); //CULogger watcher must have observer initialized
   207     							//becouse testing null pointer is not allowed
   208     obj->StopWatching();
   209     timer.Close();
   210     TRAPD(err, obj->RunL());
   211 	  if(err != KErrNone)
   212 		  {
   213 		  INFO_PRINTF1(_L("error"));
   214 		  errors++;
   215 		  }
   216 	  delete obj;
   217 	  
   218 	  return errors;
   219 }
   220