/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0587
@SYMTestCaseDesc        CDbColSet class test
@SYMTestPriority        Medium
@SYMTestActions        	Tests for creation of a CDbColSet column set object
                        Tests for adding and removing columns to the column set
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestCDbColSetL()
	{
	TInt r;
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0587 ctor and dtor "));
	CDbColSet* c=CDbColSet::NewL();		// assume it will succeed
	test(c!=NULL);
	test (c->Count()==0);
	delete c;
	__UHEAP_CHECK(0);
#if defined(_DEBUG)
	__UHEAP_FAILNEXT(1);
	TRAP(r,c=CDbColSet::NewL());
	test(r!=KErrNone);
	__UHEAP_CHECK(0);
#endif
	c=CDbColSet::NewLC();
	test(c!=NULL);
	CleanupStack::PopAndDestroy();
	__UHEAP_CHECK(0);
	c=CDbColSet::NewL();
	TDbCol col(KColName,EDbColText,20);
	c->AddL(col);
	delete c;
	__UHEAP_CHECK(0);
	TRAP(r,c=CDbColSet::NewLC();c->AddL(col);User::Leave(KLeaveError););
Beispiel #2
0
void CTestNbssMtm::StartL()
	{
	test.Next(_L("CTestNbssMtm::Start()\n"));
	Cancel();
	iState=ENbssReadingFiles;
#if defined _HEAP_FAILURE_TEST_
	TBool finished=EFalse;
#ifdef _DEBUG
	TInt failCount=0;
	failCount1=0;
#endif
	while (!finished)
		{
		__UHEAP_FAILNEXT(failCount++);
		TRAPD(error,InitialiseTesterL());
		if (error==KErrNone)
			{
			finished=ETrue;
			__UHEAP_RESET;
			}
		else 
			{
			test(error==KErrNoMemory);
			__UHEAP_RESET;
			}
		}
#else
	InitialiseTesterL();
#endif
	QueueOperationAsync(KErrNone);
	}
Beispiel #3
0
/**
	@SYMTestCaseID
	GRAPHICS-FBSERV-0511

	@SYMTestCaseDesc
	Allocated sessions with the FbsServer and simulates memory allocation errors

	@SYMTestActions
	Checks the heap

	@SYMTestExpectedResults
	Test should pass
*/
void CTAlloc::Session()
	{
	INFO_PRINTF1(_L("RFbsSession::Connect()\r\n"));

	for (TInt count = 1; ; count++)
		{
		__UHEAP_FAILNEXT(count);
		__UHEAP_MARK;

		TInt ret = RFbsSession::Connect();

		if (ret == KErrNoMemory)
			{
			__UHEAP_MARKEND;
			}
		else if (ret == KErrNone)
			{
			RFbsSession::Disconnect();
			__UHEAP_MARKEND;
			break;
			}
		else 
			{
			__UHEAP_MARKEND;
			TEST2(ret, KErrNone);
			}
		}

	__UHEAP_RESET;
	}
Beispiel #4
0
void CTestNbssMtm::DoProcessAgainL()
	{
	TBuf8<1>dummy;
	iState = ENbssTestProcess;
	// add service entry and msg entry to selection passed to MTM
	iSelection->Reset();
	iSelection->AppendL((*iMsvSelection)[iFilesProcessed]);

#if defined _HEAP_FAILURE_TEST_
	TBool finished=EFalse;

#ifdef _DEBUG
	TInt failCount=0;
#endif

	while (!finished)
		{
		__UHEAP_FAILNEXT(failCount++);
		TRAPD(error,iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmProcess, dummy, iStatus));
		if (error==KErrNone)
			{
			finished=ETrue;
			__UHEAP_RESET;
			}
		else 
			{
			test(error==KErrNoMemory);
			__UHEAP_RESET;
			}
		}
#else
	iNbssServerMtm->StartCommandL(*iSelection, KBiosMtmProcess, dummy, iStatus);
#endif
	iState = ENbssTestProcess;
	}
// CLogServSecurity instance creation - OOM test
static void OOMTest()
	{
	for(TInt count=1;;++count)
		{
		__UHEAP_FAILNEXT(count);
		__UHEAP_MARK;
		TRAPD(err, ::DoOOMTestL());

		if(err == KErrNoMemory)
			{
			__UHEAP_MARKEND;
			}
		else if(err == KErrNone)
			{
			__UHEAP_MARKEND;
			TheTest.Printf(_L("The test succeeded at heap failure rate=%d.\n"), count);
			break;
			}
		else 
			{
			__UHEAP_MARKEND;
			TEST2(err, KErrNone);
			}
		}
	__UHEAP_RESET;
	}
Beispiel #6
0
void CFailureTester::HeapFailureTest()
	{
	__LOG_ALWAYS("Test Results");
	__LOG_ALWAYS(" ");

	__LOG_ALWAYS("***** HEAP FAILURE TEST FOR PUSH MESSAGE *****");

	TInt error;
	TBool finished = EFalse;
	TInt failCount = 0;
	CPushMessageTester* push = NULL;
	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);
		__UHEAP_MARK;
		TRAP(error, push = DoPushMessageTestL());
		if (error == KErrNone)
			{
			delete push;
			__UHEAP_RESET;
			LogFormatInt(_L("Made %d attempts at calling DoPushMessageTestL()"), failCount);
			finished = ETrue;
			}
		else  // Handle error
			{
			// Check if error is out of memory
			gTest(error == KErrNoMemory);
			__UHEAP_RESET;
			}
		__UHEAP_MARKEND;
		}

	__LOG_ALWAYS("RTEST: SUCCESS ***** PUSH MESSAGE TEST SUCCESSFUL ******");
	__LOG_ALWAYS(" ");
	}
