pimappservices/calendar/tsrc/caltestoom.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2006-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 //
       
    15 
       
    16 #include "caltestoom.h"
       
    17 #include "caltestlib.h"
       
    18 
       
    19 #include <calsession.h>
       
    20 #include <e32debug.h>
       
    21 #include <ecom/ecom.h>
       
    22 
       
    23 EXPORT_C void CalTestOom::OutOfMemoryTestL(MCalTestOomCallBack& aCallBack, MCalTestOomCallBack::TType aType, CCalSession& aCalSession)
       
    24 	{
       
    25 	TInt clientFailAt(0);
       
    26 	TInt serverFailAt(0);
       
    27 	
       
    28 	TAny* dummy = NULL;
       
    29 	
       
    30 	TBool cleanCache = EFalse;
       
    31 	
       
    32 	for (TInt i(0) ; i < 10000 ; ++i)
       
    33 		{
       
    34 		CleanupStack::PushL(dummy);
       
    35 		}
       
    36 		
       
    37 	CleanupStack::Pop(10000);
       
    38 	
       
    39 	if(aType == MCalTestOomCallBack::EClient)
       
    40 		{
       
    41 		FOREVER
       
    42 			{
       
    43 			aCalSession.__dbgClearTzClientCacheL(cleanCache);
       
    44 			__UHEAP_SETFAIL(RHeap::EDeterministic, ++clientFailAt);
       
    45 			__UHEAP_MARK;
       
    46 			
       
    47 			TRAPD(err, aCallBack.OomTestL(MCalTestOomCallBack::EClient, clientFailAt));
       
    48 			
       
    49 			__UHEAP_RESET;
       
    50 			
       
    51 			REComSession::FinalClose();
       
    52 			
       
    53 			aCalSession.__dbgClearTzClientCacheL(cleanCache);
       
    54 						
       
    55 			if (err == KErrNoMemory)
       
    56 				{
       
    57 				__UHEAP_MARKEND;
       
    58 				}
       
    59 			else if (err == KErrNone)
       
    60 			    {
       
    61 			    break;
       
    62 			    }
       
    63 			else
       
    64 				{
       
    65 				User::Leave(err);
       
    66 				}
       
    67 			}
       
    68 			cleanCache = ETrue;
       
    69 			aCalSession.__dbgClearTzClientCacheL(cleanCache);
       
    70 		}
       
    71 	else if(aType == MCalTestOomCallBack::EServer)
       
    72 		{
       
    73 		
       
    74 		// server side oom test
       
    75 		FOREVER
       
    76 			{
       
    77 			aCalSession._DebugSetHeapFailL(RAllocator::EDeterministic, ++serverFailAt);
       
    78 			
       
    79 			TRAPD(err, aCallBack.OomTestL(MCalTestOomCallBack::EServer, serverFailAt));
       
    80 			
       
    81 			REComSession::FinalClose();
       
    82 			
       
    83 			if (err == KErrNoMemory)
       
    84 				{
       
    85 				aCalSession._DebugSetHeapFailL(RAllocator::ENone, 0);
       
    86 				}
       
    87 			else if (err == KErrNone)
       
    88 				{
       
    89 				aCalSession._DebugSetHeapFailL(RAllocator::ENone, 0);
       
    90 				break;
       
    91 				}
       
    92 			else
       
    93 				{
       
    94 				aCalSession._DebugSetHeapFailL(RAllocator::ENone, 0);
       
    95 				User::Leave(err);
       
    96 				}
       
    97 			}
       
    98 		}
       
    99 	}