annotate src/libsndfile-1.0.27/tests/string_test.c @ 168:ceec0dd9ec9c

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 <cannam@all-day-breakfast.com>
date Fri, 07 Feb 2020 11:51:13 +0000
parents cd6cdf86811e
children
rev   line source
cannam@125 1 /*
cannam@125 2 ** Copyright (C) 2003-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@125 3 **
cannam@125 4 ** This program is free software; you can redistribute it and/or modify
cannam@125 5 ** it under the terms of the GNU General Public License as published by
cannam@125 6 ** the Free Software Foundation; either version 2 of the License, or
cannam@125 7 ** (at your option) any later version.
cannam@125 8 **
cannam@125 9 ** This program is distributed in the hope that it will be useful,
cannam@125 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@125 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@125 12 ** GNU General Public License for more details.
cannam@125 13 **
cannam@125 14 ** You should have received a copy of the GNU General Public License
cannam@125 15 ** along with this program; if not, write to the Free Software
cannam@125 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cannam@125 17 */
cannam@125 18
cannam@125 19 #include "sfconfig.h"
cannam@125 20
cannam@125 21 #include <stdio.h>
cannam@125 22 #include <stdlib.h>
cannam@125 23 #include <string.h>
cannam@125 24 #include <math.h>
cannam@125 25 #include <inttypes.h>
cannam@125 26
cannam@125 27 #if HAVE_UNISTD_H
cannam@125 28 #include <unistd.h>
cannam@125 29 #endif
cannam@125 30
cannam@125 31 #include <sndfile.h>
cannam@125 32
cannam@125 33 #include "utils.h"
cannam@125 34
cannam@125 35 #define BUFFER_LEN (1 << 10)
cannam@125 36 #define LOG_BUFFER_SIZE 1024
cannam@125 37
cannam@125 38 static void string_start_test (const char *filename, int typemajor) ;
cannam@125 39 static void string_start_end_test (const char *filename, int typemajor) ;
cannam@125 40 static void string_multi_set_test (const char *filename, int typemajor) ;
cannam@125 41 static void string_rdwr_test (const char *filename, int typemajor) ;
cannam@125 42 static void string_short_rdwr_test (const char *filename, int typemajor) ;
cannam@125 43 static void string_rdwr_grow_test (const char *filename, int typemajor) ;
cannam@125 44 static void string_header_update (const char *filename, int typemajor) ;
cannam@125 45
cannam@125 46 static void software_string_test (const char *filename) ;
cannam@125 47
cannam@125 48 static int str_count (const char * haystack, const char * needle) ;
cannam@125 49
cannam@125 50 int
cannam@125 51 main (int argc, char *argv [])
cannam@125 52 { int do_all = 0 ;
cannam@125 53 int test_count = 0 ;
cannam@125 54
cannam@125 55 if (argc != 2)
cannam@125 56 { printf ("Usage : %s <test>\n", argv [0]) ;
cannam@125 57 printf (" Where <test> is one of the following:\n") ;
cannam@125 58 printf (" wav - test adding strings to WAV files\n") ;
cannam@125 59 printf (" aiff - test adding strings to AIFF files\n") ;
cannam@125 60 printf (" flac - test adding strings to FLAC files\n") ;
cannam@125 61 printf (" ogg - test adding strings to OGG files\n") ;
cannam@125 62 printf (" all - perform all tests\n") ;
cannam@125 63 exit (1) ;
cannam@125 64 } ;
cannam@125 65
cannam@125 66 do_all = ! strcmp (argv [1], "all") ;
cannam@125 67
cannam@125 68 if (do_all || ! strcmp (argv [1], "wav"))
cannam@125 69 { string_start_end_test ("strings.wav", SF_FORMAT_WAV) ;
cannam@125 70 string_multi_set_test ("multi.wav", SF_FORMAT_WAV) ;
cannam@125 71 string_rdwr_test ("rdwr.wav", SF_FORMAT_WAV) ;
cannam@125 72 string_short_rdwr_test ("short_rdwr.wav", SF_FORMAT_WAV) ;
cannam@125 73 string_rdwr_grow_test ("rdwr_grow.wav", SF_FORMAT_WAV) ;
cannam@125 74 string_header_update ("header_update.wav", SF_FORMAT_WAV) ;
cannam@125 75
cannam@125 76 string_start_end_test ("strings.wavex", SF_FORMAT_WAVEX) ;
cannam@125 77 string_multi_set_test ("multi.wavex", SF_FORMAT_WAVEX) ;
cannam@125 78 string_rdwr_test ("rdwr.wavex", SF_FORMAT_WAVEX) ;
cannam@125 79 string_short_rdwr_test ("short_rdwr.wavex", SF_FORMAT_WAVEX) ;
cannam@125 80
cannam@125 81 string_start_end_test ("strings.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
cannam@125 82 string_multi_set_test ("multi.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
cannam@125 83 string_rdwr_test ("rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
cannam@125 84 string_short_rdwr_test ("short_rdwr.rifx", SF_ENDIAN_BIG | SF_FORMAT_WAV) ;
cannam@125 85
cannam@125 86 software_string_test ("software_string.wav") ;
cannam@125 87 test_count++ ;
cannam@125 88 } ;
cannam@125 89
cannam@125 90 if (do_all || ! strcmp (argv [1], "aiff"))
cannam@125 91 { string_start_test ("strings.aiff", SF_FORMAT_AIFF) ;
cannam@125 92 string_start_end_test ("strings.aiff", SF_FORMAT_AIFF) ;
cannam@125 93 /*
cannam@125 94 TODO : Fix src/aiff.c so these tests pass.
cannam@125 95 string_multi_set_test ("multi.aiff", SF_FORMAT_AIFF) ;
cannam@125 96 string_rdwr_test ("rdwr.aiff", SF_FORMAT_AIFF) ;
cannam@125 97 string_short_rdwr_test ("short_rdwr.aiff", SF_FORMAT_AIFF) ;
cannam@125 98 string_rdwr_grow_test ("rdwr_grow.aiff", SF_FORMAT_AIFF) ;
cannam@125 99 string_header_update ("header_update.aiff", SF_FORMAT_AIFF) ;
cannam@125 100 */
cannam@125 101
cannam@125 102 test_count++ ;
cannam@125 103 } ;
cannam@125 104
cannam@125 105 if (do_all || ! strcmp (argv [1], "flac"))
cannam@125 106 { if (HAVE_EXTERNAL_XIPH_LIBS)
cannam@125 107 string_start_test ("strings.flac", SF_FORMAT_FLAC) ;
cannam@125 108 else
cannam@125 109 puts (" No FLAC tests because FLAC support was not compiled in.") ;
cannam@125 110 test_count++ ;
cannam@125 111 } ;
cannam@125 112
cannam@125 113 if (do_all || ! strcmp (argv [1], "ogg"))
cannam@125 114 { if (HAVE_EXTERNAL_XIPH_LIBS)
cannam@125 115 string_start_test ("vorbis.oga", SF_FORMAT_OGG) ;
cannam@125 116 else
cannam@125 117 puts (" No Ogg/Vorbis tests because Ogg/Vorbis support was not compiled in.") ;
cannam@125 118 test_count++ ;
cannam@125 119 } ;
cannam@125 120
cannam@125 121 if (do_all || ! strcmp (argv [1], "caf"))
cannam@125 122 { string_start_test ("strings.caf", SF_FORMAT_CAF) ;
cannam@125 123 string_start_end_test ("strings.caf", SF_FORMAT_CAF) ;
cannam@125 124 string_multi_set_test ("multi.caf", SF_FORMAT_CAF) ;
cannam@125 125 /*
cannam@125 126 TODO : Fix src/caf.c so these tests pass.
cannam@125 127 string_rdwr_test ("rdwr.caf", SF_FORMAT_CAF) ;
cannam@125 128 string_short_rdwr_test ("short_rdwr.caf", SF_FORMAT_CAF) ;
cannam@125 129 string_header_update ("header_update.caf", SF_FORMAT_CAF) ;
cannam@125 130 */
cannam@125 131 test_count++ ;
cannam@125 132 } ;
cannam@125 133
cannam@125 134 if (do_all || ! strcmp (argv [1], "rf64"))
cannam@125 135 { string_start_test ("strings.rf64", SF_FORMAT_RF64) ;
cannam@125 136 string_start_end_test ("strings.rf64", SF_FORMAT_RF64) ;
cannam@125 137 string_multi_set_test ("multi.rf64", SF_FORMAT_RF64) ;
cannam@125 138 /*
cannam@125 139 TODO : Fix src/rf64.c so these tests pass.
cannam@125 140 string_rdwr_test ("rdwr.rf64", SF_FORMAT_RF64) ;
cannam@125 141 string_short_rdwr_test ("short_rdwr.rf64", SF_FORMAT_RF64) ;
cannam@125 142 string_header_update ("header_update.rf64", SF_FORMAT_RF64) ;
cannam@125 143 */
cannam@125 144 test_count++ ;
cannam@125 145 } ;
cannam@125 146
cannam@125 147 if (do_all || ! strcmp (argv [1], "w64"))
cannam@125 148 { puts ("\n\n **** String test not working yet for W64 format. ****\n") ;
cannam@125 149 /*
cannam@125 150 string_start_test ("strings.w64", SF_FORMAT_W64) ;
cannam@125 151 string_start_end_test ("strings.w64", SF_FORMAT_W64) ;
cannam@125 152 string_multi_set_test ("multi.w64", SF_FORMAT_W64) ;
cannam@125 153 string_rdwr_test ("rdwr.w64", SF_FORMAT_W64) ;
cannam@125 154 string_short_rdwr_test ("short_rdwr.w64", SF_FORMAT_W64) ;
cannam@125 155 string_header_update ("header_update.w64", SF_FORMAT_W64) ;
cannam@125 156 */
cannam@125 157 test_count++ ;
cannam@125 158 } ;
cannam@125 159
cannam@125 160 if (test_count == 0)
cannam@125 161 { printf ("Mono : ************************************\n") ;
cannam@125 162 printf ("Mono : * No '%s' test defined.\n", argv [1]) ;
cannam@125 163 printf ("Mono : ************************************\n") ;
cannam@125 164 return 1 ;
cannam@125 165 } ;
cannam@125 166
cannam@125 167 return 0 ;
cannam@125 168 } /* main */
cannam@125 169
cannam@125 170
cannam@125 171 /*============================================================================================
cannam@125 172 ** Here are the test functions.
cannam@125 173 */
cannam@125 174
cannam@125 175 static const char
cannam@125 176 software [] = "software (libsndfile-X.Y.Z)",
cannam@125 177 artist [] = "The Artist",
cannam@125 178 copyright [] = "Copyright (c) 2001 Artist",
cannam@125 179 comment [] = "Comment goes here!!!",
cannam@125 180 date [] = "2001/01/27",
cannam@125 181 album [] = "The Album",
cannam@125 182 license [] = "The license",
cannam@125 183 title [] = "This is the title",
cannam@125 184 long_title [] = "This is a very long and very boring title for this file",
cannam@125 185 long_artist [] = "The artist who kept on changing its name",
cannam@125 186 genre [] = "The genre",
cannam@125 187 trackno [] = "Track three" ;
cannam@125 188
cannam@125 189
cannam@125 190 static short data_out [BUFFER_LEN] ;
cannam@125 191
cannam@125 192 static void
cannam@125 193 string_start_end_test (const char *filename, int typemajor)
cannam@125 194 { const char *cptr ;
cannam@125 195 SNDFILE *file ;
cannam@125 196 SF_INFO sfinfo ;
cannam@125 197 int errors = 0 ;
cannam@125 198
cannam@125 199 print_test_name ("string_start_end_test", filename) ;
cannam@125 200
cannam@125 201 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 202 sfinfo.samplerate = 44100 ;
cannam@125 203 sfinfo.channels = 1 ;
cannam@125 204 sfinfo.frames = 0 ;
cannam@125 205 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 206
cannam@125 207 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 208
cannam@125 209 /* Write stuff at start of file. */
cannam@125 210 sf_set_string (file, SF_STR_TITLE, filename) ;
cannam@125 211 sf_set_string (file, SF_STR_SOFTWARE, software) ;
cannam@125 212 sf_set_string (file, SF_STR_ARTIST, artist) ;
cannam@125 213 sf_set_string (file, SF_STR_GENRE, genre) ;
cannam@125 214 sf_set_string (file, SF_STR_TRACKNUMBER, trackno) ;
cannam@125 215
cannam@125 216 /* Write data to file. */
cannam@125 217 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 218 test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
cannam@125 219
cannam@125 220 /* Write more stuff at end of file. */
cannam@125 221 sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
cannam@125 222 sf_set_string (file, SF_STR_COMMENT, comment) ;
cannam@125 223 sf_set_string (file, SF_STR_DATE, date) ;
cannam@125 224 sf_set_string (file, SF_STR_ALBUM, album) ;
cannam@125 225 sf_set_string (file, SF_STR_LICENSE, license) ;
cannam@125 226
cannam@125 227 sf_close (file) ;
cannam@125 228
cannam@125 229 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 230
cannam@125 231 check_log_buffer_or_die (file, __LINE__) ;
cannam@125 232
cannam@125 233 if (sfinfo.frames != BUFFER_LEN)
cannam@125 234 { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ;
cannam@125 235 errors ++ ;
cannam@125 236 } ;
cannam@125 237
cannam@125 238 cptr = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 239 if (cptr == NULL || strcmp (filename, cptr) != 0)
cannam@125 240 { if (errors++ == 0)
cannam@125 241 puts ("\n") ;
cannam@125 242 printf (" Bad filename : %s\n", cptr) ;
cannam@125 243 } ;
cannam@125 244
cannam@125 245 cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
cannam@125 246 if (cptr == NULL || strcmp (copyright, cptr) != 0)
cannam@125 247 { if (errors++ == 0)
cannam@125 248 puts ("\n") ;
cannam@125 249 printf (" Bad copyright : %s\n", cptr) ;
cannam@125 250 } ;
cannam@125 251
cannam@125 252 cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
cannam@125 253 if (cptr == NULL || strstr (cptr, software) != cptr)
cannam@125 254 { if (errors++ == 0)
cannam@125 255 puts ("\n") ;
cannam@125 256 printf (" Bad software : %s\n", cptr) ;
cannam@125 257 } ;
cannam@125 258
cannam@125 259 if (str_count (cptr, "libsndfile") != 1)
cannam@125 260 { if (errors++ == 0)
cannam@125 261 puts ("\n") ;
cannam@125 262 printf (" Bad software : %s\n", cptr) ;
cannam@125 263 } ;
cannam@125 264
cannam@125 265 cptr = sf_get_string (file, SF_STR_ARTIST) ;
cannam@125 266 if (cptr == NULL || strcmp (artist, cptr) != 0)
cannam@125 267 { if (errors++ == 0)
cannam@125 268 puts ("\n") ;
cannam@125 269 printf (" Bad artist : %s\n", cptr) ;
cannam@125 270 } ;
cannam@125 271
cannam@125 272 cptr = sf_get_string (file, SF_STR_COMMENT) ;
cannam@125 273 if (cptr == NULL || strcmp (comment, cptr) != 0)
cannam@125 274 { if (errors++ == 0)
cannam@125 275 puts ("\n") ;
cannam@125 276 printf (" Bad comment : %s\n", cptr) ;
cannam@125 277 } ;
cannam@125 278
cannam@125 279 if (typemajor != SF_FORMAT_AIFF)
cannam@125 280 { cptr = sf_get_string (file, SF_STR_DATE) ;
cannam@125 281 if (cptr == NULL || strcmp (date, cptr) != 0)
cannam@125 282 { if (errors++ == 0)
cannam@125 283 puts ("\n") ;
cannam@125 284 printf (" Bad date : %s\n", cptr) ;
cannam@125 285 } ;
cannam@125 286
cannam@125 287 cptr = sf_get_string (file, SF_STR_GENRE) ;
cannam@125 288 if (cptr == NULL || strcmp (genre, cptr) != 0)
cannam@125 289 { if (errors++ == 0)
cannam@125 290 puts ("\n") ;
cannam@125 291 printf (" Bad genre : %s\n", cptr) ;
cannam@125 292 } ;
cannam@125 293 } ;
cannam@125 294
cannam@125 295 switch (typemajor)
cannam@125 296 { case SF_FORMAT_AIFF :
cannam@125 297 case SF_FORMAT_WAV :
cannam@125 298 case SF_FORMAT_WAVEX :
cannam@125 299 case SF_ENDIAN_BIG | SF_FORMAT_WAV :
cannam@125 300 case SF_FORMAT_RF64 :
cannam@125 301 /* These formats do not support the following. */
cannam@125 302 break ;
cannam@125 303
cannam@125 304 default :
cannam@125 305 cptr = sf_get_string (file, SF_STR_ALBUM) ;
cannam@125 306 if (cptr == NULL || strcmp (album, cptr) != 0)
cannam@125 307 { if (errors++ == 0)
cannam@125 308 puts ("\n") ;
cannam@125 309 printf (" Bad album : %s\n", cptr) ;
cannam@125 310 } ;
cannam@125 311
cannam@125 312 cptr = sf_get_string (file, SF_STR_LICENSE) ;
cannam@125 313 if (cptr == NULL || strcmp (license, cptr) != 0)
cannam@125 314 { if (errors++ == 0)
cannam@125 315 puts ("\n") ;
cannam@125 316 printf (" Bad license : %s\n", cptr) ;
cannam@125 317 } ;
cannam@125 318
cannam@125 319 cptr = sf_get_string (file, SF_STR_TRACKNUMBER) ;
cannam@125 320 if (cptr == NULL || strcmp (trackno, cptr) != 0)
cannam@125 321 { if (errors++ == 0)
cannam@125 322 puts ("\n") ;
cannam@125 323 printf (" Bad track no. : %s\n", cptr) ;
cannam@125 324 } ;
cannam@125 325 break ;
cannam@125 326 } ;
cannam@125 327
cannam@125 328 if (errors > 0)
cannam@125 329 { printf ("\n*** Error count : %d ***\n\n", errors) ;
cannam@125 330 dump_log_buffer (file) ;
cannam@125 331 exit (1) ;
cannam@125 332 } ;
cannam@125 333
cannam@125 334 sf_close (file) ;
cannam@125 335 unlink (filename) ;
cannam@125 336
cannam@125 337 puts ("ok") ;
cannam@125 338 } /* string_start_end_test */
cannam@125 339
cannam@125 340 static void
cannam@125 341 string_start_test (const char *filename, int typemajor)
cannam@125 342 { const char *cptr ;
cannam@125 343 SNDFILE *file ;
cannam@125 344 SF_INFO sfinfo ;
cannam@125 345 int errors = 0 ;
cannam@125 346
cannam@125 347 print_test_name ("string_start_test", filename) ;
cannam@125 348
cannam@125 349 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 350 sfinfo.samplerate = 44100 ;
cannam@125 351 sfinfo.channels = 1 ;
cannam@125 352 sfinfo.frames = 0 ;
cannam@125 353
cannam@125 354 switch (typemajor)
cannam@125 355 { case SF_FORMAT_OGG :
cannam@125 356 sfinfo.format = typemajor | SF_FORMAT_VORBIS ;
cannam@125 357 break ;
cannam@125 358
cannam@125 359 default :
cannam@125 360 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 361 break ;
cannam@125 362 } ;
cannam@125 363
cannam@125 364 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 365
cannam@125 366 /* Write stuff at start of file. */
cannam@125 367 sf_set_string (file, SF_STR_TITLE, filename) ;
cannam@125 368 sf_set_string (file, SF_STR_SOFTWARE, software) ;
cannam@125 369 sf_set_string (file, SF_STR_ARTIST, artist) ;
cannam@125 370 sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
cannam@125 371 sf_set_string (file, SF_STR_COMMENT, comment) ;
cannam@125 372 sf_set_string (file, SF_STR_DATE, date) ;
cannam@125 373 sf_set_string (file, SF_STR_ALBUM, album) ;
cannam@125 374 sf_set_string (file, SF_STR_LICENSE, license) ;
cannam@125 375
cannam@125 376 /* Write data to file. */
cannam@125 377 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 378
cannam@125 379 sf_close (file) ;
cannam@125 380
cannam@125 381 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 382
cannam@125 383 check_log_buffer_or_die (file, __LINE__) ;
cannam@125 384
cannam@125 385 if (sfinfo.frames != BUFFER_LEN)
cannam@125 386 { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo.frames, BUFFER_LEN) ;
cannam@125 387 errors ++ ;
cannam@125 388 } ;
cannam@125 389
cannam@125 390 cptr = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 391 if (cptr == NULL || strcmp (filename, cptr) != 0)
cannam@125 392 { if (errors++ == 0)
cannam@125 393 puts ("\n") ;
cannam@125 394 printf (" Bad filename : %s\n", cptr) ;
cannam@125 395 } ;
cannam@125 396
cannam@125 397 cptr = sf_get_string (file, SF_STR_COPYRIGHT) ;
cannam@125 398 if (cptr == NULL || strcmp (copyright, cptr) != 0)
cannam@125 399 { if (errors++ == 0)
cannam@125 400 puts ("\n") ;
cannam@125 401 printf (" Bad copyright : %s\n", cptr) ;
cannam@125 402 } ;
cannam@125 403
cannam@125 404 cptr = sf_get_string (file, SF_STR_SOFTWARE) ;
cannam@125 405 if (cptr == NULL || strstr (cptr, software) != cptr)
cannam@125 406 { if (errors++ == 0)
cannam@125 407 puts ("\n") ;
cannam@125 408 printf (" Bad software : %s\n", cptr) ;
cannam@125 409 } ;
cannam@125 410
cannam@125 411 if (cptr && str_count (cptr, "libsndfile") != 1)
cannam@125 412 { if (errors++ == 0)
cannam@125 413 puts ("\n") ;
cannam@125 414 printf (" Bad software : %s\n", cptr) ;
cannam@125 415 } ;
cannam@125 416
cannam@125 417 cptr = sf_get_string (file, SF_STR_ARTIST) ;
cannam@125 418 if (cptr == NULL || strcmp (artist, cptr) != 0)
cannam@125 419 { if (errors++ == 0)
cannam@125 420 puts ("\n") ;
cannam@125 421 printf (" Bad artist : %s\n", cptr) ;
cannam@125 422 } ;
cannam@125 423
cannam@125 424 cptr = sf_get_string (file, SF_STR_COMMENT) ;
cannam@125 425 if (cptr == NULL || strcmp (comment, cptr) != 0)
cannam@125 426 { if (errors++ == 0)
cannam@125 427 puts ("\n") ;
cannam@125 428 printf (" Bad comment : %s\n", cptr) ;
cannam@125 429 } ;
cannam@125 430
cannam@125 431 if (typemajor != SF_FORMAT_AIFF)
cannam@125 432 { cptr = sf_get_string (file, SF_STR_DATE) ;
cannam@125 433 if (cptr == NULL || strcmp (date, cptr) != 0)
cannam@125 434 { if (errors++ == 0)
cannam@125 435 puts ("\n") ;
cannam@125 436 printf (" Bad date : %s\n", cptr) ;
cannam@125 437 } ;
cannam@125 438 } ;
cannam@125 439
cannam@125 440 if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF)
cannam@125 441 { cptr = sf_get_string (file, SF_STR_ALBUM) ;
cannam@125 442 if (cptr == NULL || strcmp (album, cptr) != 0)
cannam@125 443 { if (errors++ == 0)
cannam@125 444 puts ("\n") ;
cannam@125 445 printf (" Bad album : %s\n", cptr) ;
cannam@125 446 } ;
cannam@125 447 } ;
cannam@125 448
cannam@125 449 if (typemajor != SF_FORMAT_WAV && typemajor != SF_FORMAT_AIFF && typemajor != SF_FORMAT_RF64)
cannam@125 450 { cptr = sf_get_string (file, SF_STR_LICENSE) ;
cannam@125 451 if (cptr == NULL || strcmp (license, cptr) != 0)
cannam@125 452 { if (errors++ == 0)
cannam@125 453 puts ("\n") ;
cannam@125 454 printf (" Bad license : %s\n", cptr) ;
cannam@125 455 } ;
cannam@125 456 } ;
cannam@125 457
cannam@125 458 if (errors > 0)
cannam@125 459 { printf ("\n*** Error count : %d ***\n\n", errors) ;
cannam@125 460 dump_log_buffer (file) ;
cannam@125 461 exit (1) ;
cannam@125 462 } ;
cannam@125 463
cannam@125 464 sf_close (file) ;
cannam@125 465 unlink (filename) ;
cannam@125 466
cannam@125 467 puts ("ok") ;
cannam@125 468 } /* string_start_test */
cannam@125 469
cannam@125 470 static void
cannam@125 471 string_multi_set_test (const char *filename, int typemajor)
cannam@125 472 { static const char
cannam@125 473 new_software [] = "new software (libsndfile-X.Y.Z)",
cannam@125 474 new_copyright [] = "Copyright (c) 2001 New Artist",
cannam@125 475 new_artist [] = "The New Artist",
cannam@125 476 new_title [] = "This is the new title" ;
cannam@125 477
cannam@125 478 static char buffer [2048] ;
cannam@125 479 SNDFILE *file ;
cannam@125 480 SF_INFO sfinfo ;
cannam@125 481 int count ;
cannam@125 482
cannam@125 483 print_test_name (__func__, filename) ;
cannam@125 484
cannam@125 485 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 486 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 487 sfinfo.samplerate = 44100 ;
cannam@125 488 sfinfo.channels = 1 ;
cannam@125 489 sfinfo.frames = 0 ;
cannam@125 490
cannam@125 491 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 492
cannam@125 493 /* Write stuff at start of file. */
cannam@125 494 sf_set_string (file, SF_STR_TITLE, title) ;
cannam@125 495 sf_set_string (file, SF_STR_SOFTWARE, software) ;
cannam@125 496 sf_set_string (file, SF_STR_ARTIST, artist) ;
cannam@125 497
cannam@125 498 /* Write data to file. */
cannam@125 499 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 500
cannam@125 501 /* Write it all again. */
cannam@125 502
cannam@125 503 sf_set_string (file, SF_STR_TITLE, new_title) ;
cannam@125 504 sf_set_string (file, SF_STR_SOFTWARE, new_software) ;
cannam@125 505 sf_set_string (file, SF_STR_ARTIST, new_artist) ;
cannam@125 506
cannam@125 507 sf_set_string (file, SF_STR_COPYRIGHT, copyright) ;
cannam@125 508 sf_set_string (file, SF_STR_COMMENT, comment) ;
cannam@125 509 sf_set_string (file, SF_STR_DATE, date) ;
cannam@125 510 sf_set_string (file, SF_STR_ALBUM, album) ;
cannam@125 511 sf_set_string (file, SF_STR_LICENSE, license) ;
cannam@125 512 sf_set_string (file, SF_STR_COPYRIGHT, new_copyright) ;
cannam@125 513 sf_set_string (file, SF_STR_COMMENT, comment) ;
cannam@125 514 sf_set_string (file, SF_STR_DATE, date) ;
cannam@125 515 sf_set_string (file, SF_STR_ALBUM, album) ;
cannam@125 516 sf_set_string (file, SF_STR_LICENSE, license) ;
cannam@125 517
cannam@125 518 sf_close (file) ;
cannam@125 519
cannam@125 520 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 521 sf_command (file, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
cannam@125 522 sf_close (file) ;
cannam@125 523
cannam@125 524 count = str_count (buffer, new_title) ;
cannam@125 525 exit_if_true (count < 1, "\n\nLine %d : Could not find new_title in :\n%s\n", __LINE__, buffer) ;
cannam@125 526 exit_if_true (count > 1, "\n\nLine %d : new_title appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
cannam@125 527
cannam@125 528 count = str_count (buffer, software) ;
cannam@125 529 exit_if_true (count < 1, "\n\nLine %d : Could not find new_software in :\n%s\n", __LINE__, buffer) ;
cannam@125 530 exit_if_true (count > 1, "\n\nLine %d : new_software appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
cannam@125 531
cannam@125 532 count = str_count (buffer, new_artist) ;
cannam@125 533 exit_if_true (count < 1, "\n\nLine %d : Could not find new_artist in :\n%s\n", __LINE__, buffer) ;
cannam@125 534 exit_if_true (count > 1, "\n\nLine %d : new_artist appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
cannam@125 535
cannam@125 536 count = str_count (buffer, new_copyright) ;
cannam@125 537 exit_if_true (count < 1, "\n\nLine %d : Could not find new_copyright in :\n%s\n", __LINE__, buffer) ;
cannam@125 538 exit_if_true (count > 1, "\n\nLine %d : new_copyright appears %d times in :\n\n%s\n", __LINE__, count, buffer) ;
cannam@125 539
cannam@125 540 unlink (filename) ;
cannam@125 541
cannam@125 542 puts ("ok") ;
cannam@125 543 } /* string_multi_set_test */
cannam@125 544
cannam@125 545 static void
cannam@125 546 string_rdwr_test (const char *filename, int typemajor)
cannam@125 547 { SNDFILE *file ;
cannam@125 548 SF_INFO sfinfo ;
cannam@125 549 sf_count_t frames ;
cannam@125 550 const char * str ;
cannam@125 551
cannam@125 552 print_test_name (__func__, filename) ;
cannam@125 553 create_short_sndfile (filename, typemajor | SF_FORMAT_PCM_16, 2) ;
cannam@125 554
cannam@125 555 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 556 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 557 frames = sfinfo.frames ;
cannam@125 558 sf_set_string (file, SF_STR_TITLE, title) ;
cannam@125 559 sf_close (file) ;
cannam@125 560
cannam@125 561 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 562 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
cannam@125 563 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 564 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 565 exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 566 sf_close (file) ;
cannam@125 567
cannam@125 568 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 569 frames = sfinfo.frames ;
cannam@125 570 sf_set_string (file, SF_STR_TITLE, title) ;
cannam@125 571 sf_close (file) ;
cannam@125 572
cannam@125 573 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 574 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 575 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 576 sf_set_string (file, SF_STR_ARTIST, artist) ;
cannam@125 577 sf_close (file) ;
cannam@125 578
cannam@125 579 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 580
cannam@125 581 str = sf_get_string (file, SF_STR_ARTIST) ;
cannam@125 582 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ;
cannam@125 583 exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
cannam@125 584
cannam@125 585 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 586 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 587 exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 588
cannam@125 589 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
cannam@125 590
cannam@125 591 sf_close (file) ;
cannam@125 592 unlink (filename) ;
cannam@125 593
cannam@125 594 puts ("ok") ;
cannam@125 595 } /* string_rdwr_test */
cannam@125 596
cannam@125 597 static void
cannam@125 598 string_short_rdwr_test (const char *filename, int typemajor)
cannam@125 599 { SNDFILE *file ;
cannam@125 600 SF_INFO sfinfo ;
cannam@125 601 sf_count_t frames = BUFFER_LEN ;
cannam@125 602 const char * str ;
cannam@125 603
cannam@125 604 print_test_name (__func__, filename) ;
cannam@125 605
cannam@125 606 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 607 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 608 sfinfo.samplerate = 44100 ;
cannam@125 609 sfinfo.channels = 1 ;
cannam@125 610 sfinfo.frames = 0 ;
cannam@125 611
cannam@125 612 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 613
cannam@125 614 /* Write data to file. */
cannam@125 615 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 616
cannam@125 617 sf_set_string (file, SF_STR_TITLE, long_title) ;
cannam@125 618 sf_set_string (file, SF_STR_ARTIST, long_artist) ;
cannam@125 619 sf_close (file) ;
cannam@125 620
cannam@125 621 /* Open the file RDWR. */
cannam@125 622 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 623 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
cannam@125 624 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 625 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 626 exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 627 str = sf_get_string (file, SF_STR_ARTIST) ;
cannam@125 628 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 629 exit_if_true (strcmp (str, long_artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
cannam@125 630
cannam@125 631 /* Change title and artist. */
cannam@125 632 sf_set_string (file, SF_STR_TITLE, title) ;
cannam@125 633 sf_set_string (file, SF_STR_ARTIST, artist) ;
cannam@125 634
cannam@125 635 sf_close (file) ;
cannam@125 636
cannam@125 637 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_FALSE, __LINE__) ;
cannam@125 638
cannam@125 639 check_log_buffer_or_die (file, __LINE__) ;
cannam@125 640
cannam@125 641 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 642 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 643 exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 644
cannam@125 645 str = sf_get_string (file, SF_STR_ARTIST) ;
cannam@125 646 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_ARTIST string is NULL.\n", __LINE__) ;
cannam@125 647 exit_if_true (strcmp (str, artist) != 0, "\n\nLine %d : SF_STR_ARTIST doesn't match what was written.\n", __LINE__) ;
cannam@125 648
cannam@125 649 sf_close (file) ;
cannam@125 650 unlink (filename) ;
cannam@125 651
cannam@125 652 puts ("ok") ;
cannam@125 653 } /* string_short_rdwr_test */
cannam@125 654
cannam@125 655 static int
cannam@125 656 str_count (const char * haystack, const char * needle)
cannam@125 657 { int count = 0 ;
cannam@125 658
cannam@125 659 while ((haystack = strstr (haystack, needle)) != NULL)
cannam@125 660 { count ++ ;
cannam@125 661 haystack ++ ;
cannam@125 662 } ;
cannam@125 663
cannam@125 664 return count ;
cannam@125 665 } /* str_count */
cannam@125 666
cannam@125 667 #define MIN(a, b) ((a) < (b) ? (a) : (b))
cannam@125 668
cannam@125 669 static void
cannam@125 670 software_string_test (const char *filename)
cannam@125 671 { size_t k ;
cannam@125 672
cannam@125 673 print_test_name (__func__, filename) ;
cannam@125 674
cannam@125 675 for (k = 0 ; k < 50 ; k++)
cannam@125 676 { const char *result ;
cannam@125 677 char sfname [64] = "" ;
cannam@125 678 SNDFILE *file ;
cannam@125 679 SF_INFO info ;
cannam@125 680
cannam@125 681 sf_info_setup (&info, SF_FORMAT_WAV | SF_FORMAT_PCM_16, 44100, 1) ;
cannam@125 682 file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_TRUE, __LINE__) ;
cannam@125 683
cannam@125 684 snprintf (sfname, MIN (k, sizeof (sfname)), "%s", "abcdefghijklmnopqrestvwxyz0123456789abcdefghijklmnopqrestvwxyz") ;
cannam@125 685
cannam@125 686 exit_if_true (sf_set_string (file, SF_STR_SOFTWARE, sfname),
cannam@125 687 "\n\nLine %d : sf_set_string (f, SF_STR_SOFTWARE, '%s') failed : %s\n", __LINE__, sfname, sf_strerror (file)) ;
cannam@125 688
cannam@125 689 sf_close (file) ;
cannam@125 690
cannam@125 691 file = test_open_file_or_die (filename, SFM_READ, &info, SF_TRUE, __LINE__) ;
cannam@125 692 result = sf_get_string (file, SF_STR_SOFTWARE) ;
cannam@125 693
cannam@125 694 exit_if_true (result == NULL, "\n\nLine %d : sf_get_string (file, SF_STR_SOFTWARE) returned NULL.\n\n", __LINE__) ;
cannam@125 695
cannam@125 696 exit_if_true (strstr (result, sfname) != result,
cannam@125 697 "\n\nLine %d : Can't fine string '%s' in '%s'\n\n", __LINE__, sfname, result) ;
cannam@125 698 sf_close (file) ;
cannam@125 699 } ;
cannam@125 700
cannam@125 701 unlink (filename) ;
cannam@125 702 puts ("ok") ;
cannam@125 703 } /* software_string_test */
cannam@125 704
cannam@125 705
cannam@125 706 static void
cannam@125 707 string_rdwr_grow_test (const char *filename, int typemajor)
cannam@125 708 { SNDFILE *file ;
cannam@125 709 SF_INFO sfinfo ;
cannam@125 710 sf_count_t frames ;
cannam@125 711 const char * str ;
cannam@125 712
cannam@125 713 print_test_name (__func__, filename) ;
cannam@125 714
cannam@125 715 /* Create a file that contains some strings. Then open the file in RDWR mode and
cannam@125 716 grow the file by writing more audio data to it. Check that the audio data has
cannam@125 717 been added to the file, and that the strings are still there. */
cannam@125 718
cannam@125 719 /* Create a short file that contains a string. */
cannam@125 720 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 721 sfinfo.samplerate = 44100 ;
cannam@125 722 sfinfo.channels = 2 ;
cannam@125 723 sfinfo.frames = 0 ;
cannam@125 724 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 725
cannam@125 726 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 727 /* Write data to file. */
cannam@125 728 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 729
cannam@125 730 /* Write some strings at end of file. */
cannam@125 731 sf_set_string (file, SF_STR_TITLE , title) ;
cannam@125 732 sf_set_string (file, SF_STR_COMMENT, comment) ;
cannam@125 733 sf_close (file) ;
cannam@125 734
cannam@125 735
cannam@125 736 /* Now open file again in SFM_RDWR mode and write more audio data to it. */
cannam@125 737 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 738 /* Write more data to file. */
cannam@125 739 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 740 sf_close (file) ;
cannam@125 741
cannam@125 742
cannam@125 743 /* Now open file again. It should now contain two BUFFER_LEN's worth of frames and the strings. */
cannam@125 744 frames = 2 * BUFFER_LEN / sfinfo.channels ;
cannam@125 745 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 746 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
cannam@125 747
cannam@125 748 /* Check the strings */
cannam@125 749 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 750 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 751 exit_if_true (strcmp (str, title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 752
cannam@125 753 str = sf_get_string (file, SF_STR_COMMENT) ;
cannam@125 754 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_COMMENT string is NULL.\n", __LINE__) ;
cannam@125 755 exit_if_true (strcmp (str, comment) != 0, "\n\nLine %d : SF_STR_COMMENT doesn't match what was written.\n", __LINE__) ;
cannam@125 756
cannam@125 757 sf_close (file) ;
cannam@125 758 unlink (filename) ;
cannam@125 759
cannam@125 760 puts ("ok") ;
cannam@125 761 } /* string_rdwr_grow_test */
cannam@125 762
cannam@125 763 static void
cannam@125 764 string_header_update (const char *filename, int typemajor)
cannam@125 765 { SNDFILE *file , *file1 ;
cannam@125 766 SF_INFO sfinfo , sfinfo1 ;
cannam@125 767 sf_count_t frames ;
cannam@125 768 const char * str ;
cannam@125 769 const int GROW_BUFFER_AMOUNT = 4 ; /* this should be less than half the size of the string header */
cannam@125 770
cannam@125 771 print_test_name (__func__, filename) ;
cannam@125 772
cannam@125 773 /* Create a short file. */
cannam@125 774 memset (&sfinfo, 0, sizeof (sfinfo)) ;
cannam@125 775 sfinfo.samplerate = 44100 ;
cannam@125 776 sfinfo.channels = 2 ;
cannam@125 777 sfinfo.frames = 0 ;
cannam@125 778 sfinfo.format = typemajor | SF_FORMAT_PCM_16 ;
cannam@125 779
cannam@125 780 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 781 test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
cannam@125 782 sf_set_string (file, SF_STR_TITLE, long_title) ;
cannam@125 783 sf_close (file) ;
cannam@125 784
cannam@125 785
cannam@125 786 /* Check that SFC_UPDATE_HEADER_NOW correctly calculates datalength. */
cannam@125 787 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 788 /* Write a very small amount of new audio data that doesn't completely overwrite the existing header. */
cannam@125 789 test_write_short_or_die (file, 0, data_out, GROW_BUFFER_AMOUNT, __LINE__) ;
cannam@125 790
cannam@125 791 /* Update the header without closing the file. */
cannam@125 792 sf_command (file, SFC_UPDATE_HEADER_NOW, NULL, 0) ;
cannam@125 793
cannam@125 794 /* The file should now contain BUFFER_LEN + GROW_BUFFER_AMOUNT frames.
cannam@125 795 Open a second handle to the file and check the reported length. */
cannam@125 796 memset (&sfinfo1, 0, sizeof (sfinfo1)) ;
cannam@125 797 file1 = test_open_file_or_die (filename, SFM_READ, &sfinfo1, SF_TRUE, __LINE__) ;
cannam@125 798
cannam@125 799 frames = (BUFFER_LEN + GROW_BUFFER_AMOUNT) / sfinfo.channels ;
cannam@125 800 exit_if_true (frames != sfinfo1.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo1.frames, frames) ;
cannam@125 801
cannam@125 802 /* The strings are probably not readable by the second soundfile handle because write_tailer has not yet been called.
cannam@125 803 It's a design decision whether SFC_UPDATE_HEADER_NOW should write the tailer. I think it's fine that it doesn't. */
cannam@125 804
cannam@125 805 sf_close (file1) ;
cannam@125 806 sf_close (file) ;
cannam@125 807
cannam@125 808
cannam@125 809 /* Check that sf_close correctly calculates datalength. */
cannam@125 810 file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 811 /* Write a very small amount of new audio data that doesn't completely overwrite the existing header. */
cannam@125 812 test_write_short_or_die (file, 0, data_out, GROW_BUFFER_AMOUNT, __LINE__) ;
cannam@125 813 sf_close (file) ;
cannam@125 814
cannam@125 815
cannam@125 816 /* Open file again and verify data and string. */
cannam@125 817 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
cannam@125 818 frames = (BUFFER_LEN + 2*GROW_BUFFER_AMOUNT) / sfinfo.channels ;
cannam@125 819 exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
cannam@125 820 str = sf_get_string (file, SF_STR_TITLE) ;
cannam@125 821 exit_if_true (str == NULL, "\n\nLine %d : SF_STR_TITLE string is NULL.\n", __LINE__) ;
cannam@125 822 exit_if_true (strcmp (str, long_title) != 0, "\n\nLine %d : SF_STR_TITLE doesn't match what was written.\n", __LINE__) ;
cannam@125 823 sf_close (file) ;
cannam@125 824 unlink (filename) ;
cannam@125 825 puts ("ok") ;
cannam@125 826 } /* string_header_update */