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