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