Beispiel #7
0
void CFailureTester::PluginHeapFailureTest()
	{
	__LOG_ALWAYS("***** HEAP FAILURE TEST FOR PLUGIN *****");

	TInt error;
	TBool finished = EFalse;
	TInt failCount = 0;
	CPushMessageTester* push = NULL;
	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);
		__UHEAP_MARK;
		TRAP(error, push = CreatePushHandlerBaseL());
		if (error == KErrNone)
			{
			delete push;
			__UHEAP_RESET;
			LogFormatInt(_L("Made %d attempts at calling CreatePushHandlerBaseL()"), failCount);
			finished = ETrue;
			}
		else  // Handle error
			{
			// Check if error is out of memory
			gTest(error == KErrNoMemory);
			__UHEAP_RESET;
			}
		REComSession::FinalClose();
		__UHEAP_MARKEND;
		}

	__LOG_ALWAYS("RTEST: SUCCESS ***** PLUGIN TEST SUCCESSFUL ******");
	__LOG_ALWAYS(" ");
	__LOG_ALWAYS("Tests Completed");
	}
/**
@SYMTestCaseID
	GRAPHICS-DIRECTGDI-DRIVER-0002

@SYMPREQ 
	PREQ39

@SYMREQ
	REQ9211 
	REQ9226 
	REQ9195
	REQ9201 
	REQ9202 
	REQ9222 
	REQ9223 
	REQ9236 
	REQ9237

@SYMTestCaseDesc
	Out of memory test. Test that opening a driver does not cause memory leaks.

@SYMTestActions
	Repeatedly call the "Driver-ErrorCodes" test (below) in OOM conditions to make 
	sure no memory leaks occur.

@SYMTestExpectedResults
	No memory leaks.
	
@SYMTestStatus
	Implemented
*/
void CTDirectGdiDriver::TestDriverOOM()
	{
	TInt err, tryCount = 0;
	INFO_PRINTF1(_L("Driver-TestDriverOOM"));

	do
		{
		__UHEAP_FAILNEXT(++tryCount);
		__UHEAP_MARK;
		{
		err = TestDriverErrorCodes();		
		}
		__UHEAP_MARKEND;
		} 
	while(err == KErrNoMemory);
	if(err == KErrNone)
		{
		__UHEAP_RESET;
		}
	else
		{
		TEST(err == KErrNone);
		}
	INFO_PRINTF2(_L("- server succeeded at heap failure rate of %i\n"), tryCount);
	}
/**
@SYMTestCaseID SYSLIB-LOGENG-CT-0123
@SYMTestCaseDesc Delete event types
@SYMTestActions See the description and expected results.
@SYMTestPriority High
@SYMTestExpectedResults Should always succeed
@SYMREQ REQ3431
*/
LOCAL_C void TestDeleteEventTypeL(CLogClient& aClient)
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0123 "));
	CTestActive* active = new(ELeave)CTestActive();
	CleanupStack::PushL(active);

	CLogEventType* type = CLogEventType::NewL();
	CleanupStack::PushL(type);

	type->SetUid(KTestEventUid);

#ifdef _DEBUG
	TInt failCount = 0;
#endif

	TBool finished = EFalse;
	TInt error;

	while(!finished)
		{
		error = KErrNone;

		__UHEAP_FAILNEXT(failCount++);
		aClient.DeleteEventType(KTestEventUid, active->iStatus);

		active->StartL();
		CActiveScheduler::Start();

		if (active->iStatus == KErrNone)
			finished = ETrue;
		else
			error = active->iStatus.Int();

		__UHEAP_RESET;

		if (error == KErrNoMemory)
			{
			active->StartL();
			aClient.GetEventType(*type, active->iStatus);
			CActiveScheduler::Start();
			TEST2(active->iStatus.Int(), KErrNone);
			}
		else
			{
			TEST2(error, TheHiCapability ? KErrNone : KErrPermissionDenied);
			
			if(!TheHiCapability)
				finished = TRUE;
			}
		}

	active->StartL();
	aClient.GetEventType(*type, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), TheHiCapability ? KErrNotFound : KErrNone);

	CleanupStack::PopAndDestroy(2); // type, active
	}
void CMsmmSession::ServiceL(const RMessage2& aMessage)
    {
    OstTraceFunctionEntry0( CMSMMSESSION_SERVICEL_ENTRY );
    
    TInt ret(KErrNone);

#ifdef _DEBUG
    TInt* heapObj= NULL;
#endif // _DEBUG
        
    switch (aMessage.Function())
        {
    case EHostMsmmServerAddFunction:
        AddUsbMsInterfaceL(aMessage);
        break;

    case EHostMsmmServerRemoveDevice:
        RemoveUsbMsDeviceL(aMessage);
        break;

        // Supporting for server side OOM testing  
    case EHostMsmmServerDbgFailNext:
        ret = KErrNone;
#ifdef _DEBUG
        if (aMessage.Int0() == 0 )
            {
            __UHEAP_RESET;
            }
        else
            {
            __UHEAP_FAILNEXT(aMessage.Int0());
            }
#endif // _DEBUG
        break;

    case EHostMsmmServerDbgAlloc:
        ret = KErrNone;
#ifdef _DEBUG
        TRAP(ret, heapObj = new (ELeave) TInt);
        delete heapObj;
#endif // _DEBUG
        break;
        
    case EHostMsmmServerEjectUsbDrives:
        iServer.DismountUsbDrivesL(iDevicePkg());
        break;
    default:
        // Unsupported function number - panic the client
        PanicClient(aMessage, EBadRequest);
        }
        
    // Complete the request
    aMessage.Complete(ret);
    OstTraceFunctionExit0( CMSMMSESSION_SERVICEL_EXIT );
    }
