Debian Codegraph @

nsprpub/pr/tests/dbmalloc1.c

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