|
Packit |
a38265 |
/*
|
|
Packit |
a38265 |
Copyright (C) 2003 Commonwealth Scientific and Industrial Research
|
|
Packit |
a38265 |
Organisation (CSIRO) Australia
|
|
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 CSIRO Australia 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 ORGANISATION 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 "config.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include <stdio.h>
|
|
Packit |
a38265 |
#include <stdlib.h>
|
|
Packit |
a38265 |
#include <string.h>
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include "oggz/oggz.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include "oggz_tests.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#include "comment-test.h"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#define ARTIST1 "Trout Junkies"
|
|
Packit |
a38265 |
#define ARTIST2 "DJ Fugu"
|
|
Packit |
a38265 |
#define COPYRIGHT "Copyright (C) 2004. Some Rights Reserved."
|
|
Packit |
a38265 |
#define LICENSE "Creative Commons Attribute Share-Alike v1.0"
|
|
Packit |
a38265 |
#define COMMENT "Unstructured comments are evil."
|
|
Packit |
a38265 |
#define PERFORMER "Jack Mackerel"
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
static OGGZ * oggz;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
int
|
|
Packit |
a38265 |
main (int argc, char * argv[])
|
|
Packit |
a38265 |
{
|
|
Packit |
a38265 |
const OggzComment * comment, * comment2;
|
|
Packit |
a38265 |
OggzComment mycomment;
|
|
Packit |
a38265 |
ogg_packet *op;
|
|
Packit |
a38265 |
const char * vendor;
|
|
Packit |
a38265 |
int err;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
long serialno = 7;
|
|
Packit |
a38265 |
long invalidserialno = 8;
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#if OGGZ_CONFIG_WRITE
|
|
Packit |
a38265 |
INFO ("Initializing OGGZ for comments (writer)");
|
|
Packit |
a38265 |
oggz = oggz_new (OGGZ_WRITE);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding ARTIST1 byname");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "ARTIST", ARTIST1);
|
|
Packit |
a38265 |
if (err == OGGZ_ERR_BAD_SERIALNO)
|
|
Packit |
a38265 |
FAIL ("Comment add to fresh bitstream failed");
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding COPYRIGHT byname");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "COPYRIGHT", COPYRIGHT);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving first (expect ARTIST1)");
|
|
Packit |
a38265 |
comment = oggz_comment_first (oggz, serialno);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == NULL)
|
|
Packit |
a38265 |
FAIL ("Recently inserted ARTIST1 not retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->name, "ARTIST"))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST1 name found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->value, ARTIST1))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST1 value found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving next (expect COPYRIGHT)");
|
|
Packit |
a38265 |
comment = oggz_comment_next (oggz, serialno, comment);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == NULL)
|
|
Packit |
a38265 |
FAIL ("Recently inserted COPYRIGHT not retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->name, "COPYRIGHT"))
|
|
Packit |
a38265 |
FAIL ("Incorrect COPYRIGHT name found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->value, COPYRIGHT))
|
|
Packit |
a38265 |
FAIL ("Incorrect COPYRIGHT value found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Checking comments termination");
|
|
Packit |
a38265 |
comment2 = oggz_comment_next (oggz, serialno, comment);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment2 != NULL)
|
|
Packit |
a38265 |
FAIL ("Comments unterminated");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding LICENSE from local storage");
|
|
Packit |
a38265 |
mycomment.name = "LICENSE";
|
|
Packit |
a38265 |
mycomment.value = LICENSE;
|
|
Packit |
a38265 |
err = oggz_comment_add (oggz, serialno, &mycomment);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving next (expect LICENSE)");
|
|
Packit |
a38265 |
comment = oggz_comment_next (oggz, serialno, comment);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == NULL)
|
|
Packit |
a38265 |
FAIL ("Recently inserted LICENSE not retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == &mycomment)
|
|
Packit |
a38265 |
FAIL ("Recently inserted LICENSE not restored");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->name, "LICENSE"))
|
|
Packit |
a38265 |
FAIL ("Incorrect LICENSE name found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->value, LICENSE))
|
|
Packit |
a38265 |
FAIL ("Incorrect LICENSE value found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding ARTIST2 byname");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "ARTIST", ARTIST2);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving first ARTIST using wierd caps (expect ARTIST1)");
|
|
Packit |
a38265 |
comment = oggz_comment_first_byname (oggz, serialno, "ArTiSt");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == NULL)
|
|
Packit |
a38265 |
FAIL ("Recently inserted ARTIST1 not retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->name, "ARTIST"))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST1 name found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->value, ARTIST1))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST1 value found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving next ARTIST (expect ARTIST2)");
|
|
Packit |
a38265 |
comment = oggz_comment_next_byname (oggz, serialno, comment);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment == NULL)
|
|
Packit |
a38265 |
FAIL ("Recently inserted ARTIST2 not retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->name, "ARTIST"))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST2 name found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (strcmp (comment->value, ARTIST2))
|
|
Packit |
a38265 |
FAIL ("Incorrect ARTIST2 value found");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Removing LICENSE byname");
|
|
Packit |
a38265 |
err = oggz_comment_remove_byname (oggz, serialno, "LICENSE");
|
|
Packit |
a38265 |
if (err != 1) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Attempting to retrieve LICENSE");
|
|
Packit |
a38265 |
comment = oggz_comment_first_byname (oggz, serialno, "LICENSE");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment != NULL)
|
|
Packit |
a38265 |
FAIL ("Removed comment incorrectly retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Removing COPYRIGHT from local storage");
|
|
Packit |
a38265 |
mycomment.name = "COPYRIGHT";
|
|
Packit |
a38265 |
mycomment.value = COPYRIGHT;
|
|
Packit |
a38265 |
err = oggz_comment_remove (oggz, serialno, &mycomment);
|
|
Packit |
a38265 |
if (err != 1) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Attempting to retrieve COPYRIGHT");
|
|
Packit |
a38265 |
comment = oggz_comment_first_byname (oggz, serialno, "COPYRIGHT");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (comment != NULL)
|
|
Packit |
a38265 |
FAIL ("Removed comment incorrectly retrieved");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Attempting to set vendor string");
|
|
Packit |
a38265 |
err = oggz_comment_set_vendor (oggz, serialno, vendor_flac );
|
|
Packit |
a38265 |
if (err) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Retrieving vendor string");
|
|
Packit |
a38265 |
vendor = oggz_comment_get_vendor (oggz, serialno);
|
|
Packit |
a38265 |
if (!vendor || strcmp(vendor, vendor_flac))
|
|
Packit |
a38265 |
FAIL ("+ Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Generating FLAC comment packet");
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_FLAC, 0);
|
|
Packit |
a38265 |
if (!op) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Checking FLAC comment packet");
|
|
Packit |
a38265 |
if (op->bytes != sizeof comment_packet_flac ||
|
|
Packit |
a38265 |
memcmp (op->packet, comment_packet_flac, op->bytes) )
|
|
Packit |
a38265 |
FAIL ("Incorrect packet");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Generating OggPCM comment packet");
|
|
Packit |
a38265 |
/* OggPCM and Speex comment packets are identical. */
|
|
Packit |
a38265 |
err = oggz_comment_set_vendor (oggz, serialno, vendor_speex );
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_PCM, 0);
|
|
Packit |
a38265 |
if (err || !op) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Checking OggPCM comment packet");
|
|
Packit |
a38265 |
if (op->bytes != sizeof comment_packet_speex ||
|
|
Packit |
a38265 |
memcmp (op->packet, comment_packet_speex, op->bytes) )
|
|
Packit |
a38265 |
FAIL ("Incorrect packet");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Generating Speex comment packet");
|
|
Packit |
a38265 |
err = oggz_comment_set_vendor (oggz, serialno, vendor_speex );
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_SPEEX, 0);
|
|
Packit |
a38265 |
if (err || !op) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Checking Speex comment packet");
|
|
Packit |
a38265 |
if (op->bytes != sizeof comment_packet_speex ||
|
|
Packit |
a38265 |
memcmp (op->packet, comment_packet_speex, op->bytes) )
|
|
Packit |
a38265 |
FAIL ("Incorrect packet");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Generating Theora comment packet");
|
|
Packit |
a38265 |
err = oggz_comment_set_vendor (oggz, serialno, vendor_theora );
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_THEORA, 0);
|
|
Packit |
a38265 |
if (err || !op) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Checking Theora comment packet");
|
|
Packit |
a38265 |
if (op->bytes != sizeof comment_packet_theora ||
|
|
Packit |
a38265 |
memcmp (op->packet, comment_packet_theora, op->bytes) )
|
|
Packit |
a38265 |
FAIL ("Incorrect packet");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Generating Vorbis comment packet");
|
|
Packit |
a38265 |
err = oggz_comment_set_vendor (oggz, serialno, vendor_vorbis );
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_VORBIS, 0);
|
|
Packit |
a38265 |
if (err || !op) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Checking Vorbis comment packet");
|
|
Packit |
a38265 |
if (op->bytes != sizeof comment_packet_vorbis ||
|
|
Packit |
a38265 |
memcmp (op->packet, comment_packet_vorbis, op->bytes) )
|
|
Packit |
a38265 |
FAIL ("Incorrect packet");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Testing comment generate for unsupported type");
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, serialno, OGGZ_CONTENT_UNKNOWN, 0);
|
|
Packit |
a38265 |
if(op) FAIL ("Returned comment packet for unsupported type");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO("+ Testing comment generate for invalid serialno");
|
|
Packit |
a38265 |
op = oggz_comment_generate (oggz, invalidserialno, OGGZ_CONTENT_VORBIS, 0);
|
|
Packit |
a38265 |
if(op) FAIL ("Returned comment packet for invalid serialno");
|
|
Packit |
a38265 |
oggz_packet_destroy(op);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Testing add of valid plain (not key=value) COMMENT byname");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, COMMENT, NULL);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Testing add of valid plain (not key=value) COMMENT from local storage");
|
|
Packit |
a38265 |
mycomment.name = COMMENT;
|
|
Packit |
a38265 |
mycomment.value = NULL;
|
|
Packit |
a38265 |
err = oggz_comment_add (oggz, serialno, &mycomment);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding duplicate tag");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "PERFORMER", PERFORMER);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "PERFORMER", PERFORMER);
|
|
Packit |
a38265 |
if (err < 0) FAIL ("Operation failed");
|
|
Packit |
a38265 |
INFO ("+ Scanning comments (should not hang on duplicate)");
|
|
Packit |
a38265 |
for (comment = oggz_comment_first (oggz, serialno);
|
|
Packit |
a38265 |
comment != NULL;
|
|
Packit |
a38265 |
comment = oggz_comment_next (oggz, serialno, comment));
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("Closing OGGZ (writer)");
|
|
Packit |
a38265 |
oggz_close (oggz);
|
|
Packit |
a38265 |
#endif /* OGGZ_CONFIG_WRITE */
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
#if OGGZ_CONFIG_READ
|
|
Packit |
a38265 |
INFO ("Initializing OGGZ for comments (reader)");
|
|
Packit |
a38265 |
oggz = oggz_new (OGGZ_READ);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Adding ARTIST1 byname (invalid for reader)");
|
|
Packit |
a38265 |
err = oggz_comment_add_byname (oggz, serialno, "ARTIST", ARTIST1);
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (err == 0)
|
|
Packit |
a38265 |
FAIL ("Operation disallowed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("+ Removing ARTIST byname (invalid for reader)");
|
|
Packit |
a38265 |
err = oggz_comment_remove_byname (oggz, serialno, "ARTIST");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
if (err == 0)
|
|
Packit |
a38265 |
FAIL ("Operation disallowed");
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
INFO ("Closing OGGZ (reader)");
|
|
Packit |
a38265 |
oggz_close (oggz);
|
|
Packit |
a38265 |
#endif /* OGGZ_CONFIG_READ */
|
|
Packit |
a38265 |
|
|
Packit |
a38265 |
exit (0);
|
|
Packit |
a38265 |
}
|