void tst_qmainexceptions::leave()
{
    __UHEAP_MARK;
    CDummy* dummy1 = 0;
    TRAPD(err,{
        CDummy* csDummy = new (ELeave) CDummy;
        CleanupStack::PushL(csDummy);
        __UHEAP_FAILNEXT(1);
        dummy1 = new (ELeave) CDummy;
        //CleanupStack::PopAndDestroy(csDummy); not executed as previous line throws
    });
void CTe_LbsSimulationPSYSuiteStepBase::HeapTestL(const TInt aIndex)
    {
#ifdef __DEBUG__
    TInt err = KErrNone;
    TBool   warn = EFalse;
    const TInt KHeapFailureMaxLoop = KMaxTInt32 - 1;
    for (TInt i = 1; i < KHeapFailureMaxLoop; i++)
        {
        __UHEAP_FAILNEXT(i);
        __UHEAP_MARK;
        
        TRAP(err, DoTestL(aIndex));

        __UHEAP_MARKEND;
        
        // If no error occurred, fake a memory error to
        // make sure that this is the last test. If this
        // last allocation goes wrong, it proves that the
        // FAILNEXT() macro has reached its limit in this
        // test.
        if (err != KErrNoMemory)
            {
            TInt* dummy = new TInt;
            warn = (dummy != NULL);
            delete dummy;
            }

        __UHEAP_RESET;

        if ((err != KErrNoMemory) && !warn)
        	{
            break;
        	}

        if (warn)
            {
            // Commenting this out means we do not catch non leaving allocs
            // unfortunately testing for these generates too many false positives
            // as every use of INFO_PRINT triggers it.
            //LogTrap(aIndex);
            }
        }

    if (err != KErrNone)
        {
        User::Leave(err);
        }
#else
    DoTestL(aIndex);
#endif
    }
Beispiel #13
0
void CTestAppUi::TestSuccesiveAllocFailL()
	{
	RDebug::Print(_L("TVIEW2 : Test Succesive Alloc Failure During Activation Until Success"));	
	TInt error=KErrUnknown;
	for(TInt fail=1;error!=KErrNone;fail++)
		{
		RDebug::Print(_L("TVIEW2 : Next Failure Test"));
		__UHEAP_FAILNEXT(fail);// fail on succesive allocations
		__UHEAP_MARK;
		TRAP(error,CCoeAppUi::ActivateViewL(TVwsViewId(KUidViewAppTwo,KUidViewOne)));
		__UHEAP_MARKEND; // Check nothing has alloc'd due to fail
		}
	__UHEAP_SETFAIL(RHeap::ENone,0);// turn failure off
	}
/**
 *  Simulates heap allocation failure for the server.
 *
 *  The failure occurs on the next call to new or any of the functions which 
 *  allocate memory from the heap. This is defined only for debug builds.
 *
 *  @param aCount  Determines when the allocation will fail.
 *
 *  @return  KErrNone.
 */
TInt CShBufTestServer::DbgFailNext(TInt aCount) const
	{
#ifdef _DEBUG
	if (aCount == 0)
		{
		__UHEAP_RESET;
		}
	else
		{
		__UHEAP_FAILNEXT(aCount);
		}
#else
	(void) aCount;
#endif

	return(KErrNone);
	} // CShBufTestServer::DbgFailNext
enum TVerdict CIpsecTest4_1::doTestStepL()
/**
 * Each test step must supply a implementation for doTestStepL
 *
 <pre>

	   my @testcases = ("3.1", "3.2", "3.3", ...);

	   foreach $test (@testcases) {
	     my $count = 0;
	     my $ret = KErrNoMemory;
	     while($ret == KErrNoMemory) {
		   __UHEAP_FAILNEXT(count);
		   __UHEAP_MARK;

		   # run test cases

		   __UHEAP_MARKEND;
		   $count++;
		 }
	   }

 </pre>
 *
 */
{
    TInt count = 0;
    TInt ret = KErrNoMemory;

    /**
     * OOM test loop
     */
    while(ret==KErrNoMemory)
    {
        __UHEAP_FAILNEXT(count);
        __UHEAP_MARK;
        TRAP(ret, TestOomPolicyListL());
        __UHEAP_MARKEND;
        count++;
    }

    Log(_L("OOM after %d allocations"), count);

    // test steps return a result
    return iTestStepResult;
}
int main()
{
	//int count = 3;
	bool err = false;
	__UHEAP_MARK;
	__UHEAP_FAILNEXT(3);
	{
	string myString;
	while(!err)
	{
	int retval =ESuccess;
	_LIT8(KTxt, "hellohello");
  HBufC8* buff = HBufC8::NewL(10);
  *buff = KTxt;
  CleanupStack::PushL(buff);

	retval = Hbufc8ToString(buff,myString);
  
  if (retval ==EInsufficientSystemMemory)
    {

    	printf("hbufc8tostring_reliability Passed\n");
    	err = true;
    	//Logging to some file can be done here
    }
  else
    {
			assert_failed = true;
    	printf("hbufc8tostring_reliability Failed\n");
    	//Logging to some file can be done here
    }      
	}
	CleanupStack::PopAndDestroy();
	}
	__UHEAP_MARKEND;
	__UHEAP_RESET;

    testResultXml("test_hbufc8tostring_reliabilitysss");
	return 0;
}
/**
@SYMTestCaseID SYSLIB-LOGENG-CT-0125
@SYMTestCaseDesc Get database configuration
@SYMTestPriority High
@SYMTestActions All clients are allowed to do this
@SYMTestExpectedResults Should always succeed
@SYMREQ REQ3431
*/
LOCAL_C void TestGetConfigL(CLogClient& aClient)
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0125 "));
	CTestActive* active = new(ELeave)CTestActive();
	CleanupStack::PushL(active);

	TLogConfig config;

	TEST(config.iMaxEventAge == 0);
	TEST(config.iMaxLogSize == 0);
	TEST(config.iMaxRecentLogSize == 0);

#ifdef _DEBUG
	TInt failCount = 0;
#endif

	TBool finished = EFalse;

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);
		aClient.GetConfig(config, active->iStatus);

		active->StartL();
		CActiveScheduler::Start();

		if (active->iStatus == KErrNone)
			finished = ETrue;
		else
			TEST2(active->iStatus.Int(), KErrNoMemory);

		__UHEAP_RESET;
		}

	TEST(config.iMaxEventAge > 0);
	TEST(config.iMaxLogSize > 0);
	TEST(config.iMaxRecentLogSize > 0);

	CleanupStack::PopAndDestroy(); // active
	}
