]>
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 static void dump(pa_memblockq
*bq
) {
43 if (pa_memblockq_peek(bq
, &out
) < 0)
46 q
= pa_memblock_acquire(out
.memblock
);
47 for (e
= (char*) q
+ out
.index
, n
= 0; n
< out
.length
; n
++)
49 pa_memblock_release(out
.memblock
);
51 pa_memblock_unref(out
.memblock
);
52 pa_memblockq_drop(bq
, out
.length
);
58 int main(int argc
, char *argv
[]) {
63 pa_memchunk chunk1
, chunk2
, chunk3
, chunk4
;
66 pa_log_set_maximal_level(PA_LOG_DEBUG
);
68 p
= pa_mempool_new(0);
70 silence
= pa_memblock_new_fixed(p
, (char*) "__", 2, 1);
73 bq
= pa_memblockq_new(0, 40, 10, 2, 4, 4, 40, silence
);
76 chunk1
.memblock
= pa_memblock_new_fixed(p
, (char*) "11", 2, 1);
79 assert(chunk1
.memblock
);
81 chunk2
.memblock
= pa_memblock_new_fixed(p
, (char*) "XX22", 4, 1);
84 assert(chunk2
.memblock
);
86 chunk3
.memblock
= pa_memblock_new_fixed(p
, (char*) "3333", 4, 1);
89 assert(chunk3
.memblock
);
91 chunk4
.memblock
= pa_memblock_new_fixed(p
, (char*) "44444444", 8, 1);
94 assert(chunk4
.memblock
);
96 ret
= pa_memblockq_push(bq
, &chunk1
);
99 ret
= pa_memblockq_push(bq
, &chunk2
);
102 ret
= pa_memblockq_push(bq
, &chunk3
);
105 ret
= pa_memblockq_push(bq
, &chunk4
);
108 pa_memblockq_seek(bq
, -6, 0);
109 ret
= pa_memblockq_push(bq
, &chunk3
);
112 pa_memblockq_seek(bq
, -2, 0);
113 ret
= pa_memblockq_push(bq
, &chunk1
);
116 pa_memblockq_seek(bq
, -10, 0);
117 ret
= pa_memblockq_push(bq
, &chunk4
);
120 pa_memblockq_seek(bq
, 10, 0);
122 ret
= pa_memblockq_push(bq
, &chunk1
);
125 pa_memblockq_seek(bq
, -6, 0);
126 ret
= pa_memblockq_push(bq
, &chunk2
);
130 pa_memblockq_seek(bq
, -12, 0);
131 ret
= pa_memblockq_push(bq
, &chunk1
);
134 pa_memblockq_seek(bq
, 20, 0);
137 ret
= pa_memblockq_push(bq
, &chunk3
);
139 pa_memblockq_seek(bq
, -2, 0);
143 ret
= pa_memblockq_push(bq
, &chunk3
);
146 pa_memblockq_seek(bq
, 30, PA_SEEK_RELATIVE
);
150 pa_memblockq_rewind(bq
, 52);
154 pa_memblockq_free(bq
);
155 pa_memblock_unref(silence
);
156 pa_memblock_unref(chunk1
.memblock
);
157 pa_memblock_unref(chunk2
.memblock
);
158 pa_memblock_unref(chunk3
.memblock
);
159 pa_memblock_unref(chunk4
.memblock
);