mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
Fix a bug reading/writing 64 bit header fields. Complete unit tests.
This commit is contained in:
parent
9310d9bf3c
commit
0515c51c37
@ -12,6 +12,13 @@
|
||||
* src/Makefile.am src/test_file_io.c src/test_log_printf.c src/common.c
|
||||
Clean up unit testing.
|
||||
|
||||
* src/common.c
|
||||
Fix a bug reading/writing 64 bit header fields. Thanks to Jonathan Woithe
|
||||
for reporting this.
|
||||
|
||||
* src/test_conversions.c
|
||||
Complete unit test for above fix.
|
||||
|
||||
2006-11-11 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/sndfile.c
|
||||
|
23
src/common.c
23
src/common.c
@ -775,24 +775,17 @@ psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...)
|
||||
#define GET_BE_INT(ptr) ( ((ptr) [0] << 24) | ((ptr) [1] << 16) | \
|
||||
((ptr) [2] << 8) | ((ptr) [3]) )
|
||||
|
||||
#if (SIZEOF_LONG == 4)
|
||||
#define GET_LE_8BYTE(ptr) ( ((ptr) [3] << 24) | ((ptr) [2] << 16) | \
|
||||
((ptr) [1] << 8) | ((ptr) [0]) )
|
||||
#define GET_LE_8BYTE(ptr) ( (((sf_count_t) (ptr) [7]) << 56) | (((sf_count_t) (ptr) [6]) << 48) | \
|
||||
(((sf_count_t) (ptr) [5]) << 40) | (((sf_count_t) (ptr) [4]) << 32) | \
|
||||
(((sf_count_t) (ptr) [3]) << 24) | (((sf_count_t) (ptr) [2]) << 16) | \
|
||||
(((sf_count_t) (ptr) [1]) << 8 ) | ((ptr) [0]))
|
||||
|
||||
#define GET_BE_8BYTE(ptr) ( ((ptr) [4] << 24) | ((ptr) [5] << 16) | \
|
||||
((ptr) [6] << 8) | ((ptr) [7]) )
|
||||
#else
|
||||
#define GET_LE_8BYTE(ptr) ( (((ptr) [7] * 1L) << 56) | (((ptr) [6] * 1L) << 48) | \
|
||||
(((ptr) [5] * 1L) << 40) | (((ptr) [4] * 1L) << 32) | \
|
||||
(((ptr) [3] * 1L) << 24) | (((ptr) [2] * 1L) << 16) | \
|
||||
(((ptr) [1] * 1L) << 8 ) | ((ptr) [0]))
|
||||
#define GET_BE_8BYTE(ptr) ( (((sf_count_t) (ptr) [0]) << 56) | (((sf_count_t) (ptr) [1]) << 48) | \
|
||||
(((sf_count_t) (ptr) [2]) << 40) | (((sf_count_t) (ptr) [3]) << 32) | \
|
||||
(((sf_count_t) (ptr) [4]) << 24) | (((sf_count_t) (ptr) [5]) << 16) | \
|
||||
(((sf_count_t) (ptr) [6]) << 8 ) | ((ptr) [7]))
|
||||
|
||||
#define GET_BE_8BYTE(ptr) ( (((ptr) [0] * 1L) << 56) | (((ptr) [1] * 1L) << 48) | \
|
||||
(((ptr) [2] * 1L) << 40) | (((ptr) [3] * 1L) << 32) | \
|
||||
(((ptr) [4] * 1L) << 24) | (((ptr) [5] * 1L) << 16) | \
|
||||
(((ptr) [6] * 1L) << 8 ) | ((ptr) [7]))
|
||||
|
||||
#endif
|
||||
|
||||
static int
|
||||
header_read (SF_PRIVATE *psf, void *ptr, int bytes)
|
||||
|
@ -33,22 +33,35 @@
|
||||
#define cmp_test(line,ival,tval,str) \
|
||||
if (ival != tval) \
|
||||
{ printf (str, line, ival, tval) ; \
|
||||
/*-exit (1) ;-*/ \
|
||||
exit (1) ; \
|
||||
} ;
|
||||
|
||||
static void conversion_test (char endian) ;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{ SF_PRIVATE sf_private, *psf ;
|
||||
{
|
||||
conversion_test ('E') ;
|
||||
conversion_test ('e') ;
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
static void
|
||||
conversion_test (char endian)
|
||||
{
|
||||
SF_PRIVATE sf_private, *psf ;
|
||||
const char * filename = "conversion.bin" ;
|
||||
long long i64 = SF_PLATFORM_S64 (0x0123456789abcdef), t64 = 0;
|
||||
char format_str [16] ;
|
||||
char i8 = 12, t8 = 0 ;
|
||||
short i16 = 0x123, t16 = 0 ;
|
||||
int i24 = 0x23456, t24 = 0 ;
|
||||
int i32 = 0x0a0b0c0d, t32 = 0 ;
|
||||
int bytes ;
|
||||
long long i64 = SF_PLATFORM_S64 (0x0123456789abcdef), t64 = 0;
|
||||
|
||||
printf (" %-24s : ", "conversion_test") ;
|
||||
snprintf (format_str, sizeof (format_str), "%c12348", endian) ;
|
||||
|
||||
printf (" conversion_test_%-8s : ", endian == 'e' ? "le" : "be") ;
|
||||
fflush (stdout) ;
|
||||
|
||||
psf = &sf_private ;
|
||||
@ -59,7 +72,7 @@ main (void)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
psf_binheader_writef (psf, "E12348", i8, i16, i24, i32, i64) ;
|
||||
psf_binheader_writef (psf, format_str, i8, i16, i24, i32, i64) ;
|
||||
psf_fwrite (psf->header, 1, psf->headindex, psf) ;
|
||||
psf_fclose (psf) ;
|
||||
|
||||
@ -69,7 +82,7 @@ main (void)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
bytes = psf_binheader_readf (psf, "E12348", &t8, &t16, &t24, &t32, &t64) ;
|
||||
bytes = psf_binheader_readf (psf, format_str, &t8, &t16, &t24, &t32, &t64) ;
|
||||
psf_fclose (psf) ;
|
||||
|
||||
if (bytes != 18)
|
||||
@ -83,8 +96,6 @@ main (void)
|
||||
cmp_test (__LINE__, i32, t32, "\n\nLine %d : 32 bit int failed 0x%x -> 0x%x.\n\n") ;
|
||||
cmp_test (__LINE__, i64, t64, "\n\nLine %d : 64 bit int failed 0x%llx -> 0x%llx.\n\n") ;
|
||||
|
||||
remove (filename) ;
|
||||
puts ("ok") ;
|
||||
|
||||
return 0 ;
|
||||
} /* main */
|
||||
|
||||
} /* conversion_test */
|
||||
|
Loading…
Reference in New Issue
Block a user