michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /*********************************************************************** michael@0: ** michael@0: ** Name: dbmalloc1.c (OBSOLETE) michael@0: ** michael@0: ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions. michael@0: ** michael@0: ** Modification History: michael@0: ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag. michael@0: ** The debug mode will print all of the printfs associated with this test. michael@0: ** The regress mode will be the default mode. Since the regress tool limits michael@0: ** the output to a one line status:PASS or FAIL,all of the printf statements michael@0: ** have been handled with an if (debug_mode) statement. michael@0: ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to michael@0: ** recognize the return code from tha main program. michael@0: ** michael@0: ** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete). michael@0: ***********************************************************************/ michael@0: michael@0: michael@0: /*********************************************************************** michael@0: ** Includes michael@0: ***********************************************************************/ michael@0: #include michael@0: #include michael@0: #include "nspr.h" michael@0: michael@0: PRIntn failed_already=0; michael@0: PRIntn debug_mode; michael@0: michael@0: /* variable used for both r1 and r2 tests */ michael@0: int should_fail =0; michael@0: int actually_failed=0; michael@0: michael@0: michael@0: void michael@0: r1 michael@0: ( michael@0: void michael@0: ) michael@0: { michael@0: int i; michael@0: actually_failed=0; michael@0: for( i = 0; i < 5; i++ ) michael@0: { michael@0: void *x = PR_MALLOC(128); michael@0: if( (void *)0 == x ) { michael@0: if (debug_mode) printf("\tMalloc %d failed.\n", i+1); michael@0: actually_failed = 1; michael@0: } michael@0: PR_DELETE(x); michael@0: } michael@0: michael@0: if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1; michael@0: michael@0: michael@0: return; michael@0: } michael@0: michael@0: void michael@0: r2 michael@0: ( michael@0: void michael@0: ) michael@0: { michael@0: int i; michael@0: michael@0: for( i = 0; i <= 5; i++ ) michael@0: { michael@0: should_fail =0; michael@0: if( 0 == i ) { michael@0: if (debug_mode) printf("No malloc should fail:\n"); michael@0: } michael@0: else { michael@0: if (debug_mode) printf("Malloc %d should fail:\n", i); michael@0: should_fail = 1; michael@0: } michael@0: PR_SetMallocCountdown(i); michael@0: r1(); michael@0: PR_ClearMallocCountdown(); michael@0: } michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: michael@0: /* main test */ michael@0: michael@0: PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); michael@0: PR_STDIO_INIT(); michael@0: r2(); michael@0: michael@0: if(failed_already) michael@0: return 1; michael@0: else michael@0: return 0; michael@0: michael@0: michael@0: } michael@0: