mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
Add a C++ test and hook into build.
This commit is contained in:
parent
f87f524e2c
commit
576e6f6f68
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
||||
2006-07-27 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* tests/utils.tpl
|
||||
Add extern C to generated header file.
|
||||
|
||||
* src/sndfile.hh
|
||||
Work towards completing this.
|
||||
|
||||
* tests/cpp_test.cc tests/Makefile.am
|
||||
Add a C++ test and hook into build.
|
||||
|
||||
* configure.ac
|
||||
Add appropriate CXXFLAGS.
|
||||
|
||||
2006-07-26 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* configure.ac
|
||||
|
@ -6,7 +6,7 @@ noinst_PROGRAMS = sfversion floating_point_test write_read_test \
|
||||
pcm_test headerless_test pipe_test benchmark header_test misc_test \
|
||||
raw_test string_test open_fail_test multi_file_test dither_test \
|
||||
scale_clip_test win32_test fix_this aiff_rw_test virtual_io_test \
|
||||
locale_test largefile_test win32_ordinal_test
|
||||
locale_test largefile_test win32_ordinal_test cpp_test
|
||||
|
||||
SNDFILEDIR = ../src
|
||||
INCLUDES = -I$(srcdir)/$(SNDFILEDIR)
|
||||
@ -109,6 +109,9 @@ win32_test_LDADD =
|
||||
win32_ordinal_test_SOURCES = win32_ordinal_test.c utils.c
|
||||
win32_ordinal_test_LDADD = $(SNDFILEDIR)/libsndfile.la
|
||||
|
||||
cpp_test_SOURCES = cpp_test.cc utils.c
|
||||
cpp_test_LDADD = $(SNDFILEDIR)/libsndfile.la
|
||||
|
||||
# Lite remove start
|
||||
dwvw_test_SOURCES = utils.c dwvw_test.c
|
||||
dwvw_test_LDADD = $(SNDFILEDIR)/libsndfile.la
|
||||
@ -159,7 +162,8 @@ check: generic-tests wav-tests aiff-tests au-tests caf-tests raw-tests \
|
||||
mat5-tests pvf-tests xi-tests htk-tests avr-tests sds-tests sd2-tests \
|
||||
flac-tests caf-tests io-tests
|
||||
|
||||
generic-tests : error_test ulaw_test alaw_test command_test floating_point_test pcm_test win32_ordinal_test
|
||||
generic-tests : error_test ulaw_test alaw_test command_test floating_point_test \
|
||||
pcm_test win32_ordinal_test cpp_test
|
||||
uname -a
|
||||
./error_test
|
||||
./pcm_test
|
||||
@ -178,6 +182,7 @@ generic-tests : error_test ulaw_test alaw_test command_test floating_point_test
|
||||
./headerless_test
|
||||
./locale_test
|
||||
./win32_ordinal_test
|
||||
./cpp_test
|
||||
@echo "----------------------------------------------------------------------"
|
||||
@echo " `./sfversion` passed common tests."
|
||||
@echo "----------------------------------------------------------------------"
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <sndfile.hh>
|
||||
|
||||
@ -31,21 +30,12 @@ static double dbuffer [100] ;
|
||||
|
||||
static void
|
||||
create_file (const char * filename, int format)
|
||||
{ SndfileHandle file ;
|
||||
{ Sndfile file ;
|
||||
|
||||
if (file.refCount () != 0)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be zero.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file = SndfileHandle (filename, SFM_WRITE, format, 2, 48000) ;
|
||||
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be 1.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file.setString (SF_STR_TITLE, filename) ;
|
||||
file.sfinfo.format = format ;
|
||||
file.sfinfo.channels = 2 ;
|
||||
file.sfinfo.samplerate = 48000 ;
|
||||
file.openWrite (filename) ;
|
||||
|
||||
/* Item write. */
|
||||
file.write (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
@ -54,89 +44,40 @@ create_file (const char * filename, int format)
|
||||
file.write (dbuffer, ARRAY_LEN (dbuffer)) ;
|
||||
|
||||
/* Frame write. */
|
||||
file.writef (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
|
||||
file.writef (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
|
||||
file.writef (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
|
||||
file.writef (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;
|
||||
file.writef (sbuffer, ARRAY_LEN (sbuffer) / file.sfinfo.channels) ;
|
||||
file.writef (ibuffer, ARRAY_LEN (ibuffer) / file.sfinfo.channels) ;
|
||||
file.writef (fbuffer, ARRAY_LEN (fbuffer) / file.sfinfo.channels) ;
|
||||
file.writef (dbuffer, ARRAY_LEN (dbuffer) / file.sfinfo.channels) ;
|
||||
|
||||
/* RAII takes care of the SndfileHandle. */
|
||||
/*
|
||||
** An explict close() call is not really necessary as the Sndfile
|
||||
** destructor closes the file anyway.
|
||||
*/
|
||||
file.close () ;
|
||||
} /* create_file */
|
||||
|
||||
static void
|
||||
check_title (const SndfileHandle & file, const char * filename)
|
||||
{ const char *title = NULL ;
|
||||
|
||||
title = file.getString (SF_STR_TITLE) ;
|
||||
|
||||
if (title == NULL)
|
||||
{ printf ("\n\n%s %d : Error : No title.\n\n", __func__, __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (strcmp (filename, title) != 0)
|
||||
{ printf ("\n\n%s %d : Error : title '%s' should be '%s'\n\n", __func__, __LINE__, title, filename) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
return ;
|
||||
} /* check_title */
|
||||
|
||||
static void
|
||||
read_file (const char * filename, int format)
|
||||
{ SndfileHandle file ;
|
||||
sf_count_t count ;
|
||||
{ Sndfile file ;
|
||||
|
||||
if (file)
|
||||
{ printf ("\n\n%s %d : Error : should not be here.\n\n", __func__, __LINE__) ;
|
||||
file.openRead (filename) ;
|
||||
|
||||
if (file.sfinfo.format != format)
|
||||
{ printf ("\n\n%s %d : Error : format 0x%08x should be 0x%08x.\n\n", __func__, __LINE__, file.sfinfo.format, format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
file = SndfileHandle (filename) ;
|
||||
|
||||
if (1)
|
||||
{ SndfileHandle file2 = file ;
|
||||
|
||||
if (file.refCount () != 2 || file2.refCount () != 2)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be two.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
if (file.refCount () != 1)
|
||||
{ printf ("\n\n%s %d : Error : Reference count (%d) should be one.\n\n", __func__, __LINE__, file.refCount ()) ;
|
||||
if (file.sfinfo.channels != 2)
|
||||
{ printf ("\n\n%s %d : Error : channels %d should be 2.\n\n", __func__, __LINE__, file.sfinfo.channels) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (! file)
|
||||
{ printf ("\n\n%s %d : Error : should not be here.\n\n", __func__, __LINE__) ;
|
||||
if (file.sfinfo.frames != ARRAY_LEN (sbuffer) * 4)
|
||||
{ printf ("\n\n%s %d : Error : frames %ld should be %d.\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (file.sfinfo.frames), ARRAY_LEN (sbuffer) * 4 / 2) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.format () != format)
|
||||
{ printf ("\n\n%s %d : Error : format 0x%08x should be 0x%08x.\n\n", __func__, __LINE__, file.format (), format) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.channels () != 2)
|
||||
{ printf ("\n\n%s %d : Error : channels %d should be 2.\n\n", __func__, __LINE__, file.channels ()) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (file.frames () != ARRAY_LEN (sbuffer) * 4)
|
||||
{ printf ("\n\n%s %d : Error : frames %ld should be %lu.\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (file.frames ()), (long unsigned int) ARRAY_LEN (sbuffer) * 4 / 2) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
switch (format & SF_FORMAT_TYPEMASK)
|
||||
{ case SF_FORMAT_AU :
|
||||
break ;
|
||||
|
||||
default :
|
||||
check_title (file, filename) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
/* Item read. */
|
||||
file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
file.read (ibuffer, ARRAY_LEN (ibuffer)) ;
|
||||
@ -144,47 +85,28 @@ read_file (const char * filename, int format)
|
||||
file.read (dbuffer, ARRAY_LEN (dbuffer)) ;
|
||||
|
||||
/* Frame read. */
|
||||
file.readf (sbuffer, ARRAY_LEN (sbuffer) / file.channels ()) ;
|
||||
file.readf (ibuffer, ARRAY_LEN (ibuffer) / file.channels ()) ;
|
||||
file.readf (fbuffer, ARRAY_LEN (fbuffer) / file.channels ()) ;
|
||||
file.readf (dbuffer, ARRAY_LEN (dbuffer) / file.channels ()) ;
|
||||
file.readf (sbuffer, ARRAY_LEN (sbuffer) / file.sfinfo.channels) ;
|
||||
file.readf (ibuffer, ARRAY_LEN (ibuffer) / file.sfinfo.channels) ;
|
||||
file.readf (fbuffer, ARRAY_LEN (fbuffer) / file.sfinfo.channels) ;
|
||||
file.readf (dbuffer, ARRAY_LEN (dbuffer) / file.sfinfo.channels) ;
|
||||
|
||||
count = file.seek (file.frames () - 10, SEEK_SET) ;
|
||||
if (count != file.frames () - 10)
|
||||
{ printf ("\n\n%s %d : Error : offset (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (count), SF_COUNT_TO_LONG (file.frames () - 10)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
count = file.read (sbuffer, ARRAY_LEN (sbuffer)) ;
|
||||
if (count != 10 * file.channels ())
|
||||
{ printf ("\n\n%s %d : Error : count (%ld) should be %ld\n\n", __func__, __LINE__,
|
||||
SF_COUNT_TO_LONG (count), SF_COUNT_TO_LONG (10 * file.channels ())) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
/* RAII takes care of the SndfileHandle. */
|
||||
} /* read_file */
|
||||
|
||||
static void
|
||||
ceeplusplus_test (const char *filename, int format)
|
||||
{
|
||||
print_test_name ("ceeplusplus_test", filename) ;
|
||||
|
||||
create_file (filename, format) ;
|
||||
read_file (filename, format) ;
|
||||
|
||||
remove (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* ceeplusplus_test */
|
||||
/*
|
||||
** An explict close() call is not really necessary as the Sndfile
|
||||
** destructor closes the file anyway.
|
||||
*/
|
||||
file.close () ;
|
||||
} /* create_file */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ceeplusplus_test ("cpp_test.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
ceeplusplus_test ("cpp_test.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_S8) ;
|
||||
ceeplusplus_test ("cpp_test.au", SF_FORMAT_AU | SF_FORMAT_FLOAT) ;
|
||||
{ const char * filename = "cpp_test.wav" ;
|
||||
|
||||
print_test_name ("CeePlusPlus test", filename) ;
|
||||
|
||||
create_file (filename, SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
read_file (filename, SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
|
||||
puts ("ok") ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user