]>
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
30 #include <pulsecore/memblockq.h>
31 #include <pulsecore/log.h>
33 int main(int argc
, char *argv
[]) {
38 pa_memchunk chunk1
, chunk2
, chunk3
, chunk4
;
41 pa_log_set_maximal_level(PA_LOG_DEBUG
);
43 p
= pa_mempool_new(0);
45 silence
= pa_memblock_new_fixed(p
, (char*) "__", 2, 1);
48 bq
= pa_memblockq_new(0, 40, 10, 2, 4, 4, silence
);
51 chunk1
.memblock
= pa_memblock_new_fixed(p
, (char*) "AA", 2, 1);
54 assert(chunk1
.memblock
);
56 chunk2
.memblock
= pa_memblock_new_fixed(p
, (char*) "TTBB", 4, 1);
59 assert(chunk2
.memblock
);
61 chunk3
.memblock
= pa_memblock_new_fixed(p
, (char*) "ZZZZ", 4, 1);
64 assert(chunk3
.memblock
);
66 chunk4
.memblock
= pa_memblock_new_fixed(p
, (char*) "KKKKKKKK", 8, 1);
69 assert(chunk4
.memblock
);
71 ret
= pa_memblockq_push(bq
, &chunk1
);
74 ret
= pa_memblockq_push(bq
, &chunk1
);
77 ret
= pa_memblockq_push(bq
, &chunk2
);
80 ret
= pa_memblockq_push(bq
, &chunk2
);
83 pa_memblockq_seek(bq
, -6, 0);
84 ret
= pa_memblockq_push(bq
, &chunk3
);
87 pa_memblockq_seek(bq
, -2, 0);
88 ret
= pa_memblockq_push(bq
, &chunk3
);
91 pa_memblockq_seek(bq
, -10, 0);
92 ret
= pa_memblockq_push(bq
, &chunk4
);
95 pa_memblockq_seek(bq
, 10, 0);
97 ret
= pa_memblockq_push(bq
, &chunk1
);
100 pa_memblockq_seek(bq
, -6, 0);
101 ret
= pa_memblockq_push(bq
, &chunk2
);
105 pa_memblockq_seek(bq
, -12, 0);
106 ret
= pa_memblockq_push(bq
, &chunk1
);
109 pa_memblockq_seek(bq
, 20, 0);
112 ret
= pa_memblockq_push(bq
, &chunk3
);
114 pa_memblockq_seek(bq
, -2, 0);
119 ret
= pa_memblockq_push(bq
, &chunk3
);
124 pa_memblockq_shorten(bq
, 6);
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
, 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
);