sl@0: // Copyright (c) 2008-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: // *IMPORTANT*: This should only be run when called from T_UCRT0P1. sl@0: // See TestCase SYSLIB-STDLIB-UT-4003 in T_UCRT0P1.CPP for more information. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: RTest TheTest(_L("T_UCRT0P3")); sl@0: sl@0: sl@0: //Test macros and functions sl@0: LOCAL_C void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: sl@0: LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: sl@0: sl@0: //DEF124477: [coverity] RESOURCE_LEAK - stdlib. sl@0: void Defect_DEF124477_Part2() sl@0: { sl@0: int argc=0; sl@0: char** char_argv=0; sl@0: char** char_envp=0; sl@0: sl@0: TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n")); sl@0: sl@0: // Set heap memory allocation failure for 'char_argv'. sl@0: TheTest.Printf(_L("Set RHeap::EFailNext on the 4th memory allocation event.\n")); sl@0: __UHEAP_SETFAIL(RHeap::EFailNext, 4); sl@0: sl@0: TheTest.Printf(_L("Try to get args and environment.\n")); sl@0: __crt0(argc,char_argv,char_envp); // get args & environment from somewhere sl@0: sl@0: // Memory allocation failure should result in the following variables being NULL. sl@0: TheTest.Printf(_L("Check argc is NULL.\n")); sl@0: TEST(argc==0); sl@0: TheTest.Printf(_L("Check char_argv is NULL.\n")); sl@0: TEST(char_argv==0); sl@0: TheTest.Printf(_L("Check char_envp is NULL.\n")); sl@0: TEST(char_envp==0); sl@0: sl@0: sl@0: //Reset values. sl@0: argc=0; sl@0: char_argv=0; sl@0: char_envp=0; sl@0: sl@0: // Set heap memory allocation failure for 'cmdbuf' in __crt0 to fail, resulting in routine sl@0: // returning early, so 'char_argc' and 'char_envp' should still be NULL. sl@0: TheTest.Printf(_L("Set RHeap::EFailNext on the 1st memory allocation event.\n")); sl@0: __UHEAP_SETFAIL(RHeap::EFailNext, 1); sl@0: sl@0: TheTest.Printf(_L("Try to get args and environment.\n")); sl@0: __crt0(argc,char_argv,char_envp); // get args & environment from somewhere sl@0: sl@0: // Memory allocation failure should result in the following variables being NULL. sl@0: TheTest.Printf(_L("Check argc is NULL.\n")); sl@0: TEST(argc==0); sl@0: TheTest.Printf(_L("Check char_envp is NULL.\n")); sl@0: TEST(char_envp==0); sl@0: sl@0: sl@0: wchar_t** wchar_t_argv=0; sl@0: wchar_t** wchar_t_envp=0; sl@0: sl@0: TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n")); sl@0: sl@0: // Will set the memory allocation for wargv in __crt0 to fail. sl@0: TheTest.Printf(_L("Set RHeap::EFailNext on the 3rd memory allocation event.\n")); sl@0: __UHEAP_SETFAIL(RHeap::EFailNext, 3); sl@0: sl@0: TheTest.Printf(_L("Now try to get args and environment.\n")); sl@0: __crt0(argc,wchar_t_argv,wchar_t_envp); // get args & environment from somewhere sl@0: sl@0: // The arguements passed into __crt0 should still be NULL. sl@0: TheTest.Printf(_L("Check argc is NULL.\n")); sl@0: TEST(argc==0); sl@0: TheTest.Printf(_L("Check wchar_t_argv is NULL.\n")); sl@0: TEST(wchar_t_argv==0); sl@0: TheTest.Printf(_L("Check wchar_t_envp is NULL.\n")); sl@0: TEST(wchar_t_envp==0); sl@0: sl@0: exit(0); sl@0: } sl@0: sl@0: /** sl@0: Invoke the tests sl@0: */ sl@0: LOCAL_C void RunTestsL () sl@0: { sl@0: Defect_DEF124477_Part2(); sl@0: } sl@0: sl@0: /** sl@0: /This should only be called from T_UCRT0P1, as it is part of the same test. sl@0: */ sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TheTest(tc != NULL); sl@0: __UHEAP_MARK; sl@0: sl@0: TheTest.Title(); sl@0: TheTest.Printf(_L("** Starting the tests in the child process T_UCRT0P3 ...\n")); sl@0: TheTest.Start(_L(" @SYMTestCaseID: ")); sl@0: TRAPD(error,RunTestsL()); sl@0: TEST2(error,KErrNone); sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: __UHEAP_MARKEND; sl@0: delete tc; sl@0: return 0; sl@0: } sl@0: