1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/genericusabilitylib/test/src/t_emanaged.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,2437 @@
1.4 +// Copyright (c) 2008-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 +// Overview:
1.18 +// Test methods of the LManagedX and LCleanedupX classes.
1.19 +// Tests CONSTRUCTORS_MAY_LEAVE and OR_LEAVE macros
1.20 +//
1.21 +//
1.22 +
1.23 +#include <e32base.h>
1.24 +#include <e32test.h>
1.25 +#include <e32def.h>
1.26 +#include <e32cmn.h>
1.27 +#include <f32file.h>
1.28 +#include "emisc.h"
1.29 +#include "euserhl.h"
1.30 +
1.31 +
1.32 +RTest test(_L("RAII-based automatic resource management tests"));
1.33 +
1.34 +
1.35 +TInt TExtendedTestL();
1.36 +
1.37 +class CTracker : public CBase
1.38 + {
1.39 + public:
1.40 + CONSTRUCTORS_MAY_LEAVE
1.41 +
1.42 + enum TConstructionMode { ENonleavingConstructor, EConstructorLeaves};
1.43 +
1.44 + static CTracker* NewL()
1.45 + {
1.46 + return new(ELeave) CTracker;
1.47 + }
1.48 +
1.49 + static CTracker* NewL(TConstructionMode aMode)
1.50 + {
1.51 + return new(ELeave) CTracker(aMode);
1.52 + }
1.53 +
1.54 + CTracker()
1.55 + : iData(new(ELeave) TInt)
1.56 + {
1.57 + test.Printf(_L(" CTracker - %x\n"), this);
1.58 + *iData = 3;
1.59 + }
1.60 +
1.61 + explicit CTracker(TConstructionMode aMode)
1.62 + : iData(new(ELeave) TInt(aMode))
1.63 + {
1.64 + if (aMode == EConstructorLeaves)
1.65 + {
1.66 + test.Printf(_L("CTracker(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
1.67 + User::Leave(KErrGeneral);
1.68 + }
1.69 +
1.70 + test.Printf(_L(" CTracker - %x\n"), this);
1.71 + }
1.72 +
1.73 + CTracker(CTracker& aTracker)
1.74 + : iData(aTracker.iData.Unmanage())
1.75 + {
1.76 + test.Printf(_L(" CTracker::CTracker(const CTracker&) - %x (copy)\n"), this);
1.77 + }
1.78 +
1.79 + CTracker& operator=(CTracker& aTracker)
1.80 + {
1.81 + iData = aTracker.iData.Unmanage();
1.82 + test.Printf(_L(" CTracker::operator=(const CTracker&) - %x (copy)\n"), this);
1.83 + return *this;
1.84 + }
1.85 +
1.86 + virtual ~CTracker()
1.87 + {
1.88 + test.Printf(_L(" ~CTracker - %x\n"), this);
1.89 + }
1.90 +
1.91 + virtual void MemFunc()
1.92 + {
1.93 + test.Printf(_L(" CTracker::MemFunc - %x\n"), this);
1.94 + }
1.95 +
1.96 + virtual TInt Value()
1.97 + {
1.98 + return *iData;
1.99 + }
1.100 +
1.101 + static void StaticMemberRef(const CTracker& aTracker)
1.102 + {
1.103 + test.Printf(_L(" CTracker::StaticMemberRef - %x\n"), &aTracker);
1.104 + }
1.105 +
1.106 + static void StaticMemberPtr(CTracker* aTracker)
1.107 + {
1.108 + test.Printf(_L(" CTracker::StaticMemberPtr - %x\n"), aTracker);
1.109 + }
1.110 +
1.111 + private:
1.112 + LManagedPtr<TInt> iData;
1.113 + };
1.114 +
1.115 +TBool trackerDestroyed = EFalse;
1.116 +
1.117 +class TCTrackerDestroy
1.118 + {
1.119 +public:
1.120 + static void Cleanup(CTracker* aPtr)
1.121 + {
1.122 + test.Printf(_L("TCTrackerDestroy::Cleanup\n"));
1.123 + delete aPtr;
1.124 + trackerDestroyed = ETrue;
1.125 + }
1.126 + };
1.127 +
1.128 +class CDerivedTracker: public CTracker
1.129 + {
1.130 + public:
1.131 + CONSTRUCTORS_MAY_LEAVE
1.132 +
1.133 + static CDerivedTracker* NewL()
1.134 + {
1.135 + return new(ELeave) CDerivedTracker;
1.136 + }
1.137 +
1.138 + static CDerivedTracker* NewL(CTracker::TConstructionMode aMode)
1.139 + {
1.140 + return new(ELeave) CDerivedTracker(aMode);
1.141 + }
1.142 +
1.143 + CDerivedTracker()
1.144 + : iRealData(new(ELeave) TReal64)
1.145 + {
1.146 + test.Printf(_L(" CDerivedTracker - %x\n"), this);
1.147 + *iRealData = 5.5;
1.148 + }
1.149 +
1.150 + CDerivedTracker(CTracker::TConstructionMode aMode)
1.151 + {
1.152 + if (aMode == EConstructorLeaves)
1.153 + {
1.154 + test.Printf(_L("CDerivedTracker(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
1.155 + User::Leave(KErrGeneral);
1.156 + }
1.157 +
1.158 + test.Printf(_L(" CDerivedTracker - %x\n"), this);
1.159 + }
1.160 +
1.161 + CDerivedTracker(CDerivedTracker& aDerivedTracker)
1.162 + : CTracker(aDerivedTracker),
1.163 + iRealData(aDerivedTracker.iRealData.Unmanage())
1.164 + {
1.165 + test.Printf(_L(" CDerivedTracker::CDerivedTracker(const CDerivedTracker&) - %x (copy)\n"), this);
1.166 + }
1.167 +
1.168 + CDerivedTracker& operator=(CDerivedTracker& aDerivedTracker)
1.169 + {
1.170 + CTracker::operator=(aDerivedTracker);
1.171 + iRealData = aDerivedTracker.iRealData.Unmanage();
1.172 + test.Printf(_L(" CDerivedTracker::operator=(const CDerivedTracker&) - %x (copy)\n"), this);
1.173 + return *this;
1.174 + }
1.175 +
1.176 + virtual ~CDerivedTracker()
1.177 + {
1.178 + test.Printf(_L(" ~CDerivedTracker - %x\n"), this);
1.179 + }
1.180 +
1.181 + virtual void MemFunc()
1.182 + {
1.183 + test.Printf(_L(" CDerivedTracker::MemFunc - %x\n"), this);
1.184 + }
1.185 +
1.186 + static void StaticMemberRef(const CDerivedTracker& aTracker)
1.187 + {
1.188 + test.Printf(_L(" CDerivedTracker::StaticMemberRef - %x\n"), &aTracker);
1.189 + }
1.190 +
1.191 + static void StaticMemberPtr(CDerivedTracker* aTracker)
1.192 + {
1.193 + test.Printf(_L(" CDerivedTracker::StaticMemberPtr - %x\n"), aTracker);
1.194 + }
1.195 +
1.196 + private:
1.197 + LManagedPtr<TReal64> iRealData;
1.198 + };
1.199 +
1.200 +
1.201 +namespace Log
1.202 +{
1.203 +
1.204 +class RLogger
1.205 + {
1.206 + public:
1.207 + RLogger()
1.208 + : iData(NULL)
1.209 + {
1.210 + test.Printf(_L(" RLogger - %x\n"), this);
1.211 + }
1.212 +
1.213 + RLogger(TInt* aData)
1.214 + : iData(aData)
1.215 + {
1.216 + test.Printf(_L(" RLogger - %x ptr %x -> val %d\n"), this, aData, *iData);
1.217 + }
1.218 +
1.219 + RLogger(TInt aValue)
1.220 + : iData(new(ELeave) TInt(aValue))
1.221 + {
1.222 + test.Printf(_L(" RLogger - %x value %d\n"), this, *iData);
1.223 + }
1.224 +
1.225 + void OpenL(TInt aValue)
1.226 + {
1.227 + iData = new(ELeave) TInt(aValue);
1.228 + test.Printf(_L(" RLogger::OpenL(TInt aValue) - %x value %d\n"), this, *iData);
1.229 + }
1.230 +
1.231 + RLogger(const RLogger& aLogger)
1.232 + : iData(aLogger.iData)
1.233 + {
1.234 + test.Printf(_L(" RLogger::RLogger(const RLogger&) - %x (copy)\n"), this);
1.235 + }
1.236 +
1.237 +
1.238 + RLogger& operator=(const RLogger& aLogger)
1.239 + {
1.240 + iData = aLogger.iData;
1.241 +
1.242 + test.Printf(_L(" RLogger::operator=(const RLogger&) - %x copy from %x val %d\n"), this, &aLogger, *aLogger.iData);
1.243 + return *this;
1.244 + }
1.245 +
1.246 +
1.247 + ~RLogger()
1.248 + {
1.249 + test.Printf(_L(" ~RLogger - %x\n"), this);
1.250 + }
1.251 +
1.252 +
1.253 + void Close()
1.254 + {
1.255 + test.Printf(_L(" RLogger::Close - %x\n"), this);
1.256 +
1.257 + // Open or non-NULL initializing constructor not called or
1.258 + // cleanup function already called
1.259 +
1.260 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.261 + delete iData;
1.262 + iData = NULL;
1.263 + }
1.264 +
1.265 +
1.266 + void Release()
1.267 + {
1.268 + test.Printf(_L(" RLogger::Release - %x\n"), this);
1.269 +
1.270 + // Open or non-NULL initializing constructor not called or
1.271 + // cleanup function already called
1.272 +
1.273 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.274 + delete iData;
1.275 + iData = NULL;
1.276 + }
1.277 +
1.278 +
1.279 + void Destroy()
1.280 + {
1.281 + test.Printf(_L(" RLogger::Destroy - %x\n"), this);
1.282 +
1.283 + // Open or non-NULL initializing constructor not called or
1.284 + // cleanup function already called
1.285 +
1.286 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.287 + delete iData;
1.288 + iData = NULL;
1.289 + }
1.290 +
1.291 +
1.292 + void Free()
1.293 + {
1.294 + test.Printf(_L(" RLogger::Free - %x\n"), this);
1.295 +
1.296 + // Open or non-NULL initializing constructor not called or
1.297 + // cleanup function already called
1.298 +
1.299 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.300 + delete iData;
1.301 + iData = NULL;
1.302 + }
1.303 +
1.304 + void MemFunc()
1.305 + {
1.306 + test.Printf(_L(" RLogger::MemFunc - %x %x\n"), this, iData);
1.307 + }
1.308 +
1.309 + static void StaticMemberRef(const RLogger& aTracker)
1.310 + {
1.311 + test.Printf(_L(" RLogger::StaticMemberRef - %x\n"), &aTracker);
1.312 + }
1.313 +
1.314 + static void StaticMemberPtr(RLogger* aTracker)
1.315 + {
1.316 + test.Printf(_L(" RLogger::StaticMemberPtr - %x\n"), aTracker);
1.317 + }
1.318 +
1.319 + static void Cleanup(TAny* aRlogger)
1.320 + {
1.321 + static_cast<RLogger*>(aRlogger)->Close();
1.322 + }
1.323 +
1.324 + TInt* GetData() const
1.325 + {
1.326 + return iData;
1.327 + }
1.328 +
1.329 + protected:
1.330 + TInt* iData;
1.331 + };
1.332 +
1.333 +
1.334 +DEFINE_CLEANUP_FUNCTION(RLogger, Release);
1.335 +
1.336 +
1.337 +class ROtherLogger
1.338 + {
1.339 + public:
1.340 + ROtherLogger()
1.341 + : iData(NULL)
1.342 + {
1.343 + test.Printf(_L(" ROtherLogger - %x\n"), this);
1.344 + }
1.345 +
1.346 + ROtherLogger(TInt* aData)
1.347 + : iData(aData)
1.348 + {
1.349 + test.Printf(_L(" ROtherLogger - %x ptr %x -> val %d\n"), this, aData, *iData);
1.350 + }
1.351 +
1.352 + ROtherLogger(TInt aValue)
1.353 + : iData(new(ELeave) TInt(aValue))
1.354 + {
1.355 + test.Printf(_L(" ROtherLogger - %x value %d\n"), this, *iData);
1.356 + }
1.357 +
1.358 + void OpenL(TInt aValue)
1.359 + {
1.360 + iData = new(ELeave) TInt(aValue);
1.361 + test.Printf(_L(" ROtherLogger::OpenL(TInt aValue) - %x value %d\n"), this, *iData);
1.362 + }
1.363 +
1.364 + ROtherLogger(const ROtherLogger& aLogger)
1.365 + : iData(aLogger.iData)
1.366 + {
1.367 + test.Printf(_L(" ROtherLogger::ROtherLogger(const ROtherLogger&) - %x (copy)\n"), this);
1.368 + }
1.369 +
1.370 +
1.371 + ROtherLogger& operator=(const ROtherLogger& aLogger)
1.372 + {
1.373 + iData = aLogger.iData;
1.374 +
1.375 + test.Printf(_L(" ROtherLogger::operator=(const ROtherLogger&) - %x copy from %x ptr %x\n"), this, &aLogger, aLogger.iData);
1.376 + return *this;
1.377 + }
1.378 +
1.379 +
1.380 + ~ROtherLogger()
1.381 + {
1.382 + test.Printf(_L(" ~ROtherLogger - %x\n"), this);
1.383 + }
1.384 +
1.385 +
1.386 + void Close()
1.387 + {
1.388 + test.Printf(_L(" ROtherLogger::Close - %x\n"), this);
1.389 +
1.390 + // Open or non-NULL initializing constructor not called or
1.391 + // cleanup function already called
1.392 +
1.393 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.394 + delete iData;
1.395 + iData = NULL;
1.396 + }
1.397 +
1.398 +
1.399 + void Release()
1.400 + {
1.401 + test.Printf(_L(" ROtherLogger::Release - %x\n"), this);
1.402 +
1.403 + // Open or non-NULL initializing constructor not called or
1.404 + // cleanup function already called
1.405 +
1.406 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.407 + delete iData;
1.408 + iData = NULL;
1.409 + }
1.410 +
1.411 +
1.412 + void Destroy()
1.413 + {
1.414 + test.Printf(_L(" ROtherLogger::Destroy - %x\n"), this);
1.415 +
1.416 + // Open or non-NULL initializing constructor not called or
1.417 + // cleanup function already called
1.418 +
1.419 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.420 + delete iData;
1.421 + iData = NULL;
1.422 + }
1.423 +
1.424 +
1.425 + void Free()
1.426 + {
1.427 + test.Printf(_L(" ROtherLogger::Free - %x\n"), this);
1.428 +
1.429 + // Open or non-NULL initializing constructor not called or
1.430 + // cleanup function already called
1.431 +
1.432 + __ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
1.433 + delete iData;
1.434 + iData = NULL;
1.435 + }
1.436 +
1.437 + void MemFunc()
1.438 + {
1.439 + test.Printf(_L(" ROtherLogger::MemFunc - %x %x\n"), this, iData);
1.440 + }
1.441 +
1.442 + static void StaticMemberRef(const ROtherLogger& aTracker)
1.443 + {
1.444 + test.Printf(_L(" ROtherLogger::StaticMemberRef - %x\n"), &aTracker);
1.445 + }
1.446 +
1.447 + static void StaticMemberPtr(ROtherLogger* aTracker)
1.448 + {
1.449 + test.Printf(_L(" ROtherLogger::StaticMemberPtr - %x\n"), aTracker);
1.450 + }
1.451 +
1.452 + static void Cleanup(TAny* aRlogger)
1.453 + {
1.454 + static_cast<ROtherLogger*>(aRlogger)->Close();
1.455 + }
1.456 +
1.457 + operator RLogger() const
1.458 + {
1.459 + test.Printf(_L(" ROtherLogger::operator RLogger() - %x\n"), this);
1.460 + return RLogger(iData);
1.461 + }
1.462 +
1.463 + ROtherLogger& operator=(const RLogger& aLogger)
1.464 + {
1.465 + iData = aLogger.GetData();
1.466 +
1.467 + test.Printf(_L(" ROtherLogger::operator=(const RLogger&) - %x copy from %x ptr %x\n"), this, &aLogger, aLogger.GetData());
1.468 + return *this;
1.469 + }
1.470 +
1.471 + protected:
1.472 + TInt* iData;
1.473 + };
1.474 +
1.475 +} // namespace Log
1.476 +
1.477 +class RPair
1.478 + {
1.479 + public:
1.480 + RPair(const TInt& x, const TInt& y)
1.481 + : iX(x), iY(y)
1.482 + {
1.483 + test.Printf(_L(" RPair::RPair(const TInt& x, const TInt& y) %x %d %d\n"), iX, iY);
1.484 + }
1.485 +
1.486 + RPair(TInt& x, TInt& y)
1.487 + : iX(x), iY(y)
1.488 + {
1.489 + test.Printf(_L(" RPair::RPair(TInt& x, TInt& y) %x %d %d\n"), iX, iY);
1.490 + }
1.491 +
1.492 + void Close()
1.493 + {
1.494 + test.Printf(_L(" RPair::Close() %x %d %d\n"), iX, iY);
1.495 + }
1.496 +
1.497 + private:
1.498 + TInt iX;
1.499 + TInt iY;
1.500 + };
1.501 +
1.502 +
1.503 +using Log::RLogger;
1.504 +using Log::ROtherLogger;
1.505 +
1.506 +class TLogger
1.507 + {
1.508 + public:
1.509 + TLogger()
1.510 + {
1.511 + test.Printf(_L(" TLogger - %x\n"), this);
1.512 + }
1.513 +
1.514 + TLogger(const TLogger&)
1.515 + {
1.516 + test.Printf(_L(" TLogger::TLogger(const TLogger& aLogger) - %x (copy)\n"), this);
1.517 + }
1.518 +
1.519 +
1.520 + TLogger& operator=(const TLogger&)
1.521 + {
1.522 + test.Printf(_L(" TLogger::operator=(const TLogger& aLogger) - %x (copy)\n"), this);
1.523 + return *this;
1.524 + }
1.525 +
1.526 + ~TLogger()
1.527 + {
1.528 + test.Printf(_L(" ~TLogger - %x\n"), this);
1.529 + }
1.530 +
1.531 + void Test()
1.532 + {
1.533 + test.Printf(_L(" TLogger::Test - %x\n"), this);
1.534 + }
1.535 + };
1.536 +
1.537 +
1.538 +static TInt one = 1;
1.539 +static TInt two = 2;
1.540 +
1.541 +// CComposite object owns other objects:
1.542 +
1.543 +class CComposite: public CBase
1.544 + {
1.545 + public:
1.546 + enum TConstructionMode
1.547 + {
1.548 + ENonleavingConstructor,
1.549 + EConstructorLeaves,
1.550 + EMemberConstructorLeaves
1.551 + };
1.552 +
1.553 + static CComposite* NewL()
1.554 + {
1.555 + return new(ELeave) CComposite;
1.556 + }
1.557 +
1.558 + static CComposite* NewL(TConstructionMode aMode)
1.559 + {
1.560 + return new(ELeave) CComposite(aMode);
1.561 + }
1.562 +
1.563 + CONSTRUCTORS_MAY_LEAVE
1.564 +
1.565 + CComposite();
1.566 + CComposite(TConstructionMode aMode);
1.567 + ~CComposite();
1.568 +
1.569 + void ReleaseLoggers();
1.570 + void ReleaseArrays();
1.571 +
1.572 + private:
1.573 + TInt iVal;
1.574 +
1.575 +// By-value component objects
1.576 + const LManagedHandle<RLogger> iConstLogger;
1.577 + LManagedHandle<RLogger> iLogger;
1.578 + LManagedHandle<RLogger> iLogger2;
1.579 + LManagedHandle<RLogger> iLogger3;
1.580 +
1.581 + ROtherLogger iOther;
1.582 + LManagedRef<ROtherLogger> iOtherRef;
1.583 + LManagedHandle<RLogger> iAnotherLogger;
1.584 +
1.585 + LManagedHandle<RLogger, TDestroy> iDestroyer;
1.586 +
1.587 +// Component objects contained by pointer
1.588 + LManagedPtr<CTracker> iNullPtr;
1.589 + //Define a custom cleanup strategy for CTracker
1.590 + LManagedPtr<CTracker> iAutoPtr;
1.591 + LManagedPtr<CTracker> iAutoPtr2;
1.592 + LManagedPtr<CTracker> iAutoPtr3;
1.593 + LManagedPtr<CTracker, TCTrackerDestroy> iAutoPtr4;
1.594 + LManagedPtr<CDerivedTracker> iAutoPtr5;
1.595 +
1.596 + LManagedArray<CTracker> iEmptyArray;
1.597 + LManagedArray<CTracker> iAutoArray;
1.598 + LManagedArray<CTracker> iAutoArray2;
1.599 + static const TInt KNumTrackers = 3;
1.600 +
1.601 + LManagedHandle<RPointerArray<CTracker>, TResetAndDestroy> iPtrArray;
1.602 +
1.603 + RPointerArray<CTracker> iArray;
1.604 + RPointerArray<CTracker> iArray2;
1.605 + LManagedRef<RPointerArray<CTracker>, TResetAndDestroy> iArrayWrapper;
1.606 +
1.607 + RLogger iRawLogger;
1.608 + LManagedGuard iGuard;
1.609 +
1.610 + LManagedHandle<RPair> iPair1;
1.611 + LManagedHandle<RPair> iPair2;
1.612 + LManagedHandle<RPair> iPair3;
1.613 + LManagedHandle<RPair> iPair4;
1.614 + };
1.615 +
1.616 +CComposite::CComposite()
1.617 + : iConstLogger(42),
1.618 + iLogger(1),
1.619 + iLogger2(2),
1.620 + iOther(42),
1.621 + iOtherRef(iOther),
1.622 + iAnotherLogger(iOtherRef.Unmanage()),
1.623 + iDestroyer(2),
1.624 + iAutoPtr(CTracker::NewL()),
1.625 + iAutoPtr2(CTracker::NewL()),
1.626 + iAutoPtr3(CTracker::NewL()),
1.627 + iAutoPtr4(CTracker::NewL()),
1.628 + iAutoPtr5(CDerivedTracker::NewL()),
1.629 + iAutoArray(new(ELeave) CTracker[KNumTrackers]),
1.630 + iAutoArray2(new(ELeave) CTracker[KNumTrackers]),
1.631 + iPtrArray(3),
1.632 + iArrayWrapper(iArray),
1.633 + iRawLogger(42),
1.634 + iGuard(RLogger::Cleanup, &iRawLogger),
1.635 + iPair1(1, 2),
1.636 + iPair2(one, 2),
1.637 + iPair3(1, two),
1.638 + iPair4(one, two)
1.639 + {
1.640 + test.Printf(_L(" CComposite - %x\n"), this);
1.641 +
1.642 + //Clear the trackerDestroyed flag. This flag is set
1.643 + //in the custom cleanup strategy for CTracker which is
1.644 + //defined for iAutoPtr
1.645 + trackerDestroyed = EFalse;
1.646 +
1.647 + iLogger = iLogger2.Unmanage();
1.648 + iLogger3->OpenL(3);
1.649 +
1.650 + RLogger logger = iLogger3.Unmanage();
1.651 + iLogger3.ReleaseResource();
1.652 + logger.Release();
1.653 +
1.654 + iAutoPtr = iAutoPtr2.Unmanage();
1.655 + iAutoPtr2.ReleaseResource();
1.656 +
1.657 + iAutoPtr4 = iAutoPtr5.Unmanage();
1.658 +
1.659 +
1.660 + if (iAutoPtr3)
1.661 + {
1.662 + test.Printf(_L(" iAutoPtr3 pointer = %x\n"), iAutoPtr3.Get());
1.663 + }
1.664 + else
1.665 + {
1.666 + test.Printf(_L(" iAutoPtr3 pointer is null (%x)\n"), iAutoPtr3.Get());
1.667 + }
1.668 +
1.669 + if (!iNullPtr)
1.670 + {
1.671 + test.Printf(_L(" iNullPtr is null (%x)\n"), iNullPtr.Get());
1.672 + }
1.673 + else
1.674 + {
1.675 + test.Printf(_L(" iNullPtr is (%x)\n"), iNullPtr.Get());
1.676 + }
1.677 +
1.678 + if (iAutoPtr3 != iNullPtr)
1.679 + {
1.680 + test.Printf(_L(" iAutoPtr3 pointer is not null = %x\n"), iAutoPtr3.Get());
1.681 + }
1.682 +
1.683 + if (iAutoPtr3 == iNullPtr)
1.684 + {
1.685 + test.Printf(_L(" iAutoPtr3 pointer is null (%x)\n"), iAutoPtr3.Get());
1.686 + }
1.687 +
1.688 + if (iNullPtr < iAutoPtr3)
1.689 + {
1.690 + test.Printf(_L(" iNullPtr < iAutoPtr3 (%x)\n"), iAutoPtr3.Get());
1.691 + }
1.692 +
1.693 + iAutoPtr3 = NULL;
1.694 +
1.695 +
1.696 + iAutoArray = iAutoArray2.Unmanage();
1.697 + iAutoArray2.ReleaseResource();
1.698 +
1.699 + iPtrArray->Append(CTracker::NewL());
1.700 + iPtrArray->Append(CTracker::NewL());
1.701 +
1.702 + iArrayWrapper->Append(CTracker::NewL());
1.703 +
1.704 + iArrayWrapper = iArray2;
1.705 +
1.706 + iArrayWrapper->Append(CTracker::NewL());
1.707 + iArrayWrapper->Append(CTracker::NewL());
1.708 +
1.709 + test.Printf(_L(" iLogger val = %d\n"), iLogger->GetData());
1.710 + test.Printf(_L(" iDestroyer val = %d\n"), (*iDestroyer).GetData());
1.711 +
1.712 + test.Printf(_L(" iConstLogger val = %d\n"), iConstLogger->GetData());
1.713 + test.Printf(_L(" iConstLogger val = %d\n"), (*iConstLogger).GetData());
1.714 +
1.715 + test.Printf(_L(" iAutoArray[0] val = %d\n"), iAutoArray[0].Value());
1.716 +
1.717 + iOtherRef.ReleaseResource();
1.718 + }
1.719 +
1.720 +
1.721 +CComposite::CComposite(TConstructionMode aMode)
1.722 + : iConstLogger(42),
1.723 + iLogger(1),
1.724 + iLogger2(2),
1.725 + iLogger3(new int(3)),
1.726 + iOther(42),
1.727 + iOtherRef(iOther),
1.728 + iAnotherLogger(iOtherRef.Unmanage()),
1.729 + iDestroyer(2),
1.730 + iAutoPtr(CTracker::NewL(aMode == EMemberConstructorLeaves ? CTracker::EConstructorLeaves : CTracker::ENonleavingConstructor)),
1.731 + iAutoArray(new(ELeave) CTracker[KNumTrackers]),
1.732 + iPtrArray(3),
1.733 + iArrayWrapper(iArray),
1.734 + iRawLogger(42),
1.735 + iGuard(RLogger::Cleanup, &iRawLogger),
1.736 + iPair1(1, 2),
1.737 + iPair2(one, 2),
1.738 + iPair3(1, two),
1.739 + iPair4(one, two)
1.740 + {
1.741 + test.Printf(_L(" CComposite(%d) with leaving constructor - %x\n"),
1.742 + aMode,
1.743 + this);
1.744 +
1.745 + iLogger = iLogger2.Unmanage();
1.746 +
1.747 + iPtrArray->Append(CTracker::NewL());
1.748 + iPtrArray->Append(CTracker::NewL());
1.749 +
1.750 + iArrayWrapper->Append(CTracker::NewL());
1.751 + iArrayWrapper->Append(CTracker::NewL());
1.752 +
1.753 + if (aMode == EConstructorLeaves)
1.754 + {
1.755 + test.Printf(_L("CComposite(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
1.756 + User::Leave(KErrGeneral);
1.757 + }
1.758 + }
1.759 +
1.760 +CComposite::~CComposite()
1.761 + {
1.762 + test.Printf(_L(" ~CComposite - %x\n"), this);
1.763 + }
1.764 +
1.765 +
1.766 +void CComposite::ReleaseLoggers()
1.767 + {
1.768 + test.Printf(_L(" CComposite::ReleaseLoggers - %x\n"), this);
1.769 +
1.770 + iLogger.ReleaseResource();
1.771 + iDestroyer.ReleaseResource();
1.772 +
1.773 + iGuard.Dismiss();
1.774 + iRawLogger.Release();
1.775 + }
1.776 +
1.777 +
1.778 +void CComposite::ReleaseArrays()
1.779 + {
1.780 + test.Printf(_L(" CComposite::ReleaseArrays - %x\n"), this);
1.781 +
1.782 + iAutoArray.ReleaseResource();
1.783 + }
1.784 +
1.785 +
1.786 +void TrackingDesCall(const TDesC& aConst, TDes& aMut)
1.787 + {
1.788 + test.Printf(_L("TrackingDesCall const=%S, mut=%S\n"), &aConst, &aMut);
1.789 + aMut.Append(_L(": Appended"));
1.790 + }
1.791 +
1.792 +
1.793 +
1.794 +/**
1.795 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4028
1.796 +@SYMTestCaseDesc Tests automatic cleanup if a leave occurs in a Constructor
1.797 +@SYMTestPriority High
1.798 +@SYMTestActions Creates a new CTracker instance passing EConstructorLeaves to the
1.799 + factory function which causes the constructor to leave.
1.800 + Verifies that all memory allocated in the constructor is
1.801 + automatically freed if the constructor leaves.
1.802 +@SYMTestExpectedResults All memory allocated in the constructor of CTracker should
1.803 + be automatically freed if the constructor leaves.
1.804 +@SYMREQ 10368
1.805 +*/
1.806 +void TestLeaveFromConstructor()
1.807 + {
1.808 +
1.809 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4028"));
1.810 +
1.811 + __UHEAP_MARK;
1.812 + test.Next(_L("Test CONSTRUCTORS_MAY_LEAVE"));
1.813 +
1.814 + TRAPD(status,
1.815 + {
1.816 + CTracker* tracker = CTracker::NewL(CTracker::EConstructorLeaves);
1.817 + tracker->MemFunc();
1.818 + });
1.819 + if (status != KErrNone)
1.820 + {
1.821 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.822 + }
1.823 +
1.824 + __UHEAP_MARKEND;
1.825 + }
1.826 +
1.827 +/**
1.828 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4029
1.829 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle using different
1.830 + cleanup strategies
1.831 +@SYMTestPriority High
1.832 +@SYMTestActions Creates a LCleanedupHandle<RLogger> objects with different cleanup strategies.
1.833 + Verifies that the objects are automatically cleaned up when they go
1.834 + out of scope
1.835 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.836 + objects is automatically freed when the object goes out of scope.
1.837 +@SYMREQ 10373-8
1.838 +*/
1.839 +void TestLCleanedupHandleStrategies()
1.840 + {
1.841 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4029"));
1.842 +
1.843 + __UHEAP_MARK;
1.844 + test.Next(_L("LCleanedupHandle - test cleanup strategies"));
1.845 +
1.846 + {
1.847 + LCleanedupHandle<RLogger> logger(1);
1.848 + LCleanedupHandle<RLogger, TClose> logger2(2);
1.849 + LCleanedupHandle<RLogger, TRelease> logger3(3);
1.850 + LCleanedupHandle<RLogger, TDestroy> logger4(4);
1.851 + LCleanedupHandle<RLogger, TFree> logger5(5);
1.852 + }
1.853 +
1.854 + __UHEAP_MARKEND;
1.855 + }
1.856 +
1.857 +/**
1.858 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4030
1.859 +@SYMTestCaseDesc Tests construction of LCleanedUpHandle objects using complex constructors
1.860 +@SYMTestPriority High
1.861 +@SYMTestActions Creates a LCleanedupHandle<RPair> objects using different constructors.
1.862 + Verifies that the objects are automatically cleaned up when they go
1.863 + out of scope
1.864 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RPair>
1.865 + objects is automatically freed when the object goes out of scope.
1.866 +@SYMREQ 10373-8
1.867 +*/
1.868 +void TestLCleanedupConstructors()
1.869 + {
1.870 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4030"));
1.871 +
1.872 + __UHEAP_MARK;
1.873 +
1.874 + {
1.875 + LCleanedupHandle<RLogger> logger(1);
1.876 +
1.877 + LCleanedupHandle<RPair> pair1(1, 2);
1.878 + LCleanedupHandle<RPair> pair2(one, 2);
1.879 + LCleanedupHandle<RPair> pair3(1, two);
1.880 + LCleanedupHandle<RPair> pair4(one, two);
1.881 + }
1.882 +
1.883 + __UHEAP_MARKEND;
1.884 + }
1.885 +
1.886 +/**
1.887 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4031
1.888 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle
1.889 +@SYMTestPriority High
1.890 +@SYMTestActions Creates an LCleanedupHandle<RLogger> on the stack and uses the object.
1.891 + Verifies that the object is automatically cleaned up when it goes out of scope
1.892 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.893 + is automatically freed when the object goes out of scope
1.894 +@SYMREQ 10373-8
1.895 +*/
1.896 +void TestLCleanedupHandleNormalL()
1.897 + {
1.898 +
1.899 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4031"));
1.900 +
1.901 + __UHEAP_MARK;
1.902 + test.Next(_L("LCleanedupHandle - test normal exit from a block scope"));
1.903 +
1.904 + {
1.905 + LCleanedupHandle<RLogger> logger;
1.906 + logger->OpenL(42);
1.907 +
1.908 + LCleanedupHandle<RLogger> logger2(42);
1.909 + }
1.910 +
1.911 + __UHEAP_MARKEND;
1.912 + }
1.913 +
1.914 +
1.915 +/**
1.916 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4032
1.917 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle object on a leave
1.918 +@SYMTestPriority High
1.919 +@SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and uses the object.
1.920 + Verifies that the object is automatically cleaned up when a leave occurs
1.921 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.922 + is automatically freed when a leave occurs
1.923 +@SYMREQ 10373-8
1.924 +*/
1.925 +void TestLCleanedupHandleLeave()
1.926 + {
1.927 +
1.928 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4032"));
1.929 +
1.930 + __UHEAP_MARK;
1.931 + test.Next(_L("LCleanedupHandle - test leave"));
1.932 +
1.933 + TRAPD(status,
1.934 + {
1.935 + LCleanedupHandle<RLogger> logger(42);
1.936 + test.Printf(_L("TestLCleanedupHandleLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.937 + User::Leave(KErrGeneral);
1.938 + });
1.939 + if (status != KErrNone)
1.940 + {
1.941 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.942 + }
1.943 +
1.944 + __UHEAP_MARKEND;
1.945 + }
1.946 +
1.947 +/**
1.948 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4033
1.949 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupHandle object.
1.950 +@SYMTestPriority High
1.951 +@SYMTestActions Creates LCleanedupHandle<RLogger> objects on the stack and
1.952 + manually Unmanages and Closes the Handles.
1.953 + Verifies that all memory allocated for the objects can be freed
1.954 + manually.
1.955 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.956 + is freed by calling Unmanage() and Close()
1.957 +@SYMREQ 10373-8, 10375-5
1.958 +*/
1.959 +void TestLCleanedupHandleUnmanage()
1.960 + {
1.961 +
1.962 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4033"));
1.963 +
1.964 + __UHEAP_MARK;
1.965 + test.Next(_L("LCleanedupHandle - test LCleanedupHandle::Unmanage"));
1.966 +
1.967 + LCleanedupHandle<RLogger> logger1(1);
1.968 + LCleanedupHandle<RLogger> logger2(2);
1.969 + logger1.Unmanage();
1.970 + logger1->Close();
1.971 + logger2.Unmanage();
1.972 + logger2->Close();
1.973 +
1.974 + __UHEAP_MARKEND;
1.975 + }
1.976 +
1.977 +/**
1.978 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4034
1.979 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupHandle object on a leave
1.980 +@SYMTestPriority High
1.981 +@SYMTestActions Creates LCleanedupHandle<RLogger> objects on the stack and
1.982 + manually Unmanages them.
1.983 + Forces a leave and then Closes the Handles.
1.984 + Verifies that all memory allocated for the objects can be freed
1.985 + manually in the event of a leave occuring
1.986 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.987 + is freed by calling Unmanage() and Close()
1.988 +@SYMREQ 10373-8, 10375-5
1.989 +*/
1.990 +void TestLCleanedupHandleUnmanageLeave()
1.991 + {
1.992 +
1.993 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4034"));
1.994 +
1.995 + __UHEAP_MARK;
1.996 + test.Next(_L("LCleanedupHandle - test LCleanedupHandle::Unmanage and leave"));
1.997 +
1.998 + RLogger logger1;
1.999 + RLogger logger2;
1.1000 + TRAPD(status,
1.1001 + {
1.1002 + LCleanedupHandle<RLogger> auto_logger1(1);
1.1003 + LCleanedupHandle<RLogger> auto_logger2(2);
1.1004 +
1.1005 + logger1 = auto_logger1.Unmanage();
1.1006 + logger2 = auto_logger2.Unmanage();
1.1007 +
1.1008 + test.Printf(_L("TestLCleanedupHandleUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.1009 +
1.1010 + User::Leave(KErrGeneral);
1.1011 + });
1.1012 + if (status != KErrNone)
1.1013 + {
1.1014 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1015 + logger1.Close();
1.1016 + logger2.Close();
1.1017 + }
1.1018 +
1.1019 + __UHEAP_MARKEND;
1.1020 + }
1.1021 +
1.1022 +/**
1.1023 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4035
1.1024 +@SYMTestCaseDesc Tests access to managed object through LCleanedupHandle
1.1025 +@SYMTestPriority High
1.1026 +@SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and
1.1027 + uses the LCleanedupHandle object to access RLogger methods
1.1028 + via the -> operator and the LCleanedupHandle methods via
1.1029 + the . operator
1.1030 +@SYMTestExpectedResults All public RLogger methods and LCleanedupHandle methods
1.1031 + should be accessible through the LCleanedupHandle object.
1.1032 +@SYMREQ 10373-8
1.1033 +*/
1.1034 +void TestLCleanedupHandleObjectAccess()
1.1035 + {
1.1036 +
1.1037 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4035"));
1.1038 +
1.1039 + __UHEAP_MARK;
1.1040 + test.Next(_L("LCleanedupHandle - test object access"));
1.1041 +
1.1042 + {
1.1043 + LCleanedupHandle<RLogger> logger(42);
1.1044 + logger->MemFunc();
1.1045 + RLogger::StaticMemberRef(*logger);
1.1046 + RLogger::StaticMemberPtr(&logger.Get());
1.1047 + }
1.1048 +
1.1049 + __UHEAP_MARKEND;
1.1050 + }
1.1051 +
1.1052 +/**
1.1053 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4036
1.1054 +@SYMTestCaseDesc Tests forced cleanup of LCleanedupHandle object.
1.1055 +@SYMTestPriority High
1.1056 +@SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and
1.1057 + forces cleanup by calling ReleaseResource().
1.1058 + Verifies that all memory allocated for the object is freed
1.1059 + by calling ReleaseResource();
1.1060 +@SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
1.1061 + is freed by calling ReleaseResource().
1.1062 +@SYMREQ 10373-8, 10375-4
1.1063 +*/
1.1064 +void TestLCleanedupHandleRelease()
1.1065 + {
1.1066 +
1.1067 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4036"));
1.1068 +
1.1069 + __UHEAP_MARK;
1.1070 + test.Next(_L("LCleanedupHandle - test LCleanedupHandle::ReleaseResource"));
1.1071 +
1.1072 + LCleanedupHandle<RLogger> logger(42);
1.1073 + logger.ReleaseResource();
1.1074 +
1.1075 + LCleanedupHandle<RLogger> logger2(2);
1.1076 + RLogger raw_logger = logger2.Unmanage();
1.1077 + logger2.ReleaseResource();
1.1078 + raw_logger.Close();
1.1079 +
1.1080 + __UHEAP_MARKEND;
1.1081 + }
1.1082 +
1.1083 +/**
1.1084 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4037
1.1085 +@SYMTestCaseDesc Tests cleanup of derived objects using LCleanedupHandle<XXX>
1.1086 +@SYMTestPriority High
1.1087 +@SYMTestActions Creates LCleanedupHandle<XXX> objects on the stack by instantiating
1.1088 + derived classes.
1.1089 + Verifies that all memory allocated for the objects is freed
1.1090 + automatically when the objects go out of scope.
1.1091 +@SYMTestExpectedResults All memory allocated for the derived classes is freed
1.1092 + automatically.
1.1093 +@SYMREQ 10373-8
1.1094 +*/
1.1095 +void TestLCleanedupHandleConversionL()
1.1096 + {
1.1097 +
1.1098 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4037"));
1.1099 +
1.1100 + __UHEAP_MARK;
1.1101 + test.Next(_L("LCleanedupHandle - test convertible type support"));
1.1102 +
1.1103 + {
1.1104 + ROtherLogger olog;
1.1105 + olog.OpenL(1);
1.1106 + LCleanedupHandle<RLogger> logger(olog);
1.1107 + }
1.1108 +
1.1109 + {
1.1110 + RLogger log2;
1.1111 + log2.OpenL(2);
1.1112 + LCleanedupHandle<ROtherLogger> ologger(3);
1.1113 + ologger = log2;
1.1114 +
1.1115 + ROtherLogger olog4(4);
1.1116 + ologger = olog4;
1.1117 + }
1.1118 +
1.1119 + __UHEAP_MARKEND;
1.1120 + }
1.1121 +
1.1122 +
1.1123 +void TestLCleanedupHandleL()
1.1124 + {
1.1125 + __UHEAP_MARK;
1.1126 +
1.1127 + TestLCleanedupHandleStrategies();
1.1128 + TestLCleanedupConstructors();
1.1129 + TestLCleanedupHandleNormalL();
1.1130 + TestLCleanedupHandleLeave();
1.1131 + TestLCleanedupHandleUnmanage();
1.1132 + TestLCleanedupHandleUnmanageLeave();
1.1133 + TestLCleanedupHandleObjectAccess();
1.1134 + TestLCleanedupHandleRelease();
1.1135 + TestLCleanedupHandleConversionL();
1.1136 +
1.1137 + __UHEAP_MARKEND;
1.1138 + }
1.1139 +
1.1140 +
1.1141 +/**
1.1142 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4038
1.1143 +@SYMTestCaseDesc Tests cleanup of Null pointer LCleanedupPtr object
1.1144 +@SYMTestPriority High
1.1145 +@SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack but doesnt
1.1146 + intialise the pointer.
1.1147 + Verifies that the object is cleaned up when it goes out of scope
1.1148 +@SYMTestExpectedResults Cleanup of a NULL pointer should complete successfully
1.1149 +@SYMREQ 10373-6
1.1150 +*/
1.1151 +void TestLCleanedupPtrNull()
1.1152 + {
1.1153 +
1.1154 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4038"));
1.1155 +
1.1156 + __UHEAP_MARK;
1.1157 + test.Next(_L("LCleanedupPtr - test null pointer"));
1.1158 +
1.1159 + {
1.1160 + LCleanedupPtr<CTracker> tracker;
1.1161 + LCleanedupPtr<TInt> tint;
1.1162 + }
1.1163 +
1.1164 + __UHEAP_MARKEND;
1.1165 + }
1.1166 +
1.1167 +/**
1.1168 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4039
1.1169 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupPtr object
1.1170 +@SYMTestPriority High
1.1171 +@SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and uses the object.
1.1172 + Verifies that the object is automatically cleaned up when it goes out of scope
1.1173 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
1.1174 + is automatically freed when it goes out of scope.
1.1175 +@SYMREQ 10373-6
1.1176 +*/
1.1177 +void TestLCleanedupPtrNormalL()
1.1178 + {
1.1179 +
1.1180 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4039"));
1.1181 +
1.1182 + __UHEAP_MARK;
1.1183 + test.Next(_L("LCleanedupPtr - test normal exit from a block scope"));
1.1184 +
1.1185 + {
1.1186 + LCleanedupPtr<CTracker> tracker(CTracker::NewL());
1.1187 + LCleanedupPtr<TInt> tint(new TInt(42));
1.1188 + }
1.1189 +
1.1190 + __UHEAP_MARKEND;
1.1191 + }
1.1192 +
1.1193 +/**
1.1194 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4040
1.1195 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupPtr object on a leave
1.1196 +@SYMTestPriority High
1.1197 +@SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and uses the object.
1.1198 + Verifies that the object is automatically cleaned up when a leave occurs
1.1199 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
1.1200 + is automatically freed when a leave occurs
1.1201 +@SYMREQ 10373-6
1.1202 +*/
1.1203 +void TestLCleanedupPtrLeave()
1.1204 + {
1.1205 +
1.1206 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4040"));
1.1207 +
1.1208 + __UHEAP_MARK;
1.1209 + test.Next(_L("LCleanedupPtr - test leave"));
1.1210 +
1.1211 + TRAPD(status,
1.1212 + {
1.1213 + LCleanedupPtr<CTracker> tracker(CTracker::NewL());
1.1214 + LCleanedupPtr<CTracker> nulltracker;
1.1215 + LCleanedupPtr<TInt> tint(new TInt(42));
1.1216 + LCleanedupPtr<TInt> nullint;
1.1217 +
1.1218 + test.Printf(_L("TestLCleanedupPtrLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.1219 + User::Leave(KErrGeneral);
1.1220 + });
1.1221 + if (status != KErrNone)
1.1222 + {
1.1223 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1224 + }
1.1225 +
1.1226 + __UHEAP_MARKEND;
1.1227 + }
1.1228 +
1.1229 +/**
1.1230 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4041
1.1231 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupPtr object.
1.1232 +@SYMTestPriority High
1.1233 +@SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack and
1.1234 + manually Unmanages and deletes the CTracker objects
1.1235 + Verifies that all memory allocated for the objects can be freed
1.1236 + manually.
1.1237 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
1.1238 + is freed by calling Unmanage() and deleting the objects
1.1239 +@SYMREQ 10373-6, 10375-5
1.1240 +*/
1.1241 +void TestLCleanedupPtrUnmanageL()
1.1242 + {
1.1243 +
1.1244 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4041"));
1.1245 +
1.1246 + __UHEAP_MARK;
1.1247 + test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage"));
1.1248 +
1.1249 + {
1.1250 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1251 + LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
1.1252 + delete tracker1.Unmanage();
1.1253 + delete tracker2.Unmanage();
1.1254 + }
1.1255 +
1.1256 + __UHEAP_MARKEND;
1.1257 + }
1.1258 +
1.1259 +/**
1.1260 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4042
1.1261 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupPtr object on a leave
1.1262 +@SYMTestPriority High
1.1263 +@SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack and
1.1264 + manually Unmanages them.
1.1265 + Forces a leave and then deletes the CTracker objects.
1.1266 + Verifies that all memory allocated for the objects can be freed
1.1267 + manually in the event of a leave occuring
1.1268 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
1.1269 + is freed by calling Unmanage() and deleting the objects
1.1270 +@SYMREQ 10373-6, 10375-5
1.1271 +*/
1.1272 +void TestLCleanedupPtrUnmanageLeave()
1.1273 + {
1.1274 +
1.1275 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4042"));
1.1276 +
1.1277 + __UHEAP_MARK;
1.1278 + test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage and leave"));
1.1279 +
1.1280 +
1.1281 + {
1.1282 + CTracker* ptr1 = NULL;
1.1283 + CTracker* ptr2 = NULL;
1.1284 + TRAPD(status2,
1.1285 + {
1.1286 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1287 + LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
1.1288 +
1.1289 + ptr1 = tracker1.Unmanage();
1.1290 + ptr2 = tracker2.Unmanage();
1.1291 +
1.1292 + test.Printf(_L("TestLCleanedupPtrUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.1293 + User::Leave(KErrGeneral);
1.1294 + });
1.1295 +
1.1296 + if (status2 != KErrNone)
1.1297 + {
1.1298 + test.Printf(_L("Leave trapped; leave code: %d\n"), status2);
1.1299 + delete ptr1;
1.1300 + delete ptr2;
1.1301 + }
1.1302 + }
1.1303 +
1.1304 +
1.1305 + __UHEAP_MARKEND;
1.1306 + }
1.1307 +
1.1308 +/**
1.1309 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4043
1.1310 +@SYMTestCaseDesc Tests access to managed object through LCleanedupPtr
1.1311 +@SYMTestPriority High
1.1312 +@SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and
1.1313 + uses the LCleanedupPtr object to access CTracker methods
1.1314 + via the -> operator and the LCleanedupPtr methods via
1.1315 + the . operator
1.1316 +@SYMTestExpectedResults All public CTracker methods and LCleanedupPtr
1.1317 + should be accessible through the LCleanedupPtr object.
1.1318 +@SYMREQ 10373-6
1.1319 +*/
1.1320 +void TestLCleanedupPtrObjectAccessL()
1.1321 + {
1.1322 +
1.1323 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4043"));
1.1324 +
1.1325 + __UHEAP_MARK;
1.1326 + test.Next(_L("LCleanedupPtr - test managed object access"));
1.1327 +
1.1328 + {
1.1329 + LCleanedupPtr<CTracker> tracker(CTracker::NewL());
1.1330 + tracker->MemFunc();
1.1331 + CTracker::StaticMemberRef(*tracker);
1.1332 + CTracker::StaticMemberPtr(tracker.Get());
1.1333 + }
1.1334 +
1.1335 + __UHEAP_MARKEND;
1.1336 + }
1.1337 +
1.1338 +/**
1.1339 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4044
1.1340 +@SYMTestCaseDesc Tests forced cleanup of LCleanedupPtr object.
1.1341 +@SYMTestPriority High
1.1342 +@SYMTestActions Creates an LCleanedupPtr<CTracker>> on the stack and
1.1343 + forces cleanup by calling ReleaseResource().
1.1344 + Verifies that all memory allocated for the object is freed
1.1345 + by calling ReleaseResource()
1.1346 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
1.1347 + is freed by calling ReleaseResource().
1.1348 +@SYMREQ 10373-6, 10375-4
1.1349 +*/
1.1350 +void TestLCleanedupPtrReleaseL()
1.1351 + {
1.1352 +
1.1353 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4044"));
1.1354 +
1.1355 + __UHEAP_MARK;
1.1356 + test.Next(_L("LCleanedupPtr - test LCleanedupPtr::ReleaseResource"));
1.1357 +
1.1358 +
1.1359 + {
1.1360 + LCleanedupPtr<CTracker> tracker(CTracker::NewL());
1.1361 + tracker.ReleaseResource();
1.1362 +
1.1363 + LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
1.1364 + CTracker* ptracker2 = tracker2.Unmanage();
1.1365 + tracker2.ReleaseResource();
1.1366 + delete ptracker2;
1.1367 +
1.1368 + LCleanedupPtr<CTracker> tracker3(CTracker::NewL());
1.1369 + tracker3 = NULL;
1.1370 + }
1.1371 +
1.1372 + __UHEAP_MARKEND;
1.1373 + }
1.1374 +
1.1375 +/**
1.1376 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4045
1.1377 +@SYMTestCaseDesc Tests cleanup of LCleanedupPtr object using TPointerFree strategy
1.1378 +@SYMTestPriority High
1.1379 +@SYMTestActions Creates an LCleanedupPtr<TText, TPointerFree> on the stack and
1.1380 + uses the object.
1.1381 + Verifies that all memory allocated for the object is freed by the
1.1382 + TPointerFree cleanup strategy when the object goes out of scope.
1.1383 +@SYMTestExpectedResults All memory allocated for the LCleanedupPtr<TText, TPointerFree>
1.1384 + object is freed by the TPointerFree cleanup strategy.
1.1385 +@SYMREQ 10373-6
1.1386 +*/
1.1387 +void TestLCleanedupPtrPointerFree()
1.1388 + {
1.1389 +
1.1390 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4045"));
1.1391 +
1.1392 + __UHEAP_MARK;
1.1393 + test.Next(_L("LCleanedupPtr - test TPointerFree"));
1.1394 +
1.1395 + {
1.1396 + LCleanedupPtr<TText, TPointerFree> buffer(
1.1397 + static_cast<TText*>(User::Alloc(100 * sizeof(TText))));
1.1398 + TPtr bufferPtr(buffer.Get(), 100); // create a pointer to the buffer
1.1399 + // use the buffer
1.1400 + bufferPtr.Copy(_L("Hello RAII"));
1.1401 + test.Printf(_L("%S\n"), &bufferPtr);
1.1402 + }
1.1403 +
1.1404 + __UHEAP_MARKEND;
1.1405 + }
1.1406 +
1.1407 +
1.1408 +void TestLCleanedupPtrConversionL()
1.1409 + {
1.1410 + LCleanedupPtr<CTracker> tracker(CDerivedTracker::NewL());
1.1411 +
1.1412 + LCleanedupPtr<TReal64, TPointerFree> real(
1.1413 + static_cast<TReal64*>(User::Alloc(sizeof(TReal64))));
1.1414 +
1.1415 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1416 + LCleanedupPtr<CDerivedTracker> derivedTracker(CDerivedTracker::NewL());
1.1417 +
1.1418 + tracker1 = derivedTracker.Unmanage();
1.1419 +
1.1420 + }
1.1421 +
1.1422 +/**
1.1423 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4046
1.1424 +@SYMTestCaseDesc Tests cleanup of derived objects using LCleanedupPtr<XXX>
1.1425 +@SYMTestPriority High
1.1426 +@SYMTestActions Creates an LCleanedupPtr<XXX> objects on the stack by instantiating
1.1427 + derived classes.
1.1428 + Verifies that all memory allocated for the objects is freed
1.1429 + automatically when the objects go out of scope.
1.1430 +@SYMTestExpectedResults All memory allocated for the derived classes is freed
1.1431 + automatically.
1.1432 +@SYMREQ 10373-6
1.1433 +*/
1.1434 +void TestLCleanedupPtrConversion()
1.1435 + {
1.1436 +
1.1437 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4046"));
1.1438 +
1.1439 + __UHEAP_MARK;
1.1440 + test.Next(_L("LCleanedupPtr - test convertible type support"));
1.1441 +
1.1442 + TRAPD(status, TestLCleanedupPtrConversionL());
1.1443 +
1.1444 + if (status != KErrNone)
1.1445 + {
1.1446 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1447 + }
1.1448 +
1.1449 + __UHEAP_MARKEND;
1.1450 + }
1.1451 +
1.1452 +/**
1.1453 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4047
1.1454 +@SYMTestCaseDesc Tests assignment of LCleanedupPtr<XXX> objects
1.1455 +@SYMTestPriority High
1.1456 +@SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack.
1.1457 + Unamanages one of the objects and assigns the managed pointer
1.1458 + to the second LCleanedupPtr
1.1459 + Verifies that all memory allocated for the objects is freed
1.1460 + automatically when the objects go out of scope.
1.1461 +@SYMTestExpectedResults All memory allocated for the objects is freed
1.1462 + automatically when the objects go out of scope.
1.1463 +@SYMREQ 10373-6
1.1464 +*/
1.1465 +void TestLCleanedupPtrAssignL()
1.1466 + {
1.1467 +
1.1468 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4047"));
1.1469 +
1.1470 + __UHEAP_MARK;
1.1471 + test.Next(_L("LCleanedupPtr - test LCleanedupPtr reset"));
1.1472 +
1.1473 + {
1.1474 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1475 + LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
1.1476 +
1.1477 + tracker2 = tracker1.Unmanage();
1.1478 + }
1.1479 +
1.1480 + __UHEAP_MARKEND;
1.1481 + }
1.1482 +
1.1483 +void TestLCleanedupPtrBoolConversionL()
1.1484 + {
1.1485 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1486 +
1.1487 + if (tracker1)
1.1488 + {
1.1489 + test.Printf(_L("TestLCleanedupPtrBoolConversion: tracker1 pointer = %x\n"), tracker1.Get());
1.1490 + }
1.1491 + else
1.1492 + {
1.1493 + test.Printf(_L("TestLCleanedupPtrBoolConversion: tracker1 pointer is null (%x)\n"), tracker1.Get());
1.1494 + }
1.1495 +
1.1496 + LCleanedupPtr<CTracker> nullPtr;
1.1497 +
1.1498 + if (!nullPtr)
1.1499 + {
1.1500 + test.Printf(_L("TestLCleanedupPtrBoolConversion: nullPtr pointer is null (%x)\n"), nullPtr.Get());
1.1501 + }
1.1502 + else
1.1503 + {
1.1504 + test.Printf(_L("TestLCleanedupPtrBoolConversion: nullPtr pointer = %x\n"), nullPtr.Get());
1.1505 + }
1.1506 + }
1.1507 +
1.1508 +/**
1.1509 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4048
1.1510 +@SYMTestCaseDesc Tests conversion of LCleanedupPtr<XXX> objects
1.1511 +@SYMTestPriority High
1.1512 +@SYMTestActions Calls TestLCleanedupPtrBoolConversionL which creates 2
1.1513 + LCleanedupPtr<CTracker> objects on the stack, one of which
1.1514 + is a null pointer. Tests conversion of the null pointer
1.1515 + into a CTracker* via the Get() method and ensures all
1.1516 + memory is freed on scope exit.
1.1517 +@SYMTestExpectedResults All memory allocated for the objects is freed
1.1518 + automatically when the objects go out of scope.
1.1519 +@SYMREQ 10373-6
1.1520 +*/
1.1521 +void TestLCleanedupPtrBoolConversion()
1.1522 + {
1.1523 +
1.1524 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4048"));
1.1525 +
1.1526 + __UHEAP_MARK;
1.1527 + test.Next(_L("LCleanedupPtr - test bool conversion"));
1.1528 +
1.1529 + TRAPD(status, TestLCleanedupPtrBoolConversionL());
1.1530 +
1.1531 + if (status != KErrNone)
1.1532 + {
1.1533 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1534 + }
1.1535 +
1.1536 + __UHEAP_MARKEND;
1.1537 + }
1.1538 +
1.1539 +
1.1540 +void TestLCleanedupPtrCompareL()
1.1541 + {
1.1542 + LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
1.1543 + LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
1.1544 +
1.1545 + if (tracker1 == tracker2)
1.1546 + {
1.1547 + test.Printf(_L("tracker1 == tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1548 + }
1.1549 +
1.1550 + if (tracker1 != tracker2)
1.1551 + {
1.1552 + test.Printf(_L("tracker1 != tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1553 + }
1.1554 +
1.1555 +
1.1556 + if (tracker1 < tracker2)
1.1557 + {
1.1558 + test.Printf(_L("tracker1 < tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1559 + }
1.1560 +
1.1561 +
1.1562 + tracker2 = tracker1.Get();
1.1563 +
1.1564 + if (tracker1 == tracker2)
1.1565 + {
1.1566 + test.Printf(_L("tracker1 == tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1567 + }
1.1568 +
1.1569 + if (tracker1 != tracker2)
1.1570 + {
1.1571 + test.Printf(_L("tracker1 != tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1572 + }
1.1573 +
1.1574 + if (tracker1 < tracker2)
1.1575 + {
1.1576 + test.Printf(_L("tracker1 < tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
1.1577 + }
1.1578 +
1.1579 + tracker1.Unmanage();
1.1580 + }
1.1581 +
1.1582 +
1.1583 +/**
1.1584 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4049
1.1585 +@SYMTestCaseDesc Tests comparison of LCleanedupPtr<XXX> objects
1.1586 +@SYMTestPriority High
1.1587 +@SYMTestActions Calls TestLCleanedupPtrCompareL which creates 2
1.1588 + LCleanedupPtr<CTracker> objects on the stack.
1.1589 + Compares the objects using the comparison operators
1.1590 + and ensures all memory is freed on scope exit.
1.1591 +@SYMTestExpectedResults All memory allocated for the objects is freed
1.1592 + automatically when the objects go out of scope.
1.1593 +@SYMREQ 10373-6
1.1594 +*/
1.1595 +void TestLCleanedupPtrCompare()
1.1596 + {
1.1597 +
1.1598 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4049"));
1.1599 +
1.1600 + __UHEAP_MARK;
1.1601 + test.Next(_L("LCleanedupPtr - test compare"));
1.1602 +
1.1603 + TRAPD(status, TestLCleanedupPtrCompareL());
1.1604 +
1.1605 + if (status != KErrNone)
1.1606 + {
1.1607 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1608 + }
1.1609 +
1.1610 + __UHEAP_MARKEND;
1.1611 + }
1.1612 +
1.1613 +/**
1.1614 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4067
1.1615 +@SYMTestCaseDesc Tests execution of custom cleanup strategy for LCleanedupPtr<XXX> objects
1.1616 +@SYMTestPriority High
1.1617 +@SYMTestActions Creates an LCleanedupPtr<CTracker, TCTrackerDestroy> object
1.1618 + on the stack which uses a custom cleanup strategy.
1.1619 + Verifies that the custom strategy is invoked when the object goes out
1.1620 + of scope.
1.1621 +@SYMTestExpectedResults All memory allocated for the object is freed automatically by
1.1622 + the custom cleanup strategy when the objecs goes out of scope.
1.1623 +@SYMREQ 10373
1.1624 +*/
1.1625 +void TestLCleanedupPtrCustomStrategyL()
1.1626 + {
1.1627 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4067"));
1.1628 +
1.1629 + __UHEAP_MARK;
1.1630 + test.Next(_L("LCleanedupPtr - test TCTrackerDestroy strategy"));
1.1631 +
1.1632 + {
1.1633 + LCleanedupPtr<CTracker, TCTrackerDestroy> t(new(ELeave) CTracker);
1.1634 + }
1.1635 +
1.1636 + test(trackerDestroyed);
1.1637 +
1.1638 + __UHEAP_MARKEND;
1.1639 +
1.1640 + }
1.1641 +
1.1642 +
1.1643 +void TestLCleanedupPtrL()
1.1644 + {
1.1645 + __UHEAP_MARK;
1.1646 +
1.1647 + TestLCleanedupPtrNull();
1.1648 + TestLCleanedupPtrNormalL();
1.1649 + TestLCleanedupPtrLeave();
1.1650 + TestLCleanedupPtrUnmanageL();
1.1651 + TestLCleanedupPtrUnmanageLeave();
1.1652 + TestLCleanedupPtrObjectAccessL();
1.1653 + TestLCleanedupPtrReleaseL();
1.1654 + TestLCleanedupPtrPointerFree();
1.1655 + TestLCleanedupPtrConversion();
1.1656 + TestLCleanedupPtrAssignL();
1.1657 + TestLCleanedupPtrBoolConversion();
1.1658 + TestLCleanedupPtrCompare();
1.1659 + TestLCleanedupPtrCustomStrategyL();
1.1660 +
1.1661 + __UHEAP_MARKEND;
1.1662 + }
1.1663 +
1.1664 +
1.1665 +class TLogCleanupStrategy
1.1666 + {
1.1667 + public:
1.1668 + template <class T>
1.1669 + static void Cleanup(T* aObjPtr)
1.1670 + {
1.1671 + test.Printf(_L("Cleanup log: %x\n"), aObjPtr);
1.1672 + }
1.1673 + };
1.1674 +
1.1675 +/**
1.1676 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4050
1.1677 +@SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects
1.1678 +@SYMTestPriority High
1.1679 +@SYMTestActions Creates an LCleanedupPtr<CComposite> on the stack -
1.1680 + CComposite internally contains LManagedXX objects
1.1681 + Verify that all LManagedXX objects are cleaned up when
1.1682 + the LCleanedupPtr<CComposite> object goes out of scope.
1.1683 +@SYMTestExpectedResults All memory allocated for the CComposite object
1.1684 + is automatically freed when it goes out of scope.
1.1685 +@SYMREQ 10374
1.1686 +*/
1.1687 +void TestLManagedNormalL()
1.1688 + {
1.1689 +
1.1690 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4050"));
1.1691 +
1.1692 + __UHEAP_MARK;
1.1693 + test.Next(_L("LManaged - test composite object with normal exit from a block scope "));
1.1694 +
1.1695 + {
1.1696 + LCleanedupPtr<CComposite> comp(CComposite::NewL());
1.1697 + }
1.1698 +
1.1699 + //Check that the custom cleanup strategy for the iAutoPtr member of
1.1700 + //CComposite has been invoked
1.1701 + test(trackerDestroyed);
1.1702 +
1.1703 + __UHEAP_MARKEND;
1.1704 + }
1.1705 +
1.1706 +/**
1.1707 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4051
1.1708 +@SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects if
1.1709 + a leave occurs in a Constructor
1.1710 +@SYMTestPriority High
1.1711 +@SYMTestActions Creates an LCleanedupPtr<CComposite> object on the stack
1.1712 + passing EConstructorLeaves to the CComposite factory function
1.1713 + which causes the constructor to leave.
1.1714 + Verifies that all memory allocated in the constructor is
1.1715 + automatically freed if the constructor leaves.
1.1716 +@SYMTestExpectedResults All memory allocated for the CComposite object
1.1717 + is automatically freed when it goes out of scope.
1.1718 +@SYMREQ 10368, 10374
1.1719 +*/
1.1720 +void TestLManagedConstructorLeave()
1.1721 + {
1.1722 +
1.1723 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4051"));
1.1724 +
1.1725 + __UHEAP_MARK;
1.1726 + test.Next(_L("LManaged - test composite object with leave from constructor"));
1.1727 +
1.1728 + TRAPD(status,
1.1729 + {
1.1730 + LCleanedupPtr<CComposite> comp(CComposite::NewL(CComposite::EConstructorLeaves));
1.1731 + });
1.1732 +
1.1733 + if (status != KErrNone)
1.1734 + {
1.1735 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1736 + }
1.1737 +
1.1738 + //Check that the custom cleanup strategy for the iAutoPtr member of
1.1739 + //CComposite has been invoked
1.1740 + test(trackerDestroyed);
1.1741 +
1.1742 + __UHEAP_MARKEND;
1.1743 + }
1.1744 +
1.1745 +/**
1.1746 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4052
1.1747 +@SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects if
1.1748 + a leave occurs in a Constructor
1.1749 +@SYMTestPriority High
1.1750 +@SYMTestActions Creates an LCleanedupPtr<CComposite> object on the stack
1.1751 + passing EMemberConstructorLeaves to the CComposite factory function
1.1752 + which causes the constructor of the CTracker member to leave.
1.1753 + The CComposite object contains several LManagedX members which are
1.1754 + instantiated in the constructor.
1.1755 + Verifies that all memory allocated in the constructor is
1.1756 + automatically freed if the constructor leaves.
1.1757 +@SYMTestExpectedResults All memory allocated for the CComposite object
1.1758 + is automatically freed when it goes out of scope.
1.1759 +@SYMREQ 10368, 10374
1.1760 +*/
1.1761 +void TestLManagedMemberConstructorLeave()
1.1762 + {
1.1763 +
1.1764 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4052"));
1.1765 +
1.1766 + __UHEAP_MARK;
1.1767 + test.Next(_L("LManaged - test composite object with leave from member constructor"));
1.1768 +
1.1769 + TRAPD(status,
1.1770 + {
1.1771 + LCleanedupPtr<CComposite> comp(CComposite::NewL(CComposite::EMemberConstructorLeaves));
1.1772 + });
1.1773 +
1.1774 + if (status != KErrNone)
1.1775 + {
1.1776 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1777 + }
1.1778 +
1.1779 + //Check that the custom cleanup strategy for the iAutoPtr member of
1.1780 + //CComposite has been invoked
1.1781 + test(trackerDestroyed);
1.1782 +
1.1783 + __UHEAP_MARKEND;
1.1784 + }
1.1785 +
1.1786 +
1.1787 +/**
1.1788 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4053
1.1789 +@SYMTestCaseDesc Tests realease of LManagedX classes
1.1790 +@SYMTestPriority High
1.1791 +@SYMTestActions Creates 2 LCleanedupPtr<CComposite> objects on the stack.
1.1792 + Calls ReleaseLoggers() and ReleaseArrays() on the managed objects.
1.1793 + Verifies that all memory allocated for the objects is freed
1.1794 + automatically when the objects go out of scope.
1.1795 +@SYMTestExpectedResults All memory allocated for the objects is freed
1.1796 + automatically when the objects go out of scope.
1.1797 +@SYMREQ 10374
1.1798 +*/
1.1799 +void TestLManagedReleaseL()
1.1800 + {
1.1801 +
1.1802 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4053"));
1.1803 +
1.1804 + __UHEAP_MARK;
1.1805 + test.Next(_L("LManaged - test composite object release"));
1.1806 +
1.1807 + {
1.1808 + LCleanedupPtr<CComposite> comp1(CComposite::NewL());
1.1809 + comp1->ReleaseLoggers();
1.1810 +
1.1811 + LCleanedupPtr<CComposite> comp2(CComposite::NewL());
1.1812 + comp2->ReleaseArrays();
1.1813 + }
1.1814 +
1.1815 + //Check that the custom cleanup strategy for the iAutoPtr member of
1.1816 + //CComposite has been invoked
1.1817 + test(trackerDestroyed);
1.1818 +
1.1819 + __UHEAP_MARKEND;
1.1820 + }
1.1821 +
1.1822 +
1.1823 +void TestCompositeL()
1.1824 + {
1.1825 + __UHEAP_MARK;
1.1826 +
1.1827 + TestLManagedNormalL();
1.1828 + TestLManagedConstructorLeave();
1.1829 + TestLManagedMemberConstructorLeave();
1.1830 + TestLManagedReleaseL();
1.1831 +
1.1832 + __UHEAP_MARKEND;
1.1833 + }
1.1834 +
1.1835 +/**
1.1836 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4054
1.1837 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupRef object
1.1838 +@SYMTestPriority High
1.1839 +@SYMTestActions Creates a LCleanedupRef<RLogger> on the stack and uses the object.
1.1840 + Verifies that the object is automatically cleaned up when it goes out of scope
1.1841 +@SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
1.1842 + is automatically freed when it goes out of scope.
1.1843 +@SYMREQ 10373-7
1.1844 +*/
1.1845 +void TestLCleanedupRefNormalL()
1.1846 + {
1.1847 +
1.1848 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4054"));
1.1849 +
1.1850 + __UHEAP_MARK;
1.1851 + test.Next(_L("LCleanedupRef - test normal exit from a block scope"));
1.1852 +
1.1853 + {
1.1854 + RLogger logger;
1.1855 + logger.OpenL(42);
1.1856 + LCleanedupRef<RLogger> wlogger(logger);
1.1857 + wlogger->MemFunc();
1.1858 + }
1.1859 +
1.1860 + __UHEAP_MARKEND;
1.1861 + }
1.1862 +
1.1863 +
1.1864 +/**
1.1865 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4055
1.1866 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupRef object on a leave
1.1867 +@SYMTestPriority High
1.1868 +@SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and uses the object.
1.1869 + Verifies that the object is automatically cleaned up when a leave occurs
1.1870 +@SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
1.1871 + is automatically freed when a leave occurs
1.1872 +@SYMREQ 10373-7
1.1873 +*/
1.1874 +void TestLCleanedupRefLeave()
1.1875 + {
1.1876 +
1.1877 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4055"));
1.1878 +
1.1879 + __UHEAP_MARK;
1.1880 + test.Next(_L("LCleanedupRef - test leave"));
1.1881 +
1.1882 + TRAPD(status,
1.1883 + {
1.1884 + RLogger logger;
1.1885 + logger.OpenL(42);
1.1886 + LCleanedupRef<RLogger> wlogger(logger);
1.1887 + wlogger->MemFunc();
1.1888 +
1.1889 + test.Printf(_L("TestLCleanedupRefLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.1890 + User::Leave(KErrGeneral);
1.1891 + });
1.1892 + if (status != KErrNone)
1.1893 + {
1.1894 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1895 + }
1.1896 +
1.1897 + __UHEAP_MARKEND;
1.1898 + }
1.1899 +
1.1900 +/**
1.1901 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4056
1.1902 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupRef object.
1.1903 +@SYMTestPriority High
1.1904 +@SYMTestActions Creates an LCleanedupRef<RLogger> object on the stack and
1.1905 + manually Unmanages and closes the RLogger.
1.1906 + Verifies that all memory allocated for the object can be freed
1.1907 + manually.
1.1908 +@SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
1.1909 + is freed by calling Unmanage() and Close()
1.1910 +@SYMREQ 10373-7, 10375-5
1.1911 +*/
1.1912 +void TestLCleanedupRefUnmanageL()
1.1913 + {
1.1914 +
1.1915 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4056"));
1.1916 +
1.1917 + __UHEAP_MARK;
1.1918 +
1.1919 + test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage"));
1.1920 +
1.1921 + RLogger logger;
1.1922 +
1.1923 + LCleanedupRef<RLogger> rlog(logger);
1.1924 + rlog->OpenL(42);
1.1925 + rlog->MemFunc();
1.1926 + rlog.Unmanage();
1.1927 + logger.Close();
1.1928 +
1.1929 + __UHEAP_MARKEND;
1.1930 + }
1.1931 +
1.1932 +/**
1.1933 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4057
1.1934 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupRef object on a leave
1.1935 +@SYMTestPriority High
1.1936 +@SYMTestActions Creates LCleanedupRef<RLogger> objects on the stack and
1.1937 + manually Unmanages them.
1.1938 + Forces a leave and then Closes the RLogger objects.
1.1939 + Verifies that all memory allocated for the objects can be freed
1.1940 + manually in the event of a leave occuring
1.1941 +@SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
1.1942 + is freed by calling Unmanage() and Close()
1.1943 +@SYMREQ 10373-7, 10375-5
1.1944 +*/
1.1945 +void TestLCleanedupRefUnmanageLeave()
1.1946 + {
1.1947 +
1.1948 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4057"));
1.1949 +
1.1950 + __UHEAP_MARK;
1.1951 +
1.1952 + test.Next(_L("LCleanedupRef - test LCleanedupRef::Unmanage"));
1.1953 +
1.1954 + RLogger logger1(1);
1.1955 + RLogger logger2(2);
1.1956 +
1.1957 + TRAPD(status,
1.1958 + {
1.1959 + LCleanedupRef<RLogger> rlog1(logger1);
1.1960 + LCleanedupRef<RLogger> rlog2(logger2);
1.1961 + rlog1->MemFunc();
1.1962 + rlog2->MemFunc();
1.1963 + rlog1.Unmanage();
1.1964 + rlog2.Unmanage();
1.1965 +
1.1966 + test.Printf(_L("TestLCleanedupRefUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.1967 + User::Leave(KErrGeneral);
1.1968 + });
1.1969 +
1.1970 + if (status != KErrNone)
1.1971 + {
1.1972 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.1973 + logger1.Close();
1.1974 + logger2.Close();
1.1975 + }
1.1976 +
1.1977 + __UHEAP_MARKEND;
1.1978 + }
1.1979 +
1.1980 +/**
1.1981 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4058
1.1982 +@SYMTestCaseDesc Tests access to managed object through LCleanedupRef
1.1983 +@SYMTestPriority High
1.1984 +@SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and
1.1985 + uses the LCleanedupRef object to access RLogger methods
1.1986 + via the -> operator and the LCleanedupRef methods via
1.1987 + the . operator
1.1988 +@SYMTestExpectedResults All public RLogger methods and LCleanedupRef
1.1989 + should be accessible through the LCleanedupRef object.
1.1990 +@SYMREQ 10373-7
1.1991 +*/
1.1992 +void TestLCleanedupRefObjectAccessL()
1.1993 + {
1.1994 +
1.1995 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4058"));
1.1996 +
1.1997 + __UHEAP_MARK;
1.1998 + test.Next(_L("LCleanedupRef - test managed object access"));
1.1999 +
1.2000 + {
1.2001 + RLogger logger;
1.2002 + logger.OpenL(42);
1.2003 + LCleanedupRef<RLogger> rlog(logger);
1.2004 + rlog->MemFunc();
1.2005 + RLogger::StaticMemberRef(*rlog);
1.2006 + RLogger::StaticMemberPtr(&rlog.Get());
1.2007 + }
1.2008 +
1.2009 + __UHEAP_MARKEND;
1.2010 + }
1.2011 +
1.2012 +/**
1.2013 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4059
1.2014 +@SYMTestCaseDesc Tests forced cleanup of LCleanedupRef object.
1.2015 +@SYMTestPriority High
1.2016 +@SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and
1.2017 + forces cleanup by calling ReleaseResource().
1.2018 + Verifies that all memory allocated for the object is freed
1.2019 + by calling ReleaseResource()
1.2020 +@SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
1.2021 + is freed by calling ReleaseResource().
1.2022 +@SYMREQ 10373-7, 10375-4
1.2023 +*/
1.2024 +void TestLCleanedupRefReleaseL()
1.2025 + {
1.2026 +
1.2027 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4059"));
1.2028 +
1.2029 + __UHEAP_MARK;
1.2030 + test.Next(_L("LCleanedupRef - test LCleanedupRef::ReleaseResource"));
1.2031 +
1.2032 + {
1.2033 + RLogger logger;
1.2034 + logger.OpenL(42);
1.2035 +
1.2036 + LCleanedupRef<RLogger> wlogger(logger);
1.2037 + wlogger->MemFunc();
1.2038 + wlogger.ReleaseResource();
1.2039 +
1.2040 + RLogger logger2(2);
1.2041 + LCleanedupRef<RLogger> wlogger2(logger2);
1.2042 + wlogger2->MemFunc();
1.2043 + RLogger& logref2 = wlogger2.Unmanage();
1.2044 + wlogger2.ReleaseResource();
1.2045 + logref2.Release();
1.2046 + }
1.2047 +
1.2048 + __UHEAP_MARKEND;
1.2049 + }
1.2050 +
1.2051 +
1.2052 +/**
1.2053 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4060
1.2054 +@SYMTestCaseDesc Tests assignment of LCleanedupRef<XXX> objects
1.2055 +@SYMTestPriority High
1.2056 +@SYMTestActions Creates 2 LCleanedupRef<CTracker> objects on the stack.
1.2057 + Unamanages one of the objects and assigns the managed
1.2058 + reference to the second LCleanedupPtr
1.2059 + Verifies that all memory allocated for the objects is freed
1.2060 + automatically when the objects go out of scope.
1.2061 +@SYMTestExpectedResults All memory allocated for the objects is freed
1.2062 + automatically when the objects go out of scope.
1.2063 +@SYMREQ 10373-7
1.2064 +*/
1.2065 +void TestLCleanedupRefAssignL()
1.2066 + {
1.2067 +
1.2068 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4060"));
1.2069 +
1.2070 + __UHEAP_MARK;
1.2071 + test.Next(_L("LCleanedupRef - test LCleanedupRef::operator="));
1.2072 +
1.2073 + {
1.2074 + RLogger logger1;
1.2075 + logger1.OpenL(1);
1.2076 + LCleanedupRef<RLogger> wlogger1(logger1);
1.2077 +
1.2078 + RLogger logger2;
1.2079 + logger2.OpenL(2);
1.2080 + LCleanedupRef<RLogger> wlogger2(logger2);
1.2081 +
1.2082 + //The assignment results in logger2 being cleaned up before
1.2083 + //logger1 is assigned
1.2084 + wlogger2 = wlogger1.Unmanage();
1.2085 + }
1.2086 +
1.2087 + __UHEAP_MARKEND;
1.2088 + }
1.2089 +
1.2090 +
1.2091 +
1.2092 +void TestLCleanedupRefL()
1.2093 + {
1.2094 + __UHEAP_MARK;
1.2095 +
1.2096 + TestLCleanedupRefNormalL();
1.2097 + TestLCleanedupRefLeave();
1.2098 + TestLCleanedupRefUnmanageL();
1.2099 + TestLCleanedupRefUnmanageLeave();
1.2100 + TestLCleanedupRefObjectAccessL();
1.2101 + TestLCleanedupRefReleaseL();
1.2102 + TestLCleanedupRefAssignL();
1.2103 +
1.2104 + __UHEAP_MARKEND;
1.2105 + }
1.2106 +
1.2107 +/**
1.2108 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4061
1.2109 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupGuard object
1.2110 +@SYMTestPriority High
1.2111 +@SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
1.2112 + via the RLogger::Cleanup function.
1.2113 + Verifies that the object is automatically cleaned up when it goes
1.2114 + out of scope
1.2115 +@SYMTestExpectedResults All memory allocated for the RLogger
1.2116 + is automatically freed when it goes out of scope.
1.2117 +@SYMREQ 10373-10
1.2118 +*/
1.2119 +void TestLCleanedupGuardNormal()
1.2120 + {
1.2121 +
1.2122 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4061"));
1.2123 +
1.2124 + __UHEAP_MARK;
1.2125 + test.Printf(_L("LCleanedupGuard - test normal exit from a block scope\n"));
1.2126 +
1.2127 + {
1.2128 + RLogger logger(42);
1.2129 + LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
1.2130 + }
1.2131 +
1.2132 + __UHEAP_MARKEND;
1.2133 + }
1.2134 +
1.2135 +/**
1.2136 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4062
1.2137 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupGuard object on a leave
1.2138 +@SYMTestPriority High
1.2139 +@SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
1.2140 + via the RLogger::Cleanup function.
1.2141 + Verifies that the object is automatically cleaned up when a leave occurs
1.2142 +@SYMTestExpectedResults All memory allocated for the RLogger
1.2143 + is automatically freed when a leave occurs
1.2144 +@SYMREQ 10373-10
1.2145 +*/
1.2146 +void TestLCleanedupGuardLeave()
1.2147 + {
1.2148 +
1.2149 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4062"));
1.2150 +
1.2151 + __UHEAP_MARK;
1.2152 + test.Printf(_L("LCleanedupGuard - test leave"));
1.2153 +
1.2154 + TRAPD(status,
1.2155 + {
1.2156 + RLogger logger(42);
1.2157 + LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
1.2158 +
1.2159 + test.Printf(_L("TestLCleanedupGuardLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.2160 + User::Leave(KErrGeneral);
1.2161 + });
1.2162 +
1.2163 + if (status != KErrNone)
1.2164 + {
1.2165 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.2166 + }
1.2167 +
1.2168 + __UHEAP_MARKEND;
1.2169 + }
1.2170 +
1.2171 +/**
1.2172 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4063
1.2173 +@SYMTestCaseDesc Tests dissmissing of LCleanedupGuard
1.2174 +@SYMTestPriority High
1.2175 +@SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
1.2176 + via the RLogger::Cleanup function.
1.2177 + Calls LCleanedupGuard::Dismiss to disable the guard and manually calls
1.2178 + cleanup function.
1.2179 + Verifies that the memory allocated for the RLogger object is cleaned up
1.2180 +@SYMTestExpectedResults All memory allocated for the RLogger is freed by calling
1.2181 + Dismiss and manually calling RLogger::Cleanup()
1.2182 +@SYMREQ 10373-10
1.2183 +*/
1.2184 +void TestLCleanedupGuardDismiss()
1.2185 + {
1.2186 +
1.2187 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4063"));
1.2188 +
1.2189 + __UHEAP_MARK;
1.2190 + test.Printf(_L("LCleanedupGuard - test LCleanedupGuard::Dismiss\n"));
1.2191 +
1.2192 +
1.2193 + RLogger logger(42);
1.2194 + LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
1.2195 + cleanGuard.Dismiss();
1.2196 + RLogger::Cleanup(&logger);
1.2197 +
1.2198 + __UHEAP_MARKEND;
1.2199 + }
1.2200 +
1.2201 +/**
1.2202 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4064
1.2203 +@SYMTestCaseDesc Tests dismissing of LCleanedupGuard on a leave
1.2204 +@SYMTestPriority High
1.2205 +@SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
1.2206 + via the RLogger::Cleanup function.
1.2207 + Calls LCleanedupGuard::Dismiss to disable the guard and forces a leave.
1.2208 + Manually calls the RLogger cleanup function.
1.2209 + Verifies that the memory allocated for the RLogger object is cleaned up
1.2210 +@SYMTestExpectedResults All memory allocated for the RLogger is freed on a leave by
1.2211 + calling Dismiss and manually cleaning up the object.
1.2212 +@SYMREQ 10373-10
1.2213 +*/
1.2214 +void TestLCleanedupGuardDismissLeave()
1.2215 + {
1.2216 +
1.2217 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4064"));
1.2218 +
1.2219 + __UHEAP_MARK;
1.2220 + test.Printf(_L("LCleanedupGuard - test LCleanedupGuard::Dismiss\n"));
1.2221 +
1.2222 + RLogger logger(42);
1.2223 + TRAPD(status,
1.2224 + {
1.2225 + LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
1.2226 + cleanGuard.Dismiss();
1.2227 +
1.2228 + test.Printf(_L("TestLCleanedupGuardDismissLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.2229 + User::Leave(KErrGeneral);
1.2230 + });
1.2231 +
1.2232 + if (status != KErrNone)
1.2233 + {
1.2234 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.2235 + RLogger::Cleanup(&logger);
1.2236 + }
1.2237 +
1.2238 + __UHEAP_MARKEND;
1.2239 + }
1.2240 +
1.2241 +
1.2242 +void TestLCleanedupGuard()
1.2243 + {
1.2244 + __UHEAP_MARK;
1.2245 +
1.2246 + TestLCleanedupGuardNormal();
1.2247 + TestLCleanedupGuardLeave();
1.2248 + TestLCleanedupGuardDismiss();
1.2249 + TestLCleanedupGuardDismissLeave();
1.2250 +
1.2251 + __UHEAP_MARKEND;
1.2252 + }
1.2253 +
1.2254 +
1.2255 +/**
1.2256 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4065
1.2257 +@SYMTestCaseDesc Tests manual cleanup of LCleanedupArray object on a leave
1.2258 +@SYMTestPriority High
1.2259 +@SYMTestActions Creates an LCleanedupArray<TLogger> on the stack and calls Unmanage().
1.2260 + Forces a leave and then manually cleans up the array.
1.2261 + Verifies that the objects are automatically cleaned up when they go
1.2262 + out of scope
1.2263 +@SYMTestExpectedResults All memory allocated for the LCleanedupArray objects
1.2264 + is automatically freed when they go out of scope.
1.2265 +@SYMREQ 10373-9, 10375-5
1.2266 +*/
1.2267 +void TestLCleanedupArrayUnmanageLeave()
1.2268 + {
1.2269 +
1.2270 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4065"));
1.2271 +
1.2272 + __UHEAP_MARK;
1.2273 +
1.2274 + const TInt KNumLoggers = 3;
1.2275 + TLogger* ploggers = NULL;
1.2276 + TRAPD(status,
1.2277 + {
1.2278 + LCleanedupArray<TLogger> loggers(new(ELeave) TLogger[KNumLoggers]);
1.2279 +
1.2280 + ploggers = loggers.Unmanage();
1.2281 +
1.2282 + test.Printf(_L("TestLCleanedupArrayUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
1.2283 +
1.2284 + User::Leave(KErrGeneral);
1.2285 + });
1.2286 + if (status != KErrNone)
1.2287 + {
1.2288 + test.Printf(_L("Leave trapped; leave code: %d\n"), status);
1.2289 + delete[] ploggers;
1.2290 + }
1.2291 +
1.2292 + __UHEAP_MARKEND;
1.2293 + }
1.2294 +
1.2295 +/**
1.2296 +@SYMTestCaseID SYSLIB-EUSERHL-UT-4066
1.2297 +@SYMTestCaseDesc Tests automatic cleanup of LCleanedupArray object
1.2298 +@SYMTestPriority High
1.2299 +@SYMTestActions Creates an LCleanedupArray<TLogger>and uses the object.
1.2300 + Creates an LCleanedupArray<TLogger, TLogCleanupStrategy> with a custom
1.2301 + cleanup strategy and uses the object.
1.2302 + Creates an LCleanedupArray<TLogger> and forces cleanup
1.2303 + Creates an LCleanedupArray<TLogger> and calls UNmanage()
1.2304 + Verifies that the objects are automatically cleaned up when they go
1.2305 + out of scope
1.2306 +@SYMTestExpectedResults All memory allocated for the LCleanedupArray objects
1.2307 + is automatically freed when they go out of scope.
1.2308 +@SYMREQ 10373-9, 10375-4, 10375-5
1.2309 +*/
1.2310 +void TestLCleanedupArrayL()
1.2311 + {
1.2312 +
1.2313 + test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4066"));
1.2314 +
1.2315 + __UHEAP_MARK;
1.2316 + test.Next(_L("LCleanedupArray - test normal exit from a block scope"));
1.2317 +
1.2318 + {
1.2319 + const TInt KNumLoggers = 3;
1.2320 + LCleanedupArray<TLogger> array(new(ELeave) TLogger[KNumLoggers]);
1.2321 + array[0].Test();
1.2322 +
1.2323 + TLogger rawarr[2];
1.2324 + LCleanedupArray<TLogger, TLogCleanupStrategy> marr(rawarr);
1.2325 + marr[0].Test();
1.2326 +
1.2327 + LCleanedupArray<TLogger> array2(new(ELeave) TLogger[KNumLoggers]);
1.2328 + array2.ReleaseResource();
1.2329 +
1.2330 + LCleanedupArray<TLogger> array3(new(ELeave) TLogger[KNumLoggers]);
1.2331 + array2 = array3.Unmanage();
1.2332 +
1.2333 + LCleanedupArray<TLogger> nullarr;
1.2334 +
1.2335 + TestLCleanedupArrayUnmanageLeave();
1.2336 + }
1.2337 +
1.2338 + __UHEAP_MARKEND;
1.2339 + }
1.2340 +
1.2341 +
1.2342 +void TestOrLeave()
1.2343 + {
1.2344 + __UHEAP_MARK;
1.2345 +
1.2346 + {
1.2347 + TRAPD(err,KErrGeneral OR_LEAVE);
1.2348 + test(err == KErrGeneral);
1.2349 +
1.2350 + TRAP(err,(5-7) OR_LEAVE);
1.2351 + test(err == -2);
1.2352 +
1.2353 + RLogger logger;
1.2354 + logger.OpenL(KErrNoMemory);
1.2355 +
1.2356 + LCleanedupRef<RLogger> cLogger(logger);
1.2357 + TRAP(err,{
1.2358 + *(cLogger->GetData()) OR_LEAVE;
1.2359 + });
1.2360 + test(err == KErrNoMemory);
1.2361 +
1.2362 + LCleanedupHandle<RFs> cFs;
1.2363 + LCleanedupHandle<RFile> cFile;
1.2364 +
1.2365 + TRAP(err, cFs->Connect() OR_LEAVE);
1.2366 + test(err == KErrNone);
1.2367 +
1.2368 + _LIT(KTestFile,"c:\\test_emanaged");
1.2369 + err = cFile->Open(*cFs, KTestFile,EFileRead);
1.2370 + if (err != KErrNone)
1.2371 + {
1.2372 + test.Printf(_L("Error opening file: %d\n"), err);
1.2373 + if (err == KErrNotFound)
1.2374 + {
1.2375 + test.Printf(_L("Creating new file c:\\test_emanaged ... "));
1.2376 + err = cFile->Create(*cFs,
1.2377 + KTestFile,
1.2378 + EFileWrite | EFileShareAny);
1.2379 + test.Printf(_L("File created\n"));
1.2380 + }
1.2381 + }
1.2382 +
1.2383 + test(err == KErrNone);
1.2384 +
1.2385 + LCleanedupHandle<RDir> dir;
1.2386 + err = dir->Open(*cFs, _L("c:\\resource"), KEntryAttMaskSupported);
1.2387 +
1.2388 + LCleanedupHandle<RFs> aFs(cFs.Unmanage());
1.2389 + LCleanedupHandle<RFile> aFile(cFile.Unmanage());
1.2390 + LCleanedupHandle<RDir> adir(dir.Unmanage());
1.2391 +
1.2392 + test(err == KErrNone);
1.2393 + }
1.2394 +
1.2395 + __UHEAP_MARKEND;
1.2396 + }
1.2397 +
1.2398 +
1.2399 +void TestL()
1.2400 + {
1.2401 + __UHEAP_MARK;
1.2402 +
1.2403 + TestLeaveFromConstructor();
1.2404 +
1.2405 + TestLCleanedupHandleL();
1.2406 + TestLCleanedupPtrL();
1.2407 + TestLCleanedupArrayL();
1.2408 + TestLCleanedupRefL();
1.2409 + TestLCleanedupGuard();
1.2410 + TestCompositeL();
1.2411 + TestOrLeave();
1.2412 + TExtendedTestL();
1.2413 + __UHEAP_MARKEND;
1.2414 + }
1.2415 +
1.2416 +
1.2417 +TInt E32Main()
1.2418 + {
1.2419 + CTrapCleanup* stack = CTrapCleanup::New();
1.2420 + if (stack == NULL)
1.2421 + return KErrNoMemory;
1.2422 +
1.2423 + test.Title();
1.2424 + test.Start(_L("RAII-based automatic resource management tests"));
1.2425 +
1.2426 + TRAPD(status, TestL());
1.2427 + if (status != KErrNone)
1.2428 + {
1.2429 + test.Printf(_L("Test leave trapped; leave code: %d\n"), status);
1.2430 + }
1.2431 + else
1.2432 + {
1.2433 + test.End();
1.2434 + }
1.2435 +
1.2436 + delete stack;
1.2437 + return status;
1.2438 + }
1.2439 +
1.2440 +