libsndfile source files.
[Faustine.git] / interpretor / libsndfile-1.0.25 / src / test_endswap.tpl
1 [+ AutoGen5 template c +]
2 /*
3 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU Lesser General Public License as published by
7 ** the Free Software Foundation; either version 2.1 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU Lesser General Public License for more details.
14 **
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include "sfconfig.h"
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <inttypes.h>
27
28 #if HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 #include "common.h"
33 #include "sfendian.h"
34
35 #include "test_main.h"
36
37 #define FMT_SHORT "0x%04x\n"
38 #define FMT_INT "0x%08x\n"
39 #define FMT_INT64 "0x%016" PRIx64 "\n"
40
41 /*==============================================================================
42 ** Test functions.
43 */
44
45 [+ FOR int_type +]
46 static void
47 dump_[+ (get "name") +]_array (const char * name, [+ (get "name") +] * data, int datalen)
48 { int k ;
49
50 printf ("%-6s : ", name) ;
51 for (k = 0 ; k < datalen ; k++)
52 printf ([+ (get "format") +], data [k]) ;
53 putchar ('\n') ;
54 } /* dump_[+ (get "name") +]_array */
55
56 static void
57 test_endswap_[+ (get "name") +] (void)
58 { [+ (get "name") +] orig [4], first [4], second [4] ;
59 int k ;
60
61 printf (" %-40s : ", "test_endswap_[+ (get "name") +]") ;
62 fflush (stdout) ;
63
64 for (k = 0 ; k < ARRAY_LEN (orig) ; k++)
65 orig [k] = [+ (get "value") +] + k ;
66
67 endswap_[+ (get "name") +]_copy (first, orig, ARRAY_LEN (first)) ;
68 endswap_[+ (get "name") +]_copy (second, first, ARRAY_LEN (second)) ;
69
70 if (memcmp (orig, first, sizeof (orig)) == 0)
71 { printf ("\n\nLine %d : test 1 : these two array should not be the same:\n\n", __LINE__) ;
72 dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
73 dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
74 exit (1) ;
75 } ;
76
77 if (memcmp (orig, second, sizeof (orig)) != 0)
78 { printf ("\n\nLine %d : test 2 : these two array should be the same:\n\n", __LINE__) ;
79 dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
80 dump_[+ (get "name") +]_array ("second", second, ARRAY_LEN (second)) ;
81 exit (1) ;
82 } ;
83
84 endswap_[+ (get "name") +]_array (first, ARRAY_LEN (first)) ;
85
86 if (memcmp (orig, first, sizeof (orig)) != 0)
87 { printf ("\n\nLine %d : test 3 : these two array should be the same:\n\n", __LINE__) ;
88 dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
89 dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
90 exit (1) ;
91 } ;
92
93 endswap_[+ (get "name") +]_copy (first, orig, ARRAY_LEN (first)) ;
94 endswap_[+ (get "name") +]_copy (first, first, ARRAY_LEN (first)) ;
95
96 if (memcmp (orig, first, sizeof (orig)) != 0)
97 { printf ("\n\nLine %d : test 4 : these two array should be the same:\n\n", __LINE__) ;
98 dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
99 dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
100 exit (1) ;
101 } ;
102
103 puts ("ok") ;
104 } /* test_endswap_[+ (get "name") +] */
105 [+ ENDFOR int_type
106 +]
107
108
109 void
110 test_endswap (void)
111 {
112 [+ FOR int_type
113 +] test_endswap_[+ (get "name") +] () ;
114 [+ ENDFOR int_type
115 +]
116 } /* test_endswap */
117