1 /*
2    Copyright (C) 2008 Annodex Association, Inc.
3 
4    Redistribution and use in source and binary forms, with or without
5    modification, are permitted provided that the following conditions
6    are met:
7 
8    - Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 
11    - Redistributions in binary form must reproduce the above copyright
12    notice, this list of conditions and the following disclaimer in the
13    documentation and/or other materials provided with the distribution.
14 
15    - Neither the name of the Annodex Association nor the names of its
16    contributors may be used to endorse or promote products derived from
17    this software without specific prior written permission.
18 
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ASSOCIATION OR
23    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 
32 #include "oggz/oggz.h"
33 
34 #include "oggz_tests.h"
35 
36 static const long good_serialno = 0x77L;
37 static const long bad_serialno = (long)0x777777777777LL;
38 
39 int
main(int argc,char * argv[])40 main (int argc, char * argv[])
41 {
42   OGGZ * oggz;
43   unsigned char buf[1];
44   ogg_packet op;
45   long n;
46 
47   oggz = oggz_new (OGGZ_WRITE);
48   if (oggz == NULL)
49     FAIL("newly created OGGZ == NULL");
50 
51   /* Create a packet */
52   buf[0] = 'x';
53   op.packet = buf;
54   op.bytes = 1;
55   op.granulepos = 0;
56   op.packetno = 0;
57   op.b_o_s = 1;
58   op.e_o_s = 0;
59 
60   /* Feed it to the Oggz packet queue, first normally, then twice with a
61    * bad serialno */
62 
63   INFO ("Feeding packet with ok serialno");
64   if (oggz_write_feed (oggz, &op, good_serialno, 0, NULL) != 0)
65     FAIL ("Error feeding with valid serialno");
66 
67   INFO ("Feeding packet with -1 serialno");
68   if (oggz_write_feed (oggz, &op, -1L, 0, NULL) != OGGZ_ERR_BAD_SERIALNO)
69     FAIL ("Illegal serialno (-1) not detected");
70 
71   /* The following test is only active where long and int have different
72    * sizes, eg. on LP64 platforms */
73   if (sizeof(long) > sizeof(int)) {
74     INFO ("Detected sizeof(long) > sizeof(int)")
75 
76     INFO ("Feeding packet with out-of-range serialno");
77     if (oggz_write_feed (oggz, &op, bad_serialno, 0, NULL) !=
78         OGGZ_ERR_BAD_SERIALNO)
79       FAIL ("Out-of-range serialno not detected");
80   }
81 
82   if (oggz_close (oggz) != 0)
83     FAIL("Could not close OGGZ");
84 
85   exit (0);
86 }
87