annotate src/libsndfile-1.0.27/tests/string_test.c @ 84:08ae793730bd

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