annotate src/libsndfile-1.0.27/tests/stdout_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) 2001-2014 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
cannam@125 26 #if HAVE_UNISTD_H
cannam@125 27 #include <unistd.h>
cannam@125 28 #endif
cannam@125 29
cannam@125 30 #include <sndfile.h>
cannam@125 31
cannam@125 32 #include "utils.h"
cannam@125 33
cannam@125 34 static void stdout_test (int typemajor, int count) ;
cannam@125 35
cannam@125 36 int
cannam@125 37 main (int argc, char *argv [])
cannam@125 38 { int do_all, test_count = 0 ;
cannam@125 39
cannam@125 40 if (argc != 2)
cannam@125 41 { fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
cannam@125 42 fprintf (stderr, "to be run from the stdio_test program.\n") ;
cannam@125 43 exit (1) ;
cannam@125 44 } ;
cannam@125 45
cannam@125 46 do_all = ! strcmp (argv [1], "all") ;
cannam@125 47
cannam@125 48 if (do_all || ! strcmp (argv [1], "raw"))
cannam@125 49 { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
cannam@125 50 test_count ++ ;
cannam@125 51 } ;
cannam@125 52
cannam@125 53 if (do_all || ! strcmp (argv [1], "wav"))
cannam@125 54 { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
cannam@125 55 test_count ++ ;
cannam@125 56 } ;
cannam@125 57
cannam@125 58 if (do_all || ! strcmp (argv [1], "aiff"))
cannam@125 59 { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
cannam@125 60 test_count ++ ;
cannam@125 61 } ;
cannam@125 62
cannam@125 63 if (do_all || ! strcmp (argv [1], "au"))
cannam@125 64 { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
cannam@125 65 test_count ++ ;
cannam@125 66 } ;
cannam@125 67
cannam@125 68 if (do_all || ! strcmp (argv [1], "paf"))
cannam@125 69 { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
cannam@125 70 test_count ++ ;
cannam@125 71 } ;
cannam@125 72
cannam@125 73 if (do_all || ! strcmp (argv [1], "svx"))
cannam@125 74 { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
cannam@125 75 test_count ++ ;
cannam@125 76 } ;
cannam@125 77
cannam@125 78 if (do_all || ! strcmp (argv [1], "nist"))
cannam@125 79 { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
cannam@125 80 test_count ++ ;
cannam@125 81 } ;
cannam@125 82
cannam@125 83 if (do_all || ! strcmp (argv [1], "ircam"))
cannam@125 84 { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
cannam@125 85 test_count ++ ;
cannam@125 86 } ;
cannam@125 87
cannam@125 88 if (do_all || ! strcmp (argv [1], "voc"))
cannam@125 89 { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
cannam@125 90 test_count ++ ;
cannam@125 91 } ;
cannam@125 92
cannam@125 93 if (do_all || ! strcmp (argv [1], "w64"))
cannam@125 94 { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
cannam@125 95 test_count ++ ;
cannam@125 96 } ;
cannam@125 97
cannam@125 98 if (do_all || ! strcmp (argv [1], "mat4"))
cannam@125 99 { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
cannam@125 100 test_count ++ ;
cannam@125 101 } ;
cannam@125 102
cannam@125 103 if (do_all || ! strcmp (argv [1], "mat5"))
cannam@125 104 { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
cannam@125 105 test_count ++ ;
cannam@125 106 } ;
cannam@125 107
cannam@125 108 if (do_all || ! strcmp (argv [1], "pvf"))
cannam@125 109 { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
cannam@125 110 test_count ++ ;
cannam@125 111 } ;
cannam@125 112
cannam@125 113 if (test_count == 0)
cannam@125 114 { fprintf (stderr, "\n******************************************\n") ;
cannam@125 115 fprintf (stderr, "* stdout_test : No '%s' test defined.\n", argv [1]) ;
cannam@125 116 fprintf (stderr, "******************************************\n") ;
cannam@125 117 return 1 ;
cannam@125 118 } ;
cannam@125 119
cannam@125 120 return 0 ;
cannam@125 121 } /* main */
cannam@125 122
cannam@125 123 static void
cannam@125 124 stdout_test (int typemajor, int count)
cannam@125 125 { static short data [PIPE_TEST_LEN] ;
cannam@125 126
cannam@125 127 SNDFILE *file ;
cannam@125 128 SF_INFO sfinfo ;
cannam@125 129 int k, total, this_write ;
cannam@125 130
cannam@125 131 sfinfo.samplerate = 44100 ;
cannam@125 132 sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ;
cannam@125 133 sfinfo.channels = 1 ;
cannam@125 134 sfinfo.frames = 0 ;
cannam@125 135
cannam@125 136 /* Create some random data. */
cannam@125 137 for (k = 0 ; k < PIPE_TEST_LEN ; k++)
cannam@125 138 data [k] = PIPE_INDEX (k) ;
cannam@125 139
cannam@125 140 if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL)
cannam@125 141 { fprintf (stderr, "%s % d: sf_open_write failed with error : %s\n",
cannam@125 142 __func__, __LINE__, sf_strerror (NULL)) ;
cannam@125 143 exit (1) ;
cannam@125 144 } ;
cannam@125 145
cannam@125 146 if (sfinfo.frames != 0)
cannam@125 147 { fprintf (stderr, "%s % d: Frames is %d (should be 0).\n",
cannam@125 148 __func__, __LINE__, (int) sfinfo.frames) ;
cannam@125 149 exit (1) ;
cannam@125 150 } ;
cannam@125 151
cannam@125 152 total = 0 ;
cannam@125 153
cannam@125 154 while (total < count)
cannam@125 155 { this_write = (count - total > 1024) ? 1024 : count - total ;
cannam@125 156 if ((k = sf_write_short (file, data + total, this_write)) != this_write)
cannam@125 157 { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ;
cannam@125 158 exit (1) ;
cannam@125 159 } ;
cannam@125 160 total += k ;
cannam@125 161 } ;
cannam@125 162
cannam@125 163 sf_close (file) ;
cannam@125 164
cannam@125 165 return ;
cannam@125 166 } /* stdout_test */
cannam@125 167