4931650c87ff381955eb4f88847644f886c70eea
2 ** Copyright (C) 2002-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.
34 #include "test_main.h"
36 #define FMT_SHORT "0x%04x\n"
37 #define FMT_INT "0x%08x\n"
38 #define FMT_INT64 "0x%016" PRIx64 "\n"
40 /*==============================================================================
46 dump_short_array (const char * name
, short * data
, int datalen
)
49 printf ("%-6s : ", name
) ;
50 for (k
= 0 ; k
< datalen
; k
++)
51 printf (FMT_SHORT
, data
[k
]) ;
53 } /* dump_short_array */
56 test_endswap_short (void)
57 { short orig
[4], first
[4], second
[4] ;
60 printf (" %-40s : ", "test_endswap_short") ;
63 for (k
= 0 ; k
< ARRAY_LEN (orig
) ; k
++)
64 orig
[k
] = 0x3210 + k
;
66 endswap_short_copy (first
, orig
, ARRAY_LEN (first
)) ;
67 endswap_short_copy (second
, first
, ARRAY_LEN (second
)) ;
69 if (memcmp (orig
, first
, sizeof (orig
)) == 0)
70 { printf ("\n\nLine %d : test 1 : these two array should not be the same:\n\n", __LINE__
) ;
71 dump_short_array ("orig", orig
, ARRAY_LEN (orig
)) ;
72 dump_short_array ("first", first
, ARRAY_LEN (first
)) ;
76 if (memcmp (orig
, second
, sizeof (orig
)) != 0)
77 { printf ("\n\nLine %d : test 2 : these two array should be the same:\n\n", __LINE__
) ;
78 dump_short_array ("orig", orig
, ARRAY_LEN (orig
)) ;
79 dump_short_array ("second", second
, ARRAY_LEN (second
)) ;
83 endswap_short_array (first
, ARRAY_LEN (first
)) ;
85 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
86 { printf ("\n\nLine %d : test 3 : these two array should be the same:\n\n", __LINE__
) ;
87 dump_short_array ("orig", orig
, ARRAY_LEN (orig
)) ;
88 dump_short_array ("first", first
, ARRAY_LEN (first
)) ;
92 endswap_short_copy (first
, orig
, ARRAY_LEN (first
)) ;
93 endswap_short_copy (first
, first
, ARRAY_LEN (first
)) ;
95 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
96 { printf ("\n\nLine %d : test 4 : these two array should be the same:\n\n", __LINE__
) ;
97 dump_short_array ("orig", orig
, ARRAY_LEN (orig
)) ;
98 dump_short_array ("first", first
, ARRAY_LEN (first
)) ;
103 } /* test_endswap_short */
106 dump_int_array (const char * name
, int * data
, int datalen
)
109 printf ("%-6s : ", name
) ;
110 for (k
= 0 ; k
< datalen
; k
++)
111 printf (FMT_INT
, data
[k
]) ;
113 } /* dump_int_array */
116 test_endswap_int (void)
117 { int orig
[4], first
[4], second
[4] ;
120 printf (" %-40s : ", "test_endswap_int") ;
123 for (k
= 0 ; k
< ARRAY_LEN (orig
) ; k
++)
124 orig
[k
] = 0x76543210 + k
;
126 endswap_int_copy (first
, orig
, ARRAY_LEN (first
)) ;
127 endswap_int_copy (second
, first
, ARRAY_LEN (second
)) ;
129 if (memcmp (orig
, first
, sizeof (orig
)) == 0)
130 { printf ("\n\nLine %d : test 1 : these two array should not be the same:\n\n", __LINE__
) ;
131 dump_int_array ("orig", orig
, ARRAY_LEN (orig
)) ;
132 dump_int_array ("first", first
, ARRAY_LEN (first
)) ;
136 if (memcmp (orig
, second
, sizeof (orig
)) != 0)
137 { printf ("\n\nLine %d : test 2 : these two array should be the same:\n\n", __LINE__
) ;
138 dump_int_array ("orig", orig
, ARRAY_LEN (orig
)) ;
139 dump_int_array ("second", second
, ARRAY_LEN (second
)) ;
143 endswap_int_array (first
, ARRAY_LEN (first
)) ;
145 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
146 { printf ("\n\nLine %d : test 3 : these two array should be the same:\n\n", __LINE__
) ;
147 dump_int_array ("orig", orig
, ARRAY_LEN (orig
)) ;
148 dump_int_array ("first", first
, ARRAY_LEN (first
)) ;
152 endswap_int_copy (first
, orig
, ARRAY_LEN (first
)) ;
153 endswap_int_copy (first
, first
, ARRAY_LEN (first
)) ;
155 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
156 { printf ("\n\nLine %d : test 4 : these two array should be the same:\n\n", __LINE__
) ;
157 dump_int_array ("orig", orig
, ARRAY_LEN (orig
)) ;
158 dump_int_array ("first", first
, ARRAY_LEN (first
)) ;
163 } /* test_endswap_int */
166 dump_int64_t_array (const char * name
, int64_t * data
, int datalen
)
169 printf ("%-6s : ", name
) ;
170 for (k
= 0 ; k
< datalen
; k
++)
171 printf (FMT_INT64
, data
[k
]) ;
173 } /* dump_int64_t_array */
176 test_endswap_int64_t (void)
177 { int64_t orig
[4], first
[4], second
[4] ;
180 printf (" %-40s : ", "test_endswap_int64_t") ;
183 for (k
= 0 ; k
< ARRAY_LEN (orig
) ; k
++)
184 orig
[k
] = 0x0807050540302010LL
+ k
;
186 endswap_int64_t_copy (first
, orig
, ARRAY_LEN (first
)) ;
187 endswap_int64_t_copy (second
, first
, ARRAY_LEN (second
)) ;
189 if (memcmp (orig
, first
, sizeof (orig
)) == 0)
190 { printf ("\n\nLine %d : test 1 : these two array should not be the same:\n\n", __LINE__
) ;
191 dump_int64_t_array ("orig", orig
, ARRAY_LEN (orig
)) ;
192 dump_int64_t_array ("first", first
, ARRAY_LEN (first
)) ;
196 if (memcmp (orig
, second
, sizeof (orig
)) != 0)
197 { printf ("\n\nLine %d : test 2 : these two array should be the same:\n\n", __LINE__
) ;
198 dump_int64_t_array ("orig", orig
, ARRAY_LEN (orig
)) ;
199 dump_int64_t_array ("second", second
, ARRAY_LEN (second
)) ;
203 endswap_int64_t_array (first
, ARRAY_LEN (first
)) ;
205 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
206 { printf ("\n\nLine %d : test 3 : these two array should be the same:\n\n", __LINE__
) ;
207 dump_int64_t_array ("orig", orig
, ARRAY_LEN (orig
)) ;
208 dump_int64_t_array ("first", first
, ARRAY_LEN (first
)) ;
212 endswap_int64_t_copy (first
, orig
, ARRAY_LEN (first
)) ;
213 endswap_int64_t_copy (first
, first
, ARRAY_LEN (first
)) ;
215 if (memcmp (orig
, first
, sizeof (orig
)) != 0)
216 { printf ("\n\nLine %d : test 4 : these two array should be the same:\n\n", __LINE__
) ;
217 dump_int64_t_array ("orig", orig
, ARRAY_LEN (orig
)) ;
218 dump_int64_t_array ("first", first
, ARRAY_LEN (first
)) ;
223 } /* test_endswap_int64_t */
230 test_endswap_short () ;
231 test_endswap_int () ;
232 test_endswap_int64_t () ;