nsprpub/pr/tests/dbmalloc1.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/tests/dbmalloc1.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/***********************************************************************
    1.10 +**
    1.11 +** Name: dbmalloc1.c (OBSOLETE)
    1.12 +**
    1.13 +** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
    1.14 +**
    1.15 +** Modification History:
    1.16 +** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
    1.17 +**	         The debug mode will print all of the printfs associated with this test.
    1.18 +**			 The regress mode will be the default mode. Since the regress tool limits
    1.19 +**           the output to a one line status:PASS or FAIL,all of the printf statements
    1.20 +**			 have been handled with an if (debug_mode) statement.
    1.21 +** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
    1.22 +**			recognize the return code from tha main program.
    1.23 +**
    1.24 +** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
    1.25 +***********************************************************************/
    1.26 +
    1.27 +
    1.28 +/***********************************************************************
    1.29 +** Includes
    1.30 +***********************************************************************/
    1.31 +#include <stdio.h>
    1.32 +#include <stdlib.h>
    1.33 +#include "nspr.h"
    1.34 +
    1.35 +PRIntn failed_already=0;
    1.36 +PRIntn debug_mode;
    1.37 +
    1.38 +/* variable used for both r1 and r2 tests */
    1.39 +int should_fail =0;
    1.40 +int actually_failed=0;
    1.41 +
    1.42 +
    1.43 +void
    1.44 +r1
    1.45 +(
    1.46 +    void
    1.47 +)
    1.48 +{
    1.49 +    int i;
    1.50 +	actually_failed=0;
    1.51 +    for(  i = 0; i < 5; i++ )
    1.52 +    {
    1.53 +        void *x = PR_MALLOC(128);
    1.54 +        if( (void *)0 == x ) {
    1.55 +			if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
    1.56 +			actually_failed = 1;
    1.57 +		}
    1.58 +        PR_DELETE(x);
    1.59 +    }
    1.60 +
    1.61 +	if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
    1.62 +
    1.63 +
    1.64 +    return;
    1.65 +}
    1.66 +
    1.67 +void
    1.68 +r2
    1.69 +(
    1.70 +    void
    1.71 +)
    1.72 +{
    1.73 +    int i;
    1.74 +
    1.75 +    for( i = 0; i <= 5; i++ )
    1.76 +    {
    1.77 +		should_fail =0;
    1.78 +        if( 0 == i ) {
    1.79 +			if (debug_mode) printf("No malloc should fail:\n");
    1.80 +		}
    1.81 +        else {
    1.82 +			if (debug_mode) printf("Malloc %d should fail:\n", i);
    1.83 +			should_fail = 1;
    1.84 +		}
    1.85 +        PR_SetMallocCountdown(i);
    1.86 +        r1();
    1.87 +        PR_ClearMallocCountdown();
    1.88 +    }
    1.89 +}
    1.90 +
    1.91 +int main(int argc, char **argv)
    1.92 +{
    1.93 +
    1.94 + /* main test */
    1.95 +	
    1.96 +    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
    1.97 +    PR_STDIO_INIT();
    1.98 +    r2();
    1.99 +
   1.100 +    if(failed_already)    
   1.101 +        return 1;
   1.102 +    else
   1.103 +        return 0;
   1.104 +
   1.105 +    
   1.106 +}
   1.107 +

mercurial