Blame src/tests/write-bad-serialno.c

Packit a38265
/*
Packit a38265
   Copyright (C) 2008 Annodex Association, Inc.
Packit a38265
Packit a38265
   Redistribution and use in source and binary forms, with or without
Packit a38265
   modification, are permitted provided that the following conditions
Packit a38265
   are met:
Packit a38265
Packit a38265
   - Redistributions of source code must retain the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer.
Packit a38265
Packit a38265
   - Redistributions in binary form must reproduce the above copyright
Packit a38265
   notice, this list of conditions and the following disclaimer in the
Packit a38265
   documentation and/or other materials provided with the distribution.
Packit a38265
Packit a38265
   - Neither the name of the Annodex Association nor the names of its
Packit a38265
   contributors may be used to endorse or promote products derived from
Packit a38265
   this software without specific prior written permission.
Packit a38265
Packit a38265
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit a38265
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit a38265
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
Packit a38265
   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ASSOCIATION OR
Packit a38265
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit a38265
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit a38265
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit a38265
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit a38265
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit a38265
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit a38265
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit a38265
*/
Packit a38265
Packit a38265
#include "oggz/oggz.h"
Packit a38265
Packit a38265
#include "oggz_tests.h"
Packit a38265
Packit a38265
static const long good_serialno = 0x77L;
Packit a38265
static const long bad_serialno = (long)0x777777777777LL;
Packit a38265
Packit a38265
int
Packit a38265
main (int argc, char * argv[])
Packit a38265
{
Packit a38265
  OGGZ * oggz;
Packit a38265
  unsigned char buf[1];
Packit a38265
  ogg_packet op;
Packit a38265
  long n;
Packit a38265
Packit a38265
  oggz = oggz_new (OGGZ_WRITE);
Packit a38265
  if (oggz == NULL)
Packit a38265
    FAIL("newly created OGGZ == NULL");
Packit a38265
Packit a38265
  /* Create a packet */
Packit a38265
  buf[0] = 'x';
Packit a38265
  op.packet = buf;
Packit a38265
  op.bytes = 1;
Packit a38265
  op.granulepos = 0;
Packit a38265
  op.packetno = 0;
Packit a38265
  op.b_o_s = 1;
Packit a38265
  op.e_o_s = 0;
Packit a38265
    
Packit a38265
  /* Feed it to the Oggz packet queue, first normally, then twice with a
Packit a38265
   * bad serialno */
Packit a38265
Packit a38265
  INFO ("Feeding packet with ok serialno");
Packit a38265
  if (oggz_write_feed (oggz, &op, good_serialno, 0, NULL) != 0)
Packit a38265
    FAIL ("Error feeding with valid serialno");
Packit a38265
Packit a38265
  INFO ("Feeding packet with -1 serialno");
Packit a38265
  if (oggz_write_feed (oggz, &op, -1L, 0, NULL) != OGGZ_ERR_BAD_SERIALNO)
Packit a38265
    FAIL ("Illegal serialno (-1) not detected");
Packit a38265
    
Packit a38265
  /* The following test is only active where long and int have different
Packit a38265
   * sizes, eg. on LP64 platforms */
Packit a38265
  if (sizeof(long) > sizeof(int)) {
Packit a38265
    INFO ("Detected sizeof(long) > sizeof(int)")
Packit a38265
Packit a38265
    INFO ("Feeding packet with out-of-range serialno");
Packit a38265
    if (oggz_write_feed (oggz, &op, bad_serialno, 0, NULL) !=
Packit a38265
        OGGZ_ERR_BAD_SERIALNO)
Packit a38265
      FAIL ("Out-of-range serialno not detected");
Packit a38265
  }
Packit a38265
Packit a38265
  if (oggz_close (oggz) != 0)
Packit a38265
    FAIL("Could not close OGGZ");
Packit a38265
Packit a38265
  exit (0);
Packit a38265
}