4069afd3177fc413f98e773cb4a7ee1926caad88
[platform/upstream/nspr.git] / nspr / pr / tests / dbmalloc1.c
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 **
8 ** Name: dbmalloc1.c (OBSOLETE)
9 **
10 ** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
11 **
12 ** Modification History:
13 ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
14 **               The debug mode will print all of the printfs associated with this test.
15 **                       The regress mode will be the default mode. Since the regress tool limits
16 **           the output to a one line status:PASS or FAIL,all of the printf statements
17 **                       have been handled with an if (debug_mode) statement.
18 ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
19 **                      recognize the return code from tha main program.
20 **
21 ** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
22 ***********************************************************************/
23
24
25 /***********************************************************************
26 ** Includes
27 ***********************************************************************/
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include "nspr.h"
31
32 PRIntn failed_already=0;
33 PRIntn debug_mode;
34
35 /* variable used for both r1 and r2 tests */
36 int should_fail =0;
37 int actually_failed=0;
38
39
40 void
41 r1
42 (
43     void
44 )
45 {
46     int i;
47         actually_failed=0;
48     for(  i = 0; i < 5; i++ )
49     {
50         void *x = PR_MALLOC(128);
51         if( (void *)0 == x ) {
52                         if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
53                         actually_failed = 1;
54                 }
55         PR_DELETE(x);
56     }
57
58         if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
59
60
61     return;
62 }
63
64 void
65 r2
66 (
67     void
68 )
69 {
70     int i;
71
72     for( i = 0; i <= 5; i++ )
73     {
74                 should_fail =0;
75         if( 0 == i ) {
76                         if (debug_mode) printf("No malloc should fail:\n");
77                 }
78         else {
79                         if (debug_mode) printf("Malloc %d should fail:\n", i);
80                         should_fail = 1;
81                 }
82         PR_SetMallocCountdown(i);
83         r1();
84         PR_ClearMallocCountdown();
85     }
86 }
87
88 int main(int argc, char **argv)
89 {
90
91  /* main test */
92         
93     PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
94     PR_STDIO_INIT();
95     r2();
96
97     if(failed_already)    
98         return 1;
99     else
100         return 0;
101
102     
103 }
104