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