int main()
{
	//int count = 2;
	bool err = false;
	__UHEAP_MARK;
	__UHEAP_FAILNEXT(2);
	while(!err)
	{
	int retval =ESuccess;
	char* myChar = new char[30];
	_LIT16(KTxt, "hellohello");
  TBufC16<30> buf(KTxt);	
	TPtrC src = buf.Des();
	int size = 30;

	retval = Tptrc16ToCharp(src,myChar,size);
  
   if (retval ==EInsufficientSystemMemory)
    {

    	printf("tptrc16tochar_reliability Passed\n");
    	err = true;
    	//Logging to some file can be done here
    }
    else
    {
			assert_failed = true;
    	printf("tptrc16tochar_reliability Failed\n");
    	//Logging to some file can be done here
    }     
    delete[] myChar; 
	}
	__UHEAP_MARKEND;
	__UHEAP_RESET;

    testResultXml("test_tptrc16tochar_reliability");
	
	return 0;
}
void CHttpTestBase::DoLeakTestsL()
	{
	for (TInt ii = iFirstLeakIteration; ii < iLeakTests; ++ii)
		{
		iEngine->Utils().LogIt(_L("Memory Leak Testing on allocation %d\n"), ii);

		TInt err = KErrNoMemory;
		
		__UHEAP_MARK;
		__UHEAP_FAILNEXT(ii);
		TRAP(err,DoRunL());
		__UHEAP_MARKEND;
		User::Heap().Check();
		__UHEAP_RESET;

		// Break out if the test passes successfully; allow only memory failure or test failure codes to proceed.
		if (err == KErrNone)
			return;
		else if (err != KErrNoMemory && err != KErrTestFailed)
			User::Leave(err);
		}
	}
