2 ** Copyright (C) 2003 Erik de Castro Lopo <erikd@zip.com.au>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #define BUFFER_LEN (1 << 10)
29 #define LOG_BUFFER_SIZE 1024
31 static void string_test (char *filename
, int typemajor
) ;
34 main (int argc
, char *argv
[])
39 { printf ("Usage : %s <test>\n", argv
[0]) ;
40 printf (" Where <test> is one of the following:\n") ;
41 printf (" wav - test adding strings to WAV files\n") ;
42 printf (" aiff - test adding strings to AIFF files\n") ;
43 printf (" all - perform all tests\n") ;
47 do_all
=! strcmp (argv
[1], "all") ;
49 if (do_all
|| ! strcmp (argv
[1], "wav"))
50 { string_test ("strings.wav", SF_FORMAT_WAV
) ;
54 if (do_all
|| ! strcmp (argv
[1], "aiff"))
55 { string_test ("strings.aiff", SF_FORMAT_AIFF
) ;
60 { printf ("Mono : ************************************\n") ;
61 printf ("Mono : * No '%s' test defined.\n", argv
[1]) ;
62 printf ("Mono : ************************************\n") ;
70 /*============================================================================================
71 ** Here are the test functions.
75 software
[] = "software",
76 artist
[] = "The Artist",
77 copyright
[] = "Copyright (c) 2003 The Artist",
78 comment
[] = "Comment goes here!!!",
79 date
[] = "2003/01/27" ;
81 static short data_out
[BUFFER_LEN
] ;
84 string_test (char *filename
, int typemajor
)
88 int frames
, errors
= 0 ;
90 typemajor
= typemajor
;
92 print_test_name ("string_test", filename
) ;
94 sfinfo
.samplerate
= 44100 ;
99 { case SF_FORMAT_WAV
:
100 sfinfo
.format
= (typemajor
| SF_FORMAT_PCM_U8
) ;
104 sfinfo
.format
= (typemajor
| SF_FORMAT_PCM_S8
) ;
108 frames
= BUFFER_LEN
/ sfinfo
.channels
;
110 file
= test_open_file_or_die (filename
, SFM_WRITE
, &sfinfo
, __LINE__
) ;
112 /* Write stuff at start of file. */
113 sf_set_string (file
, SF_STR_TITLE
, filename
) ;
114 sf_set_string (file
, SF_STR_SOFTWARE
, software
) ;
115 sf_set_string (file
, SF_STR_ARTIST
, artist
) ;
117 /* Write data to file. */
118 test_write_short_or_die (file
, 0, data_out
, BUFFER_LEN
, __LINE__
) ;
119 test_seek_or_die (file
, 0, SEEK_SET
, 0, sfinfo
.channels
, __LINE__
) ;
121 /* Write more stuff at end of file. */
122 sf_set_string (file
, SF_STR_COPYRIGHT
, copyright
) ;
123 sf_set_string (file
, SF_STR_COMMENT
, comment
) ;
124 sf_set_string (file
, SF_STR_DATE
, date
) ;
128 file
= test_open_file_or_die (filename
, SFM_READ
, &sfinfo
, __LINE__
) ;
130 check_log_buffer_or_die (file
) ;
132 if (sfinfo
.frames
!= BUFFER_LEN
)
133 { printf ("***** Bad frame count %d (should be %d)\n\n", (int) sfinfo
.frames
, BUFFER_LEN
) ;
137 cptr
= sf_get_string (file
, SF_STR_TITLE
) ;
138 if (cptr
== NULL
|| strcmp (filename
, cptr
) != 0)
141 printf (" Bad filename : %s\n", cptr
) ;
144 cptr
= sf_get_string (file
, SF_STR_COPYRIGHT
) ;
145 if (cptr
== NULL
|| strcmp (copyright
, cptr
) != 0)
148 printf (" Bad copyright : %s\n", cptr
) ;
151 cptr
= sf_get_string (file
, SF_STR_SOFTWARE
) ;
152 if (cptr
== NULL
|| strstr (cptr
, software
) != cptr
)
155 printf (" Bad software : %s\n", cptr
) ;
158 cptr
= sf_get_string (file
, SF_STR_ARTIST
) ;
159 if (cptr
== NULL
|| strcmp (artist
, cptr
) != 0)
162 printf (" Bad artist : %s\n", cptr
) ;
165 cptr
= sf_get_string (file
, SF_STR_COMMENT
) ;
166 if (cptr
== NULL
|| strcmp (comment
, cptr
) != 0)
169 printf (" Bad comment : %s\n", cptr
) ;
172 if (typemajor
!= SF_FORMAT_AIFF
)
173 { cptr
= sf_get_string (file
, SF_STR_DATE
) ;
174 if (cptr
== NULL
|| strcmp (date
, cptr
) != 0)
177 printf (" Bad date : %s\n", cptr
) ;
182 { printf ("\n*** Error count : %d ***\n\n", errors
) ;
183 dump_log_buffer (file
) ;