annotate src/libsndfile-1.0.27/tests/aiff_rw_test.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2003-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 3 **
Chris@40 4 ** This program is free software; you can redistribute it and/or modify
Chris@40 5 ** it under the terms of the GNU General Public License as published by
Chris@40 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 7 ** (at your option) any later version.
Chris@40 8 **
Chris@40 9 ** This program is distributed in the hope that it will be useful,
Chris@40 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 12 ** GNU General Public License for more details.
Chris@40 13 **
Chris@40 14 ** You should have received a copy of the GNU General Public License
Chris@40 15 ** along with this program; if not, write to the Free Software
Chris@40 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 17 */
Chris@40 18
Chris@40 19
Chris@40 20 #include <stdio.h>
Chris@40 21 #include <stdlib.h>
Chris@40 22 #include <string.h>
Chris@40 23 #include <unistd.h>
Chris@40 24 #include <math.h>
Chris@40 25 #include <inttypes.h>
Chris@40 26
Chris@40 27
Chris@40 28 #include <sndfile.h>
Chris@40 29
Chris@40 30 #include "utils.h"
Chris@40 31
Chris@40 32
Chris@40 33 static unsigned char aifc_data [] =
Chris@40 34 { 'F' , 'O' , 'R' , 'M' ,
Chris@40 35 0x00, 0x00, 0x01, 0xE8, /* FORM length */
Chris@40 36
Chris@40 37 'A' , 'I' , 'F' , 'C' ,
Chris@40 38 0x43, 0x4F, 0x4D, 0x4D, /* COMM */
Chris@40 39 0x00, 0x00, 0x00, 0x26, /* COMM length */
Chris@40 40 0x00, 0x01, 0x00, 0x00, 0x00, 0xAE, 0x00, 0x10, 0x40, 0x0D, 0xAC, 0x44,
Chris@40 41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x4F, 0x4E, 0x45, 0x0D, 'N' ,
Chris@40 42 'o' , 't' , ' ' , 'c' , 'o' , 'm' , 'p' , 'r' , 'e' , 's' , 's' , 'e' ,
Chris@40 43 'd' , 0x00,
Chris@40 44
Chris@40 45 'F' , 'V' , 'E' , 'R' , 0x00, 0x00, 0x00, 0x04, 0xA2, 0x80, 0x51, 0x40,
Chris@40 46
Chris@40 47 /* A 'MARK' chunk. */
Chris@40 48 'M' , 'A' , 'R' , 'K' , 0x00, 0x00, 0x00, 0x36, 0x00, 0x05,
Chris@40 49 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 'A' ,
Chris@40 50 0x00, 0x02, 0x00, 0x00, 0x11, 0x3A, 0x02, 'B' , 'C' , 0x00,
Chris@40 51 0x00, 0x03, 0x00, 0x00, 0x22, 0x74, 0x03, 'D' , 'E' , 'F',
Chris@40 52 0x00, 0x04, 0x00, 0x00, 0x33, 0xAE, 0x04, 'G' , 'H' , 'I', 'J' , 0x00,
Chris@40 53 0x00, 0x05, 0x00, 0x00, 0x44, 0xE8, 0x05, 'K' , 'L' , 'M', 'N' , 'O' ,
Chris@40 54
Chris@40 55 'S' , 'S' , 'N' , 'D' ,
Chris@40 56 0x00, 0x00, 0x01, 0x64, /* SSND length */
Chris@40 57 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Chris@40 58 0xFF, 0xE0, 0xFF, 0xDB, 0xFF, 0xD0, 0xFF, 0xD5, 0xFF, 0xD6, 0xFF, 0xD0,
Chris@40 59 0xFF, 0xBF, 0xFF, 0xBE, 0xFF, 0xB9, 0xFF, 0xC8, 0xFF, 0xBF, 0xFF, 0xD5,
Chris@40 60 0xFF, 0xC3, 0xFF, 0xBF, 0xFF, 0xB3, 0xFF, 0xBE, 0xFF, 0xB4, 0xFF, 0xAD,
Chris@40 61 0xFF, 0xAC, 0xFF, 0xAF, 0xFF, 0xB9, 0xFF, 0xB3, 0xFF, 0xA4, 0xFF, 0xA5,
Chris@40 62 0xFF, 0x93, 0xFF, 0x95, 0xFF, 0x97, 0xFF, 0x98, 0xFF, 0x99, 0xFF, 0x9E,
Chris@40 63 0xFF, 0x90, 0xFF, 0x80, 0xFF, 0x81, 0xFF, 0x7C, 0xFF, 0x80, 0xFF, 0x7C,
Chris@40 64 0xFF, 0x72, 0xFF, 0x72, 0xFF, 0x6C, 0xFF, 0x75, 0xFF, 0x6E, 0xFF, 0x6F,
Chris@40 65 0xFF, 0x66, 0xFF, 0x62, 0xFF, 0x5C, 0xFF, 0x64, 0xFF, 0x50, 0xFF, 0x56,
Chris@40 66 0xFF, 0x56, 0xFF, 0x4A, 0xFF, 0x4A, 0xFF, 0x49, 0xFF, 0x44, 0xFF, 0x49,
Chris@40 67 0xFF, 0x3B, 0xFF, 0x3F, 0xFF, 0x48, 0xFF, 0x46, 0xFF, 0x42, 0xFF, 0x49,
Chris@40 68 0xFF, 0x43, 0xFF, 0x36, 0xFF, 0x40, 0xFF, 0x35, 0xFF, 0x3F, 0xFF, 0x36,
Chris@40 69 0xFF, 0x37, 0xFF, 0x2E, 0xFF, 0x23, 0xFF, 0x23, 0xFF, 0x21, 0xFF, 0x1F,
Chris@40 70 0xFF, 0x25, 0xFF, 0x2C, 0xFF, 0x1E, 0xFF, 0x22, 0xFF, 0x24, 0xFF, 0x2B,
Chris@40 71 0xFF, 0x35, 0xFF, 0x27, 0xFF, 0x2E, 0xFF, 0x21, 0xFF, 0x18, 0xFF, 0x21,
Chris@40 72 0xFF, 0x20, 0xFF, 0x0F, 0xFF, 0x21, 0xFF, 0x1A, 0xFF, 0x10, 0xFF, 0x09,
Chris@40 73 0xFF, 0x1E, 0xFF, 0x19, 0xFF, 0x21, 0xFF, 0x13, 0xFF, 0x1B, 0xFF, 0x18,
Chris@40 74 0xFF, 0x21, 0xFF, 0x0F, 0xFF, 0x1A, 0xFF, 0x16, 0xFF, 0x21, 0xFF, 0x1B,
Chris@40 75 0xFF, 0x1B, 0xFF, 0x23, 0xFF, 0x1A, 0xFF, 0x21, 0xFF, 0x26, 0xFF, 0x23,
Chris@40 76 0xFF, 0x26, 0xFF, 0x27, 0xFF, 0x30, 0xFF, 0x27, 0xFF, 0x2F, 0xFF, 0x28,
Chris@40 77 0xFF, 0x2C, 0xFF, 0x27, 0xFF, 0x33, 0xFF, 0x29, 0xFF, 0x33, 0xFF, 0x3A,
Chris@40 78 0xFF, 0x42, 0xFF, 0x3B, 0xFF, 0x4D, 0xFF, 0x4B, 0xFF, 0x4D, 0xFF, 0x4A,
Chris@40 79 0xFF, 0x67, 0xFF, 0x77, 0xFF, 0x73, 0xFF, 0x7B, 0xFF, 0xDE, 0xFF, 0xAD,
Chris@40 80 0x00, 0x4A, 0x00, 0x63, 0xEC, 0x8C, 0x03, 0xBB, 0x0E, 0xE4, 0x08, 0xF2,
Chris@40 81 0x00, 0x70, 0xE3, 0xD1, 0xE5, 0xE4, 0x01, 0x6E, 0x0A, 0x67, 0x1C, 0x74,
Chris@40 82 0xF8, 0x8E, 0x10, 0x7B, 0xEA, 0x3C, 0x09, 0x87, 0x1B, 0x24, 0xEF, 0x05,
Chris@40 83 0x17, 0x76, 0x0D, 0x5B, 0x02, 0x43, 0xF5, 0xEF, 0x0C, 0x1D, 0xF7, 0x61,
Chris@40 84 0x05, 0x95, 0x0B, 0xC2, 0xF1, 0x69, 0x1A, 0xA1, 0xEC, 0x75, 0xF4, 0x11,
Chris@40 85 0x13, 0x4F, 0x13, 0x71, 0xFA, 0x33, 0xEC, 0x32, 0xC8, 0xCF, 0x05, 0xB0,
Chris@40 86 0x0B, 0x61, 0x33, 0x19, 0xCE, 0x37, 0xEF, 0xD4, 0x21, 0x9D, 0xFA, 0xAE,
Chris@40 87 } ;
Chris@40 88
Chris@40 89 static void rw_test (const char *filename) ;
Chris@40 90
Chris@40 91 int
Chris@40 92 main (void)
Chris@40 93 { const char *filename = "rw.aifc" ;
Chris@40 94
Chris@40 95 print_test_name ("aiff_rw_test", filename) ;
Chris@40 96
Chris@40 97 dump_data_to_file (filename, aifc_data, sizeof (aifc_data)) ;
Chris@40 98
Chris@40 99 rw_test (filename) ;
Chris@40 100
Chris@40 101 unlink (filename) ;
Chris@40 102
Chris@40 103 puts ("ok") ;
Chris@40 104 return 0 ;
Chris@40 105 } /* main */
Chris@40 106
Chris@40 107 /*==============================================================================
Chris@40 108 */
Chris@40 109
Chris@40 110 static void
Chris@40 111 rw_test (const char *filename)
Chris@40 112 { SNDFILE *file ;
Chris@40 113 SF_INFO sfinfo_rd, sfinfo_rw ;
Chris@40 114
Chris@40 115 memset (&sfinfo_rd, 0, sizeof (sfinfo_rd)) ;
Chris@40 116 memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
Chris@40 117
Chris@40 118 /* Open the file in read only mode and fill in the SF_INFO struct. */
Chris@40 119 if ((file = sf_open (filename, SFM_READ, &sfinfo_rd)) == NULL)
Chris@40 120 { printf ("\n\nLine %d : sf_open SFM_READ failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
Chris@40 121 exit (1) ;
Chris@40 122 } ;
Chris@40 123 check_log_buffer_or_die (file, __LINE__) ;
Chris@40 124 sf_close (file) ;
Chris@40 125
Chris@40 126 /* Now open read/write and close the file. */
Chris@40 127 if ((file = sf_open (filename, SFM_RDWR, &sfinfo_rw)) == NULL)
Chris@40 128 { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
Chris@40 129 exit (1) ;
Chris@40 130 } ;
Chris@40 131 check_log_buffer_or_die (file, __LINE__) ;
Chris@40 132 sf_close (file) ;
Chris@40 133
Chris@40 134 /* Open again as read only again and fill in a new SF_INFO struct. */
Chris@40 135 memset (&sfinfo_rw, 0, sizeof (sfinfo_rw)) ;
Chris@40 136 if ((file = sf_open (filename, SFM_READ, &sfinfo_rw)) == NULL)
Chris@40 137 { printf ("\n\nLine %d : sf_open SFM_RDWR failed : %s\n\n", __LINE__, sf_strerror (NULL)) ;
Chris@40 138 exit (1) ;
Chris@40 139 } ;
Chris@40 140 check_log_buffer_or_die (file, __LINE__) ;
Chris@40 141 sf_close (file) ;
Chris@40 142
Chris@40 143 /* Now compare the two. */
Chris@40 144 if (sfinfo_rd.format != sfinfo_rw.format)
Chris@40 145 { printf ("\n\nLine %d : format mismatch (0x%08X != 0x%08X).\n\n", __LINE__,
Chris@40 146 sfinfo_rd.format, sfinfo_rw.format) ;
Chris@40 147 exit (1) ;
Chris@40 148 } ;
Chris@40 149
Chris@40 150 if (sfinfo_rd.channels != sfinfo_rw.channels)
Chris@40 151 { printf ("\n\nLine %d : channel count mismatch (%d != %d).\n\n", __LINE__,
Chris@40 152 sfinfo_rd.channels, sfinfo_rw.channels) ;
Chris@40 153 exit (1) ;
Chris@40 154 } ;
Chris@40 155
Chris@40 156 if (sfinfo_rd.frames != sfinfo_rw.frames)
Chris@40 157 { printf ("\n\nLine %d : frame count mismatch (rd %" PRId64 " != rw %" PRId64 ").\n\n", __LINE__,
Chris@40 158 sfinfo_rd.frames, sfinfo_rw.frames) ;
Chris@40 159 exit (1) ;
Chris@40 160 } ;
Chris@40 161
Chris@40 162 return ;
Chris@40 163 } /* rw_test */
Chris@40 164