1b815c7f3Sopenharmony_ci/* 2b815c7f3Sopenharmony_ci** Copyright (C) 2001-2017 Erik de Castro Lopo <erikd@mega-nerd.com> 3b815c7f3Sopenharmony_ci** 4b815c7f3Sopenharmony_ci** This program is free software ; you can redistribute it and/or modify 5b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by 6b815c7f3Sopenharmony_ci** the Free Software Foundation ; either version 2 of the License, or 7b815c7f3Sopenharmony_ci** (at your option) any later version. 8b815c7f3Sopenharmony_ci** 9b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful, 10b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY ; without even the implied warranty of 11b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12b815c7f3Sopenharmony_ci** GNU General Public License for more details. 13b815c7f3Sopenharmony_ci** 14b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License 15b815c7f3Sopenharmony_ci** along with this program ; if not, write to the Free Software 16b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17b815c7f3Sopenharmony_ci*/ 18b815c7f3Sopenharmony_ci 19b815c7f3Sopenharmony_ci#include "sfconfig.h" 20b815c7f3Sopenharmony_ci 21b815c7f3Sopenharmony_ci#include <stdio.h> 22b815c7f3Sopenharmony_ci#include <stdlib.h> 23b815c7f3Sopenharmony_ci#include <string.h> 24b815c7f3Sopenharmony_ci#include <errno.h> 25b815c7f3Sopenharmony_ci#include <inttypes.h> 26b815c7f3Sopenharmony_ci 27b815c7f3Sopenharmony_ci#include <sys/stat.h> 28b815c7f3Sopenharmony_ci#include <math.h> 29b815c7f3Sopenharmony_ci 30b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 31b815c7f3Sopenharmony_ci#include <unistd.h> 32b815c7f3Sopenharmony_ci#endif 33b815c7f3Sopenharmony_ci 34b815c7f3Sopenharmony_ci#if (HAVE_DECL_S_IRGRP == 0) 35b815c7f3Sopenharmony_ci#include <sf_unistd.h> 36b815c7f3Sopenharmony_ci#endif 37b815c7f3Sopenharmony_ci 38b815c7f3Sopenharmony_ci#if (defined (WIN32) || defined (_WIN32)) 39b815c7f3Sopenharmony_ci#include <io.h> 40b815c7f3Sopenharmony_ci#include <direct.h> 41b815c7f3Sopenharmony_ci#endif 42b815c7f3Sopenharmony_ci 43b815c7f3Sopenharmony_ci#include <sndfile.h> 44b815c7f3Sopenharmony_ci 45b815c7f3Sopenharmony_ci#include "utils.h" 46b815c7f3Sopenharmony_ci 47b815c7f3Sopenharmony_ci#define BUFFER_LEN (1 << 10) 48b815c7f3Sopenharmony_ci#define LOG_BUFFER_SIZE 1024 49b815c7f3Sopenharmony_ci 50b815c7f3Sopenharmony_cistatic void zero_data_test (const char *filename, int format) ; 51b815c7f3Sopenharmony_cistatic void filesystem_full_test (int format) ; 52b815c7f3Sopenharmony_cistatic void permission_test (const char *filename, int typemajor) ; 53b815c7f3Sopenharmony_cistatic void wavex_amb_test (const char *filename) ; 54b815c7f3Sopenharmony_cistatic void rf64_downgrade_test (const char *filename) ; 55b815c7f3Sopenharmony_cistatic void rf64_long_file_downgrade_test (const char *filename) ; 56b815c7f3Sopenharmony_ci 57b815c7f3Sopenharmony_ciint 58b815c7f3Sopenharmony_cimain (int argc, char *argv []) 59b815c7f3Sopenharmony_ci{ int do_all = 0 ; 60b815c7f3Sopenharmony_ci int test_count = 0 ; 61b815c7f3Sopenharmony_ci 62b815c7f3Sopenharmony_ci if (argc != 2) 63b815c7f3Sopenharmony_ci { printf ("Usage : %s <test>\n", argv [0]) ; 64b815c7f3Sopenharmony_ci printf (" Where <test> is one of the following:\n") ; 65b815c7f3Sopenharmony_ci printf (" wav - test WAV file peak chunk\n") ; 66b815c7f3Sopenharmony_ci printf (" aiff - test AIFF file PEAK chunk\n") ; 67b815c7f3Sopenharmony_ci printf (" all - perform all tests\n") ; 68b815c7f3Sopenharmony_ci exit (1) ; 69b815c7f3Sopenharmony_ci } ; 70b815c7f3Sopenharmony_ci 71b815c7f3Sopenharmony_ci do_all = ! strcmp (argv [1], "all") ; 72b815c7f3Sopenharmony_ci 73b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "wav")) 74b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; 75b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; 76b815c7f3Sopenharmony_ci permission_test ("readonly.wav", SF_FORMAT_WAV) ; 77b815c7f3Sopenharmony_ci wavex_amb_test ("ambisonic.wav") ; 78b815c7f3Sopenharmony_ci test_count++ ; 79b815c7f3Sopenharmony_ci } ; 80b815c7f3Sopenharmony_ci 81b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "aiff")) 82b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ; 83b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ; 84b815c7f3Sopenharmony_ci permission_test ("readonly.aiff", SF_FORMAT_AIFF) ; 85b815c7f3Sopenharmony_ci test_count++ ; 86b815c7f3Sopenharmony_ci } ; 87b815c7f3Sopenharmony_ci 88b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "au")) 89b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.au", SF_FORMAT_AU | SF_FORMAT_PCM_16) ; 90b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_AU | SF_FORMAT_PCM_16) ; 91b815c7f3Sopenharmony_ci permission_test ("readonly.au", SF_FORMAT_AU) ; 92b815c7f3Sopenharmony_ci test_count++ ; 93b815c7f3Sopenharmony_ci } ; 94b815c7f3Sopenharmony_ci 95b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "caf")) 96b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.caf", SF_FORMAT_CAF | SF_FORMAT_PCM_16) ; 97b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_CAF | SF_FORMAT_PCM_16) ; 98b815c7f3Sopenharmony_ci permission_test ("readonly.caf", SF_FORMAT_CAF) ; 99b815c7f3Sopenharmony_ci test_count++ ; 100b815c7f3Sopenharmony_ci } ; 101b815c7f3Sopenharmony_ci 102b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "svx")) 103b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ; 104b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_SVX | SF_FORMAT_PCM_16) ; 105b815c7f3Sopenharmony_ci permission_test ("readonly.svx", SF_FORMAT_SVX) ; 106b815c7f3Sopenharmony_ci test_count++ ; 107b815c7f3Sopenharmony_ci } ; 108b815c7f3Sopenharmony_ci 109b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "nist")) 110b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.nist", SF_FORMAT_NIST | SF_FORMAT_PCM_16) ; 111b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_NIST | SF_FORMAT_PCM_16) ; 112b815c7f3Sopenharmony_ci permission_test ("readonly.nist", SF_FORMAT_NIST) ; 113b815c7f3Sopenharmony_ci test_count++ ; 114b815c7f3Sopenharmony_ci } ; 115b815c7f3Sopenharmony_ci 116b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "paf")) 117b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_16) ; 118b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_PAF | SF_FORMAT_PCM_16) ; 119b815c7f3Sopenharmony_ci permission_test ("readonly.paf", SF_FORMAT_PAF) ; 120b815c7f3Sopenharmony_ci test_count++ ; 121b815c7f3Sopenharmony_ci } ; 122b815c7f3Sopenharmony_ci 123b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "ircam")) 124b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.ircam", SF_FORMAT_IRCAM | SF_FORMAT_PCM_16) ; 125b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_IRCAM | SF_FORMAT_PCM_16) ; 126b815c7f3Sopenharmony_ci permission_test ("readonly.ircam", SF_FORMAT_IRCAM) ; 127b815c7f3Sopenharmony_ci test_count++ ; 128b815c7f3Sopenharmony_ci } ; 129b815c7f3Sopenharmony_ci 130b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "voc")) 131b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16) ; 132b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_VOC | SF_FORMAT_PCM_16) ; 133b815c7f3Sopenharmony_ci permission_test ("readonly.voc", SF_FORMAT_VOC) ; 134b815c7f3Sopenharmony_ci test_count++ ; 135b815c7f3Sopenharmony_ci } ; 136b815c7f3Sopenharmony_ci 137b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "w64")) 138b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ; 139b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_W64 | SF_FORMAT_PCM_16) ; 140b815c7f3Sopenharmony_ci permission_test ("readonly.w64", SF_FORMAT_W64) ; 141b815c7f3Sopenharmony_ci test_count++ ; 142b815c7f3Sopenharmony_ci } ; 143b815c7f3Sopenharmony_ci 144b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "rf64")) 145b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; 146b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; 147b815c7f3Sopenharmony_ci permission_test ("readonly.rf64", SF_FORMAT_RF64) ; 148b815c7f3Sopenharmony_ci rf64_downgrade_test ("downgrade.wav") ; 149b815c7f3Sopenharmony_ci /* Disable this by default, because it needs to write 4 gigabytes of data. */ 150b815c7f3Sopenharmony_ci if (SF_FALSE) 151b815c7f3Sopenharmony_ci rf64_long_file_downgrade_test ("no-downgrade.rf64") ; 152b815c7f3Sopenharmony_ci test_count++ ; 153b815c7f3Sopenharmony_ci } ; 154b815c7f3Sopenharmony_ci 155b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat4")) 156b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ; 157b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ; 158b815c7f3Sopenharmony_ci permission_test ("readonly.mat4", SF_FORMAT_MAT4) ; 159b815c7f3Sopenharmony_ci test_count++ ; 160b815c7f3Sopenharmony_ci } ; 161b815c7f3Sopenharmony_ci 162b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat5")) 163b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ; 164b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ; 165b815c7f3Sopenharmony_ci permission_test ("readonly.mat5", SF_FORMAT_MAT5) ; 166b815c7f3Sopenharmony_ci test_count++ ; 167b815c7f3Sopenharmony_ci } ; 168b815c7f3Sopenharmony_ci 169b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "pvf")) 170b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16) ; 171b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_PVF | SF_FORMAT_PCM_16) ; 172b815c7f3Sopenharmony_ci permission_test ("readonly.pvf", SF_FORMAT_PVF) ; 173b815c7f3Sopenharmony_ci test_count++ ; 174b815c7f3Sopenharmony_ci } ; 175b815c7f3Sopenharmony_ci 176b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "htk")) 177b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16) ; 178b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_HTK | SF_FORMAT_PCM_16) ; 179b815c7f3Sopenharmony_ci permission_test ("readonly.htk", SF_FORMAT_HTK) ; 180b815c7f3Sopenharmony_ci test_count++ ; 181b815c7f3Sopenharmony_ci } ; 182b815c7f3Sopenharmony_ci 183b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "avr")) 184b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.avr", SF_FORMAT_AVR | SF_FORMAT_PCM_16) ; 185b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_AVR | SF_FORMAT_PCM_16) ; 186b815c7f3Sopenharmony_ci permission_test ("readonly.avr", SF_FORMAT_AVR) ; 187b815c7f3Sopenharmony_ci test_count++ ; 188b815c7f3Sopenharmony_ci } ; 189b815c7f3Sopenharmony_ci 190b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "sds")) 191b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ; 192b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_SDS | SF_FORMAT_PCM_16) ; 193b815c7f3Sopenharmony_ci permission_test ("readonly.sds", SF_FORMAT_SDS) ; 194b815c7f3Sopenharmony_ci test_count++ ; 195b815c7f3Sopenharmony_ci } ; 196b815c7f3Sopenharmony_ci 197b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mpc2k")) 198b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16) ; 199b815c7f3Sopenharmony_ci filesystem_full_test (SF_FORMAT_MPC2K | SF_FORMAT_PCM_16) ; 200b815c7f3Sopenharmony_ci permission_test ("readonly.mpc", SF_FORMAT_MPC2K) ; 201b815c7f3Sopenharmony_ci test_count++ ; 202b815c7f3Sopenharmony_ci } ; 203b815c7f3Sopenharmony_ci 204b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "ogg")) 205b815c7f3Sopenharmony_ci { zero_data_test ("zerolen.oga", SF_FORMAT_OGG | SF_FORMAT_VORBIS) ; 206b815c7f3Sopenharmony_ci /*-filesystem_full_test (SF_FORMAT_OGG | SF_FORMAT_VORBIS) ;-*/ 207b815c7f3Sopenharmony_ci permission_test ("readonly.oga", SF_FORMAT_OGG) ; 208b815c7f3Sopenharmony_ci test_count++ ; 209b815c7f3Sopenharmony_ci } ; 210b815c7f3Sopenharmony_ci 211b815c7f3Sopenharmony_ci if (test_count == 0) 212b815c7f3Sopenharmony_ci { printf ("Mono : ************************************\n") ; 213b815c7f3Sopenharmony_ci printf ("Mono : * No '%s' test defined.\n", argv [1]) ; 214b815c7f3Sopenharmony_ci printf ("Mono : ************************************\n") ; 215b815c7f3Sopenharmony_ci return 1 ; 216b815c7f3Sopenharmony_ci } ; 217b815c7f3Sopenharmony_ci 218b815c7f3Sopenharmony_ci return 0 ; 219b815c7f3Sopenharmony_ci} /* main */ 220b815c7f3Sopenharmony_ci 221b815c7f3Sopenharmony_ci 222b815c7f3Sopenharmony_ci/*============================================================================================ 223b815c7f3Sopenharmony_ci** Here are the test functions. 224b815c7f3Sopenharmony_ci*/ 225b815c7f3Sopenharmony_ci 226b815c7f3Sopenharmony_cistatic void 227b815c7f3Sopenharmony_cizero_data_test (const char *filename, int format) 228b815c7f3Sopenharmony_ci{ SNDFILE *file ; 229b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 230b815c7f3Sopenharmony_ci 231b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_TYPEMASK) 232b815c7f3Sopenharmony_ci { case SF_FORMAT_OGG : 233b815c7f3Sopenharmony_ci if (HAVE_EXTERNAL_XIPH_LIBS == 0) 234b815c7f3Sopenharmony_ci return ; 235b815c7f3Sopenharmony_ci break ; 236b815c7f3Sopenharmony_ci default : 237b815c7f3Sopenharmony_ci break ; 238b815c7f3Sopenharmony_ci } ; 239b815c7f3Sopenharmony_ci 240b815c7f3Sopenharmony_ci print_test_name ("zero_data_test", filename) ; 241b815c7f3Sopenharmony_ci 242b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 243b815c7f3Sopenharmony_ci sfinfo.format = format ; 244b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 245b815c7f3Sopenharmony_ci sfinfo.frames = 0 ; 246b815c7f3Sopenharmony_ci 247b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; 248b815c7f3Sopenharmony_ci 249b815c7f3Sopenharmony_ci sf_close (file) ; 250b815c7f3Sopenharmony_ci 251b815c7f3Sopenharmony_ci memset (&sfinfo, 0, sizeof (sfinfo)) ; 252b815c7f3Sopenharmony_ci 253b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; 254b815c7f3Sopenharmony_ci 255b815c7f3Sopenharmony_ci sf_close (file) ; 256b815c7f3Sopenharmony_ci 257b815c7f3Sopenharmony_ci unlink (filename) ; 258b815c7f3Sopenharmony_ci puts ("ok") ; 259b815c7f3Sopenharmony_ci} /* zero_data_test */ 260b815c7f3Sopenharmony_ci 261b815c7f3Sopenharmony_cistatic void 262b815c7f3Sopenharmony_cifilesystem_full_test (int format) 263b815c7f3Sopenharmony_ci{ 264b815c7f3Sopenharmony_ci#if (defined (WIN32) || defined (_WIN32)) 265b815c7f3Sopenharmony_ci (void) format ; 266b815c7f3Sopenharmony_ci /* Can't run this test on Win32 so return. */ 267b815c7f3Sopenharmony_ci return ; 268b815c7f3Sopenharmony_ci#else 269b815c7f3Sopenharmony_ci SNDFILE *file ; 270b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 271b815c7f3Sopenharmony_ci struct stat buf ; 272b815c7f3Sopenharmony_ci 273b815c7f3Sopenharmony_ci const char *filename = "/dev/full", *errorstr ; 274b815c7f3Sopenharmony_ci 275b815c7f3Sopenharmony_ci /* Make sure errno is zero before doing anything else. */ 276b815c7f3Sopenharmony_ci errno = 0 ; 277b815c7f3Sopenharmony_ci 278b815c7f3Sopenharmony_ci print_test_name ("filesystem_full_test", filename) ; 279b815c7f3Sopenharmony_ci 280b815c7f3Sopenharmony_ci if (stat (filename, &buf) != 0) 281b815c7f3Sopenharmony_ci { puts ("/dev/full missing") ; 282b815c7f3Sopenharmony_ci return ; 283b815c7f3Sopenharmony_ci } ; 284b815c7f3Sopenharmony_ci 285b815c7f3Sopenharmony_ci if (S_ISCHR (buf.st_mode) == 0 && S_ISBLK (buf.st_mode) == 0) 286b815c7f3Sopenharmony_ci { puts ("/dev/full is not a device file") ; 287b815c7f3Sopenharmony_ci return ; 288b815c7f3Sopenharmony_ci } ; 289b815c7f3Sopenharmony_ci 290b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 291b815c7f3Sopenharmony_ci sfinfo.format = format ; 292b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 293b815c7f3Sopenharmony_ci sfinfo.frames = 0 ; 294b815c7f3Sopenharmony_ci 295b815c7f3Sopenharmony_ci if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) != NULL) 296b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Error, file should not have openned.\n", __LINE__ - 1) ; 297b815c7f3Sopenharmony_ci exit (1) ; 298b815c7f3Sopenharmony_ci } ; 299b815c7f3Sopenharmony_ci 300b815c7f3Sopenharmony_ci errorstr = sf_strerror (file) ; 301b815c7f3Sopenharmony_ci 302b815c7f3Sopenharmony_ci if (strstr (errorstr, " space ") == NULL || strstr (errorstr, "device") == NULL) 303b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Error bad error string : %s.\n", __LINE__ - 1, errorstr) ; 304b815c7f3Sopenharmony_ci exit (1) ; 305b815c7f3Sopenharmony_ci } ; 306b815c7f3Sopenharmony_ci 307b815c7f3Sopenharmony_ci puts ("ok") ; 308b815c7f3Sopenharmony_ci#endif 309b815c7f3Sopenharmony_ci} /* filesystem_full_test */ 310b815c7f3Sopenharmony_ci 311b815c7f3Sopenharmony_cistatic void 312b815c7f3Sopenharmony_cipermission_test (const char *filename, int typemajor) 313b815c7f3Sopenharmony_ci{ 314b815c7f3Sopenharmony_ci#if (OS_IS_WIN32) 315b815c7f3Sopenharmony_ci /* Avoid compiler warnings. */ 316b815c7f3Sopenharmony_ci (void) filename ; 317b815c7f3Sopenharmony_ci (void) typemajor ; 318b815c7f3Sopenharmony_ci 319b815c7f3Sopenharmony_ci /* Can't run this test on Win32 so return. */ 320b815c7f3Sopenharmony_ci return ; 321b815c7f3Sopenharmony_ci#else 322b815c7f3Sopenharmony_ci 323b815c7f3Sopenharmony_ci FILE *textfile ; 324b815c7f3Sopenharmony_ci SNDFILE *file ; 325b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 326b815c7f3Sopenharmony_ci const char *errorstr ; 327b815c7f3Sopenharmony_ci 328b815c7f3Sopenharmony_ci /* Make sure errno is zero before doing anything else. */ 329b815c7f3Sopenharmony_ci errno = 0 ; 330b815c7f3Sopenharmony_ci 331b815c7f3Sopenharmony_ci if (getuid () == 0) 332b815c7f3Sopenharmony_ci { /* If running as root bypass this test. 333b815c7f3Sopenharmony_ci ** Root is allowed to open a readonly file for write. 334b815c7f3Sopenharmony_ci */ 335b815c7f3Sopenharmony_ci return ; 336b815c7f3Sopenharmony_ci } ; 337b815c7f3Sopenharmony_ci 338b815c7f3Sopenharmony_ci print_test_name ("permission_test", filename) ; 339b815c7f3Sopenharmony_ci 340b815c7f3Sopenharmony_ci if (access (filename, F_OK) == 0) 341b815c7f3Sopenharmony_ci { chmod (filename, S_IWUSR) ; 342b815c7f3Sopenharmony_ci unlink (filename) ; 343b815c7f3Sopenharmony_ci } ; 344b815c7f3Sopenharmony_ci 345b815c7f3Sopenharmony_ci if ((textfile = fopen (filename, "w")) == NULL) 346b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : not able to open text file for write.\n", __LINE__) ; 347b815c7f3Sopenharmony_ci exit (1) ; 348b815c7f3Sopenharmony_ci } ; 349b815c7f3Sopenharmony_ci 350b815c7f3Sopenharmony_ci fprintf (textfile, "This is a read only file.\n") ; 351b815c7f3Sopenharmony_ci fclose (textfile) ; 352b815c7f3Sopenharmony_ci 353b815c7f3Sopenharmony_ci if (chmod (filename, S_IRUSR | S_IRGRP)) 354b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : chmod failed", __LINE__) ; 355b815c7f3Sopenharmony_ci fflush (stdout) ; 356b815c7f3Sopenharmony_ci perror ("") ; 357b815c7f3Sopenharmony_ci exit (1) ; 358b815c7f3Sopenharmony_ci } ; 359b815c7f3Sopenharmony_ci 360b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 361b815c7f3Sopenharmony_ci sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; 362b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 363b815c7f3Sopenharmony_ci sfinfo.frames = 0 ; 364b815c7f3Sopenharmony_ci 365b815c7f3Sopenharmony_ci if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) != NULL) 366b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Error, file should not have opened.\n", __LINE__ - 1) ; 367b815c7f3Sopenharmony_ci exit (1) ; 368b815c7f3Sopenharmony_ci } ; 369b815c7f3Sopenharmony_ci 370b815c7f3Sopenharmony_ci errorstr = sf_strerror (file) ; 371b815c7f3Sopenharmony_ci 372b815c7f3Sopenharmony_ci if (strstr (errorstr, "ermission denied") == NULL) 373b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Error bad error string : %s.\n", __LINE__ - 1, errorstr) ; 374b815c7f3Sopenharmony_ci exit (1) ; 375b815c7f3Sopenharmony_ci } ; 376b815c7f3Sopenharmony_ci 377b815c7f3Sopenharmony_ci if (chmod (filename, S_IWUSR | S_IWGRP)) 378b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : chmod failed", __LINE__) ; 379b815c7f3Sopenharmony_ci fflush (stdout) ; 380b815c7f3Sopenharmony_ci perror ("") ; 381b815c7f3Sopenharmony_ci exit (1) ; 382b815c7f3Sopenharmony_ci } ; 383b815c7f3Sopenharmony_ci 384b815c7f3Sopenharmony_ci unlink (filename) ; 385b815c7f3Sopenharmony_ci 386b815c7f3Sopenharmony_ci puts ("ok") ; 387b815c7f3Sopenharmony_ci 388b815c7f3Sopenharmony_ci#endif 389b815c7f3Sopenharmony_ci} /* permission_test */ 390b815c7f3Sopenharmony_ci 391b815c7f3Sopenharmony_cistatic void 392b815c7f3Sopenharmony_ciwavex_amb_test (const char *filename) 393b815c7f3Sopenharmony_ci{ static short buffer [800] ; 394b815c7f3Sopenharmony_ci SNDFILE *file ; 395b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 396b815c7f3Sopenharmony_ci sf_count_t frames ; 397b815c7f3Sopenharmony_ci 398b815c7f3Sopenharmony_ci print_test_name (__func__, filename) ; 399b815c7f3Sopenharmony_ci 400b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 401b815c7f3Sopenharmony_ci sfinfo.format = SF_FORMAT_WAVEX | SF_FORMAT_PCM_16 ; 402b815c7f3Sopenharmony_ci sfinfo.channels = 4 ; 403b815c7f3Sopenharmony_ci 404b815c7f3Sopenharmony_ci frames = ARRAY_LEN (buffer) / sfinfo.channels ; 405b815c7f3Sopenharmony_ci 406b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; 407b815c7f3Sopenharmony_ci sf_command (file, SFC_WAVEX_SET_AMBISONIC, NULL, SF_AMBISONIC_B_FORMAT) ; 408b815c7f3Sopenharmony_ci test_writef_short_or_die (file, 0, buffer, frames, __LINE__) ; 409b815c7f3Sopenharmony_ci sf_close (file) ; 410b815c7f3Sopenharmony_ci 411b815c7f3Sopenharmony_ci memset (&sfinfo, 0, sizeof (sfinfo)) ; 412b815c7f3Sopenharmony_ci 413b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; 414b815c7f3Sopenharmony_ci 415b815c7f3Sopenharmony_ci exit_if_true ( 416b815c7f3Sopenharmony_ci sf_command (file, SFC_WAVEX_GET_AMBISONIC, NULL, 0) != SF_AMBISONIC_B_FORMAT, 417b815c7f3Sopenharmony_ci "\n\nLine %d : Error, this file should be in Ambisonic B format.\n", __LINE__ 418b815c7f3Sopenharmony_ci ) ; 419b815c7f3Sopenharmony_ci 420b815c7f3Sopenharmony_ci sf_close (file) ; 421b815c7f3Sopenharmony_ci 422b815c7f3Sopenharmony_ci unlink (filename) ; 423b815c7f3Sopenharmony_ci puts ("ok") ; 424b815c7f3Sopenharmony_ci} /* wavex_amb_test */ 425b815c7f3Sopenharmony_ci 426b815c7f3Sopenharmony_cistatic void 427b815c7f3Sopenharmony_cirf64_downgrade_test (const char *filename) 428b815c7f3Sopenharmony_ci{ static short output [BUFFER_LEN] ; 429b815c7f3Sopenharmony_ci static short input [BUFFER_LEN] ; 430b815c7f3Sopenharmony_ci 431b815c7f3Sopenharmony_ci SNDFILE *file ; 432b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 433b815c7f3Sopenharmony_ci unsigned k ; 434b815c7f3Sopenharmony_ci 435b815c7f3Sopenharmony_ci print_test_name (__func__, filename) ; 436b815c7f3Sopenharmony_ci 437b815c7f3Sopenharmony_ci sf_info_clear (&sfinfo) ; 438b815c7f3Sopenharmony_ci 439b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 440b815c7f3Sopenharmony_ci sfinfo.frames = ARRAY_LEN (output) ; 441b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 442b815c7f3Sopenharmony_ci sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_16 ; 443b815c7f3Sopenharmony_ci 444b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; 445b815c7f3Sopenharmony_ci 446b815c7f3Sopenharmony_ci exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_FALSE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; 447b815c7f3Sopenharmony_ci exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; 448b815c7f3Sopenharmony_ci 449b815c7f3Sopenharmony_ci test_write_short_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ; 450b815c7f3Sopenharmony_ci 451b815c7f3Sopenharmony_ci exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_FALSE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; 452b815c7f3Sopenharmony_ci exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; 453b815c7f3Sopenharmony_ci 454b815c7f3Sopenharmony_ci sf_close (file) ; 455b815c7f3Sopenharmony_ci 456b815c7f3Sopenharmony_ci memset (input, 0, sizeof (input)) ; 457b815c7f3Sopenharmony_ci sf_info_clear (&sfinfo) ; 458b815c7f3Sopenharmony_ci 459b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; 460b815c7f3Sopenharmony_ci 461b815c7f3Sopenharmony_ci exit_if_true (sfinfo.format != (SF_FORMAT_WAVEX | SF_FORMAT_PCM_16), "\n\nLine %d: RF64 to WAV downgrade failed.\n", __LINE__) ; 462b815c7f3Sopenharmony_ci exit_if_true (sfinfo.frames != ARRAY_LEN (output), "\n\nLine %d: Incorrect number of frames in file (too short). (%d should be %d)\n", __LINE__, (int) sfinfo.frames, (int) ARRAY_LEN (output)) ; 463b815c7f3Sopenharmony_ci exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; 464b815c7f3Sopenharmony_ci 465b815c7f3Sopenharmony_ci check_log_buffer_or_die (file, __LINE__) ; 466b815c7f3Sopenharmony_ci 467b815c7f3Sopenharmony_ci test_read_short_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ; 468b815c7f3Sopenharmony_ci 469b815c7f3Sopenharmony_ci sf_close (file) ; 470b815c7f3Sopenharmony_ci 471b815c7f3Sopenharmony_ci for (k = 0 ; k < ARRAY_LEN (input) ; k++) 472b815c7f3Sopenharmony_ci exit_if_true (input [k] != output [k], 473b815c7f3Sopenharmony_ci "\n\nLine: %d: Error on input %d, expected %d, got %d\n", __LINE__, k, output [k], input [k]) ; 474b815c7f3Sopenharmony_ci 475b815c7f3Sopenharmony_ci puts ("ok") ; 476b815c7f3Sopenharmony_ci unlink (filename) ; 477b815c7f3Sopenharmony_ci 478b815c7f3Sopenharmony_ci return ; 479b815c7f3Sopenharmony_ci} /* rf64_downgrade_test */ 480b815c7f3Sopenharmony_ci 481b815c7f3Sopenharmony_cistatic void 482b815c7f3Sopenharmony_cirf64_long_file_downgrade_test (const char *filename) 483b815c7f3Sopenharmony_ci{ static int output [BUFFER_LEN] ; 484b815c7f3Sopenharmony_ci static int input [1] = { 0 } ; 485b815c7f3Sopenharmony_ci 486b815c7f3Sopenharmony_ci SNDFILE *file ; 487b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 488b815c7f3Sopenharmony_ci sf_count_t output_frames = 0 ; 489b815c7f3Sopenharmony_ci 490b815c7f3Sopenharmony_ci print_test_name (__func__, filename) ; 491b815c7f3Sopenharmony_ci 492b815c7f3Sopenharmony_ci sf_info_clear (&sfinfo) ; 493b815c7f3Sopenharmony_ci 494b815c7f3Sopenharmony_ci memset (output, 0, sizeof (output)) ; 495b815c7f3Sopenharmony_ci output [0] = 0x1020304 ; 496b815c7f3Sopenharmony_ci 497b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 498b815c7f3Sopenharmony_ci sfinfo.frames = ARRAY_LEN (output) ; 499b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 500b815c7f3Sopenharmony_ci sfinfo.format = SF_FORMAT_RF64 | SF_FORMAT_PCM_32 ; 501b815c7f3Sopenharmony_ci 502b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; 503b815c7f3Sopenharmony_ci 504b815c7f3Sopenharmony_ci exit_if_true (sf_command (file, SFC_RF64_AUTO_DOWNGRADE, NULL, SF_TRUE) != SF_TRUE, "\n\nLine %d: sf_command failed.\n", __LINE__) ; 505b815c7f3Sopenharmony_ci 506b815c7f3Sopenharmony_ci while (output_frames * sizeof (output [0]) < 0x100000000) 507b815c7f3Sopenharmony_ci { test_write_int_or_die (file, 0, output, ARRAY_LEN (output), __LINE__) ; 508b815c7f3Sopenharmony_ci output_frames += ARRAY_LEN (output) ; 509b815c7f3Sopenharmony_ci } ; 510b815c7f3Sopenharmony_ci 511b815c7f3Sopenharmony_ci sf_close (file) ; 512b815c7f3Sopenharmony_ci 513b815c7f3Sopenharmony_ci sf_info_clear (&sfinfo) ; 514b815c7f3Sopenharmony_ci 515b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; 516b815c7f3Sopenharmony_ci 517b815c7f3Sopenharmony_ci exit_if_true (sfinfo.format != (SF_FORMAT_RF64 | SF_FORMAT_PCM_32), "\n\nLine %d: RF64 to WAV downgrade should have failed.\n", __LINE__) ; 518b815c7f3Sopenharmony_ci exit_if_true (sfinfo.channels != 1, "\n\nLine %d: Incorrect number of channels in file.\n", __LINE__) ; 519b815c7f3Sopenharmony_ci exit_if_true (sfinfo.frames != output_frames, "\n\nLine %d: Incorrect number of frames in file (%d should be %d).\n", __LINE__, (int) sfinfo.frames, (int) output_frames) ; 520b815c7f3Sopenharmony_ci 521b815c7f3Sopenharmony_ci /* Check that the first sample read is the same as the first written. */ 522b815c7f3Sopenharmony_ci test_read_int_or_die (file, 0, input, ARRAY_LEN (input), __LINE__) ; 523b815c7f3Sopenharmony_ci exit_if_true (input [0] != output [0], "\n\nLine %d: Bad first sample (0x%08x).\n", __LINE__, input [0]) ; 524b815c7f3Sopenharmony_ci 525b815c7f3Sopenharmony_ci check_log_buffer_or_die (file, __LINE__) ; 526b815c7f3Sopenharmony_ci 527b815c7f3Sopenharmony_ci sf_close (file) ; 528b815c7f3Sopenharmony_ci 529b815c7f3Sopenharmony_ci puts ("ok") ; 530b815c7f3Sopenharmony_ci unlink (filename) ; 531b815c7f3Sopenharmony_ci 532b815c7f3Sopenharmony_ci return ; 533b815c7f3Sopenharmony_ci} /* rf64_long_file_downgrade_test */ 534