os/ossrv/genericopenlibs/cstdlib/TSTLIB/T_UCRT0P3.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// *IMPORTANT*: This should only be run when called from T_UCRT0P1.
sl@0
    15
// See TestCase SYSLIB-STDLIB-UT-4003 in T_UCRT0P1.CPP for more information.
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <stdlib.h>
sl@0
    20
#include <e32debug.h>
sl@0
    21
#include <e32test.h>
sl@0
    22
#include <estlib.h>
sl@0
    23
sl@0
    24
sl@0
    25
RTest TheTest(_L("T_UCRT0P3"));
sl@0
    26
sl@0
    27
sl@0
    28
//Test macros and functions
sl@0
    29
LOCAL_C void Check(TInt aValue, TInt aLine)
sl@0
    30
	{
sl@0
    31
	if(!aValue)
sl@0
    32
		TheTest(EFalse, aLine);
sl@0
    33
	}
sl@0
    34
sl@0
    35
LOCAL_C void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    36
	{
sl@0
    37
	if(aValue != aExpected)
sl@0
    38
		{
sl@0
    39
		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    40
		TheTest(EFalse, aLine);
sl@0
    41
		}
sl@0
    42
	}
sl@0
    43
sl@0
    44
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    45
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
    46
sl@0
    47
sl@0
    48
sl@0
    49
//DEF124477: [coverity] RESOURCE_LEAK - stdlib.
sl@0
    50
void Defect_DEF124477_Part2()
sl@0
    51
	{
sl@0
    52
	int argc=0;
sl@0
    53
	char** char_argv=0;
sl@0
    54
	char** char_envp=0;
sl@0
    55
sl@0
    56
	TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n"));
sl@0
    57
	
sl@0
    58
	// Set heap memory allocation failure for 'char_argv'.
sl@0
    59
	TheTest.Printf(_L("Set RHeap::EFailNext on the 4th memory allocation event.\n"));
sl@0
    60
	__UHEAP_SETFAIL(RHeap::EFailNext, 4);
sl@0
    61
sl@0
    62
	TheTest.Printf(_L("Try to get args and environment.\n"));
sl@0
    63
	__crt0(argc,char_argv,char_envp);			// get args & environment from somewhere
sl@0
    64
	
sl@0
    65
	// Memory allocation failure should result in the following variables being NULL.
sl@0
    66
	TheTest.Printf(_L("Check argc is NULL.\n"));
sl@0
    67
	TEST(argc==0);
sl@0
    68
	TheTest.Printf(_L("Check char_argv is NULL.\n"));
sl@0
    69
	TEST(char_argv==0);
sl@0
    70
	TheTest.Printf(_L("Check char_envp is NULL.\n"));
sl@0
    71
	TEST(char_envp==0);
sl@0
    72
sl@0
    73
sl@0
    74
	//Reset values.
sl@0
    75
	argc=0;
sl@0
    76
	char_argv=0;
sl@0
    77
	char_envp=0;
sl@0
    78
	
sl@0
    79
	// Set heap memory allocation failure for 'cmdbuf' in __crt0 to fail, resulting in routine
sl@0
    80
	// returning early, so 'char_argc' and 'char_envp' should still be NULL.
sl@0
    81
	TheTest.Printf(_L("Set RHeap::EFailNext on the 1st memory allocation event.\n"));
sl@0
    82
	__UHEAP_SETFAIL(RHeap::EFailNext, 1);
sl@0
    83
sl@0
    84
	TheTest.Printf(_L("Try to get args and environment.\n"));
sl@0
    85
	__crt0(argc,char_argv,char_envp);			// get args & environment from somewhere
sl@0
    86
	
sl@0
    87
	// Memory allocation failure should result in the following variables being NULL.
sl@0
    88
	TheTest.Printf(_L("Check argc is NULL.\n"));
sl@0
    89
	TEST(argc==0);
sl@0
    90
	TheTest.Printf(_L("Check char_envp is NULL.\n"));
sl@0
    91
	TEST(char_envp==0);
sl@0
    92
sl@0
    93
sl@0
    94
	wchar_t** wchar_t_argv=0;
sl@0
    95
	wchar_t** wchar_t_envp=0;
sl@0
    96
	
sl@0
    97
	TheTest.Printf(_L("Retrieving the arguments passed in from T_UCRT0P1\n"));
sl@0
    98
	
sl@0
    99
	// Will set the memory allocation for wargv in __crt0 to fail.
sl@0
   100
	TheTest.Printf(_L("Set RHeap::EFailNext on the 3rd memory allocation event.\n"));
sl@0
   101
	__UHEAP_SETFAIL(RHeap::EFailNext, 3);
sl@0
   102
sl@0
   103
	TheTest.Printf(_L("Now try to get args and environment.\n"));
sl@0
   104
	__crt0(argc,wchar_t_argv,wchar_t_envp);			// get args & environment from somewhere
sl@0
   105
	
sl@0
   106
	// The arguements passed into __crt0 should still be NULL.
sl@0
   107
	TheTest.Printf(_L("Check argc is NULL.\n"));
sl@0
   108
	TEST(argc==0);
sl@0
   109
	TheTest.Printf(_L("Check wchar_t_argv is NULL.\n"));
sl@0
   110
	TEST(wchar_t_argv==0);
sl@0
   111
	TheTest.Printf(_L("Check wchar_t_envp is NULL.\n"));
sl@0
   112
	TEST(wchar_t_envp==0);
sl@0
   113
	
sl@0
   114
	exit(0);
sl@0
   115
	}
sl@0
   116
sl@0
   117
/**
sl@0
   118
Invoke the tests
sl@0
   119
*/
sl@0
   120
LOCAL_C void RunTestsL ()
sl@0
   121
    {
sl@0
   122
	Defect_DEF124477_Part2();
sl@0
   123
	}
sl@0
   124
sl@0
   125
/**
sl@0
   126
/This should only be called from T_UCRT0P1, as it is part of the same test.
sl@0
   127
*/
sl@0
   128
GLDEF_C TInt E32Main()
sl@0
   129
	{
sl@0
   130
	CTrapCleanup* tc = CTrapCleanup::New();
sl@0
   131
	TheTest(tc != NULL);
sl@0
   132
	__UHEAP_MARK;
sl@0
   133
sl@0
   134
	TheTest.Title();
sl@0
   135
	TheTest.Printf(_L("** Starting the tests in the child process T_UCRT0P3 ...\n"));
sl@0
   136
	TheTest.Start(_L(" @SYMTestCaseID: "));
sl@0
   137
	TRAPD(error,RunTestsL());
sl@0
   138
	TEST2(error,KErrNone);
sl@0
   139
sl@0
   140
	TheTest.End();
sl@0
   141
	TheTest.Close();
sl@0
   142
	__UHEAP_MARKEND;
sl@0
   143
	delete tc;
sl@0
   144
	return 0;
sl@0
   145
	}
sl@0
   146