int main()
{
	//int count = 2;
	bool err = false;
	__UHEAP_MARK;
	__UHEAP_FAILNEXT(2);
	{
	wstring myString;
	while(!err)
	{
	int retval =ESuccess;
	_LIT8(Kname,"hello");
	TBufC8<20> buf(Kname);
	TPtrC8 src = buf.Des();

	retval = Tptrc8ToWstring(src,myString);
  
   if (retval ==EInsufficientSystemMemory)
    {

    	printf("tptrc8towstring_reliability Passed\n");
    	err = true;
    	//Logging to some file can be done here
    }
    else
    {
			assert_failed = true;
    	printf("tptrc8towstring_reliability Failed\n");
    	//Logging to some file can be done here
    }      
	}
}
	__UHEAP_MARKEND;
	__UHEAP_RESET;

    testResultXml("test_tptrc8towstring_reliability");
	
	return 0;
}
Beispiel #21
0
LOCAL_C void TestReAllocLeaving(LSTRING*)
{

	test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4005"));
	
	test.Next(_L("ReAllocL(TInt aMaxLength) method"));
	TBUF des(_TS("01"));

	LSTRING lStr(des);
	TRAPD(ret, lStr.ReAllocL(6));	//ReAlloc buffer
	test(KErrNone == ret);

#if defined(_DEBUG)
	__UHEAP_FAILNEXT(1);
	TRAP(ret, lStr.ReAllocL(100));	//Realloc buffer. This should fail.
	test(KErrNoMemory == ret);
#endif //(_DEBUG)

	test(lStr.MaxLength() >=6);		//Check LString is the same as before ... 
	test(lStr.Length()==2);			//... ReAlloc that failed.
	test(lStr[0] == (TTEXT)('0'));
	test(lStr[1] == (TTEXT)('1'));
}
Beispiel #22
0
LOCAL_C void TestCleanupStackL()
	{
	CDummyObserver* ob = new(ELeave)CDummyObserver;
	CleanupStack::PushL(ob);

	CMsvSession* session = CMsvSession::OpenSyncL(*ob);
	CleanupStack::PushL(session);

	CMsvEntry* cEntry = CMsvEntry::NewL(*session, KMsvDraftEntryId, TMsvSelectionOrdering());
	CleanupStack::PushL(cEntry);

	TMsvEntry entry;
	entry.iType = KUidMsvMessageEntry;
	entry.iMtm = KUidMsvLocalServiceMtm;
	entry.iServiceId = KMsvLocalServiceIndexEntryId;

	// Create an entry
	cEntry->CreateL(entry);

	// Make sure heap failure occurs in CleanupEntryPushL
	// If a failure occurs the entry should still be on cleanup stack
	__UHEAP_FAILNEXT(0);
	TRAPD(error, session->CleanupEntryPushL(entry.Id()); session->CleanupEntryPop(); );
int main()
{
	_LIT16(Kname,"tbuf16tochar");
	//int count = 2;
	bool err = false;
	__UHEAP_MARK;
	__UHEAP_FAILNEXT(2);
	while(!err)
	{
	int retval =ESuccess;
	char* myChar = new char[40];
	int size =40;

	retval = Tlitc16ToChar(Kname,myChar,size);
  
  if (retval ==EInsufficientSystemMemory)
    {

    	printf("tlit16tochar_reliability Passed\n");
    	err = true;
    	//Logging to some file can be done here
    }
  else
    {
			assert_failed = true;
			err = true;
    	printf("tlit16tochar_reliability Failed\n");
    	//Logging to some file can be done here
    }      
  delete[] myChar;
	}
	__UHEAP_MARKEND;
	__UHEAP_RESET;

  testResultXml("test_tlit16tochar_reliability");
	return 0;
}
int main()
{
	//int count = 1;
	bool err = false;
	wstring myWstring(L"Hello");
	__UHEAP_MARK;
	__UHEAP_FAILNEXT(1);
	while(!err)	
	{
	int retval =ESuccess;
  TBuf8<20> myTbuf;
	
	retval = WstringToTbuf8(myWstring,myTbuf);
	
  if (retval ==EInsufficientSystemMemory)

    {

    	printf("wstringtotbuf8_reliability Passed\n");
    	err = true;
    	//Logging to some file can be done here
    }

  else

    {
			assert_failed = true;
    	printf("wstringtotbuf8_reliability  Failed\n");
    	//Logging to some file can be done here
    }  
	}
	__UHEAP_MARKEND;
	__UHEAP_RESET;
    testResultXml("test_wstringtotbuf8_reliability");
	return 0;
}
Beispiel #25
0
/**
@SYMTestCaseID          SYSLIB-LOGENG-CT-1009
@SYMTestCaseDesc	    Tests for CLogEvent::NewL(),SetDataL() functions
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for creation of log event on heap and 
                        test for setting  event specific data from the specified stream and try to read the data back.
                        Check for memory errors
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void TestEventWithHeapFailL()
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1009 "));
#ifdef _DEBUG
	TInt failCount = 0;
#endif
	TInt error;
	TBool finished = EFalse;

	CLogEvent* event = NULL;

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event = CLogEvent::NewL());
		
		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			CleanupStack::PushL(event);
			}
		else
			TEST2(error, KErrNoMemory);
		}

	_LIT8(KDataTest1, "01234567890123456789");
	_LIT8(KDataTest2, "012345678901234567890123456789");

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(KDataTest1));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			TEST(event->Data() == KDataTest1);
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(KDataTest2));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			finished = ETrue;
			TEST(event->Data() == KDataTest2);
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif
	event->SetDataL(KNullDesC8);

	// Check we don't get any more failures
	__UHEAP_FAILNEXT(0);
	event->SetDataL(KDataTest2);
	TEST(event->Data() == KDataTest2);
	event->SetDataL(KDataTest1);
	TEST(event->Data() == KDataTest1);
	event->SetDataL(KNullDesC8);
	TEST(event->Data() == KNullDesC8);
	__UHEAP_RESET;

	// streaming
	TFileName storename = _L("c:\\T_BASIC_DATA");
	TUid uid={0x12345678};

	// create a store
	theFs.Delete(storename);
	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(theFs, storename, uid);
	
	RDictionaryWriteStream write;
	RDictionaryReadStream read;

	uid.iUid++;
	write.AssignL(*store, uid);
	write << KNullDesC8;
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);

#ifdef _DEBUG
	failCount = 0;
#endif
	finished = EFalse;

	__UHEAP_FAILNEXT(0);
	event->SetDataL(read, 0);
	__UHEAP_RESET;

	read.Close();	
	TEST(event->Data() == KNullDesC8);

	HBufC8* buf8 = TestUtils::CreateBuf8LC(100);

	uid.iUid++;
	write.AssignL(*store, uid);
	write.WriteL(buf8->Des());
	write.CommitL();
	write.Close();

	read.OpenL(*store, uid);

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event->SetDataL(read, 100));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			TEST(event->Data() == buf8->Des());
			read.Close();
			finished = ETrue;
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(event->Data() == KNullDesC8);
			}
		}

	event->SetId(0x12345678);
	event->SetEventType(TUid::Uid(0x12345678));

	HBufC* buf = TestUtils::CreateBufLC(KLogMaxRemotePartyLength / 2);
	event->SetRemoteParty(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxDirectionLength / 2);
	event->SetDirection(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	TTime time;

	time.UniversalTime();
	event->SetTime(time);
	TEST(event->Time() == time);

	event->SetDurationType(0xf);
	event->SetDuration(0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxStatusLength / 2);
	event->SetStatus(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxSubjectLength / 2);
	event->SetSubject(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	buf = TestUtils::CreateBufLC(KLogMaxNumberLength / 2);
	event->SetNumber(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event->SetContact(0x12345678);
	event->SetLink(0x12345678);

	buf = TestUtils::CreateBufLC(KLogMaxDescriptionLength / 2);
	event->SetDescription(buf->Des());
	CleanupStack::PopAndDestroy(); // buf

	event->SetFlags(0xA);

	buf8 = TestUtils::CreateBuf8LC(100);
	event->SetDataL(buf8->Des());
	TEST(event->Data() == buf8->Des());
	CleanupStack::PopAndDestroy(); // buf8

	CLogEvent* event1 = CLogEvent::NewL();
	CleanupStack::PushL(event1);

	CLogEvent* event2 = CLogEvent::NewL();
	CleanupStack::PushL(event2);

	TEST(TestUtils::EventsEqual(*event1, *event2));

	finished = EFalse;
#ifdef _DEBUG
	failCount = 0;
#endif

	while(!finished)
		{
		__UHEAP_FAILNEXT(failCount++);

		TRAP(error, event1->CopyL(*event));

		__UHEAP_RESET;

		if (error == KErrNone)
			{
			TEST(!TestUtils::EventsEqual(*event1, *event2));
			TEST(TestUtils::EventsEqual(*event1, *event));
			finished = ETrue;
			}
		else
			{
			TEST2(error, KErrNoMemory);
			TEST(TestUtils::EventsEqual(*event1, *event2));
			TEST(!TestUtils::EventsEqual(*event1, *event));
			}
		}

	CleanupStack::PopAndDestroy(5); // buf8, store, event, event1, event2
	::DeleteDataFile(storename);
	}
EXPORT_C void CTe_LbsNotifyPositionUpdateErrStep::ReallyDoTestStepImpL()
	{
	//SIMPLE POSITION UPDATE ERROR (Scenario 3.0)
	INFO_PRINTF1(_L("SIMPLE POSITION UPDATE ERROR (Scenario 3.0) START"));
	INFO_PRINTF1(_L("Create positioner and the position update object"));
		
	CTe_PsyPositioner* positioner = MakePositionerLC(); 
	CTe_PsyRequest* updateRequest = CTe_PsyRequest::NewLC(*this);
		
	INFO_PRINTF1(_L("Call NotifyPositionUpdate() PSY->ALM"));
	updateRequest->NotifyPsyRequest();
	positioner->NotifyPositionUpdate();
	StartSchedulerWaitL(KUsualTimeout, 1);
		
	updateRequest->ExpectDefaultUpdateRequest();
	updateRequest->UpdateRequest().NewClient() = ETrue;
	updateRequest->CheckPosUpdateOrReqReceivedL();
	
	INFO_PRINTF1(_L("Set a position update on the bus ALM->PSY"));
	CTe_PsyResponse* errUpdate = CTe_PsyResponse::IssueErrPosUpdateLC(KErrNoMemory,
			TPositionModuleInfo::ETechnologyTerminal);

	INFO_PRINTF2(_L("Start the active scheduler for %d microsec"), KUsualTimeout);
	StartSchedulerWaitL(KUsualTimeout, 1);
	INFO_PRINTF1(_L("The active scheduler stopped"));
	
	positioner->CheckPosUpdateFailedL(KErrNoMemory);
	CleanupStack::PopAndDestroy(errUpdate);
	
	INFO_PRINTF1(_L("SIMPLE POSITION UPDATE ERROR (Scenario 3.0) END"));
	
	__UHEAP_FAILNEXT(0);	
	TInt* marker = new TInt(0);
	delete marker;
		
	if(marker) //it is the urel OS version - skipping the memory leak tests
		{
		CleanupStack::PopAndDestroy(updateRequest);
		CleanupStack::PopAndDestroy(positioner);
		return;
		}
	
	//CPOSITIONER CREATION/DESTRUCTION WITH MEMORY LEAKS (Scenario 3.2)
	INFO_PRINTF1(_L("CPOSITIONER CREATION/DESTRUCTION WITH MEMORY LEAKS (Scenario 3.2) START"));	
	for(TInt i=1; marker; i++)
		{			
		INFO_PRINTF1(_L("Calling the MakePositionerLC"));
		__UHEAP_FAILNEXT(i);
		CTe_PsyPositioner* positioner = NULL;
		TRAPD(err, positioner = MakePositionerLC(); CleanupStack::PopAndDestroy(positioner));
		marker = new TInt(0);
		delete marker;
			
		if(marker) //Leave has happened inside the MakePositionerLC
			{
			INFO_PRINTF4(_L("Leave has happened inside the MakePositionerLC, i=%d err=%d positioner=0x%x"),
					i, err, positioner);
			if(err==KErrNone && !positioner)
				{
				User::Leave(EFail);
				}
			}
		else//Leave hasn't happened inside the MakePositionerLC - not interested
			{
			INFO_PRINTF2(_L("No leave has happened inside the MakePositionerLC - stop the test, i=%d"), i);
			break;
			}
		}
	INFO_PRINTF1(_L("CPOSITIONER CREATION/DESTRUCTION WITH MEMORY LEAKS (Scenario 3.2) END"));
	
	
	//SIMPLE POSITION UPDATE WITH OOM WHILE CALLING NotifyPositionUpdate (Scenario 3.3)
	INFO_PRINTF1(_L("SIMPLE POSITION UPDATE WITH OOM WHILE CALLING NotifyPositionUpdate (Scenario 3.3) START"));
	INFO_PRINTF1(_L("Create positioner and the position update object"));
	
	marker = new TInt(0);
	delete marker;
	for(TInt i=1; marker; i++)
		{
		INFO_PRINTF1(_L("Call NotifyPositionUpdate() PSY->ALM"));
		updateRequest->NotifyPsyRequest();
	
		__UHEAP_FAILNEXT(i);
		positioner->NotifyPositionUpdate();
		
		marker = new TInt(0);
		delete marker;
		
		StartSchedulerWaitL(KUsualTimeout, 1);
		
		if(!marker) //The leave has occured after the  NotifyPositionUpdate - not interested
			{
			break;
			}
		
		updateRequest->ExpectDefaultUpdateRequest();
		TRAPD(err, updateRequest->CheckPosUpdateOrReqReceivedL());
		if(err==KErrNone)
			{
			INFO_PRINTF1(_L("Set a position update on the bus ALM->PSY"));
			CTe_PsyResponse* simplePosUpdate = CTe_PsyResponse::IssueSimplePosUpdateLC(
					TPositionModuleInfo::ETechnologyTerminal);

			INFO_PRINTF2(_L("Start the active scheduler for %d microsec"), KUsualTimeout);
			StartSchedulerWaitL(KUsualTimeout, 1);
			INFO_PRINTF1(_L("The active scheduler stopped"));
			positioner->CheckPosUpdateReceivedL(*simplePosUpdate);
			CleanupStack::PopAndDestroy(simplePosUpdate);
			}
		else if(err==KErrNotFound)
			{
			INFO_PRINTF2(_L("Start the active scheduler for %d microsec"), KUsualTimeout);
			StartSchedulerWaitL(KLongTimeoutInterval, 1);
			INFO_PRINTF1(_L("The active scheduler stopped"));
			positioner->CheckPosUpdateFailedL(KErrTimedOut);			
			}
		else //the request is received in the wrong format or some unexpected leave
			{
			User::Leave(err);
			}
		}
	
	
	INFO_PRINTF1(_L("SIMPLE POSITION UPDATE WITH OOM WHILE CALLING NotifyPositionUpdate (Scenario 3.3) END"));
		

	CleanupStack::PopAndDestroy(updateRequest);
	CleanupStack::PopAndDestroy(positioner);		
	
	}
void CPigeonServerMtm::DoStartCommandL(CMsvEntrySelection& aSelection, TSchSendTestOperation aCommand, const TDesC8& aParameter, TRequestStatus& aStatus)
{

    if(iHeapFailure)
        __UHEAP_FAILNEXT(iNextFailure++);
    else
        __UHEAP_RESET;

    TMsvSchedulePackage package;
    package.iCommandId = ESendScheduledL;
    package.iParameter = aParameter;

    switch(aCommand)
    {
    case EOpFail:
    {
        TPckgC<TInt> pkg(0);
        pkg.Set(aParameter);
        User::Leave(pkg());
    }
    break;
    case EScheduleOpFail:
    {
        package.iCommandId = EOpFail;
        //pass through
    }
    case EScheduleAllL:
    {
        iScheduleSend->ScheduleL(aSelection, package);
        UpdateProgressL(aSelection);
    }
    break;
    case EReScheduleRetryAllL:
    {
        // Change the iCommandId to do a re-schedule
        package.iCommandId = EReScheduleRetryAllL;
        iScheduleSend->ReScheduleL(aSelection, package);
        UpdateProgressL(aSelection);

        // Bit of a hack here!! Check the selection to see if the messages
        // have been re-scheduled. If they have not been re-scheduled, then
        // copy to the Sent folder...
        for( TInt i=0; i<aSelection.Count(); ++i )
        {
            User::LeaveIfError(iServerEntry->SetEntry(aSelection[i]));
            TMsvEntry entry = iServerEntry->Entry();

            if( entry.SendingState() == KMsvSendStateWaiting )
            {
                User::LeaveIfError(iServerEntry->SetEntry(KMsvSentEntryId));
                User::LeaveIfError(iServerEntry->CreateEntry(entry));
            }
        }
        User::LeaveIfError(iServerEntry->SetEntry(KMsvNullIndexEntryId));
    }
    break;
    case EReScheduleAllL:
    {
        // Pass through action to be performed on reschedule. (Default is to do nothing.)
        TMsvSendErrorAction laterAction;
        laterAction.iAction = ESendActionRetryImmediately;
        laterAction.iRetries = ESendRetriesFixed;
        laterAction.iRetrySpacing = ESendRetrySpacingStatic;

        iScheduleSend->ReScheduleL(aSelection, package, &laterAction);
        UpdateProgressL(aSelection);
    }
    break;
    case EDeleteScheduleL:
    {
        iScheduleSend->DeleteScheduleL(aSelection);
    }
    break;
    case ESendScheduledL:
    {
        SendScheduledL(aSelection, aCommand, aParameter, aStatus);
    }
    break;
    case ECheckScheduleL:
    {
        iScheduleSend->CheckScheduleL(aSelection);
    }
    break;
    case ESetRetryImmediately:
    case ESetRetryLater:
    case ESetRetryVariable:
    case ESetNoRetry:
    {
        iScheduleSend->SetupL(aCommand);

        CRepository* repository = CRepository::NewLC(KUidMsgTypePigeon);
        iScheduleSend->SaveSysAgentActionsL(*repository);
        CleanupStack::PopAndDestroy(repository);
    }
    break;
    case ESetNowOffPeak:
    case ESetNowNotOffPeak:
    case ESetFirstOffPeakBest:
    case ESetLastOffPeakBest:
    {
        iScheduleSend->SetupL(aCommand);
    }
    break;
    case ESetIncrementalHeapFailure:
    {
        iHeapFailure = ETrue;
        // drop through
    }
    case EResetIncrementalHeapFailure:
    {
        iNextFailure = 0;
    }
    break;
    case ENoIncrementalHeapFailure:
    {
        iHeapFailure = EFalse;
        __UHEAP_RESET;
    }
    break;
    case EScheduleFailFirstSend:
    {
        SetFailFirstSendL(aSelection);

        iScheduleSend->ScheduleL(aSelection, package);
        UpdateProgressL(aSelection);
    }
    break;
    default:
        User::Panic(_L("pigeon server"), 1);
        break;
    }

    if(iHeapFailure)
    {
        __UHEAP_RESET;
    }

}
enum TVerdict CTestMemMMLists::doTestStepL()
	{
	iTestCount=1;
	TInt err = KErrNone;
	INFO_PRINTF1(_L(""));
	INFO_PRINTF1(_L("Test List classes coping with OOM"));

	CMobilePhoneBroadcastIdList *list = CMobilePhoneBroadcastIdList::NewL();
	CleanupStack::PushL(list);

	
	RMobileBroadcastMessaging::TMobileBroadcastIdEntryV1 entry;
	entry.iId = STATIC_CAST(TInt16,1);

	TInt failNext = 0;
	do
		{
		__UHEAP_FAILNEXT(++failNext);
		TRAP(err,list->AddEntryL(entry));
		} while (err != KErrNone);
	__UHEAP_RESET;

	INFO_PRINTF3(_L("Test %d - CMobilePhoneBroadcastIdList::AddEntryL OOM Test required %d allocations to succeed"),iTestCount++,failNext);
	CleanupStack::PopAndDestroy();

	list = CMobilePhoneBroadcastIdList::NewL();
	CleanupStack::PushL(list);

	failNext = 0;
	entry.iId = STATIC_CAST(TInt16,0);
	do
		{
		__UHEAP_FAILNEXT(++failNext);
		TRAP(err,list->InsertEntryL(0,entry));
		} while (err == KErrNoMemory);
	__UHEAP_RESET;
	
	INFO_PRINTF3(_L("Test %d - CMobilePhoneBroadcastIdList::InsertEntryL OOM Test required %d allocations to succeed"),iTestCount++,failNext);

	CleanupStack::PopAndDestroy();
	
	list = CMobilePhoneBroadcastIdList::NewL();
	CleanupStack::PushL(list);

	RMobileBroadcastMessaging::TMobileBroadcastIdEntryV1 start,end;

	start.iId = 0;
	end.iId = 49;

	failNext = 0;
	do
		{
		__UHEAP_FAILNEXT(++failNext);
		TRAP(err,list->AddRangeEntryL(start,end));
		} while (err == KErrNoMemory);
	__UHEAP_RESET;
	
	INFO_PRINTF3(_L("Test %d - CMobilePhoneBroadcastIdList::AddRangeEntryL OOM Test required %d allocations to succeed"),iTestCount++,failNext);

	CleanupStack::PopAndDestroy();
	INFO_PRINTF1(_L(""));

	return TestStepResult();
	}
/**
@SYMTestCaseID SYSLIB-LOGENG-CT-0126
@SYMTestCaseDesc Change the database configuration
@SYMTestPriority High
@SYMTestActions Low capability clients can't do this
@SYMTestExpectedResults Should always succeed
@SYMREQ REQ3431
*/
LOCAL_C void TestChangeConfigL(CLogClient& aClient)
	{
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-0126 "));
	CTestActive* active = new(ELeave)CTestActive();
	CleanupStack::PushL(active);

	TLogConfig configOld;

	active->StartL();
	aClient.GetConfig(configOld, active->iStatus);
	CActiveScheduler::Start();
	TEST2(active->iStatus.Int(), KErrNone);

	TLogConfig config;

#ifdef _DEBUG
	TInt failCount = 0;
#endif

	TBool finished = EFalse;
	TInt error;

	while(!finished)
		{
		error = KErrNone;

		config.iMaxLogSize = KTestMaxLogSize;
		config.iMaxRecentLogSize = KTestMaxRecentLogSize;
		config.iMaxEventAge = KTestMaxEventAge;

		__UHEAP_FAILNEXT(failCount++);
		aClient.ChangeConfig(config, active->iStatus);

		active->StartL();
		CActiveScheduler::Start();

		if (active->iStatus == KErrNone)
			finished = ETrue;
		else
			error = active->iStatus.Int();
		
		__UHEAP_RESET;

		if ((error == KErrNoMemory) || (error == KErrPermissionDenied))
			{
			active->StartL();
			aClient.GetConfig(config, active->iStatus);
			CActiveScheduler::Start();
			TEST2(active->iStatus.Int(), KErrNone);

			TEST(config.iMaxLogSize == configOld.iMaxLogSize);
			TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize);
			TEST(config.iMaxEventAge == configOld.iMaxEventAge);
			}
		else
			{
			TEST2(error, KErrNone);		
			}
			
		if(! TheHiCapability)
			finished = TRUE;
						
		}

	if(TheHiCapability)
		{
		TEST(config.iMaxLogSize == KTestMaxLogSize);
		TEST(config.iMaxRecentLogSize == KTestMaxRecentLogSize);
		TEST(config.iMaxEventAge == KTestMaxEventAge);
		}
	else
		{
		TEST(config.iMaxLogSize == configOld.iMaxLogSize);
		TEST(config.iMaxRecentLogSize == configOld.iMaxRecentLogSize);
		TEST(config.iMaxEventAge == configOld.iMaxEventAge);
		}
		
	CleanupStack::PopAndDestroy(); // active
	}
