1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/T_UCRT0P3.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,146 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// *IMPORTANT*: This should only be run when called from T_UCRT0P1.
1.18 +// See TestCase SYSLIB-STDLIB-UT-4003 in T_UCRT0P1.CPP for more information.
1.19 +//
1.20 +//
1.21 +
1.22 +#include <stdlib.h>
1.23 +#include <e32debug.h>
1.24 +#include <e32test.h>
1.25 +#include <estlib.h>
1.26 +
1.27 +
1.28 +RTest TheTest(_L("T_UCRT0P3"));
1.29 +
1.30 +
1.31 +//Test macros and functions
1.32 +LOCAL_C void Check(TInt aValue, TInt aLine)
1.33 + {
1.34 + if(!aValue)
1.35 + TheTest(EFalse, aLine);
1.36 + }
1.37 +
1.38 +LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
1.39 + {
1.40 + if(aValue != aExpected)
1.41 + {
1.42 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.43 + TheTest(EFalse, aLine);
1.44 + }
1.45 + }
1.46 +
1.47 +#define TEST(arg) ::Check((arg), __LINE__)
1.48 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.49 +
1.50 +
1.51 +
1.52 +//DEF124477: [coverity] RESOURCE_LEAK - stdlib.
1.53 +void Defect_DEF124477_Part2()
1.54 + {
1.55 + int argc=0;
1.56 + char** char_argv=0;
1.57 + char** char_envp=0;
1.58 +
1.59 + TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n"));
1.60 +
1.61 + // Set heap memory allocation failure for 'char_argv'.
1.62 + TheTest.Printf(_L("Set RHeap::EFailNext on the 4th memory allocation event.\n"));
1.63 + __UHEAP_SETFAIL(RHeap::EFailNext, 4);
1.64 +
1.65 + TheTest.Printf(_L("Try to get args and environment.\n"));
1.66 + __crt0(argc,char_argv,char_envp); // get args & environment from somewhere
1.67 +
1.68 + // Memory allocation failure should result in the following variables being NULL.
1.69 + TheTest.Printf(_L("Check argc is NULL.\n"));
1.70 + TEST(argc==0);
1.71 + TheTest.Printf(_L("Check char_argv is NULL.\n"));
1.72 + TEST(char_argv==0);
1.73 + TheTest.Printf(_L("Check char_envp is NULL.\n"));
1.74 + TEST(char_envp==0);
1.75 +
1.76 +
1.77 + //Reset values.
1.78 + argc=0;
1.79 + char_argv=0;
1.80 + char_envp=0;
1.81 +
1.82 + // Set heap memory allocation failure for 'cmdbuf' in __crt0 to fail, resulting in routine
1.83 + // returning early, so 'char_argc' and 'char_envp' should still be NULL.
1.84 + TheTest.Printf(_L("Set RHeap::EFailNext on the 1st memory allocation event.\n"));
1.85 + __UHEAP_SETFAIL(RHeap::EFailNext, 1);
1.86 +
1.87 + TheTest.Printf(_L("Try to get args and environment.\n"));
1.88 + __crt0(argc,char_argv,char_envp); // get args & environment from somewhere
1.89 +
1.90 + // Memory allocation failure should result in the following variables being NULL.
1.91 + TheTest.Printf(_L("Check argc is NULL.\n"));
1.92 + TEST(argc==0);
1.93 + TheTest.Printf(_L("Check char_envp is NULL.\n"));
1.94 + TEST(char_envp==0);
1.95 +
1.96 +
1.97 + wchar_t** wchar_t_argv=0;
1.98 + wchar_t** wchar_t_envp=0;
1.99 +
1.100 + TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n"));
1.101 +
1.102 + // Will set the memory allocation for wargv in __crt0 to fail.
1.103 + TheTest.Printf(_L("Set RHeap::EFailNext on the 3rd memory allocation event.\n"));
1.104 + __UHEAP_SETFAIL(RHeap::EFailNext, 3);
1.105 +
1.106 + TheTest.Printf(_L("Now try to get args and environment.\n"));
1.107 + __crt0(argc,wchar_t_argv,wchar_t_envp); // get args & environment from somewhere
1.108 +
1.109 + // The arguements passed into __crt0 should still be NULL.
1.110 + TheTest.Printf(_L("Check argc is NULL.\n"));
1.111 + TEST(argc==0);
1.112 + TheTest.Printf(_L("Check wchar_t_argv is NULL.\n"));
1.113 + TEST(wchar_t_argv==0);
1.114 + TheTest.Printf(_L("Check wchar_t_envp is NULL.\n"));
1.115 + TEST(wchar_t_envp==0);
1.116 +
1.117 + exit(0);
1.118 + }
1.119 +
1.120 +/**
1.121 +Invoke the tests
1.122 +*/
1.123 +LOCAL_C void RunTestsL ()
1.124 + {
1.125 + Defect_DEF124477_Part2();
1.126 + }
1.127 +
1.128 +/**
1.129 +/This should only be called from T_UCRT0P1, as it is part of the same test.
1.130 +*/
1.131 +GLDEF_C TInt E32Main()
1.132 + {
1.133 + CTrapCleanup* tc = CTrapCleanup::New();
1.134 + TheTest(tc != NULL);
1.135 + __UHEAP_MARK;
1.136 +
1.137 + TheTest.Title();
1.138 + TheTest.Printf(_L("** Starting the tests in the child process T_UCRT0P3 ...\n"));
1.139 + TheTest.Start(_L(" @SYMTestCaseID: "));
1.140 + TRAPD(error,RunTestsL());
1.141 + TEST2(error,KErrNone);
1.142 +
1.143 + TheTest.End();
1.144 + TheTest.Close();
1.145 + __UHEAP_MARKEND;
1.146 + delete tc;
1.147 + return 0;
1.148 + }
1.149 +