34600b0abdb592646d0614e80d103e22a84a60d7
2 ** Copyright (C) 2006-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser 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.
29 #include "test_main.h"
33 ** This is a bit rough, but it is the nicest way to do it.
36 #define cmp_test(line,ival,tval,str) \
38 { printf (str, line, ival, tval) ; \
43 conversion_test (char endian
)
45 SF_PRIVATE sf_private
, *psf
;
46 const char * filename
= "conversion.bin" ;
47 int64_t i64
= SF_PLATFORM_S64 (0x0123456789abcdef), t64
= 0 ;
48 char format_str
[16] ;
50 char i8
= 12, t8
= 0 ;
51 short i16
= 0x123, t16
= 0 ;
52 int i24
= 0x23456, t24
= 0 ;
53 int i32
= 0x0a0b0c0d, t32
= 0 ;
56 snprintf (format_str
, sizeof (format_str
), "%c12348", endian
) ;
58 snprintf (test_name
, sizeof (test_name
), "Testing %s conversions", endian
== 'e' ? "little endian" : "big endian") ;
59 print_test_name (test_name
) ;
62 memset (psf
, 0, sizeof (sf_private
)) ;
64 psf
->file
.mode
= SFM_WRITE
;
65 snprintf (psf
->file
.path
.c
, sizeof (psf
->file
.path
.c
), "%s", filename
) ;
67 if (psf_fopen (psf
) != 0)
68 { printf ("\n\nError : failed to open file '%s' for write.\n\n", filename
) ;
72 psf_binheader_writef (psf
, format_str
, i8
, i16
, i24
, i32
, i64
) ;
73 psf_fwrite (psf
->header
, 1, psf
->headindex
, psf
) ;
76 memset (psf
, 0, sizeof (sf_private
)) ;
78 psf
->file
.mode
= SFM_READ
;
79 snprintf (psf
->file
.path
.c
, sizeof (psf
->file
.path
.c
), "%s", filename
) ;
81 if (psf_fopen (psf
) != 0)
82 { printf ("\n\nError : failed to open file '%s' for read.\n\n", filename
) ;
86 bytes
= psf_binheader_readf (psf
, format_str
, &t8
, &t16
, &t24
, &t32
, &t64
) ;
90 { printf ("\n\nLine %d : read %d bytes.\n\n", __LINE__
, bytes
) ;
94 cmp_test (__LINE__
, i8
, t8
, "\n\nLine %d : 8 bit int failed %d -> %d.\n\n") ;
95 cmp_test (__LINE__
, i16
, t16
, "\n\nLine %d : 16 bit int failed 0x%x -> 0x%x.\n\n") ;
96 cmp_test (__LINE__
, i24
, t24
, "\n\nLine %d : 24 bit int failed 0x%x -> 0x%x.\n\n") ;
97 cmp_test (__LINE__
, i32
, t32
, "\n\nLine %d : 32 bit int failed 0x%x -> 0x%x.\n\n") ;
98 cmp_test (__LINE__
, i64
, t64
, "\n\nLine %d : 64 bit int failed 0x%" PRIx64
"x -> 0x%" PRIx64
"x.\n\n") ;
102 } /* conversion_test */
105 test_conversions (void)
107 conversion_test ('E') ;
108 conversion_test ('e') ;
109 } /* test_conversion */