]>
code.delx.au - pulseaudio/blob - src/tests/memblockq-test.c
4 This file is part of PulseAudio.
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <pulsecore/memblockq.h>
32 #include <pulsecore/log.h>
34 int main(int argc
, char *argv
[]) {
39 pa_memchunk chunk1
, chunk2
, chunk3
, chunk4
;
42 pa_log_set_maximal_level(PA_LOG_DEBUG
);
44 p
= pa_mempool_new(0);
46 silence
= pa_memblock_new_fixed(p
, (char*) "__", 2, 1);
49 bq
= pa_memblockq_new(0, 40, 10, 2, 4, 4, silence
);
52 chunk1
.memblock
= pa_memblock_new_fixed(p
, (char*) "11", 2, 1);
55 assert(chunk1
.memblock
);
57 chunk2
.memblock
= pa_memblock_new_fixed(p
, (char*) "XX22", 4, 1);
60 assert(chunk2
.memblock
);
62 chunk3
.memblock
= pa_memblock_new_fixed(p
, (char*) "3333", 4, 1);
65 assert(chunk3
.memblock
);
67 chunk4
.memblock
= pa_memblock_new_fixed(p
, (char*) "44444444", 8, 1);
70 assert(chunk4
.memblock
);
72 ret
= pa_memblockq_push(bq
, &chunk1
);
75 ret
= pa_memblockq_push(bq
, &chunk1
);
78 ret
= pa_memblockq_push(bq
, &chunk2
);
81 ret
= pa_memblockq_push(bq
, &chunk2
);
84 pa_memblockq_seek(bq
, -6, 0);
85 ret
= pa_memblockq_push(bq
, &chunk3
);
88 pa_memblockq_seek(bq
, -2, 0);
89 ret
= pa_memblockq_push(bq
, &chunk3
);
92 pa_memblockq_seek(bq
, -10, 0);
93 ret
= pa_memblockq_push(bq
, &chunk4
);
96 pa_memblockq_seek(bq
, 10, 0);
98 ret
= pa_memblockq_push(bq
, &chunk1
);
101 pa_memblockq_seek(bq
, -6, 0);
102 ret
= pa_memblockq_push(bq
, &chunk2
);
106 pa_memblockq_seek(bq
, -12, 0);
107 ret
= pa_memblockq_push(bq
, &chunk1
);
110 pa_memblockq_seek(bq
, 20, 0);
113 ret
= pa_memblockq_push(bq
, &chunk3
);
115 pa_memblockq_seek(bq
, -2, 0);
119 ret
= pa_memblockq_push(bq
, &chunk3
);
122 pa_memblockq_shorten(bq
, pa_memblockq_get_length(bq
)-2);
131 if (pa_memblockq_peek(bq
, &out
) < 0)
134 p
= pa_memblock_acquire(out
.memblock
);
135 for (e
= (char*) p
+ out
.index
, n
= 0; n
< out
.length
; n
++)
137 pa_memblock_release(out
.memblock
);
139 pa_memblock_unref(out
.memblock
);
140 pa_memblockq_drop(bq
, out
.length
);
145 pa_memblockq_free(bq
);
146 pa_memblock_unref(silence
);
147 pa_memblock_unref(chunk1
.memblock
);
148 pa_memblock_unref(chunk2
.memblock
);
149 pa_memblock_unref(chunk3
.memblock
);
150 pa_memblock_unref(chunk4
.memblock
);