summaryrefslogtreecommitdiff
path: root/src/test_endswap.tpl
blob: ad7cee171192be9296447d355088013cf0f482cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
[+ AutoGen5 template c +]
/*
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2.1 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "sfconfig.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>

#if HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "common.h"
#include "sfendian.h"

#include "test_main.h"

#define	FMT_SHORT	"0x%04x\n"
#define	FMT_INT		"0x%08x\n"
#define	FMT_INT64	"0x%016" PRIx64 "\n"

/*==============================================================================
** Test functions.
*/

[+ FOR int_type +]
static void
dump_[+ (get "name") +]_array (const char * name, [+ (get "name") +] * data, int datalen)
{	int k ;

	printf ("%-6s : ", name) ;
	for (k = 0 ; k < datalen ; k++)
		printf ([+ (get "format") +], data [k]) ;
	putchar ('\n') ;
} /* dump_[+ (get "name") +]_array */

static void
test_endswap_[+ (get "name") +] (void)
{	[+ (get "name") +] orig [4], first [4], second [4] ;
	int k ;

	printf ("    %-40s : ", "test_endswap_[+ (get "name") +]") ;
	fflush (stdout) ;

	for (k = 0 ; k < ARRAY_LEN (orig) ; k++)
		orig [k] = [+ (get "value") +] + k ;

	endswap_[+ (get "name") +]_copy (first, orig, ARRAY_LEN (first)) ;
	endswap_[+ (get "name") +]_copy (second, first, ARRAY_LEN (second)) ;

	if (memcmp (orig, first, sizeof (orig)) == 0)
	{	printf ("\n\nLine %d : test 1 : these two array should not be the same:\n\n", __LINE__) ;
		dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
		dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
		exit (1) ;
		} ;

	if (memcmp (orig, second, sizeof (orig)) != 0)
	{	printf ("\n\nLine %d : test 2 : these two array should be the same:\n\n", __LINE__) ;
		dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
		dump_[+ (get "name") +]_array ("second", second, ARRAY_LEN (second)) ;
		exit (1) ;
		} ;

	endswap_[+ (get "name") +]_array (first, ARRAY_LEN (first)) ;

	if (memcmp (orig, first, sizeof (orig)) != 0)
	{	printf ("\n\nLine %d : test 3 : these two array should be the same:\n\n", __LINE__) ;
		dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
		dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
		exit (1) ;
		} ;

	endswap_[+ (get "name") +]_copy (first, orig, ARRAY_LEN (first)) ;
	endswap_[+ (get "name") +]_copy (first, first, ARRAY_LEN (first)) ;

	if (memcmp (orig, first, sizeof (orig)) != 0)
	{	printf ("\n\nLine %d : test 4 : these two array should be the same:\n\n", __LINE__) ;
		dump_[+ (get "name") +]_array ("orig", orig, ARRAY_LEN (orig)) ;
		dump_[+ (get "name") +]_array ("first", first, ARRAY_LEN (first)) ;
		exit (1) ;
		} ;

	puts ("ok") ;
} /* test_endswap_[+ (get "name") +] */
[+ ENDFOR int_type
+]


void
test_endswap (void)
{
[+ FOR int_type
+]	test_endswap_[+ (get "name") +] () ;
[+ ENDFOR int_type
+]
} /* test_endswap */