os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest0step.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/tracefw/ulogger/unit_test/te-server/uloggerservertest0step.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,220 @@
1.4 +// Copyright (c) 2005-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 +// Example CTestStep derived implementation
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file UloggerServerTest0Step.cpp
1.23 + @internalTechnology
1.24 +*/
1.25 +#include "uloggerservertest0step.h"
1.26 +#include "te_uloggerservertestsuitedefs.h"
1.27 +#include "uloggerwatcher.h"
1.28 +
1.29 +
1.30 +
1.31 +CUloggerServerTest0Step::~CUloggerServerTest0Step()
1.32 +/**
1.33 + * Destructor
1.34 + */
1.35 + {
1.36 + }
1.37 +
1.38 +CUloggerServerTest0Step::CUloggerServerTest0Step()
1.39 +/**
1.40 + * Constructor
1.41 + */
1.42 + {
1.43 + // **MUST** call SetTestStepName in the constructor as the controlling
1.44 + // framework uses the test step name immediately following construction to set
1.45 + // up the step's unique logging ID.
1.46 + SetTestStepName(KUloggerServerTest0Step);
1.47 + }
1.48 +
1.49 +TVerdict CUloggerServerTest0Step::doTestStepPreambleL()
1.50 +/**
1.51 + * @return - TVerdict code
1.52 + * Override of base class virtual
1.53 + */
1.54 + {
1.55 + INFO_PRINTF1(_L("****This is unit test for CULoggerWatcher class****"));
1.56 +
1.57 + INFO_PRINTF1(_L("************************************************"));
1.58 + INFO_PRINTF1(_L("Note: To test CUloggerServer properly we must:"));
1.59 + INFO_PRINTF1(_L("- change UID3 for our test unit as we need access to server private directory"));
1.60 + INFO_PRINTF1(_L("************************************************"));
1.61 +
1.62 +
1.63 + iScheduler = new (ELeave) CActiveScheduler();
1.64 + CActiveScheduler::Install(iScheduler);
1.65 +
1.66 + SetTestStepResult(EPass);
1.67 + return TestStepResult();
1.68 + }
1.69 +
1.70 +
1.71 +TVerdict CUloggerServerTest0Step::doTestStepL()
1.72 +/**
1.73 + * @return - TVerdict code
1.74 + * Override of base class pure virtual
1.75 + * Our implementation only gets called if the base class doTestStepPreambleL() did
1.76 + * not leave. That being the case, the current test result value will be EPass.
1.77 + */
1.78 + {
1.79 + iErrors = 0;
1.80 + if (TestStepResult()==EPass)
1.81 + {
1.82 + iErrors += this->Test1L();//CULoggerWatcher::NewL
1.83 + iErrors += this->Test2L();//CULoggerWatcher::NewLC
1.84 + iErrors += this->Test3L();//CULoggerWatcher::StartWatching
1.85 + iErrors += this->Test4L();//CULoggerWatcher::StopWatching
1.86 + iErrors += this->Test5L();//CULoggerWatcher::RunL
1.87 +
1.88 +
1.89 + //display results
1.90 + TBuf<128> res;
1.91 + res.AppendFormat(_L("%d errors"), iErrors);
1.92 + INFO_PRINTF1(_L("****Results****"));
1.93 + INFO_PRINTF1(res);
1.94 + if(iErrors == 0)
1.95 + SetTestStepResult(EPass);
1.96 + else
1.97 + SetTestStepResult(EFail);
1.98 + }
1.99 +
1.100 + return TestStepResult();
1.101 + }
1.102 +
1.103 +
1.104 +
1.105 +TVerdict CUloggerServerTest0Step::doTestStepPostambleL()
1.106 +/**
1.107 + * @return - TVerdict code
1.108 + * Override of base class virtual
1.109 + */
1.110 + {
1.111 + delete iScheduler;
1.112 + iScheduler = NULL;
1.113 + return TestStepResult();
1.114 + }
1.115 +
1.116 +
1.117 +TInt CUloggerServerTest0Step::Test1L()
1.118 + {
1.119 + TInt errors = 0;
1.120 + INFO_PRINTF1(_L("Testing - CULoggerWatcher::NewL method"));
1.121 + CULoggerWatcher *obj = CULoggerWatcher::NewL();
1.122 + if(obj == NULL)
1.123 + {
1.124 + INFO_PRINTF1(_L("error"));
1.125 + errors++;
1.126 + }
1.127 + else
1.128 + {
1.129 + delete obj;
1.130 + obj = NULL;
1.131 + }
1.132 + return errors;
1.133 + }
1.134 +
1.135 +TInt CUloggerServerTest0Step::Test2L()
1.136 + {
1.137 + TInt errors = 0;
1.138 + //CULoggerWatcher::NewLC
1.139 + INFO_PRINTF1(_L("Testing - CULoggerWatcher::NewLC method"));
1.140 + CULoggerWatcher *obj = CULoggerWatcher::NewLC();
1.141 + if(obj == NULL)
1.142 + {
1.143 + INFO_PRINTF1(_L("error"));
1.144 + errors++;
1.145 + }
1.146 + else
1.147 + CleanupStack::PopAndDestroy();
1.148 + return errors;
1.149 + }
1.150 +
1.151 +TInt CUloggerServerTest0Step::Test3L()
1.152 +{
1.153 + TInt errors = 0;
1.154 + //CULoggerWatcher::StartWatching
1.155 + INFO_PRINTF1(_L("Testing - CULoggerWatcher::StartWatching method"));
1.156 + CULoggerWatcher *obj = CULoggerWatcher::NewL();
1.157 + /*
1.158 + * We need to create service provider for active object (RTimer is good choice)
1.159 + * */
1.160 + RTimer timer;
1.161 + timer.CreateLocal();
1.162 + timer.After(obj->GetStatus(), 2*1000*1000);
1.163 + obj->StartWatching(this);
1.164 + obj->StopWatching();
1.165 + timer.Close();
1.166 + if(obj->GetStatus().Int() != KErrNone)
1.167 + {
1.168 + INFO_PRINTF1(_L("error"));
1.169 + errors++;
1.170 + }
1.171 + delete obj;
1.172 + return errors;
1.173 +}
1.174 +
1.175 +TInt CUloggerServerTest0Step::Test4L()
1.176 +{
1.177 + TInt errors = 0;
1.178 + //CULoggerWatcher::StopWatching
1.179 + INFO_PRINTF1(_L("Testing - CULoggerWatcher::StopWatching method"));
1.180 + CULoggerWatcher *obj = CULoggerWatcher::NewL();
1.181 + RTimer timer;
1.182 + timer.CreateLocal();
1.183 + timer.After(obj->GetStatus(), 2*1000*1000);
1.184 + obj->StartWatching(this);
1.185 + obj->StopWatching();
1.186 + timer.Close();
1.187 + TBuf<128> buf;
1.188 + buf.AppendFormat(_L("Result of Stopping: %d"), obj->GetStatus().Int());
1.189 + INFO_PRINTF1(buf);
1.190 + if(obj->GetStatus().Int() != KErrNone)
1.191 + {
1.192 + INFO_PRINTF1(_L("error"));
1.193 + errors++;
1.194 + }
1.195 + delete obj;
1.196 +
1.197 + return errors;
1.198 +}
1.199 +
1.200 +TInt CUloggerServerTest0Step::Test5L()
1.201 +{
1.202 + TInt errors = 0;
1.203 + //CULoggerWatcher::RunL
1.204 + INFO_PRINTF1(_L("Testing - CULoggerWatcher::RunL method"));
1.205 + CULoggerWatcher *obj = CULoggerWatcher::NewL();
1.206 + RTimer timer;
1.207 + timer.CreateLocal();
1.208 + timer.After(obj->GetStatus(), 2*1000*1000);
1.209 + obj->StartWatching(this); //CULogger watcher must have observer initialized
1.210 + //becouse testing null pointer is not allowed
1.211 + obj->StopWatching();
1.212 + timer.Close();
1.213 + TRAPD(err, obj->RunL());
1.214 + if(err != KErrNone)
1.215 + {
1.216 + INFO_PRINTF1(_L("error"));
1.217 + errors++;
1.218 + }
1.219 + delete obj;
1.220 +
1.221 + return errors;
1.222 +}
1.223 +