VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/tests/dbmalloc1.c@ 32258

Last change on this file since 32258 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38/***********************************************************************
39**
40** Name: dbmalloc1.c (OBSOLETE)
41**
42** Description: Tests PR_SetMallocCountdown PR_ClearMallocCountdown functions.
43**
44** Modification History:
45** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
46** The debug mode will print all of the printfs associated with this test.
47** The regress mode will be the default mode. Since the regress tool limits
48** the output to a one line status:PASS or FAIL,all of the printf statements
49** have been handled with an if (debug_mode) statement.
50** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
51** recognize the return code from tha main program.
52**
53** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
54***********************************************************************/
55
56
57/***********************************************************************
58** Includes
59***********************************************************************/
60#include <stdio.h>
61#include <stdlib.h>
62#include "nspr.h"
63
64PRIntn failed_already=0;
65PRIntn debug_mode;
66
67/* variable used for both r1 and r2 tests */
68int should_fail =0;
69int actually_failed=0;
70
71
72void
73r1
74(
75 void
76)
77{
78 int i;
79 actually_failed=0;
80 for( i = 0; i < 5; i++ )
81 {
82 void *x = PR_MALLOC(128);
83 if( (void *)0 == x ) {
84 if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
85 actually_failed = 1;
86 }
87 PR_DELETE(x);
88 }
89
90 if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
91
92
93 return;
94}
95
96void
97r2
98(
99 void
100)
101{
102 int i;
103
104 for( i = 0; i <= 5; i++ )
105 {
106 should_fail =0;
107 if( 0 == i ) {
108 if (debug_mode) printf("No malloc should fail:\n");
109 }
110 else {
111 if (debug_mode) printf("Malloc %d should fail:\n", i);
112 should_fail = 1;
113 }
114 PR_SetMallocCountdown(i);
115 r1();
116 PR_ClearMallocCountdown();
117 }
118}
119
120int
121main
122(
123 int argc,
124 char *argv[]
125)
126{
127
128 /* main test */
129
130 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
131 PR_STDIO_INIT();
132 r2();
133
134 if(failed_already)
135 return 1;
136 else
137 return 0;
138
139
140}
141
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette