1
/* $Id: fifobuf.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
/* To prevent warning about "translation unit is empty"
23
* when this test is disabled.
25
int dummy_fifobuf_test;
27
#if INCLUDE_FIFOBUF_TEST
33
enum { SIZE = 1024, MAX_ENTRIES = 128,
34
MIN_SIZE = 4, MAX_SIZE = 64,
38
unsigned available = SIZE;
39
void *entries[MAX_ENTRIES];
43
pool = pj_pool_create(mem, NULL, SIZE+256, 0, NULL);
47
buffer = pj_pool_alloc(pool, SIZE);
51
pj_fifobuf_init (&fifo, buffer, SIZE);
54
for (i=0; i<LOOP*MAX_ENTRIES; ++i) {
60
size = MIN_SIZE+(pj_rand() % MAX_SIZE);
61
entries[c] = pj_fifobuf_alloc (&fifo, size);
62
} while (entries[c] == 0);
64
pj_fifobuf_free(&fifo, entries[f]);
68
pj_fifobuf_free(&fifo, entries[(i+1)%2]);
70
if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
76
entries[0] = pj_fifobuf_alloc (&fifo, MIN_SIZE);
77
if (!entries[0]) return -1;
78
for (i=0; i<LOOP*MAX_ENTRIES; ++i) {
79
int size = MIN_SIZE+(pj_rand() % MAX_SIZE);
80
entries[1] = pj_fifobuf_alloc (&fifo, size);
82
pj_fifobuf_unalloc(&fifo, entries[1]);
84
pj_fifobuf_unalloc(&fifo, entries[0]);
85
if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
91
for (i=0; i<LOOP; ++i) {
93
for (count=0; available>=MIN_SIZE+4 && count < MAX_ENTRIES;) {
94
int size = MIN_SIZE+(pj_rand() % MAX_SIZE);
95
entries[count] = pj_fifobuf_alloc (&fifo, size);
97
available -= (size+4);
101
for (j=0; j<count; ++j) {
102
pj_fifobuf_free (&fifo, entries[j]);
107
if (pj_fifobuf_max_size(&fifo) < SIZE-4) {
111
pj_pool_release(pool);
115
#endif /* INCLUDE_FIFOBUF_TEST */