2
Copyright (C) 2003 Commonwealth Scientific and Industrial Research
3
Organisation (CSIRO) Australia
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions
9
- Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
12
- Redistributions in binary form must reproduce the above copyright
13
notice, this list of conditions and the following disclaimer in the
14
documentation and/or other materials provided with the distribution.
16
- Neither the name of CSIRO Australia nor the names of its
17
contributors may be used to endorse or promote products derived from
18
this software without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
24
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
#include <oggz/oggz.h>
39
#include "oggz_tests.h"
43
#define DATA_BUF_LEN 1024
46
static long bytes_generated = 0;
47
static int read_called = 0;
48
static int eof_reached = 0;
51
hungry (OGGZ * oggz, int empty, void * user_data)
56
static long b_o_s = 1;
57
static long e_o_s = 0;
59
if (iter > 10) return 1;
71
if (oggz_write_feed (oggz, &op, serialno, 0, NULL) != 0)
72
FAIL ("Oggz write failed");
76
if (iter == 10) e_o_s = 1;
82
read_packet (OGGZ * oggz, ogg_packet * op, long serialno, void * user_data)
85
static long b_o_s = 1;
86
static long e_o_s = 0;
89
printf ("%08" PRI_off_t "x: serialno %010ld, "
90
"granulepos %" PRId64 ", packetno %" PRId64,
91
oggz_tell (oggz), serialno, op->granulepos, op->packetno);
105
FAIL ("Packet too long");
107
if (op->packet[0] != 'a' + iter)
108
FAIL ("Packet contains incorrect data");
110
if ((op->b_o_s == 0) != (b_o_s == 0))
111
FAIL ("Packet has incorrect b_o_s");
113
if ((op->e_o_s == 0) != (e_o_s == 0))
114
FAIL ("Packet has incorrect e_o_s");
116
if (op->granulepos != -1 && op->granulepos != iter)
117
FAIL ("Packet has incorrect granulepos");
119
if (op->packetno != iter)
120
FAIL ("Packet has incorrect packetno");
124
if (iter == 10) e_o_s = 1;
130
my_io_read (void * user_handle, void * buf, size_t n)
132
unsigned char * data_buf = (unsigned char *)user_handle;
133
static int offset = 0;
136
/* Mark that the read IO method was actually used */
139
len = MIN (n, bytes_generated - offset);
141
memcpy (buf, &data_buf[offset], len);
145
if (len == 0) eof_reached = 1;
151
main (int argc, char * argv[])
153
OGGZ * reader, * writer;
154
unsigned char data_buf[DATA_BUF_LEN];
157
INFO ("Testing override of IO reading");
159
writer = oggz_new (OGGZ_WRITE);
161
FAIL("newly created OGGZ writer == NULL");
163
serialno = oggz_serialno_new (writer);
165
if (oggz_write_set_hungry_callback (writer, hungry, 1, NULL) == -1)
166
FAIL("Could not set hungry callback");
168
reader = oggz_new (OGGZ_READ);
170
FAIL("newly created OGGZ reader == NULL");
172
oggz_io_set_read (reader, my_io_read, data_buf);
174
oggz_set_read_callback (reader, -1, read_packet, NULL);
176
n = oggz_write_output (writer, data_buf, DATA_BUF_LEN);
178
if (n >= DATA_BUF_LEN)
179
FAIL("Too much data generated by writer");
184
ret = oggz_read (reader, 4);
185
} while (ret > 0 || ret == OGGZ_ERR_READ_STOP_OK);
187
if (ret != 0) FAIL ("oggz_read didn't reach EOF");
189
if (!eof_reached) FAIL ("oggz_read returned 0 before EOF");
191
if (read_called == 0)
192
FAIL("Read method ignored");
194
if (oggz_close (reader) != 0)
195
FAIL("Could not close OGGZ reader");
197
if (oggz_close (writer) != 0)
198
FAIL("Could not close OGGZ writer");