sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <e32cons.h>
sl@0: #include <e32test.h>
sl@0: 
sl@0: 
sl@0: LOCAL_D RTest test(_L("T_UCRT0P1"));
sl@0: LOCAL_D RProcess me;
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID 			SYSLIB-STDLIB-UT-1669
sl@0: @SYMTestCaseDesc	    Testing whether increasing KMaxArgC from 20 to 25 results in the extra arguments
sl@0: 						passed in to a new process to be handled correctly.
sl@0: @SYMTestPriority 	    High
sl@0: @SYMTestActions  	    Starts a new process (T_UCRT0P2) passing in a set of arguments and this new process
sl@0: 						checks all the arguements were handled correctly.
sl@0: @SYMTestExpectedResults The test should not fail.
sl@0: @SYMDEF 				DEF074278
sl@0: */
sl@0: void Defect_DEF074278()
sl@0: 	{
sl@0: 	test.Next(_L(" @SYMTestCaseID:SYSLIB-STDLIB-UT-1669 - Defect_DEF074278... "));
sl@0: 	
sl@0: 	TBuf<180> arguments(_L("one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four "));
sl@0: 
sl@0: 	test.Printf(_L("Create a new process passing in a large number of arguements\n"));
sl@0: 	//Creating another process to run T_UCRT0P2 passing in 24 arguments (25th will be the
sl@0: 	//path and name of the exe). T_UCRT0P2 should only be run via this test and not on it's own.
sl@0: 	TInt err=me.Create(_L("T_UCRT0P2"),arguments);
sl@0: 	if (err==KErrNotFound)
sl@0: 		err=me.Create(_L("z:\\test\\T_UCRT0P2"),arguments);
sl@0:     if (err==KErrNotFound)
sl@0:         err=me.Create(_L("c:\\test\\T_UCRT0P2"),arguments);
sl@0:     if (err==KErrNotFound)
sl@0:         err=me.Create(_L("z:\\sys\\bin\\T_UCRT0P2"),arguments);
sl@0: 	test(err==KErrNone);
sl@0: 
sl@0: 	//Checking that the child proces T_UCRT0P2 executes properly with no panic
sl@0: 	TRequestStatus status;
sl@0: 	me.Logon(status);
sl@0: 	me.Resume();
sl@0: 	User::WaitForRequest(status);
sl@0: 	//Test to make sure the child process ended correctly
sl@0: 	test(status==KErrNone);
sl@0: 	test(me.ExitReason()==KErrNone);
sl@0: 	me.Close();
sl@0: 	}
sl@0: 
sl@0: 
sl@0: /**
sl@0: @SYMTestCaseID           SYSLIB-STDLIB-UT-4003
sl@0: @SYMTestCaseDesc	     When there are heap memory allocation failures in __crt0, any locally allocated
sl@0:                          heap memory should be cleaned up before the pointers go out of scope, preventing a memory leak.
sl@0: @SYMTestPriority         Medium
sl@0: @SYMTestActions  	     Start new process (T_UCRT0P3) passing arguments. Set heap allocation to fail at certain
sl@0:                          points in __crt0. Clean up any locally allocated before routine returns. Check pointers
sl@0:                          are set to NULL and there are no memory leaks. 
sl@0: @SYMTestExpectedResults  No memory is leaked and pointer are NULL.
sl@0: @SYMDEF                  DEF124477
sl@0: */
sl@0: void Defect_DEF124477()
sl@0: 	{
sl@0: 	test.Next(_L("@SYMTestCaseID:SYSLIB-STDLIB-UT-4003 - Defect_DEF124477..."));
sl@0: 	
sl@0: 	TBuf<20> arguments(_L("random arguements"));
sl@0: 
sl@0: 	test.Printf(_L("Create a new process passing in the arguements\n"));
sl@0: 	//Creating another process to run T_UCRT0P3 passing in the arguments. 
sl@0: 	// T_UCRT0P3 should only be run via this test and not on it's own.
sl@0: 	TInt err=me.Create(_L("T_UCRT0P3"),arguments);
sl@0: 	if (err==KErrNotFound)
sl@0: 		err=me.Create(_L("z:\\test\\T_UCRT0P3"),arguments);
sl@0: 	test(err==KErrNone);
sl@0: 
sl@0: 	//Checking that the child proces T_UCRT0P3 executes properly with no panic
sl@0: 	TRequestStatus status;
sl@0: 	me.Logon(status);
sl@0: 	me.Resume();
sl@0: 	User::WaitForRequest(status);
sl@0: 	//Test to make sure the child process ended correctly
sl@0: 	test(status==KErrNone);
sl@0: 	test(me.ExitReason()==KErrNone);
sl@0: 	me.Close();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: Invoke the tests
sl@0: */
sl@0: LOCAL_C void RunTestsL()
sl@0:     {
sl@0: 	Defect_DEF074278();
sl@0: 	#ifdef _DEBUG	
sl@0: 		Defect_DEF124477();  // OOM related test.
sl@0: 	#endif
sl@0: 	}
sl@0: 
sl@0: 
sl@0: GLDEF_C TInt E32Main()
sl@0:     {
sl@0: 	test.Title();
sl@0: 	test.Start(_L(" Running T_UCRT0P1 tests..."));
sl@0: 	__UHEAP_MARK;
sl@0: 	CTrapCleanup* cleanup=CTrapCleanup::New();
sl@0: 	test(cleanup != NULL);
sl@0: 	TRAPD(error,RunTestsL());
sl@0: 	test(error==KErrNone);
sl@0: 	test.End();
sl@0: 	test.Close();
sl@0: 	delete cleanup;
sl@0: 	__UHEAP_MARKEND;
sl@0: 	return 0;
sl@0:     }
sl@0: