home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / dbmalloc1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.0 KB  |  123 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /***********************************************************************
  20. **
  21. ** Name: dbmalloc1.c (OBSOLETE)
  22. **
  23. ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
  24. **
  25. ** Modification History:
  26. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  27. **             The debug mode will print all of the printfs associated with this test.
  28. **             The regress mode will be the default mode. Since the regress tool limits
  29. **           the output to a one line status:PASS or FAIL,all of the printf statements
  30. **             have been handled with an if (debug_mode) statement.
  31. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
  32. **            recognize the return code from tha main program.
  33. **
  34. ** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
  35. ***********************************************************************/
  36.  
  37.  
  38. /***********************************************************************
  39. ** Includes
  40. ***********************************************************************/
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include "nspr.h"
  44.  
  45. PRIntn failed_already=0;
  46. PRIntn debug_mode;
  47.  
  48. /* variable used for both r1 and r2 tests */
  49. int should_fail =0;
  50. int actually_failed=0;
  51.  
  52.  
  53. void
  54. r1
  55. (
  56.     void
  57. )
  58. {
  59.     int i;
  60.     actually_failed=0;
  61.     for(  i = 0; i < 5; i++ )
  62.     {
  63.         void *x = PR_MALLOC(128);
  64.         if( (void *)0 == x ) {
  65.             if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
  66.             actually_failed = 1;
  67.         }
  68.         PR_DELETE(x);
  69.     }
  70.  
  71.     if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
  72.  
  73.  
  74.     return;
  75. }
  76.  
  77. void
  78. r2
  79. (
  80.     void
  81. )
  82. {
  83.     int i;
  84.  
  85.     for( i = 0; i <= 5; i++ )
  86.     {
  87.         should_fail =0;
  88.         if( 0 == i ) {
  89.             if (debug_mode) printf("No malloc should fail:\n");
  90.         }
  91.         else {
  92.             if (debug_mode) printf("Malloc %d should fail:\n", i);
  93.             should_fail = 1;
  94.         }
  95.         PR_SetMallocCountdown(i);
  96.         r1();
  97.         PR_ClearMallocCountdown();
  98.     }
  99. }
  100.  
  101. int
  102. main
  103. (
  104.     int     argc,
  105.     char   *argv[]
  106. )
  107. {
  108.  
  109.  /* main test */
  110.     
  111.     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  112.     PR_STDIO_INIT();
  113.     r2();
  114.  
  115.     if(failed_already)    
  116.         return 1;
  117.     else
  118.         return 0;
  119.  
  120.     
  121. }
  122.  
  123.