Beispiel #30
0
LOCAL_C void TestInitialCreationL()
	{
	CMsvServer* server;

	// non-existant directory
	CMsgsTestUtils::CleanMessageFolderL(KTestIndexFile);
	server=CMsvServer::NewL();
	PAUSE(100000);
	delete server;
	server=NULL;

	// only directory exists
	CMsgsTestUtils::CleanMessageFolderL(KTestIndexFile);
	theUtils->FileSession().MkDirAll(KTestIndexFile);
	server=CMsvServer::NewL();
	PAUSE(100000);
	delete server;
	server=NULL;

	// heap failure when constructing index
	CMsgsTestUtils::CleanMessageFolderL(KTestIndexFile);
	TInt failCount=0;
	TBool failed=ETrue;
	TUint at;
	TInt error;
	while (failed)
		{
		__UHEAP_FAILNEXT(failCount++);
		TRAP(error, server=CMsvServer::NewL());
		__UHEAP_RESET;
		PAUSE(100000);
		if (error)
			{
			TUint at;
			TInt error = theUtils->FileSession().Att(KTestIndexFile, at);
			test(error==KErrNotFound||error==KErrPathNotFound);
			}
		else
			failed=EFalse;
		delete server;
		server=NULL;
		}

	// file failure when constructing index
	CMsgsTestUtils::CleanMessageFolderL(KTestIndexFile);
	failCount=0;
	failed=ETrue;
	while (failed && failCount<3)  
		{
		theUtils->FileSession().SetErrorCondition(KErrGeneral, failCount++);
		TRAP(error, server=CMsvServer::NewL());
		theUtils->FileSession().SetErrorCondition(KErrGeneral, KMaxTInt);
		PAUSE(100000);
		if (error)
			{
			TInt error2 = theUtils->FileSession().Att(KTestIndexFile, at);
			test(error2==KErrNotFound||error2==KErrPathNotFound);
			}
		delete server;
		server=NULL;
		}

	// test missing index file but stores are still there
#if defined(_NDEBUG)
	CMsgsTestUtils::CleanMessageFolderL(KTestIndexFile);
	server=CMsvServer::NewL();
	PAUSE(100000);
	delete server;
	server=NULL;
	theUtils->FileSession().Delete(KTestIndexFile);
	server=CMsvServer::NewL();
	delete server;
	server=NULL;
#endif
	}