dbmalloc1.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /***********************************************************************
  6. **
  7. ** Name: dbmalloc1.c (OBSOLETE)
  8. **
  9. ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
  10. **
  11. ** Modification History:
  12. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  13. ** The debug mode will print all of the printfs associated with this test.
  14. ** The regress mode will be the default mode. Since the regress tool limits
  15. ** the output to a one line status:PASS or FAIL,all of the printf statements
  16. ** have been handled with an if (debug_mode) statement.
  17. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
  18. ** recognize the return code from tha main program.
  19. **
  20. ** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
  21. ***********************************************************************/
  22. /***********************************************************************
  23. ** Includes
  24. ***********************************************************************/
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "nspr.h"
  28. PRIntn failed_already=0;
  29. PRIntn debug_mode;
  30. /* variable used for both r1 and r2 tests */
  31. int should_fail =0;
  32. int actually_failed=0;
  33. void
  34. r1
  35. (
  36. void
  37. )
  38. {
  39. int i;
  40. actually_failed=0;
  41. for( i = 0; i < 5; i++ )
  42. {
  43. void *x = PR_MALLOC(128);
  44. if( (void *)0 == x ) {
  45. if (debug_mode) {
  46. printf("\tMalloc %d failed.\n", i+1);
  47. }
  48. actually_failed = 1;
  49. }
  50. PR_DELETE(x);
  51. }
  52. if (((should_fail != actually_failed) & (!debug_mode))) {
  53. failed_already=1;
  54. }
  55. return;
  56. }
  57. void
  58. r2
  59. (
  60. void
  61. )
  62. {
  63. int i;
  64. for( i = 0; i <= 5; i++ )
  65. {
  66. should_fail =0;
  67. if( 0 == i ) {
  68. if (debug_mode) {
  69. printf("No malloc should fail:\n");
  70. }
  71. }
  72. else {
  73. if (debug_mode) {
  74. printf("Malloc %d should fail:\n", i);
  75. }
  76. should_fail = 1;
  77. }
  78. PR_SetMallocCountdown(i);
  79. r1();
  80. PR_ClearMallocCountdown();
  81. }
  82. }
  83. int main(int argc, char **argv)
  84. {
  85. /* main test */
  86. PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  87. PR_STDIO_INIT();
  88. r2();
  89. if(failed_already) {
  90. return 1;
  91. }
  92. else {
  93. return 0;
  94. }
  95. }