os/ossrv/lowlevellibsandfws/genericusabilitylib/test/src/t_emanaged.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Overview:
    15 // Test methods of the LManagedX and LCleanedupX classes.
    16 // Tests CONSTRUCTORS_MAY_LEAVE and OR_LEAVE macros
    17 // 
    18 //
    19 
    20 #include <e32base.h>
    21 #include <e32test.h>
    22 #include <e32def.h>
    23 #include <e32cmn.h>
    24 #include <f32file.h>
    25 #include "emisc.h"
    26 #include "euserhl.h"
    27 
    28 
    29 RTest test(_L("RAII-based automatic resource management tests"));
    30 
    31 
    32 TInt TExtendedTestL();
    33 
    34 class CTracker : public CBase
    35 	{
    36   public:
    37 	CONSTRUCTORS_MAY_LEAVE
    38 
    39 	enum TConstructionMode { ENonleavingConstructor, EConstructorLeaves};
    40 
    41 	static CTracker* NewL()
    42 		{
    43 		return new(ELeave) CTracker;
    44 		}
    45 
    46 	static CTracker* NewL(TConstructionMode aMode)
    47 		{
    48 		return new(ELeave) CTracker(aMode);
    49 		}
    50 
    51 	CTracker()
    52 		: iData(new(ELeave) TInt)
    53 		{
    54 		test.Printf(_L("  CTracker - %x\n"), this);
    55 		*iData = 3;
    56 		}
    57 
    58 	explicit CTracker(TConstructionMode aMode)
    59 		: iData(new(ELeave) TInt(aMode))
    60 		{
    61 		if (aMode == EConstructorLeaves)
    62 			{
    63 			test.Printf(_L("CTracker(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
    64 			User::Leave(KErrGeneral);
    65 			}
    66 
    67 		test.Printf(_L("  CTracker - %x\n"), this);
    68 		}
    69 
    70 	CTracker(CTracker& aTracker)
    71 		: iData(aTracker.iData.Unmanage())
    72 		{
    73 		test.Printf(_L("  CTracker::CTracker(const CTracker&) - %x (copy)\n"), this);
    74 		}
    75 
    76 	CTracker& operator=(CTracker& aTracker)
    77 		{
    78 		iData = aTracker.iData.Unmanage();
    79 		test.Printf(_L("  CTracker::operator=(const CTracker&) - %x (copy)\n"), this);
    80 		return *this;
    81 		}
    82 
    83 	virtual ~CTracker()
    84 		{
    85 		test.Printf(_L("  ~CTracker - %x\n"), this);
    86 		}
    87 
    88 	virtual void MemFunc()
    89 		{
    90 		test.Printf(_L("  CTracker::MemFunc - %x\n"), this);
    91 		}
    92 
    93 	virtual TInt Value()
    94 		{
    95 		return *iData;
    96 		}
    97 
    98 	static void StaticMemberRef(const CTracker& aTracker)
    99 		{
   100 		test.Printf(_L("  CTracker::StaticMemberRef - %x\n"), &aTracker);
   101 		}
   102 
   103 	static void StaticMemberPtr(CTracker* aTracker)
   104 		{
   105 		test.Printf(_L("  CTracker::StaticMemberPtr - %x\n"), aTracker);
   106 		}
   107 
   108   private:
   109 	LManagedPtr<TInt> iData;
   110 	};
   111 
   112 TBool trackerDestroyed = EFalse;
   113 
   114 class TCTrackerDestroy
   115 	{
   116 public:
   117 	static void Cleanup(CTracker* aPtr)
   118 		{
   119 		test.Printf(_L("TCTrackerDestroy::Cleanup\n"));
   120 		delete aPtr;
   121 		trackerDestroyed = ETrue;
   122 		}
   123 	};
   124 
   125 class CDerivedTracker: public CTracker
   126 	{
   127   public:
   128 	CONSTRUCTORS_MAY_LEAVE
   129 
   130 	static CDerivedTracker* NewL()
   131 		{
   132 		return new(ELeave) CDerivedTracker;
   133 		}
   134 
   135 	static CDerivedTracker* NewL(CTracker::TConstructionMode aMode)
   136 		{
   137 		return new(ELeave) CDerivedTracker(aMode);
   138 		}
   139 
   140 	CDerivedTracker()
   141 		: iRealData(new(ELeave) TReal64)
   142 		{
   143 		test.Printf(_L("  CDerivedTracker - %x\n"), this);
   144 		*iRealData = 5.5;
   145 		}
   146 
   147 	CDerivedTracker(CTracker::TConstructionMode aMode)
   148 		{
   149 		if (aMode == EConstructorLeaves)
   150 			{
   151 			test.Printf(_L("CDerivedTracker(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
   152 			User::Leave(KErrGeneral);
   153 			}
   154 
   155 		test.Printf(_L("  CDerivedTracker - %x\n"), this);
   156 		}
   157 
   158 	CDerivedTracker(CDerivedTracker& aDerivedTracker)
   159 		: CTracker(aDerivedTracker),
   160 		  iRealData(aDerivedTracker.iRealData.Unmanage())
   161 		{
   162 		test.Printf(_L("  CDerivedTracker::CDerivedTracker(const CDerivedTracker&) - %x (copy)\n"), this);
   163 		}
   164 
   165 	CDerivedTracker& operator=(CDerivedTracker& aDerivedTracker)
   166 		{
   167 		CTracker::operator=(aDerivedTracker);
   168 		iRealData = aDerivedTracker.iRealData.Unmanage();
   169 		test.Printf(_L("  CDerivedTracker::operator=(const CDerivedTracker&) - %x (copy)\n"), this);
   170 		return *this;
   171 		}
   172 
   173 	virtual ~CDerivedTracker()
   174 		{
   175 		test.Printf(_L("  ~CDerivedTracker - %x\n"), this);
   176 		}
   177 
   178 	virtual void MemFunc()
   179 		{
   180 		test.Printf(_L("  CDerivedTracker::MemFunc - %x\n"), this);
   181 		}
   182 
   183 	static void StaticMemberRef(const CDerivedTracker& aTracker)
   184 		{
   185 		test.Printf(_L("  CDerivedTracker::StaticMemberRef - %x\n"), &aTracker);
   186 		}
   187 
   188 	static void StaticMemberPtr(CDerivedTracker* aTracker)
   189 		{
   190 		test.Printf(_L("  CDerivedTracker::StaticMemberPtr - %x\n"), aTracker);
   191 		}
   192 
   193   private:
   194 	LManagedPtr<TReal64> iRealData;
   195 	};
   196 
   197 
   198 namespace Log
   199 {
   200 
   201 class RLogger
   202 	{
   203   public:
   204 	RLogger()
   205 		: iData(NULL)
   206 		{
   207 		test.Printf(_L("  RLogger - %x\n"), this);
   208 		}
   209 
   210 	RLogger(TInt* aData)
   211 		: iData(aData)
   212 		{
   213 		test.Printf(_L("  RLogger - %x ptr %x -> val %d\n"), this, aData, *iData);
   214 		}
   215 
   216 	RLogger(TInt aValue)
   217 		: iData(new(ELeave) TInt(aValue))
   218 		{
   219 		test.Printf(_L("  RLogger - %x value %d\n"), this, *iData);
   220 		}
   221 
   222 	void OpenL(TInt aValue)
   223 		{
   224 		iData = new(ELeave) TInt(aValue);
   225 		test.Printf(_L("  RLogger::OpenL(TInt aValue) - %x value %d\n"), this, *iData);
   226 		}
   227 
   228 	RLogger(const RLogger& aLogger)
   229 		: iData(aLogger.iData)
   230 		{
   231 		test.Printf(_L("  RLogger::RLogger(const RLogger&) - %x (copy)\n"), this);
   232 		}
   233 
   234 
   235 	RLogger& operator=(const RLogger& aLogger)
   236 		{
   237 		iData = aLogger.iData;
   238 
   239 		test.Printf(_L("  RLogger::operator=(const RLogger&) - %x copy from %x val %d\n"), this, &aLogger, *aLogger.iData);
   240 		return *this;
   241 		}
   242 
   243 
   244 	~RLogger()
   245 		{
   246 		test.Printf(_L("  ~RLogger - %x\n"), this);
   247 		}
   248 
   249 
   250 	void Close()
   251 		{
   252 		test.Printf(_L("  RLogger::Close - %x\n"), this);
   253 
   254 		// Open or non-NULL initializing constructor not called or
   255 		// cleanup function already called
   256 
   257 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   258 		delete iData;
   259 		iData = NULL;
   260 		}
   261 
   262 
   263 	void Release()
   264 		{
   265 		test.Printf(_L("  RLogger::Release - %x\n"), this);
   266 
   267 		// Open or non-NULL initializing constructor not called or
   268 		// cleanup function already called
   269 
   270 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   271 		delete iData;
   272 		iData = NULL;
   273 		}
   274 
   275 
   276 	void Destroy()
   277 		{
   278 		test.Printf(_L("  RLogger::Destroy - %x\n"), this);
   279 
   280 		// Open or non-NULL initializing constructor not called or
   281 		// cleanup function already called
   282 
   283 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   284 		delete iData;
   285 		iData = NULL;
   286 		}
   287 
   288 
   289 	void Free()
   290 		{
   291 		test.Printf(_L("  RLogger::Free - %x\n"), this);
   292 
   293 		// Open or non-NULL initializing constructor not called or
   294 		// cleanup function already called
   295 
   296 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   297 		delete iData;
   298 		iData = NULL;
   299 		}
   300 
   301 	void MemFunc()
   302 		{
   303 		test.Printf(_L("  RLogger::MemFunc - %x %x\n"), this, iData);
   304 		}
   305 
   306 	static void StaticMemberRef(const RLogger& aTracker)
   307 		{
   308 		test.Printf(_L("  RLogger::StaticMemberRef - %x\n"), &aTracker);
   309 		}
   310 
   311 	static void StaticMemberPtr(RLogger* aTracker)
   312 		{
   313 		test.Printf(_L("  RLogger::StaticMemberPtr - %x\n"), aTracker);
   314 		}
   315 
   316 	static void Cleanup(TAny* aRlogger)
   317 		{
   318 		static_cast<RLogger*>(aRlogger)->Close();
   319 		}
   320 
   321 	TInt* GetData() const
   322 		{
   323 		return iData;
   324 		}
   325 
   326   protected:
   327 	TInt* iData;
   328 	};
   329 
   330 
   331 DEFINE_CLEANUP_FUNCTION(RLogger, Release);
   332 
   333 
   334 class ROtherLogger
   335 	{
   336   public:
   337 	ROtherLogger()
   338 		: iData(NULL)
   339 		{
   340 		test.Printf(_L("  ROtherLogger - %x\n"), this);
   341 		}
   342 
   343 	ROtherLogger(TInt* aData)
   344 		: iData(aData)
   345 		{
   346 		test.Printf(_L("  ROtherLogger - %x ptr %x -> val %d\n"), this, aData, *iData);
   347 		}
   348 
   349 	ROtherLogger(TInt aValue)
   350 		: iData(new(ELeave) TInt(aValue))
   351 		{
   352 		test.Printf(_L("  ROtherLogger - %x value %d\n"), this, *iData);
   353 		}
   354 
   355 	void OpenL(TInt aValue)
   356 		{
   357 		iData = new(ELeave) TInt(aValue);
   358 		test.Printf(_L("  ROtherLogger::OpenL(TInt aValue) - %x value %d\n"), this, *iData);
   359 		}
   360 
   361 	ROtherLogger(const ROtherLogger& aLogger)
   362 		: iData(aLogger.iData)
   363 		{
   364 		test.Printf(_L("  ROtherLogger::ROtherLogger(const ROtherLogger&) - %x (copy)\n"), this);
   365 		}
   366 
   367 
   368 	ROtherLogger& operator=(const ROtherLogger& aLogger)
   369 		{
   370 		iData = aLogger.iData;
   371 
   372 		test.Printf(_L("  ROtherLogger::operator=(const ROtherLogger&) - %x copy from %x ptr %x\n"), this, &aLogger, aLogger.iData);
   373 		return *this;
   374 		}
   375 
   376 
   377 	~ROtherLogger()
   378 		{
   379 		test.Printf(_L("  ~ROtherLogger - %x\n"), this);
   380 		}
   381 
   382 
   383 	void Close()
   384 		{
   385 		test.Printf(_L("  ROtherLogger::Close - %x\n"), this);
   386 
   387 		// Open or non-NULL initializing constructor not called or
   388 		// cleanup function already called
   389 
   390 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   391 		delete iData;
   392 		iData = NULL;
   393 		}
   394 
   395 
   396 	void Release()
   397 		{
   398 		test.Printf(_L("  ROtherLogger::Release - %x\n"), this);
   399 
   400 		// Open or non-NULL initializing constructor not called or
   401 		// cleanup function already called
   402 
   403 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   404 		delete iData;
   405 		iData = NULL;
   406 		}
   407 
   408 
   409 	void Destroy()
   410 		{
   411 		test.Printf(_L("  ROtherLogger::Destroy - %x\n"), this);
   412 
   413 		// Open or non-NULL initializing constructor not called or
   414 		// cleanup function already called
   415 
   416 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   417 		delete iData;
   418 		iData = NULL;
   419 		}
   420 
   421 
   422 	void Free()
   423 		{
   424 		test.Printf(_L("  ROtherLogger::Free - %x\n"), this);
   425 
   426 		// Open or non-NULL initializing constructor not called or
   427 		// cleanup function already called
   428 
   429 		__ASSERT_ALWAYS(iData != NULL, test.Panic(_L("NULL pointer")));
   430 		delete iData;
   431 		iData = NULL;
   432 		}
   433 
   434 	void MemFunc()
   435 		{
   436 		test.Printf(_L("  ROtherLogger::MemFunc - %x %x\n"), this, iData);
   437 		}
   438 
   439 	static void StaticMemberRef(const ROtherLogger& aTracker)
   440 		{
   441 		test.Printf(_L("  ROtherLogger::StaticMemberRef - %x\n"), &aTracker);
   442 		}
   443 
   444 	static void StaticMemberPtr(ROtherLogger* aTracker)
   445 		{
   446 		test.Printf(_L("  ROtherLogger::StaticMemberPtr - %x\n"), aTracker);
   447 		}
   448 
   449 	static void Cleanup(TAny* aRlogger)
   450 		{
   451 		static_cast<ROtherLogger*>(aRlogger)->Close();
   452 		}
   453 
   454 	operator RLogger() const
   455 		{
   456 		test.Printf(_L("  ROtherLogger::operator RLogger() - %x\n"), this);
   457 		return RLogger(iData);
   458 		}
   459 
   460 	ROtherLogger& operator=(const RLogger& aLogger)
   461 		{
   462 		iData = aLogger.GetData();
   463 
   464 		test.Printf(_L("  ROtherLogger::operator=(const RLogger&) - %x copy from %x ptr %x\n"), this, &aLogger, aLogger.GetData());
   465 		return *this;
   466 		}
   467 
   468   protected:
   469 	TInt* iData;
   470 	};
   471 
   472 } // namespace Log
   473 
   474 class RPair
   475 	{
   476   public:
   477 	RPair(const TInt& x, const TInt& y)
   478 		: iX(x), iY(y)
   479 		{
   480 		test.Printf(_L("  RPair::RPair(const TInt& x, const TInt& y) %x %d %d\n"), iX, iY);
   481 		}
   482 
   483 	RPair(TInt& x, TInt& y)
   484 		: iX(x), iY(y)
   485 		{
   486 		test.Printf(_L("  RPair::RPair(TInt& x, TInt& y) %x %d %d\n"), iX, iY);
   487 		}
   488 
   489 	void Close()
   490 		{
   491 		test.Printf(_L("  RPair::Close() %x %d %d\n"), iX, iY);
   492 		}
   493 
   494   private:
   495 	TInt iX;
   496 	TInt iY;
   497 	};
   498 
   499 
   500 using Log::RLogger;
   501 using Log::ROtherLogger;
   502 
   503 class TLogger
   504 	{
   505   public:
   506 	TLogger()
   507 		{
   508 		test.Printf(_L("  TLogger - %x\n"), this);
   509 		}
   510 
   511 	TLogger(const TLogger&)
   512 		{
   513 		test.Printf(_L("  TLogger::TLogger(const TLogger& aLogger) - %x (copy)\n"), this);
   514 		}
   515 
   516 
   517 	TLogger& operator=(const TLogger&)
   518 		{
   519 		test.Printf(_L("  TLogger::operator=(const TLogger& aLogger) - %x (copy)\n"), this);
   520 		return *this;
   521 		}
   522 
   523 	~TLogger()
   524 		{
   525 		test.Printf(_L("  ~TLogger - %x\n"), this);
   526 		}
   527 
   528 	void Test()
   529 		{
   530 		test.Printf(_L("  TLogger::Test - %x\n"), this);
   531 		}
   532 	};
   533 
   534 
   535 static TInt one = 1;
   536 static TInt two = 2;
   537 
   538 // CComposite object owns other objects:
   539 
   540 class CComposite: public CBase
   541 	{
   542   public:
   543 	enum TConstructionMode
   544 	{
   545 		ENonleavingConstructor,
   546 		EConstructorLeaves,
   547 		EMemberConstructorLeaves
   548 	};
   549 
   550 	static CComposite* NewL()
   551 		{
   552 		return new(ELeave) CComposite;
   553 		}
   554 
   555 	static CComposite* NewL(TConstructionMode aMode)
   556 		{
   557 		return new(ELeave) CComposite(aMode);
   558 		}
   559 
   560 	CONSTRUCTORS_MAY_LEAVE
   561 
   562 	CComposite();
   563 	CComposite(TConstructionMode aMode);
   564 	~CComposite();
   565 
   566 	void ReleaseLoggers();
   567 	void ReleaseArrays();
   568 
   569   private:
   570 	TInt iVal;
   571 
   572 // By-value component objects
   573 	const LManagedHandle<RLogger> iConstLogger;
   574 	LManagedHandle<RLogger> iLogger;
   575 	LManagedHandle<RLogger> iLogger2;
   576 	LManagedHandle<RLogger> iLogger3;
   577 
   578 	ROtherLogger iOther;
   579 	LManagedRef<ROtherLogger> iOtherRef;
   580 	LManagedHandle<RLogger> iAnotherLogger;
   581 
   582 	LManagedHandle<RLogger, TDestroy> iDestroyer;
   583 
   584 // Component objects contained by pointer
   585 	LManagedPtr<CTracker> iNullPtr;
   586 	//Define a custom cleanup strategy for CTracker
   587 	LManagedPtr<CTracker> iAutoPtr;
   588 	LManagedPtr<CTracker> iAutoPtr2;
   589 	LManagedPtr<CTracker> iAutoPtr3;
   590 	LManagedPtr<CTracker, TCTrackerDestroy> iAutoPtr4;
   591 	LManagedPtr<CDerivedTracker> iAutoPtr5;
   592 
   593 	LManagedArray<CTracker> iEmptyArray;
   594 	LManagedArray<CTracker> iAutoArray;
   595 	LManagedArray<CTracker> iAutoArray2;
   596 	static const TInt KNumTrackers = 3;
   597 
   598 	LManagedHandle<RPointerArray<CTracker>, TResetAndDestroy> iPtrArray;
   599 
   600 	RPointerArray<CTracker> iArray;
   601 	RPointerArray<CTracker> iArray2;
   602 	LManagedRef<RPointerArray<CTracker>, TResetAndDestroy> iArrayWrapper;
   603 
   604 	RLogger iRawLogger;
   605 	LManagedGuard iGuard;
   606 
   607 	LManagedHandle<RPair> iPair1;
   608 	LManagedHandle<RPair> iPair2;
   609 	LManagedHandle<RPair> iPair3;
   610 	LManagedHandle<RPair> iPair4;
   611 	};
   612 	
   613 CComposite::CComposite()
   614 	: iConstLogger(42),
   615 	  iLogger(1),
   616 	  iLogger2(2),
   617 	  iOther(42),
   618 	  iOtherRef(iOther),
   619 	  iAnotherLogger(iOtherRef.Unmanage()),
   620 	  iDestroyer(2),
   621 	  iAutoPtr(CTracker::NewL()),
   622 	  iAutoPtr2(CTracker::NewL()),
   623 	  iAutoPtr3(CTracker::NewL()),
   624 	  iAutoPtr4(CTracker::NewL()),
   625 	  iAutoPtr5(CDerivedTracker::NewL()),
   626 	  iAutoArray(new(ELeave) CTracker[KNumTrackers]),
   627 	  iAutoArray2(new(ELeave) CTracker[KNumTrackers]),
   628 	  iPtrArray(3),
   629 	  iArrayWrapper(iArray),
   630 	  iRawLogger(42),
   631 	  iGuard(RLogger::Cleanup, &iRawLogger),
   632 	  iPair1(1, 2),
   633 	  iPair2(one, 2),
   634 	  iPair3(1, two),
   635 	  iPair4(one, two)
   636 	{
   637 	test.Printf(_L("  CComposite - %x\n"), this);
   638 	
   639 	//Clear the trackerDestroyed flag.  This flag is set
   640 	//in the custom cleanup strategy for CTracker which is
   641 	//defined for iAutoPtr
   642 	trackerDestroyed = EFalse;
   643 
   644 	iLogger = iLogger2.Unmanage();
   645 	iLogger3->OpenL(3);
   646 
   647 	RLogger logger = iLogger3.Unmanage();
   648 	iLogger3.ReleaseResource();
   649 	logger.Release();
   650 
   651 	iAutoPtr = iAutoPtr2.Unmanage();
   652 	iAutoPtr2.ReleaseResource();
   653 	
   654 	iAutoPtr4 = iAutoPtr5.Unmanage();
   655 	
   656 
   657 	if (iAutoPtr3)
   658 		{
   659 		test.Printf(_L("  iAutoPtr3 pointer = %x\n"), iAutoPtr3.Get());
   660 		}
   661 	else
   662 		{
   663 		test.Printf(_L("  iAutoPtr3 pointer is null (%x)\n"), iAutoPtr3.Get());
   664 		}
   665 
   666 	if (!iNullPtr)
   667 		{
   668 		test.Printf(_L("  iNullPtr is null (%x)\n"), iNullPtr.Get());
   669 		}
   670 	else
   671 		{
   672 		test.Printf(_L("  iNullPtr is (%x)\n"), iNullPtr.Get());
   673 		}
   674 
   675 	if (iAutoPtr3 != iNullPtr)
   676 		{
   677 		test.Printf(_L("  iAutoPtr3 pointer is not null = %x\n"), iAutoPtr3.Get());
   678 		}
   679 
   680 	if (iAutoPtr3 == iNullPtr)
   681 		{
   682 		test.Printf(_L("  iAutoPtr3 pointer is null (%x)\n"), iAutoPtr3.Get());
   683 		}
   684 
   685 	if (iNullPtr < iAutoPtr3)
   686 		{
   687 		test.Printf(_L("  iNullPtr < iAutoPtr3 (%x)\n"), iAutoPtr3.Get());
   688 		}
   689 
   690 	iAutoPtr3 = NULL;
   691 
   692 
   693 	iAutoArray = iAutoArray2.Unmanage();
   694 	iAutoArray2.ReleaseResource();
   695 
   696 	iPtrArray->Append(CTracker::NewL());
   697 	iPtrArray->Append(CTracker::NewL());
   698 
   699 	iArrayWrapper->Append(CTracker::NewL());
   700 
   701 	iArrayWrapper = iArray2;
   702 
   703 	iArrayWrapper->Append(CTracker::NewL());
   704 	iArrayWrapper->Append(CTracker::NewL());
   705 
   706 	test.Printf(_L("  iLogger val = %d\n"), iLogger->GetData());
   707 	test.Printf(_L("  iDestroyer val = %d\n"), (*iDestroyer).GetData());
   708 
   709 	test.Printf(_L("  iConstLogger val = %d\n"), iConstLogger->GetData());
   710 	test.Printf(_L("  iConstLogger val = %d\n"), (*iConstLogger).GetData());
   711 
   712 	test.Printf(_L("  iAutoArray[0] val = %d\n"), iAutoArray[0].Value());
   713 
   714 	iOtherRef.ReleaseResource();
   715 	}
   716 
   717 
   718 CComposite::CComposite(TConstructionMode aMode)
   719 	: iConstLogger(42),
   720 	  iLogger(1),
   721 	  iLogger2(2),
   722 	  iLogger3(new int(3)),
   723 	  iOther(42),
   724 	  iOtherRef(iOther),
   725 	  iAnotherLogger(iOtherRef.Unmanage()),
   726 	  iDestroyer(2),
   727 	  iAutoPtr(CTracker::NewL(aMode == EMemberConstructorLeaves ? CTracker::EConstructorLeaves : CTracker::ENonleavingConstructor)),
   728 	  iAutoArray(new(ELeave) CTracker[KNumTrackers]),
   729 	  iPtrArray(3),
   730 	  iArrayWrapper(iArray),
   731 	  iRawLogger(42),
   732 	  iGuard(RLogger::Cleanup, &iRawLogger),
   733 	  iPair1(1, 2),
   734 	  iPair2(one, 2),
   735 	  iPair3(1, two),
   736 	  iPair4(one, two)
   737 	{
   738 	test.Printf(_L("  CComposite(%d) with leaving constructor - %x\n"),
   739 				aMode,
   740 				this);
   741 
   742 	iLogger = iLogger2.Unmanage();
   743 
   744 	iPtrArray->Append(CTracker::NewL());
   745 	iPtrArray->Append(CTracker::NewL());
   746 
   747 	iArrayWrapper->Append(CTracker::NewL());
   748 	iArrayWrapper->Append(CTracker::NewL());
   749 
   750 	if (aMode == EConstructorLeaves)
   751 		{
   752 		test.Printf(_L("CComposite(EConstructorLeaves): Now leaving with User::Leave(KErrGeneral)\n"));
   753 		User::Leave(KErrGeneral);
   754 		}
   755 	}
   756 
   757 CComposite::~CComposite()
   758 	{
   759 	test.Printf(_L("  ~CComposite - %x\n"), this);
   760 	}
   761 
   762 
   763 void CComposite::ReleaseLoggers()
   764 	{
   765 	test.Printf(_L("  CComposite::ReleaseLoggers - %x\n"), this);
   766 
   767 	iLogger.ReleaseResource();
   768 	iDestroyer.ReleaseResource();
   769 
   770 	iGuard.Dismiss();
   771 	iRawLogger.Release();
   772 	}
   773 
   774 
   775 void CComposite::ReleaseArrays()
   776 	{
   777 	test.Printf(_L("  CComposite::ReleaseArrays - %x\n"), this);
   778 
   779 	iAutoArray.ReleaseResource();
   780 	}
   781 
   782 
   783 void TrackingDesCall(const TDesC& aConst, TDes& aMut)
   784 	{
   785 	test.Printf(_L("TrackingDesCall const=%S, mut=%S\n"), &aConst, &aMut);
   786 	aMut.Append(_L(": Appended"));
   787 	}
   788 
   789 
   790 
   791 /**
   792 @SYMTestCaseID SYSLIB-EUSERHL-UT-4028
   793 @SYMTestCaseDesc Tests automatic cleanup if a leave occurs in a Constructor
   794 @SYMTestPriority High
   795 @SYMTestActions Creates a new CTracker instance passing EConstructorLeaves to the 
   796 				factory function which causes the constructor to leave.
   797 				Verifies that all memory allocated in the constructor is 
   798 				automatically freed if the constructor leaves.				
   799 @SYMTestExpectedResults All memory allocated in the constructor of CTracker should 
   800 				be automatically freed if the constructor leaves.
   801 @SYMREQ	10368
   802 */
   803 void TestLeaveFromConstructor()
   804 	{
   805 	
   806 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4028"));
   807 	
   808 	__UHEAP_MARK;
   809 	test.Next(_L("Test CONSTRUCTORS_MAY_LEAVE"));
   810 
   811 	TRAPD(status,
   812 		  {
   813 		  CTracker* tracker = CTracker::NewL(CTracker::EConstructorLeaves);
   814 		  tracker->MemFunc();
   815 		  });
   816 	if (status != KErrNone)
   817 		{
   818 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
   819 		}
   820 
   821 	__UHEAP_MARKEND;
   822 	}
   823 
   824 /**
   825 @SYMTestCaseID SYSLIB-EUSERHL-UT-4029
   826 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle using different 
   827 			cleanup strategies
   828 @SYMTestPriority High
   829 @SYMTestActions Creates a LCleanedupHandle<RLogger> objects with different cleanup strategies.
   830 				Verifies that the objects are automatically cleaned up when they go
   831 				out of scope
   832 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
   833 				objects is automatically freed when the object goes out of scope.
   834 @SYMREQ	10373-8
   835 */
   836 void TestLCleanedupHandleStrategies()
   837 	{
   838 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4029"));
   839 	
   840 	__UHEAP_MARK;
   841 	test.Next(_L("LCleanedupHandle - test cleanup strategies"));
   842 
   843 		{
   844 		LCleanedupHandle<RLogger> logger(1);
   845 		LCleanedupHandle<RLogger, TClose> logger2(2);
   846 		LCleanedupHandle<RLogger, TRelease> logger3(3);
   847 		LCleanedupHandle<RLogger, TDestroy> logger4(4);
   848 		LCleanedupHandle<RLogger, TFree> logger5(5);
   849 		}
   850 
   851 	__UHEAP_MARKEND;
   852 	}
   853 
   854 /**
   855 @SYMTestCaseID SYSLIB-EUSERHL-UT-4030
   856 @SYMTestCaseDesc Tests construction of LCleanedUpHandle objects using complex constructors
   857 @SYMTestPriority High
   858 @SYMTestActions Creates a LCleanedupHandle<RPair> objects using different constructors.
   859 				Verifies that the objects are automatically cleaned up when they go
   860 				out of scope
   861 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RPair>
   862 				objects is automatically freed when the object goes out of scope.
   863 @SYMREQ	10373-8
   864 */
   865 void TestLCleanedupConstructors()
   866 	{
   867 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4030"));
   868 	
   869 	__UHEAP_MARK;
   870 
   871 		{
   872 		LCleanedupHandle<RLogger> logger(1);
   873 
   874 		LCleanedupHandle<RPair> pair1(1, 2);
   875 		LCleanedupHandle<RPair> pair2(one, 2);
   876 		LCleanedupHandle<RPair> pair3(1, two);
   877 		LCleanedupHandle<RPair> pair4(one, two);
   878 		}
   879 
   880 	__UHEAP_MARKEND;
   881 	}
   882 
   883 /**
   884 @SYMTestCaseID SYSLIB-EUSERHL-UT-4031
   885 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle
   886 @SYMTestPriority High
   887 @SYMTestActions Creates an LCleanedupHandle<RLogger> on the stack and uses the object.
   888 				Verifies that the object is automatically cleaned up when it goes out of scope
   889 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
   890 				is automatically freed when the object goes out of scope
   891 @SYMREQ	10373-8
   892 */
   893 void TestLCleanedupHandleNormalL()
   894 	{
   895 	
   896 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4031"));
   897 	
   898 	__UHEAP_MARK;
   899 	test.Next(_L("LCleanedupHandle - test normal exit from a block scope"));
   900 
   901 		{
   902 		LCleanedupHandle<RLogger> logger;
   903 		logger->OpenL(42);
   904 
   905 		LCleanedupHandle<RLogger> logger2(42);
   906 		}
   907 
   908 	__UHEAP_MARKEND;
   909 	}
   910 
   911 
   912 /**
   913 @SYMTestCaseID SYSLIB-EUSERHL-UT-4032
   914 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupHandle object on a leave
   915 @SYMTestPriority High
   916 @SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and uses the object.
   917 				Verifies that the object is automatically cleaned up when a leave occurs
   918 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
   919 				is automatically freed when a leave occurs
   920 @SYMREQ	10373-8
   921 */
   922 void TestLCleanedupHandleLeave()
   923 	{
   924 	
   925 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4032"));
   926 	
   927 	__UHEAP_MARK;
   928 	test.Next(_L("LCleanedupHandle - test leave"));
   929 
   930 	TRAPD(status,
   931 		  {
   932 		  LCleanedupHandle<RLogger> logger(42);
   933 		  test.Printf(_L("TestLCleanedupHandleLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
   934 		  User::Leave(KErrGeneral);
   935 		  });
   936 	if (status != KErrNone)
   937 		{
   938 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
   939 		}
   940 
   941 	__UHEAP_MARKEND;
   942 	}
   943 
   944 /**
   945 @SYMTestCaseID SYSLIB-EUSERHL-UT-4033
   946 @SYMTestCaseDesc Tests manual cleanup of LCleanedupHandle object.
   947 @SYMTestPriority High
   948 @SYMTestActions Creates LCleanedupHandle<RLogger> objects on the stack and 
   949 				manually Unmanages and Closes the Handles.
   950 				Verifies that all memory allocated for the objects can be freed
   951 				manually.
   952 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
   953 				is freed by calling Unmanage() and Close()
   954 @SYMREQ	10373-8, 10375-5
   955 */
   956 void TestLCleanedupHandleUnmanage()
   957 	{
   958 	
   959 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4033"));
   960 	
   961 	__UHEAP_MARK;
   962 	test.Next(_L("LCleanedupHandle - test LCleanedupHandle::Unmanage"));
   963 
   964 	LCleanedupHandle<RLogger> logger1(1);
   965 	LCleanedupHandle<RLogger> logger2(2);
   966 	logger1.Unmanage();
   967 	logger1->Close();
   968 	logger2.Unmanage();
   969 	logger2->Close();
   970 
   971 	__UHEAP_MARKEND;
   972 	}
   973 
   974 /**
   975 @SYMTestCaseID SYSLIB-EUSERHL-UT-4034
   976 @SYMTestCaseDesc Tests manual cleanup of LCleanedupHandle object on a leave
   977 @SYMTestPriority High
   978 @SYMTestActions Creates LCleanedupHandle<RLogger> objects on the stack and 
   979 				manually Unmanages them.  
   980 				Forces a leave and then Closes the Handles.
   981 				Verifies that all memory allocated for the objects can be freed
   982 				manually in the event of a leave occuring
   983 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
   984 				is freed by calling Unmanage() and Close()
   985 @SYMREQ	10373-8, 10375-5
   986 */
   987 void TestLCleanedupHandleUnmanageLeave()
   988 	{
   989 	
   990 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4034"));
   991 	
   992 	__UHEAP_MARK;
   993 	test.Next(_L("LCleanedupHandle - test LCleanedupHandle::Unmanage and leave"));
   994 
   995 	RLogger logger1;
   996 	RLogger logger2;
   997 	TRAPD(status,
   998 		  {
   999 		  LCleanedupHandle<RLogger> auto_logger1(1);
  1000 		  LCleanedupHandle<RLogger> auto_logger2(2);
  1001 
  1002 		  logger1 = auto_logger1.Unmanage();
  1003 		  logger2 = auto_logger2.Unmanage();
  1004 
  1005 		  test.Printf(_L("TestLCleanedupHandleUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  1006 
  1007 		  User::Leave(KErrGeneral);
  1008 		  });
  1009 	if (status != KErrNone)
  1010 		{
  1011 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1012 		logger1.Close();
  1013 		logger2.Close();
  1014 		}
  1015 
  1016 	__UHEAP_MARKEND;
  1017 	}
  1018 
  1019 /**
  1020 @SYMTestCaseID SYSLIB-EUSERHL-UT-4035
  1021 @SYMTestCaseDesc Tests access to managed object through LCleanedupHandle
  1022 @SYMTestPriority High
  1023 @SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and 
  1024 				uses the LCleanedupHandle object to access RLogger methods
  1025 				via the -> operator and the LCleanedupHandle methods via 
  1026 				the . operator
  1027 @SYMTestExpectedResults All public RLogger methods and LCleanedupHandle methods
  1028 				should be accessible through the LCleanedupHandle object.
  1029 @SYMREQ	10373-8
  1030 */
  1031 void TestLCleanedupHandleObjectAccess()
  1032 	{
  1033 	
  1034 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4035"));
  1035 	
  1036 	__UHEAP_MARK;
  1037 	test.Next(_L("LCleanedupHandle - test object access"));
  1038 
  1039 		{
  1040 		LCleanedupHandle<RLogger> logger(42);
  1041 		logger->MemFunc();
  1042 		RLogger::StaticMemberRef(*logger);
  1043 		RLogger::StaticMemberPtr(&logger.Get());
  1044 		}
  1045 
  1046 	__UHEAP_MARKEND;
  1047 	}
  1048 
  1049 /**
  1050 @SYMTestCaseID SYSLIB-EUSERHL-UT-4036
  1051 @SYMTestCaseDesc Tests forced cleanup of LCleanedupHandle object.
  1052 @SYMTestPriority High
  1053 @SYMTestActions Creates a LCleanedupHandle<RLogger> on the stack and 
  1054 				forces cleanup by calling ReleaseResource().
  1055 				Verifies that all memory allocated for the object is freed
  1056 				by calling ReleaseResource();
  1057 @SYMTestExpectedResults All memory allocated for the LCleanedupHandle<RLogger>
  1058 				is freed by calling ReleaseResource().
  1059 @SYMREQ	10373-8, 10375-4
  1060 */
  1061 void TestLCleanedupHandleRelease()
  1062 	{
  1063 	
  1064 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4036"));
  1065 	
  1066 	__UHEAP_MARK;
  1067 	test.Next(_L("LCleanedupHandle - test LCleanedupHandle::ReleaseResource"));
  1068 
  1069 	LCleanedupHandle<RLogger> logger(42);
  1070 	logger.ReleaseResource();
  1071 
  1072 	LCleanedupHandle<RLogger> logger2(2);
  1073 	RLogger raw_logger = logger2.Unmanage();
  1074 	logger2.ReleaseResource();
  1075 	raw_logger.Close();
  1076 
  1077 	__UHEAP_MARKEND;
  1078 	}
  1079 
  1080 /**
  1081 @SYMTestCaseID SYSLIB-EUSERHL-UT-4037
  1082 @SYMTestCaseDesc Tests cleanup of derived objects using LCleanedupHandle<XXX>
  1083 @SYMTestPriority High
  1084 @SYMTestActions Creates LCleanedupHandle<XXX> objects on the stack by instantiating 
  1085 				derived classes.  
  1086 				Verifies that all memory allocated for the objects is freed 
  1087 				automatically when the objects go out of scope.
  1088 @SYMTestExpectedResults All memory allocated for the derived classes is freed
  1089 				automatically.
  1090 @SYMREQ	10373-8
  1091 */
  1092 void TestLCleanedupHandleConversionL()
  1093 	{
  1094 	
  1095 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4037"));
  1096 	
  1097 	__UHEAP_MARK;
  1098 	test.Next(_L("LCleanedupHandle - test convertible type support"));
  1099 
  1100 		{
  1101 		ROtherLogger olog;
  1102 		olog.OpenL(1);
  1103 		LCleanedupHandle<RLogger> logger(olog);
  1104 		}
  1105 
  1106 		{
  1107 		RLogger log2;
  1108 		log2.OpenL(2);
  1109 		LCleanedupHandle<ROtherLogger> ologger(3);
  1110 		ologger = log2;
  1111 
  1112 		ROtherLogger olog4(4);
  1113 		ologger = olog4;
  1114 		}
  1115 
  1116 	__UHEAP_MARKEND;
  1117 	}
  1118 
  1119 
  1120 void TestLCleanedupHandleL()
  1121 	{
  1122 	__UHEAP_MARK;
  1123 
  1124 	TestLCleanedupHandleStrategies();
  1125 	TestLCleanedupConstructors();
  1126 	TestLCleanedupHandleNormalL();
  1127 	TestLCleanedupHandleLeave();
  1128 	TestLCleanedupHandleUnmanage();
  1129 	TestLCleanedupHandleUnmanageLeave();
  1130 	TestLCleanedupHandleObjectAccess();
  1131 	TestLCleanedupHandleRelease();
  1132 	TestLCleanedupHandleConversionL();
  1133 
  1134 	__UHEAP_MARKEND;
  1135 	}
  1136 
  1137 
  1138 /**
  1139 @SYMTestCaseID SYSLIB-EUSERHL-UT-4038
  1140 @SYMTestCaseDesc Tests cleanup of Null pointer LCleanedupPtr object
  1141 @SYMTestPriority High
  1142 @SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack but doesnt 
  1143 				intialise the pointer.
  1144 				Verifies that the object is cleaned up when it goes out of scope
  1145 @SYMTestExpectedResults Cleanup of a NULL pointer should complete successfully
  1146 @SYMREQ	10373-6
  1147 */
  1148 void TestLCleanedupPtrNull()
  1149 	{
  1150 	
  1151 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4038"));
  1152 	
  1153 	__UHEAP_MARK;
  1154 	test.Next(_L("LCleanedupPtr - test null pointer"));
  1155 
  1156 		{
  1157 		LCleanedupPtr<CTracker> tracker;
  1158 		LCleanedupPtr<TInt> tint;
  1159 		}
  1160 
  1161 	__UHEAP_MARKEND;
  1162 	}
  1163 
  1164 /**
  1165 @SYMTestCaseID SYSLIB-EUSERHL-UT-4039
  1166 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupPtr object
  1167 @SYMTestPriority High
  1168 @SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and uses the object.
  1169 				Verifies that the object is automatically cleaned up when it goes out of scope
  1170 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
  1171 				is automatically freed when it goes out of scope.
  1172 @SYMREQ	10373-6
  1173 */
  1174 void TestLCleanedupPtrNormalL()
  1175 	{
  1176 	
  1177 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4039"));
  1178 	
  1179 	__UHEAP_MARK;
  1180 	test.Next(_L("LCleanedupPtr - test normal exit from a block scope"));
  1181 
  1182 	{
  1183 	LCleanedupPtr<CTracker> tracker(CTracker::NewL());
  1184 	LCleanedupPtr<TInt> tint(new TInt(42));
  1185 	}
  1186 
  1187 	__UHEAP_MARKEND;
  1188 	}
  1189 
  1190 /**
  1191 @SYMTestCaseID SYSLIB-EUSERHL-UT-4040
  1192 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupPtr object on a leave
  1193 @SYMTestPriority High
  1194 @SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and uses the object.
  1195 				Verifies that the object is automatically cleaned up when a leave occurs
  1196 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
  1197 				is automatically freed when a leave occurs
  1198 @SYMREQ	10373-6
  1199 */
  1200 void TestLCleanedupPtrLeave()
  1201 	{
  1202 	
  1203 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4040"));
  1204 	
  1205 	__UHEAP_MARK;
  1206 	test.Next(_L("LCleanedupPtr - test leave"));
  1207 
  1208 	TRAPD(status,
  1209 		  {
  1210 		  LCleanedupPtr<CTracker> tracker(CTracker::NewL());
  1211 		  LCleanedupPtr<CTracker> nulltracker;
  1212 		  LCleanedupPtr<TInt> tint(new TInt(42));
  1213 		  LCleanedupPtr<TInt> nullint;
  1214 
  1215 		  test.Printf(_L("TestLCleanedupPtrLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  1216 		  User::Leave(KErrGeneral);
  1217 		  });
  1218 	if (status != KErrNone)
  1219 		{
  1220 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1221 		}
  1222 
  1223 	__UHEAP_MARKEND;
  1224 	}
  1225 
  1226 /**
  1227 @SYMTestCaseID SYSLIB-EUSERHL-UT-4041
  1228 @SYMTestCaseDesc Tests manual cleanup of LCleanedupPtr object.
  1229 @SYMTestPriority High
  1230 @SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack and 
  1231 				manually Unmanages and deletes the CTracker objects
  1232 				Verifies that all memory allocated for the objects can be freed
  1233 				manually.
  1234 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
  1235 				is freed by calling Unmanage() and deleting the objects
  1236 @SYMREQ	10373-6, 10375-5
  1237 */
  1238 void TestLCleanedupPtrUnmanageL()
  1239 	{
  1240 	
  1241 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4041"));
  1242 	
  1243 	__UHEAP_MARK;
  1244 	test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage"));
  1245 
  1246 	{
  1247 	LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1248 	LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
  1249 	delete tracker1.Unmanage();
  1250 	delete tracker2.Unmanage();
  1251 	}
  1252 
  1253 	__UHEAP_MARKEND;
  1254 	}
  1255 
  1256 /**
  1257 @SYMTestCaseID SYSLIB-EUSERHL-UT-4042
  1258 @SYMTestCaseDesc Tests manual cleanup of LCleanedupPtr object on a leave
  1259 @SYMTestPriority High
  1260 @SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack and 
  1261 				manually Unmanages them.  
  1262 				Forces a leave and then deletes the CTracker objects.
  1263 				Verifies that all memory allocated for the objects can be freed
  1264 				manually in the event of a leave occuring
  1265 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
  1266 				is freed by calling Unmanage() and deleting the objects
  1267 @SYMREQ	10373-6, 10375-5
  1268 */
  1269 void TestLCleanedupPtrUnmanageLeave()
  1270 	{
  1271 	
  1272 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4042"));
  1273 	
  1274 	__UHEAP_MARK;
  1275 	test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage and leave"));
  1276 
  1277 
  1278 	{
  1279 	CTracker* ptr1 = NULL;
  1280 	CTracker* ptr2 = NULL;
  1281 	TRAPD(status2,
  1282 		{
  1283 		LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1284 		LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
  1285 
  1286 		ptr1 = tracker1.Unmanage();
  1287 		ptr2 = tracker2.Unmanage();
  1288 
  1289 		test.Printf(_L("TestLCleanedupPtrUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  1290 		User::Leave(KErrGeneral);
  1291 		});
  1292 
  1293 	if (status2 != KErrNone)
  1294 		{
  1295 		test.Printf(_L("Leave trapped; leave code: %d\n"), status2);
  1296 		delete ptr1;
  1297 		delete ptr2;
  1298 		}
  1299 	}
  1300 
  1301 
  1302 	__UHEAP_MARKEND;
  1303 	}
  1304 
  1305 /**
  1306 @SYMTestCaseID SYSLIB-EUSERHL-UT-4043
  1307 @SYMTestCaseDesc Tests access to managed object through LCleanedupPtr
  1308 @SYMTestPriority High
  1309 @SYMTestActions Creates an LCleanedupPtr<CTracker> on the stack and 
  1310 				uses the LCleanedupPtr object to access CTracker methods
  1311 				via the -> operator and the LCleanedupPtr methods via 
  1312 				the . operator
  1313 @SYMTestExpectedResults All public CTracker methods and LCleanedupPtr
  1314 				should be accessible through the LCleanedupPtr object.
  1315 @SYMREQ	10373-6
  1316 */
  1317 void TestLCleanedupPtrObjectAccessL()
  1318 	{
  1319 	
  1320 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4043"));
  1321 	
  1322 	__UHEAP_MARK;
  1323 	test.Next(_L("LCleanedupPtr - test managed object access"));
  1324 
  1325 	{
  1326 	LCleanedupPtr<CTracker> tracker(CTracker::NewL());
  1327 	tracker->MemFunc();
  1328 	CTracker::StaticMemberRef(*tracker);
  1329 	CTracker::StaticMemberPtr(tracker.Get());
  1330 	}
  1331 
  1332 	__UHEAP_MARKEND;
  1333 	}
  1334 
  1335 /**
  1336 @SYMTestCaseID SYSLIB-EUSERHL-UT-4044
  1337 @SYMTestCaseDesc Tests forced cleanup of LCleanedupPtr object.
  1338 @SYMTestPriority High
  1339 @SYMTestActions Creates an LCleanedupPtr<CTracker>> on the stack and 
  1340 				forces cleanup by calling ReleaseResource().
  1341 				Verifies that all memory allocated for the object is freed
  1342 				by calling ReleaseResource()
  1343 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<CTracker>
  1344 				is freed by calling ReleaseResource().
  1345 @SYMREQ	10373-6, 10375-4
  1346 */
  1347 void TestLCleanedupPtrReleaseL()
  1348 	{
  1349 	
  1350 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4044"));
  1351 	
  1352 	__UHEAP_MARK;
  1353 	test.Next(_L("LCleanedupPtr - test LCleanedupPtr::ReleaseResource"));
  1354 
  1355 
  1356 	{
  1357 	LCleanedupPtr<CTracker> tracker(CTracker::NewL());
  1358 	tracker.ReleaseResource();
  1359 	
  1360 	LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
  1361 	CTracker* ptracker2 = tracker2.Unmanage();
  1362 	tracker2.ReleaseResource();
  1363 	delete ptracker2;
  1364 
  1365 	LCleanedupPtr<CTracker> tracker3(CTracker::NewL());
  1366 	tracker3 = NULL;
  1367 	}
  1368 
  1369 	__UHEAP_MARKEND;
  1370 	}
  1371 
  1372 /**
  1373 @SYMTestCaseID SYSLIB-EUSERHL-UT-4045
  1374 @SYMTestCaseDesc Tests cleanup of LCleanedupPtr object using TPointerFree strategy
  1375 @SYMTestPriority High
  1376 @SYMTestActions Creates an LCleanedupPtr<TText, TPointerFree> on the stack and 
  1377 				uses the object.
  1378 				Verifies that all memory allocated for the object is freed by the
  1379 				TPointerFree cleanup strategy when the object goes out of scope.
  1380 @SYMTestExpectedResults All memory allocated for the LCleanedupPtr<TText, TPointerFree>
  1381 				object is freed by the TPointerFree cleanup strategy.
  1382 @SYMREQ	10373-6
  1383 */
  1384 void TestLCleanedupPtrPointerFree()
  1385 	{
  1386 	
  1387 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4045"));
  1388 	
  1389 	__UHEAP_MARK;
  1390 	test.Next(_L("LCleanedupPtr - test TPointerFree"));
  1391 
  1392 		{
  1393 		LCleanedupPtr<TText, TPointerFree> buffer(
  1394 		  static_cast<TText*>(User::Alloc(100 * sizeof(TText))));
  1395 		TPtr bufferPtr(buffer.Get(), 100);	// create a pointer to the buffer
  1396 		// use the buffer
  1397 		bufferPtr.Copy(_L("Hello RAII"));
  1398 		test.Printf(_L("%S\n"), &bufferPtr);
  1399 		}
  1400 
  1401 	__UHEAP_MARKEND;
  1402 	}
  1403 
  1404 
  1405 void TestLCleanedupPtrConversionL()
  1406 	{
  1407 	LCleanedupPtr<CTracker> tracker(CDerivedTracker::NewL());
  1408 
  1409 	LCleanedupPtr<TReal64, TPointerFree> real(
  1410 	  static_cast<TReal64*>(User::Alloc(sizeof(TReal64))));
  1411 	
  1412 	LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1413 	LCleanedupPtr<CDerivedTracker> derivedTracker(CDerivedTracker::NewL());
  1414 	
  1415 	tracker1 = derivedTracker.Unmanage();
  1416 
  1417 	}
  1418 
  1419 /**
  1420 @SYMTestCaseID SYSLIB-EUSERHL-UT-4046
  1421 @SYMTestCaseDesc Tests cleanup of derived objects using LCleanedupPtr<XXX>
  1422 @SYMTestPriority High
  1423 @SYMTestActions Creates an LCleanedupPtr<XXX> objects on the stack by instantiating 
  1424 				derived classes.  
  1425 				Verifies that all memory allocated for the objects is freed 
  1426 				automatically when the objects go out of scope.
  1427 @SYMTestExpectedResults All memory allocated for the derived classes is freed
  1428 				automatically.
  1429 @SYMREQ	10373-6
  1430 */
  1431 void TestLCleanedupPtrConversion()
  1432 	{
  1433 	
  1434 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4046"));
  1435 	
  1436 	__UHEAP_MARK;
  1437 	test.Next(_L("LCleanedupPtr - test convertible type support"));
  1438 
  1439 	TRAPD(status, TestLCleanedupPtrConversionL());
  1440 
  1441 	if (status != KErrNone)
  1442 		{
  1443 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1444 		}
  1445 
  1446 	__UHEAP_MARKEND;
  1447 	}
  1448 
  1449 /**
  1450 @SYMTestCaseID SYSLIB-EUSERHL-UT-4047
  1451 @SYMTestCaseDesc Tests assignment of LCleanedupPtr<XXX> objects
  1452 @SYMTestPriority High
  1453 @SYMTestActions Creates 2 LCleanedupPtr<CTracker> objects on the stack.
  1454 				Unamanages one of the objects and assigns the managed pointer 
  1455 				to the second LCleanedupPtr
  1456 				Verifies that all memory allocated for the objects is freed 
  1457 				automatically when the objects go out of scope.
  1458 @SYMTestExpectedResults All memory allocated for the objects is freed
  1459 				automatically when the objects go out of scope.
  1460 @SYMREQ	10373-6
  1461 */
  1462 void TestLCleanedupPtrAssignL()
  1463 	{
  1464 	
  1465 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4047"));
  1466 	
  1467 	__UHEAP_MARK;
  1468 	test.Next(_L("LCleanedupPtr - test LCleanedupPtr reset"));
  1469 
  1470 	{
  1471 	LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1472 	LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
  1473 
  1474 	tracker2 = tracker1.Unmanage();
  1475 	}
  1476 
  1477 	__UHEAP_MARKEND;
  1478 	}
  1479 
  1480 void TestLCleanedupPtrBoolConversionL()
  1481 	{
  1482 	LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1483 
  1484 	if (tracker1)
  1485 		{
  1486 		test.Printf(_L("TestLCleanedupPtrBoolConversion: tracker1 pointer = %x\n"), tracker1.Get());
  1487 		}
  1488 	else
  1489 		{
  1490 		test.Printf(_L("TestLCleanedupPtrBoolConversion: tracker1 pointer is null (%x)\n"), tracker1.Get());
  1491 		}
  1492 
  1493 	LCleanedupPtr<CTracker> nullPtr;
  1494 
  1495 	if (!nullPtr)
  1496 		{
  1497 		test.Printf(_L("TestLCleanedupPtrBoolConversion: nullPtr pointer is null (%x)\n"), nullPtr.Get());
  1498 		}
  1499 	else
  1500 		{
  1501 		test.Printf(_L("TestLCleanedupPtrBoolConversion: nullPtr pointer = %x\n"), nullPtr.Get());
  1502 		}
  1503 	}
  1504 
  1505 /**
  1506 @SYMTestCaseID SYSLIB-EUSERHL-UT-4048
  1507 @SYMTestCaseDesc Tests conversion of LCleanedupPtr<XXX> objects
  1508 @SYMTestPriority High
  1509 @SYMTestActions Calls TestLCleanedupPtrBoolConversionL which creates 2 
  1510 				LCleanedupPtr<CTracker> objects on the stack, one of which
  1511 				is a null pointer.  Tests conversion of the null pointer
  1512 				into a CTracker* via the Get() method and ensures all 
  1513 				memory is freed on scope exit.
  1514 @SYMTestExpectedResults All memory allocated for the objects is freed
  1515 				automatically when the objects go out of scope.
  1516 @SYMREQ	10373-6
  1517 */
  1518 void TestLCleanedupPtrBoolConversion()
  1519 	{
  1520 	
  1521 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4048"));
  1522 	
  1523 	__UHEAP_MARK;
  1524 	test.Next(_L("LCleanedupPtr - test bool conversion"));
  1525 
  1526 	TRAPD(status, TestLCleanedupPtrBoolConversionL());
  1527 
  1528 	if (status != KErrNone)
  1529 		{
  1530 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1531 		}
  1532 
  1533 	__UHEAP_MARKEND;
  1534 	}
  1535 
  1536 
  1537 void TestLCleanedupPtrCompareL()
  1538 	{
  1539 	LCleanedupPtr<CTracker> tracker1(CTracker::NewL());
  1540 	LCleanedupPtr<CTracker> tracker2(CTracker::NewL());
  1541 
  1542 	if (tracker1 == tracker2)
  1543 		{
  1544 		test.Printf(_L("tracker1 == tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1545 		}
  1546 
  1547 	if (tracker1 != tracker2)
  1548 		{
  1549 		test.Printf(_L("tracker1 != tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1550 		}
  1551 
  1552 
  1553 	if (tracker1 < tracker2)
  1554 		{
  1555 		test.Printf(_L("tracker1 < tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1556 		}
  1557 
  1558 
  1559 	tracker2 = tracker1.Get();
  1560 
  1561 	if (tracker1 == tracker2)
  1562 		{
  1563 		test.Printf(_L("tracker1 == tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1564 		}
  1565 
  1566 	if (tracker1 != tracker2)
  1567 		{
  1568 		test.Printf(_L("tracker1 != tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1569 		}
  1570 
  1571 	if (tracker1 < tracker2)
  1572 		{
  1573 		test.Printf(_L("tracker1 < tracker2 %x %x\n"), tracker1.Get(), tracker2.Get());
  1574 		}
  1575 
  1576 	tracker1.Unmanage();
  1577 	}
  1578 
  1579 
  1580 /**
  1581 @SYMTestCaseID SYSLIB-EUSERHL-UT-4049
  1582 @SYMTestCaseDesc Tests comparison of LCleanedupPtr<XXX> objects
  1583 @SYMTestPriority High
  1584 @SYMTestActions Calls TestLCleanedupPtrCompareL which creates 2 
  1585 				LCleanedupPtr<CTracker> objects on the stack.
  1586 				Compares the objects using the comparison operators 
  1587 				and ensures all memory is freed on scope exit.
  1588 @SYMTestExpectedResults All memory allocated for the objects is freed
  1589 				automatically when the objects go out of scope.
  1590 @SYMREQ	10373-6
  1591 */
  1592 void TestLCleanedupPtrCompare()
  1593 	{
  1594 	
  1595 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4049"));
  1596 	
  1597 	__UHEAP_MARK;
  1598 	test.Next(_L("LCleanedupPtr - test compare"));
  1599 
  1600 	TRAPD(status, TestLCleanedupPtrCompareL());
  1601 
  1602 	if (status != KErrNone)
  1603 		{
  1604 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1605 		}
  1606 
  1607 	__UHEAP_MARKEND;
  1608 	}
  1609 
  1610 /**
  1611 @SYMTestCaseID SYSLIB-EUSERHL-UT-4067
  1612 @SYMTestCaseDesc Tests execution of custom cleanup strategy for LCleanedupPtr<XXX> objects
  1613 @SYMTestPriority High
  1614 @SYMTestActions Creates an LCleanedupPtr<CTracker, TCTrackerDestroy> object 
  1615 				on the stack which uses a custom cleanup strategy.
  1616 				Verifies that the custom strategy is invoked when the object goes out
  1617 				of scope.
  1618 @SYMTestExpectedResults All memory allocated for the object is freed automatically by 
  1619 						the custom cleanup strategy when the objecs goes out of scope.
  1620 @SYMREQ	10373
  1621 */
  1622 void TestLCleanedupPtrCustomStrategyL()
  1623 	{
  1624 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4067"));
  1625 	
  1626 	__UHEAP_MARK;
  1627 	test.Next(_L("LCleanedupPtr - test TCTrackerDestroy strategy"));
  1628 
  1629 		{
  1630 		LCleanedupPtr<CTracker, TCTrackerDestroy> t(new(ELeave) CTracker);
  1631 		}
  1632 		
  1633 	test(trackerDestroyed);
  1634 
  1635 	__UHEAP_MARKEND;
  1636 
  1637 	}
  1638 
  1639 
  1640 void TestLCleanedupPtrL()
  1641 	{
  1642 	__UHEAP_MARK;
  1643 
  1644 	TestLCleanedupPtrNull();
  1645 	TestLCleanedupPtrNormalL();
  1646 	TestLCleanedupPtrLeave();
  1647 	TestLCleanedupPtrUnmanageL();
  1648 	TestLCleanedupPtrUnmanageLeave();
  1649 	TestLCleanedupPtrObjectAccessL();
  1650 	TestLCleanedupPtrReleaseL();
  1651 	TestLCleanedupPtrPointerFree();
  1652 	TestLCleanedupPtrConversion();
  1653 	TestLCleanedupPtrAssignL();
  1654 	TestLCleanedupPtrBoolConversion();
  1655 	TestLCleanedupPtrCompare();
  1656 	TestLCleanedupPtrCustomStrategyL();
  1657 	
  1658 	__UHEAP_MARKEND;
  1659 	}
  1660 
  1661 
  1662 class TLogCleanupStrategy
  1663 	{
  1664   public:
  1665 	template <class T>
  1666 	static void Cleanup(T* aObjPtr)
  1667 		{
  1668 		test.Printf(_L("Cleanup log: %x\n"), aObjPtr);
  1669 		}
  1670 	};
  1671 
  1672 /**
  1673 @SYMTestCaseID SYSLIB-EUSERHL-UT-4050
  1674 @SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects
  1675 @SYMTestPriority High
  1676 @SYMTestActions Creates an LCleanedupPtr<CComposite> on the stack -
  1677 				CComposite internally contains LManagedXX objects
  1678 				Verify that all LManagedXX objects are cleaned up when 
  1679 				the LCleanedupPtr<CComposite> object goes out of scope.
  1680 @SYMTestExpectedResults All memory allocated for the CComposite object
  1681 				is automatically freed when it goes out of scope.
  1682 @SYMREQ	10374
  1683 */
  1684 void TestLManagedNormalL()
  1685 	{
  1686 	
  1687 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4050"));
  1688 	
  1689 	__UHEAP_MARK;
  1690 	test.Next(_L("LManaged - test composite object with normal exit from a block scope "));
  1691 
  1692 	{
  1693 	LCleanedupPtr<CComposite> comp(CComposite::NewL());
  1694 	}
  1695 	
  1696 	//Check that the custom cleanup strategy for the iAutoPtr member of
  1697 	//CComposite has been invoked
  1698 	test(trackerDestroyed);
  1699 
  1700 	__UHEAP_MARKEND;
  1701 	}
  1702 
  1703 /**
  1704 @SYMTestCaseID SYSLIB-EUSERHL-UT-4051
  1705 @SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects if 
  1706 				a leave occurs in a Constructor
  1707 @SYMTestPriority High
  1708 @SYMTestActions Creates an LCleanedupPtr<CComposite> object on the stack 
  1709 				passing EConstructorLeaves to the CComposite factory function 
  1710 				which causes the constructor to leave.
  1711 				Verifies that all memory allocated in the constructor is 
  1712 				automatically freed if the constructor leaves.	
  1713 @SYMTestExpectedResults All memory allocated for the CComposite object
  1714 				is automatically freed when it goes out of scope.
  1715 @SYMREQ	10368, 10374 
  1716 */
  1717 void TestLManagedConstructorLeave()
  1718 	{
  1719 	
  1720 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4051"));
  1721 	
  1722 	__UHEAP_MARK;
  1723 	test.Next(_L("LManaged - test composite object with leave from constructor"));
  1724 
  1725 	TRAPD(status,
  1726 		  {
  1727 		  LCleanedupPtr<CComposite> comp(CComposite::NewL(CComposite::EConstructorLeaves));
  1728 		  });
  1729 
  1730 	if (status != KErrNone)
  1731 		{
  1732 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1733 		}
  1734 	
  1735 	//Check that the custom cleanup strategy for the iAutoPtr member of
  1736 	//CComposite has been invoked
  1737 	test(trackerDestroyed);
  1738 
  1739 	__UHEAP_MARKEND;
  1740 	}
  1741 
  1742 /**
  1743 @SYMTestCaseID SYSLIB-EUSERHL-UT-4052
  1744 @SYMTestCaseDesc Tests automatic cleanup of LManagedXX objects if 
  1745 				a leave occurs in a Constructor
  1746 @SYMTestPriority High
  1747 @SYMTestActions Creates an LCleanedupPtr<CComposite> object on the stack 
  1748 				passing EMemberConstructorLeaves to the CComposite factory function 
  1749 				which causes the constructor of the CTracker member to leave.
  1750 				The CComposite object contains several LManagedX members which are 
  1751 				instantiated in the constructor.
  1752 				Verifies that all memory allocated in the constructor is 
  1753 				automatically freed if the constructor leaves.	
  1754 @SYMTestExpectedResults All memory allocated for the CComposite object
  1755 				is automatically freed when it goes out of scope.
  1756 @SYMREQ	10368, 10374
  1757 */
  1758 void TestLManagedMemberConstructorLeave()
  1759 	{
  1760 	
  1761 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4052"));
  1762 	
  1763 	__UHEAP_MARK;
  1764 	test.Next(_L("LManaged - test composite object with leave from member constructor"));
  1765 
  1766 	TRAPD(status,
  1767 		  {
  1768 		  LCleanedupPtr<CComposite> comp(CComposite::NewL(CComposite::EMemberConstructorLeaves));
  1769 		  });
  1770 
  1771 	if (status != KErrNone)
  1772 		{
  1773 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1774 		}
  1775 	
  1776 	//Check that the custom cleanup strategy for the iAutoPtr member of
  1777 	//CComposite has been invoked
  1778 	test(trackerDestroyed);
  1779 
  1780 	__UHEAP_MARKEND;
  1781 	}
  1782 
  1783 
  1784 /**
  1785 @SYMTestCaseID SYSLIB-EUSERHL-UT-4053
  1786 @SYMTestCaseDesc Tests realease of LManagedX classes
  1787 @SYMTestPriority High
  1788 @SYMTestActions Creates 2 LCleanedupPtr<CComposite> objects on the stack.
  1789 				Calls ReleaseLoggers() and ReleaseArrays() on the managed objects.
  1790 				Verifies that all memory allocated for the objects is freed 
  1791 				automatically when the objects go out of scope.
  1792 @SYMTestExpectedResults All memory allocated for the objects is freed
  1793 				automatically when the objects go out of scope.
  1794 @SYMREQ	10374
  1795 */
  1796 void TestLManagedReleaseL()
  1797 	{
  1798 	
  1799 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4053"));
  1800 	
  1801 	__UHEAP_MARK;
  1802 	test.Next(_L("LManaged - test composite object release"));
  1803 
  1804 	{
  1805 	LCleanedupPtr<CComposite> comp1(CComposite::NewL());
  1806 	comp1->ReleaseLoggers();
  1807 
  1808 	LCleanedupPtr<CComposite> comp2(CComposite::NewL());
  1809 	comp2->ReleaseArrays();
  1810 	}
  1811 	
  1812 	//Check that the custom cleanup strategy for the iAutoPtr member of
  1813 	//CComposite has been invoked
  1814 	test(trackerDestroyed);
  1815 
  1816 	__UHEAP_MARKEND;
  1817 	}
  1818 
  1819 
  1820 void TestCompositeL()
  1821 	{
  1822 	__UHEAP_MARK;
  1823 
  1824 	  TestLManagedNormalL();
  1825 	  TestLManagedConstructorLeave();
  1826 	  TestLManagedMemberConstructorLeave();
  1827 	  TestLManagedReleaseL();
  1828 
  1829 	__UHEAP_MARKEND;
  1830 	}
  1831 
  1832 /**
  1833 @SYMTestCaseID SYSLIB-EUSERHL-UT-4054
  1834 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupRef object
  1835 @SYMTestPriority High
  1836 @SYMTestActions Creates a LCleanedupRef<RLogger> on the stack and uses the object.
  1837 				Verifies that the object is automatically cleaned up when it goes out of scope
  1838 @SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
  1839 				is automatically freed when it goes out of scope.
  1840 @SYMREQ	10373-7
  1841 */
  1842 void TestLCleanedupRefNormalL()
  1843 	{
  1844 	
  1845 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4054"));
  1846 	
  1847 	__UHEAP_MARK;
  1848 	test.Next(_L("LCleanedupRef - test normal exit from a block scope"));
  1849 
  1850 		{
  1851 		RLogger logger;
  1852 		logger.OpenL(42);
  1853 		LCleanedupRef<RLogger> wlogger(logger);
  1854 		wlogger->MemFunc();
  1855 		}
  1856 
  1857 	__UHEAP_MARKEND;
  1858 	}
  1859 
  1860 
  1861 /**
  1862 @SYMTestCaseID SYSLIB-EUSERHL-UT-4055
  1863 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupRef object on a leave
  1864 @SYMTestPriority High
  1865 @SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and uses the object.
  1866 				Verifies that the object is automatically cleaned up when a leave occurs
  1867 @SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
  1868 				is automatically freed when a leave occurs
  1869 @SYMREQ	10373-7
  1870 */
  1871 void TestLCleanedupRefLeave()
  1872 	{
  1873 	
  1874 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4055"));
  1875 	
  1876 	__UHEAP_MARK;
  1877 	test.Next(_L("LCleanedupRef - test leave"));
  1878 
  1879 	TRAPD(status,
  1880 		  {
  1881 		  RLogger logger;
  1882 		  logger.OpenL(42);
  1883 		  LCleanedupRef<RLogger> wlogger(logger);
  1884 		  wlogger->MemFunc();
  1885 
  1886 		  test.Printf(_L("TestLCleanedupRefLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  1887 		  User::Leave(KErrGeneral);
  1888 		  });
  1889 	if (status != KErrNone)
  1890 		{
  1891 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1892 		}
  1893 
  1894 	__UHEAP_MARKEND;
  1895 	}
  1896 
  1897 /**
  1898 @SYMTestCaseID SYSLIB-EUSERHL-UT-4056
  1899 @SYMTestCaseDesc Tests manual cleanup of LCleanedupRef object.
  1900 @SYMTestPriority High
  1901 @SYMTestActions Creates an LCleanedupRef<RLogger> object on the stack and 
  1902 				manually Unmanages and closes the RLogger.
  1903 				Verifies that all memory allocated for the object can be freed
  1904 				manually.
  1905 @SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
  1906 				is freed by calling Unmanage() and Close()
  1907 @SYMREQ	10373-7, 10375-5
  1908 */
  1909 void TestLCleanedupRefUnmanageL()
  1910 	{
  1911 	
  1912 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4056"));
  1913 	
  1914 	__UHEAP_MARK;
  1915 
  1916 	test.Next(_L("LCleanedupPtr - test LCleanedupPtr::Unmanage"));
  1917 
  1918 	RLogger logger;
  1919 
  1920 	LCleanedupRef<RLogger> rlog(logger);
  1921 	rlog->OpenL(42);
  1922 	rlog->MemFunc();
  1923 	rlog.Unmanage();
  1924 	logger.Close();
  1925 
  1926 	__UHEAP_MARKEND;
  1927 	}
  1928 
  1929 /**
  1930 @SYMTestCaseID SYSLIB-EUSERHL-UT-4057
  1931 @SYMTestCaseDesc Tests manual cleanup of LCleanedupRef object on a leave
  1932 @SYMTestPriority High
  1933 @SYMTestActions Creates LCleanedupRef<RLogger> objects on the stack and 
  1934 				manually Unmanages them.  
  1935 				Forces a leave and then Closes the RLogger objects.
  1936 				Verifies that all memory allocated for the objects can be freed
  1937 				manually in the event of a leave occuring
  1938 @SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
  1939 				is freed by calling Unmanage() and Close()
  1940 @SYMREQ	10373-7, 10375-5
  1941 */
  1942 void TestLCleanedupRefUnmanageLeave()
  1943 	{
  1944 	
  1945 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4057"));
  1946 	
  1947 	__UHEAP_MARK;
  1948 
  1949 	test.Next(_L("LCleanedupRef - test LCleanedupRef::Unmanage"));
  1950 
  1951 	RLogger logger1(1);
  1952 	RLogger logger2(2);
  1953 
  1954 	TRAPD(status,
  1955 		  {
  1956 		  LCleanedupRef<RLogger> rlog1(logger1);
  1957 		  LCleanedupRef<RLogger> rlog2(logger2);
  1958 		  rlog1->MemFunc();
  1959 		  rlog2->MemFunc();
  1960 		  rlog1.Unmanage();
  1961 		  rlog2.Unmanage();
  1962 
  1963 		  test.Printf(_L("TestLCleanedupRefUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  1964 		  User::Leave(KErrGeneral);
  1965 		  });
  1966 
  1967 	if (status != KErrNone)
  1968 		{
  1969 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  1970 		logger1.Close();
  1971 		logger2.Close();
  1972 		}
  1973 
  1974 	__UHEAP_MARKEND;
  1975 	}
  1976 
  1977 /**
  1978 @SYMTestCaseID SYSLIB-EUSERHL-UT-4058
  1979 @SYMTestCaseDesc Tests access to managed object through LCleanedupRef
  1980 @SYMTestPriority High
  1981 @SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and 
  1982 				uses the LCleanedupRef object to access RLogger methods
  1983 				via the -> operator and the LCleanedupRef methods via 
  1984 				the . operator
  1985 @SYMTestExpectedResults All public RLogger methods and LCleanedupRef
  1986 				should be accessible through the LCleanedupRef object.
  1987 @SYMREQ	10373-7
  1988 */
  1989 void TestLCleanedupRefObjectAccessL()
  1990 	{
  1991 	
  1992 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4058"));
  1993 	
  1994 	__UHEAP_MARK;
  1995 	test.Next(_L("LCleanedupRef - test managed object access"));
  1996 
  1997 		{
  1998 		RLogger logger;
  1999 		logger.OpenL(42);
  2000 		LCleanedupRef<RLogger> rlog(logger);
  2001 		rlog->MemFunc();
  2002 		RLogger::StaticMemberRef(*rlog);
  2003 		RLogger::StaticMemberPtr(&rlog.Get());
  2004 		}
  2005 
  2006 	__UHEAP_MARKEND;
  2007 	}
  2008 
  2009 /**
  2010 @SYMTestCaseID SYSLIB-EUSERHL-UT-4059
  2011 @SYMTestCaseDesc Tests forced cleanup of LCleanedupRef object.
  2012 @SYMTestPriority High
  2013 @SYMTestActions Creates an LCleanedupRef<RLogger> on the stack and 
  2014 				forces cleanup by calling ReleaseResource().
  2015 				Verifies that all memory allocated for the object is freed
  2016 				by calling ReleaseResource()
  2017 @SYMTestExpectedResults All memory allocated for the LCleanedupRef<RLogger>
  2018 				is freed by calling ReleaseResource().
  2019 @SYMREQ	10373-7, 10375-4
  2020 */
  2021 void TestLCleanedupRefReleaseL()
  2022 	{
  2023 	
  2024 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4059"));
  2025 	
  2026 	__UHEAP_MARK;
  2027 	test.Next(_L("LCleanedupRef - test LCleanedupRef::ReleaseResource"));
  2028 
  2029 		{
  2030 		RLogger logger;
  2031 		logger.OpenL(42);
  2032 
  2033 		LCleanedupRef<RLogger> wlogger(logger);
  2034 		wlogger->MemFunc();
  2035 		wlogger.ReleaseResource();
  2036 
  2037 		RLogger logger2(2);
  2038 		LCleanedupRef<RLogger> wlogger2(logger2);
  2039 		wlogger2->MemFunc();
  2040 		RLogger& logref2 = wlogger2.Unmanage();
  2041 		wlogger2.ReleaseResource();
  2042 		logref2.Release();
  2043 		}
  2044 
  2045 	__UHEAP_MARKEND;
  2046 	}
  2047 
  2048 
  2049 /**
  2050 @SYMTestCaseID SYSLIB-EUSERHL-UT-4060
  2051 @SYMTestCaseDesc Tests assignment of LCleanedupRef<XXX> objects
  2052 @SYMTestPriority High
  2053 @SYMTestActions Creates 2 LCleanedupRef<CTracker> objects on the stack.
  2054 				Unamanages one of the objects and assigns the managed 
  2055 				reference to the second LCleanedupPtr
  2056 				Verifies that all memory allocated for the objects is freed 
  2057 				automatically when the objects go out of scope.
  2058 @SYMTestExpectedResults All memory allocated for the objects is freed
  2059 				automatically when the objects go out of scope.
  2060 @SYMREQ	10373-7
  2061 */
  2062 void TestLCleanedupRefAssignL()
  2063 	{
  2064 	
  2065 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4060"));
  2066 	
  2067 	__UHEAP_MARK;
  2068 	test.Next(_L("LCleanedupRef - test LCleanedupRef::operator="));
  2069 
  2070 		{
  2071 		RLogger logger1;
  2072 		logger1.OpenL(1);
  2073 		LCleanedupRef<RLogger> wlogger1(logger1);
  2074 
  2075 		RLogger logger2;
  2076 		logger2.OpenL(2);
  2077 		LCleanedupRef<RLogger> wlogger2(logger2);
  2078 
  2079 		//The assignment results in logger2 being cleaned up before 
  2080 		//logger1 is assigned
  2081 		wlogger2 = wlogger1.Unmanage();
  2082 		}
  2083 
  2084 	__UHEAP_MARKEND;
  2085 	}
  2086 
  2087 
  2088 
  2089 void TestLCleanedupRefL()
  2090 	{
  2091 	__UHEAP_MARK;
  2092 
  2093 	TestLCleanedupRefNormalL();
  2094  	TestLCleanedupRefLeave();
  2095  	TestLCleanedupRefUnmanageL();
  2096  	TestLCleanedupRefUnmanageLeave();
  2097  	TestLCleanedupRefObjectAccessL();
  2098  	TestLCleanedupRefReleaseL();
  2099 	TestLCleanedupRefAssignL();
  2100 
  2101 	__UHEAP_MARKEND;
  2102 	}
  2103 
  2104 /**
  2105 @SYMTestCaseID SYSLIB-EUSERHL-UT-4061
  2106 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupGuard object
  2107 @SYMTestPriority High
  2108 @SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
  2109 				via the RLogger::Cleanup function.
  2110 				Verifies that the object is automatically cleaned up when it goes 
  2111 				out of scope
  2112 @SYMTestExpectedResults All memory allocated for the RLogger
  2113 				is automatically freed when it goes out of scope.
  2114 @SYMREQ	10373-10
  2115 */
  2116 void TestLCleanedupGuardNormal()
  2117 	{
  2118 	
  2119 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4061"));
  2120 	
  2121 	__UHEAP_MARK;
  2122 	test.Printf(_L("LCleanedupGuard - test normal exit from a block scope\n"));
  2123 
  2124 		{
  2125 		RLogger logger(42);
  2126 		LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
  2127 		}
  2128 
  2129 	__UHEAP_MARKEND;
  2130 	}
  2131 
  2132 /**
  2133 @SYMTestCaseID SYSLIB-EUSERHL-UT-4062
  2134 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupGuard object on a leave
  2135 @SYMTestPriority High
  2136 @SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
  2137 				via the RLogger::Cleanup function.
  2138 				Verifies that the object is automatically cleaned up when a leave occurs
  2139 @SYMTestExpectedResults All memory allocated for the RLogger
  2140 				is automatically freed when a leave occurs
  2141 @SYMREQ	10373-10
  2142 */
  2143 void TestLCleanedupGuardLeave()
  2144 	{
  2145 	
  2146 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4062"));
  2147 	
  2148 	__UHEAP_MARK;
  2149 	test.Printf(_L("LCleanedupGuard - test leave"));
  2150 
  2151 	TRAPD(status,
  2152 		  {
  2153 		  RLogger logger(42);
  2154 		  LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
  2155 
  2156 		  test.Printf(_L("TestLCleanedupGuardLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  2157 		  User::Leave(KErrGeneral);
  2158 		  });
  2159 
  2160 	if (status != KErrNone)
  2161 		{
  2162 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  2163 		}
  2164 
  2165 	__UHEAP_MARKEND;
  2166 	}
  2167 
  2168 /**
  2169 @SYMTestCaseID SYSLIB-EUSERHL-UT-4063
  2170 @SYMTestCaseDesc Tests dissmissing of LCleanedupGuard
  2171 @SYMTestPriority High
  2172 @SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
  2173 				via the RLogger::Cleanup function.
  2174 				Calls LCleanedupGuard::Dismiss to disable the guard and manually calls 
  2175 				cleanup function.
  2176 				Verifies that the memory allocated for the RLogger object is cleaned up
  2177 @SYMTestExpectedResults All memory allocated for the RLogger is freed by calling
  2178 				Dismiss and manually calling RLogger::Cleanup()
  2179 @SYMREQ	10373-10
  2180 */
  2181 void TestLCleanedupGuardDismiss()
  2182 	{
  2183 	
  2184 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4063"));
  2185 	
  2186 	__UHEAP_MARK;
  2187 	test.Printf(_L("LCleanedupGuard - test LCleanedupGuard::Dismiss\n"));
  2188 
  2189 
  2190 	RLogger logger(42);
  2191 	LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
  2192 	cleanGuard.Dismiss();
  2193 	RLogger::Cleanup(&logger);
  2194 
  2195 	__UHEAP_MARKEND;
  2196 	}
  2197 
  2198 /**
  2199 @SYMTestCaseID SYSLIB-EUSERHL-UT-4064
  2200 @SYMTestCaseDesc Tests dismissing of LCleanedupGuard on a leave
  2201 @SYMTestPriority High
  2202 @SYMTestActions Creates an LCleanedupGuard on the stack to clean up an RLogger object
  2203 				via the RLogger::Cleanup function.
  2204 				Calls LCleanedupGuard::Dismiss to disable the guard and forces a leave.
  2205 				Manually calls the RLogger cleanup function.
  2206 				Verifies that the memory allocated for the RLogger object is cleaned up
  2207 @SYMTestExpectedResults All memory allocated for the RLogger is freed on a leave by 
  2208 			calling Dismiss and manually cleaning up the object.
  2209 @SYMREQ	10373-10
  2210 */
  2211 void TestLCleanedupGuardDismissLeave()
  2212 	{
  2213 	
  2214 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4064"));
  2215 	
  2216 	__UHEAP_MARK;
  2217 	test.Printf(_L("LCleanedupGuard - test LCleanedupGuard::Dismiss\n"));
  2218 
  2219 	RLogger logger(42);
  2220 	TRAPD(status,
  2221 		  {
  2222 		  LCleanedupGuard cleanGuard(RLogger::Cleanup, &logger);
  2223 		  cleanGuard.Dismiss();
  2224 
  2225 		  test.Printf(_L("TestLCleanedupGuardDismissLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  2226 		  User::Leave(KErrGeneral);
  2227 		  });
  2228 
  2229 	if (status != KErrNone)
  2230 		{
  2231 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  2232 		RLogger::Cleanup(&logger);
  2233 		}
  2234 
  2235 	__UHEAP_MARKEND;
  2236 	}
  2237 
  2238 
  2239 void TestLCleanedupGuard()
  2240 	{
  2241 	__UHEAP_MARK;
  2242 
  2243 	TestLCleanedupGuardNormal();
  2244 	TestLCleanedupGuardLeave();
  2245 	TestLCleanedupGuardDismiss();
  2246 	TestLCleanedupGuardDismissLeave();
  2247 
  2248 	__UHEAP_MARKEND;
  2249 	}
  2250 
  2251 
  2252 /**
  2253 @SYMTestCaseID SYSLIB-EUSERHL-UT-4065
  2254 @SYMTestCaseDesc Tests manual cleanup of LCleanedupArray object on a leave
  2255 @SYMTestPriority High
  2256 @SYMTestActions Creates an LCleanedupArray<TLogger> on the stack and calls Unmanage().
  2257 				Forces a leave and then manually cleans up the array.
  2258 				Verifies that the objects are automatically cleaned up when they go
  2259 				out of scope
  2260 @SYMTestExpectedResults All memory allocated for the LCleanedupArray objects
  2261 				is automatically freed when they go out of scope.
  2262 @SYMREQ	10373-9, 10375-5
  2263 */
  2264 void TestLCleanedupArrayUnmanageLeave()
  2265 	{
  2266 	
  2267 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4065"));
  2268 	
  2269 	__UHEAP_MARK;
  2270 
  2271 	const TInt KNumLoggers = 3;
  2272 	TLogger* ploggers = NULL;
  2273 	TRAPD(status,
  2274 		  {
  2275 		  LCleanedupArray<TLogger> loggers(new(ELeave) TLogger[KNumLoggers]);
  2276 
  2277 		  ploggers = loggers.Unmanage();
  2278 
  2279 		  test.Printf(_L("TestLCleanedupArrayUnmanageLeave(): Now leaving with User::Leave(KErrGeneral)\n"));
  2280 
  2281 		  User::Leave(KErrGeneral);
  2282 		  });
  2283 	if (status != KErrNone)
  2284 		{
  2285 		test.Printf(_L("Leave trapped; leave code: %d\n"), status);
  2286 		delete[] ploggers;
  2287 		}
  2288 
  2289 	__UHEAP_MARKEND;
  2290 	}
  2291 
  2292 /**
  2293 @SYMTestCaseID SYSLIB-EUSERHL-UT-4066
  2294 @SYMTestCaseDesc Tests automatic cleanup of LCleanedupArray object
  2295 @SYMTestPriority High
  2296 @SYMTestActions Creates an LCleanedupArray<TLogger>and uses the object.
  2297 				Creates an LCleanedupArray<TLogger, TLogCleanupStrategy> with a custom
  2298 				cleanup strategy and uses the object.
  2299 				Creates an LCleanedupArray<TLogger> and forces cleanup
  2300 				Creates an LCleanedupArray<TLogger> and calls UNmanage()
  2301 				Verifies that the objects are automatically cleaned up when they go
  2302 				out of scope
  2303 @SYMTestExpectedResults All memory allocated for the LCleanedupArray objects
  2304 				is automatically freed when they go out of scope.
  2305 @SYMREQ	10373-9, 10375-4, 10375-5
  2306 */
  2307 void TestLCleanedupArrayL()
  2308 	{
  2309 	
  2310 	test.Next(_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4066"));
  2311 	
  2312 	__UHEAP_MARK;
  2313 	test.Next(_L("LCleanedupArray - test normal exit from a block scope"));
  2314 
  2315 		{
  2316 		const TInt KNumLoggers = 3;
  2317 		LCleanedupArray<TLogger> array(new(ELeave) TLogger[KNumLoggers]);
  2318 		array[0].Test();
  2319 
  2320 		TLogger rawarr[2];
  2321 		LCleanedupArray<TLogger, TLogCleanupStrategy> marr(rawarr);
  2322 		marr[0].Test();
  2323 
  2324 		LCleanedupArray<TLogger> array2(new(ELeave) TLogger[KNumLoggers]);
  2325 		array2.ReleaseResource();
  2326 
  2327 		LCleanedupArray<TLogger> array3(new(ELeave) TLogger[KNumLoggers]);
  2328 		array2 = array3.Unmanage();
  2329 
  2330 		LCleanedupArray<TLogger> nullarr;
  2331 
  2332 		TestLCleanedupArrayUnmanageLeave();
  2333 		}
  2334 
  2335 	__UHEAP_MARKEND;
  2336 	}
  2337 
  2338 
  2339 void TestOrLeave()
  2340  	{
  2341 	__UHEAP_MARK;
  2342 
  2343 		{		
  2344 		TRAPD(err,KErrGeneral OR_LEAVE);
  2345 		test(err == KErrGeneral);
  2346   	
  2347 		TRAP(err,(5-7) OR_LEAVE);
  2348 		test(err == -2);
  2349  	
  2350 		RLogger logger;
  2351 		logger.OpenL(KErrNoMemory);
  2352  	
  2353 		LCleanedupRef<RLogger> cLogger(logger);	
  2354 		TRAP(err,{
  2355  			*(cLogger->GetData()) OR_LEAVE;
  2356  			});
  2357 		test(err == KErrNoMemory);
  2358 		
  2359 		LCleanedupHandle<RFs> cFs;
  2360 		LCleanedupHandle<RFile> cFile;
  2361  	
  2362 		TRAP(err, cFs->Connect() OR_LEAVE);
  2363 		test(err == KErrNone);
  2364 
  2365 		_LIT(KTestFile,"c:\\test_emanaged");
  2366 		err = cFile->Open(*cFs, KTestFile,EFileRead);
  2367 		if (err != KErrNone)
  2368 			{
  2369 			test.Printf(_L("Error opening file: %d\n"), err);
  2370 			if (err == KErrNotFound)
  2371 				{
  2372 				test.Printf(_L("Creating new file c:\\test_emanaged ... "));
  2373 				err = cFile->Create(*cFs,
  2374 									KTestFile,
  2375 									EFileWrite | EFileShareAny);
  2376 				test.Printf(_L("File created\n"));
  2377 				}
  2378 			}
  2379  	
  2380 		test(err == KErrNone);
  2381 
  2382 		LCleanedupHandle<RDir> dir;
  2383 		err = dir->Open(*cFs, _L("c:\\resource"), KEntryAttMaskSupported);
  2384 
  2385 		LCleanedupHandle<RFs> aFs(cFs.Unmanage());
  2386 		LCleanedupHandle<RFile> aFile(cFile.Unmanage());
  2387 		LCleanedupHandle<RDir> adir(dir.Unmanage());
  2388 
  2389 		test(err == KErrNone);
  2390 		}
  2391  	
  2392 	__UHEAP_MARKEND;
  2393  	}
  2394 
  2395 
  2396 void TestL()
  2397 	{
  2398 	__UHEAP_MARK;
  2399 
  2400 	TestLeaveFromConstructor();
  2401 
  2402 	TestLCleanedupHandleL();
  2403 	TestLCleanedupPtrL();
  2404 	TestLCleanedupArrayL();
  2405 	TestLCleanedupRefL();
  2406 	TestLCleanedupGuard();
  2407 	TestCompositeL();
  2408 	TestOrLeave();
  2409 	TExtendedTestL();
  2410 	__UHEAP_MARKEND;
  2411 	}
  2412 
  2413 
  2414 TInt E32Main()
  2415 	{
  2416 	CTrapCleanup* stack = CTrapCleanup::New();
  2417 	if (stack == NULL)
  2418 		return KErrNoMemory;
  2419 
  2420 	test.Title();
  2421 	test.Start(_L("RAII-based automatic resource management tests"));
  2422 
  2423 	TRAPD(status, TestL());
  2424 	if (status != KErrNone)
  2425 		{
  2426 		test.Printf(_L("Test leave trapped; leave code: %d\n"), status);
  2427 		}
  2428 	else
  2429 		{
  2430 		test.End();
  2431 		}
  2432 
  2433 	delete stack;
  2434 	return status;
  2435 	}
  2436 
  2437